alchemy 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +324 -0
- package/lib/$.d.ts +8 -3
- package/lib/$.d.ts.map +1 -1
- package/lib/$.js +38 -27
- package/lib/$.js.map +1 -1
- package/lib/alchemize.d.ts.map +1 -1
- package/lib/alchemize.js +7 -0
- package/lib/alchemize.js.map +1 -1
- package/lib/apply.d.ts +2 -2
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +3 -3
- package/lib/apply.js.map +1 -1
- package/lib/aws/index.d.ts +1 -0
- package/lib/aws/index.d.ts.map +1 -1
- package/lib/aws/index.js +1 -0
- package/lib/aws/index.js.map +1 -1
- package/lib/aws/ses.d.ts +75 -0
- package/lib/aws/ses.d.ts.map +1 -0
- package/lib/aws/ses.js +197 -0
- package/lib/aws/ses.js.map +1 -0
- package/lib/cloudflare/api.d.ts +88 -0
- package/lib/cloudflare/api.d.ts.map +1 -0
- package/lib/cloudflare/api.js +184 -0
- package/lib/cloudflare/api.js.map +1 -0
- package/lib/cloudflare/asset-manifest.d.ts +15 -0
- package/lib/cloudflare/asset-manifest.d.ts.map +1 -0
- package/lib/cloudflare/asset-manifest.js +2 -0
- package/lib/cloudflare/asset-manifest.js.map +1 -0
- package/lib/cloudflare/auth.d.ts +52 -0
- package/lib/cloudflare/auth.d.ts.map +1 -0
- package/lib/cloudflare/auth.js +114 -0
- package/lib/cloudflare/auth.js.map +1 -0
- package/lib/cloudflare/bindings.d.ts +254 -0
- package/lib/cloudflare/bindings.d.ts.map +1 -0
- package/lib/cloudflare/bindings.js +2 -0
- package/lib/cloudflare/bindings.js.map +1 -0
- package/lib/cloudflare/durable-object-namespace.d.ts +23 -0
- package/lib/cloudflare/durable-object-namespace.d.ts.map +1 -0
- package/lib/cloudflare/durable-object-namespace.js +26 -0
- package/lib/cloudflare/durable-object-namespace.js.map +1 -0
- package/lib/cloudflare/generate-asset-manifest.d.ts +3 -0
- package/lib/cloudflare/generate-asset-manifest.d.ts.map +1 -0
- package/lib/cloudflare/generate-asset-manifest.js +69 -0
- package/lib/cloudflare/generate-asset-manifest.js.map +1 -0
- package/lib/cloudflare/index.d.ts +7 -0
- package/lib/cloudflare/index.d.ts.map +1 -0
- package/lib/cloudflare/index.js +7 -0
- package/lib/cloudflare/index.js.map +1 -0
- package/lib/cloudflare/kv-namespace.d.ts +61 -0
- package/lib/cloudflare/kv-namespace.d.ts.map +1 -0
- package/lib/cloudflare/kv-namespace.js +93 -0
- package/lib/cloudflare/kv-namespace.js.map +1 -0
- package/lib/cloudflare/state.d.ts +83 -0
- package/lib/cloudflare/state.d.ts.map +1 -0
- package/lib/cloudflare/state.js +109 -0
- package/lib/cloudflare/state.js.map +1 -0
- package/lib/cloudflare/static-site-router.d.ts +19 -0
- package/lib/cloudflare/static-site-router.d.ts.map +1 -0
- package/lib/cloudflare/static-site-router.js +110 -0
- package/lib/cloudflare/static-site-router.js.map +1 -0
- package/lib/cloudflare/static-site.d.ts +166 -0
- package/lib/cloudflare/static-site.d.ts.map +1 -0
- package/lib/cloudflare/static-site.js +168 -0
- package/lib/cloudflare/static-site.js.map +1 -0
- package/lib/cloudflare/types.d.ts +52 -0
- package/lib/cloudflare/types.d.ts.map +1 -0
- package/lib/cloudflare/types.js +21 -0
- package/lib/cloudflare/types.js.map +1 -0
- package/lib/cloudflare/upload-asset-manifest.d.ts +12 -0
- package/lib/cloudflare/upload-asset-manifest.d.ts.map +1 -0
- package/lib/cloudflare/upload-asset-manifest.js +55 -0
- package/lib/cloudflare/upload-asset-manifest.js.map +1 -0
- package/lib/cloudflare/worker-metadata.d.ts +130 -0
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -0
- package/lib/cloudflare/worker-metadata.js +2 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -0
- package/lib/cloudflare/worker-migration.d.ts +110 -0
- package/lib/cloudflare/worker-migration.d.ts.map +1 -0
- package/lib/cloudflare/worker-migration.js +11 -0
- package/lib/cloudflare/worker-migration.js.map +1 -0
- package/lib/cloudflare/worker.d.ts +105 -0
- package/lib/cloudflare/worker.d.ts.map +1 -0
- package/lib/cloudflare/worker.js +358 -0
- package/lib/cloudflare/worker.js.map +1 -0
- package/lib/destroy.d.ts +1 -1
- package/lib/destroy.d.ts.map +1 -1
- package/lib/destroy.js +2 -1
- package/lib/destroy.js.map +1 -1
- package/lib/esbuild.d.ts +83 -1
- package/lib/esbuild.d.ts.map +1 -1
- package/lib/esbuild.js +27 -18
- package/lib/esbuild.js.map +1 -1
- package/lib/fs.d.ts +1 -1
- package/lib/global.d.ts +0 -2
- package/lib/global.d.ts.map +1 -1
- package/lib/global.js +3 -3
- package/lib/global.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/main.js +1 -1
- package/lib/main.js.map +1 -1
- package/lib/output.d.ts +18 -13
- package/lib/output.d.ts.map +1 -1
- package/lib/output.js +12 -5
- package/lib/output.js.map +1 -1
- package/lib/print.d.ts +7 -0
- package/lib/print.d.ts.map +1 -0
- package/lib/print.js +10 -0
- package/lib/print.js.map +1 -0
- package/lib/resource.d.ts +9 -4
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +127 -93
- package/lib/resource.js.map +1 -1
- package/lib/scope.d.ts +3 -0
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +4 -12
- package/lib/scope.js.map +1 -1
- package/lib/utils/content-type.d.ts +8 -0
- package/lib/utils/content-type.d.ts.map +1 -0
- package/lib/utils/content-type.js +41 -0
- package/lib/utils/content-type.js.map +1 -0
- package/package.json +27 -8
- package/src/$.ts +63 -30
- package/src/alchemize.ts +12 -0
- package/src/apply.ts +6 -6
- package/src/aws/index.ts +1 -0
- package/src/aws/ses.ts +346 -0
- package/src/cloudflare/api.ts +282 -0
- package/src/cloudflare/asset-manifest.ts +16 -0
- package/src/cloudflare/auth.ts +187 -0
- package/src/cloudflare/bindings.ts +297 -0
- package/src/cloudflare/durable-object-namespace.ts +43 -0
- package/src/cloudflare/generate-asset-manifest.ts +93 -0
- package/src/cloudflare/index.ts +6 -0
- package/src/cloudflare/kv-namespace.ts +195 -0
- package/src/cloudflare/state.ts +138 -0
- package/src/cloudflare/static-site-router.ts +150 -0
- package/src/cloudflare/static-site.ts +395 -0
- package/src/cloudflare/types.ts +71 -0
- package/src/cloudflare/upload-asset-manifest.ts +83 -0
- package/src/cloudflare/worker-metadata.ts +154 -0
- package/src/cloudflare/worker-migration.ts +145 -0
- package/src/cloudflare/worker.ts +666 -0
- package/src/destroy.ts +2 -2
- package/src/esbuild.ts +34 -22
- package/src/global.ts +1 -3
- package/src/index.ts +1 -1
- package/src/main.ts +1 -1
- package/src/output.ts +53 -37
- package/src/print.ts +18 -0
- package/src/resource.ts +163 -116
- package/src/scope.ts +7 -12
- package/src/utils/content-type.ts +42 -0
- package/lib/agent/ai.d.ts +0 -40
- package/lib/agent/ai.d.ts.map +0 -1
- package/lib/agent/ai.js +0 -132
- package/lib/agent/ai.js.map +0 -1
- package/lib/agent/anthropic.d.ts +0 -9
- package/lib/agent/anthropic.d.ts.map +0 -1
- package/lib/agent/anthropic.js +0 -25
- package/lib/agent/anthropic.js.map +0 -1
- package/lib/agent/dependencies.d.ts +0 -4
- package/lib/agent/dependencies.d.ts.map +0 -1
- package/lib/agent/dependencies.js +0 -48
- package/lib/agent/dependencies.js.map +0 -1
- package/lib/agent/file-context.d.ts +0 -13
- package/lib/agent/file-context.d.ts.map +0 -1
- package/lib/agent/file-context.js +0 -6
- package/lib/agent/file-context.js.map +0 -1
- package/lib/agent/index.d.ts +0 -10
- package/lib/agent/index.d.ts.map +0 -1
- package/lib/agent/index.js +0 -10
- package/lib/agent/index.js.map +0 -1
- package/lib/agent/model.d.ts +0 -8
- package/lib/agent/model.d.ts.map +0 -1
- package/lib/agent/model.js +0 -29
- package/lib/agent/model.js.map +0 -1
- package/lib/agent/module.d.ts +0 -81
- package/lib/agent/module.d.ts.map +0 -1
- package/lib/agent/module.js +0 -309
- package/lib/agent/module.js.map +0 -1
- package/lib/agent/openai.d.ts +0 -6
- package/lib/agent/openai.d.ts.map +0 -1
- package/lib/agent/openai.js +0 -41
- package/lib/agent/openai.js.map +0 -1
- package/lib/agent/program.d.ts +0 -12
- package/lib/agent/program.d.ts.map +0 -1
- package/lib/agent/program.js +0 -21
- package/lib/agent/program.js.map +0 -1
- package/lib/agent/prompts.d.ts +0 -4
- package/lib/agent/prompts.d.ts.map +0 -1
- package/lib/agent/prompts.js +0 -11
- package/lib/agent/prompts.js.map +0 -1
- package/lib/agent/scrape.d.ts +0 -71
- package/lib/agent/scrape.d.ts.map +0 -1
- package/lib/agent/scrape.js +0 -45
- package/lib/agent/scrape.js.map +0 -1
- package/lib/aws/auto/docs.d.ts +0 -11
- package/lib/aws/auto/docs.d.ts.map +0 -1
- package/lib/aws/auto/docs.js +0 -56
- package/lib/aws/auto/docs.js.map +0 -1
- package/lib/aws/auto/index.d.ts +0 -5
- package/lib/aws/auto/index.d.ts.map +0 -1
- package/lib/aws/auto/index.js +0 -5
- package/lib/aws/auto/index.js.map +0 -1
- package/lib/aws/auto/resource.d.ts +0 -24
- package/lib/aws/auto/resource.d.ts.map +0 -1
- package/lib/aws/auto/resource.js +0 -194
- package/lib/aws/auto/resource.js.map +0 -1
- package/lib/aws/auto/service.d.ts +0 -10
- package/lib/aws/auto/service.d.ts.map +0 -1
- package/lib/aws/auto/service.js +0 -34
- package/lib/aws/auto/service.js.map +0 -1
- package/lib/aws/auto/spec.d.ts +0 -83
- package/lib/aws/auto/spec.d.ts.map +0 -1
- package/lib/aws/auto/spec.js +0 -58
- package/lib/aws/auto/spec.js.map +0 -1
- package/lib/markdown/design.d.ts +0 -17
- package/lib/markdown/design.d.ts.map +0 -1
- package/lib/markdown/design.js +0 -92
- package/lib/markdown/design.js.map +0 -1
- package/lib/markdown/extract.d.ts +0 -7
- package/lib/markdown/extract.d.ts.map +0 -1
- package/lib/markdown/extract.js +0 -10
- package/lib/markdown/extract.js.map +0 -1
- package/lib/markdown/index.d.ts +0 -4
- package/lib/markdown/index.d.ts.map +0 -1
- package/lib/markdown/index.js +0 -4
- package/lib/markdown/index.js.map +0 -1
- package/lib/markdown/requirements.d.ts +0 -79
- package/lib/markdown/requirements.d.ts.map +0 -1
- package/lib/markdown/requirements.js +0 -105
- package/lib/markdown/requirements.js.map +0 -1
- package/lib/typescript/check-omission.d.ts +0 -2
- package/lib/typescript/check-omission.d.ts.map +0 -1
- package/lib/typescript/check-omission.js +0 -43
- package/lib/typescript/check-omission.js.map +0 -1
- package/lib/typescript/debug-type-errors.d.ts +0 -3
- package/lib/typescript/debug-type-errors.d.ts.map +0 -1
- package/lib/typescript/debug-type-errors.js +0 -35
- package/lib/typescript/debug-type-errors.js.map +0 -1
- package/lib/typescript/extract.d.ts +0 -7
- package/lib/typescript/extract.d.ts.map +0 -1
- package/lib/typescript/extract.js +0 -10
- package/lib/typescript/extract.js.map +0 -1
- package/lib/typescript/index.d.ts +0 -7
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/index.js +0 -7
- package/lib/typescript/index.js.map +0 -1
- package/lib/typescript/install-dependencies.d.ts +0 -29
- package/lib/typescript/install-dependencies.d.ts.map +0 -1
- package/lib/typescript/install-dependencies.js +0 -52
- package/lib/typescript/install-dependencies.js.map +0 -1
- package/lib/typescript/package.d.ts +0 -157
- package/lib/typescript/package.d.ts.map +0 -1
- package/lib/typescript/package.js +0 -115
- package/lib/typescript/package.js.map +0 -1
- package/lib/typescript/repair-omissions.d.ts +0 -3
- package/lib/typescript/repair-omissions.d.ts.map +0 -1
- package/lib/typescript/repair-omissions.js +0 -23
- package/lib/typescript/repair-omissions.js.map +0 -1
- package/lib/typescript/repair.d.ts +0 -3
- package/lib/typescript/repair.d.ts.map +0 -1
- package/lib/typescript/repair.js +0 -34
- package/lib/typescript/repair.js.map +0 -1
- package/lib/typescript/tsconfig.d.ts +0 -469
- package/lib/typescript/tsconfig.d.ts.map +0 -1
- package/lib/typescript/tsconfig.js +0 -143
- package/lib/typescript/tsconfig.js.map +0 -1
- package/lib/typescript/typescript.d.ts +0 -107
- package/lib/typescript/typescript.d.ts.map +0 -1
- package/lib/typescript/typescript.js +0 -180
- package/lib/typescript/typescript.js.map +0 -1
- package/lib/typescript/validate.d.ts +0 -10
- package/lib/typescript/validate.d.ts.map +0 -1
- package/lib/typescript/validate.js +0 -49
- package/lib/typescript/validate.js.map +0 -1
- package/src/agent/ai.ts +0 -215
- package/src/agent/anthropic.ts +0 -31
- package/src/agent/dependencies.ts +0 -62
- package/src/agent/file-context.ts +0 -8
- package/src/agent/index.ts +0 -9
- package/src/agent/model.ts +0 -39
- package/src/agent/module.ts +0 -418
- package/src/agent/openai.ts +0 -50
- package/src/agent/program.md +0 -38
- package/src/agent/program.ts +0 -37
- package/src/agent/prompts.ts +0 -20
- package/src/agent/scrape.ts +0 -47
- package/src/aws/auto/cfn.json +0 -225310
- package/src/aws/auto/docs.ts +0 -73
- package/src/aws/auto/index.ts +0 -4
- package/src/aws/auto/resource.ts +0 -269
- package/src/aws/auto/service.ts +0 -51
- package/src/aws/auto/spec.ts +0 -160
- package/src/markdown/design.ts +0 -125
- package/src/markdown/extract.ts +0 -9
- package/src/markdown/index.ts +0 -3
- package/src/markdown/requirements.ts +0 -135
- package/src/typescript/check-omission.ts +0 -47
- package/src/typescript/debug-type-errors.ts +0 -42
- package/src/typescript/extract.ts +0 -9
- package/src/typescript/index.ts +0 -6
- package/src/typescript/install-dependencies.ts +0 -61
- package/src/typescript/package.ts +0 -143
- package/src/typescript/repair-omissions.ts +0 -31
- package/src/typescript/repair.ts +0 -45
- package/src/typescript/tsconfig.ts +0 -170
- package/src/typescript/typescript.ts +0 -217
- package/src/typescript/validate.ts +0 -73
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type AssetManifest = AssetManifestEntry[];
|
|
2
|
+
|
|
3
|
+
export interface AssetManifestEntry {
|
|
4
|
+
source: string;
|
|
5
|
+
key: string;
|
|
6
|
+
hash: string;
|
|
7
|
+
cacheControl: string;
|
|
8
|
+
contentType?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FileOption {
|
|
12
|
+
files: string | string[];
|
|
13
|
+
cacheControl: string;
|
|
14
|
+
contentType?: string;
|
|
15
|
+
ignore?: string[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication options for Cloudflare API
|
|
3
|
+
*/
|
|
4
|
+
export interface CloudflareAuthOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If true, throw an error when no authentication is found
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
required?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Email to use with API Key
|
|
13
|
+
* If not provided, will attempt to discover from Cloudflare API
|
|
14
|
+
*/
|
|
15
|
+
email?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Authentication headers for Cloudflare API
|
|
20
|
+
*/
|
|
21
|
+
export interface CloudflareAuthHeaders {
|
|
22
|
+
/**
|
|
23
|
+
* Authentication headers to use with fetch
|
|
24
|
+
*/
|
|
25
|
+
headers: Record<string, string>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Type of authentication being used
|
|
29
|
+
*/
|
|
30
|
+
type: "token" | "key" | "none";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* User email (only present when using API Key auth)
|
|
34
|
+
*/
|
|
35
|
+
email?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Response from the Cloudflare User API
|
|
40
|
+
*/
|
|
41
|
+
interface CloudflareUserResponse {
|
|
42
|
+
success: boolean;
|
|
43
|
+
result: {
|
|
44
|
+
id: string;
|
|
45
|
+
email: string;
|
|
46
|
+
name: string;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get authentication headers for Cloudflare API
|
|
53
|
+
*
|
|
54
|
+
* Priority:
|
|
55
|
+
* 1. API Token (CLOUDFLARE_API_TOKEN) - Recommended by Cloudflare
|
|
56
|
+
* 2. API Key (CLOUDFLARE_API_KEY) - Will attempt to discover email automatically
|
|
57
|
+
*
|
|
58
|
+
* @param options Authentication options
|
|
59
|
+
* @returns Authentication headers
|
|
60
|
+
*/
|
|
61
|
+
export async function getCloudflareAuth(
|
|
62
|
+
options: CloudflareAuthOptions = {},
|
|
63
|
+
): Promise<CloudflareAuthHeaders> {
|
|
64
|
+
const { required = true } = options;
|
|
65
|
+
|
|
66
|
+
// Check for API Token (preferred method)
|
|
67
|
+
const apiToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
68
|
+
if (apiToken) {
|
|
69
|
+
return {
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Bearer ${apiToken}`,
|
|
72
|
+
},
|
|
73
|
+
type: "token",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Check for API Key
|
|
78
|
+
const apiKey = process.env.CLOUDFLARE_API_KEY;
|
|
79
|
+
if (apiKey) {
|
|
80
|
+
// If email is provided directly, use it
|
|
81
|
+
const providedEmail = options.email || process.env.CLOUDFLARE_EMAIL;
|
|
82
|
+
if (providedEmail) {
|
|
83
|
+
return {
|
|
84
|
+
headers: {
|
|
85
|
+
"X-Auth-Key": apiKey,
|
|
86
|
+
"X-Auth-Email": providedEmail,
|
|
87
|
+
},
|
|
88
|
+
type: "key",
|
|
89
|
+
email: providedEmail,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Otherwise, try to discover email from Cloudflare API
|
|
94
|
+
try {
|
|
95
|
+
const email = await getUserEmailFromApiKey(apiKey);
|
|
96
|
+
return {
|
|
97
|
+
headers: {
|
|
98
|
+
"X-Auth-Key": apiKey,
|
|
99
|
+
"X-Auth-Email": email,
|
|
100
|
+
},
|
|
101
|
+
type: "key",
|
|
102
|
+
email,
|
|
103
|
+
};
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error("Failed to discover email from API key:", error);
|
|
106
|
+
throw new Error(
|
|
107
|
+
"Failed to automatically discover email for API Key authentication.\n" +
|
|
108
|
+
"Options:\n" +
|
|
109
|
+
"1. Set CLOUDFLARE_EMAIL environment variable\n" +
|
|
110
|
+
"2. Use CLOUDFLARE_API_TOKEN instead (recommended by Cloudflare)",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// No authentication found
|
|
116
|
+
if (required) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"Cloudflare authentication required. Set either:\n" +
|
|
119
|
+
"1. CLOUDFLARE_API_TOKEN (recommended by Cloudflare)\n" +
|
|
120
|
+
" Generate a token at: https://dash.cloudflare.com/profile/api-tokens\n" +
|
|
121
|
+
"2. CLOUDFLARE_API_KEY environment variable",
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
headers: {},
|
|
127
|
+
type: "none",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Fetch the user's email from Cloudflare API using API Key
|
|
133
|
+
*
|
|
134
|
+
* @param apiKey The Cloudflare API key
|
|
135
|
+
* @returns The user's email
|
|
136
|
+
*/
|
|
137
|
+
async function getUserEmailFromApiKey(apiKey: string): Promise<string> {
|
|
138
|
+
try {
|
|
139
|
+
const baseUrl = "https://api.cloudflare.com/client/v4";
|
|
140
|
+
|
|
141
|
+
// Call the /user endpoint to get user information
|
|
142
|
+
const response = await fetch(`${baseUrl}/user`, {
|
|
143
|
+
headers: {
|
|
144
|
+
"Content-Type": "application/json",
|
|
145
|
+
"X-Auth-Key": apiKey,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (!response.ok) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Failed to get user information: ${response.status} ${response.statusText}`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const data = (await response.json()) as CloudflareUserResponse;
|
|
156
|
+
|
|
157
|
+
if (!data.success || !data.result || !data.result.email) {
|
|
158
|
+
throw new Error("Cloudflare API did not return valid user information");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return data.result.email;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error("Error retrieving email from Cloudflare API:", error);
|
|
164
|
+
throw new Error(
|
|
165
|
+
"Failed to automatically discover email for API Key authentication",
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get headers for a Cloudflare API request, including content-type
|
|
172
|
+
*
|
|
173
|
+
* @param contentType Content type for the request
|
|
174
|
+
* @param options Authentication options
|
|
175
|
+
* @returns Complete headers for the request
|
|
176
|
+
*/
|
|
177
|
+
export async function getCloudflareHeaders(
|
|
178
|
+
contentType = "application/json",
|
|
179
|
+
options: CloudflareAuthOptions = {},
|
|
180
|
+
): Promise<Record<string, string>> {
|
|
181
|
+
const auth = await getCloudflareAuth(options);
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
"Content-Type": contentType,
|
|
185
|
+
...auth.headers,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Cloudflare Worker bindings
|
|
3
|
+
* Based on Cloudflare API documentation:
|
|
4
|
+
* https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/
|
|
5
|
+
*/
|
|
6
|
+
import type { DurableObjectNamespace } from "./durable-object-namespace";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Union type for all Worker binding types (Alchemy abstraction)
|
|
10
|
+
*/
|
|
11
|
+
export type WorkerBinding = WorkerBindingSpec | DurableObjectNamespace;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Union type for all Worker binding types (API spec)
|
|
15
|
+
*/
|
|
16
|
+
export type WorkerBindingSpec =
|
|
17
|
+
| WorkerBindingAI
|
|
18
|
+
| WorkerBindingAnalyticsEngine
|
|
19
|
+
| WorkerBindingAssets
|
|
20
|
+
| WorkerBindingBrowserRendering
|
|
21
|
+
| WorkerBindingD1
|
|
22
|
+
| WorkerBindingDispatchNamespace
|
|
23
|
+
| WorkerBindingDurableObjectNamespace
|
|
24
|
+
| WorkerBindingHyperdrive
|
|
25
|
+
| WorkerBindingJson
|
|
26
|
+
| WorkerBindingKVNamespace
|
|
27
|
+
| WorkerBindingMTLSCertificate
|
|
28
|
+
| WorkerBindingPlainText
|
|
29
|
+
| WorkerBindingQueue
|
|
30
|
+
| WorkerBindingR2Bucket
|
|
31
|
+
| WorkerBindingSecretText
|
|
32
|
+
| WorkerBindingService
|
|
33
|
+
| WorkerBindingStaticContent
|
|
34
|
+
| WorkerBindingTailConsumer
|
|
35
|
+
| WorkerBindingVectorize
|
|
36
|
+
| WorkerBindingVersionMetadata
|
|
37
|
+
| WorkerBindingWasmModule;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* AI binding type
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkerBindingAI {
|
|
43
|
+
/** The name of the binding */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Type identifier for AI binding */
|
|
46
|
+
type: "ai";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Analytics Engine binding type
|
|
51
|
+
*/
|
|
52
|
+
export interface WorkerBindingAnalyticsEngine {
|
|
53
|
+
/** The name of the binding */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Type identifier for Analytics Engine binding */
|
|
56
|
+
type: "analytics_engine";
|
|
57
|
+
/** Dataset name */
|
|
58
|
+
dataset: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Assets binding type
|
|
63
|
+
*/
|
|
64
|
+
export interface WorkerBindingAssets {
|
|
65
|
+
/** The name of the binding */
|
|
66
|
+
name: string;
|
|
67
|
+
/** Type identifier for Assets binding */
|
|
68
|
+
type: "assets";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Browser Rendering binding type
|
|
73
|
+
*/
|
|
74
|
+
export interface WorkerBindingBrowserRendering {
|
|
75
|
+
/** The name of the binding */
|
|
76
|
+
name: string;
|
|
77
|
+
/** Type identifier for Browser Rendering binding */
|
|
78
|
+
type: "browser_rendering";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* D1 database binding type
|
|
83
|
+
*/
|
|
84
|
+
export interface WorkerBindingD1 {
|
|
85
|
+
/** The name of the binding */
|
|
86
|
+
name: string;
|
|
87
|
+
/** Type identifier for D1 binding */
|
|
88
|
+
type: "d1";
|
|
89
|
+
/** D1 database ID */
|
|
90
|
+
id: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Dispatch Namespace binding type
|
|
95
|
+
*/
|
|
96
|
+
export interface WorkerBindingDispatchNamespace {
|
|
97
|
+
/** The name of the binding */
|
|
98
|
+
name: string;
|
|
99
|
+
/** Type identifier for Dispatch Namespace binding */
|
|
100
|
+
type: "dispatch_namespace";
|
|
101
|
+
/** Namespace identifier */
|
|
102
|
+
namespace: string;
|
|
103
|
+
/** Optional outbound service */
|
|
104
|
+
outbound?: any; // Documentation doesn't specify the exact type
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Durable Object Namespace binding type
|
|
109
|
+
*/
|
|
110
|
+
export interface WorkerBindingDurableObjectNamespace {
|
|
111
|
+
/**
|
|
112
|
+
* The stable ID of the binding
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
stableId?: string;
|
|
116
|
+
/** The name of the binding */
|
|
117
|
+
name: string;
|
|
118
|
+
/** Type identifier for Durable Object Namespace binding */
|
|
119
|
+
type: "durable_object_namespace";
|
|
120
|
+
/** Durable Object class name */
|
|
121
|
+
class_name: string;
|
|
122
|
+
/** Script name that contains the Durable Object */
|
|
123
|
+
script_name?: string;
|
|
124
|
+
/** Environment */
|
|
125
|
+
environment?: string;
|
|
126
|
+
/** Namespace ID */
|
|
127
|
+
namespace_id?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Hyperdrive binding type
|
|
132
|
+
*/
|
|
133
|
+
export interface WorkerBindingHyperdrive {
|
|
134
|
+
/** The name of the binding */
|
|
135
|
+
name: string;
|
|
136
|
+
/** Type identifier for Hyperdrive binding */
|
|
137
|
+
type: "hyperdrive";
|
|
138
|
+
/** Hyperdrive ID */
|
|
139
|
+
id: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* JSON binding type
|
|
144
|
+
*/
|
|
145
|
+
export interface WorkerBindingJson {
|
|
146
|
+
/** The name of the binding */
|
|
147
|
+
name: string;
|
|
148
|
+
/** Type identifier for JSON binding */
|
|
149
|
+
type: "json";
|
|
150
|
+
/** JSON value */
|
|
151
|
+
json: any;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* KV Namespace binding type
|
|
156
|
+
*/
|
|
157
|
+
export interface WorkerBindingKVNamespace {
|
|
158
|
+
/** The name of the binding */
|
|
159
|
+
name: string;
|
|
160
|
+
/** Type identifier for KV Namespace binding */
|
|
161
|
+
type: "kv_namespace";
|
|
162
|
+
/** KV Namespace ID */
|
|
163
|
+
namespace_id: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* MTLS Certificate binding type
|
|
168
|
+
*/
|
|
169
|
+
export interface WorkerBindingMTLSCertificate {
|
|
170
|
+
/** The name of the binding */
|
|
171
|
+
name: string;
|
|
172
|
+
/** Type identifier for MTLS Certificate binding */
|
|
173
|
+
type: "mtls_certificate";
|
|
174
|
+
/** Certificate ID */
|
|
175
|
+
certificate_id: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Plain Text binding type
|
|
180
|
+
*/
|
|
181
|
+
export interface WorkerBindingPlainText {
|
|
182
|
+
/** The name of the binding */
|
|
183
|
+
name: string;
|
|
184
|
+
/** Type identifier for Plain Text binding */
|
|
185
|
+
type: "plain_text";
|
|
186
|
+
/** Text content */
|
|
187
|
+
text: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Queue binding type
|
|
192
|
+
*/
|
|
193
|
+
export interface WorkerBindingQueue {
|
|
194
|
+
/** The name of the binding */
|
|
195
|
+
name: string;
|
|
196
|
+
/** Type identifier for Queue binding */
|
|
197
|
+
type: "queue";
|
|
198
|
+
/** Queue name */
|
|
199
|
+
queue_name: string;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* R2 Bucket binding type
|
|
204
|
+
*/
|
|
205
|
+
export interface WorkerBindingR2Bucket {
|
|
206
|
+
/** The name of the binding */
|
|
207
|
+
name: string;
|
|
208
|
+
/** Type identifier for R2 Bucket binding */
|
|
209
|
+
type: "r2_bucket";
|
|
210
|
+
/** Bucket name */
|
|
211
|
+
bucket_name: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Secret Text binding type
|
|
216
|
+
*/
|
|
217
|
+
export interface WorkerBindingSecretText {
|
|
218
|
+
/** The name of the binding */
|
|
219
|
+
name: string;
|
|
220
|
+
/** Type identifier for Secret Text binding */
|
|
221
|
+
type: "secret_text";
|
|
222
|
+
/** Secret value */
|
|
223
|
+
text: string;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Service binding type
|
|
228
|
+
*/
|
|
229
|
+
export interface WorkerBindingService {
|
|
230
|
+
/** The name of the binding */
|
|
231
|
+
name: string;
|
|
232
|
+
/** Type identifier for Service binding */
|
|
233
|
+
type: "service";
|
|
234
|
+
/** Service name */
|
|
235
|
+
service: string;
|
|
236
|
+
/** Environment */
|
|
237
|
+
environment?: string;
|
|
238
|
+
/** Service namespace */
|
|
239
|
+
namespace?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Tail Consumer binding type
|
|
244
|
+
*/
|
|
245
|
+
export interface WorkerBindingTailConsumer {
|
|
246
|
+
/** The name of the binding */
|
|
247
|
+
name: string;
|
|
248
|
+
/** Type identifier for Tail Consumer binding */
|
|
249
|
+
type: "tail_consumer";
|
|
250
|
+
/** Service name */
|
|
251
|
+
service: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Vectorize binding type
|
|
256
|
+
*/
|
|
257
|
+
export interface WorkerBindingVectorize {
|
|
258
|
+
/** The name of the binding */
|
|
259
|
+
name: string;
|
|
260
|
+
/** Type identifier for Vectorize binding */
|
|
261
|
+
type: "vectorize";
|
|
262
|
+
/** Index name */
|
|
263
|
+
index_name: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Version Metadata binding type
|
|
268
|
+
*/
|
|
269
|
+
export interface WorkerBindingVersionMetadata {
|
|
270
|
+
/** The name of the binding */
|
|
271
|
+
name: string;
|
|
272
|
+
/** Type identifier for Version Metadata binding */
|
|
273
|
+
type: "version_metadata";
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* WASM Module binding type
|
|
278
|
+
*/
|
|
279
|
+
export interface WorkerBindingWasmModule {
|
|
280
|
+
/** The name of the binding */
|
|
281
|
+
name: string;
|
|
282
|
+
/** Type identifier for WASM Module binding */
|
|
283
|
+
type: "wasm_module";
|
|
284
|
+
/** Module name */
|
|
285
|
+
module: string;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Static content binding for Cloudflare Workers
|
|
290
|
+
* Used for Workers Sites and static assets
|
|
291
|
+
*/
|
|
292
|
+
export interface WorkerBindingStaticContent {
|
|
293
|
+
/** The name of the binding */
|
|
294
|
+
name: string;
|
|
295
|
+
/** Type identifier for Static Content binding */
|
|
296
|
+
type: "static_content";
|
|
297
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { WorkerBinding } from "./bindings";
|
|
2
|
+
|
|
3
|
+
export interface DurableObjectNamespaceInput {
|
|
4
|
+
bindingName: string;
|
|
5
|
+
className: string;
|
|
6
|
+
scriptName?: string | undefined;
|
|
7
|
+
environment?: string | undefined;
|
|
8
|
+
sqlite?: boolean | undefined;
|
|
9
|
+
namespaceId?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isDurableObjectNamespace(
|
|
13
|
+
binding: WorkerBinding,
|
|
14
|
+
): binding is DurableObjectNamespace {
|
|
15
|
+
return (
|
|
16
|
+
binding.type === "durable_object_namespace" &&
|
|
17
|
+
typeof (binding as any).bindingName === "string"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class DurableObjectNamespace implements DurableObjectNamespaceInput {
|
|
22
|
+
public readonly type = "durable_object_namespace" as const;
|
|
23
|
+
// alias for bindingName to be consistent with other bindings
|
|
24
|
+
public readonly name: string;
|
|
25
|
+
public readonly bindingName: string;
|
|
26
|
+
public readonly className: string;
|
|
27
|
+
public readonly scriptName?: string | undefined;
|
|
28
|
+
public readonly environment?: string | undefined;
|
|
29
|
+
public readonly sqlite?: boolean | undefined;
|
|
30
|
+
public readonly namespaceId?: string | undefined;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
public readonly id: string,
|
|
34
|
+
input: DurableObjectNamespaceInput,
|
|
35
|
+
) {
|
|
36
|
+
this.bindingName = input.bindingName;
|
|
37
|
+
this.name = this.bindingName;
|
|
38
|
+
this.className = input.className;
|
|
39
|
+
this.scriptName = input.scriptName;
|
|
40
|
+
this.environment = input.environment;
|
|
41
|
+
this.sqlite = input.sqlite;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { glob } from "glob";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { getContentType } from "../utils/content-type";
|
|
6
|
+
import type {
|
|
7
|
+
AssetManifest,
|
|
8
|
+
AssetManifestEntry,
|
|
9
|
+
FileOption,
|
|
10
|
+
} from "./asset-manifest";
|
|
11
|
+
|
|
12
|
+
export async function generateAssetManifest(
|
|
13
|
+
dir: string,
|
|
14
|
+
fileOptions: FileOption[] = [
|
|
15
|
+
{
|
|
16
|
+
files: "**",
|
|
17
|
+
cacheControl: "max-age=0,no-cache,no-store,must-revalidate",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
files: ["**/*.js", "**/*.css"],
|
|
21
|
+
cacheControl: "max-age=31536000,public,immutable",
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
): Promise<AssetManifest> {
|
|
25
|
+
// First, collect all file info based on fileOptions (reversed to prioritize later rules)
|
|
26
|
+
const fileInfos: Array<{
|
|
27
|
+
file: string;
|
|
28
|
+
cacheControl: string;
|
|
29
|
+
contentType?: string;
|
|
30
|
+
}> = [];
|
|
31
|
+
const filesProcessed: Set<string> = new Set();
|
|
32
|
+
|
|
33
|
+
// Process file options in reverse order (later rules override earlier ones)
|
|
34
|
+
// Use for...of to maintain order but allow await inside the loop
|
|
35
|
+
const reversedOptions = [...fileOptions].reverse();
|
|
36
|
+
for (const fileOption of reversedOptions) {
|
|
37
|
+
const patterns = Array.isArray(fileOption.files)
|
|
38
|
+
? fileOption.files
|
|
39
|
+
: [fileOption.files];
|
|
40
|
+
|
|
41
|
+
// Get all files matching the pattern
|
|
42
|
+
const files = (
|
|
43
|
+
await Promise.all(
|
|
44
|
+
patterns.map(async (p) => {
|
|
45
|
+
// Use glob as async function instead of globSync
|
|
46
|
+
return glob(p, {
|
|
47
|
+
cwd: path.resolve(dir),
|
|
48
|
+
nodir: true,
|
|
49
|
+
dot: true,
|
|
50
|
+
ignore: [
|
|
51
|
+
".git/**",
|
|
52
|
+
"node_modules/**",
|
|
53
|
+
...(typeof fileOption.ignore === "string"
|
|
54
|
+
? [fileOption.ignore]
|
|
55
|
+
: (fileOption.ignore ?? [])),
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
}),
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
.flat()
|
|
62
|
+
.filter((file) => !filesProcessed.has(file));
|
|
63
|
+
|
|
64
|
+
// Add files to processed set
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
filesProcessed.add(file);
|
|
67
|
+
fileInfos.push({
|
|
68
|
+
file,
|
|
69
|
+
cacheControl: fileOption.cacheControl,
|
|
70
|
+
contentType: fileOption.contentType,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Process all files in parallel
|
|
76
|
+
const manifestEntries = await Promise.all(
|
|
77
|
+
fileInfos.map(async ({ file, cacheControl, contentType }) => {
|
|
78
|
+
const source = path.resolve(dir, file);
|
|
79
|
+
const content = await fs.readFile(source);
|
|
80
|
+
const hash = crypto.createHash("sha256").update(content).digest("hex");
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
source,
|
|
84
|
+
key: file,
|
|
85
|
+
hash,
|
|
86
|
+
cacheControl,
|
|
87
|
+
contentType: contentType ?? getContentType(file),
|
|
88
|
+
} satisfies AssetManifestEntry;
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return manifestEntries;
|
|
93
|
+
}
|