contracts 1.8.0: crosscode.identity-request/1 (import and people.* calls to Accounts)

Product -> Accounts requests at /api/accounts/v1/requests, signed with the
link secret: import.begin/batch/finish/abort for moving a product's users
in (EVENTS-3.0-PLAN §4), people.* for product admins (§8). sealLinkValue /
openLinkValue seal password hashes and TOTP secrets with a key derived
from the link secret; importIdsHash for the final check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 13:33:15 +02:00
co-authored by Claude Opus 5.5
parent ac017395df
commit 08fef930c1
24 changed files with 1585 additions and 10 deletions
+5 -5
View File
@@ -1,8 +1,8 @@
# Cross Events 3.0.0 — signing in through Accounts
Phase **4** of [ROADMAP-v3.md](./ROADMAP-v3.md) (§3 "Moving Cross Events onto Accounts", §8, §9;
decisions 2, 14, 15, 17, 24, 38). Written 2026-11-19. **Not started; decisions below still to be
confirmed.** Moved before the Website on 2026-11-19 (decision 38), so this is the first product
decisions 2, 14, 15, 17, 24, 38). Written 2026-11-19. **Decisions confirmed 2026-11-19** (all as proposed); being built on
`feat/events-3.0`. Moved before the Website on 2026-11-19 (decision 38), so this is the first product
that really signs people in through [Accounts](./ACCOUNTS-1.0-PLAN.md).
**What 3.0.0 is:** Cross Events stops keeping passwords. Sign-in, sign-up, forgot password, 2FA,
@@ -52,7 +52,7 @@ connected before its Events can move.
12. [What changes in each repo](#11-what-changes-in-each-repo)
13. [Testing](#12-testing)
14. [Releasing and rolling it out](#13-releasing-and-rolling-it-out)
15. [Decisions to confirm](#decisions-to-confirm)
15. [Decisions](#decisions)
16. [Still open](#still-open)
---
@@ -418,9 +418,9 @@ only for a connected product:
login events, Events' audit log) → after 14 days the Undo window closes and the old secrets are
cleared. **The demo site first, then Hope Family Church**, then the rest.
## Decisions to confirm
## Decisions
Proposed; confirm with Joshua before building.
Confirmed by Joshua on 2026-11-19, all as proposed.
1. **`User.accountId` instead of rewriting `User.id`** (§2). Every imported person still gets
`sub = User.id`; the column handles guests, deleted people and emails already in Accounts
+1 -1
View File
@@ -32,7 +32,7 @@ every release).
| 1d | Agent 1.0.x + Hub 2.1.x (+ contracts 1.3.0) | **Released** 2026-11-17 (`agent@1.0.0`, `contracts@1.3.0`, Hub `v2.1.0`). **VM tested** end to end (AGENT-1.0-PLAN §13: joins, installs behind frp, scheduled / batch / missed updates, uninstall with export and purge, forged and replayed jobs). 2026-11-18: **`agent@1.0.1`** (the agent answers status on the central server itself) and Hub **`v2.1.1`** (adopt passes the church's address; Link takes the short name as a name). **Not rolled out**: use agent 1.0.1 and Hub 2.1.1 |
| 2 | Cross Events 2.4.0: protocol v2, Linked products, event feed, `packages/seo` (+ contracts 1.4.0, Hub 2.2.0) | **Released** 2026-11-18 (`events@2.4.0`, `contracts@1.4.0`, Hub `v2.2.0`, crosscode-site `v1.4.0`; [EVENTS-2.4-PLAN.md](./EVENTS-2.4-PLAN.md)). **Before any church gets it:** the Events e2e run on Postgres and the VM test (EVENTS-2.4-PLAN §8) |
| 3 | Accounts 1.0.0 (+ contracts 1.5.0, agent 1.1.0, Hub 2.3.0) | **Released** 2026-11-18 (`accounts@1.0.0`, `contracts@1.5.0`, `agent@1.1.0`, Hub `v2.3.0`, crosscode-site `v1.5.0`; [ACCOUNTS-1.0-PLAN.md](./ACCOUNTS-1.0-PLAN.md)). 37 backend and 8 Playwright tests pass without Postgres. **Before installing it for a church:** the VM test and a run on real Postgres; a Hub release source for `accounts@` tags |
| 4 | Cross Events 3.0.0: sign-in through Accounts, users migrated with their password hashes and 2FA | **Next.** Moved before the Website on 2026-11-19 (ROADMAP decision 38). Planned: [EVENTS-3.0-PLAN.md](./EVENTS-3.0-PLAN.md) (with contracts 1.8.0, Accounts 1.1.0, Hub 2.5.0); its decisions still to be confirmed |
| 4 | Cross Events 3.0.0: sign-in through Accounts, users migrated with their password hashes and 2FA | **Next.** Moved before the Website on 2026-11-19 (ROADMAP decision 38). Planned: [EVENTS-3.0-PLAN.md](./EVENTS-3.0-PLAN.md) (with contracts 1.8.0, Accounts 1.1.0, Hub 2.5.0); decisions confirmed 2026-11-19; being built on `feat/events-3.0` |
| 5–7 | Website 1.0.0 → App 1.0.0 → App 1.x | Not started |
## Next up
+6 -3
View File
@@ -183,8 +183,11 @@ touching anyone's account.
This is a breaking change, so it's a major version.
- A migration copies every Events user into Accounts **with their existing password hash**, 2FA
setting (including authenticator secrets and unused recovery codes), consent and notice acceptance, so nobody has to reset anything. The Events `User`
table keeps its id (now equal to the account `sub`), role, campus scope and product data.
setting (including authenticator secrets), consent and notice acceptance, so nobody has to reset anything. Recovery codes
can't move (Events keys them with its own secret), so people with 2FA get new ones at their first
sign-in through Accounts (EVENTS-3.0-PLAN decision 2). The Events `User` table keeps its id
(equal to the account `sub` for everyone moved; a new `accountId` column links guests and
existing accounts, decision 1), role, campus scope and product data.
- Sign-in, forgot password, 2FA, the news question and the notice re-acceptance move to Accounts.
The Events privacy centre links to Accounts for account-level items.
- Every place Events sends someone to sign in today (`/login?redirect=…`, `useRequireAuth`, the
@@ -621,7 +624,7 @@ Planned in [AGENT-1.0-PLAN.md](./AGENT-1.0-PLAN.md). In short:
| 1d | **Agent 1.0.0 + Hub 2.1.0** (contracts 1.3.0) | **Server agent** on every server (polls only, signed jobs, runs the `crosscode` script); Hub: Servers page with stats and alerts, server configuration, frp port list, New install with a choice of server, scheduled / emergency / batch updates with notice to the church, uninstall with an encrypted JSON export, emailed reports. [AGENT-1.0-PLAN.md](./AGENT-1.0-PLAN.md). **Released 2026-11-17** after the VM test; rollout in [ROLLOUT-1.0.md](./ROLLOUT-1.0.md) | Right after 1b (it runs the `crosscode` script), so every new church from then on is installed from the Hub. Can run alongside 1c |
| 2 | **Cross Events 2.4.0** | Reports `product: "events"` (protocol v2), **Linked products**, the event feed (publish + show events from siblings), `packages/seo` (§11) with canonical links for imported events. **Planned and built 2026-11-18:** [EVENTS-2.4-PLAN.md](./EVENTS-2.4-PLAN.md) (also needs contracts 1.4.0 and Hub 2.2.0, for a public key in the v2 heartbeat); not tagged yet | Small; ready for when the Website exists |
| 3 | **Accounts 1.0.0** | OIDC provider, sign-in, 2FA (email, WhatsApp, authenticator app), password reset, consent and notice, export / delete fan-out, admin, install script. [ACCOUNTS-1.0-PLAN.md](./ACCOUNTS-1.0-PLAN.md) (with contracts 1.5.0, `packages/auth-client`, Hub 2.3.0). **Released 2026-11-18** (`accounts@1.0.0`, 1.0.1 on 2026-11-19); the VM test and a run on real Postgres are still to do before a church gets it | Every later product signs in through it |
| 4 | **Cross Events 3.0.0** | Sign-in moves to Accounts; user migration keeping password hashes; migration guide. **Planned 2026-11-19:** [EVENTS-3.0-PLAN.md](./EVENTS-3.0-PLAN.md) (with contracts 1.8.0, Accounts 1.1.0, Hub 2.5.0; decisions to confirm) | Breaking change, so a major version. **Moved before the Website on 2026-11-19** (decision 38): Events is the product churches use today, so Accounts is proven on real users first, and the Website then starts with a church whose people already have accounts |
| 4 | **Cross Events 3.0.0** | Sign-in moves to Accounts; user migration keeping password hashes; migration guide. **Planned 2026-11-19:** [EVENTS-3.0-PLAN.md](./EVENTS-3.0-PLAN.md) (with contracts 1.8.0, Accounts 1.1.0, Hub 2.5.0; decisions confirmed 2026-11-19) | Breaking change, so a major version. **Moved before the Website on 2026-11-19** (decision 38): Events is the product churches use today, so Accounts is proven on real users first, and the Website then starts with a church whose people already have accounts |
| 5 | **Church Website 1.0.0** | Public site with the **four templates** (§6), admin, simple events + feed, SEO (§11), Hope Family Church as the first church, then a second test church on a different template to prove it repeats | More churches need a website than an app; it also covers the "website only" case. Built on Accounts from day one |
| 6 | **Church App 1.0.0** | Foundation (PWA, branding, Accounts), House of Prayer, announcements, devotionals, events (simple + feed) | Starts with shared users and the feed already in place |
| 7 | Church App 1.x | Reading plans, sermons, groups, pastoral care, serving, giving links, directory | After House of Prayer is in use |
+1
View File
@@ -10,6 +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` |
| 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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@crosscode/contracts",
"version": "1.7.0",
"version": "1.8.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,11 @@
{
"schema": "crosscode.identity-request/1",
"results": [
{
"id": "5f0c7d2a-3b1e-4c8f-9a6d-2e4b1c7f8a90",
"outcome": "created",
"sub": "5f0c7d2a-3b1e-4c8f-9a6d-2e4b1c7f8a90",
"reason": null
}
]
}
@@ -0,0 +1,49 @@
{
"schema": "crosscode.identity-request/1",
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
"requestId": "1c7f2a3b-4d5e-4f6a-9b0c-1d2e3f4a5b6c",
"type": "import.batch",
"check": false,
"people": [
{
"id": "5f0c7d2a-3b1e-4c8f-9a6d-2e4b1c7f8a90",
"name": "Thandi Mokoena",
"email": "thandi@hopefamily.co.za",
"emailVerified": true,
"phone": "+27821234567",
"passwordHash": "sealed1.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"twoFactor": "totp",
"totpSecret": "sealed1.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"totpLastStep": 59012345,
"failedSignIns": 0,
"lockedUntil": null,
"news": {
"email": true,
"whatsapp": false
},
"newsAskedAt": "2026-03-01T08:00:00.000Z",
"noticeVersionAccepted": 2,
"noticeAcceptances": [
{
"version": 1,
"acceptedAt": "2025-06-01T08:00:00.000Z"
},
{
"version": 2,
"acceptedAt": "2026-03-01T08:00:00.000Z"
}
],
"consentChanges": [
{
"channel": "email",
"granted": true,
"at": "2026-03-01T08:00:00.000Z"
}
],
"lastSignInAt": "2026-11-18T17:30:00.000Z",
"status": "active",
"admin": true,
"createdAt": "2025-06-01T08:00:00.000Z"
}
]
}
@@ -0,0 +1,19 @@
{
"schema": "crosscode.identity-request/1",
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
"requestId": "0b6e1f2a-3c4d-4e5f-8a9b-0c1d2e3f4a5b",
"type": "import.begin",
"check": false,
"notices": [
{
"version": 2,
"title": "Privacy notice",
"body": "How Hope Family Church uses your information…",
"publishedAt": "2026-03-01T08:00:00.000Z"
}
],
"church": {
"name": "Hope Family Church",
"primaryColour": "#1e40af"
}
}
@@ -0,0 +1,8 @@
{
"schema": "crosscode.identity-request/1",
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
"requestId": "2d8a3b4c-5e6f-4a7b-8c1d-2e3f4a5b6c7d",
"type": "import.finish",
"count": 1,
"idsHash": "9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f"
}
@@ -0,0 +1,5 @@
{
"schema": "crosscode.identity-request/1",
"sub": "4fac5d6e-7a8b-4c9d-8e3f-4a5b6c7d8e9f",
"created": true
}
@@ -0,0 +1,10 @@
{
"schema": "crosscode.identity-request/1",
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
"requestId": "3e9b4c5d-6f7a-4b8c-9d2e-3f4a5b6c7d8e",
"type": "people.ensure",
"name": "Sipho Dlamini",
"email": "sipho@hopefamily.co.za",
"phone": null,
"returnUrl": "https://events.hopefamily.co.za/dashboard"
}
@@ -0,0 +1,792 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/identity-request.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"oneOf": [
{
"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": "import.begin"
},
"check": {
"type": "boolean"
},
"notices": {
"maxItems": 100,
"type": "array",
"items": {
"type": "object",
"properties": {
"version": {
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
},
"title": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"body": {
"type": "string",
"minLength": 1,
"maxLength": 200000
},
"publishedAt": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"version",
"title",
"body",
"publishedAt"
]
}
},
"church": {
"type": "object",
"properties": {
"name": {
"anyOf": [
{
"type": "string",
"minLength": 1,
"maxLength": 200
},
{
"type": "null"
}
]
},
"primaryColour": {
"anyOf": [
{
"type": "string",
"pattern": "^#[0-9a-fA-F]{6}$"
},
{
"type": "null"
}
]
}
},
"required": [
"name",
"primaryColour"
]
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"check",
"notices",
"church"
]
},
{
"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": "import.batch"
},
"check": {
"type": "boolean"
},
"people": {
"minItems": 1,
"maxItems": 200,
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"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)$"
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"email": {
"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,}$"
},
"emailVerified": {
"type": "boolean"
},
"phone": {
"anyOf": [
{
"type": "string",
"pattern": "^\\+[1-9]\\d{6,14}$"
},
{
"type": "null"
}
]
},
"passwordHash": {
"anyOf": [
{
"type": "string",
"maxLength": 4096,
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
},
{
"type": "null"
}
]
},
"twoFactor": {
"anyOf": [
{
"type": "string",
"enum": [
"email",
"whatsapp",
"totp"
]
},
{
"type": "null"
}
]
},
"totpSecret": {
"anyOf": [
{
"type": "string",
"maxLength": 4096,
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
},
{
"type": "null"
}
]
},
"totpLastStep": {
"anyOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
{
"type": "null"
}
]
},
"failedSignIns": {
"type": "integer",
"minimum": 0,
"maximum": 1000
},
"lockedUntil": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"news": {
"type": "object",
"properties": {
"email": {
"type": "boolean"
},
"whatsapp": {
"type": "boolean"
}
},
"required": [
"email",
"whatsapp"
]
},
"newsAskedAt": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"noticeVersionAccepted": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"noticeAcceptances": {
"maxItems": 100,
"type": "array",
"items": {
"type": "object",
"properties": {
"version": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"acceptedAt": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"version",
"acceptedAt"
]
}
},
"consentChanges": {
"maxItems": 500,
"type": "array",
"items": {
"type": "object",
"properties": {
"channel": {
"type": "string",
"enum": [
"email",
"whatsapp"
]
},
"granted": {
"type": "boolean"
},
"at": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"channel",
"granted",
"at"
]
}
},
"lastSignInAt": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"status": {
"type": "string",
"enum": [
"active",
"deactivated"
]
},
"admin": {
"type": "boolean"
},
"createdAt": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"id",
"name",
"email",
"emailVerified",
"phone",
"passwordHash",
"twoFactor",
"totpSecret",
"totpLastStep",
"failedSignIns",
"lockedUntil",
"news",
"newsAskedAt",
"noticeVersionAccepted",
"noticeAcceptances",
"consentChanges",
"lastSignInAt",
"status",
"admin",
"createdAt"
]
}
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"check",
"people"
]
},
{
"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": "import.finish"
},
"count": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"idsHash": {
"type": "string",
"pattern": "^[0-9a-f]{64}$"
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"count",
"idsHash"
]
},
{
"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": "import.abort"
}
},
"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": "people.ensure"
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"email": {
"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,}$"
},
"phone": {
"anyOf": [
{
"type": "string",
"pattern": "^\\+[1-9]\\d{6,14}$"
},
{
"type": "null"
}
]
},
"returnUrl": {
"type": "string",
"maxLength": 2048,
"format": "uri"
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"name",
"email",
"phone",
"returnUrl"
]
},
{
"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": "people.update"
},
"sub": {
"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)$"
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"email": {
"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,}$"
},
"phone": {
"anyOf": [
{
"type": "string",
"pattern": "^\\+[1-9]\\d{6,14}$"
},
{
"type": "null"
}
]
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"sub"
]
},
{
"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": "people.resetTwoFactor"
},
"sub": {
"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)$"
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"sub"
]
},
{
"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": "people.unlock"
},
"sub": {
"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)$"
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"sub"
]
},
{
"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": "people.setActive"
},
"sub": {
"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)$"
},
"active": {
"type": "boolean"
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"sub",
"active"
]
},
{
"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": "people.newsOff"
},
"sub": {
"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)$"
},
"channel": {
"type": "string",
"enum": [
"email",
"whatsapp",
"all"
]
}
},
"required": [
"schema",
"requestId",
"actor",
"type",
"sub",
"channel"
]
}
]
}
@@ -0,0 +1,66 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/import-batch-reply.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"schema": {
"type": "string",
"const": "crosscode.identity-request/1"
},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"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)$"
},
"outcome": {
"type": "string",
"enum": [
"created",
"updated",
"linked",
"refused"
]
},
"sub": {
"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"
}
]
},
"reason": {
"anyOf": [
{
"type": "string",
"maxLength": 300
},
{
"type": "null"
}
]
}
},
"required": [
"id",
"outcome",
"sub",
"reason"
]
}
}
},
"required": [
"schema",
"results"
]
}
@@ -0,0 +1,31 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/import-begin-reply.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"schema": {
"type": "string",
"const": "crosscode.identity-request/1"
},
"noticesTaken": {
"type": "boolean"
},
"accountsNoticeVersions": {
"type": "array",
"items": {
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
}
},
"accountsVersion": {
"type": "string"
}
},
"required": [
"schema",
"noticesTaken",
"accountsNoticeVersions",
"accountsVersion"
]
}
@@ -0,0 +1,24 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/import-finish-reply.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"schema": {
"type": "string",
"const": "crosscode.identity-request/1"
},
"matched": {
"type": "boolean"
},
"count": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"schema",
"matched",
"count"
]
}
@@ -0,0 +1,238 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/import-person.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"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)$"
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"email": {
"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,}$"
},
"emailVerified": {
"type": "boolean"
},
"phone": {
"anyOf": [
{
"type": "string",
"pattern": "^\\+[1-9]\\d{6,14}$"
},
{
"type": "null"
}
]
},
"passwordHash": {
"anyOf": [
{
"type": "string",
"maxLength": 4096,
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
},
{
"type": "null"
}
]
},
"twoFactor": {
"anyOf": [
{
"type": "string",
"enum": [
"email",
"whatsapp",
"totp"
]
},
{
"type": "null"
}
]
},
"totpSecret": {
"anyOf": [
{
"type": "string",
"maxLength": 4096,
"pattern": "^sealed1\\.[A-Za-z0-9_-]{40,}$"
},
{
"type": "null"
}
]
},
"totpLastStep": {
"anyOf": [
{
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
{
"type": "null"
}
]
},
"failedSignIns": {
"type": "integer",
"minimum": 0,
"maximum": 1000
},
"lockedUntil": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"news": {
"type": "object",
"properties": {
"email": {
"type": "boolean"
},
"whatsapp": {
"type": "boolean"
}
},
"required": [
"email",
"whatsapp"
]
},
"newsAskedAt": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"noticeVersionAccepted": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"noticeAcceptances": {
"maxItems": 100,
"type": "array",
"items": {
"type": "object",
"properties": {
"version": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"acceptedAt": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"version",
"acceptedAt"
]
}
},
"consentChanges": {
"maxItems": 500,
"type": "array",
"items": {
"type": "object",
"properties": {
"channel": {
"type": "string",
"enum": [
"email",
"whatsapp"
]
},
"granted": {
"type": "boolean"
},
"at": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"channel",
"granted",
"at"
]
}
},
"lastSignInAt": {
"anyOf": [
{
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
},
{
"type": "null"
}
]
},
"status": {
"type": "string",
"enum": [
"active",
"deactivated"
]
},
"admin": {
"type": "boolean"
},
"createdAt": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
}
},
"required": [
"id",
"name",
"email",
"emailVerified",
"phone",
"passwordHash",
"twoFactor",
"totpSecret",
"totpLastStep",
"failedSignIns",
"lockedUntil",
"news",
"newsAskedAt",
"noticeVersionAccepted",
"noticeAcceptances",
"consentChanges",
"lastSignInAt",
"status",
"admin",
"createdAt"
]
}
@@ -0,0 +1,24 @@
{
"$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/people-ensure-reply.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"schema": {
"type": "string",
"const": "crosscode.identity-request/1"
},
"sub": {
"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)$"
},
"created": {
"type": "boolean"
}
},
"required": [
"schema",
"sub",
"created"
]
}
@@ -58,6 +58,12 @@ function contracts(c) {
"link-disconnect": c.linkDisconnectSchema,
"link-disconnected": c.linkDisconnectedSchema,
"link-error": c.linkErrorSchema,
"identity-request": c.identityRequestSchema,
"import-person": c.importPersonSchema,
"import-begin-reply": c.importBeginReplySchema,
"import-batch-reply": c.importBatchReplySchema,
"import-finish-reply": c.importFinishReplySchema,
"people-ensure-reply": c.peopleEnsureReplySchema,
};
}
+195
View File
@@ -0,0 +1,195 @@
import { z } from "zod";
import { dateTimeSchema, emailSchema, idSchema, phoneSchema } from "./common";
import { twoFactorMethodSchema } from "./identity";
import { schemaName } from "./schema-name";
/**
* `crosscode.identity-request/1` (contracts 1.8.0, docs/EVENTS-3.0-PLAN.md §4 and §8): what a
* linked product asks of its church's Accounts. The other direction from `crosscode.identity/1`
* (Accounts → product), so it has its own schema and path:
*
* POST <accounts>/api/accounts/v1/requests signed with the link's secret (LINK_HEADERS)
*
* - **`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.
* - **`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
* imported by it), and audits each with the product and the admin's `sub`.
*/
export const IDENTITY_REQUEST_SCHEMA = schemaName("identity-request", 1);
/** On Accounts' address. */
export const ACCOUNTS_REQUEST_PATH = "/api/accounts/v1/requests";
/** People per `import.batch`. */
export const IMPORT_BATCH_MAX = 200;
/** A value sealed with `sealLinkValue`: `sealed1.<base64url iv ‖ ciphertext ‖ tag>`. */
export const sealedValueSchema = z.string().regex(/^sealed1\.[A-Za-z0-9_-]{40,}$/, "Expected a sealed value").max(4096);
const base = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
/** Unique per request; Accounts answers a repeat with the first answer's outcome. */
requestId: idSchema,
/** The product admin this is done for (their `sub`), or null for the product itself. */
actor: idSchema.nullable(),
});
// ─── import.* ────────────────────────────────────────────────────────────────
/** A privacy notice version, numbers kept (EVENTS-3.0-PLAN decision 5). */
export const importNoticeSchema = z.object({
version: z.int().positive(),
title: z.string().trim().min(1).max(200),
body: z.string().min(1).max(200_000),
publishedAt: dateTimeSchema,
});
/** One person to move into Accounts. `id` becomes the account's `sub`. */
export const importPersonSchema = z.object({
id: idSchema,
name: z.string().trim().min(1).max(200),
email: emailSchema,
emailVerified: z.boolean(),
phone: phoneSchema.nullable(),
/** bcrypt or Argon2id hash, sealed. Null: the person has to set a password (never activated). */
passwordHash: sealedValueSchema.nullable(),
twoFactor: twoFactorMethodSchema.nullable(),
/** The authenticator secret (base32), sealed; only with `twoFactor: "totp"`. */
totpSecret: sealedValueSchema.nullable(),
totpLastStep: z.int().nonnegative().nullable(),
failedSignIns: z.int().nonnegative().max(1000),
lockedUntil: dateTimeSchema.nullable(),
news: z.object({ email: z.boolean(), whatsapp: z.boolean() }),
newsAskedAt: dateTimeSchema.nullable(),
/** 0: never accepted a numbered version. */
noticeVersionAccepted: z.int().nonnegative(),
noticeAcceptances: z.array(z.object({ version: z.int().nonnegative(), acceptedAt: dateTimeSchema })).max(100),
consentChanges: z.array(z.object({ channel: z.enum(["email", "whatsapp"]), granted: z.boolean(), at: dateTimeSchema })).max(500),
lastSignInAt: dateTimeSchema.nullable(),
status: z.enum(["active", "deactivated"]),
/** Also an Accounts admin (ticked at the move). */
admin: z.boolean(),
createdAt: dateTimeSchema,
});
export type ImportPerson = z.infer<typeof importPersonSchema>;
/**
* Starts (or, with `check: true`, tries) a move. Accounts remembers that this link is moving until
* `import.finish` or `import.abort`; `import.batch` is refused otherwise.
*/
export const importBeginSchema = base.extend({
type: z.literal("import.begin"),
check: z.boolean(),
/** The product's privacy notice versions. Taken only when Accounts has published none of its own. */
notices: z.array(importNoticeSchema).max(100),
/** Fills the church profile's empty fields, so the sign-in page looks like the church at once. */
church: z.object({ name: z.string().trim().min(1).max(200).nullable(), primaryColour: z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable() }),
});
export const importBatchSchema = base.extend({
type: z.literal("import.batch"),
/** With `check: true` nothing is written; the answer says what would happen. */
check: z.boolean(),
people: z.array(importPersonSchema).min(1).max(IMPORT_BATCH_MAX),
});
/** Ends a move: Accounts compares the count and the ids' hash (`importIdsHash`) with what it holds. */
export const importFinishSchema = base.extend({
type: z.literal("import.finish"),
count: z.int().nonnegative(),
idsHash: z.string().regex(/^[0-9a-f]{64}$/),
});
export const importAbortSchema = base.extend({ type: z.literal("import.abort") });
// ─── people.* ────────────────────────────────────────────────────────────────
/** Find the account with this email, or make one without a password and email a "set your password" link. */
export const peopleEnsureSchema = base.extend({
type: z.literal("people.ensure"),
name: z.string().trim().min(1).max(200),
email: emailSchema,
phone: phoneSchema.nullable(),
/** Where the "set your password" email's link ends (the product's address), after the password is set. */
returnUrl: z.url({ protocol: /^https?$/ }).max(2048),
});
const onePerson = { sub: idSchema };
export const peopleUpdateSchema = base.extend({
type: z.literal("people.update"),
...onePerson,
name: z.string().trim().min(1).max(200).optional(),
email: emailSchema.optional(),
phone: phoneSchema.nullable().optional(),
});
export const peopleResetTwoFactorSchema = base.extend({ type: z.literal("people.resetTwoFactor"), ...onePerson });
export const peopleUnlockSchema = base.extend({ type: z.literal("people.unlock"), ...onePerson });
export const peopleSetActiveSchema = base.extend({ type: z.literal("people.setActive"), ...onePerson, active: z.boolean() });
/** 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"]) });
export const identityRequestSchema = z.discriminatedUnion("type", [
importBeginSchema, importBatchSchema, importFinishSchema, importAbortSchema,
peopleEnsureSchema, peopleUpdateSchema, peopleResetTwoFactorSchema, peopleUnlockSchema, peopleSetActiveSchema, peopleNewsOffSchema,
]);
export type IdentityRequest = z.infer<typeof identityRequestSchema>;
export type IdentityRequestType = IdentityRequest["type"];
// ─── Replies ─────────────────────────────────────────────────────────────────
export const importBeginReplySchema = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
/** False when Accounts has its own notice versions: the move stops and an admin chooses. */
noticesTaken: z.boolean(),
/** Accounts' own notice versions, when it has some (so the product can show the choice). */
accountsNoticeVersions: z.array(z.int().positive()),
accountsVersion: z.string(),
});
export const IMPORT_OUTCOMES = ["created", "updated", "linked", "refused"] as const;
export const importResultSchema = z.object({
id: idSchema,
outcome: z.enum(IMPORT_OUTCOMES),
/** The account's `sub`: the same as `id`, except `linked` (the email already had an account). */
sub: idSchema.nullable(),
reason: z.string().max(300).nullable(),
});
export type ImportResult = z.infer<typeof importResultSchema>;
export const importBatchReplySchema = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
results: z.array(importResultSchema),
});
export const importFinishReplySchema = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
matched: z.boolean(),
count: z.int().nonnegative(),
});
export const peopleEnsureReplySchema = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
sub: idSchema,
created: z.boolean(),
});
export const okReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEMA), ok: z.literal(true) });
/** 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",
] as const;
/**
* The hash `import.finish` carries: SHA-256 (hex) of the sorted ids joined by "\n". Pure JS so it
* works in the browser build too; products compute it over the ids they sent (not `refused`).
*/
export function importIdsInput(ids: Iterable<string>): string {
return [...ids].sort().join("\n");
}
+1
View File
@@ -7,6 +7,7 @@ export * from "./common";
export * from "./event";
export * from "./church";
export * from "./identity";
export * from "./identity-request";
export * from "./return-to";
export * from "./link";
export * from "./oidc";
+37
View File
@@ -1,6 +1,7 @@
import {
createCipheriv,
createDecipheriv,
createHash,
createHmac,
createPrivateKey,
createPublicKey,
@@ -15,6 +16,7 @@ import {
} from "node:crypto";
import { AGENT_HEADERS, type Sealed } from "./agent";
import { canonicalJson } from "./canonical";
import { importIdsInput } from "./identity-request";
export { canonicalJson } from "./canonical";
@@ -292,3 +294,38 @@ export function verifyLink(message: Record<string, unknown>, publicKeyPem: strin
export function oidcClientSecret(linkSecret: string): string {
return b64u(createHmac("sha256", linkSecret).update("crosscode.oidc-client/1").digest());
}
// ---------------------------------------------------------------------------------------------
// Moving users into Accounts (contracts 1.8.0, docs/EVENTS-3.0-PLAN.md §4): secret fields of an
// `import.batch` are sealed with a key derived from the link's secret, on top of the request's
// signature, so a password hash or authenticator secret never shows up in a proxy or error log.
// ---------------------------------------------------------------------------------------------
const SEALED_PREFIX = "sealed1.";
function linkSealKey(linkSecret: string): Buffer {
return Buffer.from(hkdfSync("sha256", Buffer.from(linkSecret), Buffer.alloc(0), Buffer.from("crosscode.identity-import/1"), 32));
}
/** `sealed1.<base64url(iv ‖ ciphertext ‖ tag)>`, AES-256-GCM with a key from the link's secret. */
export function sealLinkValue(linkSecret: string, plain: string): string {
const iv = randomBytes(12);
const cipher = createCipheriv("aes-256-gcm", linkSealKey(linkSecret), iv);
const data = Buffer.concat([cipher.update(plain, "utf8"), cipher.final()]);
return `${SEALED_PREFIX}${b64u(Buffer.concat([iv, data, cipher.getAuthTag()]))}`;
}
/** Opens a value from {@link sealLinkValue}. Throws if it was changed or sealed with another link's secret. */
export function openLinkValue(linkSecret: string, sealed: string): string {
if (!sealed.startsWith(SEALED_PREFIX)) throw new Error("Not a sealed value");
const raw = unb64u(sealed.slice(SEALED_PREFIX.length));
if (raw.length < 12 + 16) throw new Error("Not a sealed value");
const decipher = createDecipheriv("aes-256-gcm", linkSealKey(linkSecret), raw.subarray(0, 12));
decipher.setAuthTag(raw.subarray(raw.length - 16));
return Buffer.concat([decipher.update(raw.subarray(12, raw.length - 16)), decipher.final()]).toString("utf8");
}
/** The `idsHash` of `import.finish`: SHA-256 (hex) of the sorted ids joined by "\n". */
export function importIdsHash(ids: Iterable<string>): string {
return createHash("sha256").update(importIdsInput(ids)).digest("hex");
}
@@ -0,0 +1,40 @@
import { identityRequestSchema, importPersonSchema, sealedValueSchema } from "../src";
import { importIdsHash, newLinkSecret, openLinkValue, sealLinkValue } from "../src/signing";
import { sample } from "./helpers";
describe("crosscode.identity-request/1", () => {
test("a sealed value opens with the same link secret, and only that one", () => {
const secret = newLinkSecret();
const hash = "$2b$10$abcdefghijklmnopqrstuuJt1Yx0H1iLx3m6nS6m1j0fDqv3p4q5W";
const sealed = sealLinkValue(secret, hash);
expect(sealedValueSchema.safeParse(sealed).success).toBe(true);
expect(sealed).not.toContain("abcdefghij");
expect(openLinkValue(secret, sealed)).toBe(hash);
expect(() => openLinkValue(newLinkSecret(), sealed)).toThrow();
const tampered = sealed.slice(0, -2) + (sealed.endsWith("A") ? "BB" : "AA");
expect(() => openLinkValue(secret, tampered)).toThrow();
});
test("the ids hash doesn't depend on order", () => {
const a = ["b8f1c2d3-0000-4000-8000-000000000002", "a7e0b1c2-0000-4000-8000-000000000001"];
expect(importIdsHash(a)).toBe(importIdsHash([...a].reverse()));
expect(importIdsHash(a)).toMatch(/^[0-9a-f]{64}$/);
expect(importIdsHash(a)).not.toBe(importIdsHash(a.slice(0, 1)));
});
test("an unsealed password hash is refused", () => {
const person = sample<{ people: Record<string, unknown>[] }>("import-batch.json").people[0]!;
expect(importPersonSchema.safeParse(person).success).toBe(true);
expect(importPersonSchema.safeParse({ ...person, passwordHash: "$2b$10$plain" }).success).toBe(false);
});
test("a batch is at most 200 people", () => {
const batch = sample<{ people: unknown[] }>("import-batch.json");
const many = { ...batch, people: Array.from({ length: 201 }, () => batch.people[0]) };
expect(identityRequestSchema.safeParse(many).success).toBe(false);
});
test("unknown request types are refused", () => {
expect(identityRequestSchema.safeParse({ ...sample("people-ensure.json"), type: "people.delete" }).success).toBe(false);
});
});
@@ -40,6 +40,12 @@ const SAMPLE_SCHEMA: Record<string, string> = {
"link-connect.json": "link-connect",
"link-connected.json": "link-connected",
"link-disconnect.json": "link-disconnect",
"import-begin.json": "identity-request",
"import-batch.json": "identity-request",
"import-batch-reply.json": "import-batch-reply",
"import-finish.json": "identity-request",
"people-ensure.json": "identity-request",
"people-ensure-reply.json": "people-ensure-reply",
};
describe("JSON Schema (schemas/)", () => {
+9
View File
@@ -13,6 +13,9 @@ import {
linkConnectedSchema,
linkDisconnectSchema,
identityClaimsSchema,
identityRequestSchema,
importBatchReplySchema,
peopleEnsureReplySchema,
userDeletedReplySchema,
userExportReplySchema,
} from "../src";
@@ -44,6 +47,12 @@ const SCHEMAS: Record<string, z.ZodType> = {
"link-connect.json": linkConnectSchema,
"link-connected.json": linkConnectedSchema,
"link-disconnect.json": linkDisconnectSchema,
"import-begin.json": identityRequestSchema,
"import-batch.json": identityRequestSchema,
"import-batch-reply.json": importBatchReplySchema,
"import-finish.json": identityRequestSchema,
"people-ensure.json": identityRequestSchema,
"people-ensure-reply.json": peopleEnsureReplySchema,
};
describe("samples", () => {