IWSN: "Połącz z IWSN" — a person of Intecion connects the site (contract 1.8.0)

- 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 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 21:42:23 +01:00
co-authored by Claude Opus 5.5
parent 347e3bafa1
commit 2c0262367d
41 changed files with 1113 additions and 57 deletions
+21
View File
@@ -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.
+10 -5
View File
@@ -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
+71 -3
View File
@@ -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": "[email protected]" },
"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.
+1 -1
View File
@@ -1 +1 @@
1.7.1
1.8.0
@@ -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
}
}
@@ -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
}
}
@@ -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
}
}
@@ -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
}
}
@@ -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"
}
}
+1 -1
View File
@@ -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) {
+63 -1
View File
@@ -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"
]
}
]
}
}
}
}
}