Mail relay: state block without an import-map entry, e2e on the reference site, sharper failure reports

- the state block is rendered by IntegrationStatusBanner (no new admin component: generate:importmap gives no diff)
- reference site: e2e/mail-relay.spec.ts with a fixture and setup script; e2e:built runs it with both bundlers
- a failed enrolment is reported as what it was; the service's own refusal after a fresh enrolment
- a message keeps its key after any failure that is not final
- a local site is shown as refused in the panel before any e-mail

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 21:14:47 +01:00
co-authored by Claude Fable 5.2
parent dd3792cbc7
commit 2cceceffd0
29 changed files with 1461 additions and 65 deletions
+10 -4
View File
@@ -170,10 +170,16 @@ export async function withRelayToken<T>(
const token = candidate?.token ?? stored.token
const enrolNow = async (): Promise<null | RelayRefusal> => {
if (!enrol || use.enrolled) {return refusal(LOCAL_CODES.noToken, 'The site is not connected to the mail service.')}
// once per message: a second request for it says again why the first enrolment failed
const failed = () => (use.enrolment && !use.enrolment.ok ? refusal(use.enrolment.code, use.enrolment.message, { reason: use.enrolment.reason, retryable: use.enrolment.retryable }) : null)
if (!enrol || use.enrolled) {return failed() ?? refusal(LOCAL_CODES.noToken, 'The site is not connected to the mail service.')}
use.enrolled = true
use.enrolment = await enrolRelay(payload, options)
return use.enrolment.ok ? null : refusal(use.enrolment.code, use.enrolment.message, { reason: use.enrolment.reason, retryable: use.enrolment.retryable })
if (use.enrolment.ok) {return null}
// The enrolment has no good answer, but the call-back may have delivered a token all the same (the
// service's answer was lost): try it — the service says at once whether it made that token valid.
if (round < 3 && (await readRelayCandidate(payload))) {return null}
return failed()
}
if (!token) {
@@ -191,7 +197,7 @@ export async function withRelayToken<T>(
continue
}
const failed = await enrolNow()
if (failed) {return use.enrolment ? failed : answer}
if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer}
continue
}
if (candidate) {
@@ -201,7 +207,7 @@ export async function withRelayToken<T>(
}
if (!answer.ok && answer.code === 'reverify') {
const failed = await enrolNow()
if (failed) {return use.enrolment ? failed : answer}
if (failed) {return use.enrolment && !use.enrolment.ok ? failed : answer}
continue
}
return answer