Events 3.1.0, Accounts 1.2.0, contracts 1.9.0: the move needs Accounts' email
A church moved sign-in to Accounts without email set up there: codes and password links couldn't be sent, sign-in failed with a 500, nobody could get in. - contracts 1.9.0: messaging.status/test/set (SMTP, WAWP; secrets sealed); people.ensure answers emailSent. - Accounts 1.2.0: SendError instead of a 500; WhatsApp codes fall back to email; forgot password says email isn't set up; setup only offers methods that work; messaging.* (test, save only what worked); test WhatsApp in admin; WAWP from .env. - Events 3.1.0: Settings -> Sign-in shows what Accounts can send and copies this site's SMTP/WAWP into it (secrets stay on the server), test then save; Move disabled and refused (EMAIL_NOT_READY) without email. Tests: Accounts 54, contracts 218, Events 774, test:accounts 16 (also on Postgres). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,9 @@ import { schemaName } from "./schema-name";
|
||||
* - **`import.*`**: moving a product's existing users into Accounts (Cross Events 3.0), with their
|
||||
* password hashes and authenticator secrets. Secret fields are sealed with the link's secret
|
||||
* (`sealLinkValue` in `@crosscode/contracts/signing`) on top of the request signature.
|
||||
* - **`messaging.*`** (1.9.0): whether Accounts can send email and WhatsApp (its sign-in codes and
|
||||
* links need them), and setting them up from a product: a test first, saved only if it worked.
|
||||
* The SMTP password and WAWP access token are sealed with the link's secret.
|
||||
* - **`people.*`**: what a product's admin can do to someone's account from the product (add a
|
||||
* person, change their name or email, reset 2FA, unlock, deactivate, news off from an
|
||||
* unsubscribe link). Accounts only acts on people the product knows (signed in through it or
|
||||
@@ -140,9 +143,46 @@ export const peopleSetActiveSchema = base.extend({ type: z.literal("people.setAc
|
||||
/** Only ever turns news off (an unsubscribe link); turning it on is the person's own choice in Accounts. */
|
||||
export const peopleNewsOffSchema = base.extend({ type: z.literal("people.newsOff"), ...onePerson, channel: z.enum(["email", "whatsapp", "all"]) });
|
||||
|
||||
// ─── messaging.* (contracts 1.9.0) ───────────────────────────────────────────
|
||||
|
||||
/** SMTP settings as Cross Events and Accounts both keep them (`smtp_*`). `pass` sealed; null: keep the saved one. */
|
||||
export const smtpSettingsSchema = z.object({
|
||||
host: z.string().trim().min(1).max(253),
|
||||
port: z.int().min(1).max(65535),
|
||||
secure: z.boolean(),
|
||||
user: z.string().max(254),
|
||||
pass: sealedValueSchema.nullable(),
|
||||
from: z.string().trim().min(3).max(320),
|
||||
});
|
||||
export type SmtpSettings = z.infer<typeof smtpSettingsSchema>;
|
||||
|
||||
/** WAWP (wawp.net) settings, as both keep them. `accessToken` sealed; null: keep the saved one. */
|
||||
export const wawpSettingsSchema = z.object({
|
||||
accessToken: sealedValueSchema.nullable(),
|
||||
instanceId: z.string().trim().min(1).max(200),
|
||||
});
|
||||
export type WawpSettings = z.infer<typeof wawpSettingsSchema>;
|
||||
|
||||
/** Whether Accounts can send email and WhatsApp now (never its secrets). */
|
||||
export const messagingStatusSchema = base.extend({ type: z.literal("messaging.status") });
|
||||
|
||||
/**
|
||||
* Sends a test with the settings given (not saved): an email to `email.to`, a WhatsApp message to
|
||||
* `whatsapp.to`. Each part is tried on its own; the answer says how each went.
|
||||
*/
|
||||
export const messagingTestSchema = base.extend({
|
||||
type: z.literal("messaging.test"),
|
||||
email: z.object({ settings: smtpSettingsSchema, to: emailSchema }).optional(),
|
||||
whatsapp: z.object({ settings: wawpSettingsSchema, to: phoneSchema }).optional(),
|
||||
});
|
||||
|
||||
/** Tests the settings given as messaging.test does, and saves each part only if its test worked. */
|
||||
export const messagingSetSchema = messagingTestSchema.extend({ type: z.literal("messaging.set") });
|
||||
|
||||
export const identityRequestSchema = z.discriminatedUnion("type", [
|
||||
importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema,
|
||||
peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema,
|
||||
messagingStatusSchema, messagingTestSchema, messagingSetSchema,
|
||||
]);
|
||||
export type IdentityRequest = z.infer<typeof identityRequestSchema>;
|
||||
export type IdentityRequestType = IdentityRequest["type"];
|
||||
@@ -188,10 +228,32 @@ export const peopleEnsureReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
sub: idSchema,
|
||||
created: z.boolean(),
|
||||
/** 1.9.0: whether the "choose your password" email went (false: Accounts' email isn't working). */
|
||||
emailSent: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const okReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEMA), ok: z.literal(true) });
|
||||
|
||||
/** messaging.status: what's set up (no secrets; `from` and `host` to recognise it). */
|
||||
export const messagingStatusReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
email: z.object({ ready: z.boolean(), host: z.string().nullable(), from: z.string().nullable() }),
|
||||
whatsapp: z.object({ ready: z.boolean(), instanceId: z.string().nullable() }),
|
||||
});
|
||||
export type MessagingStatusReply = z.infer<typeof messagingStatusReplySchema>;
|
||||
|
||||
/** One part's test: sent, or why not. `saved` only on messaging.set. */
|
||||
export const messagingResultSchema = z.object({ ok: z.boolean(), error: z.string().max(500).nullable(), saved: z.boolean() });
|
||||
|
||||
/** messaging.test / messaging.set: each part that was given, and the status after. */
|
||||
export const messagingTestReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
email: messagingResultSchema.nullable(),
|
||||
whatsapp: messagingResultSchema.nullable(),
|
||||
status: messagingStatusReplySchema.omit({ schema: true }),
|
||||
});
|
||||
export type MessagingTestReply = z.infer<typeof messagingTestReplySchema>;
|
||||
|
||||
/** Errors: `{ message, code }` as the other link calls. */
|
||||
export const IDENTITY_REQUEST_ERROR_CODES = [
|
||||
"NOT_LINKED", "BAD_SIGNATURE", "STALE_REQUEST", "INVALID_REQUEST", "NOT_MOVING", "WRONG_PRODUCT", "UNKNOWN_PERSON", "EMAIL_TAKEN", "NOT_ALLOWED",
|
||||
|
||||
Reference in New Issue
Block a user