@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.
Files changed (128) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/app-store/config.cjs +105 -128
  3. package/dist/app-store/config.cjs.map +1 -1
  4. package/dist/app-store/config.d.cts +36 -33
  5. package/dist/app-store/config.d.cts.map +1 -0
  6. package/dist/app-store/config.d.mts +42 -0
  7. package/dist/app-store/config.d.mts.map +1 -0
  8. package/dist/app-store/config.mjs +100 -91
  9. package/dist/app-store/config.mjs.map +1 -1
  10. package/dist/app-store/index.cjs +3 -31
  11. package/dist/app-store/index.d.cts +2 -3
  12. package/dist/app-store/index.d.mts +2 -0
  13. package/dist/app-store/index.mjs +1 -5
  14. package/dist/google-play/config.cjs +108 -123
  15. package/dist/google-play/config.cjs.map +1 -1
  16. package/dist/google-play/config.d.cts +35 -33
  17. package/dist/google-play/config.d.cts.map +1 -0
  18. package/dist/google-play/config.d.mts +41 -0
  19. package/dist/google-play/config.d.mts.map +1 -0
  20. package/dist/google-play/config.mjs +103 -86
  21. package/dist/google-play/config.mjs.map +1 -1
  22. package/dist/google-play/index.cjs +9 -42
  23. package/dist/google-play/index.d.cts +3 -4
  24. package/dist/google-play/index.d.mts +3 -0
  25. package/dist/google-play/index.mjs +2 -17
  26. package/dist/google-play/real-time-developer-notification.cjs +122 -81
  27. package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
  28. package/dist/google-play/real-time-developer-notification.d.cts +119 -117
  29. package/dist/google-play/real-time-developer-notification.d.cts.map +1 -0
  30. package/dist/google-play/real-time-developer-notification.d.mts +150 -0
  31. package/dist/google-play/real-time-developer-notification.d.mts.map +1 -0
  32. package/dist/google-play/real-time-developer-notification.mjs +118 -53
  33. package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
  34. package/dist/index.cjs +13 -48
  35. package/dist/index.d.cts +5 -6
  36. package/dist/index.d.mts +5 -0
  37. package/dist/index.mjs +2 -19
  38. package/dist/stripe/config.cjs +114 -133
  39. package/dist/stripe/config.cjs.map +1 -1
  40. package/dist/stripe/config.d.cts +46 -37
  41. package/dist/stripe/config.d.cts.map +1 -0
  42. package/dist/stripe/config.d.mts +52 -0
  43. package/dist/stripe/config.d.mts.map +1 -0
  44. package/dist/stripe/config.mjs +109 -96
  45. package/dist/stripe/config.mjs.map +1 -1
  46. package/dist/stripe/handler.cjs +25 -53
  47. package/dist/stripe/handler.cjs.map +1 -1
  48. package/dist/stripe/handler.d.cts +10 -9
  49. package/dist/stripe/handler.d.cts.map +1 -0
  50. package/dist/stripe/handler.d.mts +16 -0
  51. package/dist/stripe/handler.d.mts.map +1 -0
  52. package/dist/stripe/handler.mjs +25 -29
  53. package/dist/stripe/handler.mjs.map +1 -1
  54. package/dist/stripe/index.cjs +27 -74
  55. package/dist/stripe/index.d.cts +8 -12
  56. package/dist/stripe/index.d.mts +8 -0
  57. package/dist/stripe/index.mjs +5 -44
  58. package/dist/stripe/mapper.cjs +168 -219
  59. package/dist/stripe/mapper.cjs.map +1 -1
  60. package/dist/stripe/mapper.d.cts +115 -114
  61. package/dist/stripe/mapper.d.cts.map +1 -0
  62. package/dist/stripe/mapper.d.mts +158 -0
  63. package/dist/stripe/mapper.d.mts.map +1 -0
  64. package/dist/stripe/mapper.mjs +155 -182
  65. package/dist/stripe/mapper.mjs.map +1 -1
  66. package/dist/stripe/metadata.cjs +11 -35
  67. package/dist/stripe/metadata.cjs.map +1 -1
  68. package/dist/stripe/metadata.d.cts +9 -7
  69. package/dist/stripe/metadata.d.cts.map +1 -0
  70. package/dist/stripe/metadata.d.mts +12 -0
  71. package/dist/stripe/metadata.d.mts.map +1 -0
  72. package/dist/stripe/metadata.mjs +11 -11
  73. package/dist/stripe/metadata.mjs.map +1 -1
  74. package/dist/stripe/pending-checkout.cjs +55 -61
  75. package/dist/stripe/pending-checkout.cjs.map +1 -1
  76. package/dist/stripe/pending-checkout.d.cts +3 -1
  77. package/dist/stripe/pending-checkout.d.cts.map +1 -0
  78. package/dist/stripe/{pending-checkout.d.ts → pending-checkout.d.mts} +3 -1
  79. package/dist/stripe/pending-checkout.d.mts.map +1 -0
  80. package/dist/stripe/pending-checkout.mjs +52 -34
  81. package/dist/stripe/pending-checkout.mjs.map +1 -1
  82. package/dist/stripe/schema.cjs +30 -55
  83. package/dist/stripe/schema.cjs.map +1 -1
  84. package/dist/stripe/schema.d.cts +36 -37
  85. package/dist/stripe/schema.d.cts.map +1 -0
  86. package/dist/stripe/schema.d.mts +40 -0
  87. package/dist/stripe/schema.d.mts.map +1 -0
  88. package/dist/stripe/schema.mjs +28 -40
  89. package/dist/stripe/schema.mjs.map +1 -1
  90. package/dist/subscription/index.cjs +178 -80
  91. package/dist/subscription/index.cjs.map +1 -1
  92. package/dist/subscription/index.d.cts +136 -134
  93. package/dist/subscription/index.d.cts.map +1 -0
  94. package/dist/subscription/index.d.mts +150 -0
  95. package/dist/subscription/index.d.mts.map +1 -0
  96. package/dist/subscription/index.mjs +173 -51
  97. package/dist/subscription/index.mjs.map +1 -1
  98. package/dist/types.cjs +0 -19
  99. package/dist/types.d.cts +7 -6
  100. package/dist/types.d.cts.map +1 -0
  101. package/dist/types.d.mts +10 -0
  102. package/dist/types.d.mts.map +1 -0
  103. package/dist/types.mjs +1 -1
  104. package/package.json +40 -25
  105. package/dist/app-store/config.d.ts +0 -39
  106. package/dist/app-store/index.cjs.map +0 -1
  107. package/dist/app-store/index.d.ts +0 -3
  108. package/dist/app-store/index.mjs.map +0 -1
  109. package/dist/google-play/config.d.ts +0 -39
  110. package/dist/google-play/index.cjs.map +0 -1
  111. package/dist/google-play/index.d.ts +0 -4
  112. package/dist/google-play/index.mjs.map +0 -1
  113. package/dist/google-play/real-time-developer-notification.d.ts +0 -148
  114. package/dist/index.cjs.map +0 -1
  115. package/dist/index.d.ts +0 -6
  116. package/dist/index.mjs.map +0 -1
  117. package/dist/stripe/config.d.ts +0 -43
  118. package/dist/stripe/handler.d.ts +0 -15
  119. package/dist/stripe/index.cjs.map +0 -1
  120. package/dist/stripe/index.d.ts +0 -12
  121. package/dist/stripe/index.mjs.map +0 -1
  122. package/dist/stripe/mapper.d.ts +0 -157
  123. package/dist/stripe/metadata.d.ts +0 -10
  124. package/dist/stripe/schema.d.ts +0 -41
  125. package/dist/subscription/index.d.ts +0 -148
  126. package/dist/types.cjs.map +0 -1
  127. package/dist/types.d.ts +0 -9
  128. package/dist/types.mjs.map +0 -1
@@ -1,137 +1,118 @@
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");
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
- 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
- price = (priceId, metadata = { credits: 0, expiresIn: "0" }) => {
53
- this.prices.set(priceId, metadata);
54
- return this;
55
- };
56
- default = (defaultPriceId) => {
57
- this.defaultPriceId = defaultPriceId;
58
- this.config[addMethod](this);
59
- return this.config;
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 _StripeConfig {
63
- products = /* @__PURE__ */ new Map();
64
- returnUrl;
65
- cancelUrl;
66
- successUrl;
67
- cancellationCouponId;
68
- allowPromotionCodes;
69
- get productIds() {
70
- return Array.from(this.products.keys());
71
- }
72
- [addMethod] = (product) => {
73
- this.products.set(product.id, product);
74
- return this;
75
- };
76
- constructor(options) {
77
- this.returnUrl = options.returnUrl;
78
- this.cancelUrl = options.cancelUrl;
79
- this.successUrl = options.successUrl;
80
- this.cancellationCouponId = options.cancellationCouponId;
81
- this.allowPromotionCodes = options.allowPromotionCodes;
82
- }
83
- static create = (options) => {
84
- return new _StripeConfig(options);
85
- };
86
- product = (productId, plan = null) => {
87
- return new Product(this, productId, plan);
88
- };
89
- getPlan = (productId) => {
90
- const product = this.products.get(productId);
91
- (0, import_utils.invariant)(product, `Product not found for ${productId}`);
92
- (0, import_utils.invariant)(product.plan, `Product ${productId} is not a subscription`);
93
- return product.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
- };
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
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {
135
- StripeConfig
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>, id: string, plan: PE | 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 price = <K extends PriceId>(\n priceId: K extends I ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, PI, I | K> => {\n this.prices.set(priceId, metadata);\n return this as Product<NS, PE, 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 PI extends string = never,\n> {\n private products: Map<string, Product<NS, PE, 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, 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>(options: Options) => {\n return new StripeConfig<NS, PE>(options);\n };\n\n product = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n plan: PE | null = null\n ) => {\n return new Product<NS, PE, K | PI>(this, productId, plan);\n };\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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,gBAAe;AAKf,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,UAAN,MAKE;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEA,YAAY,QAAkC,IAAY,OAAkB,MAAM;AAChF,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,SAAS,oBAAI,IAAI;AACtB,SAAK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
+ {"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,OAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;CACxC;CAEA,CAAC,cA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U,KAAK,SAAS,IAAI,SAAS;EAC3C,CAAA,GAAA,cAAA,UAAA,CAAU,SAAS,yBAAyB,WAAW;EACvD,IAAI,SAAS;GACX,MAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;GACnD,CAAA,GAAA,cAAA,UAAA,CAAU,OAAO,uBAAuB,SAAS;GACjD,OAAO,MAAM;EACf;EAEA,CAAA,GAAA,cAAA,UAAA,CAAU,QAAQ,gBAAgB,uCAAuC,WAAW;EACpF,OAAO,QAAQ,OAAO,IAAI,QAAQ,cAAc,CAAC,EAAE,WAAW;CAChE;CAEA,sBAA8B,WAAmB,YAA6B;EAC5E,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS;EAC3C,CAAA,GAAA,cAAA,UAAA,CAAU,SAAS,yBAAyB,WAAW;EACvD,IAAI,SAAS;GACX,MAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;GACnD,CAAA,GAAA,cAAA,UAAA,CAAU,OAAO,uBAAuB,SAAS;GACjD,QAAA,GAAA,GAAA,QAAA,CAAU,MAAM,SAAS;EAC3B;EAEA,CAAA,GAAA,cAAA,UAAA,CAAU,QAAQ,gBAAgB,uCAAuC,WAAW;EACpF,QAAA,GAAA,GAAA,QAAA,CAAU,QAAQ,OAAO,IAAI,QAAQ,cAAc,CAAC,EAAE,aAAa,GAAG;CACxE;CAEA,sBAAsB,WAAmB,YAA6B;EACpE,MAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;EAC5D,OAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,CAAC,YAAY;CACtD;AACF"}
@@ -1,43 +1,52 @@
1
- import { Metadata } from '../types.cjs';
2
- import 'ms';
3
-
1
+ import { Metadata } from "../types.cjs";
2
+ //#region src/stripe/config.d.ts
4
3
  type PriceId = `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
- readonly id: string;
8
- readonly config: StripeConfig<NS, PE, PI>;
9
- readonly plan: PE | null;
10
- readonly prices: Map<PriceId, Metadata>;
11
- defaultPriceId: I | null;
12
- constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
13
- price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, PI, I | K>;
14
- default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
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
- returnUrl: string;
18
- cancelUrl: string;
19
- successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
20
- cancellationCouponId: string;
21
- allowPromotionCodes: boolean;
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
- 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, PI>) => this;
32
- private constructor();
33
- static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => StripeConfig<NS_1, PE_1, never>;
34
- product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, plan?: PE | null) => Product<NS, PE, PI | K, never>;
35
- getPlan: (productId: string) => PE;
36
- getMode: (productId: string) => "payment" | "subscription";
37
- getPriceId: (productId: string) => PriceId;
38
- getCreditAmount: (productId: string, priceId?: string) => number;
39
- private getCreditExpiresIn;
40
- getCreditExpiresAt: (productId: string, priceId?: string) => string;
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 { type PriceId, StripeConfig };
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"}