From c9540d291a08634613e69d7c786ddb565f5c4440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Wed, 25 Nov 2026 03:30:40 +0100 Subject: [PATCH] Copied staff collections: access guide, API table, changelog, reference index Co-Authored-By: Claude Fable 5.2 --- docs/CHANGELOG.md | 40 ++++++++++++++++ docs/access.md | 37 +++++++++++++++ docs/agent/reference-site/INDEX.md | 46 +------------------ .../skills/ipal-reference/resources/api.md | 5 +- .../skills/ipal-reference/resources/api.md | 5 +- scripts/reference-index.mjs | 4 +- 6 files changed, 87 insertions(+), 50 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 533e103..b95a81f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,46 @@ versions at once, go through every "Requires project changes" section in order, version you have. A new release = a new section at the top; we remove the oldest ones only once there are more than 20. +## Unreleased — copied staff collections (version to be set at release; after the security follow-ups below) + +> No option, schema, migration or import-map change. Matters only to a project in which a plugin listed after +> ipalKit **copies a staff collection** under a new slug or reuses its `access` object. No known site does. + +### Security +- **A copy of a staff collection kept rules written for the original.** A plugin listed after ipalKit that + spreads a staff collection into another slug (`{ ...staff, slug: 'copy' }`) carried the "already handled" marker + and the plugin's rules along. "An admin, or the account itself" then meant the ORIGINAL's accounts: with + numeric ids (Postgres, SQLite) an account of the original could change the password of the account with the + same id in the copy. Now the plugin puts its rule for the copy's own slug **in front of** every rule it wrote + for the original, and both must allow; on a copy named as staff, in front of every rule. Nothing is replaced + or rewritten, so a copy is never opened wider than it was and never wider than the plugin's rule — whatever + role values it has and however it uses or wraps the copied rules. Its `roles` field is guarded on every copy. + The marker `custom.ipalAccounts` names the slug and the staff status (`{ slug, staff }`). + +### Fixed +- `next dev`: a collection that becomes a staff collection in an edit (named in `access.staffCollections` for + the first time) gets its rules on the reload; it needed a restart when its config object outlived the reload. +- A plain 2FA config guards nothing twice at start (the plugin's rules are marked before its 2FA guard). + +### Added +- Exports: `staffRuleOf`, `isPasswordRuleHook`; types `StaffRuleMark`, `AccountsMarker`. + `markSeenAuthCollections(config, staffSlugs)` takes the staff slugs. +- `pnpm e2e:built` covers copied staff collections on the built site (both bundlers). + +### Requires project changes +- **Only if a plugin of yours copies a staff collection:** in the copy, the copied rule "an admin, or the account + itself" lets only an admin through (it still speaks of the original's accounts). If the copy's own accounts + should edit themselves, give the copy its own rule — one line: + `access: { ...staff.access, update: adminOrSelfIn('copy') }` ([access.md](./access.md) "Account rules"). + Before this change those accounts could not edit themselves either. +- `pnpm ipal:skills`. + +### Known limitations +- `next dev`: a collection that STOPS being a staff collection in an edit keeps the rules until a restart; after + a reload the adoption still runs with the options the site started with. +- A marker or a function mark written by hand in the project's own config is taken at its word ("handled" for a + marker of the collection's own slug); a hand-made function mark only ever adds the plugin's rule in front. + ## Unreleased — security follow-ups to 1.16.7 (version to be set at release) > **Read before upgrading.** No option, schema, migration or import-map change. Two points: diff --git a/docs/access.md b/docs/access.md index d666d25..dbb681f 100644 --- a/docs/access.md +++ b/docs/access.md @@ -355,6 +355,43 @@ is kept and can only narrow it. To keep a late collection's rules exactly as the wider `read` — say so on the collection: `custom: { ipal: { accountRules: false } }` (the password rule and the first-user endpoint still apply), or list that plugin before ipalKit. +**A copy of a staff collection** — a later plugin that spreads one into a new slug (`{ ...staff, slug: 'copy' }`), +or a new collection that reuses a staff collection's `access` object — brings along rules the plugin wrote for +the ORIGINAL: "an account of `staff`", "the account itself" = one of the original's. The plugin sees them by a +mark it puts on its own functions (`staffRuleOf(rule)` → `{ slug, self }`; the mark counts only on the very +function it was made for, so a wrapper of yours around a plugin rule is your rule). What it does is one thing, +in every case: + +> **The plugin's rule for THIS collection goes in front of the rule that is there, and both must allow.** +> Nothing is replaced and nothing is rewritten. + +| The copy | Where the plugin's rule goes in front | +|---|---| +| named in `access.staffCollections` | of every rule — as on any late staff collection | +| not named as staff, or with `custom: { ipal: { accountRules: false } }` | only of the rules the plugin wrote for the original; your own rules there stay as they are | +| its `roles` field | guarded on every copy (the plugin's roles: only an admin changes them; others: never one's own) unless the field has an `access.update` of its own — then the guard goes in front only of a rule the plugin wrote for the original | + +So a copy is never opened wider than its rules were before, and never wider than the plugin's rule — whatever +role values it has, whichever operation it uses a copied rule for, however it wraps it. The original's account +with the same id is not "the account itself" in the copy. + +**The cost, and the one line that pays it:** a copied rule that says "an admin, or the account itself" still +means the ORIGINAL's accounts, so in the copy only an admin passes it — the copy's own accounts cannot edit +themselves until the copy says who may: + +```ts +import { adminOrSelfIn } from '@intecion/ipal-kit' +// in the plugin that makes the copy: +{ ...staff, slug: 'copy', access: { ...staff.access, update: adminOrSelfIn('copy') } } +``` + +A rule you write there is not marked, so on a staff copy it is combined with the plugin's rule for `copy` +("an admin, or the account itself" of the copy) and works. The password rule is on a copy once +(`isPasswordRuleHook`). The marker `custom.ipalAccounts` (`{ slug, staff }`, type `AccountsMarker`) records which +collection the plugin has handled and whether as staff: a copy carries the original's marker and is handled under +its own slug; in `next dev` a collection named as staff in an edit is handled on the reload. A marker for the +collection's own slug means "handled" — only your own config can write one, like `accountRules: false`. + **A slug in `access.staffCollections` or `access.authCollection` that is not an auth collection of the config:** Payload does not start. The log names the slug and the auth collections it knows. The process stays up, but every Payload call fails — `/api/health` answers 503, `/api/*` and the panel 500; a page that needs no Payload diff --git a/docs/agent/reference-site/INDEX.md b/docs/agent/reference-site/INDEX.md index d81e54a..aabe8e7 100644 --- a/docs/agent/reference-site/INDEX.md +++ b/docs/agent/reference-site/INDEX.md @@ -1164,8 +1164,8 @@ Rules: AGENT.md §8a. |---|---| | `e2e/create-test-admin.ts` | two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests' mail sink (local / CI database only) | | `e2e/global-setup.ts` | Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order (below) | -| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin's values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up) (below) | -| `e2e/late-staff.spec.ts` | the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin | +| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (staff collections of the config: roles with one more value, the plugin's roles, roles of the project's own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up) | +| `e2e/late-staff.spec.ts` | the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, staff collections whose accounts can hold `admin`, and copies of staff collections — a visitor account gets nothing, nobody raises its own role or makes an admin, a copy is never wider than the plugin's rule | | `e2e/smoke.spec.ts` | the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA | | `e2e/smtp-sink.ts` | a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments) | | `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test, and the address of the second test admin (below) | @@ -1191,48 +1191,6 @@ export default function globalSetup(): void { } ``` -### `e2e/late-staff-fixture.ts` - -```ts -import type { Config, Plugin } from 'payload' - -/** - * Test fixture, on only with E2E_LATE_STAFF=1 (e2e/late-staff.spec.ts): a plugin listed AFTER ipalKit that adds - * a staff collection (`late-staff`, named in `access.staffCollections`) and a visitor collection with open - * sign-up. ipalKit has already run when these collections appear, so it must give them its account rules when - * the config goes live — and it must do so in a BUILT site too, where bundlers rename every function. - * Never part of a real site: the starter drops `e2e/` and the lines that use this file. - */ -export const E2E_LATE_STAFF = process.env.E2E_LATE_STAFF === '1' - -/** Slugs the fixture names as staff (payload.config.ts → `access.staffCollections`). */ -export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text'] - -/** - * Listed BEFORE ipalKit: a staff collection of the project's own, without rules, whose roles are the plugin's values - * PLUS one more. `admin` on an account of it makes a plugin admin, so its accounts must not hand that value out. - */ -export const e2eEarlyStaff: Plugin = (config: Config) => - E2E_LATE_STAFF - ? { ...config, collections: [...(config.collections ?? []), { slug: 'e2e-crew', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin', 'boss'], saveToJWT: true }] }] } - : config - -export const e2eLateStaff: Plugin = (config: Config) => - E2E_LATE_STAFF - ? { - ...config, - collections: [ - ...(config.collections ?? []), - // no access rules at all: Payload's defaults ("any logged-in user") are what ipalKit must replace - { slug: 'late-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }], versions: true }, - // a late staff collection whose `roles` is a text field: any value can be written there, `admin` included - { slug: 'e2e-late-text', auth: true, fields: [{ name: 'roles', type: 'text', hasMany: true }] }, - { slug: 'e2e-visitors', access: { create: () => true }, auth: true, fields: [] }, - ], - } - : config -``` - ### `e2e/totp.ts` ```ts diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index ada3950..c044987 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -68,7 +68,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | | `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. A collection is "handled" when its marker `custom.ipalAccounts` (`AccountsMarker`: `{ slug, staff }`) names its own slug and its staff status; a copy under a new slug, or a collection that became staff since, is handled again (`markSeenAuthCollections(config, staffSlugs)` writes the marker at config time). On a COPY the plugin never replaces or rewrites a rule: its rule for the copy's slug goes in front of every rule on a staff copy, and in front of the rules marked as the plugin's for another collection (`staffRuleOf`) on a copy that is not staff or keeps its own rules; the `roles` field of every copy is guarded. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `staffRuleOf(rule)`, `isPasswordRuleHook(hook)` | `@intecion/ipal-kit` | The plugin's mark on its own functions, read-only (a `Symbol.for` property on the function, so it travels with a copied collection and is the same for every instance of the module): `{ slug, self }` — the collection the rule was written for and the function the mark was made for — or `undefined` for a rule the plugin did not put there. It counts only on that very function: a closure, a `Proxy` or a copied function around the plugin's rule is your own rule. `isPasswordRuleHook`: whether a `beforeOperation` hook is the plugin's password rule. The mark is used for one thing: to put the plugin's rule for a copy's own slug in front of a rule written for the original. | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | @@ -81,7 +82,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffRuleMark` (`{ slug, self }`), `AccountsMarker` (`{ slug, staff }`, in `custom.ipalAccounts`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index ada3950..c044987 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -68,7 +68,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | | `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. A collection is "handled" when its marker `custom.ipalAccounts` (`AccountsMarker`: `{ slug, staff }`) names its own slug and its staff status; a copy under a new slug, or a collection that became staff since, is handled again (`markSeenAuthCollections(config, staffSlugs)` writes the marker at config time). On a COPY the plugin never replaces or rewrites a rule: its rule for the copy's slug goes in front of every rule on a staff copy, and in front of the rules marked as the plugin's for another collection (`staffRuleOf`) on a copy that is not staff or keeps its own rules; the `roles` field of every copy is guarded. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `staffRuleOf(rule)`, `isPasswordRuleHook(hook)` | `@intecion/ipal-kit` | The plugin's mark on its own functions, read-only (a `Symbol.for` property on the function, so it travels with a copied collection and is the same for every instance of the module): `{ slug, self }` — the collection the rule was written for and the function the mark was made for — or `undefined` for a rule the plugin did not put there. It counts only on that very function: a closure, a `Proxy` or a copied function around the plugin's rule is your own rule. `isPasswordRuleHook`: whether a `beforeOperation` hook is the plugin's password rule. The mark is used for one thing: to put the plugin's rule for a copy's own slug in front of a rule written for the original. | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | @@ -81,7 +82,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffRuleMark` (`{ slug, self }`), `AccountsMarker` (`{ slug, staff }`, in `custom.ipalAccounts`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/scripts/reference-index.mjs b/scripts/reference-index.mjs index fa64395..384386c 100644 --- a/scripts/reference-index.mjs +++ b/scripts/reference-index.mjs @@ -60,8 +60,8 @@ export const DESCRIPTIONS = { 'README.md': 'how to run the reference site and what is where', 'docs/DEPLOY.md': 'the Coolify runbook: local check, app settings, MongoDB resource, env, targeted seeds, DNS, rollback', 'e2e/create-test-admin.ts': 'two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests\' mail sink (local / CI database only)', - 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin\'s values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up)', - 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin', + 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (staff collections of the config: roles with one more value, the plugin\'s roles, roles of the project\'s own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up)', + 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, staff collections whose accounts can hold `admin`, and copies of staff collections — a visitor account gets nothing, nobody raises its own role or makes an admin, a copy is never wider than the plugin\'s rule', 'e2e/global-setup.ts': 'Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order', 'e2e/two-factor-setup.spec.ts': 'browser check of "2FA setup required": the first admin of a fresh site, a new editor, the administrator\'s reset on the account page', 'e2e/smoke.spec.ts': 'the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA',