Mail relay: the built-in client for the Intecion Notifications Webservice

Transport, enrolment with the confirm route, token and state in payload-kv, rotation,
the panel's state block, doctor rules, the fake service and the copied contract 1.5.0.
Tests against the contract's runner and the fake. Docs and HTTP tests follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 20:29:46 +01:00
co-authored by Claude Fable 5.2
parent 9efd86a06f
commit ea9703f8e3
97 changed files with 7720 additions and 48 deletions
+75
View File
@@ -0,0 +1,75 @@
# Changelog of the wire contract
## 1.5.0 — 2026-11-25 (not released; no tag yet)
After the third review.
- `new-recipients`: `account` mail is outside it; a form's confirmations may use four fifths of it.
- Failed sends: those in flight are counted in.
- Wording: `backend-failed`, `internal` and unknown codes mean "probably not sent"; the checklist asks a client
to limit "forgot password" itself.
## 1.4.0 — 2026-11-25 (never released)
After the second review.
- **Limits by kind:** `security-alert` has a budget of its own (`limit: "alerts"`, `limits.securityAlertsPerDay`)
outside hour and day; `account` mail may use the whole hour and day, every other kind four fifths. The
`quota` of a send answer is for that kind. `recipient` counts `form-confirmation` messages only.
- **The idempotency promise is now what the service does:** a key whose message was handed to the mail back end
is never sent again within 24 hours; when the result was not recorded it answers `in-progress` until then.
- **Failed sends** have a limit of their own: `429 rate-limited` after 60 in an hour.
- **Retrying:** three attempts, 30 seconds each, ten seconds of waiting in all; an enrolment on the way does
not count.
- **Subject:** U+200D, U+200C and U+00AD are allowed; everything else as before, with the rule a client strips by.
- Any mail of a site to Intecion's own address gets `[host]` in front of its subject.
- The confirm address: no redirect is followed — the usual causes and what to do; `given.quota` gains
`hour-share-used`.
## 1.3.0 — 2026-11-25 (never released)
- **The confirm path is fixed per product** (owner, 2026-11-25): `iapl` → `/api/iapl/mail-relay/confirm`,
`iawl` → `/?rest_route=/iawl/v1/mail-relay/confirm`. **`callbackPath` is gone from the enrolment request**
(a request that carries it is refused). A site that serves its API elsewhere has its path set by Intecion.
- Suppression is account-wide and stays so (owner, 2026-11-25): said in the code table.
## 1.2.0 — 2026-11-25 (never released)
After the first independent review. The wire format is the same; the text now has one reading where it had two.
- **Retrying:** at most three attempts in ten seconds, and the ten seconds win over `retryAfter`; "no answer"
and `in-progress` are reported as *not confirmed*, never as *not sent*.
- **Idempotency:** "the same body" is the same bytes; a client encodes a message once.
- **The confirm endpoint:** exactly `200` and the JSON object, at most 1024 bytes, within 8 seconds; the site
keeps its earlier token until `/v1/enrol` answers 200.
- **An answer that is not JSON** is `unavailable`, retryable.
- `Authorization: Bearer` in any case.
- **Schema:** `code` and `warnings` are open strings (new ones are minor changes); `to` is required unless the
kind is `security-alert`; recipients' `maxItems` is the service's bound, the site's limit is in `/v1/status`;
base64 is padded to a multiple of four (said in words: a pattern for it overflows on large files); lengths are
in code points.
- **Changed behaviour:** the per-recipient limit refuses `form-confirmation` only; a subject may not start with
the service's name in brackets; a `security-alert` gets the site's host in front of its subject;
`attachment-refused` names the file in `field` (suggested status `relay-attachment-refused`);
invisible characters (all of Unicode category Cf) are refused in subject and file names.
- Added: `limits.serverAddresses` in `/v1/status`; what happens beyond it.
- Before the first release tag, versions are development versions (§9).
## 1.1.0 — 2026-11-25 (never released)
- **The base address is `https://webservices.intecion.net/mail`**: one host for Intecion's web services, this
one under the path `/mail`. Paths in the contract are relative to the base address, as before; a client that
kept the base address as one constant changes that constant and nothing else.
- Added: `service.name` in the answer of `/v1/status` ("Intecion Notifications Webservice").
- The service sends from `[email protected]` (owner, 2026-11-25).
Minor, by the contract's own rule (§9): an answer field was added. No copy of 1.0.0 was released; a client that
copied it during development copies the folder again.
## 1.0.0 — 2026-11-25 (never released)
First version: `/v1/enrol` with the call-back and its confirmation, `/v1/send`, `/v1/status`, `/v1/rotate`,
`/v1/revoke`, `/health`; the error codes; the examples and the runner.
Differs from the design proposal (draft 4) in one visible point: the site's confirm endpoint answers `200` with
a `confirmation` (SHA-256 of nonce and token), not a bare `204`. Reason: `services/mail-relay/DECISIONS.md`, D1.
+62
View File
@@ -0,0 +1,62 @@
8573bc968031c595b4e06f6694dd50e1d8e813255023b0397922352dcbc0a758 README.md
fc5bd405549ceffe38e47de8e30ce4041556559fd65fb7aa4097c26fb494e9e5 CHANGELOG.md
acb57a7135b2d7d6e665f67f056e21353023b93835f54def1ae523bf76f1bfb3 VERSION
275ee643112eac77430dba9ea3f93c8f53dc1676b8d56ba95a25dd3f35a8746f schema.json
be56a59e13474a8184576fef90cc01145cc3233886d4147e2ac2b867921fba1d runner.mjs
7c46860adee597e570832c72bcdb418752a20b9f7d1b2d7a656ed065f9632b2a checksums.mjs
df6015faf02a7cf7e9b5816b9e22b2e82968678ddd72a61c1f9665a8c0897ddf examples/callback-confirm-wordpress.json
f5018ca4fb7d25794ee92168d715aaf47feeba3d907c0550651b16c10a691ceb examples/callback-confirm.json
27bd95712cc36a71519cddc52c03d857b1009c2c384940dbc052022d86bc4231 examples/callback-unknown-nonce.json
de693b060c10c3d0f88fb8edfcd38c491cf141628d747328beee1b50c700c19b examples/enrol-address-literal.json
7c4cf75eb9ab156a3031336ab2688e7c9dcd4cd266b7b7e5e4592285dcbd25ba examples/enrol-callback-no-content.json
64466afc5bf0fecfa36f986d973cd987bbe1f64867e01cdf35e0de40838eb0d1 examples/enrol-callback-not-found.json
0000bcb2b3b676e4fda6c30b8de6e062c88f98c1fa2cc9f75bcd350d65dc0db4 examples/enrol-callback-path-given.json
8b522f16bc9b9980a5c849e94cea35fb268b0ba664dcd5a2e8e0fedd67c2c034 examples/enrol-callback-redirect.json
1e6483ebd85e3851848357266d8e16628a70420428b30d3ddb15253cdc2d9a0d examples/enrol-callback-wrong-confirmation.json
f64e4c75ced60e70b0f2f8e16adbde151be888fe5ac75813cdbe7eb5ecf8a00b examples/enrol-from-browser.json
218f463c95fd79868916390d4616c796d66154398a9864615f9ad0768f801aff examples/enrol-listed-active.json
b628eb5b30e693767e6830de58e0fd172497336f67b76a49a5fb06bfa626c481 examples/enrol-localhost.json
93304590382de5153a47fa88ee98356d0a5ba8039e195959291acd3c33e4a406 examples/enrol-short-nonce.json
e86e6ab23088c1c985ba18f287f66b49c50f51a584a7ca679b8b768597130efd examples/enrol-suspended.json
fe38f1fd1394a7fd42b1a1b0b74aa604578f17ab52590bf95a462a0c0f7d6087 examples/enrol-unlisted-pending.json
b9f71fe993dc39bdbc07e775e925a37175e18e1682fd8bffcc72b3581919be17 examples/health.json
5dff4194764f6f61b01a3f7f504907e578306a486d214e22d1a70b1a207e5ca3 examples/not-found.json
7df29aaf11934bb3a73f6899c66c4f73cfcc048c804ca52871b60376323cb222 examples/revoke-ok.json
148ae206781250f5de72d8d8f024fb1a0ba9c61c3f14c2866cdbda5244940097 examples/rotate-ok.json
81b6eeec98cdc35860241b1a958ab35cf6de2872bf1ffcdb24629156f5308996 examples/rotate-previous-token.json
2e9b2d088310ed1965639ad48e3aa4753ca277bb4c7119b8b58b082d25a5f46c examples/send-attachments-too-large.json
3585fde1439db56351a99c40e8262f606a3884eb4035546c76591279adbba0e8 examples/send-backend-failed.json
938761bbe576ca2da017cff8a42c4586bee971b9f5ce27a2fa024f7643fa1d3e examples/send-bearer-any-case.json
dbfdf96f791057e7a228330dba706cdcdf07f87d46d37734e2f4a3a49d557db0 examples/send-day-quota.json
93455791565a0b2f8d464aed858cc470a014bf16c943d3883383a145e43424f9 examples/send-display-name-recipient.json
01d7927fa99572fee0adf73c9d079ca7a544c3bf90d90c068e4b85137b59b53d examples/send-executable-attachment.json
54db430c75ae132fda615f5a27a2e8d0f53157acdceedaba2c035edd1938f0e9 examples/send-from-browser.json
650c8a79f38901e0027d3e105ad8e8edaab776f091011930093b7b1bc96bad66 examples/send-from-field.json
f9db7bdf34887406fdf80e037c83212e9523c553a2566fe7d1a9411a491cd85c examples/send-headers-field.json
5679e08b88d2206dc6810f73bb2139a8f7f46b7fd0470420081f8543e4466889 examples/send-hour-quota-account.json
40828edcba271529de9d452239fb218afc63a1dd6606c5e201ad622f2748ba09 examples/send-hour-quota.json
60e2eb9841a379c3985ae53e0c821a9e8a6f1de1cffc41f55f63a2bf91ffb315 examples/send-key-reused.json
6b10a5fce8dc51188cad654804bf742d9221e3825f04c688d724c2c8893bc2af examples/send-no-sender-name.json
1c37294029f41bb3953245950bde50ef6f550f9459aa16df525d4f8897f6f610 examples/send-no-token.json
3408947e979677ab07bdac2939c716083c78bdf75ac0e06993cc68fcdbae071f examples/send-ok.json
3660c55e7a359183793fd06c73a8c8c1529670e720cd9aa933a0a915b7f18a9f examples/send-pending.json
cec3126afeffbc18ee02a23556c184dc9195f05a0fc9cff8a31be7bbd444a557 examples/send-previous-token.json
b3b8ca0aae457e1d7afaa557b73ba1ab9c6c6427727c5d159e5290427f05ad8c examples/send-recipient-quota-other-kinds.json
9ac1a9cccea648f5a54c55abd7d2271ac8b1916d789138f09bbacff1960c45eb examples/send-recipient-quota.json
84d37df95af790ade19255736868fc38295e2674082dfec1c13f64031f88571c examples/send-recipient-suppressed.json
5243b6a33a200c4e57f1f32bf285bd7a1499663e3073462e057548c2e1201d9f examples/send-replay.json
40b86320ccfbe321b2831672035df618b4f5a6b3a70e398260698b4690b9c9a8 examples/send-security-alert.json
af073fb884954c55f606fd2c6f7dc0bbedc29ec6b0daff4c77e91c16c129ac6d examples/send-sender-name-replaced.json
bf0ce766240ad5df96176a8a6e0f54e7eaa533262657c8105ce342f957f156fb examples/send-subject-direction-mark.json
47824ad6a90c27da507a98fef4e31486f8fac445d4f0657c6f98312752884da0 examples/send-subject-imitates-service.json
85d43f2c6855accbece8bf09c281544355421de308850846fe28b7aa457fab21 examples/send-subject-line-break.json
be98bd6277fadc03eacfa901ac15c9f69895ddfb3b01fbf40d849e9eeded61fe examples/send-subject-visitor-text.json
a5dddf15899dfb6d7212b63f5bc32819d7f35a14872daae4f46324555bffa0e1 examples/send-suspended.json
bcf24c613cfb4eb223667ab2eee8ca6ebe91a6f97b86e6545b9d9316c63ca728 examples/send-text-plain.json
725fc1f4b059dc192f49955f67df4263f4a67f618b7314ca87ddfd7647e4514e examples/send-to-intecion-marked.json
aac0a3d17fe69e8d6c0adbcd3513650c2802b7f43c2103d5cd3de5a0346456c0 examples/send-too-many-recipients.json
4833a6b7cf81eba320f20c33fd44cb990681144186218332c2fb97a043b774cf examples/send-unknown-address.json
1ad0d24c691ab35b5603d63f5b29c5a3a3e50265aea9524fd26d314c0b7c1437 examples/send-unknown-token.json
cd2812d7b33698851116dd96fc1019e7ddfcc7f0b14511c6fa8f1b94acbfdb7e examples/status-active.json
e1bbb759fc3f7084d4bc027fa7d490cf0d24bc8ca124bd9a82e5dde372eb7bcd examples/status-pending.json
daaf53c17b92e61049b230e6a91edf9450967d920c05d23b3da67959e27474e4 examples/status-unknown-address.json
+472
View File
@@ -0,0 +1,472 @@
# Intecion Notifications Webservice — wire contract
Version: see [`VERSION`](VERSION) (this text describes **1.5.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
the `product` field. A client written from this document, in any language, works with the service.
| File | What |
|---|---|
| `README.md` | This document. Where it and the schema disagree, the schema wins and that is a bug to report |
| `schema.json` | JSON Schema (2020-12) of every body, under `$defs` |
| `examples/*.json` | One request and its answer per file, with the state it needs. They are the contract tests |
| `runner.mjs` | Runs the examples against anything that speaks the contract. No dependency; works in Node and in the Workers runtime |
| `checksums.mjs`, `CHECKSUMS` | SHA-256 of every file above, to detect a hand-edited copy |
| `VERSION`, `CHANGELOG.md` | Semantic version of the contract and what changed |
## 1. Basics
- **Base address: `https://webservices.intecion.net/mail`** — a client keeps it as one constant, host and path
together. Every path in this document and in the examples is relative to it: `POST /v1/send` is
`POST https://webservices.intecion.net/mail/v1/send`, `GET /health` is `…/mail/health`. A client joins the
base address and the path as text; it never resolves a path against the host alone.
- HTTPS only. Bodies are JSON in UTF-8. A request with a body carries `Content-Type: application/json`.
- **The service is for servers, not browsers.** It sends no CORS header, and it refuses any request that
carries an `Origin` header or a `Sec-Fetch-Site` header other than `none` (`403 browser-not-allowed`).
- **Requests are closed:** an unknown field is refused with `400 invalid-request` and the field's name. A
client cannot set `From`, `Sender`, `Return-Path` or any free header — there are no such fields.
- **Answers are open:** a client ignores fields it does not know.
- A client identifies itself with `User-Agent: <product>/<version>` (not checked, used for the log).
- **An answer that is not JSON** — an error page of the network in front of the service, an empty body, a cut-off
answer — is treated exactly like `503 unavailable` with `retryable: true`, whatever its status.
### Answers
Success is status `200` and a body with `"ok": true`.
Every refusal has the same body ([`Error`](schema.json)) — with one exception: `/health` answers only
`{ "ok": false }`.
```json
{ "ok": false, "code": "quota-exceeded", "message": "…", "retryable": false, "limit": "hour", "retryAfter": 1260 }
```
- `code` is what a client acts on. `message` is English text for a log or an administrator; never show it to a visitor.
- **`retryable` decides whether to try again, not the status.** `429 quota-exceeded` is not retryable;
`429 rate-limited` is.
- `retryAfter` (seconds) is also sent as the `Retry-After` header.
- The list of codes grows with minor versions. A client that meets a code it does not know acts on `retryable`
and shows the `message` to an administrator.
### All codes
| Status | `code` | Meaning | Retry | What a client does | Suggested site status |
|---|---|---|---|---|---|
| 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-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` |
| 403 | `browser-not-allowed` | The request came from a browser | no | — | — |
| 404 | `not-found` | No such route | no | Report a bug | — |
| 405 | `method-not-allowed` | Wrong method | no | Report a bug | — |
| 409 | `enrolment-in-progress` | Another enrolment for this host is running right now | **yes** | Wait `retryAfter`, read your own store again (another process may have the token by now), enrol only if still without one | — |
| 409 | `in-progress` | A send with this `Idempotency-Key` is running right now — or was handed to the mail back end and its result was never recorded (then `retryAfter` is long, and the message may be out) | **yes** | Retry with the same key within the ten seconds; then report "not confirmed" | — |
| 409 | `idempotency-conflict` | This `Idempotency-Key` was used for a different message | no | Report a bug | — |
| 409 | `already-rotated` | `/v1/rotate` with a token that is no longer the current one | no | Read your own store again; if it has no newer token, enrol again | — |
| 413 | `too-large` | `limit` says what: `request`, `body` or `attachments` | no | Show it | `relay-too-large` |
| 415 | `unsupported-media-type` | Not `application/json` | no | Report a bug | — |
| 422 | `callback-failed` | Enrolment: the site's confirm endpoint did not confirm; `reason` is `unreachable`, `timeout`, `redirect`, `status` or `confirmation` | no | Show it, with the reason: firewall or wrong public host (`unreachable`, `timeout`); the site answers the confirm address with a redirect (`redirect`, §2); the endpoint is missing, blocked, or served at another path than its product's (`status`); something prints around the JSON (`confirmation`) | `relay-refused` |
| 422 | `too-many-recipients` | More than the allowed number in To, CC and BCC together | no | Show it | `relay-quota` |
| 422 | `attachment-refused` | A file type the service never carries, or a bad file name; `field` says which file (`attachments[0]`) | no | Show it; the message can be sent without that file | `relay-attachment-refused` |
| 422 | `recipient-suppressed` | The back end refuses one of the recipients (it bounced or complained before — for any site: **the suppression list is one for the whole service, and there is none per site**; an address that bounced for one client's site is refused for every other site too, until Intecion removes it). **Nothing was sent, to anybody.** The service is not told which address it is | no | Show it. With several recipients a client may send to each alone, each with a new key, to find the one | `relay-recipient-suppressed` |
| 429 | `rate-limited` | Too many requests from this address — or too many of this site's sends were refused or failed at the mail back end within the hour (60; a send that fails costs no quota, so it has a limit of its own; account mail and alerts are counted apart from the rest) | **yes** | Wait `retryAfter`; when that is longer than the ten seconds, report | `relay-unreachable` if it persists |
| 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 |
| 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
the IAPL design uses; a product may name its own. The warning `sender-name-replaced` (below) maps to
`relay-name-replaced`.
**Retrying — the one rule.** A client makes at most **three attempts** for one message, the same
`Idempotency-Key` and the same bytes each time, and only after an answer with `retryable: true` (or no usable
answer at all). Between the attempts it waits **at most ten seconds in all**. **The ten seconds win over
`retryAfter`:** when `retryAfter` is longer than what is left of them, the client stops at once and reports.
- **One attempt** has a time-out of **30 seconds** from sending the request to the end of the answer (a 10 MB
attachment has to fit). An attempt that times out counts as "no answer".
- **An enrolment made on the way** — because the client had no token, or got `invalid-token` or `reverify` — is
not one of the three attempts and its time (up to 10 seconds: the call-back has 8) is not part of the ten
seconds. A client enrols at most once per message.
What the client reports:
| The last thing that happened | The message | Report |
|---|---|---|
| `200` | was accepted | sent |
| A refusal with `retryable: false` | was not sent | the status of that code |
| `rate-limited`, `unavailable`, `enrolment-in-progress` | was not sent | `relay-unreachable` |
| `backend-failed`, `internal`, or a code the client does not know | **probably** not sent — the mail back end failed in a way it does not explain, and it does not say whether such a message can still go out | `relay-unreachable`, worded as "probably not sent". Like the next row: the same key and bytes if it is tried again |
| **No answer** (time-out, connection lost), or `409 in-progress` | **may have been sent** — the service cannot say yet, or will never be able to | `relay-unreachable`, worded as "not confirmed", never as "not sent". If the client tries this message again later it uses the **same key and bytes**: within 24 hours of the first attempt that cannot produce a second mail — once the service has handed a message to the mail back end, its key either answers with the result or goes on answering `in-progress`; it is never sent again. A client never sends the message under a new key by itself |
## 2. Enrolment — `POST /v1/enrol`
A site gets its token by proving that it is served at its host. No authentication, nothing to type.
1. The site makes a random **nonce** (32 to 128 characters of `A–Z a–z 0–9 _ -`; at least 128 bits of
randomness), keeps it for 5 minutes, and sends:
```json
{ "host": "example.com", "nonce": "…", "product": "iapl", "productVersion": "1.17.0" }
```
- `host`: the site's public DNS name, lowercase, punycode. No scheme, port, path, address literal, single
label, or private suffix (`.local`, `.internal`, `.test`, `localhost` …).
- There is **no call-back address in the request.** Where a site is called back is fixed per product
(below); a request that names a path is refused (`400`, field `callbackPath`).
2. Before it answers, the service calls the site: `POST https://<host><confirm path of the product>`, port 443,
no redirect followed, **8 seconds** for the whole exchange, body ([`CallbackRequest`](schema.json)):
```json
{ "nonce": "…", "token": "ims_…", "state": "active" }
```
3. **The site's confirm endpoint** accepts the call only if it holds exactly this nonce (compare in constant
time; single use; not expired). Then it stores the token and answers `200` with
```json
{ "confirmation": "<lowercase hex SHA-256 of nonce + \".\" + token>" }
```
In every other case it answers `404` and changes nothing. It is a public route: rate-limit it.
**Exactly this answer and nothing else.** Status `200` (not 201, not 204). The body is the JSON object alone,
UTF-8, at most 1024 bytes, the hex in lower case. Anything printed before or after it — a PHP notice, a
debug toolbar, a wrapper of the framework — makes the enrolment fail with `callback-failed`, reason
`confirmation`. The service reads no more than 1024 bytes and waits no longer than the 8 seconds.
**Which token.** The call-back arrives *before* `/v1/enrol` has answered. The site stores the new token
**beside** the one it has, and makes it the token it uses when `/v1/enrol` answers `200`. If that answer
never arrives, the site tries the new token on its next request and goes back to the earlier one on
`401 invalid-token` (the service may have failed after the call-back; the earlier token is then still good).
A site never throws a working token away for one it has not seen accepted.
4. The service checks the confirmation. Only then does the token become valid, the calling server's address
become one of the site's known addresses, and `/v1/enrol` answer `200`:
```json
{ "ok": true, "state": "active" }
```
`state` is `active` (the site may send) or `pending` (waiting for approval; sends answer `403 site-pending`
until Intecion approves, then the same token works). **The answer never carries the token.**
Why the confirmation, and not a bare `204`: plenty of ordinary endpoints answer "no content" to any POST (a
report collector, for one). Only an endpoint that knows the nonce *and* has read the token can compute the
confirmation, so nothing else on the host can be mistaken for the confirm endpoint.
Rules a client must know:
- **Enrolling again is the same call** and is how a site heals: after `401 invalid-token`, after `401 reverify`,
after a lost token. The earlier token stays valid for 24 hours (so other processes of the same site are not
cut off), the state is kept — a suspended site stays suspended (`403 site-suspended`, no call-back is made).
- A failed enrolment changes nothing on the service: tokens and addresses stay as they were.
- `409 enrolment-in-progress`: an enrolment for this host from this server is already running (or the
registry changed while the site was being called). It is retryable and is not counted against the site.
- **The confirm path is fixed per product**; a site cannot choose it:
| `product` | The service calls | Notes |
|---|---|---|
| `iapl` | `POST https://<host>/api/iapl/mail-relay/confirm` | Under Payload's default API route (`/api`) |
| `iawl` | `POST https://<host>/?rest_route=/iawl/v1/mail-relay/confirm` | WordPress's REST API addressed by query: the same address works with and without pretty permalinks. The route is `mail-relay/confirm` in the namespace `iawl/v1` |
The service calls **exactly that address and follows no redirect.** A site that redirects it fails with
reason `redirect` — the usual causes: the site adds or removes a trailing slash (Next.js `trailingSlash`),
sends `example.com` to `www.example.com` (enrol the host the site really answers on), or redirects `/` by
language. On WordPress, a security plugin or a setting that blocks or redirects `?rest_route=` gives
`status`. In each case either the site is changed to answer at the address, or Intecion sets the address it
does answer at (a path ending in `/confirm/`, for a site with trailing slashes).
**A project that serves its API somewhere else** — Payload with another `routes.api`, WordPress installed in a
sub-folder, a path prefix in front of the site — cannot say so in the request. Its path is set for its host
**by Intecion** (`ims callback-path <host> <path>`), before the site enrols; until then the enrolment fails
with `callback-failed`, reason `status`. A client shows that as "ask Intecion to set this site's confirm
address", with the address it serves. When an enrolled host confirms at another path than before, Intecion
is told.
- **Server addresses.** A site may send from a limited number of server addresses at a time
(`limits.serverAddresses` in `/v1/status`, 8 unless Intecion set another number). Each new address enrols by
itself after `401 reverify`; beyond the limit the address used longest ago is dropped and gets `reverify`
again. A site whose requests leave from many changing addresses (serverless hosting, a pool of egress
addresses) must have the limit raised by Intecion, or it will enrol in a loop.
- A site on `localhost` or behind a firewall cannot be called back. Intecion can issue a token by hand; the
site stores it the same way.
- Use the token only from the site's server. Never print it, never send it to a browser.
## 3. Sending — `POST /v1/send`
Headers (`Bearer` in any case; one space; then the token exactly):
```
Authorization: Bearer ims_…
Idempotency-Key: <16 to 128 characters of A–Z a–z 0–9 _ ->
Content-Type: application/json
```
Body ([`SendRequest`](schema.json)):
```json
{
"product": "iapl", "productVersion": "1.17.0",
"kind": "form-notification",
"to": ["[email protected]"],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "…", "html": "…",
"attachments": [{ "filename": "cv.pdf", "contentType": "application/pdf", "content": "<base64>" }]
}
```
- **`kind`** (required): `form-notification`, `form-confirmation`, `account`, `security-alert`, `system`, `test`.
Mail whose purpose the client does not know is `system`. **The kind decides which limits apply (§3.3), so a
client must set it truthfully for its own mail:** `account` only for mail to an account holder (password
reset, invitation), `form-confirmation` for mail to an address a visitor typed.
- **`to`, `cc`, `bcc`**: bare addresses (`name@domain`), ASCII, no display names. At least one `to` (for every
kind but `security-alert`). The total over the three lists is limited per site
(`limits.recipientsPerMessage` in `/v1/status`; the schema's 50 is only the service's upper bound).
- **`security-alert` is addressed by the service.** `to`, `cc` and `bcc` may be left out and are ignored;
whoever controls a site cannot redirect its alerts. The service puts the site's host in front of the
subject: `[example.com] …` — as it does for **any** mail of a site that has Intecion's own address among its
recipients.
- **`replyTo`**: one bare address. The sender address has no mailbox, so send one whenever a reply makes sense.
- **`senderName`**: the display name. Optional; without it the mail leaves under the site's host. See §3.1.
- **`subject`**: 1 to 300 characters, **no line breaks, no control characters, no characters that hide or
reorder text** — Unicode categories Cc, Zl, Zp, Co, lone surrogates, and Cf (zero-width space, direction
marks and overrides, word joiner, byte-order mark, tag characters) **except three that are ordinary text**:
the zero-width joiner U+200D (inside emoji), the zero-width non-joiner U+200C (Persian and other scripts) and
the soft hyphen U+00AD. A subject is often a visitor's own words: **the client strips what is not allowed
before sending** (a regular expression for it: `/[\p{Cc}\p{Zl}\p{Zp}\p{Co}\p{Cs}]|(?![\u200C\u200D\u00AD])\p{Cf}/gu`);
the service refuses, it does not repair, and a refused message is a lost one. A subject must not start with the
service's name in brackets (`[Intecion Notifications Webservice] …`): that is how the service's own notices
begin.
- **`text` and/or `html`**: at least one. Together at most `limits.maxBodyBytes` (UTF-8).
- **`senderName`**, **`subject`**: lengths are counted in characters (Unicode code points), not bytes.
- **`attachments`**: `content` is base64 (standard alphabet, padded to a multiple of four, no line breaks).
Decoded, all files together are at most `limits.maxAttachmentBytes`. File names: no path, no quotes, no
control or invisible characters. Programs and scripts are refused by extension
(`422 attachment-refused`, with `field` naming the file).
- The sender address is fixed by the service. It adds `X-Intecion-Site: <host>` and `X-Intecion-Product: <product>`
to the mail.
Answer ([`SendResponse`](schema.json)):
```json
{ "ok": true, "id": "…", "messageId": "…", "replayed": false,
"senderName": "Kancelaria Example", "warnings": [],
"quota": { "hour": { "limit": 30, "remaining": 29 }, "day": { "limit": 200, "remaining": 199 } } }
```
`200` means the back end accepted the message for delivery, not that it arrived.
### 3.1 The sender name
The service cleans the name and may replace it. A name that is not accepted is **not** a failed send: the mail
leaves under the site's host instead, and the answer carries `"warnings": ["sender-name-replaced"]` and the
name used in `senderName`.
Accepted: at most 64 characters; letters, digits, spaces and `. , & ' - ( ) /`; letters of one script only.
The guard errs on the careful side and will now and then replace an honest name (one that contains a word
from the list, or reads like a web address: "Dom.Pl"). **A client shows the warning in its panel, with the name
that was used,** so that the site's owner can choose another.
Not accepted: `@ < > " \`, anything that looks like an e-mail or web address (the site's own host is allowed),
and names on the service's list of names that are never a client's (mailbox providers, banks, "support",
"security", "administrator", "no-reply" …). The list is the service's and can change without a new contract
version.
### 3.2 `Idempotency-Key`
- One key per message; the same key on every retry of that message.
- **"The same body" means the same bytes.** A client encodes a message to JSON **once**, keeps those bytes with
the key, and sends exactly them on every retry. Encoding the same message again is not safe: another order of
the fields, `\/` instead of `/`, or other spacing is another body.
- The same key with the same bytes within 24 hours: no second mail; the first answer comes back with
`"replayed": true`.
- The same key with other bytes: `409 idempotency-conflict`.
- A send that was refused or failed does not use up its key.
### 3.3 Limits
A message that would pass a limit is refused whole with `429 quota-exceeded` and `limit`:
| `limit` | Counted | Applies to |
|---|---|---|
| `hour` | messages in the last 60 minutes | every kind but `security-alert`. **`account` mail may use all of it; every other kind only four fifths** (24 of 30), so that a busy or abused form cannot use up the room for a password reset |
| `day` | messages this UTC day | the same: four fifths (160 of 200) for everything but `account` |
| `alerts` | `security-alert` messages this UTC day | `security-alert` only: a budget of its own (`limits.securityAlertsPerDay`, 20), outside `hour` and `day` in both directions — alerts use up nothing else, and nothing else can use up the alerts |
| `recipient` | `form-confirmation` messages to one address this UTC day | `form-confirmation` only: it is for addresses a visitor typed into a form. Other mail to one address (a form's notification to the client's office) is never refused by it |
| `new-recipients` | addresses this site has not mailed in the last 30 days, this UTC day | every kind but `account` and `security-alert`. **A form's confirmations may use four fifths of it** (40 of 50); the rest is kept for the site's other mail, so that addresses a stranger invents in a form cannot keep a notification from an office the site has not written to for a month. `account` mail is outside it altogether: a password reset goes to whoever asked |
| `service` | all sites together this UTC day | every kind |
The numbers are the service's, per site, and are reported by `/v1/status` (`limits`; its `quota` is the whole
hour and day). The `quota` in the answer to a send is what is left **for a message of that kind**. A refused or
failed send costs no quota (failed ones are limited by themselves: 60 an hour per site, the sends that are
with the mail back end at that moment counted in, then `rate-limited`, §1). With a limit below
five nothing is set apart.
## 4. Status — `GET /v1/status`
`Authorization: Bearer ims_…`. Answers for a pending and a suspended site too, so a panel can say why mail does
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.5.0" },
"sender": { "address": "[email protected]" },
"limits": { "messagesPerHour": 30, "messagesPerDay": 200, "recipientsPerMessage": 10,
"perRecipientPerDay": 10, "newRecipientsPerDay": 50,
"maxBodyBytes": 512000, "maxAttachmentBytes": 10485760, "maxAttachments": 20 },
"quota": { "hour": { "limit": 30, "remaining": 30 }, "day": { "limit": 200, "remaining": 200 } },
"kinds": ["form-notification", "form-confirmation", "account", "security-alert", "system", "test"],
"token": { "issuedAt": "2026-11-25T10:00:00.000Z", "rotateAfter": "2027-02-23T10:00:00.000Z" } }
```
A client takes its attachment limit from `limits.maxAttachmentBytes`, never from a constant of its own.
## 5. Rotation — `POST /v1/rotate`
`Authorization: Bearer ims_…`, no body. When `token.rotateAfter` has passed (90 days after issue), the client
asks for a new token. The answer carries it ([`RotateResponse`](schema.json)):
```json
{ "ok": true, "token": "ims_…", "previousValidUntil": "2027-02-24T10:00:00.000Z" }
```
- Store the new token at once. The previous one stays valid for 24 hours.
- Only the **current** token can rotate. With several processes on one site, exactly one rotation wins; the
others get `409 already-rotated` and read the shared store again.
- If the answer is lost, the new token is lost: the old one works for 24 hours, then `401 invalid-token` leads
to a new enrolment. A client that gets `already-rotated` and finds no newer token in its store enrols again
at once instead of waiting for that.
## 6. Giving up the token — `POST /v1/revoke`
`Authorization: Bearer ims_…`, no body. Every token of the site stops working at once; `{ "ok": true }`. The
site's state is kept. To send again the site enrols again.
## 7. `GET /health`
No authentication. `200 { "ok": true }` or `503 { "ok": false }`, nothing else. For an uptime check, not for a client.
## 8. Authentication, in one place
- The token is `ims_` and 43 characters. It is opaque; the service keeps only its SHA-256.
- Every route except `/v1/enrol` and `/health` needs it, **and** needs the request to come from a server
address the site enrolled from (IPv6: the same `/64`). A good token from another address gets `401 reverify`
and nothing else — not even the site's state.
- A token belongs to one host and cannot act for another.
## 9. Versions
- `VERSION` is `major.minor.patch`. The major is the path prefix (`/v1`).
- **Minor:** something was added that an older client need not know — a new optional request field, a new
answer field, a new `kind`, a new error `code` (treat an unknown code by its `retryable`), a new warning.
For that reason `code` and `warnings` are open strings in the schema, not closed lists.
- **Before the first release** (the first `mail-relay-contract/v…` tag) these are development versions: any
change of behaviour bumps the minor, and nobody is promised that an older copy still works. From the first
tag on the rules above hold strictly.
- **Patch:** wording, examples.
- **Major:** anything else. The service keeps answering the previous major for as long as any released client
speaks it.
- `/v1/status` reports the contract version the service speaks. A client carries the `VERSION` of its copy.
## 10. The examples and the runner
Each file in `examples/` is one case:
```json
{
"id": "send-hour-quota",
"title": "…",
"given": { "site": "active", "quota": "hour-exhausted" },
"request": { "method": "POST", "path": "/v1/send",
"headers": { "authorization": "Bearer {{token}}", "idempotency-key": "{{idempotencyKey}}", "content-type": "application/json" },
"schema": "SendRequest", "body": { } },
"response": { "status": 429, "schema": "Error", "body": { "ok": false, "code": "quota-exceeded", "limit": "hour" } },
"then": { "mails": 0 },
"client": { "retry": false, "reEnrol": false, "status": "relay-quota" }
}
```
- **`given`** names the state the case needs; whoever runs the examples arranges it (table below).
- **`request`** is sent as written, after `{{name}}` is replaced. `schema` names the `$defs` entry the body
must match (left out when the body is wrong on purpose). `{ "$base64Bytes": n }` stands for the base64 of
`n` bytes.
- **`response.body`** is a subset: every field written must be there with that value; more may be there.
- **`then`** says what must be true afterwards: `mails` (how many messages reached the back end in this case)
and `mail` (fields of the one message).
- **`client`** says what a client does with this answer: `retry`, `reEnrol`, and the suggested site status.
Use it to test a client against a canned answer.
- `"direction": "service-to-site"` marks a case that describes the call-back: the request is what the
service sends, the response what the site's confirm endpoint answers.
### `given`
| Key | Values | Meaning |
|---|---|---|
| `site` | `none`, `pending`, `active`, `suspended` | State of `{{host}}` in the registry. Anything but `none` implies a token in `{{token}}` |
| `listed` | `true`, `false` | Enrolment: whether `{{host}}` is on Intecion's list |
| `callback` | `ok`, `not-found`, `wrong-confirmation`, `redirect`, `no-content` | Enrolment: how the site's confirm endpoint behaves. `no-content` answers a bare `204` |
| `token` | `current`, `unknown`, `previous`, `none` | Which token `{{token}}` is. `previous` is a token replaced less than 24 hours ago. `none`: the header is left out |
| `address` | `known`, `unknown` | Whether the request comes from an address the site enrolled from |
| `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 |
Variables: `{{host}}`, `{{token}}`, `{{nonce}}`, `{{idempotencyKey}}`, `{{recipient}}`, and — read from the
service — `{{senderAddress}}`, `{{alertRecipient}}`.
### Running them
```js
import { runExample } from './runner.mjs'
const driver = {
// Arrange `given`; return the variables for {{…}}.
async arrange(given, example) { return { host, token, nonce, idempotencyKey, recipient, senderAddress, alertRecipient } },
// Send one request to the thing under test.
async request({ method, path, headers, body }) { return { status, headers, body } },
// Optional: validate `value` against schema.json#/$defs/<name>; return a list of problems.
validate(name, value) { return [] },
// Optional: the messages that reached the back end since arrange().
async mails() { return [{ from, fromName, to, cc, bcc, replyTo, subject, headers }] },
}
for (const example of examples) await runExample(example, driver) // throws on the first mismatch
```
The service runs every example against the Worker under the local Workers runtime
(`services/mail-relay/test/contract.test.ts`). A client's local stand-in for the service runs the same files.
## 11. Using the contract in a client
Until a client lives in this repository it **copies** this folder (all of it, `CHECKSUMS` included) from a
`mail-relay-contract/v…` tag, and has one test that runs `node checksums.mjs --check` on the copy, so a
hand-edited copy fails. The copy's `VERSION` says which contract the client speaks.
Checklist for a client:
1. Constants: the base address, the contract version. No secret.
2. A confirm endpoint (public, rate-limited, `404` unless it holds the nonce, constant-time compare, single
use, answers the confirmation as the only output, keeps the earlier token until the new one is accepted).
3. A token store that is never readable from outside and never printed.
4. Enrol on the first send without a token, after `invalid-token` and after `reverify`. Guard against two
processes enrolling at once (`enrolment-in-progress`).
5. One `Idempotency-Key` per message and one encoding of it, both kept across retries; at most three attempts,
30 seconds each, ten seconds of waiting in all, only when `retryable`; an enrolment on the way does not
count; "no answer" and `in-progress` are reported as not confirmed, never as not sent.
6. **Limit what a visitor can make the site send as `account` mail.** "Forgot password" for an address somebody
types is a visitor's lever like a form: the service lets `account` mail use the whole hour and day and no
limit per address, so thirty requests use up the site's hour. The client's own limiter (per address and per
visitor) is what decides; the service cannot tell a wanted reset from an unwanted one.
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`.
9. Run the examples: the `client` block of each against canned answers, and the whole set against your local
stand-in.
+1
View File
@@ -0,0 +1 @@
1.5.0
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env node
// SHA-256 of every contract file, so a hand-edited copy is noticed.
// node checksums.mjs --check compare the files with CHECKSUMS (exit 1 on any difference)
// node checksums.mjs --write rewrite CHECKSUMS (only in the IWDL repository, when the contract changes)
// Node only, no dependency. Works on a copy of this folder anywhere.
import { createHash } from 'node:crypto'
import { readFileSync, readdirSync, writeFileSync, existsSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const here = dirname(fileURLToPath(import.meta.url))
const FIXED = ['README.md', 'CHANGELOG.md', 'VERSION', 'schema.json', 'runner.mjs', 'checksums.mjs']
function files() {
const examples = readdirSync(join(here, 'examples'))
.filter((f) => f.endsWith('.json'))
.sort()
.map((f) => `examples/${f}`)
return [...FIXED, ...examples]
}
function sums() {
return files()
.map((f) => `${createHash('sha256').update(readFileSync(join(here, f))).digest('hex')} ${f}`)
.join('\n') + '\n'
}
const mode = process.argv[2]
if (mode === '--write') {
writeFileSync(join(here, 'CHECKSUMS'), sums())
console.log(`CHECKSUMS written (${files().length} files)`)
} else if (mode === '--check') {
if (!existsSync(join(here, 'CHECKSUMS'))) {
console.error('CHECKSUMS is missing')
process.exit(1)
}
const want = new Map(
readFileSync(join(here, 'CHECKSUMS'), 'utf8').split('\n').filter(Boolean).map((l) => {
const [sum, name] = l.split(' ')
return [name, sum]
}),
)
const have = new Map(sums().split('\n').filter(Boolean).map((l) => {
const [sum, name] = l.split(' ')
return [name, sum]
}))
const problems = []
for (const [name, sum] of have) {
if (!want.has(name)) problems.push(`not in CHECKSUMS: ${name}`)
else if (want.get(name) !== sum) problems.push(`changed: ${name}`)
}
for (const name of want.keys()) if (!have.has(name)) problems.push(`missing: ${name}`)
if (problems.length) {
console.error(problems.join('\n'))
console.error('\nThe contract files do not match CHECKSUMS. Copy them again from IWDL; do not edit a copy.')
process.exit(1)
}
console.log(`contract ${readFileSync(join(here, 'VERSION'), 'utf8').trim()}: ${have.size} files match CHECKSUMS`)
} else {
console.error('usage: node checksums.mjs --check | --write')
process.exit(2)
}
@@ -0,0 +1,25 @@
{
"id": "callback-confirm-wordpress",
"direction": "service-to-site",
"title": "IAWL (WordPress) sites: the same call at the REST route addressed by query, which works with and without pretty permalinks",
"request": {
"method": "POST",
"path": "/?rest_route=/iawl/v1/mail-relay/confirm",
"headers": {
"content-type": "application/json"
},
"schema": "CallbackRequest",
"body": {
"nonce": "EXAMPLEnonceEXAMPLEnonceEXAMPLEnonce00000000",
"token": "ims_EXAMPLEtokenEXAMPLEtokenEXAMPLEtoken0000000",
"state": "active"
}
},
"response": {
"status": 200,
"schema": "CallbackResponse",
"body": {
"confirmation": "1d5818782053c1f5aae3f9abd898a530cf974c59526d240902c9e19619e0462b"
}
}
}
@@ -0,0 +1,25 @@
{
"id": "callback-confirm",
"direction": "service-to-site",
"title": "IAPL (Payload) sites: the call the service makes, and the only answer that enrols. confirmation = hex SHA-256 of nonce + \".\" + token",
"request": {
"method": "POST",
"path": "/api/iapl/mail-relay/confirm",
"headers": {
"content-type": "application/json"
},
"schema": "CallbackRequest",
"body": {
"nonce": "EXAMPLEnonceEXAMPLEnonceEXAMPLEnonce00000000",
"token": "ims_EXAMPLEtokenEXAMPLEtokenEXAMPLEtoken0000000",
"state": "active"
}
},
"response": {
"status": 200,
"schema": "CallbackResponse",
"body": {
"confirmation": "1d5818782053c1f5aae3f9abd898a530cf974c59526d240902c9e19619e0462b"
}
}
}
@@ -0,0 +1,21 @@
{
"id": "callback-unknown-nonce",
"direction": "service-to-site",
"title": "A call with a nonce the site does not hold: 404, nothing stored",
"request": {
"method": "POST",
"path": "/api/iapl/mail-relay/confirm",
"headers": {
"content-type": "application/json"
},
"schema": "CallbackRequest",
"body": {
"nonce": "UNKNOWNnonceUNKNOWNnonceUNKNOWNnonce00000000",
"token": "ims_EXAMPLEtokenEXAMPLEtokenEXAMPLEtoken0000000",
"state": "active"
}
},
"response": {
"status": 404
}
}
@@ -0,0 +1,33 @@
{
"id": "enrol-address-literal",
"title": "An address literal is not a host",
"given": {
"site": "none"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"body": {
"host": "192.0.2.10",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "host-not-allowed"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,37 @@
{
"id": "enrol-callback-no-content",
"title": "An endpoint that answers 204 to anything is not a confirm endpoint",
"given": {
"site": "none",
"listed": true,
"callback": "no-content"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "callback-failed",
"reason": "status"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,38 @@
{
"id": "enrol-callback-not-found",
"title": "Enrolment for a host whose confirm endpoint does not hold the nonce (a host the caller does not control) yields nothing",
"given": {
"site": "none",
"listed": true,
"callback": "not-found"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "callback-failed",
"reason": "status",
"retryable": false
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,37 @@
{
"id": "enrol-callback-path-given",
"title": "A site cannot say where it is to be called back: the path is fixed per product",
"given": {
"site": "none",
"listed": true,
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"body": {
"host": "{{host}}",
"callbackPath": "/api/iapl/mail-relay/confirm",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "callbackPath"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,37 @@
{
"id": "enrol-callback-redirect",
"title": "A redirect is never followed",
"given": {
"site": "none",
"listed": true,
"callback": "redirect"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "callback-failed",
"reason": "redirect"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,37 @@
{
"id": "enrol-callback-wrong-confirmation",
"title": "A 200 answer without the right confirmation does not enrol",
"given": {
"site": "none",
"listed": true,
"callback": "wrong-confirmation"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "callback-failed",
"reason": "confirmation"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,37 @@
{
"id": "enrol-from-browser",
"title": "A cross-site POST from a browser is refused",
"given": {
"site": "none",
"listed": true,
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json",
"origin": "https://evil.example.net"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "browser-not-allowed"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,36 @@
{
"id": "enrol-listed-active",
"title": "A host on Intecion's list enrols and is active at once; the answer has no token",
"given": {
"site": "none",
"listed": true,
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 200,
"schema": "EnrolResponse",
"body": {
"ok": true,
"state": "active"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,33 @@
{
"id": "enrol-localhost",
"title": "A local name cannot be enrolled",
"given": {
"site": "none"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"body": {
"host": "shop.localhost",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "host-not-allowed"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-refused"
}
}
@@ -0,0 +1,36 @@
{
"id": "enrol-short-nonce",
"title": "A short nonce is refused",
"given": {
"site": "none",
"listed": true,
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"body": {
"host": "{{host}}",
"nonce": "short",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "nonce"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,35 @@
{
"id": "enrol-suspended",
"title": "A suspended site cannot enrol its way back",
"given": {
"site": "suspended",
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "site-suspended"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-suspended"
}
}
@@ -0,0 +1,36 @@
{
"id": "enrol-unlisted-pending",
"title": "A host that is not on the list enrols and waits for approval",
"given": {
"site": "none",
"listed": false,
"callback": "ok"
},
"request": {
"method": "POST",
"path": "/v1/enrol",
"headers": {
"content-type": "application/json"
},
"schema": "EnrolRequest",
"body": {
"host": "{{host}}",
"nonce": "{{nonce}}",
"product": "iapl",
"productVersion": "1.17.0"
}
},
"response": {
"status": 200,
"schema": "EnrolResponse",
"body": {
"ok": true,
"state": "pending"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-pending"
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"id": "health",
"title": "Health says yes or no and nothing else",
"given": {},
"request": {
"method": "GET",
"path": "/health",
"headers": {}
},
"response": {
"status": 200,
"schema": "HealthResponse",
"body": {
"ok": true
}
}
}
@@ -0,0 +1,18 @@
{
"id": "not-found",
"title": "An unknown route",
"given": {},
"request": {
"method": "GET",
"path": "/v2/send",
"headers": {}
},
"response": {
"status": 404,
"schema": "Error",
"body": {
"ok": false,
"code": "not-found"
}
}
}
@@ -0,0 +1,26 @@
{
"id": "revoke-ok",
"title": "The site gives up its token",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/revoke",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 200,
"schema": "RevokeResponse",
"body": {
"ok": true
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,26 @@
{
"id": "rotate-ok",
"title": "The current token rotates; the answer carries the new one",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/rotate",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 200,
"schema": "RotateResponse",
"body": {
"ok": true
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,28 @@
{
"id": "rotate-previous-token",
"title": "A token that was already replaced cannot rotate",
"given": {
"site": "active",
"token": "previous"
},
"request": {
"method": "POST",
"path": "/v1/rotate",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 409,
"schema": "Error",
"body": {
"ok": false,
"code": "already-rotated"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,55 @@
{
"id": "send-attachments-too-large",
"title": "Attachments over the limit",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello.",
"attachments": [
{
"filename": "big.pdf",
"contentType": "application/pdf",
"content": {
"$base64Bytes": 10485761
}
}
]
}
},
"response": {
"status": 413,
"schema": "Error",
"body": {
"ok": false,
"code": "too-large",
"limit": "attachments"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-too-large"
}
}
@@ -0,0 +1,47 @@
{
"id": "send-backend-failed",
"title": "The back end fails; the client may retry with the same key",
"given": {
"site": "active",
"backend": "failure"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 502,
"schema": "Error",
"body": {
"ok": false,
"code": "backend-failed",
"retryable": true
}
},
"then": {
"mails": 0
},
"client": {
"retry": true,
"reEnrol": false,
"status": "relay-unreachable"
}
}
@@ -0,0 +1,47 @@
{
"id": "send-bearer-any-case",
"title": "The word \"Bearer\" in any case",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"replayed": false,
"senderName": "Kancelaria Example",
"warnings": []
}
},
"then": {
"mails": 1
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,48 @@
{
"id": "send-day-quota",
"title": "The daily limit refuses the message",
"given": {
"site": "active",
"quota": "day-exhausted"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 429,
"schema": "Error",
"body": {
"ok": false,
"code": "quota-exceeded",
"limit": "day",
"retryable": false
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-quota"
}
}
@@ -0,0 +1,45 @@
{
"id": "send-display-name-recipient",
"title": "Recipients are bare addresses",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"Jan <[email protected]>"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "to"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,53 @@
{
"id": "send-executable-attachment",
"title": "A program is never carried",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello.",
"attachments": [
{
"filename": "invoice.pdf.exe",
"contentType": "application/pdf",
"content": "TVqQAAMAAAA="
}
]
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "attachment-refused",
"field": "attachments[0]"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-attachment-refused"
}
}
@@ -0,0 +1,46 @@
{
"id": "send-from-browser",
"title": "A request with an Origin header is refused whatever the token",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json",
"origin": "https://evil.example.net"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "browser-not-allowed"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,46 @@
{
"id": "send-from-field",
"title": "The sender address cannot be set",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello.",
"from": "[email protected]"
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "from"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,48 @@
{
"id": "send-headers-field",
"title": "Free headers cannot be set",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello.",
"headers": {
"Return-Path": "[email protected]"
}
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "headers"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,45 @@
{
"id": "send-hour-quota-account",
"title": "When other mail has used its share of the hour, account mail (a password reset) still goes out",
"given": {
"site": "active",
"quota": "hour-share-used"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "account",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true
}
},
"then": {
"mails": 1
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,48 @@
{
"id": "send-hour-quota",
"title": "The hourly limit refuses the message and says so",
"given": {
"site": "active",
"quota": "hour-exhausted"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 429,
"schema": "Error",
"body": {
"ok": false,
"code": "quota-exceeded",
"limit": "hour",
"retryable": false
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-quota"
}
}
@@ -0,0 +1,46 @@
{
"id": "send-key-reused",
"title": "The same Idempotency-Key for another message",
"given": {
"site": "active",
"idempotency": "sent-other"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 409,
"schema": "Error",
"body": {
"ok": false,
"code": "idempotency-conflict"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,48 @@
{
"id": "send-no-sender-name",
"title": "Without a sender name the mail leaves under the host, with no warning",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"senderName": "{{host}}",
"warnings": []
}
},
"then": {
"mails": 1,
"mail": {
"fromName": "{{host}}"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,46 @@
{
"id": "send-no-token",
"title": "No Authorization header",
"given": {
"site": "active",
"token": "none"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 401,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-token"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": true,
"status": null
}
}
@@ -0,0 +1,60 @@
{
"id": "send-ok",
"title": "An active site sends one message",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"replayed": false,
"senderName": "Kancelaria Example",
"warnings": []
}
},
"then": {
"mails": 1,
"mail": {
"from": "{{senderAddress}}",
"fromName": "Kancelaria Example",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"subject": "New enquiry",
"headers": {
"X-Intecion-Site": "{{host}}",
"X-Intecion-Product": "iapl"
}
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,45 @@
{
"id": "send-pending",
"title": "A site waiting for approval sends nothing",
"given": {
"site": "pending"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "site-pending"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-pending"
}
}
@@ -0,0 +1,45 @@
{
"id": "send-previous-token",
"title": "A token replaced less than 24 hours ago still sends",
"given": {
"site": "active",
"token": "previous"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true
}
},
"then": {
"mails": 1
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,45 @@
{
"id": "send-recipient-quota-other-kinds",
"title": "Other mail to the same address is not refused by that limit (a form's notification to the client's office)",
"given": {
"site": "active",
"quota": "recipient-exhausted"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true
}
},
"then": {
"mails": 1
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,47 @@
{
"id": "send-recipient-quota",
"title": "A form's confirmation: one address gets only so many a day",
"given": {
"site": "active",
"quota": "recipient-exhausted"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-confirmation",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 429,
"schema": "Error",
"body": {
"ok": false,
"code": "quota-exceeded",
"limit": "recipient"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-quota"
}
}
@@ -0,0 +1,47 @@
{
"id": "send-recipient-suppressed",
"title": "The back end refuses a suppressed recipient",
"given": {
"site": "active",
"backend": "recipient-suppressed"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "recipient-suppressed",
"retryable": false
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-recipient-suppressed"
}
}
@@ -0,0 +1,46 @@
{
"id": "send-replay",
"title": "The same Idempotency-Key and body again: no second mail",
"given": {
"site": "active",
"idempotency": "sent-same"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"replayed": true
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,52 @@
{
"id": "send-security-alert",
"title": "A security alert is addressed by the service and marked with the site's host; the recipients in the request are ignored",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "security-alert",
"to": [
"[email protected]"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true
}
},
"then": {
"mails": 1,
"mail": {
"to": [
"{{alertRecipient}}"
],
"cc": [],
"bcc": [],
"subject": "[{{host}}] New enquiry"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,51 @@
{
"id": "send-sender-name-replaced",
"title": "A sender name that looks like an address is replaced by the host; the mail still goes out",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "PayPal <[email protected]>",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"senderName": "{{host}}",
"warnings": [
"sender-name-replaced"
]
}
},
"then": {
"mails": 1,
"mail": {
"fromName": "{{host}}"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-name-replaced"
}
}
@@ -0,0 +1,46 @@
{
"id": "send-subject-direction-mark",
"title": "A direction override in the subject is refused: the client strips such characters first",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "Invoice ‮fdp.exe",
"text": "Hello."
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "subject"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,46 @@
{
"id": "send-subject-imitates-service",
"title": "A subject that starts like one of the service's own notices is refused",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "[Intecion Notifications Webservice] example.com waits for approval",
"text": "Hello."
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "subject"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,46 @@
{
"id": "send-subject-line-break",
"title": "A line break in the subject (header injection) is refused, not repaired",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "Hello\r\nBcc: [email protected]",
"text": "Hello."
}
},
"response": {
"status": 400,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-request",
"field": "subject"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,50 @@
{
"id": "send-subject-visitor-text",
"title": "A subject with what visitors write — an emoji made of several, a soft hyphen — is carried as it is",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "👩‍💻 Straßen­bahn",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true,
"replayed": false,
"senderName": "Kancelaria Example",
"warnings": []
}
},
"then": {
"mails": 1,
"mail": {
"subject": "👩‍💻 Straßen­bahn"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,45 @@
{
"id": "send-suspended",
"title": "A suspended site sends nothing",
"given": {
"site": "suspended"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 403,
"schema": "Error",
"body": {
"ok": false,
"code": "site-suspended"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-suspended"
}
}
@@ -0,0 +1,45 @@
{
"id": "send-text-plain",
"title": "A form post (text/plain) is refused",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "text/plain"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 415,
"schema": "Error",
"body": {
"ok": false,
"code": "unsupported-media-type"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,50 @@
{
"id": "send-to-intecion-marked",
"title": "Any mail of a site that reaches Intecion's own address gets the site's host in front of its subject",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "system",
"to": [
"{{alertRecipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 200,
"schema": "SendResponse",
"body": {
"ok": true
}
},
"then": {
"mails": 1,
"mail": {
"to": [
"{{alertRecipient}}"
],
"subject": "[{{host}}] New enquiry"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,59 @@
{
"id": "send-too-many-recipients",
"title": "More than ten recipients over To, CC and BCC",
"given": {
"site": "active"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello.",
"cc": [
"[email protected]",
"[email protected]",
"[email protected]"
],
"bcc": [
"[email protected]",
"[email protected]"
]
}
},
"response": {
"status": 422,
"schema": "Error",
"body": {
"ok": false,
"code": "too-many-recipients"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-quota"
}
}
@@ -0,0 +1,47 @@
{
"id": "send-unknown-address",
"title": "A good token from a server address the site never enrolled from (a stolen token)",
"given": {
"site": "active",
"address": "unknown"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 401,
"schema": "Error",
"body": {
"ok": false,
"code": "reverify",
"retryable": false
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": true,
"status": null
}
}
@@ -0,0 +1,46 @@
{
"id": "send-unknown-token",
"title": "A token the service does not know",
"given": {
"site": "active",
"token": "unknown"
},
"request": {
"method": "POST",
"path": "/v1/send",
"headers": {
"authorization": "Bearer {{token}}",
"idempotency-key": "{{idempotencyKey}}",
"content-type": "application/json"
},
"schema": "SendRequest",
"body": {
"product": "iapl",
"productVersion": "1.17.0",
"kind": "form-notification",
"to": [
"{{recipient}}"
],
"replyTo": "[email protected]",
"senderName": "Kancelaria Example",
"subject": "New enquiry",
"text": "Hello."
}
},
"response": {
"status": 401,
"schema": "Error",
"body": {
"ok": false,
"code": "invalid-token"
}
},
"then": {
"mails": 0
},
"client": {
"retry": false,
"reEnrol": true,
"status": null
}
}
@@ -0,0 +1,35 @@
{
"id": "status-active",
"title": "Status of an active site",
"given": {
"site": "active"
},
"request": {
"method": "GET",
"path": "/v1/status",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 200,
"schema": "StatusResponse",
"body": {
"ok": true,
"state": "active",
"host": "{{host}}",
"product": "iapl",
"service": {
"name": "Intecion Notifications Webservice"
},
"sender": {
"address": "{{senderAddress}}"
}
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": null
}
}
@@ -0,0 +1,27 @@
{
"id": "status-pending",
"title": "Status answers for a pending site too",
"given": {
"site": "pending"
},
"request": {
"method": "GET",
"path": "/v1/status",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 200,
"schema": "StatusResponse",
"body": {
"ok": true,
"state": "pending"
}
},
"client": {
"retry": false,
"reEnrol": false,
"status": "relay-pending"
}
}
@@ -0,0 +1,28 @@
{
"id": "status-unknown-address",
"title": "Status gives nothing to a token from an unknown address",
"given": {
"site": "active",
"address": "unknown"
},
"request": {
"method": "GET",
"path": "/v1/status",
"headers": {
"authorization": "Bearer {{token}}"
}
},
"response": {
"status": 401,
"schema": "Error",
"body": {
"ok": false,
"code": "reverify"
}
},
"client": {
"retry": false,
"reEnrol": true,
"status": null
}
}
+160
View File
@@ -0,0 +1,160 @@
// Contract test runner for the Intecion Notifications Webservice.
// 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.5.0'
export class ContractError extends Error {
constructor(exampleId, message) {
super(`[${exampleId}] ${message}`)
this.name = 'ContractError'
this.exampleId = exampleId
}
}
/** The confirmation a site's confirm endpoint answers with: lowercase hex SHA-256 of nonce + "." + token. */
export async function confirmationFor(nonce, token) {
const bytes = new TextEncoder().encode(`${nonce}.${token}`)
const digest = await crypto.subtle.digest('SHA-256', bytes)
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('')
}
/** Base64 of `n` zero bytes, built without holding the bytes. */
export function base64OfBytes(n) {
const full = Math.floor(n / 3)
const rest = n % 3
return 'AAAA'.repeat(full) + (rest === 1 ? 'AA==' : rest === 2 ? 'AAA=' : '')
}
/** Replace {{name}} and { "$base64Bytes": n } everywhere in a value. Unknown names are an error. */
export function expand(value, vars, exampleId = '?') {
if (typeof value === 'string') {
return value.replace(/\{\{([A-Za-z]+)\}\}/g, (_, name) => {
if (vars[name] === undefined || vars[name] === null) {
throw new ContractError(exampleId, `the driver's arrange() gave no value for {{${name}}}`)
}
return String(vars[name])
})
}
if (Array.isArray(value)) return value.map((v) => expand(v, vars, exampleId))
if (value && typeof value === 'object') {
if (typeof value.$base64Bytes === 'number') return base64OfBytes(value.$base64Bytes)
const out = {}
for (const [k, v] of Object.entries(value)) out[k] = expand(v, vars, exampleId)
return out
}
return value
}
/** Every field of `expected` must be in `actual` with that value; `actual` may have more. Arrays must be equal. */
export function subsetMismatch(actual, expected, path = '') {
if (expected === null || typeof expected !== 'object') {
return Object.is(actual, expected) ? null : `${path || 'value'}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`
}
if (Array.isArray(expected)) {
if (!Array.isArray(actual) || actual.length !== expected.length) {
return `${path || 'value'}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`
}
for (let i = 0; i < expected.length; i++) {
const m = subsetMismatch(actual[i], expected[i], `${path}[${i}]`)
if (m) return m
}
return null
}
if (actual === null || typeof actual !== 'object') {
return `${path || 'value'}: expected an object, got ${JSON.stringify(actual)}`
}
for (const [k, v] of Object.entries(expected)) {
const m = subsetMismatch(actual[k], v, path ? `${path}.${k}` : k)
if (m) return m
}
return null
}
function headerLookup(headers) {
const out = {}
for (const [k, v] of Object.entries(headers ?? {})) out[k.toLowerCase()] = v
return out
}
/**
* Run one example (direction site-to-service) against a driver. Throws ContractError on the first mismatch.
* Returns { request, response, vars } for further checks by the caller.
*/
export async function runExample(example, driver) {
const id = example.id
if (example.direction === 'service-to-site') {
throw new ContractError(id, 'this example describes the call-back; use runCallbackExample()')
}
const given = example.given ?? {}
const vars = (await driver.arrange(given, example)) ?? {}
const headers = expand(example.request.headers ?? {}, given.token === 'none' ? { ...vars, token: '' } : vars, id)
if (given.token === 'none') delete headers.authorization
const body = example.request.body === undefined ? undefined : expand(example.request.body, vars, id)
if (example.request.schema && driver.validate) {
const problems = driver.validate(example.request.schema, body)
if (problems.length) throw new ContractError(id, `the example's request does not match ${example.request.schema}: ${problems.join('; ')}`)
}
const request = { method: example.request.method, path: example.request.path, headers, body }
const response = await driver.request(request)
if (response.status !== example.response.status) {
throw new ContractError(id, `status: expected ${example.response.status}, got ${response.status} ${JSON.stringify(response.body)}`)
}
if (example.response.schema && driver.validate) {
const problems = driver.validate(example.response.schema, response.body)
if (problems.length) throw new ContractError(id, `the answer does not match ${example.response.schema}: ${problems.join('; ')}`)
}
if (example.response.body !== undefined) {
const m = subsetMismatch(response.body, expand(example.response.body, vars, id))
if (m) throw new ContractError(id, `body: ${m}`)
}
if (response.body && response.body.ok === false) {
const got = headerLookup(response.headers)
if (typeof response.body.retryAfter === 'number' && got['retry-after'] !== undefined && String(got['retry-after']) !== String(response.body.retryAfter)) {
throw new ContractError(id, `Retry-After header (${got['retry-after']}) differs from retryAfter (${response.body.retryAfter})`)
}
if (example.client && typeof example.client.retry === 'boolean' && response.body.retryable !== example.client.retry) {
throw new ContractError(id, `retryable: expected ${example.client.retry}, got ${response.body.retryable}`)
}
}
const cors = headerLookup(response.headers)['access-control-allow-origin']
if (cors !== undefined) throw new ContractError(id, 'the service must not send CORS headers')
if (example.then && driver.mails) {
const mails = await driver.mails()
if (typeof example.then.mails === 'number' && mails.length !== example.then.mails) {
throw new ContractError(id, `mails handed to the back end: expected ${example.then.mails}, got ${mails.length}`)
}
if (example.then.mail) {
const m = subsetMismatch(mails[0], expand(example.then.mail, vars, id), 'mail')
if (m) throw new ContractError(id, m)
}
}
return { request, response, vars }
}
/**
* Run a call-back example against a site's confirm endpoint.
* `site.prepare(body)` makes the site hold (or not hold) the nonce; `site.confirm(request)` calls the endpoint.
*/
export async function runCallbackExample(example, site) {
const id = example.id
if (example.direction !== 'service-to-site') throw new ContractError(id, 'not a call-back example')
const holds = example.response.status === 200
await site.prepare({ ...example.request.body, held: holds })
const response = await site.confirm({ ...example.request })
if (response.status !== example.response.status) {
throw new ContractError(id, `status: expected ${example.response.status}, got ${response.status}`)
}
if (holds) {
const expected = await confirmationFor(example.request.body.nonce, example.request.body.token)
if (!response.body || response.body.confirmation !== expected) {
throw new ContractError(id, 'the confirmation is not hex SHA-256 of nonce + "." + token')
}
}
return response
}
+623
View File
@@ -0,0 +1,623 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://webservices.intecion.net/mail/contract/v1/schema.json",
"title": "Intecion Notifications Webservice — wire contract v1",
"description": "Bodies of every request and answer. Requests are closed (an unknown field is refused); answers are open (a client ignores fields it does not know).",
"$defs": {
"Host": {
"description": "A public DNS name, lowercase, punycode for international names. No scheme, port, path or address literal.",
"type": "string",
"minLength": 4,
"maxLength": 253,
"pattern": "^(?=.{4,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]([a-z0-9-]{0,61}[a-z0-9])$"
},
"Product": {
"description": "The client product. The list is the service's.",
"type": "string",
"enum": [
"iapl",
"iawl"
]
},
"ProductVersion": {
"type": "string",
"minLength": 1,
"maxLength": 32,
"pattern": "^[0-9A-Za-z][0-9A-Za-z.+_-]*$"
},
"Kind": {
"type": "string",
"enum": [
"form-notification",
"form-confirmation",
"account",
"security-alert",
"system",
"test"
]
},
"SiteState": {
"type": "string",
"enum": [
"pending",
"active",
"suspended"
]
},
"Address": {
"description": "A bare e-mail address. No display name, no angle brackets, no comment.",
"type": "string",
"minLength": 6,
"maxLength": 254,
"pattern": "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z]([A-Za-z0-9-]{0,61}[A-Za-z0-9])$"
},
"Nonce": {
"type": "string",
"pattern": "^[A-Za-z0-9_-]{32,128}$"
},
"Token": {
"description": "Opaque. Never logged, never shown.",
"type": "string",
"pattern": "^ims_[A-Za-z0-9_-]{43}$"
},
"Window": {
"type": "object",
"required": [
"limit",
"remaining"
],
"properties": {
"limit": {
"type": "integer",
"minimum": 0
},
"remaining": {
"type": "integer",
"minimum": 0
}
}
},
"Quota": {
"type": "object",
"required": [
"hour",
"day"
],
"properties": {
"hour": {
"$ref": "#/$defs/Window"
},
"day": {
"$ref": "#/$defs/Window"
}
}
},
"EnrolRequest": {
"type": "object",
"additionalProperties": false,
"required": [
"host",
"nonce",
"product",
"productVersion"
],
"properties": {
"host": {
"$ref": "#/$defs/Host"
},
"nonce": {
"$ref": "#/$defs/Nonce"
},
"product": {
"$ref": "#/$defs/Product"
},
"productVersion": {
"$ref": "#/$defs/ProductVersion"
}
},
"description": "No call-back path: the service calls the path fixed for the product (README §2)."
},
"EnrolResponse": {
"description": "Never carries the token: it went to the site's confirm endpoint.",
"type": "object",
"required": [
"ok",
"state"
],
"properties": {
"ok": {
"const": true
},
"state": {
"$ref": "#/$defs/SiteState"
}
},
"not": {
"required": [
"token"
]
}
},
"CallbackRequest": {
"description": "Sent BY the service TO the site's confirm endpoint: POST https://<host><the product's confirm path>.",
"type": "object",
"additionalProperties": false,
"required": [
"nonce",
"token",
"state"
],
"properties": {
"nonce": {
"$ref": "#/$defs/Nonce"
},
"token": {
"$ref": "#/$defs/Token"
},
"state": {
"$ref": "#/$defs/SiteState"
}
}
},
"CallbackResponse": {
"description": "The site's answer: status 200, a body of at most 1024 bytes that is this JSON object and nothing else, within 8 seconds. confirmation = lowercase hex SHA-256 of the UTF-8 text nonce + \".\" + token.",
"type": "object",
"required": [
"confirmation"
],
"properties": {
"confirmation": {
"type": "string",
"pattern": "^[0-9a-f]{64}$"
}
}
},
"Attachment": {
"type": "object",
"additionalProperties": false,
"required": [
"filename",
"contentType",
"content"
],
"properties": {
"filename": {
"type": "string",
"minLength": 1,
"maxLength": 255
},
"contentType": {
"type": "string",
"maxLength": 127,
"pattern": "^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$"
},
"content": {
"description": "Base64, standard alphabet, no line breaks, padded: the length is a multiple of four. The pattern states the alphabet only — a pattern that also stated the length would overflow regular-expression engines on a 10 MB file; the service checks the length.",
"type": "string",
"minLength": 4,
"pattern": "^[A-Za-z0-9+/]+={0,2}$"
}
}
},
"SendRequest": {
"type": "object",
"additionalProperties": false,
"required": [
"product",
"productVersion",
"kind",
"subject"
],
"properties": {
"product": {
"$ref": "#/$defs/Product"
},
"productVersion": {
"$ref": "#/$defs/ProductVersion"
},
"kind": {
"$ref": "#/$defs/Kind"
},
"to": {
"description": "Bare addresses. The number over to, cc and bcc together is limited per site: limits.recipientsPerMessage in /v1/status (the schema only states the service's upper bound).",
"type": "array",
"items": {
"$ref": "#/$defs/Address"
},
"maxItems": 50
},
"cc": {
"description": "Bare addresses. The number over to, cc and bcc together is limited per site: limits.recipientsPerMessage in /v1/status (the schema only states the service's upper bound).",
"type": "array",
"items": {
"$ref": "#/$defs/Address"
},
"maxItems": 50
},
"bcc": {
"description": "Bare addresses. The number over to, cc and bcc together is limited per site: limits.recipientsPerMessage in /v1/status (the schema only states the service's upper bound).",
"type": "array",
"items": {
"$ref": "#/$defs/Address"
},
"maxItems": 50
},
"replyTo": {
"$ref": "#/$defs/Address"
},
"senderName": {
"description": "At most 256 characters (Unicode code points).",
"type": "string",
"maxLength": 256
},
"subject": {
"description": "1 to 300 characters (code points). No line breaks, control characters or characters that hide or reorder text (README §3 has the exact rule and the three exceptions); must not start with the service's name in brackets.",
"type": "string",
"minLength": 1,
"maxLength": 300
},
"text": {
"type": "string",
"minLength": 1
},
"html": {
"type": "string",
"minLength": 1
},
"attachments": {
"type": "array",
"items": {
"$ref": "#/$defs/Attachment"
},
"maxItems": 20
}
},
"anyOf": [
{
"required": [
"text"
]
},
{
"required": [
"html"
]
}
],
"allOf": [
{
"if": {
"properties": {
"kind": {
"const": "security-alert"
}
},
"required": [
"kind"
]
},
"else": {
"required": [
"to"
],
"properties": {
"to": {
"minItems": 1
}
}
}
}
]
},
"SendResponse": {
"type": "object",
"required": [
"ok",
"id",
"replayed",
"senderName",
"warnings",
"quota"
],
"properties": {
"ok": {
"const": true
},
"id": {
"description": "The service's id of this message in its log.",
"type": "string",
"minLength": 1
},
"messageId": {
"description": "The back end's id, when it gave one.",
"type": "string"
},
"replayed": {
"description": "true when this Idempotency-Key was already sent and no second mail went out.",
"type": "boolean"
},
"senderName": {
"description": "The name the mail left under.",
"type": "string"
},
"warnings": {
"description": "Known today: sender-name-replaced. A client ignores a warning it does not know.",
"type": "array",
"items": {
"type": "string"
}
},
"quota": {
"description": "What is left for a message of the kind just sent.",
"$ref": "#/$defs/Quota"
}
}
},
"StatusResponse": {
"type": "object",
"required": [
"ok",
"state",
"host",
"product",
"service",
"sender",
"limits",
"quota",
"kinds",
"token"
],
"properties": {
"ok": {
"const": true
},
"state": {
"$ref": "#/$defs/SiteState"
},
"host": {
"$ref": "#/$defs/Host"
},
"product": {
"$ref": "#/$defs/Product"
},
"service": {
"type": "object",
"required": [
"version",
"contract"
],
"properties": {
"name": {
"description": "The service's name, for a panel to show.",
"type": "string"
},
"version": {
"type": "string"
},
"contract": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
}
}
},
"sender": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"$ref": "#/$defs/Address"
}
}
},
"limits": {
"type": "object",
"required": [
"messagesPerHour",
"messagesPerDay",
"recipientsPerMessage",
"perRecipientPerDay",
"newRecipientsPerDay",
"maxBodyBytes",
"maxAttachmentBytes",
"maxAttachments"
],
"properties": {
"messagesPerHour": {
"type": "integer",
"minimum": 0
},
"messagesPerDay": {
"type": "integer",
"minimum": 0
},
"recipientsPerMessage": {
"type": "integer",
"minimum": 1
},
"perRecipientPerDay": {
"type": "integer",
"minimum": 0
},
"newRecipientsPerDay": {
"type": "integer",
"minimum": 0
},
"maxBodyBytes": {
"type": "integer",
"minimum": 0
},
"maxAttachmentBytes": {
"type": "integer",
"minimum": 0
},
"maxAttachments": {
"type": "integer",
"minimum": 0
},
"serverAddresses": {
"description": "Server addresses the site may send from at a time.",
"type": "integer",
"minimum": 1
},
"securityAlertsPerDay": {
"description": "Security alerts a day: a budget of their own, outside the hour and day limits.",
"type": "integer",
"minimum": 0
}
}
},
"quota": {
"$ref": "#/$defs/Quota"
},
"kinds": {
"type": "array",
"items": {
"type": "string"
}
},
"token": {
"type": "object",
"required": [
"issuedAt",
"rotateAfter"
],
"properties": {
"issuedAt": {
"type": "string",
"format": "date-time"
},
"rotateAfter": {
"type": "string",
"format": "date-time"
}
}
},
"senderName": {
"description": "The name the last mail left under, when there was one.",
"type": "string"
}
}
},
"RotateResponse": {
"type": "object",
"required": [
"ok",
"token",
"previousValidUntil"
],
"properties": {
"ok": {
"const": true
},
"token": {
"$ref": "#/$defs/Token"
},
"previousValidUntil": {
"type": "string",
"format": "date-time"
}
}
},
"RevokeResponse": {
"type": "object",
"required": [
"ok"
],
"properties": {
"ok": {
"const": true
}
}
},
"HealthResponse": {
"description": "No detail on purpose — also when it says no: the one answer that is not an Error.",
"type": "object",
"additionalProperties": false,
"required": [
"ok"
],
"properties": {
"ok": {
"type": "boolean"
}
}
},
"ErrorCode": {
"type": "string",
"enum": [
"invalid-request",
"invalid-token",
"reverify",
"site-pending",
"site-suspended",
"host-not-allowed",
"enrolment-closed",
"enrolment-in-progress",
"callback-failed",
"browser-not-allowed",
"not-found",
"method-not-allowed",
"unsupported-media-type",
"idempotency-conflict",
"in-progress",
"already-rotated",
"too-large",
"too-many-recipients",
"attachment-refused",
"recipient-suppressed",
"rate-limited",
"quota-exceeded",
"backend-failed",
"unavailable",
"internal"
],
"description": "The codes the service answers with today. The list grows with minor versions; that is why Error.code is an open string."
},
"Error": {
"type": "object",
"required": [
"ok",
"code",
"message",
"retryable"
],
"properties": {
"ok": {
"const": false
},
"code": {
"description": "One of ErrorCode today. A client that meets a code it does not know acts on `retryable`.",
"type": "string",
"minLength": 1
},
"message": {
"description": "For a log or an administrator. English. Never shown to a visitor.",
"type": "string"
},
"retryable": {
"description": "true: the same request, with the same Idempotency-Key, may be sent again after a short wait.",
"type": "boolean"
},
"retryAfter": {
"description": "Seconds.",
"type": "integer",
"minimum": 0
},
"field": {
"description": "With invalid-request: the field at fault. With attachment-refused: which file, as attachments[n] (n from 0).",
"type": "string"
},
"limit": {
"description": "With quota-exceeded: hour, day, alerts, recipient, new-recipients or service. With too-large: request, body or attachments.",
"type": "string"
},
"reason": {
"description": "With callback-failed: unreachable, timeout, redirect, status or confirmation.",
"type": "string"
}
}
}
}
}