import type { ClinicianInvitation } from "../../services/ClinicianInvitationService"; export type ResendReadBack = | { kind: "changed"; invitation: ClinicianInvitation } | { kind: "unknown" }; /** * A resend whose answer was lost is read back rather than repeated, since repeating it blind would kill the link * just sent and send a second. The read never proves the outcome: an unchanged invitation may still be rotated by the * request in flight, and a changed one may be another resend. So a change is shown as seen, and nothing is "not sent". */ export const readBackResend = async ( before: ClinicianInvitation, list: () => Promise, ): Promise => { try { const now = (await list()).find((each) => each.id === before.id); return now && now.expiresAt !== before.expiresAt ? { kind: "changed", invitation: now } : { kind: "unknown" }; } catch { return { kind: "unknown" }; } }; export const RESEND_UNCONFIRMED = "We could not confirm whether the invitation was sent again. Its link may have changed, so check the invitation before sending it again."; export const RESEND_CHANGED = "The invitation now has a new link and expiry, but we could not confirm it came from this attempt. Check it before sending it again.";