@samebase/alchemy-convex 0.45.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 +71 -67
- package/lib/{IdentityHub-CDG7GXm6.js → IdentityBroker-BqA_2V3_.js} +113 -106
- package/lib/IdentityBroker-BqA_2V3_.js.map +1 -0
- package/lib/{IdentityHub.d.ts → IdentityBroker.d.ts} +35 -32
- package/lib/IdentityBroker.d.ts.map +1 -0
- package/lib/IdentityBroker.js +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/{IdentityHub.ts → IdentityBroker.ts} +197 -178
- package/src/Providers.ts +10 -4
- package/lib/IdentityHub-CDG7GXm6.js.map +0 -1
- package/lib/IdentityHub.d.ts.map +0 -1
- package/lib/IdentityHub.js +0 -1
|
@@ -8,20 +8,22 @@ import * as Provider from "alchemy/Provider";
|
|
|
8
8
|
import { Random } from "alchemy/Random";
|
|
9
9
|
import * as Output from "alchemy/Output";
|
|
10
10
|
import { State } from "alchemy/State";
|
|
11
|
-
//#region src/
|
|
11
|
+
//#region src/IdentityBroker.d.ts
|
|
12
|
+
/** The client ID and the client secret of a deployment without a broker client. */
|
|
13
|
+
export declare const DISABLED = "broker-disabled";
|
|
12
14
|
/**
|
|
13
15
|
* The app's default name: the stack's path below `owner/repo`, or `app` for a stack named after
|
|
14
16
|
* the repository. Undefined for a stack whose name is not `owner/repo` or `owner/repo/<path>`.
|
|
15
17
|
*/
|
|
16
18
|
export declare const defaultApp: (stackName: string) => string | undefined;
|
|
17
19
|
/**
|
|
18
|
-
* An identity
|
|
20
|
+
* An identity broker of @samebase/identity-broker, such as Samebase's public broker:
|
|
19
21
|
* `{ issuer: "https://id.samebase.com" }`.
|
|
20
22
|
*/
|
|
21
|
-
export interface
|
|
23
|
+
export interface BrokerEndpoint {
|
|
22
24
|
/**
|
|
23
|
-
* The
|
|
24
|
-
* a GitHub token whose audience is the issuer, so no other
|
|
25
|
+
* The broker's issuer, such as `https://auth.example.com`. The run asks at `<issuer>/register`,
|
|
26
|
+
* with a GitHub token whose audience is the issuer, so no other broker can use that token.
|
|
25
27
|
*/
|
|
26
28
|
readonly issuer: string;
|
|
27
29
|
}
|
|
@@ -32,18 +34,18 @@ interface CommonProps {
|
|
|
32
34
|
* repository. A changed name registers a new client under the new name.
|
|
33
35
|
*/
|
|
34
36
|
readonly app?: string;
|
|
35
|
-
/** The
|
|
36
|
-
readonly
|
|
37
|
+
/** The broker to register at. A changed broker registers a new client there; the old one stays. */
|
|
38
|
+
readonly broker: BrokerEndpoint;
|
|
37
39
|
/**
|
|
38
|
-
* The connectors the client signs in through, by their names on the
|
|
39
|
-
* `["google", "github"]`: at least one, each of `[a-z0-9-]{1,64}`. The
|
|
40
|
-
* not offer, or does not allow this repository, and the log then names the allowed ones. The
|
|
41
|
-
* is recorded on the client for good: a changed set registers a new client.
|
|
40
|
+
* The connectors the client signs in through, by their names on the broker, such as
|
|
41
|
+
* `["google", "github"]`: at least one, each of `[a-z0-9-]{1,64}`. The broker refuses a name it
|
|
42
|
+
* does not offer, or does not allow this repository, and the log then names the allowed ones. The
|
|
43
|
+
* set is recorded on the client for good: a changed set registers a new client.
|
|
42
44
|
*/
|
|
43
45
|
readonly connectors: readonly string[];
|
|
44
46
|
/**
|
|
45
47
|
* The return addresses of this deployment, one to eight, such as
|
|
46
|
-
* `[`${site.siteUrl}/auth/
|
|
48
|
+
* `[`${site.siteUrl}/auth/broker/callback`]`: each an https URL whose origin serves
|
|
47
49
|
* `/samebase-verification.json` with the numeric GitHub id of this repository,
|
|
48
50
|
* `{ "repository": "123" }`. They can come from a resource that this run creates. A development
|
|
49
51
|
* client can also have http on a loopback host, which needs no file. Every request of the client
|
|
@@ -51,21 +53,22 @@ interface CommonProps {
|
|
|
51
53
|
* client.
|
|
52
54
|
*/
|
|
53
55
|
readonly redirectUris: string[];
|
|
54
|
-
/** Recorded on the
|
|
56
|
+
/** Recorded on the broker's client, such as the commit. The broker records "unknown" without it. */
|
|
55
57
|
readonly softwareVersion?: string;
|
|
56
58
|
/**
|
|
57
|
-
* The run fails unless the
|
|
58
|
-
* does not answer a registration or a renewal, and when it suspended the client.
|
|
59
|
-
* a run gives the off values or keeps the saved client, so the app deploys
|
|
60
|
-
* sign-in is the product. A failed run saves nothing, so the next run asks
|
|
59
|
+
* The run fails unless the broker confirms the client in this run: it fails when the broker
|
|
60
|
+
* refuses or does not answer a registration or a renewal, and when it suspended the client.
|
|
61
|
+
* Without it, such a run gives the off values or keeps the saved client, so the app deploys
|
|
62
|
+
* anyway. Set it where sign-in is the product. A failed run saves nothing, so the next run asks
|
|
63
|
+
* the broker again.
|
|
61
64
|
*/
|
|
62
65
|
readonly required?: boolean;
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
65
68
|
* A production or preview client asks with the GitHub OIDC token of the run. A development client
|
|
66
|
-
* asks with the app's initial access token, which `
|
|
67
|
-
* A client of any type with `key` asks with that key, a key of a
|
|
68
|
-
* `
|
|
69
|
+
* asks with the app's initial access token, which `IdentityBroker.Client.read` gives from stage
|
|
70
|
+
* `prod`. A client of any type with `key` asks with that key, a key of a broker on the stack layer,
|
|
71
|
+
* such as `IdentityBroker.registrationKey` gives.
|
|
69
72
|
*/
|
|
70
73
|
export type ClientProps = (CommonProps & {
|
|
71
74
|
readonly deploymentType: "production" | "preview";
|
|
@@ -80,7 +83,7 @@ export type ClientProps = (CommonProps & {
|
|
|
80
83
|
readonly deploymentType: "production" | "preview" | "development";
|
|
81
84
|
/**
|
|
82
85
|
* The Bearer of `POST /register`. Undefined, as before the stage that makes the key ever
|
|
83
|
-
* ran: the client gets the off values, or the run fails when `required`. The
|
|
86
|
+
* ran: the client gets the off values, or the run fails when `required`. The broker decides
|
|
84
87
|
* whether this key may register a production client.
|
|
85
88
|
*/
|
|
86
89
|
readonly key: Redacted.Redacted<string> | undefined;
|
|
@@ -89,16 +92,16 @@ export type ClientProps = (CommonProps & {
|
|
|
89
92
|
declare const Attributes: Schema.Struct<{
|
|
90
93
|
/** `off`: no client, and the values below are the off values. */
|
|
91
94
|
readonly status: Schema.Literals<readonly ["on", "off", "suspended"]>;
|
|
92
|
-
/** The issuer of the
|
|
95
|
+
/** The issuer of the broker, which the deployment names to sign in. */
|
|
93
96
|
readonly issuer: Schema.String;
|
|
94
97
|
readonly clientId: Schema.String;
|
|
95
98
|
/** Returned only at registration. */
|
|
96
99
|
readonly clientSecret: Schema.Redacted<Schema.String>;
|
|
97
|
-
/** Returned only at registration. It reads and deletes this client on the
|
|
100
|
+
/** Returned only at registration. It reads and deletes this client on the broker, and nothing else. */
|
|
98
101
|
readonly registrationAccessToken: Schema.Redacted<Schema.String>;
|
|
99
102
|
readonly registrationClientUri: Schema.String;
|
|
100
103
|
readonly deploymentType: Schema.Literals<readonly ["production", "preview", "development"]>;
|
|
101
|
-
/** The app's name on the
|
|
104
|
+
/** The app's name on the broker, as sent. Empty for the off values. */
|
|
102
105
|
readonly app: Schema.String;
|
|
103
106
|
/** The return addresses the client serves, sorted, each once. Empty for the off values. */
|
|
104
107
|
readonly redirectUris: Schema.$Array<Schema.String>;
|
|
@@ -114,22 +117,22 @@ declare const Attributes: Schema.Struct<{
|
|
|
114
117
|
}>;
|
|
115
118
|
/**
|
|
116
119
|
* The attributes keep the real values of a suspended client, so that an unblock needs no new client.
|
|
117
|
-
* `
|
|
120
|
+
* `IdentityBroker.Client.variables` gives the values that the app gets.
|
|
118
121
|
*/
|
|
119
122
|
export interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}
|
|
120
123
|
/**
|
|
121
|
-
* A key of a
|
|
122
|
-
* `
|
|
123
|
-
* can make several. In `options.stage`, the stage that deploys the
|
|
124
|
+
* A key of a broker on the stack layer, as a redacted Output, for the broker's secret binding and
|
|
125
|
+
* for `IdentityBroker.Client`'s `key`. `id` is the key's resource id, the author's name for it, so a
|
|
126
|
+
* stack can make several. In `options.stage`, the stage that deploys the broker, the key is an
|
|
124
127
|
* `Alchemy.Random` at the stack's root, made once and kept in state; the stack's providers need
|
|
125
128
|
* Random's provider (`Convex.providers()` and `Cloudflare.providers()` hold one). Every other stage
|
|
126
|
-
* reads that row from the state store, as `
|
|
127
|
-
* key; before the
|
|
129
|
+
* reads that row from the state store, as `IdentityBroker.Client.read` does, so it never creates the
|
|
130
|
+
* key; before the broker's stage ran, there is no row and no key (`undefined`).
|
|
128
131
|
*/
|
|
129
132
|
export declare const registrationKey: (id: string, options: {
|
|
130
133
|
readonly stage: string;
|
|
131
134
|
}) => Effect.Effect<Output.Output<Redacted.Redacted<string> | undefined, any>, never, Stack | Provider.Provider<Random>>;
|
|
132
|
-
export type Client = Resource<"
|
|
135
|
+
export type Client = Resource<"IdentityBroker.Client", ClientProps, ClientAttributes, never, Providers>;
|
|
133
136
|
export declare const Client: import("alchemy").ResourceClassWithMethods<Client, {
|
|
134
137
|
readonly read: (id: string, options: {
|
|
135
138
|
readonly stage: string;
|
|
@@ -156,4 +159,4 @@ export declare const Client: import("alchemy").ResourceClassWithMethods<Client,
|
|
|
156
159
|
export declare const ClientProvider: () => import("effect/Layer").Layer<Provider.Provider<Client>, never, Stack>;
|
|
157
160
|
//#endregion
|
|
158
161
|
export {};
|
|
159
|
-
//# sourceMappingURL=
|
|
162
|
+
//# sourceMappingURL=IdentityBroker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdentityBroker.d.ts","names":[],"sources":["../src/IdentityBroker.ts"],"mappings":";;;;;;;;;;;;qBAgEa;;;;;qBAiBA,aAAc;;;;;iBAYV;;;;;WAKN;;UAGD;;;;;;WAMC;;WAEA,QAAQ;;;;;;;WAOR;;;;;;;;;;WAUA;;WAEA;;;;;;;;WAQA;;;;;;;;YASC,eACP;WACU;WACA;WACA;MAEV;WACU;;WAEA,oBAAoB,SAAS;WAC7B;MAEV;WACU;;;;;;WAMA,KAAK,SAAS;WACd;;cAKT,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BC,yBAAyB,OAAO,OAAO,YAAY;;;;;;;;;;qBAoevD,kBAAmB,YAAY;WAAoB;MAAe,OAAA,OAAA,OAAA,OAAA,SAAA,2CAAA,QAAA,SAAA,SAAA;YAkDnE,SAAS,kCAEnB,aACA,yBAEA;qBAEW,0BAAM,yBAAA;WAjGD,OAAA,YAAM;aAAsB;QAAe,OAAA;;;;;;;;;;;;;;WA2ElC,YAAA,QAAA,WAAM,OAAA;;;;;;qBA6BpB,6CAAc,MAAA,SAAA,SAAA,gBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Client, n as ClientProvider, r as DISABLED, i as defaultApp, a as registrationKey } from "./IdentityBroker-BqA_2V3_.js";
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as Credentials, C as parseDeployOutput, D as ManagementApiLive, E as ManagementApi, M as DEPLOY_KEY_ENV, N as fromConfig, O as readLocalDeployment, P as fromValues, S as VariablesOwnedBySomeoneElse, T as ConvexApiError, _ as CodePushFailed, a as Project, b as EnvironmentNeedsDeployKey, c as ProjectProvider, d as AmbiguousDeployment, f as Deployment, g as ProductionDeploymentNotFound, h as DeploymentResource, i as CreatedProjectNotFound, j as CredentialsError, k as ACCESS_TOKEN_ENV, l as ProjectTeamChange, m as DeploymentProvider, n as state, o as ProjectDeploymentChange, p as DeploymentIdentityChange, r as AmbiguousProject, s as ProjectNotFound, t as STORE_PROJECT_NAME, u as AbsoluteRootDir, v as ConvexAppNotFound, w as push, x as PushTargetMismatch, y as ConvexCliNotFound } from "./State-Bp7iSx8T.js";
|
|
2
|
-
import { n as ClientProvider, t as Client } from "./
|
|
2
|
+
import { n as ClientProvider, t as Client } from "./IdentityBroker-BqA_2V3_.js";
|
|
3
3
|
import { toPath } from "alchemy/FQN";
|
|
4
4
|
import { Stack } from "alchemy/Stack";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["IdentityHub.Client","IdentityHub.ClientProvider"],"sources":["../src/Component.ts","../src/LocalDeployment.ts","../src/Providers.ts"],"sourcesContent":["import { toPath } from \"alchemy/FQN\";\nimport type { NamespaceNode } from \"alchemy/Namespace\";\nimport { Stack } from \"alchemy/Stack\";\nimport * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\nimport type { Deployment } from \"./Deployment.ts\";\n\n/** A component's resources occupy this namespace in the deployment's Alchemy stack and stage. */\nexport interface ComponentBinding {\n readonly type: \"component\";\n readonly path: string;\n readonly namespace: readonly string[];\n}\n\n/**\n * Associate a native namespace with an installed component. `component` is the\n * installed name from the app's `convex.config.ts`; a nested install joins the\n * names with slashes, such as `\"workspace/mail\"`. An undefined namespace\n * associates the stack root. This records display metadata; it does not install\n * the component, set its environment, or change removal policies.\n */\nexport const bindComponent = (options: {\n deployment: Deployment;\n component: string;\n namespace: NamespaceNode | undefined;\n}) =>\n Effect.gen(function* () {\n if (options.component === \"\") {\n return yield* Effect.die(new Error(\"The component name is empty.\"));\n }\n const namespace = toPath(options.namespace);\n const sid = `convex.component:${JSON.stringify(namespace)}`;\n const stack = yield* Stack;\n const previous = stack.bindings[options.deployment.FQN]?.find((binding) => binding.sid === sid);\n // Alchemy keeps the last binding with a given sid. Reject conflicting owners before that happens.\n if (previous !== undefined) {\n const existing = Schema.decodeUnknownSync(Schema.Struct({ path: Schema.String }))(\n previous.data,\n );\n if (existing.path !== options.component) {\n return yield* Effect.die(\n new Error(\n `Alchemy namespace ${JSON.stringify(namespace)} is already bound to ${existing.path}.`,\n ),\n );\n }\n return;\n }\n yield* options.deployment.bind(sid, {\n type: \"component\",\n path: options.component,\n namespace,\n });\n });\n","// Convex.LocalDeployment: the logged-in local deployment of one folder, which\n// `npx convex deployment create <team>:<project>:local --select` makes and `npx convex dev` runs on\n// this machine. Each folder, such as each git worktree, has its own, with its own data.\n//\n// The resource writes its `env` and nothing else. The running `convex dev` owns the backend and\n// pushes the functions, so the development stage runs after `convex dev` has started, and the\n// first push of a new local deployment takes the variables that the project's default variables\n// for development gave it. The resource reads the deployment from\n// `.convex/local/default/config.json`, where the Convex CLI keeps its name, ports, and admin key,\n// and writes with that admin key through the same call as for a cloud deployment.\n//\n// A destroy changes nothing: the folder's deployment and its variables stay with the folder.\nimport { Resource } from \"alchemy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Provider from \"alchemy/Provider\";\nimport * as Effect from \"effect/Effect\";\nimport * as ChildProcessSpawner from \"effect/process/ChildProcessSpawner\";\nimport * as Schema from \"effect/Schema\";\nimport { readLocalDeployment } from \"./ManagementApi.ts\";\nimport type { Providers } from \"./Providers.ts\";\nimport { type EnvValue, push } from \"./Push.ts\";\n\n/** The folder has no logged-in local deployment. */\nexport class LocalDeploymentNotFound extends Schema.TaggedError<LocalDeploymentNotFound>()(\n \"LocalDeploymentNotFound\",\n { rootDir: Schema.String },\n) {\n override get message() {\n return `Convex.LocalDeployment: ${this.rootDir} has no logged-in local deployment. Run \\`npx convex deployment create <team>:<project>:local --select\\` there, then \\`npx convex dev\\`.`;\n }\n}\n\n/**\n * The folder's logged-in local deployment, read when the stack's program runs, so that a client\n * can take its `siteUrl`. Fails with `LocalDeploymentNotFound` when the folder has none.\n */\nconst of = (rootDir = \".\") => {\n const info = readLocalDeployment(rootDir);\n if (info === undefined) throw new LocalDeploymentNotFound({ rootDir });\n return { name: info.name, url: info.url, siteUrl: info.siteUrl };\n};\n\nexport interface LocalDeploymentProps {\n /** The folder of the Convex app, where `.convex/local/default` is. The working directory without it. */\n readonly rootDir?: string;\n /** The variables of the deployment. A name that leaves `env` is removed. */\n readonly env: Readonly<Record<string, EnvValue>>;\n}\n\nexport interface LocalDeploymentAttributes {\n readonly name: string;\n readonly url: string;\n readonly siteUrl: string;\n /** The names that this resource set, so a name that leaves `env` is removed. */\n readonly envNames: readonly string[];\n}\n\nexport type LocalDeployment = Resource<\n \"Convex.LocalDeployment\",\n LocalDeploymentProps,\n LocalDeploymentAttributes,\n never,\n Providers\n>;\nexport const LocalDeployment = Resource<LocalDeployment>(\"Convex.LocalDeployment\")({ of });\n\nexport const LocalDeploymentProvider = () =>\n Provider.effect(\n LocalDeployment,\n Effect.gen(function* () {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n return {\n // Always an update: the variables are read and only changed values are written.\n diff: ({ news }) =>\n Effect.succeed(isResolved(news) ? ({ action: \"update\" } as const) : undefined),\n\n read: ({ output }) => Effect.succeed(output),\n\n reconcile: Effect.fn(function* ({ news, output }) {\n const rootDir = news.rootDir ?? \".\";\n const info = readLocalDeployment(rootDir);\n if (info === undefined) return yield* new LocalDeploymentNotFound({ rootDir });\n // Without `source`, a push only sets the variables and removes the names that left `env`.\n yield* push(spawner, info.adminKey, {\n deployment: info.name,\n url: info.url,\n rootDir,\n source: undefined,\n env: news.env,\n previousEnvNames: output?.name === info.name ? output.envNames : [],\n adopt: true,\n previewName: undefined,\n });\n return {\n name: info.name,\n url: info.url,\n siteUrl: info.siteUrl,\n envNames: Object.keys(news.env).sort(),\n };\n }),\n\n delete: () => Effect.void,\n };\n }),\n );\n","// The provider collection users merge into a stack:\n// providers: Layer.mergeAll(Cloudflare.providers(), Convex.providers())\nimport * as Provider from \"alchemy/Provider\";\nimport { Random, RandomProvider } from \"alchemy/Random\";\nimport * as Layer from \"effect/Layer\";\nimport { type Credentials, fromConfig } from \"./Credentials.ts\";\nimport { DeploymentProvider, DeploymentResource } from \"./Deployment.ts\";\nimport * as IdentityHub from \"./IdentityHub.ts\";\nimport { LocalDeployment, LocalDeploymentProvider } from \"./LocalDeployment.ts\";\nimport { ManagementApiLive } from \"./ManagementApi.ts\";\nimport { Project, ProjectProvider } from \"./Project.ts\";\n\nexport class Providers extends Provider.ProviderCollection<Providers>()(\"Convex\") {}\n\n/**\n * The Convex resource providers. Pass a credentials layer to override the\n * default lookup (`CONVEX_ACCESS_TOKEN`, then the Convex CLI login, and\n * `CONVEX_DEPLOY_KEY`).\n */\nexport const providers = (credentials: Layer.Layer<Credentials> = fromConfig()) =>\n Layer.effect(\n Providers,\n // Random's provider serves `IdentityHub.registrationKey` in a stack with no other collection\n // that holds one; with Cloudflare's too, the first found serves it, and both are the same.\n Provider.collection([Project, DeploymentResource, LocalDeployment, IdentityHub.Client, Random]),\n ).pipe(\n Layer.provide(\n Layer.mergeAll(\n ProjectProvider(),\n DeploymentProvider(),\n LocalDeploymentProvider(),\n IdentityHub.ClientProvider(),\n RandomProvider(),\n ),\n ),\n Layer.provide(ManagementApiLive()),\n Layer.provide(credentials),\n Layer.orDie,\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,iBAAiB,YAK5B,OAAO,IAAI,aAAa;CACtB,IAAI,QAAQ,cAAc,IACxB,OAAO,OAAO,OAAO,oBAAI,IAAI,MAAM,8BAA8B,CAAC;CAEpE,MAAM,YAAY,OAAO,QAAQ,SAAS;CAC1C,MAAM,MAAM,oBAAoB,KAAK,UAAU,SAAS;CAExD,MAAM,YAAW,OADI,MAAA,CACE,SAAS,QAAQ,WAAW,IAAI,EAAE,MAAM,YAAY,QAAQ,QAAQ,GAAG;CAE9F,IAAI,aAAa,KAAA,GAAW;EAC1B,MAAM,WAAW,OAAO,kBAAkB,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CAAC,CAAC,CAC/E,SAAS,IACX;EACA,IAAI,SAAS,SAAS,QAAQ,WAC5B,OAAO,OAAO,OAAO,oBACnB,IAAI,MACF,qBAAqB,KAAK,UAAU,SAAS,EAAE,uBAAuB,SAAS,KAAK,EACtF,CACF;EAEF;CACF;CACA,OAAO,QAAQ,WAAW,KAAK,KAAK;EAClC,MAAM;EACN,MAAM,QAAQ;EACd;CACF,CAAC;AACH,CAAC;;;;AC9BH,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CACxF,2BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC;CACA,IAAa,UAAU;EAC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AAa,cAAwC,WAAW,MAC3E,MAAM,OACJ,WAGA,SAAS,WAAW;CAAC;CAAS;CAAoB;CAAiBA;CAAoB;AAAM,CAAC,CAChG,CAAC,CAAC,KACA,MAAM,QACJ,MAAM,SACJ,gBAAgB,GAChB,mBAAmB,GACnB,wBAAwB,GACxBC,eAA2B,GAC3B,eAAe,CACjB,CACF,GACA,MAAM,QAAQ,kBAAkB,CAAC,GACjC,MAAM,QAAQ,WAAW,GACzB,MAAM,KACR"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["IdentityBroker.Client","IdentityBroker.ClientProvider"],"sources":["../src/Component.ts","../src/LocalDeployment.ts","../src/Providers.ts"],"sourcesContent":["import { toPath } from \"alchemy/FQN\";\nimport type { NamespaceNode } from \"alchemy/Namespace\";\nimport { Stack } from \"alchemy/Stack\";\nimport * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\nimport type { Deployment } from \"./Deployment.ts\";\n\n/** A component's resources occupy this namespace in the deployment's Alchemy stack and stage. */\nexport interface ComponentBinding {\n readonly type: \"component\";\n readonly path: string;\n readonly namespace: readonly string[];\n}\n\n/**\n * Associate a native namespace with an installed component. `component` is the\n * installed name from the app's `convex.config.ts`; a nested install joins the\n * names with slashes, such as `\"workspace/mail\"`. An undefined namespace\n * associates the stack root. This records display metadata; it does not install\n * the component, set its environment, or change removal policies.\n */\nexport const bindComponent = (options: {\n deployment: Deployment;\n component: string;\n namespace: NamespaceNode | undefined;\n}) =>\n Effect.gen(function* () {\n if (options.component === \"\") {\n return yield* Effect.die(new Error(\"The component name is empty.\"));\n }\n const namespace = toPath(options.namespace);\n const sid = `convex.component:${JSON.stringify(namespace)}`;\n const stack = yield* Stack;\n const previous = stack.bindings[options.deployment.FQN]?.find((binding) => binding.sid === sid);\n // Alchemy keeps the last binding with a given sid. Reject conflicting owners before that happens.\n if (previous !== undefined) {\n const existing = Schema.decodeUnknownSync(Schema.Struct({ path: Schema.String }))(\n previous.data,\n );\n if (existing.path !== options.component) {\n return yield* Effect.die(\n new Error(\n `Alchemy namespace ${JSON.stringify(namespace)} is already bound to ${existing.path}.`,\n ),\n );\n }\n return;\n }\n yield* options.deployment.bind(sid, {\n type: \"component\",\n path: options.component,\n namespace,\n });\n });\n","// Convex.LocalDeployment: the logged-in local deployment of one folder, which\n// `npx convex deployment create <team>:<project>:local --select` makes and `npx convex dev` runs on\n// this machine. Each folder, such as each git worktree, has its own, with its own data.\n//\n// The resource writes its `env` and nothing else. The running `convex dev` owns the backend and\n// pushes the functions, so the development stage runs after `convex dev` has started, and the\n// first push of a new local deployment takes the variables that the project's default variables\n// for development gave it. The resource reads the deployment from\n// `.convex/local/default/config.json`, where the Convex CLI keeps its name, ports, and admin key,\n// and writes with that admin key through the same call as for a cloud deployment.\n//\n// A destroy changes nothing: the folder's deployment and its variables stay with the folder.\nimport { Resource } from \"alchemy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Provider from \"alchemy/Provider\";\nimport * as Effect from \"effect/Effect\";\nimport * as ChildProcessSpawner from \"effect/process/ChildProcessSpawner\";\nimport * as Schema from \"effect/Schema\";\nimport { readLocalDeployment } from \"./ManagementApi.ts\";\nimport type { Providers } from \"./Providers.ts\";\nimport { type EnvValue, push } from \"./Push.ts\";\n\n/** The folder has no logged-in local deployment. */\nexport class LocalDeploymentNotFound extends Schema.TaggedError<LocalDeploymentNotFound>()(\n \"LocalDeploymentNotFound\",\n { rootDir: Schema.String },\n) {\n override get message() {\n return `Convex.LocalDeployment: ${this.rootDir} has no logged-in local deployment. Run \\`npx convex deployment create <team>:<project>:local --select\\` there, then \\`npx convex dev\\`.`;\n }\n}\n\n/**\n * The folder's logged-in local deployment, read when the stack's program runs, so that a client\n * can take its `siteUrl`. Fails with `LocalDeploymentNotFound` when the folder has none.\n */\nconst of = (rootDir = \".\") => {\n const info = readLocalDeployment(rootDir);\n if (info === undefined) throw new LocalDeploymentNotFound({ rootDir });\n return { name: info.name, url: info.url, siteUrl: info.siteUrl };\n};\n\nexport interface LocalDeploymentProps {\n /** The folder of the Convex app, where `.convex/local/default` is. The working directory without it. */\n readonly rootDir?: string;\n /** The variables of the deployment. A name that leaves `env` is removed. */\n readonly env: Readonly<Record<string, EnvValue>>;\n}\n\nexport interface LocalDeploymentAttributes {\n readonly name: string;\n readonly url: string;\n readonly siteUrl: string;\n /** The names that this resource set, so a name that leaves `env` is removed. */\n readonly envNames: readonly string[];\n}\n\nexport type LocalDeployment = Resource<\n \"Convex.LocalDeployment\",\n LocalDeploymentProps,\n LocalDeploymentAttributes,\n never,\n Providers\n>;\nexport const LocalDeployment = Resource<LocalDeployment>(\"Convex.LocalDeployment\")({ of });\n\nexport const LocalDeploymentProvider = () =>\n Provider.effect(\n LocalDeployment,\n Effect.gen(function* () {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;\n return {\n // Always an update: the variables are read and only changed values are written.\n diff: ({ news }) =>\n Effect.succeed(isResolved(news) ? ({ action: \"update\" } as const) : undefined),\n\n read: ({ output }) => Effect.succeed(output),\n\n reconcile: Effect.fn(function* ({ news, output }) {\n const rootDir = news.rootDir ?? \".\";\n const info = readLocalDeployment(rootDir);\n if (info === undefined) return yield* new LocalDeploymentNotFound({ rootDir });\n // Without `source`, a push only sets the variables and removes the names that left `env`.\n yield* push(spawner, info.adminKey, {\n deployment: info.name,\n url: info.url,\n rootDir,\n source: undefined,\n env: news.env,\n previousEnvNames: output?.name === info.name ? output.envNames : [],\n adopt: true,\n previewName: undefined,\n });\n return {\n name: info.name,\n url: info.url,\n siteUrl: info.siteUrl,\n envNames: Object.keys(news.env).sort(),\n };\n }),\n\n delete: () => Effect.void,\n };\n }),\n );\n","// The provider collection users merge into a stack:\n// providers: Layer.mergeAll(Cloudflare.providers(), Convex.providers())\nimport * as Provider from \"alchemy/Provider\";\nimport { Random, RandomProvider } from \"alchemy/Random\";\nimport * as Layer from \"effect/Layer\";\nimport { type Credentials, fromConfig } from \"./Credentials.ts\";\nimport { DeploymentProvider, DeploymentResource } from \"./Deployment.ts\";\nimport * as IdentityBroker from \"./IdentityBroker.ts\";\nimport { LocalDeployment, LocalDeploymentProvider } from \"./LocalDeployment.ts\";\nimport { ManagementApiLive } from \"./ManagementApi.ts\";\nimport { Project, ProjectProvider } from \"./Project.ts\";\n\nexport class Providers extends Provider.ProviderCollection<Providers>()(\"Convex\") {}\n\n/**\n * The Convex resource providers. Pass a credentials layer to override the\n * default lookup (`CONVEX_ACCESS_TOKEN`, then the Convex CLI login, and\n * `CONVEX_DEPLOY_KEY`).\n */\nexport const providers = (credentials: Layer.Layer<Credentials> = fromConfig()) =>\n Layer.effect(\n Providers,\n // Random's provider serves `IdentityBroker.registrationKey` in a stack with no other collection\n // that holds one; with Cloudflare's too, the first found serves it, and both are the same.\n Provider.collection([\n Project,\n DeploymentResource,\n LocalDeployment,\n IdentityBroker.Client,\n Random,\n ]),\n ).pipe(\n Layer.provide(\n Layer.mergeAll(\n ProjectProvider(),\n DeploymentProvider(),\n LocalDeploymentProvider(),\n IdentityBroker.ClientProvider(),\n RandomProvider(),\n ),\n ),\n Layer.provide(ManagementApiLive()),\n Layer.provide(credentials),\n Layer.orDie,\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,iBAAiB,YAK5B,OAAO,IAAI,aAAa;CACtB,IAAI,QAAQ,cAAc,IACxB,OAAO,OAAO,OAAO,oBAAI,IAAI,MAAM,8BAA8B,CAAC;CAEpE,MAAM,YAAY,OAAO,QAAQ,SAAS;CAC1C,MAAM,MAAM,oBAAoB,KAAK,UAAU,SAAS;CAExD,MAAM,YAAW,OADI,MAAA,CACE,SAAS,QAAQ,WAAW,IAAI,EAAE,MAAM,YAAY,QAAQ,QAAQ,GAAG;CAE9F,IAAI,aAAa,KAAA,GAAW;EAC1B,MAAM,WAAW,OAAO,kBAAkB,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,CAAC,CAAC,CAC/E,SAAS,IACX;EACA,IAAI,SAAS,SAAS,QAAQ,WAC5B,OAAO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,WAAW,CAAC;IAClE,OAAO;IACP,aAAa,KAAA;GACf,CAAC;GACD,OAAO;IACL,MAAM,KAAK;IACX,KAAK,KAAK;IACV,SAAS,KAAK;IACd,UAAU,OAAO,KAAK,KAAK,GAAG,CAAC,CAAC,KAAK;GACvC;EACF,CAAC;EAED,cAAc,OAAO;CACvB;AACF,CAAC,CACH;;;AC5FF,IAAa,YAAb,cAA+B,SAAS,mBAA8B,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;;;;;;AAOnF,MAAa,aAAa,cAAwC,WAAW,MAC3E,MAAM,OACJ,WAGA,SAAS,WAAW;CAClB;CACA;CACA;CACAA;CACA;AACF,CAAC,CACH,CAAC,CAAC,KACA,MAAM,QACJ,MAAM,SACJ,gBAAgB,GAChB,mBAAmB,GACnB,wBAAwB,GACxBC,eAA8B,GAC9B,eAAe,CACjB,CACF,GACA,MAAM,QAAQ,kBAAkB,CAAC,GACjC,MAAM,QAAQ,WAAW,GACzB,MAAM,KACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samebase/alchemy-convex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "The Convex plane for Alchemy v2: projects, deployments, environment variables, and the push of the functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alchemy",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"types": "./lib/index.d.ts",
|
|
37
37
|
"import": "./lib/index.js"
|
|
38
38
|
},
|
|
39
|
-
"./identity-
|
|
40
|
-
"types": "./lib/
|
|
41
|
-
"import": "./lib/
|
|
39
|
+
"./identity-broker": {
|
|
40
|
+
"types": "./lib/IdentityBroker.d.ts",
|
|
41
|
+
"import": "./lib/IdentityBroker.js"
|
|
42
42
|
},
|
|
43
43
|
"./sealed-secret": {
|
|
44
44
|
"types": "./lib/sealedSecret.d.ts",
|