Positions for Payload: scoped, dated grants people hold on a site, an organization or a project, with host-defined types, grant rules and an audit trail.
Status: early, 0.x, not on npm yet. The 56 tests run against a real Payload with an in-memory MongoDB. It hasn't been tried in a real app, and the admin screens haven't been looked at in a browser.
The scope agreed with Captive Origins:
- A position is a scoped, dated grant that opens tools or portals: on a site, an organization or a project.
- One grant table holds the person, the position type, the scope, start and end dates, who granted it, and an audit trail.
- The host passes in the position types, the scope kinds and who may grant each. Each defaults to nobody.
- A hook can refuse a grant. A host uses it so minors never hold positions.
- A grant holds a user, a position type, a scope (a kind and an id, such as
projectandp-1), a start and end date (ISO dates only;0,1and words are refused), who granted it, a status and notes. A position with no scope, such as one for a whole site, is a type markedunscoped. - Statuses: active, paused, revoked, expired. Revoked and expired are final; grant again to renew. Grants can't be deleted, not even by server code that skips access.
- History. Every grant, pause, resume, end-date change, revoke and expiry adds a row to
position-grant-history: what changed, who did it (ascollection:id), and a copy of the grant (without its notes). Only the plugin can add rows, and rows can't be changed or deleted through Payload. Someone with direct database access can still change anything. - Notes and history are read through their own option,
canReadPrivate, notcanGrant, so a granter limited to one scope doesn't read everything. Without it, nobody reads them through the API. For notes it is asked per grant and must answer exactlytrue. For the history it may also answer with a Payloadwhereon the rows, such as{ 'snapshot.scopeId': { equals: 'p-1' } }. Holders can't read their own notes, and someone who can't read a grant's notes can't overwrite them either. Notes are capped at 2000 characters and scope ids at 200. - Fails closed. Without a
canGrantthat answers exactlytrue, nobody can grant. A throw or any other answer is a no.canRevoke(default: the same ascanGrant) covers revoking, pausing and shortening an end date. Resuming a paused grant, or moving an end date later or to none, is a grant, so it needscanGrant, the veto, and can't be done for your own account. - Self-grants refused. Nobody grants, resumes or extends a position for their own account unless the host sets
allowSelfGrant: true. - Host veto.
refuseGrantis required: pass a function, orfalsefor no veto. It can block a grant for any reason. It also runs on resume and on extension, and for server code that skips access. On an extension it sees the grant with the new end date already in it. Its reason is shown to the person who tried, so keep it general. A reason like "under 18" would tell them a child's age. - Audit hooks before and after grant, revoke, expiry, pause, resume and end-date change. A failing
beforehook stops the change. A failingafterhook is logged. - Helpers that respect start and end dates:
hasPositionandpositionsOf. - One live grant per holder, position and scope, enforced by a unique index on a
liveKeyfield, so two requests at once can't both get in. The index has to exist. On Mongo, setensureIndexes: trueonmongooseAdapter(it is off by default). On SQL adapters, run a migration that adds a unique index onposition_grants.live_key. - Needs database transactions. The history row is written in the same transaction as the change, so if it fails the change is undone. Without transactions (a standalone Mongo, or
transactionOptions: false) the plugin refuses every change. SetallowWithoutTransactions: trueonly if you accept a grant that can be saved without its history row.
Not on npm yet. To work on it:
npm install
npm test
npm run build
import { positions, hasPosition, expireGrants } from '@extantape/payload-plugin-positions'
positions({
users: 'users', // default
positionTypes: [
{ value: 'editor', label: 'Editor' },
{ value: 'steward', unscoped: true },
],
scopeKinds: [{ value: 'project' }, { value: 'group' }],
canGrant: ({ user }) => user.role === 'staff',
refuseGrant: ({ holder }) => (holder.restricted ? 'Not available for this account.' : null), // or false
audit: { afterGrant: (e) => console.log(e.event, e.grant.id) },
})
await hasPosition(payload, user, 'editor', { kind: 'project', id: 'p-1' }) // true or false
await positionsOf(payload, user) // [{ id, position, scope, startsAt, endsAt }]
await expireGrants(payload) // run from a job: marks ended grants expired and runs the expiry hooksPass req.user or a user id. A user document is only accepted when its collection is the plugin's users collection, so an id from another collection can't match. hasPosition answers for exactly the scope you give. Leave the scope out to ask about an unscoped position. No user, a paused, revoked or expired grant, a date outside the window, or an error reading grants all give false. positionsOf throws if grants can't be read. Pass { at } to check another moment and { req } to stay in a transaction.
By default staff who pass canGrant read every grant and everyone else reads their own. canRevoke and canRead can change who revokes and who reads.
Invites, codes, contact addresses, a verification step, expiry reminders and syncing a user's role list are not built. Expiry runs when the host calls expireGrants; until then the helpers already refuse an ended grant.
MIT. Copyright (c) 2026 EXTANT APE. See LICENSE.
Contributions arrive as pull requests from co/ branches in this repo. Only the owner merges.