@shware/purchase 1.8.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/app-store/config.cjs +105 -128
- package/dist/app-store/config.cjs.map +1 -1
- package/dist/app-store/config.d.cts +36 -33
- package/dist/app-store/config.d.cts.map +1 -0
- package/dist/app-store/config.d.mts +42 -0
- package/dist/app-store/config.d.mts.map +1 -0
- package/dist/app-store/config.mjs +100 -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 +108 -123
- package/dist/google-play/config.cjs.map +1 -1
- package/dist/google-play/config.d.cts +35 -33
- package/dist/google-play/config.d.cts.map +1 -0
- package/dist/google-play/config.d.mts +41 -0
- package/dist/google-play/config.d.mts.map +1 -0
- package/dist/google-play/config.mjs +103 -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 +114 -133
- package/dist/stripe/config.cjs.map +1 -1
- package/dist/stripe/config.d.cts +46 -37
- package/dist/stripe/config.d.cts.map +1 -0
- package/dist/stripe/config.d.mts +52 -0
- package/dist/stripe/config.d.mts.map +1 -0
- package/dist/stripe/config.mjs +109 -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 -219
- 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 -182
- 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 +40 -25
- 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
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IsUnique, Metadata } from "../types.cjs";
|
|
2
|
+
//#region src/google-play/config.d.ts
|
|
4
3
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PI extends string = never, I extends Lowercase<string> = never> {
|
|
5
|
+
readonly productId: string;
|
|
6
|
+
readonly config: GooglePlayConfig<NS, PE, BP, PI>;
|
|
7
|
+
readonly plans: Map<string, Metadata & {
|
|
8
|
+
plan?: PE;
|
|
9
|
+
billingPeriod?: BP;
|
|
10
|
+
}>;
|
|
11
|
+
readonly defaultPlans: Set<string>;
|
|
12
|
+
constructor(config: GooglePlayConfig<NS, PE, BP, PI>, productId: string);
|
|
13
|
+
basePlan: <K extends Lowercase<string>>(planId: K extends I ? never : K, plan: PE, billingPeriod: BP, metadata?: Metadata) => Subscription<NS, PE, BP, PI, I | K>;
|
|
14
|
+
default: <const T extends readonly [I, ...I[]]>(planIds: T & (IsUnique<T> extends true ? unknown : never)) => GooglePlayConfig<NS, PE, BP, PI>;
|
|
15
15
|
}
|
|
16
16
|
type Options = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
package: string;
|
|
18
|
+
audience: string;
|
|
19
19
|
};
|
|
20
|
-
declare class GooglePlayConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, PI extends string = never> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
declare class GooglePlayConfig<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP 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, BP, PI>) => this;
|
|
27
|
+
private getId;
|
|
28
|
+
private constructor();
|
|
29
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string = string, BP_1 extends string = string>(options: Options) => GooglePlayConfig<NS_1, PE_1, BP_1, never>;
|
|
30
|
+
subscription: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => Subscription<NS, PE, BP, K | PI, never>;
|
|
31
|
+
onetime: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => GooglePlayConfig<NS, PE, BP, PI | K>;
|
|
32
|
+
getPlan: (productId: string, planId: string) => PE;
|
|
33
|
+
getBillingPeriod: (productId: string, planId: string) => BP;
|
|
34
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
35
|
+
getCreditAmount: (productId: string, planId?: string) => number;
|
|
36
|
+
private getCreditExpiresIn;
|
|
37
|
+
getCreditExpiresAt: (productId: string, planId?: string) => string;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
//#endregion
|
|
39
40
|
export { GooglePlayConfig };
|
|
41
|
+
//# sourceMappingURL=config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.cts","names":[],"sources":["../../src/google-play/config.ts"],"mappings":";;cAIM;cAEA,aACJ,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA,UAAU;WAED;WACA,QAAQ,iBAAiB,IAAI,IAAI,IAAI;WACrC,OAAO,YAAY;IAAa,OAAO;IAAI,gBAAgB;;WAC3D,cAAc;EAEvB,YAAY,QAAQ,iBAAiB,IAAI,IAAI,IAAI,KAAK;EAOtD,WAAY,UAAU,mBAAiB,QAC7B,UAAU,YAAY,GAAC,MACzB,IAAE,eACO,IAAE,WACP,aACT,aAAa,IAAI,IAAI,IAAI,IAAI,IAAI;EAKpC,gBAAiB,oBAAoB,MAAM,MAAI,SACpC,KAAK,SAAS,uCAAkC,iBAAA,IAAA,IAAA,IAAA;;KAQxD;EAAY;EAAiB;;cAErB,iBACX,WAAW,oBAAoB,mBAC/B,4BACA,4BACA;WAES;WACA;UACD;UACA;UACA;GAEP,aAAU,cAAkB,aAAa,IAAI,IAAI,IAAI;UAQ9C;UAID;SAQA,SACL,aAAW,mBACX,8BACA,8BAA0B,SAEjB,YAAO,iBAAA,MAAA,MAAA;EAKlB,eAAgB,aAAa,MAAM,qBAAmB,WAAa,UAAU,aAAa,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;EAI3F,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,WACzB,aAIK,iBAAiB,IAAI,IAAI,IAAI,KAAK;EAGnD,UAAO,mBAAqB,mBAAmB;EAQ/C,mBAAgB,mBAAqB,mBAAmB;EAQxD,UAAO;EAMP,kBAAe,mBAAqB;UAO5B;EAOR,qBAAkB,mBAAqB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IsUnique, Metadata } from "../types.mjs";
|
|
2
|
+
//#region src/google-play/config.d.ts
|
|
3
|
+
declare const addMethod: unique symbol;
|
|
4
|
+
declare class Subscription<NS extends Lowercase<string> = Lowercase<string>, PE extends string = string, BP extends string = string, PI extends string = never, I extends Lowercase<string> = never> {
|
|
5
|
+
readonly productId: string;
|
|
6
|
+
readonly config: GooglePlayConfig<NS, PE, BP, PI>;
|
|
7
|
+
readonly plans: Map<string, Metadata & {
|
|
8
|
+
plan?: PE;
|
|
9
|
+
billingPeriod?: BP;
|
|
10
|
+
}>;
|
|
11
|
+
readonly defaultPlans: Set<string>;
|
|
12
|
+
constructor(config: GooglePlayConfig<NS, PE, BP, PI>, productId: string);
|
|
13
|
+
basePlan: <K extends Lowercase<string>>(planId: K extends I ? never : K, plan: PE, billingPeriod: BP, metadata?: Metadata) => Subscription<NS, PE, BP, PI, I | K>;
|
|
14
|
+
default: <const T extends readonly [I, ...I[]]>(planIds: T & (IsUnique<T> extends true ? unknown : never)) => GooglePlayConfig<NS, PE, BP, 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, BP 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, BP, PI>) => this;
|
|
27
|
+
private getId;
|
|
28
|
+
private constructor();
|
|
29
|
+
static create: <NS_1 extends Lowercase<string>, PE_1 extends string = string, BP_1 extends string = string>(options: Options) => GooglePlayConfig<NS_1, PE_1, BP_1, never>;
|
|
30
|
+
subscription: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => Subscription<NS, PE, BP, K | PI, never>;
|
|
31
|
+
onetime: <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K, metadata?: Metadata) => GooglePlayConfig<NS, PE, BP, PI | K>;
|
|
32
|
+
getPlan: (productId: string, planId: string) => PE;
|
|
33
|
+
getBillingPeriod: (productId: string, planId: string) => BP;
|
|
34
|
+
getMode: (productId: string) => 'payment' | 'subscription';
|
|
35
|
+
getCreditAmount: (productId: string, planId?: string) => number;
|
|
36
|
+
private getCreditExpiresIn;
|
|
37
|
+
getCreditExpiresAt: (productId: string, planId?: string) => string;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { GooglePlayConfig };
|
|
41
|
+
//# sourceMappingURL=config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.mts","names":[],"sources":["../../src/google-play/config.ts"],"mappings":";;cAIM;cAEA,aACJ,WAAW,oBAAoB,mBAC/B,4BACA,4BACA,2BACA,UAAU;WAED;WACA,QAAQ,iBAAiB,IAAI,IAAI,IAAI;WACrC,OAAO,YAAY;IAAa,OAAO;IAAI,gBAAgB;;WAC3D,cAAc;EAEvB,YAAY,QAAQ,iBAAiB,IAAI,IAAI,IAAI,KAAK;EAOtD,WAAY,UAAU,mBAAiB,QAC7B,UAAU,YAAY,GAAC,MACzB,IAAE,eACO,IAAE,WACP,aACT,aAAa,IAAI,IAAI,IAAI,IAAI,IAAI;EAKpC,gBAAiB,oBAAoB,MAAM,MAAI,SACpC,KAAK,SAAS,uCAAkC,iBAAA,IAAA,IAAA,IAAA;;KAQxD;EAAY;EAAiB;;cAErB,iBACX,WAAW,oBAAoB,mBAC/B,4BACA,4BACA;WAES;WACA;UACD;UACA;UACA;GAEP,aAAU,cAAkB,aAAa,IAAI,IAAI,IAAI;UAQ9C;UAID;SAQA,SACL,aAAW,mBACX,8BACA,8BAA0B,SAEjB,YAAO,iBAAA,MAAA,MAAA;EAKlB,eAAgB,aAAa,MAAM,qBAAmB,WAAa,UAAU,aAAa,MAAC,aAAA,IAAA,IAAA,IAAA,IAAA;EAI3F,UAAW,aAAa,MAAM,qBAAmB,WACpC,UAAU,aAAa,GAAC,WACzB,aAIK,iBAAiB,IAAI,IAAI,IAAI,KAAK;EAGnD,UAAO,mBAAqB,mBAAmB;EAQ/C,mBAAgB,mBAAqB,mBAAmB;EAQxD,UAAO;EAMP,kBAAe,mBAAqB;UAO5B;EAOR,qBAAkB,mBAAqB"}
|
|
@@ -1,92 +1,109 @@
|
|
|
1
|
-
// src/google-play/config.ts
|
|
2
1
|
import { invariant } from "@shware/utils";
|
|
3
2
|
import ms from "ms";
|
|
4
|
-
|
|
3
|
+
//#region src/google-play/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
|
+
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, billingPeriod, metadata = {
|
|
17
|
+
credits: 0,
|
|
18
|
+
expiresIn: "0"
|
|
19
|
+
}) => {
|
|
20
|
+
this.plans.set(planId, {
|
|
21
|
+
...metadata,
|
|
22
|
+
plan,
|
|
23
|
+
billingPeriod
|
|
24
|
+
});
|
|
25
|
+
return this;
|
|
26
|
+
};
|
|
27
|
+
default = (planIds) => {
|
|
28
|
+
planIds.forEach((planId) => this.defaultPlans.add(planId));
|
|
29
|
+
this.config[addMethod](this);
|
|
30
|
+
return this.config;
|
|
31
|
+
};
|
|
25
32
|
};
|
|
26
|
-
var GooglePlayConfig = 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
|
-
|
|
33
|
+
var GooglePlayConfig = class GooglePlayConfig {
|
|
34
|
+
package;
|
|
35
|
+
audience;
|
|
36
|
+
onetimes;
|
|
37
|
+
subscriptions;
|
|
38
|
+
products;
|
|
39
|
+
[addMethod] = (subscription) => {
|
|
40
|
+
subscription.plans.forEach((metadata, planId) => {
|
|
41
|
+
this.products.set(this.getId(subscription.productId, planId), metadata);
|
|
42
|
+
});
|
|
43
|
+
this.subscriptions.set(subscription.productId, subscription);
|
|
44
|
+
return this;
|
|
45
|
+
};
|
|
46
|
+
getId = (productId, planId) => {
|
|
47
|
+
return planId ? `${productId}:${planId}` : productId;
|
|
48
|
+
};
|
|
49
|
+
constructor(options) {
|
|
50
|
+
this.package = options.package;
|
|
51
|
+
this.audience = options.audience;
|
|
52
|
+
this.products = /* @__PURE__ */ new Map();
|
|
53
|
+
this.onetimes = /* @__PURE__ */ new Set();
|
|
54
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
55
|
+
}
|
|
56
|
+
static create = (options) => {
|
|
57
|
+
return new GooglePlayConfig(options);
|
|
58
|
+
};
|
|
59
|
+
subscription = (productId) => {
|
|
60
|
+
return new Subscription(this, productId);
|
|
61
|
+
};
|
|
62
|
+
onetime = (productId, metadata = {
|
|
63
|
+
credits: 0,
|
|
64
|
+
expiresIn: "0"
|
|
65
|
+
}) => {
|
|
66
|
+
this.onetimes.add(productId);
|
|
67
|
+
this.products.set(productId, metadata);
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
getPlan = (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
|
+
invariant(metadata.plan, `Plan not found for ${id}`);
|
|
75
|
+
return metadata.plan;
|
|
76
|
+
};
|
|
77
|
+
getBillingPeriod = (productId, planId) => {
|
|
78
|
+
const id = this.getId(productId, planId);
|
|
79
|
+
const metadata = this.products.get(id);
|
|
80
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
81
|
+
invariant(metadata.billingPeriod, `Billing period not found for ${id}`);
|
|
82
|
+
return metadata.billingPeriod;
|
|
83
|
+
};
|
|
84
|
+
getMode = (productId) => {
|
|
85
|
+
if (this.onetimes.has(productId)) return "payment";
|
|
86
|
+
if (this.subscriptions.has(productId)) return "subscription";
|
|
87
|
+
throw new Error(`Mode not found for product ${productId}`);
|
|
88
|
+
};
|
|
89
|
+
getCreditAmount = (productId, planId) => {
|
|
90
|
+
const id = this.getId(productId, planId);
|
|
91
|
+
const metadata = this.products.get(id);
|
|
92
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
93
|
+
return metadata.credits;
|
|
94
|
+
};
|
|
95
|
+
getCreditExpiresIn = (productId, planId) => {
|
|
96
|
+
const id = this.getId(productId, planId);
|
|
97
|
+
const metadata = this.products.get(id);
|
|
98
|
+
invariant(metadata, `Product not found for ${id}`);
|
|
99
|
+
return ms(metadata.expiresIn);
|
|
100
|
+
};
|
|
101
|
+
getCreditExpiresAt = (productId, planId) => {
|
|
102
|
+
const expiresIn = this.getCreditExpiresIn(productId, planId);
|
|
103
|
+
return new Date(Date.now() + expiresIn).toISOString();
|
|
104
|
+
};
|
|
91
105
|
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { GooglePlayConfig };
|
|
108
|
+
|
|
92
109
|
//# sourceMappingURL=config.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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;\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);\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) => {\n return planId ? `${productId}:${planId}` : productId;\n };\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 =
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"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 BP 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, BP, PI>;\n readonly plans: Map<string, Metadata & { plan?: PE; billingPeriod?: BP }>;\n readonly defaultPlans: Set<string>;\n\n constructor(config: GooglePlayConfig<NS, PE, BP, 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 billingPeriod: BP,\n metadata: Metadata = { credits: 0, expiresIn: '0' }\n ): Subscription<NS, PE, BP, PI, I | K> => {\n this.plans.set(planId, { ...metadata, plan, billingPeriod });\n return this;\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);\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 BP 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, BP, PI>>;\n private products: Map<string, (Metadata & { plan?: PE; billingPeriod?: BP }) | null>;\n\n [addMethod] = (subscription: Subscription<NS, PE, BP, 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) => {\n return planId ? `${productId}:${planId}` : productId;\n };\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 = <\n NS extends Lowercase<string>,\n PE extends string = string,\n BP extends string = string,\n >(\n options: Options\n ) => {\n return new GooglePlayConfig<NS, PE, BP>(options);\n };\n\n subscription = <K extends `${NS}.${Lowercase<string>}`>(productId: K extends PI ? never : K) => {\n return new Subscription<NS, PE, BP, 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 as GooglePlayConfig<NS, PE, BP, PI | K>;\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 getBillingPeriod = (productId: string, planId: string): BP => {\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.billingPeriod, `Billing period not found for ${id}`);\n return metadata.billingPeriod;\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":"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"}
|
|
@@ -1,42 +1,9 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/google-play/index.ts
|
|
21
|
-
var google_play_exports = {};
|
|
22
|
-
__export(google_play_exports, {
|
|
23
|
-
GooglePlayConfig: () => import_config.GooglePlayConfig,
|
|
24
|
-
GooglePlaySubscriptionState: () => import_real_time_developer_notification.GooglePlaySubscriptionState,
|
|
25
|
-
OneTimeProductNotificationType: () => import_real_time_developer_notification.OneTimeProductNotificationType,
|
|
26
|
-
SubscriptionNotificationType: () => import_real_time_developer_notification.SubscriptionNotificationType,
|
|
27
|
-
VoidedPurchaseProductType: () => import_real_time_developer_notification.VoidedPurchaseProductType,
|
|
28
|
-
VoidedPurchaseRefundType: () => import_real_time_developer_notification.VoidedPurchaseRefundType
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(google_play_exports);
|
|
31
|
-
var import_real_time_developer_notification = require("./real-time-developer-notification.cjs");
|
|
32
|
-
var import_config = require("./config.cjs");
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
GooglePlayConfig,
|
|
36
|
-
GooglePlaySubscriptionState,
|
|
37
|
-
OneTimeProductNotificationType,
|
|
38
|
-
SubscriptionNotificationType,
|
|
39
|
-
VoidedPurchaseProductType,
|
|
40
|
-
VoidedPurchaseRefundType
|
|
41
|
-
});
|
|
42
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_google_play_config = require("./config.cjs");
|
|
3
|
+
const require_google_play_real_time_developer_notification = require("./real-time-developer-notification.cjs");
|
|
4
|
+
exports.GooglePlayConfig = require_google_play_config.GooglePlayConfig;
|
|
5
|
+
exports.GooglePlaySubscriptionState = require_google_play_real_time_developer_notification.GooglePlaySubscriptionState;
|
|
6
|
+
exports.OneTimeProductNotificationType = require_google_play_real_time_developer_notification.OneTimeProductNotificationType;
|
|
7
|
+
exports.SubscriptionNotificationType = require_google_play_real_time_developer_notification.SubscriptionNotificationType;
|
|
8
|
+
exports.VoidedPurchaseProductType = require_google_play_real_time_developer_notification.VoidedPurchaseProductType;
|
|
9
|
+
exports.VoidedPurchaseRefundType = require_google_play_real_time_developer_notification.VoidedPurchaseRefundType;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import 'ms';
|
|
1
|
+
import { GooglePlayConfig } from "./config.cjs";
|
|
2
|
+
import { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from "./real-time-developer-notification.cjs";
|
|
3
|
+
export { type DeveloperNotification, GooglePlayConfig, GooglePlaySubscriptionState, type OneTimeProductNotification, OneTimeProductNotificationType, type PubsubMessage, type SubscriptionNotification, SubscriptionNotificationType, type TestNotification, type VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GooglePlayConfig } from "./config.mjs";
|
|
2
|
+
import { DeveloperNotification, GooglePlaySubscriptionState, OneTimeProductNotification, OneTimeProductNotificationType, PubsubMessage, SubscriptionNotification, SubscriptionNotificationType, TestNotification, VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType } from "./real-time-developer-notification.mjs";
|
|
3
|
+
export { type DeveloperNotification, GooglePlayConfig, GooglePlaySubscriptionState, type OneTimeProductNotification, OneTimeProductNotificationType, type PubsubMessage, type SubscriptionNotification, SubscriptionNotificationType, type TestNotification, type VoidedPurchaseNotification, VoidedPurchaseProductType, VoidedPurchaseRefundType };
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
// src/google-play/index.ts
|
|
2
|
-
import {
|
|
3
|
-
GooglePlaySubscriptionState,
|
|
4
|
-
SubscriptionNotificationType,
|
|
5
|
-
OneTimeProductNotificationType,
|
|
6
|
-
VoidedPurchaseProductType,
|
|
7
|
-
VoidedPurchaseRefundType
|
|
8
|
-
} from "./real-time-developer-notification.mjs";
|
|
9
1
|
import { GooglePlayConfig } from "./config.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
GooglePlaySubscriptionState,
|
|
13
|
-
OneTimeProductNotificationType,
|
|
14
|
-
SubscriptionNotificationType,
|
|
15
|
-
VoidedPurchaseProductType,
|
|
16
|
-
VoidedPurchaseRefundType
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=index.mjs.map
|
|
2
|
+
import { GooglePlaySubscriptionState, OneTimeProductNotificationType, SubscriptionNotificationType, VoidedPurchaseProductType, VoidedPurchaseRefundType } from "./real-time-developer-notification.mjs";
|
|
3
|
+
export { GooglePlayConfig, GooglePlaySubscriptionState, OneTimeProductNotificationType, SubscriptionNotificationType, VoidedPurchaseProductType, VoidedPurchaseRefundType };
|