@shware/purchase 1.8.8 → 1.9.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 +98 -128
  3. package/dist/app-store/config.cjs.map +1 -1
  4. package/dist/app-store/config.d.cts +31 -31
  5. package/dist/app-store/config.d.cts.map +1 -0
  6. package/dist/app-store/config.d.mts +39 -0
  7. package/dist/app-store/config.d.mts.map +1 -0
  8. package/dist/app-store/config.mjs +93 -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 +100 -123
  15. package/dist/google-play/config.cjs.map +1 -1
  16. package/dist/google-play/config.d.cts +31 -31
  17. package/dist/google-play/config.d.cts.map +1 -0
  18. package/dist/google-play/config.d.mts +39 -0
  19. package/dist/google-play/config.d.mts.map +1 -0
  20. package/dist/google-play/config.mjs +95 -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 +104 -133
  39. package/dist/stripe/config.cjs.map +1 -1
  40. package/dist/stripe/config.d.cts +35 -35
  41. package/dist/stripe/config.d.cts.map +1 -0
  42. package/dist/stripe/config.d.mts +43 -0
  43. package/dist/stripe/config.d.mts.map +1 -0
  44. package/dist/stripe/config.mjs +99 -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 -218
  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 -181
  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 +41 -26
  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,102 +1,105 @@
1
- // src/stripe/config.ts
2
1
  import { invariant } from "@shware/utils";
3
2
  import ms from "ms";
4
- var addMethod = /* @__PURE__ */ Symbol("addMethod");
3
+ //#region src/stripe/config.ts
4
+ const addMethod = Symbol("addMethod");
5
5
  var Product = class {
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
- price = (priceId, metadata = { credits: 0, expiresIn: "0" }) => {
19
- this.prices.set(priceId, metadata);
20
- return this;
21
- };
22
- default = (defaultPriceId) => {
23
- this.defaultPriceId = defaultPriceId;
24
- this.config[addMethod](this);
25
- return this.config;
26
- };
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
+ price = (priceId, metadata = {
19
+ credits: 0,
20
+ expiresIn: "0"
21
+ }) => {
22
+ this.prices.set(priceId, metadata);
23
+ return this;
24
+ };
25
+ default = (defaultPriceId) => {
26
+ this.defaultPriceId = defaultPriceId;
27
+ this.config[addMethod](this);
28
+ return this.config;
29
+ };
27
30
  };
28
- var StripeConfig = class _StripeConfig {
29
- products = /* @__PURE__ */ new Map();
30
- returnUrl;
31
- cancelUrl;
32
- successUrl;
33
- cancellationCouponId;
34
- allowPromotionCodes;
35
- get productIds() {
36
- return Array.from(this.products.keys());
37
- }
38
- [addMethod] = (product) => {
39
- this.products.set(product.id, product);
40
- return this;
41
- };
42
- constructor(options) {
43
- this.returnUrl = options.returnUrl;
44
- this.cancelUrl = options.cancelUrl;
45
- this.successUrl = options.successUrl;
46
- this.cancellationCouponId = options.cancellationCouponId;
47
- this.allowPromotionCodes = options.allowPromotionCodes;
48
- }
49
- static create = (options) => {
50
- return new _StripeConfig(options);
51
- };
52
- product = (productId, plan = null) => {
53
- return new Product(this, productId, plan);
54
- };
55
- getPlan = (productId) => {
56
- const product = this.products.get(productId);
57
- invariant(product, `Product not found for ${productId}`);
58
- invariant(product.plan, `Product ${productId} is not a subscription`);
59
- return product.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
31
+ var StripeConfig = class StripeConfig {
32
+ products = /* @__PURE__ */ new Map();
33
+ returnUrl;
34
+ cancelUrl;
35
+ successUrl;
36
+ cancellationCouponId;
37
+ allowPromotionCodes;
38
+ get productIds() {
39
+ return Array.from(this.products.keys());
40
+ }
41
+ [addMethod] = (product) => {
42
+ this.products.set(product.id, product);
43
+ return this;
44
+ };
45
+ constructor(options) {
46
+ this.returnUrl = options.returnUrl;
47
+ this.cancelUrl = options.cancelUrl;
48
+ this.successUrl = options.successUrl;
49
+ this.cancellationCouponId = options.cancellationCouponId;
50
+ this.allowPromotionCodes = options.allowPromotionCodes;
51
+ }
52
+ static create = (options) => {
53
+ return new StripeConfig(options);
54
+ };
55
+ product = (productId, plan = null) => {
56
+ return new Product(this, productId, plan);
57
+ };
58
+ getPlan = (productId) => {
59
+ const product = this.products.get(productId);
60
+ invariant(product, `Product not found for ${productId}`);
61
+ invariant(product.plan, `Product ${productId} is not a subscription`);
62
+ return product.plan;
63
+ };
64
+ getMode = (productId) => {
65
+ const product = this.products.get(productId);
66
+ invariant(product, `Product not found for ${productId}`);
67
+ return product.plan === null ? "payment" : "subscription";
68
+ };
69
+ getPriceId = (productId) => {
70
+ const product = this.products.get(productId);
71
+ invariant(product, `Product not found for ${productId}`);
72
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
73
+ return product.defaultPriceId;
74
+ };
75
+ getCreditAmount = (productId, priceId) => {
76
+ const product = this.products.get(productId);
77
+ invariant(product, `Product not found for ${productId}`);
78
+ if (priceId) {
79
+ const price = product.prices.get(priceId);
80
+ invariant(price, `Price not found for ${priceId}`);
81
+ return price.credits;
82
+ }
83
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
84
+ return product.prices.get(product.defaultPriceId)?.credits ?? 0;
85
+ };
86
+ getCreditExpiresIn = (productId, priceId) => {
87
+ const product = this.products.get(productId);
88
+ invariant(product, `Product not found for ${productId}`);
89
+ if (priceId) {
90
+ const price = product.prices.get(priceId);
91
+ invariant(price, `Price not found for ${priceId}`);
92
+ return ms(price.expiresIn);
93
+ }
94
+ invariant(product.defaultPriceId, `Default price not found for product ${productId}`);
95
+ return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? "0");
96
+ };
97
+ getCreditExpiresAt = (productId, priceId) => {
98
+ const expiresIn = this.getCreditExpiresIn(productId, priceId);
99
+ return new Date(Date.now() + expiresIn).toISOString();
100
+ };
101
101
  };
102
+ //#endregion
103
+ export { StripeConfig };
104
+
102
105
  //# sourceMappingURL=config.mjs.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":"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","names":[]}
1
+ {"version":3,"file":"config.mjs","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 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":";;;AAMA,MAAM,YAAY,OAAO,WAAW;AAEpC,IAAM,UAAN,MAKE;CACA;CACA;CACA;CACA;CAEA;CAEA,YAAY,QAAkC,IAAY,OAAkB,MAAM;EAChF,KAAK,KAAK;EACV,KAAK,SAAS;EACd,KAAK,OAAO;EACZ,KAAK,yBAAS,IAAI,IAAI;EACtB,KAAK,iBAAiB;CACxB;CAEA,SACE,SACA,WAAqB;EAAE,SAAS;EAAG,WAAW;CAAI,MACnB;EAC/B,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,aAIX;CACA,2BAAqD,IAAI,IAAI;CAE7D;CACA;CACA;CACA;CACA;CAEA,IAAI,aAAuB;EACzB,OAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;CACxC;CAEA,CAAC,cAAc,YAAiC;EAC9C,KAAK,SAAS,IAAI,QAAQ,IAAI,OAAO;EACrC,OAAO;CACT;CAEA,YAAoB,SAAkB;EACpC,KAAK,YAAY,QAAQ;EACzB,KAAK,YAAY,QAAQ;EACzB,KAAK,aAAa,QAAQ;EAC1B,KAAK,uBAAuB,QAAQ;EACpC,KAAK,sBAAsB,QAAQ;CACrC;CAEA,OAAO,UAA2D,YAAqB;EACrF,OAAO,IAAI,aAAqB,OAAO;CACzC;CAEA,WACE,WACA,OAAkB,SACf;EACH,OAAO,IAAI,QAAwB,MAAM,WAAW,IAAI;CAC1D;CAEA,WAAW,cAA0B;EACnC,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS;EAC3C,UAAU,SAAS,yBAAyB,WAAW;EACvD,UAAU,QAAQ,MAAM,WAAW,UAAU,uBAAuB;EACpE,OAAO,QAAQ;CACjB;CAEA,WAAW,cAAkD;EAC3D,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS;EAC3C,UAAU,SAAS,yBAAyB,WAAW;EACvD,OAAO,QAAQ,SAAS,OAAO,YAAY;CAC7C;CAEA,cAAc,cAA+B;EAC3C,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS;EAC3C,UAAU,SAAS,yBAAyB,WAAW;EACvD,UAAU,QAAQ,gBAAgB,uCAAuC,WAAW;EACpF,OAAO,QAAQ;CACjB;CAEA,mBAAmB,WAAmB,YAA6B;EACjE,MAAM,UAAU,KAAK,SAAS,IAAI,SAAS;EAC3C,UAAU,SAAS,yBAAyB,WAAW;EACvD,IAAI,SAAS;GACX,MAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;GACnD,UAAU,OAAO,uBAAuB,SAAS;GACjD,OAAO,MAAM;EACf;EAEA,UAAU,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,UAAU,SAAS,yBAAyB,WAAW;EACvD,IAAI,SAAS;GACX,MAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;GACnD,UAAU,OAAO,uBAAuB,SAAS;GACjD,OAAO,GAAG,MAAM,SAAS;EAC3B;EAEA,UAAU,QAAQ,gBAAgB,uCAAuC,WAAW;EACpF,OAAO,GAAG,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,56 +1,28 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/stripe/handler.ts
3
+ var StripeEventHandler = class StripeEventHandler {
4
+ handlers;
5
+ constructor() {
6
+ this.handlers = /* @__PURE__ */ new Map();
7
+ }
8
+ static create() {
9
+ return new StripeEventHandler();
10
+ }
11
+ on = (type, handler) => {
12
+ if (!this.handlers.has(type)) this.handlers.set(type, []);
13
+ this.handlers.get(type)?.push(handler);
14
+ return this;
15
+ };
16
+ process = async (event) => {
17
+ const eventHandlers = this.handlers.get(event.type);
18
+ if (eventHandlers) await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
19
+ else {
20
+ console.error(`No stripe event handler found for event type: ${event.type}`);
21
+ throw new Error(`No stripe event handler found for event type: ${event.type}`);
22
+ }
23
+ };
9
24
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ //#endregion
26
+ exports.StripeEventHandler = StripeEventHandler;
19
27
 
20
- // src/stripe/handler.ts
21
- var handler_exports = {};
22
- __export(handler_exports, {
23
- StripeEventHandler: () => StripeEventHandler
24
- });
25
- module.exports = __toCommonJS(handler_exports);
26
- var StripeEventHandler = class _StripeEventHandler {
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- handlers;
29
- constructor() {
30
- this.handlers = /* @__PURE__ */ new Map();
31
- }
32
- static create() {
33
- return new _StripeEventHandler();
34
- }
35
- on = (type, handler) => {
36
- if (!this.handlers.has(type)) {
37
- this.handlers.set(type, []);
38
- }
39
- this.handlers.get(type)?.push(handler);
40
- return this;
41
- };
42
- process = async (event) => {
43
- const eventHandlers = this.handlers.get(event.type);
44
- if (eventHandlers) {
45
- await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
46
- } else {
47
- console.error(`No stripe event handler found for event type: ${event.type}`);
48
- throw new Error(`No stripe event handler found for event type: ${event.type}`);
49
- }
50
- };
51
- };
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- StripeEventHandler
55
- });
56
28
  //# sourceMappingURL=handler.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,IAAM,qBAAN,MAAM,oBAAmB;AAAA;AAAA,EAEb;AAAA,EAET,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,OAAO,SAAS;AACd,WAAO,IAAI,oBAAmB;AAAA,EAChC;AAAA,EAEA,KAAK,CAA8B,MAAS,YAA+B;AACzE,QAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GAAG;AAC5B,WAAK,SAAS,IAAI,MAAM,CAAC,CAAC;AAAA,IAC5B;AAEA,SAAK,SAAS,IAAI,IAAI,GAAG,KAAK,OAAO;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,OAAO,UAAuC;AACtD,UAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;AAClD,QAAI,eAAe;AACjB,YAAM,QAAQ,IAAI,cAAc,IAAI,CAAC,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;AAAA,IAC9E,OAAO;AACL,cAAQ,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAC3E,YAAM,IAAI,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"handler.cjs","names":[],"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";;AAWA,IAAa,qBAAb,MAAa,mBAAmB;CAE9B;CAEA,cAAsB;EACpB,KAAK,2BAAW,IAAI,IAAI;CAC1B;CAEA,OAAO,SAAS;EACd,OAAO,IAAI,mBAAmB;CAChC;CAEA,MAAmC,MAAS,YAA+B;EACzE,IAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GACzB,KAAK,SAAS,IAAI,MAAM,CAAC,CAAC;EAG5B,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO;EACrC,OAAO;CACT;CAEA,UAAU,OAAO,UAAuC;EACtD,MAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;EAClD,IAAI,eACF,MAAM,QAAQ,IAAI,cAAc,KAAK,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;OACvE;GACL,QAAQ,MAAM,iDAAiD,MAAM,MAAM;GAC3E,MAAM,IAAI,MAAM,iDAAiD,MAAM,MAAM;EAC/E;CACF;AACF"}
@@ -1,15 +1,16 @@
1
- import { Stripe } from 'stripe';
2
-
1
+ import { Stripe } from "stripe";
2
+ //#region src/stripe/handler.d.ts
3
3
  type StripeEventObject<T extends Stripe.Event.Type> = Extract<Stripe.Event, {
4
- type: T;
4
+ type: T;
5
5
  }>['data']['object'];
6
6
  type EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (object: StripeEventObject<T>) => Promise<void>;
7
7
  declare class StripeEventHandler {
8
- private readonly handlers;
9
- private constructor();
10
- static create(): StripeEventHandler;
11
- on: <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => this;
12
- process: (event: Stripe.Event) => Promise<void>;
8
+ private readonly handlers;
9
+ private constructor();
10
+ static create(): StripeEventHandler;
11
+ on: <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => this;
12
+ process: (event: Stripe.Event) => Promise<void>;
13
13
  }
14
-
14
+ //#endregion
15
15
  export { StripeEventHandler };
16
+ //# sourceMappingURL=handler.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.cts","names":[],"sources":["../../src/stripe/handler.ts"],"mappings":";;KAEK,kBAAkB,UAAU,OAAO,MAAM,QAAQ,QACpD,OAAO;EACL,MAAM;;KAGL,eAAe,UAAU,OAAO,MAAM,OAAO,OAAO,MAAM,SAC7D,QAAQ,kBAAkB,OACvB;cAEQ;mBAEM;UAEV;SAIA,UAAM;EAIb,KAAM,UAAU,OAAO,MAAM,MAAI,MAAQ,GAAC,SAAW,eAAe;EASpE,UAAO,OAAiB,OAAO,UAAQ"}
@@ -0,0 +1,16 @@
1
+ import { Stripe } from "stripe";
2
+ //#region src/stripe/handler.d.ts
3
+ type StripeEventObject<T extends Stripe.Event.Type> = Extract<Stripe.Event, {
4
+ type: T;
5
+ }>['data']['object'];
6
+ type EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (object: StripeEventObject<T>) => Promise<void>;
7
+ declare class StripeEventHandler {
8
+ private readonly handlers;
9
+ private constructor();
10
+ static create(): StripeEventHandler;
11
+ on: <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => this;
12
+ process: (event: Stripe.Event) => Promise<void>;
13
+ }
14
+ //#endregion
15
+ export { StripeEventHandler };
16
+ //# sourceMappingURL=handler.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.mts","names":[],"sources":["../../src/stripe/handler.ts"],"mappings":";;KAEK,kBAAkB,UAAU,OAAO,MAAM,QAAQ,QACpD,OAAO;EACL,MAAM;;KAGL,eAAe,UAAU,OAAO,MAAM,OAAO,OAAO,MAAM,SAC7D,QAAQ,kBAAkB,OACvB;cAEQ;mBAEM;UAEV;SAIA,UAAM;EAIb,KAAM,UAAU,OAAO,MAAM,MAAI,MAAQ,GAAC,SAAW,eAAe;EASpE,UAAO,OAAiB,OAAO,UAAQ"}
@@ -1,31 +1,27 @@
1
- // src/stripe/handler.ts
2
- var StripeEventHandler = class _StripeEventHandler {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- handlers;
5
- constructor() {
6
- this.handlers = /* @__PURE__ */ new Map();
7
- }
8
- static create() {
9
- return new _StripeEventHandler();
10
- }
11
- on = (type, handler) => {
12
- if (!this.handlers.has(type)) {
13
- this.handlers.set(type, []);
14
- }
15
- this.handlers.get(type)?.push(handler);
16
- return this;
17
- };
18
- process = async (event) => {
19
- const eventHandlers = this.handlers.get(event.type);
20
- if (eventHandlers) {
21
- await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
22
- } else {
23
- console.error(`No stripe event handler found for event type: ${event.type}`);
24
- throw new Error(`No stripe event handler found for event type: ${event.type}`);
25
- }
26
- };
27
- };
28
- export {
29
- StripeEventHandler
1
+ //#region src/stripe/handler.ts
2
+ var StripeEventHandler = class StripeEventHandler {
3
+ handlers;
4
+ constructor() {
5
+ this.handlers = /* @__PURE__ */ new Map();
6
+ }
7
+ static create() {
8
+ return new StripeEventHandler();
9
+ }
10
+ on = (type, handler) => {
11
+ if (!this.handlers.has(type)) this.handlers.set(type, []);
12
+ this.handlers.get(type)?.push(handler);
13
+ return this;
14
+ };
15
+ process = async (event) => {
16
+ const eventHandlers = this.handlers.get(event.type);
17
+ if (eventHandlers) await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));
18
+ else {
19
+ console.error(`No stripe event handler found for event type: ${event.type}`);
20
+ throw new Error(`No stripe event handler found for event type: ${event.type}`);
21
+ }
22
+ };
30
23
  };
24
+ //#endregion
25
+ export { StripeEventHandler };
26
+
31
27
  //# sourceMappingURL=handler.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";AAWO,IAAM,qBAAN,MAAM,oBAAmB;AAAA;AAAA,EAEb;AAAA,EAET,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,OAAO,SAAS;AACd,WAAO,IAAI,oBAAmB;AAAA,EAChC;AAAA,EAEA,KAAK,CAA8B,MAAS,YAA+B;AACzE,QAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GAAG;AAC5B,WAAK,SAAS,IAAI,MAAM,CAAC,CAAC;AAAA,IAC5B;AAEA,SAAK,SAAS,IAAI,IAAI,GAAG,KAAK,OAAO;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,OAAO,UAAuC;AACtD,UAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;AAClD,QAAI,eAAe;AACjB,YAAM,QAAQ,IAAI,cAAc,IAAI,CAAC,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;AAAA,IAC9E,OAAO;AACL,cAAQ,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAC3E,YAAM,IAAI,MAAM,iDAAiD,MAAM,IAAI,EAAE;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"handler.mjs","names":[],"sources":["../../src/stripe/handler.ts"],"sourcesContent":["import { type Stripe } from 'stripe';\n\ntype StripeEventObject<T extends Stripe.Event.Type> = Extract<\n Stripe.Event,\n { type: T }\n>['data']['object'];\n\ntype EventHandlerFn<T extends Stripe.Event.Type = Stripe.Event.Type> = (\n object: StripeEventObject<T>\n) => Promise<void>;\n\nexport class StripeEventHandler {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private readonly handlers: Map<Stripe.Event.Type, Array<EventHandlerFn<any>>>;\n\n private constructor() {\n this.handlers = new Map();\n }\n\n static create() {\n return new StripeEventHandler();\n }\n\n on = <T extends Stripe.Event.Type>(type: T, handler: EventHandlerFn<T>) => {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, []);\n }\n\n this.handlers.get(type)?.push(handler);\n return this;\n };\n\n process = async (event: Stripe.Event): Promise<void> => {\n const eventHandlers = this.handlers.get(event.type);\n if (eventHandlers) {\n await Promise.all(eventHandlers.map((handler) => handler(event.data.object)));\n } else {\n console.error(`No stripe event handler found for event type: ${event.type}`);\n throw new Error(`No stripe event handler found for event type: ${event.type}`);\n }\n };\n}\n"],"mappings":";AAWA,IAAa,qBAAb,MAAa,mBAAmB;CAE9B;CAEA,cAAsB;EACpB,KAAK,2BAAW,IAAI,IAAI;CAC1B;CAEA,OAAO,SAAS;EACd,OAAO,IAAI,mBAAmB;CAChC;CAEA,MAAmC,MAAS,YAA+B;EACzE,IAAI,CAAC,KAAK,SAAS,IAAI,IAAI,GACzB,KAAK,SAAS,IAAI,MAAM,CAAC,CAAC;EAG5B,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO;EACrC,OAAO;CACT;CAEA,UAAU,OAAO,UAAuC;EACtD,MAAM,gBAAgB,KAAK,SAAS,IAAI,MAAM,IAAI;EAClD,IAAI,eACF,MAAM,QAAQ,IAAI,cAAc,KAAK,YAAY,QAAQ,MAAM,KAAK,MAAM,CAAC,CAAC;OACvE;GACL,QAAQ,MAAM,iDAAiD,MAAM,MAAM;GAC3E,MAAM,IAAI,MAAM,iDAAiD,MAAM,MAAM;EAC/E;CACF;AACF"}
@@ -1,74 +1,27 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/stripe/index.ts
21
- var stripe_exports = {};
22
- __export(stripe_exports, {
23
- METADATA_KEYS: () => import_metadata.METADATA_KEYS,
24
- StripeConfig: () => import_config.StripeConfig,
25
- StripeEventHandler: () => import_handler.StripeEventHandler,
26
- addPendingCheckout: () => import_pending_checkout.addPendingCheckout,
27
- cancellationDetailsSchema: () => import_schema.cancellationDetailsSchema,
28
- createCheckoutSessionSchema: () => import_schema.createCheckoutSessionSchema,
29
- getBeginCheckoutProperties: () => import_mapper.getBeginCheckoutProperties,
30
- getPendingCheckouts: () => import_pending_checkout.getPendingCheckouts,
31
- getPurchaseProperties: () => import_mapper.getPurchaseProperties,
32
- mapCharge: () => import_mapper.mapCharge,
33
- mapCheckoutSession: () => import_mapper.mapCheckoutSession,
34
- mapInvoice: () => import_mapper.mapInvoice,
35
- mapLineItem: () => import_mapper.mapLineItem,
36
- mapPaymentIntent: () => import_mapper.mapPaymentIntent,
37
- mapPrice: () => import_mapper.mapPrice,
38
- mapSubscriptionStatus: () => import_mapper.mapSubscriptionStatus,
39
- mapTime: () => import_mapper.mapTime,
40
- minorUnits: () => import_mapper.minorUnits,
41
- price: () => import_mapper.price,
42
- removePendingCheckout: () => import_pending_checkout.removePendingCheckout
43
- });
44
- module.exports = __toCommonJS(stripe_exports);
45
- var import_mapper = require("./mapper.cjs");
46
- var import_handler = require("./handler.cjs");
47
- var import_schema = require("./schema.cjs");
48
- var import_metadata = require("./metadata.cjs");
49
- var import_config = require("./config.cjs");
50
- var import_pending_checkout = require("./pending-checkout.cjs");
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- METADATA_KEYS,
54
- StripeConfig,
55
- StripeEventHandler,
56
- addPendingCheckout,
57
- cancellationDetailsSchema,
58
- createCheckoutSessionSchema,
59
- getBeginCheckoutProperties,
60
- getPendingCheckouts,
61
- getPurchaseProperties,
62
- mapCharge,
63
- mapCheckoutSession,
64
- mapInvoice,
65
- mapLineItem,
66
- mapPaymentIntent,
67
- mapPrice,
68
- mapSubscriptionStatus,
69
- mapTime,
70
- minorUnits,
71
- price,
72
- removePendingCheckout
73
- });
74
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_stripe_config = require("./config.cjs");
3
+ const require_stripe_handler = require("./handler.cjs");
4
+ const require_stripe_mapper = require("./mapper.cjs");
5
+ const require_stripe_schema = require("./schema.cjs");
6
+ const require_stripe_metadata = require("./metadata.cjs");
7
+ const require_stripe_pending_checkout = require("./pending-checkout.cjs");
8
+ exports.METADATA_KEYS = require_stripe_metadata.METADATA_KEYS;
9
+ exports.StripeConfig = require_stripe_config.StripeConfig;
10
+ exports.StripeEventHandler = require_stripe_handler.StripeEventHandler;
11
+ exports.addPendingCheckout = require_stripe_pending_checkout.addPendingCheckout;
12
+ exports.cancellationDetailsSchema = require_stripe_schema.cancellationDetailsSchema;
13
+ exports.createCheckoutSessionSchema = require_stripe_schema.createCheckoutSessionSchema;
14
+ exports.getBeginCheckoutProperties = require_stripe_mapper.getBeginCheckoutProperties;
15
+ exports.getPendingCheckouts = require_stripe_pending_checkout.getPendingCheckouts;
16
+ exports.getPurchaseProperties = require_stripe_mapper.getPurchaseProperties;
17
+ exports.mapCharge = require_stripe_mapper.mapCharge;
18
+ exports.mapCheckoutSession = require_stripe_mapper.mapCheckoutSession;
19
+ exports.mapInvoice = require_stripe_mapper.mapInvoice;
20
+ exports.mapLineItem = require_stripe_mapper.mapLineItem;
21
+ exports.mapPaymentIntent = require_stripe_mapper.mapPaymentIntent;
22
+ exports.mapPrice = require_stripe_mapper.mapPrice;
23
+ exports.mapSubscriptionStatus = require_stripe_mapper.mapSubscriptionStatus;
24
+ exports.mapTime = require_stripe_mapper.mapTime;
25
+ exports.minorUnits = require_stripe_mapper.minorUnits;
26
+ exports.price = require_stripe_mapper.price;
27
+ exports.removePendingCheckout = require_stripe_pending_checkout.removePendingCheckout;
@@ -1,12 +1,8 @@
1
- export { BeginCheckoutProperties, CheckoutSession, PaymentStatus, Price, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.cjs';
2
- export { StripeEventHandler } from './handler.cjs';
3
- export { CancellationDetails, CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema } from './schema.cjs';
4
- export { METADATA_KEYS } from './metadata.cjs';
5
- export { PriceId, StripeConfig } from './config.cjs';
6
- export { addPendingCheckout, getPendingCheckouts, removePendingCheckout } from './pending-checkout.cjs';
7
- export { Stripe } from 'stripe';
8
- import '../subscription/index.cjs';
9
- import 'zod/v4/core';
10
- import 'zod/mini';
11
- import '../types.cjs';
12
- import 'ms';
1
+ import { PriceId, StripeConfig } from "./config.cjs";
2
+ import { StripeEventHandler } from "./handler.cjs";
3
+ import { BeginCheckoutProperties, CheckoutSession, PaymentStatus, Price, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price } from "./mapper.cjs";
4
+ import { CancellationDetails, CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema } from "./schema.cjs";
5
+ import { METADATA_KEYS } from "./metadata.cjs";
6
+ import { addPendingCheckout, getPendingCheckouts, removePendingCheckout } from "./pending-checkout.cjs";
7
+ import { Stripe } from "stripe";
8
+ export { type BeginCheckoutProperties, type CancellationDetails, type CheckoutSession, type CreateCheckoutSessionDTO, METADATA_KEYS, type PaymentStatus, type Price, type PriceId, type ProductPrice, type PurchaseProperties, type Stripe, StripeConfig, StripeEventHandler, addPendingCheckout, cancellationDetailsSchema, createCheckoutSessionSchema, getBeginCheckoutProperties, getPendingCheckouts, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price, removePendingCheckout };
@@ -0,0 +1,8 @@
1
+ import { PriceId, StripeConfig } from "./config.mjs";
2
+ import { StripeEventHandler } from "./handler.mjs";
3
+ import { BeginCheckoutProperties, CheckoutSession, PaymentStatus, Price, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price } from "./mapper.mjs";
4
+ import { CancellationDetails, CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema } from "./schema.mjs";
5
+ import { METADATA_KEYS } from "./metadata.mjs";
6
+ import { addPendingCheckout, getPendingCheckouts, removePendingCheckout } from "./pending-checkout.mjs";
7
+ import { Stripe } from "stripe";
8
+ export { type BeginCheckoutProperties, type CancellationDetails, type CheckoutSession, type CreateCheckoutSessionDTO, METADATA_KEYS, type PaymentStatus, type Price, type PriceId, type ProductPrice, type PurchaseProperties, type Stripe, StripeConfig, StripeEventHandler, addPendingCheckout, cancellationDetailsSchema, createCheckoutSessionSchema, getBeginCheckoutProperties, getPendingCheckouts, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapPrice, mapSubscriptionStatus, mapTime, minorUnits, price, removePendingCheckout };