@shware/purchase 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-store/config.cjs +5 -5
- package/dist/app-store/config.cjs.map +1 -1
- package/dist/app-store/config.d.cts +6 -9
- package/dist/app-store/config.d.ts +6 -9
- package/dist/app-store/config.mjs +5 -5
- package/dist/app-store/config.mjs.map +1 -1
- package/dist/app-store/index.d.cts +1 -0
- package/dist/app-store/index.d.ts +1 -0
- package/dist/google-play/config.cjs +94 -1
- package/dist/google-play/config.cjs.map +1 -1
- package/dist/google-play/config.d.cts +36 -1
- package/dist/google-play/config.d.ts +36 -1
- package/dist/google-play/config.mjs +84 -1
- package/dist/google-play/config.mjs.map +1 -1
- package/dist/google-play/index.d.cts +2 -0
- package/dist/google-play/index.d.ts +2 -0
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/dist/stripe/config.cjs +2 -2
- package/dist/stripe/config.cjs.map +1 -1
- package/dist/stripe/config.d.cts +5 -8
- package/dist/stripe/config.d.ts +5 -8
- package/dist/stripe/config.mjs +2 -2
- package/dist/stripe/config.mjs.map +1 -1
- package/dist/stripe/index.d.cts +1 -0
- package/dist/stripe/index.d.ts +1 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +9 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.mjs +1 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -47,8 +47,8 @@ var Subscription = class {
|
|
|
47
47
|
this.products = /* @__PURE__ */ new Map();
|
|
48
48
|
this.defaultProductId = null;
|
|
49
49
|
}
|
|
50
|
-
product = (productId,
|
|
51
|
-
this.products.set(productId,
|
|
50
|
+
product = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
51
|
+
this.products.set(productId, metadata);
|
|
52
52
|
return this;
|
|
53
53
|
};
|
|
54
54
|
default = (defaultProductId) => {
|
|
@@ -68,7 +68,7 @@ var AppStoreConfig = class _AppStoreConfig {
|
|
|
68
68
|
return Array.from(this.products.keys());
|
|
69
69
|
}
|
|
70
70
|
[addMethod] = (subscription) => {
|
|
71
|
-
subscription.products.forEach((
|
|
71
|
+
subscription.products.forEach((metadata, productId) => this.products.set(productId, metadata));
|
|
72
72
|
this.subscriptions.set(subscription.plan, subscription);
|
|
73
73
|
return this;
|
|
74
74
|
};
|
|
@@ -86,9 +86,9 @@ var AppStoreConfig = class _AppStoreConfig {
|
|
|
86
86
|
subscription = (plan) => {
|
|
87
87
|
return new Subscription(this, plan);
|
|
88
88
|
};
|
|
89
|
-
consumable = (productId,
|
|
89
|
+
consumable = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
90
90
|
this.consumables.add(productId);
|
|
91
|
-
this.products.set(productId,
|
|
91
|
+
this.products.set(productId, metadata);
|
|
92
92
|
return this;
|
|
93
93
|
};
|
|
94
94
|
nonConsumable = (productId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms
|
|
1
|
+
{"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\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, Metadata>;\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 metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PL, PI | K, I | K> => {\n this.products.set(productId, metadata);\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\ntype Options = { appId: `${number}`; bundleId: string };\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 readonly appId: string;\n readonly bundleId: string;\n\n private products: Map<string, Metadata | null>;\n private consumables: Set<string>;\n private subscriptions: Map<PE, Subscription<NS, PE, PL, PI>>;\n private nonConsumables: Set<string>;\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((metadata, productId) => this.products.set(productId, metadata));\n this.subscriptions.set(subscription.plan, subscription);\n return this;\n };\n\n private constructor(options: Options) {\n this.appId = options.appId;\n this.bundleId = options.bundleId;\n this.products = new Map();\n this.consumables = new Set();\n this.subscriptions = new Map();\n this.nonConsumables = new Set();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>(options: Options) => {\n return new AppStoreConfig<NS, PE>(options);\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 consumable = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ) => {\n this.consumables.add(productId);\n this.products.set(productId, metadata);\n return this as AppStoreConfig<NS, PE, PL, PI | K>;\n };\n\n nonConsumable = <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => {\n this.nonConsumables.add(productId);\n this.products.set(productId, null);\n return this as AppStoreConfig<NS, PE, PL, PI | K>;\n };\n\n getPlan = (productId: string): PE => {\n for (const [plan, subscription] of this.subscriptions.entries()) {\n if (subscription.products.has(productId)) return plan;\n }\n throw new Error(`Plan not found for product ${productId}`);\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n if (this.consumables.has(productId) || this.nonConsumables.has(productId)) return 'payment';\n for (const subscription of this.subscriptions.values()) {\n if (subscription.products.has(productId)) return 'subscription';\n }\n throw new Error(`Mode not found for product ${productId}`);\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,gBAAe;AAGf,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,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACN;AAC5C,SAAK,SAAS,IAAI,WAAW,QAAQ;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,qBAAwB;AACjC,SAAK,mBAAmB;AACxB,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AAIO,IAAM,iBAAN,MAAM,gBAKX;AAAA,EACS;AAAA,EACA;AAAA,EAED;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,IAAI,aAAuB;AAC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AAS,EAAG,QAAO;AAClF,eAAW,gBAAgB,KAAK,cAAc,OAAO,GAAG;AACtD,UAAI,aAAa,SAAS,IAAI,SAAS,EAAG,QAAO;AAAA,IACnD;AACA,UAAM,IAAI,MAAM,8BAA8B,SAAS,EAAE;AAAA,EAC3D;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"]}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Metadata } from '../types.cjs';
|
|
2
|
+
import 'ms';
|
|
2
3
|
|
|
3
|
-
type CreditConfig = {
|
|
4
|
-
credits: number;
|
|
5
|
-
expiresIn: StringValue;
|
|
6
|
-
};
|
|
7
4
|
declare const addMethod: unique symbol;
|
|
8
5
|
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
6
|
readonly plan: PL;
|
|
10
7
|
readonly config: AppStoreConfig<NS, PE, PL, PI>;
|
|
11
|
-
readonly products: Map<string,
|
|
8
|
+
readonly products: Map<string, Metadata>;
|
|
12
9
|
defaultProductId: I | null;
|
|
13
10
|
constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
|
|
14
|
-
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K,
|
|
11
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => Subscription<NS, PE, PL, PI | K, I | K>;
|
|
15
12
|
default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
|
|
16
13
|
}
|
|
17
14
|
type Options = {
|
|
@@ -30,7 +27,7 @@ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, P
|
|
|
30
27
|
private constructor();
|
|
31
28
|
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => AppStoreConfig<NS_1, PE_1, never, never>;
|
|
32
29
|
subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, PL | K, PI, never>;
|
|
33
|
-
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K,
|
|
30
|
+
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
34
31
|
nonConsumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
35
32
|
getPlan: (productId: string) => PE;
|
|
36
33
|
getMode: (productId: string) => "payment" | "subscription";
|
|
@@ -39,4 +36,4 @@ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, P
|
|
|
39
36
|
getCreditExpiresAt: (productId: string) => string;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
export { AppStoreConfig
|
|
39
|
+
export { AppStoreConfig };
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Metadata } from '../types.js';
|
|
2
|
+
import 'ms';
|
|
2
3
|
|
|
3
|
-
type CreditConfig = {
|
|
4
|
-
credits: number;
|
|
5
|
-
expiresIn: StringValue;
|
|
6
|
-
};
|
|
7
4
|
declare const addMethod: unique symbol;
|
|
8
5
|
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
6
|
readonly plan: PL;
|
|
10
7
|
readonly config: AppStoreConfig<NS, PE, PL, PI>;
|
|
11
|
-
readonly products: Map<string,
|
|
8
|
+
readonly products: Map<string, Metadata>;
|
|
12
9
|
defaultProductId: I | null;
|
|
13
10
|
constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
|
|
14
|
-
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K,
|
|
11
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => Subscription<NS, PE, PL, PI | K, I | K>;
|
|
15
12
|
default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
|
|
16
13
|
}
|
|
17
14
|
type Options = {
|
|
@@ -30,7 +27,7 @@ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, P
|
|
|
30
27
|
private constructor();
|
|
31
28
|
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => AppStoreConfig<NS_1, PE_1, never, never>;
|
|
32
29
|
subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, PL | K, PI, never>;
|
|
33
|
-
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K,
|
|
30
|
+
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
34
31
|
nonConsumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
35
32
|
getPlan: (productId: string) => PE;
|
|
36
33
|
getMode: (productId: string) => "payment" | "subscription";
|
|
@@ -39,4 +36,4 @@ declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, P
|
|
|
39
36
|
getCreditExpiresAt: (productId: string) => string;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
export { AppStoreConfig
|
|
39
|
+
export { AppStoreConfig };
|
|
@@ -13,8 +13,8 @@ var Subscription = class {
|
|
|
13
13
|
this.products = /* @__PURE__ */ new Map();
|
|
14
14
|
this.defaultProductId = null;
|
|
15
15
|
}
|
|
16
|
-
product = (productId,
|
|
17
|
-
this.products.set(productId,
|
|
16
|
+
product = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
17
|
+
this.products.set(productId, metadata);
|
|
18
18
|
return this;
|
|
19
19
|
};
|
|
20
20
|
default = (defaultProductId) => {
|
|
@@ -34,7 +34,7 @@ var AppStoreConfig = class _AppStoreConfig {
|
|
|
34
34
|
return Array.from(this.products.keys());
|
|
35
35
|
}
|
|
36
36
|
[addMethod] = (subscription) => {
|
|
37
|
-
subscription.products.forEach((
|
|
37
|
+
subscription.products.forEach((metadata, productId) => this.products.set(productId, metadata));
|
|
38
38
|
this.subscriptions.set(subscription.plan, subscription);
|
|
39
39
|
return this;
|
|
40
40
|
};
|
|
@@ -52,9 +52,9 @@ var AppStoreConfig = class _AppStoreConfig {
|
|
|
52
52
|
subscription = (plan) => {
|
|
53
53
|
return new Subscription(this, plan);
|
|
54
54
|
};
|
|
55
|
-
consumable = (productId,
|
|
55
|
+
consumable = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
56
56
|
this.consumables.add(productId);
|
|
57
|
-
this.products.set(productId,
|
|
57
|
+
this.products.set(productId, metadata);
|
|
58
58
|
return this;
|
|
59
59
|
};
|
|
60
60
|
nonConsumable = (productId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms
|
|
1
|
+
{"version":3,"sources":["../../src/app-store/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { Metadata } from '../types';\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, Metadata>;\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 metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PL, PI | K, I | K> => {\n this.products.set(productId, metadata);\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\ntype Options = { appId: `${number}`; bundleId: string };\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 readonly appId: string;\n readonly bundleId: string;\n\n private products: Map<string, Metadata | null>;\n private consumables: Set<string>;\n private subscriptions: Map<PE, Subscription<NS, PE, PL, PI>>;\n private nonConsumables: Set<string>;\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((metadata, productId) => this.products.set(productId, metadata));\n this.subscriptions.set(subscription.plan, subscription);\n return this;\n };\n\n private constructor(options: Options) {\n this.appId = options.appId;\n this.bundleId = options.bundleId;\n this.products = new Map();\n this.consumables = new Set();\n this.subscriptions = new Map();\n this.nonConsumables = new Set();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string>(options: Options) => {\n return new AppStoreConfig<NS, PE>(options);\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 consumable = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ) => {\n this.consumables.add(productId);\n this.products.set(productId, metadata);\n return this as AppStoreConfig<NS, PE, PL, PI | K>;\n };\n\n nonConsumable = <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => {\n this.nonConsumables.add(productId);\n this.products.set(productId, null);\n return this as AppStoreConfig<NS, PE, PL, PI | K>;\n };\n\n getPlan = (productId: string): PE => {\n for (const [plan, subscription] of this.subscriptions.entries()) {\n if (subscription.products.has(productId)) return plan;\n }\n throw new Error(`Plan not found for product ${productId}`);\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n if (this.consumables.has(productId) || this.nonConsumables.has(productId)) return 'payment';\n for (const subscription of this.subscriptions.values()) {\n if (subscription.products.has(productId)) return 'subscription';\n }\n throw new Error(`Mode not found for product ${productId}`);\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,QAAQ;AAGf,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,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACN;AAC5C,SAAK,SAAS,IAAI,WAAW,QAAQ;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CAAC,qBAAwB;AACjC,SAAK,mBAAmB;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,SAAS,IAAI,SAAS,EAAG,QAAO;AAAA,IACnD;AACA,UAAM,IAAI,MAAM,8BAA8B,SAAS,EAAE;AAAA,EAC3D;AAAA,EAEA,UAAU,CAAC,cAAkD;AAC3D,QAAI,KAAK,YAAY,IAAI,SAAS,KAAK,KAAK,eAAe,IAAI,SAAS,EAAG,QAAO;AAClF,eAAW,gBAAgB,KAAK,cAAc,OAAO,GAAG;AACtD,UAAI,aAAa,SAAS,IAAI,SAAS,EAAG,QAAO;AAAA,IACnD;AACA,UAAM,IAAI,MAAM,8BAA8B,SAAS,EAAE;AAAA,EAC3D;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,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/google-play/config.ts
|
|
@@ -23,7 +33,90 @@ __export(config_exports, {
|
|
|
23
33
|
GooglePlayConfig: () => GooglePlayConfig
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(config_exports);
|
|
26
|
-
var
|
|
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
|
+
productId;
|
|
41
|
+
config;
|
|
42
|
+
plans;
|
|
43
|
+
defaultPlans;
|
|
44
|
+
constructor(config, productId) {
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.productId = productId;
|
|
47
|
+
this.plans = /* @__PURE__ */ new Map();
|
|
48
|
+
this.defaultPlans = /* @__PURE__ */ new Set();
|
|
49
|
+
}
|
|
50
|
+
basePlan = (planId, plan, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
51
|
+
this.plans.set(planId, { ...metadata, plan });
|
|
52
|
+
return this;
|
|
53
|
+
};
|
|
54
|
+
default = (planIds) => {
|
|
55
|
+
planIds.forEach((planId) => this.defaultPlans.add(planId));
|
|
56
|
+
this.config[addMethod](this);
|
|
57
|
+
return this.config;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
var GooglePlayConfig = class _GooglePlayConfig {
|
|
61
|
+
package;
|
|
62
|
+
audience;
|
|
63
|
+
onetimes;
|
|
64
|
+
subscriptions;
|
|
65
|
+
products;
|
|
66
|
+
[addMethod] = (subscription) => {
|
|
67
|
+
subscription.plans.forEach((metadata, planId) => {
|
|
68
|
+
this.products.set(this.getId(subscription.productId, planId), metadata);
|
|
69
|
+
});
|
|
70
|
+
this.subscriptions.set(subscription.productId, subscription);
|
|
71
|
+
return this;
|
|
72
|
+
};
|
|
73
|
+
getId = (productId, planId) => `${productId}:${planId}`;
|
|
74
|
+
constructor(options) {
|
|
75
|
+
this.package = options.package;
|
|
76
|
+
this.audience = options.audience;
|
|
77
|
+
this.products = /* @__PURE__ */ new Map();
|
|
78
|
+
this.onetimes = /* @__PURE__ */ new Set();
|
|
79
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
80
|
+
}
|
|
81
|
+
static create = (options) => {
|
|
82
|
+
return new _GooglePlayConfig(options);
|
|
83
|
+
};
|
|
84
|
+
subscription = (productId) => {
|
|
85
|
+
return new Subscription(this, productId);
|
|
86
|
+
};
|
|
87
|
+
onetime = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
88
|
+
this.onetimes.add(productId);
|
|
89
|
+
this.products.set(productId, metadata);
|
|
90
|
+
return this;
|
|
91
|
+
};
|
|
92
|
+
getPlan = (productId, planId) => {
|
|
93
|
+
const id = this.getId(productId, planId);
|
|
94
|
+
const metadata = this.products.get(id);
|
|
95
|
+
(0, import_utils.invariant)(metadata, `Product not found for ${id}`);
|
|
96
|
+
(0, import_utils.invariant)(metadata.plan, `Plan not found for ${id}`);
|
|
97
|
+
return metadata.plan;
|
|
98
|
+
};
|
|
99
|
+
getMode = (productId) => {
|
|
100
|
+
if (this.onetimes.has(productId)) return "payment";
|
|
101
|
+
if (this.subscriptions.has(productId)) return "subscription";
|
|
102
|
+
throw new Error(`Mode not found for product ${productId}`);
|
|
103
|
+
};
|
|
104
|
+
getCreditAmount = (productId, planId) => {
|
|
105
|
+
const id = this.getId(productId, planId);
|
|
106
|
+
const metadata = this.products.get(id);
|
|
107
|
+
(0, import_utils.invariant)(metadata, `Product not found for ${id}`);
|
|
108
|
+
return metadata.credits;
|
|
109
|
+
};
|
|
110
|
+
getCreditExpiresIn = (productId, planId) => {
|
|
111
|
+
const id = this.getId(productId, planId);
|
|
112
|
+
const metadata = this.products.get(id);
|
|
113
|
+
(0, import_utils.invariant)(metadata, `Product not found for ${id}`);
|
|
114
|
+
return (0, import_ms.default)(metadata.expiresIn);
|
|
115
|
+
};
|
|
116
|
+
getCreditExpiresAt = (productId, planId) => {
|
|
117
|
+
const expiresIn = this.getCreditExpiresIn(productId, planId);
|
|
118
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
119
|
+
};
|
|
27
120
|
};
|
|
28
121
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
122
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { IsUnique, Metadata } from '../types';\n\nconst addMethod = Symbol('addMethod');\n\nclass Subscription<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n I extends Lowercase<string> = never,\n> {\n readonly productId: string;\n readonly config: GooglePlayConfig<NS, PE, PI>;\n readonly plans: Map<string, Metadata & { plan?: PE }>;\n readonly defaultPlans: Set<string>;\n\n constructor(config: GooglePlayConfig<NS, PE, PI>, productId: string) {\n this.config = config;\n this.productId = productId;\n this.plans = new Map();\n this.defaultPlans = new Set();\n }\n\n basePlan = <K extends Lowercase<string>>(\n planId: K extends I ? never : K,\n plan: PE,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PI, I | K> => {\n this.plans.set(planId, { ...metadata, plan });\n return this as Subscription<NS, PE, PI, I | K>;\n };\n\n default = <const T extends readonly [I, ...I[]]>(\n planIds: T & (IsUnique<T> extends true ? unknown : never)\n ) => {\n planIds.forEach((planId) => this.defaultPlans.add(planId));\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = { package: string; audience: string };\n\nexport class GooglePlayConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n> {\n readonly package: string;\n readonly audience: string;\n private onetimes: Set<string>;\n private subscriptions: Map<string, Subscription<NS, PE, PI>>;\n private products: Map<string, (Metadata & { plan?: PE }) | null>;\n\n [addMethod] = (subscription: Subscription<NS, PE, PI>) => {\n subscription.plans.forEach((metadata, planId) => {\n this.products.set(this.getId(subscription.productId, planId), metadata);\n });\n this.subscriptions.set(subscription.productId, subscription);\n return this;\n };\n\n private getId = (productId: string, planId: string) => `${productId}:${planId}`;\n\n private constructor(options: Options) {\n this.package = options.package;\n this.audience = options.audience;\n this.products = new Map();\n this.onetimes = new Set();\n this.subscriptions = new Map();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string = string>(options: Options) => {\n return new GooglePlayConfig<NS, PE>(options);\n };\n\n subscription = <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => {\n return new Subscription<NS, PE, PI | K>(this, productId);\n };\n\n onetime = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ) => {\n this.onetimes.add(productId);\n this.products.set(productId, metadata);\n return this;\n };\n\n getPlan = (productId: string, planId: string): PE => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n invariant(metadata.plan, `Plan not found for ${id}`);\n return metadata.plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n if (this.onetimes.has(productId)) return 'payment';\n if (this.subscriptions.has(productId)) return 'subscription';\n throw new Error(`Mode not found for product ${productId}`);\n };\n\n getCreditAmount = (productId: string, planId: string): number => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n return metadata.credits;\n };\n\n private getCreditExpiresIn = (productId: string, planId: string): number => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n return ms(metadata.expiresIn);\n };\n\n getCreditExpiresAt = (productId: string, planId: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, planId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,gBAAe;AAGf,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,eAAN,MAKE;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAsC,WAAmB;AACnE,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,QAAQ,oBAAI,IAAI;AACrB,SAAK,eAAe,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAEA,WAAW,CACT,QACA,MACA,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACd;AACpC,SAAK,MAAM,IAAI,QAAQ,EAAE,GAAG,UAAU,KAAK,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CACR,YACG;AACH,YAAQ,QAAQ,CAAC,WAAW,KAAK,aAAa,IAAI,MAAM,CAAC;AACzD,SAAK,OAAO,SAAS,EAAE,IAAa;AACpC,WAAO,KAAK;AAAA,EACd;AACF;AAIO,IAAM,mBAAN,MAAM,kBAIX;AAAA,EACS;AAAA,EACA;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EAER,CAAC,SAAS,IAAI,CAAC,iBAA2C;AACxD,iBAAa,MAAM,QAAQ,CAAC,UAAU,WAAW;AAC/C,WAAK,SAAS,IAAI,KAAK,MAAM,aAAa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AAI,EAAE;AACrC,gCAAU,UAAU,yBAAyB,EAAE,EAAE;AACjD,WAAO,SAAS;AAAA,EAClB;AAAA,EAEQ,qBAAqB,CAAC,WAAmB,WAA2B;AAC1E,UAAM,KAAK,KAAK,MAAM,WAAW,MAAM;AACvC,UAAM,WAAW,KAAK,SAAS,IAAI,EAAE;AACrC,gCAAU,UAAU,yBAAyB,EAAE,EAAE;AACjD,eAAO,UAAAA,SAAG,SAAS,SAAS;AAAA,EAC9B;AAAA,EAEA,qBAAqB,CAAC,WAAmB,WAA2B;AAClE,UAAM,YAAY,KAAK,mBAAmB,WAAW,MAAM;AAC3D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":["ms"]}
|
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import { Metadata, IsUnique } from '../types.cjs';
|
|
2
|
+
import 'ms';
|
|
3
|
+
|
|
4
|
+
declare const addMethod: unique symbol;
|
|
5
|
+
declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends Lowercase<string> = never> {
|
|
6
|
+
readonly productId: string;
|
|
7
|
+
readonly config: GooglePlayConfig<NS, PE, PI>;
|
|
8
|
+
readonly plans: Map<string, Metadata & {
|
|
9
|
+
plan?: PE;
|
|
10
|
+
}>;
|
|
11
|
+
readonly defaultPlans: Set<string>;
|
|
12
|
+
constructor(config: GooglePlayConfig<NS, PE, PI>, productId: string);
|
|
13
|
+
basePlan: <K extends Lowercase<string>>(planId: K extends I ? never : K, plan: PE, metadata?: Metadata) => Subscription<NS, PE, PI, I | K>;
|
|
14
|
+
default: <const T extends readonly [I, ...I[]]>(planIds: T & (IsUnique<T> extends true ? unknown : never)) => GooglePlayConfig<NS, PE, PI>;
|
|
15
|
+
}
|
|
16
|
+
type Options = {
|
|
17
|
+
package: string;
|
|
18
|
+
audience: string;
|
|
19
|
+
};
|
|
20
|
+
declare class GooglePlayConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
21
|
+
readonly package: string;
|
|
22
|
+
readonly audience: string;
|
|
23
|
+
private onetimes;
|
|
24
|
+
private subscriptions;
|
|
25
|
+
private products;
|
|
26
|
+
[addMethod]: (subscription: Subscription<NS, PE, PI>) => this;
|
|
27
|
+
private getId;
|
|
28
|
+
private constructor();
|
|
29
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string = string>(options: Options) => GooglePlayConfig<NS_1, PE_1, never>;
|
|
30
|
+
subscription: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => Subscription<NS, PE, PI | K, never>;
|
|
31
|
+
onetime: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => this;
|
|
32
|
+
getPlan: (productId: string, planId: string) => PE;
|
|
33
|
+
getMode: (productId: string) => "payment" | "subscription";
|
|
34
|
+
getCreditAmount: (productId: string, planId: string) => number;
|
|
35
|
+
private getCreditExpiresIn;
|
|
36
|
+
getCreditExpiresAt: (productId: string, planId: string) => string;
|
|
2
37
|
}
|
|
3
38
|
|
|
4
39
|
export { GooglePlayConfig };
|
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
import { Metadata, IsUnique } from '../types.js';
|
|
2
|
+
import 'ms';
|
|
3
|
+
|
|
4
|
+
declare const addMethod: unique symbol;
|
|
5
|
+
declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends Lowercase<string> = never> {
|
|
6
|
+
readonly productId: string;
|
|
7
|
+
readonly config: GooglePlayConfig<NS, PE, PI>;
|
|
8
|
+
readonly plans: Map<string, Metadata & {
|
|
9
|
+
plan?: PE;
|
|
10
|
+
}>;
|
|
11
|
+
readonly defaultPlans: Set<string>;
|
|
12
|
+
constructor(config: GooglePlayConfig<NS, PE, PI>, productId: string);
|
|
13
|
+
basePlan: <K extends Lowercase<string>>(planId: K extends I ? never : K, plan: PE, metadata?: Metadata) => Subscription<NS, PE, PI, I | K>;
|
|
14
|
+
default: <const T extends readonly [I, ...I[]]>(planIds: T & (IsUnique<T> extends true ? unknown : never)) => GooglePlayConfig<NS, PE, PI>;
|
|
15
|
+
}
|
|
16
|
+
type Options = {
|
|
17
|
+
package: string;
|
|
18
|
+
audience: string;
|
|
19
|
+
};
|
|
20
|
+
declare class GooglePlayConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
21
|
+
readonly package: string;
|
|
22
|
+
readonly audience: string;
|
|
23
|
+
private onetimes;
|
|
24
|
+
private subscriptions;
|
|
25
|
+
private products;
|
|
26
|
+
[addMethod]: (subscription: Subscription<NS, PE, PI>) => this;
|
|
27
|
+
private getId;
|
|
28
|
+
private constructor();
|
|
29
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string = string>(options: Options) => GooglePlayConfig<NS_1, PE_1, never>;
|
|
30
|
+
subscription: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => Subscription<NS, PE, PI | K, never>;
|
|
31
|
+
onetime: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => this;
|
|
32
|
+
getPlan: (productId: string, planId: string) => PE;
|
|
33
|
+
getMode: (productId: string) => "payment" | "subscription";
|
|
34
|
+
getCreditAmount: (productId: string, planId: string) => number;
|
|
35
|
+
private getCreditExpiresIn;
|
|
36
|
+
getCreditExpiresAt: (productId: string, planId: string) => string;
|
|
2
37
|
}
|
|
3
38
|
|
|
4
39
|
export { GooglePlayConfig };
|
|
@@ -1,5 +1,88 @@
|
|
|
1
1
|
// src/google-play/config.ts
|
|
2
|
-
|
|
2
|
+
import { invariant } from "@shware/utils";
|
|
3
|
+
import ms from "ms";
|
|
4
|
+
var addMethod = /* @__PURE__ */ Symbol("addMethod");
|
|
5
|
+
var Subscription = class {
|
|
6
|
+
productId;
|
|
7
|
+
config;
|
|
8
|
+
plans;
|
|
9
|
+
defaultPlans;
|
|
10
|
+
constructor(config, productId) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.productId = productId;
|
|
13
|
+
this.plans = /* @__PURE__ */ new Map();
|
|
14
|
+
this.defaultPlans = /* @__PURE__ */ new Set();
|
|
15
|
+
}
|
|
16
|
+
basePlan = (planId, plan, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
17
|
+
this.plans.set(planId, { ...metadata, plan });
|
|
18
|
+
return this;
|
|
19
|
+
};
|
|
20
|
+
default = (planIds) => {
|
|
21
|
+
planIds.forEach((planId) => this.defaultPlans.add(planId));
|
|
22
|
+
this.config[addMethod](this);
|
|
23
|
+
return this.config;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
var GooglePlayConfig = class _GooglePlayConfig {
|
|
27
|
+
package;
|
|
28
|
+
audience;
|
|
29
|
+
onetimes;
|
|
30
|
+
subscriptions;
|
|
31
|
+
products;
|
|
32
|
+
[addMethod] = (subscription) => {
|
|
33
|
+
subscription.plans.forEach((metadata, planId) => {
|
|
34
|
+
this.products.set(this.getId(subscription.productId, planId), metadata);
|
|
35
|
+
});
|
|
36
|
+
this.subscriptions.set(subscription.productId, subscription);
|
|
37
|
+
return this;
|
|
38
|
+
};
|
|
39
|
+
getId = (productId, planId) => `${productId}:${planId}`;
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.package = options.package;
|
|
42
|
+
this.audience = options.audience;
|
|
43
|
+
this.products = /* @__PURE__ */ new Map();
|
|
44
|
+
this.onetimes = /* @__PURE__ */ new Set();
|
|
45
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
46
|
+
}
|
|
47
|
+
static create = (options) => {
|
|
48
|
+
return new _GooglePlayConfig(options);
|
|
49
|
+
};
|
|
50
|
+
subscription = (productId) => {
|
|
51
|
+
return new Subscription(this, productId);
|
|
52
|
+
};
|
|
53
|
+
onetime = (productId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
54
|
+
this.onetimes.add(productId);
|
|
55
|
+
this.products.set(productId, metadata);
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
getPlan = (productId, planId) => {
|
|
59
|
+
const id = this.getId(productId, planId);
|
|
60
|
+
const metadata = this.products.get(id);
|
|
61
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
62
|
+
invariant(metadata.plan, `Plan not found for ${id}`);
|
|
63
|
+
return metadata.plan;
|
|
64
|
+
};
|
|
65
|
+
getMode = (productId) => {
|
|
66
|
+
if (this.onetimes.has(productId)) return "payment";
|
|
67
|
+
if (this.subscriptions.has(productId)) return "subscription";
|
|
68
|
+
throw new Error(`Mode not found for product ${productId}`);
|
|
69
|
+
};
|
|
70
|
+
getCreditAmount = (productId, planId) => {
|
|
71
|
+
const id = this.getId(productId, planId);
|
|
72
|
+
const metadata = this.products.get(id);
|
|
73
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
74
|
+
return metadata.credits;
|
|
75
|
+
};
|
|
76
|
+
getCreditExpiresIn = (productId, planId) => {
|
|
77
|
+
const id = this.getId(productId, planId);
|
|
78
|
+
const metadata = this.products.get(id);
|
|
79
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
80
|
+
return ms(metadata.expiresIn);
|
|
81
|
+
};
|
|
82
|
+
getCreditExpiresAt = (productId, planId) => {
|
|
83
|
+
const expiresIn = this.getCreditExpiresIn(productId, planId);
|
|
84
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
85
|
+
};
|
|
3
86
|
};
|
|
4
87
|
export {
|
|
5
88
|
GooglePlayConfig
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/google-play/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms from 'ms';\nimport type { IsUnique, Metadata } from '../types';\n\nconst addMethod = Symbol('addMethod');\n\nclass Subscription<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n I extends Lowercase<string> = never,\n> {\n readonly productId: string;\n readonly config: GooglePlayConfig<NS, PE, PI>;\n readonly plans: Map<string, Metadata & { plan?: PE }>;\n readonly defaultPlans: Set<string>;\n\n constructor(config: GooglePlayConfig<NS, PE, PI>, productId: string) {\n this.config = config;\n this.productId = productId;\n this.plans = new Map();\n this.defaultPlans = new Set();\n }\n\n basePlan = <K extends Lowercase<string>>(\n planId: K extends I ? never : K,\n plan: PE,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, PI, I | K> => {\n this.plans.set(planId, { ...metadata, plan });\n return this as Subscription<NS, PE, PI, I | K>;\n };\n\n default = <const T extends readonly [I, ...I[]]>(\n planIds: T & (IsUnique<T> extends true ? unknown : never)\n ) => {\n planIds.forEach((planId) => this.defaultPlans.add(planId));\n this.config[addMethod](this as never);\n return this.config;\n };\n}\n\ntype Options = { package: string; audience: string };\n\nexport class GooglePlayConfig<\n NS extends Lowercase<string> = Lowercase<string>,\n PE extends string = string,\n PI extends string = never,\n> {\n readonly package: string;\n readonly audience: string;\n private onetimes: Set<string>;\n private subscriptions: Map<string, Subscription<NS, PE, PI>>;\n private products: Map<string, (Metadata & { plan?: PE }) | null>;\n\n [addMethod] = (subscription: Subscription<NS, PE, PI>) => {\n subscription.plans.forEach((metadata, planId) => {\n this.products.set(this.getId(subscription.productId, planId), metadata);\n });\n this.subscriptions.set(subscription.productId, subscription);\n return this;\n };\n\n private getId = (productId: string, planId: string) => `${productId}:${planId}`;\n\n private constructor(options: Options) {\n this.package = options.package;\n this.audience = options.audience;\n this.products = new Map();\n this.onetimes = new Set();\n this.subscriptions = new Map();\n }\n\n static create = <NS extends Lowercase<string>, PE extends string = string>(options: Options) => {\n return new GooglePlayConfig<NS, PE>(options);\n };\n\n subscription = <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => {\n return new Subscription<NS, PE, PI | K>(this, productId);\n };\n\n onetime = <K extends `${NS}.${Lowercase<string>}`>(\n productId: K extends PI ? never : K,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ) => {\n this.onetimes.add(productId);\n this.products.set(productId, metadata);\n return this;\n };\n\n getPlan = (productId: string, planId: string): PE => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n invariant(metadata.plan, `Plan not found for ${id}`);\n return metadata.plan;\n };\n\n getMode = (productId: string): 'payment' | 'subscription' => {\n if (this.onetimes.has(productId)) return 'payment';\n if (this.subscriptions.has(productId)) return 'subscription';\n throw new Error(`Mode not found for product ${productId}`);\n };\n\n getCreditAmount = (productId: string, planId: string): number => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n return metadata.credits;\n };\n\n private getCreditExpiresIn = (productId: string, planId: string): number => {\n const id = this.getId(productId, planId);\n const metadata = this.products.get(id);\n invariant(metadata, `Product not found for ${id}`);\n return ms(metadata.expiresIn);\n };\n\n getCreditExpiresAt = (productId: string, planId: string): string => {\n const expiresIn = this.getCreditExpiresIn(productId, planId);\n return new Date(Date.now() + expiresIn).toISOString();\n };\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAGf,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,eAAN,MAKE;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAsC,WAAmB;AACnE,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,QAAQ,oBAAI,IAAI;AACrB,SAAK,eAAe,oBAAI,IAAI;AAAA,EAC9B;AAAA,EAEA,WAAW,CACT,QACA,MACA,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACd;AACpC,SAAK,MAAM,IAAI,QAAQ,EAAE,GAAG,UAAU,KAAK,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,CACR,YACG;AACH,YAAQ,QAAQ,CAAC,WAAW,KAAK,aAAa,IAAI,MAAM,CAAC;AACz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,cAAkD;AAC3D,QAAI,KAAK,SAAS,IAAI,SAAS,EAAG,QAAO;AACzC,QAAI,KAAK,cAAc,IAAI,SAAS,EAAG,QAAO;AAC9C,UAAM,IAAI,MAAM,8BAA8B,SAAS,EAAE;AAAA,EAC3D;AAAA,EAEA,kBAAkB,CAAC,WAAmB,WAA2B;AAC/D,UAAM,KAAK,KAAK,MAAM,WAAW,MAAM;AACvC,UAAM,WAAW,KAAK,SAAS,IAAI,EAAE;AACrC,cAAU,UAAU,yBAAyB,EAAE,EAAE;AACjD,WAAO,SAAS;AAAA,EAClB;AAAA,EAEQ,qBAAqB,CAAC,WAAmB,WAA2B;AAC1E,UAAM,KAAK,KAAK,MAAM,WAAW,MAAM;AACvC,UAAM,WAAW,KAAK,SAAS,IAAI,EAAE;AACrC,cAAU,UAAU,yBAAyB,EAAE,EAAE;AACjD,WAAO,GAAG,SAAS,SAAS;AAAA,EAC9B;AAAA,EAEA,qBAAqB,CAAC,WAAmB,WAA2B;AAClE,UAAM,YAAY,KAAK,mBAAmB,WAAW,MAAM;AAC3D,WAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,EAAE,YAAY;AAAA,EACtD;AACF;","names":[]}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from './real-time-developer-notification.cjs';
|
|
2
2
|
export { GooglePlayConfig } from './config.cjs';
|
|
3
|
+
import '../types.cjs';
|
|
4
|
+
import 'ms';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from './real-time-developer-notification.js';
|
|
2
2
|
export { GooglePlayConfig } from './config.js';
|
|
3
|
+
import '../types.js';
|
|
4
|
+
import 'ms';
|
package/dist/index.cjs
CHANGED
|
@@ -23,17 +23,26 @@ __export(index_exports, {
|
|
|
23
23
|
ALL_PLATFORMS: () => import_subscription.ALL_PLATFORMS,
|
|
24
24
|
ALL_SUBSCRIPTION_STATUS: () => import_subscription.ALL_SUBSCRIPTION_STATUS,
|
|
25
25
|
AVAILABLE_STATUS: () => import_subscription.AVAILABLE_STATUS,
|
|
26
|
+
AppStoreConfig: () => import_config.AppStoreConfig,
|
|
27
|
+
GooglePlayConfig: () => import_config2.GooglePlayConfig,
|
|
26
28
|
Platform: () => import_subscription.Platform,
|
|
29
|
+
StripeConfig: () => import_config3.StripeConfig,
|
|
27
30
|
SubscriptionStatus: () => import_subscription.SubscriptionStatus
|
|
28
31
|
});
|
|
29
32
|
module.exports = __toCommonJS(index_exports);
|
|
30
33
|
var import_subscription = require("./subscription/index.cjs");
|
|
34
|
+
var import_config = require("./app-store/config.cjs");
|
|
35
|
+
var import_config2 = require("./google-play/config.cjs");
|
|
36
|
+
var import_config3 = require("./stripe/config.cjs");
|
|
31
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
38
|
0 && (module.exports = {
|
|
33
39
|
ALL_PLATFORMS,
|
|
34
40
|
ALL_SUBSCRIPTION_STATUS,
|
|
35
41
|
AVAILABLE_STATUS,
|
|
42
|
+
AppStoreConfig,
|
|
43
|
+
GooglePlayConfig,
|
|
36
44
|
Platform,
|
|
45
|
+
StripeConfig,
|
|
37
46
|
SubscriptionStatus
|
|
38
47
|
});
|
|
39
48
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Platform,\n SubscriptionStatus,\n ALL_PLATFORMS,\n AVAILABLE_STATUS,\n ALL_SUBSCRIPTION_STATUS,\n} from './subscription/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAMO;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Platform,\n SubscriptionStatus,\n ALL_PLATFORMS,\n AVAILABLE_STATUS,\n ALL_SUBSCRIPTION_STATUS,\n} from './subscription/index';\n\nexport { AppStoreConfig } from './app-store/config';\nexport { GooglePlayConfig } from './google-play/config';\nexport { StripeConfig } from './stripe/config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAMO;AAEP,oBAA+B;AAC/B,IAAAA,iBAAiC;AACjC,IAAAA,iBAA6B;","names":["import_config"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from './subscription/index.cjs';
|
|
2
|
+
export { AppStoreConfig } from './app-store/config.cjs';
|
|
3
|
+
export { GooglePlayConfig } from './google-play/config.cjs';
|
|
4
|
+
export { StripeConfig } from './stripe/config.cjs';
|
|
5
|
+
import './types.cjs';
|
|
6
|
+
import 'ms';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export { ALL_PLATFORMS, ALL_SUBSCRIPTION_STATUS, AVAILABLE_STATUS, Platform, SubscriptionStatus } from './subscription/index.js';
|
|
2
|
+
export { AppStoreConfig } from './app-store/config.js';
|
|
3
|
+
export { GooglePlayConfig } from './google-play/config.js';
|
|
4
|
+
export { StripeConfig } from './stripe/config.js';
|
|
5
|
+
import './types.js';
|
|
6
|
+
import 'ms';
|
package/dist/index.mjs
CHANGED
|
@@ -6,11 +6,17 @@ import {
|
|
|
6
6
|
AVAILABLE_STATUS,
|
|
7
7
|
ALL_SUBSCRIPTION_STATUS
|
|
8
8
|
} from "./subscription/index.mjs";
|
|
9
|
+
import { AppStoreConfig } from "./app-store/config.mjs";
|
|
10
|
+
import { GooglePlayConfig } from "./google-play/config.mjs";
|
|
11
|
+
import { StripeConfig } from "./stripe/config.mjs";
|
|
9
12
|
export {
|
|
10
13
|
ALL_PLATFORMS,
|
|
11
14
|
ALL_SUBSCRIPTION_STATUS,
|
|
12
15
|
AVAILABLE_STATUS,
|
|
16
|
+
AppStoreConfig,
|
|
17
|
+
GooglePlayConfig,
|
|
13
18
|
Platform,
|
|
19
|
+
StripeConfig,
|
|
14
20
|
SubscriptionStatus
|
|
15
21
|
};
|
|
16
22
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Platform,\n SubscriptionStatus,\n ALL_PLATFORMS,\n AVAILABLE_STATUS,\n ALL_SUBSCRIPTION_STATUS,\n} from './subscription/index';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n Platform,\n SubscriptionStatus,\n ALL_PLATFORMS,\n AVAILABLE_STATUS,\n ALL_SUBSCRIPTION_STATUS,\n} from './subscription/index';\n\nexport { AppStoreConfig } from './app-store/config';\nexport { GooglePlayConfig } from './google-play/config';\nexport { StripeConfig } from './stripe/config';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;","names":[]}
|
package/dist/stripe/config.cjs
CHANGED
|
@@ -49,8 +49,8 @@ var Product = class {
|
|
|
49
49
|
this.prices = /* @__PURE__ */ new Map();
|
|
50
50
|
this.defaultPriceId = null;
|
|
51
51
|
}
|
|
52
|
-
price = (priceId,
|
|
53
|
-
this.prices.set(priceId,
|
|
52
|
+
price = (priceId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
53
|
+
this.prices.set(priceId, metadata);
|
|
54
54
|
return this;
|
|
55
55
|
};
|
|
56
56
|
default = (defaultPriceId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms
|
|
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 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,gBAAe;AAKf,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,UAAN,MAKE;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEA,YAAY,QAAkC,IAAY,OAAkB,MAAM;AAChF,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,SAAS,oBAAI,IAAI;AACtB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,QAAQ,CACN,SACA,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACnB;AAC/B,SAAK,OAAO,IAAI,SAAS,QAAQ;AACjC,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;AA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AAQ,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"]}
|
package/dist/stripe/config.d.cts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Metadata } from '../types.cjs';
|
|
2
|
+
import 'ms';
|
|
2
3
|
|
|
3
4
|
type PriceId = `price_${string}`;
|
|
4
|
-
type CreditConfig = {
|
|
5
|
-
credits: number;
|
|
6
|
-
expiresIn: StringValue;
|
|
7
|
-
};
|
|
8
5
|
declare const addMethod: unique symbol;
|
|
9
6
|
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
|
|
10
7
|
readonly id: string;
|
|
11
8
|
readonly config: StripeConfig<NS, PE, PI>;
|
|
12
9
|
readonly plan: PE | null;
|
|
13
|
-
readonly prices: Map<PriceId,
|
|
10
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
14
11
|
defaultPriceId: I | null;
|
|
15
12
|
constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
|
|
16
|
-
price: <K extends PriceId>(priceId: K extends I ? never : K,
|
|
13
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, PI, I | K>;
|
|
17
14
|
default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
|
|
18
15
|
}
|
|
19
16
|
type Options = {
|
|
@@ -41,4 +38,4 @@ declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE
|
|
|
41
38
|
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
export { type
|
|
41
|
+
export { type PriceId, StripeConfig };
|
package/dist/stripe/config.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Metadata } from '../types.js';
|
|
2
|
+
import 'ms';
|
|
2
3
|
|
|
3
4
|
type PriceId = `price_${string}`;
|
|
4
|
-
type CreditConfig = {
|
|
5
|
-
credits: number;
|
|
6
|
-
expiresIn: StringValue;
|
|
7
|
-
};
|
|
8
5
|
declare const addMethod: unique symbol;
|
|
9
6
|
declare class Product<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never, I extends PriceId = never> {
|
|
10
7
|
readonly id: string;
|
|
11
8
|
readonly config: StripeConfig<NS, PE, PI>;
|
|
12
9
|
readonly plan: PE | null;
|
|
13
|
-
readonly prices: Map<PriceId,
|
|
10
|
+
readonly prices: Map<PriceId, Metadata>;
|
|
14
11
|
defaultPriceId: I | null;
|
|
15
12
|
constructor(config: StripeConfig<NS, PE, PI>, id: string, plan?: PE | null);
|
|
16
|
-
price: <K extends PriceId>(priceId: K extends I ? never : K,
|
|
13
|
+
price: <K extends PriceId>(priceId: K extends I ? never : K, metadata?: Metadata) => Product<NS, PE, PI, I | K>;
|
|
17
14
|
default: (defaultPriceId: I) => StripeConfig<NS, PE, PI>;
|
|
18
15
|
}
|
|
19
16
|
type Options = {
|
|
@@ -41,4 +38,4 @@ declare class StripeConfig<NS extends Lowercase<string> = Lowercase<string>, PE
|
|
|
41
38
|
getCreditExpiresAt: (productId: string, priceId?: string) => string;
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
export { type
|
|
41
|
+
export { type PriceId, StripeConfig };
|
package/dist/stripe/config.mjs
CHANGED
|
@@ -15,8 +15,8 @@ var Product = class {
|
|
|
15
15
|
this.prices = /* @__PURE__ */ new Map();
|
|
16
16
|
this.defaultPriceId = null;
|
|
17
17
|
}
|
|
18
|
-
price = (priceId,
|
|
19
|
-
this.prices.set(priceId,
|
|
18
|
+
price = (priceId, metadata = { credits: 0, expiresIn: "0" }) => {
|
|
19
|
+
this.prices.set(priceId, metadata);
|
|
20
20
|
return this;
|
|
21
21
|
};
|
|
22
22
|
default = (defaultPriceId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stripe/config.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport ms
|
|
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 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,QAAQ;AAKf,IAAM,YAAY,uBAAO,WAAW;AAEpC,IAAM,UAAN,MAKE;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET;AAAA,EAEA,YAAY,QAAkC,IAAY,OAAkB,MAAM;AAChF,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,SAAS,oBAAI,IAAI;AACtB,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,QAAQ,CACN,SACA,WAAqB,EAAE,SAAS,GAAG,WAAW,IAAI,MACnB;AAC/B,SAAK,OAAO,IAAI,SAAS,QAAQ;AACjC,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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AS;AACX,YAAM,QAAQ,QAAQ,OAAO,IAAI,OAAkB;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":[]}
|
package/dist/stripe/index.d.cts
CHANGED
package/dist/stripe/index.d.ts
CHANGED
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { StringValue } from 'ms';\n\nexport type Metadata = { credits: number; expiresIn: StringValue };\n\nexport type IsUnique<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest]\n ? First extends Rest[number]\n ? false\n : IsUnique<Rest>\n : true;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StringValue } from 'ms';
|
|
2
|
+
|
|
3
|
+
type Metadata = {
|
|
4
|
+
credits: number;
|
|
5
|
+
expiresIn: StringValue;
|
|
6
|
+
};
|
|
7
|
+
type IsUnique<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? First extends Rest[number] ? false : IsUnique<Rest> : true;
|
|
8
|
+
|
|
9
|
+
export type { IsUnique, Metadata };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StringValue } from 'ms';
|
|
2
|
+
|
|
3
|
+
type Metadata = {
|
|
4
|
+
credits: number;
|
|
5
|
+
expiresIn: StringValue;
|
|
6
|
+
};
|
|
7
|
+
type IsUnique<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? First extends Rest[number] ? false : IsUnique<Rest> : true;
|
|
8
|
+
|
|
9
|
+
export type { IsUnique, Metadata };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|