@shware/purchase 1.8.9 → 2.0.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/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/app-store/config.cjs +105 -128
- package/dist/app-store/config.cjs.map +1 -1
- package/dist/app-store/config.d.cts +36 -33
- package/dist/app-store/config.d.cts.map +1 -0
- package/dist/app-store/config.d.mts +42 -0
- package/dist/app-store/config.d.mts.map +1 -0
- package/dist/app-store/config.mjs +100 -91
- package/dist/app-store/config.mjs.map +1 -1
- package/dist/app-store/index.cjs +3 -31
- package/dist/app-store/index.d.cts +2 -3
- package/dist/app-store/index.d.mts +2 -0
- package/dist/app-store/index.mjs +1 -5
- package/dist/google-play/config.cjs +108 -123
- package/dist/google-play/config.cjs.map +1 -1
- package/dist/google-play/config.d.cts +35 -33
- package/dist/google-play/config.d.cts.map +1 -0
- package/dist/google-play/config.d.mts +41 -0
- package/dist/google-play/config.d.mts.map +1 -0
- package/dist/google-play/config.mjs +103 -86
- package/dist/google-play/config.mjs.map +1 -1
- package/dist/google-play/index.cjs +9 -42
- package/dist/google-play/index.d.cts +3 -4
- package/dist/google-play/index.d.mts +3 -0
- package/dist/google-play/index.mjs +2 -17
- package/dist/google-play/real-time-developer-notification.cjs +122 -81
- package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
- package/dist/google-play/real-time-developer-notification.d.cts +119 -117
- package/dist/google-play/real-time-developer-notification.d.cts.map +1 -0
- package/dist/google-play/real-time-developer-notification.d.mts +150 -0
- package/dist/google-play/real-time-developer-notification.d.mts.map +1 -0
- package/dist/google-play/real-time-developer-notification.mjs +118 -53
- package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
- package/dist/index.cjs +13 -48
- package/dist/index.d.cts +5 -6
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +2 -19
- package/dist/stripe/config.cjs +114 -133
- package/dist/stripe/config.cjs.map +1 -1
- package/dist/stripe/config.d.cts +46 -37
- package/dist/stripe/config.d.cts.map +1 -0
- package/dist/stripe/config.d.mts +52 -0
- package/dist/stripe/config.d.mts.map +1 -0
- package/dist/stripe/config.mjs +109 -96
- package/dist/stripe/config.mjs.map +1 -1
- package/dist/stripe/handler.cjs +25 -53
- package/dist/stripe/handler.cjs.map +1 -1
- package/dist/stripe/handler.d.cts +10 -9
- package/dist/stripe/handler.d.cts.map +1 -0
- package/dist/stripe/handler.d.mts +16 -0
- package/dist/stripe/handler.d.mts.map +1 -0
- package/dist/stripe/handler.mjs +25 -29
- package/dist/stripe/handler.mjs.map +1 -1
- package/dist/stripe/index.cjs +27 -74
- package/dist/stripe/index.d.cts +8 -12
- package/dist/stripe/index.d.mts +8 -0
- package/dist/stripe/index.mjs +5 -44
- package/dist/stripe/mapper.cjs +168 -219
- package/dist/stripe/mapper.cjs.map +1 -1
- package/dist/stripe/mapper.d.cts +115 -114
- package/dist/stripe/mapper.d.cts.map +1 -0
- package/dist/stripe/mapper.d.mts +158 -0
- package/dist/stripe/mapper.d.mts.map +1 -0
- package/dist/stripe/mapper.mjs +155 -182
- package/dist/stripe/mapper.mjs.map +1 -1
- package/dist/stripe/metadata.cjs +11 -35
- package/dist/stripe/metadata.cjs.map +1 -1
- package/dist/stripe/metadata.d.cts +9 -7
- package/dist/stripe/metadata.d.cts.map +1 -0
- package/dist/stripe/metadata.d.mts +12 -0
- package/dist/stripe/metadata.d.mts.map +1 -0
- package/dist/stripe/metadata.mjs +11 -11
- package/dist/stripe/metadata.mjs.map +1 -1
- package/dist/stripe/pending-checkout.cjs +55 -61
- package/dist/stripe/pending-checkout.cjs.map +1 -1
- package/dist/stripe/pending-checkout.d.cts +3 -1
- package/dist/stripe/pending-checkout.d.cts.map +1 -0
- package/dist/stripe/{pending-checkout.d.ts → pending-checkout.d.mts} +3 -1
- package/dist/stripe/pending-checkout.d.mts.map +1 -0
- package/dist/stripe/pending-checkout.mjs +52 -34
- package/dist/stripe/pending-checkout.mjs.map +1 -1
- package/dist/stripe/schema.cjs +30 -55
- package/dist/stripe/schema.cjs.map +1 -1
- package/dist/stripe/schema.d.cts +36 -37
- package/dist/stripe/schema.d.cts.map +1 -0
- package/dist/stripe/schema.d.mts +40 -0
- package/dist/stripe/schema.d.mts.map +1 -0
- package/dist/stripe/schema.mjs +28 -40
- package/dist/stripe/schema.mjs.map +1 -1
- package/dist/subscription/index.cjs +178 -80
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.d.cts +136 -134
- package/dist/subscription/index.d.cts.map +1 -0
- package/dist/subscription/index.d.mts +150 -0
- package/dist/subscription/index.d.mts.map +1 -0
- package/dist/subscription/index.mjs +173 -51
- package/dist/subscription/index.mjs.map +1 -1
- package/dist/types.cjs +0 -19
- package/dist/types.d.cts +7 -6
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +10 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -1
- package/package.json +40 -25
- package/dist/app-store/config.d.ts +0 -39
- package/dist/app-store/index.cjs.map +0 -1
- package/dist/app-store/index.d.ts +0 -3
- package/dist/app-store/index.mjs.map +0 -1
- package/dist/google-play/config.d.ts +0 -39
- package/dist/google-play/index.cjs.map +0 -1
- package/dist/google-play/index.d.ts +0 -4
- package/dist/google-play/index.mjs.map +0 -1
- package/dist/google-play/real-time-developer-notification.d.ts +0 -148
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/stripe/config.d.ts +0 -43
- package/dist/stripe/handler.d.ts +0 -15
- package/dist/stripe/index.cjs.map +0 -1
- package/dist/stripe/index.d.ts +0 -12
- package/dist/stripe/index.mjs.map +0 -1
- package/dist/stripe/mapper.d.ts +0 -157
- package/dist/stripe/metadata.d.ts +0 -10
- package/dist/stripe/schema.d.ts +0 -41
- package/dist/subscription/index.d.ts +0 -148
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.mjs.map +0 -1
package/dist/stripe/config.cjs
CHANGED
|
@@ -1,137 +1,118 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let _shware_utils = require("@shware/utils");
|
|
4
|
+
let ms = require("ms");
|
|
5
|
+
ms = require_runtime.__toESM(ms, 1);
|
|
6
|
+
//#region src/stripe/config.ts
|
|
7
|
+
const addMethod = Symbol("addMethod");
|
|
39
8
|
var Product = class {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
9
|
+
id;
|
|
10
|
+
config;
|
|
11
|
+
plan;
|
|
12
|
+
billingPeriod;
|
|
13
|
+
prices;
|
|
14
|
+
defaultPriceId;
|
|
15
|
+
constructor(config, id, plan = null, billingPeriod = null) {
|
|
16
|
+
this.id = id;
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.plan = plan;
|
|
19
|
+
this.billingPeriod = billingPeriod;
|
|
20
|
+
this.prices = /* @__PURE__ */ new Map();
|
|
21
|
+
this.defaultPriceId = null;
|
|
22
|
+
}
|
|
23
|
+
price = (priceId, metadata = {
|
|
24
|
+
credits: 0,
|
|
25
|
+
expiresIn: "0"
|
|
26
|
+
}) => {
|
|
27
|
+
this.prices.set(priceId, metadata);
|
|
28
|
+
return this;
|
|
29
|
+
};
|
|
30
|
+
default = (defaultPriceId) => {
|
|
31
|
+
this.defaultPriceId = defaultPriceId;
|
|
32
|
+
this.config[addMethod](this);
|
|
33
|
+
return this.config;
|
|
34
|
+
};
|
|
61
35
|
};
|
|
62
|
-
var StripeConfig = class
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
36
|
+
var StripeConfig = class StripeConfig {
|
|
37
|
+
products = /* @__PURE__ */ new Map();
|
|
38
|
+
returnUrl;
|
|
39
|
+
cancelUrl;
|
|
40
|
+
successUrl;
|
|
41
|
+
cancellationCouponId;
|
|
42
|
+
allowPromotionCodes;
|
|
43
|
+
get productIds() {
|
|
44
|
+
return Array.from(this.products.keys());
|
|
45
|
+
}
|
|
46
|
+
[addMethod] = (product) => {
|
|
47
|
+
this.products.set(product.id, product);
|
|
48
|
+
return this;
|
|
49
|
+
};
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.returnUrl = options.returnUrl;
|
|
52
|
+
this.cancelUrl = options.cancelUrl;
|
|
53
|
+
this.successUrl = options.successUrl;
|
|
54
|
+
this.cancellationCouponId = options.cancellationCouponId;
|
|
55
|
+
this.allowPromotionCodes = options.allowPromotionCodes;
|
|
56
|
+
}
|
|
57
|
+
static create = (options) => {
|
|
58
|
+
return new StripeConfig(options);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* One-time products take no extra args; subscriptions require both plan and billingPeriod.
|
|
62
|
+
* A plan+period pair may be declared on only one product — version its prices in that chain.
|
|
63
|
+
*/
|
|
64
|
+
product = (productId, plan = null, billingPeriod = null) => new Product(this, productId, plan, billingPeriod);
|
|
65
|
+
getPlan = (productId) => {
|
|
66
|
+
const product = this.products.get(productId);
|
|
67
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
68
|
+
(0, _shware_utils.invariant)(product.plan, `Product ${productId} is not a subscription`);
|
|
69
|
+
return product.plan;
|
|
70
|
+
};
|
|
71
|
+
getBillingPeriod = (productId) => {
|
|
72
|
+
const product = this.products.get(productId);
|
|
73
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
74
|
+
(0, _shware_utils.invariant)(product.billingPeriod, `Product ${productId} is not a subscription`);
|
|
75
|
+
return product.billingPeriod;
|
|
76
|
+
};
|
|
77
|
+
getMode = (productId) => {
|
|
78
|
+
const product = this.products.get(productId);
|
|
79
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
80
|
+
return product.plan === null ? "payment" : "subscription";
|
|
81
|
+
};
|
|
82
|
+
getPriceId = (productId) => {
|
|
83
|
+
const product = this.products.get(productId);
|
|
84
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
85
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
86
|
+
return product.defaultPriceId;
|
|
87
|
+
};
|
|
88
|
+
getCreditAmount = (productId, priceId) => {
|
|
89
|
+
const product = this.products.get(productId);
|
|
90
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
91
|
+
if (priceId) {
|
|
92
|
+
const price = product.prices.get(priceId);
|
|
93
|
+
(0, _shware_utils.invariant)(price, `Price not found for ${priceId}`);
|
|
94
|
+
return price.credits;
|
|
95
|
+
}
|
|
96
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
97
|
+
return product.prices.get(product.defaultPriceId)?.credits ?? 0;
|
|
98
|
+
};
|
|
99
|
+
getCreditExpiresIn = (productId, priceId) => {
|
|
100
|
+
const product = this.products.get(productId);
|
|
101
|
+
(0, _shware_utils.invariant)(product, `Product not found for ${productId}`);
|
|
102
|
+
if (priceId) {
|
|
103
|
+
const price = product.prices.get(priceId);
|
|
104
|
+
(0, _shware_utils.invariant)(price, `Price not found for ${priceId}`);
|
|
105
|
+
return (0, ms.default)(price.expiresIn);
|
|
106
|
+
}
|
|
107
|
+
(0, _shware_utils.invariant)(product.defaultPriceId, `Default price not found for product ${productId}`);
|
|
108
|
+
return (0, ms.default)(product.prices.get(product.defaultPriceId)?.expiresIn ?? "0");
|
|
109
|
+
};
|
|
110
|
+
getCreditExpiresAt = (productId, priceId) => {
|
|
111
|
+
const expiresIn = this.getCreditExpiresIn(productId, priceId);
|
|
112
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
113
|
+
};
|
|
132
114
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
115
|
+
//#endregion
|
|
116
|
+
exports.StripeConfig = StripeConfig;
|
|
117
|
+
|
|
137
118
|
//# sourceMappingURL=config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\n\nexport type PriceId = `price_${string}`;\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n I extends PriceId = never,\n> {\n readonly id: string;\n readonly config: StripeConfig<NS, PE, PI>;\n readonly plan: PE | null;\n readonly prices: Map<PriceId, Metadata>;\n\n defaultPriceId: I | null;\n\n constructor(config: StripeConfig<NS, PE, PI
|
|
1
|
+
{"version":3,"file":"config.cjs","names":[],"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\n\nexport type PriceId = `price_${string}`;\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n BP extends string = string,\n PL extends string = never,\n PI extends string = never,\n I extends PriceId = never,\n> {\n readonly id: string;\n readonly config: StripeConfig<NS, PE, BP, PL, PI>;\n readonly plan: PE | null;\n readonly billingPeriod: BP | null;\n readonly prices: Map<PriceId, Metadata>;\n\n defaultPriceId: I | null;\n\n constructor(\n config: StripeConfig<NS, PE, BP, PL, PI>,\n id: string,\n plan: PE | null = null,\n billingPeriod: BP | null = null\n ) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.billingPeriod = billingPeriod;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n price = <K extends PriceId>(\n priceId: K extends I ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, BP, PL, PI, I | K> => {\n this.prices.set(priceId, metadata);\n return this as Product<NS, PE, BP, PL, PI, 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 cancellationCouponId: string;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n BP extends string = string,\n PL extends string = never,\n PI extends string = never,\n> {\n private products: Map<string, Product<NS, PE, BP, PL, PI>> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public cancellationCouponId: string;\n public allowPromotionCodes: boolean;\n\n get productIds(): string[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product<NS, PE, BP, PL, PI>) => {\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.cancellationCouponId = options.cancellationCouponId;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = <NS extends Lowercase<string>, PE extends string, BP extends string = string>(\n options: Options\n ) => {\n return new StripeConfig<NS, PE, BP>(options);\n };\n\n /**\n * One-time products take no extra args; subscriptions require both plan and billingPeriod.\n * A plan+period pair may be declared on only one product — version its prices in that chain.\n */\n product: {\n <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K\n ): Product<NS, PE, BP, PL, K | PI>;\n <K extends `${NS}.${Lowercase<string>}`, L extends PE, P extends BP>(\n productId: K extends PI ? never : K,\n plan: L,\n billingPeriod: `${L}:${P}` extends PL ? never : P\n ): Product<NS, PE, BP, `${L}:${P}` | PL, K | PI>;\n } = (productId: string, plan: PE | null = null, billingPeriod: BP | null = null) =>\n // oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- widens to the overloads' accumulated generics\n new Product(this, productId, plan, billingPeriod) as never;\n\n getPlan = (productId: string): PE => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.plan, `Product ${productId} is not a subscription`);\n return product.plan;\n };\n\n getBillingPeriod = (productId: string): BP => {\n const product = this.products.get(productId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.billingPeriod, `Product ${productId} is not a subscription`);\n return product.billingPeriod;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(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);\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);\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);\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":";;;;;;AAMA,MAAM,YAAY,OAAO,WAAW;AAEpC,IAAM,UAAN,MAOE;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA,YACE,QACA,IACA,OAAkB,MAClB,gBAA2B,MAC3B;EACA,KAAK,KAAK;EACV,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,gBAAgB;EACrB,KAAK,yBAAS,IAAI,IAAI;EACtB,KAAK,iBAAiB;CACxB;CAEA,SACE,SACA,WAAqB;EAAE,SAAS;EAAG,WAAW;CAAI,MACX;EACvC,KAAK,OAAO,IAAI,SAAS,QAAQ;EACjC,OAAO;CACT;CAEA,WAAW,mBAAsB;EAC/B,KAAK,iBAAiB;EACtB,KAAK,OAAO,UAAU,CAAC,IAAa;EACpC,OAAO,KAAK;CACd;AACF;AAUA,IAAa,eAAb,MAAa,aAMX;CACA,2BAA6D,IAAI,IAAI;CAErE;CACA;CACA;CACA;CACA;CAEA,IAAI,aAAuB;EACzB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price_${string}`;
|
|
5
4
|
declare const addMethod: unique symbol;
|
|
6
|
-
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PL extends string = never, PI extends string = never, I extends PriceId = never> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly config: StripeConfig<NS, PE, BP, PL, PI>;
|
|
8
|
+
readonly plan: PE | null;
|
|
9
|
+
readonly billingPeriod: BP | null;
|
|
10
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
11
|
+
defaultPriceId: I | null;
|
|
12
|
+
constructor(config: StripeConfig<NS, PE, BP, PL, PI>, id: string, plan?: PE | null, billingPeriod?: BP | null);
|
|
13
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, BP, PL, PI, I | K>;
|
|
14
|
+
default: (defaultPriceId: I) => StripeConfig<NS, PE, BP, PL, PI>;
|
|
15
15
|
}
|
|
16
16
|
type Options = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
returnUrl: string;
|
|
18
|
+
cancelUrl: string;
|
|
19
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
20
|
+
cancellationCouponId: string;
|
|
21
|
+
allowPromotionCodes: boolean;
|
|
22
22
|
};
|
|
23
|
-
declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PL extends string = never, PI extends string = never> {
|
|
24
|
+
private products;
|
|
25
|
+
returnUrl: string;
|
|
26
|
+
cancelUrl: string;
|
|
27
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
28
|
+
cancellationCouponId: string;
|
|
29
|
+
allowPromotionCodes: boolean;
|
|
30
|
+
get productIds(): string[];
|
|
31
|
+
[addMethod]: (product: Product<NS, PE, BP, PL, PI>) => this;
|
|
32
|
+
private constructor();
|
|
33
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string, BP_1 extends string = string>(options: Options) => StripeConfig<NS_1, PE_1, BP_1, never, never>;
|
|
34
|
+
/**
|
|
35
|
+
* One-time products take no extra args; subscriptions require both plan and billingPeriod.
|
|
36
|
+
* A plan+period pair may be declared on only one product — version its prices in that chain.
|
|
37
|
+
*/
|
|
38
|
+
product: {
|
|
39
|
+
<K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K): Product<NS, PE, BP, PL, K | PI>;
|
|
40
|
+
<K extends `${NS}.${Lowercase<string>}`, L extends PE, P extends BP>(productId: K extends PI ? never : K, plan: L, billingPeriod: `${L}:${P}` extends PL ? never : P): Product<NS, PE, BP, `${L}:${P}` | PL, K | PI>;
|
|
41
|
+
};
|
|
42
|
+
getPlan: (productId: string) => PE;
|
|
43
|
+
getBillingPeriod: (productId: string) => BP;
|
|
44
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
45
|
+
getPriceId: (productId: string) => PriceId;
|
|
46
|
+
getCreditAmount: (productId: string, priceId?: string) => number;
|
|
47
|
+
private getCreditExpiresIn;
|
|
48
|
+
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
export {
|
|
50
|
+
//#endregion
|
|
51
|
+
export { PriceId, StripeConfig };
|
|
52
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../../src/stripe/config.ts"],"mappings":";;KAIY;cAEN;cAEA,QACJ,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA,2BACA,UAAU;WAED;WACA,QAAQ,aAAa,IAAI,IAAI,IAAI,IAAI;WACrC,MAAM;WACN,eAAe;WACf,QAAQ,IAAI,SAAS;EAE9B,gBAAgB;EAEhB,YACE,QAAQ,aAAa,IAAI,IAAI,IAAI,IAAI,KACrC,YACA,OAAM,WACN,gBAAe;EAUjB,QAAS,UAAU,SAAO,SACf,UAAU,YAAY,GAAC,WACtB,aACT,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;EAKnC,UAAO,gBAAoB,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;;KAOzB;EACH;EACA;EACA;EACA;EACA;;cAGW,aACX,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA;UAEQ;EAED;EACA;EACA;EACA;EACA;MAEH;GAIH,aAAU,SAAa,QAAQ,IAAI,IAAI,IAAI,IAAI;UAKzC;SAQA,SAAU,aAAW,mBAAmB,qBAAmB,8BAA0B,SACjF,YAAO,aAAA,MAAA,MAAA;;;;;EASlB;KACG,aAAa,MAAM,qBAClB,WAAW,UAAU,aAAa,IACjC,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI;KAC9B,aAAa,MAAM,qBAAqB,UAAU,IAAI,UAAU,IAC/D,WAAW,UAAU,aAAa,GAClC,MAAM,GACN,kBAAkB,KAAK,YAAY,aAAa,IAC/C,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,IAAI;;EAK/C,UAAO,sBAAwB;EAO/B,mBAAgB,sBAAwB;EAOxC,UAAO;EAMP,aAAU,sBAAwB;EAOlC,kBAAe,mBAAqB;UAa5B;EAaR,qBAAkB,mBAAqB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Metadata } from "../types.mjs";
|
|
2
|
+
//#region src/stripe/config.d.ts
|
|
3
|
+
type PriceId = `price_${string}`;
|
|
4
|
+
declare const addMethod: unique symbol;
|
|
5
|
+
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PL extends string = never, PI extends string = never, I extends PriceId = never> {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly config: StripeConfig<NS, PE, BP, PL, PI>;
|
|
8
|
+
readonly plan: PE | null;
|
|
9
|
+
readonly billingPeriod: BP | null;
|
|
10
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
11
|
+
defaultPriceId: I | null;
|
|
12
|
+
constructor(config: StripeConfig<NS, PE, BP, PL, PI>, id: string, plan?: PE | null, billingPeriod?: BP | null);
|
|
13
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, BP, PL, PI, I | K>;
|
|
14
|
+
default: (defaultPriceId: I) => StripeConfig<NS, PE, BP, PL, PI>;
|
|
15
|
+
}
|
|
16
|
+
type Options = {
|
|
17
|
+
returnUrl: string;
|
|
18
|
+
cancelUrl: string;
|
|
19
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
20
|
+
cancellationCouponId: string;
|
|
21
|
+
allowPromotionCodes: boolean;
|
|
22
|
+
};
|
|
23
|
+
declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PL extends string = never, PI extends string = never> {
|
|
24
|
+
private products;
|
|
25
|
+
returnUrl: string;
|
|
26
|
+
cancelUrl: string;
|
|
27
|
+
successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
|
|
28
|
+
cancellationCouponId: string;
|
|
29
|
+
allowPromotionCodes: boolean;
|
|
30
|
+
get productIds(): string[];
|
|
31
|
+
[addMethod]: (product: Product<NS, PE, BP, PL, PI>) => this;
|
|
32
|
+
private constructor();
|
|
33
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string, BP_1 extends string = string>(options: Options) => StripeConfig<NS_1, PE_1, BP_1, never, never>;
|
|
34
|
+
/**
|
|
35
|
+
* One-time products take no extra args; subscriptions require both plan and billingPeriod.
|
|
36
|
+
* A plan+period pair may be declared on only one product — version its prices in that chain.
|
|
37
|
+
*/
|
|
38
|
+
product: {
|
|
39
|
+
<K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K): Product<NS, PE, BP, PL, K | PI>;
|
|
40
|
+
<K extends `${NS}.${Lowercase<string>}`, L extends PE, P extends BP>(productId: K extends PI ? never : K, plan: L, billingPeriod: `${L}:${P}` extends PL ? never : P): Product<NS, PE, BP, `${L}:${P}` | PL, K | PI>;
|
|
41
|
+
};
|
|
42
|
+
getPlan: (productId: string) => PE;
|
|
43
|
+
getBillingPeriod: (productId: string) => BP;
|
|
44
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
45
|
+
getPriceId: (productId: string) => PriceId;
|
|
46
|
+
getCreditAmount: (productId: string, priceId?: string) => number;
|
|
47
|
+
private getCreditExpiresIn;
|
|
48
|
+
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { PriceId, StripeConfig };
|
|
52
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../../src/stripe/config.ts"],"mappings":";;KAIY;cAEN;cAEA,QACJ,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA,2BACA,UAAU;WAED;WACA,QAAQ,aAAa,IAAI,IAAI,IAAI,IAAI;WACrC,MAAM;WACN,eAAe;WACf,QAAQ,IAAI,SAAS;EAE9B,gBAAgB;EAEhB,YACE,QAAQ,aAAa,IAAI,IAAI,IAAI,IAAI,KACrC,YACA,OAAM,WACN,gBAAe;EAUjB,QAAS,UAAU,SAAO,SACf,UAAU,YAAY,GAAC,WACtB,aACT,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI;EAKnC,UAAO,gBAAoB,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;;KAOzB;EACH;EACA;EACA;EACA;EACA;;cAGW,aACX,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA;UAEQ;EAED;EACA;EACA;EACA;EACA;MAEH;GAIH,aAAU,SAAa,QAAQ,IAAI,IAAI,IAAI,IAAI;UAKzC;SAQA,SAAU,aAAW,mBAAmB,qBAAmB,8BAA0B,SACjF,YAAO,aAAA,MAAA,MAAA;;;;;EASlB;KACG,aAAa,MAAM,qBAClB,WAAW,UAAU,aAAa,IACjC,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI;KAC9B,aAAa,MAAM,qBAAqB,UAAU,IAAI,UAAU,IAC/D,WAAW,UAAU,aAAa,GAClC,MAAM,GACN,kBAAkB,KAAK,YAAY,aAAa,IAC/C,QAAQ,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,IAAI;;EAK/C,UAAO,sBAAwB;EAO/B,mBAAgB,sBAAwB;EAOxC,UAAO;EAMP,aAAU,sBAAwB;EAOlC,kBAAe,mBAAqB;UAa5B;EAaR,qBAAkB,mBAAqB"}
|