contracts 1.20.0: devotionals, Bible passages, messaging.get, WhatsApp opt-out, App export
The contracts for Church App 1.0.0 (docs/APP-1.0-PLAN.md §12). Additive. - crosscode.devotional/1, the Hub's devotionals reply, and the devotionals CSV import (parseCsv, checkDevotionalCsv, template), shared by the Hub and the App - Bible books (USFM, English and Afrikaans), seven translations with YouVersion ids and copyright lines, parseBibleReference, youVersionUrl - messaging.get and the messaging.changed hint; whatsapp.optout and whatsapp_opted_out on the profile - APP_MODULES, hub.DEVOTIONALS_PATH, agent.APP_DEMO_PROFILES, app in DEMO_PRODUCTS - the app section of the church export, people[].roles - Accounts refuses the two new requests until 1.9.0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,11 @@ import { churchObjectSchema, churchSchema } from "./church";
|
||||
* (`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.
|
||||
* The SMTP password and WAWP access token are sealed with the link's secret. 1.20.0 adds
|
||||
* `messaging.get` (the App sends with the church's settings) and the `messaging.changed` hint
|
||||
* back to the product.
|
||||
* - **`whatsapp.optout`** (1.20.0): a STOP to the church's WhatsApp number, passed on to Accounts,
|
||||
* which keeps the opt-out for every product.
|
||||
* - **`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
|
||||
@@ -237,6 +241,32 @@ export const messagingTestSchema = base.extend({
|
||||
/** 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") });
|
||||
|
||||
/**
|
||||
* 1.20.0 (APP-1.0-PLAN §8, decision 4): the church's email and WhatsApp settings, for a product
|
||||
* that sends with them but never asks for its own (the Church App). One set per church: kept in
|
||||
* Events or Accounts, copied to the others. The SMTP password and WAWP token come sealed with the
|
||||
* link's secret. Accounts remembers who asked, and sends each a `messaging.changed` when they
|
||||
* change (`MESSAGING_CHANGED_PATH`), so it fetches them again.
|
||||
*/
|
||||
export const messagingGetSchema = base.extend({ type: z.literal("messaging.get") });
|
||||
|
||||
/**
|
||||
* 1.20.0 (APP-1.0-PLAN §8, decision 11): someone replied STOP to the church's WhatsApp number.
|
||||
* Whichever product's webhook received it tells Accounts, which keeps the opt-out for every
|
||||
* product: it sets `whatsapp_opted_out` on each account with that verified number and sends
|
||||
* `user.updated` to every linked product. Only ever turns WhatsApp off; turning it back on is the
|
||||
* person's own choice in Accounts. Accounts also keeps a number without an account, so an account
|
||||
* made with it later starts opted out.
|
||||
*/
|
||||
export const whatsappOptOutSchema = base.extend({
|
||||
type: z.literal("whatsapp.optout"),
|
||||
phone: phoneSchema,
|
||||
/** When the reply arrived. */
|
||||
receivedAt: dateTimeSchema,
|
||||
/** The word they sent (`STOP`, `UNSUBSCRIBE`, `STOPP`), for the audit. */
|
||||
keyword: z.string().trim().min(1).max(40),
|
||||
});
|
||||
|
||||
/**
|
||||
* 1.9.0: use the product's look (name, logo, colours) on Accounts' pages. `overwrite: false` only
|
||||
* fills what Accounts doesn't have yet; `true` replaces it (an admin pressing the button).
|
||||
@@ -277,6 +307,7 @@ export const identityRequestSchema = z.discriminatedUnion("type", [
|
||||
importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema,
|
||||
peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema,
|
||||
peopleRemoveDemoSchema, peopleCheckSchema, messagingStatusSchema, messagingTestSchema, messagingSetSchema, churchBrandingSchema, churchUpdateSchema,
|
||||
messagingGetSchema, whatsappOptOutSchema,
|
||||
]);
|
||||
export type IdentityRequest = z.infer<typeof identityRequestSchema>;
|
||||
export type IdentityRequestType = IdentityRequest["type"];
|
||||
@@ -356,6 +387,46 @@ export const messagingTestReplySchema = z.object({
|
||||
});
|
||||
export type MessagingTestReply = z.infer<typeof messagingTestReplySchema>;
|
||||
|
||||
/**
|
||||
* messaging.get: the settings, secrets sealed with the link's secret; null for a part that isn't
|
||||
* set up (or doesn't work: `ready` false in messaging.status). `email.pass` null: the server
|
||||
* takes no password. `updatedAt`: the last change to either part.
|
||||
*/
|
||||
export const messagingGetReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
email: smtpSettingsSchema.nullable(),
|
||||
whatsapp: wawpSettingsSchema.extend({ accessToken: sealedValueSchema }).nullable(),
|
||||
updatedAt: dateTimeSchema.nullable(),
|
||||
});
|
||||
export type MessagingGetReply = z.infer<typeof messagingGetReplySchema>;
|
||||
|
||||
/** whatsapp.optout: how many accounts have the number (0 is fine: the number is kept anyway). */
|
||||
export const whatsappOptOutReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
accounts: z.int().nonnegative(),
|
||||
});
|
||||
export type WhatsappOptOutReply = z.infer<typeof whatsappOptOutReplySchema>;
|
||||
|
||||
// ─── Accounts → product: messaging.changed (1.20.0) ─────────────────────────
|
||||
|
||||
/** On the product's address. Signed with the link's secret (LINK_HEADERS). */
|
||||
export const MESSAGING_CHANGED_PATH = "/api/accounts/v1/messaging-changed";
|
||||
|
||||
/**
|
||||
* A hint, as `church.changed` is: the church's email or WhatsApp settings changed (in Accounts,
|
||||
* or copied in from Events), so send `messaging.get` again. Sent to the products that asked for
|
||||
* them. The product answers `{ ok: true }` (`okReplySchema`); Accounts retries otherwise.
|
||||
*/
|
||||
export const messagingChangedSchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
type: z.literal("messaging.changed"),
|
||||
occurredAt: dateTimeSchema,
|
||||
/** Which parts changed. */
|
||||
email: z.boolean(),
|
||||
whatsapp: z.boolean(),
|
||||
});
|
||||
export type MessagingChanged = z.infer<typeof messagingChangedSchema>;
|
||||
|
||||
/** church.update: the profile after the change. */
|
||||
export const churchUpdateReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEMA), church: churchSchema });
|
||||
export type ChurchUpdateReply = z.infer<typeof churchUpdateReplySchema>;
|
||||
|
||||
Reference in New Issue
Block a user