alchemy 0.3.1 → 0.4.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.
Files changed (104) hide show
  1. package/README.md +8 -3
  2. package/lib/ai/document.d.ts +12 -1
  3. package/lib/ai/document.js +10 -1
  4. package/lib/ai/index.d.ts +0 -2
  5. package/lib/ai/index.js +0 -2
  6. package/lib/alchemy.d.ts +5 -0
  7. package/lib/alchemy.js +44 -1
  8. package/lib/apply.js +17 -10
  9. package/lib/aws/account-id.d.ts +4 -1
  10. package/lib/aws/account-id.js +1 -1
  11. package/lib/aws/credentials.d.ts +5 -0
  12. package/lib/aws/credentials.js +0 -0
  13. package/lib/aws/oidc/oidc-provider.js +2 -2
  14. package/lib/aws/role.js +35 -23
  15. package/lib/cloudflare/account-api-token.d.ts +168 -0
  16. package/lib/cloudflare/account-api-token.js +179 -0
  17. package/lib/cloudflare/account-id.d.ts +1 -0
  18. package/lib/cloudflare/account-id.js +0 -0
  19. package/lib/cloudflare/api.d.ts +38 -1
  20. package/lib/cloudflare/api.js +55 -4
  21. package/lib/cloudflare/bucket.d.ts +118 -3
  22. package/lib/cloudflare/bucket.js +269 -89
  23. package/lib/cloudflare/custom-domain.d.ts +75 -0
  24. package/lib/cloudflare/custom-domain.js +154 -0
  25. package/lib/cloudflare/{dns.js → dns-records.js} +14 -1
  26. package/lib/cloudflare/index.d.ts +5 -1
  27. package/lib/cloudflare/index.js +5 -1
  28. package/lib/cloudflare/permission-groups.d.ts +78 -0
  29. package/lib/cloudflare/permission-groups.js +48 -0
  30. package/lib/cloudflare/r2-rest-state-store.d.ts +2 -1
  31. package/lib/cloudflare/r2-rest-state-store.js +3 -2
  32. package/lib/cloudflare/static-site.d.ts +17 -18
  33. package/lib/cloudflare/static-site.js +19 -10
  34. package/lib/{util/encrypt.d.ts → encrypt.d.ts} +1 -1
  35. package/lib/{util/encrypt.js → encrypt.js} +1 -1
  36. package/lib/fs/file-system-state-store.js +1 -1
  37. package/lib/fs/file.d.ts +18 -0
  38. package/lib/fs/file.js +6 -0
  39. package/lib/internal/{providers.d.ts → docs/providers.d.ts} +10 -4
  40. package/lib/internal/docs/providers.js +196 -0
  41. package/lib/secret.d.ts +3 -0
  42. package/lib/secret.js +13 -0
  43. package/lib/{util/serde.d.ts → serde.d.ts} +1 -1
  44. package/lib/{util/serde.js → serde.js} +12 -4
  45. package/lib/test/bun.js +3 -2
  46. package/lib/util/sha256.d.ts +1 -0
  47. package/lib/util/sha256.js +4 -0
  48. package/lib/web/vitepress/config.d.ts +2 -1
  49. package/lib/web/vitepress/config.js +1 -0
  50. package/lib/web/vitepress/index.d.ts +1 -0
  51. package/lib/web/vitepress/index.js +1 -0
  52. package/lib/web/vitepress/process-front-matter-files.d.ts +18 -0
  53. package/lib/web/vitepress/process-front-matter-files.js +68 -0
  54. package/lib/web/vitepress/vitepress.js +3 -2
  55. package/package.json +8 -4
  56. package/src/ai/document.ts +26 -2
  57. package/src/ai/index.ts +0 -2
  58. package/src/alchemy.ts +56 -2
  59. package/src/apply.ts +21 -20
  60. package/src/aws/account-id.ts +6 -2
  61. package/src/aws/credentials.ts +6 -0
  62. package/src/aws/oidc/oidc-provider.ts +17 -17
  63. package/src/aws/role.ts +68 -54
  64. package/src/cloudflare/account-api-token.ts +365 -0
  65. package/src/cloudflare/account-id.ts +0 -0
  66. package/src/cloudflare/api.ts +88 -17
  67. package/src/cloudflare/bucket.ts +493 -133
  68. package/src/cloudflare/custom-domain.ts +318 -0
  69. package/src/cloudflare/{dns.ts → dns-records.ts} +36 -22
  70. package/src/cloudflare/index.ts +5 -1
  71. package/src/cloudflare/permission-groups.ts +137 -0
  72. package/src/cloudflare/r2-rest-state-store.ts +14 -13
  73. package/src/cloudflare/static-site.ts +20 -32
  74. package/src/dns/import-dns.ts +4 -4
  75. package/src/{util/encrypt.ts → encrypt.ts} +7 -10
  76. package/src/fs/file-system-state-store.ts +5 -5
  77. package/src/fs/file.ts +29 -0
  78. package/src/internal/docs/providers.ts +281 -0
  79. package/src/secret.ts +16 -0
  80. package/src/{util/serde.ts → serde.ts} +16 -10
  81. package/src/test/bun.ts +8 -7
  82. package/src/util/sha256.ts +5 -0
  83. package/src/web/vitepress/config.ts +3 -1
  84. package/src/web/vitepress/index.ts +1 -0
  85. package/src/web/vitepress/process-front-matter-files.ts +98 -0
  86. package/src/web/vitepress/vitepress.ts +3 -2
  87. package/lib/ai/approve.d.ts +0 -99
  88. package/lib/ai/approve.js +0 -76
  89. package/lib/ai/review.d.ts +0 -122
  90. package/lib/ai/review.js +0 -101
  91. package/lib/internal/getting-started.d.ts +0 -21
  92. package/lib/internal/getting-started.js +0 -87
  93. package/lib/internal/index.d.ts +0 -3
  94. package/lib/internal/index.js +0 -3
  95. package/lib/internal/providers.js +0 -172
  96. package/lib/internal/tutorial.d.ts +0 -104
  97. package/lib/internal/tutorial.js +0 -251
  98. package/src/ai/approve.ts +0 -163
  99. package/src/ai/review.ts +0 -213
  100. package/src/internal/getting-started.ts +0 -115
  101. package/src/internal/index.ts +0 -3
  102. package/src/internal/providers.ts +0 -241
  103. package/src/internal/tutorial.ts +0 -392
  104. /package/lib/cloudflare/{dns.d.ts → dns-records.d.ts} +0 -0
@@ -1,8 +1,12 @@
1
+ export * from "./account-api-token";
2
+ export * from "./api";
1
3
  export * from "./bindings";
2
4
  export * from "./bucket";
3
- export * from "./dns";
5
+ export * from "./custom-domain";
6
+ export * from "./dns-records";
4
7
  export * from "./durable-object-namespace";
5
8
  export * from "./kv-namespace";
9
+ export * from "./permission-groups";
6
10
  export * from "./r2-rest-state-store";
7
11
  export * from "./static-site";
8
12
  export * from "./worker";
@@ -0,0 +1,78 @@
1
+ import type { Context } from "../context";
2
+ import { Resource } from "../resource";
3
+ import { type CloudflareApiOptions } from "./api";
4
+ /**
5
+ * Cloudflare permission group as returned by the API
6
+ */
7
+ export interface PermissionGroup {
8
+ /**
9
+ * Unique identifier for the permission group
10
+ */
11
+ id: string;
12
+ /**
13
+ * Human-readable name of the permission group
14
+ */
15
+ name: string;
16
+ /**
17
+ * Scopes included in this permission group
18
+ */
19
+ scopes: string[];
20
+ }
21
+ /**
22
+ * All Cloudflare permission groups mapped by name to ID
23
+ *
24
+ * @see https://developers.cloudflare.com/r2/api/tokens/#permissions
25
+ */
26
+ export type PermissionGroups = Resource<"cloudflare::PermissionGroups"> & {
27
+ /**
28
+ * Admin Read & Write - Allows create, list, delete buckets and edit bucket configurations
29
+ * plus list, write, and read object access
30
+ */
31
+ "Workers R2 Storage Write": PermissionGroup;
32
+ /**
33
+ * Admin Read only - Allows list buckets and view bucket configuration
34
+ * plus list and read object access
35
+ */
36
+ "Workers R2 Storage Read": PermissionGroup;
37
+ /**
38
+ * Object Read & Write - Allows read, write, and list objects in specific buckets
39
+ */
40
+ "Workers R2 Storage Bucket Item Write": PermissionGroup;
41
+ /**
42
+ * Object Read only - Allows read and list objects in specific buckets
43
+ */
44
+ "Workers R2 Storage Bucket Item Read": PermissionGroup;
45
+ /**
46
+ * Dynamically discovered permission groups
47
+ */
48
+ [name: string]: PermissionGroup;
49
+ };
50
+ /**
51
+ * Lists all permission groups available for the Cloudflare account
52
+ * and returns a typed map of permission names to their IDs.
53
+ *
54
+ * This is primarily used when creating API tokens for Cloudflare services like R2.
55
+ *
56
+ * @example
57
+ * // Get all permission groups including those for R2
58
+ * const permissions = await PermissionGroups("cloudflare-permissions");
59
+ *
60
+ * // Use with AccountApiToken to create a token with proper permissions
61
+ * const token = await AccountApiToken("r2-token", {
62
+ * name: "R2 Read-Only Token",
63
+ * policies: [
64
+ * {
65
+ * effect: "allow",
66
+ * resources: {
67
+ * "com.cloudflare.edge.r2.bucket.abc123_default_my-bucket": "*"
68
+ * },
69
+ * permissionGroups: [
70
+ * {
71
+ * id: permissions["Workers R2 Storage Bucket Item Read"]
72
+ * }
73
+ * ]
74
+ * }
75
+ * ]
76
+ * });
77
+ */
78
+ export declare const PermissionGroups: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<PermissionGroups>, id: string, options?: CloudflareApiOptions) => Promise<PermissionGroups>);
@@ -0,0 +1,48 @@
1
+ import { Resource } from "../resource";
2
+ import { createCloudflareApi } from "./api";
3
+ /**
4
+ * Lists all permission groups available for the Cloudflare account
5
+ * and returns a typed map of permission names to their IDs.
6
+ *
7
+ * This is primarily used when creating API tokens for Cloudflare services like R2.
8
+ *
9
+ * @example
10
+ * // Get all permission groups including those for R2
11
+ * const permissions = await PermissionGroups("cloudflare-permissions");
12
+ *
13
+ * // Use with AccountApiToken to create a token with proper permissions
14
+ * const token = await AccountApiToken("r2-token", {
15
+ * name: "R2 Read-Only Token",
16
+ * policies: [
17
+ * {
18
+ * effect: "allow",
19
+ * resources: {
20
+ * "com.cloudflare.edge.r2.bucket.abc123_default_my-bucket": "*"
21
+ * },
22
+ * permissionGroups: [
23
+ * {
24
+ * id: permissions["Workers R2 Storage Bucket Item Read"]
25
+ * }
26
+ * ]
27
+ * }
28
+ * ]
29
+ * });
30
+ */
31
+ export const PermissionGroups = Resource("cloudflare::PermissionGroups", async function (id, options) {
32
+ // Only create and update phases are supported
33
+ if (this.phase === "delete") {
34
+ return this.destroy();
35
+ }
36
+ // Initialize API client
37
+ const api = await createCloudflareApi(options);
38
+ // Fetch permission groups from Cloudflare API
39
+ const response = await api.get(`/accounts/${api.accountId}/tokens/permission_groups`);
40
+ if (!response.ok) {
41
+ throw new Error(`Failed to fetch permission groups: ${response.statusText}`);
42
+ }
43
+ const data = (await response.json());
44
+ if (!data.success || !data.result) {
45
+ throw new Error(`API returned error: ${data.errors?.[0]?.message || "Unknown error"}`);
46
+ }
47
+ return this(Object.fromEntries(data.result.map((group) => [group.name, group])));
48
+ });
@@ -1,4 +1,5 @@
1
1
  import type { Scope } from "../scope";
2
+ import type { Secret } from "../secret";
2
3
  import type { State, StateStore } from "../state";
3
4
  /**
4
5
  * Options for CloudflareR2StateStore
@@ -17,7 +18,7 @@ export interface CloudflareR2StateStoreOptions {
17
18
  /**
18
19
  * API key to use (overrides CLOUDFLARE_API_KEY env var)
19
20
  */
20
- apiKey?: string;
21
+ apiKey?: Secret;
21
22
  /**
22
23
  * Account ID to use (overrides CLOUDFLARE_ACCOUNT_ID env var)
23
24
  */
@@ -1,5 +1,5 @@
1
+ import { deserialize, serialize } from "../serde";
1
2
  import { withExponentialBackoff } from "../util/retry";
2
- import { deserialize, serialize } from "../util/serde";
3
3
  import { createCloudflareApi } from "./api";
4
4
  /**
5
5
  * State store implementation using Cloudflare R2 API
@@ -198,7 +198,8 @@ export class R2RestStateStore {
198
198
  },
199
199
  // Retry on transient errors
200
200
  (error) => error.message?.includes("503") || error.message?.includes("timeout"), 5, // 5 retry attempts
201
- 1000);
201
+ 1000 // Start with 1 second delay
202
+ );
202
203
  }
203
204
  /**
204
205
  * Delete a state by key
@@ -72,13 +72,6 @@ export interface StaticSiteProps {
72
72
  * @default true
73
73
  */
74
74
  production?: boolean;
75
- /**
76
- * Custom domain for the site
77
- */
78
- domain?: string | {
79
- name: string;
80
- redirects?: string[];
81
- };
82
75
  build?: {
83
76
  /**
84
77
  * Command to run before deploying the site
@@ -137,13 +130,6 @@ export interface StaticSite extends Resource<"cloudflare::StaticSite"> {
137
130
  * List of uploaded asset files
138
131
  */
139
132
  assets: string[];
140
- /**
141
- * Custom domain for the site
142
- */
143
- domain?: string | {
144
- name: string;
145
- redirects?: string[];
146
- };
147
133
  /**
148
134
  * Whether the site is deployed to production
149
135
  */
@@ -198,13 +184,26 @@ export interface StaticSite extends Resource<"cloudflare::StaticSite"> {
198
184
  * });
199
185
  *
200
186
  * @example
201
- * // Create a static site with custom error page and index
202
- * const customSite = await StaticSite("custom-site", {
187
+ * // Create a static site with a custom domain using the CustomDomain resource
188
+ * const site = await StaticSite("custom-site", {
203
189
  * name: "custom-site",
204
190
  * dir: "./www",
205
191
  * errorPage: "404.html",
206
- * indexPage: "home.html",
207
- * domain: "www.example.com"
192
+ * indexPage: "home.html"
193
+ * });
194
+ *
195
+ * // Then configure the custom domain separately
196
+ * const domain = await CustomDomain("custom-domain", {
197
+ * name: "www.example.com",
198
+ * zoneId: "abcdef123456789",
199
+ * workerName: site.name
200
+ * });
201
+ *
202
+ * @example
203
+ * // Create a static site with multiple domains (primary + redirects)
204
+ * const site = await StaticSite("multi-domain-site", {
205
+ * name: "multi-domain-site",
206
+ * dir: "./public"
208
207
  * });
209
208
  *
210
209
  * @see https://developers.cloudflare.com/workers/platform/sites
@@ -50,13 +50,26 @@ const __dirname = import.meta.dirname;
50
50
  * });
51
51
  *
52
52
  * @example
53
- * // Create a static site with custom error page and index
54
- * const customSite = await StaticSite("custom-site", {
53
+ * // Create a static site with a custom domain using the CustomDomain resource
54
+ * const site = await StaticSite("custom-site", {
55
55
  * name: "custom-site",
56
56
  * dir: "./www",
57
57
  * errorPage: "404.html",
58
- * indexPage: "home.html",
59
- * domain: "www.example.com"
58
+ * indexPage: "home.html"
59
+ * });
60
+ *
61
+ * // Then configure the custom domain separately
62
+ * const domain = await CustomDomain("custom-domain", {
63
+ * name: "www.example.com",
64
+ * zoneId: "abcdef123456789",
65
+ * workerName: site.name
66
+ * });
67
+ *
68
+ * @example
69
+ * // Create a static site with multiple domains (primary + redirects)
70
+ * const site = await StaticSite("multi-domain-site", {
71
+ * name: "multi-domain-site",
72
+ * dir: "./public"
60
73
  * });
61
74
  *
62
75
  * @see https://developers.cloudflare.com/workers/platform/sites
@@ -64,6 +77,8 @@ const __dirname = import.meta.dirname;
64
77
  export const StaticSite = Resource("cloudflare::StaticSite", {
65
78
  alwaysUpdate: true,
66
79
  }, async function (id, props) {
80
+ // Create Cloudflare API client with automatic account discovery
81
+ const api = await createCloudflareApi();
67
82
  if (this.phase === "delete") {
68
83
  // For delete operations, we'll rely on the Worker delete to clean up
69
84
  // Return empty output for deleted state
@@ -113,8 +128,6 @@ export const StaticSite = Resource("cloudflare::StaticSite", {
113
128
  // Use the provided name
114
129
  const siteName = props.name;
115
130
  const indexPage = props.indexPage || "index.html";
116
- // Create Cloudflare API client with automatic account discovery
117
- const api = await createCloudflareApi();
118
131
  // Step 1: Create or get the KV namespace for assets
119
132
  const [kv, assetManifest] = await Promise.all([
120
133
  KVNamespace("assets", {
@@ -122,9 +135,6 @@ export const StaticSite = Resource("cloudflare::StaticSite", {
122
135
  }),
123
136
  generateAssetManifest(props.dir),
124
137
  ]);
125
- console.log({
126
- assetManifest,
127
- });
128
138
  // Step 3: Upload assets to KV
129
139
  await uploadAssetManifest(api, kv.namespaceId, assetManifest);
130
140
  // Prepare the bindings for the worker
@@ -196,7 +206,6 @@ export const StaticSite = Resource("cloudflare::StaticSite", {
196
206
  assets: assetManifest.map((item) => item.key),
197
207
  createdAt: this.output?.createdAt || now,
198
208
  updatedAt: now,
199
- domain: props.domain,
200
209
  production: props.production !== false,
201
210
  url: worker.url,
202
211
  routes,
@@ -5,7 +5,7 @@
5
5
  * @param key - The encryption key
6
6
  * @returns The base64-encoded encrypted value with nonce
7
7
  */
8
- export declare function encryptWithKey(value: string, key: string): Promise<string>;
8
+ export declare function encrypt(value: string, key: string): Promise<string>;
9
9
  /**
10
10
  * Decrypt a value encrypted with a symmetric key
11
11
  *
@@ -6,7 +6,7 @@ import sodium from "libsodium-wrappers";
6
6
  * @param key - The encryption key
7
7
  * @returns The base64-encoded encrypted value with nonce
8
8
  */
9
- export async function encryptWithKey(value, key) {
9
+ export async function encrypt(value, key) {
10
10
  // Initialize libsodium
11
11
  await sodium.ready;
12
12
  // Derive a key from the passphrase
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { deserialize, serialize } from "../serde";
3
4
  import { ignore } from "../util/ignore";
4
- import { deserialize, serialize } from "../util/serde";
5
5
  const stateRootDir = path.join(process.cwd(), ".alchemy");
6
6
  export class FileSystemStateStore {
7
7
  scope;
package/lib/fs/file.d.ts CHANGED
@@ -45,6 +45,24 @@ declare module "../alchemy" {
45
45
  */
46
46
  files(paths: string[]): Promise<FileCollection>;
47
47
  files(path: string, ...paths: string[]): Promise<FileCollection>;
48
+ /**
49
+ * Gets all of the files in a directory.
50
+ * @param path Path to the directory
51
+ * @param props Optional properties
52
+ * @returns Promise resolving to a FileCollection
53
+ *
54
+ * @example
55
+ * // Get all files in a directory
56
+ * const files = await alchemy.folder("./docs");
57
+ *
58
+ */
59
+ folder(path: string, props?: {
60
+ /**
61
+ * Whether to recursively get all files in the directory
62
+ * @default false
63
+ */
64
+ recursive?: boolean;
65
+ }): Promise<FileCollection>;
48
66
  }
49
67
  }
50
68
  /**
package/lib/fs/file.js CHANGED
@@ -17,6 +17,12 @@ alchemy.files = async (...args) => {
17
17
  ]))),
18
18
  };
19
19
  };
20
+ alchemy.folder = async (dir, props) => {
21
+ const files = await fs.promises.readdir(dir, {
22
+ recursive: props?.recursive ?? false,
23
+ });
24
+ return alchemy.files(files.map((file) => path.join(dir, file)));
25
+ };
20
26
  /**
21
27
  * File Resource
22
28
  *
@@ -1,5 +1,5 @@
1
- import { Document } from "../ai";
2
- import { Folder } from "../fs";
1
+ import { Document } from "../../ai";
2
+ import { Folder } from "../../fs";
3
3
  export interface DocsProps {
4
4
  /**
5
5
  * The output directory for the docs.
@@ -18,10 +18,16 @@ export interface DocsProps {
18
18
  * @default true (all docs)
19
19
  */
20
20
  filter?: boolean | number;
21
+ /**
22
+ * Whether to run in parallel.
23
+ *
24
+ * @default true
25
+ */
26
+ parallel?: boolean;
21
27
  }
22
- export type AlchemyProviderDocs = {
28
+ export type Providers = {
23
29
  dir: string;
24
30
  provider: string;
25
31
  documents: Document[];
26
32
  }[];
27
- export declare function AlchemyProviderDocs({ srcDir, outDir, filter, }: DocsProps): Promise<AlchemyProviderDocs>;
33
+ export declare function Providers({ srcDir, outDir, filter, parallel, }: DocsProps): Promise<Providers>;
@@ -0,0 +1,196 @@
1
+ import { type } from "arktype";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ import { Data, Document } from "../../ai";
5
+ import { alchemy } from "../../alchemy";
6
+ import { Folder } from "../../fs";
7
+ export async function Providers({ srcDir, outDir, filter, parallel = true, }) {
8
+ outDir = typeof outDir === "string" ? outDir : outDir.path;
9
+ const exclude = [
10
+ "util",
11
+ "test",
12
+ "vitepress",
13
+ "vite",
14
+ "shadcn",
15
+ "internal",
16
+ "web",
17
+ ];
18
+ // Get all folders in the alchemy/src directory
19
+ let providers = (await fs.readdir(srcDir, {
20
+ withFileTypes: true,
21
+ }))
22
+ .filter((dirent) => dirent.isDirectory() && !exclude.includes(dirent.name))
23
+ .map((dirent) => path.join(dirent.parentPath, dirent.name));
24
+ // For each provider, list all files
25
+ if (filter === false) {
26
+ return [];
27
+ }
28
+ else if (typeof filter === "number") {
29
+ providers = providers.slice(0, filter);
30
+ }
31
+ if (parallel) {
32
+ return await Promise.all(providers.map((provider) => generateProviderDocs({ provider, outDir, parallel })));
33
+ }
34
+ else {
35
+ const generatedProviders = [];
36
+ for (const provider of providers) {
37
+ generatedProviders.push(await generateProviderDocs({ provider, outDir, parallel }));
38
+ }
39
+ return generatedProviders;
40
+ }
41
+ }
42
+ async function generateProviderDocs({ provider, outDir, parallel, }) {
43
+ const providerName = path.basename(provider);
44
+ const files = (await fs.readdir(path.resolve(provider), {
45
+ withFileTypes: true,
46
+ }))
47
+ .filter((dirent) => dirent.isFile())
48
+ .map((dirent) => path.relative(process.cwd(), path.resolve(provider, dirent.name)))
49
+ .filter((file) => file.endsWith(".ts") && !file.endsWith("index.ts"));
50
+ const { object: { groups }, } = await Data(`docs/${providerName}`, {
51
+ model: {
52
+ id: "o3-mini",
53
+ provider: "openai",
54
+ options: {
55
+ reasoningEffort: "high",
56
+ },
57
+ },
58
+ temperature: 0.1,
59
+ schema: type({
60
+ groups: type({
61
+ identifier: type("string").describe("The identifier of the file's primary exported Resource/Function/Type, e.g. Bucket or StaticSite, AstroFile, TypeScriptFile"),
62
+ filename: type("string").describe("The filename of the Resource's Document, e.g. bucket.md or static-site.md"),
63
+ category: type("'Resource'|'Client'|'Utility'|'Types'").describe("The classification of the Resource's Document, one of: Resource, Client, Utility, or Types."),
64
+ }).array(),
65
+ }),
66
+ system: await alchemy `
67
+ You are a technical writer tasked with identifying the distinct documents that need to be written for a document group (folder) in a documentation site.
68
+ You will be provided with a list of documents and instructions on how to classify them.
69
+ Each document has a title, file name, and category.
70
+ `,
71
+ prompt: await alchemy `
72
+ Identify and classify the documents that need to be written for the '${provider}' Service's Alchemy Resources.
73
+ For background knowledge on Alchemy, see ${alchemy.file("./README.md")}.
74
+ For background knowledge on the structure of an Alchemy Resource, see ${alchemy.file("./.cursorrules")}.
75
+
76
+ The ${provider} Service has the following resources:
77
+ ${alchemy.files(files)}
78
+
79
+ A file is considered a "Resource" if it contains a const <ResourceName> = Resource(...) call or if it is a function that calls a Resource function, e.g. const TypeScriptFile = () => File(...).
80
+ A file is considered a "Client" if it exposes a wrapper around creating a SDK client or fetch.
81
+ A file is considered a "Utility" if it contains utility functions that are not resources or clients.
82
+ A file is considered a "Types" if it contains just type definitions and maybe helpers around working with those types.
83
+
84
+ The title should be simply the name of the resource's const in code (with spaces added in between each word), e.g. "Bucket" or "Function", except with spaces, e.g. "Static Site" for "const StaticSite". Maintain all other casing.
85
+
86
+ // "Resource Name"
87
+ const ResourceName = Resource(...)
88
+ `,
89
+ });
90
+ const providerDocsDir = (await Folder(path.join(outDir, providerName))).path;
91
+ let documents = [];
92
+ if (parallel) {
93
+ documents = await Promise.all(groups.filter((g) => g.category === "Resource").map(generateDocument));
94
+ }
95
+ else {
96
+ for (const g of groups.filter((g) => g.category === "Resource")) {
97
+ documents.push(await generateDocument(g));
98
+ }
99
+ }
100
+ async function generateDocument(g) {
101
+ return Document(`docs/${providerName}/${g.identifier}`, {
102
+ title: g.identifier,
103
+ path: path.join(providerDocsDir, `${g.filename.replace(".ts", "").replace(".md", "")}.md`),
104
+ freeze: true,
105
+ model: {
106
+ id: "claude-3-5-sonnet-latest",
107
+ provider: "anthropic",
108
+ // options: {
109
+ // reasoningEffort: "high",
110
+ // },
111
+ },
112
+ prompt: await alchemy `
113
+ You are a technical writer writing API documentation for an Alchemy IaC Resource.
114
+ See ${alchemy.file("./README.md")} to understand the overview of Alchemy.
115
+ See ${alchemy.file("./.cursorrules")} to better understand the structure and convention of an Alchemy Resource.
116
+
117
+ Relevant files for the ${providerName} Service:
118
+ ${alchemy.files(files)}
119
+
120
+ Write concise documentation for the "${g.identifier}" Resource.
121
+
122
+ > [!CAUTION]
123
+ > Avoid the temptation to over explain or over describe. Focus on concise, simple, high value snippets. One heading and 0-1 descriptions per snippet.
124
+
125
+ > [!TIP]
126
+ > Make sure the examples follow a natural progression from the minimal example to logical next steps of how the Resource might be used.
127
+
128
+ Each document must follow the following format:
129
+
130
+ # ${g.identifier}
131
+
132
+ (simple description with an external link to the provider's website)
133
+ e.g.
134
+ The Efs component lets you add [Amazon Elastic File System (EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) to your app.
135
+
136
+ # Minimal Example
137
+
138
+ (brief 1-2 sentences of what it does)
139
+
140
+ \`\`\`ts
141
+ import { ${g.identifier.replaceAll(" ", "")} } from "alchemy/${providerName}";
142
+
143
+ (example)
144
+ \`\`\`
145
+
146
+ # (one heading per variation)
147
+
148
+ (brief 1-2 sentences of what it does)
149
+
150
+ \`\`\`ts
151
+ import { ${g.identifier.replaceAll(" ", "")} } from "alchemy/${providerName}";
152
+
153
+ (example)
154
+ \`\`\`
155
+
156
+ Before writing the document, think through:
157
+ 1. What is the minimal, most common example use case for this resource?
158
+ 2. What are the variations (e.g. combination of different options) that are also commonly used, e.g. specifying the memory size of a lambda function.
159
+ 3. Make sure to draw from the examples and your understanding of Alchemy.
160
+
161
+ Refer to alchemy docs to understand the context of how this documentation is consumed:
162
+ - ${alchemy.file("./alchemy-web/docs/what-is-alchemy.md")}
163
+ - ${alchemy.file("./alchemy-web/docs/getting-started.md")}
164
+ - ${alchemy.folder("./alchemy-web/docs/concepts/")}
165
+
166
+ ${providerName === "cloudflare"
167
+ ? await alchemy `# Bind to a Worker
168
+ (if it is a Cloudflare Resource)
169
+
170
+ (brief 1-2 sentences of what it does)
171
+
172
+ \`\`\`ts
173
+ import { Worker, ${g.identifier.replaceAll(" ", "")} } from "alchemy/${providerName}";
174
+
175
+ const myResource = await ${g.identifier.replaceAll(" ", "")}("my-resource", {
176
+ // ...
177
+ });
178
+
179
+ await Worker("my-worker", {
180
+ name: "my-worker",
181
+ script: "console.log('Hello, world!')",
182
+ bindings: {
183
+ myResource,
184
+ },
185
+ });
186
+ \`\`\``
187
+ : ""}
188
+ `,
189
+ });
190
+ }
191
+ return {
192
+ dir: providerDocsDir,
193
+ provider: providerName,
194
+ documents,
195
+ };
196
+ }
package/lib/secret.d.ts CHANGED
@@ -72,3 +72,6 @@ export declare function isSecret(binding: any): binding is Secret;
72
72
  * @throws {Error} If no password is set in the alchemy application options or current scope
73
73
  */
74
74
  export declare function secret<S extends string | undefined>(unencrypted: S): Secret;
75
+ export declare namespace secret {
76
+ function env(name: string, value?: string, error?: string): Promise<Secret>;
77
+ }
package/lib/secret.js CHANGED
@@ -82,3 +82,16 @@ export function secret(unencrypted) {
82
82
  }
83
83
  return new Secret(unencrypted);
84
84
  }
85
+ (function (secret) {
86
+ async function env(name, value, error) {
87
+ const alchemy = await import("./alchemy");
88
+ const result = await alchemy.env(name, value, error);
89
+ if (typeof result === "string") {
90
+ return secret(result);
91
+ }
92
+ else {
93
+ throw new Error(`Secret environment variable ${name} is not a string`);
94
+ }
95
+ }
96
+ secret.env = env;
97
+ })(secret || (secret = {}));
@@ -1,4 +1,4 @@
1
- import { Scope } from "../scope";
1
+ import { Scope } from "./scope";
2
2
  export declare function serialize(scope: Scope, value: any, options?: {
3
3
  encrypt?: boolean;
4
4
  }): Promise<any>;
@@ -1,6 +1,6 @@
1
- import { Scope } from "../scope";
2
- import { Secret } from "../secret";
3
- import { decryptWithKey, encryptWithKey } from "./encrypt";
1
+ import { decryptWithKey, encrypt } from "./encrypt";
2
+ import { Scope } from "./scope";
3
+ import { Secret } from "./secret";
4
4
  // zero-dependency type guard for ArkType
5
5
  function isType(value) {
6
6
  return (value &&
@@ -17,7 +17,7 @@ export async function serialize(scope, value, options) {
17
17
  }
18
18
  return {
19
19
  "@secret": options?.encrypt !== false
20
- ? await encryptWithKey(value.unencrypted, scope.password)
20
+ ? await encrypt(value.unencrypted, scope.password)
21
21
  : value.unencrypted,
22
22
  };
23
23
  }
@@ -26,6 +26,11 @@ export async function serialize(scope, value, options) {
26
26
  "@schema": value.toJSON(),
27
27
  };
28
28
  }
29
+ else if (value instanceof Date) {
30
+ return {
31
+ "@date": value.toISOString(),
32
+ };
33
+ }
29
34
  else if (value instanceof Scope) {
30
35
  return undefined;
31
36
  }
@@ -51,6 +56,9 @@ export async function deserialize(scope, value) {
51
56
  else if ("@schema" in value) {
52
57
  return value["@schema"];
53
58
  }
59
+ else if ("@date" in value) {
60
+ return new Date(value["@date"]);
61
+ }
54
62
  else {
55
63
  return Object.fromEntries(await Promise.all(Object.entries(value).map(async ([key, value]) => [
56
64
  key,