diff --git a/docs/agent/reference-site/INDEX.md b/docs/agent/reference-site/INDEX.md index bf9a37f..e49b92e 100644 --- a/docs/agent/reference-site/INDEX.md +++ b/docs/agent/reference-site/INDEX.md @@ -2,7 +2,7 @@ -The reference site is one complete client site on ipal-kit 1.16.6 ("Example Studio", made up) that uses +The reference site is one complete client site on ipal-kit 1.16.7 ("Example Studio", made up) that uses every convention in AGENT.md. It lives in the plugin repo (`reference/`, not in the npm package). Copy the PATTERN of the file you need; change only the project's content. Files up to 40 lines are below in full; open the rest in the repo at the tag of your plugin version: diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index e866e00..81483c5 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -37,7 +37,7 @@ through this procedure. Ask only when you are missing something you cannot get y | the 2FA code screen answers "Too many codes were tried…" (`429` from `/api/verify-totp`) | more than 5 verify attempts for that account in 10 minutes (`twoFactor.verifyLimit`); repeated lines `[ipal] 2FA: too many verify attempts` in the log without the owner trying = someone has the password | wait for the window, enter the current code once; unexplained attempts: change that account's password. Tests that log in often: `verifyLimit: { max: … }` for that environment | | `isAdmin(req.user)` says `false` for a real administrator on the server, in a process that loads two Payload configs (tests, a multi-site script) | a call without a source counts only collections that are staff in **every** config of the process | pass the source: `isAdmin(req.user, req.payload)` — with it each config gets its own answer | | `isAdmin(user)` / `isEditor(user)` is always `false` in a client component or in `proxy.ts` | the staff collections are not known there (no config in the browser bundle / middleware), and the predicates fail closed | `isAdmin(user, config)` with `useConfig()`, imported from `@intecion/ipal-kit/client`; in middleware `isAdmin(user, { staffCollections: ['users'] })` | -| `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there after 1.16.6; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component | +| `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there since 1.16.7; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component | | an account logs in but every page and request answers 403 / the setup screen says "The time to set up two-step verification has passed" | 2FA setup required: the account did not set TOTP up within the window (72 h from its creation, an admin's reset, or the first start after the upgrade) | an administrator opens the account in the panel → Two-step verification → "Reopen setup" (or `POST /api/ipal/two-factor/reset` `{ userId }`); every administrator is blocked: security.md "Every administrator is blocked" — a script with the Local API, `payload.update({ collection: 'users', id, data: { totpSetupFrom: new Date().toISOString() } })` (`pnpm payload run`), then log in and set TOTP up; or `requireSetup: { windowHours: false }`, redeploy, set up, put it back | | a new account gets `403` from the API although its role allows the request | 2FA setup required: until TOTP is set up the account reaches only the setup screen | set TOTP up (log in to the panel); an integration: use an API key, or `twoFactor.requireSetup.exempt` | | after an upgrade EVERY panel login answers `500` (also `/api/users/init`), administrators with 2FA included; log: `[ipal] 2FA: the column for "totpSetupFrom" is missing … NOBODY CAN LOG IN` or `column users.totp_setup_from does not exist` | Postgres/SQLite: the migration that adds the 2FA column has not run (needed whenever 2FA is on) | `pnpm payload migrate:create` if no migration has it, commit, and redeploy with migrations run when the new container starts — `prodMigrations` in the adapter or the start command `pnpm payload migrate && pnpm start` (deployment.md §4.3; not Coolify's Pre-deployment command, which runs in the old container); nothing is lost. `ipal-doctor` reports a project whose migrations lack `totp_setup_from` | diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index 063174a..8adba70 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -351,7 +351,7 @@ for every site:** `grep -rnE "isAdmin\(|isEditor\(|hasMinimumRole\(" src` — a call in a **client component** or in `proxy.ts` / middleware now returns `false` without a source: `isAdmin(user, config)` (`useConfig()`), or `isAdmin(user, { staffCollections: ['users'] })`. A **client component imports them from - `@intecion/ipal-kit/client`** (not in 1.16.4–1.16.6: go to the next version); the main entry there fails with + `@intecion/ipal-kit/client`** (not in 1.16.4–1.16.6: go to 1.16.7); the main entry there fails with `next build --webpack` (`'server-only' cannot be imported from a Client Component module`). 4. `pnpm exec ipal-doctor --url ` (with the doctor token) → accounts without 2FA must be 0. An account that has not set TOTP up opens everything with its password alone: have its owner set it up now, or remove it. @@ -423,7 +423,7 @@ site without steps 1–3 and a deploy day agreed with the owner. Steps 2, 3 and setup screen with "Set up two-step verification by …"; after the code it is in. As an administrator open that account → "Two-step verification: Set up." and the reset button; delete the account. -**→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** +**→ 1.16.7 (hardening; CHANGELOG 1.16.7; PROGRAMISTA §6, item 69) — not a routine patch: agree the deploy with the owner, read every point, most sites change nothing:** 1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, **no schema change and no migration** on any database (the verify count uses Payload's own `payload-kv` collection). `grep -n "staffCollections\|authCollection" src/payload.config.ts`: every slug there must be an @@ -489,6 +489,9 @@ account → "Two-step verification: Set up." and the reset button; delete the ac 9. **Dashboard alerts.** Editors now see "An integration needs attention. Ask an administrator." instead of the error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it (`'all'` checks no role and no second factor). +10. **Role checks in client components.** `grep -rlE "^['\"]use client" src | xargs grep -nE "from '@intecion/ipal-kit'"` + — a file that imports `isAdmin`, `isEditor` or `hasMinimumRole` there: change the import to + `@intecion/ipal-kit/client` and keep the second argument (`isAdmin(user, config)`). `import type` may stay. **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, `staff-accounts-open`, `staff-own-roles`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. diff --git a/docs/dev/PROGRAMISTA.md b/docs/dev/PROGRAMISTA.md index a7f21f3..97e85f5 100644 --- a/docs/dev/PROGRAMISTA.md +++ b/docs/dev/PROGRAMISTA.md @@ -676,7 +676,8 @@ Do one item at a time, build, check. Order by importance: | 66 | **1.16.4** — production `PAYLOAD_SECRET` shorter than 32 characters (the site would stop at `assertEnv`) | Before deploying 1.16.4, check the length in Coolify (`node -e 'console.log(process.env.PAYLOAD_SECRET.length)'`). Shorter: a random 32+ character secret (logs everyone out, asks for 2FA again, breaks stored API keys), or `ipalEnvRules({ secretMinLength: 0 })` for now | CHANGELOG 1.16.4, deployment.md "PAYLOAD_SECRET — length and changing it" | | 67 | **1.16.5 — security** — with 2FA on, `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` sends the user to example.com after the code (and `back=javascript:…` runs script in the panel) | Upgrade and, **in ONE deploy**, `pnpm payload generate:importmap` (adds `@intecion/ipal-kit/admin#SafeTotpView`), commit `importMap.js`, `rm -rf .next`, redeploy on Coolify — with the old map the 2FA screens have no code form and nobody can sign in (run `pnpm exec ipal-doctor` before deploying; the start log says so too); check: the link above ends on `/admin`. `pnpm ipal:skills`. No option, env or migration; off / own rule: `twoFactor.safeBack` | CHANGELOG 1.16.5, security.md "The `back` link of the 2FA screens" | | 68 | **1.16.6 — 2FA setup required** (not a routine patch: a new default that can lock accounts out) — an account that has not set 2FA up still reads data over the API with its password; or after the upgrade an account "can do nothing" / is blocked | Before upgrading: `ipal-doctor --url` → accounts without 2FA set it up or are removed; one admin (better two) must have 2FA; deploy day agreed with the owner. Then, in ONE deploy: update, `generate:types`, `generate:importmap` (`TwoFactorStatusField`, `TwoFactorAlert`), **Postgres/SQLite: `migrate:create` and the migration applied in the same deploy when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, never a pre-deployment command (deployment.md §4.3) — (column `totp_setup_from`); without it every login answers 500**, build, redeploy. Existing accounts get 72 h from the first start; blocked later → admin: account page → "Reopen setup". Password-login integrations: API key or `requireSetup.exempt`. `pnpm ipal:skills` | CHANGELOG 1.16.6, security.md "Setup required" | -| 69 | **Unreleased — hardening (M1)** — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters."; or "Enter the password again…" on the SMTP password; or `403` "Not allowed from this origin." on the 2FA code | Update, `generate:types`, redeploy; no import map, schema or migration. Every slug in `access.staffCollections` must be an auth collection (otherwise Payload does not start: `/api/health` 503, the old container keeps serving). Set `serverURL` (a proxy that rewrites `Host` otherwise blocks the 2FA code; the log names the origin). Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without rules: an admin (update: or the account itself; roles only by an admin; read by staff only) where the roles are the plugin's, accounts of that collection where they are the project's own — write that collection's own rules. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG "Unreleased — hardening", access.md "Account rules", security.md "Stored secrets", turnstile.md | +| 69 | **1.16.7 — hardening** (not a routine patch: stricter defaults) — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters."; or "Enter the password again…" on the SMTP password; or `403` "Not allowed from this origin." on the 2FA code | Update, `generate:types`, redeploy; no import map, schema or migration. Every slug in `access.staffCollections` must be an auth collection (otherwise Payload does not start: `/api/health` 503, the old container keeps serving). Set `serverURL` (a proxy that rewrites `Host` otherwise blocks the 2FA code; the log names the origin). Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without rules: an admin (update: or the account itself; roles only by an admin; read by staff only) where the roles are the plugin's, accounts of that collection where they are the project's own — write that collection's own rules. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG 1.16.7, access.md "Account rules", security.md "Stored secrets", turnstile.md | +| 70 | **1.16.7** — `next build --webpack`: `'server-only' cannot be imported from a Client Component module`, from a `'use client'` file that imports `isAdmin`, `isEditor` or `hasMinimumRole` | Import them from `@intecion/ipal-kit/client` in client components, keep the second argument (`isAdmin(user, config)`); `import type` may stay on the main entry | CHANGELOG 1.16.7, access.md | After updating the package: `pnpm ipal:skills` (new skill versions), `pnpm payload generate:importmap`, `rm -rf .next`, restart dev, grep for the new symbol in `node_modules/@intecion/ipal-kit/dist`. diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index e866e00..81483c5 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -37,7 +37,7 @@ through this procedure. Ask only when you are missing something you cannot get y | the 2FA code screen answers "Too many codes were tried…" (`429` from `/api/verify-totp`) | more than 5 verify attempts for that account in 10 minutes (`twoFactor.verifyLimit`); repeated lines `[ipal] 2FA: too many verify attempts` in the log without the owner trying = someone has the password | wait for the window, enter the current code once; unexplained attempts: change that account's password. Tests that log in often: `verifyLimit: { max: … }` for that environment | | `isAdmin(req.user)` says `false` for a real administrator on the server, in a process that loads two Payload configs (tests, a multi-site script) | a call without a source counts only collections that are staff in **every** config of the process | pass the source: `isAdmin(req.user, req.payload)` — with it each config gets its own answer | | `isAdmin(user)` / `isEditor(user)` is always `false` in a client component or in `proxy.ts` | the staff collections are not known there (no config in the browser bundle / middleware), and the predicates fail closed | `isAdmin(user, config)` with `useConfig()`, imported from `@intecion/ipal-kit/client`; in middleware `isAdmin(user, { staffCollections: ['users'] })` | -| `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there after 1.16.6; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component | +| `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there since 1.16.7; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component | | an account logs in but every page and request answers 403 / the setup screen says "The time to set up two-step verification has passed" | 2FA setup required: the account did not set TOTP up within the window (72 h from its creation, an admin's reset, or the first start after the upgrade) | an administrator opens the account in the panel → Two-step verification → "Reopen setup" (or `POST /api/ipal/two-factor/reset` `{ userId }`); every administrator is blocked: security.md "Every administrator is blocked" — a script with the Local API, `payload.update({ collection: 'users', id, data: { totpSetupFrom: new Date().toISOString() } })` (`pnpm payload run`), then log in and set TOTP up; or `requireSetup: { windowHours: false }`, redeploy, set up, put it back | | a new account gets `403` from the API although its role allows the request | 2FA setup required: until TOTP is set up the account reaches only the setup screen | set TOTP up (log in to the panel); an integration: use an API key, or `twoFactor.requireSetup.exempt` | | after an upgrade EVERY panel login answers `500` (also `/api/users/init`), administrators with 2FA included; log: `[ipal] 2FA: the column for "totpSetupFrom" is missing … NOBODY CAN LOG IN` or `column users.totp_setup_from does not exist` | Postgres/SQLite: the migration that adds the 2FA column has not run (needed whenever 2FA is on) | `pnpm payload migrate:create` if no migration has it, commit, and redeploy with migrations run when the new container starts — `prodMigrations` in the adapter or the start command `pnpm payload migrate && pnpm start` (deployment.md §4.3; not Coolify's Pre-deployment command, which runs in the old container); nothing is lost. `ipal-doctor` reports a project whose migrations lack `totp_setup_from` | diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index 063174a..8adba70 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -351,7 +351,7 @@ for every site:** `grep -rnE "isAdmin\(|isEditor\(|hasMinimumRole\(" src` — a call in a **client component** or in `proxy.ts` / middleware now returns `false` without a source: `isAdmin(user, config)` (`useConfig()`), or `isAdmin(user, { staffCollections: ['users'] })`. A **client component imports them from - `@intecion/ipal-kit/client`** (not in 1.16.4–1.16.6: go to the next version); the main entry there fails with + `@intecion/ipal-kit/client`** (not in 1.16.4–1.16.6: go to 1.16.7); the main entry there fails with `next build --webpack` (`'server-only' cannot be imported from a Client Component module`). 4. `pnpm exec ipal-doctor --url ` (with the doctor token) → accounts without 2FA must be 0. An account that has not set TOTP up opens everything with its password alone: have its owner set it up now, or remove it. @@ -423,7 +423,7 @@ site without steps 1–3 and a deploy day agreed with the owner. Steps 2, 3 and setup screen with "Set up two-step verification by …"; after the code it is in. As an administrator open that account → "Two-step verification: Set up." and the reset button; delete the account. -**→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** +**→ 1.16.7 (hardening; CHANGELOG 1.16.7; PROGRAMISTA §6, item 69) — not a routine patch: agree the deploy with the owner, read every point, most sites change nothing:** 1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, **no schema change and no migration** on any database (the verify count uses Payload's own `payload-kv` collection). `grep -n "staffCollections\|authCollection" src/payload.config.ts`: every slug there must be an @@ -489,6 +489,9 @@ account → "Two-step verification: Set up." and the reset button; delete the ac 9. **Dashboard alerts.** Editors now see "An integration needs attention. Ask an administrator." instead of the error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it (`'all'` checks no role and no second factor). +10. **Role checks in client components.** `grep -rlE "^['\"]use client" src | xargs grep -nE "from '@intecion/ipal-kit'"` + — a file that imports `isAdmin`, `isEditor` or `hasMinimumRole` there: change the import to + `@intecion/ipal-kit/client` and keep the second argument (`isAdmin(user, config)`). `import type` may stay. **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, `staff-accounts-open`, `staff-own-roles`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. diff --git a/reference/AGENTS.md b/reference/AGENTS.md index ad84691..50d755b 100644 --- a/reference/AGENTS.md +++ b/reference/AGENTS.md @@ -47,7 +47,7 @@ Write everything in this file in English. -## ipal-kit 1.16.6 — agent guide +## ipal-kit 1.16.7 — agent guide This project is built on `@intecion/ipal-kit` (a Payload CMS 3 plugin). Before you write code: