Links a minor's account to up to two guardians using single-use codes. Guardian writes to the minor's listed records are refused and turned into suggestions the minor approves or declines, while the minor's larger requests go to a guardian for a decision. Requires a users collection, MongoDB with transactions, and the site to supply isMinor, access.manage and actingFor functions. Works with Payload 3.80 or later.
Guardians for Payload: link a minor's account to up to two guardians, turn a guardian's changes to the minor's records into suggestions the minor decides, and route the minor's bigger requests to a guardian.
Installation
npm i @extantape/payload-plugin-guardians0
Stars
0
Forks
0
Open Issues
1 weeks ago
Last Updated
366
Weekly Downloads
v0.2.0
npm Version
113.1 KB
Unpacked Size
0
Dependencies
00 since Nov 8
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
381+381 since Nov 15
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 381 |
| Dec 5, 2026 | 414 |
| Dec 4, 2026 | 581 |
| Dec 3, 2026 | 601 |
| Dec 2, 2026 | 617 |
| Dec 1, 2026 | 631 |
| Nov 30, 2026 | 465 |
| Nov 29, 2026 | 544 |
| Nov 28, 2026 | 504 |
| Nov 27, 2026 | 332 |
| Nov 26, 2026 | 284 |
| Nov 25, 2026 | 245 |
| Nov 24, 2026 | 195 |
| Nov 23, 2026 | 317 |
| Nov 22, 2026 | 205 |
| Nov 21, 2026 | 195 |
| Nov 20, 2026 | 192 |
| Nov 19, 2026 | 184 |
| Nov 18, 2026 | 179 |
| Nov 17, 2026 | 172 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1457696390-root)<a href="https://payloaddirectory.dev/plugins/1457696390-root"><img src="https://payloaddirectory.dev/badge/1457696390-root.svg" alt="Payload Directory"></a>README
Guardians for Payload: link a minor's account to up to two guardians, turn a guardian's changes to the minor's records into suggestions the minor decides, and route the minor's bigger requests to a guardian.
Status: 0.2.0 (2026-11-27). It changes how the functions are called since 0.1.0, which went to npm on 2026-11-14; read the upgrading notes in the changelog first. 186 tests pass against Payload 3.92 with an in-memory MongoDB replica set. They cover links and every refusal, decisions refused outside the person's own session, refusals when actingFor doesn't say who is acting, a race for the last place, canActAs, guardian writes refused on every path, suggestions from start to finish, requests with the first decision winning, coming of age, deleted accounts, races between two decisions, access, failed notices and events, lost transactions, and links that fail partway through ending. Not tested: a real site, the SQL adapter, Hats or any other real role switcher (the tests stand in for one with a header), GraphQL, REST routes of a site's own, and uploads on a listed collection. The changelog lists the narrower gaps. No site uses it yet, and none will turn it on before a legal review of minors and guardian consent.
createLinkCode): 12 characters, single use, 7 days. The other side enters it, signed in (useLinkCode), and the link is active.badCode), and so does a code that would break one of the rules below. The person entering a code learns nothing about who made it.isMinor can't tell, there's no link). You can't link to yourself, or link twice, even with two codes at once. A minor has at most 2 active guardians. A guardian has at most 5 kids, unless a manager raises it with setKidLimit (never below the default).endLink with asStaff, checked against access.manage). Ended links are kept, with who ended them and why. Deleting an account ends its links (account-deleted), so a deleted guardian stops holding one of the minor's places. The ex-guardian's pending suggestions are withdrawn, and they stop reading the kid's requests to a guardian, including ones they decided. They can still read their own past suggestions to the kid.req) and checks it first: createLinkCode, useLinkCode, endLink, setKidLimit, suggest, approveSuggestion, declineSuggestion, reopenSuggestion, withdrawSuggestion, requestApproval and decideApproval.
req, as actingFor says, or the signed-in account when nobody is acting for anyone, must be the person the call names. Kid-side actions need the kid's own session.notFound, badCode for a code, notGuardian for suggest, notAllowed for setKidLimit), before anything is written. That covers someone else acting for them, a missing req, nobody signed in, another person's session, an actingFor that throws, and any answer from it other than null or undefined that doesn't name an actor with an account.suggest in their own name.await declineSuggestion(payload, { minor: req.user, request, req }).isMinor (yours, for example from Age Gate's minorUntil) is checked at every use, so access stops the moment someone is an adult. endComeOfAge(payload), daily, ends the links and tells both sides. History stays.canActAs(payload, { actor, target }): self, guardian (an active link, the actor known to be an adult, and the target known to be a minor), or no. Any error, or an age that can't be told, is no. Use it in your access rules. Hats links, one person's own accounts, are your own check.suggestionRequired), whether they switched into the kid's account or wrote from their own. That covers creates, updates and deletes, bulk ones included.
beforeChange, so a site hook that fills in the owner can't slip past. It's checked once more after the write, inside its transaction, which also catches a hook on another field.where) on these collections are refused for anyone who is an active guardian, and for anyone the plugin can't check. Payload doesn't roll back one document of a bulk update, so they can't be checked safely. Guardians change records one at a time.beforeChange hook stops the site at start-up, because field hooks run after the last check.disableTransaction: true gets past the after-write check, though not the beforeChange ones.actingFor that throws, or gives an answer other than null or undefined that doesn't name an actor with an account), or can't read the owner, it refuses.actingFor answers null or undefined for them.actingFor is required. If your site lets one account act as another (a switcher, or anything that changes req.user to the kid), it must say who is really acting, or a guardian acting as the kid would look like the kid. Return null or undefined when nobody is acting for anyone. Nothing else means that: false, 0, '', NaN, {} or any other answer that names no actor counts as unknown, and is refused. The actor is a user's id, or a record with an id. The id is a number other than 0, or text that isn't empty and has no space or invisible, format or control character (U+200B, say) at either end, so blank text names nobody (turn a database id object into text first). Watch for shortcuts such as return switched && { actor, target }, which can answer false or ''.actingFor reports. It can't see a child's API key or token held by someone else, a shared login, or another impersonation tool (a masquerade plugin, for example) unless you report it through actingFor. Without that report, those requests look like the signed-in account's own.suggest stores the change instead, with the real time. Nothing changes until the minor acts. The change can be up to 64 KB as JSON; a bigger one is refused (tooLarge).approveSuggestion applies it as the minor, with the minor's own access, in one transaction. For a new record, the time it was suggested goes into your timeField, for example when the animal was fed. An edit keeps the record's own time.
replace: true. Show "This replaces what you entered".gone.declineSuggestion keeps it for good, and reopenSuggestion puts it back on the list. Suggestions never expire.pendingCount gives the kid's badge.apply and an optional expiry.
requestApproval tells every active guardian, and each of them can read it. Tell the kid it goes to their guardian before calling it.decideApproval: the first decision wins, and the other gets notPending (409), even when both arrive at once. If a decision fails on a write conflict about something else, and the request is still pending, the answer is busy (409): That didn’t go through. Please try again. Approving runs apply as the minor, in the same transaction, so a failed apply leaves the request pending. An expired request is marked expired and can't be approved. Someone who can't decide it (the kid came of age, say) gets notFound, and the request is left as it was.onNotice. They carry no names or ages.
useLinkCode, endLink, suggest, declineSuggestion, reopenSuggestion, withdrawSuggestion and requestApproval save their writes outside your transaction. Their notices and events get your request without its transactionID, so they can't roll your transaction back, and they're saved even if you roll yours back.suggestion-withdrawn event sent when a link ends, here or any other way, comes with no request at all.onEvent write to a link the delete just ended without going through Payload (a raw database call with no session). MongoDB holds that write until the delete's transaction times out, about a minute and a half, and then the delete fails. Payload has no hook that runs after a transaction commits, so the plugin can't wait for it. A Local API write on the request it's given is refused at once and logged, and the delete goes on.approveSuggestion and decideApproval send their notices and events inside the decision's transaction.actingFor, access.manage, onNotice (or Notifications), onEvent and an approval's apply, the plugin checks the transaction is still open: the request it gave, or its copy, still has the same transactionID, and the database adapter still has it open. If not, the call throws TransactionLost (code transactionLost, 500), even when your function caught its own error. Approving and deciding check again before they commit.viaGuardian, or a write to a listed record throws inside your transaction, refusals included, roll it back and end the request. Never catch the error and carry on.isMinor is given no request, so it isn't checked. A database adapter that keeps no sessions list leaves only the transactionID comparison.onEvent) for every link, suggestion and decision, with references only: never the suggested data or ages. An event that fails is handled like a notice: logged with its type and the error's name and code, and passed over, so an audit trail that's down never blocks deleting an account, ending a link or a decision, and never makes a call throw after its writes are saved. The notices and events after it still go out. A lost transaction still fails the call. For your audit trail's via, viaGuardian(req) gives { kind: 'guardian', id } when a guardian acts for a minor. It gives null when actingFor names no actor with an account. If actingFor or the account read throws, viaGuardian throws too.access.manage, required; only an answer of exactly true counts). For a request to a guardian, the guardian side is whoever is linked now. Who decided a request (decidedBy) is read by managers only.access.manage throws, the read is refused, and endLink as staff and setKidLimit refuse. If it lost the transaction, the read or call fails with TransactionLost.On its own: it needs a users collection, MongoDB with transactions, and three things from you: isMinor, access.manage and actingFor. Without Notifications, notices go to your onNotice. It doesn't depend on any other plugin.
Needs: Payload ^3.80.0 as a peer dependency. No other EXTANT APE plugin is required.
Works with:
isMinor can read Age Gate's minorUntil, as the Install example does.actingFor, so a guardian who switched into a kid's account is still seen as the guardian.config.custom.notificationKinds and sends through config.custom.notifications.notify.onEvent through Audit Trail's fromPluginEvent, and use viaGuardian(req) in its via.Color Theory: none needed. It has no screens of its own, and its collections use Payload's standard admin, which takes Color Theory's admin colors when its applyToAdmin option is on.
Family: It's part of the Identity family (a working draft): plugins designed to sit together for accounts and access.
npm install @extantape/payload-plugin-guardians
import { guardiansPlugin, viaGuardian } from '@extantape/payload-plugin-guardians'
guardiansPlugin({
isMinor: (user) => typeof user.minorUntil === 'string' && user.minorUntil > new Date().toISOString().slice(0, 7), // required
access: { manage: ({ req }) => req.user?.role === 'admin' }, // required
actingFor: (req) => mySwitcher(req), // { actor, target } while someone acts for another account, else null or undefined
records: [
{ collection: 'animals', ownerField: 'keeper' },
{ collection: 'weights', ownerField: 'keeper', timeField: 'weighedAt' },
],
approvals: {
'join-project': { label: 'Join a project', expiresDays: 30, apply: async ({ request, minor, req, payload }) => { /* join, as the minor */ } },
},
onEvent: (e) => recordInMyAuditTrail(e),
})
Build the collections' indexes before first use. Run endComeOfAge and pruneLinkCodes daily.
canActAs. It doesn't hide anything else.onEvent fails, the event is logged and lost, and what it was about still happens. If your audit trail must never miss one, have onEvent queue it somewhere that can't fail for long. An approval's apply is different: it's the change itself, so if it throws, the approval rolls back and the request stays pending.endComeOfAge logs a link it can't end or announce and goes on with the rest. Ending a link, by endLink or by endComeOfAge, first takes the guardian off the kid's requests and withdraws their pending suggestions, then marks the link ended. Either step can fail. Either way the link stays active, endLink throws and can be called again, and the next endComeOfAge run tries again. If the first step failed, the guardian can still read the kid's requests until then. If only marking the link ended failed, the guardian is already off the kid's requests and their pending suggestions are withdrawn, while the link still shows active and they can still act for the kid as before, unless the kid has come of age, which is checked each time. After the link is marked ended the clean-up runs once more, logged if it fails. A request's audience only gives read access while that guardian has an active link to the kid, checked at every read, so a request saved while the link was ending never lets the ex-guardian read it, even if it still lists them. suggestion-withdrawn goes out once, after the link is marked ended, from whichever call marked it; it can be missed if onEvent fails or the process stops just after that write.onEvent that never returns holds up what it's called from. Deleting an account waits for it, inside the delete's transaction, and so does the endComeOfAge run. Give yours a timeout.npm test # integration tests, in-memory MongoDB
npm run typecheck
npm run build
MIT. See LICENSE.
Tags
payload plugin positions
Scoped, dated position grants for users on a site, organization or project, with host-defined types and an audit trail
76382/wk0v3
payload plugin organizations
Organizations with member levels, approval of pending organizations, email-domain matching and an organization picker…
67596/wk0v3
multi tenant
Manage multiple tenants and tenant-scoped content from a single Payload admin panel
100165.4k/wk46.1kv3 v4
payload plugin sharing
Share records with users and organizations through groups with Owner, Manager and Viewer levels
76425/wk0v3
payload plugin roles
Per-site role ladders and access helpers for multi-tenant Payload sites
76128/wk0v3
payload plugin guard
Central access policy file, typed predicates and guarded endpoints for Payload plugins and Local API calls
73664/wk37v3