@samebase/alchemy-convex 0.45.0 → 0.47.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,86 +313,6 @@ 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
319
- host, and for development as a stage of the same stack. `deploymentType` is `production`,
320
- `preview`, or `development`. A production or preview client needs `permissions: id-token: write`
321
- 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
324
- 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
- `issuer`, `clientId`, `clientSecret`, `registrationAccessToken`, `registrationClientUri`,
327
- `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
- the repository, `apps/web` for the stack `owner/repo/apps/web`, and `app` for a stack named
330
- `owner/repo`. A stack with another name, or a path over 64 characters, sets `app`. The name
331
- groups the clients of one deployable thing, their budgets, and the initial access token; it
332
- 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
335
- lists what it offers in `connectors_supported`, and its policy decides what a repository may
336
- enroll in; a name outside that is refused, and the log names the allowed ones. The set is
337
- 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
- - A production registration also gets the app's initial access token (RFC 7591) and the numeric
340
- repository id, which the state keeps. A renewal keeps both. They are empty for a preview, for a
341
- development client, and for the off values.
342
- - 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
- 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
347
- 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
358
- administrator deletes it, and a new production client replaces the app's initial access token,
359
- so a development stage reads the latest state of `prod` before its next registration. A saved
360
- row whose attributes this version cannot read stops the run with a fixed message, which holds no
361
- 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.
366
- 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
379
- 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,
381
- 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
- - A destroy deletes a preview or development client. It does nothing to a production client,
386
- because the production deployment can stay.
387
- - `hub` is the identity hub to register at, required: `{ issuer }`, such as
388
- `{ issuer: "https://id.samebase.com" }`. The run registers at `<issuer>/register`, the client
389
- registration endpoint of RFC 7591, with a GitHub token whose audience is the issuer, and the
390
- 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.
395
-
396
316
  - `Convex.LocalDeployment`: `{ rootDir?, env }` writes the `env` of the logged-in local deployment
397
317
  of the folder `rootDir` (the working directory without it), which
398
318
  `npx convex deployment create <team>:<project>:local --select` makes and `npx convex dev` runs.
@@ -407,64 +327,9 @@ resources and output, from the store function `state:readStack({ stack })` in on
407
327
  - With a `local:` deployment selected in `.env.local`, the Convex CLI login takes the team of the
408
328
  project in `config.json`.
409
329
 
410
- ### The development stage
411
-
412
- A development checkout gets its client from a stage `dev-<name>` of the app's stack, run on purpose,
413
- not at each dev start: `npx convex dev` has made and selected the dev deployment and pushed the
414
- code, and then `alchemy deploy --stage dev-<name>` gives that deployment its variables. The stage
415
- creates nothing and pushes nothing. It has three rows on the deployment that `.env.local` selects,
416
- taken over by its Convex name:
417
-
418
- ```ts
419
- // `selected` is the name in CONVEX_DEPLOYMENT of .env.local, such as happy-animal-123, and
420
- // `project` is the project of stage `prod`.
421
- const prod = IdentityHub.Client.read("HubClient", { stage: "prod" });
422
- const site =
423
- yield *
424
- Convex.Deployment("Verification", {
425
- project,
426
- type: "dev",
427
- name: selected,
428
- env: { SAMEBASE_REPOSITORY_ID: prod.repository },
429
- }).pipe(adopt(true));
430
- const hub =
431
- yield *
432
- IdentityHub.Client("HubClient", {
433
- redirectUris: [Output.interpolate`${site.siteUrl}/auth/hub/callback`],
434
- deploymentType: "development",
435
- connectors: ["google", "github"],
436
- initialAccessToken: prod.initialAccessToken,
437
- });
438
- const variables = IdentityHub.Client.variables(hub);
439
- yield *
440
- Convex.Deployment("Site", {
441
- project,
442
- type: "dev",
443
- name: selected,
444
- env: {
445
- IDENTITY_HUB_ISSUER: variables.issuer,
446
- IDENTITY_HUB_CLIENT_ID: variables.clientId,
447
- IDENTITY_HUB_CLIENT_SECRET: variables.clientSecret,
448
- },
449
- }).pipe(adopt(true));
450
- ```
451
-
452
- The imports are `alchemy/AdoptPolicy` for `adopt`, `alchemy/Output` for `Output`, and
453
- `@samebase/alchemy-convex/identity-hub` for `IdentityHub`.
454
-
455
- 1. `read` gives the initial access token and the repository id from the `HubClient` row of stage
456
- `prod`.
457
- 2. "Verification" sets `SAMEBASE_REPOSITORY_ID`, which the site serves as
458
- `/samebase-verification.json`. `adopt` takes over the deployment and the variables that the dev
459
- 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.
463
- 4. "Site" writes the three variables. It removes only a name that leaves its own `env`, so
464
- `SAMEBASE_REPOSITORY_ID` stays.
465
-
466
- Both deployment rows keep the default removal policy `retain`. `alchemy destroy --stage dev-<name>`
467
- deletes the development client and keeps the deployment.
330
+ A client of an identity broker, `IdentityBroker.Client`, is in `@samebase/identity-broker/alchemy`:
331
+ see
332
+ [An app that uses a broker](https://github.com/samebase/samebase/tree/main/packages/identity-broker#an-app-that-uses-a-broker).
468
333
 
469
334
  ## Pull request comment
470
335
 
@@ -472,8 +337,8 @@ deletes the development client and keeps the deployment.
472
337
  stack of the repository at the stage `pr-<number>`: the folder, the address, the last run, and a row
473
338
  for each main resource, with its type, its link and its schedule, each under the resource that uses
474
339
  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.
340
+ stack diagram, so a project or a broker client shows under its deployment and not as a row of its
341
+ own. A stack sees only itself, so a comment that a stack declares cannot show this.
477
342
 
478
343
  Run it after every deploy of the workflow. The run record gives the repository and the pull request,
479
344
  so the command needs no argument with a team access token:
@@ -27,9 +27,9 @@ import { hashDirectory } from "alchemy/Command/Memo";
27
27
  import * as Clock from "effect/Clock";
28
28
  import * as ChildProcess from "effect/process/ChildProcess";
29
29
  import * as Stream from "effect/Stream";
30
- import { STATE_STORE_VERSION, State, StateStoreError, encodeState, reviveState } from "alchemy/State";
31
30
  import { fileURLToPath } from "node:url";
32
31
  import * as Scope from "effect/Scope";
32
+ import { STATE_STORE_VERSION, State, StateStoreError, encodeState, reviveState } from "alchemy/State";
33
33
  //#region src/Credentials.ts
34
34
  var Credentials = class extends Context.Service()("@samebase/alchemy-convex/Credentials") {};
35
35
  /** Environment variable for the access token, read by {@link fromConfig}. */
@@ -1696,4 +1696,4 @@ const state = () => Layer.effect(State, Effect.gen(function* () {
1696
1696
  //#endregion
1697
1697
  export { Credentials as A, parseDeployOutput as C, ManagementApiLive as D, ManagementApi as E, DEPLOY_KEY_ENV as M, fromConfig as N, readLocalDeployment as O, fromValues as P, VariablesOwnedBySomeoneElse as S, ConvexApiError as T, CodePushFailed as _, Project as a, EnvironmentNeedsDeployKey as b, ProjectProvider as c, AmbiguousDeployment as d, Deployment as f, ProductionDeploymentNotFound as g, DeploymentResource as h, CreatedProjectNotFound as i, CredentialsError as j, ACCESS_TOKEN_ENV as k, ProjectTeamChange as l, DeploymentProvider as m, state as n, ProjectDeploymentChange as o, DeploymentIdentityChange as p, AmbiguousProject as r, ProjectNotFound as s, STORE_PROJECT_NAME as t, AbsoluteRootDir as u, ConvexAppNotFound as v, push as w, PushTargetMismatch as x, ConvexCliNotFound as y };
1698
1698
 
1699
- //# sourceMappingURL=State-Bp7iSx8T.js.map
1699
+ //# sourceMappingURL=State-Dd88J2_z.js.map