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:
@@ -10,7 +10,7 @@ Events and the Hub, uses it, so the key fields are the same in every product's J
|
||||
| Event feed | `crosscode.event-feed/1` | `GET /api/feed/v1/events?updatedSince=` and the `event.changed` webhook | `src/event.ts` |
|
||||
| Church | `crosscode.church/1` | The church profile: name, branding, campuses, service times, contact details, product links | `src/church.ts` |
|
||||
| Identity | `crosscode.identity/1` | Accounts' sign-in claims and back-channel calls (`user.updated`, `user.deleted`, `user.export`) and their replies | `src/identity.ts` |
|
||||
| Identity requests | `crosscode.identity-request/1` | From 1.8.0: what a product asks of its Accounts at `POST /api/accounts/v1/requests`: moving its users in (`import.begin` / `batch` / `finish` / `abort`, secrets sealed with `sealLinkValue`) and `people.*` (ensure, update, reset 2FA, unlock, set active, news off) | `src/identity-request.ts` |
|
||||
| Identity requests | `crosscode.identity-request/1` | From 1.8.0: what a product asks of its Accounts at `POST /api/accounts/v1/requests`: moving its users in (`import.begin` / `batch` / `finish` / `abort`, secrets sealed with `sealLinkValue`) and `people.*` (ensure, update, reset 2FA, unlock, set active, news off); from 1.9.0 `messaging.*` (status, test, set Accounts' email and WhatsApp) | `src/identity-request.ts` |
|
||||
| Sign-in return | — | The return-path check and OIDC `state` every product uses (ROADMAP-v3 §3) | `src/return-to.ts` |
|
||||
| Product link | `crosscode.link/1` | **Connect** under Settings → Linked products: the signed handshake that sets up a link's secret (`link.connect`, `link.connected`, `link.disconnect`) | `src/link.ts` |
|
||||
| Hub protocol v2 | `protocolVersion: 2` | Register, heartbeat (stats per product), linked products, update requests, AI, licence token | `src/hub.ts` (exported as `hub`) |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/contracts",
|
||||
"version": "1.8.0",
|
||||
"version": "1.9.0",
|
||||
"description": "The shared JSON formats used by every Cross Code product: zod schemas, JSON Schema, TypeScript types and sample payloads",
|
||||
"license": "UNLICENSED",
|
||||
"type": "commonjs",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"schema": "crosscode.identity-request/1",
|
||||
"requestId": "5a0b1c2d-3e4f-4a5b-8c6d-7e8f9a0b1c2d",
|
||||
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
|
||||
"type": "messaging.set",
|
||||
"email": {
|
||||
"settings": {
|
||||
"host": "smtp.hopefamily.co.za",
|
||||
"port": 587,
|
||||
"secure": false,
|
||||
"user": "events@hopefamily.co.za",
|
||||
"pass": "sealed1.BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
|
||||
"from": "events@hopefamily.co.za"
|
||||
},
|
||||
"to": "office@hopefamily.co.za"
|
||||
},
|
||||
"whatsapp": {
|
||||
"settings": {
|
||||
"accessToken": "sealed1.CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
|
||||
"instanceId": "ABC123"
|
||||
},
|
||||
"to": "+27821234567"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"schema": "crosscode.identity-request/1",
|
||||
"email": {
|
||||
"ok": true,
|
||||
"error": null,
|
||||
"saved": true
|
||||
},
|
||||
"whatsapp": {
|
||||
"ok": false,
|
||||
"error": "WhatsApp couldn't send the message (401).",
|
||||
"saved": false
|
||||
},
|
||||
"status": {
|
||||
"email": {
|
||||
"ready": true,
|
||||
"host": "smtp.hopefamily.co.za",
|
||||
"from": "events@hopefamily.co.za"
|
||||
},
|
||||
"whatsapp": {
|
||||
"ready": false,
|
||||
"instanceId": null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -786,6 +786,316 @@
|
||||
"sub",
|
||||
"channel"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"const": "crosscode.identity-request/1"
|
||||
},
|
||||
"requestId": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
"actor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "messaging.status"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"requestId",
|
||||
"actor",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"const": "crosscode.identity-request/1"
|
||||
},
|
||||
"requestId": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
"actor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "messaging.test"
|
||||
},
|
||||
"email": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 253
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 65535
|
||||
},
|
||||
"secure": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"user": {
|
||||
"type": "string",
|
||||
"maxLength": 254
|
||||
},
|
||||
"pass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
"minLength": 3,
|
||||
"maxLength": 320
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host",
|
||||
"port",
|
||||
"secure",
|
||||
"user",
|
||||
"pass",
|
||||
"from"
|
||||
]
|
||||
},
|
||||
"to": {
|
||||
"type": "string",
|
||||
"maxLength": 254,
|
||||
"format": "email",
|
||||
"pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings",
|
||||
"to"
|
||||
]
|
||||
},
|
||||
"whatsapp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"accessToken": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"instanceId": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 200
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"accessToken",
|
||||
"instanceId"
|
||||
]
|
||||
},
|
||||
"to": {
|
||||
"type": "string",
|
||||
"pattern": "^\\+[1-9]\\d{6,14}$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings",
|
||||
"to"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"requestId",
|
||||
"actor",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"const": "crosscode.identity-request/1"
|
||||
},
|
||||
"requestId": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
"actor": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "messaging.set"
|
||||
},
|
||||
"email": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 253
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 65535
|
||||
},
|
||||
"secure": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"user": {
|
||||
"type": "string",
|
||||
"maxLength": 254
|
||||
},
|
||||
"pass": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
"minLength": 3,
|
||||
"maxLength": 320
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host",
|
||||
"port",
|
||||
"secure",
|
||||
"user",
|
||||
"pass",
|
||||
"from"
|
||||
]
|
||||
},
|
||||
"to": {
|
||||
"type": "string",
|
||||
"maxLength": 254,
|
||||
"format": "email",
|
||||
"pattern": "^(?:[A-Za-z0-9_'+\\-]+\\.)*[A-Za-z0-9_'+\\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings",
|
||||
"to"
|
||||
]
|
||||
},
|
||||
"whatsapp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"accessToken": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 4096,
|
||||
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"instanceId": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 200
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"accessToken",
|
||||
"instanceId"
|
||||
]
|
||||
},
|
||||
"to": {
|
||||
"type": "string",
|
||||
"pattern": "^\\+[1-9]\\d{6,14}$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"settings",
|
||||
"to"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"requestId",
|
||||
"actor",
|
||||
"type"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/messaging-status-reply.json",
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"const": "crosscode.identity-request/1"
|
||||
},
|
||||
"email": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ready": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"host": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"from": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ready",
|
||||
"host",
|
||||
"from"
|
||||
]
|
||||
},
|
||||
"whatsapp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ready": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"instanceId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ready",
|
||||
"instanceId"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"email",
|
||||
"whatsapp"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/messaging-test-reply.json",
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"const": "crosscode.identity-request/1"
|
||||
},
|
||||
"email": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ok": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"error": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"saved": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ok",
|
||||
"error",
|
||||
"saved"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"whatsapp": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ok": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"error": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"maxLength": 500
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"saved": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ok",
|
||||
"error",
|
||||
"saved"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ready": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"host": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"from": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ready",
|
||||
"host",
|
||||
"from"
|
||||
]
|
||||
},
|
||||
"whatsapp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ready": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"instanceId": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"ready",
|
||||
"instanceId"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"email",
|
||||
"whatsapp"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"email",
|
||||
"whatsapp",
|
||||
"status"
|
||||
]
|
||||
}
|
||||
@@ -14,6 +14,9 @@
|
||||
},
|
||||
"created": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"emailSent": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -64,6 +64,8 @@ function contracts(c) {
|
||||
"import-batch-reply": c.importBatchReplySchema,
|
||||
"import-finish-reply": c.importFinishReplySchema,
|
||||
"people-ensure-reply": c.peopleEnsureReplySchema,
|
||||
"messaging-status-reply": c.messagingStatusReplySchema,
|
||||
"messaging-test-reply": c.messagingTestReplySchema,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -33,6 +33,13 @@ describe("crosscode.identity-request/1", () => {
|
||||
expect(identityRequestSchema.safeParse(many).success).toBe(false);
|
||||
});
|
||||
|
||||
test("messaging.set needs the password sealed, or null to keep the saved one", () => {
|
||||
const set = sample<{ email: { settings: Record<string, unknown> } }>("messaging-set.json");
|
||||
expect(identityRequestSchema.safeParse(set).success).toBe(true);
|
||||
expect(identityRequestSchema.safeParse({ ...set, email: { ...set.email, settings: { ...set.email.settings, pass: null } } }).success).toBe(true);
|
||||
expect(identityRequestSchema.safeParse({ ...set, email: { ...set.email, settings: { ...set.email.settings, pass: "plain-password" } } }).success).toBe(false);
|
||||
});
|
||||
|
||||
test("unknown request types are refused", () => {
|
||||
expect(identityRequestSchema.safeParse({ ...sample("people-ensure.json"), type: "people.delete" }).success).toBe(false);
|
||||
});
|
||||
|
||||
@@ -46,6 +46,8 @@ const SAMPLE_SCHEMA: Record<string, string> = {
|
||||
"import-finish.json": "identity-request",
|
||||
"people-ensure.json": "identity-request",
|
||||
"people-ensure-reply.json": "people-ensure-reply",
|
||||
"messaging-set.json": "identity-request",
|
||||
"messaging-test-reply.json": "messaging-test-reply",
|
||||
};
|
||||
|
||||
describe("JSON Schema (schemas/)", () => {
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
identityRequestSchema,
|
||||
importBatchReplySchema,
|
||||
peopleEnsureReplySchema,
|
||||
messagingTestReplySchema,
|
||||
userDeletedReplySchema,
|
||||
userExportReplySchema,
|
||||
} from "../src";
|
||||
@@ -53,6 +54,8 @@ const SCHEMAS: Record<string, z.ZodType> = {
|
||||
"import-finish.json": identityRequestSchema,
|
||||
"people-ensure.json": identityRequestSchema,
|
||||
"people-ensure-reply.json": peopleEnsureReplySchema,
|
||||
"messaging-set.json": identityRequestSchema,
|
||||
"messaging-test-reply.json": messagingTestReplySchema,
|
||||
};
|
||||
|
||||
describe("samples", () => {
|
||||
|
||||
Reference in New Issue
Block a user