@shware/purchase 0.2.8 → 1.1.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.
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/stripe/config.ts
31
+ var config_exports = {};
32
+ __export(config_exports, {
33
+ StripeConfig: () => StripeConfig
34
+ });
35
+ module.exports = __toCommonJS(config_exports);
36
+ var import_utils = require("@shware/utils");
37
+ var import_ms = __toESM(require("ms"), 1);
38
+ var addMethod = /* @__PURE__ */ Symbol("addMethod");
39
+ var Product = class _Product {
40
+ id;
41
+ config;
42
+ plan;
43
+ prices;
44
+ defaultPriceId;
45
+ constructor(config, id, plan = null) {
46
+ this.id = id;
47
+ this.config = config;
48
+ this.plan = plan;
49
+ this.prices = /* @__PURE__ */ new Map();
50
+ this.defaultPriceId = null;
51
+ }
52
+ static create = (config, id, plan = null) => {
53
+ return new _Product(config, id, plan);
54
+ };
55
+ price = (priceId, credit = { credits: 0, expiresIn: "0" }) => {
56
+ this.prices.set(priceId, credit);
57
+ return this;
58
+ };
59
+ default = (defaultPriceId) => {
60
+ this.defaultPriceId = defaultPriceId;
61
+ this.config[addMethod](this);
62
+ return this.config;
63
+ };
64
+ };
65
+ var StripeConfig = class _StripeConfig {
66
+ products = /* @__PURE__ */ new Map();
67
+ returnUrl;
68
+ cancelUrl;
69
+ successUrl;
70
+ allowPromotionCodes;
71
+ get productIds() {
72
+ return Array.from(this.products.keys());
73
+ }
74
+ [addMethod] = (product) => {
75
+ this.products.set(product.id, product);
76
+ return this;
77
+ };
78
+ constructor(options) {
79
+ this.returnUrl = options.returnUrl;
80
+ this.cancelUrl = options.cancelUrl;
81
+ this.successUrl = options.successUrl;
82
+ this.allowPromotionCodes = options.allowPromotionCodes;
83
+ }
84
+ static create = (options) => {
85
+ return new _StripeConfig(options);
86
+ };
87
+ product = (id, plan = null) => {
88
+ return Product.create(this, id, plan);
89
+ };
90
+ getPlan = (productId) => {
91
+ const plan = this.products.get(productId)?.plan;
92
+ if (!plan) throw new Error(`Plan not found for product ${productId}`);
93
+ return plan;
94
+ };
95
+ getMode = (productId) => {
96
+ const product = this.products.get(productId);
97
+ (0, import_utils.invariant)(product, `Product not found for ${productId}`);
98
+ return product.plan === null ? "payment" : "subscription";
99
+ };
100
+ getPriceId = (productId) => {
101
+ const product = this.products.get(productId);
102
+ (0, import_utils.invariant)(product, `Product not found for ${productId}`);
103
+ (0, import_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
104
+ return product.defaultPriceId;
105
+ };
106
+ getCreditAmount = (productId, priceId) => {
107
+ const product = this.products.get(productId);
108
+ (0, import_utils.invariant)(product, `Product not found for ${productId}`);
109
+ if (priceId) {
110
+ const price = product.prices.get(priceId);
111
+ (0, import_utils.invariant)(price, `Price not found for ${priceId}`);
112
+ return price.credits;
113
+ }
114
+ (0, import_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
115
+ return product.prices.get(product.defaultPriceId)?.credits ?? 0;
116
+ };
117
+ getCreditExpiresIn = (productId, priceId) => {
118
+ const product = this.products.get(productId);
119
+ (0, import_utils.invariant)(product, `Product not found for ${productId}`);
120
+ if (priceId) {
121
+ const price = product.prices.get(priceId);
122
+ (0, import_utils.invariant)(price, `Price not found for ${priceId}`);
123
+ return (0, import_ms.default)(price.expiresIn);
124
+ }
125
+ (0, import_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
126
+ return (0, import_ms.default)(product.prices.get(product.defaultPriceId)?.expiresIn ?? "0");
127
+ };
128
+ getCreditExpiresAt = (productId, priceId) => {
129
+ const expiresIn = this.getCreditExpiresIn(productId, priceId);
130
+ return new Date(Date.now() + expiresIn).toISOString();
131
+ };
132
+ };
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ StripeConfig
136
+ });
137
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type ProductId = Lowercase<string>;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<P extends ProductId = ProductId, I extends PriceId = never> {\n readonly id: P;\n readonly config: StripeConfig;\n readonly plan: string | null;\n readonly prices: Map<PriceId, CreditConfig>;\n\n defaultPriceId: I | null;\n\n private constructor(config: StripeConfig, id: P, plan: string | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n static create = <P extends ProductId>(\n config: StripeConfig,\n id: P,\n plan: string | null = null\n ) => {\n return new Product<P>(config, id, plan);\n };\n\n price = <K extends PriceId>(\n priceId: K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<P, I | K> => {\n this.prices.set(priceId, credit);\n return this as Product<P, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig {\n private products: Map<ProductId, Product> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public allowPromotionCodes: boolean;\n\n get productIds(): ProductId[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = (options: Options) => {\n return new StripeConfig(options);\n };\n\n product = (id: ProductId, plan: string | null = null) => {\n return Product.create(this, id, plan);\n };\n\n getPlan = (productId: string): string => {\n const plan = this.products.get(productId as ProductId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,gBAAqC;AAMrC,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,UAAN,MAAM,SAAoE;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEQ,YAAY,QAAsB,IAAO,OAAsB,MAAM;AAC3E,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,SAAS,oBAAI,IAAI;AACtB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,OAAO,SAAS,CACd,QACA,IACA,OAAsB,SACnB;AACH,WAAO,IAAI,SAAW,QAAQ,IAAI,IAAI;AAAA,EACxC;AAAA,EAEA,QAAQ,CACN,SACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MAC9B;AACtB,SAAK,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,mBAAsB;AAC/B,SAAK,iBAAiB;AACtB,SAAK,OAAO,SAAS,EAAE,IAAa;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,UAAM,UAAU,KAAK,SAAS,IAAI,SAAsB;AACxD,gCAAU,SAAS,yBAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,aAAO,MAAM;AAAA,IACf;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,WAAW;AAAA,EAChE;AAAA,EAEQ,qBAAqB,CAAC,WAAmB,YAA6B;AAC5E,UAAM,UAAU,KAAK,SAAS,IAAI,SAAsB;AACxD,gCAAU,SAAS,yBAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,iBAAO,UAAAA,SAAG,MAAM,SAAS;AAAA,IAC3B;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,eAAO,UAAAA,SAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":["ms"]}
@@ -0,0 +1,46 @@
1
+ import { StringValue } from 'ms';
2
+
3
+ type PriceId = `price_${string}`;
4
+ type ProductId = Lowercase<string>;
5
+ type CreditConfig = {
6
+ credits: number;
7
+ expiresIn: StringValue;
8
+ };
9
+ declare const addMethod: unique symbol;
10
+ declare class Product<P extends ProductId = ProductId, I extends PriceId = never> {
11
+ readonly id: P;
12
+ readonly config: StripeConfig;
13
+ readonly plan: string | null;
14
+ readonly prices: Map<PriceId, CreditConfig>;
15
+ defaultPriceId: I | null;
16
+ private constructor();
17
+ static create: <P_1 extends ProductId>(config: StripeConfig, id: P_1, plan?: string | null) => Product<P_1, never>;
18
+ price: <K extends PriceId>(priceId: K, credit?: CreditConfig) => Product<P, I | K>;
19
+ default: (defaultPriceId: I) => StripeConfig;
20
+ }
21
+ type Options = {
22
+ returnUrl: string;
23
+ cancelUrl: string;
24
+ successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
25
+ allowPromotionCodes: boolean;
26
+ };
27
+ declare class StripeConfig {
28
+ private products;
29
+ returnUrl: string;
30
+ cancelUrl: string;
31
+ successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
32
+ allowPromotionCodes: boolean;
33
+ get productIds(): ProductId[];
34
+ [addMethod]: (product: Product) => this;
35
+ private constructor();
36
+ static create: (options: Options) => StripeConfig;
37
+ product: (id: ProductId, plan?: string | null) => Product<Lowercase<string>, never>;
38
+ getPlan: (productId: string) => string;
39
+ getMode: (productId: string) => "payment" | "subscription";
40
+ getPriceId: (productId: string) => PriceId;
41
+ getCreditAmount: (productId: string, priceId?: string) => number;
42
+ private getCreditExpiresIn;
43
+ getCreditExpiresAt: (productId: string, priceId?: string) => string;
44
+ }
45
+
46
+ export { type CreditConfig, type PriceId, type ProductId, StripeConfig };
@@ -0,0 +1,46 @@
1
+ import { StringValue } from 'ms';
2
+
3
+ type PriceId = `price_${string}`;
4
+ type ProductId = Lowercase<string>;
5
+ type CreditConfig = {
6
+ credits: number;
7
+ expiresIn: StringValue;
8
+ };
9
+ declare const addMethod: unique symbol;
10
+ declare class Product<P extends ProductId = ProductId, I extends PriceId = never> {
11
+ readonly id: P;
12
+ readonly config: StripeConfig;
13
+ readonly plan: string | null;
14
+ readonly prices: Map<PriceId, CreditConfig>;
15
+ defaultPriceId: I | null;
16
+ private constructor();
17
+ static create: <P_1 extends ProductId>(config: StripeConfig, id: P_1, plan?: string | null) => Product<P_1, never>;
18
+ price: <K extends PriceId>(priceId: K, credit?: CreditConfig) => Product<P, I | K>;
19
+ default: (defaultPriceId: I) => StripeConfig;
20
+ }
21
+ type Options = {
22
+ returnUrl: string;
23
+ cancelUrl: string;
24
+ successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
25
+ allowPromotionCodes: boolean;
26
+ };
27
+ declare class StripeConfig {
28
+ private products;
29
+ returnUrl: string;
30
+ cancelUrl: string;
31
+ successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
32
+ allowPromotionCodes: boolean;
33
+ get productIds(): ProductId[];
34
+ [addMethod]: (product: Product) => this;
35
+ private constructor();
36
+ static create: (options: Options) => StripeConfig;
37
+ product: (id: ProductId, plan?: string | null) => Product<Lowercase<string>, never>;
38
+ getPlan: (productId: string) => string;
39
+ getMode: (productId: string) => "payment" | "subscription";
40
+ getPriceId: (productId: string) => PriceId;
41
+ getCreditAmount: (productId: string, priceId?: string) => number;
42
+ private getCreditExpiresIn;
43
+ getCreditExpiresAt: (productId: string, priceId?: string) => string;
44
+ }
45
+
46
+ export { type CreditConfig, type PriceId, type ProductId, StripeConfig };
@@ -0,0 +1,102 @@
1
+ // src/stripe/config.ts
2
+ import { invariant } from "@shware/utils";
3
+ import ms from "ms";
4
+ var addMethod = /* @__PURE__ */ Symbol("addMethod");
5
+ var Product = class _Product {
6
+ id;
7
+ config;
8
+ plan;
9
+ prices;
10
+ defaultPriceId;
11
+ constructor(config, id, plan = null) {
12
+ this.id = id;
13
+ this.config = config;
14
+ this.plan = plan;
15
+ this.prices = /* @__PURE__ */ new Map();
16
+ this.defaultPriceId = null;
17
+ }
18
+ static create = (config, id, plan = null) => {
19
+ return new _Product(config, id, plan);
20
+ };
21
+ price = (priceId, credit = { credits: 0, expiresIn: "0" }) => {
22
+ this.prices.set(priceId, credit);
23
+ return this;
24
+ };
25
+ default = (defaultPriceId) => {
26
+ this.defaultPriceId = defaultPriceId;
27
+ this.config[addMethod](this);
28
+ return this.config;
29
+ };
30
+ };
31
+ var StripeConfig = class _StripeConfig {
32
+ products = /* @__PURE__ */ new Map();
33
+ returnUrl;
34
+ cancelUrl;
35
+ successUrl;
36
+ allowPromotionCodes;
37
+ get productIds() {
38
+ return Array.from(this.products.keys());
39
+ }
40
+ [addMethod] = (product) => {
41
+ this.products.set(product.id, product);
42
+ return this;
43
+ };
44
+ constructor(options) {
45
+ this.returnUrl = options.returnUrl;
46
+ this.cancelUrl = options.cancelUrl;
47
+ this.successUrl = options.successUrl;
48
+ this.allowPromotionCodes = options.allowPromotionCodes;
49
+ }
50
+ static create = (options) => {
51
+ return new _StripeConfig(options);
52
+ };
53
+ product = (id, plan = null) => {
54
+ return Product.create(this, id, plan);
55
+ };
56
+ getPlan = (productId) => {
57
+ const plan = this.products.get(productId)?.plan;
58
+ if (!plan) throw new Error(`Plan not found for product ${productId}`);
59
+ return plan;
60
+ };
61
+ getMode = (productId) => {
62
+ const product = this.products.get(productId);
63
+ invariant(product, `Product not found for ${productId}`);
64
+ return product.plan === null ? "payment" : "subscription";
65
+ };
66
+ getPriceId = (productId) => {
67
+ const product = this.products.get(productId);
68
+ invariant(product, `Product not found for ${productId}`);
69
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
70
+ return product.defaultPriceId;
71
+ };
72
+ getCreditAmount = (productId, priceId) => {
73
+ const product = this.products.get(productId);
74
+ invariant(product, `Product not found for ${productId}`);
75
+ if (priceId) {
76
+ const price = product.prices.get(priceId);
77
+ invariant(price, `Price not found for ${priceId}`);
78
+ return price.credits;
79
+ }
80
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
81
+ return product.prices.get(product.defaultPriceId)?.credits ?? 0;
82
+ };
83
+ getCreditExpiresIn = (productId, priceId) => {
84
+ const product = this.products.get(productId);
85
+ invariant(product, `Product not found for ${productId}`);
86
+ if (priceId) {
87
+ const price = product.prices.get(priceId);
88
+ invariant(price, `Price not found for ${priceId}`);
89
+ return ms(price.expiresIn);
90
+ }
91
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
92
+ return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? "0");
93
+ };
94
+ getCreditExpiresAt = (productId, priceId) => {
95
+ const expiresIn = this.getCreditExpiresIn(productId, priceId);
96
+ return new Date(Date.now() + expiresIn).toISOString();
97
+ };
98
+ };
99
+ export {
100
+ StripeConfig
101
+ };
102
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type ProductId = Lowercase<string>;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<P extends ProductId = ProductId, I extends PriceId = never> {\n readonly id: P;\n readonly config: StripeConfig;\n readonly plan: string | null;\n readonly prices: Map<PriceId, CreditConfig>;\n\n defaultPriceId: I | null;\n\n private constructor(config: StripeConfig, id: P, plan: string | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n static create = <P extends ProductId>(\n config: StripeConfig,\n id: P,\n plan: string | null = null\n ) => {\n return new Product<P>(config, id, plan);\n };\n\n price = <K extends PriceId>(\n priceId: K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<P, I | K> => {\n this.prices.set(priceId, credit);\n return this as Product<P, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig {\n private products: Map<ProductId, Product> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public allowPromotionCodes: boolean;\n\n get productIds(): ProductId[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = (options: Options) => {\n return new StripeConfig(options);\n };\n\n product = (id: ProductId, plan: string | null = null) => {\n return Product.create(this, id, plan);\n };\n\n getPlan = (productId: string): string => {\n const plan = this.products.get(productId as ProductId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,O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AQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,GAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":[]}
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var stripe_exports = {};
22
22
  __export(stripe_exports, {
23
23
  METADATA_KEYS: () => import_metadata.METADATA_KEYS,
24
+ StripeConfig: () => import_config.StripeConfig,
24
25
  StripeEventHandler: () => import_handler.StripeEventHandler,
25
26
  cancellationDetailsSchema: () => import_schema.cancellationDetailsSchema,
26
27
  checkoutSessionSchema: () => import_schema.checkoutSessionSchema,
@@ -41,9 +42,11 @@ var import_mapper = require("./mapper.cjs");
41
42
  var import_handler = require("./handler.cjs");
42
43
  var import_schema = require("./schema.cjs");
43
44
  var import_metadata = require("./metadata.cjs");
45
+ var import_config = require("./config.cjs");
44
46
  // Annotate the CommonJS export names for ESM import in node:
45
47
  0 && (module.exports = {
46
48
  METADATA_KEYS,
49
+ StripeConfig,
47
50
  StripeEventHandler,
48
51
  cancellationDetailsSchema,
49
52
  checkoutSessionSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,qBAAmC;AACnC,oBAIO;AAEP,sBAA8B;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type ProductId, type PriceId } from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,qBAAmC;AACnC,oBAIO;AAEP,sBAA8B;AAC9B,oBAA2D;","names":[]}
@@ -1,9 +1,11 @@
1
1
  export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.cjs';
2
2
  export { StripeEventHandler } from './handler.cjs';
3
3
  export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.cjs';
4
- export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.cjs';
4
+ export { Config, CreateCheckoutSessionDTO } from './types.cjs';
5
5
  export { METADATA_KEYS } from './metadata.cjs';
6
+ export { PriceId, ProductId, StripeConfig } from './config.cjs';
6
7
  import '../subscription/index.cjs';
7
8
  import 'stripe';
8
9
  import 'zod/v4/core';
9
10
  import 'zod/mini';
11
+ import 'ms';
@@ -1,9 +1,11 @@
1
1
  export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.js';
2
2
  export { StripeEventHandler } from './handler.js';
3
3
  export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.js';
4
- export { Config, CreateCheckoutSessionDTO, PriceId, ProductId } from './types.js';
4
+ export { Config, CreateCheckoutSessionDTO } from './types.js';
5
5
  export { METADATA_KEYS } from './metadata.js';
6
+ export { PriceId, ProductId, StripeConfig } from './config.js';
6
7
  import '../subscription/index.js';
7
8
  import 'stripe';
8
9
  import 'zod/v4/core';
9
10
  import 'zod/mini';
11
+ import 'ms';
@@ -18,8 +18,10 @@ import {
18
18
  checkoutSessionSchema
19
19
  } from "./schema.mjs";
20
20
  import { METADATA_KEYS } from "./metadata.mjs";
21
+ import { StripeConfig } from "./config.mjs";
21
22
  export {
22
23
  METADATA_KEYS,
24
+ StripeConfig,
23
25
  StripeEventHandler,
24
26
  cancellationDetailsSchema,
25
27
  checkoutSessionSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { ProductId, PriceId, Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type ProductId, type PriceId } from './config';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,oBAAkD;","names":[]}
@@ -26,7 +26,9 @@ module.exports = __toCommonJS(metadata_exports);
26
26
  var METADATA_KEYS = {
27
27
  USER_ID: "user_id",
28
28
  USER_ACCOUNT_TOKEN: "user_account_token",
29
- PRODUCT_ID: "product_id"
29
+ PRODUCT_ID: "product_id",
30
+ CREDIT_AMOUNT: "credit_amount",
31
+ CREDIT_EXPIRES_IN: "credit_expires_in"
30
32
  };
31
33
  // Annotate the CommonJS export names for ESM import in node:
32
34
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/metadata.ts"],"sourcesContent":["export const METADATA_KEYS = {\n USER_ID: 'user_id',\n USER_ACCOUNT_TOKEN: 'user_account_token',\n PRODUCT_ID: 'product_id',\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,oBAAoB;AAAA,EACpB,YAAY;AACd;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/metadata.ts"],"sourcesContent":["export const METADATA_KEYS = {\n USER_ID: 'user_id',\n USER_ACCOUNT_TOKEN: 'user_account_token',\n PRODUCT_ID: 'product_id',\n CREDIT_AMOUNT: 'credit_amount',\n CREDIT_EXPIRES_IN: 'credit_expires_in',\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,mBAAmB;AACrB;","names":[]}
@@ -2,6 +2,8 @@ declare const METADATA_KEYS: {
2
2
  readonly USER_ID: "user_id";
3
3
  readonly USER_ACCOUNT_TOKEN: "user_account_token";
4
4
  readonly PRODUCT_ID: "product_id";
5
+ readonly CREDIT_AMOUNT: "credit_amount";
6
+ readonly CREDIT_EXPIRES_IN: "credit_expires_in";
5
7
  };
6
8
 
7
9
  export { METADATA_KEYS };
@@ -2,6 +2,8 @@ declare const METADATA_KEYS: {
2
2
  readonly USER_ID: "user_id";
3
3
  readonly USER_ACCOUNT_TOKEN: "user_account_token";
4
4
  readonly PRODUCT_ID: "product_id";
5
+ readonly CREDIT_AMOUNT: "credit_amount";
6
+ readonly CREDIT_EXPIRES_IN: "credit_expires_in";
5
7
  };
6
8
 
7
9
  export { METADATA_KEYS };
@@ -2,7 +2,9 @@
2
2
  var METADATA_KEYS = {
3
3
  USER_ID: "user_id",
4
4
  USER_ACCOUNT_TOKEN: "user_account_token",
5
- PRODUCT_ID: "product_id"
5
+ PRODUCT_ID: "product_id",
6
+ CREDIT_AMOUNT: "credit_amount",
7
+ CREDIT_EXPIRES_IN: "credit_expires_in"
6
8
  };
7
9
  export {
8
10
  METADATA_KEYS
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/metadata.ts"],"sourcesContent":["export const METADATA_KEYS = {\n USER_ID: 'user_id',\n USER_ACCOUNT_TOKEN: 'user_account_token',\n PRODUCT_ID: 'product_id',\n} as const;\n"],"mappings":";AAAO,IAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,oBAAoB;AAAA,EACpB,YAAY;AACd;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/metadata.ts"],"sourcesContent":["export const METADATA_KEYS = {\n USER_ID: 'user_id',\n USER_ACCOUNT_TOKEN: 'user_account_token',\n PRODUCT_ID: 'product_id',\n CREDIT_AMOUNT: 'credit_amount',\n CREDIT_EXPIRES_IN: 'credit_expires_in',\n} as const;\n"],"mappings":";AAAO,IAAM,gBAAgB;AAAA,EAC3B,SAAS;AAAA,EACT,oBAAoB;AAAA,EACpB,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,mBAAmB;AACrB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/types.ts"],"sourcesContent":["export type ProductId = Lowercase<string>;\nexport type PriceId = `price_${string}`;\n\nexport interface Config {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n payments: Record<ProductId, PriceId>;\n subscriptions: Record<ProductId, PriceId>;\n}\n\nexport interface CreateCheckoutSessionDTO {\n productId: string;\n cancelUrl?: string;\n successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/types.ts"],"sourcesContent":["export type ProductId = Lowercase<string>;\nexport type PriceId = `price_${string}`;\n\n/** @deprecated Use StripeConfig instead */\nexport interface Config {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n payments: Record<ProductId, PriceId>;\n subscriptions: Record<ProductId, PriceId>;\n}\n\nexport interface CreateCheckoutSessionDTO {\n productId: string;\n cancelUrl?: string;\n successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,5 +1,6 @@
1
1
  type ProductId = Lowercase<string>;
2
2
  type PriceId = `price_${string}`;
3
+ /** @deprecated Use StripeConfig instead */
3
4
  interface Config {
4
5
  returnUrl: string;
5
6
  cancelUrl: string;
@@ -1,5 +1,6 @@
1
1
  type ProductId = Lowercase<string>;
2
2
  type PriceId = `price_${string}`;
3
+ /** @deprecated Use StripeConfig instead */
3
4
  interface Config {
4
5
  returnUrl: string;
5
6
  cancelUrl: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/purchase",
3
- "version": "0.2.8",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -38,16 +38,17 @@
38
38
  "dist"
39
39
  ],
40
40
  "devDependencies": {
41
- "@types/jest": "^30.0.0",
41
+ "@types/ms": "^2.1.0",
42
42
  "@types/node": "^24.10.2",
43
- "jest": "^30.2.0",
44
- "ts-jest": "^29.4.6",
45
43
  "typescript": "^5.9.3",
44
+ "vitest": "^4.0.16",
46
45
  "@repo/eslint-config": "0.0.11",
47
46
  "@repo/typescript-config": "0.0.0"
48
47
  },
49
48
  "dependencies": {
50
- "zod": "^4.2.1"
49
+ "ms": "^2.1.3",
50
+ "zod": "^4.2.1",
51
+ "@shware/utils": "^1.1.2"
51
52
  },
52
53
  "peerDependencies": {
53
54
  "stripe": "^20"
@@ -60,7 +61,7 @@
60
61
  "scripts": {
61
62
  "dev": "tsc --watch",
62
63
  "build": "tsup",
63
- "test": "jest",
64
+ "test": "vitest",
64
65
  "check-types": "tsc --noEmit",
65
66
  "lint": "npx eslint . --fix --ext .js,.jsx,.ts,.tsx"
66
67
  }