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,135 @@
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
+ type CouponDuration = Stripe.CouponCreateParams.Duration;
6
+ /**
7
+ * Properties for creating a Stripe coupon
8
+ */
9
+ export interface CouponProps {
10
+ /**
11
+ * Unique string of your choice that will be used to identify this coupon when applying it to a customer
12
+ */
13
+ id?: string;
14
+ /**
15
+ * Specifies how long the discount will be in effect
16
+ */
17
+ duration: CouponDuration;
18
+ /**
19
+ * A positive integer representing the amount to subtract from an invoice total (required if percent_off is not passed)
20
+ */
21
+ amountOff?: number;
22
+ /**
23
+ * Three-letter ISO code for the currency of the amount_off parameter (required if amount_off is passed)
24
+ */
25
+ currency?: string;
26
+ /**
27
+ * Required only if duration is repeating, in which case it must be a positive integer that specifies the number of months the discount will be in effect
28
+ */
29
+ durationInMonths?: number;
30
+ /**
31
+ * A positive integer specifying the number of times the coupon can be redeemed before it's no longer valid
32
+ */
33
+ maxRedemptions?: number;
34
+ /**
35
+ * Name of the coupon displayed to customers on, for instance invoices, or receipts
36
+ */
37
+ name?: string;
38
+ /**
39
+ * A positive float larger than 0, and smaller or equal to 100, that represents the discount the coupon will apply (required if amount_off is not passed)
40
+ */
41
+ percentOff?: number;
42
+ /**
43
+ * Unix timestamp specifying the last time at which the coupon can be redeemed
44
+ */
45
+ redeemBy?: number;
46
+ /**
47
+ * Number of times this coupon has been applied to a customer
48
+ */
49
+ timesRedeemed?: number;
50
+ /**
51
+ * Taking account of the above properties, whether this coupon can still be applied to a customer
52
+ */
53
+ valid?: boolean;
54
+ /**
55
+ * Set of key-value pairs that you can attach to an object
56
+ */
57
+ metadata?: Record<string, string>;
58
+ /**
59
+ * API key to use (overrides environment variable)
60
+ */
61
+ apiKey?: Secret;
62
+ /**
63
+ * If true, adopt existing resource if creation fails due to conflict
64
+ */
65
+ adopt?: boolean;
66
+ }
67
+ /**
68
+ * Output from the Stripe coupon
69
+ */
70
+ export interface Coupon extends Resource<"stripe::Coupon">, CouponProps {
71
+ /**
72
+ * The ID of the coupon
73
+ */
74
+ id: string;
75
+ /**
76
+ * String representing the object's type
77
+ */
78
+ object: "coupon";
79
+ /**
80
+ * Time at which the object was created
81
+ */
82
+ created: number;
83
+ /**
84
+ * Has the value true if the object exists in live mode or the value false if the object exists in test mode
85
+ */
86
+ livemode: boolean;
87
+ }
88
+ /**
89
+ * Create and manage Stripe coupons for discounts
90
+ *
91
+ * @example
92
+ * // Create a percentage-based coupon
93
+ * const percentageCoupon = await Coupon("summer-sale", {
94
+ * id: "SUMMER25",
95
+ * duration: "once",
96
+ * percentOff: 25,
97
+ * name: "Summer Sale 25% Off",
98
+ * maxRedemptions: 1000,
99
+ * metadata: {
100
+ * campaign: "summer_2024",
101
+ * type: "seasonal"
102
+ * }
103
+ * });
104
+ *
105
+ * @example
106
+ * // Create a fixed amount coupon
107
+ * const fixedAmountCoupon = await Coupon("new-customer", {
108
+ * id: "WELCOME10",
109
+ * duration: "once",
110
+ * amountOff: 1000,
111
+ * currency: "usd",
112
+ * name: "Welcome $10 Off",
113
+ * metadata: {
114
+ * type: "welcome",
115
+ * target: "new_customers"
116
+ * }
117
+ * });
118
+ *
119
+ * @example
120
+ * // Create a repeating coupon for subscriptions
121
+ * const subscriptionCoupon = await Coupon("loyal-customer", {
122
+ * id: "LOYAL15",
123
+ * duration: "repeating",
124
+ * durationInMonths: 6,
125
+ * percentOff: 15,
126
+ * name: "Loyal Customer 15% Off",
127
+ * metadata: {
128
+ * type: "loyalty",
129
+ * tier: "premium"
130
+ * }
131
+ * });
132
+ */
133
+ export declare const Coupon: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Coupon>, _id: string, props: CouponProps) => Promise<Coupon>);
134
+ export {};
135
+ //# sourceMappingURL=coupon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coupon.d.ts","sourceRoot":"","sources":["../../src/stripe/coupon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAO3C,KAAK,cAAc,GAAG,MAAM,CAAC,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C"}
@@ -0,0 +1,161 @@
1
+ import { Resource } from "../resource.js";
2
+ import { createStripeClient, handleStripeDeleteError, isStripeConflictError, } from "./client.js";
3
+ /**
4
+ * Create and manage Stripe coupons for discounts
5
+ *
6
+ * @example
7
+ * // Create a percentage-based coupon
8
+ * const percentageCoupon = await Coupon("summer-sale", {
9
+ * id: "SUMMER25",
10
+ * duration: "once",
11
+ * percentOff: 25,
12
+ * name: "Summer Sale 25% Off",
13
+ * maxRedemptions: 1000,
14
+ * metadata: {
15
+ * campaign: "summer_2024",
16
+ * type: "seasonal"
17
+ * }
18
+ * });
19
+ *
20
+ * @example
21
+ * // Create a fixed amount coupon
22
+ * const fixedAmountCoupon = await Coupon("new-customer", {
23
+ * id: "WELCOME10",
24
+ * duration: "once",
25
+ * amountOff: 1000,
26
+ * currency: "usd",
27
+ * name: "Welcome $10 Off",
28
+ * metadata: {
29
+ * type: "welcome",
30
+ * target: "new_customers"
31
+ * }
32
+ * });
33
+ *
34
+ * @example
35
+ * // Create a repeating coupon for subscriptions
36
+ * const subscriptionCoupon = await Coupon("loyal-customer", {
37
+ * id: "LOYAL15",
38
+ * duration: "repeating",
39
+ * durationInMonths: 6,
40
+ * percentOff: 15,
41
+ * name: "Loyal Customer 15% Off",
42
+ * metadata: {
43
+ * type: "loyalty",
44
+ * tier: "premium"
45
+ * }
46
+ * });
47
+ */
48
+ export const Coupon = Resource("stripe::Coupon", async function (_id, props) {
49
+ const stripe = createStripeClient({ apiKey: props.apiKey });
50
+ if (this.phase === "delete") {
51
+ try {
52
+ if (this.output?.id) {
53
+ await stripe.coupons.del(this.output.id);
54
+ }
55
+ }
56
+ catch (error) {
57
+ handleStripeDeleteError(error, "Coupon", this.output?.id);
58
+ }
59
+ return this.destroy();
60
+ }
61
+ try {
62
+ let coupon;
63
+ if (this.phase === "update" && this.output?.id) {
64
+ coupon = await stripe.coupons.update(this.output.id, {
65
+ name: props.name,
66
+ metadata: props.metadata,
67
+ });
68
+ }
69
+ else {
70
+ const createParams = {
71
+ duration: props.duration,
72
+ name: props.name,
73
+ metadata: props.metadata,
74
+ };
75
+ if (props.id) {
76
+ createParams.id = props.id;
77
+ }
78
+ if (props.amountOff !== undefined) {
79
+ createParams.amount_off = props.amountOff;
80
+ }
81
+ if (props.currency) {
82
+ createParams.currency = props.currency;
83
+ }
84
+ if (props.durationInMonths !== undefined) {
85
+ createParams.duration_in_months = props.durationInMonths;
86
+ }
87
+ if (props.maxRedemptions !== undefined) {
88
+ createParams.max_redemptions = props.maxRedemptions;
89
+ }
90
+ if (props.percentOff !== undefined) {
91
+ createParams.percent_off = props.percentOff;
92
+ }
93
+ if (props.redeemBy !== undefined) {
94
+ createParams.redeem_by = props.redeemBy;
95
+ }
96
+ try {
97
+ try {
98
+ coupon = await stripe.coupons.create(createParams);
99
+ }
100
+ catch (error) {
101
+ if (isStripeConflictError(error) && props.adopt) {
102
+ if (props.id) {
103
+ const existingCoupon = await stripe.coupons.retrieve(props.id);
104
+ const updateParams = {
105
+ metadata: props.metadata,
106
+ name: props.name,
107
+ };
108
+ coupon = await stripe.coupons.update(existingCoupon.id, updateParams);
109
+ }
110
+ else {
111
+ throw error;
112
+ }
113
+ }
114
+ else {
115
+ throw error;
116
+ }
117
+ }
118
+ }
119
+ catch (error) {
120
+ if (isStripeConflictError(error) && props.adopt) {
121
+ if (props.id) {
122
+ const existingCoupon = await stripe.coupons.retrieve(props.id);
123
+ const updateParams = {
124
+ metadata: props.metadata,
125
+ name: props.name,
126
+ };
127
+ coupon = await stripe.coupons.update(existingCoupon.id, updateParams);
128
+ }
129
+ else {
130
+ throw error;
131
+ }
132
+ }
133
+ else {
134
+ throw error;
135
+ }
136
+ }
137
+ }
138
+ return this({
139
+ id: coupon.id,
140
+ object: coupon.object,
141
+ duration: coupon.duration,
142
+ amountOff: coupon.amount_off || undefined,
143
+ currency: coupon.currency || undefined,
144
+ durationInMonths: coupon.duration_in_months || undefined,
145
+ maxRedemptions: coupon.max_redemptions || undefined,
146
+ name: coupon.name || undefined,
147
+ percentOff: coupon.percent_off || undefined,
148
+ redeemBy: coupon.redeem_by || undefined,
149
+ timesRedeemed: coupon.times_redeemed || undefined,
150
+ valid: coupon.valid,
151
+ metadata: coupon.metadata || undefined,
152
+ created: coupon.created,
153
+ livemode: coupon.livemode,
154
+ });
155
+ }
156
+ catch (error) {
157
+ console.error("Error creating/updating coupon:", error);
158
+ throw error;
159
+ }
160
+ });
161
+ //# sourceMappingURL=coupon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coupon.js","sourceRoot":"","sources":["../../src/stripe/coupon.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAwGrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAC5B,gBAAgB,EAChB,KAAK,WAEH,GAAW,EACX,KAAkB;IAElB,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAE5D,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;gBACpB,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAuB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,CAAC;QACH,IAAI,MAAqB,CAAC;QA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Ac,CAAC,EAAE,EACjB,YAAY,CACb,CAAC;oBACJ,CAAC;yBAAM,CAAC;wBACN,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;YACV,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAA0B;YAC3C,SAAS,EAAE,MAAM,CAAC,UAAU,IAAI,SAAS;YACzC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,SAAS;YACtC,gBAAgB,EAAE,MAAM,CAAC,kBAAkB,IAAI,SAAS;YACxD,cAAc,EAAE,MAAM,CAAC,eAAe,IAAI,SAAS;YACnD,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,SAAS;YAC9B,UAAU,EAAE,MAAM,CAAC,WAAW,IAAI,SAAS;YAC3C,QAAQ,EAAE,MAAM,CAAC,SAAS,IAAI,SAAS;YACvC,aAAa,EAAE,MAAM,CAAC,cAAc,IAAI,SAAS;YACjD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,SAAS;YACtC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC"}
@@ -0,0 +1,269 @@
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
+ /**
6
+ * Customer address information
7
+ */
8
+ export interface CustomerAddress {
9
+ /**
10
+ * City, district, suburb, town, or village
11
+ */
12
+ city?: string;
13
+ /**
14
+ * Two-letter country code (ISO 3166-1 alpha-2)
15
+ */
16
+ country?: string;
17
+ /**
18
+ * Address line 1 (e.g., street, PO Box, or company name)
19
+ */
20
+ line1?: string;
21
+ /**
22
+ * Address line 2 (e.g., apartment, suite, unit, or building)
23
+ */
24
+ line2?: string;
25
+ /**
26
+ * ZIP or postal code
27
+ */
28
+ postalCode?: string;
29
+ /**
30
+ * State, county, province, or region
31
+ */
32
+ state?: string;
33
+ }
34
+ /**
35
+ * Customer shipping information
36
+ */
37
+ export interface CustomerShipping {
38
+ /**
39
+ * Customer's shipping address
40
+ */
41
+ address?: CustomerAddress;
42
+ /**
43
+ * Customer name
44
+ */
45
+ name?: string;
46
+ /**
47
+ * Customer phone number
48
+ */
49
+ phone?: string;
50
+ }
51
+ /**
52
+ * Customer invoice settings
53
+ */
54
+ export interface CustomerInvoiceSettings {
55
+ /**
56
+ * Default custom fields to be displayed on invoices for this customer
57
+ */
58
+ customFields?: Array<{
59
+ name: string;
60
+ value: string;
61
+ }>;
62
+ /**
63
+ * ID of a payment method that's attached to the customer, to be used as the customer's default payment method for subscriptions and invoices
64
+ */
65
+ defaultPaymentMethod?: string;
66
+ /**
67
+ * Default footer to be displayed on invoices for this customer
68
+ */
69
+ footer?: string;
70
+ /**
71
+ * Default options for invoice PDF rendering for this customer
72
+ */
73
+ renderingOptions?: {
74
+ amountTaxDisplay?: Stripe.CustomerCreateParams.InvoiceSettings.RenderingOptions.AmountTaxDisplay;
75
+ };
76
+ }
77
+ /**
78
+ * Properties for creating a Stripe customer
79
+ */
80
+ export interface CustomerProps {
81
+ /**
82
+ * The customer's address
83
+ */
84
+ address?: CustomerAddress;
85
+ /**
86
+ * An integer amount in cents that represents the customer's current balance
87
+ */
88
+ balance?: number;
89
+ /**
90
+ * If you provide a coupon code, the customer will have a discount applied on all recurring charges
91
+ */
92
+ coupon?: string;
93
+ /**
94
+ * An arbitrary string attached to the object
95
+ */
96
+ description?: string;
97
+ /**
98
+ * Customer's email address
99
+ */
100
+ email?: string;
101
+ /**
102
+ * The prefix for the customer used to generate unique invoice numbers
103
+ */
104
+ invoicePrefix?: string;
105
+ /**
106
+ * Default invoice settings for this customer
107
+ */
108
+ invoiceSettings?: CustomerInvoiceSettings;
109
+ /**
110
+ * Set of key-value pairs that you can attach to an object
111
+ */
112
+ metadata?: Record<string, string>;
113
+ /**
114
+ * The customer's full name or business name
115
+ */
116
+ name?: string;
117
+ /**
118
+ * The sequence to be used on the customer's next invoice
119
+ */
120
+ nextInvoiceSequence?: number;
121
+ /**
122
+ * The ID of the PaymentMethod to attach to the customer
123
+ */
124
+ paymentMethod?: string;
125
+ /**
126
+ * The customer's phone number
127
+ */
128
+ phone?: string;
129
+ /**
130
+ * Customer's preferred languages, ordered by preference
131
+ */
132
+ preferredLocales?: string[];
133
+ /**
134
+ * The ID of a promotion code to apply to the customer
135
+ */
136
+ promotionCode?: string;
137
+ /**
138
+ * The customer's shipping information
139
+ */
140
+ shipping?: CustomerShipping;
141
+ /**
142
+ * When using a card as a source, you can pass the card information
143
+ */
144
+ source?: string;
145
+ /**
146
+ * The customer's tax exemption status
147
+ */
148
+ taxExempt?: Stripe.CustomerCreateParams.TaxExempt;
149
+ /**
150
+ * ID of the test clock to attach to the customer
151
+ */
152
+ testClock?: string;
153
+ /**
154
+ * API key to use (overrides environment variable)
155
+ */
156
+ apiKey?: Secret;
157
+ /**
158
+ * If true, adopt existing resource if creation fails due to conflict
159
+ */
160
+ adopt?: boolean;
161
+ }
162
+ /**
163
+ * Output from the Stripe customer
164
+ */
165
+ export interface Customer extends Resource<"stripe::Customer">, CustomerProps {
166
+ /**
167
+ * The ID of the customer
168
+ */
169
+ id: string;
170
+ /**
171
+ * String representing the object's type
172
+ */
173
+ object: "customer";
174
+ /**
175
+ * Time at which the object was created
176
+ */
177
+ created: number;
178
+ /**
179
+ * Three-letter ISO code for the currency the customer can be charged in for recurring billing purposes
180
+ */
181
+ currency?: string;
182
+ /**
183
+ * ID of the default payment source for the customer
184
+ */
185
+ defaultSource?: string;
186
+ /**
187
+ * Whether or not the customer is currently delinquent
188
+ */
189
+ delinquent?: boolean;
190
+ /**
191
+ * Describes the current discount active on the customer, if there is one
192
+ */
193
+ discount?: any;
194
+ /**
195
+ * Has the value true if the object exists in live mode or the value false if the object exists in test mode
196
+ */
197
+ livemode: boolean;
198
+ /**
199
+ * The customer's payment sources, if any
200
+ */
201
+ sources?: any;
202
+ /**
203
+ * The customer's current subscriptions, if any
204
+ */
205
+ subscriptions?: any;
206
+ /**
207
+ * The customer's tax IDs, if any
208
+ */
209
+ taxIds?: any;
210
+ }
211
+ /**
212
+ * Create and manage Stripe customers
213
+ *
214
+ * @example
215
+ * // Create a basic customer
216
+ * const basicCustomer = await Customer("basic-customer", {
217
+ * email: "john@example.com",
218
+ * name: "John Doe",
219
+ * description: "Premium customer",
220
+ * metadata: {
221
+ * tier: "premium",
222
+ * source: "website"
223
+ * }
224
+ * });
225
+ *
226
+ * @example
227
+ * // Create a customer with full address information
228
+ * const customerWithAddress = await Customer("customer-with-address", {
229
+ * email: "jane@example.com",
230
+ * name: "Jane Smith",
231
+ * phone: "+1-555-123-4567",
232
+ * address: {
233
+ * line1: "123 Main St",
234
+ * line2: "Apt 4B",
235
+ * city: "San Francisco",
236
+ * state: "CA",
237
+ * postalCode: "94105",
238
+ * country: "US"
239
+ * },
240
+ * shipping: {
241
+ * name: "Jane Smith",
242
+ * address: {
243
+ * line1: "456 Oak Ave",
244
+ * city: "Oakland",
245
+ * state: "CA",
246
+ * postalCode: "94612",
247
+ * country: "US"
248
+ * }
249
+ * }
250
+ * });
251
+ *
252
+ * @example
253
+ * // Create a business customer with tax exemption
254
+ * const businessCustomer = await Customer("business-customer", {
255
+ * email: "billing@acmecorp.com",
256
+ * name: "Acme Corporation",
257
+ * description: "Enterprise customer",
258
+ * taxExempt: "exempt",
259
+ * invoicePrefix: "ACME",
260
+ * preferredLocales: ["en"],
261
+ * metadata: {
262
+ * type: "business",
263
+ * industry: "technology",
264
+ * employees: "500+"
265
+ * }
266
+ * });
267
+ */
268
+ export declare const Customer: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<Customer>, _id: string, props: CustomerProps) => Promise<Customer>);
269
+ //# sourceMappingURL=customer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer.d.ts","sourceRoot":"","sources":["../../src/stripe/customer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;O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