alchemy-convex 0.0.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +244 -0
  3. package/dist/AuthProvider.d.ts +35 -0
  4. package/dist/AuthProvider.d.ts.map +1 -0
  5. package/dist/AuthProvider.js +127 -0
  6. package/dist/AuthProvider.js.map +1 -0
  7. package/dist/Credentials.d.ts +13 -0
  8. package/dist/Credentials.d.ts.map +1 -0
  9. package/dist/Credentials.js +23 -0
  10. package/dist/Credentials.js.map +1 -0
  11. package/dist/Deployment.d.ts +45 -0
  12. package/dist/Deployment.d.ts.map +1 -0
  13. package/dist/Deployment.js +175 -0
  14. package/dist/Deployment.js.map +1 -0
  15. package/dist/ManagementApi.d.ts +108 -0
  16. package/dist/ManagementApi.d.ts.map +1 -0
  17. package/dist/ManagementApi.js +312 -0
  18. package/dist/ManagementApi.js.map +1 -0
  19. package/dist/OAuthClient.d.ts +38 -0
  20. package/dist/OAuthClient.d.ts.map +1 -0
  21. package/dist/OAuthClient.js +154 -0
  22. package/dist/OAuthClient.js.map +1 -0
  23. package/dist/Project.d.ts +34 -0
  24. package/dist/Project.d.ts.map +1 -0
  25. package/dist/Project.js +75 -0
  26. package/dist/Project.js.map +1 -0
  27. package/dist/ProjectHash.d.ts +25 -0
  28. package/dist/ProjectHash.d.ts.map +1 -0
  29. package/dist/ProjectHash.js +59 -0
  30. package/dist/ProjectHash.js.map +1 -0
  31. package/dist/Providers.d.ts +15 -0
  32. package/dist/Providers.d.ts.map +1 -0
  33. package/dist/Providers.js +24 -0
  34. package/dist/Providers.js.map +1 -0
  35. package/dist/Runtime.d.ts +61 -0
  36. package/dist/Runtime.d.ts.map +1 -0
  37. package/dist/Runtime.js +208 -0
  38. package/dist/Runtime.js.map +1 -0
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +10 -0
  42. package/dist/index.js.map +1 -0
  43. package/package.json +55 -0
@@ -0,0 +1,38 @@
1
+ import * as Effect from "effect/Effect";
2
+ /**
3
+ * Registered Convex OAuth application credentials.
4
+ *
5
+ * Convex requires the client secret when exchanging an authorization code.
6
+ * A distributed CLI cannot keep that value private, so it ships with the
7
+ * provider in the same way as Alchemy's PlanetScale OAuth client. PKCE still
8
+ * protects intercepted authorization codes. Rotate these credentials by
9
+ * registering a new application secret and publishing a new release.
10
+ */
11
+ export declare const OAUTH_CLIENT_ID = "abee2524fbd24f70";
12
+ export declare const OAUTH_CLIENT_SECRET = "a87d14bda3004142a70d9868e87ca0a1";
13
+ export declare const OAUTH_REDIRECT_URI = "http://localhost:9976/auth/callback";
14
+ export interface OAuthCredentials {
15
+ readonly type: "oauth";
16
+ readonly access: string;
17
+ }
18
+ export interface Authorization {
19
+ readonly url: string;
20
+ readonly state: string;
21
+ readonly codeVerifier: string;
22
+ }
23
+ declare const OAuthError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
24
+ readonly _tag: "OAuthError";
25
+ } & Readonly<A>;
26
+ export declare class OAuthError extends OAuthError_base<{
27
+ readonly error: string;
28
+ readonly errorDescription: string;
29
+ }> {
30
+ }
31
+ /** Create a team-scoped Convex authorization URL using state and PKCE S256. */
32
+ export declare const authorize: () => Effect.Effect<Authorization, OAuthError>;
33
+ /** Exchange a single-use authorization code for a Convex application token. */
34
+ export declare const exchange: (authorization: Authorization, code: string) => Effect.Effect<OAuthCredentials, OAuthError>;
35
+ /** Wait for the localhost OAuth callback. Times out after five minutes. */
36
+ export declare const callback: (authorization: Authorization) => Effect.Effect<OAuthCredentials, OAuthError>;
37
+ export {};
38
+ //# sourceMappingURL=OAuthClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OAuthClient.d.ts","sourceRoot":"","sources":["../src/OAuthClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAClD,eAAO,MAAM,mBAAmB,qCAAqC,CAAC;AACtE,eAAO,MAAM,kBAAkB,wCAAwC,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;;;;AAED,qBAAa,UAAW,SAAQ,gBAA+B;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,CAAC;CAAG;AAOL,+EAA+E;AAC/E,eAAO,MAAM,SAAS,QAAO,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAYhE,CAAC;AAEL,+EAA+E;AAC/E,eAAO,MAAM,QAAQ,kBACJ,aAAa,QACtB,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,UAAU,CAgDzC,CAAC;AAEL,2EAA2E;AAC3E,eAAO,MAAM,QAAQ,kBACJ,aAAa,KAC3B,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,UAAU,CAUzC,CAAC"}
@@ -0,0 +1,154 @@
1
+ import { AUTH_ERROR_URL, AUTH_SUCCESS_URL } from "alchemy/Auth";
2
+ import * as Data from "effect/Data";
3
+ import * as Effect from "effect/Effect";
4
+ import crypto from "node:crypto";
5
+ import http from "node:http";
6
+ /**
7
+ * Registered Convex OAuth application credentials.
8
+ *
9
+ * Convex requires the client secret when exchanging an authorization code.
10
+ * A distributed CLI cannot keep that value private, so it ships with the
11
+ * provider in the same way as Alchemy's PlanetScale OAuth client. PKCE still
12
+ * protects intercepted authorization codes. Rotate these credentials by
13
+ * registering a new application secret and publishing a new release.
14
+ */
15
+ export const OAUTH_CLIENT_ID = "abee2524fbd24f70";
16
+ export const OAUTH_CLIENT_SECRET = "a87d14bda3004142a70d9868e87ca0a1";
17
+ export const OAUTH_REDIRECT_URI = "http://localhost:9976/auth/callback";
18
+ export class OAuthError extends Data.TaggedError("OAuthError") {
19
+ }
20
+ const randomValue = () => crypto.randomBytes(32).toString("base64url");
21
+ const codeChallenge = (verifier) => crypto.createHash("sha256").update(verifier).digest("base64url");
22
+ /** Create a team-scoped Convex authorization URL using state and PKCE S256. */
23
+ export const authorize = () => Effect.sync(() => {
24
+ const state = randomValue();
25
+ const codeVerifier = randomValue();
26
+ const url = new URL("https://dashboard.convex.dev/oauth/authorize/team");
27
+ url.searchParams.set("client_id", OAUTH_CLIENT_ID);
28
+ url.searchParams.set("redirect_uri", OAUTH_REDIRECT_URI);
29
+ url.searchParams.set("response_type", "code");
30
+ url.searchParams.set("state", state);
31
+ url.searchParams.set("code_challenge", codeChallenge(codeVerifier));
32
+ url.searchParams.set("code_challenge_method", "S256");
33
+ return { url: url.toString(), state, codeVerifier };
34
+ });
35
+ /** Exchange a single-use authorization code for a Convex application token. */
36
+ export const exchange = (authorization, code) => Effect.gen(function* () {
37
+ const body = new URLSearchParams({
38
+ client_id: OAUTH_CLIENT_ID,
39
+ client_secret: OAUTH_CLIENT_SECRET,
40
+ grant_type: "authorization_code",
41
+ redirect_uri: OAUTH_REDIRECT_URI,
42
+ code,
43
+ code_verifier: authorization.codeVerifier,
44
+ });
45
+ const response = yield* Effect.tryPromise({
46
+ try: () => fetch("https://api.convex.dev/oauth/token", {
47
+ method: "POST",
48
+ headers: {
49
+ Accept: "application/json",
50
+ "Content-Type": "application/x-www-form-urlencoded",
51
+ },
52
+ body,
53
+ }),
54
+ catch: (cause) => new OAuthError({
55
+ error: "network_error",
56
+ errorDescription: `Convex token request failed: ${String(cause)}`,
57
+ }),
58
+ });
59
+ const payload = yield* Effect.tryPromise({
60
+ try: () => response.json(),
61
+ catch: () => new OAuthError({
62
+ error: "parse_error",
63
+ errorDescription: `Convex token endpoint returned ${response.status}.`,
64
+ }),
65
+ });
66
+ if (!response.ok || typeof payload.access_token !== "string") {
67
+ return yield* new OAuthError({
68
+ error: typeof payload.error === "string" ? payload.error : "token_error",
69
+ errorDescription: typeof payload.error_description === "string"
70
+ ? payload.error_description
71
+ : `Convex token endpoint returned ${response.status}.`,
72
+ });
73
+ }
74
+ return { type: "oauth", access: payload.access_token };
75
+ });
76
+ /** Wait for the localhost OAuth callback. Times out after five minutes. */
77
+ export const callback = (authorization) => Effect.tryPromise({
78
+ try: () => callbackPromise(authorization),
79
+ catch: (cause) => cause instanceof OAuthError
80
+ ? cause
81
+ : new OAuthError({
82
+ error: "callback_error",
83
+ errorDescription: `Convex OAuth callback failed: ${String(cause)}`,
84
+ }),
85
+ });
86
+ const callbackPromise = (authorization) => {
87
+ const redirect = new URL(OAUTH_REDIRECT_URI);
88
+ return new Promise((resolvePromise, reject) => {
89
+ const server = http.createServer(async (request, response) => {
90
+ const url = new URL(request.url ?? "/", `http://${request.headers.host}`);
91
+ if (url.pathname !== redirect.pathname) {
92
+ response.statusCode = 404;
93
+ response.end("Not Found");
94
+ return;
95
+ }
96
+ const finish = (location) => {
97
+ response.writeHead(302, { Location: location });
98
+ response.end();
99
+ cleanup();
100
+ };
101
+ const oauthError = url.searchParams.get("error");
102
+ if (oauthError) {
103
+ finish(AUTH_ERROR_URL);
104
+ reject(new OAuthError({
105
+ error: oauthError,
106
+ errorDescription: url.searchParams.get("error_description") ??
107
+ "Convex authorization failed.",
108
+ }));
109
+ return;
110
+ }
111
+ const code = url.searchParams.get("code");
112
+ const state = url.searchParams.get("state");
113
+ if (!code || state !== authorization.state) {
114
+ finish(AUTH_ERROR_URL);
115
+ reject(new OAuthError({
116
+ error: "invalid_callback",
117
+ errorDescription: !code
118
+ ? "The Convex OAuth callback did not include a code."
119
+ : "The Convex OAuth state did not match.",
120
+ }));
121
+ return;
122
+ }
123
+ try {
124
+ const credentials = await Effect.runPromise(exchange(authorization, code));
125
+ finish(AUTH_SUCCESS_URL);
126
+ resolvePromise(credentials);
127
+ }
128
+ catch (cause) {
129
+ finish(AUTH_ERROR_URL);
130
+ reject(cause);
131
+ }
132
+ });
133
+ const timeout = setTimeout(() => {
134
+ cleanup();
135
+ reject(new OAuthError({
136
+ error: "timeout",
137
+ errorDescription: "Convex authorization timed out.",
138
+ }));
139
+ }, 5 * 60 * 1000);
140
+ const cleanup = () => {
141
+ clearTimeout(timeout);
142
+ server.close();
143
+ };
144
+ server.on("error", (cause) => {
145
+ cleanup();
146
+ reject(new OAuthError({
147
+ error: "server_error",
148
+ errorDescription: `Could not start the OAuth callback server: ${cause.message}`,
149
+ }));
150
+ });
151
+ server.listen(Number(redirect.port || 80), redirect.hostname);
152
+ });
153
+ };
154
+ //# sourceMappingURL=OAuthClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OAuthClient.js","sourceRoot":"","sources":["../src/OAuthClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,MAAM,CAAC,MAAM,mBAAmB,GAAG,kCAAkC,CAAC;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,qCAAqC,CAAC;AAaxE,MAAM,OAAO,UAAW,SAAQ,IAAI,CAAC,WAAW,CAAC,YAAY,CAG3D;CAAG;AAEL,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,MAAM,CA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KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,cAAc,CAAC,CAAC;gBACvB,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,UAAU,CACxB,GAAG,EAAE;YACH,OAAO,EAAE,CAAC;YACV,MAAM,CACJ,IAAI,UAAU,CAAC;gBACb,KAAK,EAAE,SAAS;gBAChB,gBAAgB,EAAE,iCAAiC;aACpD,CAAC,CACH,CAAC;QACJ,CAAC,EACD,CAAC,GAAG,EAAE,GAAG,IAAI,CACd,CAAC;QAEF,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;QAEF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,OAAO,EAAE,CAAC;YACV,MAAM,CACJ,IAAI,UAAU,CAAC;gBACb,KAAK,EAAE,cAAc;gBACrB,gBAAgB,EAAE,8CAA8C,KAAK,CAAC,OAAO,EAAE;aAChF,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Resource } from "alchemy";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { ConvexManagementApi } from "./ManagementApi.js";
4
+ import type { ProjectHashOptions } from "./ProjectHash.js";
5
+ import type { Providers } from "./Providers.js";
6
+ export declare const ProjectTypeId = "Convex.Project";
7
+ export type ProjectTypeId = typeof ProjectTypeId;
8
+ export interface ProjectProps {
9
+ /** Project name. Generated from the Alchemy resource ID when omitted. */
10
+ readonly name?: string;
11
+ /**
12
+ * Directory containing package.json and the Convex project configuration.
13
+ * Defaults to the stack's working directory (`"."`).
14
+ */
15
+ readonly dir?: string;
16
+ /** Source hash customization consumed by child deployments. */
17
+ readonly source?: ProjectHashOptions;
18
+ }
19
+ export interface ProjectAttributes {
20
+ readonly projectId: number;
21
+ readonly name: string;
22
+ readonly slug: string;
23
+ readonly teamId: number;
24
+ readonly teamSlug: string;
25
+ readonly defaultProductionDeploymentName: string;
26
+ readonly dir: string;
27
+ readonly source: ProjectHashOptions | undefined;
28
+ }
29
+ export interface Project extends Resource<ProjectTypeId, ProjectProps, ProjectAttributes, never, Providers> {
30
+ }
31
+ /** A Convex project. Deploy code with a child {@link Deployment}. */
32
+ export declare const Project: import("alchemy").ResourceClass<Project>;
33
+ export declare const ProjectProvider: () => import("effect/Layer").Layer<Provider.Provider<Project>, never, ConvexManagementApi | import("alchemy").Stack | import("alchemy").Stage>;
34
+ //# sourceMappingURL=Project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Project.d.ts","sourceRoot":"","sources":["../src/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKT,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAC9C,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,+BAA+B,EAAE,MAAM,CAAC;IACjD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,WAAW,OAAQ,SAAQ,QAAQ,CACvC,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,KAAK,EACL,SAAS,CACV;CAAG;AAEJ,qEAAqE;AACrE,eAAO,MAAM,OAAO,0CAAmC,CAAC;AAexD,eAAO,MAAM,eAAe,gJA0EzB,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { Resource, createPhysicalName, havePropsChanged, isResolved, } from "alchemy";
2
+ import { Unowned } from "alchemy/AdoptPolicy";
3
+ import * as Provider from "alchemy/Provider";
4
+ import * as Effect from "effect/Effect";
5
+ import { ConvexManagementApi } from "./ManagementApi.js";
6
+ export const ProjectTypeId = "Convex.Project";
7
+ /** A Convex project. Deploy code with a child {@link Deployment}. */
8
+ export const Project = Resource(ProjectTypeId);
9
+ const projectName = (id, name, previousName) => Effect.gen(function* () {
10
+ return (name ??
11
+ previousName ??
12
+ (yield* createPhysicalName({ id, lowercase: true, maxLength: 100 })));
13
+ });
14
+ export const ProjectProvider = () => Provider.effect(Project, Effect.gen(function* () {
15
+ const management = yield* ConvexManagementApi;
16
+ return Project.Provider.of({
17
+ version: 4,
18
+ nuke: { skip: true },
19
+ list: () => Effect.succeed([]),
20
+ read: Effect.fn(function* ({ id, olds, output }) {
21
+ const name = yield* projectName(id, olds?.name, output?.name);
22
+ const project = yield* management.findProject({ name });
23
+ if (project === undefined)
24
+ return undefined;
25
+ const attributes = {
26
+ projectId: project.projectId,
27
+ name: project.name,
28
+ slug: project.slug,
29
+ teamId: project.teamId,
30
+ teamSlug: project.teamSlug,
31
+ defaultProductionDeploymentName: project.defaultProductionDeploymentName ?? "",
32
+ dir: olds?.dir ?? output?.dir ?? ".",
33
+ source: olds?.source,
34
+ };
35
+ return output?.projectId === project.projectId
36
+ ? attributes
37
+ : Unowned(attributes);
38
+ }),
39
+ diff: ({ olds, news, output }) => Effect.succeed(!output || !isResolved(news)
40
+ ? undefined
41
+ : havePropsChanged(olds, news)
42
+ ? { action: "update" }
43
+ : { action: "noop" }),
44
+ reconcile: Effect.fn(function* ({ id, news, output, session }) {
45
+ const name = yield* projectName(id, news?.name, output?.name);
46
+ const project = yield* management.ensureProject({
47
+ name,
48
+ ...(output?.projectId === undefined
49
+ ? {}
50
+ : { projectId: output.projectId, managedProject: true }),
51
+ });
52
+ if (project.createdProject) {
53
+ yield* session.note(`Created Convex project ${project.name} (${project.projectId}).`);
54
+ }
55
+ else if (project.createdDeployment) {
56
+ yield* session.note(`Created default production deployment ${project.defaultProductionDeploymentName}.`);
57
+ }
58
+ return {
59
+ projectId: project.projectId,
60
+ name: project.name,
61
+ slug: project.slug,
62
+ teamId: project.teamId,
63
+ teamSlug: project.teamSlug,
64
+ defaultProductionDeploymentName: project.defaultProductionDeploymentName,
65
+ dir: news?.dir ?? ".",
66
+ source: news?.source,
67
+ };
68
+ }),
69
+ delete: Effect.fn(function* ({ output, session }) {
70
+ yield* management.deleteProject(output.projectId);
71
+ yield* session.note(`Deleted Convex project ${output.name}.`);
72
+ }),
73
+ });
74
+ }));
75
+ //# sourceMappingURL=Project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Project.js","sourceRoot":"","sources":["../src/Project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,GAEX,MAAM,SAAS,CAAC;AACjB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,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAChE,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import * as Effect from "effect/Effect";
2
+ export interface ProjectHashOptions {
3
+ /** Glob patterns to hash, relative to `projectDir`. */
4
+ readonly include?: readonly string[];
5
+ /** Additional glob patterns to exclude from the hash. */
6
+ readonly exclude?: readonly string[];
7
+ }
8
+ export declare const defaultProjectHashExcludes: readonly ["**/.git/**", "**/.alchemy/**", "**/.convex/**", "**/node_modules/**", "**/dist/**", "**/build/**", "**/coverage/**", "**/.env", "**/.env.*", "**/convex/_generated/**"];
9
+ declare const ProjectHashError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
10
+ readonly _tag: "ProjectHashError";
11
+ } & Readonly<A>;
12
+ export declare class ProjectHashError extends ProjectHashError_base<{
13
+ readonly projectDir: string;
14
+ readonly cause: unknown;
15
+ }> {
16
+ get message(): string;
17
+ }
18
+ /**
19
+ * Hash the source tree deterministically. Generated Convex types and common
20
+ * build/secret directories are excluded so a successful deploy does not make
21
+ * the next Alchemy plan dirty.
22
+ */
23
+ export declare const hashProject: (projectDir: string, options?: ProjectHashOptions) => Effect.Effect<string, ProjectHashError>;
24
+ export {};
25
+ //# sourceMappingURL=ProjectHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProjectHash.d.ts","sourceRoot":"","sources":["../src/ProjectHash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,yDAAyD;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,eAAO,MAAM,0BAA0B,YACrC,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,yBAAyB,CACjB,CAAC;;;;AAEX,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,eACV,MAAM,YACT,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAgCxC,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile, stat } from "node:fs/promises";
3
+ import { resolve } from "node:path";
4
+ import * as Data from "effect/Data";
5
+ import * as Effect from "effect/Effect";
6
+ import fg from "fast-glob";
7
+ export const defaultProjectHashExcludes = [
8
+ "**/.git/**",
9
+ "**/.alchemy/**",
10
+ "**/.convex/**",
11
+ "**/node_modules/**",
12
+ "**/dist/**",
13
+ "**/build/**",
14
+ "**/coverage/**",
15
+ "**/.env",
16
+ "**/.env.*",
17
+ "**/convex/_generated/**",
18
+ ];
19
+ export class ProjectHashError extends Data.TaggedError("ProjectHashError") {
20
+ get message() {
21
+ return `Failed to hash Convex project at ${this.projectDir}`;
22
+ }
23
+ }
24
+ /**
25
+ * Hash the source tree deterministically. Generated Convex types and common
26
+ * build/secret directories are excluded so a successful deploy does not make
27
+ * the next Alchemy plan dirty.
28
+ */
29
+ export const hashProject = (projectDir, options = {}) => {
30
+ const cwd = resolve(projectDir);
31
+ return Effect.tryPromise({
32
+ try: async () => {
33
+ const project = await stat(cwd);
34
+ if (!project.isDirectory()) {
35
+ throw new Error(`Convex project path is not a directory: ${cwd}`);
36
+ }
37
+ await readFile(resolve(cwd, "package.json"));
38
+ const files = await fg([...(options.include ?? ["**/*"])], {
39
+ cwd,
40
+ absolute: false,
41
+ dot: true,
42
+ followSymbolicLinks: false,
43
+ ignore: [...defaultProjectHashExcludes, ...(options.exclude ?? [])],
44
+ onlyFiles: true,
45
+ });
46
+ files.sort();
47
+ const hash = createHash("sha256");
48
+ for (const file of files) {
49
+ hash.update(file.replaceAll("\\", "/"));
50
+ hash.update("\0");
51
+ hash.update(await readFile(resolve(cwd, file)));
52
+ hash.update("\0");
53
+ }
54
+ return hash.digest("hex");
55
+ },
56
+ catch: (cause) => new ProjectHashError({ projectDir: cwd, cause }),
57
+ });
58
+ };
59
+ //# sourceMappingURL=ProjectHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProjectHash.js","sourceRoot":"","sources":["../src/ProjectHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,WAAW,CAAC;AAS3B,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,oBAAoB;IACpB,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,SAAS;IACT,WAAW;IACX,yBAAyB;CACjB,CAAC;AAEX,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAGvE;IACA,IAAa,OAAO;QAClB,OAAO,oCAAoC,IAAI,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,UAAkB,EAClB,OAAO,GAAuB,EAAE,EACS,EAAE;IAC3C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CAAC;QAC5B,CAAC;QACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;KACnE,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { ConvexManagementApi, type ConvexManagementApiOptions } from "./ManagementApi.js";
4
+ import { ConvexCli, type ConvexCliOptions } from "./Runtime.js";
5
+ declare const Providers_base: Provider.ProviderCollection<Providers, "Convex">;
6
+ export declare class Providers extends Providers_base {
7
+ }
8
+ export interface ConvexProviderOptions extends ConvexCliOptions, ConvexManagementApiOptions {
9
+ }
10
+ /** Register Convex resources using the local CLI and Management API. */
11
+ export declare const providers: (options?: ConvexProviderOptions) => Layer.Layer<import("alchemy/Auth/Profile").AlchemyProfile | import("./Credentials.js").Credentials | import("alchemy/Auth/Credentials").CredentialsStore | Providers, never, import("alchemy").AuthProviders | import("effect/FileSystem").FileSystem | import("alchemy").Stack | import("alchemy").Stage>;
12
+ /** Supply custom runtime services, primarily for provider tests. */
13
+ export declare const providersWithRuntime: (runtime: Layer.Layer<ConvexCli, never, never>, management: Layer.Layer<ConvexManagementApi, never, never>) => Layer.Layer<Providers, never, import("alchemy").Stack | import("alchemy").Stage>;
14
+ export {};
15
+ //# sourceMappingURL=Providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Providers.d.ts","sourceRoot":"","sources":["../src/Providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAO7C,OAAO,EACL,mBAAmB,EAEnB,KAAK,0BAA0B,EAChC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAiB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;;AAE/E,qBAAa,SAAU,SAAQ,cAE9B;CAAG;AAWJ,MAAM,WAAW,qBACf,SAAQ,gBAAgB,EAAE,0BAA0B;CAAG;AAEzD,wEAAwE;AACxE,eAAO,MAAM,SAAS,aAAa,qBAAqB,+SAYvD,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,YACtB,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,cACjC,KAAK,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,EAAE,KAAK,CAAC,qFAEkB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as Provider from "alchemy/Provider";
3
+ import { CredentialsStoreLive, ProfileLive } from "alchemy/Auth";
4
+ import { ConvexAuth } from "./AuthProvider.js";
5
+ import { fromAuthProvider } from "./Credentials.js";
6
+ import { Deployment, DeploymentProvider } from "./Deployment.js";
7
+ import { Project, ProjectProvider } from "./Project.js";
8
+ import { ConvexManagementApi, ConvexManagementApiLive, } from "./ManagementApi.js";
9
+ import { ConvexCli, ConvexCliLive } from "./Runtime.js";
10
+ export class Providers extends Provider.ProviderCollection()("Convex") {
11
+ }
12
+ const providerCollection = () => Layer.effect(Providers, Provider.collection([
13
+ Project,
14
+ Deployment,
15
+ ])).pipe(Layer.provide(ProjectProvider()), Layer.provide(DeploymentProvider()));
16
+ /** Register Convex resources using the local CLI and Management API. */
17
+ export const providers = (options = {}) => {
18
+ const credentials = fromAuthProvider();
19
+ const management = ConvexManagementApiLive(options);
20
+ return providerCollection().pipe(Layer.provide(management), Layer.provide(ConvexCliLive(options)), Layer.provideMerge(credentials), Layer.provideMerge(ConvexAuth()), Layer.provideMerge(ProfileLive), Layer.provideMerge(CredentialsStoreLive), Layer.orDie);
21
+ };
22
+ /** Supply custom runtime services, primarily for provider tests. */
23
+ export const providersWithRuntime = (runtime, management) => providerCollection().pipe(Layer.provide(runtime), Layer.provide(management));
24
+ //# sourceMappingURL=Providers.js.map
@@ -0,0 +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,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EACrC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,EAC/B,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC,EAChC,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,EAC/B,KAAK,CAAC,YAAY,CAAC,oBAAoB,CAAC,EACxC,KAAK,CAAC,KAAK,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA6C,EAC7C,UAA0D,EAC1D,EAAE,CACF,kBAAkB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC"}
@@ -0,0 +1,61 @@
1
+ import type { BaseRuntimeContext } from "alchemy";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Redacted from "effect/Redacted";
6
+ export type ConvexEnvironmentValue = string | Redacted.Redacted<string>;
7
+ export type ConvexEnvironment = Readonly<Record<string, ConvexEnvironmentValue>>;
8
+ export type ConvexDeploymentType = "prod" | "dev" | "preview" | "unknown";
9
+ export interface ConvexDeployRequest {
10
+ readonly projectDir: string;
11
+ readonly deployKey: Redacted.Redacted<string>;
12
+ readonly environment: ConvexEnvironment;
13
+ readonly previousEnvironmentKeys: readonly string[];
14
+ readonly typecheck: "enable" | "try" | "disable";
15
+ readonly codegen: boolean;
16
+ readonly message?: string;
17
+ }
18
+ export interface ConvexDeployResult {
19
+ readonly deploymentName: string;
20
+ readonly deploymentType: ConvexDeploymentType;
21
+ readonly url: string;
22
+ readonly httpActionsUrl: string;
23
+ readonly stdout: string;
24
+ readonly stderr: string;
25
+ }
26
+ export interface ConvexCliOptions {
27
+ /**
28
+ * Override the Convex executable. By default the runtime resolves the local
29
+ * `convex` package from the deployed project and invokes its JS entrypoint.
30
+ */
31
+ readonly binary?: string;
32
+ readonly extraEnv?: Readonly<Record<string, string>>;
33
+ }
34
+ declare const ConvexCliError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
35
+ readonly _tag: "ConvexCliError";
36
+ } & Readonly<A>;
37
+ export declare class ConvexCliError extends ConvexCliError_base<{
38
+ readonly operation: string;
39
+ readonly message: string;
40
+ readonly exitCode?: number;
41
+ readonly stderr?: string;
42
+ readonly cause?: unknown;
43
+ }> {
44
+ }
45
+ declare const ConvexCli_base: Context.ServiceClass<ConvexCli, "alchemy-convex/ConvexCli", {
46
+ readonly deploy: (request: ConvexDeployRequest) => Effect.Effect<ConvexDeployResult, ConvexCliError>;
47
+ }>;
48
+ export declare class ConvexCli extends ConvexCli_base {
49
+ }
50
+ export declare const deploymentMetadata: (deployKey: string, output: string) => Omit<ConvexDeployResult, "stdout" | "stderr">;
51
+ export declare const ConvexCliLive: (options?: ConvexCliOptions) => Layer.Layer<ConvexCli, never, never>;
52
+ export interface ConvexRuntimeContext extends BaseRuntimeContext {
53
+ }
54
+ /**
55
+ * Runtime context used by Alchemy's `Platform` constructor. Convex owns the
56
+ * actual function runtime; this context captures Alchemy Outputs as Convex
57
+ * environment variables during the plan phase.
58
+ */
59
+ export declare const createConvexRuntimeContext: (type: string, id: string) => ConvexRuntimeContext;
60
+ export {};
61
+ //# sourceMappingURL=Runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../src/Runtime.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ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