alchemy 0.30.0 → 0.31.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/bin/alchemy.mjs +17 -12
- package/bin/create-alchemy.ts +17 -11
- package/lib/cloudflare/bindings.d.ts +24 -4
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bindings.js.map +1 -1
- package/lib/cloudflare/bound.d.ts +3 -2
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/queue.d.ts +24 -0
- package/lib/cloudflare/queue.d.ts.map +1 -1
- package/lib/cloudflare/queue.js +24 -0
- package/lib/cloudflare/queue.js.map +1 -1
- package/lib/cloudflare/secret-key.d.ts +120 -0
- package/lib/cloudflare/secret-key.d.ts.map +1 -0
- package/lib/cloudflare/secret-key.js +92 -0
- package/lib/cloudflare/secret-key.js.map +1 -0
- package/lib/cloudflare/secret.d.ts +9 -5
- package/lib/cloudflare/secret.d.ts.map +1 -1
- package/lib/cloudflare/secret.js +13 -5
- package/lib/cloudflare/secret.js.map +1 -1
- package/lib/cloudflare/secrets-store.d.ts +3 -0
- package/lib/cloudflare/secrets-store.d.ts.map +1 -1
- package/lib/cloudflare/secrets-store.js +3 -3
- package/lib/cloudflare/secrets-store.js.map +1 -1
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +11 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +30 -2
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.js +3 -0
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/secret.d.ts +5 -5
- package/lib/secret.d.ts.map +1 -1
- package/lib/secret.js.map +1 -1
- package/lib/serde.d.ts +5 -1
- package/lib/serde.d.ts.map +1 -1
- package/lib/serde.js +9 -2
- package/lib/serde.js.map +1 -1
- package/package.json +18 -17
- package/src/cloudflare/bindings.ts +34 -2
- package/src/cloudflare/bound.ts +36 -33
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/queue.ts +24 -0
- package/src/cloudflare/secret-key.ts +143 -0
- package/src/cloudflare/secret.ts +55 -41
- package/src/cloudflare/secrets-store.ts +4 -5
- package/src/cloudflare/worker-metadata.ts +10 -0
- package/src/cloudflare/worker.ts +30 -2
- package/src/cloudflare/wrangler.json.ts +2 -0
- package/src/secret.ts +7 -7
- package/src/serde.ts +40 -20
package/lib/serde.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde.d.ts","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EAEX,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAW,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAY,MAAM,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAWpC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SACzB,SAAS,GACT,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,CAAC,GACD,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GACtB;IACE,SAAS,EAAE,MAAM,CAAC;CACnB,GACD,CAAC,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"serde.d.ts","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EAEX,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAW,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAY,MA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,EACZ,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CACjC,GACA,OAAO,CAAC,GAAG,CAAC,CAwEd;AAYD,wBAAsB,WAAW,CAC/B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KACnB,SAAS,GACT;QACE,KAAK,EAAE,GAAG,CAAC;KACZ,CAAC;CACP,GACA,OAAO,CAAC,GAAG,CAAC,CA+Cd"}
|
package/lib/serde.js
CHANGED
|
@@ -49,7 +49,11 @@ export async function serialize(scope, value, options) {
|
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
51
|
"@secret": options?.encrypt !== false
|
|
52
|
-
?
|
|
52
|
+
? typeof value.unencrypted === "string"
|
|
53
|
+
? await encrypt(value.unencrypted, scope.password)
|
|
54
|
+
: {
|
|
55
|
+
data: await encrypt(JSON.stringify(value.unencrypted), scope.password),
|
|
56
|
+
}
|
|
53
57
|
: value.unencrypted,
|
|
54
58
|
};
|
|
55
59
|
}
|
|
@@ -113,11 +117,14 @@ export async function deserialize(scope, value, options) {
|
|
|
113
117
|
return await Promise.all(value.map(async (item) => await deserialize(scope, item, options)));
|
|
114
118
|
}
|
|
115
119
|
if (value && typeof value === "object") {
|
|
116
|
-
if (
|
|
120
|
+
if (value["@secret"]) {
|
|
117
121
|
if (!scope.password) {
|
|
118
122
|
throw new Error("Cannot deserialize secret without password, did you forget to set password when initializing your alchemy app?\n" +
|
|
119
123
|
"See: https://alchemy.run/docs/concepts/secret.html#encryption-password");
|
|
120
124
|
}
|
|
125
|
+
if (typeof value["@secret"] === "object") {
|
|
126
|
+
return new Secret(JSON.parse(await decryptWithKey(value["@secret"].data, scope.password)));
|
|
127
|
+
}
|
|
121
128
|
return new Secret(await decryptWithKey(value["@secret"], scope.password));
|
|
122
129
|
}
|
|
123
130
|
else if ("@schema" in value) {
|
package/lib/serde.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serde.js","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI/C,yCAAyC;AACzC,SAAS,MAAM,CAAC,KAAU;IACxB,OAAO,CACL,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CACzC,CAAC;AACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"serde.js","sourceRoot":"","sources":["../src/serde.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI/C,yCAAyC;AACzC,SAAS,MAAM,CAAC,KAAU;IACxB,OAAO,CACL,KAAK;QACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CACzC,CAAC;AACJ,CAAC;AAoDD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAAY;IAC/C,MAAM,GAAG,GAAoB,EAAE,CAAC;IAEhC,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAE7B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,CAAC,mCAAmC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./lib/index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -113,7 +113,23 @@
|
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"
|
|
116
|
+
"@aws-sdk/credential-providers": "^3.0.0",
|
|
117
|
+
"@cloudflare/unenv-preset": "^2.3.1",
|
|
118
|
+
"@cloudflare/workers-shared": "^0.17.5",
|
|
119
|
+
"@iarna/toml": "^2.2.5",
|
|
120
|
+
"@smithy/node-config-provider": "^4.0.0",
|
|
121
|
+
"@swc/core": "^1.11.24",
|
|
122
|
+
"aws4fetch": "^1.0.20",
|
|
123
|
+
"diff": "^8.0.2",
|
|
124
|
+
"esbuild": "^0.25.1",
|
|
125
|
+
"fast-json-patch": "^3.1.1",
|
|
126
|
+
"glob": "^10.0.0",
|
|
127
|
+
"jszip": "^3.0.0",
|
|
128
|
+
"kleur": "^4.1.5",
|
|
129
|
+
"libsodium-wrappers": "^0.7.15",
|
|
130
|
+
"turndown": "^7.0.0",
|
|
131
|
+
"unenv": "2.0.0-rc.15",
|
|
132
|
+
"yaml": "^2.0.0"
|
|
117
133
|
},
|
|
118
134
|
"peerDependencies": {
|
|
119
135
|
"@ai-sdk/openai": "^1.1.9",
|
|
@@ -128,29 +144,14 @@
|
|
|
128
144
|
"@aws-sdk/client-sqs": "^3.0.0",
|
|
129
145
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
130
146
|
"@aws-sdk/client-sts": "^3.0.0",
|
|
131
|
-
"@aws-sdk/credential-providers": "^3.0.0",
|
|
132
|
-
"@smithy/node-config-provider": "^4.0.0",
|
|
133
|
-
"@cloudflare/unenv-preset": "^2.3.1",
|
|
134
|
-
"@cloudflare/workers-shared": "^0.17.5",
|
|
135
|
-
"@iarna/toml": "^2.2.5",
|
|
136
147
|
"@octokit/rest": "^21.1.1",
|
|
137
|
-
"@swc/core": "^1.11.24",
|
|
138
148
|
"ai": "^4.0.0",
|
|
139
149
|
"arktype": "^2.0.0",
|
|
140
|
-
"aws4fetch": "^1.0.20",
|
|
141
150
|
"cloudflare": "^4.0.0",
|
|
142
|
-
"diff": "^8.0.2",
|
|
143
151
|
"dofs": "^0.0.1",
|
|
144
|
-
"esbuild": "^0.25.1",
|
|
145
|
-
"fast-json-patch": "^3.1.1",
|
|
146
|
-
"glob": "^10.0.0",
|
|
147
152
|
"hono": "^4.0.0",
|
|
148
|
-
"jszip": "^3.0.0",
|
|
149
|
-
"libsodium-wrappers": "^0.7.15",
|
|
150
153
|
"prettier": "^3.0.0",
|
|
151
154
|
"stripe": "^17.0.0",
|
|
152
|
-
"turndown": "^7.0.0",
|
|
153
|
-
"yaml": "^2.0.0",
|
|
154
155
|
"zod": "^3.0.0"
|
|
155
156
|
},
|
|
156
157
|
"devDependencies": {
|
|
@@ -15,16 +15,17 @@ import type { D1DatabaseResource } from "./d1-database.ts";
|
|
|
15
15
|
import type { DispatchNamespaceResource } from "./dispatch-namespace.ts";
|
|
16
16
|
import type { DurableObjectNamespace } from "./durable-object-namespace.ts";
|
|
17
17
|
import type { HyperdriveResource } from "./hyperdrive.ts";
|
|
18
|
+
import type { Images } from "./images.ts";
|
|
18
19
|
import type { KVNamespaceResource } from "./kv-namespace.ts";
|
|
19
20
|
import type { PipelineResource } from "./pipeline.ts";
|
|
20
21
|
import type { QueueResource } from "./queue.ts";
|
|
22
|
+
import type { SecretKey } from "./secret-key.ts";
|
|
23
|
+
import type { Secret as CloudflareSecret } from "./secret.ts";
|
|
21
24
|
import type { VectorizeIndexResource } from "./vectorize-index.ts";
|
|
22
25
|
import type { VersionMetadata } from "./version-metadata.ts";
|
|
23
26
|
import type { WorkerStub } from "./worker-stub.ts";
|
|
24
27
|
import type { Worker, WorkerRef } from "./worker.ts";
|
|
25
28
|
import type { Workflow } from "./workflow.ts";
|
|
26
|
-
import type { Images } from "./images.ts";
|
|
27
|
-
import type { Secret as CloudflareSecret } from "./secret.ts";
|
|
28
29
|
|
|
29
30
|
export type Bindings = {
|
|
30
31
|
[bindingName: string]: Binding;
|
|
@@ -59,6 +60,7 @@ export type Binding =
|
|
|
59
60
|
id: string;
|
|
60
61
|
}
|
|
61
62
|
| Secret
|
|
63
|
+
| SecretKey
|
|
62
64
|
| string
|
|
63
65
|
| VectorizeIndexResource
|
|
64
66
|
| Worker
|
|
@@ -105,6 +107,7 @@ export type WorkerBindingSpec =
|
|
|
105
107
|
| WorkerBindingPlainText
|
|
106
108
|
| WorkerBindingQueue
|
|
107
109
|
| WorkerBindingR2Bucket
|
|
110
|
+
| WorkerBindingSecretKey
|
|
108
111
|
| WorkerBindingSecretText
|
|
109
112
|
| WorkerBindingSecretsStore
|
|
110
113
|
| WorkerBindingSecretsStoreSecret
|
|
@@ -291,6 +294,35 @@ export interface WorkerBindingR2Bucket {
|
|
|
291
294
|
bucket_name: string;
|
|
292
295
|
}
|
|
293
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Secret Key binding type
|
|
299
|
+
*/
|
|
300
|
+
export interface WorkerBindingSecretKey {
|
|
301
|
+
/** The name of the binding */
|
|
302
|
+
name: string;
|
|
303
|
+
/** Type identifier for Secret Key binding */
|
|
304
|
+
type: "secret_key";
|
|
305
|
+
/** Algorithm-specific key parameters */
|
|
306
|
+
algorithm: unknown;
|
|
307
|
+
/** Data format of the key */
|
|
308
|
+
format: "raw" | "pkcs8" | "spki" | "jwk";
|
|
309
|
+
/** Allowed operations with the key */
|
|
310
|
+
usages: Array<
|
|
311
|
+
| "encrypt"
|
|
312
|
+
| "decrypt"
|
|
313
|
+
| "sign"
|
|
314
|
+
| "verify"
|
|
315
|
+
| "deriveKey"
|
|
316
|
+
| "deriveBits"
|
|
317
|
+
| "wrapKey"
|
|
318
|
+
| "unwrapKey"
|
|
319
|
+
>;
|
|
320
|
+
/** Base64-encoded key data. Required if format is "raw", "pkcs8", or "spki" */
|
|
321
|
+
key_base64?: string;
|
|
322
|
+
/** Key data in JSON Web Key format. Required if format is "jwk" */
|
|
323
|
+
key_jwk?: unknown;
|
|
324
|
+
}
|
|
325
|
+
|
|
294
326
|
/**
|
|
295
327
|
* Secret Text binding type
|
|
296
328
|
*/
|
package/src/cloudflare/bound.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Pipeline } from "cloudflare:pipelines";
|
|
2
2
|
import type { Secret } from "../secret.ts";
|
|
3
|
-
import type { Secret as CloudflareSecret } from "./secret.ts";
|
|
4
3
|
import type { AiGatewayResource as _AiGateway } from "./ai-gateway.ts";
|
|
5
4
|
import type { Ai as _Ai } from "./ai.ts";
|
|
6
5
|
import type { AnalyticsEngineDataset as _AnalyticsEngineDataset } from "./analytics-engine.ts";
|
|
@@ -15,6 +14,8 @@ import type { HyperdriveResource as _Hyperdrive } from "./hyperdrive.ts";
|
|
|
15
14
|
import type { Images as _Images } from "./images.ts";
|
|
16
15
|
import type { PipelineResource as _Pipeline } from "./pipeline.ts";
|
|
17
16
|
import type { QueueResource as _Queue } from "./queue.ts";
|
|
17
|
+
import type { SecretKey } from "./secret-key.ts";
|
|
18
|
+
import type { Secret as CloudflareSecret } from "./secret.ts";
|
|
18
19
|
import type { VectorizeIndexResource as _VectorizeIndex } from "./vectorize-index.ts";
|
|
19
20
|
import type { VersionMetadata as _VersionMetadata } from "./version-metadata.ts";
|
|
20
21
|
import type { Worker as _Worker, WorkerRef } from "./worker.ts";
|
|
@@ -46,35 +47,37 @@ export type Bound<T extends Binding> = T extends _DurableObjectNamespace<
|
|
|
46
47
|
: T extends Secret
|
|
47
48
|
? string
|
|
48
49
|
: T extends CloudflareSecret
|
|
49
|
-
?
|
|
50
|
-
: T extends
|
|
51
|
-
?
|
|
52
|
-
: T extends
|
|
53
|
-
?
|
|
54
|
-
: T extends
|
|
55
|
-
?
|
|
56
|
-
: T extends
|
|
57
|
-
?
|
|
58
|
-
: T extends
|
|
59
|
-
?
|
|
60
|
-
: T extends
|
|
61
|
-
?
|
|
62
|
-
: T extends
|
|
63
|
-
?
|
|
64
|
-
: T extends
|
|
65
|
-
?
|
|
66
|
-
: T extends
|
|
67
|
-
?
|
|
68
|
-
: T extends
|
|
69
|
-
?
|
|
70
|
-
: T extends
|
|
71
|
-
?
|
|
72
|
-
: T extends
|
|
73
|
-
?
|
|
74
|
-
: T extends
|
|
75
|
-
?
|
|
76
|
-
: T extends
|
|
77
|
-
?
|
|
78
|
-
: T extends
|
|
79
|
-
?
|
|
80
|
-
:
|
|
50
|
+
? SecretsStoreSecret
|
|
51
|
+
: T extends SecretKey
|
|
52
|
+
? CryptoKey
|
|
53
|
+
: T extends Assets
|
|
54
|
+
? Service
|
|
55
|
+
: T extends _Workflow<infer P>
|
|
56
|
+
? Workflow<P>
|
|
57
|
+
: T extends D1DatabaseResource
|
|
58
|
+
? D1Database
|
|
59
|
+
: T extends DispatchNamespaceResource
|
|
60
|
+
? { get(name: string): Fetcher }
|
|
61
|
+
: T extends _VectorizeIndex
|
|
62
|
+
? VectorizeIndex
|
|
63
|
+
: T extends _Queue<infer Body>
|
|
64
|
+
? Queue<Body>
|
|
65
|
+
: T extends _AnalyticsEngineDataset
|
|
66
|
+
? AnalyticsEngineDataset
|
|
67
|
+
: T extends _Pipeline<infer R>
|
|
68
|
+
? Pipeline<R>
|
|
69
|
+
: T extends string
|
|
70
|
+
? string
|
|
71
|
+
: T extends BrowserRendering
|
|
72
|
+
? Fetcher
|
|
73
|
+
: T extends _Ai<infer M>
|
|
74
|
+
? Ai<M>
|
|
75
|
+
: T extends _Images
|
|
76
|
+
? ImagesBinding
|
|
77
|
+
: T extends _VersionMetadata
|
|
78
|
+
? WorkerVersionMetadata
|
|
79
|
+
: T extends Self
|
|
80
|
+
? Service
|
|
81
|
+
: T extends Json<infer T>
|
|
82
|
+
? T
|
|
83
|
+
: Service;
|
package/src/cloudflare/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from "./react-router.ts";
|
|
|
39
39
|
export * from "./redwood.ts";
|
|
40
40
|
export * from "./route.ts";
|
|
41
41
|
export * from "./secret.ts";
|
|
42
|
+
export * from "./secret-key.ts";
|
|
42
43
|
export * from "./secrets-store.ts";
|
|
43
44
|
export * from "./sveltekit.ts";
|
|
44
45
|
export * from "./tanstack-start.ts";
|
package/src/cloudflare/queue.ts
CHANGED
|
@@ -176,6 +176,30 @@ export type Queue<Body = unknown> = QueueResource<Body> &
|
|
|
176
176
|
* dlq: dlqQueue
|
|
177
177
|
* });
|
|
178
178
|
*
|
|
179
|
+
* @example
|
|
180
|
+
* // Create a queue and configure Worker consumer with custom settings
|
|
181
|
+
* const processingQueue = await Queue("processing-queue", {
|
|
182
|
+
* name: "processing-queue"
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* const processingWorker = await Worker("processor", {
|
|
186
|
+
* entrypoint: "./src/processor.ts",
|
|
187
|
+
* bindings: {
|
|
188
|
+
* QUEUE: processingQueue // Producer: bind queue for sending messages
|
|
189
|
+
* },
|
|
190
|
+
* eventSources: [{ // Consumer: configure processing settings
|
|
191
|
+
* queue: processingQueue,
|
|
192
|
+
* settings: {
|
|
193
|
+
* batchSize: 25, // Process 25 messages at once
|
|
194
|
+
* maxConcurrency: 5, // Allow 5 concurrent invocations
|
|
195
|
+
* maxRetries: 3, // Retry failed messages up to 3 times
|
|
196
|
+
* maxWaitTimeMs: 1500, // Wait up to 1.5 seconds to fill a batch
|
|
197
|
+
* retryDelay: 45, // Wait 45 seconds before retrying failed messages
|
|
198
|
+
* deadLetterQueue: "failed-processing" // Send failed messages to DLQ
|
|
199
|
+
* }
|
|
200
|
+
* }]
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
179
203
|
* @see https://developers.cloudflare.com/queues/
|
|
180
204
|
*/
|
|
181
205
|
export async function Queue<Body = unknown>(
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SecretKey binding for Cloudflare Workers
|
|
3
|
+
*
|
|
4
|
+
* A data class that represents a secret key binding with cryptographic properties.
|
|
5
|
+
* Keys are securely stored and exposed as CryptoKey objects for use with the Web Crypto API.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Create an RSA signing key from a JWK format:
|
|
9
|
+
* const keyPair = await crypto.subtle.generateKey(
|
|
10
|
+
* {
|
|
11
|
+
* name: "RSA-PSS",
|
|
12
|
+
* modulusLength: 2048,
|
|
13
|
+
* publicExponent: new Uint8Array([1, 0, 1]),
|
|
14
|
+
* hash: "SHA-256",
|
|
15
|
+
* },
|
|
16
|
+
* true,
|
|
17
|
+
* ["sign", "verify"]
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* const privateKeyJwk = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
|
|
21
|
+
*
|
|
22
|
+
* const signingKey = new SecretKey({
|
|
23
|
+
* algorithm: { name: "RSA-PSS", hash: "SHA-256" },
|
|
24
|
+
* format: "jwk",
|
|
25
|
+
* usages: ["sign"],
|
|
26
|
+
* key_jwk: secret(privateKeyJwk),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Create an AES encryption key from raw bytes:
|
|
31
|
+
* const aesKey = await crypto.subtle.generateKey(
|
|
32
|
+
* { name: "AES-GCM", length: 256 },
|
|
33
|
+
* true,
|
|
34
|
+
* ["encrypt", "decrypt"]
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* const keyData = await crypto.subtle.exportKey("raw", aesKey);
|
|
38
|
+
* const keyBase64 = btoa(String.fromCharCode(...new Uint8Array(keyData)));
|
|
39
|
+
*
|
|
40
|
+
* const encryptionKey = new SecretKey({
|
|
41
|
+
* algorithm: { name: "AES-GCM" },
|
|
42
|
+
* format: "raw",
|
|
43
|
+
* usages: ["encrypt", "decrypt"],
|
|
44
|
+
* key_base64: secret(keyBase64),
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Create an ECDSA key from PKCS#8 format:
|
|
49
|
+
* const ecdsaKey = new SecretKey({
|
|
50
|
+
* algorithm: { name: "ECDSA", namedCurve: "P-256" },
|
|
51
|
+
* format: "pkcs8",
|
|
52
|
+
* usages: ["sign"],
|
|
53
|
+
* key_base64: secret("MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg..."),
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Create an HMAC key for message authentication:
|
|
58
|
+
* const hmacKey = await crypto.subtle.generateKey(
|
|
59
|
+
* { name: "HMAC", hash: "SHA-256" },
|
|
60
|
+
* true,
|
|
61
|
+
* ["sign", "verify"]
|
|
62
|
+
* );
|
|
63
|
+
*
|
|
64
|
+
* const keyData = await crypto.subtle.exportKey("raw", hmacKey);
|
|
65
|
+
* const keyBase64 = btoa(String.fromCharCode(...new Uint8Array(keyData)));
|
|
66
|
+
*
|
|
67
|
+
* const macKey = new SecretKey({
|
|
68
|
+
* algorithm: { name: "HMAC", hash: "SHA-256" },
|
|
69
|
+
* format: "raw",
|
|
70
|
+
* usages: ["sign", "verify"],
|
|
71
|
+
* key_base64: secret(keyBase64),
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* @see https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/
|
|
75
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#keyusages
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
import type { Secret } from "../secret.ts";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Data format of the key
|
|
82
|
+
*/
|
|
83
|
+
export type SecretKeyFormat = "raw" | "pkcs8" | "spki" | "jwk";
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Allowed operations with the key
|
|
87
|
+
*/
|
|
88
|
+
export type SecretKeyUsage =
|
|
89
|
+
| "encrypt"
|
|
90
|
+
| "decrypt"
|
|
91
|
+
| "sign"
|
|
92
|
+
| "verify"
|
|
93
|
+
| "deriveKey"
|
|
94
|
+
| "deriveBits"
|
|
95
|
+
| "wrapKey"
|
|
96
|
+
| "unwrapKey";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* SecretKey binding properties
|
|
100
|
+
*/
|
|
101
|
+
export interface SecretKeyProps {
|
|
102
|
+
/**
|
|
103
|
+
* Algorithm-specific key parameters
|
|
104
|
+
*/
|
|
105
|
+
algorithm: unknown;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Data format of the key
|
|
109
|
+
*/
|
|
110
|
+
format: SecretKeyFormat;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Allowed operations with the key
|
|
114
|
+
*/
|
|
115
|
+
usages: SecretKeyUsage[];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Base64-encoded key data. Required if format is "raw", "pkcs8", or "spki"
|
|
119
|
+
*/
|
|
120
|
+
key_base64?: Secret;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Key data in JSON Web Key format. Required if format is "jwk"
|
|
124
|
+
*/
|
|
125
|
+
key_jwk?: Secret<JsonWebKey>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export class SecretKey {
|
|
129
|
+
readonly type = "secret_key";
|
|
130
|
+
readonly algorithm: unknown;
|
|
131
|
+
readonly format: SecretKeyFormat;
|
|
132
|
+
readonly usages: SecretKeyUsage[];
|
|
133
|
+
readonly key_base64?: Secret;
|
|
134
|
+
readonly key_jwk?: Secret<JsonWebKey>;
|
|
135
|
+
|
|
136
|
+
constructor(props: SecretKeyProps) {
|
|
137
|
+
this.algorithm = props.algorithm;
|
|
138
|
+
this.format = props.format;
|
|
139
|
+
this.usages = props.usages;
|
|
140
|
+
this.key_base64 = props.key_base64;
|
|
141
|
+
this.key_jwk = props.key_jwk;
|
|
142
|
+
}
|
|
143
|
+
}
|
package/src/cloudflare/secret.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type CloudflareApi,
|
|
11
11
|
type CloudflareApiOptions,
|
|
12
12
|
} from "./api.ts";
|
|
13
|
-
import
|
|
13
|
+
import { findSecretsStoreByName, SecretsStore } from "./secrets-store.ts";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Properties for creating or updating a Secret in a Secrets Store (internal interface)
|
|
@@ -18,8 +18,10 @@ import type { SecretsStore } from "./secrets-store.ts";
|
|
|
18
18
|
interface _SecretProps extends CloudflareApiOptions {
|
|
19
19
|
/**
|
|
20
20
|
* The secrets store to add this secret to
|
|
21
|
+
*
|
|
22
|
+
* @default - the default-secret-store
|
|
21
23
|
*/
|
|
22
|
-
store
|
|
24
|
+
store?: SecretsStore<any>;
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* The secret value to store (must be an AlchemySecret for security)
|
|
@@ -41,8 +43,10 @@ interface _SecretProps extends CloudflareApiOptions {
|
|
|
41
43
|
export interface SecretProps extends CloudflareApiOptions {
|
|
42
44
|
/**
|
|
43
45
|
* The secrets store to add this secret to
|
|
46
|
+
*
|
|
47
|
+
* @default - the default-secret-store
|
|
44
48
|
*/
|
|
45
|
-
store
|
|
49
|
+
store?: SecretsStore<any>;
|
|
46
50
|
|
|
47
51
|
/**
|
|
48
52
|
* The secret value to store
|
|
@@ -71,39 +75,38 @@ export function isSecret(resource: Resource): resource is Secret {
|
|
|
71
75
|
return resource[ResourceKind] === "cloudflare::Secret";
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
78
|
+
export type Secret = Resource<"cloudflare::Secret"> &
|
|
79
|
+
Omit<_SecretProps, "delete"> & {
|
|
80
|
+
/**
|
|
81
|
+
* The binding type for Cloudflare Workers
|
|
82
|
+
*/
|
|
83
|
+
type: "secrets_store_secret";
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The name of the secret
|
|
87
|
+
*/
|
|
88
|
+
name: string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The unique identifier of the secrets store this secret belongs to
|
|
92
|
+
*/
|
|
93
|
+
storeId: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The secret value (as an alchemy Secret instance)
|
|
97
|
+
*/
|
|
98
|
+
value: AlchemySecret;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Timestamp when the secret was created
|
|
102
|
+
*/
|
|
103
|
+
createdAt: number;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Timestamp when the secret was last modified
|
|
107
|
+
*/
|
|
108
|
+
modifiedAt: number;
|
|
109
|
+
};
|
|
107
110
|
|
|
108
111
|
/**
|
|
109
112
|
* A Cloudflare Secret represents an individual secret stored in a Secrets Store.
|
|
@@ -179,9 +182,20 @@ const _Secret = Resource(
|
|
|
179
182
|
): Promise<Secret> {
|
|
180
183
|
const api = await createCloudflareApi(props);
|
|
181
184
|
|
|
185
|
+
const storeId =
|
|
186
|
+
props.store?.id ??
|
|
187
|
+
(await findSecretsStoreByName(api, SecretsStore.Default))?.id ??
|
|
188
|
+
(
|
|
189
|
+
await SecretsStore("default-store", {
|
|
190
|
+
name: SecretsStore.Default,
|
|
191
|
+
adopt: true,
|
|
192
|
+
delete: false,
|
|
193
|
+
})
|
|
194
|
+
)?.id!;
|
|
195
|
+
|
|
182
196
|
if (this.phase === "delete") {
|
|
183
197
|
if (props.delete !== false) {
|
|
184
|
-
await deleteSecret(api,
|
|
198
|
+
await deleteSecret(api, storeId, name);
|
|
185
199
|
}
|
|
186
200
|
return this.destroy();
|
|
187
201
|
}
|
|
@@ -192,12 +206,12 @@ const _Secret = Resource(
|
|
|
192
206
|
: Date.now();
|
|
193
207
|
|
|
194
208
|
// Insert or update the secret
|
|
195
|
-
await insertSecret(api,
|
|
209
|
+
await insertSecret(api, storeId, name, props.value);
|
|
196
210
|
|
|
197
211
|
return this({
|
|
198
212
|
type: "secrets_store_secret",
|
|
199
213
|
name,
|
|
200
|
-
storeId
|
|
214
|
+
storeId,
|
|
201
215
|
store: props.store,
|
|
202
216
|
value: props.value,
|
|
203
217
|
createdAt,
|
|
@@ -317,10 +331,10 @@ export async function deleteSecret(
|
|
|
317
331
|
storeId: string,
|
|
318
332
|
secretName: string,
|
|
319
333
|
): Promise<void> {
|
|
334
|
+
const secretId = await getSecretId(api, storeId, secretName);
|
|
320
335
|
const response = await api.delete(
|
|
321
|
-
`/accounts/${api.accountId}/secrets_store/stores/${storeId}/secrets`,
|
|
336
|
+
`/accounts/${api.accountId}/secrets_store/stores/${storeId}/secrets/${secretId}`,
|
|
322
337
|
{
|
|
323
|
-
body: JSON.stringify([secretName]),
|
|
324
338
|
headers: {
|
|
325
339
|
"Content-Type": "application/json",
|
|
326
340
|
},
|
|
@@ -168,6 +168,10 @@ export async function SecretsStore<
|
|
|
168
168
|
return _SecretsStore(name, normalizedProps);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
export namespace SecretsStore {
|
|
172
|
+
export const Default = "default_secrets_store";
|
|
173
|
+
}
|
|
174
|
+
|
|
171
175
|
const _SecretsStore = Resource("cloudflare::SecretsStore", async function <
|
|
172
176
|
S extends Record<string, Secret> | undefined = undefined,
|
|
173
177
|
>(this: Context<SecretsStore<S>>, id: string, props: SecretsStoreProps<S>): Promise<
|
|
@@ -206,17 +210,12 @@ const _SecretsStore = Resource("cloudflare::SecretsStore", async function <
|
|
|
206
210
|
} else {
|
|
207
211
|
// If adopt is true, first check if a store with this name already exists
|
|
208
212
|
if (props.adopt) {
|
|
209
|
-
console.log(`Checking for existing secrets store '${name}' to adopt`);
|
|
210
213
|
const existingStore = await findSecretsStoreByName(api, name);
|
|
211
214
|
|
|
212
215
|
if (existingStore) {
|
|
213
|
-
console.log(`Found existing secrets store '${name}', adopting it`);
|
|
214
216
|
storeId = existingStore.id;
|
|
215
217
|
createdAt = existingStore.createdAt || Date.now();
|
|
216
218
|
} else {
|
|
217
|
-
console.log(
|
|
218
|
-
`No existing secrets store '${name}' found, creating new one`,
|
|
219
|
-
);
|
|
220
219
|
const { id } = await createSecretsStore(api, {
|
|
221
220
|
...props,
|
|
222
221
|
name,
|