alchemy 0.2.3 → 0.2.5

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 (141) 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/data.d.ts +101 -0
  6. package/lib/ai/data.js +70 -0
  7. package/lib/ai/document.d.ts +101 -0
  8. package/lib/ai/document.js +82 -0
  9. package/lib/ai/index.d.ts +3 -0
  10. package/lib/ai/index.js +3 -0
  11. package/lib/alchemy.d.ts +83 -2
  12. package/lib/alchemy.js +31 -3
  13. package/lib/aws/bucket.d.ts +87 -1
  14. package/lib/aws/bucket.js +48 -1
  15. package/lib/aws/function.d.ts +186 -1
  16. package/lib/aws/function.js +62 -8
  17. package/lib/aws/oidc/github-oidc-provider.d.ts +81 -0
  18. package/lib/aws/oidc/github-oidc-provider.js +68 -0
  19. package/lib/aws/oidc/oidc-provider.d.ts +14 -6
  20. package/lib/aws/oidc/oidc-provider.js +26 -5
  21. package/lib/aws/policy-attachment.d.ts +44 -1
  22. package/lib/aws/policy-attachment.js +31 -0
  23. package/lib/aws/policy.d.ts +160 -1
  24. package/lib/aws/policy.js +78 -0
  25. package/lib/aws/queue.d.ts +83 -1
  26. package/lib/aws/queue.js +39 -0
  27. package/lib/aws/role.d.ts +162 -1
  28. package/lib/aws/role.js +114 -0
  29. package/lib/aws/ses.d.ts +57 -2
  30. package/lib/aws/ses.js +42 -1
  31. package/lib/aws/table.d.ts +96 -1
  32. package/lib/aws/table.js +36 -0
  33. package/lib/cloudflare/asset-manifest.js +0 -1
  34. package/lib/cloudflare/bound.js +0 -1
  35. package/lib/cloudflare/bucket.d.ts +37 -1
  36. package/lib/cloudflare/bucket.js +36 -0
  37. package/lib/cloudflare/durable-object-namespace.d.ts +25 -0
  38. package/lib/cloudflare/durable-object-namespace.js +22 -0
  39. package/lib/cloudflare/kv-namespace.d.ts +37 -1
  40. package/lib/cloudflare/kv-namespace.js +36 -0
  41. package/lib/cloudflare/static-site.d.ts +53 -1
  42. package/lib/cloudflare/static-site.js +53 -1
  43. package/lib/cloudflare/worker-metadata.js +0 -1
  44. package/lib/cloudflare/worker.d.ts +64 -1
  45. package/lib/cloudflare/worker.js +63 -0
  46. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  47. package/lib/cloudflare/zone-settings.js +0 -1
  48. package/lib/cloudflare/zone.d.ts +56 -1
  49. package/lib/cloudflare/zone.js +55 -0
  50. package/lib/destroy.js +1 -1
  51. package/lib/esbuild/bundle.d.ts +43 -4
  52. package/lib/esbuild/bundle.js +16 -0
  53. package/lib/fs/file-collection.d.ts +16 -0
  54. package/lib/fs/file-collection.js +6 -0
  55. package/lib/fs/file-ref.d.ts +14 -0
  56. package/lib/fs/file-ref.js +6 -0
  57. package/lib/fs/file.d.ts +71 -25
  58. package/lib/fs/file.js +20 -44
  59. package/lib/fs/folder.d.ts +37 -5
  60. package/lib/fs/folder.js +26 -2
  61. package/lib/fs/index.d.ts +6 -0
  62. package/lib/fs/index.js +6 -0
  63. package/lib/fs/json-file.d.ts +16 -0
  64. package/lib/fs/json-file.js +7 -0
  65. package/lib/fs/text-file.d.ts +12 -0
  66. package/lib/fs/text-file.js +7 -0
  67. package/lib/fs/typescript-file.d.ts +19 -0
  68. package/lib/fs/typescript-file.js +14 -0
  69. package/lib/fs/yaml-file.d.ts +19 -0
  70. package/lib/fs/yaml-file.js +8 -0
  71. package/lib/github/secret.d.ts +63 -2
  72. package/lib/github/secret.js +61 -1
  73. package/lib/internal/docs.d.ts +5 -0
  74. package/lib/internal/docs.js +287 -0
  75. package/lib/resource.d.ts +1 -1
  76. package/lib/secret.d.ts +67 -0
  77. package/lib/secret.js +67 -0
  78. package/lib/shadcn/component.d.ts +1 -1
  79. package/lib/stripe/price.d.ts +51 -1
  80. package/lib/stripe/price.js +50 -0
  81. package/lib/stripe/product.d.ts +39 -1
  82. package/lib/stripe/product.js +38 -0
  83. package/lib/stripe/webhook.d.ts +46 -1
  84. package/lib/stripe/webhook.js +45 -0
  85. package/lib/test/bun.d.ts +64 -0
  86. package/lib/test/bun.js +35 -3
  87. package/lib/util/serde.js +14 -0
  88. package/lib/vite/vite.d.ts +1 -1
  89. package/lib/vitepress/dependencies.d.ts +2 -6
  90. package/lib/vitepress/vitepress.d.ts +12 -1
  91. package/lib/vitepress/vitepress.js +29 -23
  92. package/package.json +8 -3
  93. package/src/ai/ark.ts +118 -0
  94. package/src/ai/client.ts +78 -0
  95. package/src/ai/data.ts +149 -0
  96. package/src/ai/document.ts +165 -0
  97. package/src/ai/index.ts +3 -0
  98. package/src/alchemy.ts +88 -5
  99. package/src/aws/bucket.ts +111 -7
  100. package/src/aws/function.ts +231 -10
  101. package/src/aws/oidc/github-oidc-provider.ts +83 -0
  102. package/src/aws/oidc/oidc-provider.ts +39 -7
  103. package/src/aws/policy-attachment.ts +44 -1
  104. package/src/aws/policy.ts +177 -2
  105. package/src/aws/queue.ts +89 -0
  106. package/src/aws/role.ts +174 -2
  107. package/src/aws/ses.ts +56 -1
  108. package/src/aws/table.ts +103 -0
  109. package/src/cloudflare/bucket.ts +36 -0
  110. package/src/cloudflare/durable-object-namespace.ts +25 -0
  111. package/src/cloudflare/kv-namespace.ts +36 -0
  112. package/src/cloudflare/static-site.ts +53 -1
  113. package/src/cloudflare/worker.ts +63 -0
  114. package/src/cloudflare/zone.ts +55 -0
  115. package/src/destroy.ts +1 -1
  116. package/src/esbuild/bundle.ts +53 -3
  117. package/src/fs/file-collection.ts +24 -0
  118. package/src/fs/file-ref.ts +22 -0
  119. package/src/fs/file.ts +70 -77
  120. package/src/fs/folder.ts +44 -5
  121. package/src/fs/index.ts +6 -0
  122. package/src/fs/json-file.ts +23 -0
  123. package/src/fs/text-file.ts +19 -0
  124. package/src/fs/typescript-file.ts +36 -0
  125. package/src/fs/yaml-file.ts +26 -0
  126. package/src/github/secret.ts +65 -2
  127. package/src/internal/docs.ts +338 -0
  128. package/src/resource.ts +1 -1
  129. package/src/secret.ts +67 -0
  130. package/src/stripe/price.ts +50 -0
  131. package/src/stripe/product.ts +38 -0
  132. package/src/stripe/webhook.ts +45 -0
  133. package/src/test/bun.ts +83 -3
  134. package/src/util/serde.ts +17 -0
  135. package/src/vitepress/vitepress.ts +47 -26
  136. package/lib/docs/document.d.ts +0 -123
  137. package/lib/docs/document.js +0 -67
  138. package/lib/docs/index.d.ts +0 -1
  139. package/lib/docs/index.js +0 -1
  140. package/src/docs/document.ts +0 -225
  141. package/src/docs/index.ts +0 -1
@@ -0,0 +1,338 @@
1
+ import { type } from "arktype";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ import { Data } from "../ai/data";
5
+ import { Document } from "../ai/document";
6
+ import { alchemy } from "../alchemy";
7
+ import { Folder } from "../fs/folder";
8
+ import { VitePressProject } from "../vitepress/vitepress";
9
+
10
+ export interface DocsProps {
11
+ docs?: boolean | number;
12
+ }
13
+
14
+ export type AlchemyDocs = Awaited<ReturnType<typeof AlchemyDocs>>;
15
+
16
+ export async function AlchemyDocs({ docs: isDocsEnabled }: DocsProps) {
17
+ const root = (await Folder("alchemy-web")).path;
18
+
19
+ const docs = (await Folder(path.join(root, "docs"))).path;
20
+
21
+ const providersDir = (await Folder(path.join(docs, "providers"))).path;
22
+
23
+ const exclude = ["util", "test", "vitepress", "vite", "shadcn", "internal"];
24
+
25
+ // Get all folders in the alchemy/src directory
26
+ let providers = (
27
+ await fs.readdir(path.resolve("alchemy", "src"), {
28
+ withFileTypes: true,
29
+ })
30
+ )
31
+ .filter((dirent) => dirent.isDirectory() && !exclude.includes(dirent.name))
32
+ .map((dirent) => path.join(dirent.parentPath, dirent.name));
33
+
34
+ // For each provider, list all files
35
+ if (isDocsEnabled === false) {
36
+ return;
37
+ } else if (typeof isDocsEnabled === "number") {
38
+ providers = providers.slice(0, isDocsEnabled);
39
+ }
40
+
41
+ const providerDocs = await Promise.all(
42
+ providers.map(async (provider) => {
43
+ const providerName = path.basename(provider);
44
+ const files = (
45
+ await fs.readdir(path.resolve(provider), {
46
+ withFileTypes: true,
47
+ })
48
+ )
49
+ .filter((dirent) => dirent.isFile())
50
+ .map((dirent) =>
51
+ path.relative(process.cwd(), path.resolve(provider, dirent.name)),
52
+ )
53
+ .filter((file) => file.endsWith(".ts") && !file.endsWith("index.ts"));
54
+
55
+ const {
56
+ object: { groups },
57
+ } = await Data(`docs/${providerName}`, {
58
+ schema: type({
59
+ groups: type({
60
+ title: type("string").describe(
61
+ "The title of the group, should be the Resource Name exactly without spaces, e.g. Bucket or Static Site.",
62
+ ),
63
+ filename: type("string").describe(
64
+ "The filename of the Resource's Document, e.g. bucket.md or static-site.md",
65
+ ),
66
+ category: type("'Resource'|'Client'|'Utility'|'Types'").describe(
67
+ "The classification of the Resource's Document, one of: Resource, Client, Utility, or Types.",
68
+ ),
69
+ }).array(),
70
+ }),
71
+ system: await alchemy`
72
+ 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.
73
+ You will be provided with a list of documents and instructions on how to classify them.
74
+ Each document has a title, file name, and category.
75
+ `,
76
+ prompt: await alchemy`
77
+ Identify and classify the documents that need to be written for the '${provider}' Service's Alchemy Resources.
78
+ For background knowledge on Alchemy, see ${alchemy.file("./README.md")}.
79
+ For background knowledge on the structure of an Alchemy Resource, see ${alchemy.file("./.cursorrules")}.
80
+
81
+ The ${provider} Service has the following resources:
82
+ ${alchemy.files(files)}
83
+
84
+ 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(...).
85
+ A file is considered a "Client" if it exposes a wrapper around creating a SDK client or fetch.
86
+ A file is considered a "Utility" if it contains utility functions that are not resources or clients.
87
+ A file is considered a "Types" if it contains just type definitions and maybe helpers around working with those types.
88
+
89
+ The title should be simply the name of the resource, e.g. "Bucket" or "Function", except with spaces, e.g. "Static Site" instead of "StaticSite". Maintain all other casing.
90
+ `,
91
+ });
92
+
93
+ const providerDocsDir = (
94
+ await Folder(path.join(providersDir, providerName))
95
+ ).path;
96
+
97
+ const documents = await Promise.all(
98
+ groups
99
+ .filter((g) => g.category === "Resource")
100
+ .map(async (g) =>
101
+ Document(`docs/${providerName}/${g.title}`, {
102
+ title: g.title,
103
+ path: path.join(
104
+ providerDocsDir,
105
+ `${g.filename.replace(".ts", "").replace(".md", "")}.md`,
106
+ ),
107
+ prompt: await alchemy`
108
+ You are a technical writer writing API documentation for an Alchemy IaC Resource.
109
+ See ${alchemy.file("./README.md")} to understand the overview of Alchemy.
110
+ See ${alchemy.file("./.cursorrules")} to better understand the structure and convention of an Alchemy Resource.
111
+
112
+ Relevant files for the ${providerName} Service:
113
+ ${alchemy.files(files)}
114
+
115
+ Write concise documentation for the "${g.title}" Resource.
116
+
117
+ > [!CAUTION]
118
+ > Avoid the temptation to over explain or over describe. Focus on concise, simple, high value snippets. One heading and 0-1 descriptions per snippet.
119
+
120
+ > [!TIP]
121
+ > Make sure the examples follow a natural progression from the minimal example to logical next steps of how the Resource might be used.
122
+
123
+ Each document must follow the following format:
124
+
125
+ # ${g.title}
126
+
127
+ (simple description with an external link to the provider's website)
128
+ e.g.
129
+ The Efs component lets you add [Amazon Elastic File System (EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) to your app.
130
+
131
+ # Minimal Example
132
+
133
+ \`\`\`ts
134
+ import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
135
+
136
+ (example)
137
+ \`\`\`
138
+
139
+
140
+ # Create the ${g.title}
141
+
142
+ \`\`\`ts
143
+ import { ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
144
+
145
+ (example)
146
+ \`\`\`
147
+
148
+ ${
149
+ providerName === "cloudflare"
150
+ ? await alchemy`# Bind to a Worker
151
+ (if it is a Cloudflare Resource)
152
+
153
+ \`\`\`ts
154
+ import { Worker, ${g.title.replaceAll(" ", "")} } from "alchemy/${providerName}";
155
+
156
+ const myResource = await ${g.title.replaceAll(" ", "")}("my-resource", {
157
+ // ...
158
+ });
159
+
160
+ await Worker("my-worker", {
161
+ name: "my-worker",
162
+ script: "console.log('Hello, world!')",
163
+ bindings: {
164
+ myResource,
165
+ },
166
+ });
167
+ \`\`\``
168
+ : ""
169
+ }
170
+ `,
171
+ }),
172
+ ),
173
+ );
174
+
175
+ return {
176
+ dir: providerDocsDir,
177
+ provider: providerName,
178
+ documents,
179
+ } as const;
180
+ }),
181
+ );
182
+
183
+ await VitePressProject("docs", {
184
+ name: "alchemy-web",
185
+ title: "Alchemy",
186
+ description: "Alchemy is an TypeScript-native, embeddable IaC library",
187
+ overwrite: true,
188
+ delete: false,
189
+ tsconfig: {
190
+ extends: "../tsconfig.base.json",
191
+ references: ["../alchemy/tsconfig.json"],
192
+ },
193
+ devDependencies: {
194
+ alchemy: "workspace:*",
195
+ },
196
+ theme: {
197
+ light: "light-plus",
198
+ dark: "dark-plus",
199
+ },
200
+ home: {
201
+ layout: "home",
202
+ hero: {
203
+ name: "Alchemy",
204
+ text: "Materialize all the things! 🪄",
205
+ tagline: "TypeScript-native Infrastructure-as-Code (IaC)",
206
+ image: {
207
+ src: "./public/alchemist.png",
208
+ alt: "The Alchemist",
209
+ },
210
+ actions: [
211
+ {
212
+ text: "Get Started",
213
+ link: "/docs",
214
+ theme: "brand",
215
+ },
216
+ ],
217
+ },
218
+ features: [
219
+ {
220
+ title: "JS-native",
221
+ details:
222
+ "No second language, toolchains, dependencies, processes, services, etc. to lug around.",
223
+ },
224
+ {
225
+ title: "Async",
226
+ details:
227
+ "Resources are just async functions - no complex abstraction to learn.",
228
+ },
229
+ {
230
+ title: "ESM",
231
+ details:
232
+ "Built exclusively on ESM, with a slight preference for modern JS runtimes like Bun.",
233
+ },
234
+ {
235
+ title: "Embeddable",
236
+ details:
237
+ "Runs in any JavaScript/TypeScript environment, including the browser!",
238
+ },
239
+ {
240
+ title: "Extensible",
241
+ details: "Implement your own resources with a simple function.",
242
+ },
243
+ {
244
+ title: "AI-first",
245
+ details:
246
+ "Create, copy, fork, and modify resources using LLMs to fit your needs.",
247
+ },
248
+ {
249
+ title: "No dependencies",
250
+ details: "The alchemy core package has 0 required dependencies.",
251
+ },
252
+ {
253
+ title: "No service",
254
+ details:
255
+ "State files are stored locally in your project for easy inspection and version control.",
256
+ },
257
+ {
258
+ title: "No strong opinions",
259
+ details:
260
+ "Structure your codebase however you want, store state anywhere - we don't care!",
261
+ },
262
+ ],
263
+ },
264
+ themeConfig: {
265
+ sidebar: {
266
+ "/blog/": [{ text: "Blog", items: [{ text: "Blog", link: "/blog/" }] }],
267
+ "/docs/": [
268
+ {
269
+ text: "Getting Started",
270
+ items: [{ text: "Install", link: "/docs/getting-started/install" }],
271
+ },
272
+ {
273
+ text: "Guides",
274
+ items: [
275
+ {
276
+ text: "Custom Resource",
277
+ link: "/docs/guides/custom-resource",
278
+ },
279
+ {
280
+ text: "Automating with LLMs",
281
+ link: "/docs/guides/llms",
282
+ },
283
+ ],
284
+ },
285
+ {
286
+ text: "Core",
287
+ collapsed: true,
288
+ items: [
289
+ { text: "App", link: "/docs/core/app" },
290
+ { text: "Resource", link: "/docs/core/resource" },
291
+ { text: "Scope", link: "/docs/core/scope" },
292
+ { text: "Phase", link: "/docs/core/phase" },
293
+ { text: "Finalize", link: "/docs/core/finalize" },
294
+ { text: "State", link: "/docs/core/state" },
295
+ { text: "Secret", link: "/docs/core/secret" },
296
+ { text: "Context", link: "/docs/core/context" },
297
+ ],
298
+ },
299
+ {
300
+ text: "Providers",
301
+ items: providerDocs
302
+ .map((provider) => ({
303
+ text: provider.provider,
304
+ link: `/docs/providers/${provider.provider}`,
305
+ collapsed: true,
306
+ items: provider.documents.map((document) => ({
307
+ text: document.title,
308
+ link: `/docs/providers/${provider.provider}/${path.basename(document.path, ".md")}`,
309
+ })),
310
+ }))
311
+ .sort((a, b) => a.text.localeCompare(b.text)),
312
+ },
313
+ ],
314
+ "/examples/": [
315
+ {
316
+ text: "Examples",
317
+ items: [{ text: "Foo", link: "/examples/foo" }],
318
+ },
319
+ ],
320
+ "/": [
321
+ {
322
+ text: "Home",
323
+ items: [
324
+ { text: "Markdown Examples", link: "/markdown-examples" },
325
+ { text: "Runtime API Examples", link: "/api-examples" },
326
+ ],
327
+ },
328
+ ],
329
+ },
330
+ socialLinks: [
331
+ {
332
+ icon: "github",
333
+ link: "https://github.com/sam-goodwin/alchemy",
334
+ },
335
+ ],
336
+ },
337
+ });
338
+ }
package/src/resource.ts CHANGED
@@ -75,7 +75,7 @@ type ResourceLifecycleHandler = (
75
75
  // see: https://x.com/samgoodwin89/status/1904640134097887653
76
76
  type Handler<F extends (...args: any[]) => any> =
77
77
  | F
78
- | (((this: any, id: string, props?: Parameters<F>[1]) => never) & IsClass);
78
+ | (((this: any, id: string, props?: {}) => never) & IsClass);
79
79
 
80
80
  export function Resource<
81
81
  const Type extends string,
package/src/secret.ts CHANGED
@@ -1,8 +1,46 @@
1
+ /**
2
+ * Internal wrapper for sensitive values like API keys and credentials.
3
+ * When stored in alchemy state files, the value is automatically encrypted
4
+ * using the application's password. The password can be provided either:
5
+ *
6
+ * 1. Globally when initializing the alchemy application:
7
+ * ```ts
8
+ * const app = alchemy("my-app", {
9
+ * password: process.env.SECRET_PASSPHRASE
10
+ * });
11
+ * ```
12
+ *
13
+ * 2. For a specific scope using alchemy.run:
14
+ * ```ts
15
+ * await alchemy.run("scope-name", {
16
+ * password: process.env.SECRET_PASSPHRASE
17
+ * }, async () => {
18
+ * // Secrets in this scope will use this password
19
+ * alchemy.secret(process.env.MY_SECRET)
20
+ * });
21
+ * ```
22
+ *
23
+ * Without a password, secrets cannot be encrypted or decrypted, and operations
24
+ * involving sensitive values will fail.
25
+ *
26
+ * @example
27
+ * // In state file (.alchemy/app/prod/resource.json):
28
+ * {
29
+ * "props": {
30
+ * "apiKey": {
31
+ * "@secret": "encrypted-value-here..." // encrypted using app password
32
+ * }
33
+ * }
34
+ * }
35
+ */
1
36
  export class Secret {
2
37
  public readonly type = "secret";
3
38
  constructor(readonly unencrypted: string) {}
4
39
  }
5
40
 
41
+ /**
42
+ * Type guard to check if a value is a Secret wrapper
43
+ */
6
44
  export function isSecret(binding: any): binding is Secret {
7
45
  return (
8
46
  binding instanceof Secret ||
@@ -10,6 +48,35 @@ export function isSecret(binding: any): binding is Secret {
10
48
  );
11
49
  }
12
50
 
51
+ /**
52
+ * Wraps a sensitive value so it will be encrypted when stored in state files.
53
+ * Requires a password to be set either globally in the alchemy application options
54
+ * or locally in an alchemy.run scope.
55
+ *
56
+ * @example
57
+ * // Global password for all secrets
58
+ * const app = alchemy("my-app", {
59
+ * password: process.env.SECRET_PASSPHRASE
60
+ * });
61
+ *
62
+ * const resource = await Resource("my-resource", {
63
+ * apiKey: alchemy.secret(process.env.API_KEY)
64
+ * });
65
+ *
66
+ * @example
67
+ * // Scoped password for specific secrets
68
+ * await alchemy.run("secure-scope", {
69
+ * password: process.env.SCOPE_SECRET_PASSPHRASE
70
+ * }, async () => {
71
+ * const resource = await Resource("my-resource", {
72
+ * apiKey: alchemy.secret(process.env.API_KEY)
73
+ * });
74
+ * });
75
+ *
76
+ * @param unencrypted The sensitive value to encrypt in state files
77
+ * @throws {Error} If the value is undefined
78
+ * @throws {Error} If no password is set in the alchemy application options or current scope
79
+ */
13
80
  export function secret<S extends string | undefined>(unencrypted: S): Secret {
14
81
  if (unencrypted === undefined) {
15
82
  throw new Error("Secret cannot be undefined");
@@ -125,6 +125,56 @@ export interface Price extends Resource<"stripe::Price">, PriceProps {
125
125
  lookupKey?: string;
126
126
  }
127
127
 
128
+ /**
129
+ * Create and manage Stripe prices for products
130
+ *
131
+ * @example
132
+ * // Create a one-time fixed price for a product
133
+ * const oneTimePrice = await Price("basic-license", {
134
+ * currency: "usd",
135
+ * unitAmount: 2999, // $29.99
136
+ * product: "prod_xyz"
137
+ * });
138
+ *
139
+ * @example
140
+ * // Create a recurring subscription price with fixed monthly billing
141
+ * const subscriptionPrice = await Price("pro-monthly", {
142
+ * currency: "usd",
143
+ * unitAmount: 1499, // $14.99/month
144
+ * product: "prod_xyz",
145
+ * recurring: {
146
+ * interval: "month",
147
+ * usageType: "licensed"
148
+ * }
149
+ * });
150
+ *
151
+ * @example
152
+ * // Create a metered price for usage-based billing
153
+ * const meteredPrice = await Price("storage", {
154
+ * currency: "usd",
155
+ * unitAmount: 25, // $0.25 per GB
156
+ * product: "prod_xyz",
157
+ * recurring: {
158
+ * interval: "month",
159
+ * usageType: "metered",
160
+ * aggregateUsage: "sum"
161
+ * }
162
+ * });
163
+ *
164
+ * @example
165
+ * // Create a tiered price with tax behavior
166
+ * const tieredPrice = await Price("enterprise", {
167
+ * currency: "usd",
168
+ * unitAmount: 10000, // $100.00
169
+ * product: "prod_xyz",
170
+ * billingScheme: "tiered",
171
+ * taxBehavior: "exclusive",
172
+ * metadata: {
173
+ * tier: "enterprise",
174
+ * features: "all"
175
+ * }
176
+ * });
177
+ */
128
178
  export const Price = Resource(
129
179
  "stripe::Price",
130
180
  async function (
@@ -99,6 +99,44 @@ export interface Product extends Resource<"stripe::Product">, ProductProps {
99
99
  };
100
100
  }
101
101
 
102
+ /**
103
+ * Create and manage Stripe products
104
+ *
105
+ * @example
106
+ * // Create a basic digital product
107
+ * const digitalProduct = await Product("basic-software", {
108
+ * name: "Basic Software License",
109
+ * description: "Single-user license for basic software package",
110
+ * metadata: {
111
+ * type: "digital",
112
+ * features: "basic"
113
+ * }
114
+ * });
115
+ *
116
+ * @example
117
+ * // Create a physical product with shipping details
118
+ * const physicalProduct = await Product("premium-hardware", {
119
+ * name: "Premium Hardware Kit",
120
+ * description: "Complete hardware kit with premium components",
121
+ * shippable: true,
122
+ * images: ["https://example.com/hardware-kit.jpg"],
123
+ * unitLabel: "kit",
124
+ * statementDescriptor: "PREMIUM HW KIT"
125
+ * });
126
+ *
127
+ * @example
128
+ * // Create a service product with tax code
129
+ * const serviceProduct = await Product("consulting", {
130
+ * name: "Professional Consulting",
131
+ * description: "Expert consulting services",
132
+ * type: "service",
133
+ * taxCode: "txcd_10000000",
134
+ * metadata: {
135
+ * industry: "technology",
136
+ * expertise: "cloud"
137
+ * }
138
+ * });
139
+ */
102
140
  export const Product = Resource(
103
141
  "stripe::Product",
104
142
  async function (
@@ -86,6 +86,51 @@ export interface WebhookEndpoint
86
86
  status: string;
87
87
  }
88
88
 
89
+ /**
90
+ * Create and manage Stripe webhook endpoints
91
+ *
92
+ * @example
93
+ * // Create a basic webhook for payment events
94
+ * const paymentWebhook = await WebhookEndpoint("payment-webhook", {
95
+ * url: "https://api.example.com/stripe/payments",
96
+ * enabledEvents: [
97
+ * "payment_intent.succeeded",
98
+ * "payment_intent.payment_failed"
99
+ * ],
100
+ * description: "Webhook for payment notifications"
101
+ * });
102
+ *
103
+ * @example
104
+ * // Create a webhook for subscription management
105
+ * const subscriptionWebhook = await WebhookEndpoint("subscription-webhook", {
106
+ * url: "https://api.example.com/stripe/subscriptions",
107
+ * enabledEvents: [
108
+ * "customer.subscription.created",
109
+ * "customer.subscription.updated",
110
+ * "customer.subscription.deleted",
111
+ * "invoice.payment_succeeded",
112
+ * "invoice.payment_failed"
113
+ * ],
114
+ * description: "Webhook for subscription lifecycle events"
115
+ * });
116
+ *
117
+ * @example
118
+ * // Create a webhook for Connect platform events
119
+ * const connectWebhook = await WebhookEndpoint("connect-webhook", {
120
+ * url: "https://api.example.com/stripe/connect",
121
+ * enabledEvents: [
122
+ * "account.updated",
123
+ * "account.application.deauthorized",
124
+ * "payout.created",
125
+ * "payout.failed"
126
+ * ],
127
+ * connect: true,
128
+ * metadata: {
129
+ * platform: "connect",
130
+ * environment: "production"
131
+ * }
132
+ * });
133
+ */
89
134
  export const WebhookEndpoint = Resource(
90
135
  "stripe::WebhookEndpoint",
91
136
  async function (