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.
- package/lib/aws/control/client.js +1 -1
- package/lib/aws/control/client.js.map +1 -1
- package/lib/aws/control/resource.d.ts.map +1 -1
- package/lib/aws/control/resource.js +2 -1
- package/lib/aws/control/resource.js.map +1 -1
- package/lib/aws/function.d.ts.map +1 -1
- package/lib/aws/function.js +1 -4
- package/lib/aws/function.js.map +1 -1
- package/lib/cloudflare/ai.d.ts +21 -0
- package/lib/cloudflare/ai.d.ts.map +1 -1
- package/lib/cloudflare/ai.js +21 -0
- package/lib/cloudflare/ai.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +3 -3
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bindings.js.map +1 -1
- package/lib/cloudflare/bound.d.ts +3 -3
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/do-state-store/index.d.ts +2 -0
- package/lib/cloudflare/do-state-store/index.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/index.js +2 -0
- package/lib/cloudflare/do-state-store/index.js.map +1 -0
- package/lib/cloudflare/do-state-store/internal.d.ts +19 -0
- package/lib/cloudflare/do-state-store/internal.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/internal.js +163 -0
- package/lib/cloudflare/do-state-store/internal.js.map +1 -0
- package/lib/cloudflare/do-state-store/store.d.ts +59 -0
- package/lib/cloudflare/do-state-store/store.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/store.js +120 -0
- package/lib/cloudflare/do-state-store/store.js.map +1 -0
- package/lib/cloudflare/do-state-store/types.d.ts +82 -0
- package/lib/cloudflare/do-state-store/types.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/types.js +1 -0
- package/lib/cloudflare/do-state-store/types.js.map +1 -0
- package/lib/cloudflare/do-state-store/worker.d.ts +27 -0
- package/lib/cloudflare/do-state-store/worker.d.ts.map +1 -0
- package/lib/cloudflare/do-state-store/worker.js +170 -0
- package/lib/cloudflare/do-state-store/worker.js.map +1 -0
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/pipeline.js +1 -1
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/queue-consumer.d.ts +14 -1
- package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
- package/lib/cloudflare/queue-consumer.js +17 -0
- package/lib/cloudflare/queue-consumer.js.map +1 -1
- package/lib/cloudflare/website.d.ts +30 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +8 -5
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-assets.d.ts.map +1 -1
- package/lib/cloudflare/worker-assets.js +13 -3
- package/lib/cloudflare/worker-assets.js.map +1 -1
- package/lib/cloudflare/worker-metadata.js +1 -1
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +40 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +40 -38
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.js +1 -1
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/cloudflare/zone.d.ts +30 -2
- package/lib/cloudflare/zone.d.ts.map +1 -1
- package/lib/cloudflare/zone.js +53 -0
- package/lib/cloudflare/zone.js.map +1 -1
- package/lib/fs/file-system-state-store.d.ts +3 -1
- package/lib/fs/file-system-state-store.d.ts.map +1 -1
- package/lib/fs/file-system-state-store.js +2 -2
- package/lib/fs/file-system-state-store.js.map +1 -1
- package/lib/stripe/card.d.ts +171 -0
- package/lib/stripe/card.d.ts.map +1 -0
- package/lib/stripe/card.js +148 -0
- package/lib/stripe/card.js.map +1 -0
- package/lib/stripe/client.d.ts +9 -0
- package/lib/stripe/client.d.ts.map +1 -0
- package/lib/stripe/client.js +94 -0
- package/lib/stripe/client.js.map +1 -0
- package/lib/stripe/coupon.d.ts +135 -0
- package/lib/stripe/coupon.d.ts.map +1 -0
- package/lib/stripe/coupon.js +161 -0
- package/lib/stripe/coupon.js.map +1 -0
- package/lib/stripe/customer.d.ts +269 -0
- package/lib/stripe/customer.d.ts.map +1 -0
- package/lib/stripe/customer.js +289 -0
- package/lib/stripe/customer.js.map +1 -0
- package/lib/stripe/entitlements-feature.d.ts +84 -0
- package/lib/stripe/entitlements-feature.d.ts.map +1 -0
- package/lib/stripe/entitlements-feature.js +102 -0
- package/lib/stripe/entitlements-feature.js.map +1 -0
- package/lib/stripe/file.d.ts +143 -0
- package/lib/stripe/file.d.ts.map +1 -0
- package/lib/stripe/file.js +97 -0
- package/lib/stripe/file.js.map +1 -0
- package/lib/stripe/index.d.ts +11 -0
- package/lib/stripe/index.d.ts.map +1 -1
- package/lib/stripe/index.js +11 -0
- package/lib/stripe/index.js.map +1 -1
- package/lib/stripe/meter.d.ts +10 -1
- package/lib/stripe/meter.d.ts.map +1 -1
- package/lib/stripe/meter.js +13 -7
- package/lib/stripe/meter.js.map +1 -1
- package/lib/stripe/portal-configuration.d.ts +286 -0
- package/lib/stripe/portal-configuration.d.ts.map +1 -0
- package/lib/stripe/portal-configuration.js +320 -0
- package/lib/stripe/portal-configuration.js.map +1 -0
- package/lib/stripe/price.d.ts +10 -1
- package/lib/stripe/price.d.ts.map +1 -1
- package/lib/stripe/price.js +34 -13
- package/lib/stripe/price.js.map +1 -1
- package/lib/stripe/product-feature.d.ts +76 -0
- package/lib/stripe/product-feature.d.ts.map +1 -0
- package/lib/stripe/product-feature.js +74 -0
- package/lib/stripe/product-feature.js.map +1 -0
- package/lib/stripe/product.d.ts +10 -1
- package/lib/stripe/product.d.ts.map +1 -1
- package/lib/stripe/product.js +33 -14
- package/lib/stripe/product.js.map +1 -1
- package/lib/stripe/promotion-code.d.ts +138 -0
- package/lib/stripe/promotion-code.d.ts.map +1 -0
- package/lib/stripe/promotion-code.js +150 -0
- package/lib/stripe/promotion-code.js.map +1 -0
- package/lib/stripe/shipping-rate.d.ts +188 -0
- package/lib/stripe/shipping-rate.d.ts.map +1 -0
- package/lib/stripe/shipping-rate.js +198 -0
- package/lib/stripe/shipping-rate.js.map +1 -0
- package/lib/stripe/tax-rate.d.ts +130 -0
- package/lib/stripe/tax-rate.d.ts.map +1 -0
- package/lib/stripe/tax-rate.js +126 -0
- package/lib/stripe/tax-rate.js.map +1 -0
- package/lib/stripe/webhook.d.ts +10 -1
- package/lib/stripe/webhook.d.ts.map +1 -1
- package/lib/stripe/webhook.js +59 -14
- package/lib/stripe/webhook.js.map +1 -1
- package/lib/test/bun.d.ts.map +1 -1
- package/lib/test/bun.js +2 -6
- package/lib/test/bun.js.map +1 -1
- package/lib/test/vitest.d.ts.map +1 -1
- package/lib/test/vitest.js +3 -7
- package/lib/test/vitest.js.map +1 -1
- package/lib/util/retry.d.ts +1 -1
- package/lib/util/retry.d.ts.map +1 -1
- package/lib/util/retry.js.map +1 -1
- package/package.json +3 -2
- package/src/aws/control/client.ts +1 -1
- package/src/aws/control/resource.ts +2 -1
- package/src/aws/function.ts +3 -6
- package/src/cloudflare/ai.ts +21 -0
- package/src/cloudflare/bindings.ts +3 -2
- package/src/cloudflare/bound.ts +3 -3
- package/src/cloudflare/do-state-store/index.ts +1 -0
- package/src/cloudflare/do-state-store/internal.ts +215 -0
- package/src/cloudflare/do-state-store/store.ts +188 -0
- package/src/cloudflare/do-state-store/types.ts +74 -0
- package/src/cloudflare/do-state-store/worker.ts +199 -0
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/pipeline.ts +1 -1
- package/src/cloudflare/queue-consumer.ts +59 -1
- package/src/cloudflare/website.ts +38 -6
- package/src/cloudflare/worker-assets.ts +15 -3
- package/src/cloudflare/worker-metadata.ts +1 -1
- package/src/cloudflare/worker.ts +66 -46
- package/src/cloudflare/wrangler.json.ts +1 -1
- package/src/cloudflare/zone.ts +75 -2
- package/src/fs/file-system-state-store.ts +7 -2
- package/src/stripe/card.ts +320 -0
- package/src/stripe/client.ts +145 -0
- package/src/stripe/coupon.ts +280 -0
- package/src/stripe/customer.ts +528 -0
- package/src/stripe/entitlements-feature.ts +169 -0
- package/src/stripe/file.ts +219 -0
- package/src/stripe/index.ts +11 -0
- package/src/stripe/meter.ts +23 -7
- package/src/stripe/portal-configuration.ts +609 -0
- package/src/stripe/price.ts +47 -14
- package/src/stripe/product-feature.ts +150 -0
- package/src/stripe/product.ts +48 -15
- package/src/stripe/promotion-code.ts +268 -0
- package/src/stripe/shipping-rate.ts +362 -0
- package/src/stripe/tax-rate.ts +218 -0
- package/src/stripe/webhook.ts +82 -15
- package/src/test/bun.ts +2 -7
- package/src/test/vitest.ts +3 -8
- package/src/util/retry.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../src/stripe/product.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../src/stripe/product.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,KAAK,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,IAAI,CAAC,EAAE,WAAW,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,OAAQ,SAAQ,QAAQ,CAAC,iBAAiB,CAAC,EAAE,YAAY;IACxE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,iBAAiB,CAAC,EAAE;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,OAAO,yFAGV,OAAO,CAAC,OAAO,CAAC,OACjB,MAAM,SACJ,YAAY,KAClB,OAAO,CAAC,OAAO,CAAC,CAoGpB,CAAC"}
|
package/lib/stripe/product.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Stripe from "stripe";
|
|
2
1
|
import { Resource } from "../resource.js";
|
|
2
|
+
import { createStripeClient, handleStripeDeleteError } from "./client.js";
|
|
3
3
|
/**
|
|
4
4
|
* Create and manage Stripe products
|
|
5
5
|
*
|
|
@@ -39,13 +39,7 @@ import { Resource } from "../resource.js";
|
|
|
39
39
|
* });
|
|
40
40
|
*/
|
|
41
41
|
export const Product = Resource("stripe::Product", async function (_id, props) {
|
|
42
|
-
|
|
43
|
-
const apiKey = process.env.STRIPE_API_KEY;
|
|
44
|
-
if (!apiKey) {
|
|
45
|
-
throw new Error("STRIPE_API_KEY environment variable is required");
|
|
46
|
-
}
|
|
47
|
-
// Initialize Stripe client
|
|
48
|
-
const stripe = new Stripe(apiKey);
|
|
42
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
49
43
|
if (this.phase === "delete") {
|
|
50
44
|
try {
|
|
51
45
|
if (this.phase === "delete" && this.output?.id) {
|
|
@@ -53,8 +47,7 @@ export const Product = Resource("stripe::Product", async function (_id, props) {
|
|
|
53
47
|
}
|
|
54
48
|
}
|
|
55
49
|
catch (error) {
|
|
56
|
-
|
|
57
|
-
console.error("Error deactivating product:", error);
|
|
50
|
+
handleStripeDeleteError(error, "Product", this.output?.id);
|
|
58
51
|
}
|
|
59
52
|
// Return a minimal output for deleted state
|
|
60
53
|
return this.destroy();
|
|
@@ -63,7 +56,7 @@ export const Product = Resource("stripe::Product", async function (_id, props) {
|
|
|
63
56
|
let product;
|
|
64
57
|
if (this.phase === "update" && this.output?.id) {
|
|
65
58
|
// Update existing product
|
|
66
|
-
|
|
59
|
+
const updateParams = {
|
|
67
60
|
name: props.name,
|
|
68
61
|
description: props.description,
|
|
69
62
|
active: props.active,
|
|
@@ -72,11 +65,12 @@ export const Product = Resource("stripe::Product", async function (_id, props) {
|
|
|
72
65
|
statement_descriptor: props.statementDescriptor,
|
|
73
66
|
metadata: props.metadata,
|
|
74
67
|
tax_code: props.taxCode,
|
|
75
|
-
}
|
|
68
|
+
};
|
|
69
|
+
product = await stripe.products.update(this.output.id, updateParams);
|
|
76
70
|
}
|
|
77
71
|
else {
|
|
78
72
|
// Create new product
|
|
79
|
-
|
|
73
|
+
const createParams = {
|
|
80
74
|
name: props.name,
|
|
81
75
|
description: props.description,
|
|
82
76
|
active: props.active,
|
|
@@ -88,7 +82,32 @@ export const Product = Resource("stripe::Product", async function (_id, props) {
|
|
|
88
82
|
statement_descriptor: props.statementDescriptor,
|
|
89
83
|
metadata: props.metadata,
|
|
90
84
|
tax_code: props.taxCode,
|
|
91
|
-
}
|
|
85
|
+
};
|
|
86
|
+
if (props.adopt) {
|
|
87
|
+
const existingProducts = await stripe.products.list({
|
|
88
|
+
limit: 100,
|
|
89
|
+
});
|
|
90
|
+
const existingProduct = existingProducts.data.find((p) => p.name === props.name);
|
|
91
|
+
if (existingProduct) {
|
|
92
|
+
const updateParams = {
|
|
93
|
+
name: props.name,
|
|
94
|
+
description: props.description,
|
|
95
|
+
active: props.active,
|
|
96
|
+
images: props.images,
|
|
97
|
+
url: props.url,
|
|
98
|
+
statement_descriptor: props.statementDescriptor,
|
|
99
|
+
metadata: props.metadata,
|
|
100
|
+
tax_code: props.taxCode,
|
|
101
|
+
};
|
|
102
|
+
product = await stripe.products.update(existingProduct.id, updateParams);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
product = await stripe.products.create(createParams);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
product = await stripe.products.create(createParams);
|
|
110
|
+
}
|
|
92
111
|
}
|
|
93
112
|
return this({
|
|
94
113
|
id: product.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/stripe/product.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/stripe/product.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AA6G1E;;;;;;;;;;;;;;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AAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
import type { Secret } from "../secret.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Restrictions for promotion code usage
|
|
6
|
+
*/
|
|
7
|
+
export interface PromotionCodeRestrictions {
|
|
8
|
+
/**
|
|
9
|
+
* Promotion codes defined with this restriction will only work for Checkout Sessions in payment mode
|
|
10
|
+
*/
|
|
11
|
+
firstTimeTransaction?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Minimum amount required to redeem this promotion code into a coupon
|
|
14
|
+
*/
|
|
15
|
+
minimumAmount?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Three-letter ISO code for minimum_amount
|
|
18
|
+
*/
|
|
19
|
+
minimumAmountCurrency?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Properties for creating a Stripe promotion code
|
|
23
|
+
*/
|
|
24
|
+
export interface PromotionCodeProps {
|
|
25
|
+
/**
|
|
26
|
+
* The coupon for this promotion code
|
|
27
|
+
*/
|
|
28
|
+
coupon: string;
|
|
29
|
+
/**
|
|
30
|
+
* The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for a specific customer
|
|
31
|
+
*/
|
|
32
|
+
code?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the promotion code is currently active
|
|
35
|
+
*/
|
|
36
|
+
active?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The customer that this promotion code can be used by
|
|
39
|
+
*/
|
|
40
|
+
customer?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The timestamp at which this promotion code will expire
|
|
43
|
+
*/
|
|
44
|
+
expiresAt?: number;
|
|
45
|
+
/**
|
|
46
|
+
* The maximum number of times this promotion code can be redeemed
|
|
47
|
+
*/
|
|
48
|
+
maxRedemptions?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Set of key-value pairs that you can attach to an object
|
|
51
|
+
*/
|
|
52
|
+
metadata?: Record<string, string>;
|
|
53
|
+
/**
|
|
54
|
+
* Settings that restrict the redemption of the promotion code
|
|
55
|
+
*/
|
|
56
|
+
restrictions?: PromotionCodeRestrictions;
|
|
57
|
+
/**
|
|
58
|
+
* API key to use (overrides environment variable)
|
|
59
|
+
*/
|
|
60
|
+
apiKey?: Secret;
|
|
61
|
+
/**
|
|
62
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
63
|
+
*/
|
|
64
|
+
adopt?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Output from the Stripe promotion code
|
|
68
|
+
*/
|
|
69
|
+
export interface PromotionCode extends Resource<"stripe::PromotionCode">, PromotionCodeProps {
|
|
70
|
+
/**
|
|
71
|
+
* The ID of the promotion code
|
|
72
|
+
*/
|
|
73
|
+
id: string;
|
|
74
|
+
/**
|
|
75
|
+
* String representing the object's type
|
|
76
|
+
*/
|
|
77
|
+
object: "promotion_code";
|
|
78
|
+
/**
|
|
79
|
+
* Time at which the object was created
|
|
80
|
+
*/
|
|
81
|
+
created: number;
|
|
82
|
+
/**
|
|
83
|
+
* Has the value true if the object exists in live mode or the value false if the object exists in test mode
|
|
84
|
+
*/
|
|
85
|
+
livemode: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Number of times this promotion code has been used
|
|
88
|
+
*/
|
|
89
|
+
timesRedeemed: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create and manage Stripe promotion codes for coupons
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Create a basic promotion code
|
|
96
|
+
* const basicPromoCode = await PromotionCode("summer-promo", {
|
|
97
|
+
* coupon: "SUMMER25",
|
|
98
|
+
* code: "SAVE25NOW",
|
|
99
|
+
* active: true,
|
|
100
|
+
* metadata: {
|
|
101
|
+
* campaign: "summer_sale",
|
|
102
|
+
* channel: "email"
|
|
103
|
+
* }
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Create a customer-specific promotion code
|
|
108
|
+
* const customerPromoCode = await PromotionCode("vip-discount", {
|
|
109
|
+
* coupon: "VIP15",
|
|
110
|
+
* code: "VIP15OFF",
|
|
111
|
+
* customer: "cus_xyz123",
|
|
112
|
+
* maxRedemptions: 1,
|
|
113
|
+
* expiresAt: Math.floor(Date.now() / 1000) + 86400 * 30,
|
|
114
|
+
* metadata: {
|
|
115
|
+
* type: "vip_exclusive",
|
|
116
|
+
* tier: "gold"
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Create a promotion code with restrictions
|
|
122
|
+
* const restrictedPromoCode = await PromotionCode("first-time-buyer", {
|
|
123
|
+
* coupon: "WELCOME10",
|
|
124
|
+
* code: "FIRSTTIME10",
|
|
125
|
+
* restrictions: {
|
|
126
|
+
* firstTimeTransaction: true,
|
|
127
|
+
* minimumAmount: 5000,
|
|
128
|
+
* minimumAmountCurrency: "usd"
|
|
129
|
+
* },
|
|
130
|
+
* maxRedemptions: 1000,
|
|
131
|
+
* metadata: {
|
|
132
|
+
* campaign: "new_customer_acquisition",
|
|
133
|
+
* minimum_order: "50_usd"
|
|
134
|
+
* }
|
|
135
|
+
* });
|
|
136
|
+
*/
|
|
137
|
+
export declare const PromotionCode: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<PromotionCode>, _id: string, props: PromotionCodeProps) => Promise<PromotionCode>);
|
|
138
|
+
//# sourceMappingURL=promotion-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion-code.d.ts","sourceRoot":"","sources":["../../src/stripe/promotion-code.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,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;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,aAAa,yFAGhB,OAAO,CAAC,aAAa,CAAC,OACvB,MAAM,SACJ,kBAAkB,KACxB,OAAO,CAAC,aAAa,CAAC,CA+G1B,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Resource } from "../resource.js";
|
|
2
|
+
import { createStripeClient, handleStripeDeleteError, isStripeConflictError, } from "./client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create and manage Stripe promotion codes for coupons
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Create a basic promotion code
|
|
8
|
+
* const basicPromoCode = await PromotionCode("summer-promo", {
|
|
9
|
+
* coupon: "SUMMER25",
|
|
10
|
+
* code: "SAVE25NOW",
|
|
11
|
+
* active: true,
|
|
12
|
+
* metadata: {
|
|
13
|
+
* campaign: "summer_sale",
|
|
14
|
+
* channel: "email"
|
|
15
|
+
* }
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Create a customer-specific promotion code
|
|
20
|
+
* const customerPromoCode = await PromotionCode("vip-discount", {
|
|
21
|
+
* coupon: "VIP15",
|
|
22
|
+
* code: "VIP15OFF",
|
|
23
|
+
* customer: "cus_xyz123",
|
|
24
|
+
* maxRedemptions: 1,
|
|
25
|
+
* expiresAt: Math.floor(Date.now() / 1000) + 86400 * 30,
|
|
26
|
+
* metadata: {
|
|
27
|
+
* type: "vip_exclusive",
|
|
28
|
+
* tier: "gold"
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Create a promotion code with restrictions
|
|
34
|
+
* const restrictedPromoCode = await PromotionCode("first-time-buyer", {
|
|
35
|
+
* coupon: "WELCOME10",
|
|
36
|
+
* code: "FIRSTTIME10",
|
|
37
|
+
* restrictions: {
|
|
38
|
+
* firstTimeTransaction: true,
|
|
39
|
+
* minimumAmount: 5000,
|
|
40
|
+
* minimumAmountCurrency: "usd"
|
|
41
|
+
* },
|
|
42
|
+
* maxRedemptions: 1000,
|
|
43
|
+
* metadata: {
|
|
44
|
+
* campaign: "new_customer_acquisition",
|
|
45
|
+
* minimum_order: "50_usd"
|
|
46
|
+
* }
|
|
47
|
+
* });
|
|
48
|
+
*/
|
|
49
|
+
export const PromotionCode = Resource("stripe::PromotionCode", async function (_id, props) {
|
|
50
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
51
|
+
if (this.phase === "delete") {
|
|
52
|
+
try {
|
|
53
|
+
if (this.output?.id) {
|
|
54
|
+
await stripe.promotionCodes.update(this.output.id, { active: false });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
handleStripeDeleteError(error, "PromotionCode", this.output?.id);
|
|
59
|
+
}
|
|
60
|
+
return this.destroy();
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
let promotionCode;
|
|
64
|
+
if (this.phase === "update" && this.output?.id) {
|
|
65
|
+
const updateParams = {
|
|
66
|
+
active: props.active,
|
|
67
|
+
metadata: props.metadata,
|
|
68
|
+
};
|
|
69
|
+
promotionCode = await stripe.promotionCodes.update(this.output.id, updateParams);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const createParams = {
|
|
73
|
+
coupon: props.coupon,
|
|
74
|
+
code: props.code,
|
|
75
|
+
active: props.active,
|
|
76
|
+
customer: props.customer,
|
|
77
|
+
expires_at: props.expiresAt,
|
|
78
|
+
max_redemptions: props.maxRedemptions,
|
|
79
|
+
metadata: props.metadata,
|
|
80
|
+
};
|
|
81
|
+
if (props.restrictions) {
|
|
82
|
+
createParams.restrictions = {
|
|
83
|
+
first_time_transaction: props.restrictions.firstTimeTransaction,
|
|
84
|
+
minimum_amount: props.restrictions.minimumAmount,
|
|
85
|
+
minimum_amount_currency: props.restrictions.minimumAmountCurrency,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
promotionCode = await stripe.promotionCodes.create(createParams);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (isStripeConflictError(error) && props.adopt) {
|
|
93
|
+
if (props.code) {
|
|
94
|
+
const existingPromotionCodes = await stripe.promotionCodes.list({
|
|
95
|
+
code: props.code,
|
|
96
|
+
limit: 1,
|
|
97
|
+
});
|
|
98
|
+
if (existingPromotionCodes.data.length > 0) {
|
|
99
|
+
const existingPromotionCode = existingPromotionCodes.data[0];
|
|
100
|
+
const updateParams = {
|
|
101
|
+
active: props.active,
|
|
102
|
+
metadata: props.metadata,
|
|
103
|
+
};
|
|
104
|
+
promotionCode = await stripe.promotionCodes.update(existingPromotionCode.id, updateParams);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return this({
|
|
120
|
+
id: promotionCode.id,
|
|
121
|
+
object: promotionCode.object,
|
|
122
|
+
coupon: typeof promotionCode.coupon === "string"
|
|
123
|
+
? promotionCode.coupon
|
|
124
|
+
: promotionCode.coupon.id,
|
|
125
|
+
code: promotionCode.code,
|
|
126
|
+
active: promotionCode.active,
|
|
127
|
+
customer: typeof promotionCode.customer === "string"
|
|
128
|
+
? promotionCode.customer
|
|
129
|
+
: promotionCode.customer?.id,
|
|
130
|
+
expiresAt: promotionCode.expires_at || undefined,
|
|
131
|
+
maxRedemptions: promotionCode.max_redemptions || undefined,
|
|
132
|
+
metadata: promotionCode.metadata || undefined,
|
|
133
|
+
restrictions: promotionCode.restrictions
|
|
134
|
+
? {
|
|
135
|
+
firstTimeTransaction: promotionCode.restrictions.first_time_transaction || undefined,
|
|
136
|
+
minimumAmount: promotionCode.restrictions.minimum_amount || undefined,
|
|
137
|
+
minimumAmountCurrency: promotionCode.restrictions.minimum_amount_currency || undefined,
|
|
138
|
+
}
|
|
139
|
+
: undefined,
|
|
140
|
+
created: promotionCode.created,
|
|
141
|
+
livemode: promotionCode.livemode,
|
|
142
|
+
timesRedeemed: promotionCode.times_redeemed,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error("Error creating/updating promotion code:", error);
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=promotion-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promotion-code.js","sourceRoot":"","sources":["../../src/stripe/promotion-code.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAgGrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CACnC,uBAAuB,EACvB,KAAK,WAEH,GAAW,EACX,KAAyB;IAEzB,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,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACnE,CA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UAAU,IAAI,SAAS;YAChD,cAAc,EAAE,aAAa,CAAC,eAAe,IAAI,SAAS;YAC1D,QAAQ,EAAE,aAAa,CAAC,QAAQ,IAAI,SAAS;YAC7C,YAAY,EAAE,aAAa,CAAC,YAAY;gBACtC,CAAC,CAAC;oBACE,oBAAoB,EAClB,aAAa,CAAC,YAAY,CAAC,sBAAsB,IAAI,SAAS;oBAChE,aAAa,EACX,aAAa,CAAC,YAAY,CAAC,cAAc,IAAI,SAAS;oBACxD,qBAAqB,EACnB,aAAa,CAAC,YAAY,CAAC,uBAAuB,IAAI,SAAS;iBAClE;gBACH,CAAC,CAAC,SAAS;YACb,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,QAAQ,EAAE,aAAa,CAAC,QAAQ;YAChC,aAAa,EAAE,aAAa,CAAC,cAAc;SAC5C,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
* Delivery estimate for shipping rate
|
|
7
|
+
*/
|
|
8
|
+
export interface ShippingRateDeliveryEstimate {
|
|
9
|
+
/**
|
|
10
|
+
* The lower bound of the estimated range
|
|
11
|
+
*/
|
|
12
|
+
minimum?: {
|
|
13
|
+
/**
|
|
14
|
+
* A unit of time
|
|
15
|
+
*/
|
|
16
|
+
unit: Stripe.ShippingRateCreateParams.DeliveryEstimate.Minimum.Unit;
|
|
17
|
+
/**
|
|
18
|
+
* Must be greater than 0
|
|
19
|
+
*/
|
|
20
|
+
value: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The upper bound of the estimated range
|
|
24
|
+
*/
|
|
25
|
+
maximum?: {
|
|
26
|
+
/**
|
|
27
|
+
* A unit of time
|
|
28
|
+
*/
|
|
29
|
+
unit: Stripe.ShippingRateCreateParams.DeliveryEstimate.Maximum.Unit;
|
|
30
|
+
/**
|
|
31
|
+
* Must be greater than 0
|
|
32
|
+
*/
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fixed amount configuration for shipping rate
|
|
38
|
+
*/
|
|
39
|
+
export interface ShippingRateFixedAmount {
|
|
40
|
+
/**
|
|
41
|
+
* A non-negative integer in cents representing how much to charge
|
|
42
|
+
*/
|
|
43
|
+
amount: number;
|
|
44
|
+
/**
|
|
45
|
+
* Three-letter ISO currency code, in lowercase
|
|
46
|
+
*/
|
|
47
|
+
currency: string;
|
|
48
|
+
/**
|
|
49
|
+
* Shipping rates defined in each available currency option
|
|
50
|
+
*/
|
|
51
|
+
currencyOptions?: Record<string, {
|
|
52
|
+
/**
|
|
53
|
+
* A non-negative integer in cents representing how much to charge
|
|
54
|
+
*/
|
|
55
|
+
amount: number;
|
|
56
|
+
/**
|
|
57
|
+
* Specifies whether the rate is considered inclusive or exclusive of taxes
|
|
58
|
+
*/
|
|
59
|
+
taxBehavior?: Stripe.ShippingRateCreateParams.FixedAmount.CurrencyOptions.TaxBehavior;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Properties for creating a Stripe shipping rate
|
|
64
|
+
*/
|
|
65
|
+
export interface ShippingRateProps {
|
|
66
|
+
/**
|
|
67
|
+
* The name of the shipping rate, meant to be displayable to the customer
|
|
68
|
+
*/
|
|
69
|
+
displayName: string;
|
|
70
|
+
/**
|
|
71
|
+
* Describes a fixed amount to charge for shipping
|
|
72
|
+
*/
|
|
73
|
+
fixedAmount?: ShippingRateFixedAmount;
|
|
74
|
+
/**
|
|
75
|
+
* The estimated range for how long shipping will take
|
|
76
|
+
*/
|
|
77
|
+
deliveryEstimate?: ShippingRateDeliveryEstimate;
|
|
78
|
+
/**
|
|
79
|
+
* Set of key-value pairs that you can attach to an object
|
|
80
|
+
*/
|
|
81
|
+
metadata?: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the shipping rate can be used for new purchases
|
|
84
|
+
*/
|
|
85
|
+
active?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Specifies whether the rate is considered inclusive or exclusive of taxes
|
|
88
|
+
*/
|
|
89
|
+
taxBehavior?: Stripe.ShippingRateCreateParams.TaxBehavior;
|
|
90
|
+
/**
|
|
91
|
+
* A tax code ID
|
|
92
|
+
*/
|
|
93
|
+
taxCode?: string;
|
|
94
|
+
/**
|
|
95
|
+
* The type of calculation to use on the shipping rate
|
|
96
|
+
*/
|
|
97
|
+
type?: "fixed_amount";
|
|
98
|
+
/**
|
|
99
|
+
* API key to use (overrides environment variable)
|
|
100
|
+
*/
|
|
101
|
+
apiKey?: Secret;
|
|
102
|
+
/**
|
|
103
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
104
|
+
*/
|
|
105
|
+
adopt?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Output from the Stripe shipping rate
|
|
109
|
+
*/
|
|
110
|
+
export interface ShippingRate extends Resource<"stripe::ShippingRate">, ShippingRateProps {
|
|
111
|
+
/**
|
|
112
|
+
* The ID of the shipping rate
|
|
113
|
+
*/
|
|
114
|
+
id: string;
|
|
115
|
+
/**
|
|
116
|
+
* String representing the object's type
|
|
117
|
+
*/
|
|
118
|
+
object: "shipping_rate";
|
|
119
|
+
/**
|
|
120
|
+
* Time at which the object was created
|
|
121
|
+
*/
|
|
122
|
+
created: number;
|
|
123
|
+
/**
|
|
124
|
+
* Has the value true if the object exists in live mode or the value false if the object exists in test mode
|
|
125
|
+
*/
|
|
126
|
+
livemode: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create and manage Stripe shipping rates
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Create a standard shipping rate
|
|
133
|
+
* const standardShipping = await ShippingRate("standard-shipping", {
|
|
134
|
+
* displayName: "Standard Shipping",
|
|
135
|
+
* type: "fixed_amount",
|
|
136
|
+
* fixedAmount: {
|
|
137
|
+
* amount: 500,
|
|
138
|
+
* currency: "usd"
|
|
139
|
+
* },
|
|
140
|
+
* deliveryEstimate: {
|
|
141
|
+
* minimum: { unit: "business_day", value: 5 },
|
|
142
|
+
* maximum: { unit: "business_day", value: 7 }
|
|
143
|
+
* },
|
|
144
|
+
* taxBehavior: "exclusive"
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Create an express shipping rate
|
|
149
|
+
* const expressShipping = await ShippingRate("express-shipping", {
|
|
150
|
+
* displayName: "Express Shipping",
|
|
151
|
+
* type: "fixed_amount",
|
|
152
|
+
* fixedAmount: {
|
|
153
|
+
* amount: 1500,
|
|
154
|
+
* currency: "usd"
|
|
155
|
+
* },
|
|
156
|
+
* deliveryEstimate: {
|
|
157
|
+
* minimum: { unit: "business_day", value: 1 },
|
|
158
|
+
* maximum: { unit: "business_day", value: 2 }
|
|
159
|
+
* },
|
|
160
|
+
* taxBehavior: "exclusive",
|
|
161
|
+
* metadata: {
|
|
162
|
+
* priority: "high",
|
|
163
|
+
* service_level: "express"
|
|
164
|
+
* }
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Create a free shipping rate
|
|
169
|
+
* const freeShipping = await ShippingRate("free-shipping", {
|
|
170
|
+
* displayName: "Free Shipping",
|
|
171
|
+
* type: "fixed_amount",
|
|
172
|
+
* fixedAmount: {
|
|
173
|
+
* amount: 0,
|
|
174
|
+
* currency: "usd"
|
|
175
|
+
* },
|
|
176
|
+
* deliveryEstimate: {
|
|
177
|
+
* minimum: { unit: "business_day", value: 7 },
|
|
178
|
+
* maximum: { unit: "business_day", value: 10 }
|
|
179
|
+
* },
|
|
180
|
+
* taxBehavior: "unspecified",
|
|
181
|
+
* metadata: {
|
|
182
|
+
* promotion: "free_shipping_over_50",
|
|
183
|
+
* cost_center: "marketing"
|
|
184
|
+
* }
|
|
185
|
+
* });
|
|
186
|
+
*/
|
|
187
|
+
export declare const ShippingRate: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<ShippingRate>, _id: string, props: ShippingRateProps) => Promise<ShippingRate>);
|
|
188
|
+
//# sourceMappingURL=shipping-rate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shipping-rate.d.ts","sourceRoot":"","sources":["../../src/stripe/shipping-rate.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;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC;QACpE;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF;;OAEG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC;QACpE;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,C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