From 48d62ab86c74f2b8badb90561ade263fc3855c55 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Sun, 22 Nov 2026 01:03:56 +0200 Subject: [PATCH 1/2] Move to @samebase/identity-broker 0.37.0 --- AGENTS.md | 12 ++--- README.md | 9 ++-- alchemy.run.ts | 4 +- convex/broker.ts | 93 +++++++++++++++------------------- convex/convex.config.ts | 4 +- convex/http.ts | 4 +- convex/owners.test.ts | 8 +-- convex/owners.ts | 17 ++----- package.json | 8 +-- pnpm-lock.yaml | 108 ++++++++++------------------------------ scripts/check-keys.ts | 28 ----------- scripts/convex-cli.ts | 2 +- scripts/init-keys.ts | 21 +++++++- 13 files changed, 115 insertions(+), 203 deletions(-) delete mode 100644 scripts/check-keys.ts diff --git a/AGENTS.md b/AGENTS.md index 062ebf0..534401b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,16 +2,16 @@ An identity hub: a Convex app that mounts `@samebase/identity-broker`. See README.md. -- `convex/broker.ts` is the hub: connectors `google` and `github`, the registration policy (who may - register comes from `HUB_OWNERS`, parsed in `convex/owners.ts`), and the admin functions. - `convex/convex.config.ts` declares every deployment variable; `convex/http.ts` mounts the routes; - `convex/crons.ts` runs the cleanup. +- `convex/broker.ts` is the hub (`convexHub` of `@samebase/identity-broker/convex`): connectors + `google` and `github`, and the GitHub registration layer with the moderation API (who may register + comes from `HUB_OWNERS`, parsed in `convex/owners.ts`). `convex/convex.config.ts` declares every + deployment variable; `convex/http.ts` mounts the routes; `convex/crons.ts` runs the cleanup. - Every value that differs between hubs is a GitHub variable or secret that `alchemy.run.ts` hands to the deployment. Keep it that way: a copy of this repository changes settings, not code. - `alchemy.run.ts` creates the Convex project and its production deployment and never adopts one (`adopt(false)` on both). Without the four client values it pushes nothing. -- `scripts/init-keys.ts` creates `IDENTITY_BROKER_KEYS` once, by hand; `scripts/check-keys.ts` - checks it before every push and never creates it. +- `scripts/init-keys.ts` creates `IDENTITY_BROKER_KEYS` once, by hand; no push creates it, and a + push fails while it is missing (`convex/convex.config.ts` declares it required). - Never use `npx convex import --replace-all` on a hub: it deletes the rows of the components. - Never use the U+2014 em dash character. No `any`, no type assertions except `as const`. - `pnpm install`, then `pnpm run check`. `convex/_generated` is committed; a push refreshes it. diff --git a/README.md b/README.md index c2a6284..3215e5f 100644 --- a/README.md +++ b/README.md @@ -148,9 +148,10 @@ and needs the new callbacks. - **Pause every app:** set `APPS_PAUSED=true` on the deployment (Convex dashboard, Environment Variables). Remove it to resume. -- **List and delete:** `npx convex run --deployment broker:listApps`, then - `broker:listClients '{"appId":"..."}'`, `broker:deleteClient '{"clientId":"..."}'`, - `broker:deleteApp '{"appId":"..."}'`. +- **List and delete clients:** `GET /moderation/clients` lists the newest clients, or with + `?owner=` those of one GitHub account; + `DELETE /moderation/clients/` deletes one. Both take the moderation key, as + below. - **Block a repository or an owner** at once, whatever `HUB_OWNERS` says: ```sh @@ -161,7 +162,7 @@ and needs the new callbacks. `"kind":"owner"` blocks every repository of an account, and `"action":"unblock"` lifts a block. The other endpoints are in the broker's - [moderation API](https://github.com/samebase/samebase/blob/main/packages/identity-broker/src/client/moderation.ts). + [moderation API](https://github.com/samebase/samebase/blob/main/packages/identity-broker/README.md#moderation). - A daily cron removes expired requests, old sign-in records, and preview and development clients that no deploy renewed for 14 days. A production client stays until you delete it. diff --git a/alchemy.run.ts b/alchemy.run.ts index 8bd05bf..8b8f24e 100644 --- a/alchemy.run.ts +++ b/alchemy.run.ts @@ -98,8 +98,8 @@ export default Alchemy.Stack( const deployment = yield* Convex.Deployment("Deployment", { project, type: "prod", - // The push is the `deploy` package script, which checks the key set first. The functions, - // package.json, and the lockfile are always hashed. + // The push is the `deploy` package script. The functions, package.json, and the lockfile + // are always hashed. source: { path: "./convex", command: ["node", "--run", "deploy"], diff --git a/convex/broker.ts b/convex/broker.ts index 3a46c4c..39e1649 100644 --- a/convex/broker.ts +++ b/convex/broker.ts @@ -1,61 +1,48 @@ -import { defineIdentityBroker, github, google } from "@samebase/identity-broker"; +import { github, hubSettings } from "@samebase/identity-broker"; +import { convexHub } from "@samebase/identity-broker/convex"; +import { moderation } from "@samebase/identity-broker/moderation"; +import { Config } from "effect"; import { components } from "./_generated/api"; import { env } from "./_generated/server"; -import { mayRegister, parseOwners } from "./owners"; +import { parseOwners } from "./owners"; // The whole hub. Every value that differs between hubs is a deployment variable, which the stack // (alchemy.run.ts) sets from the repository's GitHub variables and secrets, so this file is the // same in every copy. `http.ts` mounts the routes, `crons.ts` runs the cleanup, and -// `convex.config.ts` declares the variables. +// `convex.config.ts` declares the variables. The signing keys are IDENTITY_BROKER_KEYS. -/** - * The deployment's own convex.site URL until ISSUER names a custom domain. Every app names the - * issuer, so ISSUER is set before the first app registers (README, Custom domain). - */ -export const issuer = env.ISSUER ?? env.CONVEX_SITE_URL; +export const hub = convexHub( + components.identityBroker, + hubSettings({ + // The deployment's own convex.site URL until ISSUER names a custom domain. Every app names the + // issuer, so ISSUER is set before the first app registers (README, Custom domain). + issuer: env.ISSUER ?? env.CONVEX_SITE_URL, + // One Google OAuth client and one GitHub OAuth App, with the callbacks + // `/connectors/google/callback` and `/connectors/github/callback`. A user's + // `sub` is the provider's own id, `google:` or `github:`, the same at every hub. Each + // sign-in shows the provider's account screen. + connectors: { + google: { + clientId: Config.Redacted("GOOGLE_CLIENT_ID"), + clientSecret: Config.Redacted("GOOGLE_CLIENT_SECRET"), + }, + github: { + clientId: Config.Redacted("AUTH_GITHUB_CLIENT_ID"), + clientSecret: Config.Redacted("AUTH_GITHUB_CLIENT_SECRET"), + }, + }, + service: { name: env.HUB_NAME, terms: env.HUB_TERMS_URL, privacy: env.HUB_PRIVACY_URL }, + }), + // `POST /register` creates every client. A repository of an allowed owner gets both connectors; + // any other gets none, unless the moderation API granted its repository a connector. + github(parseOwners(env.HUB_OWNERS), { + moderation: moderation({ key: Config.Redacted("IDENTITY_HUB_MODERATION_KEY") }), + // The emergency brake, set by hand on the deployment: only `true` pauses every app. + paused: Config.String("APPS_PAUSED").pipe( + Config.map((value) => value === "true"), + Config.withDefault(false), + ), + }), +); -const owners = parseOwners(env.HUB_OWNERS); - -export const broker = defineIdentityBroker({ - component: components.identityBroker, - issuer, - keys: () => env.IDENTITY_BROKER_KEYS, - // One Google OAuth client and one GitHub OAuth App, with the callbacks - // `/connectors/google/callback` and `/connectors/github/callback`. A user's `sub` - // is the provider's own id, `google:` or `github:`, the same at every hub. Each sign-in - // shows the provider's account screen, so one app of this hub never passes a user to another - // with no click. - connectors: [ - google({ - clientId: () => env.GOOGLE_CLIENT_ID, - clientSecret: () => env.GOOGLE_CLIENT_SECRET, - selectAccount: true, - }), - github({ - clientId: () => env.AUTH_GITHUB_CLIENT_ID, - clientSecret: () => env.AUTH_GITHUB_CLIENT_SECRET, - selectAccount: true, - }), - ], - // `POST /register` creates every client; `/moderation/*` answers the holder of the moderation - // key. - registration: { - name: env.HUB_NAME, - terms: env.HUB_TERMS_URL, - privacy: env.HUB_PRIVACY_URL, - moderationKey: () => env.IDENTITY_HUB_MODERATION_KEY, - policy: (registration) => ({ - // Both connectors for a repository of an allowed owner. Any other gets none, so its - // registration is refused, unless the moderation API granted its repository a connector. - connectors: mayRegister(owners, registration.ownerId) ? ["google", "github"] : [], - resources: [], - // The emergency brake, set by hand on the deployment: `true` pauses every app. - paused: env.APPS_PAUSED === "true", - }), - }, -}); - -// Administration with `npx convex run --deployment broker:`: -// listApps, listClients '{"appId":"..."}', deleteClient '{"clientId":"..."}', deleteApp '{"appId":"..."}' -// `crons.ts` runs `cleanup` daily. -export const { deleteApp, listApps, listClients, deleteClient, cleanup } = broker.admin(); +export const cleanup = hub.cleanup; diff --git a/convex/convex.config.ts b/convex/convex.config.ts index a11cec8..a01f0e3 100644 --- a/convex/convex.config.ts +++ b/convex/convex.config.ts @@ -3,8 +3,8 @@ import { defineApp } from "convex/server"; import { v } from "convex/values"; // A push fails while a required variable is missing. The stack (alchemy.run.ts) sets every -// variable here but IDENTITY_BROKER_KEYS, which scripts/init-keys.ts creates once by hand and -// scripts/check-keys.ts checks before each push, and APPS_PAUSED, which is set by hand. +// variable here but IDENTITY_BROKER_KEYS, which scripts/init-keys.ts creates once by hand, and +// APPS_PAUSED, which is set by hand. const app = defineApp({ env: { /** The signing key set. */ diff --git a/convex/http.ts b/convex/http.ts index 577eabf..429f621 100644 --- a/convex/http.ts +++ b/convex/http.ts @@ -1,7 +1,7 @@ import { httpRouter } from "convex/server"; -import { broker } from "./broker"; +import { hub } from "./broker"; const http = httpRouter(); -broker.addHttpRoutes(http); +hub.addHttpRoutes(http); export default http; diff --git a/convex/owners.test.ts b/convex/owners.test.ts index 08bf933..d53ce11 100644 --- a/convex/owners.test.ts +++ b/convex/owners.test.ts @@ -1,17 +1,13 @@ import { describe, expect, test } from "vitest"; -import { mayRegister, parseOwners } from "./owners"; +import { parseOwners } from "./owners"; describe("HUB_OWNERS", () => { test("any lets every owner register", () => { expect(parseOwners(" any ")).toBe("any"); - expect(mayRegister("any", "583231")).toBe(true); }); test("a list lets only its owners register", () => { - const owners = parseOwners("583231, 9919"); - expect(owners).toEqual(["583231", "9919"]); - expect(mayRegister(owners, "9919")).toBe(true); - expect(mayRegister(owners, "1")).toBe(false); + expect(parseOwners("583231, 9919")).toEqual([{ ownerId: "583231" }, { ownerId: "9919" }]); }); test.each(["", " ", "Any", "octocat", "583231,", "583231,,9919", "-1", "0", "1e3"])( diff --git a/convex/owners.ts b/convex/owners.ts index 8a9c970..0386a46 100644 --- a/convex/owners.ts +++ b/convex/owners.ts @@ -1,9 +1,11 @@ /** * Who may register at this hub, from HUB_OWNERS: `any`, or the numeric ids of the GitHub accounts * (users or organizations) whose repositories may register, separated by commas. Anything else - * throws, so a typo stops the deploy instead of opening or closing the hub. + * throws, so a typo stops the deploy instead of opening or closing the hub. The owner is the one + * GitHub's token of the registering run proves: the account that owns the repository, never the + * person or bot that ran the workflow. */ -export function parseOwners(value: string): "any" | readonly string[] { +export function parseOwners(value: string): "any" | Array<{ ownerId: string }> { const trimmed = value.trim(); if (trimmed === "any") { return "any"; @@ -14,14 +16,5 @@ export function parseOwners(value: string): "any" | readonly string[] { `HUB_OWNERS is "any" or numeric GitHub owner ids separated by commas, not "${value}".`, ); } - return ids; -} - -/** - * Whether a repository of this owner may register. The owner is the one GitHub's token of the - * registering run proves: the account that owns the repository, never the person or bot that ran - * the workflow. - */ -export function mayRegister(owners: "any" | readonly string[], ownerId: string): boolean { - return owners === "any" || owners.includes(ownerId); + return ids.map((ownerId) => ({ ownerId })); } diff --git a/package.json b/package.json index c827310..0e1127c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "MIT", "type": "module", "scripts": { - "deploy": "node ./scripts/check-keys.ts && convex deploy --yes", + "deploy": "convex deploy --yes", "keys:init": "node ./scripts/init-keys.ts", "check": "vp check && pnpm run typecheck && vp test", "typecheck": "tsc --project convex/tsconfig.json && tsc --project tsconfig.node.json", @@ -13,15 +13,15 @@ "test": "vp test" }, "dependencies": { - "@samebase/identity-broker": "0.34.0", - "convex": "1.48.0" + "@samebase/identity-broker": "0.37.0", + "convex": "1.48.0", + "effect": "4.1.4" }, "devDependencies": { "@effect/platform-node": "4.1.4", "@samebase/alchemy-convex": "0.44.0", "@types/node": "26.6.6", "alchemy": "2.0.0-beta.87", - "effect": "4.1.4", "typescript": "7.0.2", "vite": "catalog:", "vite-plus": "catalog:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 463dcdc..c45a0b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -202,11 +202,14 @@ importers: .: dependencies: '@samebase/identity-broker': - specifier: 0.34.0 - version: 0.34.0(convex@1.48.0)(typescript@7.0.2) + specifier: 0.37.0 + version: 0.37.0(alchemy@2.0.0-beta.87(@effect/platform-node@4.1.4(effect@4.1.4)(redis@6.3.1))(@voidzero-dev/vite-plus-core@1.4.0(@types/node@26.6.6)(esbuild@0.27.0)(typescript@7.0.2)(yaml@2.9.1))(effect@4.1.4)(ws@8.22.1))(convex@1.48.0)(effect@4.1.4) convex: specifier: 1.48.0 version: 1.48.0 + effect: + specifier: 4.1.4 + version: 4.1.4 devDependencies: '@effect/platform-node': specifier: 4.1.4 @@ -220,9 +223,6 @@ importers: alchemy: specifier: 2.0.0-beta.87 version: 2.0.0-beta.87(@effect/platform-node@4.1.4(effect@4.1.4)(redis@6.3.1))(@voidzero-dev/vite-plus-core@1.4.0(@types/node@26.6.6)(esbuild@0.27.0)(typescript@7.0.2)(yaml@2.9.1))(effect@4.1.4)(ws@8.22.1) - effect: - specifier: 4.1.4 - version: 4.1.4 typescript: specifier: 7.0.2 version: 7.0.2 @@ -268,23 +268,9 @@ packages: '@blazediff/core@1.10.0': resolution: {integrity: sha512-AOQff0zgR7cGsZL+4E7hVkmujoPUpm0J9xzWGWZj5wCjd3gmxESXAPfKyuzs93VdpQNFhHlBhfOjrcZ+XTERtQ==} - '@convex-dev/batch-worker@0.3.5': - resolution: {integrity: sha512-kTxLGy1TXRN6WLcENcoRWWnvPshv1sIZp2EpPqGqCB4FxDI7m8tEHUr+jCLdhGtSZT1UHkWtb1w8YYuEzTxHWQ==} - peerDependencies: - convex: ^1.43.0 - '@convex-dev/platform@0.1.11': resolution: {integrity: sha512-qdX+tYjNhNpEeLIiUhKDQQwdvUJDB529TrfJ9dAIclzLOW7DW1ozgIcyB2nl/MhlhBOUlHLY3wZ1xkjafrJO+Q==} - '@convex-dev/rate-limiter@0.4.2': - resolution: {integrity: sha512-njheoDd//MZgxtw+0PP3LL47PVMkvOKZmXDjYglDKSu5IdrfJtGmz/EHd6px9UcALuk/w7LTo83YwQ3bTGsMIg==} - peerDependencies: - convex: ^1.43.0 - react: ^18.2.0 || ^19.0.0 - peerDependenciesMeta: - react: - optional: true - '@effect/platform-node-shared@4.1.4': resolution: {integrity: sha512-DWdfphHGOFJNj/mYadgpT3jIm8aRXDcPrQiGXFBH4p2H4XmA7iYMrPsI8NxVgZ7kNX0q1+FGJZJama0tINHRAg==} engines: {node: '>=22.19.0'} @@ -907,12 +893,24 @@ packages: alchemy: 2.0.0-beta.87 effect: ^4.1.4 - '@samebase/identity-broker@0.34.0': - resolution: {integrity: sha512-jbg7KUZ9RA/4TcKaOSFZqAHW4xQkR9ArH30oomsk1UABw9kO2h/z+bZakmdXYZixrzeTYx/I8X8DOgSaTtaV8g==} + '@samebase/identity-broker@0.37.0': + resolution: {integrity: sha512-vL5z+nJcMOq2B4SuTBn70muOmoIZslXHCzeh6ndJk2xS/ItSSbS07Bi7hzs2ZrqmpQYsaCG445e1Vc3WDm8KxA==} engines: {node: '>=24.11.0'} - hasBin: true peerDependencies: - convex: ^1.47.0 + '@alchemy.run/cloudflare': 2.0.0-beta.87 + alchemy: 2.0.0-beta.87 + convex: ^1.48.0 + effect: ^4.1.4 + fast-check: ^4.10.2 + peerDependenciesMeta: + '@alchemy.run/cloudflare': + optional: true + alchemy: + optional: true + convex: + optional: true + fast-check: + optional: true '@testing-library/dom@10.4.2': resolution: {integrity: sha512-yzr2S9HyAIdhz2/6qHgbs665Q7PKVcDF05vsOlHPxG1mo36gKVesdYVeDLnXgfjJ03CrKRk08knc6+E/9m8v2Q==} @@ -1341,28 +1339,6 @@ packages: convert-source-map@2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} - convex-helpers@0.1.128: - resolution: {integrity: sha512-5n7uKsJrYnnybvuSAWgDQ9d5Avqk4CzFsJ22SXow4tHmVxSUH6qiJCeomWWxcLSfN9t9jpKIXNJiGJrjddS4ng==} - hasBin: true - peerDependencies: - '@standard-schema/spec': ^1.0.0 - convex: ^1.46.0 - hono: ^4.0.5 - react: ^17.0.2 || ^18.0.0 || ^19.0.0 - typescript: ^5.5 || ^6.0.0 || ^7.0.0 - zod: ^3.25.0 || ^4.0.0 - peerDependenciesMeta: - '@standard-schema/spec': - optional: true - hono: - optional: true - react: - optional: true - typescript: - optional: true - zod: - optional: true - convex@1.48.0: resolution: {integrity: sha512-M9jEgTvCN8ziP/VgQQUH+j0ijM7g+NmQd8tFlvETK8/HMC/aaqHZwcu4hBO30X5DV2VIyYK4mOoLQGIb1766ew==} engines: {node: '>=20.0.0', npm: '>=7.0.0'} @@ -1783,31 +1759,10 @@ snapshots: '@blazediff/core@1.10.0': {} - '@convex-dev/batch-worker@0.3.5(convex@1.48.0)(typescript@7.0.2)': - dependencies: - convex: 1.48.0 - convex-helpers: 0.1.128(convex@1.48.0)(typescript@7.0.2) - transitivePeerDependencies: - - '@standard-schema/spec' - - hono - - react - - typescript - - zod - '@convex-dev/platform@0.1.11': dependencies: openapi-fetch: 0.17.0 - '@convex-dev/rate-limiter@0.4.2(convex@1.48.0)(typescript@7.0.2)': - dependencies: - '@convex-dev/batch-worker': 0.3.5(convex@1.48.0)(typescript@7.0.2) - convex: 1.48.0 - transitivePeerDependencies: - - '@standard-schema/spec' - - hono - - typescript - - zod - '@effect/platform-node-shared@4.1.4(effect@4.1.4)': dependencies: '@types/ws': 8.18.2 @@ -2135,19 +2090,14 @@ snapshots: alchemy: 2.0.0-beta.87(@effect/platform-node@4.1.4(effect@4.1.4)(redis@6.3.1))(@voidzero-dev/vite-plus-core@1.4.0(@types/node@26.6.6)(esbuild@0.27.0)(typescript@7.0.2)(yaml@2.9.1))(effect@4.1.4)(ws@8.22.1) effect: 4.1.4 - '@samebase/identity-broker@0.34.0(convex@1.48.0)(typescript@7.0.2)': + '@samebase/identity-broker@0.37.0(alchemy@2.0.0-beta.87(@effect/platform-node@4.1.4(effect@4.1.4)(redis@6.3.1))(@voidzero-dev/vite-plus-core@1.4.0(@types/node@26.6.6)(esbuild@0.27.0)(typescript@7.0.2)(yaml@2.9.1))(effect@4.1.4)(ws@8.22.1))(convex@1.48.0)(effect@4.1.4)': dependencies: - '@convex-dev/rate-limiter': 0.4.2(convex@1.48.0)(typescript@7.0.2) - convex: 1.48.0 - convex-helpers: 0.1.128(convex@1.48.0)(typescript@7.0.2) + effect: 4.1.4 jose: 6.2.13 oauth4webapi: 3.8.8 - transitivePeerDependencies: - - '@standard-schema/spec' - - hono - - react - - typescript - - zod + optionalDependencies: + alchemy: 2.0.0-beta.87(@effect/platform-node@4.1.4(effect@4.1.4)(redis@6.3.1))(@voidzero-dev/vite-plus-core@1.4.0(@types/node@26.6.6)(esbuild@0.27.0)(typescript@7.0.2)(yaml@2.9.1))(effect@4.1.4)(ws@8.22.1) + convex: 1.48.0 '@testing-library/dom@10.4.2': dependencies: @@ -2435,12 +2385,6 @@ snapshots: convert-source-map@2.0.0: {} - convex-helpers@0.1.128(convex@1.48.0)(typescript@7.0.2): - dependencies: - convex: 1.48.0 - optionalDependencies: - typescript: 7.0.2 - convex@1.48.0: dependencies: esbuild: 0.27.0 diff --git a/scripts/check-keys.ts b/scripts/check-keys.ts deleted file mode 100644 index 8901ab4..0000000 --- a/scripts/check-keys.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Checks IDENTITY_BROKER_KEYS on the selected Convex deployment before the push. The stack -// (alchemy.run.ts) runs it in the `deploy` script with the deployment's deploy key. The variable -// must exist (read from `env list`, which lists an empty variable too) and hold a key set the -// broker's parser accepts; otherwise the deploy stops here instead of at the first sign-in. -// -// Creation is separate, because a new key set stops every token signed with the old one: an -// established hub that lost the variable gets a new set by hand, never from a deploy. No deploy -// creates keys; `pnpm run keys:init`, scripts/init-keys.ts, does it once by hand. -/// -import { assertKeySetUsable, parseKeySet } from "@samebase/identity-broker"; -import process from "node:process"; -import { hasVariable, runConvex } from "./convex-cli.ts"; - -async function main(selection: string[]) { - if (await hasVariable("IDENTITY_BROKER_KEYS", selection)) { - const current = await runConvex(["env", "get", "IDENTITY_BROKER_KEYS", ...selection]); - // The shape, then a sign-and-verify round trip through the broker's own signer and JWKS: a - // key set that would fail at the first sign-in stops the deploy here. - await assertKeySetUsable(parseKeySet(current.stdout.replace(/\n$/, ""))); - console.log("IDENTITY_BROKER_KEYS is set and usable."); - return; - } - throw new Error( - "IDENTITY_BROKER_KEYS does not exist on this deployment. A new hub creates it once with `pnpm run keys:init`; an established hub restores its backup. Nothing was deployed.", - ); -} - -await main(process.argv.slice(2)); diff --git a/scripts/convex-cli.ts b/scripts/convex-cli.ts index eb03d6f..18c9980 100644 --- a/scripts/convex-cli.ts +++ b/scripts/convex-cli.ts @@ -1,4 +1,4 @@ -// Runs the installed Convex CLI for the key scripts. The selection after the script name names the +// Runs the installed Convex CLI for scripts/init-keys.ts. The selection after the script name names the // deployment: `--prod`, `--deployment `, or nothing for the deployment of CONVEX_DEPLOY_KEY // or of this checkout. /// diff --git a/scripts/init-keys.ts b/scripts/init-keys.ts index 676a337..1b69bce 100644 --- a/scripts/init-keys.ts +++ b/scripts/init-keys.ts @@ -6,10 +6,29 @@ // pnpm run keys:init --prod // pnpm run keys:init --deployment /// -import { createKeySet } from "@samebase/identity-broker"; import process from "node:process"; import { hasVariable, runConvex } from "./convex-cli.ts"; +/** A key set with one current RS256 key, in the format of the broker's README (Environment variables). */ +async function createKeySet() { + const { privateKey } = await crypto.subtle.generateKey( + { + name: "RSASSA-PKCS1-v1_5", + modulusLength: 2048, + publicExponent: new Uint8Array([1, 0, 1]), + hash: "SHA-256", + }, + true, + ["sign", "verify"], + ); + const jwk = await crypto.subtle.exportKey("jwk", privateKey); + const kid = crypto.randomUUID(); + return { + version: 1, + keys: [{ kid, status: "current", privateJwk: { ...jwk, kid, use: "sig" } }], + }; +} + async function main(selection: string[]) { if (await hasVariable("IDENTITY_BROKER_KEYS", selection)) { throw new Error( From 39049e589edb6d8a354cd4dd0177e1888587b980 Mon Sep 17 00:00:00 2001 From: Nicu Chiciuc Date: Sun, 22 Nov 2026 01:22:16 +0200 Subject: [PATCH 2/2] Mount the component as identityHub, apart from 0.34.0's rows --- README.md | 4 +++- convex/_generated/api.d.ts | 2 +- convex/broker.ts | 2 +- convex/convex.config.ts | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3215e5f..760ef9e 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,9 @@ and needs the new callbacks. Renovate opens a pull request when a new broker or alchemy-convex version is out. Read the [broker's changelog](https://github.com/samebase/samebase/blob/main/packages/identity-broker/CHANGELOG.md) -before you merge: a release that changes stored data says what to do. +before you merge: a release that changes stored data says what to do. After the first push of +0.37.0, the old component `identityBroker` is unmounted; its rows stay in the deployment, and the +Convex dashboard can delete them. ## What the hub holds diff --git a/convex/_generated/api.d.ts b/convex/_generated/api.d.ts index 2e83bbd..55fd961 100644 --- a/convex/_generated/api.d.ts +++ b/convex/_generated/api.d.ts @@ -53,5 +53,5 @@ export declare const internal: FilterApi< >; export declare const components: { - identityBroker: import("@samebase/identity-broker/_generated/component.js").ComponentApi<"identityBroker">; + identityHub: import("@samebase/identity-broker/_generated/component.js").ComponentApi<"identityHub">; }; diff --git a/convex/broker.ts b/convex/broker.ts index 39e1649..8ef29a1 100644 --- a/convex/broker.ts +++ b/convex/broker.ts @@ -12,7 +12,7 @@ import { parseOwners } from "./owners"; // `convex.config.ts` declares the variables. The signing keys are IDENTITY_BROKER_KEYS. export const hub = convexHub( - components.identityBroker, + components.identityHub, hubSettings({ // The deployment's own convex.site URL until ISSUER names a custom domain. Every app names the // issuer, so ISSUER is set before the first app registers (README, Custom domain). diff --git a/convex/convex.config.ts b/convex/convex.config.ts index a01f0e3..e48be6e 100644 --- a/convex/convex.config.ts +++ b/convex/convex.config.ts @@ -37,6 +37,7 @@ const app = defineApp({ }, }); -app.use(identityBroker); +// Not the default name: a deployment that ran 0.34.0 or earlier keeps its rows under `identityBroker`, which do not fit this schema. +app.use(identityBroker, { name: "identityHub" }); export default app;