alchemy 0.2.2 → 0.2.4

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 (161) hide show
  1. package/lib/ai/ark.d.ts +11 -0
  2. package/lib/ai/ark.js +86 -0
  3. package/lib/ai/client.d.ts +51 -0
  4. package/lib/ai/client.js +29 -0
  5. package/lib/ai/document.d.ts +97 -0
  6. package/lib/ai/document.js +82 -0
  7. package/lib/ai/index.d.ts +2 -0
  8. package/lib/ai/index.js +2 -0
  9. package/lib/ai/object.d.ts +101 -0
  10. package/lib/ai/object.js +70 -0
  11. package/lib/alchemy.d.ts +84 -2
  12. package/lib/alchemy.js +114 -10
  13. package/lib/apply.d.ts +1 -1
  14. package/lib/apply.js +13 -10
  15. package/lib/aws/bucket.d.ts +87 -1
  16. package/lib/aws/bucket.js +48 -1
  17. package/lib/aws/function.d.ts +186 -1
  18. package/lib/aws/function.js +62 -8
  19. package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
  20. package/lib/aws/oidc/github-oidc-provider.js +68 -0
  21. package/lib/aws/oidc/oidc-provider.d.ts +14 -6
  22. package/lib/aws/oidc/oidc-provider.js +26 -5
  23. package/lib/aws/policy-attachment.d.ts +44 -1
  24. package/lib/aws/policy-attachment.js +31 -0
  25. package/lib/aws/policy.d.ts +160 -1
  26. package/lib/aws/policy.js +78 -0
  27. package/lib/aws/queue.d.ts +83 -1
  28. package/lib/aws/queue.js +39 -0
  29. package/lib/aws/role.d.ts +162 -1
  30. package/lib/aws/role.js +114 -0
  31. package/lib/aws/ses.d.ts +57 -2
  32. package/lib/aws/ses.js +42 -1
  33. package/lib/aws/table.d.ts +96 -1
  34. package/lib/aws/table.js +36 -0
  35. package/lib/cloudflare/asset-manifest.js +0 -1
  36. package/lib/cloudflare/bound.js +0 -1
  37. package/lib/cloudflare/bucket.d.ts +37 -1
  38. package/lib/cloudflare/bucket.js +36 -0
  39. package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
  40. package/lib/cloudflare/durable-object-namespace.js +22 -0
  41. package/lib/cloudflare/kv-namespace.d.ts +37 -1
  42. package/lib/cloudflare/kv-namespace.js +36 -0
  43. package/lib/cloudflare/static-site.d.ts +53 -1
  44. package/lib/cloudflare/static-site.js +53 -1
  45. package/lib/cloudflare/worker-metadata.js +0 -1
  46. package/lib/cloudflare/worker.d.ts +64 -1
  47. package/lib/cloudflare/worker.js +63 -0
  48. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  49. package/lib/cloudflare/zone-settings.js +0 -1
  50. package/lib/cloudflare/zone.d.ts +56 -1
  51. package/lib/cloudflare/zone.js +55 -0
  52. package/lib/context.d.ts +9 -4
  53. package/lib/context.js +4 -2
  54. package/lib/destroy.js +9 -8
  55. package/lib/esbuild/bundle.d.ts +43 -4
  56. package/lib/esbuild/bundle.js +16 -0
  57. package/lib/fs/file-collection.d.ts +16 -0
  58. package/lib/fs/file-collection.js +6 -0
  59. package/lib/fs/file-ref.d.ts +14 -0
  60. package/lib/fs/file-ref.js +6 -0
  61. package/lib/fs/file.d.ts +78 -5
  62. package/lib/fs/file.js +39 -3
  63. package/lib/fs/folder.d.ts +37 -5
  64. package/lib/fs/folder.js +28 -3
  65. package/lib/fs/index.d.ts +6 -0
  66. package/lib/fs/index.js +6 -0
  67. package/lib/fs/json-file.d.ts +16 -0
  68. package/lib/fs/json-file.js +7 -0
  69. package/lib/fs/text-file.d.ts +12 -0
  70. package/lib/fs/text-file.js +7 -0
  71. package/lib/fs/typescript-file.d.ts +19 -0
  72. package/lib/fs/typescript-file.js +14 -0
  73. package/lib/fs/yaml-file.d.ts +19 -0
  74. package/lib/fs/yaml-file.js +8 -0
  75. package/lib/github/secret.d.ts +63 -2
  76. package/lib/github/secret.js +61 -1
  77. package/lib/internal/docs.d.ts +5 -0
  78. package/lib/internal/docs.js +324 -0
  79. package/lib/resource.d.ts +2 -2
  80. package/lib/resource.js +4 -0
  81. package/lib/scope.d.ts +1 -1
  82. package/lib/scope.js +6 -6
  83. package/lib/secret.d.ts +67 -0
  84. package/lib/secret.js +67 -0
  85. package/lib/shadcn/component.d.ts +1 -1
  86. package/lib/state.d.ts +1 -1
  87. package/lib/state.js +8 -1
  88. package/lib/stripe/price.d.ts +51 -1
  89. package/lib/stripe/price.js +50 -0
  90. package/lib/stripe/product.d.ts +39 -1
  91. package/lib/stripe/product.js +38 -0
  92. package/lib/stripe/webhook.d.ts +46 -1
  93. package/lib/stripe/webhook.js +45 -0
  94. package/lib/test/bun.d.ts +64 -0
  95. package/lib/test/bun.js +35 -3
  96. package/lib/util/serde.d.ts +3 -1
  97. package/lib/util/serde.js +20 -4
  98. package/lib/vite/vite.d.ts +1 -1
  99. package/lib/vitepress/dependencies.d.ts +12 -0
  100. package/lib/vitepress/dependencies.js +35 -0
  101. package/lib/vitepress/home-page.d.ts +133 -0
  102. package/lib/vitepress/home-page.js +11 -0
  103. package/lib/vitepress/index.d.ts +2 -0
  104. package/lib/vitepress/index.js +2 -0
  105. package/lib/vitepress/vitepress.d.ts +71 -0
  106. package/lib/vitepress/vitepress.js +266 -0
  107. package/package.json +22 -10
  108. package/src/ai/ark.ts +118 -0
  109. package/src/ai/client.ts +78 -0
  110. package/src/ai/document.ts +160 -0
  111. package/src/ai/index.ts +2 -0
  112. package/src/ai/object.ts +149 -0
  113. package/src/alchemy.ts +192 -17
  114. package/src/apply.ts +25 -13
  115. package/src/aws/bucket.ts +111 -7
  116. package/src/aws/function.ts +231 -10
  117. package/src/aws/oidc/github-oidc-provider.ts +83 -0
  118. package/src/aws/oidc/oidc-provider.ts +39 -7
  119. package/src/aws/policy-attachment.ts +44 -1
  120. package/src/aws/policy.ts +177 -2
  121. package/src/aws/queue.ts +89 -0
  122. package/src/aws/role.ts +174 -2
  123. package/src/aws/ses.ts +56 -1
  124. package/src/aws/table.ts +103 -0
  125. package/src/cloudflare/bucket.ts +36 -0
  126. package/src/cloudflare/durable-object-namespace.ts +25 -0
  127. package/src/cloudflare/kv-namespace.ts +36 -0
  128. package/src/cloudflare/static-site.ts +53 -1
  129. package/src/cloudflare/worker.ts +63 -0
  130. package/src/cloudflare/zone.ts +55 -0
  131. package/src/context.ts +30 -10
  132. package/src/destroy.ts +11 -8
  133. package/src/esbuild/bundle.ts +53 -3
  134. package/src/fs/file-collection.ts +24 -0
  135. package/src/fs/file-ref.ts +22 -0
  136. package/src/fs/file.ts +107 -6
  137. package/src/fs/folder.ts +45 -5
  138. package/src/fs/index.ts +6 -0
  139. package/src/fs/json-file.ts +23 -0
  140. package/src/fs/text-file.ts +19 -0
  141. package/src/fs/typescript-file.ts +36 -0
  142. package/src/fs/yaml-file.ts +26 -0
  143. package/src/github/secret.ts +65 -2
  144. package/src/internal/docs.ts +369 -0
  145. package/src/resource.ts +7 -2
  146. package/src/scope.ts +9 -9
  147. package/src/secret.ts +67 -0
  148. package/src/state.ts +9 -2
  149. package/src/stripe/price.ts +50 -0
  150. package/src/stripe/product.ts +38 -0
  151. package/src/stripe/webhook.ts +45 -0
  152. package/src/test/bun.ts +83 -3
  153. package/src/util/serde.ts +30 -4
  154. package/src/vitepress/dependencies.ts +68 -0
  155. package/src/vitepress/home-page.ts +166 -0
  156. package/src/vitepress/index.md +75 -0
  157. package/src/vitepress/index.ts +2 -0
  158. package/src/vitepress/vitepress.ts +382 -0
  159. package/lib/project/vite.d.ts +0 -90
  160. package/lib/project/vite.js +0 -228
  161. package/src/project/vite.ts +0 -406
@@ -1,10 +1,42 @@
1
1
  import type { Context } from "../context";
2
2
  import { Resource } from "../resource";
3
+ export interface FolderProps {
4
+ /**
5
+ * The path of the folder
6
+ */
7
+ path?: string;
8
+ /**
9
+ * Whether to delete the folder during the delete phase
10
+ * @default true
11
+ */
12
+ delete?: boolean;
13
+ }
14
+ /**
15
+ * Base folder resource type
16
+ */
3
17
  export interface Folder extends Resource<"fs::Folder"> {
4
18
  path: string;
5
19
  }
6
- export declare const Folder: ((this: Context<Folder>, id: string, { path: dirPath }: {
7
- path: string;
8
- }) => Promise<Folder>) | (((this: any, id: string, props: {
9
- path: string;
10
- }) => never) & (new (_: never) => never));
20
+ /**
21
+ * Folder Resource
22
+ *
23
+ * Creates and manages directories in the filesystem with automatic parent
24
+ * directory creation and cleanup on deletion.
25
+ *
26
+ * @example
27
+ * // Create a directory using id as path
28
+ * const dir = await Folder("uploads");
29
+ *
30
+ * @example
31
+ * // Create a directory with explicit path
32
+ * const dir = await Folder("uploads", {
33
+ * path: "uploads"
34
+ * });
35
+ *
36
+ * @example
37
+ * // Create a nested directory structure
38
+ * const logs = await Folder("var/log/app", {
39
+ * path: "var/log/app"
40
+ * });
41
+ */
42
+ export declare const Folder: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Folder>, id: string, props?: FolderProps) => Promise<Folder>);
package/lib/fs/folder.js CHANGED
@@ -1,10 +1,35 @@
1
1
  import fs from "node:fs";
2
2
  import { Resource } from "../resource";
3
3
  import { ignore } from "../util/ignore";
4
- export const Folder = Resource("fs::Folder", async function (id, { path: dirPath }) {
4
+ /**
5
+ * Folder Resource
6
+ *
7
+ * Creates and manages directories in the filesystem with automatic parent
8
+ * directory creation and cleanup on deletion.
9
+ *
10
+ * @example
11
+ * // Create a directory using id as path
12
+ * const dir = await Folder("uploads");
13
+ *
14
+ * @example
15
+ * // Create a directory with explicit path
16
+ * const dir = await Folder("uploads", {
17
+ * path: "uploads"
18
+ * });
19
+ *
20
+ * @example
21
+ * // Create a nested directory structure
22
+ * const logs = await Folder("var/log/app", {
23
+ * path: "var/log/app"
24
+ * });
25
+ */
26
+ export const Folder = Resource("fs::Folder", async function (id, props) {
27
+ const dirPath = props?.path ?? id;
5
28
  if (this.phase === "delete") {
6
- // we just do a best effort attempt
7
- await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
29
+ if (props?.delete !== false) {
30
+ // we just do a best effort attempt
31
+ await ignore(["ENOENT", "ENOTEMPTY"], async () => fs.promises.rmdir(dirPath));
32
+ }
8
33
  return this.destroy();
9
34
  }
10
35
  else {
package/lib/fs/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
1
  export * from "./file";
2
+ export * from "./file-collection";
3
+ export * from "./file-ref";
2
4
  export * from "./folder";
5
+ export * from "./json-file";
6
+ export * from "./text-file";
7
+ export * from "./typescript-file";
8
+ export * from "./yaml-file";
package/lib/fs/index.js CHANGED
@@ -1,2 +1,8 @@
1
1
  export * from "./file";
2
+ export * from "./file-collection";
3
+ export * from "./file-ref";
2
4
  export * from "./folder";
5
+ export * from "./json-file";
6
+ export * from "./text-file";
7
+ export * from "./typescript-file";
8
+ export * from "./yaml-file";
@@ -0,0 +1,16 @@
1
+ import { File } from "./file";
2
+ /**
3
+ * Creates a JSON file with formatted content
4
+ *
5
+ * @example
6
+ * // Create a JSON configuration file
7
+ * const config = await JsonFile("config.json", {
8
+ * api: {
9
+ * endpoint: "https://api.example.com",
10
+ * version: "v1"
11
+ * },
12
+ * features: ["auth", "logging"]
13
+ * });
14
+ */
15
+ export type JsonFile = File;
16
+ export declare function JsonFile(id: string, content: any): Promise<JsonFile>;
@@ -0,0 +1,7 @@
1
+ import { File } from "./file";
2
+ export function JsonFile(id, content) {
3
+ return File(id, {
4
+ path: id,
5
+ content: JSON.stringify(content, null, 2),
6
+ });
7
+ }
@@ -0,0 +1,12 @@
1
+ import { File } from "./file";
2
+ /**
3
+ * Creates a plain text file
4
+ *
5
+ * @example
6
+ * // Create a text file with content
7
+ * const readme = await TextFile("README.md",
8
+ * "# Project Name\n\nProject description goes here."
9
+ * );
10
+ */
11
+ export type TextFile = File;
12
+ export declare function TextFile(id: string, content: string): Promise<TextFile>;
@@ -0,0 +1,7 @@
1
+ import { File } from "./file";
2
+ export function TextFile(id, content) {
3
+ return File(id, {
4
+ path: id,
5
+ content,
6
+ });
7
+ }
@@ -0,0 +1,19 @@
1
+ import { File } from "./file";
2
+ /**
3
+ * Creates a TypeScript file with formatted content using prettier
4
+ *
5
+ * @example
6
+ * // Create a TypeScript file
7
+ * const component = await TypeScriptFile("Component.ts", `
8
+ * interface Props {
9
+ * name: string;
10
+ * age: number;
11
+ * }
12
+ *
13
+ * export function Component({ name, age }: Props) {
14
+ * return <div>Hello {name}, you are {age} years old</div>;
15
+ * }
16
+ * `);
17
+ */
18
+ export type TypeScriptFile = File;
19
+ export declare function TypeScriptFile(id: string, content: string): Promise<TypeScriptFile>;
@@ -0,0 +1,14 @@
1
+ import { File } from "./file";
2
+ export async function TypeScriptFile(id, content) {
3
+ const prettier = await import("prettier");
4
+ return File(id, {
5
+ path: id,
6
+ content: await prettier.format(content, {
7
+ parser: "typescript",
8
+ editor: {
9
+ tabWidth: 2,
10
+ indentWidth: 2,
11
+ },
12
+ }),
13
+ });
14
+ }
@@ -0,0 +1,19 @@
1
+ import { File } from "./file";
2
+ /**
3
+ * Creates a YAML file with formatted content
4
+ *
5
+ * @example
6
+ * // Create a YAML configuration file
7
+ * const config = await YamlFile("config.yaml", {
8
+ * server:
9
+ * host: "localhost"
10
+ * port: 3000
11
+ * database:
12
+ * url: "postgresql://localhost:5432/db"
13
+ * pool:
14
+ * min: 1
15
+ * max: 10
16
+ * });
17
+ */
18
+ export type YamlFile = File;
19
+ export declare function YamlFile(id: string, content: any): Promise<YamlFile>;
@@ -0,0 +1,8 @@
1
+ import { File } from "./file";
2
+ export async function YamlFile(id, content) {
3
+ const yaml = await import("yaml");
4
+ return File(id, {
5
+ path: id,
6
+ content: yaml.stringify(content),
7
+ });
8
+ }
@@ -23,8 +23,11 @@ export interface GitHubSecretProps {
23
23
  value: Secret;
24
24
  /**
25
25
  * Optional GitHub API token (overrides environment variable)
26
+ * If not provided, will use GITHUB_TOKEN environment variable
27
+ * Token must have 'repo' scope for private repositories
28
+ * or 'public_repo' scope for public repositories
26
29
  */
27
- token?: string;
30
+ token?: Secret;
28
31
  }
29
32
  /**
30
33
  * Output returned after Secret creation/update
@@ -41,5 +44,63 @@ export interface GitHubSecretOutput extends Resource<"github::Secret">, Omit<Git
41
44
  }
42
45
  /**
43
46
  * Resource for managing GitHub repository secrets
47
+ *
48
+ * Authentication is handled in the following order:
49
+ * 1. `token` parameter in the resource props (if provided)
50
+ * 2. `GITHUB_TOKEN` environment variable
51
+ *
52
+ * The token must have the following permissions:
53
+ * - 'repo' scope for private repositories
54
+ * - 'public_repo' scope for public repositories
55
+ *
56
+ * @example
57
+ * // Create a secret using GITHUB_TOKEN environment variable:
58
+ * const secret = await GitHubSecret("my-secret", {
59
+ * owner: "my-github-username",
60
+ * repository: "my-repo",
61
+ * name: "API_KEY",
62
+ * value: alchemy.secret("my-secret-value")
63
+ * });
64
+ *
65
+ * @example
66
+ * // Create a secret with a custom GitHub token:
67
+ * const secret = await GitHubSecret("my-secret", {
68
+ * owner: "my-github-username",
69
+ * repository: "my-repo",
70
+ * name: "API_KEY",
71
+ * value: alchemy.secret("my-secret-value"),
72
+ * token: alchemy.secret(process.env.CUSTOM_GITHUB_TOKEN)
73
+ * });
74
+ *
75
+ * @example
76
+ * // Create multiple secrets with environment variables:
77
+ * const secrets = await Promise.all([
78
+ * GitHubSecret("aws-secret", {
79
+ * owner: "my-github-username",
80
+ * repository: "cloud-app",
81
+ * name: "AWS_ROLE_ARN",
82
+ * value: alchemy.secret(process.env.AWS_ROLE_ARN)
83
+ * }),
84
+ * GitHubSecret("cf-secret", {
85
+ * owner: "my-github-username",
86
+ * repository: "cloud-app",
87
+ * name: "CLOUDFLARE_API_KEY",
88
+ * value: alchemy.secret(process.env.CLOUDFLARE_API_KEY)
89
+ * })
90
+ * ]);
91
+ *
92
+ * @example
93
+ * // Create a secret in a secure scope with a password:
94
+ * await alchemy.run("secure-scope", {
95
+ * password: process.env.SECRET_PASSPHRASE
96
+ * }, async () => {
97
+ * const secret = await GitHubSecret("deploy-secret", {
98
+ * owner: "my-github-username",
99
+ * repository: "my-app",
100
+ * name: "DEPLOY_TOKEN",
101
+ * value: alchemy.secret(process.env.DEPLOY_TOKEN),
102
+ * token: alchemy.secret(process.env.GITHUB_TOKEN)
103
+ * });
104
+ * });
44
105
  */
45
- export declare const GitHubSecret: ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>) | (((this: any, id: string, props: GitHubSecretProps) => never) & (new (_: never) => never));
106
+ export declare const GitHubSecret: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<GitHubSecretOutput>, id: string, props: GitHubSecretProps) => Promise<GitHubSecretOutput>);
@@ -3,11 +3,71 @@ import { Resource } from "../resource";
3
3
  import { createGitHubClient, verifyGitHubAuth } from "./client";
4
4
  /**
5
5
  * Resource for managing GitHub repository secrets
6
+ *
7
+ * Authentication is handled in the following order:
8
+ * 1. `token` parameter in the resource props (if provided)
9
+ * 2. `GITHUB_TOKEN` environment variable
10
+ *
11
+ * The token must have the following permissions:
12
+ * - 'repo' scope for private repositories
13
+ * - 'public_repo' scope for public repositories
14
+ *
15
+ * @example
16
+ * // Create a secret using GITHUB_TOKEN environment variable:
17
+ * const secret = await GitHubSecret("my-secret", {
18
+ * owner: "my-github-username",
19
+ * repository: "my-repo",
20
+ * name: "API_KEY",
21
+ * value: alchemy.secret("my-secret-value")
22
+ * });
23
+ *
24
+ * @example
25
+ * // Create a secret with a custom GitHub token:
26
+ * const secret = await GitHubSecret("my-secret", {
27
+ * owner: "my-github-username",
28
+ * repository: "my-repo",
29
+ * name: "API_KEY",
30
+ * value: alchemy.secret("my-secret-value"),
31
+ * token: alchemy.secret(process.env.CUSTOM_GITHUB_TOKEN)
32
+ * });
33
+ *
34
+ * @example
35
+ * // Create multiple secrets with environment variables:
36
+ * const secrets = await Promise.all([
37
+ * GitHubSecret("aws-secret", {
38
+ * owner: "my-github-username",
39
+ * repository: "cloud-app",
40
+ * name: "AWS_ROLE_ARN",
41
+ * value: alchemy.secret(process.env.AWS_ROLE_ARN)
42
+ * }),
43
+ * GitHubSecret("cf-secret", {
44
+ * owner: "my-github-username",
45
+ * repository: "cloud-app",
46
+ * name: "CLOUDFLARE_API_KEY",
47
+ * value: alchemy.secret(process.env.CLOUDFLARE_API_KEY)
48
+ * })
49
+ * ]);
50
+ *
51
+ * @example
52
+ * // Create a secret in a secure scope with a password:
53
+ * await alchemy.run("secure-scope", {
54
+ * password: process.env.SECRET_PASSPHRASE
55
+ * }, async () => {
56
+ * const secret = await GitHubSecret("deploy-secret", {
57
+ * owner: "my-github-username",
58
+ * repository: "my-app",
59
+ * name: "DEPLOY_TOKEN",
60
+ * value: alchemy.secret(process.env.DEPLOY_TOKEN),
61
+ * token: alchemy.secret(process.env.GITHUB_TOKEN)
62
+ * });
63
+ * });
6
64
  */
7
65
  export const GitHubSecret = Resource("github::Secret", async function (id, props) {
8
66
  // Create authenticated Octokit client - will automatically handle token resolution
9
67
  /// TODO: use fetch
10
- const octokit = await createGitHubClient({ token: props.token });
68
+ const octokit = await createGitHubClient({
69
+ token: props.token?.unencrypted,
70
+ });
11
71
  // Verify authentication and permissions
12
72
  if (!this.quiet) {
13
73
  await verifyGitHubAuth(octokit, props.owner, props.repository);
@@ -0,0 +1,5 @@
1
+ export interface DocsProps {
2
+ docs?: boolean | number;
3
+ }
4
+ export type AlchemyDocs = Awaited<ReturnType<typeof AlchemyDocs>>;
5
+ export declare function AlchemyDocs({ docs: isDocsEnabled }: DocsProps): Promise<void>;