@shware/purchase 1.8.8 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/app-store/config.cjs +98 -128
- package/dist/app-store/config.cjs.map +1 -1
- package/dist/app-store/config.d.cts +31 -31
- package/dist/app-store/config.d.cts.map +1 -0
- package/dist/app-store/config.d.mts +39 -0
- package/dist/app-store/config.d.mts.map +1 -0
- package/dist/app-store/config.mjs +93 -91
- package/dist/app-store/config.mjs.map +1 -1
- package/dist/app-store/index.cjs +3 -31
- package/dist/app-store/index.d.cts +2 -3
- package/dist/app-store/index.d.mts +2 -0
- package/dist/app-store/index.mjs +1 -5
- package/dist/google-play/config.cjs +100 -123
- package/dist/google-play/config.cjs.map +1 -1
- package/dist/google-play/config.d.cts +31 -31
- package/dist/google-play/config.d.cts.map +1 -0
- package/dist/google-play/config.d.mts +39 -0
- package/dist/google-play/config.d.mts.map +1 -0
- package/dist/google-play/config.mjs +95 -86
- package/dist/google-play/config.mjs.map +1 -1
- package/dist/google-play/index.cjs +9 -42
- package/dist/google-play/index.d.cts +3 -4
- package/dist/google-play/index.d.mts +3 -0
- package/dist/google-play/index.mjs +2 -17
- package/dist/google-play/real-time-developer-notification.cjs +122 -81
- package/dist/google-play/real-time-developer-notification.cjs.map +1 -1
- package/dist/google-play/real-time-developer-notification.d.cts +119 -117
- package/dist/google-play/real-time-developer-notification.d.cts.map +1 -0
- package/dist/google-play/real-time-developer-notification.d.mts +150 -0
- package/dist/google-play/real-time-developer-notification.d.mts.map +1 -0
- package/dist/google-play/real-time-developer-notification.mjs +118 -53
- package/dist/google-play/real-time-developer-notification.mjs.map +1 -1
- package/dist/index.cjs +13 -48
- package/dist/index.d.cts +5 -6
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +2 -19
- package/dist/stripe/config.cjs +104 -133
- package/dist/stripe/config.cjs.map +1 -1
- package/dist/stripe/config.d.cts +35 -35
- package/dist/stripe/config.d.cts.map +1 -0
- package/dist/stripe/config.d.mts +43 -0
- package/dist/stripe/config.d.mts.map +1 -0
- package/dist/stripe/config.mjs +99 -96
- package/dist/stripe/config.mjs.map +1 -1
- package/dist/stripe/handler.cjs +25 -53
- package/dist/stripe/handler.cjs.map +1 -1
- package/dist/stripe/handler.d.cts +10 -9
- package/dist/stripe/handler.d.cts.map +1 -0
- package/dist/stripe/handler.d.mts +16 -0
- package/dist/stripe/handler.d.mts.map +1 -0
- package/dist/stripe/handler.mjs +25 -29
- package/dist/stripe/handler.mjs.map +1 -1
- package/dist/stripe/index.cjs +27 -74
- package/dist/stripe/index.d.cts +8 -12
- package/dist/stripe/index.d.mts +8 -0
- package/dist/stripe/index.mjs +5 -44
- package/dist/stripe/mapper.cjs +168 -218
- package/dist/stripe/mapper.cjs.map +1 -1
- package/dist/stripe/mapper.d.cts +115 -114
- package/dist/stripe/mapper.d.cts.map +1 -0
- package/dist/stripe/mapper.d.mts +158 -0
- package/dist/stripe/mapper.d.mts.map +1 -0
- package/dist/stripe/mapper.mjs +155 -181
- package/dist/stripe/mapper.mjs.map +1 -1
- package/dist/stripe/metadata.cjs +11 -35
- package/dist/stripe/metadata.cjs.map +1 -1
- package/dist/stripe/metadata.d.cts +9 -7
- package/dist/stripe/metadata.d.cts.map +1 -0
- package/dist/stripe/metadata.d.mts +12 -0
- package/dist/stripe/metadata.d.mts.map +1 -0
- package/dist/stripe/metadata.mjs +11 -11
- package/dist/stripe/metadata.mjs.map +1 -1
- package/dist/stripe/pending-checkout.cjs +55 -61
- package/dist/stripe/pending-checkout.cjs.map +1 -1
- package/dist/stripe/pending-checkout.d.cts +3 -1
- package/dist/stripe/pending-checkout.d.cts.map +1 -0
- package/dist/stripe/{pending-checkout.d.ts → pending-checkout.d.mts} +3 -1
- package/dist/stripe/pending-checkout.d.mts.map +1 -0
- package/dist/stripe/pending-checkout.mjs +52 -34
- package/dist/stripe/pending-checkout.mjs.map +1 -1
- package/dist/stripe/schema.cjs +30 -55
- package/dist/stripe/schema.cjs.map +1 -1
- package/dist/stripe/schema.d.cts +36 -37
- package/dist/stripe/schema.d.cts.map +1 -0
- package/dist/stripe/schema.d.mts +40 -0
- package/dist/stripe/schema.d.mts.map +1 -0
- package/dist/stripe/schema.mjs +28 -40
- package/dist/stripe/schema.mjs.map +1 -1
- package/dist/subscription/index.cjs +178 -80
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.d.cts +136 -134
- package/dist/subscription/index.d.cts.map +1 -0
- package/dist/subscription/index.d.mts +150 -0
- package/dist/subscription/index.d.mts.map +1 -0
- package/dist/subscription/index.mjs +173 -51
- package/dist/subscription/index.mjs.map +1 -1
- package/dist/types.cjs +0 -19
- package/dist/types.d.cts +7 -6
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +10 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -1
- package/package.json +41 -26
- package/dist/app-store/config.d.ts +0 -39
- package/dist/app-store/index.cjs.map +0 -1
- package/dist/app-store/index.d.ts +0 -3
- package/dist/app-store/index.mjs.map +0 -1
- package/dist/google-play/config.d.ts +0 -39
- package/dist/google-play/index.cjs.map +0 -1
- package/dist/google-play/index.d.ts +0 -4
- package/dist/google-play/index.mjs.map +0 -1
- package/dist/google-play/real-time-developer-notification.d.ts +0 -148
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/stripe/config.d.ts +0 -43
- package/dist/stripe/handler.d.ts +0 -15
- package/dist/stripe/index.cjs.map +0 -1
- package/dist/stripe/index.d.ts +0 -12
- package/dist/stripe/index.mjs.map +0 -1
- package/dist/stripe/mapper.d.ts +0 -157
- package/dist/stripe/metadata.d.ts +0 -10
- package/dist/stripe/schema.d.ts +0 -41
- package/dist/subscription/index.d.ts +0 -148
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.mjs.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -1,132 +1,102 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/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");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
let _shware_utils = require("@shware/utils");
|
|
4
|
+
let ms = require("ms");
|
|
5
|
+
ms = require_runtime.__toESM(ms, 1);
|
|
6
|
+
//#region src/app-store/config.ts
|
|
7
|
+
const addMethod = Symbol("addMethod");
|
|
39
8
|
var Subscription = class {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
9
|
+
plan;
|
|
10
|
+
config;
|
|
11
|
+
products;
|
|
12
|
+
defaultProductId;
|
|
13
|
+
constructor(config, plan) {
|
|
14
|
+
this.plan = plan;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.products = /* @__PURE__ */ new Map();
|
|
17
|
+
this.defaultProductId = null;
|
|
18
|
+
}
|
|
19
|
+
product = (productId, metadata = {
|
|
20
|
+
credits: 0,
|
|
21
|
+
expiresIn: "0"
|
|
22
|
+
}) => {
|
|
23
|
+
this.products.set(productId, metadata);
|
|
24
|
+
return this;
|
|
25
|
+
};
|
|
26
|
+
default = (defaultProductId) => {
|
|
27
|
+
this.defaultProductId = defaultProductId;
|
|
28
|
+
this.config[addMethod](this);
|
|
29
|
+
return this.config;
|
|
30
|
+
};
|
|
59
31
|
};
|
|
60
|
-
var AppStoreConfig = class
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
32
|
+
var AppStoreConfig = class AppStoreConfig {
|
|
33
|
+
appId;
|
|
34
|
+
bundleId;
|
|
35
|
+
products;
|
|
36
|
+
consumables;
|
|
37
|
+
subscriptions;
|
|
38
|
+
nonConsumables;
|
|
39
|
+
get productIds() {
|
|
40
|
+
return Array.from(this.products.keys());
|
|
41
|
+
}
|
|
42
|
+
[addMethod] = (subscription) => {
|
|
43
|
+
subscription.products.forEach((metadata, productId) => this.products.set(productId, metadata));
|
|
44
|
+
this.subscriptions.set(subscription.plan, subscription);
|
|
45
|
+
return this;
|
|
46
|
+
};
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.appId = options.appId;
|
|
49
|
+
this.bundleId = options.bundleId;
|
|
50
|
+
this.products = /* @__PURE__ */ new Map();
|
|
51
|
+
this.consumables = /* @__PURE__ */ new Set();
|
|
52
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
53
|
+
this.nonConsumables = /* @__PURE__ */ new Set();
|
|
54
|
+
}
|
|
55
|
+
static create = (options) => {
|
|
56
|
+
return new AppStoreConfig(options);
|
|
57
|
+
};
|
|
58
|
+
subscription = (plan) => {
|
|
59
|
+
return new Subscription(this, plan);
|
|
60
|
+
};
|
|
61
|
+
consumable = (productId, metadata = {
|
|
62
|
+
credits: 0,
|
|
63
|
+
expiresIn: "0"
|
|
64
|
+
}) => {
|
|
65
|
+
this.consumables.add(productId);
|
|
66
|
+
this.products.set(productId, metadata);
|
|
67
|
+
return this;
|
|
68
|
+
};
|
|
69
|
+
nonConsumable = (productId) => {
|
|
70
|
+
this.nonConsumables.add(productId);
|
|
71
|
+
this.products.set(productId, null);
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
getPlan = (productId) => {
|
|
75
|
+
for (const [plan, subscription] of this.subscriptions.entries()) if (subscription.products.has(productId)) return plan;
|
|
76
|
+
throw new Error(`Plan not found for product ${productId}`);
|
|
77
|
+
};
|
|
78
|
+
getMode = (productId) => {
|
|
79
|
+
if (this.consumables.has(productId) || this.nonConsumables.has(productId)) return "payment";
|
|
80
|
+
for (const subscription of this.subscriptions.values()) if (subscription.products.has(productId)) return "subscription";
|
|
81
|
+
throw new Error(`Mode not found for product ${productId}`);
|
|
82
|
+
};
|
|
83
|
+
getCreditAmount = (productId) => {
|
|
84
|
+
const config = this.products.get(productId);
|
|
85
|
+
(0, _shware_utils.invariant)(config !== void 0, `Product not found for ${productId}`);
|
|
86
|
+
(0, _shware_utils.invariant)(config !== null, `Credits not available for non-consumable product ${productId}`);
|
|
87
|
+
return config.credits;
|
|
88
|
+
};
|
|
89
|
+
getCreditExpiresIn = (productId) => {
|
|
90
|
+
const config = this.products.get(productId);
|
|
91
|
+
(0, _shware_utils.invariant)(config, `Product not found for ${productId}`);
|
|
92
|
+
return (0, ms.default)(config.expiresIn);
|
|
93
|
+
};
|
|
94
|
+
getCreditExpiresAt = (productId) => {
|
|
95
|
+
const expiresIn = this.getCreditExpiresIn(productId);
|
|
96
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
97
|
+
};
|
|
127
98
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
99
|
+
//#endregion
|
|
100
|
+
exports.AppStoreConfig = AppStoreConfig;
|
|
101
|
+
|
|
132
102
|
//# sourceMappingURL=config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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 !== undefined, `Product not found for ${productId}`);\n invariant(config !== null, `Credits not available for non-consumable product ${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":"
|
|
1
|
+
{"version":3,"file":"config.cjs","names":[],"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 // oxlint-disable-next-line typescript/no-unnecessary-type-assertion -- tsc requires the cast (tsgolint false positive)\n return new Subscription<NS, PE, K | PL, PI>(this as never, 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 !== undefined, `Product not found for ${productId}`);\n invariant(config !== null, `Credits not available for non-consumable product ${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":";;;;;;AAIA,MAAM,YAAY,OAAO,WAAW;AAEpC,IAAM,eAAN,MAME;CACA;CACA;CACA;CAEA;CAEA,YAAY,QAAwC,MAAU;EAC5D,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,2BAAW,IAAI,IAAI;EACxB,KAAK,mBAAmB;CAC1B;CAEA,WACE,WACA,WAAqB;EAAE,SAAS;EAAG,WAAW;CAAI,MACN;EAC5C,KAAK,SAAS,IAAI,WAAW,QAAQ;EACrC,OAAO;CACT;CAEA,WAAW,qBAAwB;EACjC,KAAK,mBAAmB;EACxB,KAAK,OAAO,UAAU,CAAC,IAAa;EACpC,OAAO,KAAK;CACd;AACF;AAIA,IAAa,iBAAb,MAAa,eAKX;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA,IAAI,aAAuB;EACzB,OAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;CACxC;CAEA,CAAC,cAAc,iBAA+C;EAC5D,aAAa,SAAS,SAAS,UAAU,cAAc,KAAK,SAAS,IAAI,WAAW,QAAQ,CAAC;EAC7F,KAAK,cAAc,IAAI,aAAa,MAAM,YAAY;EACtD,OAAO;CACT;CAEA,YAAoB,SAAkB;EACpC,KAAK,QAAQ,QAAQ;EACrB,KAAK,WAAW,QAAQ;EACxB,KAAK,2BAAW,IAAI,IAAI;EACxB,KAAK,8BAAc,IAAI,IAAI;EAC3B,KAAK,gCAAgB,IAAI,IAAI;EAC7B,KAAK,iCAAiB,IAAI,IAAI;CAChC;CAEA,OAAO,UAA2D,YAAqB;EACrF,OAAO,IAAI,eAAuB,OAAO;CAC3C;CAEA,gBAA8B,SAAmC;EAE/D,OAAO,IAAI,aAAiC,MAAe,IAAI;CACjE;CAEA,cACE,WACA,WAAqB;EAAE,SAAS;EAAG,WAAW;CAAI,MAC/C;EACH,KAAK,YAAY,IAAI,SAAS;EAC9B,KAAK,SAAS,IAAI,WAAW,QAAQ;EACrC,OAAO;CACT;CAEA,iBAAyD,cAAwC;EAC/F,KAAK,eAAe,IAAI,SAAS;EACjC,KAAK,SAAS,IAAI,WAAW,IAAI;EACjC,OAAO;CACT;CAEA,WAAW,cAA0B;EACnC,KAAK,MAAM,CAAC,MAAM,iBAAiB,KAAK,cAAc,QAAQ,GAC5D,IAAI,aAAa,SAAS,IAAI,SAAS,GAAG,OAAO;EAEnD,MAAM,IAAI,MAAM,8BAA8B,WAAW;CAC3D;CAEA,WAAW,cAAkD;EAC3D,IAAI,KAAK,YAAY,IAAI,SAAS,KAAK,KAAK,eAAe,IAAI,SAAS,GAAG,OAAO;EAClF,KAAK,MAAM,gBAAgB,KAAK,cAAc,OAAO,GACnD,IAAI,aAAa,SAAS,IAAI,SAAS,GAAG,OAAO;EAEnD,MAAM,IAAI,MAAM,8BAA8B,WAAW;CAC3D;CAEA,mBAAmB,cAA8B;EAC/C,MAAM,SAAS,KAAK,SAAS,IAAI,SAAS;EAC1C,CAAA,GAAA,cAAA,UAAA,CAAU,WAAW,KAAA,GAAW,yBAAyB,WAAW;EACpE,CAAA,GAAA,cAAA,UAAA,CAAU,WAAW,MAAM,oDAAoD,WAAW;EAC1F,OAAO,OAAO;CAChB;CAEA,sBAA8B,cAA8B;EAC1D,MAAM,SAAS,KAAK,SAAS,IAAI,SAAS;EAC1C,CAAA,GAAA,cAAA,UAAA,CAAU,QAAQ,yBAAyB,WAAW;EACtD,QAAA,GAAA,GAAA,QAAA,CAAU,OAAO,SAAS;CAC5B;CAEA,sBAAsB,cAA8B;EAClD,MAAM,YAAY,KAAK,mBAAmB,SAAS;EACnD,OAAO,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,CAAC,YAAY;CACtD;AACF"}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { Metadata } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Metadata } from "../types.cjs";
|
|
2
|
+
//#region src/app-store/config.d.ts
|
|
4
3
|
declare const addMethod: unique symbol;
|
|
5
4
|
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> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
readonly plan: PL;
|
|
6
|
+
readonly config: AppStoreConfig<NS, PE, PL, PI>;
|
|
7
|
+
readonly products: Map<string, Metadata>;
|
|
8
|
+
defaultProductId: I | null;
|
|
9
|
+
constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
|
|
10
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => Subscription<NS, PE, PL, PI | K, I | K>;
|
|
11
|
+
default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
|
|
13
12
|
}
|
|
14
13
|
type Options = {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
appId: `${number}`;
|
|
15
|
+
bundleId: string;
|
|
17
16
|
};
|
|
18
17
|
declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
readonly appId: string;
|
|
19
|
+
readonly bundleId: string;
|
|
20
|
+
private products;
|
|
21
|
+
private consumables;
|
|
22
|
+
private subscriptions;
|
|
23
|
+
private nonConsumables;
|
|
24
|
+
get productIds(): string[];
|
|
25
|
+
[addMethod]: (subscription: Subscription<NS, PE, PL, PI>) => this;
|
|
26
|
+
private constructor();
|
|
27
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => AppStoreConfig<NS_1, PE_1, never, never>;
|
|
28
|
+
subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, K | PL, PI, never>;
|
|
29
|
+
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
30
|
+
nonConsumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
31
|
+
getPlan: (productId: string) => PE;
|
|
32
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
33
|
+
getCreditAmount: (productId: string) => number;
|
|
34
|
+
private getCreditExpiresIn;
|
|
35
|
+
getCreditExpiresAt: (productId: string) => string;
|
|
37
36
|
}
|
|
38
|
-
|
|
37
|
+
//#endregion
|
|
39
38
|
export { AppStoreConfig };
|
|
39
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../../src/app-store/config.ts"],"mappings":";;cAIM;cAEA,aACJ,WAAW,oBAAoB,mBAC/B,4BACA,WAAW,YACX,2BACA;WAES,MAAM;WACN,QAAQ,eAAe,IAAI,IAAI,IAAI;WACnC,UAAU,YAAY;EAE/B,kBAAkB;EAElB,YAAY,QAAQ,eAAe,IAAI,IAAI,IAAI,KAAK,MAAM;EAO1D,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,WACzB,aACT,aAAa,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI;EAKxC,UAAO,kBAAsB,MAAC,eAAA,IAAA,IAAA,IAAA;;KAO3B;EAAY;EAAoB;;cAExB,eACX,WAAW,oBAAoB,mBAC/B,4BACA,WAAW,YACX;WAES;WACA;UAED;UACA;UACA;UACA;MAEJ;GAIH,aAAU,cAAkB,aAAa,IAAI,IAAI,IAAI;UAM/C;SASA,SAAU,aAAW,mBAAmB,qBAAiB,SAAW,YAAO,eAAA,MAAA;EAIlF,eAAgB,UAAU,IAAE,MAAQ,UAAU,aAAa,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;EAK5D,aAAc,aAAa,MAAM,qBAAmB,WACvC,UAAU,aAAa,GAAC,WACzB,aAIK,eAAe,IAAI,IAAI,IAAI,KAAK;EAGjD,gBAAiB,aAAa,MAAM,qBAAmB,WAAa,UAAU,aAAa,MAG1E,eAAe,IAAI,IAAI,IAAI,KAAK;EAGjD,UAAO,sBAAwB;EAO/B,UAAO;EAQP,kBAAe;UAOP;EAMR,qBAAkB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Metadata } from "../types.mjs";
|
|
2
|
+
//#region src/app-store/config.d.ts
|
|
3
|
+
declare const addMethod: unique symbol;
|
|
4
|
+
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> {
|
|
5
|
+
readonly plan: PL;
|
|
6
|
+
readonly config: AppStoreConfig<NS, PE, PL, PI>;
|
|
7
|
+
readonly products: Map<string, Metadata>;
|
|
8
|
+
defaultProductId: I | null;
|
|
9
|
+
constructor(config: AppStoreConfig<NS, PE, PL, PI>, plan: PL);
|
|
10
|
+
product: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => Subscription<NS, PE, PL, PI | K, I | K>;
|
|
11
|
+
default: (defaultProductId: I) => AppStoreConfig<NS, PE, PL, PI>;
|
|
12
|
+
}
|
|
13
|
+
type Options = {
|
|
14
|
+
appId: `${number}`;
|
|
15
|
+
bundleId: string;
|
|
16
|
+
};
|
|
17
|
+
declare class AppStoreConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PL extends PE = never, PI extends string = never> {
|
|
18
|
+
readonly appId: string;
|
|
19
|
+
readonly bundleId: string;
|
|
20
|
+
private products;
|
|
21
|
+
private consumables;
|
|
22
|
+
private subscriptions;
|
|
23
|
+
private nonConsumables;
|
|
24
|
+
get productIds(): string[];
|
|
25
|
+
[addMethod]: (subscription: Subscription<NS, PE, PL, PI>) => this;
|
|
26
|
+
private constructor();
|
|
27
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string>(options: Options) => AppStoreConfig<NS_1, PE_1, never, never>;
|
|
28
|
+
subscription: <K extends PE>(plan: K extends PL ? never : K) => Subscription<NS, PE, K | PL, PI, never>;
|
|
29
|
+
consumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
30
|
+
nonConsumable: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => AppStoreConfig<NS, PE, PL, PI | K>;
|
|
31
|
+
getPlan: (productId: string) => PE;
|
|
32
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
33
|
+
getCreditAmount: (productId: string) => number;
|
|
34
|
+
private getCreditExpiresIn;
|
|
35
|
+
getCreditExpiresAt: (productId: string) => string;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { AppStoreConfig };
|
|
39
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../../src/app-store/config.ts"],"mappings":";;cAIM;cAEA,aACJ,WAAW,oBAAoB,mBAC/B,4BACA,WAAW,YACX,2BACA;WAES,MAAM;WACN,QAAQ,eAAe,IAAI,IAAI,IAAI;WACnC,UAAU,YAAY;EAE/B,kBAAkB;EAElB,YAAY,QAAQ,eAAe,IAAI,IAAI,IAAI,KAAK,MAAM;EAO1D,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,WACzB,aACT,aAAa,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI;EAKxC,UAAO,kBAAsB,MAAC,eAAA,IAAA,IAAA,IAAA;;KAO3B;EAAY;EAAoB;;cAExB,eACX,WAAW,oBAAoB,mBAC/B,4BACA,WAAW,YACX;WAES;WACA;UAED;UACA;UACA;UACA;MAEJ;GAIH,aAAU,cAAkB,aAAa,IAAI,IAAI,IAAI;UAM/C;SASA,SAAU,aAAW,mBAAmB,qBAAiB,SAAW,YAAO,eAAA,MAAA;EAIlF,eAAgB,UAAU,IAAE,MAAQ,UAAU,aAAa,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;EAK5D,aAAc,aAAa,MAAM,qBAAmB,WACvC,UAAU,aAAa,GAAC,WACzB,aAIK,eAAe,IAAI,IAAI,IAAI,KAAK;EAGjD,gBAAiB,aAAa,MAAM,qBAAmB,WAAa,UAAU,aAAa,MAG1E,eAAe,IAAI,IAAI,IAAI,KAAK;EAGjD,UAAO,sBAAwB;EAO/B,UAAO;EAQP,kBAAe;UAOP;EAMR,qBAAkB"}
|
|
@@ -1,97 +1,99 @@
|
|
|
1
|
-
// src/app-store/config.ts
|
|
2
1
|
import { invariant } from "@shware/utils";
|
|
3
2
|
import ms from "ms";
|
|
4
|
-
|
|
3
|
+
//#region src/app-store/config.ts
|
|
4
|
+
const addMethod = Symbol("addMethod");
|
|
5
5
|
var Subscription = class {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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, metadata = {
|
|
17
|
+
credits: 0,
|
|
18
|
+
expiresIn: "0"
|
|
19
|
+
}) => {
|
|
20
|
+
this.products.set(productId, metadata);
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
default = (defaultProductId) => {
|
|
24
|
+
this.defaultProductId = defaultProductId;
|
|
25
|
+
this.config[addMethod](this);
|
|
26
|
+
return this.config;
|
|
27
|
+
};
|
|
25
28
|
};
|
|
26
|
-
var AppStoreConfig = class
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
export {
|
|
95
|
-
AppStoreConfig
|
|
29
|
+
var AppStoreConfig = class AppStoreConfig {
|
|
30
|
+
appId;
|
|
31
|
+
bundleId;
|
|
32
|
+
products;
|
|
33
|
+
consumables;
|
|
34
|
+
subscriptions;
|
|
35
|
+
nonConsumables;
|
|
36
|
+
get productIds() {
|
|
37
|
+
return Array.from(this.products.keys());
|
|
38
|
+
}
|
|
39
|
+
[addMethod] = (subscription) => {
|
|
40
|
+
subscription.products.forEach((metadata, productId) => this.products.set(productId, metadata));
|
|
41
|
+
this.subscriptions.set(subscription.plan, subscription);
|
|
42
|
+
return this;
|
|
43
|
+
};
|
|
44
|
+
constructor(options) {
|
|
45
|
+
this.appId = options.appId;
|
|
46
|
+
this.bundleId = options.bundleId;
|
|
47
|
+
this.products = /* @__PURE__ */ new Map();
|
|
48
|
+
this.consumables = /* @__PURE__ */ new Set();
|
|
49
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
50
|
+
this.nonConsumables = /* @__PURE__ */ new Set();
|
|
51
|
+
}
|
|
52
|
+
static create = (options) => {
|
|
53
|
+
return new AppStoreConfig(options);
|
|
54
|
+
};
|
|
55
|
+
subscription = (plan) => {
|
|
56
|
+
return new Subscription(this, plan);
|
|
57
|
+
};
|
|
58
|
+
consumable = (productId, metadata = {
|
|
59
|
+
credits: 0,
|
|
60
|
+
expiresIn: "0"
|
|
61
|
+
}) => {
|
|
62
|
+
this.consumables.add(productId);
|
|
63
|
+
this.products.set(productId, metadata);
|
|
64
|
+
return this;
|
|
65
|
+
};
|
|
66
|
+
nonConsumable = (productId) => {
|
|
67
|
+
this.nonConsumables.add(productId);
|
|
68
|
+
this.products.set(productId, null);
|
|
69
|
+
return this;
|
|
70
|
+
};
|
|
71
|
+
getPlan = (productId) => {
|
|
72
|
+
for (const [plan, subscription] of this.subscriptions.entries()) if (subscription.products.has(productId)) return plan;
|
|
73
|
+
throw new Error(`Plan not found for product ${productId}`);
|
|
74
|
+
};
|
|
75
|
+
getMode = (productId) => {
|
|
76
|
+
if (this.consumables.has(productId) || this.nonConsumables.has(productId)) return "payment";
|
|
77
|
+
for (const subscription of this.subscriptions.values()) if (subscription.products.has(productId)) return "subscription";
|
|
78
|
+
throw new Error(`Mode not found for product ${productId}`);
|
|
79
|
+
};
|
|
80
|
+
getCreditAmount = (productId) => {
|
|
81
|
+
const config = this.products.get(productId);
|
|
82
|
+
invariant(config !== void 0, `Product not found for ${productId}`);
|
|
83
|
+
invariant(config !== null, `Credits not available for non-consumable product ${productId}`);
|
|
84
|
+
return config.credits;
|
|
85
|
+
};
|
|
86
|
+
getCreditExpiresIn = (productId) => {
|
|
87
|
+
const config = this.products.get(productId);
|
|
88
|
+
invariant(config, `Product not found for ${productId}`);
|
|
89
|
+
return ms(config.expiresIn);
|
|
90
|
+
};
|
|
91
|
+
getCreditExpiresAt = (productId) => {
|
|
92
|
+
const expiresIn = this.getCreditExpiresIn(productId);
|
|
93
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
94
|
+
};
|
|
96
95
|
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { AppStoreConfig };
|
|
98
|
+
|
|
97
99
|
//# sourceMappingURL=config.mjs.map
|