alchemy 0.24.0 → 0.25.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 (184) hide show
  1. package/lib/aws/control/client.js +1 -1
  2. package/lib/aws/control/client.js.map +1 -1
  3. package/lib/aws/control/resource.d.ts.map +1 -1
  4. package/lib/aws/control/resource.js +2 -1
  5. package/lib/aws/control/resource.js.map +1 -1
  6. package/lib/aws/function.d.ts.map +1 -1
  7. package/lib/aws/function.js +1 -4
  8. package/lib/aws/function.js.map +1 -1
  9. package/lib/cloudflare/ai.d.ts +21 -0
  10. package/lib/cloudflare/ai.d.ts.map +1 -1
  11. package/lib/cloudflare/ai.js +21 -0
  12. package/lib/cloudflare/ai.js.map +1 -1
  13. package/lib/cloudflare/bindings.d.ts +3 -3
  14. package/lib/cloudflare/bindings.d.ts.map +1 -1
  15. package/lib/cloudflare/bindings.js.map +1 -1
  16. package/lib/cloudflare/bound.d.ts +3 -3
  17. package/lib/cloudflare/bound.d.ts.map +1 -1
  18. package/lib/cloudflare/do-state-store/index.d.ts +2 -0
  19. package/lib/cloudflare/do-state-store/index.d.ts.map +1 -0
  20. package/lib/cloudflare/do-state-store/index.js +2 -0
  21. package/lib/cloudflare/do-state-store/index.js.map +1 -0
  22. package/lib/cloudflare/do-state-store/internal.d.ts +19 -0
  23. package/lib/cloudflare/do-state-store/internal.d.ts.map +1 -0
  24. package/lib/cloudflare/do-state-store/internal.js +163 -0
  25. package/lib/cloudflare/do-state-store/internal.js.map +1 -0
  26. package/lib/cloudflare/do-state-store/store.d.ts +59 -0
  27. package/lib/cloudflare/do-state-store/store.d.ts.map +1 -0
  28. package/lib/cloudflare/do-state-store/store.js +120 -0
  29. package/lib/cloudflare/do-state-store/store.js.map +1 -0
  30. package/lib/cloudflare/do-state-store/types.d.ts +82 -0
  31. package/lib/cloudflare/do-state-store/types.d.ts.map +1 -0
  32. package/lib/cloudflare/do-state-store/types.js +1 -0
  33. package/lib/cloudflare/do-state-store/types.js.map +1 -0
  34. package/lib/cloudflare/do-state-store/worker.d.ts +27 -0
  35. package/lib/cloudflare/do-state-store/worker.d.ts.map +1 -0
  36. package/lib/cloudflare/do-state-store/worker.js +170 -0
  37. package/lib/cloudflare/do-state-store/worker.js.map +1 -0
  38. package/lib/cloudflare/index.d.ts +1 -0
  39. package/lib/cloudflare/index.d.ts.map +1 -1
  40. package/lib/cloudflare/index.js +1 -0
  41. package/lib/cloudflare/index.js.map +1 -1
  42. package/lib/cloudflare/pipeline.js +1 -1
  43. package/lib/cloudflare/pipeline.js.map +1 -1
  44. package/lib/cloudflare/queue-consumer.d.ts +14 -1
  45. package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
  46. package/lib/cloudflare/queue-consumer.js +17 -0
  47. package/lib/cloudflare/queue-consumer.js.map +1 -1
  48. package/lib/cloudflare/website.d.ts +30 -1
  49. package/lib/cloudflare/website.d.ts.map +1 -1
  50. package/lib/cloudflare/website.js +8 -5
  51. package/lib/cloudflare/website.js.map +1 -1
  52. package/lib/cloudflare/worker-assets.d.ts.map +1 -1
  53. package/lib/cloudflare/worker-assets.js +13 -3
  54. package/lib/cloudflare/worker-assets.js.map +1 -1
  55. package/lib/cloudflare/worker-metadata.js +1 -1
  56. package/lib/cloudflare/worker-metadata.js.map +1 -1
  57. package/lib/cloudflare/worker.d.ts +40 -1
  58. package/lib/cloudflare/worker.d.ts.map +1 -1
  59. package/lib/cloudflare/worker.js +40 -38
  60. package/lib/cloudflare/worker.js.map +1 -1
  61. package/lib/cloudflare/wrangler.json.js +1 -1
  62. package/lib/cloudflare/wrangler.json.js.map +1 -1
  63. package/lib/cloudflare/zone.d.ts +30 -2
  64. package/lib/cloudflare/zone.d.ts.map +1 -1
  65. package/lib/cloudflare/zone.js +53 -0
  66. package/lib/cloudflare/zone.js.map +1 -1
  67. package/lib/fs/file-system-state-store.d.ts +3 -1
  68. package/lib/fs/file-system-state-store.d.ts.map +1 -1
  69. package/lib/fs/file-system-state-store.js +2 -2
  70. package/lib/fs/file-system-state-store.js.map +1 -1
  71. package/lib/stripe/card.d.ts +171 -0
  72. package/lib/stripe/card.d.ts.map +1 -0
  73. package/lib/stripe/card.js +148 -0
  74. package/lib/stripe/card.js.map +1 -0
  75. package/lib/stripe/client.d.ts +9 -0
  76. package/lib/stripe/client.d.ts.map +1 -0
  77. package/lib/stripe/client.js +94 -0
  78. package/lib/stripe/client.js.map +1 -0
  79. package/lib/stripe/coupon.d.ts +135 -0
  80. package/lib/stripe/coupon.d.ts.map +1 -0
  81. package/lib/stripe/coupon.js +161 -0
  82. package/lib/stripe/coupon.js.map +1 -0
  83. package/lib/stripe/customer.d.ts +269 -0
  84. package/lib/stripe/customer.d.ts.map +1 -0
  85. package/lib/stripe/customer.js +289 -0
  86. package/lib/stripe/customer.js.map +1 -0
  87. package/lib/stripe/entitlements-feature.d.ts +84 -0
  88. package/lib/stripe/entitlements-feature.d.ts.map +1 -0
  89. package/lib/stripe/entitlements-feature.js +102 -0
  90. package/lib/stripe/entitlements-feature.js.map +1 -0
  91. package/lib/stripe/file.d.ts +143 -0
  92. package/lib/stripe/file.d.ts.map +1 -0
  93. package/lib/stripe/file.js +97 -0
  94. package/lib/stripe/file.js.map +1 -0
  95. package/lib/stripe/index.d.ts +11 -0
  96. package/lib/stripe/index.d.ts.map +1 -1
  97. package/lib/stripe/index.js +11 -0
  98. package/lib/stripe/index.js.map +1 -1
  99. package/lib/stripe/meter.d.ts +10 -1
  100. package/lib/stripe/meter.d.ts.map +1 -1
  101. package/lib/stripe/meter.js +13 -7
  102. package/lib/stripe/meter.js.map +1 -1
  103. package/lib/stripe/portal-configuration.d.ts +286 -0
  104. package/lib/stripe/portal-configuration.d.ts.map +1 -0
  105. package/lib/stripe/portal-configuration.js +320 -0
  106. package/lib/stripe/portal-configuration.js.map +1 -0
  107. package/lib/stripe/price.d.ts +10 -1
  108. package/lib/stripe/price.d.ts.map +1 -1
  109. package/lib/stripe/price.js +34 -13
  110. package/lib/stripe/price.js.map +1 -1
  111. package/lib/stripe/product-feature.d.ts +76 -0
  112. package/lib/stripe/product-feature.d.ts.map +1 -0
  113. package/lib/stripe/product-feature.js +74 -0
  114. package/lib/stripe/product-feature.js.map +1 -0
  115. package/lib/stripe/product.d.ts +10 -1
  116. package/lib/stripe/product.d.ts.map +1 -1
  117. package/lib/stripe/product.js +33 -14
  118. package/lib/stripe/product.js.map +1 -1
  119. package/lib/stripe/promotion-code.d.ts +138 -0
  120. package/lib/stripe/promotion-code.d.ts.map +1 -0
  121. package/lib/stripe/promotion-code.js +150 -0
  122. package/lib/stripe/promotion-code.js.map +1 -0
  123. package/lib/stripe/shipping-rate.d.ts +188 -0
  124. package/lib/stripe/shipping-rate.d.ts.map +1 -0
  125. package/lib/stripe/shipping-rate.js +198 -0
  126. package/lib/stripe/shipping-rate.js.map +1 -0
  127. package/lib/stripe/tax-rate.d.ts +130 -0
  128. package/lib/stripe/tax-rate.d.ts.map +1 -0
  129. package/lib/stripe/tax-rate.js +126 -0
  130. package/lib/stripe/tax-rate.js.map +1 -0
  131. package/lib/stripe/webhook.d.ts +10 -1
  132. package/lib/stripe/webhook.d.ts.map +1 -1
  133. package/lib/stripe/webhook.js +59 -14
  134. package/lib/stripe/webhook.js.map +1 -1
  135. package/lib/test/bun.d.ts.map +1 -1
  136. package/lib/test/bun.js +2 -6
  137. package/lib/test/bun.js.map +1 -1
  138. package/lib/test/vitest.d.ts.map +1 -1
  139. package/lib/test/vitest.js +3 -7
  140. package/lib/test/vitest.js.map +1 -1
  141. package/lib/util/retry.d.ts +1 -1
  142. package/lib/util/retry.d.ts.map +1 -1
  143. package/lib/util/retry.js.map +1 -1
  144. package/package.json +3 -2
  145. package/src/aws/control/client.ts +1 -1
  146. package/src/aws/control/resource.ts +2 -1
  147. package/src/aws/function.ts +3 -6
  148. package/src/cloudflare/ai.ts +21 -0
  149. package/src/cloudflare/bindings.ts +3 -2
  150. package/src/cloudflare/bound.ts +3 -3
  151. package/src/cloudflare/do-state-store/index.ts +1 -0
  152. package/src/cloudflare/do-state-store/internal.ts +215 -0
  153. package/src/cloudflare/do-state-store/store.ts +188 -0
  154. package/src/cloudflare/do-state-store/types.ts +74 -0
  155. package/src/cloudflare/do-state-store/worker.ts +199 -0
  156. package/src/cloudflare/index.ts +1 -0
  157. package/src/cloudflare/pipeline.ts +1 -1
  158. package/src/cloudflare/queue-consumer.ts +59 -1
  159. package/src/cloudflare/website.ts +38 -6
  160. package/src/cloudflare/worker-assets.ts +15 -3
  161. package/src/cloudflare/worker-metadata.ts +1 -1
  162. package/src/cloudflare/worker.ts +66 -46
  163. package/src/cloudflare/wrangler.json.ts +1 -1
  164. package/src/cloudflare/zone.ts +75 -2
  165. package/src/fs/file-system-state-store.ts +7 -2
  166. package/src/stripe/card.ts +320 -0
  167. package/src/stripe/client.ts +145 -0
  168. package/src/stripe/coupon.ts +280 -0
  169. package/src/stripe/customer.ts +528 -0
  170. package/src/stripe/entitlements-feature.ts +169 -0
  171. package/src/stripe/file.ts +219 -0
  172. package/src/stripe/index.ts +11 -0
  173. package/src/stripe/meter.ts +23 -7
  174. package/src/stripe/portal-configuration.ts +609 -0
  175. package/src/stripe/price.ts +47 -14
  176. package/src/stripe/product-feature.ts +150 -0
  177. package/src/stripe/product.ts +48 -15
  178. package/src/stripe/promotion-code.ts +268 -0
  179. package/src/stripe/shipping-rate.ts +362 -0
  180. package/src/stripe/tax-rate.ts +218 -0
  181. package/src/stripe/webhook.ts +82 -15
  182. package/src/test/bun.ts +2 -7
  183. package/src/test/vitest.ts +3 -8
  184. package/src/util/retry.ts +1 -1
@@ -0,0 +1,219 @@
1
+ import type Stripe from "stripe";
2
+ import type { Context } from "../context.ts";
3
+ import { Resource } from "../resource.ts";
4
+ import type { Secret } from "../secret.ts";
5
+ import { createStripeClient, isStripeConflictError } from "./client.ts";
6
+
7
+ /**
8
+ * Properties for creating a Stripe file
9
+ */
10
+ export interface FileProps {
11
+ /**
12
+ * A file to upload. The file should follow the specifications of RFC 2388
13
+ */
14
+ file: any;
15
+ /**
16
+ * The purpose of the uploaded file
17
+ */
18
+ purpose: Stripe.FileCreateParams.Purpose;
19
+ /**
20
+ * Optional parameters for the file link data
21
+ */
22
+ fileLink?: {
23
+ /**
24
+ * Whether to create a file link for the uploaded file
25
+ */
26
+ create: boolean;
27
+ /**
28
+ * The time at which the file link expires
29
+ */
30
+ expiresAt?: number;
31
+ /**
32
+ * Set of key-value pairs that you can attach to the file link
33
+ */
34
+ metadata?: Record<string, string>;
35
+ };
36
+
37
+ /**
38
+ * API key to use (overrides environment variable)
39
+ */
40
+ apiKey?: Secret;
41
+
42
+ /**
43
+ * If true, adopt existing resource if creation fails due to conflict
44
+ */
45
+ adopt?: boolean;
46
+ }
47
+
48
+ /**
49
+ * Output from the Stripe file
50
+ */
51
+ export interface File extends Resource<"stripe::File"> {
52
+ /**
53
+ * The ID of the file
54
+ */
55
+ id: string;
56
+ /**
57
+ * String representing the object's type
58
+ */
59
+ object: "file";
60
+ /**
61
+ * Time at which the object was created
62
+ */
63
+ created: number;
64
+ /**
65
+ * The time at which the file expires and is no longer available
66
+ */
67
+ expiresAt?: number;
68
+ /**
69
+ * A filename for the file, suitable for saving to a filesystem
70
+ */
71
+ filename?: string;
72
+ /**
73
+ * Any links that have been created for the file
74
+ */
75
+ links?: {
76
+ object: "list";
77
+ data: Array<{
78
+ id: string;
79
+ object: "file_link";
80
+ created: number;
81
+ expired: boolean;
82
+ expiresAt?: number;
83
+ file: string;
84
+ livemode: boolean;
85
+ metadata: Record<string, string>;
86
+ url?: string;
87
+ }>;
88
+ hasMore: boolean;
89
+ url: string;
90
+ };
91
+ /**
92
+ * The purpose of the uploaded file
93
+ */
94
+ purpose: Stripe.File.Purpose;
95
+ /**
96
+ * The size in bytes of the file object
97
+ */
98
+ size: number;
99
+ /**
100
+ * A user friendly title for the document
101
+ */
102
+ title?: string;
103
+ /**
104
+ * The type of the file returned
105
+ */
106
+ type?: string;
107
+ /**
108
+ * The URL from which the file can be downloaded
109
+ */
110
+ url?: string;
111
+ /**
112
+ * Has the value true if the object exists in live mode or the value false if the object exists in test mode
113
+ */
114
+ livemode: boolean;
115
+ }
116
+
117
+ /**
118
+ * Create and manage Stripe files for uploads
119
+ *
120
+ * @example
121
+ * // Upload a dispute evidence file
122
+ * const disputeEvidence = await File("dispute-evidence", {
123
+ * file: fs.readFileSync("./evidence.pdf"),
124
+ * purpose: "dispute_evidence"
125
+ * });
126
+ *
127
+ * @example
128
+ * // Upload an identity document
129
+ * const identityDocument = await File("identity-doc", {
130
+ * file: fs.readFileSync("./passport.jpg"),
131
+ * purpose: "identity_document"
132
+ * });
133
+ *
134
+ * @example
135
+ * // Upload a business logo with file link
136
+ * const businessLogo = await File("business-logo", {
137
+ * file: fs.readFileSync("./logo.png"),
138
+ * purpose: "business_logo",
139
+ * fileLink: {
140
+ * create: true,
141
+ * expiresAt: Math.floor(Date.now() / 1000) + 86400,
142
+ * metadata: {
143
+ * brand: "company_logo"
144
+ * }
145
+ * }
146
+ * });
147
+ */
148
+ export const File = Resource(
149
+ "stripe::File",
150
+ async function (
151
+ this: Context<File>,
152
+ _id: string,
153
+ props: FileProps,
154
+ ): Promise<File> {
155
+ const stripe = createStripeClient({ apiKey: props.apiKey });
156
+
157
+ if (this.phase === "delete") {
158
+ return this.destroy();
159
+ }
160
+
161
+ try {
162
+ let file: Stripe.File;
163
+
164
+ if (this.phase === "update" && this.output?.id) {
165
+ file = await stripe.files.retrieve(this.output.id);
166
+ } else {
167
+ try {
168
+ file = await stripe.files.create({
169
+ file: props.file,
170
+ purpose: props.purpose,
171
+ });
172
+ } catch (error) {
173
+ if (isStripeConflictError(error) && props.adopt) {
174
+ throw new Error(
175
+ "File adoption is not supported - files are immutable and cannot be adopted",
176
+ );
177
+ } else {
178
+ throw error;
179
+ }
180
+ }
181
+ }
182
+
183
+ return this({
184
+ id: file.id,
185
+ object: file.object,
186
+ created: file.created,
187
+ expiresAt: file.expires_at || undefined,
188
+ filename: file.filename || undefined,
189
+ links: file.links
190
+ ? {
191
+ object: file.links.object,
192
+ data: file.links.data.map((link) => ({
193
+ id: link.id,
194
+ object: link.object,
195
+ created: link.created,
196
+ expired: link.expired,
197
+ expiresAt: link.expires_at || undefined,
198
+ file: typeof link.file === "string" ? link.file : link.file.id,
199
+ livemode: link.livemode,
200
+ metadata: link.metadata,
201
+ url: link.url || undefined,
202
+ })),
203
+ hasMore: file.links.has_more,
204
+ url: file.links.url,
205
+ }
206
+ : undefined,
207
+ purpose: file.purpose as Stripe.File.Purpose,
208
+ size: file.size,
209
+ title: file.title || undefined,
210
+ type: file.type || undefined,
211
+ url: file.url || undefined,
212
+ livemode: true,
213
+ });
214
+ } catch (error) {
215
+ console.error("Error creating/retrieving file:", error);
216
+ throw error;
217
+ }
218
+ },
219
+ );
@@ -1,4 +1,15 @@
1
+ export * from "./card.ts";
2
+ export * from "./client.ts";
3
+ export * from "./coupon.ts";
4
+ export * from "./customer.ts";
5
+ export * from "./entitlements-feature.ts";
6
+ export * from "./file.ts";
1
7
  export * from "./meter.ts";
8
+ export * from "./portal-configuration.ts";
2
9
  export * from "./price.ts";
3
10
  export * from "./product.ts";
11
+ export * from "./product-feature.ts";
12
+ export * from "./promotion-code.ts";
13
+ export * from "./shipping-rate.ts";
14
+ export * from "./tax-rate.ts";
4
15
  export * from "./webhook.ts";
@@ -1,6 +1,8 @@
1
- import Stripe from "stripe";
1
+ import type Stripe from "stripe";
2
2
  import type { Context } from "../context.ts";
3
3
  import { Resource } from "../resource.ts";
4
+ import type { Secret } from "../secret.ts";
5
+ import { createStripeClient, isStripeConflictError } from "./client.ts";
4
6
 
5
7
  /**
6
8
  * Properties for creating or updating a Stripe Meter.
@@ -22,6 +24,14 @@ export interface MeterProps {
22
24
  valueSettings: {
23
25
  eventPayloadKey: string;
24
26
  };
27
+ /**
28
+ * API key to use (overrides environment variable)
29
+ */
30
+ apiKey?: Secret;
31
+ /**
32
+ * If true, adopt existing resource if creation fails due to conflict
33
+ */
34
+ adopt?: boolean;
25
35
  }
26
36
 
27
37
  /**
@@ -144,11 +154,7 @@ export const Meter = Resource(
144
154
  _logicalId: string,
145
155
  props: MeterProps,
146
156
  ): Promise<Meter> {
147
- const apiKey = process.env.STRIPE_API_KEY;
148
- if (!apiKey) {
149
- throw new Error("STRIPE_API_KEY environment variable is required");
150
- }
151
- const stripe = new Stripe(apiKey);
157
+ const stripe = createStripeClient({ apiKey: props.apiKey });
152
158
 
153
159
  const currentOutputId = this.output?.id;
154
160
 
@@ -292,7 +298,17 @@ export const Meter = Resource(
292
298
  }
293
299
 
294
300
  const createParams = mapPropsToStripeParams(props);
295
- stripeAPIResponse = await stripe.billing.meters.create(createParams);
301
+ try {
302
+ stripeAPIResponse = await stripe.billing.meters.create(createParams);
303
+ } catch (error) {
304
+ if (isStripeConflictError(error) && props.adopt) {
305
+ throw new Error(
306
+ "Meter adoption is not supported - meters cannot be uniquely identified for adoption",
307
+ );
308
+ } else {
309
+ throw error;
310
+ }
311
+ }
296
312
 
297
313
  // If status 'inactive' is requested during creation, and Stripe created it as 'active'
298
314
  if (