From 2c0262367d000cd90e0c3c1ce8a582a68c7c2ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Tue, 1 Dec 2026 21:42:23 +0100 Subject: [PATCH 1/3] =?UTF-8?q?IWSN:=20"Po=C5=82=C4=85cz=20z=20IWSN"=20?= =?UTF-8?q?=E2=80=94=20a=20person=20of=20Intecion=20connects=20the=20site?= =?UTF-8?q?=20(contract=201.8.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - the state block on the e-mail tab (method IWSN): the button while the service offers the confirmation page (connectAvailable) or before the site has enrolled; a click asks the site's server for the link (POST /api/iapl/mail-relay/connect-link, admin only), which asks the service (POST /v1/connect, enrolling first), checks that it begins with the service's own {base}/connect?, and hands it over without storing or logging it; the browser opens it in a new tab with noopener noreferrer; the block asks /v1/status every 5 s for 10 min - states: waiting for confirmation (button), waiting for approval (no page), connected, stopped; 503 connect-unavailable and 429 said in the admin's language; a load of the panel asks the service while the site waits - dashboard alert for a waiting site (live); doctor mail-relay-connect (error) — replaces the pending warning and the "not enrolled yet" note of mail-relay-state - opt-out mail.relay.connectButton: false (no button, no route); building blocks requestRelayConnectLink, isRelayConnectUrl, RELAY_CONNECT_LINK_PATH; the fake service implements /v1/connect, connectAvailable and confirmConnect - contract copy 1.8.0 (IWDL working tree, checksums match); docs, AGENT.md, setup / upgrade / debug skills, changelog Co-Authored-By: Claude Opus 5.5 --- contracts/mail-relay/CHANGELOG.md | 21 +++ contracts/mail-relay/CHECKSUMS | 15 +- contracts/mail-relay/README.md | 74 ++++++++- contracts/mail-relay/VERSION | 2 +- .../mail-relay/examples/connect-active.json | 31 ++++ .../mail-relay/examples/connect-pending.json | 31 ++++ .../examples/connect-suspended.json | 32 ++++ .../examples/connect-unavailable.json | 33 ++++ .../examples/status-pending-connect.json | 29 ++++ contracts/mail-relay/runner.mjs | 2 +- contracts/mail-relay/schema.json | 64 +++++++- docs/CHANGELOG.md | 29 ++++ docs/agent/AGENT.md | 10 +- docs/agent/skills/iapl-debug/SKILL.md | 2 +- docs/agent/skills/iapl-setup/SKILL.md | 2 +- docs/agent/skills/iapl-upgrade/SKILL.md | 13 +- docs/doctor.md | 3 +- docs/email.md | 48 ++++-- reference/.agents/skills/iapl-debug/SKILL.md | 2 +- reference/.agents/skills/iapl-setup/SKILL.md | 2 +- .../.agents/skills/iapl-upgrade/SKILL.md | 13 +- reference/e2e/mail-relay.spec.ts | 35 ++++ .../components/MailRelayStatus.tsx | 83 +++++++++- src/index.ts | 4 + src/modules/admin-i18n/texts/integrations.ts | 26 ++- src/modules/doctor/rules/mail.ts | 28 +++- src/modules/doctor/status.ts | 1 + src/modules/doctor/types.ts | 2 + src/modules/email/relay/constants.ts | 4 +- src/modules/email/relay/fake.ts | 52 +++++- src/modules/email/relay/index.ts | 13 +- src/modules/email/relay/options.ts | 7 + src/modules/email/relay/panel.ts | 55 ++++++- src/modules/email/relay/session.ts | 56 +++++++ src/modules/email/relay/store.ts | 2 + .../integrations/IntegrationAlerts.tsx | 13 ++ src/plugin.ts | 2 +- test/doctor.test.ts | 23 ++- test/mailRelayConnect.test.ts | 150 +++++++++++++++++ test/mailRelayConnectHttp.test.ts | 155 ++++++++++++++++++ test/mailRelayContract.test.ts | 1 + 41 files changed, 1113 insertions(+), 57 deletions(-) create mode 100644 contracts/mail-relay/examples/connect-active.json create mode 100644 contracts/mail-relay/examples/connect-pending.json create mode 100644 contracts/mail-relay/examples/connect-suspended.json create mode 100644 contracts/mail-relay/examples/connect-unavailable.json create mode 100644 contracts/mail-relay/examples/status-pending-connect.json create mode 100644 test/mailRelayConnect.test.ts create mode 100644 test/mailRelayConnectHttp.test.ts diff --git a/contracts/mail-relay/CHANGELOG.md b/contracts/mail-relay/CHANGELOG.md index 067232b..2abcf29 100644 --- a/contracts/mail-relay/CHANGELOG.md +++ b/contracts/mail-relay/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog of the wire contract +## 1.8.0 — 2026-12-01 (not released; no tag yet) + +A site is confirmed by a person of Intecion on the service's own page (§2.1). Additive: a client of 1.7 keeps +working — its sites enrol, are `pending`, and get `403 site-pending` until an operator confirms them by hand. +**Client: to let its own administrator start the confirmation, add what is marked.** + +- **New route `POST /v1/connect`** (token and `X-Intecion-Site`, no body). For a pending site it answers + `{ ok, state: "pending", connectUrl, expiresAt }` — a link valid 15 minutes, for one confirmation, each call + replacing the earlier link; for an active site `{ ok, state: "active" }`. **Client: a panel button that asks + for the link from the server on the click and opens `connectUrl` in a new tab** (after checking that it + begins with the service's base address and `/connect?`). Schema `ConnectResponse`. +- **New code `503 connect-unavailable`** (not retryable): no confirmation page is set up. **Client: show "ask + Intecion to confirm this site".** +- **`/v1/status` of a pending site may carry `connectAvailable: true`.** **Client: show the button only then.** +- **How a site learns that it was confirmed:** it asks `/v1/status` (at most every 5 seconds for at most 10 + minutes while the panel that opened the link is open, and on every panel load), or it simply sends. The + service does not call the site. **Client: add the polling.** +- `site-pending` now reads "not yet confirmed by Intecion"; its handling is unchanged. +- Examples: `connect-pending`, `connect-active`, `connect-suspended`, `connect-unavailable`, + `status-pending-connect`; `given.connect`. + ## 1.7.1 — 2026-11-25 (not released; no tag yet) Wording only; nothing for a client to change, and a copy of 1.7.0 need not be refreshed for it. diff --git a/contracts/mail-relay/CHECKSUMS b/contracts/mail-relay/CHECKSUMS index ab7b170..a21c6d0 100644 --- a/contracts/mail-relay/CHECKSUMS +++ b/contracts/mail-relay/CHECKSUMS @@ -1,12 +1,16 @@ -3d5c4b7ed53fe6fe2c7c28826c0cf666f9c1d0b79f861b404503e7029728a61f README.md -53da77d5dfff9948d68fca26b828563e21f83418245053d78b03a5aecac6c1d1 CHANGELOG.md -249182a01164b81a5f7af87e5c5cdbd3344a80a7a66dfca624cecfb1501b2420 VERSION -2ff0ad5b6a245365c0fa8733fa17b7bbd3ab91d4825981709d0fd02b762b939f schema.json -9d8381d2e3465e97dc801a61f598fcf822e27e73a2c0729877744ec307097910 runner.mjs +eabe3563e3ada8c4bb85ca03be33b259a38f80e49cc235603096e6efd74974a5 README.md +af76187dbaf87e9ad8de8bf75f1066ec2f3120fb8d1de34feb2028d67f478f92 CHANGELOG.md +3eb1ef94b5890ca727158b106142685c8733b0ace5bcb4cf3f0ac14f9f0643f4 VERSION +9d1e429d266561d4b4baddee5fa8526c7fbce93dad0f16c32fe6e0999b5c9475 schema.json +8a15b61b862fb01c8cb928ef202ba0bb14cf77cbce1fd1bfe32be6873d67989b runner.mjs 7c46860adee597e570832c72bcdb418752a20b9f7d1b2d7a656ed065f9632b2a checksums.mjs df6015faf02a7cf7e9b5816b9e22b2e82968678ddd72a61c1f9665a8c0897ddf examples/callback-confirm-wordpress.json f5018ca4fb7d25794ee92168d715aaf47feeba3d907c0550651b16c10a691ceb examples/callback-confirm.json 27bd95712cc36a71519cddc52c03d857b1009c2c384940dbc052022d86bc4231 examples/callback-unknown-nonce.json +4008be4ec65e46d6a43221e400acf8682162cb14d54c5d8a4ab20b49e9985821 examples/connect-active.json +9110ce20a6577b5884fa48a7ddb5d203f4671c863d56ef952a411907daaf45de examples/connect-pending.json +6658a53ffec104a45e00fe962801bdc1a2b47a3f9cb10647d5405e0ed0355fa6 examples/connect-suspended.json +394096063e2c135bb99622d4b37f65ad609cb276b610949fffdc26175cdb0dc9 examples/connect-unavailable.json de693b060c10c3d0f88fb8edfcd38c491cf141628d747328beee1b50c700c19b examples/enrol-address-literal.json 7c4cf75eb9ab156a3031336ab2688e7c9dcd4cd266b7b7e5e4592285dcbd25ba examples/enrol-callback-no-content.json 64466afc5bf0fecfa36f986d973cd987bbe1f64867e01cdf35e0de40838eb0d1 examples/enrol-callback-not-found.json @@ -60,5 +64,6 @@ ce4cbea2306f73bd5905249c10ab451a2599cb779e2386828971f40c97b8c591 examples/send- 28e05f3c53cab6433b6af4d425511fa6655d0673df2e840af1fed9d25294a123 examples/send-unknown-token.json f105c38ab11ab5fc508ba0ed3f23f69108c318765c2670029b230b5b9a83912a examples/status-active.json 89009ee9ab8f38e9ec290fb5412f206e1be28ad10fce6a7071d4406ac52dd4f0 examples/status-no-site-header.json +28eeab5dc50c26f452e438f5cceddf99635ee7b3897e44dfe4255eb49123cc0f examples/status-pending-connect.json c9f49fa0dae1f0beacaacfe01660b467d06f990228c35a653307c8793f3c97a5 examples/status-pending.json afdb07ba8279479b6bbfdc4289efda657d4e5a9eccd94b8de165ec728b4a2386 examples/status-unknown-address.json diff --git a/contracts/mail-relay/README.md b/contracts/mail-relay/README.md index cbd1ae5..b1aafbc 100644 --- a/contracts/mail-relay/README.md +++ b/contracts/mail-relay/README.md @@ -1,6 +1,6 @@ # Intecion Notifications Webservice — wire contract -Version: see [`VERSION`](VERSION) (this text describes **1.7.1**). Path prefix of this major version: `/v1`. +Version: see [`VERSION`](VERSION) (this text describes **1.8.0**). Path prefix of this major version: `/v1`. This is the whole agreement between the Intecion Notifications Webservice ("the service" below) and a client (the mail transport built into a site's plugin). It names no product: nothing here says Payload, WordPress, IAPL or IAWL except the values of @@ -63,7 +63,7 @@ Every refusal has the same body ([`Error`](schema.json)) — with one exception: | 400 | `invalid-request` | Body, header or field is wrong; `field` names it | no | Report a bug | — | | 401 | `invalid-token` | No token, or one the service does not know (unknown, expired, revoked) | no | Enrol again, then send once more (§2, "Which token") | — | | 401 | `reverify` | The token is good but comes from a server address the service has not seen for this site | no | Enrol again (the same call-back), then send once more | — | -| 403 | `site-pending` | Enrolled, waiting for approval by Intecion | no | Keep the token; show "waiting for approval" | `relay-pending` | +| 403 | `site-pending` | Enrolled, not yet confirmed by Intecion (§2.1) | no | Keep the token; show "waiting for confirmation" with the connect button (§2.1) | `relay-pending` | | 403 | `site-suspended` | Stopped by Intecion | no | Keep the token; show it; do not enrol again | `relay-suspended` | | 403 | `host-not-allowed` | Enrolment: the host is not a public DNS name | no | Show it (a local or private site cannot use the service) | `relay-refused` | | 403 | `enrolment-closed` | Enrolment is closed for this product, or altogether | no | Show it | `relay-refused` | @@ -85,6 +85,7 @@ Every refusal has the same body ([`Error`](schema.json)) — with one exception: | 429 | `quota-exceeded` | A limit of the site (`limit`: `hour`, `day`, `recipient`, `new-recipients`, `alerts`) or of the whole service (`service`) | no | Show it; the message is not sent | `relay-quota` | | 502 | `backend-failed` | The mail back end failed, or refused this message | **as `retryable` says** | Retry with the same key when `retryable` is true | `relay-unreachable` if it persists | | 503 | `unavailable` | The service cannot work right now | **as `retryable` says** | Retry when `retryable` is true | `relay-unreachable` if it persists | +| 503 | `connect-unavailable` | `/v1/connect` only: the service has no confirmation page set up right now | no | Show "ask Intecion to confirm this site"; do not retry by itself | `relay-pending` | | 500 | `internal` | A fault in the service | **yes** | Retry | `relay-unreachable` if it persists | A network error or a time-out is treated like `503`. The "suggested site status" column is advice, in the words @@ -240,6 +241,66 @@ Rules a client must know: site stores it the same way. - Use the token only from the site's server. Never print it, never send it to a browser. +### 2.1 Connecting a waiting site — `POST /v1/connect` (since 1.8.0) + +An enrolment proves that a site is served at its host; it does not prove that the site is Intecion's. Under the +service's `connect` policy every newly enrolled site is therefore **`pending`** and sends nothing +(`403 site-pending`) until a person of Intecion confirms it on the service's own page, signed in with an +`@intecion.com` address. The site's part is to hand that person the link: + +1. **The site enrols as always** (§2). The answer says `"state": "pending"`; the token is stored as always. +2. **An administrator of the site presses a button in the site's panel** ("Połącz z IWSN"). On that click — never + on page load, never by itself — the site's **server** calls + + ``` + POST /v1/connect + Authorization: Bearer ims_… + X-Intecion-Site: example.com + ``` + + with no body (or `{}`). If the site holds no token yet it enrols first, as before any other call. The answer + ([`ConnectResponse`](schema.json)): + + ```json + { "ok": true, "state": "pending", + "connectUrl": "https://webservices.intecion.net/mail/connect?ref=…", + "expiresAt": "2026-12-01T10:15:00.000Z" } + ``` + + | Answer | Meaning | The panel | + |---|---|---| + | `200`, `state: "pending"`, `connectUrl`, `expiresAt` | A link for this host, valid **15 minutes**, usable for **one** confirmation. Each call makes a new link and the earlier one stops working | Opens `connectUrl` in a **new browser tab** | + | `200`, `state: "active"` (no `connectUrl`) | The site is confirmed already | Shows "connected"; opens nothing | + | `403 site-suspended` | Stopped by Intecion | As everywhere | + | `503 connect-unavailable` | The service has no confirmation page right now | "Ask Intecion to confirm this site" (an operator can do it by hand) | + | `429 rate-limited` | More than 10 links for this site within an hour | Wait `retryAfter` | + | `401` / `403 host-mismatch` | As for every route with a token (§8) | Enrol again / forget the token, as there | + +3. **The browser opens `connectUrl`** as a top-level navigation in a new tab + (`target="_blank" rel="noopener noreferrer"`, or the equivalent after the click). The client + - takes the address from the answer as it is and adds nothing to it; + - opens it only if it begins with the service's base address followed by `/connect?` — anything else is a + fault, shown as such; + - never fetches it from the server, never puts it in a frame, never stores it and never writes it to a log. + It is not a secret — it authorises nothing by itself, the person's sign-in does — but it is of use only + for those fifteen minutes. +4. **On the service's page** the person signs in (Cloudflare Access: a one-time code sent to their + `@intecion.com` address), sees the host, and presses "Potwierdź". Nothing of this passes through the site. +5. **The site learns that it is active by asking** — the service never calls the site for this: + - `GET /v1/status` answers `"state": "active"`. While the panel that opened the link is open, the client + asks **at most every 5 seconds, for at most 10 minutes**, then stops and shows "not confirmed yet" with + the button again. It also asks whenever the panel is loaded. + - Or simply by sending: the first `/v1/send` after the confirmation is accepted. Mail refused with + `site-pending` before that was **not sent and is not kept by the service**; what a client does with it is + what it does for any refusal that is not retryable. + +**States a panel shows.** `pending` with `connectAvailable: true` in `/v1/status` (§4): "waiting for +confirmation" and the button. `pending` without it: "waiting for approval by Intecion", no button. `active`: +connected. `suspended`: stopped by Intecion. + +A pending site that nobody confirms is forgotten 14 days after it first enrolled; it then enrols again by itself +on its next send and is pending again. + ## 3. Sending — `POST /v1/send` Headers (`Bearer` in any case; one space; then the token exactly): @@ -360,7 +421,7 @@ not go out ([`StatusResponse`](schema.json)): ```json { "ok": true, "state": "active", "host": "example.com", "product": "iapl", - "service": { "name": "Intecion Notifications Webservice", "version": "1.0.0", "contract": "1.7.1" }, + "service": { "name": "Intecion Notifications Webservice", "version": "1.0.0", "contract": "1.8.0" }, "sender": { "address": "notification@webservices.intecion.net" }, "limits": { "messagesPerHour": 30, "messagesPerDay": 200, "recipientsPerMessage": 10, "perRecipientPerDay": 10, "newRecipientsPerDay": 50, @@ -372,6 +433,9 @@ not go out ([`StatusResponse`](schema.json)): A client takes its attachment limit from `limits.maxAttachmentBytes`, never from a constant of its own. +Since 1.8.0 the answer for a **pending** site may carry `"connectAvailable": true`: the site can be confirmed +through `/v1/connect` (§2.1) and a panel shows the button. The field is left out otherwise. + ## 5. Rotation — `POST /v1/rotate` `Authorization: Bearer ims_…`, no body. When `token.rotateAfter` has passed (90 days after issue), the client @@ -474,6 +538,7 @@ Each file in `examples/` is one case: | `quota` | `fresh`, `hour-exhausted`, `day-exhausted`, `recipient-exhausted`, `hour-share-used` | The site's counters. `recipient-exhausted`: `{{recipient}}` got the day's maximum of form confirmations. `hour-share-used`: mail other than `account` has used its four fifths of the hour | | `idempotency` | `fresh`, `sent-same`, `sent-other` | Whether `{{idempotencyKey}}` was already used: for this very body, or for another | | `backend` | `ok`, `recipient-suppressed`, `failure` | How the mail back end answers | +| `connect` | `available`, `unavailable` | Whether the service's confirmation page is set up (§2.1). `available` when left out | Variables: `{{host}}`, `{{token}}`, `{{nonce}}`, `{{idempotencyKey}}`, `{{recipient}}`, and — read from the service — `{{senderAddress}}`, `{{alertRecipient}}`. @@ -536,5 +601,8 @@ Checklist for a client: 7. Strip from the subject what §3 does not allow (line breaks, control characters, direction marks and other invisible characters — not only line breaks); bare addresses only; the right `kind` for each mail. 8. Read limits from `/v1/status`; rotate after `token.rotateAfter`. +8a. **Connect (§2.1):** a button for an administrator that asks `/v1/connect` from the server on the click and + opens the answered `connectUrl` in a new tab after checking its beginning; `/v1/status` every 5 seconds for + at most 10 minutes while that panel is open; the four states shown. No link is asked for on page load. 9. Run the examples: the `client` block of each against canned answers, and the whole set against your local stand-in. diff --git a/contracts/mail-relay/VERSION b/contracts/mail-relay/VERSION index 943f9cb..27f9cd3 100644 --- a/contracts/mail-relay/VERSION +++ b/contracts/mail-relay/VERSION @@ -1 +1 @@ -1.7.1 +1.8.0 diff --git a/contracts/mail-relay/examples/connect-active.json b/contracts/mail-relay/examples/connect-active.json new file mode 100644 index 0000000..2cd0362 --- /dev/null +++ b/contracts/mail-relay/examples/connect-active.json @@ -0,0 +1,31 @@ +{ + "id": "connect-active", + "title": "A site that is confirmed already gets no link", + "given": { + "site": "active" + }, + "request": { + "method": "POST", + "path": "/v1/connect", + "headers": { + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" + } + }, + "response": { + "status": 200, + "schema": "ConnectResponse", + "body": { + "ok": true, + "state": "active" + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": null + }, + "then": { + "mails": 0 + } +} diff --git a/contracts/mail-relay/examples/connect-pending.json b/contracts/mail-relay/examples/connect-pending.json new file mode 100644 index 0000000..eb153a0 --- /dev/null +++ b/contracts/mail-relay/examples/connect-pending.json @@ -0,0 +1,31 @@ +{ + "id": "connect-pending", + "title": "A waiting site asks for the link a person of Intecion confirms it with", + "given": { + "site": "pending" + }, + "request": { + "method": "POST", + "path": "/v1/connect", + "headers": { + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" + } + }, + "response": { + "status": 200, + "schema": "ConnectResponse", + "body": { + "ok": true, + "state": "pending" + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": "relay-pending" + }, + "then": { + "mails": 0 + } +} diff --git a/contracts/mail-relay/examples/connect-suspended.json b/contracts/mail-relay/examples/connect-suspended.json new file mode 100644 index 0000000..42f675b --- /dev/null +++ b/contracts/mail-relay/examples/connect-suspended.json @@ -0,0 +1,32 @@ +{ + "id": "connect-suspended", + "title": "A suspended site cannot be connected", + "given": { + "site": "suspended" + }, + "request": { + "method": "POST", + "path": "/v1/connect", + "headers": { + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" + } + }, + "response": { + "status": 403, + "schema": "Error", + "body": { + "ok": false, + "code": "site-suspended", + "retryable": false + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": "relay-suspended" + }, + "then": { + "mails": 0 + } +} diff --git a/contracts/mail-relay/examples/connect-unavailable.json b/contracts/mail-relay/examples/connect-unavailable.json new file mode 100644 index 0000000..6f7ad5d --- /dev/null +++ b/contracts/mail-relay/examples/connect-unavailable.json @@ -0,0 +1,33 @@ +{ + "id": "connect-unavailable", + "title": "The service has no confirmation page set up: the site stays waiting and says whom to ask", + "given": { + "site": "pending", + "connect": "unavailable" + }, + "request": { + "method": "POST", + "path": "/v1/connect", + "headers": { + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" + } + }, + "response": { + "status": 503, + "schema": "Error", + "body": { + "ok": false, + "code": "connect-unavailable", + "retryable": false + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": "relay-pending" + }, + "then": { + "mails": 0 + } +} diff --git a/contracts/mail-relay/examples/status-pending-connect.json b/contracts/mail-relay/examples/status-pending-connect.json new file mode 100644 index 0000000..875ed5c --- /dev/null +++ b/contracts/mail-relay/examples/status-pending-connect.json @@ -0,0 +1,29 @@ +{ + "id": "status-pending-connect", + "title": "Status of a waiting site says that it can be confirmed through /v1/connect", + "given": { + "site": "pending" + }, + "request": { + "method": "GET", + "path": "/v1/status", + "headers": { + "authorization": "Bearer {{token}}", + "x-intecion-site": "{{host}}" + } + }, + "response": { + "status": 200, + "schema": "StatusResponse", + "body": { + "ok": true, + "state": "pending", + "connectAvailable": true + } + }, + "client": { + "retry": false, + "reEnrol": false, + "status": "relay-pending" + } +} diff --git a/contracts/mail-relay/runner.mjs b/contracts/mail-relay/runner.mjs index c5a67d6..b826163 100644 --- a/contracts/mail-relay/runner.mjs +++ b/contracts/mail-relay/runner.mjs @@ -2,7 +2,7 @@ // No dependency. Works in Node 20+ and in the Workers runtime (uses only WebCrypto, btoa and TextEncoder). // How to use it: README.md, "The examples and the runner". -export const CONTRACT_VERSION = '1.7.1' +export const CONTRACT_VERSION = '1.8.0' export class ContractError extends Error { constructor(exampleId, message) { diff --git a/contracts/mail-relay/schema.json b/contracts/mail-relay/schema.json index d346ede..8a75f20 100644 --- a/contracts/mail-relay/schema.json +++ b/contracts/mail-relay/schema.json @@ -497,6 +497,10 @@ "senderName": { "description": "The name the last mail left under, when there was one.", "type": "string" + }, + "connectAvailable": { + "description": "Only for a pending site, and only when true: the site can be confirmed through /v1/connect (contract 2.1).", + "const": true } } }, @@ -572,7 +576,8 @@ "quota-exceeded", "backend-failed", "unavailable", - "internal" + "internal", + "connect-unavailable" ], "description": "The codes the service answers with today. The list grows with minor versions; that is why Error.code is an open string." }, @@ -619,6 +624,63 @@ "type": "string" } } + }, + "ConnectResponse": { + "description": "Answer of POST /v1/connect. For a pending site: a link for a person of Intecion, valid until expiresAt, usable for one confirmation. For an active site: no link.", + "type": "object", + "required": [ + "ok", + "state" + ], + "properties": { + "ok": { + "const": true + }, + "state": { + "enum": [ + "pending", + "active" + ] + }, + "connectUrl": { + "type": "string", + "pattern": "^https?://[^/?#\\s]+(/[A-Za-z0-9._~-]+)*/connect\\?ref=[A-Za-z0-9_-]{43}$", + "description": "Opened by a person's browser as a top-level navigation. Never fetched by the site's server." + }, + "expiresAt": { + "type": "string", + "format": "date-time" + } + }, + "if": { + "properties": { + "state": { + "const": "pending" + } + } + }, + "then": { + "required": [ + "connectUrl", + "expiresAt" + ] + }, + "else": { + "not": { + "anyOf": [ + { + "required": [ + "connectUrl" + ] + }, + { + "required": [ + "expiresAt" + ] + } + ] + } + } } } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8ac9d01..7a68ba4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,6 +14,35 @@ once there are more than 20. This heading and the 1.17.2 section below (never released on its own) become one 1.18.0 entry at release. Read every "what changes for an existing site" list: the one here and the one in each subsection. +### IWSN: "Połącz z IWSN" — a person of Intecion connects the site (docs/email.md, contract 1.8.0) + +> **What changes for an existing site:** nothing for a site whose "Sending method" is SMTP or Microsoft Graph, and +> nothing for a site already active on IWSN. A site on IWSN that is new or still waits now shows **"Połącz z IWSN"** +> on Site integrations → E-mail sending: pressing it opens the service's confirmation page in a new tab, where a +> person of Intecion signs in with an `@intecion.com` address and presses "Potwierdź"; the panel then shows +> "Connected to IWSN" by itself. Until then the site's e-mails are refused (`relay-pending`), the dashboard alert says +> so, and `iapl-doctor --deep` reports an **error** (`mail-relay-connect`). No schema change, no import-map change. + +- **The button** (state block on the e-mail tab, method IWSN): shown while the service offers the confirmation page + (`connectAvailable` in `/v1/status`) or before the site has enrolled. A click asks the site's server for the link + (`POST /api/iapl/mail-relay/connect-link`, admin only, enrolling first when there is no token); the server asks the + service (`POST /v1/connect`), checks that the link begins with the service's own `{base}/connect?`, and hands it + over without storing or logging it; the browser opens it with `noopener noreferrer`. The panel then asks + `/v1/status` every 5 seconds for at most 10 minutes; every load of the panel asks too while the site waits. +- **States shown:** "Waiting for confirmation" (with the button), "waiting for approval" (no button: no confirmation + page), "Connected to IWSN", stopped. "The confirmation page is not available now" for `503 connect-unavailable`; a + wait in minutes for more than 10 links an hour. +- **Dashboard alert** for a waiting site (live, no call to the service); the text of `relay-pending` now speaks of + confirmation. +- **Doctor:** `mail-relay-connect` (error, deep) — the method is IWSN and the site is not connected or not confirmed. + `mail-relay-state` no longer reports "waiting for approval" (warning) or "not enrolled yet" (info): both are this error. +- **Opt-out:** `mail: { relay: { connectButton: false } }` — no button, no route. +- **Building blocks:** `requestRelayConnectLink(payload, options?)` (`ConnectLinkResult`), `isRelayConnectUrl(url, base)`, + `RELAY_CONNECT_LINK_PATH`, `RelayStatus.connectAvailable`; `relayPanelEndpoints(own, { connectLink })`. The stand-in: + `createFakeRelay({ connect: 'available' | 'unavailable' })`, `relay.confirmConnect(connectUrl)`, `connectAvailable` in + its `/v1/status`, `/v1/connect`. +- The contract copy is 1.8.0 (`RELAY_CONTRACT_VERSION`); additive, every other route unchanged. + ### Two-step verification: the first set-up is confirmed by e-mail (docs/security.md) > **Read before upgrading — what changes for an existing site, most important first:** diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index be442f8..a20eade 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1363,8 +1363,12 @@ reports `mail-method` info (nothing picked yet) or nothing (picked and usable). 3. The server may call `https://webservices.intecion.net`. 4. Site integrations → E-mail sending: "Sender name" (else the site name is used) and **"Sender address"** — with the mail service that is where replies go; the service's own address has no mailbox. -5. Nothing to arrange with Intecion: a site that passes the call-back is active at once (`relay-pending`, held for - approval, is the exception — the panel says so). +5. **A person of Intecion connects the site** (contract 1.8.0): after its first e-mail (or the button) the site waits + (`relay-pending`). Site integrations → E-mail sending → **"Połącz z IWSN"** opens the service's confirmation page in a + new tab; a person of Intecion signs in with an `@intecion.com` address and presses "Potwierdź"; the block shows + "Connected to IWSN" by itself (it asks every 5 s for 10 min, and on every load while the site waits). Tell the owner + that step is theirs. Nothing to paste, no token. Opt-out: `mail: { relay: { connectButton: false } }` (no button, no + route). **Verify:** `iapl-doctor --deep` has no `mail-relay-connect` error; a test e-mail answers "through IWSN". 6. **Launch needs nobody:** a site enrolled on its development address and then served on the real domain (or moved to another domain) enrols by itself on its first e-mail. **A non-public copy does not send by itself:** a site whose host matches `iapl({ developmentHosts })` — default `['*.dev.netscale.pl']`, Intecion's development @@ -1414,6 +1418,7 @@ overrides per adapter; `resolveRelayOptions` reads what is in effect): | `otherHosts` | `'auto'` | a database holding another host's connection: a public site enrols by itself (launch, a move), a non-public one (`IAPL_NOINDEX=1` / `developmentHosts`) neither enrols nor sends until "Connect again"; a list of the site's own other hosts; `'wait'` (a public site without a connection waits too); `'enrol'` (no rule) | | `developmentHosts` | `iapl({ developmentHosts })`, default `DEFAULT_DEVELOPMENT_HOSTS` = `['*.dev.netscale.pl']` (`pluginDevelopmentHosts`) | host patterns (`*`) of development and staging addresses, for the mail service alone: a site there is non-public for `otherHosts` with no env (`siteIsNonPublic`, `siteNonPublicSignal` → `NonPublicSignal`, `matchDevelopmentHost`, `isDevelopmentHost`); `[]` = none. Checked when the config is built (`assertDevelopmentHosts`): not an array of non-empty host patterns, or a lone `*` → the site does not start; Unicode patterns are punycoded, a trailing dot and the port are ignored | | `enrol` | `'auto'` | `'manual'` (only "Connect again" / `enrolRelay`), `false` (token from `token` / `setRelayToken`) | +| `connectButton` | `true` | `false`: no "Połącz z IWSN" and no `POST /api/iapl/mail-relay/connect-link`; confirm by an operator or with `requestRelayConnectLink` | | `accessKeyField` | `false` | `true`: admins get "Enter an access key" in the state block (a hand-issued token) | | `token` | — | a token from elsewhere; nothing is stored, the site does not enrol | | `senderName` | panel → site name (`relaySenderName`) | fixed name or function | @@ -1447,6 +1452,7 @@ needs more: Intecion raises the limits, or SMTP. |---|---| | The transport alone, no SMTP / Graph | `email: relayAdapter()` (`RelayAdapterArgs`) | | Enrol from a deploy script; state; rotate; disconnect; a token issued by hand | `enrolRelay` (`EnrolResult`), `getRelayStatus` (`RelayStatus`), `rotateRelayToken`, `disconnectRelay`, `setRelayToken` | +| A button of your own for the confirmation by Intecion | `requestRelayConnectLink(payload)` (`ConnectLinkResult`: `{ state: 'pending', connectUrl, expiresAt }` / `{ state: 'active' }` / a refusal) on a person's click only; open `connectUrl` in a new tab with `noopener noreferrer`; never store, log or fetch it; `isRelayConnectUrl(url, base)`; the route `RELAY_CONNECT_LINK_PATH`; the stand-in `createFakeRelay({ connect })` + `relay.confirmConnect(url)` | | Your own state block or panel route | `mailPanelState` (`MailPanelState`), `relayPanelEndpoints`, `relayConfirmEndpoint`; the plugin's component is `MailRelayStatus` (`/admin`) | | One message with the retry rule; one HTTP call | `sendThroughRelay` (`RelaySendContext`, `RelaySendResult`), `relayRequest` (`RelayCall`, `RelayAnswer`, `RelayRefusal`) | | The request the service takes | `buildRelayMessage` (`BuildRelayMessageArgs`, `BuiltRelayMessage`, `RelaySendRequest`), `bareAddress`, `bareAddresses`, `cleanSubject` | diff --git a/docs/agent/skills/iapl-debug/SKILL.md b/docs/agent/skills/iapl-debug/SKILL.md index 7803602..4800773 100644 --- a/docs/agent/skills/iapl-debug/SKILL.md +++ b/docs/agent/skills/iapl-debug/SKILL.md @@ -122,7 +122,7 @@ through this procedure. Ask only when you are missing something you cannot get y | a site sends nothing: "The data comes from another site (…), so this copy does not send e-mails by itself" / `relay-refused`, cause `client-other-host` | the site is non-public — its host matches `developmentHosts` (built in: `*.dev.netscale.pl`) or `IAPL_NOINDEX=1` is set; `iapl-doctor --deep` says which (`mail-non-public`) — and its database holds another host's connection: a staging copy of production, or production's data copied back onto the development address. Expected — a copy with production's data must not mail real people by itself | should it send: "Connect again" in the state block, once (until the data is replaced). A copy that must never send: `mail: { relay: false }` or SMTP to a catcher. **The production site itself says this:** `IAPL_NOINDEX` was left set after launch — remove it; or its host matches a development pattern — take it out of `iapl({ developmentHosts })` | | the site does not start: "[iapl] … developmentHosts must be an array of host patterns …" | the list is not an array of non-empty host patterns (a single string, `null`, `['']`), or holds a lone `*` | write it as `['*.dev.netscale.pl', 'staging.client.pl']`; `[]` = none; to change who waits use `mail.relay.otherHosts` | | a staging or test copy **does** send, to real addresses | its host matches no development pattern and it has no `IAPL_NOINDEX=1`, so it looks like a launch (a public site enrols by itself); the doctor's deep run notes "the database also holds the mail-service connection of another host" | name its host in `iapl({ developmentHosts: ['*.dev.netscale.pl', ''] })`, or `IAPL_NOINDEX=1` on the copy; to be sure: `mail: { relay: false }` or SMTP to a catcher | -| `relay-pending` / "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; after that, the exception (many new sites at once, or approval by hand) | Intecion approves it on the service; nothing to change on the site; the same token then works | +| `relay-pending` / "Waiting for confirmation" / doctor `mail-relay-connect` | a new site waits until a person of Intecion confirms it (contract 1.8.0) | Site integrations → E-mail sending → "Połącz z IWSN"; the person signs in with an @intecion.com address on the page that opens and presses "Potwierdź"; the block turns "Connected" by itself. "Waiting for approval" with no button, or "the confirmation page is not available": Intecion confirms the host by hand. "Too many confirmation links": wait the minutes it says. The same token works afterwards | | `relay-suspended` | Intecion stopped the site (abuse, a flood from a form) | contact Intecion; fill in SMTP meanwhile | | `relay-disconnected` | an admin pressed "Disconnect" | "Connect again", or SMTP | | `relay-quota` | the site's hour or day is used up (30 / 200 by default), more than 10 recipients, more than 10 confirmations to one address a day, too many new addresses, or the site's own limit on account mail (`mail.relay.accountMail`) | the server log names the limit; look for a form being abused (Turnstile on? rate limit?); a site that really sends more: Intecion raises the limits, or SMTP | diff --git a/docs/agent/skills/iapl-setup/SKILL.md b/docs/agent/skills/iapl-setup/SKILL.md index 7affb3e..7aba266 100644 --- a/docs/agent/skills/iapl-setup/SKILL.md +++ b/docs/agent/skills/iapl-setup/SKILL.md @@ -669,7 +669,7 @@ scaling (5). `●` routes for pages need the database at build time (PROGRAMISTA 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). "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. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). 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 + for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("Waiting for confirmation": press "Połącz z IWSN" and have a person of Intecion confirm the site on the page that opens — the owner's step, @intecion.com sign-in; "waiting for approval" with no button: ask Intecion; 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. diff --git a/docs/agent/skills/iapl-upgrade/SKILL.md b/docs/agent/skills/iapl-upgrade/SKILL.md index 679630b..f860f2b 100644 --- a/docs/agent/skills/iapl-upgrade/SKILL.md +++ b/docs/agent/skills/iapl-upgrade/SKILL.md @@ -714,7 +714,7 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re 3. **For a site that will use the mail service:** `serverURL` is the public address the site answers on without a redirect; no proxy or WAF rule blocks `/api/iapl/mail-relay/confirm`; `trailingSlash: true` or another `routes.api` → Intecion sets the site's confirm address first; "Sender address" is filled in (replies go there); the client's - processing agreement names the service. Tell Intecion the host: while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval (the panel says "waiting for approval"); under open enrolment a site is active as soon as it enrols. + processing agreement names the service. A new site waits until a person of Intecion confirms it: "Połącz z IWSN" in the panel (contract 1.8.0). **Launch and a domain move need nothing:** the real domain enrols by itself although the database holds the development address's connection. **A staging or test copy of the database** neither enrols nor sends by itself **when it is non-public**: its host matches `iapl({ developmentHosts })` — built in `*.dev.netscale.pl`, so the @@ -736,7 +736,16 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re **Check:** `pnpm exec iapl-doctor --deep --url ` → no `mail-transport` / `mail-relay-state` / `mail-reply-address` / `mail-relay-route` finding (or only `mail-graph-deprecated` on a Graph site); Site integrations → E-mail sending → **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`.** +`https://webservices.intecion.net/mail`; a new site waits until a person of Intecion confirms it ("Połącz z IWSN") — keep SMTP until then, or `relay: false`.** + +**→ 1.18.0, IWSN is connected by a person of Intecion (CHANGELOG "Unreleased (for 1.18.0)" → "IWSN: Połącz z IWSN"; email.md "The mail service"; AGENT.md §7.2 point 5) — nothing to run:** +1. No schema change, no migration, no import-map change. Sites whose "Sending method" is SMTP or Microsoft Graph see no + change at all. +2. A site on IWSN that is already active stays active. A site that waits (`relay-pending`, or doctor `mail-relay-connect` + error after the upgrade): Site integrations → E-mail sending → **"Połącz z IWSN"** → a person of Intecion confirms + it on the page that opens (an @intecion.com sign-in — the owner's step, tell them) → the block says "Connected to + IWSN" by itself. Then send a test e-mail. +3. A project that does not want the button: `mail: { relay: { connectButton: false } }` (no button, no route). **→ 1.17.1, e-mail (CHANGELOG 1.17.1 point 5; PROGRAMISTA §6, item 82; email.md "Which transport a send takes"; AGENT.md §7.2) — nothing to run, one check:** 1. **MongoDB: no migration. Postgres / SQLite: `pnpm payload migrate:create`** (the new field `emailMethod` is a column), diff --git a/docs/doctor.md b/docs/doctor.md index 09a7f5a..52824ff 100644 --- a/docs/doctor.md +++ b/docs/doctor.md @@ -131,7 +131,8 @@ Turn off: `iapl({ doctor: false })`. Adapt: `iapl({ doctor: { tokenVar: 'MY_TOKE | mail | `mail-method` | error / info | (deep) the chosen "Sending method" can be used — "Own SMTP server" with server, user name and password, "Microsoft Graph" with the `GRAPH_*` variables; otherwise e-mails are not sent and nothing is sent another way (error). On Postgres / SQLite: the column of `emailMethod` exists — the 1.17.1 migration has run (error). Nobody has chosen yet: the site picks a method from what is filled in until Site integrations is saved (info) | | | `mail-transport` | error / warning | (deep) an e-mail transport is in effect (not: the mail service switched off and no SMTP server); the last sends worked — failing: warning, error once it has lasted 24 hours | | | `mail-non-public` | info | (deep) on the mail service: says which signal makes the site a non-public copy — its host matches a development pattern (`developmentHosts`, named in the finding) or `IAPL_NOINDEX` is set — and what to change if the site is in fact the public one | -| | `mail-relay-state` | error / warning / info | (deep) on the Intecion mail service: not disconnected and not stopped (error), not waiting for approval, not refused at enrolment, not a non-public copy of another site's database that waits for "Connect again" (`client-other-host`), the sender name not replaced (warning); not enrolled yet, and a public site whose database also holds another host's connection — its own past after a launch or a move, or a copy that forgot `IAPL_NOINDEX=1` (info) | +| | `mail-relay-connect` | error | (deep) the sending method is IWSN and the site is connected and confirmed — not "not enrolled yet", not waiting for confirmation by Intecion (contract 1.8.0). The fix names "Połącz z IWSN", or Intecion when the service offers no confirmation page | +| | `mail-relay-state` | error / warning / info | (deep) on the Intecion mail service: not disconnected and not stopped (error), not refused at enrolment, not a non-public copy of another site's database that waits for "Connect again" (`client-other-host`), the sender name not replaced (warning); a public site whose database also holds another host's connection — its own past after a launch or a move, or a copy that forgot `IAPL_NOINDEX=1` (info) | | | `mail-reply-address` | warning | (deep) on the mail service, "Sender address" is filled in: replies go there | | | `mail-graph-deprecated` | warning | Microsoft Graph is not in use: no `GRAPH_*` variables on the site (deep), no `graphAdapter` / `emailGraph: true` in the config — deprecated, removed in 2.0 | | | `mail-relay-route` | warning | nothing keeps the mail service from confirming the site: no `trailingSlash: true`, `routes.api` is `/api` (else Intecion sets the site's confirm address); live, on the mail service: `/api/iapl/mail-relay/confirm` answers without a redirect, a block or a server error. Skipped with `relay: false` | diff --git a/docs/email.md b/docs/email.md index 885d2cf..fa4f092 100644 --- a/docs/email.md +++ b/docs/email.md @@ -136,10 +136,28 @@ What the site needs for it: 443, **without a redirect** — the service follows none. No basic auth, no firewall rule, no maintenance page in front of it. (Coolify: nothing to set; the route is part of Payload's API.) - **Outbound HTTPS** from the server to `webservices.intecion.net`. -- **A site that passes the call-back is active at once.** Waiting for approval is the exception: the service - holds a new site back when many new sites appear at once (more than a few a day from one address or domain, or - more than its daily number in all), or when Intecion has set it to approve by hand. Mail is then not sent until - Intecion approves the site; the same token works afterwards, and the panel says so. +- **A new site is connected by a person of Intecion** (contract 1.8.0 §2.1, the service's `connect` policy). It + enrols as before, then **waits** (`pending`): its mail is refused with `site-pending` (status `relay-pending`), not + sent and not kept. On Site integrations → E-mail sending, with "IWSN (built-in)" as the method, an administrator + presses **"Połącz z IWSN"** ("Connect to IWSN"). The site's **server** asks the service for a link + (`POST /v1/connect`) and the panel opens it **in a new tab** (`noopener noreferrer`). A person of Intecion signs + in there with an `@intecion.com` address (Cloudflare Access) and presses "Potwierdź". The panel asks the service + every 5 seconds for at most 10 minutes and shows "Connected to IWSN" by itself; every load of the panel asks too + while the site waits. Mail sent after that leaves; mail refused before it is not sent again. + - The link is valid 15 minutes, for one confirmation; each press makes a new one. It is opened only when it begins + with the service's own `{base}/connect?` (the plugin checks it on the server and in the browser), and it is + never stored, logged or fetched by the server. + - What the block says: **"Waiting for confirmation"** with the button (the service offers the page: + `connectAvailable`); **"waiting for approval"** with no button (no confirmation page — an operator confirms the + site); **"Connected to IWSN"**; **stopped** (suspended). A site that has not enrolled yet shows the button too: + pressing it enrols first. + - When the service has no confirmation page right now (`503 connect-unavailable`) the panel says "ask your + administrator to have the site confirmed"; more than 10 links an hour (`429`) says when to try again. + - The dashboard alert shows a waiting site; `iapl-doctor --deep` reports it as an **error** (`mail-relay-connect`). + - No token or paste field is involved. Sites on SMTP or Microsoft Graph see nothing of this. + - **Opt-out:** `mail: { relay: { connectButton: false } }` — no button and no route; the site is then confirmed by + an operator, or by the project's own button with `requestRelayConnectLink(payload)` (open the answered + `connectUrl` in a new tab; `isRelayConnectUrl(url, base)` checks it). A site on `localhost`, on a private address or without `serverURL` is refused **by the plugin itself**, before any call leaves the server — development machines do not contact the service. To test mail locally use SMTP (a local @@ -392,18 +410,19 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user)) Site integrations → E-mail sending starts with "How e-mails are sent" (component `MailRelayStatus` from `/admin`, rendered by the tab's status banner — **no import-map entry of its own, so nothing to regenerate**): the -transport in effect; for the mail service the state (connected, waiting for approval, stopped, not connected and -why), the address mail leaves from, where replies go, what is left of the hour and the day, and a sender name the +transport in effect; for the mail service the state (connected, waiting for confirmation — with "Połącz z IWSN" —, +waiting for approval, stopped, not connected and why), the address mail leaves from, where replies go, what is left of the hour and the day, and a sender name the service replaced. Buttons: **Check now**, **Connect again**, **Disconnect** — and **Enter an access key** only with `mail.relay.accessKeyField: true` ("The token" above). -Routes (all three need the `admin` role: not logged in → 401, other role → 403; none ever answers with a token): +Routes (all four need the `admin` role: not logged in → 401, other role → 403; none ever answers with a token): | Route | What | |---|---| | `GET /api/iapl/mail-relay/status` | the transport and the stored state; `?refresh=1` asks the service | | `POST /api/iapl/mail-relay/connect` | enrol now; with `{ token }` store a token issued by hand — only with `accessKeyField: true`, otherwise `403` | | `POST /api/iapl/mail-relay/disconnect` | give the token up | +| `POST /api/iapl/mail-relay/connect-link` | "Połącz z IWSN": asks the service for the confirmation link (`POST /v1/connect`, enrolling first when there is no token) and answers it as `connectUrl` + `expiresAt`, `Cache-Control: no-store`; nothing is stored. Absent with `connectButton: false` (`RELAY_CONNECT_LINK_PATH`) | | `POST /api/iapl/mail-relay/confirm` | **public** — the service's call-back. `404` and no change unless the site itself started an enrolment in the last 5 minutes; **refused** calls are rate-limited (10 a minute per address, `mail.relay.confirmRateLimit`) — a call that carries the nonce is never turned away by the limit, so junk from the same address cannot keep the site from enrolling | These are the first routes under `/api/iapl/`; the others stay under `/api/ipal/` until 2.0. The confirm path is @@ -419,7 +438,7 @@ the service), each with a text in the editor's language: | Code | Meaning | What to do | |---|---|---| -| `relay-pending` | enrolled, but held for approval by Intecion — the rule while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval; after that the exception (many new sites at once, or approval by hand) | Intecion approves the host; nothing to do on the site | +| `relay-pending` | enrolled, waiting for confirmation by a person of Intecion (contract 1.8.0) | "Połącz z IWSN" in the panel and the confirmation on the page that opens; without the button (no confirmation page), Intecion confirms the host | | `relay-suspended` | stopped by Intecion | contact Intecion; SMTP in the panel sends meanwhile | | `relay-refused` | the site could not enrol; or a token issued by hand stopped working (new server address, token no longer valid) | "When the site cannot be confirmed" below; hand-issued: ask Intecion for the address to be added or for a new token | | `relay-disconnected` | an admin pressed "Disconnect" | "Connect again", or fill in SMTP | @@ -464,6 +483,7 @@ message); "Connect again" asks at once. Other causes: `host-not-allowed` (not a | `otherHosts` | `'auto'` | a database that holds another host's connection. `'auto'`: a public site enrols by itself (launch, a domain move); a non-public one (`IAPL_NOINDEX=1` or `developmentHosts`) neither enrols nor sends until "Connect again". A list = those hosts are this site's own. `'wait'` = a public site without a connection of its own waits too. `'enrol'` = no rule | | `developmentHosts` | the plugin's list: `iapl({ developmentHosts })`, default `['*.dev.netscale.pl']` (`pluginDevelopmentHosts(payload)`) | host patterns (`*` = any characters) of development, staging and preview addresses, for the mail service alone: a site on such a host is non-public for `otherHosts`, like one with `IAPL_NOINDEX=1`, with no environment variable (`siteIsNonPublic`, `siteNonPublicSignal`, `matchDevelopmentHost`, `isDevelopmentHost`). `[]` = none | | `enrol` | `'auto'` | `'manual'`: only "Connect again" or `enrolRelay()` enrols. `false`: never (the token comes from `token` or `setRelayToken`) | +| `connectButton` | `true` | `false`: no "Połącz z IWSN" in the state block and no `connect-link` route; the site is confirmed by an operator or by the project's own code (`requestRelayConnectLink`) | | `accessKeyField` | `false` | `true` shows "Enter an access key" in the state block and lets its route store a hand-issued token an admin pastes | | `token` | — | a token from elsewhere (`string` or a function): the stored token is not used and the site does not enrol | | `senderName` | panel, then site name | a fixed name, or a function | @@ -516,7 +536,9 @@ await payload.sendEmail({ to: 'a@example.org', subject: 'Hi', html: '

Hi

' expect(relay.outbox[0]).toMatchObject({ kind: 'system', to: ['a@example.org'] }) ``` -- `allow` / `relay.allow(host)`: hosts that are active at once; others wait for approval. `relay.setSite(host, state)`, +- `allow` / `relay.allow(host)`: hosts that are active at once; others wait (`pending`). `connect: 'unavailable'` makes + `/v1/connect` answer `503 connect-unavailable`; `relay.confirmConnect(connectUrl)` stands in for the person who + confirms a link (true when it was the site's current one, not expired). `relay.setSite(host, state)`, `relay.issueToken(host)`, `relay.backend = 'failure'`, `relay.intercept`, `relay.limits`, `relay.clientAddress` arrange what a test needs; `relay.listen(port)` serves it over HTTP for a site in another process (`allowLocalHosts: true` lets it call back `http://localhost:`). @@ -647,7 +669,8 @@ Works on any `text` field. After wiring it in a project you may need To the mail service (when the owner says so): 1. Upgrade; check that `serverURL` is the site's public address. -2. Tell Intecion the host: while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval; the panel says so. Under open enrolment the site is active as soon as it enrols. +2. After the first e-mail the site waits for confirmation: press "Połącz z IWSN" in Site integrations → E-mail + sending and have a person of Intecion confirm it on the page that opens (keep Graph until then). 3. Site integrations → E-mail sending → "Sending method": choose **IWSN (built-in)** and save. Then remove the four `GRAPH_*` variables in Coolify and redeploy. 4. Site integrations → E-mail sending → send a test e-mail: the answer says "through IWSN". @@ -829,8 +852,9 @@ send (e.g. **Send test e-mail**) the current one appears. ## Doctor -`iapl-doctor` ([doctor.md](./doctor.md)): `mail-transport` (nothing set up; sending is failing), `mail-relay-state` -(waiting for approval, stopped, refused, disconnected, a replaced sender name), `mail-reply-address`, +`iapl-doctor` ([doctor.md](./doctor.md)): `mail-transport` (nothing set up; sending is failing), `mail-relay-connect` +(error: the method is IWSN and the site is not connected or not confirmed), `mail-relay-state` (stopped, refused, +disconnected, a held copy, a replaced sender name), `mail-reply-address`, `mail-graph-deprecated`, `mail-relay-route` (trailing slashes, another API route, a redirect or a block in front of the confirm route on the live site). diff --git a/reference/.agents/skills/iapl-debug/SKILL.md b/reference/.agents/skills/iapl-debug/SKILL.md index 7803602..4800773 100644 --- a/reference/.agents/skills/iapl-debug/SKILL.md +++ b/reference/.agents/skills/iapl-debug/SKILL.md @@ -122,7 +122,7 @@ through this procedure. Ask only when you are missing something you cannot get y | a site sends nothing: "The data comes from another site (…), so this copy does not send e-mails by itself" / `relay-refused`, cause `client-other-host` | the site is non-public — its host matches `developmentHosts` (built in: `*.dev.netscale.pl`) or `IAPL_NOINDEX=1` is set; `iapl-doctor --deep` says which (`mail-non-public`) — and its database holds another host's connection: a staging copy of production, or production's data copied back onto the development address. Expected — a copy with production's data must not mail real people by itself | should it send: "Connect again" in the state block, once (until the data is replaced). A copy that must never send: `mail: { relay: false }` or SMTP to a catcher. **The production site itself says this:** `IAPL_NOINDEX` was left set after launch — remove it; or its host matches a development pattern — take it out of `iapl({ developmentHosts })` | | the site does not start: "[iapl] … developmentHosts must be an array of host patterns …" | the list is not an array of non-empty host patterns (a single string, `null`, `['']`), or holds a lone `*` | write it as `['*.dev.netscale.pl', 'staging.client.pl']`; `[]` = none; to change who waits use `mail.relay.otherHosts` | | a staging or test copy **does** send, to real addresses | its host matches no development pattern and it has no `IAPL_NOINDEX=1`, so it looks like a launch (a public site enrols by itself); the doctor's deep run notes "the database also holds the mail-service connection of another host" | name its host in `iapl({ developmentHosts: ['*.dev.netscale.pl', ''] })`, or `IAPL_NOINDEX=1` on the copy; to be sure: `mail: { relay: false }` or SMTP to a catcher | -| `relay-pending` / "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; after that, the exception (many new sites at once, or approval by hand) | Intecion approves it on the service; nothing to change on the site; the same token then works | +| `relay-pending` / "Waiting for confirmation" / doctor `mail-relay-connect` | a new site waits until a person of Intecion confirms it (contract 1.8.0) | Site integrations → E-mail sending → "Połącz z IWSN"; the person signs in with an @intecion.com address on the page that opens and presses "Potwierdź"; the block turns "Connected" by itself. "Waiting for approval" with no button, or "the confirmation page is not available": Intecion confirms the host by hand. "Too many confirmation links": wait the minutes it says. The same token works afterwards | | `relay-suspended` | Intecion stopped the site (abuse, a flood from a form) | contact Intecion; fill in SMTP meanwhile | | `relay-disconnected` | an admin pressed "Disconnect" | "Connect again", or SMTP | | `relay-quota` | the site's hour or day is used up (30 / 200 by default), more than 10 recipients, more than 10 confirmations to one address a day, too many new addresses, or the site's own limit on account mail (`mail.relay.accountMail`) | the server log names the limit; look for a form being abused (Turnstile on? rate limit?); a site that really sends more: Intecion raises the limits, or SMTP | diff --git a/reference/.agents/skills/iapl-setup/SKILL.md b/reference/.agents/skills/iapl-setup/SKILL.md index 7affb3e..7aba266 100644 --- a/reference/.agents/skills/iapl-setup/SKILL.md +++ b/reference/.agents/skills/iapl-setup/SKILL.md @@ -669,7 +669,7 @@ scaling (5). `●` routes for pages need the database at build time (PROGRAMISTA 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). "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. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). 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 + for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("Waiting for confirmation": press "Połącz z IWSN" and have a person of Intecion confirm the site on the page that opens — the owner's step, @intecion.com sign-in; "waiting for approval" with no button: ask Intecion; 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. diff --git a/reference/.agents/skills/iapl-upgrade/SKILL.md b/reference/.agents/skills/iapl-upgrade/SKILL.md index 679630b..f860f2b 100644 --- a/reference/.agents/skills/iapl-upgrade/SKILL.md +++ b/reference/.agents/skills/iapl-upgrade/SKILL.md @@ -714,7 +714,7 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re 3. **For a site that will use the mail service:** `serverURL` is the public address the site answers on without a redirect; no proxy or WAF rule blocks `/api/iapl/mail-relay/confirm`; `trailingSlash: true` or another `routes.api` → Intecion sets the site's confirm address first; "Sender address" is filled in (replies go there); the client's - processing agreement names the service. Tell Intecion the host: while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval (the panel says "waiting for approval"); under open enrolment a site is active as soon as it enrols. + processing agreement names the service. A new site waits until a person of Intecion confirms it: "Połącz z IWSN" in the panel (contract 1.8.0). **Launch and a domain move need nothing:** the real domain enrols by itself although the database holds the development address's connection. **A staging or test copy of the database** neither enrols nor sends by itself **when it is non-public**: its host matches `iapl({ developmentHosts })` — built in `*.dev.netscale.pl`, so the @@ -736,7 +736,16 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re **Check:** `pnpm exec iapl-doctor --deep --url ` → no `mail-transport` / `mail-relay-state` / `mail-reply-address` / `mail-relay-route` finding (or only `mail-graph-deprecated` on a Graph site); Site integrations → E-mail sending → **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`.** +`https://webservices.intecion.net/mail`; a new site waits until a person of Intecion confirms it ("Połącz z IWSN") — keep SMTP until then, or `relay: false`.** + +**→ 1.18.0, IWSN is connected by a person of Intecion (CHANGELOG "Unreleased (for 1.18.0)" → "IWSN: Połącz z IWSN"; email.md "The mail service"; AGENT.md §7.2 point 5) — nothing to run:** +1. No schema change, no migration, no import-map change. Sites whose "Sending method" is SMTP or Microsoft Graph see no + change at all. +2. A site on IWSN that is already active stays active. A site that waits (`relay-pending`, or doctor `mail-relay-connect` + error after the upgrade): Site integrations → E-mail sending → **"Połącz z IWSN"** → a person of Intecion confirms + it on the page that opens (an @intecion.com sign-in — the owner's step, tell them) → the block says "Connected to + IWSN" by itself. Then send a test e-mail. +3. A project that does not want the button: `mail: { relay: { connectButton: false } }` (no button, no route). **→ 1.17.1, e-mail (CHANGELOG 1.17.1 point 5; PROGRAMISTA §6, item 82; email.md "Which transport a send takes"; AGENT.md §7.2) — nothing to run, one check:** 1. **MongoDB: no migration. Postgres / SQLite: `pnpm payload migrate:create`** (the new field `emailMethod` is a column), diff --git a/reference/e2e/mail-relay.spec.ts b/reference/e2e/mail-relay.spec.ts index 076af49..9b8cf11 100644 --- a/reference/e2e/mail-relay.spec.ts +++ b/reference/e2e/mail-relay.spec.ts @@ -104,4 +104,39 @@ test.describe('the mail service', () => { await page.waitForLoadState('networkidle') for (const body of [await page.content(), await status.text(), ...seen]) {expect(body).not.toContain('ims_')} }) + + test('"Connect to IWSN" (contract 1.8.0 §2.1): the link opens in a new tab, the person confirms, the block sees it by itself', async ({ page }) => { + // the site enrolled above; the service now holds it for confirmation by a person of Intecion + relay.site(site)!.state = 'pending' + await page.goto('/admin/login') + await page.fill('#field-email', email!) + await page.fill('#field-password', password!) + await page.click('.form-submit button') + await page.waitForURL(/verify-totp|\/admin(\?|$)/, { waitUntil: 'commit' }) + if (page.url().includes('verify-totp')) { + await page.getByRole('textbox').first().click() + await page.keyboard.type(totp(secret!)) + } + await expect(page).toHaveTitle(/Dashboard|Pulpit/, { timeout: 20_000 }) + await page.goto('/admin/globals/site-integrations') + await page.getByRole('tab', { name: /E-mail sending|Wysyłka e-mail/ }).or(page.getByRole('button', { name: /E-mail sending|Wysyłka e-mail/ })).first().click() + const block = page.locator('[data-mail-transport]') + await block.getByRole('button', { name: /Check now|Sprawdź teraz/ }).click() + const connect = block.locator('[data-mail-relay-connect]') + await expect(connect).toBeVisible({ timeout: 20_000 }) + await expect(block).toContainText(/Waiting for confirmation|Oczekuje na potwierdzenie/) + // no link was asked for by the page itself + expect(relay.requests.filter((r) => r.path === '/v1/connect')).toEqual([]) + + const [tab] = await Promise.all([page.waitForEvent('popup'), connect.click()]) + const url = tab.url() + expect(url.startsWith(`${server.url}/connect?ref=`)).toBe(true) + expect(await tab.evaluate(() => window.opener)).toBeNull() + // the person of Intecion signs in and presses "Potwierdź" on the service's page (the stand-in does it here) + expect(relay.confirmConnect(url)).toBe(true) + await tab.close() + // the block asks every 5 s and shows the result without a reload + await expect(block).toContainText(/Connected to IWSN|Połączono z IWSN/, { timeout: 20_000 }) + await expect(connect).toHaveCount(0) + }) }) diff --git a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx index d51d5d0..d34934b 100644 --- a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx +++ b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx @@ -4,12 +4,14 @@ import { useConfig, useFormFields, useTranslation } from '@payloadcms/ui' import { useCallback, useEffect, useState } from 'react' import { formatDateTime, iaplT } from '../../../modules/admin-i18n/t.js' -import { RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH, RELAY_STATUS_PATH } from '../../../modules/email/relay/constants.js' +import { RELAY_CONNECT_LINK_PATH, RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH, RELAY_STATUS_PATH } from '../../../modules/email/relay/constants.js' import { SECRET_CLEAR } from '../../../modules/secrets/constants.js' type Window = { limit: number; remaining: number } type State = { accessKeyField?: boolean + /** `mail.relay.connectButton` is on: "Połącz z IWSN" may be shown. */ + connectButton?: boolean error?: string graphReady?: boolean message?: string @@ -18,6 +20,7 @@ type State = { ok?: boolean refusalText?: string relay?: { + connectAvailable?: boolean connected?: boolean disconnected?: boolean lastFailure?: { at: string; code: string } @@ -36,6 +39,11 @@ type State = { const box = { border: '1px solid var(--theme-elevation-150)', borderRadius: 4, marginBottom: '1.5rem', padding: '0.9rem 1rem' } as const const line = { margin: '0.35rem 0 0' } as const const warn = { ...line, color: 'var(--theme-warning-600, #b45309)' } as const +/** Contract §2.1: while the panel that opened the link is open, ask at most every 5 s, for at most 10 min. */ +const POLL_EVERY_MS = 5_000 +const POLL_FOR_MS = 10 * 60_000 +/** The shape of the service's link (the server checked that it begins with the service's own address). */ +const CONNECT_URL = /^https?:\/\/[^/?#\s]+(?:\/[\w.~-]+)*\/connect\?ref=[\w-]{43}$/ /** * Admin UI: the state block at the top of Site integrations → E-mail sending. Says which transport is @@ -52,7 +60,7 @@ export const MailRelayStatus = () => { const { i18n, t } = useTranslation() const { config } = useConfig() const api = config.routes?.api ?? '/api' - const text = (key: Parameters[1], vars?: Record) => iaplT(t as never, key, vars) + const text = useCallback((key: Parameters[1], vars?: Record) => iaplT(t as never, key, vars), [t]) const [state, setState] = useState(null) const [busy, setBusy] = useState(false) const [note, setNote] = useState<{ kind: 'error' | 'ok'; msg: string } | null>(null) @@ -85,12 +93,70 @@ export const MailRelayStatus = () => { // (a stored password arrives as the mask: set; "Remove the stored value" is SECRET_CLEAR: not set) const formPassword = useFormFields(([f]) => f.smtpPassword?.value) as string | undefined const savedAt = useFormFields(([f]) => f.updatedAt?.value) as string | undefined + // "Połącz z IWSN": the link lives in this component only — never stored, never logged — until it expires + const [link, setLink] = useState<{ until: number; url: string } | null>(null) + const [pollingSince, setPollingSince] = useState(null) // on load, and again after every save of the page: the state block says what the saved settings do useEffect(() => { void call(RELAY_STATUS_PATH) }, [call, savedAt]) + const connectIwsn = async () => { + setBusy(true) + try { + const res = await fetch(`${api}${RELAY_CONNECT_LINK_PATH}`, { credentials: 'include', method: 'POST' }) + const data = (await res.json()) as { connectUrl?: string; error?: string; expiresAt?: string; message?: string } & State + if (data.transport) {setState(data)} + if (!data.ok) { + setNote({ kind: 'error', msg: data.error ?? iaplT(t as never, 'mailRelayLoadFailed') }) + return + } + if (data.connectUrl) { + if (!CONNECT_URL.test(data.connectUrl)) { + setNote({ kind: 'error', msg: text('mailRelayConnectBadLink') }) + return + } + // a top-level navigation in a new tab, with no way back to this page (contract §2.1) + window.open(data.connectUrl, '_blank', 'noopener,noreferrer') + setLink({ until: data.expiresAt ? Date.parse(data.expiresAt) : Date.now() + 15 * 60_000, url: data.connectUrl }) + setPollingSince(Date.now()) + } + setNote(data.message ? { kind: 'ok', msg: data.message } : null) + } catch { + setNote({ kind: 'error', msg: iaplT(t as never, 'mailRelayLoadFailed') }) + } finally { + setBusy(false) + } + } + + // after the link was opened: is the site confirmed yet? Every 5 s, for 10 min at most, while this panel is open + const waiting = pollingSince !== null && state?.relay?.state === 'pending' + useEffect(() => { + if (pollingSince === null) {return} + if (state?.relay?.state && state.relay.state !== 'pending') { + setPollingSince(null) + setLink(null) + if (state.relay.state === 'active') {setNote({ kind: 'ok', msg: text('mailRelayConnectDone') })} + return + } + const timer = window.setTimeout(() => { + if (Date.now() - pollingSince >= POLL_FOR_MS) { + setPollingSince(null) + setLink(null) + setNote({ kind: 'error', msg: text('mailRelayConnectNotYet') }) + return + } + void fetch(`${api}${RELAY_STATUS_PATH}?refresh=1`, { credentials: 'include' }) + .then(async (res) => (await res.json()) as State) + .then((data) => { + if (data.transport) {setState(data)} + }) + .catch(() => undefined) + }, POLL_EVERY_MS) + return () => window.clearTimeout(timer) + }, [api, pollingSince, state, text]) + const post = (path: string, body?: object) => call(path, { body: body ? JSON.stringify(body) : undefined, headers: body ? { 'Content-Type': 'application/json' } : undefined, method: 'POST' }, true) @@ -103,7 +169,7 @@ export const MailRelayStatus = () => { // why the service does not take this site: a refused enrolment, or a hand-issued token that stopped working : state.refusalText ? state.refusalText : !relay.connected ? text('mailRelayStateNotConnected') - : relay.state === 'pending' ? text('mailRelayStatePending') + : relay.state === 'pending' ? text(relay.connectAvailable && state.connectButton ? 'mailRelayStateAwaitingConnect' : 'mailRelayStatePending') : relay.state === 'suspended' ? text('mailRelayStateSuspended') : text('mailRelayStateActive') const attention = Boolean(relay && onRelay && (relay.disconnected || relay.state === 'pending' || relay.state === 'suspended' || state.refusalText)) @@ -137,6 +203,17 @@ export const MailRelayStatus = () => { {relay.quota?.hour && relay.quota.day ? (

{text('mailRelayQuota', { day: relay.quota.day.remaining, hour: relay.quota.hour.remaining })}

) : null} + {state.connectButton && !relay.disconnected && relay.state !== 'suspended' && (relay.state === 'pending' ? relay.connectAvailable : !relay.connected) ? ( +
+ + {link && link.until > Date.now() ? ( + {text('mailRelayConnectOpenLink')} + ) : null} + {waiting ? {text('mailRelayConnectWaiting')} : null} +
+ ) : null} {relay.tokenSource === 'option' ? null : (