alchemy 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/README.md +324 -0
  2. package/lib/apply.d.ts +2 -2
  3. package/lib/apply.d.ts.map +1 -1
  4. package/lib/apply.js +2 -2
  5. package/lib/apply.js.map +1 -1
  6. package/lib/aws/index.d.ts +1 -0
  7. package/lib/aws/index.d.ts.map +1 -1
  8. package/lib/aws/index.js +1 -0
  9. package/lib/aws/index.js.map +1 -1
  10. package/lib/aws/ses.d.ts +75 -0
  11. package/lib/aws/ses.d.ts.map +1 -0
  12. package/lib/aws/ses.js +197 -0
  13. package/lib/aws/ses.js.map +1 -0
  14. package/lib/cloudflare/api.d.ts +84 -0
  15. package/lib/cloudflare/api.d.ts.map +1 -0
  16. package/lib/cloudflare/api.js +178 -0
  17. package/lib/cloudflare/api.js.map +1 -0
  18. package/lib/cloudflare/asset-manifest.d.ts +15 -0
  19. package/lib/cloudflare/asset-manifest.d.ts.map +1 -0
  20. package/lib/cloudflare/asset-manifest.js +2 -0
  21. package/lib/cloudflare/asset-manifest.js.map +1 -0
  22. package/lib/cloudflare/auth.d.ts +52 -0
  23. package/lib/cloudflare/auth.d.ts.map +1 -0
  24. package/lib/cloudflare/auth.js +114 -0
  25. package/lib/cloudflare/auth.js.map +1 -0
  26. package/lib/cloudflare/bindings.d.ts +244 -0
  27. package/lib/cloudflare/bindings.d.ts.map +1 -0
  28. package/lib/cloudflare/bindings.js +7 -0
  29. package/lib/cloudflare/bindings.js.map +1 -0
  30. package/lib/cloudflare/generate-asset-manifest.d.ts +3 -0
  31. package/lib/cloudflare/generate-asset-manifest.d.ts.map +1 -0
  32. package/lib/cloudflare/generate-asset-manifest.js +69 -0
  33. package/lib/cloudflare/generate-asset-manifest.js.map +1 -0
  34. package/lib/cloudflare/index.d.ts +6 -0
  35. package/lib/cloudflare/index.d.ts.map +1 -0
  36. package/lib/cloudflare/index.js +6 -0
  37. package/lib/cloudflare/index.js.map +1 -0
  38. package/lib/cloudflare/kv-namespace.d.ts +61 -0
  39. package/lib/cloudflare/kv-namespace.d.ts.map +1 -0
  40. package/lib/cloudflare/kv-namespace.js +93 -0
  41. package/lib/cloudflare/kv-namespace.js.map +1 -0
  42. package/lib/cloudflare/state.d.ts +83 -0
  43. package/lib/cloudflare/state.d.ts.map +1 -0
  44. package/lib/cloudflare/state.js +109 -0
  45. package/lib/cloudflare/state.js.map +1 -0
  46. package/lib/cloudflare/static-site-router.d.ts +10 -0
  47. package/lib/cloudflare/static-site-router.d.ts.map +1 -0
  48. package/lib/cloudflare/static-site-router.js +88 -0
  49. package/lib/cloudflare/static-site-router.js.map +1 -0
  50. package/lib/cloudflare/static-site.d.ts +166 -0
  51. package/lib/cloudflare/static-site.d.ts.map +1 -0
  52. package/lib/cloudflare/static-site.js +152 -0
  53. package/lib/cloudflare/static-site.js.map +1 -0
  54. package/lib/cloudflare/types.d.ts +52 -0
  55. package/lib/cloudflare/types.d.ts.map +1 -0
  56. package/lib/cloudflare/types.js +21 -0
  57. package/lib/cloudflare/types.js.map +1 -0
  58. package/lib/cloudflare/upload-asset-manifest.d.ts +12 -0
  59. package/lib/cloudflare/upload-asset-manifest.d.ts.map +1 -0
  60. package/lib/cloudflare/upload-asset-manifest.js +55 -0
  61. package/lib/cloudflare/upload-asset-manifest.js.map +1 -0
  62. package/lib/cloudflare/worker.d.ts +87 -0
  63. package/lib/cloudflare/worker.d.ts.map +1 -0
  64. package/lib/cloudflare/worker.js +364 -0
  65. package/lib/cloudflare/worker.js.map +1 -0
  66. package/lib/esbuild.d.ts +82 -0
  67. package/lib/esbuild.d.ts.map +1 -1
  68. package/lib/esbuild.js +24 -17
  69. package/lib/esbuild.js.map +1 -1
  70. package/lib/fs.d.ts +1 -1
  71. package/lib/global.d.ts.map +1 -1
  72. package/lib/global.js +3 -1
  73. package/lib/global.js.map +1 -1
  74. package/lib/index.d.ts +0 -1
  75. package/lib/index.d.ts.map +1 -1
  76. package/lib/index.js +0 -1
  77. package/lib/index.js.map +1 -1
  78. package/lib/main.js +1 -1
  79. package/lib/main.js.map +1 -1
  80. package/lib/output.d.ts +17 -13
  81. package/lib/output.d.ts.map +1 -1
  82. package/lib/output.js +2 -2
  83. package/lib/output.js.map +1 -1
  84. package/lib/resource.d.ts +3 -2
  85. package/lib/resource.d.ts.map +1 -1
  86. package/lib/resource.js +2 -2
  87. package/lib/resource.js.map +1 -1
  88. package/lib/utils/content-type.d.ts +8 -0
  89. package/lib/utils/content-type.d.ts.map +1 -0
  90. package/lib/utils/content-type.js +41 -0
  91. package/lib/utils/content-type.js.map +1 -0
  92. package/package.json +26 -8
  93. package/src/apply.ts +5 -5
  94. package/src/aws/index.ts +1 -0
  95. package/src/aws/ses.ts +346 -0
  96. package/src/cloudflare/api.ts +276 -0
  97. package/src/cloudflare/asset-manifest.ts +16 -0
  98. package/src/cloudflare/auth.ts +187 -0
  99. package/src/cloudflare/bindings.ts +286 -0
  100. package/src/cloudflare/generate-asset-manifest.ts +93 -0
  101. package/src/cloudflare/index.ts +5 -0
  102. package/src/cloudflare/kv-namespace.ts +195 -0
  103. package/src/cloudflare/state.ts +138 -0
  104. package/src/cloudflare/static-site-router.ts +108 -0
  105. package/src/cloudflare/static-site.ts +379 -0
  106. package/src/cloudflare/types.ts +71 -0
  107. package/src/cloudflare/upload-asset-manifest.ts +83 -0
  108. package/src/cloudflare/worker.ts +568 -0
  109. package/src/esbuild.ts +31 -22
  110. package/src/global.ts +1 -0
  111. package/src/index.ts +0 -1
  112. package/src/main.ts +1 -1
  113. package/src/output.ts +32 -32
  114. package/src/resource.ts +11 -5
  115. package/src/utils/content-type.ts +42 -0
  116. package/lib/$.d.ts +0 -7
  117. package/lib/$.d.ts.map +0 -1
  118. package/lib/$.js +0 -31
  119. package/lib/$.js.map +0 -1
  120. package/lib/agent/ai.d.ts +0 -40
  121. package/lib/agent/ai.d.ts.map +0 -1
  122. package/lib/agent/ai.js +0 -132
  123. package/lib/agent/ai.js.map +0 -1
  124. package/lib/agent/anthropic.d.ts +0 -9
  125. package/lib/agent/anthropic.d.ts.map +0 -1
  126. package/lib/agent/anthropic.js +0 -25
  127. package/lib/agent/anthropic.js.map +0 -1
  128. package/lib/agent/dependencies.d.ts +0 -4
  129. package/lib/agent/dependencies.d.ts.map +0 -1
  130. package/lib/agent/dependencies.js +0 -48
  131. package/lib/agent/dependencies.js.map +0 -1
  132. package/lib/agent/file-context.d.ts +0 -13
  133. package/lib/agent/file-context.d.ts.map +0 -1
  134. package/lib/agent/file-context.js +0 -6
  135. package/lib/agent/file-context.js.map +0 -1
  136. package/lib/agent/index.d.ts +0 -10
  137. package/lib/agent/index.d.ts.map +0 -1
  138. package/lib/agent/index.js +0 -10
  139. package/lib/agent/index.js.map +0 -1
  140. package/lib/agent/model.d.ts +0 -8
  141. package/lib/agent/model.d.ts.map +0 -1
  142. package/lib/agent/model.js +0 -29
  143. package/lib/agent/model.js.map +0 -1
  144. package/lib/agent/module.d.ts +0 -81
  145. package/lib/agent/module.d.ts.map +0 -1
  146. package/lib/agent/module.js +0 -309
  147. package/lib/agent/module.js.map +0 -1
  148. package/lib/agent/openai.d.ts +0 -6
  149. package/lib/agent/openai.d.ts.map +0 -1
  150. package/lib/agent/openai.js +0 -41
  151. package/lib/agent/openai.js.map +0 -1
  152. package/lib/agent/program.d.ts +0 -12
  153. package/lib/agent/program.d.ts.map +0 -1
  154. package/lib/agent/program.js +0 -21
  155. package/lib/agent/program.js.map +0 -1
  156. package/lib/agent/prompts.d.ts +0 -4
  157. package/lib/agent/prompts.d.ts.map +0 -1
  158. package/lib/agent/prompts.js +0 -11
  159. package/lib/agent/prompts.js.map +0 -1
  160. package/lib/agent/scrape.d.ts +0 -71
  161. package/lib/agent/scrape.d.ts.map +0 -1
  162. package/lib/agent/scrape.js +0 -45
  163. package/lib/agent/scrape.js.map +0 -1
  164. package/lib/aws/auto/docs.d.ts +0 -11
  165. package/lib/aws/auto/docs.d.ts.map +0 -1
  166. package/lib/aws/auto/docs.js +0 -56
  167. package/lib/aws/auto/docs.js.map +0 -1
  168. package/lib/aws/auto/index.d.ts +0 -5
  169. package/lib/aws/auto/index.d.ts.map +0 -1
  170. package/lib/aws/auto/index.js +0 -5
  171. package/lib/aws/auto/index.js.map +0 -1
  172. package/lib/aws/auto/resource.d.ts +0 -24
  173. package/lib/aws/auto/resource.d.ts.map +0 -1
  174. package/lib/aws/auto/resource.js +0 -194
  175. package/lib/aws/auto/resource.js.map +0 -1
  176. package/lib/aws/auto/service.d.ts +0 -10
  177. package/lib/aws/auto/service.d.ts.map +0 -1
  178. package/lib/aws/auto/service.js +0 -34
  179. package/lib/aws/auto/service.js.map +0 -1
  180. package/lib/aws/auto/spec.d.ts +0 -83
  181. package/lib/aws/auto/spec.d.ts.map +0 -1
  182. package/lib/aws/auto/spec.js +0 -58
  183. package/lib/aws/auto/spec.js.map +0 -1
  184. package/lib/markdown/design.d.ts +0 -17
  185. package/lib/markdown/design.d.ts.map +0 -1
  186. package/lib/markdown/design.js +0 -92
  187. package/lib/markdown/design.js.map +0 -1
  188. package/lib/markdown/extract.d.ts +0 -7
  189. package/lib/markdown/extract.d.ts.map +0 -1
  190. package/lib/markdown/extract.js +0 -10
  191. package/lib/markdown/extract.js.map +0 -1
  192. package/lib/markdown/index.d.ts +0 -4
  193. package/lib/markdown/index.d.ts.map +0 -1
  194. package/lib/markdown/index.js +0 -4
  195. package/lib/markdown/index.js.map +0 -1
  196. package/lib/markdown/requirements.d.ts +0 -79
  197. package/lib/markdown/requirements.d.ts.map +0 -1
  198. package/lib/markdown/requirements.js +0 -105
  199. package/lib/markdown/requirements.js.map +0 -1
  200. package/lib/typescript/check-omission.d.ts +0 -2
  201. package/lib/typescript/check-omission.d.ts.map +0 -1
  202. package/lib/typescript/check-omission.js +0 -43
  203. package/lib/typescript/check-omission.js.map +0 -1
  204. package/lib/typescript/debug-type-errors.d.ts +0 -3
  205. package/lib/typescript/debug-type-errors.d.ts.map +0 -1
  206. package/lib/typescript/debug-type-errors.js +0 -35
  207. package/lib/typescript/debug-type-errors.js.map +0 -1
  208. package/lib/typescript/extract.d.ts +0 -7
  209. package/lib/typescript/extract.d.ts.map +0 -1
  210. package/lib/typescript/extract.js +0 -10
  211. package/lib/typescript/extract.js.map +0 -1
  212. package/lib/typescript/index.d.ts +0 -7
  213. package/lib/typescript/index.d.ts.map +0 -1
  214. package/lib/typescript/index.js +0 -7
  215. package/lib/typescript/index.js.map +0 -1
  216. package/lib/typescript/install-dependencies.d.ts +0 -29
  217. package/lib/typescript/install-dependencies.d.ts.map +0 -1
  218. package/lib/typescript/install-dependencies.js +0 -52
  219. package/lib/typescript/install-dependencies.js.map +0 -1
  220. package/lib/typescript/package.d.ts +0 -157
  221. package/lib/typescript/package.d.ts.map +0 -1
  222. package/lib/typescript/package.js +0 -115
  223. package/lib/typescript/package.js.map +0 -1
  224. package/lib/typescript/repair-omissions.d.ts +0 -3
  225. package/lib/typescript/repair-omissions.d.ts.map +0 -1
  226. package/lib/typescript/repair-omissions.js +0 -23
  227. package/lib/typescript/repair-omissions.js.map +0 -1
  228. package/lib/typescript/repair.d.ts +0 -3
  229. package/lib/typescript/repair.d.ts.map +0 -1
  230. package/lib/typescript/repair.js +0 -34
  231. package/lib/typescript/repair.js.map +0 -1
  232. package/lib/typescript/tsconfig.d.ts +0 -469
  233. package/lib/typescript/tsconfig.d.ts.map +0 -1
  234. package/lib/typescript/tsconfig.js +0 -143
  235. package/lib/typescript/tsconfig.js.map +0 -1
  236. package/lib/typescript/typescript.d.ts +0 -107
  237. package/lib/typescript/typescript.d.ts.map +0 -1
  238. package/lib/typescript/typescript.js +0 -180
  239. package/lib/typescript/typescript.js.map +0 -1
  240. package/lib/typescript/validate.d.ts +0 -10
  241. package/lib/typescript/validate.d.ts.map +0 -1
  242. package/lib/typescript/validate.js +0 -49
  243. package/lib/typescript/validate.js.map +0 -1
  244. package/src/$.ts +0 -36
  245. package/src/agent/ai.ts +0 -215
  246. package/src/agent/anthropic.ts +0 -31
  247. package/src/agent/dependencies.ts +0 -62
  248. package/src/agent/file-context.ts +0 -8
  249. package/src/agent/index.ts +0 -9
  250. package/src/agent/model.ts +0 -39
  251. package/src/agent/module.ts +0 -418
  252. package/src/agent/openai.ts +0 -50
  253. package/src/agent/program.md +0 -38
  254. package/src/agent/program.ts +0 -37
  255. package/src/agent/prompts.ts +0 -20
  256. package/src/agent/scrape.ts +0 -47
  257. package/src/aws/auto/cfn.json +0 -225310
  258. package/src/aws/auto/docs.ts +0 -73
  259. package/src/aws/auto/index.ts +0 -4
  260. package/src/aws/auto/resource.ts +0 -269
  261. package/src/aws/auto/service.ts +0 -51
  262. package/src/aws/auto/spec.ts +0 -160
  263. package/src/markdown/design.ts +0 -125
  264. package/src/markdown/extract.ts +0 -9
  265. package/src/markdown/index.ts +0 -3
  266. package/src/markdown/requirements.ts +0 -135
  267. package/src/typescript/check-omission.ts +0 -47
  268. package/src/typescript/debug-type-errors.ts +0 -42
  269. package/src/typescript/extract.ts +0 -9
  270. package/src/typescript/index.ts +0 -6
  271. package/src/typescript/install-dependencies.ts +0 -61
  272. package/src/typescript/package.ts +0 -143
  273. package/src/typescript/repair-omissions.ts +0 -31
  274. package/src/typescript/repair.ts +0 -45
  275. package/src/typescript/tsconfig.ts +0 -170
  276. package/src/typescript/typescript.ts +0 -217
  277. package/src/typescript/validate.ts +0 -73
@@ -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,286 @@
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
+
7
+ /**
8
+ * AI binding type
9
+ */
10
+ export interface WorkerBindingAI {
11
+ /** The name of the binding */
12
+ name: string;
13
+ /** Type identifier for AI binding */
14
+ type: "ai";
15
+ }
16
+
17
+ /**
18
+ * Analytics Engine binding type
19
+ */
20
+ export interface WorkerBindingAnalyticsEngine {
21
+ /** The name of the binding */
22
+ name: string;
23
+ /** Type identifier for Analytics Engine binding */
24
+ type: "analytics_engine";
25
+ /** Dataset name */
26
+ dataset: string;
27
+ }
28
+
29
+ /**
30
+ * Assets binding type
31
+ */
32
+ export interface WorkerBindingAssets {
33
+ /** The name of the binding */
34
+ name: string;
35
+ /** Type identifier for Assets binding */
36
+ type: "assets";
37
+ }
38
+
39
+ /**
40
+ * Browser Rendering binding type
41
+ */
42
+ export interface WorkerBindingBrowserRendering {
43
+ /** The name of the binding */
44
+ name: string;
45
+ /** Type identifier for Browser Rendering binding */
46
+ type: "browser_rendering";
47
+ }
48
+
49
+ /**
50
+ * D1 database binding type
51
+ */
52
+ export interface WorkerBindingD1 {
53
+ /** The name of the binding */
54
+ name: string;
55
+ /** Type identifier for D1 binding */
56
+ type: "d1";
57
+ /** D1 database ID */
58
+ id: string;
59
+ }
60
+
61
+ /**
62
+ * Dispatch Namespace binding type
63
+ */
64
+ export interface WorkerBindingDispatchNamespace {
65
+ /** The name of the binding */
66
+ name: string;
67
+ /** Type identifier for Dispatch Namespace binding */
68
+ type: "dispatch_namespace";
69
+ /** Namespace identifier */
70
+ namespace: string;
71
+ /** Optional outbound service */
72
+ outbound?: any; // Documentation doesn't specify the exact type
73
+ }
74
+
75
+ /**
76
+ * Durable Object Namespace binding type
77
+ */
78
+ export interface WorkerBindingDurableObjectNamespace {
79
+ /** The name of the binding */
80
+ name: string;
81
+ /** Type identifier for Durable Object Namespace binding */
82
+ type: "durable_object_namespace";
83
+ /** Durable Object class name */
84
+ class_name: string;
85
+ /** Script name that contains the Durable Object */
86
+ script_name?: string;
87
+ /** Environment */
88
+ environment?: string;
89
+ /** Namespace ID */
90
+ namespace_id?: string;
91
+ }
92
+
93
+ /**
94
+ * Hyperdrive binding type
95
+ */
96
+ export interface WorkerBindingHyperdrive {
97
+ /** The name of the binding */
98
+ name: string;
99
+ /** Type identifier for Hyperdrive binding */
100
+ type: "hyperdrive";
101
+ /** Hyperdrive ID */
102
+ id: string;
103
+ }
104
+
105
+ /**
106
+ * JSON binding type
107
+ */
108
+ export interface WorkerBindingJson {
109
+ /** The name of the binding */
110
+ name: string;
111
+ /** Type identifier for JSON binding */
112
+ type: "json";
113
+ /** JSON value */
114
+ json: any;
115
+ }
116
+
117
+ /**
118
+ * KV Namespace binding type
119
+ */
120
+ export interface WorkerBindingKVNamespace {
121
+ /** The name of the binding */
122
+ name: string;
123
+ /** Type identifier for KV Namespace binding */
124
+ type: "kv_namespace";
125
+ /** KV Namespace ID */
126
+ namespace_id: string;
127
+ }
128
+
129
+ /**
130
+ * MTLS Certificate binding type
131
+ */
132
+ export interface WorkerBindingMTLSCertificate {
133
+ /** The name of the binding */
134
+ name: string;
135
+ /** Type identifier for MTLS Certificate binding */
136
+ type: "mtls_certificate";
137
+ /** Certificate ID */
138
+ certificate_id: string;
139
+ }
140
+
141
+ /**
142
+ * Plain Text binding type
143
+ */
144
+ export interface WorkerBindingPlainText {
145
+ /** The name of the binding */
146
+ name: string;
147
+ /** Type identifier for Plain Text binding */
148
+ type: "plain_text";
149
+ /** Text content */
150
+ text: string;
151
+ }
152
+
153
+ /**
154
+ * Queue binding type
155
+ */
156
+ export interface WorkerBindingQueue {
157
+ /** The name of the binding */
158
+ name: string;
159
+ /** Type identifier for Queue binding */
160
+ type: "queue";
161
+ /** Queue name */
162
+ queue_name: string;
163
+ }
164
+
165
+ /**
166
+ * R2 Bucket binding type
167
+ */
168
+ export interface WorkerBindingR2Bucket {
169
+ /** The name of the binding */
170
+ name: string;
171
+ /** Type identifier for R2 Bucket binding */
172
+ type: "r2_bucket";
173
+ /** Bucket name */
174
+ bucket_name: string;
175
+ }
176
+
177
+ /**
178
+ * Secret Text binding type
179
+ */
180
+ export interface WorkerBindingSecretText {
181
+ /** The name of the binding */
182
+ name: string;
183
+ /** Type identifier for Secret Text binding */
184
+ type: "secret_text";
185
+ /** Secret value */
186
+ text: string;
187
+ }
188
+
189
+ /**
190
+ * Service binding type
191
+ */
192
+ export interface WorkerBindingService {
193
+ /** The name of the binding */
194
+ name: string;
195
+ /** Type identifier for Service binding */
196
+ type: "service";
197
+ /** Service name */
198
+ service: string;
199
+ /** Environment */
200
+ environment?: string;
201
+ /** Service namespace */
202
+ namespace?: string;
203
+ }
204
+
205
+ /**
206
+ * Tail Consumer binding type
207
+ */
208
+ export interface WorkerBindingTailConsumer {
209
+ /** The name of the binding */
210
+ name: string;
211
+ /** Type identifier for Tail Consumer binding */
212
+ type: "tail_consumer";
213
+ /** Service name */
214
+ service: string;
215
+ }
216
+
217
+ /**
218
+ * Vectorize binding type
219
+ */
220
+ export interface WorkerBindingVectorize {
221
+ /** The name of the binding */
222
+ name: string;
223
+ /** Type identifier for Vectorize binding */
224
+ type: "vectorize";
225
+ /** Index name */
226
+ index_name: string;
227
+ }
228
+
229
+ /**
230
+ * Version Metadata binding type
231
+ */
232
+ export interface WorkerBindingVersionMetadata {
233
+ /** The name of the binding */
234
+ name: string;
235
+ /** Type identifier for Version Metadata binding */
236
+ type: "version_metadata";
237
+ }
238
+
239
+ /**
240
+ * WASM Module binding type
241
+ */
242
+ export interface WorkerBindingWasmModule {
243
+ /** The name of the binding */
244
+ name: string;
245
+ /** Type identifier for WASM Module binding */
246
+ type: "wasm_module";
247
+ /** Module name */
248
+ module: string;
249
+ }
250
+
251
+ /**
252
+ * Static content binding for Cloudflare Workers
253
+ * Used for Workers Sites and static assets
254
+ */
255
+ export interface WorkerBindingStaticContent {
256
+ /** The name of the binding */
257
+ name: string;
258
+ /** Type identifier for Static Content binding */
259
+ type: "static_content";
260
+ }
261
+
262
+ /**
263
+ * Union type for all Worker binding types
264
+ */
265
+ export type WorkerBinding =
266
+ | WorkerBindingAI
267
+ | WorkerBindingAnalyticsEngine
268
+ | WorkerBindingAssets
269
+ | WorkerBindingBrowserRendering
270
+ | WorkerBindingD1
271
+ | WorkerBindingDispatchNamespace
272
+ | WorkerBindingDurableObjectNamespace
273
+ | WorkerBindingHyperdrive
274
+ | WorkerBindingJson
275
+ | WorkerBindingKVNamespace
276
+ | WorkerBindingMTLSCertificate
277
+ | WorkerBindingPlainText
278
+ | WorkerBindingQueue
279
+ | WorkerBindingR2Bucket
280
+ | WorkerBindingSecretText
281
+ | WorkerBindingService
282
+ | WorkerBindingStaticContent
283
+ | WorkerBindingTailConsumer
284
+ | WorkerBindingVectorize
285
+ | WorkerBindingVersionMetadata
286
+ | WorkerBindingWasmModule;
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./bindings";
2
+ export * from "./kv-namespace";
3
+ export * from "./state";
4
+ export * from "./static-site";
5
+ export * from "./worker";