@shware/purchase 1.1.0 → 1.3.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 (48) hide show
  1. package/dist/app-store/config.cjs +100 -0
  2. package/dist/app-store/config.cjs.map +1 -0
  3. package/dist/app-store/config.d.cts +30 -0
  4. package/dist/app-store/config.d.ts +30 -0
  5. package/dist/app-store/config.mjs +65 -0
  6. package/dist/app-store/config.mjs.map +1 -0
  7. package/dist/app-store/index.cjs +29 -0
  8. package/dist/app-store/index.cjs.map +1 -1
  9. package/dist/app-store/index.d.cts +2 -2
  10. package/dist/app-store/index.d.ts +2 -2
  11. package/dist/app-store/index.mjs +5 -0
  12. package/dist/app-store/index.mjs.map +1 -1
  13. package/dist/{stripe/types.cjs → google-play/config.cjs} +17 -4
  14. package/dist/google-play/config.cjs.map +1 -0
  15. package/dist/google-play/config.d.cts +4 -0
  16. package/dist/google-play/config.d.ts +4 -0
  17. package/dist/google-play/config.mjs +7 -0
  18. package/dist/google-play/config.mjs.map +1 -0
  19. package/dist/google-play/index.cjs +3 -0
  20. package/dist/google-play/index.cjs.map +1 -1
  21. package/dist/google-play/index.d.cts +1 -0
  22. package/dist/google-play/index.d.ts +1 -0
  23. package/dist/google-play/index.mjs +2 -0
  24. package/dist/google-play/index.mjs.map +1 -1
  25. package/dist/stripe/config.cjs +3 -6
  26. package/dist/stripe/config.cjs.map +1 -1
  27. package/dist/stripe/config.d.cts +14 -16
  28. package/dist/stripe/config.d.ts +14 -16
  29. package/dist/stripe/config.mjs +3 -6
  30. package/dist/stripe/config.mjs.map +1 -1
  31. package/dist/stripe/index.cjs +2 -2
  32. package/dist/stripe/index.cjs.map +1 -1
  33. package/dist/stripe/index.d.cts +2 -3
  34. package/dist/stripe/index.d.ts +2 -3
  35. package/dist/stripe/index.mjs +2 -2
  36. package/dist/stripe/index.mjs.map +1 -1
  37. package/dist/stripe/schema.cjs +3 -3
  38. package/dist/stripe/schema.cjs.map +1 -1
  39. package/dist/stripe/schema.d.cts +8 -4
  40. package/dist/stripe/schema.d.ts +8 -4
  41. package/dist/stripe/schema.mjs +2 -2
  42. package/dist/stripe/schema.mjs.map +1 -1
  43. package/package.json +2 -2
  44. package/dist/stripe/types.cjs.map +0 -1
  45. package/dist/stripe/types.d.cts +0 -18
  46. package/dist/stripe/types.d.ts +0 -18
  47. package/dist/stripe/types.mjs +0 -1
  48. package/dist/stripe/types.mjs.map +0 -1
@@ -0,0 +1,100 @@
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/app-store/config.ts
31
+ var config_exports = {};
32
+ __export(config_exports, {
33
+ AppStoreConfig: () => AppStoreConfig
34
+ });
35
+ module.exports = __toCommonJS(config_exports);
36
+ var import_utils = require("@shware/utils");
37
+ var import_ms = __toESM(require("ms"), 1);
38
+ var addMethod = /* @__PURE__ */ Symbol("addMethod");
39
+ var Subscription = class {
40
+ plan;
41
+ config;
42
+ products;
43
+ defaultProductId;
44
+ constructor(config, plan) {
45
+ this.plan = plan;
46
+ this.config = config;
47
+ this.products = /* @__PURE__ */ new Map();
48
+ this.defaultProductId = null;
49
+ }
50
+ product = (productId, credit = { credits: 0, expiresIn: "0" }) => {
51
+ this.products.set(productId, credit);
52
+ return this;
53
+ };
54
+ default = (defaultProductId) => {
55
+ this.defaultProductId = defaultProductId;
56
+ this.config[addMethod](this);
57
+ return this.config;
58
+ };
59
+ };
60
+ var AppStoreConfig = class _AppStoreConfig {
61
+ products;
62
+ subscriptions;
63
+ get productIds() {
64
+ return Array.from(this.products.keys());
65
+ }
66
+ [addMethod] = (subscription) => {
67
+ subscription.products.forEach((credit, productId) => this.products.set(productId, credit));
68
+ this.subscriptions.set(subscription.plan, subscription);
69
+ return this;
70
+ };
71
+ constructor() {
72
+ this.products = /* @__PURE__ */ new Map();
73
+ this.subscriptions = /* @__PURE__ */ new Map();
74
+ }
75
+ static create = () => {
76
+ return new _AppStoreConfig();
77
+ };
78
+ subscription = (plan) => {
79
+ return new Subscription(this, plan);
80
+ };
81
+ getCreditAmount = (productId) => {
82
+ const config = this.products.get(productId);
83
+ (0, import_utils.invariant)(config, `Product not found for ${productId}`);
84
+ return config.credits;
85
+ };
86
+ getCreditExpiresIn = (productId) => {
87
+ const config = this.products.get(productId);
88
+ (0, import_utils.invariant)(config, `Product not found for ${productId}`);
89
+ return (0, import_ms.default)(config.expiresIn);
90
+ };
91
+ getCreditExpiresAt = (productId) => {
92
+ const expiresIn = this.getCreditExpiresIn(productId);
93
+ return new Date(Date.now() + expiresIn).toISOString();
94
+ };
95
+ };
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ AppStoreConfig
99
+ });
100
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Subscription<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PL extends PE = never,\n PI extends string = never,\n I extends string = never,\n> {\n readonly plan: PL;\n readonly config: AppStoreConfig<NS, PE, PL, PI>;\n readonly products: Map<string, CreditConfig>;\n\n defaultProductId: I | null;\n\n constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL) {\n this.plan = plan;\n this.config = config;\n this.products = new Map();\n this.defaultProductId = null;\n }\n\n product = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PL, PI | K, I | K> => {\n this.products.set(productId, credit);\n return this as Subscription<NS, PE, PL, PI | K, I | K>;\n };\n\n default = (defaultProductId: I) => {\n this.defaultProductId = defaultProductId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\nexport class AppStoreConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PL extends PE = never,\n PI extends string = never,\n> {\n private products: Map<string, CreditConfig>;\n private subscriptions: Map<PE, Subscription<NS, PE, PL, PI>>;\n\n get productIds(): string[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (subscription: Subscription<NS, PE, PL, PI>) => {\n subscription.products.forEach((credit, productId) => this.products.set(productId, credit));\n this.subscriptions.set(subscription.plan, subscription);\n return this;\n };\n\n private constructor() {\n this.products = new Map();\n this.subscriptions = new Map();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>() => {\n return new AppStoreConfig<NS, PE>();\n };\n\n subscription = <K extends PE>(plan: K extends PL ? never : K) => {\n return new Subscription<NS, PE, K | PL, PI>(this, plan);\n };\n\n getCreditAmount = (productId: string): number => {\n const config = this.products.get(productId);\n invariant(config, `Product not found for ${productId}`);\n return config.credits;\n };\n\n private getCreditExpiresIn = (productId: string): number => {\n const config = this.products.get(productId);\n invariant(config, `Product not found for ${productId}`);\n return ms(config.expiresIn);\n };\n\n getCreditExpiresAt = (productId: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,gBAAqC;AAIrC,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,eAAN,MAME;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEA,YAAY,QAAwC,MAAU;AAC5D,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW,oBAAI,IAAI;AACxB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEA,UAAU,CACR,WACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MACR;AAC5C,SAAK,SAAS,IAAI,WAAW,MAAM;AACnC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,qBAAwB;AACjC,SAAK,mBAAmB;AACxB,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,MAAM,gBAKX;AAAA,EACQ;AAAA,EACA;AAAA,EAER,IAAI,aAAuB;AACzB,WAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;AAAA,EACxC;AAAA,EAEA,CAAC,SAAS,IAAI,CAAC,iBAA+C;AAC5D,iBAAa,SAAS,QAAQ,CAAC,QAAQ,cAAc,KAAK,SAAS,IAAI,WAAW,MAAM,CAAC;AACzF,SAAK,cAAc,IAAI,aAAa,MAAM,YAAY;AACtD,WAAO;AAAA,EACT;AAAA,EAEQ,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AACxB,SAAK,gBAAgB,oBAAI,IAAI;AAAA,EAC/B;AAAA,EAEA,OAAO,SAAS,MAAuD;AACrE,WAAO,IAAI,gBAAuB;AAAA,EACpC;AAAA,EAEA,eAAe,CAAe,SAAmC;AAC/D,WAAO,IAAI,aAAiC,MAAM,IAAI;AAAA,EACxD;AAAA,EAEA,kBAAkB,CAAC,cAA8B;AAC/C,UAAM,SAAS,KAAK,SAAS,IAAI,SAAS;AAC1C,gCAAU,QAAQ,yBAAyB,SAAS,EAAE;AACtD,WAAO,OAAO;AAAA,EAChB;AAAA,EAEQ,qBAAqB,CAAC,cAA8B;AAC1D,UAAM,SAAS,KAAK,SAAS,IAAI,SAAS;AAC1C,gCAAU,QAAQ,yBAAyB,SAAS,EAAE;AACtD,eAAO,UAAAA,SAAG,OAAO,SAAS;AAAA,EAC5B;AAAA,EAEA,qBAAqB,CAAC,cAA8B;AAClD,UAAM,YAAY,KAAK,mBAAmB,SAAS;AACnD,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":["ms"]}
@@ -0,0 +1,30 @@
1
+ import { StringValue } from 'ms';
2
+
3
+ type CreditConfig = {
4
+ credits: number;
5
+ expiresIn: StringValue;
6
+ };
7
+ declare const addMethod: unique symbol;
8
+ declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never, I extends string = never> {
9
+ readonly plan: PL;
10
+ readonly config: AppStoreConfig<NS, PE, PL, PI>;
11
+ readonly products: Map<string, CreditConfig>;
12
+ defaultProductId: I | null;
13
+ constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
14
+ product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, credit?: CreditConfig) => Subscription<NS, PE, PL, PI | K, I | K>;
15
+ default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
16
+ }
17
+ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never> {
18
+ private products;
19
+ private subscriptions;
20
+ get productIds(): string[];
21
+ [addMethod]: (subscription: Subscription<NS, PE, PL, PI>) => this;
22
+ private constructor();
23
+ static create: <NS_1 extends Lowercase<string>, PE_1 extends string>() => AppStoreConfig<NS_1, PE_1, never, never>;
24
+ subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, PL | K, PI, never>;
25
+ getCreditAmount: (productId: string) => number;
26
+ private getCreditExpiresIn;
27
+ getCreditExpiresAt: (productId: string) => string;
28
+ }
29
+
30
+ export { AppStoreConfig, type CreditConfig };
@@ -0,0 +1,30 @@
1
+ import { StringValue } from 'ms';
2
+
3
+ type CreditConfig = {
4
+ credits: number;
5
+ expiresIn: StringValue;
6
+ };
7
+ declare const addMethod: unique symbol;
8
+ declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never, I extends string = never> {
9
+ readonly plan: PL;
10
+ readonly config: AppStoreConfig<NS, PE, PL, PI>;
11
+ readonly products: Map<string, CreditConfig>;
12
+ defaultProductId: I | null;
13
+ constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
14
+ product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, credit?: CreditConfig) => Subscription<NS, PE, PL, PI | K, I | K>;
15
+ default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
16
+ }
17
+ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never> {
18
+ private products;
19
+ private subscriptions;
20
+ get productIds(): string[];
21
+ [addMethod]: (subscription: Subscription<NS, PE, PL, PI>) => this;
22
+ private constructor();
23
+ static create: <NS_1 extends Lowercase<string>, PE_1 extends string>() => AppStoreConfig<NS_1, PE_1, never, never>;
24
+ subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, PL | K, PI, never>;
25
+ getCreditAmount: (productId: string) => number;
26
+ private getCreditExpiresIn;
27
+ getCreditExpiresAt: (productId: string) => string;
28
+ }
29
+
30
+ export { AppStoreConfig, type CreditConfig };
@@ -0,0 +1,65 @@
1
+ // src/app-store/config.ts
2
+ import { invariant } from "@shware/utils";
3
+ import ms from "ms";
4
+ var addMethod = /* @__PURE__ */ Symbol("addMethod");
5
+ var Subscription = class {
6
+ plan;
7
+ config;
8
+ products;
9
+ defaultProductId;
10
+ constructor(config, plan) {
11
+ this.plan = plan;
12
+ this.config = config;
13
+ this.products = /* @__PURE__ */ new Map();
14
+ this.defaultProductId = null;
15
+ }
16
+ product = (productId, credit = { credits: 0, expiresIn: "0" }) => {
17
+ this.products.set(productId, credit);
18
+ return this;
19
+ };
20
+ default = (defaultProductId) => {
21
+ this.defaultProductId = defaultProductId;
22
+ this.config[addMethod](this);
23
+ return this.config;
24
+ };
25
+ };
26
+ var AppStoreConfig = class _AppStoreConfig {
27
+ products;
28
+ subscriptions;
29
+ get productIds() {
30
+ return Array.from(this.products.keys());
31
+ }
32
+ [addMethod] = (subscription) => {
33
+ subscription.products.forEach((credit, productId) => this.products.set(productId, credit));
34
+ this.subscriptions.set(subscription.plan, subscription);
35
+ return this;
36
+ };
37
+ constructor() {
38
+ this.products = /* @__PURE__ */ new Map();
39
+ this.subscriptions = /* @__PURE__ */ new Map();
40
+ }
41
+ static create = () => {
42
+ return new _AppStoreConfig();
43
+ };
44
+ subscription = (plan) => {
45
+ return new Subscription(this, plan);
46
+ };
47
+ getCreditAmount = (productId) => {
48
+ const config = this.products.get(productId);
49
+ invariant(config, `Product not found for ${productId}`);
50
+ return config.credits;
51
+ };
52
+ getCreditExpiresIn = (productId) => {
53
+ const config = this.products.get(productId);
54
+ invariant(config, `Product not found for ${productId}`);
55
+ return ms(config.expiresIn);
56
+ };
57
+ getCreditExpiresAt = (productId) => {
58
+ const expiresIn = this.getCreditExpiresIn(productId);
59
+ return new Date(Date.now() + expiresIn).toISOString();
60
+ };
61
+ };
62
+ export {
63
+ AppStoreConfig
64
+ };
65
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Subscription<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PL extends PE = never,\n PI extends string = never,\n I extends string = never,\n> {\n readonly plan: PL;\n readonly config: AppStoreConfig<NS, PE, PL, PI>;\n readonly products: Map<string, CreditConfig>;\n\n defaultProductId: I | null;\n\n constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL) {\n this.plan = plan;\n this.config = config;\n this.products = new Map();\n this.defaultProductId = null;\n }\n\n product = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PL, PI | K, I | K> => {\n this.products.set(productId, credit);\n return this as Subscription<NS, PE, PL, PI | K, I | K>;\n };\n\n default = (defaultProductId: I) => {\n this.defaultProductId = defaultProductId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\nexport class AppStoreConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PL extends PE = never,\n PI extends string = never,\n> {\n private products: Map<string, CreditConfig>;\n private subscriptions: Map<PE, Subscription<NS, PE, PL, PI>>;\n\n get productIds(): string[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (subscription: Subscription<NS, PE, PL, PI>) => {\n subscription.products.forEach((credit, productId) => this.products.set(productId, credit));\n this.subscriptions.set(subscription.plan, subscription);\n return this;\n };\n\n private constructor() {\n this.products = new Map();\n this.subscriptions = new Map();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>() => {\n return new AppStoreConfig<NS, PE>();\n };\n\n subscription = <K extends PE>(plan: K extends PL ? never : K) => {\n return new Subscription<NS, PE, K | PL, PI>(this, plan);\n };\n\n getCreditAmount = (productId: string): number => {\n const config = this.products.get(productId);\n invariant(config, `Product not found for ${productId}`);\n return config.credits;\n };\n\n private getCreditExpiresIn = (productId: string): number => {\n const config = this.products.get(productId);\n invariant(config, `Product not found for ${productId}`);\n return ms(config.expiresIn);\n };\n\n getCreditExpiresAt = (productId: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,QAA8B;AAIrC,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,eAAN,MAME;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEA,YAAY,QAAwC,MAAU;AAC5D,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,WAAW,oBAAI,IAAI;AACxB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEA,UAAU,CACR,WACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MACR;AAC5C,SAAK,SAAS,IAAI,WAAW,MAAM;AACnC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,qBAAwB;AACjC,SAAK,mBAAmB;AACxB,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AAEO,IAAM,iBAAN,MAAM,gBAKX;AAAA,EACQ;AAAA,EACA;AAAA,EAER,IAAI,aAAuB;AACzB,WAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;AAAA,EACxC;AAAA,EAEA,CAAC,SAAS,IAAI,CAAC,iBAA+C;AAC5D,iBAAa,SAAS,QAAQ,CAAC,QAAQ,cAAc,KAAK,SAAS,IAAI,WAAW,MAAM,CAAC;AACzF,SAAK,cAAc,IAAI,aAAa,MAAM,YAAY;AACtD,WAAO;AAAA,EACT;AAAA,EAEQ,cAAc;AACpB,SAAK,WAAW,oBAAI,IAAI;AACxB,SAAK,gBAAgB,oBAAI,IAAI;AAAA,EAC/B;AAAA,EAEA,OAAO,SAAS,MAAuD;AACrE,WAAO,IAAI,gBAAuB;AAAA,EACpC;AAAA,EAEA,eAAe,CAAe,SAAmC;AAC/D,WAAO,IAAI,aAAiC,MAAM,IAAI;AAAA,EACxD;AAAA,EAEA,kBAAkB,CAAC,cAA8B;AAC/C,UAAM,SAAS,KAAK,SAAS,IAAI,SAAS;AAC1C,cAAU,QAAQ,yBAAyB,SAAS,EAAE;AACtD,WAAO,OAAO;AAAA,EAChB;AAAA,EAEQ,qBAAqB,CAAC,cAA8B;AAC1D,UAAM,SAAS,KAAK,SAAS,IAAI,SAAS;AAC1C,cAAU,QAAQ,yBAAyB,SAAS,EAAE;AACtD,WAAO,GAAG,OAAO,SAAS;AAAA,EAC5B;AAAA,EAEA,qBAAqB,CAAC,cAA8B;AAClD,UAAM,YAAY,KAAK,mBAAmB,SAAS;AACnD,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":[]}
@@ -1,2 +1,31 @@
1
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/app-store/index.ts
21
+ var app_store_exports = {};
22
+ __export(app_store_exports, {
23
+ AppStoreConfig: () => import_config.AppStoreConfig
24
+ });
25
+ module.exports = __toCommonJS(app_store_exports);
26
+ var import_config = require("./config.cjs");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ AppStoreConfig
30
+ });
2
31
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/app-store/index.ts"],"sourcesContent":["export { AppStoreConfig } from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;","names":[]}
@@ -1,2 +1,2 @@
1
-
2
- export { }
1
+ export { AppStoreConfig } from './config.cjs';
2
+ import 'ms';
@@ -1,2 +1,2 @@
1
-
2
- export { }
1
+ export { AppStoreConfig } from './config.js';
2
+ import 'ms';
@@ -1 +1,6 @@
1
+ // src/app-store/index.ts
2
+ import { AppStoreConfig } from "./config.mjs";
3
+ export {
4
+ AppStoreConfig
5
+ };
1
6
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":["../../src/app-store/index.ts"],"sourcesContent":["export { AppStoreConfig } from './config';\n"],"mappings":";AAAA,SAAS,sBAAsB;","names":[]}
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -13,7 +17,16 @@ var __copyProps = (to, from, except, desc) => {
13
17
  };
14
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
19
 
16
- // src/stripe/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
19
- //# sourceMappingURL=types.cjs.map
20
+ // src/google-play/config.ts
21
+ var config_exports = {};
22
+ __export(config_exports, {
23
+ GooglePlayConfig: () => GooglePlayConfig
24
+ });
25
+ module.exports = __toCommonJS(config_exports);
26
+ var GooglePlayConfig = class {
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ GooglePlayConfig
31
+ });
32
+ //# sourceMappingURL=config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["export class GooglePlayConfig {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,mBAAN,MAAuB;AAAC;","names":[]}
@@ -0,0 +1,4 @@
1
+ declare class GooglePlayConfig {
2
+ }
3
+
4
+ export { GooglePlayConfig };
@@ -0,0 +1,4 @@
1
+ declare class GooglePlayConfig {
2
+ }
3
+
4
+ export { GooglePlayConfig };
@@ -0,0 +1,7 @@
1
+ // src/google-play/config.ts
2
+ var GooglePlayConfig = class {
3
+ };
4
+ export {
5
+ GooglePlayConfig
6
+ };
7
+ //# sourceMappingURL=config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["export class GooglePlayConfig {}\n"],"mappings":";AAAO,IAAM,mBAAN,MAAuB;AAAC;","names":[]}
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/google-play/index.ts
21
21
  var google_play_exports = {};
22
22
  __export(google_play_exports, {
23
+ GooglePlayConfig: () => import_config.GooglePlayConfig,
23
24
  GooglePlaySubscriptionState: () => import_real_time_developer_notification.GooglePlaySubscriptionState,
24
25
  OneTimeProductNotificationType: () => import_real_time_developer_notification.OneTimeProductNotificationType,
25
26
  SubscriptionNotificationType: () => import_real_time_developer_notification.SubscriptionNotificationType,
@@ -28,8 +29,10 @@ __export(google_play_exports, {
28
29
  });
29
30
  module.exports = __toCommonJS(google_play_exports);
30
31
  var import_real_time_developer_notification = require("./real-time-developer-notification.cjs");
32
+ var import_config = require("./config.cjs");
31
33
  // Annotate the CommonJS export names for ESM import in node:
32
34
  0 && (module.exports = {
35
+ GooglePlayConfig,
33
36
  GooglePlaySubscriptionState,
34
37
  OneTimeProductNotificationType,
35
38
  SubscriptionNotificationType,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/google-play/index.ts"],"sourcesContent":["export {\n type PubsubMessage,\n type DeveloperNotification,\n type SubscriptionNotification,\n type OneTimeProductNotification,\n type VoidedPurchaseNotification,\n type TestNotification,\n GooglePlaySubscriptionState,\n SubscriptionNotificationType,\n OneTimeProductNotificationType,\n VoidedPurchaseProductType,\n VoidedPurchaseRefundType,\n} from './real-time-developer-notification';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAYO;","names":[]}
1
+ {"version":3,"sources":["../../src/google-play/index.ts"],"sourcesContent":["export {\n type PubsubMessage,\n type DeveloperNotification,\n type SubscriptionNotification,\n type OneTimeProductNotification,\n type VoidedPurchaseNotification,\n type TestNotification,\n GooglePlaySubscriptionState,\n SubscriptionNotificationType,\n OneTimeProductNotificationType,\n VoidedPurchaseProductType,\n VoidedPurchaseRefundType,\n} from './real-time-developer-notification';\nexport { GooglePlayConfig } from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAYO;AACP,oBAAiC;","names":[]}
@@ -1 +1,2 @@
1
1
  export { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from './real-time-developer-notification.cjs';
2
+ export { GooglePlayConfig } from './config.cjs';
@@ -1 +1,2 @@
1
1
  export { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from './real-time-developer-notification.js';
2
+ export { GooglePlayConfig } from './config.js';
@@ -6,7 +6,9 @@ import {
6
6
  VoidedPurchaseProductType,
7
7
  VoidedPurchaseRefundType
8
8
  } from "./real-time-developer-notification.mjs";
9
+ import { GooglePlayConfig } from "./config.mjs";
9
10
  export {
11
+ GooglePlayConfig,
10
12
  GooglePlaySubscriptionState,
11
13
  OneTimeProductNotificationType,
12
14
  SubscriptionNotificationType,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/google-play/index.ts"],"sourcesContent":["export {\n type PubsubMessage,\n type DeveloperNotification,\n type SubscriptionNotification,\n type OneTimeProductNotification,\n type VoidedPurchaseNotification,\n type TestNotification,\n GooglePlaySubscriptionState,\n SubscriptionNotificationType,\n OneTimeProductNotificationType,\n VoidedPurchaseProductType,\n VoidedPurchaseRefundType,\n} from './real-time-developer-notification';\n"],"mappings":";AAAA;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../../src/google-play/index.ts"],"sourcesContent":["export {\n type PubsubMessage,\n type DeveloperNotification,\n type SubscriptionNotification,\n type OneTimeProductNotification,\n type VoidedPurchaseNotification,\n type TestNotification,\n GooglePlaySubscriptionState,\n SubscriptionNotificationType,\n OneTimeProductNotificationType,\n VoidedPurchaseProductType,\n VoidedPurchaseRefundType,\n} from './real-time-developer-notification';\nexport { GooglePlayConfig } from './config';\n"],"mappings":";AAAA;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;","names":[]}
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(config_exports);
36
36
  var import_utils = require("@shware/utils");
37
37
  var import_ms = __toESM(require("ms"), 1);
38
38
  var addMethod = /* @__PURE__ */ Symbol("addMethod");
39
- var Product = class _Product {
39
+ var Product = class {
40
40
  id;
41
41
  config;
42
42
  plan;
@@ -49,9 +49,6 @@ var Product = class _Product {
49
49
  this.prices = /* @__PURE__ */ new Map();
50
50
  this.defaultPriceId = null;
51
51
  }
52
- static create = (config, id, plan = null) => {
53
- return new _Product(config, id, plan);
54
- };
55
52
  price = (priceId, credit = { credits: 0, expiresIn: "0" }) => {
56
53
  this.prices.set(priceId, credit);
57
54
  return this;
@@ -84,8 +81,8 @@ var StripeConfig = class _StripeConfig {
84
81
  static create = (options) => {
85
82
  return new _StripeConfig(options);
86
83
  };
87
- product = (id, plan = null) => {
88
- return Product.create(this, id, plan);
84
+ product = (productId, plan = null) => {
85
+ return new Product(this, productId, plan);
89
86
  };
90
87
  getPlan = (productId) => {
91
88
  const plan = this.products.get(productId)?.plan;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type ProductId = Lowercase<string>;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<P extends ProductId = ProductId, I extends PriceId = never> {\n readonly id: P;\n readonly config: StripeConfig;\n readonly plan: string | null;\n readonly prices: Map<PriceId, CreditConfig>;\n\n defaultPriceId: I | null;\n\n private constructor(config: StripeConfig, id: P, plan: string | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n static create = <P extends ProductId>(\n config: StripeConfig,\n id: P,\n plan: string | null = null\n ) => {\n return new Product<P>(config, id, plan);\n };\n\n price = <K extends PriceId>(\n priceId: K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<P, I | K> => {\n this.prices.set(priceId, credit);\n return this as Product<P, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig {\n private products: Map<ProductId, Product> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public allowPromotionCodes: boolean;\n\n get productIds(): ProductId[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = (options: Options) => {\n return new StripeConfig(options);\n };\n\n product = (id: ProductId, plan: string | null = null) => {\n return Product.create(this, id, plan);\n };\n\n getPlan = (productId: string): string => {\n const plan = this.products.get(productId as ProductId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,gBAAqC;AAMrC,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,UAAN,MAAM,SAAoE;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEQ,YAAY,QAAsB,IAAO,OAAsB,MAAM;AAC3E,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,SAAS,oBAAI,IAAI;AACtB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,OAAO,SAAS,CACd,QACA,IACA,OAAsB,SACnB;AACH,WAAO,IAAI,SAAW,QAAQ,IAAI,IAAI;AAAA,EACxC;AAAA,EAEA,QAAQ,CACN,SACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MAC9B;AACtB,SAAK,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,mBAAsB;AAC/B,SAAK,iBAAiB;AACtB,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AASO,IAAM,eAAN,MAAM,cA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BAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,aAAO,MAAM;AAAA,IACf;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,WAAW;AAAA,EAChE;AAAA,EAEQ,qBAAqB,CAAC,WAAmB,YAA6B;AAC5E,UAAM,UAAU,KAAK,SAAS,IAAI,SAAsB;AACxD,gCAAU,SAAS,yBAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,iBAAO,UAAAA,SAAG,MAAM,SAAS;AAAA,IAC3B;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,eAAO,UAAAA,SAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":["ms"]}
1
+ {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\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, CreditConfig>;\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 credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, PI, I | K> => {\n this.prices.set(priceId, credit);\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 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 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.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 plan = this.products.get(productId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId);\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,gBAAqC;AAKrC,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,iBAAiB;AAAA,EACxB;AAAA,EAEA,QAAQ,CACN,SACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MACrB;AAC/B,SAAK,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,EACT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,SAAS,EAAE;AACpF,WAAO,QAAQ;AAAA,EACjB;AAAA,EAEA,kBAAkB,CAAC,WAAmB,YAA6B;AACjE,UAAM,UAAU,KAAK,SAAS,IAAI,SAAS;AAC3C,gCAAU,SAAS,yBAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,aAAO,MAAM;AAAA,IACf;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,WAAW;AAAA,EAChE;AAAA,EAEQ,qBAAqB,CAAC,WAAmB,YAA6B;AAC5E,UAAM,UAAU,KAAK,SAAS,IAAI,SAAS;AAC3C,gCAAU,SAAS,yBAAyB,SAAS,EAAE;AACvD,QAAI,SAAS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;AACnD,kCAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,iBAAO,UAAAA,SAAG,MAAM,SAAS;AAAA,IAC3B;AAEA,gCAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,eAAO,UAAAA,SAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":["ms"]}
@@ -1,22 +1,20 @@
1
1
  import { StringValue } from 'ms';
2
2
 
3
3
  type PriceId = `price_${string}`;
4
- type ProductId = Lowercase<string>;
5
4
  type CreditConfig = {
6
5
  credits: number;
7
6
  expiresIn: StringValue;
8
7
  };
9
8
  declare const addMethod: unique symbol;
10
- declare class Product<P extends ProductId = ProductId, I extends PriceId = never> {
11
- readonly id: P;
12
- readonly config: StripeConfig;
13
- readonly plan: string | null;
9
+ declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
10
+ readonly id: string;
11
+ readonly config: StripeConfig<NS, PE, PI>;
12
+ readonly plan: PE | null;
14
13
  readonly prices: Map<PriceId, CreditConfig>;
15
14
  defaultPriceId: I | null;
16
- private constructor();
17
- static create: <P_1 extends ProductId>(config: StripeConfig, id: P_1, plan?: string | null) => Product<P_1, never>;
18
- price: <K extends PriceId>(priceId: K, credit?: CreditConfig) => Product<P, I | K>;
19
- default: (defaultPriceId: I) => StripeConfig;
15
+ constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
16
+ price: <K extends PriceId>(priceId: K extends I ? never : K, credit?: CreditConfig) => Product<NS, PE, PI, I | K>;
17
+ default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
20
18
  }
21
19
  type Options = {
22
20
  returnUrl: string;
@@ -24,18 +22,18 @@ type Options = {
24
22
  successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
25
23
  allowPromotionCodes: boolean;
26
24
  };
27
- declare class StripeConfig {
25
+ declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
28
26
  private products;
29
27
  returnUrl: string;
30
28
  cancelUrl: string;
31
29
  successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
32
30
  allowPromotionCodes: boolean;
33
- get productIds(): ProductId[];
34
- [addMethod]: (product: Product) => this;
31
+ get productIds(): string[];
32
+ [addMethod]: (product: Product<NS, PE, PI>) => this;
35
33
  private constructor();
36
- static create: (options: Options) => StripeConfig;
37
- product: (id: ProductId, plan?: string | null) => Product<Lowercase<string>, never>;
38
- getPlan: (productId: string) => string;
34
+ static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => StripeConfig<NS_1, PE_1, never>;
35
+ product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, plan?: PE | null) => Product<NS, PE, PI | K, never>;
36
+ getPlan: (productId: string) => PE;
39
37
  getMode: (productId: string) => "payment" | "subscription";
40
38
  getPriceId: (productId: string) => PriceId;
41
39
  getCreditAmount: (productId: string, priceId?: string) => number;
@@ -43,4 +41,4 @@ declare class StripeConfig {
43
41
  getCreditExpiresAt: (productId: string, priceId?: string) => string;
44
42
  }
45
43
 
46
- export { type CreditConfig, type PriceId, type ProductId, StripeConfig };
44
+ export { type CreditConfig, type PriceId, StripeConfig };
@@ -1,22 +1,20 @@
1
1
  import { StringValue } from 'ms';
2
2
 
3
3
  type PriceId = `price_${string}`;
4
- type ProductId = Lowercase<string>;
5
4
  type CreditConfig = {
6
5
  credits: number;
7
6
  expiresIn: StringValue;
8
7
  };
9
8
  declare const addMethod: unique symbol;
10
- declare class Product<P extends ProductId = ProductId, I extends PriceId = never> {
11
- readonly id: P;
12
- readonly config: StripeConfig;
13
- readonly plan: string | null;
9
+ declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
10
+ readonly id: string;
11
+ readonly config: StripeConfig<NS, PE, PI>;
12
+ readonly plan: PE | null;
14
13
  readonly prices: Map<PriceId, CreditConfig>;
15
14
  defaultPriceId: I | null;
16
- private constructor();
17
- static create: <P_1 extends ProductId>(config: StripeConfig, id: P_1, plan?: string | null) => Product<P_1, never>;
18
- price: <K extends PriceId>(priceId: K, credit?: CreditConfig) => Product<P, I | K>;
19
- default: (defaultPriceId: I) => StripeConfig;
15
+ constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
16
+ price: <K extends PriceId>(priceId: K extends I ? never : K, credit?: CreditConfig) => Product<NS, PE, PI, I | K>;
17
+ default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
20
18
  }
21
19
  type Options = {
22
20
  returnUrl: string;
@@ -24,18 +22,18 @@ type Options = {
24
22
  successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
25
23
  allowPromotionCodes: boolean;
26
24
  };
27
- declare class StripeConfig {
25
+ declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
28
26
  private products;
29
27
  returnUrl: string;
30
28
  cancelUrl: string;
31
29
  successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
32
30
  allowPromotionCodes: boolean;
33
- get productIds(): ProductId[];
34
- [addMethod]: (product: Product) => this;
31
+ get productIds(): string[];
32
+ [addMethod]: (product: Product<NS, PE, PI>) => this;
35
33
  private constructor();
36
- static create: (options: Options) => StripeConfig;
37
- product: (id: ProductId, plan?: string | null) => Product<Lowercase<string>, never>;
38
- getPlan: (productId: string) => string;
34
+ static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => StripeConfig<NS_1, PE_1, never>;
35
+ product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, plan?: PE | null) => Product<NS, PE, PI | K, never>;
36
+ getPlan: (productId: string) => PE;
39
37
  getMode: (productId: string) => "payment" | "subscription";
40
38
  getPriceId: (productId: string) => PriceId;
41
39
  getCreditAmount: (productId: string, priceId?: string) => number;
@@ -43,4 +41,4 @@ declare class StripeConfig {
43
41
  getCreditExpiresAt: (productId: string, priceId?: string) => string;
44
42
  }
45
43
 
46
- export { type CreditConfig, type PriceId, type ProductId, StripeConfig };
44
+ export { type CreditConfig, type PriceId, StripeConfig };
@@ -2,7 +2,7 @@
2
2
  import { invariant } from "@shware/utils";
3
3
  import ms from "ms";
4
4
  var addMethod = /* @__PURE__ */ Symbol("addMethod");
5
- var Product = class _Product {
5
+ var Product = class {
6
6
  id;
7
7
  config;
8
8
  plan;
@@ -15,9 +15,6 @@ var Product = class _Product {
15
15
  this.prices = /* @__PURE__ */ new Map();
16
16
  this.defaultPriceId = null;
17
17
  }
18
- static create = (config, id, plan = null) => {
19
- return new _Product(config, id, plan);
20
- };
21
18
  price = (priceId, credit = { credits: 0, expiresIn: "0" }) => {
22
19
  this.prices.set(priceId, credit);
23
20
  return this;
@@ -50,8 +47,8 @@ var StripeConfig = class _StripeConfig {
50
47
  static create = (options) => {
51
48
  return new _StripeConfig(options);
52
49
  };
53
- product = (id, plan = null) => {
54
- return Product.create(this, id, plan);
50
+ product = (productId, plan = null) => {
51
+ return new Product(this, productId, plan);
55
52
  };
56
53
  getPlan = (productId) => {
57
54
  const plan = this.products.get(productId)?.plan;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type ProductId = Lowercase<string>;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\n\nconst addMethod = Symbol('addMethod');\n\nclass Product<P extends ProductId = ProductId, I extends PriceId = never> {\n readonly id: P;\n readonly config: StripeConfig;\n readonly plan: string | null;\n readonly prices: Map<PriceId, CreditConfig>;\n\n defaultPriceId: I | null;\n\n private constructor(config: StripeConfig, id: P, plan: string | null = null) {\n this.id = id;\n this.config = config;\n this.plan = plan;\n this.prices = new Map();\n this.defaultPriceId = null;\n }\n\n static create = <P extends ProductId>(\n config: StripeConfig,\n id: P,\n plan: string | null = null\n ) => {\n return new Product<P>(config, id, plan);\n };\n\n price = <K extends PriceId>(\n priceId: K,\n credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<P, I | K> => {\n this.prices.set(priceId, credit);\n return this as Product<P, I | K>;\n };\n\n default = (defaultPriceId: I) => {\n this.defaultPriceId = defaultPriceId;\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n};\n\nexport class StripeConfig {\n private products: Map<ProductId, Product> = new Map();\n\n public returnUrl: string;\n public cancelUrl: string;\n public successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n public allowPromotionCodes: boolean;\n\n get productIds(): ProductId[] {\n return Array.from(this.products.keys());\n }\n\n [addMethod] = (product: Product) => {\n this.products.set(product.id, product);\n return this;\n };\n\n private constructor(options: Options) {\n this.returnUrl = options.returnUrl;\n this.cancelUrl = options.cancelUrl;\n this.successUrl = options.successUrl;\n this.allowPromotionCodes = options.allowPromotionCodes;\n }\n\n static create = (options: Options) => {\n return new StripeConfig(options);\n };\n\n product = (id: ProductId, plan: string | null = null) => {\n return Product.create(this, id, plan);\n };\n\n getPlan = (productId: string): string => {\n const plan = this.products.get(productId as ProductId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n return product.plan === null ? 'payment' : 'subscription';\n };\n\n getPriceId = (productId: string): PriceId => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.defaultPriceId;\n };\n\n getCreditAmount = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return price.credits;\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return product.prices.get(product.defaultPriceId)?.credits ?? 0;\n };\n\n private getCreditExpiresIn = (productId: string, priceId?: string): number => {\n const product = this.products.get(productId as ProductId);\n invariant(product, `Product not found for ${productId}`);\n if (priceId) {\n const price = product.prices.get(priceId as PriceId);\n invariant(price, `Price not found for ${priceId}`);\n return ms(price.expiresIn);\n }\n\n invariant(product.defaultPriceId, `Default price not found for product ${productId}`);\n return ms(product.prices.get(product.defaultPriceId)?.expiresIn ?? '0');\n };\n\n getCreditExpiresAt = (productId: string, priceId?: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, priceId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],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M,SAAS;AAAA,IAC3B;AAEA,cAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,GAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms, { type StringValue } from 'ms';\n\nexport type PriceId = `price_${string}`;\nexport type CreditConfig = { credits: number; expiresIn: StringValue };\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, CreditConfig>;\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 credit: CreditConfig = { credits: 0, expiresIn: '0' }\n ): Product<NS, PE, PI, I | K> => {\n this.prices.set(priceId, credit);\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 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 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.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 plan = this.products.get(productId)?.plan;\n if (!plan) throw new Error(`Plan not found for product ${productId}`);\n return plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n const product = this.products.get(productId);\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,SAAS,iBAAiB;AAC1B,OAAO,QAA8B;AAKrC,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,iBAAiB;AAAA,EACxB;AAAA,EAEA,QAAQ,CACN,SACA,SAAuB,EAAE,SAAS,GAAG,WAAW,IAAI,MACrB;AAC/B,SAAK,OAAO,IAAI,SAAS,MAAM;AAC/B,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,mBAAsB;AAC/B,SAAK,iBAAiB;AACtB,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AASO,IAAM,eAAN,MAAM,cAIX;AAAA,EACQ,WAA6C,oBAAI,IAAI;AAAA,EAEtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEP,IAAI,aAAuB;AACzB,WAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;AAAA,EACxC;AAAA,EAEA,CAAC,SAAS,IAAI,CAAC,YAAiC;AAC9C,SAAK,SAAS,IAAI,QAAQ,IAAI,OAAO;AACrC,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,SAAkB;AACpC,SAAK,YAAY,QAAQ;AACzB,SAAK,YAAY,QAAQ;AACzB,SAAK,aAAa,QAAQ;AAC1B,SAAK,sBAAsB,QAAQ;AAAA,EACrC;AAAA,EAEA,OAAO,SAA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AAkB;AACnD,gBAAU,OAAO,uBAAuB,OAAO,EAAE;AACjD,aAAO,GAAG,MAAM,SAAS;AAAA,IAC3B;AAEA,cAAU,QAAQ,gBAAgB,uCAAuC,SAAS,EAAE;AACpF,WAAO,GAAG,QAAQ,OAAO,IAAI,QAAQ,cAAc,GAAG,aAAa,GAAG;AAAA,EACxE;AAAA,EAEA,qBAAqB,CAAC,WAAmB,YAA6B;AACpE,UAAM,YAAY,KAAK,mBAAmB,WAAW,OAAO;AAC5D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":[]}
@@ -24,7 +24,7 @@ __export(stripe_exports, {
24
24
  StripeConfig: () => import_config.StripeConfig,
25
25
  StripeEventHandler: () => import_handler.StripeEventHandler,
26
26
  cancellationDetailsSchema: () => import_schema.cancellationDetailsSchema,
27
- checkoutSessionSchema: () => import_schema.checkoutSessionSchema,
27
+ createCheckoutSessionSchema: () => import_schema.createCheckoutSessionSchema,
28
28
  getBeginCheckoutProperties: () => import_mapper.getBeginCheckoutProperties,
29
29
  getPurchaseProperties: () => import_mapper.getPurchaseProperties,
30
30
  mapCharge: () => import_mapper.mapCharge,
@@ -49,7 +49,7 @@ var import_config = require("./config.cjs");
49
49
  StripeConfig,
50
50
  StripeEventHandler,
51
51
  cancellationDetailsSchema,
52
- checkoutSessionSchema,
52
+ createCheckoutSessionSchema,
53
53
  getBeginCheckoutProperties,
54
54
  getPurchaseProperties,
55
55
  mapCharge,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type ProductId, type PriceId } from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,qBAAmC;AACnC,oBAIO;AAEP,sBAA8B;AAC9B,oBAA2D;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n createCheckoutSessionSchema,\n type CancellationDetails,\n type CreateCheckoutSessionDTO,\n} from './schema';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type PriceId } from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAgBO;AACP,qBAAmC;AACnC,oBAKO;AACP,sBAA8B;AAC9B,oBAA2C;","names":[]}
@@ -1,9 +1,8 @@
1
1
  export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.cjs';
2
2
  export { StripeEventHandler } from './handler.cjs';
3
- export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.cjs';
4
- export { Config, CreateCheckoutSessionDTO } from './types.cjs';
3
+ export { CancellationDetails, CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema } from './schema.cjs';
5
4
  export { METADATA_KEYS } from './metadata.cjs';
6
- export { PriceId, ProductId, StripeConfig } from './config.cjs';
5
+ export { PriceId, StripeConfig } from './config.cjs';
7
6
  import '../subscription/index.cjs';
8
7
  import 'stripe';
9
8
  import 'zod/v4/core';
@@ -1,9 +1,8 @@
1
1
  export { BeginCheckoutProperties, CheckoutSession, ProductPrice, PurchaseProperties, getBeginCheckoutProperties, getPurchaseProperties, mapCharge, mapCheckoutSession, mapInvoice, mapLineItem, mapPaymentIntent, mapSubscriptionStatus, mapTime, minorUnits, price } from './mapper.js';
2
2
  export { StripeEventHandler } from './handler.js';
3
- export { CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema } from './schema.js';
4
- export { Config, CreateCheckoutSessionDTO } from './types.js';
3
+ export { CancellationDetails, CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema } from './schema.js';
5
4
  export { METADATA_KEYS } from './metadata.js';
6
- export { PriceId, ProductId, StripeConfig } from './config.js';
5
+ export { PriceId, StripeConfig } from './config.js';
7
6
  import '../subscription/index.js';
8
7
  import 'stripe';
9
8
  import 'zod/v4/core';
@@ -15,7 +15,7 @@ import {
15
15
  import { StripeEventHandler } from "./handler.mjs";
16
16
  import {
17
17
  cancellationDetailsSchema,
18
- checkoutSessionSchema
18
+ createCheckoutSessionSchema
19
19
  } from "./schema.mjs";
20
20
  import { METADATA_KEYS } from "./metadata.mjs";
21
21
  import { StripeConfig } from "./config.mjs";
@@ -24,7 +24,7 @@ export {
24
24
  StripeConfig,
25
25
  StripeEventHandler,
26
26
  cancellationDetailsSchema,
27
- checkoutSessionSchema,
27
+ createCheckoutSessionSchema,
28
28
  getBeginCheckoutProperties,
29
29
  getPurchaseProperties,
30
30
  mapCharge,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n checkoutSessionSchema,\n type CancellationDetails,\n} from './schema';\nexport type { Config, CreateCheckoutSessionDTO } from './types';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type ProductId, type PriceId } from './config';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,oBAAkD;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/index.ts"],"sourcesContent":["export {\n mapTime,\n mapCharge,\n mapInvoice,\n mapLineItem,\n mapPaymentIntent,\n mapCheckoutSession,\n mapSubscriptionStatus,\n minorUnits,\n price,\n getPurchaseProperties,\n getBeginCheckoutProperties,\n type CheckoutSession,\n type PurchaseProperties,\n type ProductPrice,\n type BeginCheckoutProperties,\n} from './mapper';\nexport { StripeEventHandler } from './handler';\nexport {\n cancellationDetailsSchema,\n createCheckoutSessionSchema,\n type CancellationDetails,\n type CreateCheckoutSessionDTO,\n} from './schema';\nexport { METADATA_KEYS } from './metadata';\nexport { StripeConfig, type PriceId } from './config';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AACP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,qBAAqB;AAC9B,SAAS,oBAAkC;","names":[]}
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var schema_exports = {};
22
22
  __export(schema_exports, {
23
23
  cancellationDetailsSchema: () => cancellationDetailsSchema,
24
- checkoutSessionSchema: () => checkoutSessionSchema
24
+ createCheckoutSessionSchema: () => createCheckoutSessionSchema
25
25
  });
26
26
  module.exports = __toCommonJS(schema_exports);
27
27
  var import_mini = require("zod/mini");
@@ -42,7 +42,7 @@ var cancellationDetailsSchema = (0, import_mini.object)({
42
42
  )
43
43
  )
44
44
  });
45
- function checkoutSessionSchema(productIds) {
45
+ function createCheckoutSessionSchema(productIds) {
46
46
  return (0, import_mini.object)({
47
47
  quantity: (0, import_mini._default)((0, import_mini.int)().check((0, import_mini.gte)(1)), 1),
48
48
  productId: (0, import_mini.enum)(productIds),
@@ -53,6 +53,6 @@ function checkoutSessionSchema(productIds) {
53
53
  // Annotate the CommonJS export names for ESM import in node:
54
54
  0 && (module.exports = {
55
55
  cancellationDetailsSchema,
56
- checkoutSessionSchema
56
+ createCheckoutSessionSchema
57
57
  });
58
58
  //# sourceMappingURL=schema.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/schema.ts"],"sourcesContent":["import {\n _default,\n enum as _enum,\n gte,\n int,\n maxLength,\n nullable,\n object,\n optional,\n type output,\n string,\n url,\n} from 'zod/mini';\nimport type { ProductId } from './types';\n\nexport const cancellationDetailsSchema = object({\n comment: optional(nullable(string().check(maxLength(1024)))),\n feedback: optional(\n nullable(\n _enum([\n 'customer_service',\n 'low_quality',\n 'missing_features',\n 'switched_service',\n 'too_complex',\n 'too_expensive',\n 'unused',\n 'other',\n ])\n )\n ),\n});\n\nexport function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]) {\n return object({\n quantity: _default(int().check(gte(1)), 1),\n productId: _enum(productIds),\n cancelUrl: optional(url()),\n successUrl: optional(url()),\n });\n}\n\nexport interface CancellationDetails extends output<typeof cancellationDetailsSchema> {\n reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAYO;AAGA,IAAM,gCAA4B,oBAAO;AAAA,EAC9C,aAAS,0BAAS,0BAAS,oBAAO,EAAE,UAAM,uBAAU,IAAI,CAAC,CAAC,CAAC;AAAA,EAC3D,cAAU;AAAA,QACR;AAAA,UACE,YAAAA,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;AAEM,SAAS,sBAAsB,YAAyC;AAC7E,aAAO,oBAAO;AAAA,IACZ,cAAU,0BAAS,iBAAI,EAAE,UAAM,iBAAI,CAAC,CAAC,GAAG,CAAC;AAAA,IACzC,eAAW,YAAAA,MAAM,UAAU;AAAA,IAC3B,eAAW,0BAAS,iBAAI,CAAC;AAAA,IACzB,gBAAY,0BAAS,iBAAI,CAAC;AAAA,EAC5B,CAAC;AACH;","names":["_enum"]}
1
+ {"version":3,"sources":["../../src/stripe/schema.ts"],"sourcesContent":["import {\n _default,\n enum as _enum,\n gte,\n int,\n maxLength,\n nullable,\n object,\n optional,\n type output,\n string,\n url,\n} from 'zod/mini';\n\nexport const cancellationDetailsSchema = object({\n comment: optional(nullable(string().check(maxLength(1024)))),\n feedback: optional(\n nullable(\n _enum([\n 'customer_service',\n 'low_quality',\n 'missing_features',\n 'switched_service',\n 'too_complex',\n 'too_expensive',\n 'unused',\n 'other',\n ])\n )\n ),\n});\n\nexport function createCheckoutSessionSchema(productIds: string[]) {\n return object({\n quantity: _default(int().check(gte(1)), 1),\n productId: _enum(productIds),\n cancelUrl: optional(url()),\n successUrl: optional(url()),\n });\n}\n\nexport interface CancellationDetails extends output<typeof cancellationDetailsSchema> {\n reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;\n}\n\nexport interface CreateCheckoutSessionDTO {\n productId: string;\n cancelUrl?: string;\n successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAYO;AAEA,IAAM,gCAA4B,oBAAO;AAAA,EAC9C,aAAS,0BAAS,0BAAS,oBAAO,EAAE,UAAM,uBAAU,IAAI,CAAC,CAAC,CAAC;AAAA,EAC3D,cAAU;AAAA,QACR;AAAA,UACE,YAAAA,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;AAEM,SAAS,4BAA4B,YAAsB;AAChE,aAAO,oBAAO;AAAA,IACZ,cAAU,0BAAS,iBAAI,EAAE,UAAM,iBAAI,CAAC,CAAC,GAAG,CAAC;AAAA,IACzC,eAAW,YAAAA,MAAM,UAAU;AAAA,IAC3B,eAAW,0BAAS,iBAAI,CAAC;AAAA,IACzB,gBAAY,0BAAS,iBAAI,CAAC;AAAA,EAC5B,CAAC;AACH;","names":["_enum"]}
@@ -1,7 +1,6 @@
1
1
  import * as zod_v4_core from 'zod/v4/core';
2
2
  import * as zod_mini from 'zod/mini';
3
3
  import { output } from 'zod/mini';
4
- import { ProductId } from './types.cjs';
5
4
 
6
5
  declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
7
6
  comment: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniString<string>>>;
@@ -16,10 +15,10 @@ declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
16
15
  unused: "unused";
17
16
  }>>>;
18
17
  }, zod_v4_core.$strip>;
19
- declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]): zod_mini.ZodMiniObject<{
18
+ declare function createCheckoutSessionSchema(productIds: string[]): zod_mini.ZodMiniObject<{
20
19
  quantity: zod_mini.ZodMiniDefault<zod_mini.ZodMiniNumberFormat>;
21
20
  productId: zod_mini.ZodMiniEnum<{
22
- [x: Lowercase<string>]: Lowercase<string>;
21
+ [x: string]: string;
23
22
  }>;
24
23
  cancelUrl: zod_mini.ZodMiniOptional<zod_mini.ZodMiniURL>;
25
24
  successUrl: zod_mini.ZodMiniOptional<zod_mini.ZodMiniURL>;
@@ -27,5 +26,10 @@ declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]):
27
26
  interface CancellationDetails extends output<typeof cancellationDetailsSchema> {
28
27
  reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;
29
28
  }
29
+ interface CreateCheckoutSessionDTO {
30
+ productId: string;
31
+ cancelUrl?: string;
32
+ successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
33
+ }
30
34
 
31
- export { type CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema };
35
+ export { type CancellationDetails, type CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema };
@@ -1,7 +1,6 @@
1
1
  import * as zod_v4_core from 'zod/v4/core';
2
2
  import * as zod_mini from 'zod/mini';
3
3
  import { output } from 'zod/mini';
4
- import { ProductId } from './types.js';
5
4
 
6
5
  declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
7
6
  comment: zod_mini.ZodMiniOptional<zod_mini.ZodMiniNullable<zod_mini.ZodMiniString<string>>>;
@@ -16,10 +15,10 @@ declare const cancellationDetailsSchema: zod_mini.ZodMiniObject<{
16
15
  unused: "unused";
17
16
  }>>>;
18
17
  }, zod_v4_core.$strip>;
19
- declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]): zod_mini.ZodMiniObject<{
18
+ declare function createCheckoutSessionSchema(productIds: string[]): zod_mini.ZodMiniObject<{
20
19
  quantity: zod_mini.ZodMiniDefault<zod_mini.ZodMiniNumberFormat>;
21
20
  productId: zod_mini.ZodMiniEnum<{
22
- [x: Lowercase<string>]: Lowercase<string>;
21
+ [x: string]: string;
23
22
  }>;
24
23
  cancelUrl: zod_mini.ZodMiniOptional<zod_mini.ZodMiniURL>;
25
24
  successUrl: zod_mini.ZodMiniOptional<zod_mini.ZodMiniURL>;
@@ -27,5 +26,10 @@ declare function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]):
27
26
  interface CancellationDetails extends output<typeof cancellationDetailsSchema> {
28
27
  reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;
29
28
  }
29
+ interface CreateCheckoutSessionDTO {
30
+ productId: string;
31
+ cancelUrl?: string;
32
+ successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
33
+ }
30
34
 
31
- export { type CancellationDetails, cancellationDetailsSchema, checkoutSessionSchema };
35
+ export { type CancellationDetails, type CreateCheckoutSessionDTO, cancellationDetailsSchema, createCheckoutSessionSchema };
@@ -28,7 +28,7 @@ var cancellationDetailsSchema = object({
28
28
  )
29
29
  )
30
30
  });
31
- function checkoutSessionSchema(productIds) {
31
+ function createCheckoutSessionSchema(productIds) {
32
32
  return object({
33
33
  quantity: _default(int().check(gte(1)), 1),
34
34
  productId: _enum(productIds),
@@ -38,6 +38,6 @@ function checkoutSessionSchema(productIds) {
38
38
  }
39
39
  export {
40
40
  cancellationDetailsSchema,
41
- checkoutSessionSchema
41
+ createCheckoutSessionSchema
42
42
  };
43
43
  //# sourceMappingURL=schema.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stripe/schema.ts"],"sourcesContent":["import {\n _default,\n enum as _enum,\n gte,\n int,\n maxLength,\n nullable,\n object,\n optional,\n type output,\n string,\n url,\n} from 'zod/mini';\nimport type { ProductId } from './types';\n\nexport const cancellationDetailsSchema = object({\n comment: optional(nullable(string().check(maxLength(1024)))),\n feedback: optional(\n nullable(\n _enum([\n 'customer_service',\n 'low_quality',\n 'missing_features',\n 'switched_service',\n 'too_complex',\n 'too_expensive',\n 'unused',\n 'other',\n ])\n )\n ),\n});\n\nexport function checkoutSessionSchema(productIds: [ProductId, ...ProductId[]]) {\n return object({\n quantity: _default(int().check(gte(1)), 1),\n productId: _enum(productIds),\n cancelUrl: optional(url()),\n successUrl: optional(url()),\n });\n}\n\nexport interface CancellationDetails extends output<typeof cancellationDetailsSchema> {\n reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAGA,IAAM,4BAA4B,OAAO;AAAA,EAC9C,SAAS,SAAS,SAAS,OAAO,EAAE,MAAM,UAAU,IAAI,CAAC,CAAC,CAAC;AAAA,EAC3D,UAAU;AAAA,IACR;AAAA,MACE,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;AAEM,SAAS,sBAAsB,YAAyC;AAC7E,SAAO,OAAO;AAAA,IACZ,UAAU,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;AAAA,IACzC,WAAW,MAAM,UAAU;AAAA,IAC3B,WAAW,SAAS,IAAI,CAAC;AAAA,IACzB,YAAY,SAAS,IAAI,CAAC;AAAA,EAC5B,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/stripe/schema.ts"],"sourcesContent":["import {\n _default,\n enum as _enum,\n gte,\n int,\n maxLength,\n nullable,\n object,\n optional,\n type output,\n string,\n url,\n} from 'zod/mini';\n\nexport const cancellationDetailsSchema = object({\n comment: optional(nullable(string().check(maxLength(1024)))),\n feedback: optional(\n nullable(\n _enum([\n 'customer_service',\n 'low_quality',\n 'missing_features',\n 'switched_service',\n 'too_complex',\n 'too_expensive',\n 'unused',\n 'other',\n ])\n )\n ),\n});\n\nexport function createCheckoutSessionSchema(productIds: string[]) {\n return object({\n quantity: _default(int().check(gte(1)), 1),\n productId: _enum(productIds),\n cancelUrl: optional(url()),\n successUrl: optional(url()),\n });\n}\n\nexport interface CancellationDetails extends output<typeof cancellationDetailsSchema> {\n reason?: 'cancellation_requested' | 'payment_disputed' | 'payment_failed' | null;\n}\n\nexport interface CreateCheckoutSessionDTO {\n productId: string;\n cancelUrl?: string;\n successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,4BAA4B,OAAO;AAAA,EAC9C,SAAS,SAAS,SAAS,OAAO,EAAE,MAAM,UAAU,IAAI,CAAC,CAAC,CAAC;AAAA,EAC3D,UAAU;AAAA,IACR;AAAA,MACE,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;AAEM,SAAS,4BAA4B,YAAsB;AAChE,SAAO,OAAO;AAAA,IACZ,UAAU,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;AAAA,IACzC,WAAW,MAAM,UAAU;AAAA,IAC3B,WAAW,SAAS,IAAI,CAAC;AAAA,IACzB,YAAY,SAAS,IAAI,CAAC;AAAA,EAC5B,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/purchase",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -61,7 +61,7 @@
61
61
  "scripts": {
62
62
  "dev": "tsc --watch",
63
63
  "build": "tsup",
64
- "test": "vitest",
64
+ "test": "vitest run",
65
65
  "check-types": "tsc --noEmit",
66
66
  "lint": "npx eslint . --fix --ext .js,.jsx,.ts,.tsx"
67
67
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/stripe/types.ts"],"sourcesContent":["export type ProductId = Lowercase<string>;\nexport type PriceId = `price_${string}`;\n\n/** @deprecated Use StripeConfig instead */\nexport interface Config {\n returnUrl: string;\n cancelUrl: string;\n successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n allowPromotionCodes: boolean;\n payments: Record<ProductId, PriceId>;\n subscriptions: Record<ProductId, PriceId>;\n}\n\nexport interface CreateCheckoutSessionDTO {\n productId: string;\n cancelUrl?: string;\n successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,18 +0,0 @@
1
- type ProductId = Lowercase<string>;
2
- type PriceId = `price_${string}`;
3
- /** @deprecated Use StripeConfig instead */
4
- interface Config {
5
- returnUrl: string;
6
- cancelUrl: string;
7
- successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
8
- allowPromotionCodes: boolean;
9
- payments: Record<ProductId, PriceId>;
10
- subscriptions: Record<ProductId, PriceId>;
11
- }
12
- interface CreateCheckoutSessionDTO {
13
- productId: string;
14
- cancelUrl?: string;
15
- successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
16
- }
17
-
18
- export type { Config, CreateCheckoutSessionDTO, PriceId, ProductId };
@@ -1,18 +0,0 @@
1
- type ProductId = Lowercase<string>;
2
- type PriceId = `price_${string}`;
3
- /** @deprecated Use StripeConfig instead */
4
- interface Config {
5
- returnUrl: string;
6
- cancelUrl: string;
7
- successUrl: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
8
- allowPromotionCodes: boolean;
9
- payments: Record<ProductId, PriceId>;
10
- subscriptions: Record<ProductId, PriceId>;
11
- }
12
- interface CreateCheckoutSessionDTO {
13
- productId: string;
14
- cancelUrl?: string;
15
- successUrl?: `${string}session_id={CHECKOUT_SESSION_ID}${string}`;
16
- }
17
-
18
- export type { Config, CreateCheckoutSessionDTO, PriceId, ProductId };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}