@samebase/alchemy-convex 0.46.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 +3 -142
- package/lib/{State-Bp7iSx8T.js → State-Dd88J2_z.js} +2 -2
- package/lib/{State-Bp7iSx8T.js.map → State-Dd88J2_z.js.map} +1 -1
- package/lib/cli.js +2 -2
- package/lib/index.d.ts +52 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -7
- package/lib/index.js.map +1 -1
- package/package.json +1 -5
- package/src/Providers.ts +2 -21
- package/lib/IdentityBroker-BqA_2V3_.js +0 -430
- package/lib/IdentityBroker-BqA_2V3_.js.map +0 -1
- package/lib/IdentityBroker.d.ts +0 -162
- package/lib/IdentityBroker.d.ts.map +0 -1
- package/lib/IdentityBroker.js +0 -1
- package/lib/Providers-zL1fUs0r.d.ts +0 -58
- package/lib/Providers-zL1fUs0r.d.ts.map +0 -1
- package/src/IdentityBroker.ts +0 -849
package/README.md
CHANGED
|
@@ -313,90 +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
|
-
- `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
|
|
320
|
-
host, and for development as a stage of the same stack. `deploymentType` is `production`,
|
|
321
|
-
`preview`, or `development`. A production or preview client needs `permissions: id-token: write`
|
|
322
|
-
in the workflow, and no key and no Samebase account. `redirectUris` lists every return address of
|
|
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
|
|
325
|
-
repository, `{ "repository": "123" }`, which `gh api repos/<owner>/<name> --jq .id` prints. The
|
|
326
|
-
broker reads it before it registers the client, so the site must be live first. Outputs `status`,
|
|
327
|
-
`issuer`, `clientId`, `clientSecret`, `registrationAccessToken`, `registrationClientUri`,
|
|
328
|
-
`deploymentType`, `app`, `redirectUris`, `connectors`, `initialAccessToken`, and `repository`.
|
|
329
|
-
- `app` is the app's name on the broker, at most 64 characters. Its default is the stack's path in
|
|
330
|
-
the repository, `apps/web` for the stack `owner/repo/apps/web`, and `app` for a stack named
|
|
331
|
-
`owner/repo`. A stack with another name, or a path over 64 characters, sets `app`. The name
|
|
332
|
-
groups the clients of one deployable thing, their budgets, and the initial access token; it
|
|
333
|
-
plays no part in user ids.
|
|
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
|
|
336
|
-
lists what it offers in `connectors_supported`, and its policy decides what a repository may
|
|
337
|
-
enroll in; a name outside that is refused, and the log names the allowed ones. The set is
|
|
338
|
-
recorded on the client for good, sorted, each once. The app sends `connector=<name>` to
|
|
339
|
-
`/authorize` to skip the broker's page, or nothing to let the user choose among the set.
|
|
340
|
-
- A production registration also gets the app's initial access token (RFC 7591) and the numeric
|
|
341
|
-
repository id, which the state keeps. A renewal keeps both. They are empty for a preview, for a
|
|
342
|
-
development client, and for the off values.
|
|
343
|
-
- A development client needs `initialAccessToken`, and only a development client takes it. The
|
|
344
|
-
client asks the broker with this token in place of the GitHub OIDC token, so it works in
|
|
345
|
-
development. With an empty token, the client gets the off values, and the log says "deploy to
|
|
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
|
|
348
|
-
any run, with no GitHub token and no verification file. It waits up to about three minutes for
|
|
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
|
|
359
|
-
administrator deletes it, and a new production client replaces the app's initial access token,
|
|
360
|
-
so a development stage reads the latest state of `prod` before its next registration. A saved
|
|
361
|
-
row whose attributes this version cannot read stops the run with a fixed message, which holds no
|
|
362
|
-
value of the row.
|
|
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.
|
|
367
|
-
Without saved values, `status` is `off`, and `issuer`, `clientId`, and `clientSecret` are the
|
|
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
|
|
382
|
-
stage of the same stack, from the state store of the stack. When that stage has no row, it gives
|
|
383
|
-
the off attributes and does not fail. `IdentityBroker.Client.ref` fails when the row is missing,
|
|
384
|
-
and a development stage before the first deploy to main has no `prod` row.
|
|
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.
|
|
388
|
-
- A destroy deletes a preview or development client. It does nothing to a production client,
|
|
389
|
-
because the production deployment can stay.
|
|
390
|
-
- `broker` is the identity broker to register at, required: `{ issuer }`, such as
|
|
391
|
-
`{ issuer: "https://id.samebase.com" }`. The run registers at `<issuer>/register`, the client
|
|
392
|
-
registration endpoint of RFC 7591, with a GitHub token whose audience is the issuer, and the
|
|
393
|
-
answer must name that issuer. The request sends `redirect_uris`, `software_id` (the app name),
|
|
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.
|
|
399
|
-
|
|
400
316
|
- `Convex.LocalDeployment`: `{ rootDir?, env }` writes the `env` of the logged-in local deployment
|
|
401
317
|
of the folder `rootDir` (the working directory without it), which
|
|
402
318
|
`npx convex deployment create <team>:<project>:local --select` makes and `npx convex dev` runs.
|
|
@@ -411,64 +327,9 @@ resources and output, from the store function `state:readStack({ stack })` in on
|
|
|
411
327
|
- With a `local:` deployment selected in `.env.local`, the Convex CLI login takes the team of the
|
|
412
328
|
project in `config.json`.
|
|
413
329
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
not at each dev start: `npx convex dev` has made and selected the dev deployment and pushed the
|
|
418
|
-
code, and then `alchemy deploy --stage dev-<name>` gives that deployment its variables. The stage
|
|
419
|
-
creates nothing and pushes nothing. It has three rows on the deployment that `.env.local` selects,
|
|
420
|
-
taken over by its Convex name:
|
|
421
|
-
|
|
422
|
-
```ts
|
|
423
|
-
// `selected` is the name in CONVEX_DEPLOYMENT of .env.local, such as happy-animal-123, and
|
|
424
|
-
// `project` is the project of stage `prod`.
|
|
425
|
-
const prod = IdentityBroker.Client.read("BrokerClient", { stage: "prod" });
|
|
426
|
-
const site =
|
|
427
|
-
yield *
|
|
428
|
-
Convex.Deployment("Verification", {
|
|
429
|
-
project,
|
|
430
|
-
type: "dev",
|
|
431
|
-
name: selected,
|
|
432
|
-
env: { SAMEBASE_REPOSITORY_ID: prod.repository },
|
|
433
|
-
}).pipe(adopt(true));
|
|
434
|
-
const client =
|
|
435
|
-
yield *
|
|
436
|
-
IdentityBroker.Client("BrokerClient", {
|
|
437
|
-
redirectUris: [Output.interpolate`${site.siteUrl}/auth/broker/callback`],
|
|
438
|
-
deploymentType: "development",
|
|
439
|
-
connectors: ["google", "github"],
|
|
440
|
-
initialAccessToken: prod.initialAccessToken,
|
|
441
|
-
});
|
|
442
|
-
const variables = IdentityBroker.Client.variables(client);
|
|
443
|
-
yield *
|
|
444
|
-
Convex.Deployment("Site", {
|
|
445
|
-
project,
|
|
446
|
-
type: "dev",
|
|
447
|
-
name: selected,
|
|
448
|
-
env: {
|
|
449
|
-
IDENTITY_BROKER_ISSUER: variables.issuer,
|
|
450
|
-
IDENTITY_BROKER_CLIENT_ID: variables.clientId,
|
|
451
|
-
IDENTITY_BROKER_CLIENT_SECRET: variables.clientSecret,
|
|
452
|
-
},
|
|
453
|
-
}).pipe(adopt(true));
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
The imports are `alchemy/AdoptPolicy` for `adopt`, `alchemy/Output` for `Output`, and
|
|
457
|
-
`@samebase/alchemy-convex/identity-broker` for `IdentityBroker`.
|
|
458
|
-
|
|
459
|
-
1. `read` gives the initial access token and the repository id from the `BrokerClient` row of stage
|
|
460
|
-
`prod`.
|
|
461
|
-
2. "Verification" sets `SAMEBASE_REPOSITORY_ID`, which the site serves as
|
|
462
|
-
`/samebase-verification.json`. `adopt` takes over the deployment and the variables that the dev
|
|
463
|
-
start set before.
|
|
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.
|
|
467
|
-
4. "Site" writes the three variables. It removes only a name that leaves its own `env`, so
|
|
468
|
-
`SAMEBASE_REPOSITORY_ID` stays.
|
|
469
|
-
|
|
470
|
-
Both deployment rows keep the default removal policy `retain`. `alchemy destroy --stage dev-<name>`
|
|
471
|
-
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).
|
|
472
333
|
|
|
473
334
|
## Pull request comment
|
|
474
335
|
|
|
@@ -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-
|
|
1699
|
+
//# sourceMappingURL=State-Dd88J2_z.js.map
|