@samebase/alchemy-convex 0.31.0 → 0.33.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 +55 -46
- package/lib/{State-t0BZggNl.js → State-CuktZaOh.js} +6 -6
- package/lib/{State-t0BZggNl.js.map → State-CuktZaOh.js.map} +1 -1
- package/lib/cli.js +11 -8
- package/lib/cli.js.map +1 -1
- package/lib/index.d.ts +19 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +49 -15
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LocalDeployment.ts +1 -1
- package/src/RunRecord.ts +10 -5
- package/src/SharedHubClient.ts +107 -43
- package/src/StackComment.ts +8 -3
- package/src/store/component/_generated/component.ts +5 -5
- package/src/store/component/runRecord.ts +2 -2
- package/src/store/convex/version.ts +2 -1
package/README.md
CHANGED
|
@@ -182,20 +182,20 @@ export default Alchemy.Stack(
|
|
|
182
182
|
);
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
Every run needs the team token in `CONVEX_ACCESS_TOKEN`, or the Convex CLI login on a
|
|
186
|
-
state and the projects are in the team of that credential. A team access token and an
|
|
187
|
-
a team name their team. The Convex CLI login names no team, so the run uses the team
|
|
188
|
-
deployment that the Convex CLI selected: `CONVEX_DEPLOYMENT` in the environment or in
|
|
189
|
-
which `npx convex dev` writes. A logged-in local deployment gives the team of its
|
|
190
|
-
folder's `.convex/local/default/config.json`. An anonymous deployment is in no
|
|
191
|
-
stops and asks for a deployment of a project. The first run of a team creates the
|
|
192
|
-
`alchemy-state-store` and pushes the store functions to its production deployment with the
|
|
193
|
-
CLI of the app; a later version of this package pushes a newer store when it finds an older
|
|
194
|
-
store that is newer than the package fails the run with both versions, so the repositories of
|
|
195
|
-
upgrade the package together. Each run makes a deploy key of that deployment that can only
|
|
196
|
-
store's internal functions, and deletes it at the end. Rows are in the tables `resources`
|
|
197
|
-
`outputs` of the component `alchemyState` in the dashboard, under the stack name. The store has
|
|
198
|
-
lock: run one deploy of a stage at a time, such as with a CI concurrency group. The store and its
|
|
185
|
+
Every run needs the team token in `CONVEX_ACCESS_TOKEN`, or the Convex CLI login on a development
|
|
186
|
+
machine. The state and the projects are in the team of that credential. A team access token and an
|
|
187
|
+
OAuth token of a team name their team. The Convex CLI login names no team, so the run uses the team
|
|
188
|
+
of the deployment that the Convex CLI selected: `CONVEX_DEPLOYMENT` in the environment or in
|
|
189
|
+
`.env.local`, which `npx convex dev` writes. A logged-in local deployment gives the team of its
|
|
190
|
+
project, from the folder's `.convex/local/default/config.json`. An anonymous deployment is in no
|
|
191
|
+
team, so the run stops and asks for a deployment of a project. The first run of a team creates the
|
|
192
|
+
project `alchemy-state-store` and pushes the store functions to its production deployment with the
|
|
193
|
+
Convex CLI of the app; a later version of this package pushes a newer store when it finds an older
|
|
194
|
+
one. A store that is newer than the package fails the run with both versions, so the repositories of
|
|
195
|
+
a team upgrade the package together. Each run makes a deploy key of that deployment that can only
|
|
196
|
+
run the store's internal functions, and deletes it at the end. Rows are in the tables `resources`
|
|
197
|
+
and `outputs` of the component `alchemyState` in the dashboard, under the stack name. The store has
|
|
198
|
+
no lock: run one deploy of a stage at a time, such as with a CI concurrency group. The store and its
|
|
199
199
|
readers (Samebase) are released and upgraded together.
|
|
200
200
|
|
|
201
201
|
Store version 3 supports native subscriptions. A trusted server checks repository access, then calls
|
|
@@ -236,8 +236,8 @@ To rotate the key, from a directory that selects the project `alchemy-state-stor
|
|
|
236
236
|
|
|
237
237
|
Alchemy state holds no time, commit, branch, or run. `Convex.state()` adds them to the stage output:
|
|
238
238
|
the document that `setOutput` stores is the stack's output plus the key `samebase.run`. On GitHub
|
|
239
|
-
Actions the record comes from the run's variables and the event payload; on a
|
|
240
|
-
needs a branch and an `origin` remote. It holds no secret.
|
|
239
|
+
Actions the record comes from the run's variables and the event payload; on a development machine
|
|
240
|
+
from git, which needs a branch and an `origin` remote. It holds no secret.
|
|
241
241
|
|
|
242
242
|
```json
|
|
243
243
|
{
|
|
@@ -257,13 +257,13 @@ needs a branch and an `origin` remote. It holds no secret.
|
|
|
257
257
|
```
|
|
258
258
|
|
|
259
259
|
`stackFile` is the working directory of the run below the repository root plus `alchemy.run.ts`.
|
|
260
|
-
`pullRequest` and `runUrl` are `null` for a push and for a
|
|
261
|
-
value that the stack itself returns under `samebase.run` stays. A checkout
|
|
262
|
-
such as a tarball without git or a detached HEAD, writes its outputs without
|
|
263
|
-
why. Alchemy writes the output once after a full successful deploy, so a
|
|
264
|
-
previous record, and a deploy of selected resources writes none. A reader
|
|
265
|
-
stack, with its resources and output, from the store function
|
|
266
|
-
call.
|
|
260
|
+
`pullRequest` and `runUrl` are `null` for a push and for a checkout outside GitHub Actions, where
|
|
261
|
+
`source` is `checkout`. A value that the stack itself returns under `samebase.run` stays. A checkout
|
|
262
|
+
that gives no record, such as a tarball without git or a detached HEAD, writes its outputs without
|
|
263
|
+
one, and the log says why. Alchemy writes the output once after a full successful deploy, so a
|
|
264
|
+
failed deploy leaves the previous record, and a deploy of selected resources writes none. A reader
|
|
265
|
+
gets every stage of a stack, with its resources and output, from the store function
|
|
266
|
+
`state:readStack({ stack })` in one call.
|
|
267
267
|
|
|
268
268
|
## Resources
|
|
269
269
|
|
|
@@ -305,32 +305,40 @@ call.
|
|
|
305
305
|
every action, because the command can do more than a push.
|
|
306
306
|
|
|
307
307
|
- `Convex.SharedHubClient`:
|
|
308
|
-
`{ app, redirectUri, deploymentType, initialAccessToken?, softwareVersion? }` gets a
|
|
309
|
-
central identity hub, for an app that deploys in its own GitHub Actions run, on any
|
|
310
|
-
|
|
311
|
-
`development`. A production or preview client needs `permissions: id-token: write`
|
|
312
|
-
workflow, and no key and no Samebase account. `app` is at most 64 characters. The origin of
|
|
313
|
-
https `redirectUri` must serve `/samebase-verification.json` with the numeric GitHub id of the
|
|
308
|
+
`{ app, redirectUri, deploymentType, connectors, initialAccessToken?, softwareVersion? }` gets a
|
|
309
|
+
client of the central identity hub, for an app that deploys in its own GitHub Actions run, on any
|
|
310
|
+
host, and for development as a stage of the same stack. `deploymentType` is `production`,
|
|
311
|
+
`preview`, or `development`. A production or preview client needs `permissions: id-token: write`
|
|
312
|
+
in the workflow, and no key and no Samebase account. `app` is at most 64 characters. The origin of
|
|
313
|
+
an https `redirectUri` must serve `/samebase-verification.json` with the numeric GitHub id of the
|
|
314
314
|
repository, `{ "repository": "123" }`, which `gh api repos/<owner>/<name> --jq .id` prints. The
|
|
315
315
|
hub reads it before it registers the client, so the site must be live first. Outputs `status`,
|
|
316
316
|
`issuer`, `clientId`, `clientSecret`, `registrationAccessToken`, `registrationClientUri`,
|
|
317
|
-
`deploymentType`, `redirectUri`, `initialAccessToken`, and `repository`.
|
|
317
|
+
`deploymentType`, `redirectUri`, `connectors`, `initialAccessToken`, and `repository`.
|
|
318
|
+
- `connectors` names the hub's connectors the client signs in through, such as
|
|
319
|
+
`["google", "github"]`: at least one name of `[a-z0-9-]{1,64}`. The hub's discovery document
|
|
320
|
+
lists what it offers in `connectors_supported`, and its policy decides what a repository may
|
|
321
|
+
enroll in; a name outside that is refused, and the log names the allowed ones. The set is
|
|
322
|
+
recorded on the client for good, sorted, each once. The app sends `connector=<name>` to
|
|
323
|
+
`/authorize` to skip the hub's page, or nothing to let the user choose among the set.
|
|
318
324
|
- A production registration also gets the app's initial access token (RFC 7591) and the numeric
|
|
319
325
|
repository id, which the state keeps. A renewal keeps both. They are empty for a preview, for a
|
|
320
326
|
development client, and for the off values.
|
|
321
327
|
- A development client needs `initialAccessToken`, and only a development client takes it. The
|
|
322
|
-
client asks the hub with this token in place of the GitHub OIDC token, so it works
|
|
323
|
-
With an empty token, the client gets the off values, and the log says "deploy to
|
|
324
|
-
|
|
328
|
+
client asks the hub with this token in place of the GitHub OIDC token, so it works in
|
|
329
|
+
development. With an empty token, the client gets the off values, and the log says "deploy to
|
|
330
|
+
main once for hub sign-in in development". See "The development stage" below.
|
|
325
331
|
- Each deploy reads the saved client on the hub with its own token. A client that is gone gets a
|
|
326
|
-
new one, and a client on another `redirectUri
|
|
332
|
+
new one, and a client on another `redirectUri`, of another `deploymentType`, or with other
|
|
333
|
+
`connectors` too. A replaced production client stays valid on the hub until its administrator
|
|
334
|
+
deletes it.
|
|
327
335
|
- A new client logs the link to the terms of the shared sign-in service. A refusal logs its
|
|
328
|
-
reason, such as a host that does not serve the file, a block, a token of another app,
|
|
329
|
-
hourly limit it reached.
|
|
336
|
+
reason, such as a host that does not serve the file, a block, a token of another app, a
|
|
337
|
+
connector the hub does not offer or allow, or the hourly limit it reached.
|
|
330
338
|
- No failure stops a deploy or a destroy. A failed renewal keeps the saved values. Without saved
|
|
331
339
|
values, `status` is `off`, and `issuer`, `clientId`, and `clientSecret` are the `no-hub` values
|
|
332
340
|
of a checkout without a hub. A production or preview run without a GitHub OIDC token, such as on
|
|
333
|
-
a
|
|
341
|
+
a development machine, does the same, and logs no warning.
|
|
334
342
|
- `required: true` makes the run fail unless the hub confirms the client in this run: a refusal, a
|
|
335
343
|
hub that does not answer a registration or a renewal, or a suspended client fails it. Set it
|
|
336
344
|
where sign-in is the product, so a deploy never ships guest sign-in, or a client that the hub
|
|
@@ -343,7 +351,7 @@ call.
|
|
|
343
351
|
- `Convex.SharedHubClient.read(id, { stage })` gives the attributes of the client `id` in another
|
|
344
352
|
stage of the same stack, from the state store of the stack. When that stage has no row, it gives
|
|
345
353
|
the off attributes and does not fail. `Convex.SharedHubClient.ref` fails when the row is
|
|
346
|
-
missing, and a
|
|
354
|
+
missing, and a development stage before the first deploy to main has no `prod` row.
|
|
347
355
|
- A destroy deletes a preview or development client. It does nothing to a production client,
|
|
348
356
|
because the production deployment can stay.
|
|
349
357
|
- `HUB_URL` replaces `https://auth.samebase.com`, the hub that the run asks at `/hub-clients`.
|
|
@@ -364,11 +372,11 @@ call.
|
|
|
364
372
|
|
|
365
373
|
### The development stage
|
|
366
374
|
|
|
367
|
-
A
|
|
368
|
-
dev start: `npx convex dev` has made and selected the dev deployment and pushed the
|
|
369
|
-
`alchemy deploy --stage dev-<name>` gives that deployment its variables. The stage
|
|
370
|
-
and pushes nothing. It has three rows on the deployment that `.env.local` selects,
|
|
371
|
-
Convex name:
|
|
375
|
+
A development checkout gets its client from a stage `dev-<name>` of the app's stack, run on purpose,
|
|
376
|
+
not at each dev start: `npx convex dev` has made and selected the dev deployment and pushed the
|
|
377
|
+
code, and then `alchemy deploy --stage dev-<name>` gives that deployment its variables. The stage
|
|
378
|
+
creates nothing and pushes nothing. It has three rows on the deployment that `.env.local` selects,
|
|
379
|
+
taken over by its Convex name:
|
|
372
380
|
|
|
373
381
|
```ts
|
|
374
382
|
// `selected` is the name in CONVEX_DEPLOYMENT of .env.local, such as happy-animal-123, and
|
|
@@ -388,6 +396,7 @@ const hub =
|
|
|
388
396
|
app: "scout",
|
|
389
397
|
redirectUri: Output.interpolate`${site.siteUrl}/auth/hub/callback`,
|
|
390
398
|
deploymentType: "development",
|
|
399
|
+
connectors: ["google", "github"],
|
|
391
400
|
initialAccessToken: prod.initialAccessToken,
|
|
392
401
|
});
|
|
393
402
|
const variables = Convex.SharedHubClient.variables(hub);
|
|
@@ -412,8 +421,8 @@ The imports are `alchemy/AdoptPolicy` for `adopt` and `alchemy/Output` for `Outp
|
|
|
412
421
|
`/samebase-verification.json`. `adopt` takes over the deployment and the variables that the dev
|
|
413
422
|
start set before.
|
|
414
423
|
3. "HubClient" asks the hub for a development client on the deployment's site URL with the token. A
|
|
415
|
-
later run renews it. A sign-in renews it too, so a
|
|
416
|
-
development client expires 14 days after its last run or sign-in.
|
|
424
|
+
later run renews it. A sign-in renews it too, so a development server in use never needs the
|
|
425
|
+
stage again; a development client expires 14 days after its last run or sign-in.
|
|
417
426
|
4. "Site" writes the three variables. It removes only a name that leaves its own `env`, so
|
|
418
427
|
`SAMEBASE_REPOSITORY_ID` stays.
|
|
419
428
|
|
|
@@ -424,7 +433,7 @@ deletes the development client and keeps the deployment.
|
|
|
424
433
|
|
|
425
434
|
`alchemy-convex stack-comment` keeps one comment on a pull request. The comment has a card for each
|
|
426
435
|
stack of the repository at the stage `pr-<number>`: the folder, the address, the last run, the
|
|
427
|
-
Convex deployments, Workers, and R2 buckets, and the
|
|
436
|
+
Convex deployments, Workers, and R2 buckets, and the sign-in status and connectors of a
|
|
428
437
|
`Convex.SharedHubClient`. A stack sees only itself, so a comment that a stack declares cannot show
|
|
429
438
|
this.
|
|
430
439
|
|
|
@@ -1513,7 +1513,7 @@ const fromGit = (where) => Effect.gen(function* () {
|
|
|
1513
1513
|
pullRequest: null,
|
|
1514
1514
|
headCommit: yield* git(cwd, ["rev-parse", "HEAD"]),
|
|
1515
1515
|
runUrl: null,
|
|
1516
|
-
source: "
|
|
1516
|
+
source: "checkout",
|
|
1517
1517
|
recordedAt: yield* now
|
|
1518
1518
|
};
|
|
1519
1519
|
});
|
|
@@ -1679,7 +1679,7 @@ const storeDirectory = () => join(dirname(fileURLToPath(import.meta.url)), "..",
|
|
|
1679
1679
|
*/
|
|
1680
1680
|
const pushStore = (options, deployment) => Effect.gen(function* () {
|
|
1681
1681
|
const cli = yield* installedCli(join(options.store, ".."));
|
|
1682
|
-
yield* Effect.logInfo(`Convex state: pushing the store version
|
|
1682
|
+
yield* Effect.logInfo(`Convex state: pushing the store version 6 to ${deployment.name}`);
|
|
1683
1683
|
yield* withPushKey(options.api, deployment.name, PUSH_KEY_ACTIONS, (key) => push(options.spawner, key, {
|
|
1684
1684
|
deployment: deployment.name,
|
|
1685
1685
|
url: deployment.deploymentUrl,
|
|
@@ -1762,15 +1762,15 @@ const makeConvexState = (options) => Effect.gen(function* () {
|
|
|
1762
1762
|
return next.call(path, args);
|
|
1763
1763
|
})))) };
|
|
1764
1764
|
let version = yield* storeVersion(functions);
|
|
1765
|
-
if (version === void 0 || version <
|
|
1765
|
+
if (version === void 0 || version < 6) {
|
|
1766
1766
|
if (version === void 0 && deployment.lastDeployTime) return yield* failure(`project ${STORE_PROJECT_NAME} (${project.id}) of team ${teamId} has code that is not the state store, and Convex.state does not push over it. Rename that project in the Convex dashboard.`);
|
|
1767
1767
|
version = yield* storeVersion(functions);
|
|
1768
|
-
if (version === void 0 || version <
|
|
1768
|
+
if (version === void 0 || version < 6) {
|
|
1769
1769
|
yield* pushStore(options, deployment);
|
|
1770
1770
|
version = yield* storeVersion(functions);
|
|
1771
1771
|
}
|
|
1772
1772
|
}
|
|
1773
|
-
if (version !==
|
|
1773
|
+
if (version !== 6) return yield* failure(`${deployment.name} answers store version ${version ?? "none"}, and this package needs store version 6.`);
|
|
1774
1774
|
yield* ensureSealed(options, deployment, functions);
|
|
1775
1775
|
const remote = remoteOf(functions, options.run);
|
|
1776
1776
|
/** The stack's output plus the record, when the run has one and the output has a place for it. */
|
|
@@ -1840,4 +1840,4 @@ const state = () => Layer.effect(State, Effect.gen(function* () {
|
|
|
1840
1840
|
//#endregion
|
|
1841
1841
|
export { ManagementApi as A, ConvexCliNotFound as C, parseDeployOutput as D, VariablesOwnedBySomeoneElse as E, CredentialsError as F, DEPLOY_KEY_ENV as I, fromConfig as L, readLocalDeployment as M, ACCESS_TOKEN_ENV as N, push as O, Credentials as P, fromValues as R, ConvexAppNotFound as S, PushTargetMismatch as T, DeploymentIdentityChange as _, runRecord as a, ProductionDeploymentNotFound as b, CreatedProjectNotFound as c, ProjectNotFound as d, ProjectProvider as f, Deployment as g, AmbiguousDeployment as h, RunRecordError as i, ManagementApiLive as j, ConvexApiError as k, Project as l, AbsoluteRootDir as m, state as n, withRunRecord as o, ProjectTeamChange as p, RUN_RECORD_KEY as r, AmbiguousProject as s, STORE_PROJECT_NAME as t, ProjectDeploymentChange as u, DeploymentProvider as v, EnvironmentNeedsDeployKey as w, CodePushFailed as x, DeploymentResource as y };
|
|
1842
1842
|
|
|
1843
|
-
//# sourceMappingURL=State-
|
|
1843
|
+
//# sourceMappingURL=State-CuktZaOh.js.map
|