@samebase/alchemy-convex 0.36.0 → 0.38.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 +33 -27
- package/lib/IdentityHub-XSCxmYoN.js +322 -0
- package/lib/IdentityHub-XSCxmYoN.js.map +1 -0
- package/lib/IdentityHub.d.ts +117 -0
- package/lib/IdentityHub.d.ts.map +1 -0
- package/lib/IdentityHub.js +1 -0
- package/lib/Providers-Bq-4JsdP.d.ts +58 -0
- package/lib/Providers-Bq-4JsdP.d.ts.map +1 -0
- package/lib/{State-DVC61yrQ.js → State-CfIbfbVv.js} +20 -6
- package/lib/State-CfIbfbVv.js.map +1 -0
- package/lib/cli.js +3 -2
- package/lib/cli.js.map +1 -1
- package/lib/index.d.ts +2 -163
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -312
- package/lib/index.js.map +1 -1
- package/package.json +5 -1
- package/src/Deployment.ts +2 -1
- package/src/{SharedHubClient.ts → IdentityHub.ts} +66 -70
- package/src/Providers.ts +3 -3
- package/src/Push.ts +34 -7
- package/src/StackComment.ts +4 -1
- package/src/index.ts +0 -6
- package/lib/State-DVC61yrQ.js.map +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { t as Providers } from "./Providers-Bq-4JsdP.js";
|
|
2
|
+
import { Stack } from "alchemy/Stack";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
import { Resource } from "alchemy";
|
|
6
|
+
import * as Provider from "alchemy/Provider";
|
|
7
|
+
import * as Output from "alchemy/Output";
|
|
8
|
+
import { State } from "alchemy/State";
|
|
9
|
+
//#region src/IdentityHub.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* An identity hub of @samebase/identity-broker, such as Samebase's public hub:
|
|
12
|
+
* `{ issuer: "https://id.samebase.com" }`.
|
|
13
|
+
*/
|
|
14
|
+
export interface Hub {
|
|
15
|
+
/**
|
|
16
|
+
* The hub's issuer, such as `https://auth.example.com`. The run asks at `<issuer>/hub-clients`,
|
|
17
|
+
* with a GitHub token whose audience is the issuer, so no other hub can use that token.
|
|
18
|
+
*/
|
|
19
|
+
readonly issuer: string;
|
|
20
|
+
}
|
|
21
|
+
interface CommonProps {
|
|
22
|
+
/** The stable name of the app, set once in the stack. */
|
|
23
|
+
readonly app: string;
|
|
24
|
+
/** The hub to register at. A changed hub registers a new client there; the old one stays. */
|
|
25
|
+
readonly hub: Hub;
|
|
26
|
+
/**
|
|
27
|
+
* The connectors the client signs in through, by their names on the hub, such as
|
|
28
|
+
* `["google", "github"]`: at least one, each of `[a-z0-9-]{1,64}`. The hub refuses a name it does
|
|
29
|
+
* not offer, or does not allow this repository, and the log then names the allowed ones. The set
|
|
30
|
+
* is recorded on the client for good: a changed set registers a new client.
|
|
31
|
+
*/
|
|
32
|
+
readonly connectors: readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* The return address of the hub's sign-ins, such as `${site.siteUrl}/auth/hub/callback`: an https
|
|
35
|
+
* URL whose origin serves `/samebase-verification.json` with the numeric GitHub id of this
|
|
36
|
+
* repository, `{ "repository": "123" }`. It can come from a resource that this run creates. A
|
|
37
|
+
* development client can also have http on a loopback host, which needs no file.
|
|
38
|
+
*/
|
|
39
|
+
readonly redirectUri: string;
|
|
40
|
+
/** Recorded on the hub's client, such as the commit. The hub records "unknown" without it. */
|
|
41
|
+
readonly softwareVersion?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The run fails unless the hub confirms the client in this run: it fails when the hub refuses or
|
|
44
|
+
* does not answer a registration or a renewal, and when it suspended the client. Without it, such
|
|
45
|
+
* a run gives the off values or keeps the saved client, so the app deploys anyway. Set it where
|
|
46
|
+
* sign-in is the product. A failed run saves nothing, so the next run asks the hub again.
|
|
47
|
+
*/
|
|
48
|
+
readonly required?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A production or preview client asks with the GitHub OIDC token of the run. A development client
|
|
52
|
+
* asks with the app's initial access token, which `IdentityHub.Client.read` gives from stage `prod`.
|
|
53
|
+
*/
|
|
54
|
+
export type ClientProps = (CommonProps & {
|
|
55
|
+
readonly deploymentType: "production" | "preview";
|
|
56
|
+
readonly initialAccessToken?: never;
|
|
57
|
+
}) | (CommonProps & {
|
|
58
|
+
readonly deploymentType: "development";
|
|
59
|
+
/** Empty before the first production registration: the client gets the off values. */
|
|
60
|
+
readonly initialAccessToken: Redacted.Redacted<string>;
|
|
61
|
+
});
|
|
62
|
+
declare const Attributes: Schema.Struct<{
|
|
63
|
+
/** `off`: no client, and the values below are the off values. */
|
|
64
|
+
readonly status: Schema.Literals<readonly ["on", "off", "suspended"]>;
|
|
65
|
+
/** The issuer of the hub, which the deployment names to sign in. */
|
|
66
|
+
readonly issuer: Schema.String;
|
|
67
|
+
readonly clientId: Schema.String;
|
|
68
|
+
/** Returned only at registration. */
|
|
69
|
+
readonly clientSecret: Schema.Redacted<Schema.String>;
|
|
70
|
+
/** Returned only at registration. It reads and deletes this client on the hub, and nothing else. */
|
|
71
|
+
readonly registrationAccessToken: Schema.Redacted<Schema.String>;
|
|
72
|
+
readonly registrationClientUri: Schema.String;
|
|
73
|
+
readonly deploymentType: Schema.Literals<readonly ["production", "preview", "development"]>;
|
|
74
|
+
/** The return address that the client serves. Empty for the off values. */
|
|
75
|
+
readonly redirectUri: Schema.String;
|
|
76
|
+
/** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */
|
|
77
|
+
readonly connectors: Schema.$Array<Schema.String>;
|
|
78
|
+
/**
|
|
79
|
+
* Returned only at a production registration (RFC 7591 section 1.2). It registers development
|
|
80
|
+
* clients of this app. Empty for a preview, for a development client, and for the off values.
|
|
81
|
+
*/
|
|
82
|
+
readonly initialAccessToken: Schema.Redacted<Schema.String>;
|
|
83
|
+
/** The numeric GitHub id of the repository, with the initial access token. Empty without it. */
|
|
84
|
+
readonly repository: Schema.String;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* The attributes keep the real values of a suspended client, so that an unblock needs no new client.
|
|
88
|
+
* `IdentityHub.Client.variables` gives the values that the app gets.
|
|
89
|
+
*/
|
|
90
|
+
export interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}
|
|
91
|
+
export type Client = Resource<"IdentityHub.Client", ClientProps, ClientAttributes, never, Providers>;
|
|
92
|
+
export declare const Client: import("alchemy").ResourceClassWithMethods<Client, {
|
|
93
|
+
readonly read: (id: string, options: {
|
|
94
|
+
readonly stage: string;
|
|
95
|
+
}) => Output.ObjectExpr<{
|
|
96
|
+
readonly status: "on" | "off" | "suspended";
|
|
97
|
+
readonly issuer: string;
|
|
98
|
+
readonly clientId: string;
|
|
99
|
+
readonly clientSecret: Redacted.Redacted<string>;
|
|
100
|
+
readonly registrationAccessToken: Redacted.Redacted<string>;
|
|
101
|
+
readonly registrationClientUri: string;
|
|
102
|
+
readonly deploymentType: "production" | "preview" | "development";
|
|
103
|
+
readonly redirectUri: string;
|
|
104
|
+
readonly connectors: readonly string[];
|
|
105
|
+
readonly initialAccessToken: Redacted.Redacted<string>;
|
|
106
|
+
readonly repository: string;
|
|
107
|
+
}, State | Stack>;
|
|
108
|
+
readonly variables: (client: Client) => Output.ObjectExpr<{
|
|
109
|
+
issuer: string;
|
|
110
|
+
clientId: string;
|
|
111
|
+
clientSecret: Redacted.Redacted<string>;
|
|
112
|
+
}, never>;
|
|
113
|
+
}>;
|
|
114
|
+
export declare const ClientProvider: () => import("effect/Layer").Layer<Provider.Provider<Client>, never, never>;
|
|
115
|
+
//#endregion
|
|
116
|
+
export {};
|
|
117
|
+
//# sourceMappingURL=IdentityHub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdentityHub.d.ts","names":[],"sources":["../src/IdentityHub.ts"],"mappings":";;;;;;;;;;;;;iBA2DiB;;;;;WAKN;;UAGD;;WAEC;;WAEA,KAAK;;;;;;;WAOL;;;;;;;WAOA;;WAEA;;;;;;;WAOA;;;;;;YAOC,eACP;WACU;WACA;MAEV;WACU;;WAEA,oBAAoB,SAAS;;cAKtC,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6BC,yBAAyB,OAAO,OAAO,YAAY;YAsXxD,SAAS,+BAEnB,aACA,yBAEA;qBAEW,0BAAM,yBAAA;WArDD,OAAA,YAAM;aAAsB;QAAe,OAAA;;;;;;;;;;;;;WA+BlC,YAAA,QAAA,WAAM,OAAA;;;;;;qBA2BpB,6CAAc,MAAA,SAAA,SAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Client, n as ClientProvider } from "./IdentityHub-XSCxmYoN.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
import * as Provider from "alchemy/Provider";
|
|
7
|
+
//#region src/Credentials.d.ts
|
|
8
|
+
interface ResolvedCredentials {
|
|
9
|
+
/** Bearer token accepted by https://api.convex.dev/v1: a team access token, an OAuth token, or the Convex CLI login. */
|
|
10
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
11
|
+
/** Where the token came from, for error messages only. */
|
|
12
|
+
readonly source: "env" | "explicit" | "convex-cli-login";
|
|
13
|
+
}
|
|
14
|
+
interface CredentialsService {
|
|
15
|
+
/** The Management API token. Dies when there is none. */
|
|
16
|
+
readonly accessToken: Effect.Effect<ResolvedCredentials>;
|
|
17
|
+
/** True when there is a Management API token. */
|
|
18
|
+
readonly hasAccessToken: Effect.Effect<boolean>;
|
|
19
|
+
/** A deploy key or a preview deploy key, or undefined. */
|
|
20
|
+
readonly deployKey: Effect.Effect<Redacted.Redacted<string> | undefined>;
|
|
21
|
+
}
|
|
22
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "@samebase/alchemy-convex/Credentials", CredentialsService>;
|
|
23
|
+
declare class Credentials extends Credentials_base {}
|
|
24
|
+
/** Environment variable for the access token, read by {@link fromConfig}. */
|
|
25
|
+
declare const ACCESS_TOKEN_ENV = "CONVEX_ACCESS_TOKEN";
|
|
26
|
+
/** Environment variable for the deploy key, read by {@link fromConfig}. The Convex CLI reads the same name. */
|
|
27
|
+
declare const DEPLOY_KEY_ENV = "CONVEX_DEPLOY_KEY";
|
|
28
|
+
declare const CredentialsError_base: Schema.Class<CredentialsError, Schema.TaggedStruct<"CredentialsError", {
|
|
29
|
+
readonly reason: Schema.String;
|
|
30
|
+
}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
declare class CredentialsError extends CredentialsError_base {}
|
|
32
|
+
/**
|
|
33
|
+
* Default resolution through the stack ConfigProvider (process env, `.env`,
|
|
34
|
+
* stack secrets): `CONVEX_ACCESS_TOKEN`, then the Convex CLI login on this
|
|
35
|
+
* machine, for the access token; `CONVEX_DEPLOY_KEY` for the deploy key. A
|
|
36
|
+
* developer who ran `npx convex login` needs nothing. CI sets only the
|
|
37
|
+
* deploy key when the stack pushes to deployments that exist, and the access
|
|
38
|
+
* token when the stack also creates projects or deployments.
|
|
39
|
+
*/
|
|
40
|
+
declare const fromConfig: () => Layer.Layer<Credentials>;
|
|
41
|
+
/** Explicit values, for tests or callers that already hold them. */
|
|
42
|
+
declare const fromValues: (values: {
|
|
43
|
+
readonly accessToken?: Redacted.Redacted<string>;
|
|
44
|
+
readonly deployKey?: Redacted.Redacted<string>;
|
|
45
|
+
}) => Layer.Layer<Credentials>;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/Providers.d.ts
|
|
48
|
+
declare const Providers_base: Provider.ProviderCollection<Providers, "Convex">;
|
|
49
|
+
declare class Providers extends Providers_base {}
|
|
50
|
+
/**
|
|
51
|
+
* The Convex resource providers. Pass a credentials layer to override the
|
|
52
|
+
* default lookup (`CONVEX_ACCESS_TOKEN`, then the Convex CLI login, and
|
|
53
|
+
* `CONVEX_DEPLOY_KEY`).
|
|
54
|
+
*/
|
|
55
|
+
declare const providers: (credentials?: Layer.Layer<Credentials>) => Layer.Layer<Providers, never, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | import("effect/FileSystem").FileSystem | import("effect/Path").Path>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CredentialsError as a, fromValues as c, Credentials as i, providers as n, DEPLOY_KEY_ENV as o, ACCESS_TOKEN_ENV as r, fromConfig as s, Providers as t };
|
|
58
|
+
//# sourceMappingURL=Providers-Bq-4JsdP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Providers-Bq-4JsdP.d.ts","names":[],"sources":["../src/Credentials.ts","../src/Providers.ts"],"mappings":";;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;cAGhC,oBAAoB;;cAKpB;;cAGA;;;;cAOA,yBAAyB;;;;;;;;;cAiCzB,kBAAiB,MAAM,MAAM;;cA0B7B,aAAc;WAChB,cAAc,SAAS;WACvB,YAAY,SAAS;MAC5B,MAAM,MAAM;;;;cC/GH,kBAAkB;;;;;;cAOlB,YAAa,cAAa,MAAM,MAAM,iBAA2B,MAAA,MAAA,+DAAA,kDAAA,mCAAA"}
|
|
@@ -569,8 +569,10 @@ const checkSource = (rootDir, input) => Effect.gen(function* () {
|
|
|
569
569
|
/**
|
|
570
570
|
* Sets the `env` variables and pushes the functions of `source` to one
|
|
571
571
|
* deployment with `key`: a deploy key of the deployment, or a preview deploy
|
|
572
|
-
* key of its project with `previewName`.
|
|
573
|
-
*
|
|
572
|
+
* key of its project with `previewName`. A name of `previousEnvNames` that
|
|
573
|
+
* left `env` is removed after a successful push, or, without `source`, in the
|
|
574
|
+
* same write as the new values. Returns the URL that the CLI printed, or
|
|
575
|
+
* undefined without `source`.
|
|
574
576
|
*/
|
|
575
577
|
const push = (spawner, key, options) => Effect.gen(function* () {
|
|
576
578
|
const source = options.source === void 0 ? void 0 : sourceOf(options.source);
|
|
@@ -579,7 +581,8 @@ const push = (spawner, key, options) => Effect.gen(function* () {
|
|
|
579
581
|
const program = resolved?.program;
|
|
580
582
|
const env = Object.entries(options.env).sort(([a], [b]) => a < b ? -1 : 1);
|
|
581
583
|
const removed = options.previousEnvNames.filter((name) => !Object.hasOwn(options.env, name));
|
|
582
|
-
const
|
|
584
|
+
const removedBeforePush = source === void 0 ? removed : [];
|
|
585
|
+
const written = env.length === 0 && removedBeforePush.length === 0 ? {
|
|
583
586
|
current: {},
|
|
584
587
|
changes: []
|
|
585
588
|
} : yield* retryIdempotentWrite(Effect.gen(function* () {
|
|
@@ -594,7 +597,7 @@ const push = (spawner, key, options) => Effect.gen(function* () {
|
|
|
594
597
|
const changes = [...env.filter(([name, value]) => current[name] !== valueOf$1(value)).map(([name, value]) => ({
|
|
595
598
|
name,
|
|
596
599
|
value: valueOf$1(value)
|
|
597
|
-
})), ...
|
|
600
|
+
})), ...removedBeforePush.filter((name) => Object.hasOwn(current, name)).map((name) => ({
|
|
598
601
|
name,
|
|
599
602
|
value: null
|
|
600
603
|
}))];
|
|
@@ -604,6 +607,15 @@ const push = (spawner, key, options) => Effect.gen(function* () {
|
|
|
604
607
|
changes
|
|
605
608
|
};
|
|
606
609
|
}));
|
|
610
|
+
/** After a successful push: removes the names that left `env`, as the variables are now. */
|
|
611
|
+
const removeAfterPush = removedBeforePush.length === removed.length ? Effect.void : retryIdempotentWrite(Effect.gen(function* () {
|
|
612
|
+
const current = yield* listVariables(options.url, key);
|
|
613
|
+
const changes = removed.filter((name) => Object.hasOwn(current, name)).map((name) => ({
|
|
614
|
+
name,
|
|
615
|
+
value: null
|
|
616
|
+
}));
|
|
617
|
+
if (changes.length > 0) yield* writeVariables(options.url, key, changes);
|
|
618
|
+
}));
|
|
607
619
|
/**
|
|
608
620
|
* After a failed push, the variables go back to their earlier values, so
|
|
609
621
|
* that the deployment matches the hash in state. A failed rollback is
|
|
@@ -614,12 +626,14 @@ const push = (spawner, key, options) => Effect.gen(function* () {
|
|
|
614
626
|
value: Object.hasOwn(written.current, name) ? written.current[name] ?? null : null
|
|
615
627
|
})))).pipe(Effect.catch((error) => Effect.logWarning(`Convex.Deployment could not set the env variables of ${options.deployment} back after the failed push (${error.message}). Run the deploy again.`)));
|
|
616
628
|
if (source === void 0 || cwd === void 0 || program === void 0) return void 0;
|
|
617
|
-
|
|
629
|
+
const url = yield* runPush(spawner, key, {
|
|
618
630
|
...options,
|
|
619
631
|
cwd,
|
|
620
632
|
program,
|
|
621
633
|
command: source.command
|
|
622
634
|
}).pipe(Effect.onError(() => rollback));
|
|
635
|
+
yield* removeAfterPush;
|
|
636
|
+
return url;
|
|
623
637
|
});
|
|
624
638
|
/** Runs the installed CLI or the push command once, and checks the deployment that it names. */
|
|
625
639
|
const runPush = (spawner, key, options) => Effect.gen(function* () {
|
|
@@ -1841,4 +1855,4 @@ const state = () => Layer.effect(State, Effect.gen(function* () {
|
|
|
1841
1855
|
//#endregion
|
|
1842
1856
|
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 };
|
|
1843
1857
|
|
|
1844
|
-
//# sourceMappingURL=State-
|
|
1858
|
+
//# sourceMappingURL=State-CfIbfbVv.js.map
|