@revenuecat/purchases-js 0.0.6 → 0.0.9
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/Purchases.es.d.ts +6 -6
- package/dist/Purchases.es.js +125 -83
- package/dist/Purchases.umd.js +1 -1
- package/package.json +2 -1
package/dist/Purchases.es.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ declare interface Offering_2 {
|
|
|
10
10
|
export declare type OfferingsPage = OfferingsPage_2;
|
|
11
11
|
|
|
12
12
|
declare interface OfferingsPage_2 {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[packageId: string]: number;
|
|
13
|
+
all: {
|
|
14
|
+
[offeringId: string]: Offering_2;
|
|
16
15
|
};
|
|
16
|
+
current: Offering_2 | null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export declare type Package = Package_2;
|
|
@@ -21,7 +21,6 @@ export declare type Package = Package_2;
|
|
|
21
21
|
declare interface Package_2 {
|
|
22
22
|
id: string;
|
|
23
23
|
identifier: string;
|
|
24
|
-
displayName: string;
|
|
25
24
|
rcBillingProduct: Product | null;
|
|
26
25
|
}
|
|
27
26
|
|
|
@@ -45,11 +44,12 @@ export declare class Purchases {
|
|
|
45
44
|
private static readonly _BASE_PATH;
|
|
46
45
|
constructor(apiKey: string);
|
|
47
46
|
private toOfferingsPage;
|
|
48
|
-
listOfferings(): Promise<OfferingsPage>;
|
|
47
|
+
listOfferings(appUserId: string): Promise<OfferingsPage>;
|
|
49
48
|
isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
|
|
50
49
|
waitForEntitlement(appUserId: string, entitlementIdentifier: string, maxAttempts?: number): Promise<boolean>;
|
|
51
50
|
subscribe(appUserId: string, productId: string, email: string, environment?: "sandbox" | "production"): Promise<SubscribeResponse>;
|
|
52
|
-
getPackage(packageIdentifier: string): Promise<Package | null>;
|
|
51
|
+
getPackage(appUserId: string, packageIdentifier: string): Promise<Package | null>;
|
|
52
|
+
private logMissingProductIds;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
declare interface SubscribeResponse {
|
package/dist/Purchases.es.js
CHANGED
|
@@ -1,84 +1,112 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var A = (E,
|
|
4
|
-
const
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var o = (E, n, r) => n in E ? D(E, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : E[n] = r;
|
|
3
|
+
var A = (E, n, r) => (o(E, typeof n != "symbol" ? n + "" : n, r), r);
|
|
4
|
+
const p = (E) => ({
|
|
5
5
|
amount: E.amount,
|
|
6
6
|
currency: E.currency
|
|
7
|
-
}),
|
|
8
|
-
id: E.
|
|
7
|
+
}), L = (E) => ({
|
|
8
|
+
id: E.identifier,
|
|
9
9
|
identifier: E.identifier,
|
|
10
|
-
displayName: E.
|
|
11
|
-
currentPrice: E.current_price ?
|
|
10
|
+
displayName: E.title,
|
|
11
|
+
currentPrice: E.current_price ? p(E.current_price) : null,
|
|
12
12
|
normalPeriodDuration: E.normal_period_duration
|
|
13
|
-
}),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
}), M = (E, n) => {
|
|
14
|
+
const r = n[E.platform_product_identifier];
|
|
15
|
+
return {
|
|
16
|
+
id: E.identifier,
|
|
17
|
+
identifier: E.identifier,
|
|
18
|
+
rcBillingProduct: r ? L(r) : null
|
|
19
|
+
};
|
|
20
|
+
}, P = (E, n) => ({
|
|
21
|
+
id: E.identifier,
|
|
20
22
|
identifier: E.identifier,
|
|
21
|
-
displayName: E.
|
|
22
|
-
packages: E.packages.map(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
displayName: E.description,
|
|
24
|
+
packages: E.packages.map(
|
|
25
|
+
(r) => M(r, n)
|
|
26
|
+
)
|
|
27
|
+
}), t = (E) => {
|
|
28
|
+
var n;
|
|
25
29
|
return {
|
|
26
30
|
nextAction: E.next_action,
|
|
27
31
|
data: {
|
|
28
|
-
clientSecret: ((
|
|
32
|
+
clientSecret: ((n = E.data) == null ? void 0 : n.client_secret) ?? void 0
|
|
29
33
|
}
|
|
30
34
|
};
|
|
31
35
|
};
|
|
32
|
-
var
|
|
36
|
+
var I;
|
|
33
37
|
(function(E) {
|
|
34
38
|
E[E.CONTINUE = 100] = "CONTINUE", E[E.SWITCHING_PROTOCOLS = 101] = "SWITCHING_PROTOCOLS", E[E.PROCESSING = 102] = "PROCESSING", E[E.EARLY_HINTS = 103] = "EARLY_HINTS", E[E.OK = 200] = "OK", E[E.CREATED = 201] = "CREATED", E[E.ACCEPTED = 202] = "ACCEPTED", E[E.NON_AUTHORITATIVE_INFORMATION = 203] = "NON_AUTHORITATIVE_INFORMATION", E[E.NO_CONTENT = 204] = "NO_CONTENT", E[E.RESET_CONTENT = 205] = "RESET_CONTENT", E[E.PARTIAL_CONTENT = 206] = "PARTIAL_CONTENT", E[E.MULTI_STATUS = 207] = "MULTI_STATUS", E[E.MULTIPLE_CHOICES = 300] = "MULTIPLE_CHOICES", E[E.MOVED_PERMANENTLY = 301] = "MOVED_PERMANENTLY", E[E.MOVED_TEMPORARILY = 302] = "MOVED_TEMPORARILY", E[E.SEE_OTHER = 303] = "SEE_OTHER", E[E.NOT_MODIFIED = 304] = "NOT_MODIFIED", E[E.USE_PROXY = 305] = "USE_PROXY", E[E.TEMPORARY_REDIRECT = 307] = "TEMPORARY_REDIRECT", E[E.PERMANENT_REDIRECT = 308] = "PERMANENT_REDIRECT", E[E.BAD_REQUEST = 400] = "BAD_REQUEST", E[E.UNAUTHORIZED = 401] = "UNAUTHORIZED", E[E.PAYMENT_REQUIRED = 402] = "PAYMENT_REQUIRED", E[E.FORBIDDEN = 403] = "FORBIDDEN", E[E.NOT_FOUND = 404] = "NOT_FOUND", E[E.METHOD_NOT_ALLOWED = 405] = "METHOD_NOT_ALLOWED", E[E.NOT_ACCEPTABLE = 406] = "NOT_ACCEPTABLE", E[E.PROXY_AUTHENTICATION_REQUIRED = 407] = "PROXY_AUTHENTICATION_REQUIRED", E[E.REQUEST_TIMEOUT = 408] = "REQUEST_TIMEOUT", E[E.CONFLICT = 409] = "CONFLICT", E[E.GONE = 410] = "GONE", E[E.LENGTH_REQUIRED = 411] = "LENGTH_REQUIRED", E[E.PRECONDITION_FAILED = 412] = "PRECONDITION_FAILED", E[E.REQUEST_TOO_LONG = 413] = "REQUEST_TOO_LONG", E[E.REQUEST_URI_TOO_LONG = 414] = "REQUEST_URI_TOO_LONG", E[E.UNSUPPORTED_MEDIA_TYPE = 415] = "UNSUPPORTED_MEDIA_TYPE", E[E.REQUESTED_RANGE_NOT_SATISFIABLE = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE", E[E.EXPECTATION_FAILED = 417] = "EXPECTATION_FAILED", E[E.IM_A_TEAPOT = 418] = "IM_A_TEAPOT", E[E.INSUFFICIENT_SPACE_ON_RESOURCE = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE", E[E.METHOD_FAILURE = 420] = "METHOD_FAILURE", E[E.MISDIRECTED_REQUEST = 421] = "MISDIRECTED_REQUEST", E[E.UNPROCESSABLE_ENTITY = 422] = "UNPROCESSABLE_ENTITY", E[E.LOCKED = 423] = "LOCKED", E[E.FAILED_DEPENDENCY = 424] = "FAILED_DEPENDENCY", E[E.UPGRADE_REQUIRED = 426] = "UPGRADE_REQUIRED", E[E.PRECONDITION_REQUIRED = 428] = "PRECONDITION_REQUIRED", E[E.TOO_MANY_REQUESTS = 429] = "TOO_MANY_REQUESTS", E[E.REQUEST_HEADER_FIELDS_TOO_LARGE = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE", E[E.UNAVAILABLE_FOR_LEGAL_REASONS = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS", E[E.INTERNAL_SERVER_ERROR = 500] = "INTERNAL_SERVER_ERROR", E[E.NOT_IMPLEMENTED = 501] = "NOT_IMPLEMENTED", E[E.BAD_GATEWAY = 502] = "BAD_GATEWAY", E[E.SERVICE_UNAVAILABLE = 503] = "SERVICE_UNAVAILABLE", E[E.GATEWAY_TIMEOUT = 504] = "GATEWAY_TIMEOUT", E[E.HTTP_VERSION_NOT_SUPPORTED = 505] = "HTTP_VERSION_NOT_SUPPORTED", E[E.INSUFFICIENT_STORAGE = 507] = "INSUFFICIENT_STORAGE", E[E.NETWORK_AUTHENTICATION_REQUIRED = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
35
|
-
})(
|
|
39
|
+
})(I || (I = {}));
|
|
36
40
|
class c extends Error {
|
|
37
|
-
constructor(
|
|
38
|
-
super(
|
|
41
|
+
constructor(n, r) {
|
|
42
|
+
super(r), this.statusCode = n;
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
|
-
class
|
|
45
|
+
class h extends c {
|
|
42
46
|
constructor() {
|
|
43
|
-
super(
|
|
47
|
+
super(I.INTERNAL_SERVER_ERROR, "An unknown error occurred.");
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
class
|
|
50
|
+
class g extends c {
|
|
47
51
|
}
|
|
48
|
-
class
|
|
52
|
+
class F extends c {
|
|
49
53
|
}
|
|
50
|
-
class
|
|
54
|
+
class Y extends c {
|
|
51
55
|
}
|
|
52
|
-
class
|
|
56
|
+
class w extends c {
|
|
53
57
|
}
|
|
54
|
-
const
|
|
55
|
-
constructor(
|
|
58
|
+
const l = "0.0.8", N = class N {
|
|
59
|
+
constructor(n) {
|
|
56
60
|
A(this, "_API_KEY", null);
|
|
57
61
|
A(this, "_APP_USER_ID", null);
|
|
58
|
-
A(this, "toOfferingsPage", (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
A(this, "toOfferingsPage", (n, r) => {
|
|
63
|
+
const _ = n.offerings.find(
|
|
64
|
+
(T) => T.identifier === n.current_offering_id
|
|
65
|
+
) ?? null, R = {};
|
|
66
|
+
r.product_details.forEach((T) => {
|
|
67
|
+
R[T.identifier] = T;
|
|
68
|
+
});
|
|
69
|
+
const O = _ == null ? null : P(_, R), i = {};
|
|
70
|
+
return n.offerings.forEach(
|
|
71
|
+
(T) => i[T.identifier] = P(T, R)
|
|
72
|
+
), {
|
|
73
|
+
all: i,
|
|
74
|
+
current: O
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
this._API_KEY = n, N._RC_ENDPOINT === void 0 && console.error(
|
|
63
78
|
"Project was build without some of the environment variables set"
|
|
64
79
|
);
|
|
65
80
|
}
|
|
66
|
-
async listOfferings() {
|
|
81
|
+
async listOfferings(n) {
|
|
67
82
|
const _ = await (await fetch(
|
|
68
|
-
`${
|
|
83
|
+
`${N._RC_ENDPOINT}/v1/subscribers/${n}/offerings`,
|
|
69
84
|
{
|
|
70
85
|
headers: {
|
|
71
86
|
Authorization: `Bearer ${this._API_KEY}`,
|
|
72
87
|
"Content-Type": "application/json",
|
|
73
|
-
Accept: "application/json"
|
|
88
|
+
Accept: "application/json",
|
|
89
|
+
"X-Platform": "web",
|
|
90
|
+
"X-Version": l
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
)).json(), R = _.offerings.flatMap((T) => T.packages).map((T) => T.platform_product_identifier), i = await (await fetch(
|
|
94
|
+
`${N._RC_ENDPOINT}/${N._BASE_PATH}/subscribers/${n}/products?id=${R.join("&id=")}`,
|
|
95
|
+
{
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Bearer ${this._API_KEY}`,
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
Accept: "application/json",
|
|
100
|
+
"X-Platform": "web",
|
|
101
|
+
"X-Version": l
|
|
74
102
|
}
|
|
75
103
|
}
|
|
76
104
|
)).json();
|
|
77
|
-
return this.toOfferingsPage(_);
|
|
105
|
+
return this.logMissingProductIds(R, i.product_details), this.toOfferingsPage(_, i);
|
|
78
106
|
}
|
|
79
|
-
async isEntitledTo(
|
|
80
|
-
const
|
|
81
|
-
`${
|
|
107
|
+
async isEntitledTo(n, r) {
|
|
108
|
+
const _ = await fetch(
|
|
109
|
+
`${N._RC_ENDPOINT}/${N._BASE_PATH}/entitlements/${n}`,
|
|
82
110
|
{
|
|
83
111
|
headers: {
|
|
84
112
|
Authorization: `Bearer ${this._API_KEY}`,
|
|
@@ -87,28 +115,28 @@ const r = class r {
|
|
|
87
115
|
}
|
|
88
116
|
}
|
|
89
117
|
);
|
|
90
|
-
return
|
|
91
|
-
(
|
|
92
|
-
).includes(
|
|
118
|
+
return _.status === 404 ? !1 : (await _.json()).entitlements.map(
|
|
119
|
+
(T) => T.lookup_key
|
|
120
|
+
).includes(r);
|
|
93
121
|
}
|
|
94
|
-
waitForEntitlement(
|
|
95
|
-
return new Promise((O,
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
122
|
+
waitForEntitlement(n, r, _ = 10) {
|
|
123
|
+
return new Promise((O, i) => {
|
|
124
|
+
const T = (e = 1) => this.isEntitledTo(n, r).then((f) => {
|
|
125
|
+
if (e > _)
|
|
98
126
|
return O(!1);
|
|
99
|
-
if (
|
|
127
|
+
if (f)
|
|
100
128
|
return O(!0);
|
|
101
129
|
setTimeout(
|
|
102
|
-
() =>
|
|
130
|
+
() => T(e + 1),
|
|
103
131
|
1e3
|
|
104
132
|
);
|
|
105
|
-
}).catch(
|
|
106
|
-
|
|
133
|
+
}).catch(i);
|
|
134
|
+
T();
|
|
107
135
|
});
|
|
108
136
|
}
|
|
109
|
-
async subscribe(
|
|
110
|
-
const O =
|
|
111
|
-
`${
|
|
137
|
+
async subscribe(n, r, _, R = "production") {
|
|
138
|
+
const O = R === "sandbox", i = await fetch(
|
|
139
|
+
`${N._RC_ENDPOINT}/${N._BASE_PATH}/subscribe`,
|
|
112
140
|
{
|
|
113
141
|
method: "POST",
|
|
114
142
|
headers: {
|
|
@@ -117,40 +145,54 @@ const r = class r {
|
|
|
117
145
|
Accept: "application/json"
|
|
118
146
|
},
|
|
119
147
|
body: JSON.stringify({
|
|
120
|
-
app_user_id:
|
|
121
|
-
product_id:
|
|
148
|
+
app_user_id: n,
|
|
149
|
+
product_id: r,
|
|
122
150
|
is_sandbox: O,
|
|
123
|
-
email:
|
|
151
|
+
email: _
|
|
124
152
|
})
|
|
125
153
|
}
|
|
126
154
|
);
|
|
127
|
-
if (
|
|
128
|
-
throw new
|
|
129
|
-
if (
|
|
130
|
-
throw new
|
|
131
|
-
if (
|
|
132
|
-
throw new
|
|
133
|
-
if (
|
|
134
|
-
throw new
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
return
|
|
155
|
+
if (i.status === I.BAD_REQUEST)
|
|
156
|
+
throw new g(i.status);
|
|
157
|
+
if (i.status === I.TOO_MANY_REQUESTS)
|
|
158
|
+
throw new w(i.status);
|
|
159
|
+
if (i.status === I.CONFLICT)
|
|
160
|
+
throw new F(i.status);
|
|
161
|
+
if (i.status === I.INTERNAL_SERVER_ERROR)
|
|
162
|
+
throw new Y(i.status);
|
|
163
|
+
if (i.status === I.OK || i.status === I.CREATED) {
|
|
164
|
+
const T = await i.json();
|
|
165
|
+
return t(T);
|
|
138
166
|
}
|
|
139
|
-
throw new
|
|
167
|
+
throw new h();
|
|
168
|
+
}
|
|
169
|
+
async getPackage(n, r) {
|
|
170
|
+
const _ = await this.listOfferings(n), R = [];
|
|
171
|
+
Object.values(_.all).forEach(
|
|
172
|
+
(i) => R.push(...i.packages)
|
|
173
|
+
);
|
|
174
|
+
const O = R.filter(
|
|
175
|
+
(i) => i.identifier === r
|
|
176
|
+
);
|
|
177
|
+
return O.length === 0 ? null : O[0];
|
|
140
178
|
}
|
|
141
|
-
|
|
142
|
-
const _ =
|
|
143
|
-
|
|
144
|
-
(O) =>
|
|
179
|
+
logMissingProductIds(n, r) {
|
|
180
|
+
const _ = {};
|
|
181
|
+
r.forEach(
|
|
182
|
+
(O) => _[O.identifier] = O
|
|
145
183
|
);
|
|
146
|
-
const
|
|
147
|
-
|
|
184
|
+
const R = [];
|
|
185
|
+
n.forEach((O) => {
|
|
186
|
+
_[O] === void 0 && R.push(O);
|
|
187
|
+
}), R.length > 0 && console.log(
|
|
188
|
+
"Could not find product data for product ids: ",
|
|
189
|
+
R,
|
|
190
|
+
". Please check that your product configuration is correct."
|
|
148
191
|
);
|
|
149
|
-
return N.length === 0 ? null : N[0];
|
|
150
192
|
}
|
|
151
193
|
};
|
|
152
|
-
A(
|
|
153
|
-
let
|
|
194
|
+
A(N, "_RC_ENDPOINT", "https://api.revenuecat.com"), A(N, "_BASE_PATH", "rcbilling/v1");
|
|
195
|
+
let U = N;
|
|
154
196
|
export {
|
|
155
|
-
|
|
197
|
+
U as Purchases
|
|
156
198
|
};
|
package/dist/Purchases.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(N,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(N=typeof globalThis<"u"?globalThis:N||self,e(N.Purchases={}))})(this,function(N){"use strict";var m=Object.defineProperty;var w=(N,e,A)=>e in N?m(N,e,{enumerable:!0,configurable:!0,writable:!0,value:A}):N[e]=A;var P=(N,e,A)=>(w(N,typeof e!="symbol"?e+"":e,A),A);const e=E=>({amount:E.amount,currency:E.currency}),A=E=>({id:E.identifier,identifier:E.identifier,displayName:E.title,currentPrice:E.current_price?e(E.current_price):null,normalPeriodDuration:E.normal_period_duration}),p=(E,n)=>{const r=n[E.platform_product_identifier];return{id:E.identifier,identifier:E.identifier,rcBillingProduct:r?A(r):null}},U=(E,n)=>({id:E.identifier,identifier:E.identifier,displayName:E.description,packages:E.packages.map(r=>p(r,n))}),L=E=>{var n;return{nextAction:E.next_action,data:{clientSecret:((n=E.data)==null?void 0:n.client_secret)??void 0}}};var I;(function(E){E[E.CONTINUE=100]="CONTINUE",E[E.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",E[E.PROCESSING=102]="PROCESSING",E[E.EARLY_HINTS=103]="EARLY_HINTS",E[E.OK=200]="OK",E[E.CREATED=201]="CREATED",E[E.ACCEPTED=202]="ACCEPTED",E[E.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",E[E.NO_CONTENT=204]="NO_CONTENT",E[E.RESET_CONTENT=205]="RESET_CONTENT",E[E.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",E[E.MULTI_STATUS=207]="MULTI_STATUS",E[E.MULTIPLE_CHOICES=300]="MULTIPLE_CHOICES",E[E.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",E[E.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",E[E.SEE_OTHER=303]="SEE_OTHER",E[E.NOT_MODIFIED=304]="NOT_MODIFIED",E[E.USE_PROXY=305]="USE_PROXY",E[E.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",E[E.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",E[E.BAD_REQUEST=400]="BAD_REQUEST",E[E.UNAUTHORIZED=401]="UNAUTHORIZED",E[E.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",E[E.FORBIDDEN=403]="FORBIDDEN",E[E.NOT_FOUND=404]="NOT_FOUND",E[E.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",E[E.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",E[E.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",E[E.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",E[E.CONFLICT=409]="CONFLICT",E[E.GONE=410]="GONE",E[E.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",E[E.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",E[E.REQUEST_TOO_LONG=413]="REQUEST_TOO_LONG",E[E.REQUEST_URI_TOO_LONG=414]="REQUEST_URI_TOO_LONG",E[E.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",E[E.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",E[E.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",E[E.IM_A_TEAPOT=418]="IM_A_TEAPOT",E[E.INSUFFICIENT_SPACE_ON_RESOURCE=419]="INSUFFICIENT_SPACE_ON_RESOURCE",E[E.METHOD_FAILURE=420]="METHOD_FAILURE",E[E.MISDIRECTED_REQUEST=421]="MISDIRECTED_REQUEST",E[E.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",E[E.LOCKED=423]="LOCKED",E[E.FAILED_DEPENDENCY=424]="FAILED_DEPENDENCY",E[E.UPGRADE_REQUIRED=426]="UPGRADE_REQUIRED",E[E.PRECONDITION_REQUIRED=428]="PRECONDITION_REQUIRED",E[E.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",E[E.REQUEST_HEADER_FIELDS_TOO_LARGE=431]="REQUEST_HEADER_FIELDS_TOO_LARGE",E[E.UNAVAILABLE_FOR_LEGAL_REASONS=451]="UNAVAILABLE_FOR_LEGAL_REASONS",E[E.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",E[E.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",E[E.BAD_GATEWAY=502]="BAD_GATEWAY",E[E.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",E[E.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",E[E.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",E[E.INSUFFICIENT_STORAGE=507]="INSUFFICIENT_STORAGE",E[E.NETWORK_AUTHENTICATION_REQUIRED=511]="NETWORK_AUTHENTICATION_REQUIRED"})(I||(I={}));class f extends Error{constructor(n,r){super(r),this.statusCode=n}}class t extends f{constructor(){super(I.INTERNAL_SERVER_ERROR,"An unknown error occurred.")}}class M extends f{}class h extends f{}class g extends f{}class F extends f{}const o="0.0.8",c=class c{constructor(n){P(this,"_API_KEY",null);P(this,"_APP_USER_ID",null);P(this,"toOfferingsPage",(n,r)=>{const _=n.offerings.find(T=>T.identifier===n.current_offering_id)??null,R={};r.product_details.forEach(T=>{R[T.identifier]=T});const O=_==null?null:U(_,R),i={};return n.offerings.forEach(T=>i[T.identifier]=U(T,R)),{all:i,current:O}});this._API_KEY=n,c._RC_ENDPOINT===void 0&&console.error("Project was build without some of the environment variables set")}async listOfferings(n){const _=await(await fetch(`${c._RC_ENDPOINT}/v1/subscribers/${n}/offerings`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json","X-Platform":"web","X-Version":o}})).json(),R=_.offerings.flatMap(T=>T.packages).map(T=>T.platform_product_identifier),i=await(await fetch(`${c._RC_ENDPOINT}/${c._BASE_PATH}/subscribers/${n}/products?id=${R.join("&id=")}`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json","X-Platform":"web","X-Version":o}})).json();return this.logMissingProductIds(R,i.product_details),this.toOfferingsPage(_,i)}async isEntitledTo(n,r){const _=await fetch(`${c._RC_ENDPOINT}/${c._BASE_PATH}/entitlements/${n}`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"}});return _.status===404?!1:(await _.json()).entitlements.map(T=>T.lookup_key).includes(r)}waitForEntitlement(n,r,_=10){return new Promise((O,i)=>{const T=(D=1)=>this.isEntitledTo(n,r).then(Y=>{if(D>_)return O(!1);if(Y)return O(!0);setTimeout(()=>T(D+1),1e3)}).catch(i);T()})}async subscribe(n,r,_,R="production"){const O=R==="sandbox",i=await fetch(`${c._RC_ENDPOINT}/${c._BASE_PATH}/subscribe`,{method:"POST",headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({app_user_id:n,product_id:r,is_sandbox:O,email:_})});if(i.status===I.BAD_REQUEST)throw new M(i.status);if(i.status===I.TOO_MANY_REQUESTS)throw new F(i.status);if(i.status===I.CONFLICT)throw new h(i.status);if(i.status===I.INTERNAL_SERVER_ERROR)throw new g(i.status);if(i.status===I.OK||i.status===I.CREATED){const T=await i.json();return L(T)}throw new t}async getPackage(n,r){const _=await this.listOfferings(n),R=[];Object.values(_.all).forEach(i=>R.push(...i.packages));const O=R.filter(i=>i.identifier===r);return O.length===0?null:O[0]}logMissingProductIds(n,r){const _={};r.forEach(O=>_[O.identifier]=O);const R=[];n.forEach(O=>{_[O]===void 0&&R.push(O)}),R.length>0&&console.log("Could not find product data for product ids: ",R,". Please check that your product configuration is correct.")}};P(c,"_RC_ENDPOINT","https://api.revenuecat.com"),P(c,"_BASE_PATH","rcbilling/v1");let l=c;N.Purchases=l,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenuecat/purchases-js",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"main": "./dist/Purchases.umd.js",
|
|
10
10
|
"module": "./dist/Purchases.es.js",
|
|
11
|
+
"types": "./dist/Purchases.es.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"import": "./dist/Purchases.es.js",
|