alchemy 0.24.0 → 0.24.1
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/function.d.ts.map +1 -1
- package/lib/aws/function.js +1 -4
- package/lib/aws/function.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-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/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 +2 -1
- package/src/aws/function.ts +3 -6
- 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-metadata.ts +1 -1
- package/src/cloudflare/worker.ts +66 -46
- package/src/cloudflare/wrangler.json.ts +1 -1
- 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
package/lib/stripe/price.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 prices for products
|
|
5
5
|
*
|
|
@@ -51,13 +51,7 @@ import { Resource } from "../resource.js";
|
|
|
51
51
|
* });
|
|
52
52
|
*/
|
|
53
53
|
export const Price = Resource("stripe::Price", async function (_id, props) {
|
|
54
|
-
|
|
55
|
-
const apiKey = process.env.STRIPE_API_KEY;
|
|
56
|
-
if (!apiKey) {
|
|
57
|
-
throw new Error("STRIPE_API_KEY environment variable is required");
|
|
58
|
-
}
|
|
59
|
-
// Initialize Stripe client
|
|
60
|
-
const stripe = new Stripe(apiKey);
|
|
54
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
61
55
|
if (this.phase === "delete") {
|
|
62
56
|
try {
|
|
63
57
|
if (this.phase === "delete" && this.output?.id) {
|
|
@@ -66,8 +60,7 @@ export const Price = Resource("stripe::Price", async function (_id, props) {
|
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
catch (error) {
|
|
69
|
-
|
|
70
|
-
console.error("Error deactivating price:", error);
|
|
63
|
+
handleStripeDeleteError(error, "Price", this.output?.id);
|
|
71
64
|
}
|
|
72
65
|
return this.destroy();
|
|
73
66
|
}
|
|
@@ -75,13 +68,14 @@ export const Price = Resource("stripe::Price", async function (_id, props) {
|
|
|
75
68
|
let price;
|
|
76
69
|
if (this.phase === "update" && this.output?.id) {
|
|
77
70
|
// Update existing price (limited properties can be updated)
|
|
78
|
-
|
|
71
|
+
const updateParams = {
|
|
79
72
|
active: props.active,
|
|
80
73
|
metadata: props.metadata,
|
|
81
74
|
nickname: props.nickname,
|
|
82
75
|
lookup_key: props.lookupKey,
|
|
83
76
|
transfer_lookup_key: props.transferLookupKey,
|
|
84
|
-
}
|
|
77
|
+
};
|
|
78
|
+
price = await stripe.prices.update(this.output.id, updateParams);
|
|
85
79
|
}
|
|
86
80
|
else {
|
|
87
81
|
// Create new price
|
|
@@ -112,7 +106,34 @@ export const Price = Resource("stripe::Price", async function (_id, props) {
|
|
|
112
106
|
aggregate_usage: props.recurring.aggregateUsage,
|
|
113
107
|
};
|
|
114
108
|
}
|
|
115
|
-
|
|
109
|
+
if (props.lookupKey) {
|
|
110
|
+
const existingPrices = await stripe.prices.list({
|
|
111
|
+
lookup_keys: [props.lookupKey],
|
|
112
|
+
limit: 1,
|
|
113
|
+
});
|
|
114
|
+
if (existingPrices.data.length > 0) {
|
|
115
|
+
if (props.adopt) {
|
|
116
|
+
const existingPrice = existingPrices.data[0];
|
|
117
|
+
const updateParams = {
|
|
118
|
+
active: props.active,
|
|
119
|
+
metadata: props.metadata,
|
|
120
|
+
nickname: props.nickname,
|
|
121
|
+
lookup_key: props.lookupKey,
|
|
122
|
+
transfer_lookup_key: props.transferLookupKey,
|
|
123
|
+
};
|
|
124
|
+
price = await stripe.prices.update(existingPrice.id, updateParams);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
price = existingPrices.data[0];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
price = await stripe.prices.create(createParams);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
price = await stripe.prices.create(createParams);
|
|
136
|
+
}
|
|
116
137
|
}
|
|
117
138
|
// Transform Stripe recurring object to our format
|
|
118
139
|
const recurring = price.recurring
|
package/lib/stripe/price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/stripe/price.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/stripe/price.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAoJ1E;;;;;;;;;;;;;;;;;;;;;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AAC,EAAE;YACZ,OAAO,EACL,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YACtE,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,UAAU,EAAE,KAAK,CAAC,WAAW,IAAI,SAAS;YAC1C,iBAAiB,EAAE,KAAK,CAAC,mBAAmB,IAAI,SAAS;YACzD,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,aAAa,EAAE,KAAK,CAAC,cAA+B;YACpD,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,SAAS;YACrC,SAAS,EAAE,SAAS;YACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,SAAS;YACrC,WAAW,EAAE,KAAK,CAAC,YAA2B;YAC9C,SAAS,EAAE,KAAK,CAAC,OAAO;YACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,IAAI,EAAE,KAAK,CAAC,IAAyB;YACrC,SAAS,EAAE,KAAK,CAAC,UAAU,IAAI,SAAS;SACzC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Context } from "../context.ts";
|
|
2
|
+
import { Resource } from "../resource.ts";
|
|
3
|
+
import type { Secret } from "../secret.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Properties for creating a Stripe product feature
|
|
6
|
+
*/
|
|
7
|
+
export interface ProductFeatureProps {
|
|
8
|
+
/**
|
|
9
|
+
* The ID of the product that this feature will be attached to
|
|
10
|
+
*/
|
|
11
|
+
product: string;
|
|
12
|
+
/**
|
|
13
|
+
* The ID of the entitlements feature to attach to the product
|
|
14
|
+
*/
|
|
15
|
+
entitlementFeature: string;
|
|
16
|
+
/**
|
|
17
|
+
* API key to use (overrides environment variable)
|
|
18
|
+
*/
|
|
19
|
+
apiKey?: Secret;
|
|
20
|
+
/**
|
|
21
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
22
|
+
*/
|
|
23
|
+
adopt?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Output from the Stripe product feature
|
|
27
|
+
*/
|
|
28
|
+
export interface ProductFeature extends Resource<"stripe::ProductFeature">, ProductFeatureProps {
|
|
29
|
+
/**
|
|
30
|
+
* The ID of the product feature
|
|
31
|
+
*/
|
|
32
|
+
id: string;
|
|
33
|
+
/**
|
|
34
|
+
* String representing the object's type
|
|
35
|
+
*/
|
|
36
|
+
object: "product_feature";
|
|
37
|
+
/**
|
|
38
|
+
* The entitlement feature object attached to this product
|
|
39
|
+
*/
|
|
40
|
+
entitlementFeatureObject?: {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
lookupKey?: string;
|
|
44
|
+
metadata?: Record<string, string>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Has the value true if the object exists in live mode or the value false if the object exists in test mode
|
|
48
|
+
*/
|
|
49
|
+
livemode: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create and manage Stripe product features
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Attach an API access feature to a product
|
|
56
|
+
* const productApiFeature = await ProductFeature("product-api-access", {
|
|
57
|
+
* product: "prod_xyz123",
|
|
58
|
+
* entitlementFeature: "feat_abc456"
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Attach analytics feature to a premium product
|
|
63
|
+
* const productAnalytics = await ProductFeature("premium-analytics", {
|
|
64
|
+
* product: "prod_premium789",
|
|
65
|
+
* entitlementFeature: "feat_analytics123"
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Attach custom integrations to enterprise product
|
|
70
|
+
* const enterpriseIntegrations = await ProductFeature("enterprise-integrations", {
|
|
71
|
+
* product: "prod_enterprise456",
|
|
72
|
+
* entitlementFeature: "feat_integrations789"
|
|
73
|
+
* });
|
|
74
|
+
*/
|
|
75
|
+
export declare const ProductFeature: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<ProductFeature>, _id: string, props: ProductFeatureProps) => Promise<ProductFeature>);
|
|
76
|
+
//# sourceMappingURL=product-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-feature.d.ts","sourceRoot":"","sources":["../../src/stripe/product-feature.ts"],"names":[],"mappings":"AACA,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,mBAAmB;IAClC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cACf,SAAQ,QAAQ,CAAC,wBAAwB,CAAC,EACxC,mBAAmB;IACrB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;OAEG;IACH,wBAAwB,CAAC,EAAE;QACzB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACnC,CAAC;IAEF;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc,yFAGjB,OAAO,CAAC,cAAc,CAAC,OACxB,MAAM,SACJ,mBAAmB,KACzB,OAAO,CAAC,cAAc,CAAC,CAoD3B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Resource } from "../resource.js";
|
|
2
|
+
import { createStripeClient, handleStripeDeleteError, isStripeConflictError, } from "./client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create and manage Stripe product features
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Attach an API access feature to a product
|
|
8
|
+
* const productApiFeature = await ProductFeature("product-api-access", {
|
|
9
|
+
* product: "prod_xyz123",
|
|
10
|
+
* entitlementFeature: "feat_abc456"
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Attach analytics feature to a premium product
|
|
15
|
+
* const productAnalytics = await ProductFeature("premium-analytics", {
|
|
16
|
+
* product: "prod_premium789",
|
|
17
|
+
* entitlementFeature: "feat_analytics123"
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Attach custom integrations to enterprise product
|
|
22
|
+
* const enterpriseIntegrations = await ProductFeature("enterprise-integrations", {
|
|
23
|
+
* product: "prod_enterprise456",
|
|
24
|
+
* entitlementFeature: "feat_integrations789"
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
export const ProductFeature = Resource("stripe::ProductFeature", async function (_id, props) {
|
|
28
|
+
const stripe = createStripeClient({ apiKey: props.apiKey });
|
|
29
|
+
if (this.phase === "delete") {
|
|
30
|
+
try {
|
|
31
|
+
if (this.output?.id && this.output?.product) {
|
|
32
|
+
await stripe.products.deleteFeature(this.output.product, this.output.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
handleStripeDeleteError(error, "ProductFeature", this.output?.id);
|
|
37
|
+
}
|
|
38
|
+
return this.destroy();
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
let productFeature;
|
|
42
|
+
if (this.phase === "update" && this.output?.id) {
|
|
43
|
+
throw new Error("Product features cannot be updated after creation");
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
try {
|
|
47
|
+
productFeature = await stripe.products.createFeature(props.product, {
|
|
48
|
+
entitlement_feature: props.entitlementFeature,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (isStripeConflictError(error) && props.adopt) {
|
|
53
|
+
throw new Error("ProductFeature adoption is not supported - product features cannot be uniquely identified for adoption");
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return this({
|
|
61
|
+
id: productFeature.id,
|
|
62
|
+
object: productFeature.object,
|
|
63
|
+
product: props.product,
|
|
64
|
+
entitlementFeature: props.entitlementFeature,
|
|
65
|
+
entitlementFeatureObject: productFeature.entitlement_feature || undefined,
|
|
66
|
+
livemode: productFeature.livemode,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error("Error creating product feature:", error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=product-feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-feature.js","sourceRoot":"","sources":["../../src/stripe/product-feature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AA2DrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CACpC,wBAAwB,EACxB,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AAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;YACV,EAAE,EAAE,cAAc,CAAC,EAAE;YACrB,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;YAC5C,wBAAwB,EACtB,cAAc,CAAC,mBAAmB,IAAI,SAAS;YACjD,QAAQ,EAAE,cAAc,CAAC,QAAQ;SAClC,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"}
|
package/lib/stripe/product.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
4
5
|
type ProductType = Stripe.Product.Type;
|
|
5
6
|
/**
|
|
6
7
|
* Properties for creating a Stripe product
|
|
@@ -50,6 +51,14 @@ export interface ProductProps {
|
|
|
50
51
|
* Default tax code for the product
|
|
51
52
|
*/
|
|
52
53
|
taxCode?: string;
|
|
54
|
+
/**
|
|
55
|
+
* API key to use (overrides environment variable)
|
|
56
|
+
*/
|
|
57
|
+
apiKey?: Secret;
|
|
58
|
+
/**
|
|
59
|
+
* If true, adopt existing resource if creation fails due to conflict
|
|
60
|
+
*/
|
|
61
|
+
adopt?: boolean;
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
55
64
|
* Output from the Stripe product
|
|
@@ -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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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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAC7B,iBAAiB,EACjB,KAAK,WAEH,GAAW,EACX,KAAmB;IAEnB,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,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;gBAC/C,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAuB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,4CAA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S;YAC7B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,SAAS;YACzC,IAAI,EAAE,OAAO,CAAC,IAAmB;YACjC,SAAS,EAAE,OAAO,CAAC,UAAU,IAAI,SAAS;YAC1C,mBAAmB,EAAE,OAAO,CAAC,oBAAoB,IAAI,SAAS;YAC9D,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,SAAS;YACvC,OAAO,EACL,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACrE,SAAS,EAAE,OAAO,CAAC,OAAO;YAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,SAAS,EAAE,OAAO,CAAC,OAAO;YAC1B,iBAAiB,EAAE,OAAO,CAAC,kBAAkB,IAAI,SAAS;SAC3D,CAAC,CAAC;IACL,CAAC;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,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,yBAAyB;IACxC;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,QAAQ,C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