From 9e94c8250242d398c998dc0098e14c035b8305a7 Mon Sep 17 00:00:00 2001 From: Joshua Oosthuizen Date: Wed, 4 Nov 2026 14:30:37 +0200 Subject: [PATCH] Contracts 1.0.0: generated JSON Schema for every contract - schemas/: JSON Schema (draft 2020-12) generated from the zod schemas by npm run build (scripts/json-schemas.cjs), exported as @crosscode/contracts/schemas/* - Test: files match the zod schemas, every sample passes them (Ajv) - Version 1.0.0, CHANGELOG and README Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +- eslint.config.mjs | 2 +- package-lock.json | 97 ++ packages/contracts/README.md | 11 +- packages/contracts/package.json | 9 +- packages/contracts/schemas/accounts-call.json | 204 ++++ packages/contracts/schemas/church.json | 549 +++++++++++ packages/contracts/schemas/event-changed.json | 35 + packages/contracts/schemas/event-feed.json | 440 +++++++++ packages/contracts/schemas/event.json | 395 ++++++++ packages/contracts/schemas/health.json | 96 ++ .../schemas/hub-ai-complete-request.json | 49 + .../schemas/hub-ai-complete-response.json | 86 ++ .../schemas/hub-ai-status-request.json | 14 + packages/contracts/schemas/hub-ai-status.json | 38 + packages/contracts/schemas/hub-error.json | 18 + .../schemas/hub-heartbeat-request.json | 922 ++++++++++++++++++ .../schemas/hub-heartbeat-response.json | 163 ++++ .../schemas/hub-licence-payload.json | 101 ++ .../schemas/hub-public-key-response.json | 32 + .../schemas/hub-register-request.json | 154 +++ .../schemas/hub-register-response.json | 174 ++++ .../hub-update-request-cancel-response.json | 13 + .../schemas/hub-update-request-cancel.json | 14 + .../schemas/hub-update-request-response.json | 32 + .../contracts/schemas/hub-update-request.json | 19 + .../contracts/schemas/identity-claims.json | 125 +++ .../contracts/schemas/user-deleted-reply.json | 52 + packages/contracts/schemas/user-deleted.json | 43 + .../contracts/schemas/user-export-reply.json | 77 ++ packages/contracts/schemas/user-export.json | 43 + .../contracts/schemas/user-updated-reply.json | 19 + packages/contracts/schemas/user-updated.json | 118 +++ packages/contracts/scripts/json-schemas.cjs | 101 ++ packages/contracts/tests/json-schemas.test.ts | 82 ++ 35 files changed, 4330 insertions(+), 5 deletions(-) create mode 100644 packages/contracts/schemas/accounts-call.json create mode 100644 packages/contracts/schemas/church.json create mode 100644 packages/contracts/schemas/event-changed.json create mode 100644 packages/contracts/schemas/event-feed.json create mode 100644 packages/contracts/schemas/event.json create mode 100644 packages/contracts/schemas/health.json create mode 100644 packages/contracts/schemas/hub-ai-complete-request.json create mode 100644 packages/contracts/schemas/hub-ai-complete-response.json create mode 100644 packages/contracts/schemas/hub-ai-status-request.json create mode 100644 packages/contracts/schemas/hub-ai-status.json create mode 100644 packages/contracts/schemas/hub-error.json create mode 100644 packages/contracts/schemas/hub-heartbeat-request.json create mode 100644 packages/contracts/schemas/hub-heartbeat-response.json create mode 100644 packages/contracts/schemas/hub-licence-payload.json create mode 100644 packages/contracts/schemas/hub-public-key-response.json create mode 100644 packages/contracts/schemas/hub-register-request.json create mode 100644 packages/contracts/schemas/hub-register-response.json create mode 100644 packages/contracts/schemas/hub-update-request-cancel-response.json create mode 100644 packages/contracts/schemas/hub-update-request-cancel.json create mode 100644 packages/contracts/schemas/hub-update-request-response.json create mode 100644 packages/contracts/schemas/hub-update-request.json create mode 100644 packages/contracts/schemas/identity-claims.json create mode 100644 packages/contracts/schemas/user-deleted-reply.json create mode 100644 packages/contracts/schemas/user-deleted.json create mode 100644 packages/contracts/schemas/user-export-reply.json create mode 100644 packages/contracts/schemas/user-export.json create mode 100644 packages/contracts/schemas/user-updated-reply.json create mode 100644 packages/contracts/schemas/user-updated.json create mode 100644 packages/contracts/scripts/json-schemas.cjs create mode 100644 packages/contracts/tests/json-schemas.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d08a2f1..f40b876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `a ## Unreleased +## contracts@1.0.0 - 2026-11-04 + ### Monorepo - Set up: npm workspaces (`packages/*`, `apps/*`), shared TypeScript, ESLint and Jest setup, @@ -12,7 +14,7 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `a schema-name helpers every contract uses (`crosscode./`). - `packages/ui`, `apps/accounts`, `apps/website`, `apps/app`: placeholders. -### Contracts (towards 1.0.0) +### Contracts - `crosscode.event/1` and `crosscode.event-feed/1`: the event, the feed response and the `event.changed` webhook. Checks that `startsAt` / `endsAt` match the sessions and that only @@ -30,3 +32,7 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `a products in the replies, `customerId` / `product` in the licence token. - `@crosscode/contracts/signing` (Node only): the Hub's HMAC scheme for the Hub and product links. - Sample payloads for every contract in `samples/`, checked by the tests. +- **JSON Schema** (draft 2020-12) for every contract in `schemas/`, generated from the zod + schemas by `npm run build` (`scripts/json-schemas.cjs`), for consumers that don't use + TypeScript or zod. A test checks the files match the zod schemas and that every sample passes + them (Ajv). Checks JSON Schema can't express (e.g. `startsAt` matching the sessions) only run in zod. diff --git a/eslint.config.mjs b/eslint.config.mjs index 4f4f856..5844573 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -8,7 +8,7 @@ export default defineConfig([ ...tseslint.configs.recommended, { files: ["**/*.cjs", "**/jest.config.js"], - languageOptions: { sourceType: "commonjs", globals: { module: "writable", require: "readonly" } }, + languageOptions: { sourceType: "commonjs", globals: { module: "writable", require: "readonly", __dirname: "readonly", process: "readonly", console: "readonly" } }, rules: { "@typescript-eslint/no-require-imports": "off" }, }, { diff --git a/package-lock.json b/package-lock.json index 99271fc..4604a1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3363,6 +3363,48 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/ajv-formats/node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, "node_modules/ansi-escapes": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", @@ -4318,6 +4360,23 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-uri": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", + "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/fb-watchman": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.4.tgz", @@ -6212,6 +6271,16 @@ "node": ">=0.10.0" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/resolve-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz", @@ -7210,8 +7279,36 @@ "license": "UNLICENSED", "dependencies": { "zod": "^4.6.7" + }, + "devDependencies": { + "ajv": "^8.20.0", + "ajv-formats": "^3.0.1" } }, + "packages/contracts/node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "packages/contracts/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, "packages/ui": { "name": "@crosscode/ui", "version": "0.0.0" diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 87aebb0..b7fbb65 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -1,7 +1,7 @@ # @crosscode/contracts Everything that crosses between Cross Code products is defined once, here (ROADMAP-v3 §2): -zod schemas, TypeScript types and sample payloads (`samples/`). Every product, including Cross +zod schemas, JSON Schema (`schemas/`), TypeScript types and sample payloads (`samples/`). Every product, including Cross Events and the Hub, uses it, so the key fields are the same in every product's JSON. | Contract | Schema name | Used for | Source | @@ -62,6 +62,15 @@ for install → Hub; `LINK_HEADERS` (`X-Crosscode-Sender`, `-Timestamp`, `-Signa `event.changed` webhooks and Accounts back-channel calls, with the secret set up by **Connect**. Verify the raw bytes before parsing the JSON. +### JSON Schema + +`schemas/` has a JSON Schema (draft 2020-12) for every contract, for consumers that don't use +TypeScript or zod (e.g. `@crosscode/contracts/schemas/event.json`). They are generated from the +zod schemas by `npm run build`; commit them with the change (a test fails when they're out of +date). They allow unknown fields, like the zod schemas. The zod schemas stay the source of truth: +a few checks can't be written in JSON Schema (e.g. `startsAt` / `endsAt` matching the sessions, +only Cross Events using `registration.mode: "origin"`), so use the zod schemas where you can. + ## Versioning - Every payload carries its `schema` name: `crosscode./` (`parseSchemaName`, `isSchema`). diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 7393b64..9f1f12f 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/contracts", - "version": "0.1.0", + "version": "1.0.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", @@ -28,6 +28,7 @@ "default": "./dist/signing.js" } }, + "./schemas/*": "./schemas/*", "./package.json": "./package.json" }, "files": [ @@ -38,7 +39,7 @@ ], "sideEffects": false, "scripts": { - "build": "tsup", + "build": "tsup && node scripts/json-schemas.cjs", "typecheck": "tsc -p tsconfig.json --noEmit", "test": "jest" }, @@ -52,5 +53,9 @@ "type": "git", "url": "https://c-git.crosscode.co.za/joshua/crosscode-platform.git", "directory": "packages/contracts" + }, + "devDependencies": { + "ajv": "^8.20.0", + "ajv-formats": "^3.0.1" } } diff --git a/packages/contracts/schemas/accounts-call.json b/packages/contracts/schemas/accounts-call.json new file mode 100644 index 0000000..c0a59c2 --- /dev/null +++ b/packages/contracts/schemas/accounts-call.json @@ -0,0 +1,204 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/accounts-call.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.updated" + }, + "profile": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "given_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "family_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "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,}$" + }, + "email_verified": { + "type": "boolean" + }, + "phone_number": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "phone_number_verified": { + "type": "boolean" + }, + "news_consent": { + "type": "object", + "properties": { + "email": { + "type": "boolean" + }, + "whatsapp": { + "type": "boolean" + } + }, + "required": [ + "email", + "whatsapp" + ] + } + }, + "required": [ + "name", + "given_name", + "family_name", + "email", + "email_verified", + "phone_number", + "phone_number_verified", + "news_consent" + ] + } + }, + "required": [ + "schema", + "callId", + "occurredAt", + "sub", + "type", + "profile" + ] + }, + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.deleted" + }, + "approvedAt": { + "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": [ + "schema", + "callId", + "occurredAt", + "sub", + "type", + "approvedAt" + ] + }, + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.export" + }, + "exportId": { + "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", + "callId", + "occurredAt", + "sub", + "type", + "exportId" + ] + } + ] +} diff --git a/packages/contracts/schemas/church.json b/packages/contracts/schemas/church.json new file mode 100644 index 0000000..81f8b3b --- /dev/null +++ b/packages/contracts/schemas/church.json @@ -0,0 +1,549 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/church.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.church/1" + }, + "customerId": { + "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)$" + }, + "updatedAt": { + "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))$" + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "shortName": { + "anyOf": [ + { + "type": "string", + "maxLength": 30 + }, + { + "type": "null" + } + ] + }, + "timezone": { + "type": "string", + "pattern": "^[A-Za-z_]+(\\/[A-Za-z0-9_+-]+){0,2}$|^UTC$" + }, + "locale": { + "type": "string", + "pattern": "^[a-z]{2,3}(-[A-Z]{2})?$" + }, + "branding": { + "type": "object", + "properties": { + "logoUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "iconUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "colours": { + "type": "object", + "properties": { + "primary": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + "accent": { + "anyOf": [ + { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "primary", + "accent" + ] + } + }, + "required": [ + "logoUrl", + "iconUrl", + "colours" + ] + }, + "campuses": { + "maxItems": 50, + "type": "array", + "items": { + "type": "object", + "properties": { + "slug": { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "address": { + "anyOf": [ + { + "type": "object", + "properties": { + "line1": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "line2": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "suburb": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "city": { + "type": "string", + "minLength": 1, + "maxLength": 100 + }, + "province": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "postalCode": { + "anyOf": [ + { + "type": "string", + "maxLength": 20 + }, + { + "type": "null" + } + ] + }, + "country": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "geo": { + "anyOf": [ + { + "type": "object", + "properties": { + "lat": { + "type": "number", + "minimum": -90, + "maximum": 90 + }, + "lng": { + "type": "number", + "minimum": -180, + "maximum": 180 + } + }, + "required": [ + "lat", + "lng" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "line1", + "line2", + "suburb", + "city", + "province", + "postalCode", + "country", + "geo" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "slug", + "name", + "address" + ] + } + }, + "serviceTimes": { + "maxItems": 100, + "type": "array", + "items": { + "type": "object", + "properties": { + "day": { + "type": "string", + "enum": [ + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday" + ] + }, + "time": { + "type": "string", + "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$" + }, + "label": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "campus": { + "anyOf": [ + { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + }, + { + "type": "null" + } + ] + }, + "note": { + "anyOf": [ + { + "type": "string", + "maxLength": 300 + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "day", + "time", + "label", + "campus", + "note" + ] + } + }, + "contact": { + "type": "object", + "properties": { + "email": { + "anyOf": [ + { + "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,}$" + }, + { + "type": "null" + } + ] + }, + "phone": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "whatsapp": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "address": { + "anyOf": [ + { + "type": "object", + "properties": { + "line1": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "line2": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "suburb": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "city": { + "type": "string", + "minLength": 1, + "maxLength": 100 + }, + "province": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "postalCode": { + "anyOf": [ + { + "type": "string", + "maxLength": 20 + }, + { + "type": "null" + } + ] + }, + "country": { + "type": "string", + "pattern": "^[A-Z]{2}$" + }, + "geo": { + "anyOf": [ + { + "type": "object", + "properties": { + "lat": { + "type": "number", + "minimum": -90, + "maximum": 90 + }, + "lng": { + "type": "number", + "minimum": -180, + "maximum": 180 + } + }, + "required": [ + "lat", + "lng" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "line1", + "line2", + "suburb", + "city", + "province", + "postalCode", + "country", + "geo" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "email", + "phone", + "whatsapp", + "address" + ] + }, + "social": { + "maxItems": 20, + "type": "array", + "items": { + "type": "object", + "properties": { + "network": { + "type": "string", + "enum": [ + "facebook", + "instagram", + "youtube", + "tiktok", + "x", + "spotify", + "whatsapp-channel", + "other" + ] + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": [ + "network", + "url" + ] + } + }, + "links": { + "type": "object", + "properties": { + "website": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "events": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "app": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "accounts": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": [ + "website", + "events", + "app", + "accounts" + ] + } + }, + "required": [ + "schema", + "customerId", + "updatedAt", + "name", + "shortName", + "timezone", + "locale", + "branding", + "campuses", + "serviceTimes", + "contact", + "social", + "links" + ] +} diff --git a/packages/contracts/schemas/event-changed.json b/packages/contracts/schemas/event-changed.json new file mode 100644 index 0000000..1ef7a49 --- /dev/null +++ b/packages/contracts/schemas/event-changed.json @@ -0,0 +1,35 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/event-changed.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.event-feed/1" + }, + "type": { + "type": "string", + "const": "event.changed" + }, + "occurredAt": { + "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))$" + }, + "eventIds": { + "maxItems": 100, + "type": "array", + "items": { + "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", + "type", + "occurredAt", + "eventIds" + ] +} diff --git a/packages/contracts/schemas/event-feed.json b/packages/contracts/schemas/event-feed.json new file mode 100644 index 0000000..17247e8 --- /dev/null +++ b/packages/contracts/schemas/event-feed.json @@ -0,0 +1,440 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/event-feed.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.event-feed/1" + }, + "generatedAt": { + "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))$" + }, + "events": { + "type": "array", + "items": { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.event/1" + }, + "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)$" + }, + "origin": { + "type": "object", + "properties": { + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app" + ] + }, + "installId": { + "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)$" + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": [ + "product", + "installId", + "url" + ] + }, + "status": { + "type": "string", + "enum": [ + "published", + "cancelled" + ] + }, + "updatedAt": { + "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))$" + }, + "title": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "summary": { + "anyOf": [ + { + "type": "string", + "maxLength": 300 + }, + { + "type": "null" + } + ] + }, + "description": { + "anyOf": [ + { + "type": "string", + "maxLength": 20000 + }, + { + "type": "null" + } + ] + }, + "imageUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "timezone": { + "type": "string", + "pattern": "^[A-Za-z_]+(\\/[A-Za-z0-9_+-]+){0,2}$|^UTC$" + }, + "startsAt": { + "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))$" + }, + "endsAt": { + "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))$" + }, + "allDay": { + "type": "boolean" + }, + "sessions": { + "maxItems": 500, + "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)$" + }, + "label": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "startsAt": { + "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))$" + }, + "endsAt": { + "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))$" + }, + "location": { + "anyOf": [ + { + "type": "string", + "maxLength": 300 + }, + { + "type": "null" + } + ] + }, + "cancelled": { + "type": "boolean" + } + }, + "required": [ + "id", + "label", + "startsAt", + "endsAt", + "location", + "cancelled" + ] + } + }, + "location": { + "anyOf": [ + { + "type": "object", + "properties": { + "name": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "address": { + "anyOf": [ + { + "type": "string", + "maxLength": 500 + }, + { + "type": "null" + } + ] + }, + "onlineUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "name", + "address", + "onlineUrl" + ] + }, + { + "type": "null" + } + ] + }, + "campus": { + "anyOf": [ + { + "type": "object", + "properties": { + "slug": { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + } + }, + "required": [ + "slug", + "name" + ] + }, + { + "type": "null" + } + ] + }, + "series": { + "anyOf": [ + { + "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 + } + }, + "required": [ + "id", + "name" + ] + }, + { + "type": "null" + } + ] + }, + "tags": { + "maxItems": 20, + "type": "array", + "items": { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + } + }, + "registration": { + "type": "object", + "properties": { + "mode": { + "type": "string", + "enum": [ + "origin", + "external", + "contact", + "none" + ] + }, + "url": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "status": { + "type": "string", + "enum": [ + "open", + "not_open", + "closed", + "full", + "waitlist" + ] + }, + "opensAt": { + "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" + } + ] + }, + "closesAt": { + "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" + } + ] + }, + "priceFrom": { + "anyOf": [ + { + "type": "object", + "properties": { + "amountCents": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "currency": { + "type": "string", + "pattern": "^[A-Z]{3}$" + } + }, + "required": [ + "amountCents", + "currency" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "mode", + "url", + "status", + "opensAt", + "closesAt", + "priceFrom" + ] + } + }, + "required": [ + "schema", + "id", + "origin", + "status", + "updatedAt", + "title", + "summary", + "description", + "imageUrl", + "timezone", + "startsAt", + "endsAt", + "allDay", + "sessions", + "location", + "campus", + "series", + "tags", + "registration" + ] + } + }, + "deleted": { + "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)$" + }, + "deletedAt": { + "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", + "deletedAt" + ] + } + } + }, + "required": [ + "schema", + "generatedAt", + "events", + "deleted" + ] +} diff --git a/packages/contracts/schemas/event.json b/packages/contracts/schemas/event.json new file mode 100644 index 0000000..7063a08 --- /dev/null +++ b/packages/contracts/schemas/event.json @@ -0,0 +1,395 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/event.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.event/1" + }, + "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)$" + }, + "origin": { + "type": "object", + "properties": { + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app" + ] + }, + "installId": { + "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)$" + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + } + }, + "required": [ + "product", + "installId", + "url" + ] + }, + "status": { + "type": "string", + "enum": [ + "published", + "cancelled" + ] + }, + "updatedAt": { + "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))$" + }, + "title": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "summary": { + "anyOf": [ + { + "type": "string", + "maxLength": 300 + }, + { + "type": "null" + } + ] + }, + "description": { + "anyOf": [ + { + "type": "string", + "maxLength": 20000 + }, + { + "type": "null" + } + ] + }, + "imageUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "timezone": { + "type": "string", + "pattern": "^[A-Za-z_]+(\\/[A-Za-z0-9_+-]+){0,2}$|^UTC$" + }, + "startsAt": { + "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))$" + }, + "endsAt": { + "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))$" + }, + "allDay": { + "type": "boolean" + }, + "sessions": { + "maxItems": 500, + "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)$" + }, + "label": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "startsAt": { + "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))$" + }, + "endsAt": { + "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))$" + }, + "location": { + "anyOf": [ + { + "type": "string", + "maxLength": 300 + }, + { + "type": "null" + } + ] + }, + "cancelled": { + "type": "boolean" + } + }, + "required": [ + "id", + "label", + "startsAt", + "endsAt", + "location", + "cancelled" + ] + } + }, + "location": { + "anyOf": [ + { + "type": "object", + "properties": { + "name": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "address": { + "anyOf": [ + { + "type": "string", + "maxLength": 500 + }, + { + "type": "null" + } + ] + }, + "onlineUrl": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "name", + "address", + "onlineUrl" + ] + }, + { + "type": "null" + } + ] + }, + "campus": { + "anyOf": [ + { + "type": "object", + "properties": { + "slug": { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + }, + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + } + }, + "required": [ + "slug", + "name" + ] + }, + { + "type": "null" + } + ] + }, + "series": { + "anyOf": [ + { + "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 + } + }, + "required": [ + "id", + "name" + ] + }, + { + "type": "null" + } + ] + }, + "tags": { + "maxItems": 20, + "type": "array", + "items": { + "type": "string", + "maxLength": 100, + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" + } + }, + "registration": { + "type": "object", + "properties": { + "mode": { + "type": "string", + "enum": [ + "origin", + "external", + "contact", + "none" + ] + }, + "url": { + "anyOf": [ + { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + { + "type": "null" + } + ] + }, + "status": { + "type": "string", + "enum": [ + "open", + "not_open", + "closed", + "full", + "waitlist" + ] + }, + "opensAt": { + "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" + } + ] + }, + "closesAt": { + "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" + } + ] + }, + "priceFrom": { + "anyOf": [ + { + "type": "object", + "properties": { + "amountCents": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "currency": { + "type": "string", + "pattern": "^[A-Z]{3}$" + } + }, + "required": [ + "amountCents", + "currency" + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "mode", + "url", + "status", + "opensAt", + "closesAt", + "priceFrom" + ] + } + }, + "required": [ + "schema", + "id", + "origin", + "status", + "updatedAt", + "title", + "summary", + "description", + "imageUrl", + "timezone", + "startsAt", + "endsAt", + "allDay", + "sessions", + "location", + "campus", + "series", + "tags", + "registration" + ] +} diff --git a/packages/contracts/schemas/health.json b/packages/contracts/schemas/health.json new file mode 100644 index 0000000..45e16b6 --- /dev/null +++ b/packages/contracts/schemas/health.json @@ -0,0 +1,96 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/health.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "uptimeSeconds": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "db": { + "type": "boolean" + }, + "jobs": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "failedLast24h": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "mode", + "failedLast24h" + ] + }, + "lastBackupAt": { + "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" + } + ] + }, + "disk": { + "anyOf": [ + { + "type": "object", + "properties": { + "freeBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totalBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "freeBytes", + "totalBytes" + ] + }, + { + "type": "null" + } + ] + }, + "errorsLast24h": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ] + }, + "pendingMigrations": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "uptimeSeconds", + "db", + "jobs", + "lastBackupAt", + "disk", + "errorsLast24h", + "pendingMigrations" + ] +} diff --git a/packages/contracts/schemas/hub-ai-complete-request.json b/packages/contracts/schemas/hub-ai-complete-request.json new file mode 100644 index 0000000..e178648 --- /dev/null +++ b/packages/contracts/schemas/hub-ai-complete-request.json @@ -0,0 +1,49 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-ai-complete-request.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "helper": { + "type": "string", + "maxLength": 60, + "pattern": "^[a-z][a-z0-9_]*$" + }, + "system": { + "type": "string" + }, + "input": { + "type": "string" + }, + "schema": { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": {} + }, + "maxTokens": { + "type": "integer", + "minimum": 1, + "maximum": 8000 + }, + "effort": { + "type": "string", + "enum": [ + "low", + "medium", + "high" + ] + } + }, + "required": [ + "protocolVersion", + "helper", + "system", + "input", + "maxTokens" + ] +} diff --git a/packages/contracts/schemas/hub-ai-complete-response.json b/packages/contracts/schemas/hub-ai-complete-response.json new file mode 100644 index 0000000..b421071 --- /dev/null +++ b/packages/contracts/schemas/hub-ai-complete-response.json @@ -0,0 +1,86 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-ai-complete-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "output": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": {} + } + ] + }, + "usage": { + "type": "object", + "properties": { + "inputTokens": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "outputTokens": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "inputTokens", + "outputTokens" + ] + }, + "chargedCents": { + "type": "number", + "minimum": 0 + }, + "status": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "capReached": { + "type": "boolean" + }, + "capCents": { + "type": "number", + "minimum": 0 + }, + "usedCents": { + "type": "number", + "minimum": 0 + }, + "usedPercent": { + "type": "number", + "minimum": 0 + }, + "renewsOn": { + "type": "string", + "format": "date", + "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])))$" + } + }, + "required": [ + "enabled", + "capReached", + "capCents", + "usedCents", + "usedPercent", + "renewsOn" + ] + } + }, + "required": [ + "output", + "usage", + "chargedCents", + "status" + ] +} diff --git a/packages/contracts/schemas/hub-ai-status-request.json b/packages/contracts/schemas/hub-ai-status-request.json new file mode 100644 index 0000000..9923b1c --- /dev/null +++ b/packages/contracts/schemas/hub-ai-status-request.json @@ -0,0 +1,14 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-ai-status-request.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + } + }, + "required": [ + "protocolVersion" + ] +} diff --git a/packages/contracts/schemas/hub-ai-status.json b/packages/contracts/schemas/hub-ai-status.json new file mode 100644 index 0000000..4e05a65 --- /dev/null +++ b/packages/contracts/schemas/hub-ai-status.json @@ -0,0 +1,38 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-ai-status.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "capReached": { + "type": "boolean" + }, + "capCents": { + "type": "number", + "minimum": 0 + }, + "usedCents": { + "type": "number", + "minimum": 0 + }, + "usedPercent": { + "type": "number", + "minimum": 0 + }, + "renewsOn": { + "type": "string", + "format": "date", + "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])))$" + } + }, + "required": [ + "enabled", + "capReached", + "capCents", + "usedCents", + "usedPercent", + "renewsOn" + ] +} diff --git a/packages/contracts/schemas/hub-error.json b/packages/contracts/schemas/hub-error.json new file mode 100644 index 0000000..fbdda4a --- /dev/null +++ b/packages/contracts/schemas/hub-error.json @@ -0,0 +1,18 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-error.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "code": { + "type": "string", + "pattern": "^[A-Z][A-Z0-9_]*$" + } + }, + "required": [ + "message", + "code" + ] +} diff --git a/packages/contracts/schemas/hub-heartbeat-request.json b/packages/contracts/schemas/hub-heartbeat-request.json new file mode 100644 index 0000000..de10033 --- /dev/null +++ b/packages/contracts/schemas/hub-heartbeat-request.json @@ -0,0 +1,922 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-heartbeat-request.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "health": { + "type": "object", + "properties": { + "uptimeSeconds": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "db": { + "type": "boolean" + }, + "jobs": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "failedLast24h": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "mode", + "failedLast24h" + ] + }, + "lastBackupAt": { + "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" + } + ] + }, + "disk": { + "anyOf": [ + { + "type": "object", + "properties": { + "freeBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totalBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "freeBytes", + "totalBytes" + ] + }, + { + "type": "null" + } + ] + }, + "errorsLast24h": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ] + }, + "pendingMigrations": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "uptimeSeconds", + "db", + "jobs", + "lastBackupAt", + "disk", + "errorsLast24h", + "pendingMigrations" + ] + }, + "product": { + "type": "string", + "const": "events" + }, + "stats": { + "type": "object", + "properties": { + "users": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "events": { + "type": "object", + "properties": { + "active": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "upcoming": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "total": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "active", + "upcoming", + "total" + ] + }, + "registrations": { + "type": "object", + "properties": { + "last30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "total": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "last30d", + "total" + ] + }, + "tickets": { + "type": "object", + "properties": { + "last30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "total": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "last30d", + "total" + ] + }, + "checkIns": { + "type": "object", + "properties": { + "last30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "last30d" + ] + }, + "messages": { + "anyOf": [ + { + "type": "object", + "properties": { + "email30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "whatsapp30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "email30d", + "whatsapp30d" + ] + }, + { + "type": "null" + } + ] + }, + "paymentProviders": { + "type": "array", + "items": { + "type": "string" + } + }, + "campuses": { + "type": "boolean" + }, + "campusCount": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "income": { + "type": "object", + "properties": { + "last30d": { + "type": "string", + "enum": [ + "R0–R1 000", + "R1 001–R5 000", + "R5 001–R20 000", + "R20 001–R50 000", + "R50 001–R100 000", + "R100 001–R150 000", + "R150 001–R250 000", + "R250 001–R400 000", + "R400 001–R700 000", + "R700 001–R1 000 000", + "R1 000 001–R2 500 000", + "R2 500 001–R5 000 000", + "R5 000 001–R10 000 000", + "over R10 000 000" + ] + }, + "allTime": { + "type": "string", + "enum": [ + "R0–R1 000", + "R1 001–R5 000", + "R5 001–R20 000", + "R20 001–R50 000", + "R50 001–R100 000", + "R100 001–R150 000", + "R150 001–R250 000", + "R250 001–R400 000", + "R400 001–R700 000", + "R700 001–R1 000 000", + "R1 000 001–R2 500 000", + "R2 500 001–R5 000 000", + "R5 000 001–R10 000 000", + "over R10 000 000" + ] + }, + "eventIncome12m": { + "type": "string", + "enum": [ + "R0–R1 000", + "R1 001–R5 000", + "R5 001–R20 000", + "R20 001–R50 000", + "R50 001–R100 000", + "R100 001–R150 000", + "R150 001–R250 000", + "R250 001–R400 000", + "R400 001–R700 000", + "R700 001–R1 000 000", + "R1 000 001–R2 500 000", + "R2 500 001–R5 000 000", + "R5 000 001–R10 000 000", + "over R10 000 000" + ] + } + }, + "required": [ + "last30d", + "allTime", + "eventIncome12m" + ] + } + }, + "required": [ + "users", + "events", + "registrations", + "tickets", + "checkIns", + "messages", + "paymentProviders", + "campuses", + "campusCount", + "income" + ] + } + }, + "required": [ + "protocolVersion", + "version", + "health", + "product", + "stats" + ] + }, + { + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "health": { + "type": "object", + "properties": { + "uptimeSeconds": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "db": { + "type": "boolean" + }, + "jobs": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "failedLast24h": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "mode", + "failedLast24h" + ] + }, + "lastBackupAt": { + "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" + } + ] + }, + "disk": { + "anyOf": [ + { + "type": "object", + "properties": { + "freeBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totalBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "freeBytes", + "totalBytes" + ] + }, + { + "type": "null" + } + ] + }, + "errorsLast24h": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ] + }, + "pendingMigrations": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "uptimeSeconds", + "db", + "jobs", + "lastBackupAt", + "disk", + "errorsLast24h", + "pendingMigrations" + ] + }, + "product": { + "type": "string", + "const": "website" + }, + "stats": { + "type": "object", + "properties": { + "pages": { + "type": "object", + "properties": { + "published": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "drafts": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "published", + "drafts" + ] + }, + "messages": { + "type": "object", + "properties": { + "total": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "last30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "total", + "last30d" + ] + }, + "events": { + "type": "object", + "properties": { + "upcomingSimple": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "imported": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "upcomingSimple", + "imported" + ] + }, + "editors": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "storage": { + "type": "object", + "properties": { + "usedBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "includedBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "usedBytes", + "includedBytes" + ] + } + }, + "required": [ + "pages", + "messages", + "events", + "editors", + "storage" + ] + } + }, + "required": [ + "protocolVersion", + "version", + "health", + "product", + "stats" + ] + }, + { + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "health": { + "type": "object", + "properties": { + "uptimeSeconds": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "db": { + "type": "boolean" + }, + "jobs": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "failedLast24h": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "mode", + "failedLast24h" + ] + }, + "lastBackupAt": { + "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" + } + ] + }, + "disk": { + "anyOf": [ + { + "type": "object", + "properties": { + "freeBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totalBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "freeBytes", + "totalBytes" + ] + }, + { + "type": "null" + } + ] + }, + "errorsLast24h": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ] + }, + "pendingMigrations": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "uptimeSeconds", + "db", + "jobs", + "lastBackupAt", + "disk", + "errorsLast24h", + "pendingMigrations" + ] + }, + "product": { + "type": "string", + "const": "app" + }, + "stats": { + "type": "object", + "properties": { + "activeMembers90d": { + "type": "string", + "enum": [ + "0–100", + "101–300", + "301–750", + "751–2 000", + "2 001–5 000", + "over 5 000" + ] + }, + "modules": { + "type": "array", + "items": { + "type": "string", + "pattern": "^[a-z][a-z0-9-]*$" + } + }, + "prayer": { + "type": "object", + "properties": { + "coverageLast7dPercent": { + "type": "number", + "minimum": 0, + "maximum": 100 + }, + "activeCommitments": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "coverageLast7dPercent", + "activeCommitments" + ] + }, + "announcements": { + "type": "object", + "properties": { + "last30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "last30d" + ] + }, + "messages": { + "type": "object", + "properties": { + "email30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "whatsapp30d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "email30d", + "whatsapp30d" + ] + } + }, + "required": [ + "activeMembers90d", + "modules", + "prayer", + "announcements", + "messages" + ] + } + }, + "required": [ + "protocolVersion", + "version", + "health", + "product", + "stats" + ] + }, + { + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "health": { + "type": "object", + "properties": { + "uptimeSeconds": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "db": { + "type": "boolean" + }, + "jobs": { + "type": "object", + "properties": { + "mode": { + "type": "string" + }, + "failedLast24h": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "mode", + "failedLast24h" + ] + }, + "lastBackupAt": { + "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" + } + ] + }, + "disk": { + "anyOf": [ + { + "type": "object", + "properties": { + "freeBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totalBytes": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "freeBytes", + "totalBytes" + ] + }, + { + "type": "null" + } + ] + }, + "errorsLast24h": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + { + "type": "null" + } + ] + }, + "pendingMigrations": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "uptimeSeconds", + "db", + "jobs", + "lastBackupAt", + "disk", + "errorsLast24h", + "pendingMigrations" + ] + }, + "product": { + "type": "string", + "const": "accounts" + }, + "stats": { + "type": "object", + "properties": { + "accounts": { + "type": "object", + "properties": { + "total": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "active90d": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "total", + "active90d" + ] + }, + "twoFactor": { + "type": "object", + "properties": { + "email": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "whatsapp": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "totp": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "off": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "email", + "whatsapp", + "totp", + "off" + ] + }, + "linkedProducts": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "accounts", + "twoFactor", + "linkedProducts" + ] + } + }, + "required": [ + "protocolVersion", + "version", + "health", + "product", + "stats" + ] + } + ] +} diff --git a/packages/contracts/schemas/hub-heartbeat-response.json b/packages/contracts/schemas/hub-heartbeat-response.json new file mode 100644 index 0000000..4e7805c --- /dev/null +++ b/packages/contracts/schemas/hub-heartbeat-response.json @@ -0,0 +1,163 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-heartbeat-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "licence": { + "type": "string" + }, + "latestVersion": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + { + "type": "null" + } + ] + }, + "releases": { + "type": "array", + "items": { + "type": "object", + "properties": { + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "releasedAt": { + "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))$" + }, + "urgent": { + "type": "boolean" + }, + "notes": { + "type": "string" + } + }, + "required": [ + "version", + "releasedAt", + "urgent", + "notes" + ] + } + }, + "notices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "level": { + "type": "string", + "enum": [ + "info", + "maintenance", + "warning" + ] + }, + "title": { + "type": "string" + }, + "message": { + "type": "string" + }, + "startsAt": { + "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" + } + ] + }, + "endsAt": { + "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" + } + ] + }, + "updatedAt": { + "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", + "level", + "title", + "message", + "startsAt", + "endsAt", + "updatedAt" + ] + } + }, + "linkedProducts": { + "type": "array", + "items": { + "type": "object", + "properties": { + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app", + "accounts" + ] + }, + "installId": { + "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)$" + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + "publicKey": { + "type": "string", + "pattern": "^-----BEGIN PUBLIC KEY-----.*" + } + }, + "required": [ + "product", + "installId", + "url", + "publicKey" + ] + } + }, + "serverTime": { + "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": [ + "licence", + "latestVersion", + "releases", + "notices", + "linkedProducts", + "serverTime" + ] +} diff --git a/packages/contracts/schemas/hub-licence-payload.json b/packages/contracts/schemas/hub-licence-payload.json new file mode 100644 index 0000000..17c5a84 --- /dev/null +++ b/packages/contracts/schemas/hub-licence-payload.json @@ -0,0 +1,101 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-licence-payload.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "v": { + "type": "number", + "const": 1 + }, + "licenceId": { + "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)$" + }, + "installId": { + "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)$" + }, + "customerId": { + "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)$" + }, + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app", + "accounts" + ] + }, + "customer": { + "type": "string" + }, + "plan": { + "type": "string" + }, + "status": { + "type": "string", + "enum": [ + "active", + "suspended", + "revoked" + ] + }, + "licenceExpiresAt": { + "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" + } + ] + }, + "graceDays": { + "type": "integer", + "minimum": 0, + "maximum": 9007199254740991 + }, + "issuedAt": { + "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))$" + }, + "validUntil": { + "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))$" + }, + "limits": { + "type": "object", + "properties": { + "aiMonthlyCapCents": { + "type": "number", + "minimum": 0 + } + }, + "required": [ + "aiMonthlyCapCents" + ] + } + }, + "required": [ + "v", + "licenceId", + "installId", + "customer", + "plan", + "status", + "licenceExpiresAt", + "graceDays", + "issuedAt", + "validUntil", + "limits" + ] +} diff --git a/packages/contracts/schemas/hub-public-key-response.json b/packages/contracts/schemas/hub-public-key-response.json new file mode 100644 index 0000000..e0dfc7a --- /dev/null +++ b/packages/contracts/schemas/hub-public-key-response.json @@ -0,0 +1,32 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-public-key-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersions": { + "type": "array", + "items": { + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + } + }, + "keyId": { + "type": "string" + }, + "algorithm": { + "type": "string", + "const": "Ed25519" + }, + "publicKey": { + "type": "string", + "pattern": "^-----BEGIN PUBLIC KEY-----.*" + } + }, + "required": [ + "protocolVersions", + "keyId", + "algorithm", + "publicKey" + ] +} diff --git a/packages/contracts/schemas/hub-register-request.json b/packages/contracts/schemas/hub-register-request.json new file mode 100644 index 0000000..77fa686 --- /dev/null +++ b/packages/contracts/schemas/hub-register-request.json @@ -0,0 +1,154 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-register-request.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "licenceKey": { + "type": "string", + "pattern": "^[A-Z]{3}(-[A-Z0-9]{4}){4}$" + }, + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app", + "accounts" + ] + }, + "install": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + "adminContact": { + "anyOf": [ + { + "type": "object", + "properties": { + "name": { + "anyOf": [ + { + "type": "string", + "maxLength": 200 + }, + { + "type": "null" + } + ] + }, + "email": { + "anyOf": [ + { + "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,}$" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "name", + "email" + ] + }, + { + "type": "null" + } + ] + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "timezone": { + "type": "string", + "pattern": "^[A-Za-z_]+(\\/[A-Za-z0-9_+-]+){0,2}$|^UTC$" + }, + "server": { + "type": "object", + "properties": { + "node": { + "type": "string" + }, + "postgres": { + "type": [ + "string", + "null" + ] + }, + "os": { + "type": "string" + } + }, + "required": [ + "node", + "postgres", + "os" + ] + }, + "features": { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "type": "number" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "publicKey": { + "type": "string", + "pattern": "^-----BEGIN PUBLIC KEY-----.*" + } + }, + "required": [ + "name", + "url", + "adminContact", + "version", + "timezone", + "server", + "features", + "publicKey" + ] + } + }, + "required": [ + "protocolVersion", + "licenceKey", + "product", + "install" + ] +} diff --git a/packages/contracts/schemas/hub-register-response.json b/packages/contracts/schemas/hub-register-response.json new file mode 100644 index 0000000..6b7ea22 --- /dev/null +++ b/packages/contracts/schemas/hub-register-response.json @@ -0,0 +1,174 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-register-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "installId": { + "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)$" + }, + "installSecret": { + "type": "string", + "minLength": 32 + }, + "licence": { + "type": "string" + }, + "heartbeatIntervalMinutes": { + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + }, + "latestVersion": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + { + "type": "null" + } + ] + }, + "releases": { + "type": "array", + "items": { + "type": "object", + "properties": { + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "releasedAt": { + "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))$" + }, + "urgent": { + "type": "boolean" + }, + "notes": { + "type": "string" + } + }, + "required": [ + "version", + "releasedAt", + "urgent", + "notes" + ] + } + }, + "notices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "level": { + "type": "string", + "enum": [ + "info", + "maintenance", + "warning" + ] + }, + "title": { + "type": "string" + }, + "message": { + "type": "string" + }, + "startsAt": { + "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" + } + ] + }, + "endsAt": { + "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" + } + ] + }, + "updatedAt": { + "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", + "level", + "title", + "message", + "startsAt", + "endsAt", + "updatedAt" + ] + } + }, + "linkedProducts": { + "type": "array", + "items": { + "type": "object", + "properties": { + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app", + "accounts" + ] + }, + "installId": { + "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)$" + }, + "url": { + "type": "string", + "maxLength": 2048, + "format": "uri" + }, + "publicKey": { + "type": "string", + "pattern": "^-----BEGIN PUBLIC KEY-----.*" + } + }, + "required": [ + "product", + "installId", + "url", + "publicKey" + ] + } + } + }, + "required": [ + "installId", + "installSecret", + "licence", + "heartbeatIntervalMinutes", + "latestVersion", + "releases", + "notices", + "linkedProducts" + ] +} diff --git a/packages/contracts/schemas/hub-update-request-cancel-response.json b/packages/contracts/schemas/hub-update-request-cancel-response.json new file mode 100644 index 0000000..e39e2a3 --- /dev/null +++ b/packages/contracts/schemas/hub-update-request-cancel-response.json @@ -0,0 +1,13 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-update-request-cancel-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "cancelled": { + "type": "boolean" + } + }, + "required": [ + "cancelled" + ] +} diff --git a/packages/contracts/schemas/hub-update-request-cancel.json b/packages/contracts/schemas/hub-update-request-cancel.json new file mode 100644 index 0000000..c5004e0 --- /dev/null +++ b/packages/contracts/schemas/hub-update-request-cancel.json @@ -0,0 +1,14 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-update-request-cancel.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + } + }, + "required": [ + "protocolVersion" + ] +} diff --git a/packages/contracts/schemas/hub-update-request-response.json b/packages/contracts/schemas/hub-update-request-response.json new file mode 100644 index 0000000..01868d5 --- /dev/null +++ b/packages/contracts/schemas/hub-update-request-response.json @@ -0,0 +1,32 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-update-request-response.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "requestedAt": { + "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))$" + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + }, + "alreadyRequested": { + "type": "boolean" + }, + "changed": { + "type": "boolean" + }, + "previousVersion": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + } + }, + "required": [ + "requestedAt", + "version", + "alreadyRequested", + "changed" + ] +} diff --git a/packages/contracts/schemas/hub-update-request.json b/packages/contracts/schemas/hub-update-request.json new file mode 100644 index 0000000..d815eba --- /dev/null +++ b/packages/contracts/schemas/hub-update-request.json @@ -0,0 +1,19 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/hub-update-request.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "protocolVersion": { + "type": "number", + "const": 2 + }, + "version": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$" + } + }, + "required": [ + "protocolVersion", + "version" + ] +} diff --git a/packages/contracts/schemas/identity-claims.json b/packages/contracts/schemas/identity-claims.json new file mode 100644 index 0000000..b8200ba --- /dev/null +++ b/packages/contracts/schemas/identity-claims.json @@ -0,0 +1,125 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/identity-claims.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "given_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "family_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "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,}$" + }, + "email_verified": { + "type": "boolean" + }, + "phone_number": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "phone_number_verified": { + "type": "boolean" + }, + "news_consent": { + "type": "object", + "properties": { + "email": { + "type": "boolean" + }, + "whatsapp": { + "type": "boolean" + } + }, + "required": [ + "email", + "whatsapp" + ] + }, + "schema": { + "type": "string", + "const": "crosscode.identity/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)$" + }, + "amr": { + "maxItems": 10, + "type": "array", + "items": { + "type": "string", + "minLength": 1, + "maxLength": 20 + } + }, + "two_factor": { + "anyOf": [ + { + "type": "string", + "enum": [ + "email", + "whatsapp", + "totp" + ] + }, + { + "type": "null" + } + ] + }, + "privacy_notice_version": { + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + } + }, + "required": [ + "name", + "given_name", + "family_name", + "email", + "email_verified", + "phone_number", + "phone_number_verified", + "news_consent", + "schema", + "sub", + "amr", + "two_factor", + "privacy_notice_version" + ] +} diff --git a/packages/contracts/schemas/user-deleted-reply.json b/packages/contracts/schemas/user-deleted-reply.json new file mode 100644 index 0000000..ba1b562 --- /dev/null +++ b/packages/contracts/schemas/user-deleted-reply.json @@ -0,0 +1,52 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-deleted-reply.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "status": { + "type": "string", + "const": "deleted" + } + }, + "required": [ + "schema", + "status" + ] + }, + { + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "status": { + "type": "string", + "const": "deferred" + }, + "reason": { + "type": "string", + "minLength": 1, + "maxLength": 500 + }, + "retryAfter": { + "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": [ + "schema", + "status", + "reason", + "retryAfter" + ] + } + ] +} diff --git a/packages/contracts/schemas/user-deleted.json b/packages/contracts/schemas/user-deleted.json new file mode 100644 index 0000000..78732a1 --- /dev/null +++ b/packages/contracts/schemas/user-deleted.json @@ -0,0 +1,43 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-deleted.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.deleted" + }, + "approvedAt": { + "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": [ + "schema", + "callId", + "occurredAt", + "sub", + "type", + "approvedAt" + ] +} diff --git a/packages/contracts/schemas/user-export-reply.json b/packages/contracts/schemas/user-export-reply.json new file mode 100644 index 0000000..f4ec14c --- /dev/null +++ b/packages/contracts/schemas/user-export-reply.json @@ -0,0 +1,77 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-export-reply.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "exportId": { + "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)$" + }, + "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)$" + }, + "product": { + "type": "string", + "enum": [ + "events", + "website", + "app", + "accounts" + ] + }, + "generatedAt": { + "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))$" + }, + "sections": { + "maxItems": 100, + "type": "array", + "items": { + "type": "object", + "properties": { + "key": { + "type": "string", + "maxLength": 50, + "pattern": "^[a-z][a-z0-9_]*$" + }, + "title": { + "type": "string", + "minLength": 1, + "maxLength": 100 + }, + "records": { + "type": "array", + "items": { + "type": "object", + "propertyNames": { + "type": "string" + }, + "additionalProperties": {} + } + } + }, + "required": [ + "key", + "title", + "records" + ] + } + } + }, + "required": [ + "schema", + "exportId", + "sub", + "product", + "generatedAt", + "sections" + ] +} diff --git a/packages/contracts/schemas/user-export.json b/packages/contracts/schemas/user-export.json new file mode 100644 index 0000000..e0e8285 --- /dev/null +++ b/packages/contracts/schemas/user-export.json @@ -0,0 +1,43 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-export.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.export" + }, + "exportId": { + "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", + "callId", + "occurredAt", + "sub", + "type", + "exportId" + ] +} diff --git a/packages/contracts/schemas/user-updated-reply.json b/packages/contracts/schemas/user-updated-reply.json new file mode 100644 index 0000000..eacca17 --- /dev/null +++ b/packages/contracts/schemas/user-updated-reply.json @@ -0,0 +1,19 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-updated-reply.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "ok": { + "type": "boolean", + "const": true + } + }, + "required": [ + "schema", + "ok" + ] +} diff --git a/packages/contracts/schemas/user-updated.json b/packages/contracts/schemas/user-updated.json new file mode 100644 index 0000000..f2bf95c --- /dev/null +++ b/packages/contracts/schemas/user-updated.json @@ -0,0 +1,118 @@ +{ + "$id": "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/user-updated.json", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "schema": { + "type": "string", + "const": "crosscode.identity/1" + }, + "callId": { + "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)$" + }, + "occurredAt": { + "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))$" + }, + "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)$" + }, + "type": { + "type": "string", + "const": "user.updated" + }, + "profile": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1, + "maxLength": 200 + }, + "given_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "family_name": { + "anyOf": [ + { + "type": "string", + "maxLength": 100 + }, + { + "type": "null" + } + ] + }, + "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,}$" + }, + "email_verified": { + "type": "boolean" + }, + "phone_number": { + "anyOf": [ + { + "type": "string", + "pattern": "^\\+[1-9]\\d{6,14}$" + }, + { + "type": "null" + } + ] + }, + "phone_number_verified": { + "type": "boolean" + }, + "news_consent": { + "type": "object", + "properties": { + "email": { + "type": "boolean" + }, + "whatsapp": { + "type": "boolean" + } + }, + "required": [ + "email", + "whatsapp" + ] + } + }, + "required": [ + "name", + "given_name", + "family_name", + "email", + "email_verified", + "phone_number", + "phone_number_verified", + "news_consent" + ] + } + }, + "required": [ + "schema", + "callId", + "occurredAt", + "sub", + "type", + "profile" + ] +} diff --git a/packages/contracts/scripts/json-schemas.cjs b/packages/contracts/scripts/json-schemas.cjs new file mode 100644 index 0000000..5464e4e --- /dev/null +++ b/packages/contracts/scripts/json-schemas.cjs @@ -0,0 +1,101 @@ +// Generates the JSON Schema files in `schemas/` from the zod schemas (ROADMAP-v3 §2), for +// consumers that don't use TypeScript or zod. Run after the build (`npm run build` does it): +// node scripts/json-schemas.cjs write schemas/ +// node scripts/json-schemas.cjs --check fail if schemas/ is out of date +// The test (tests/json-schemas.test.ts) uses `buildSchemas` with the source, so the files in git +// always match the zod schemas. +const { z } = require("zod"); +const fs = require("node:fs"); +const path = require("node:path"); + +const BASE_ID = "https://c-git.crosscode.co.za/joshua/crosscode-platform/raw/branch/main/packages/contracts/schemas/"; + +/** File name (without .json) → schema, from the package exports (`c`) and `c.hub`. */ +function contracts(c) { + return { + "event": c.eventSchema, + "event-feed": c.eventFeedSchema, + "event-changed": c.eventChangedSchema, + "church": c.churchSchema, + "identity-claims": c.identityClaimsSchema, + "accounts-call": c.accountsCallSchema, + "user-updated": c.userUpdatedSchema, + "user-updated-reply": c.userUpdatedReplySchema, + "user-deleted": c.userDeletedSchema, + "user-deleted-reply": c.userDeletedReplySchema, + "user-export": c.userExportSchema, + "user-export-reply": c.userExportReplySchema, + "hub-register-request": c.hub.registerRequestSchema, + "hub-register-response": c.hub.registerResponseSchema, + "hub-heartbeat-request": c.hub.heartbeatRequestSchema, + "hub-heartbeat-response": c.hub.heartbeatResponseSchema, + "hub-licence-payload": c.hub.licencePayloadSchema, + "hub-public-key-response": c.hub.publicKeyResponseSchema, + "hub-update-request": c.hub.updateRequestSchema, + "hub-update-request-response": c.hub.updateRequestResponseSchema, + "hub-update-request-cancel": c.hub.updateRequestCancelSchema, + "hub-update-request-cancel-response": c.hub.updateRequestCancelResponseSchema, + "hub-ai-status-request": c.hub.aiStatusRequestSchema, + "hub-ai-status": c.hub.aiStatusSchema, + "hub-ai-complete-request": c.hub.aiCompleteRequestSchema, + "hub-ai-complete-response": c.hub.aiCompleteResponseSchema, + "hub-error": c.hub.hubErrorSchema, + "health": c.hub.healthSchema, + }; +} + +// zod writes .startsWith() / .endsWith() / .includes() as a `format` that isn't a JSON Schema +// format (strict validators such as Ajv refuse it) next to a `pattern` that does the real check. +const ZOD_ONLY_FORMATS = new Set(["starts_with", "ends_with", "includes"]); +function dropZodFormats(ctx) { + const json = ctx.jsonSchema; + if (ZOD_ONLY_FORMATS.has(json.format) && json.pattern) delete json.format; +} + +/** + * name → JSON Schema (draft 2020-12). `io: "input"` describes what may be sent: unknown fields + * are allowed (consumers drop them, never refuse them) and defaults are optional. + * Checks zod can't express in JSON Schema (refinements, e.g. startsAt matching the sessions) + * only run in zod. + */ +function buildSchemas(c) { + const out = {}; + for (const [name, schema] of Object.entries(contracts(c))) { + if (!schema) throw new Error(`json-schemas: no schema exported for "${name}"`); + out[name] = { $id: `${BASE_ID}${name}.json`, ...z.toJSONSchema(schema, { io: "input", override: dropZodFormats }) }; + } + return out; +} + +const serialise = (json) => `${JSON.stringify(json, null, 2)}\n`; + +function main() { + const dir = path.join(__dirname, "..", "schemas"); + const schemas = buildSchemas(require("../dist/index.js")); + const check = process.argv.includes("--check"); + const stale = []; + if (!check) fs.mkdirSync(dir, { recursive: true }); + const wanted = new Set(Object.keys(schemas).map((n) => `${n}.json`)); + for (const [name, json] of Object.entries(schemas)) { + const file = path.join(dir, `${name}.json`); + const text = serialise(json); + const current = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; + if (current === text) continue; + if (check) stale.push(`${name}.json`); + else fs.writeFileSync(file, text); + } + for (const file of fs.existsSync(dir) ? fs.readdirSync(dir) : []) { + if (!file.endsWith(".json") || wanted.has(file)) continue; + if (check) stale.push(`${file} (no longer generated)`); + else fs.unlinkSync(path.join(dir, file)); + } + if (check && stale.length) { + console.error(`schemas/ is out of date: ${stale.join(", ")}. Run npm run build.`); + process.exit(1); + } + console.log(check ? "schemas/ is up to date" : `Wrote ${Object.keys(schemas).length} JSON Schema files to schemas/`); +} + +if (require.main === module) main(); + +module.exports = { buildSchemas, serialise }; diff --git a/packages/contracts/tests/json-schemas.test.ts b/packages/contracts/tests/json-schemas.test.ts new file mode 100644 index 0000000..ab557e5 --- /dev/null +++ b/packages/contracts/tests/json-schemas.test.ts @@ -0,0 +1,82 @@ +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import Ajv2020 from "ajv/dist/2020"; +import addFormats from "ajv-formats"; +import * as contracts from "../src"; +import { SAMPLES, sample } from "./helpers"; + +// eslint-disable-next-line @typescript-eslint/no-require-imports +const { buildSchemas, serialise } = require("../scripts/json-schemas.cjs") as { + buildSchemas: (c: typeof contracts) => Record; + serialise: (json: object) => string; +}; + +const SCHEMAS_DIR = join(__dirname, "..", "schemas"); +const schemas = buildSchemas(contracts); + +/** Every sample file and the JSON Schema (file name without .json) it must pass. */ +const SAMPLE_SCHEMA: Record = { + "event.json": "event", + "event-simple.json": "event", + "event-feed.json": "event-feed", + "event-changed.json": "event-changed", + "church.json": "church", + "identity-claims.json": "identity-claims", + "user-updated.json": "user-updated", + "user-deleted.json": "user-deleted", + "user-deleted-reply.json": "user-deleted-reply", + "user-export.json": "user-export", + "user-export-reply.json": "user-export-reply", + "hub-register-request.json": "hub-register-request", + "hub-register-response.json": "hub-register-response", + "hub-heartbeat-events.json": "hub-heartbeat-request", + "hub-heartbeat-website.json": "hub-heartbeat-request", + "hub-heartbeat-app.json": "hub-heartbeat-request", + "hub-heartbeat-accounts.json": "hub-heartbeat-request", + "hub-heartbeat-response.json": "hub-heartbeat-response", + "hub-licence-payload.json": "hub-licence-payload", +}; + +describe("JSON Schema (schemas/)", () => { + it("the files in schemas/ match the zod schemas (run npm run build after changing a contract)", () => { + const files = readdirSync(SCHEMAS_DIR).filter((f) => f.endsWith(".json")).sort(); + expect(files).toEqual(Object.keys(schemas).map((n) => `${n}.json`).sort()); + for (const [name, json] of Object.entries(schemas)) { + expect(readFileSync(join(SCHEMAS_DIR, `${name}.json`), "utf8").replace(/\r\n/g, "\n")).toBe(serialise(json)); + } + }); + + const ajv = new Ajv2020({ allErrors: true, strict: true }); + addFormats(ajv); + for (const json of Object.values(schemas)) ajv.addSchema(json); + const validatorFor = (name: string) => { + const validate = ajv.getSchema((schemas[name] as { $id: string }).$id); + if (!validate) throw new Error(`no JSON Schema "${name}"`); + return validate; + }; + + it("every JSON Schema compiles", () => { + for (const name of Object.keys(schemas)) expect(() => validatorFor(name)).not.toThrow(); + }); + + it("every sample has a JSON Schema", () => { + const files = readdirSync(SAMPLES).filter((f) => f.endsWith(".json")); + expect(files.filter((f) => !(f in SAMPLE_SCHEMA))).toEqual([]); + }); + + it.each(Object.entries(SAMPLE_SCHEMA))("%s passes the JSON Schema %s", (file, name) => { + const validate = validatorFor(name); + validate(sample(file)); + expect(validate.errors ?? []).toEqual([]); + }); + + it("refuses a payload with a wrong schema name", () => { + const validate = validatorFor("event"); + expect(validate({ ...(sample("event.json") as object), schema: "crosscode.event/2" })).toBe(false); + }); + + it("allows fields it doesn't know (consumers drop them, never refuse them)", () => { + const validate = validatorFor("event"); + expect(validate({ ...(sample("event.json") as object), somethingNew: true })).toBe(true); + }); +});