- Q3: the integration status (emailStatus, turnstileStatus) is written alone through the database adapter (writeGlobalFields, exported): a visitor's form submit no longer puts back an admin's SMTP or Turnstile change saved at the same moment. addToCookieList reads the list again right before writing and works the change out again when an editor's save changed it (up to 5 times). Both races reproduced exactly in test/statusWrites.test.ts, on the three adapters. - Q4: cookieScanner.access and the doctor's access go through accessAllowed: any truthy answer still allows, an answer that is not a boolean is reported once per option; strict (only true) is announced for 1.19.0. - Q5: related documents that are drafts are left out of what the public helpers answer (resolveRoute, getSettings, getArchiveEntries, the 404 page, llms-full; Markdown and MCP through resolveRoute): null alone, removed from a list, value null in a polymorphic one. A preview keeps them; draftRelations: 'keep' keeps the old behaviour. withoutDraftRelations, applyDraftRelations exported. - Docs: content.md, frontend.md, integrations.md, cookie-scanner.md, security.md, AGENT.md; iapl-nav and iapl-doctor skills. Co-Authored-By: Claude Opus 5.5 <[email protected]>
99 lines
6.7 KiB
Markdown
99 lines
6.7 KiB
Markdown
# integrations — the Site integrations global and integration status in the admin panel
|
||
|
||
External service keys edited in the admin panel, plus a notice for the editor when one of them
|
||
stops working — no crons, no polling: the server records the status when it actually uses an integration.
|
||
|
||
Related: [email.md](./email.md) (the mail service, SMTP, Graph), [turnstile.md](./turnstile.md),
|
||
[analytics.md](./analytics.md), [seo.md](./seo.md) (IndexNow), [deployment.md](./deployment.md).
|
||
|
||
## The `site-integrations` global (panel: Settings → Site integrations)
|
||
|
||
Currently always added by the plugin. Tabs (unnamed — flat data, e.g. `ga4MeasurementId`):
|
||
|
||
| Tab | Fields |
|
||
|---|---|
|
||
| Analytics | `ga4MeasurementId`, `gtmContainerId`, `metaPixelId`, `clarityProjectId`, `linkedInPartnerId`, `tiktokPixelId` |
|
||
| Spam protection | `turnstileSiteKey`, `turnstileSecretKey`, hidden `turnstileStatus` + banner |
|
||
| E-mail sending | the state block "How e-mails are sent" (part of the tab's status banner — nothing stored; absent with `mail: { relay: false }`), "Sending method" `emailMethod` (`relay` = IWSN / `smtp` / `graph` = deprecated; empty until somebody chooses, a read shows the method in effect; new in 1.17.1 — a column on Postgres / SQLite), `emailTransport` (hidden; the stored field of 1.6 – 1.17.0), `smtpHost`, `smtpPort`, `smtpUser`, `smtpPassword`, `smtpFromAddress`, `smtpFromName`, test button, hidden `emailStatus` + banner |
|
||
| IndexNow | `indexNowKey` (generated on first save) |
|
||
| More | fields from the `integrationsFields` option — only when given |
|
||
|
||
Access: read and write only for the `admin` role (secrets) — anonymous users and editors get nothing
|
||
over REST/GraphQL. On the server, read through the Local API:
|
||
|
||
```ts
|
||
import { getSiteIntegrations } from '@intecion/ipal-kit'
|
||
const integrations = await getSiteIntegrations<SiteIntegration>(payload) // overrideAccess — do not send the whole thing to the browser
|
||
```
|
||
|
||
The "Send test" button (E-mail sending tab) calls `POST /api/ipal/test-email` (endpoint currently always added).
|
||
The state block above it reads `GET /api/iapl/mail-relay/status` and acts through `POST …/connect` and
|
||
`POST …/disconnect` (admin only; [email.md](./email.md) "The state block in the panel").
|
||
|
||
## Integration status — dashboard alert and tab banner
|
||
|
||
- **Write:** `mailAdapter()` on every send (`emailStatus`) and Turnstile verification on a
|
||
form (`turnstileStatus`) call `recordIntegrationStatus`. It writes only when the state changes,
|
||
or at most every 10 min while an error lasts; it never throws. The same change already being written (many sends
|
||
failing at once) is written once; while every transaction place of a Postgres pool is taken
|
||
([deployment.md](./deployment.md) §4.3a) the write goes on in the background instead of holding the caller.
|
||
- **The status is written alone (1.18.0).** `updateGlobal` reads the whole document, merges and writes it whole: a
|
||
status written after a visitor's form submit put back an admin's SMTP or Turnstile change saved in the same
|
||
moment. The status field is now written through the database adapter on its own (`writeGlobalFields(payload,
|
||
slug, data)`, exported): no read of the rest, no hooks, no new version (fit for bookkeeping fields only). A global
|
||
that does not exist yet is created the usual way.
|
||
- **Changing keys in the admin panel** (Turnstile, the sending method / `smtp*`) clears that integration's old status.
|
||
- **`emailStatus.code`** of a send through the Intecion mail service is one of the `relay-…` codes (`relay-pending`,
|
||
`relay-quota`, `relay-unreachable`, …), each with a text in the editor's language — the list and what to do:
|
||
[email.md](./email.md) "Status codes". The token of the mail service is **not** in this global: it lives in
|
||
`payload-kv` and no route answers with it.
|
||
- **`IntegrationAlerts`** (`@intecion/ipal-kit/admin`) — the plugin always wires it into
|
||
`admin.components.beforeDashboard`: a list of integrations in the `degraded` state + Turnstile key
|
||
problems + an "Open Site integrations" link (from `adminRoute`). When everything works it renders nothing.
|
||
- **`IntegrationStatusBanner`** (`/admin`) — a banner on the tab: red on error (message,
|
||
code, since when), a green line after a fix, nothing before first use.
|
||
|
||
## Building blocks for your own integrations
|
||
|
||
The same mechanism for project integrations (fields via `integrationsFields`):
|
||
|
||
```ts
|
||
import { buildIntegrationStatusBanner, buildIntegrationStatusField, recordIntegrationStatus } from '@intecion/ipal-kit'
|
||
|
||
iapl({
|
||
integrationsFields: [
|
||
// UI field `crmStatusBanner`; label as a string or { en, pl }; optional third argument
|
||
// { failing, hint } = keys of your own texts in i18n.translations.<lang>.ipal
|
||
buildIntegrationStatusBanner('crmStatus', { en: 'CRM', pl: 'CRM' }),
|
||
{ name: 'crmApiKey', type: 'text' },
|
||
buildIntegrationStatusField('crmStatus'), // hidden group: state, code, message, since, checkedAt
|
||
],
|
||
})
|
||
|
||
// after calling the CRM (previous = the current crmStatus from getSiteIntegrations)
|
||
await recordIntegrationStatus(payload, 'crmStatus', previous, { state: 'degraded', code: 'http-500', message: 'CRM is down' })
|
||
await recordIntegrationStatus(payload, 'crmStatus', previous, { state: 'ok' })
|
||
```
|
||
|
||
After adding the banner: `pnpm payload generate:importmap`; Postgres: `migrate:create`.
|
||
|
||
Types: `IntegrationState` (`'ok' | 'degraded'`), `IntegrationStatus`, `IntegrationLabel`
|
||
(`string | { en, pl }`), `IntegrationBannerTexts` (`{ failing, hint }` — text keys). Without
|
||
texts the banner says "{label} is not working."; the plugin's own banners use
|
||
`statusEmailFailing` / `statusEmailHint` and `statusTurnstileFailing` / `statusTurnstileHint`
|
||
(override per language in `i18n.translations.<lang>.ipal`, see i18n.md "Admin panel languages and texts").
|
||
The dashboard `IntegrationAlerts` checks only `emailStatus` and `turnstileStatus` by default
|
||
(prop `checks`, labels as strings or `{ en, pl }`) — to show your own integration, wire a second
|
||
`IntegrationAlerts` with `checks: { crmStatus: 'CRM' }` into `beforeDashboard`.
|
||
|
||
## Turn off / override
|
||
|
||
- The mail service's state block and its four routes: `iapl({ mail: { relay: false } })`.
|
||
- The `site-integrations` global, the `/api/ipal/test-email` endpoint and `IntegrationAlerts` on the dashboard
|
||
are **currently always added** — there is no option to turn them off. Workaround: a project plugin
|
||
wired after `iapl()` that removes / replaces the entry in `config.globals`, `config.endpoints` or
|
||
`admin.components.beforeDashboard`.
|
||
- Extension: `integrationsFields` (the *More* tab). Access, hooks, labels and tabs: override with
|
||
`iapl({ globalOverrides: { 'site-integrations': … } })` (an object merges `access` / `admin` / `hooks`,
|
||
a function gets the whole global — hooks.md).
|