@samebase/alchemy-convex 0.44.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -209,10 +209,10 @@ its own native signing key and JWKS, so no extra signing secret is required. See
209
209
 
210
210
  ### Secrets in the rows
211
211
 
212
- Alchemy writes a `Redacted` value in clear text, and a row must keep it: the hub keeps only the hash
213
- of a client secret, so the next run can get the value only from the state. The store seals each of
214
- these values with AES-256-GCM before it writes the row. A table view, a snapshot, and a reader that
215
- forgets to remove secrets show no value.
212
+ Alchemy writes a `Redacted` value in clear text, and a row must keep it: the broker keeps only the
213
+ hash of a client secret, so the next run can get the value only from the state. The store seals each
214
+ of these values with AES-256-GCM before it writes the row. A table view, a snapshot, and a reader
215
+ that forgets to remove secrets show no value.
216
216
 
217
217
  Each key is one variable `STATE_KEY_<keyId>` of the store deployment, and a sealed value names its
218
218
  key. A run that finds no key makes one, writes it to the deployment, and never reads it back. A
@@ -313,85 +313,89 @@ resources and output, from the store function `state:readStack({ stack })` in on
313
313
  as the build inputs `["src/**", "public/**", "vite.config.ts"]`. A minted key for a command has
314
314
  every action, because the command can do more than a push.
315
315
 
316
- - `IdentityHub.Client`, from `import * as IdentityHub from "@samebase/alchemy-convex/identity-hub"`:
317
- `{ hub, redirectUris, deploymentType, connectors, app?, initialAccessToken?, key?, softwareVersion? }`
318
- gets a client of an identity hub, for an app that deploys in its own GitHub Actions run, on any
316
+ - `IdentityBroker.Client`, from
317
+ `import * as IdentityBroker from "@samebase/alchemy-convex/identity-broker"`:
318
+ `{ broker, redirectUris, deploymentType, connectors, app?, initialAccessToken?, key?, softwareVersion? }`
319
+ gets a client of an identity broker, for an app that deploys in its own GitHub Actions run, on any
319
320
  host, and for development as a stage of the same stack. `deploymentType` is `production`,
320
321
  `preview`, or `development`. A production or preview client needs `permissions: id-token: write`
321
322
  in the workflow, and no key and no Samebase account. `redirectUris` lists every return address of
322
- the deployment, one to eight, one per handler that receives the hub's answers. The origin of each
323
- https address must serve `/samebase-verification.json` with the numeric GitHub id of the
323
+ the deployment, one to eight, one per handler that receives the broker's answers. The origin of
324
+ each https address must serve `/samebase-verification.json` with the numeric GitHub id of the
324
325
  repository, `{ "repository": "123" }`, which `gh api repos/<owner>/<name> --jq .id` prints. The
325
- hub reads it before it registers the client, so the site must be live first. Outputs `status`,
326
+ broker reads it before it registers the client, so the site must be live first. Outputs `status`,
326
327
  `issuer`, `clientId`, `clientSecret`, `registrationAccessToken`, `registrationClientUri`,
327
328
  `deploymentType`, `app`, `redirectUris`, `connectors`, `initialAccessToken`, and `repository`.
328
- - `app` is the app's name on the hub, at most 64 characters. Its default is the stack's path in
329
+ - `app` is the app's name on the broker, at most 64 characters. Its default is the stack's path in
329
330
  the repository, `apps/web` for the stack `owner/repo/apps/web`, and `app` for a stack named
330
331
  `owner/repo`. A stack with another name, or a path over 64 characters, sets `app`. The name
331
332
  groups the clients of one deployable thing, their budgets, and the initial access token; it
332
333
  plays no part in user ids.
333
- - `connectors` names the hub's connectors the client signs in through, such as
334
- `["google", "github"]`: at least one name of `[a-z0-9-]{1,64}`. The hub's discovery document
334
+ - `connectors` names the broker's connectors the client signs in through, such as
335
+ `["google", "github"]`: at least one name of `[a-z0-9-]{1,64}`. The broker's discovery document
335
336
  lists what it offers in `connectors_supported`, and its policy decides what a repository may
336
337
  enroll in; a name outside that is refused, and the log names the allowed ones. The set is
337
338
  recorded on the client for good, sorted, each once. The app sends `connector=<name>` to
338
- `/authorize` to skip the hub's page, or nothing to let the user choose among the set.
339
+ `/authorize` to skip the broker's page, or nothing to let the user choose among the set.
339
340
  - A production registration also gets the app's initial access token (RFC 7591) and the numeric
340
341
  repository id, which the state keeps. A renewal keeps both. They are empty for a preview, for a
341
342
  development client, and for the off values.
342
343
  - A development client needs `initialAccessToken`, and only a development client takes it. The
343
- client asks the hub with this token in place of the GitHub OIDC token, so it works in
344
+ client asks the broker with this token in place of the GitHub OIDC token, so it works in
344
345
  development. With an empty token, the client gets the off values, and the log says "deploy to
345
- main once for hub sign-in in development". See "The development stage" below.
346
- - A client of any `deploymentType` with `key` asks a hub on the stack layer with that key, from
346
+ main once for broker sign-in in development". See "The development stage" below.
347
+ - A client of any `deploymentType` with `key` asks a broker on the stack layer with that key, from
347
348
  any run, with no GitHub token and no verification file. It waits up to about three minutes for
348
- the hub to answer discovery, so the run that deploys the hub registers its own client. The hub
349
- decides whether the key may register a production client. An undefined key gives the off values,
350
- or fails a `required` client.
351
- - `IdentityHub.registrationKey(id, { stage })` gives the key `id` as a redacted Output: in the
352
- stage that deploys the hub it is an `Alchemy.Random`, kept in state; in any other stage it is
353
- read from that stage's row, and it is `undefined` before that stage ran. Bind it to the hub as a
354
- secret, and give it to `key`.
355
- - Each deploy reads the saved client on the hub with its own token. A client that is gone gets a
356
- new one, and a client with other `redirectUris`, another `app`, another `deploymentType`, or
357
- other `connectors` too. A replaced production client stays valid on the hub until its
349
+ the broker to answer discovery, so the run that deploys the broker registers its own client. The
350
+ broker decides whether the key may register a production client. An undefined key gives the off
351
+ values, or fails a `required` client.
352
+ - `IdentityBroker.registrationKey(id, { stage })` gives the key `id` as a redacted Output: in the
353
+ stage that deploys the broker it is an `Alchemy.Random`, kept in state; in any other stage it is
354
+ read from that stage's row, and it is `undefined` before that stage ran. Bind it to the broker
355
+ as a secret, and give it to `key`.
356
+ - Each deploy reads the saved client on the broker with its own token. A client that is gone gets
357
+ a new one, and a client with other `redirectUris`, another `app`, another `deploymentType`, or
358
+ other `connectors` too. A replaced production client stays valid on the broker until its
358
359
  administrator deletes it, and a new production client replaces the app's initial access token,
359
360
  so a development stage reads the latest state of `prod` before its next registration. A saved
360
361
  row whose attributes this version cannot read stops the run with a fixed message, which holds no
361
362
  value of the row.
362
- - A new client logs the hub's issuer. A refusal logs its reason, such as a host that does not
363
- serve the file, a block, a token of another app, a connector the hub does not offer or allow, or
364
- the hourly limit it reached.
365
- - No failure of the hub stops a deploy or a destroy. A failed renewal keeps the saved values.
363
+ - A new client logs the broker's issuer. A refusal logs its reason, such as a host that does not
364
+ serve the file, a block, a token of another app, a connector the broker does not offer or allow,
365
+ or the hourly limit it reached.
366
+ - No failure of the broker stops a deploy or a destroy. A failed renewal keeps the saved values.
366
367
  Without saved values, `status` is `off`, and `issuer`, `clientId`, and `clientSecret` are the
367
- `no-hub` values of a checkout without a hub. A production or preview run without a GitHub OIDC
368
- token, such as on a development machine, does the same, and logs no warning.
369
- - `required: true` makes the run fail unless the hub confirms the client in this run: a refusal, a
370
- hub that does not answer a registration or a renewal, or a suspended client fails it. Set it
371
- where sign-in is the product, so a deploy never ships guest sign-in, or a client that the hub
372
- stopped, with a green run. A failed run saves nothing, and the next run asks the hub again.
373
- - `status` is `suspended` when the hub suspended the client. The state keeps the client and its
374
- values, so the client works again when the hub lifts the suspension.
375
- - `IdentityHub.Client.variables(client)` gives `issuer`, `clientId`, and `clientSecret` for the
376
- app's deployment: the client's values when `status` is `on`, and the `no-hub` values when it is
377
- `off` or `suspended`. Give these to the deployment, not the outputs of the client.
378
- - `IdentityHub.Client.read(id, { stage })` gives the attributes of the client `id` in another
368
+ off values of a checkout without a broker: `http://127.0.0.1:1`, and `IdentityBroker.DISABLED`
369
+ (`broker-disabled`) for the client ID and the secret. A production or preview run without a
370
+ GitHub OIDC token, such as on a development machine, does the same, and logs no warning.
371
+ - `required: true` makes the run fail unless the broker confirms the client in this run: a
372
+ refusal, a broker that does not answer a registration or a renewal, or a suspended client fails
373
+ it. Set it where sign-in is the product, so a deploy never ships guest sign-in, or a client that
374
+ the broker stopped, with a green run. A failed run saves nothing, and the next run asks the
375
+ broker again.
376
+ - `status` is `suspended` when the broker suspended the client. The state keeps the client and its
377
+ values, so the client works again when the broker lifts the suspension.
378
+ - `IdentityBroker.Client.variables(client)` gives `issuer`, `clientId`, and `clientSecret` for the
379
+ app's deployment: the client's values when `status` is `on`, and the off values when it is `off`
380
+ or `suspended`. Give these to the deployment, not the outputs of the client.
381
+ - `IdentityBroker.Client.read(id, { stage })` gives the attributes of the client `id` in another
379
382
  stage of the same stack, from the state store of the stack. When that stage has no row, it gives
380
- the off attributes and does not fail. `IdentityHub.Client.ref` fails when the row is missing,
383
+ the off attributes and does not fail. `IdentityBroker.Client.ref` fails when the row is missing,
381
384
  and a development stage before the first deploy to main has no `prod` row.
382
- - The resource type is `IdentityHub.Client`. A row that an earlier version saved as
383
- `IdentityHub.SharedClient` is the same client: the next deploy updates it in place and saves it
384
- with the new type.
385
+ - The resource type is `IdentityBroker.Client`. A row that an earlier version saved as
386
+ `IdentityHub.Client` or `IdentityHub.SharedClient` is the same client: the next deploy updates
387
+ it in place and saves it with the new type, and `read` reads it.
385
388
  - A destroy deletes a preview or development client. It does nothing to a production client,
386
389
  because the production deployment can stay.
387
- - `hub` is the identity hub to register at, required: `{ issuer }`, such as
390
+ - `broker` is the identity broker to register at, required: `{ issuer }`, such as
388
391
  `{ issuer: "https://id.samebase.com" }`. The run registers at `<issuer>/register`, the client
389
392
  registration endpoint of RFC 7591, with a GitHub token whose audience is the issuer, and the
390
393
  answer must name that issuer. The request sends `redirect_uris`, `software_id` (the app name),
391
- `software_version`, `token_endpoint_auth_method` (`client_secret_post`), and the hub's own
392
- `connectors`. The hub must run `@samebase/identity-broker` 0.33.0 or later. An earlier hub
393
- answers 404, and the client gets the off values. A client is renewed only at the hub that issued
394
- it: a changed hub registers a new client there, and the old one stays at the old hub.
394
+ `software_version`, `token_endpoint_auth_method` (`client_secret_post`), and the broker's own
395
+ `connectors`. The broker must run `@samebase/identity-broker` 0.33.0 or later. An earlier broker
396
+ answers 404, and the client gets the off values. A client is renewed only at the broker that
397
+ issued it: a changed broker registers a new client there, and the old one stays at the old
398
+ broker.
395
399
 
396
400
  - `Convex.LocalDeployment`: `{ rootDir?, env }` writes the `env` of the logged-in local deployment
397
401
  of the folder `rootDir` (the working directory without it), which
@@ -418,7 +422,7 @@ taken over by its Convex name:
418
422
  ```ts
419
423
  // `selected` is the name in CONVEX_DEPLOYMENT of .env.local, such as happy-animal-123, and
420
424
  // `project` is the project of stage `prod`.
421
- const prod = IdentityHub.Client.read("HubClient", { stage: "prod" });
425
+ const prod = IdentityBroker.Client.read("BrokerClient", { stage: "prod" });
422
426
  const site =
423
427
  yield *
424
428
  Convex.Deployment("Verification", {
@@ -427,39 +431,39 @@ const site =
427
431
  name: selected,
428
432
  env: { SAMEBASE_REPOSITORY_ID: prod.repository },
429
433
  }).pipe(adopt(true));
430
- const hub =
434
+ const client =
431
435
  yield *
432
- IdentityHub.Client("HubClient", {
433
- redirectUris: [Output.interpolate`${site.siteUrl}/auth/hub/callback`],
436
+ IdentityBroker.Client("BrokerClient", {
437
+ redirectUris: [Output.interpolate`${site.siteUrl}/auth/broker/callback`],
434
438
  deploymentType: "development",
435
439
  connectors: ["google", "github"],
436
440
  initialAccessToken: prod.initialAccessToken,
437
441
  });
438
- const variables = IdentityHub.Client.variables(hub);
442
+ const variables = IdentityBroker.Client.variables(client);
439
443
  yield *
440
444
  Convex.Deployment("Site", {
441
445
  project,
442
446
  type: "dev",
443
447
  name: selected,
444
448
  env: {
445
- IDENTITY_HUB_ISSUER: variables.issuer,
446
- IDENTITY_HUB_CLIENT_ID: variables.clientId,
447
- IDENTITY_HUB_CLIENT_SECRET: variables.clientSecret,
449
+ IDENTITY_BROKER_ISSUER: variables.issuer,
450
+ IDENTITY_BROKER_CLIENT_ID: variables.clientId,
451
+ IDENTITY_BROKER_CLIENT_SECRET: variables.clientSecret,
448
452
  },
449
453
  }).pipe(adopt(true));
450
454
  ```
451
455
 
452
456
  The imports are `alchemy/AdoptPolicy` for `adopt`, `alchemy/Output` for `Output`, and
453
- `@samebase/alchemy-convex/identity-hub` for `IdentityHub`.
457
+ `@samebase/alchemy-convex/identity-broker` for `IdentityBroker`.
454
458
 
455
- 1. `read` gives the initial access token and the repository id from the `HubClient` row of stage
459
+ 1. `read` gives the initial access token and the repository id from the `BrokerClient` row of stage
456
460
  `prod`.
457
461
  2. "Verification" sets `SAMEBASE_REPOSITORY_ID`, which the site serves as
458
462
  `/samebase-verification.json`. `adopt` takes over the deployment and the variables that the dev
459
463
  start set before.
460
- 3. "HubClient" asks the hub for a development client on the deployment's site URL with the token. A
461
- later run renews it. A sign-in renews it too, so a development server in use never needs the
462
- stage again; a development client expires 14 days after its last run or sign-in.
464
+ 3. "BrokerClient" asks the broker for a development client on the deployment's site URL with the
465
+ token. A later run renews it. A sign-in renews it too, so a development server in use never needs
466
+ the stage again; a development client expires 14 days after its last run or sign-in.
463
467
  4. "Site" writes the three variables. It removes only a name that leaves its own `env`, so
464
468
  `SAMEBASE_REPOSITORY_ID` stays.
465
469
 
@@ -472,8 +476,8 @@ deletes the development client and keeps the deployment.
472
476
  stack of the repository at the stage `pr-<number>`: the folder, the address, the last run, and a row
473
477
  for each main resource, with its type, its link and its schedule, each under the resource that uses
474
478
  it. The rows come from `stageDiagram` of `@samebase/alchemy-kit/stack`, the same model as Samebase's
475
- stack diagram, so a project or a hub client shows under its deployment and not as a row of its own.
476
- A stack sees only itself, so a comment that a stack declares cannot show this.
479
+ stack diagram, so a project or a broker client shows under its deployment and not as a row of its
480
+ own. A stack sees only itself, so a comment that a stack declares cannot show this.
477
481
 
478
482
  Run it after every deploy of the workflow. The run record gives the repository and the pull request,
479
483
  so the command needs no argument with a team access token: