@samebase/alchemy-convex 0.1.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/LICENSE +201 -0
- package/README.md +146 -0
- package/lib/Credentials.d.ts +39 -0
- package/lib/Credentials.d.ts.map +1 -0
- package/lib/Credentials.js +49 -0
- package/lib/Credentials.js.map +1 -0
- package/lib/DefaultEnvironmentVariable.d.ts +58 -0
- package/lib/DefaultEnvironmentVariable.d.ts.map +1 -0
- package/lib/DefaultEnvironmentVariable.js +93 -0
- package/lib/DefaultEnvironmentVariable.js.map +1 -0
- package/lib/Deploy.d.ts +62 -0
- package/lib/Deploy.d.ts.map +1 -0
- package/lib/Deploy.js +92 -0
- package/lib/Deploy.js.map +1 -0
- package/lib/DeployKey.d.ts +48 -0
- package/lib/DeployKey.d.ts.map +1 -0
- package/lib/DeployKey.js +104 -0
- package/lib/DeployKey.js.map +1 -0
- package/lib/EnvironmentVariable.d.ts +37 -0
- package/lib/EnvironmentVariable.d.ts.map +1 -0
- package/lib/EnvironmentVariable.js +65 -0
- package/lib/EnvironmentVariable.js.map +1 -0
- package/lib/ManagementApi.d.ts +50 -0
- package/lib/ManagementApi.d.ts.map +1 -0
- package/lib/ManagementApi.js +103 -0
- package/lib/ManagementApi.js.map +1 -0
- package/lib/PreviewDeployKey.d.ts +34 -0
- package/lib/PreviewDeployKey.d.ts.map +1 -0
- package/lib/PreviewDeployKey.js +78 -0
- package/lib/PreviewDeployKey.js.map +1 -0
- package/lib/Project.d.ts +29 -0
- package/lib/Project.d.ts.map +1 -0
- package/lib/Project.js +114 -0
- package/lib/Project.js.map +1 -0
- package/lib/Providers.d.ts +13 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +30 -0
- package/lib/Providers.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/package.json +71 -0
- package/src/Credentials.ts +78 -0
- package/src/DefaultEnvironmentVariable.ts +165 -0
- package/src/Deploy.ts +171 -0
- package/src/DeployKey.ts +171 -0
- package/src/EnvironmentVariable.ts +129 -0
- package/src/ManagementApi.ts +193 -0
- package/src/PreviewDeployKey.ts +126 -0
- package/src/Project.ts +191 -0
- package/src/Providers.ts +51 -0
- package/src/index.ts +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @samebase/alchemy-convex
|
|
2
|
+
|
|
3
|
+
Convex resources for [Alchemy v2](https://alchemy.run): projects, deploy keys, environment
|
|
4
|
+
variables, project default environment variables, and a deploy step that hands the deployment URL
|
|
5
|
+
to your frontend build. The Convex CLI keeps doing typecheck, codegen, bundling, and the code push.
|
|
6
|
+
This package manages the control plane around it.
|
|
7
|
+
|
|
8
|
+
Alchemy has no built-in Convex provider ([alchemy-run/alchemy-async#1306](https://github.com/alchemy-run/alchemy-async/issues/1306)).
|
|
9
|
+
This is a community provider, maintained by [Samebase](https://samebase.com).
|
|
10
|
+
|
|
11
|
+
Status: 0.1, pinned to `alchemy@2.0.0-beta.80` and Effect 4. Alchemy ships breaking changes
|
|
12
|
+
between betas; upgrade this package and Alchemy together. Verified end to end on a Vite app with a
|
|
13
|
+
Cloudflare Worker: production on `main`, a Convex preview deployment plus a Worker Preview per pull
|
|
14
|
+
request, destroy on close.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
pnpm add -D @samebase/alchemy-convex alchemy@2.0.0-beta.80 effect@^4.0.0 @effect/platform-node@^4.0.0 convex
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Credentials
|
|
23
|
+
|
|
24
|
+
The provider calls the [Convex Management API](https://docs.convex.dev/management-api) with a
|
|
25
|
+
bearer token. By default it reads `CONVEX_ACCESS_TOKEN` through the stack's config provider
|
|
26
|
+
(process env, `.env`, stack secrets) and then falls back to the token the Convex CLI saved after
|
|
27
|
+
`npx convex login` (`~/.convex/config.json`). A developer who is logged in needs no setup. CI sets
|
|
28
|
+
the variable to a team access token.
|
|
29
|
+
|
|
30
|
+
To pass a token explicitly:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
Convex.providers(Convex.fromToken(Redacted.make(token)));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
A team access token is team wide. The deploy keys this provider creates are scoped to one
|
|
37
|
+
deployment or one project, and those are what CI deploys with.
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import * as Alchemy from "alchemy";
|
|
43
|
+
import * as Cloudflare from "alchemy/Cloudflare";
|
|
44
|
+
import * as Effect from "effect/Effect";
|
|
45
|
+
import * as Layer from "effect/Layer";
|
|
46
|
+
import * as Convex from "@samebase/alchemy-convex";
|
|
47
|
+
|
|
48
|
+
export default Alchemy.Stack(
|
|
49
|
+
"MyApp",
|
|
50
|
+
{
|
|
51
|
+
providers: Layer.mergeAll(Cloudflare.providers(), Convex.providers()),
|
|
52
|
+
state: Cloudflare.state(),
|
|
53
|
+
},
|
|
54
|
+
Effect.gen(function* () {
|
|
55
|
+
const project = yield* Convex.Project("Backend", {
|
|
56
|
+
team: "my-team",
|
|
57
|
+
name: "my-app",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const deployKey = yield* Convex.DeployKey("DeployKey", {
|
|
61
|
+
deployment: project.prodDeploymentName.as<string>(),
|
|
62
|
+
name: "alchemy",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const backend = yield* Convex.Deploy("Backend", {
|
|
66
|
+
cwd: ".",
|
|
67
|
+
deployKey: deployKey.deployKey,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const site = yield* Cloudflare.Website.StaticSite("Website", {
|
|
71
|
+
command: "npm run build",
|
|
72
|
+
outdir: "dist/client",
|
|
73
|
+
env: { VITE_CONVEX_URL: backend.url },
|
|
74
|
+
assets: { notFoundHandling: "single-page-application" },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
yield* Convex.EnvironmentVariable("SiteUrl", {
|
|
78
|
+
deployment: backend.deploymentName,
|
|
79
|
+
deployKey: deployKey.deployKey,
|
|
80
|
+
name: "SITE_URL",
|
|
81
|
+
value: site.url,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return { url: site.url, backendUrl: backend.url };
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Order follows the outputs: the project exists before its key, the key before the deploy, the
|
|
90
|
+
deploy before the frontend build that embeds the URL.
|
|
91
|
+
|
|
92
|
+
Preview stages: give `Convex.Deploy` a `PreviewDeployKey` and `previewName: <branch>` on pull
|
|
93
|
+
request stages, and the production key on `prod`. Variables that every preview deployment needs,
|
|
94
|
+
such as auth keys, go on the project as `DefaultEnvironmentVariable` for `preview`.
|
|
95
|
+
|
|
96
|
+
## Resources
|
|
97
|
+
|
|
98
|
+
- `Convex.Project`: `{ team: slug | id, name, deploymentRegion?, deploymentType? }`. Creates a
|
|
99
|
+
project with its default deployment. Outputs `projectId`, `slug`, `teamId`,
|
|
100
|
+
`prodDeploymentName`, `prodDeploymentUrl`. There is no project update API, so a changed property
|
|
101
|
+
replaces the project. An existing project with the same name is adopted only with `--adopt`.
|
|
102
|
+
Deleting the resource deletes the project with all of its deployments and data.
|
|
103
|
+
- `Convex.DeployKey`: `{ deployment, name, allowedActions? }`. Outputs `uniqueName` and the
|
|
104
|
+
`deployKey` secret. Any change replaces the key. Keys are never adopted: a key without its secret
|
|
105
|
+
is useless.
|
|
106
|
+
- `Convex.PreviewDeployKey`: `{ projectId, name }`. Project-level key for preview deployments.
|
|
107
|
+
Outputs `uniqueName` and `previewDeployKey`.
|
|
108
|
+
- `Convex.EnvironmentVariable`: `{ deployment, deployKey, name, value }`. One variable on one
|
|
109
|
+
deployment, set through the deployment API with that deployment's key. An existing variable with
|
|
110
|
+
the same name is adopted and overwritten.
|
|
111
|
+
- `Convex.DefaultEnvironmentVariable`: `{ projectId, name, value, deploymentType }`. A project
|
|
112
|
+
default that new deployments of that type inherit. Use it for preview and dev deployments.
|
|
113
|
+
- `Convex.Deploy`: `{ cwd?, env?, deployKey, previewName?, previewCreate?, previewRun?, extraArgs?,
|
|
114
|
+
memo?, timeout? }`. Runs `npx convex deploy` with `CONVEX_DEPLOY_KEY` set and parses the
|
|
115
|
+
deployment URL from the CLI output. Outputs `url`, `deploymentName`, `hash`. Memoized by content
|
|
116
|
+
hash like Alchemy's own build steps. Deleting the resource does nothing; the deployment belongs to
|
|
117
|
+
the project, and preview deployments expire on Convex's schedule.
|
|
118
|
+
|
|
119
|
+
## Limits
|
|
120
|
+
|
|
121
|
+
- Team slugs resolve through an unofficial dashboard endpoint. Pass the numeric team id to avoid
|
|
122
|
+
it.
|
|
123
|
+
- Deploy keys and other secret outputs are part of Alchemy state. Alchemy's Cloudflare state store
|
|
124
|
+
encrypts state at rest; the local file store does not.
|
|
125
|
+
- A deleted deploy key keeps working on the deployment API for roughly 30 seconds.
|
|
126
|
+
- Not covered: dev deployments, custom domains, log streams, teams and members, components,
|
|
127
|
+
snapshots.
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
pnpm install
|
|
133
|
+
pnpm run check # format, lint, typecheck, unit tests
|
|
134
|
+
pnpm run build # lib/ with declarations
|
|
135
|
+
pnpm run test:live # real API calls, see below
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Unit tests run against recorded Management API payloads in `test/fixtures/management/`. Live tests
|
|
139
|
+
need `ALCHEMY_CONVEX_LIVE=1`, a Convex login or `CONVEX_ACCESS_TOKEN`, and a throwaway project.
|
|
140
|
+
Point them at yours with `ALCHEMY_CONVEX_LIVE_TEAM`, `ALCHEMY_CONVEX_LIVE_PROJECT_ID`,
|
|
141
|
+
`ALCHEMY_CONVEX_LIVE_DEPLOYMENT`, and `ALCHEMY_CONVEX_LIVE_PROJECT_DIR` (a Convex app directory for
|
|
142
|
+
the deploy test). They create resources named `tmp-alchemy-convex-*` and remove them again.
|
|
143
|
+
|
|
144
|
+
Releases: push a `v*` tag; `.github/workflows/release.yml` publishes with npm trusted publishing.
|
|
145
|
+
|
|
146
|
+
License: Apache 2.0.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
export interface ResolvedCredentials {
|
|
7
|
+
/** Bearer token accepted by https://api.convex.dev/v1: a team access token, an OAuth token, or the Convex CLI login. */
|
|
8
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
9
|
+
/** Where the token came from, for error messages only. */
|
|
10
|
+
readonly source: "env" | "explicit" | "convex-cli-login";
|
|
11
|
+
}
|
|
12
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "@samebase/alchemy-convex/Credentials", Effect.Effect<ResolvedCredentials, never, never>>;
|
|
13
|
+
export declare class Credentials extends Credentials_base {
|
|
14
|
+
}
|
|
15
|
+
/** Environment variable read by {@link fromConfig}. */
|
|
16
|
+
export declare const ACCESS_TOKEN_ENV = "CONVEX_ACCESS_TOKEN";
|
|
17
|
+
/** The Convex CLI stores its device login here after `npx convex login`. */
|
|
18
|
+
export declare const convexCliConfigPath: () => string;
|
|
19
|
+
/**
|
|
20
|
+
* Token the Convex CLI saved on this machine. It works on the Management API
|
|
21
|
+
* for the teams the logged-in user belongs to. Fails when nobody is logged in.
|
|
22
|
+
*/
|
|
23
|
+
export declare const readConvexCliLogin: Effect.Effect<ResolvedCredentials, CredentialsError>;
|
|
24
|
+
declare const CredentialsError_base: Schema.Class<CredentialsError, Schema.TaggedStruct<"CredentialsError", {
|
|
25
|
+
readonly reason: Schema.String;
|
|
26
|
+
}>, import("effect/Cause").YieldableError>;
|
|
27
|
+
export declare class CredentialsError extends CredentialsError_base {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Default resolution: `CONVEX_ACCESS_TOKEN` from the stack ConfigProvider
|
|
31
|
+
* (process env, `.env`, stack secrets), then the Convex CLI login on this
|
|
32
|
+
* machine. CI sets the variable; a developer who ran `npx convex login` needs
|
|
33
|
+
* nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare const fromConfig: () => Layer.Layer<Credentials>;
|
|
36
|
+
/** Explicit token, for tests or callers that already hold a value. */
|
|
37
|
+
export declare const fromToken: (accessToken: Redacted.Redacted<string>) => Layer.Layer<Credentials>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=Credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Credentials.d.ts","sourceRoot":"","sources":["../src/Credentials.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,MAAM,WAAW,mBAAmB;IAClC,wHAAwH;IACxH,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,UAAU,GAAG,kBAAkB,CAAC;CAC1D;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAEJ,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,cAAkD,CAAC;AAInF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAYnF,CAAC;;;;AAEF,qBAAa,gBAAiB,SAAQ,qBAEpC;CAAG;AAEL;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAO,KAAK,CAAC,KAAK,CAAC,WAAW,CAUlD,CAAC;AAEJ,sEAAsE;AACtE,eAAO,MAAM,SAAS,GAAI,aAAa,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CACA,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Convex control-plane credentials for the provider.
|
|
2
|
+
//
|
|
3
|
+
// The service value is an Effect so that building the providers layer never
|
|
4
|
+
// touches the environment or the filesystem. The token is read on the first
|
|
5
|
+
// lifecycle call, which keeps `alchemy plan` on an unrelated stack free of
|
|
6
|
+
// Convex credential errors.
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import * as Config from "effect/Config";
|
|
11
|
+
import * as Context from "effect/Context";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Layer from "effect/Layer";
|
|
14
|
+
import * as Redacted from "effect/Redacted";
|
|
15
|
+
import * as Schema from "effect/Schema";
|
|
16
|
+
export class Credentials extends Context.Service()("@samebase/alchemy-convex/Credentials") {
|
|
17
|
+
}
|
|
18
|
+
/** Environment variable read by {@link fromConfig}. */
|
|
19
|
+
export const ACCESS_TOKEN_ENV = "CONVEX_ACCESS_TOKEN";
|
|
20
|
+
/** The Convex CLI stores its device login here after `npx convex login`. */
|
|
21
|
+
export const convexCliConfigPath = () => join(homedir(), ".convex", "config.json");
|
|
22
|
+
const CliConfig = Schema.Struct({ accessToken: Schema.String });
|
|
23
|
+
/**
|
|
24
|
+
* Token the Convex CLI saved on this machine. It works on the Management API
|
|
25
|
+
* for the teams the logged-in user belongs to. Fails when nobody is logged in.
|
|
26
|
+
*/
|
|
27
|
+
export const readConvexCliLogin = Effect.gen(function* () {
|
|
28
|
+
const path = convexCliConfigPath();
|
|
29
|
+
const text = yield* Effect.tryPromise({
|
|
30
|
+
try: () => readFile(path, "utf8"),
|
|
31
|
+
catch: () => new CredentialsError({ reason: `no Convex CLI login at ${path}` }),
|
|
32
|
+
});
|
|
33
|
+
const parsed = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(CliConfig))(text).pipe(Effect.mapError(() => new CredentialsError({ reason: `${path} has no accessToken` })));
|
|
34
|
+
return { accessToken: Redacted.make(parsed.accessToken), source: "convex-cli-login" };
|
|
35
|
+
});
|
|
36
|
+
export class CredentialsError extends Schema.TaggedError()("CredentialsError", {
|
|
37
|
+
reason: Schema.String,
|
|
38
|
+
}) {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Default resolution: `CONVEX_ACCESS_TOKEN` from the stack ConfigProvider
|
|
42
|
+
* (process env, `.env`, stack secrets), then the Convex CLI login on this
|
|
43
|
+
* machine. CI sets the variable; a developer who ran `npx convex login` needs
|
|
44
|
+
* nothing.
|
|
45
|
+
*/
|
|
46
|
+
export const fromConfig = () => Layer.succeed(Credentials, Effect.cached(Config.Redacted(ACCESS_TOKEN_ENV).pipe(Effect.map((accessToken) => ({ accessToken, source: "env" })), Effect.catch(() => readConvexCliLogin), Effect.orDie)).pipe(Effect.flatten));
|
|
47
|
+
/** Explicit token, for tests or callers that already hold a value. */
|
|
48
|
+
export const fromToken = (accessToken) => Layer.succeed(Credentials, Effect.succeed({ accessToken, source: "explicit" }));
|
|
49
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,GAAG,CAAC,WAAsC,EAA4B,EAAE,CAC5F,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAW,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Resource } from "alchemy";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import type { components } from "@convex-dev/platform/managementApi";
|
|
7
|
+
import { ManagementApi, type ManagementApiService } from "./ManagementApi.ts";
|
|
8
|
+
import type { Providers } from "./Providers.ts";
|
|
9
|
+
/** Deployment types a default can target, from the generated schema. */
|
|
10
|
+
export type DeploymentType = components["schemas"]["DeploymentType"];
|
|
11
|
+
/**
|
|
12
|
+
* Attributes when the listing has `name` for `deploymentType`. An unfiltered
|
|
13
|
+
* listing merges the deployment types that share one value into one row, so
|
|
14
|
+
* the match checks membership in `deploymentTypes`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const findDefault: (list: typeof DefaultEnvironmentVariableList.Type, projectId: number, name: string, deploymentType: DeploymentType) => DefaultEnvironmentVariableAttributes | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Lists the defaults named `name` for `deploymentType`. Convex filters on
|
|
19
|
+
* both, so the listing has at most one row and needs no pagination.
|
|
20
|
+
*/
|
|
21
|
+
export declare const listDefaults: (api: ManagementApiService, projectId: number, name: string, deploymentType: DeploymentType) => Effect.Effect<{
|
|
22
|
+
readonly items: readonly {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly deploymentTypes: readonly string[];
|
|
25
|
+
}[];
|
|
26
|
+
}, import("./ManagementApi.ts").ConvexApiError, never>;
|
|
27
|
+
/**
|
|
28
|
+
* Sets one default, or removes it when `value` is null. Convex answers 200
|
|
29
|
+
* with an empty body, so this reads no response data.
|
|
30
|
+
*/
|
|
31
|
+
export declare const updateDefault: (api: ManagementApiService, projectId: number, name: string, deploymentType: DeploymentType, value: string | Redacted.Redacted<string> | null) => Effect.Effect<void, import("./ManagementApi.ts").ConvexApiError, never>;
|
|
32
|
+
/**
|
|
33
|
+
* GET /projects/{project_id}/list_default_environment_variables. Only the
|
|
34
|
+
* fields the provider uses: the row's `value` is the secret in plain text.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DefaultEnvironmentVariableList: Schema.Struct<{
|
|
37
|
+
readonly items: Schema.$Array<Schema.Struct<{
|
|
38
|
+
readonly name: Schema.String;
|
|
39
|
+
readonly deploymentTypes: Schema.$Array<Schema.String>;
|
|
40
|
+
}>>;
|
|
41
|
+
}>;
|
|
42
|
+
export interface DefaultEnvironmentVariableProps {
|
|
43
|
+
/** Numeric project id, such as `project.projectId`. */
|
|
44
|
+
readonly projectId: number;
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly value: string | Redacted.Redacted<string>;
|
|
47
|
+
/** Deployments of this type that Convex creates from now on get the variable. */
|
|
48
|
+
readonly deploymentType: DeploymentType;
|
|
49
|
+
}
|
|
50
|
+
export interface DefaultEnvironmentVariableAttributes {
|
|
51
|
+
readonly projectId: number;
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly deploymentType: DeploymentType;
|
|
54
|
+
}
|
|
55
|
+
export type DefaultEnvironmentVariable = Resource<"Convex.DefaultEnvironmentVariable", DefaultEnvironmentVariableProps, DefaultEnvironmentVariableAttributes, never, Providers>;
|
|
56
|
+
export declare const DefaultEnvironmentVariable: import("alchemy").ResourceClass<DefaultEnvironmentVariable>;
|
|
57
|
+
export declare const DefaultEnvironmentVariableProvider: () => import("effect/Layer").Layer<Provider.Provider<DefaultEnvironmentVariable>, never, ManagementApi>;
|
|
58
|
+
//# sourceMappingURL=DefaultEnvironmentVariable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultEnvironmentVariable.d.ts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,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnD,iFAAiF;IACjF,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACzC;AAED,MAAM,WAAW,oCAAoC;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACzC;AAED,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAC/C,mCAAmC,EACnC,+BAA+B,EAC/B,oCAAoC,EACpC,KAAK,EACL,SAAS,CACV,CAAC;AACF,eAAO,MAAM,0BAA0B,6DAEtC,CAAC;AAEF,eAAO,MAAM,kCAAkC,yGAgD5C,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Convex.DefaultEnvironmentVariable: a project default environment variable
|
|
2
|
+
// for one deployment type. Convex sets it on each new deployment of that type,
|
|
3
|
+
// such as auth keys that every pull request preview deployment needs.
|
|
4
|
+
//
|
|
5
|
+
// Defaults live on the Management API and authenticate with the team
|
|
6
|
+
// credential, not with a deploy key. Setting a default and removing it are the
|
|
7
|
+
// same call: update_default_environment_variables with `value: null` removes
|
|
8
|
+
// the default, and removing an absent default also answers 200.
|
|
9
|
+
import { Resource } from "alchemy";
|
|
10
|
+
import { isResolved } from "alchemy/Diff";
|
|
11
|
+
import * as Provider from "alchemy/Provider";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Redacted from "effect/Redacted";
|
|
14
|
+
import * as Schema from "effect/Schema";
|
|
15
|
+
import { absentAsUndefined, ManagementApi } from "./ManagementApi.js";
|
|
16
|
+
/**
|
|
17
|
+
* Attributes when the listing has `name` for `deploymentType`. An unfiltered
|
|
18
|
+
* listing merges the deployment types that share one value into one row, so
|
|
19
|
+
* the match checks membership in `deploymentTypes`.
|
|
20
|
+
*/
|
|
21
|
+
export const findDefault = (list, projectId, name, deploymentType) => list.items.some((item) => item.name === name && item.deploymentTypes.includes(deploymentType))
|
|
22
|
+
? { projectId, name, deploymentType }
|
|
23
|
+
: undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Lists the defaults named `name` for `deploymentType`. Convex filters on
|
|
26
|
+
* both, so the listing has at most one row and needs no pagination.
|
|
27
|
+
*/
|
|
28
|
+
export const listDefaults = (api, projectId, name, deploymentType) => api
|
|
29
|
+
.request("list default environment variables", (client) => client.GET("/projects/{project_id}/list_default_environment_variables", {
|
|
30
|
+
params: { path: { project_id: projectId }, query: { name, deploymentType } },
|
|
31
|
+
}))
|
|
32
|
+
.pipe(Effect.map((body) => Schema.decodeUnknownSync(DefaultEnvironmentVariableList)(body)));
|
|
33
|
+
/**
|
|
34
|
+
* Sets one default, or removes it when `value` is null. Convex answers 200
|
|
35
|
+
* with an empty body, so this reads no response data.
|
|
36
|
+
*/
|
|
37
|
+
export const updateDefault = (api, projectId, name, deploymentType, value) => api.requestVoid("update default environment variables", (client) => client.POST("/projects/{project_id}/update_default_environment_variables", {
|
|
38
|
+
params: { path: { project_id: projectId } },
|
|
39
|
+
body: {
|
|
40
|
+
changes: [
|
|
41
|
+
{
|
|
42
|
+
name,
|
|
43
|
+
deploymentType,
|
|
44
|
+
value: Redacted.isRedacted(value) ? Redacted.value(value) : value,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
/**
|
|
50
|
+
* GET /projects/{project_id}/list_default_environment_variables. Only the
|
|
51
|
+
* fields the provider uses: the row's `value` is the secret in plain text.
|
|
52
|
+
*/
|
|
53
|
+
export const DefaultEnvironmentVariableList = Schema.Struct({
|
|
54
|
+
items: Schema.Array(Schema.Struct({ name: Schema.String, deploymentTypes: Schema.Array(Schema.String) })),
|
|
55
|
+
});
|
|
56
|
+
export const DefaultEnvironmentVariable = Resource("Convex.DefaultEnvironmentVariable");
|
|
57
|
+
export const DefaultEnvironmentVariableProvider = () => Provider.effect(DefaultEnvironmentVariable, Effect.gen(function* () {
|
|
58
|
+
const api = yield* ManagementApi;
|
|
59
|
+
return {
|
|
60
|
+
stables: ["projectId", "name", "deploymentType"],
|
|
61
|
+
diff: ({ olds, news }) => {
|
|
62
|
+
if (!isResolved(news))
|
|
63
|
+
return Effect.succeed(undefined);
|
|
64
|
+
// Otherwise undefined: the engine updates when any prop changed and
|
|
65
|
+
// compares a Redacted value by content.
|
|
66
|
+
return Effect.succeed(olds.projectId !== news.projectId ||
|
|
67
|
+
olds.name !== news.name ||
|
|
68
|
+
olds.deploymentType !== news.deploymentType
|
|
69
|
+
? { action: "replace" }
|
|
70
|
+
: undefined);
|
|
71
|
+
},
|
|
72
|
+
read: Effect.fn(function* ({ olds }) {
|
|
73
|
+
// 404 ProjectNotFound: the project no longer exists, so neither does the default.
|
|
74
|
+
const list = yield* absentAsUndefined(listDefaults(api, olds.projectId, olds.name, olds.deploymentType));
|
|
75
|
+
if (list === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
return findDefault(list, olds.projectId, olds.name, olds.deploymentType);
|
|
78
|
+
}),
|
|
79
|
+
reconcile: Effect.fn(function* ({ news }) {
|
|
80
|
+
yield* updateDefault(api, news.projectId, news.name, news.deploymentType, news.value);
|
|
81
|
+
return {
|
|
82
|
+
projectId: news.projectId,
|
|
83
|
+
name: news.name,
|
|
84
|
+
deploymentType: news.deploymentType,
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
delete: Effect.fn(function* ({ output }) {
|
|
88
|
+
// Removing an absent default succeeds; 404 ProjectNotFound means the project is gone.
|
|
89
|
+
yield* absentAsUndefined(updateDefault(api, output.projectId, output.name, output.deploymentType, null));
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
}));
|
|
93
|
+
//# sourceMappingURL=DefaultEnvironmentVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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