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

- the state block on the e-mail tab (method IWSN): the button while the service offers the confirmation page
  (connectAvailable) or before the site has enrolled; a click asks the site's server for the link
  (POST /api/iapl/mail-relay/connect-link, admin only), which asks the service (POST /v1/connect, enrolling first),
  checks that it begins with the service's own {base}/connect?, and hands it over without storing or logging it;
  the browser opens it in a new tab with noopener noreferrer; the block asks /v1/status every 5 s for 10 min
- states: waiting for confirmation (button), waiting for approval (no page), connected, stopped; 503
  connect-unavailable and 429 said in the admin's language; a load of the panel asks the service while the site waits
- dashboard alert for a waiting site (live); doctor mail-relay-connect (error) — replaces the pending warning and the
  "not enrolled yet" note of mail-relay-state
- opt-out mail.relay.connectButton: false (no button, no route); building blocks requestRelayConnectLink,
  isRelayConnectUrl, RELAY_CONNECT_LINK_PATH; the fake service implements /v1/connect, connectAvailable and
  confirmConnect
- contract copy 1.8.0 (IWDL working tree, checksums match); docs, AGENT.md, setup / upgrade / debug skills, changelog

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 21:42:23 +01:00
co-authored by Claude Opus 5.5
parent 347e3bafa1
commit 2c0262367d
41 changed files with 1113 additions and 57 deletions
+20 -3
View File
@@ -728,7 +728,7 @@ describe('iapl-doctor: first-seen dates', () => {
})
describe('e-mail: transport, the mail service, Graph, the confirm route', () => {
const ids = ['mail-transport', 'mail-method', 'mail-non-public', 'mail-relay-state', 'mail-reply-address', 'mail-graph-deprecated', 'mail-relay-route']
const ids = ['mail-transport', 'mail-method', 'mail-non-public', 'mail-relay-connect', 'mail-relay-state', 'mail-reply-address', 'mail-graph-deprecated', 'mail-relay-route']
const relay = (extra: object = {}) => ({ connected: true, disconnected: false, nameReplaced: false, state: 'active', ...extra })
const mail = (extra: object = {}) => ({ graphEnv: false, relay: relay(), replyAddress: true, status: null, transport: 'relay', ...extra })
const run = async (deep: null | object, files: Record<string, string> = {}) =>
@@ -747,12 +747,29 @@ describe('e-mail: transport, the mail service, Graph, the confirm route', () =>
expect(await run(failing('2026-10-27T09:00:00.000Z'))).toEqual(['mail-transport:error'])
})
test('mail-relay-connect: the method is IWSN and the site is not connected — an error, and the fix names the button or Intecion', async () => {
const find = async (deep: object) => (await doctor(project({ ...base(), 'src/payload.config.ts': 'iapl({ forms: {} })' }), ids, { deepStatus: { mail: mail(deep) } })).findings.filter((f) => f.rule === 'mail-relay-connect')
const button = await find({ relay: relay({ connectAvailable: true, state: 'pending' }) })
expect(button.map((f) => f.severity)).toEqual(['error'])
expect(button[0].message).toContain('not confirmed yet')
expect(button[0].fix).toContain('Połącz z IWSN')
const noButton = await find({ relay: relay({ state: 'pending' }) })
expect(noButton[0].fix).toContain('ask Intecion')
const never = await find({ relay: relay({ connected: false, state: undefined }) })
expect(never[0].message).toContain('not connected yet')
expect(never[0].fix).toContain('Połącz z IWSN')
// nothing for: connected and active, suspended, disconnected, a refused enrolment, another method
for (const deep of [{}, { relay: relay({ state: 'suspended' }) }, { relay: relay({ connected: false, disconnected: true }) }, { relay: relay({ connected: false, refusal: 'callback-failed', state: undefined }) }, { relay: relay({ connectAvailable: true, state: 'pending' }), transport: 'smtp' }]) {
expect(await find(deep), JSON.stringify(deep)).toEqual([])
}
})
test('mail-relay-state: disconnected, suspended, pending, refused, not enrolled yet, a replaced sender name', async () => {
expect(await run(mail({ relay: relay({ connected: false, disconnected: true }) }))).toEqual(['mail-relay-state:error'])
expect(await run(mail({ relay: relay({ state: 'suspended' }) }))).toEqual(['mail-relay-state:error'])
expect(await run(mail({ relay: relay({ state: 'pending' }) }))).toEqual(['mail-relay-state:warning'])
expect(await run(mail({ relay: relay({ state: 'pending' }) }))).toEqual(['mail-relay-connect:error'])
expect(await run(mail({ relay: relay({ connected: false, reason: 'redirect', refusal: 'callback-failed', state: undefined }) }))).toEqual(['mail-relay-state:warning'])
expect(await run(mail({ relay: relay({ connected: false, state: undefined }) }))).toEqual(['mail-relay-state:info'])
expect(await run(mail({ relay: relay({ connected: false, state: undefined }) }))).toEqual(['mail-relay-connect:error'])
// a copy of another site's database: it does not connect by itself, and the finding says what to do
const copy = await doctor(project({ ...base(), 'src/payload.config.ts': 'iapl({ forms: {} })' }), ids, { deepStatus: { mail: mail({ relay: relay({ connected: false, reason: 'client.pl', refusal: 'client-other-host', state: undefined }) }) } })
expect(rules(copy)).toEqual(['mail-relay-state:warning'])