Files
ipal-kit/src/modules/email/relay/constants.ts
T
Radosław SmolińskiandClaude Fable 5.2 fef2c51bae Mail relay: contract 1.7.0 — X-Intecion-Site on every request with a token, host-mismatch
contracts/mail-relay refreshed from IWDL 6cd99f7 (64 files). A token the service knows as another
site's is forgotten without revoking and the site enrols as itself; a hand-issued one is refused.
The fake requires the header and answers host-mismatch.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 22:13:58 +01:00

102 lines
4.4 KiB
TypeScript

/**
* The Intecion Notifications Webservice, as the plugin knows it. No secret is here and none is in the
* package: a site gets its own token by enrolling (enrol.ts). The wire contract these values come from
* is copied in `contracts/mail-relay/` (test/mailRelayContract.test.ts fails on a hand-edited copy).
*/
/** Base address: host and path together, joined with a path as text. Override: `mail: { relay: { url } }`. */
export const RELAY_BASE_URL = 'https://webservices.intecion.net/mail'
/** The version of the copied contract this client speaks (`contracts/mail-relay/VERSION`). */
export const RELAY_CONTRACT_VERSION = '1.7.0'
/** The `product` value of this plugin. */
export const RELAY_PRODUCT = 'iapl'
/** The service's name, for docs, logs and the doctor. */
export const RELAY_SERVICE_NAME = 'Intecion Notifications Webservice'
/** Its short name: what the admin panel calls it, in every language. The one place it is written. */
export const RELAY_SHORT_NAME = 'IWSN'
/** Where the service calls a site of this product back, under Payload's API route. Fixed by the contract. */
export const RELAY_CONFIRM_PATH = '/iapl/mail-relay/confirm'
/** Admin-only routes of the panel's status block. */
export const RELAY_STATUS_PATH = '/iapl/mail-relay/status'
export const RELAY_CONNECT_PATH = '/iapl/mail-relay/connect'
export const RELAY_DISCONNECT_PATH = '/iapl/mail-relay/disconnect'
/** Key of the site's token and state in `payload.kv`; the candidate token and the nonces hang off it. */
export const RELAY_KV_KEY = 'iapl:mail-relay'
export const RELAY_DEFAULTS = {
/** A visitor's lever: "forgot password" mail per address and per visitor in the window (accountMail option). */
accountMail: { perAddress: 5, perVisitor: 10, windowMinutes: 60 },
/** Requests for one message, the same key and bytes each time. */
attempts: 3,
/** One attempt, from sending the request to the end of the answer. */
attemptTimeoutMs: 30_000,
/** Calls to the confirm route per address a minute. */
confirmRateLimit: { max: 10, windowMs: 60_000 },
/** The enrolment call: the service's call-back has 8 seconds of it. */
enrolTimeoutMs: 15_000,
/** How long a site keeps the nonce of an enrolment it started. */
nonceTtlMs: 5 * 60_000,
/** After a refused enrolment the site does not ask again by itself for this long ("Connect again" does). */
refusalCooldownMs: 15 * 60_000,
/** How long the limits read from `/v1/status` are used before they are read again. */
statusTtlMs: 60 * 60_000,
/**
* Everything a send may take, enrolment and retries included: somebody waits for the request that sends
* the mail (a form's visitor). After it the message is reported and nothing more is tried.
*/
totalTimeoutMs: 10_000,
/** The same for a message with files: a 10 MB upload has to fit. */
totalTimeoutWithFilesMs: 30_000,
/** Other calls (status, rotate, revoke). */
timeoutMs: 10_000,
/** Waiting between the attempts for one message, in all. Wins over `retryAfter`. */
waitBudgetMs: 10_000,
} as const
/**
* What a send through the service can leave in `emailStatus.code` (Site integrations), each with a
* text in the editor's language. `relay-name-replaced` is a warning shown in the status block: the
* mail went out.
*/
export const RELAY_STATUS_CODES = [
'relay-pending',
'relay-suspended',
'relay-refused',
'relay-quota',
'relay-too-large',
'relay-attachment-refused',
'relay-recipient-suppressed',
'relay-unreachable',
'relay-not-confirmed',
'relay-disconnected',
'relay-error',
'relay-name-replaced',
] as const
export type RelayStatusCode = (typeof RELAY_STATUS_CODES)[number]
/** The site status for a code of the service (contract §1, "suggested site status"). */
export function relayStatusFor(code: string, retryable: boolean): RelayStatusCode {
switch (code) {
case 'attachment-refused':
return 'relay-attachment-refused'
case 'callback-failed':
case 'enrolment-closed':
case 'host-not-allowed':
return 'relay-refused'
case 'quota-exceeded':
case 'too-many-recipients':
return 'relay-quota'
case 'recipient-suppressed':
return 'relay-recipient-suppressed'
case 'site-pending':
return 'relay-pending'
case 'site-suspended':
return 'relay-suspended'
case 'too-large':
return 'relay-too-large'
default:
// A code this client does not know is acted on by `retryable` (contract §1).
return retryable ? 'relay-unreachable' : 'relay-error'
}
}