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.
- package/LICENSE +21 -0
- package/README.md +244 -0
- package/dist/AuthProvider.d.ts +35 -0
- package/dist/AuthProvider.d.ts.map +1 -0
- package/dist/AuthProvider.js +127 -0
- package/dist/AuthProvider.js.map +1 -0
- package/dist/Credentials.d.ts +13 -0
- package/dist/Credentials.d.ts.map +1 -0
- package/dist/Credentials.js +23 -0
- package/dist/Credentials.js.map +1 -0
- package/dist/Deployment.d.ts +45 -0
- package/dist/Deployment.d.ts.map +1 -0
- package/dist/Deployment.js +175 -0
- package/dist/Deployment.js.map +1 -0
- package/dist/ManagementApi.d.ts +108 -0
- package/dist/ManagementApi.d.ts.map +1 -0
- package/dist/ManagementApi.js +312 -0
- package/dist/ManagementApi.js.map +1 -0
- package/dist/OAuthClient.d.ts +38 -0
- package/dist/OAuthClient.d.ts.map +1 -0
- package/dist/OAuthClient.js +154 -0
- package/dist/OAuthClient.js.map +1 -0
- package/dist/Project.d.ts +34 -0
- package/dist/Project.d.ts.map +1 -0
- package/dist/Project.js +75 -0
- package/dist/Project.js.map +1 -0
- package/dist/ProjectHash.d.ts +25 -0
- package/dist/ProjectHash.d.ts.map +1 -0
- package/dist/ProjectHash.js +59 -0
- package/dist/ProjectHash.js.map +1 -0
- package/dist/Providers.d.ts +15 -0
- package/dist/Providers.d.ts.map +1 -0
- package/dist/Providers.js +24 -0
- package/dist/Providers.js.map +1 -0
- package/dist/Runtime.d.ts +61 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +208 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alchemy-convex contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# alchemy-convex
|
|
2
|
+
|
|
3
|
+
`alchemy-convex` is an experimental Alchemy v2 provider for deploying a
|
|
4
|
+
standard Convex project from an Alchemy stack.
|
|
5
|
+
|
|
6
|
+
The MVP contains five pieces:
|
|
7
|
+
|
|
8
|
+
- `Convex.Project`, an Alchemy resource that creates or adopts a Convex
|
|
9
|
+
project.
|
|
10
|
+
- `Convex.Deployment`, an Alchemy `Platform` that deploys a project directory
|
|
11
|
+
to a production, development, or preview reference.
|
|
12
|
+
- `ConvexCli`, a replaceable Effect service that reconciles environment
|
|
13
|
+
variables and invokes the project's local Convex CLI.
|
|
14
|
+
- `ConvexAuth`, an Alchemy Auth Provider supporting a Convex team access token
|
|
15
|
+
or an OAuth application token.
|
|
16
|
+
- `ConvexManagementApi`, which turns those durable credentials into a
|
|
17
|
+
deployment-scoped key only while reconciliation is running.
|
|
18
|
+
|
|
19
|
+
The Convex CLI still owns typechecking, code generation, bundling, and the code
|
|
20
|
+
push. This follows Convex's recommendation to use its CLI rather than reproduce
|
|
21
|
+
the private deployment protocol in an integration.
|
|
22
|
+
|
|
23
|
+
## Status
|
|
24
|
+
|
|
25
|
+
This is an MVP built against Alchemy `2.0.0-beta.63`, Effect
|
|
26
|
+
`4.0.0-beta.99`, and Convex `1.42.3`. Alchemy v2 and Effect 4 are prereleases,
|
|
27
|
+
so compatibility adjustments may be needed while their APIs stabilize.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
bun add alchemy-convex "alchemy@next" convex "effect@beta" \
|
|
33
|
+
"@effect/platform-bun@beta" "@effect/platform-node@beta"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Authentication
|
|
37
|
+
|
|
38
|
+
Run Alchemy's profile configuration:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
bun alchemy login --configure
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The Convex provider offers three methods:
|
|
45
|
+
|
|
46
|
+
- **Environment Variable** reads an access token from
|
|
47
|
+
`CONVEX_ACCESS_TOKEN`. This is selected automatically when `CI=1`.
|
|
48
|
+
- **OAuth** opens Convex in the browser and stores the resulting application
|
|
49
|
+
token under the active Alchemy profile.
|
|
50
|
+
- **Access Token** prompts securely and stores the token under
|
|
51
|
+
`~/.alchemy/credentials/<profile>/`.
|
|
52
|
+
|
|
53
|
+
Create team access tokens from the Convex Team Settings access-token page. A
|
|
54
|
+
token remains constrained by the permissions of the member who created it, so
|
|
55
|
+
a dedicated service account is recommended for automation.
|
|
56
|
+
|
|
57
|
+
OAuth uses the provider's registered Convex application and the localhost
|
|
58
|
+
redirect URI `http://localhost:9976/auth/callback`; no client credential setup
|
|
59
|
+
is required. The MVP always requests a team-scoped application token.
|
|
60
|
+
|
|
61
|
+
`CONVEX_DEPLOY_KEY` is intentionally not an Auth Provider credential. During a
|
|
62
|
+
reconciliation, `ConvexManagementApi` asks Convex for a deploy-key view of the
|
|
63
|
+
target deployment. With a team access token this is a least-privilege,
|
|
64
|
+
one-hour key that is revoked after the CLI exits; the expiry limits exposure if
|
|
65
|
+
cleanup cannot run. With OAuth, Convex returns a deployment-scoped view backed
|
|
66
|
+
by the same OAuth grant, so the provider does not attempt to revoke it as a
|
|
67
|
+
deploy key. No deploy key is written to Alchemy profiles, resource props,
|
|
68
|
+
outputs, state, or CLI arguments.
|
|
69
|
+
|
|
70
|
+
## Use
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import * as Alchemy from "alchemy";
|
|
74
|
+
import * as Convex from "alchemy-convex";
|
|
75
|
+
import * as Effect from "effect/Effect";
|
|
76
|
+
|
|
77
|
+
export default Alchemy.Stack(
|
|
78
|
+
"MyApp",
|
|
79
|
+
{
|
|
80
|
+
providers: Convex.providers(),
|
|
81
|
+
state: Alchemy.localState(),
|
|
82
|
+
},
|
|
83
|
+
Effect.gen(function* () {
|
|
84
|
+
const project = yield* Convex.Project("Backend");
|
|
85
|
+
|
|
86
|
+
const backend = yield* Convex.Deployment("BackendDeployment", {
|
|
87
|
+
project,
|
|
88
|
+
env: {
|
|
89
|
+
APP_ENV: "production",
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
convexUrl: backend.url,
|
|
95
|
+
convexHttpActionsUrl: backend.httpActionsUrl,
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Run the stack normally:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
bun alchemy deploy
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`Project.name` and `Project.dir` are optional. When `name` is omitted, the
|
|
108
|
+
provider derives a stable name from the Alchemy stack, stage, and resource ID.
|
|
109
|
+
`dir` defaults to `"."`, the stack's working directory. With a team-scoped
|
|
110
|
+
token the provider resolves the name in the authorized team and creates the
|
|
111
|
+
project when none exists. If that name already belongs to a project outside
|
|
112
|
+
the stack, Alchemy requires explicit adoption with `--adopt` or `adopt()`.
|
|
113
|
+
|
|
114
|
+
`Deployment.reference` selects the deployment and defaults to `"production"`.
|
|
115
|
+
Development and preview references carry their deployment type in the
|
|
116
|
+
reference itself:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const preview = yield* Convex.Deployment("PullRequest", {
|
|
120
|
+
project,
|
|
121
|
+
reference: "preview/pr-123",
|
|
122
|
+
expiresAt: "2030-01-01T00:00:00Z",
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Supported references are `"production"`, `"dev/<name>"`, and
|
|
127
|
+
`"preview/<name>"`. The stable reference is desired configuration; Convex's
|
|
128
|
+
generated deployment name is exposed as `deployment.name`.
|
|
129
|
+
An existing development or preview reference also requires explicit adoption;
|
|
130
|
+
the default production deployment is attached automatically because Convex
|
|
131
|
+
creates it with the parent project.
|
|
132
|
+
|
|
133
|
+
The authenticated token must be allowed to access the project. `Project.dir`
|
|
134
|
+
must contain the project's `package.json`; each child deployment invokes that
|
|
135
|
+
project's installed Convex CLI, so no global CLI is required. Override the
|
|
136
|
+
executable with `Convex.providers({ binary: "/path/to/convex" })`.
|
|
137
|
+
|
|
138
|
+
## Use resource outputs as environment variables
|
|
139
|
+
|
|
140
|
+
Pass outputs from other Alchemy resources directly in `env`, just like other
|
|
141
|
+
Alchemy resources do:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const web = yield* Cloudflare.Worker("Web", {
|
|
145
|
+
main: "./src/worker.ts",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const project = yield* Convex.Project("Backend", {
|
|
149
|
+
dir: "./apps/backend",
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const backend = yield* Convex.Deployment("BackendDeployment", {
|
|
153
|
+
project,
|
|
154
|
+
env: {
|
|
155
|
+
APP_ENV: "production",
|
|
156
|
+
SITE_URL: web.url,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Alchemy resolves nested outputs before the Convex provider reconciles the
|
|
162
|
+
project, so no separate binding helper is needed. Managed variables removed
|
|
163
|
+
from `env` are removed from Convex on the next deployment.
|
|
164
|
+
|
|
165
|
+
## Change detection and lifecycle
|
|
166
|
+
|
|
167
|
+
The provider hashes the project tree and skips `convex deploy` when both props
|
|
168
|
+
and source are unchanged. It excludes secrets, dependencies, build outputs,
|
|
169
|
+
Alchemy state, and `convex/_generated` by default. Monorepos can customize hash
|
|
170
|
+
inputs:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
const project = yield* Convex.Project("Backend", {
|
|
174
|
+
dir: "./apps/backend",
|
|
175
|
+
source: {
|
|
176
|
+
include: ["convex/**", "packages/domain/**", "package.json", "bun.lock"],
|
|
177
|
+
exclude: ["packages/domain/test/**"],
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
yield* Convex.Deployment("BackendDeployment", { project });
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`Deployment.alwaysDeploy: true` disables memoization.
|
|
185
|
+
|
|
186
|
+
Both resources use Alchemy's normal removal policy. Destroying a
|
|
187
|
+
`Convex.Deployment` deletes that deployment, including its data and files.
|
|
188
|
+
Destroying a `Convex.Project` deletes the project and cascades to every
|
|
189
|
+
deployment in it. Dependencies are destroyed first, so a stack containing both
|
|
190
|
+
resources deletes the deployment before its parent project.
|
|
191
|
+
|
|
192
|
+
Use Alchemy's `retain()` when remote data should survive stack removal:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { retain } from "alchemy/RemovalPolicy";
|
|
196
|
+
|
|
197
|
+
const project = yield* Convex.Project("Backend", {
|
|
198
|
+
dir: "./apps/backend",
|
|
199
|
+
}).pipe(retain());
|
|
200
|
+
|
|
201
|
+
const deployment = yield* Convex.Deployment("BackendDeployment", {
|
|
202
|
+
project,
|
|
203
|
+
}).pipe(retain());
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Adopt an existing named project explicitly when you intend the stack to own
|
|
207
|
+
and eventually delete it:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { adopt } from "alchemy/AdoptPolicy";
|
|
211
|
+
|
|
212
|
+
const project = yield* Convex.Project("Backend", {
|
|
213
|
+
name: "existing-project",
|
|
214
|
+
dir: "./apps/backend",
|
|
215
|
+
}).pipe(adopt());
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## What “custom runtime” means here
|
|
219
|
+
|
|
220
|
+
`Deployment` uses Alchemy's `Platform` API with a Convex-specific
|
|
221
|
+
`BaseRuntimeContext`. Alchemy resolves Outputs nested in its props, including
|
|
222
|
+
Convex environment variables, before reconciliation. Its provider then gives
|
|
223
|
+
the source tree to the Convex CLI, which packages functions for Convex's
|
|
224
|
+
managed runtime.
|
|
225
|
+
|
|
226
|
+
It does not translate arbitrary Effect HTTP handlers into Convex queries,
|
|
227
|
+
mutations, or actions. That deeper runtime needs a stable function manifest or
|
|
228
|
+
code-generation boundary, ideally shared with Confect, before depending on
|
|
229
|
+
private Convex or Confect internals.
|
|
230
|
+
|
|
231
|
+
## Development
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
bun install
|
|
235
|
+
bun run format:check
|
|
236
|
+
bun run lint
|
|
237
|
+
bun run check
|
|
238
|
+
bun run test
|
|
239
|
+
bun run build
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Provider tests inject `ConvexCli` and `ConvexManagementApi` Layers, so they
|
|
243
|
+
exercise Alchemy's create/no-op/update/destroy lifecycle without touching a
|
|
244
|
+
real Convex deployment or local profile.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AuthError, CredentialsStore, type CredentialsStoreService } from "alchemy/Auth";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Redacted from "effect/Redacted";
|
|
4
|
+
export declare const CONVEX_AUTH_PROVIDER_NAME = "Convex";
|
|
5
|
+
export declare const CONVEX_ACCESS_TOKEN_ENV_NAME = "CONVEX_ACCESS_TOKEN";
|
|
6
|
+
export type ConvexAuthConfig = {
|
|
7
|
+
readonly method: "env";
|
|
8
|
+
} | {
|
|
9
|
+
readonly method: "stored";
|
|
10
|
+
} | {
|
|
11
|
+
readonly method: "oauth";
|
|
12
|
+
};
|
|
13
|
+
export interface ConvexStoredCredentials {
|
|
14
|
+
readonly type: "accessToken";
|
|
15
|
+
readonly accessToken: string;
|
|
16
|
+
}
|
|
17
|
+
export type ConvexResolvedCredentials = {
|
|
18
|
+
readonly type: "accessToken";
|
|
19
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
20
|
+
readonly source: {
|
|
21
|
+
readonly type: "env" | "stored";
|
|
22
|
+
readonly details?: string;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "oauth";
|
|
26
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
27
|
+
readonly source: {
|
|
28
|
+
readonly type: "oauth";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Resolve a configured Convex credential using the caller's active store. */
|
|
32
|
+
export declare const readCredentials: (store: CredentialsStoreService, profileName: string, config: ConvexAuthConfig) => Effect.Effect<ConvexResolvedCredentials, AuthError>;
|
|
33
|
+
/** Registers Convex access-token and OAuth authentication with `alchemy login`. */
|
|
34
|
+
export declare const ConvexAuth: () => import("effect/Layer").Layer<never, never, import("alchemy").AuthProviders | CredentialsStore>;
|
|
35
|
+
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.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,KACvB,MAAM,CAAC,MAAM,CAAC,yBAAyB,EAAE,SAAS,CA8DlD,CAAC;AAEJ,mFAAmF;AACnF,eAAO,MAAM,UAAU,sGAsKpB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AuthError, AuthProviderLayer, CredentialsStore, displayRedacted, getEnvRedacted, retryOnce, } from "alchemy/Auth";
|
|
2
|
+
import * as Clank from "alchemy/Util/Clank";
|
|
3
|
+
import * as Console from "effect/Console";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Match from "effect/Match";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
import * as OAuthClient from "./OAuthClient.js";
|
|
8
|
+
export const CONVEX_AUTH_PROVIDER_NAME = "Convex";
|
|
9
|
+
export const CONVEX_ACCESS_TOKEN_ENV_NAME = "CONVEX_ACCESS_TOKEN";
|
|
10
|
+
const storedCredentialName = "convex-stored";
|
|
11
|
+
const oauthCredentialName = "convex-oauth";
|
|
12
|
+
const options = [
|
|
13
|
+
{
|
|
14
|
+
value: "env",
|
|
15
|
+
label: "Environment Variable",
|
|
16
|
+
hint: CONVEX_ACCESS_TOKEN_ENV_NAME,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: "oauth",
|
|
20
|
+
label: "OAuth",
|
|
21
|
+
hint: "browser-based Convex team authorization",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: "stored",
|
|
25
|
+
label: "Access Token",
|
|
26
|
+
hint: "enter interactively, stored in ~/.alchemy/credentials",
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
/** Resolve a configured Convex credential using the caller's active store. */
|
|
30
|
+
export const readCredentials = (store, profileName, config) => Match.value(config).pipe(Match.when({ method: "env" }, Effect.fn(function* () {
|
|
31
|
+
const accessToken = yield* getEnvRedacted(CONVEX_ACCESS_TOKEN_ENV_NAME);
|
|
32
|
+
if (!accessToken || Redacted.value(accessToken).length === 0) {
|
|
33
|
+
return yield* new AuthError({
|
|
34
|
+
message: `Convex environment credentials not found. Set ${CONVEX_ACCESS_TOKEN_ENV_NAME}.`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
type: "accessToken",
|
|
39
|
+
accessToken,
|
|
40
|
+
source: {
|
|
41
|
+
type: "env",
|
|
42
|
+
details: CONVEX_ACCESS_TOKEN_ENV_NAME,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
})), Match.when({ method: "stored" }, () => store
|
|
46
|
+
.read(profileName, storedCredentialName)
|
|
47
|
+
.pipe(Effect.flatMap((credentials) => credentials == null || credentials.type !== "accessToken"
|
|
48
|
+
? Effect.fail(new AuthError({
|
|
49
|
+
message: "Convex stored access token not found. Run: alchemy login --configure",
|
|
50
|
+
}))
|
|
51
|
+
: Effect.succeed({
|
|
52
|
+
type: "accessToken",
|
|
53
|
+
accessToken: Redacted.make(credentials.accessToken),
|
|
54
|
+
source: { type: "stored" },
|
|
55
|
+
})))), Match.when({ method: "oauth" }, () => store
|
|
56
|
+
.read(profileName, oauthCredentialName)
|
|
57
|
+
.pipe(Effect.flatMap((credentials) => credentials == null || credentials.type !== "oauth"
|
|
58
|
+
? Effect.fail(new AuthError({
|
|
59
|
+
message: "Convex OAuth credentials not found. Run: alchemy login",
|
|
60
|
+
}))
|
|
61
|
+
: Effect.succeed({
|
|
62
|
+
type: "oauth",
|
|
63
|
+
accessToken: Redacted.make(credentials.access),
|
|
64
|
+
source: { type: "oauth" },
|
|
65
|
+
})))), Match.exhaustive);
|
|
66
|
+
/** Registers Convex access-token and OAuth authentication with `alchemy login`. */
|
|
67
|
+
export const ConvexAuth = () => AuthProviderLayer()(CONVEX_AUTH_PROVIDER_NAME, Effect.gen(function* () {
|
|
68
|
+
const store = yield* CredentialsStore;
|
|
69
|
+
const oauthLogin = (profileName) => Effect.gen(function* () {
|
|
70
|
+
const authorization = yield* OAuthClient.authorize();
|
|
71
|
+
yield* Clank.info("Convex: opening browser for OAuth login...");
|
|
72
|
+
yield* Clank.info(authorization.url);
|
|
73
|
+
yield* Clank.openUrl(authorization.url).pipe(Effect.catch(() => Clank.warn("Convex: could not open a browser. Open the URL above manually.")));
|
|
74
|
+
yield* Clank.info("Convex: waiting for authorization (up to 5 minutes)...");
|
|
75
|
+
const credentials = yield* OAuthClient.callback(authorization);
|
|
76
|
+
yield* store.write(profileName, oauthCredentialName, credentials);
|
|
77
|
+
yield* Clank.success("Convex: OAuth credentials saved.");
|
|
78
|
+
return credentials;
|
|
79
|
+
});
|
|
80
|
+
const loginStored = Effect.fn(function* (profileName) {
|
|
81
|
+
const accessToken = yield* Clank.password({
|
|
82
|
+
message: "Convex access token",
|
|
83
|
+
validate: (value) => (value.length === 0 ? "Required" : undefined),
|
|
84
|
+
}).pipe(retryOnce);
|
|
85
|
+
yield* store.write(profileName, storedCredentialName, { type: "accessToken", accessToken });
|
|
86
|
+
yield* Clank.success("Convex: access token saved.");
|
|
87
|
+
return { method: "stored" };
|
|
88
|
+
});
|
|
89
|
+
const configureInteractive = (profileName) => Clank.select({
|
|
90
|
+
message: "Convex authentication method",
|
|
91
|
+
options,
|
|
92
|
+
}).pipe(Effect.flatMap((method) => Match.value(method).pipe(Match.when("env", () => Effect.succeed({ method: "env" })), Match.when("oauth", () => oauthLogin(profileName).pipe(Effect.as({ method: "oauth" }))), Match.when("stored", () => loginStored(profileName)), Match.exhaustive)));
|
|
93
|
+
const configure = (profileName, context) => Effect.gen(function* () {
|
|
94
|
+
if (context.ci)
|
|
95
|
+
return { method: "env" };
|
|
96
|
+
return yield* configureInteractive(profileName);
|
|
97
|
+
}).pipe(Effect.mapError((cause) => new AuthError({
|
|
98
|
+
message: "Failed to configure Convex credentials",
|
|
99
|
+
cause,
|
|
100
|
+
})));
|
|
101
|
+
const read = (profileName, config) => readCredentials(store, profileName, config);
|
|
102
|
+
const logout = (profileName, config) => Match.value(config).pipe(Match.when({ method: "env" }, () => Effect.void), Match.when({ method: "stored" }, () => store
|
|
103
|
+
.delete(profileName, storedCredentialName)
|
|
104
|
+
.pipe(Effect.andThen(Clank.success("Convex: stored access token removed.")))), Match.when({ method: "oauth" }, () => store
|
|
105
|
+
.delete(profileName, oauthCredentialName)
|
|
106
|
+
.pipe(Effect.andThen(Clank.success("Convex: OAuth credentials removed.")))), Match.exhaustive);
|
|
107
|
+
const login = (profileName, config) => Match.value(config)
|
|
108
|
+
.pipe(Match.when({ method: "env" }, () => Effect.void), Match.when({ method: "stored" }, () => store
|
|
109
|
+
.read(profileName, storedCredentialName)
|
|
110
|
+
.pipe(Effect.flatMap((credentials) => credentials?.type === "accessToken"
|
|
111
|
+
? Effect.void
|
|
112
|
+
: loginStored(profileName).pipe(Effect.asVoid)))), Match.when({ method: "oauth" }, () => store
|
|
113
|
+
.read(profileName, oauthCredentialName)
|
|
114
|
+
.pipe(Effect.flatMap((credentials) => credentials?.type === "oauth"
|
|
115
|
+
? Effect.void
|
|
116
|
+
: oauthLogin(profileName).pipe(Effect.asVoid)))), Match.exhaustive)
|
|
117
|
+
.pipe(Effect.mapError((cause) => new AuthError({
|
|
118
|
+
message: "Failed to log in to Convex",
|
|
119
|
+
cause,
|
|
120
|
+
})));
|
|
121
|
+
const prettyPrint = (profileName, config) => read(profileName, config).pipe(Effect.flatMap((credentials) => Effect.all([
|
|
122
|
+
Console.log(` accessToken: ${displayRedacted(credentials.accessToken, 12)}`),
|
|
123
|
+
Console.log(` source: ${credentials.source.type}`),
|
|
124
|
+
])), Effect.asVoid);
|
|
125
|
+
return { configure, login, logout, prettyPrint, read };
|
|
126
|
+
}));
|
|
127
|
+
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../src/AuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,SAAS,GAGV,MAAM,cAAc,CAAC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ACrC,KAAK;KACN,CAAC,CACL,CACF,CAAC;IAEN,MAAM,WAAW,GAAG,CAAC,WAAmB,EAAE,MAAwB,EAAE,EAAE,CACpE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,IAAI,CAC5B,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC;QACT,OAAO,CAAC,GAAG,CACT,kBAAkB,eAAe,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CACjE;QACD,OAAO,CAAC,GAAG,CAAC,aAAa,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;KACpD,CAAC,CACH,EACD,MAAM,CAAC,MAAM,CACd,CAAC;IAEJ,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AACzD,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AlchemyProfile, CredentialsStore } from "alchemy/Auth";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { type ConvexResolvedCredentials } from "./AuthProvider.js";
|
|
7
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "Convex::Credentials", Effect.Effect<ConvexResolvedCredentials, never, never>>;
|
|
8
|
+
/** Lazy credentials resolved from the active Alchemy profile. */
|
|
9
|
+
export declare class Credentials extends Credentials_base {
|
|
10
|
+
}
|
|
11
|
+
export declare const fromAuthProvider: () => Layer.Layer<Credentials, import("alchemy/Auth/AuthProvider").AuthError | Config.ConfigError, AlchemyProfile | import("alchemy").AuthProviders | CredentialsStore>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=Credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Credentials.d.ts","sourceRoot":"","sources":["../src/Credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EAIL,KAAK,yBAAyB,EAC/B,MAAM,mBAAmB,CAAC;;AAE3B,iEAAiE;AACjE,qBAAa,WAAY,SAAQ,gBAGP;CAAG;AAE7B,eAAO,MAAM,gBAAgB,yKAwB1B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ALCHEMY_PROFILE, AlchemyProfile, CredentialsStore, getAuthProvider, } from "alchemy/Auth";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { CONVEX_AUTH_PROVIDER_NAME, readCredentials, } from "./AuthProvider.js";
|
|
7
|
+
/** Lazy credentials resolved from the active Alchemy profile. */
|
|
8
|
+
export class Credentials extends Context.Service()("Convex::Credentials") {
|
|
9
|
+
}
|
|
10
|
+
export const fromAuthProvider = () => Layer.effect(Credentials, Effect.gen(function* () {
|
|
11
|
+
const profiles = yield* AlchemyProfile;
|
|
12
|
+
const store = yield* CredentialsStore;
|
|
13
|
+
const auth = yield* getAuthProvider(CONVEX_AUTH_PROVIDER_NAME);
|
|
14
|
+
const profileName = yield* ALCHEMY_PROFILE;
|
|
15
|
+
const ci = yield* Config.boolean("CI").pipe(Config.withDefault(false));
|
|
16
|
+
return yield* Effect.gen(function* () {
|
|
17
|
+
const config = yield* profiles.loadOrConfigure(auth, profileName, {
|
|
18
|
+
ci,
|
|
19
|
+
});
|
|
20
|
+
return yield* readCredentials(store, profileName, config);
|
|
21
|
+
}).pipe(Effect.orDie, Effect.cached);
|
|
22
|
+
}));
|
|
23
|
+
//# sourceMappingURL=Credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Credentials.js","sourceRoot":"","sources":["../src/Credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,eAAe,GAGhB,MAAM,mBAAmB,CAAC;AAE3B,iEAAiE;AACjE,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAG7C,CAAC,qBAAqB,CAAC;CAAG;AAE7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,KAAK,CAAC,MAAM,CACV,WAAW,EACX,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,eAAe,CAGjC,yBAAyB,CAAC,CAAC;IAC7B,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;IAC3C,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAEvE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE;YAChE,EAAE;SACH,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,CAAC,eAAe,CAC3B,KAAK,EACL,WAAW,EACX,MAA0B,CAC3B,CAAC;IACJ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Platform, type PlatformProps, type Resource } from "alchemy";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import { ConvexManagementApi } from "./ManagementApi.js";
|
|
4
|
+
import type { Project } from "./Project.js";
|
|
5
|
+
import type { Providers } from "./Providers.js";
|
|
6
|
+
import { ConvexCli, type ConvexEnvironment, type ConvexRuntimeContext } from "./Runtime.js";
|
|
7
|
+
export declare const DeploymentTypeId = "Convex.Deployment";
|
|
8
|
+
export type DeploymentTypeId = typeof DeploymentTypeId;
|
|
9
|
+
export type DeploymentReference = "production" | `dev/${string}` | `preview/${string}`;
|
|
10
|
+
export type DeploymentKind = "production" | "development" | "preview";
|
|
11
|
+
export interface DeploymentProps extends PlatformProps {
|
|
12
|
+
/** Parent Convex project. */
|
|
13
|
+
readonly project: Project;
|
|
14
|
+
/** Target deployment reference. Defaults to `"production"`. */
|
|
15
|
+
readonly reference?: DeploymentReference;
|
|
16
|
+
/** Environment variables reconciled before code is deployed. */
|
|
17
|
+
readonly env?: ConvexEnvironment;
|
|
18
|
+
/** Deploy even if the source hash and resource properties are unchanged. */
|
|
19
|
+
readonly alwaysDeploy?: boolean;
|
|
20
|
+
readonly typecheck?: "enable" | "try" | "disable";
|
|
21
|
+
readonly codegen?: boolean;
|
|
22
|
+
readonly message?: string;
|
|
23
|
+
/** Absolute preview expiration as an ISO timestamp or Unix milliseconds. */
|
|
24
|
+
readonly expiresAt?: string | number;
|
|
25
|
+
}
|
|
26
|
+
export interface DeploymentAttributes {
|
|
27
|
+
readonly projectId: number;
|
|
28
|
+
readonly deploymentId: number;
|
|
29
|
+
/** Convex-generated physical deployment name. */
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly reference: DeploymentReference;
|
|
32
|
+
readonly type: DeploymentKind;
|
|
33
|
+
readonly isDefault: boolean;
|
|
34
|
+
readonly url: string;
|
|
35
|
+
readonly httpActionsUrl: string;
|
|
36
|
+
readonly expiresAt: number | null;
|
|
37
|
+
readonly sourceHash: string;
|
|
38
|
+
readonly environmentKeys: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface Deployment extends Resource<DeploymentTypeId, DeploymentProps, DeploymentAttributes, never, Providers> {
|
|
41
|
+
}
|
|
42
|
+
/** A production, development, or preview deployment within a Convex project. */
|
|
43
|
+
export declare const Deployment: Platform<Deployment, never, void, ConvexRuntimeContext>;
|
|
44
|
+
export declare const DeploymentProvider: () => import("effect/Layer").Layer<Provider.Provider<Deployment>, never, ConvexCli | ConvexManagementApi>;
|
|
45
|
+
//# sourceMappingURL=Deployment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Deployment.d.ts","sourceRoot":"","sources":["../src/Deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAGR,KAAK,aAAa,EAClB,KAAK,QAAQ,EACd,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACL,SAAS,EAET,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AACpD,MAA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