@revenuecat/purchases-js 0.0.8 → 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 +4 -3
- package/dist/Purchases.es.js +75 -65
- package/dist/Purchases.umd.js +1 -1
- package/package.json +1 -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;
|
|
@@ -49,6 +49,7 @@ export declare class Purchases {
|
|
|
49
49
|
waitForEntitlement(appUserId: string, entitlementIdentifier: string, maxAttempts?: number): Promise<boolean>;
|
|
50
50
|
subscribe(appUserId: string, productId: string, email: string, environment?: "sandbox" | "production"): Promise<SubscribeResponse>;
|
|
51
51
|
getPackage(appUserId: string, packageIdentifier: string): Promise<Package | null>;
|
|
52
|
+
private logMissingProductIds;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
declare interface SubscribeResponse {
|
package/dist/Purchases.es.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var A = (E, n, r) => (
|
|
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
|
-
}),
|
|
7
|
+
}), L = (E) => ({
|
|
8
8
|
id: E.identifier,
|
|
9
9
|
identifier: E.identifier,
|
|
10
10
|
displayName: E.title,
|
|
11
|
-
currentPrice: E.current_price ?
|
|
11
|
+
currentPrice: E.current_price ? p(E.current_price) : null,
|
|
12
12
|
normalPeriodDuration: E.normal_period_duration
|
|
13
13
|
}), M = (E, n) => {
|
|
14
14
|
const r = n[E.platform_product_identifier];
|
|
15
15
|
return {
|
|
16
16
|
id: E.identifier,
|
|
17
17
|
identifier: E.identifier,
|
|
18
|
-
rcBillingProduct: r ?
|
|
18
|
+
rcBillingProduct: r ? L(r) : null
|
|
19
19
|
};
|
|
20
|
-
},
|
|
20
|
+
}, P = (E, n) => ({
|
|
21
21
|
id: E.identifier,
|
|
22
22
|
identifier: E.identifier,
|
|
23
23
|
displayName: E.description,
|
|
24
24
|
packages: E.packages.map(
|
|
25
25
|
(r) => M(r, n)
|
|
26
26
|
)
|
|
27
|
-
}),
|
|
27
|
+
}), t = (E) => {
|
|
28
28
|
var n;
|
|
29
29
|
return {
|
|
30
30
|
nextAction: E.next_action,
|
|
@@ -47,70 +47,66 @@ class h extends c {
|
|
|
47
47
|
super(I.INTERNAL_SERVER_ERROR, "An unknown error occurred.");
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
class
|
|
50
|
+
class g extends c {
|
|
51
51
|
}
|
|
52
|
-
class
|
|
52
|
+
class F extends c {
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class Y extends c {
|
|
55
55
|
}
|
|
56
|
-
class
|
|
56
|
+
class w extends c {
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const l = "0.0.8", N = class N {
|
|
59
59
|
constructor(n) {
|
|
60
60
|
A(this, "_API_KEY", null);
|
|
61
61
|
A(this, "_APP_USER_ID", null);
|
|
62
62
|
A(this, "toOfferingsPage", (n, r) => {
|
|
63
|
-
const _ = n.offerings.
|
|
63
|
+
const _ = n.offerings.find(
|
|
64
64
|
(T) => T.identifier === n.current_offering_id
|
|
65
|
-
),
|
|
65
|
+
) ?? null, R = {};
|
|
66
66
|
r.product_details.forEach((T) => {
|
|
67
|
-
|
|
67
|
+
R[T.identifier] = T;
|
|
68
68
|
});
|
|
69
|
-
const R = {};
|
|
70
|
-
return
|
|
71
|
-
(T) =>
|
|
72
|
-
i[T.platform_product_identifier].current_price
|
|
73
|
-
)
|
|
69
|
+
const O = _ == null ? null : P(_, R), i = {};
|
|
70
|
+
return n.offerings.forEach(
|
|
71
|
+
(T) => i[T.identifier] = P(T, R)
|
|
74
72
|
), {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
),
|
|
78
|
-
priceByPackageId: R
|
|
73
|
+
all: i,
|
|
74
|
+
current: O
|
|
79
75
|
};
|
|
80
76
|
});
|
|
81
|
-
this._API_KEY = n,
|
|
77
|
+
this._API_KEY = n, N._RC_ENDPOINT === void 0 && console.error(
|
|
82
78
|
"Project was build without some of the environment variables set"
|
|
83
79
|
);
|
|
84
80
|
}
|
|
85
81
|
async listOfferings(n) {
|
|
86
82
|
const _ = await (await fetch(
|
|
87
|
-
`${
|
|
83
|
+
`${N._RC_ENDPOINT}/v1/subscribers/${n}/offerings`,
|
|
88
84
|
{
|
|
89
85
|
headers: {
|
|
90
86
|
Authorization: `Bearer ${this._API_KEY}`,
|
|
91
87
|
"Content-Type": "application/json",
|
|
92
88
|
Accept: "application/json",
|
|
93
89
|
"X-Platform": "web",
|
|
94
|
-
"X-Version":
|
|
90
|
+
"X-Version": l
|
|
95
91
|
}
|
|
96
92
|
}
|
|
97
|
-
)).json(),
|
|
98
|
-
`${
|
|
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=")}`,
|
|
99
95
|
{
|
|
100
96
|
headers: {
|
|
101
97
|
Authorization: `Bearer ${this._API_KEY}`,
|
|
102
98
|
"Content-Type": "application/json",
|
|
103
99
|
Accept: "application/json",
|
|
104
100
|
"X-Platform": "web",
|
|
105
|
-
"X-Version":
|
|
101
|
+
"X-Version": l
|
|
106
102
|
}
|
|
107
103
|
}
|
|
108
104
|
)).json();
|
|
109
|
-
return this.toOfferingsPage(_,
|
|
105
|
+
return this.logMissingProductIds(R, i.product_details), this.toOfferingsPage(_, i);
|
|
110
106
|
}
|
|
111
107
|
async isEntitledTo(n, r) {
|
|
112
108
|
const _ = await fetch(
|
|
113
|
-
`${
|
|
109
|
+
`${N._RC_ENDPOINT}/${N._BASE_PATH}/entitlements/${n}`,
|
|
114
110
|
{
|
|
115
111
|
headers: {
|
|
116
112
|
Authorization: `Bearer ${this._API_KEY}`,
|
|
@@ -120,27 +116,27 @@ const P = "0.0.8", O = class O {
|
|
|
120
116
|
}
|
|
121
117
|
);
|
|
122
118
|
return _.status === 404 ? !1 : (await _.json()).entitlements.map(
|
|
123
|
-
(
|
|
119
|
+
(T) => T.lookup_key
|
|
124
120
|
).includes(r);
|
|
125
121
|
}
|
|
126
122
|
waitForEntitlement(n, r, _ = 10) {
|
|
127
|
-
return new Promise((
|
|
128
|
-
const
|
|
123
|
+
return new Promise((O, i) => {
|
|
124
|
+
const T = (e = 1) => this.isEntitledTo(n, r).then((f) => {
|
|
129
125
|
if (e > _)
|
|
130
|
-
return
|
|
126
|
+
return O(!1);
|
|
131
127
|
if (f)
|
|
132
|
-
return
|
|
128
|
+
return O(!0);
|
|
133
129
|
setTimeout(
|
|
134
|
-
() =>
|
|
130
|
+
() => T(e + 1),
|
|
135
131
|
1e3
|
|
136
132
|
);
|
|
137
|
-
}).catch(
|
|
138
|
-
|
|
133
|
+
}).catch(i);
|
|
134
|
+
T();
|
|
139
135
|
});
|
|
140
136
|
}
|
|
141
|
-
async subscribe(n, r, _,
|
|
142
|
-
const
|
|
143
|
-
`${
|
|
137
|
+
async subscribe(n, r, _, R = "production") {
|
|
138
|
+
const O = R === "sandbox", i = await fetch(
|
|
139
|
+
`${N._RC_ENDPOINT}/${N._BASE_PATH}/subscribe`,
|
|
144
140
|
{
|
|
145
141
|
method: "POST",
|
|
146
142
|
headers: {
|
|
@@ -151,38 +147,52 @@ const P = "0.0.8", O = class O {
|
|
|
151
147
|
body: JSON.stringify({
|
|
152
148
|
app_user_id: n,
|
|
153
149
|
product_id: r,
|
|
154
|
-
is_sandbox:
|
|
150
|
+
is_sandbox: O,
|
|
155
151
|
email: _
|
|
156
152
|
})
|
|
157
153
|
}
|
|
158
154
|
);
|
|
159
|
-
if (
|
|
160
|
-
throw new
|
|
161
|
-
if (
|
|
162
|
-
throw new
|
|
163
|
-
if (
|
|
164
|
-
throw new
|
|
165
|
-
if (
|
|
166
|
-
throw new
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
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);
|
|
170
166
|
}
|
|
171
167
|
throw new h();
|
|
172
168
|
}
|
|
173
169
|
async getPackage(n, r) {
|
|
174
|
-
const _ = await this.listOfferings(n),
|
|
175
|
-
_.
|
|
176
|
-
(
|
|
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];
|
|
178
|
+
}
|
|
179
|
+
logMissingProductIds(n, r) {
|
|
180
|
+
const _ = {};
|
|
181
|
+
r.forEach(
|
|
182
|
+
(O) => _[O.identifier] = O
|
|
177
183
|
);
|
|
178
|
-
const R =
|
|
179
|
-
|
|
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."
|
|
180
191
|
);
|
|
181
|
-
return R.length === 0 ? null : R[0];
|
|
182
192
|
}
|
|
183
193
|
};
|
|
184
|
-
A(
|
|
185
|
-
let U =
|
|
194
|
+
A(N, "_RC_ENDPOINT", "https://api.revenuecat.com"), A(N, "_BASE_PATH", "rcbilling/v1");
|
|
195
|
+
let U = N;
|
|
186
196
|
export {
|
|
187
197
|
U as Purchases
|
|
188
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"})});
|