WIP: sending method as an explicit choice, kept in payload-kv (superseded: the choice moves to a stored field)

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 22:30:03 +01:00
co-authored by Claude Fable 5.2
parent 68a2555277
commit c6841a1674
34 changed files with 740 additions and 96 deletions
+17 -6
View File
@@ -1257,7 +1257,7 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
| Sitemap split / CDN cache / memo | `sitemapOptions: { maxUrls: Infinity, cacheControl: false, memoSeconds: 0 }` | `sitemapEntries`, `createSitemapRouteHandler`, `buildSitemapIndexXml`, `buildSitemapEntries` |
| Sitemap error = 503 + `Retry-After` | — (correct HTTP behaviour) | your own route with `buildSitemapXml` |
| IndexNow silent with `IAPL_NOINDEX` | `indexNow` off by default | `submitToIndexNow` by hand |
| A site with no SMTP server in the panel sends through the Intecion mail service: it enrols by itself on its first send (an outbound call with its host and the plugin version) and gets its own token through the public route `POST /api/iapl/mail-relay/confirm` | `mail: { relay: false }` (no call, no routes, no state block) | `mail.relay: { url, host, enrol, token, senderName, kind, accountMail, confirmRateLimit, timeoutMs, retryBackoffMs, fetchImpl }`; `mailAdapter({ relay })`; §7.2 |
| A site sends through the Intecion mail service unless an admin chose another "Sending method" (SMTP, Graph): it enrols by itself on its first send (an outbound call with its host and the plugin version) and gets its own token through the public route `POST /api/iapl/mail-relay/confirm` | `mail: { relay: false }` (no call, no routes, no state block) | `mail.relay: { url, host, enrol, token, senderName, kind, accountMail, confirmRateLimit, timeoutMs, retryBackoffMs, fetchImpl }`; `mailAdapter({ relay })`; §7.2 |
| The mail service's token is kept in `payload.kv` (never in a field, never readable over REST or GraphQL), bound to the site's server addresses, rotated every 90 days | "Disconnect" in the panel; `disconnectRelay` | `enrolRelay`, `rotateRelayToken`, `setRelayToken`, `getRelayStatus` |
| Account e-mails through the mail service: at most 5 to one address and 10 asked for by one visitor an hour | `mail: { relay: { accountMail: false } }` | `accountMail: { perAddress, perVisitor, windowMinutes }` |
| Every message says what it is (form notification, form confirmation, account, test, system) | — (other transports ignore the mark) | `withMailKind`, `runWithMailKind`, `expectMailTo`, `mail.relay.kind`, `buildFormMailKindHook` |
@@ -1289,9 +1289,20 @@ No env variable, no key, no field to fill in, no import-map change (the tab's st
banner that is already in every import map). **Do not** add `nodemailer`, `resend`, an `api/send` route or a
`GRAPH_*` variable to a project.
**How a send is routed** (`resolveMailTransport`, type `MailTransport`): Microsoft Graph when the panel says so and
`GRAPH_*` is set (deprecated) → SMTP when server, user name and password are filled in → Graph when `GRAPH_*` is set →
the mail service → nothing (`mail: { relay: false }` and no SMTP). A site with SMTP filled in never contacts the service.
**How a send is routed** — by the admin's choice, Site integrations → E-mail sending → **"Sending method"**: "IWSN
(built-in)" (the mail service), "Own SMTP server", "Microsoft Graph (deprecated)". What is chosen is what is used;
a choice that cannot be used (SMTP incomplete, Graph without `GRAPH_*`) **fails loudly and nothing is sent another
way** (state block, status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method`). The choice is kept in
`payload-kv` (`MAIL_METHOD_KV_KEY`); the panel's field `emailMethod` is virtual, so **no schema change and no
migration**. Until somebody chooses (an upgraded site, a new site) the order of 1.17.0 applies and the field shows
its result as selected (`resolveMailTransport`, type `MailTransport`): Graph when `emailTransport` is `graph` and
`GRAPH_*` is set → SMTP when server, user name and password are filled in → Graph when `GRAPH_*` is set → the mail
service → nothing. The first save of Site integrations stores the choice. From code: `getMailMethod`,
`setMailMethod(payload, 'relay' | 'smtp' | 'graph' | null)`, `resolveMailMethod` (`ResolvedMailMethod`,
`MailMethodProblem`), `MailMethod`, `MAIL_METHODS`, `isMailMethod`; or `updateGlobal` with `emailMethod`. Seeds that
set up mail write `emailMethod`, not `emailTransport`. **Verify:** the state block names the method; **Send test
e-mail** answers "through IWSN" / "through your SMTP server" / "through Microsoft Graph"; `iapl-doctor --deep`
reports no `mail-method` finding after the first save. `mail: { relay: false }` removes the option "IWSN".
**What the site needs for the mail service** — check each one:
@@ -1324,8 +1335,8 @@ the mail service → nothing (`mail: { relay: false }` and no SMTP). A site with
--deep --url <site>` reports no `mail-*` finding. On `localhost` the plugin refuses to enrol (nothing leaves the machine): test
mail locally with SMTP (Mailpit) or `createFakeRelay()`.
**The client wants its own mail server:** fill in "Own SMTP server", user name, password and "Sender address" in the
panel, send a test. Nothing in code. **A site on `GRAPH_*`:** keeps working, warns once per start; move it when the
**The client wants its own mail server:** "Sending method" → "Own SMTP server", fill in server, user name, password
and "Sender address", save, send a test. Nothing in code. **A site on `GRAPH_*`:** keeps working, warns once per start; move it when the
owner says so (email.md "Moving off Microsoft Graph").
**Your own mail** goes through `payload.sendEmail`. Say what it is when it is not a generic system message:
+1 -1
View File
@@ -1244,7 +1244,7 @@ const payload = await getPayload({ config })
await payload.updateGlobal({
slug: 'site-integrations',
context: { ipalIntegrationStatus: true },
data: { emailStatus: { checkedAt: null, code: null, message: null, since: null, state: null }, emailTransport: 'smtp', smtpFromAddress: 'site@example-studio.test', smtpFromName: 'Example Studio', smtpHost: null, smtpPassword: null, smtpUser: null } as never,
data: { emailStatus: { checkedAt: null, code: null, message: null, since: null, state: null }, emailMethod: 'relay', emailTransport: 'smtp', smtpFromAddress: 'site@example-studio.test', smtpFromName: 'Example Studio', smtpHost: null, smtpPassword: null, smtpUser: null } as never,
overrideAccess: true,
})
for (const key of await payload.kv.keys()) {
+2
View File
@@ -100,6 +100,8 @@ through this procedure. Ask only when you are missing something you cannot get y
| pixel before consent (consent-check) | script wired by hand (`<Script>`) | only through the panel → `<Analytics>` (GA/GTM/pixels) or `<ConsentScript>` (analytics.md, consent.md) |
| banner without styles | Tailwind does not scan the plugin | `@source` on `node_modules/@intecion/ipal-kit/dist/**/*.js` (path relative to the CSS file, PROGRAMISTA §2.5) |
| emails are not sent | no `email: mailAdapter()` / empty Emails tab of the form / the transport fails | Site integrations → E-mail sending: read the block "How e-mails are sent" and the banner's code, then **Send test e-mail**; rows below; email.md |
| e-mails are not sent; state block: "Your SMTP server is chosen, but its settings are incomplete" / "Microsoft Graph is chosen, but it is not set up on this server" (status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method` error) | the chosen "Sending method" cannot be used, and since 1.17.1 nothing is sent another way | fill in server, user name and password / set the `GRAPH_*` variables — or choose another method (IWSN needs nothing) and save |
| the site switched how it sends after a field or a variable changed | nobody has chosen the "Sending method" yet (doctor `mail-method` info): the site still picks by the order of 1.17.0 | Site integrations → E-mail sending: check the method shown, save |
| state block: "Not connected yet" on the production domain | no e-mail was sent yet | **Send test e-mail** (the site enrols on its first send) or "Connect again" |
| `relay-refused` / "The mail service could not reach this site at …" (cause `callback-failed`) | `unreachable` / `timeout`: firewall, private network, wrong public host in `serverURL`; `redirect`: `trailingSlash: true`, apex → `www`, a language redirect; `status`: route blocked, missing (`mail: { relay: false }`?) or another `routes.api`; `confirmation`: a proxy rewrites the answer | `curl -i -X POST https://<host>/api/iapl/mail-relay/confirm -d '{}' -H 'content-type: application/json'` must answer **404 with an empty body, no redirect**; fix `serverURL` / `mail.relay.host`, or ask Intecion to set the site's confirm address (path ending in `/confirm/` with trailing slashes); then "Connect again" (the site does not retry by itself for 15 min). email.md "When the site cannot be confirmed" |
| `relay-refused`, cause `host-not-allowed` / "This site has no public address yet" | the site runs on `localhost`, a private name, or `serverURL` is empty | expected in development (use SMTP / Mailpit there); in production set `serverURL` |
@@ -39,6 +39,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api/<slug>/first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour |
| `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) |
| `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before |
| "Sending method" (`emailMethod`, virtual; `getMailMethod` / `setMailMethod`) | nobody has chosen: the order of 1.17.0, shown as selected | `relay` (IWSN), `smtp`, `graph` (deprecated): what is chosen is what is used, no fallback; kept in `payload-kv`, no schema change |
| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server |
| `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) |
| `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)/<route>/` itself and adds the route to the proxy matcher (security.md) |
+2 -2
View File
@@ -660,8 +660,8 @@ scaling (5). `●` routes for pages need the database at build time (PROGRAMISTA
in every language.
6. **Notifications**: form messages in every language.
7. **Site integrations → E-mail sending**: "Sender name" (the client's name; empty = the site name) and **"Sender
address"** (the client's address: with the mail service replies go there). SMTP fields **only** when the client asked
for its own server. On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), then **Send test e-mail** → "through IWSN". Turnstile (for testing site
address"** (the client's address: with the mail service replies go there). "Sending method" stays **IWSN (built-in)**; choose **Own SMTP server** and fill in its fields **only** when the client asked
for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. Save the tab once so the choice is stored. On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), then **Send test e-mail** → "through IWSN". Turnstile (for testing site
`1x00000000000000000000AA`, secret `1x0000000000000000000000000000000AA`; production keys from the client), analytics/pixel
IDs, IndexNow → generate key. Mail/Turnstile errors show up as a dashboard alert.
8. **Forms**: check the addresses in the Emails tab of the seeded forms.
+13
View File
@@ -672,6 +672,19 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re
**Send test e-mail** names the transport you expect; a form submission arrives. **The service is live at
`https://webservices.intecion.net/mail`; while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — keep SMTP until it is approved, or `relay: false`.**
**→ 1.17.1, e-mail (CHANGELOG 1.17.1 point 5; email.md "Which transport a send takes"; AGENT.md §7.2) — nothing to run, one check:**
1. No schema change, no migration, no import-map change; `pnpm payload generate:types` gives a diff (the virtual field
`emailMethod`): run it and commit.
2. After the deploy open Site integrations → E-mail sending. "Sending method" shows the method the site sends through
today as selected: **IWSN (built-in)** (no SMTP server), **Own SMTP server**, or **Microsoft Graph (deprecated)**
(`GRAPH_*` on the server). Check it is the one meant, **save**, send a test e-mail: the answer names the method.
Until that save the site keeps the order of 1.17.0 and `iapl-doctor --deep` notes it (`mail-method`, info).
3. From the save on what is chosen is what is used: "Own SMTP server" with an incomplete server, or "Microsoft Graph"
without `GRAPH_*`, sends **nothing** and says so (state block, `mail-method` error) — no fallback to another method.
Tell the owner before changing the method on a live site.
4. Seeds and scripts that set up mail: write `emailMethod: 'relay' | 'smtp' | 'graph'` (or `setMailMethod(payload, …)`).
`emailTransport` written alone still works and means the old order.
**→ 1.17.1, the sign-in look (CHANGELOG 1.17.1; PROGRAMISTA §6, item 80; white-label.md → "The sign-in screens") — nothing is required:**
1. **Sites with `whiteLabel`:** after the update the login screen and the 2FA screens (code, setup) have the new
look — a dark panel with the client's logo or the site's name beside the form. No edit, no