@samebase/alchemy-convex 0.36.0 → 0.37.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 +25 -19
- package/lib/IdentityHub-CvtrHlaK.js +324 -0
- package/lib/IdentityHub-CvtrHlaK.js.map +1 -0
- package/lib/IdentityHub.d.ts +122 -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} +60 -56
- 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,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
|