@samebase/alchemy-convex 0.29.0 → 0.30.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 +29 -10
- package/lib/{HubClient-HeGoVOLO.js → HubClient-X0-FgJ8v.js} +54 -10
- package/lib/HubClient-X0-FgJ8v.js.map +1 -0
- package/lib/cli.js +1 -1
- package/lib/index.d.ts +38 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +67 -7
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LocalDeployment.ts +105 -0
- package/src/ManagementApi.ts +74 -13
- package/src/Providers.ts +3 -1
- package/src/SharedHubClient.ts +31 -7
- package/src/index.ts +6 -0
- package/lib/HubClient-HeGoVOLO.js.map +0 -1
package/README.md
CHANGED
|
@@ -186,16 +186,17 @@ Every run needs the team token in `CONVEX_ACCESS_TOKEN`, or the Convex CLI login
|
|
|
186
186
|
state and the projects are in the team of that credential. A team access token and an OAuth token of
|
|
187
187
|
a team name their team. The Convex CLI login names no team, so the run uses the team of the
|
|
188
188
|
deployment that the Convex CLI selected: `CONVEX_DEPLOYMENT` in the environment or in `.env.local`,
|
|
189
|
-
which `npx convex dev` writes. A local
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
189
|
+
which `npx convex dev` writes. A logged-in local deployment gives the team of its project, from the
|
|
190
|
+
folder's `.convex/local/default/config.json`. An anonymous deployment is in no team, so the run
|
|
191
|
+
stops and asks for a deployment of a project. The first run of a team creates the project
|
|
192
|
+
`alchemy-state-store` and pushes the store functions to its production deployment with the Convex
|
|
193
|
+
CLI of the app; a later version of this package pushes a newer store when it finds an older one. A
|
|
194
|
+
store that is newer than the package fails the run with both versions, so the repositories of a team
|
|
195
|
+
upgrade the package together. Each run makes a deploy key of that deployment that can only run the
|
|
196
|
+
store's internal functions, and deletes it at the end. Rows are in the tables `resources` and
|
|
197
|
+
`outputs` of the component `alchemyState` in the dashboard, under the stack name. The store has no
|
|
198
|
+
lock: run one deploy of a stage at a time, such as with a CI concurrency group. The store and its
|
|
199
|
+
readers (Samebase) are released and upgraded together.
|
|
199
200
|
|
|
200
201
|
Store version 3 supports native subscriptions. A trusted server checks repository access, then calls
|
|
201
202
|
internal `reader:authorize({ repository, subject })` with a deployment credential. It gives the
|
|
@@ -344,6 +345,10 @@ call.
|
|
|
344
345
|
values, `status` is `off`, and `issuer`, `clientId`, and `clientSecret` are the `no-hub` values
|
|
345
346
|
of a checkout without a hub. A production or preview run without a GitHub OIDC token, such as on
|
|
346
347
|
a laptop, does the same, and logs no warning.
|
|
348
|
+
- `required: true` makes the run fail unless the hub confirms the client in this run: a refusal, a
|
|
349
|
+
hub that does not answer a registration or a renewal, or a suspended client fails it. Set it
|
|
350
|
+
where sign-in is the product, so a deploy never ships guest sign-in, or a client that the hub
|
|
351
|
+
stopped, with a green run. A failed run saves nothing, and the next run asks the hub again.
|
|
347
352
|
- `status` is `suspended` when the hub suspended the client. The state keeps the client and its
|
|
348
353
|
values, so the client works again when the hub lifts the suspension.
|
|
349
354
|
- `Convex.SharedHubClient.variables(client)` gives `issuer`, `clientId`, and `clientSecret` for
|
|
@@ -357,6 +362,20 @@ call.
|
|
|
357
362
|
because the production deployment can stay.
|
|
358
363
|
- `HUB_URL` replaces `https://auth.samebase.com`, the hub that the run asks at `/hub-clients`.
|
|
359
364
|
|
|
365
|
+
- `Convex.LocalDeployment`: `{ rootDir?, env }` writes the `env` of the logged-in local deployment
|
|
366
|
+
of the folder `rootDir` (the working directory without it), which
|
|
367
|
+
`npx convex deployment create <team>:<project>:local --select` makes and `npx convex dev` runs.
|
|
368
|
+
Each folder, such as each git worktree, has its own, with its own data. The resource reads the
|
|
369
|
+
deployment's name, ports, and admin key from `.convex/local/default/config.json`, and writes with
|
|
370
|
+
the admin key. It never creates, pushes, or deletes: run the stack while `convex dev` runs. A name
|
|
371
|
+
that leaves `env` is removed. A destroy changes nothing. Outputs `name`, `url`, `siteUrl`, and
|
|
372
|
+
`envNames`.
|
|
373
|
+
- `Convex.LocalDeployment.of(rootDir?)` gives `name`, `url`, and `siteUrl` when the stack's
|
|
374
|
+
program runs, so a client can take the local `siteUrl` for its callback. It throws when the
|
|
375
|
+
folder has no logged-in local deployment, also for an anonymous one.
|
|
376
|
+
- With a `local:` deployment selected in `.env.local`, the Convex CLI login takes the team of the
|
|
377
|
+
project in `config.json`.
|
|
378
|
+
|
|
360
379
|
A development deployment of a team app (`Convex.HubClient`) has no stack, so the package has a
|
|
361
380
|
command for it. Run it in the directory of the app, before the first push and at each dev start,
|
|
362
381
|
with `CONVEX_ACCESS_TOKEN` or the Convex CLI login. It renews the client that `HUB_CLIENT_ID` names,
|
|
@@ -178,11 +178,45 @@ const ProjectSlugRows = Schema.Struct({ items: Schema.Array(Schema.Struct({ team
|
|
|
178
178
|
const DeploymentProject = Schema.Struct({ projectId: Schema.Number });
|
|
179
179
|
/** GET /projects/{id}: the team of the project. */
|
|
180
180
|
const ProjectTeam = Schema.Struct({ teamId: Schema.Number });
|
|
181
|
+
/** A folder's `.convex/local/default/config.json`, as the Convex CLI writes it. */
|
|
182
|
+
const LocalConfig = Schema.Struct({
|
|
183
|
+
deploymentName: Schema.String,
|
|
184
|
+
ports: Schema.Struct({
|
|
185
|
+
cloud: Schema.Number,
|
|
186
|
+
site: Schema.Number
|
|
187
|
+
}),
|
|
188
|
+
adminKey: Schema.String,
|
|
189
|
+
/** The project of a logged-in local deployment. An anonymous one has none. */
|
|
190
|
+
cloudProjectId: Schema.Number
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* The logged-in local deployment of `rootDir`, which `npx convex deployment create
|
|
194
|
+
* <team>:<project>:local` makes: undefined when the folder has none, or only an anonymous one, which
|
|
195
|
+
* belongs to no project.
|
|
196
|
+
*/
|
|
197
|
+
const readLocalDeployment = (rootDir = ".") => {
|
|
198
|
+
let raw;
|
|
199
|
+
try {
|
|
200
|
+
raw = JSON.parse(readFileSync(join(rootDir, ".convex", "local", "default", "config.json"), "utf8"));
|
|
201
|
+
} catch {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const config = Option.getOrUndefined(Schema.decodeUnknownOption(LocalConfig)(raw));
|
|
205
|
+
if (config === void 0 || !config.deploymentName.startsWith("local-")) return void 0;
|
|
206
|
+
return {
|
|
207
|
+
name: config.deploymentName,
|
|
208
|
+
url: `http://127.0.0.1:${config.ports.cloud}`,
|
|
209
|
+
siteUrl: `http://127.0.0.1:${config.ports.site}`,
|
|
210
|
+
projectId: config.cloudProjectId,
|
|
211
|
+
adminKey: Redacted.make(config.adminKey)
|
|
212
|
+
};
|
|
213
|
+
};
|
|
181
214
|
/**
|
|
182
|
-
* The
|
|
183
|
-
* `.env.local` of the working directory, as `npx convex dev` writes it
|
|
184
|
-
*
|
|
185
|
-
*
|
|
215
|
+
* The deployment that the Convex CLI selected: CONVEX_DEPLOYMENT in the environment or in
|
|
216
|
+
* `.env.local` of the working directory, as `npx convex dev` writes it. A cloud deployment
|
|
217
|
+
* (`dev:happy-animal-123`) by its name; a logged-in local deployment (`local:local-team-app`) by the
|
|
218
|
+
* project in the working directory's `.convex/local/default`, when that is the selected one.
|
|
219
|
+
* Undefined when neither has it, and for an anonymous deployment, which is in no project.
|
|
186
220
|
*/
|
|
187
221
|
const selectedDeployment = () => {
|
|
188
222
|
const fromEnv = process.env["CONVEX_DEPLOYMENT"];
|
|
@@ -193,8 +227,19 @@ const selectedDeployment = () => {
|
|
|
193
227
|
return;
|
|
194
228
|
}
|
|
195
229
|
})();
|
|
230
|
+
const localName = /^local:(local-[^:]+)$/.exec(value ?? "")?.[1];
|
|
231
|
+
if (localName !== void 0) {
|
|
232
|
+
const local = readLocalDeployment();
|
|
233
|
+
return local?.name === localName ? {
|
|
234
|
+
kind: "local",
|
|
235
|
+
projectId: local.projectId
|
|
236
|
+
} : void 0;
|
|
237
|
+
}
|
|
196
238
|
const name = /^(?:(?:dev|prod|preview):)?([^:]+)$/.exec(value ?? "")?.[1];
|
|
197
|
-
return name === void 0 || name.startsWith("anonymous-") ? void 0 :
|
|
239
|
+
return name === void 0 || name.startsWith("anonymous-") ? void 0 : {
|
|
240
|
+
kind: "cloud",
|
|
241
|
+
name
|
|
242
|
+
};
|
|
198
243
|
};
|
|
199
244
|
/** GET /token_details: the team of a team token, or the project of a project token. */
|
|
200
245
|
const TokenDetails = Schema.Union([Schema.Struct({
|
|
@@ -230,10 +275,9 @@ const makeService = (source) => {
|
|
|
230
275
|
if (selected === void 0) return yield* new ConvexApiError({
|
|
231
276
|
operation: "resolve team",
|
|
232
277
|
status: 0,
|
|
233
|
-
message: "the Convex CLI login names no team, and no
|
|
278
|
+
message: "the Convex CLI login names no team, and no deployment of a project is selected. Run `npx convex dev` once with a cloud deployment, or create a local one with `npx convex deployment create <team>:<project>:local --select`."
|
|
234
279
|
});
|
|
235
|
-
const
|
|
236
|
-
const { projectId } = Schema.decodeUnknownSync(DeploymentProject)(deployment);
|
|
280
|
+
const projectId = selected.kind === "local" ? selected.projectId : Schema.decodeUnknownSync(DeploymentProject)(yield* request("get deployment", (c) => c.GET("/deployments/{deployment_name}", { params: { path: { deployment_name: selected.name } } }))).projectId;
|
|
237
281
|
const project = yield* request("get project", (c) => c.GET("/projects/{project_id}", { params: { path: { project_id: projectId } } }));
|
|
238
282
|
return Schema.decodeUnknownSync(ProjectTeam)(project).teamId;
|
|
239
283
|
})));
|
|
@@ -2010,6 +2054,6 @@ const registerDevelopmentClient = (options) => Effect.gen(function* () {
|
|
|
2010
2054
|
return callbackUrl;
|
|
2011
2055
|
});
|
|
2012
2056
|
//#endregion
|
|
2013
|
-
export { PushTargetMismatch as A,
|
|
2057
|
+
export { PushTargetMismatch as A, Credentials as B, DeploymentProvider as C, ConvexAppNotFound as D, CodePushFailed as E, ConvexApiError as F, DEPLOY_KEY_ENV as H, ManagementApi as I, ManagementApiLive as L, installedCli as M, parseDeployOutput as N, ConvexCliNotFound as O, push as P, readLocalDeployment as R, DeploymentIdentityChange as S, ProductionDeploymentNotFound as T, fromConfig as U, CredentialsError as V, fromValues as W, ProjectProvider as _, registerDevelopmentClient as a, AmbiguousDeployment as b, RUN_RECORD_KEY as c, withRunRecord as d, AmbiguousProject as f, ProjectNotFound as g, ProjectDeploymentChange as h, HubClientProvider as i, VariablesOwnedBySomeoneElse as j, EnvironmentNeedsDeployKey as k, RunRecordError as l, Project as m, HubClient as n, STORE_PROJECT_NAME as o, CreatedProjectNotFound as p, HubClientFailed as r, state as s, HUB_PROJECT_NAME as t, runRecord as u, ProjectTeamChange as v, DeploymentResource as w, Deployment as x, AbsoluteRootDir as y, ACCESS_TOKEN_ENV as z };
|
|
2014
2058
|
|
|
2015
|
-
//# sourceMappingURL=HubClient-
|
|
2059
|
+
//# sourceMappingURL=HubClient-X0-FgJ8v.js.map
|