react-native-purchases 4.3.3 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/purchases.js CHANGED
@@ -1,4 +1,40 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.BILLING_FEATURE = exports.PURCHASE_TYPE = exports.ATTRIBUTION_NETWORK = void 0;
4
40
  var react_native_1 = require("react-native");
@@ -87,28 +123,58 @@ var Purchases = /** @class */ (function () {
87
123
  };
88
124
  /**
89
125
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
90
- * If an user tries to purchase a product that is active on the current app store account, we will treat it as a restore and alias
91
- * the new ID with the previous id.
92
- * @param {boolean} allowSharing Set this to true if you are passing in an appUserID but it is anonymous, this is true by default if you didn't pass an appUserID
126
+ * If an user tries to purchase a product that is active on the current app store account,
127
+ * we will treat it as a restore and alias the new ID with the previous id.
128
+ * @param {boolean} allowSharing Set this to true if you are passing in an appUserID but it is anonymous,
129
+ * this is true by default if you didn't pass an appUserID
130
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
93
131
  */
94
132
  Purchases.setAllowSharingStoreAccount = function (allowSharing) {
95
- RNPurchases.setAllowSharingStoreAccount(allowSharing);
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
137
+ case 1:
138
+ _a.sent();
139
+ RNPurchases.setAllowSharingStoreAccount(allowSharing);
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ });
96
144
  };
97
145
  /**
98
- * @param {boolean} finishTransactions Set finishTransactions to false if you aren't using Purchases SDK to make the purchase
146
+ * @param {boolean} finishTransactions Set finishTransactions to false if you aren't using Purchases SDK to
147
+ * make the purchase
148
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
99
149
  */
100
150
  Purchases.setFinishTransactions = function (finishTransactions) {
101
- RNPurchases.setFinishTransactions(finishTransactions);
151
+ return __awaiter(this, void 0, void 0, function () {
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
155
+ case 1:
156
+ _a.sent();
157
+ RNPurchases.setFinishTransactions(finishTransactions);
158
+ return [2 /*return*/];
159
+ }
160
+ });
161
+ });
102
162
  };
103
163
  /**
104
164
  * iOS only.
105
- * @param {boolean} simulatesAskToBuyInSandbox Set this property to true *only* when testing the ask-to-buy / SCA purchases flow.
106
- * More information: http://errors.rev.cat/ask-to-buy
165
+ * @param {boolean} simulatesAskToBuyInSandbox Set this property to true *only* when testing the ask-to-buy / SCA
166
+ * purchases flow. More information: http://errors.rev.cat/ask-to-buy
167
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
107
168
  */
108
169
  Purchases.setSimulatesAskToBuyInSandbox = function (simulatesAskToBuyInSandbox) {
109
- if (react_native_2.Platform.OS === "ios") {
110
- RNPurchases.setSimulatesAskToBuyInSandbox(simulatesAskToBuyInSandbox);
111
- }
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ return __generator(this, function (_a) {
172
+ if (react_native_2.Platform.OS === "ios") {
173
+ RNPurchases.setSimulatesAskToBuyInSandbox(simulatesAskToBuyInSandbox);
174
+ }
175
+ return [2 /*return*/];
176
+ });
177
+ });
112
178
  };
113
179
  /**
114
180
  * Sets a function to be called on updated purchaser info
@@ -149,7 +215,8 @@ var Purchases = /** @class */ (function () {
149
215
  };
150
216
  /**
151
217
  * Removes a given ShouldPurchasePromoProductListener
152
- * @param {ShouldPurchasePromoProductListener} listenerToRemove ShouldPurchasePromoProductListener reference of the listener to remove
218
+ * @param {ShouldPurchasePromoProductListener} listenerToRemove ShouldPurchasePromoProductListener reference of
219
+ * the listener to remove
153
220
  * @returns {boolean} True if listener was removed, false otherwise
154
221
  */
155
222
  Purchases.removeShouldPurchasePromoProductListener = function (listenerToRemove) {
@@ -166,27 +233,54 @@ var Purchases = /** @class */ (function () {
166
233
  * @param {Dict} data Attribution data from AppsFlyer, Adjust, or Branch
167
234
  * @param {ATTRIBUTION_NETWORKS} network Which network, see Purchases.ATTRIBUTION_NETWORKS
168
235
  * @param {String?} networkUserId An optional unique id for identifying the user. Needs to be a string.
236
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
169
237
  */
170
238
  Purchases.addAttributionData = function (data, network, networkUserId) {
171
- RNPurchases.addAttributionData(data, network, networkUserId);
239
+ return __awaiter(this, void 0, void 0, function () {
240
+ return __generator(this, function (_a) {
241
+ RNPurchases.addAttributionData(data, network, networkUserId);
242
+ return [2 /*return*/];
243
+ });
244
+ });
172
245
  };
173
246
  /**
174
247
  * Gets the map of entitlements -> offerings -> products
175
- * @returns {Promise<PurchasesOfferings>} Promise of entitlements structure
248
+ * @returns {Promise<PurchasesOfferings>} Promise of entitlements structure. The promise will be rejected if setup
249
+ * has not been called yet.
176
250
  */
177
251
  Purchases.getOfferings = function () {
178
- return RNPurchases.getOfferings();
252
+ return __awaiter(this, void 0, void 0, function () {
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
256
+ case 1:
257
+ _a.sent();
258
+ return [2 /*return*/, RNPurchases.getOfferings()];
259
+ }
260
+ });
261
+ });
179
262
  };
180
263
  /**
181
264
  * Fetch the product info
182
265
  * @param {String[]} productIdentifiers Array of product identifiers
183
266
  * @param {String} type Optional type of products to fetch, can be inapp or subs. Subs by default
184
- * @returns {Promise<PurchasesProduct[]>} A promise containing an array of products. The promise will be rejected if the products are not properly
185
- * configured in RevenueCat or if there is another error retrieving them. Rejections return an error code, and a userInfo object with more information.
267
+ * @returns {Promise<PurchasesProduct[]>} A promise containing an array of products. The promise will be rejected
268
+ * if the products are not properly configured in RevenueCat or if there is another error retrieving them.
269
+ * Rejections return an error code, and a userInfo object with more information. The promise will also be rejected
270
+ * if setup has not been called yet.
186
271
  */
187
272
  Purchases.getProducts = function (productIdentifiers, type) {
188
273
  if (type === void 0) { type = PURCHASE_TYPE.SUBS; }
189
- return RNPurchases.getProductInfo(productIdentifiers, type);
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ return __generator(this, function (_a) {
276
+ switch (_a.label) {
277
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
278
+ case 1:
279
+ _a.sent();
280
+ return [2 /*return*/, RNPurchases.getProductInfo(productIdentifiers, type)];
281
+ }
282
+ });
283
+ });
190
284
  };
191
285
  /**
192
286
  * Make a purchase
@@ -197,13 +291,23 @@ var Purchases = /** @class */ (function () {
197
291
  * @param {String} type Optional type of product, can be inapp or subs. Subs by default
198
292
  * @returns {Promise<{ productIdentifier: string, purchaserInfo:PurchaserInfo }>} A promise of an object containing
199
293
  * a purchaser info object and a product identifier. Rejections return an error code,
200
- * a boolean indicating if the user cancelled the purchase, and an object with more information.
294
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will
295
+ * also be rejected if setup has not been called yet.
201
296
  */
202
297
  Purchases.purchaseProduct = function (productIdentifier, upgradeInfo, type) {
203
298
  if (type === void 0) { type = PURCHASE_TYPE.SUBS; }
204
- return RNPurchases.purchaseProduct(productIdentifier, upgradeInfo, type, null).catch(function (error) {
205
- error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
206
- throw error;
299
+ return __awaiter(this, void 0, void 0, function () {
300
+ return __generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
303
+ case 1:
304
+ _a.sent();
305
+ return [2 /*return*/, RNPurchases.purchaseProduct(productIdentifier, upgradeInfo, type, null).catch(function (error) {
306
+ error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
307
+ throw error;
308
+ })];
309
+ }
310
+ });
207
311
  });
208
312
  };
209
313
  /**
@@ -213,15 +317,25 @@ var Purchases = /** @class */ (function () {
213
317
  * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
214
318
  * @returns {Promise<{ productIdentifier: string, purchaserInfo:PurchaserInfo }>} A promise of an object containing
215
319
  * a purchaser info object and a product identifier. Rejections return an error code,
216
- * a boolean indicating if the user cancelled the purchase, and an object with more information.
320
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
321
+ * rejected if setup has not been called yet.
217
322
  */
218
323
  Purchases.purchaseDiscountedProduct = function (product, discount) {
219
- if (typeof discount === "undefined" || discount == null) {
220
- throw new Error("A discount is required");
221
- }
222
- return RNPurchases.purchaseProduct(product.identifier, null, null, discount.timestamp.toString()).catch(function (error) {
223
- error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
224
- throw error;
324
+ return __awaiter(this, void 0, void 0, function () {
325
+ return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
328
+ case 1:
329
+ _a.sent();
330
+ if (typeof discount === "undefined" || discount == null) {
331
+ throw new Error("A discount is required");
332
+ }
333
+ return [2 /*return*/, RNPurchases.purchaseProduct(product.identifier, null, null, discount.timestamp.toString()).catch(function (error) {
334
+ error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
335
+ throw error;
336
+ })];
337
+ }
338
+ });
225
339
  });
226
340
  };
227
341
  /**
@@ -231,13 +345,23 @@ var Purchases = /** @class */ (function () {
231
345
  * @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
232
346
  * and the optional prorationMode.
233
347
  * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
234
- * a purchaser info object and a product identifier. Rejections return an error code,
235
- * a boolean indicating if the user cancelled the purchase, and an object with more information.
348
+ * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
349
+ * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
350
+ * has not been called yet.
236
351
  */
237
352
  Purchases.purchasePackage = function (aPackage, upgradeInfo) {
238
- return RNPurchases.purchasePackage(aPackage.identifier, aPackage.offeringIdentifier, upgradeInfo, null).catch(function (error) {
239
- error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
240
- throw error;
353
+ return __awaiter(this, void 0, void 0, function () {
354
+ return __generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
357
+ case 1:
358
+ _a.sent();
359
+ return [2 /*return*/, RNPurchases.purchasePackage(aPackage.identifier, aPackage.offeringIdentifier, upgradeInfo, null).catch(function (error) {
360
+ error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
361
+ throw error;
362
+ })];
363
+ }
364
+ });
241
365
  });
242
366
  };
243
367
  /**
@@ -246,157 +370,308 @@ var Purchases = /** @class */ (function () {
246
370
  * @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
247
371
  * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
248
372
  * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
249
- * a purchaser info object and a product identifier. Rejections return an error code,
250
- * a boolean indicating if the user cancelled the purchase, and an object with more information.
373
+ * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
374
+ * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
375
+ * has not been called yet.
251
376
  */
252
377
  Purchases.purchaseDiscountedPackage = function (aPackage, discount) {
253
- if (typeof discount === "undefined" || discount == null) {
254
- throw new Error("A discount is required");
255
- }
256
- return RNPurchases.purchasePackage(aPackage.identifier, aPackage.offeringIdentifier, null, discount.timestamp.toString()).catch(function (error) {
257
- error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
258
- throw error;
378
+ return __awaiter(this, void 0, void 0, function () {
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
382
+ case 1:
383
+ _a.sent();
384
+ if (typeof discount === "undefined" || discount == null) {
385
+ throw new Error("A discount is required");
386
+ }
387
+ return [2 /*return*/, RNPurchases.purchasePackage(aPackage.identifier, aPackage.offeringIdentifier, null, discount.timestamp.toString()).catch(function (error) {
388
+ error.userCancelled = error.code === errors_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
389
+ throw error;
390
+ })];
391
+ }
392
+ });
259
393
  });
260
394
  };
261
395
  /**
262
396
  * Restores a user's previous purchases and links their appUserIDs to any user's also using those purchases.
263
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
397
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
398
+ * userInfo object with more information. The promise will be also be rejected if setup has not been called yet.
264
399
  */
265
400
  Purchases.restoreTransactions = function () {
266
- return RNPurchases.restoreTransactions();
401
+ return __awaiter(this, void 0, void 0, function () {
402
+ return __generator(this, function (_a) {
403
+ switch (_a.label) {
404
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
405
+ case 1:
406
+ _a.sent();
407
+ return [2 /*return*/, RNPurchases.restoreTransactions()];
408
+ }
409
+ });
410
+ });
267
411
  };
268
412
  /**
269
413
  * Get the appUserID
270
- * @returns {string} The app user id in a promise
414
+ * @returns {Promise<string>} The app user id in a promise
271
415
  */
272
416
  Purchases.getAppUserID = function () {
273
- return RNPurchases.getAppUserID();
417
+ return __awaiter(this, void 0, void 0, function () {
418
+ return __generator(this, function (_a) {
419
+ switch (_a.label) {
420
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
421
+ case 1:
422
+ _a.sent();
423
+ return [2 /*return*/, RNPurchases.getAppUserID()];
424
+ }
425
+ });
426
+ });
274
427
  };
275
428
  /**
276
429
  * This function will logIn the current user with an appUserID. Typically this would be used after a log in
277
430
  * to identify a user without calling configure.
278
431
  * @param {String} appUserID The appUserID that should be linked to the currently user
279
- * @returns {Promise<LogInResult>} A promise of an object that contains the purchaserInfo after logging in, as well as a boolean indicating
280
- * whether the user has just been created for the first time in the RevenueCat backend.
432
+ * @returns {Promise<LogInResult>} A promise of an object that contains the purchaserInfo after logging in, as well
433
+ * as a boolean indicating whether the user has just been created for the first time in the RevenueCat backend. The
434
+ * promise will be rejected if setup has not been called yet or if there's an issue logging in.
281
435
  */
282
436
  Purchases.logIn = function (appUserID) {
283
- // noinspection SuspiciousTypeOfGuard
284
- if (typeof appUserID !== "string") {
285
- throw new Error("appUserID needs to be a string");
286
- }
287
- return RNPurchases.logIn(appUserID);
437
+ return __awaiter(this, void 0, void 0, function () {
438
+ return __generator(this, function (_a) {
439
+ switch (_a.label) {
440
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
441
+ case 1:
442
+ _a.sent();
443
+ // noinspection SuspiciousTypeOfGuard
444
+ if (typeof appUserID !== "string") {
445
+ throw new Error("appUserID needs to be a string");
446
+ }
447
+ return [2 /*return*/, RNPurchases.logIn(appUserID)];
448
+ }
449
+ });
450
+ });
288
451
  };
289
452
  /**
290
453
  * Logs out the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.
291
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
454
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code,
455
+ * and a userInfo object with more information. The promise will be rejected if setup has not been called yet or if
456
+ * there's an issue logging out.
292
457
  */
293
458
  Purchases.logOut = function () {
294
- return RNPurchases.logOut();
459
+ return __awaiter(this, void 0, void 0, function () {
460
+ return __generator(this, function (_a) {
461
+ switch (_a.label) {
462
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
463
+ case 1:
464
+ _a.sent();
465
+ return [2 /*return*/, RNPurchases.logOut()];
466
+ }
467
+ });
468
+ });
295
469
  };
296
470
  /**
297
471
  * @deprecated, use logIn instead.
298
472
  * This function will alias two appUserIDs together.
299
- * @param {String} newAppUserID The new appUserID that should be linked to the currently identified appUserID. Needs to be a string.
300
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
473
+ * @param {String} newAppUserID The new appUserID that should be linked to the currently identified appUserID.
474
+ * Needs to be a string.
475
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a
476
+ * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
477
+ * there's an issue creating the alias.
301
478
  */
302
479
  Purchases.createAlias = function (newAppUserID) {
303
- // noinspection SuspiciousTypeOfGuard
304
- if (typeof newAppUserID !== "string") {
305
- throw new Error("newAppUserID needs to be a string");
306
- }
307
- return RNPurchases.createAlias(newAppUserID);
480
+ return __awaiter(this, void 0, void 0, function () {
481
+ return __generator(this, function (_a) {
482
+ switch (_a.label) {
483
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
484
+ case 1:
485
+ _a.sent();
486
+ // noinspection SuspiciousTypeOfGuard
487
+ if (typeof newAppUserID !== "string") {
488
+ throw new Error("newAppUserID needs to be a string");
489
+ }
490
+ return [2 /*return*/, RNPurchases.createAlias(newAppUserID)];
491
+ }
492
+ });
493
+ });
308
494
  };
309
495
  /**
310
496
  * @deprecated, use logIn instead.
311
- * This function will identify the current user with an appUserID. Typically this would be used after a logout to identify a new user without calling configure
497
+ * This function will identify the current user with an appUserID. Typically this would be used after a logout to
498
+ * identify a new user without calling configure
312
499
  * @param {String} newAppUserID The appUserID that should be linked to the currently user
313
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
500
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
501
+ * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
502
+ * there's an issue identifying the user.
314
503
  */
315
504
  Purchases.identify = function (newAppUserID) {
316
- // noinspection SuspiciousTypeOfGuard
317
- if (typeof newAppUserID !== "string") {
318
- throw new Error("newAppUserID needs to be a string");
319
- }
320
- return RNPurchases.identify(newAppUserID);
505
+ return __awaiter(this, void 0, void 0, function () {
506
+ return __generator(this, function (_a) {
507
+ switch (_a.label) {
508
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
509
+ case 1:
510
+ _a.sent();
511
+ // noinspection SuspiciousTypeOfGuard
512
+ if (typeof newAppUserID !== "string") {
513
+ throw new Error("newAppUserID needs to be a string");
514
+ }
515
+ return [2 /*return*/, RNPurchases.identify(newAppUserID)];
516
+ }
517
+ });
518
+ });
321
519
  };
322
520
  /**
323
521
  * @deprecated, use logOut instead.
324
- * Resets the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.
325
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
522
+ * Resets the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the
523
+ * cache.
524
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
525
+ * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
526
+ * there's an issue resetting the user.
326
527
  */
327
528
  Purchases.reset = function () {
328
- return RNPurchases.reset();
529
+ return __awaiter(this, void 0, void 0, function () {
530
+ return __generator(this, function (_a) {
531
+ switch (_a.label) {
532
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
533
+ case 1:
534
+ _a.sent();
535
+ return [2 /*return*/, RNPurchases.reset()];
536
+ }
537
+ });
538
+ });
329
539
  };
330
540
  /**
331
541
  * Enables/Disables debugs logs
332
542
  * @param {boolean} enabled Enable or not debug logs
333
543
  */
334
544
  Purchases.setDebugLogsEnabled = function (enabled) {
335
- RNPurchases.setDebugLogsEnabled(enabled);
545
+ return __awaiter(this, void 0, void 0, function () {
546
+ return __generator(this, function (_a) {
547
+ RNPurchases.setDebugLogsEnabled(enabled);
548
+ return [2 /*return*/];
549
+ });
550
+ });
336
551
  };
337
552
  /**
338
553
  * Gets current purchaser info
339
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a userInfo object with more information.
554
+ * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
555
+ * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
556
+ * there's an issue getting the purchaser information.
340
557
  */
341
558
  Purchases.getPurchaserInfo = function () {
342
- return RNPurchases.getPurchaserInfo();
559
+ return __awaiter(this, void 0, void 0, function () {
560
+ return __generator(this, function (_a) {
561
+ switch (_a.label) {
562
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
563
+ case 1:
564
+ _a.sent();
565
+ return [2 /*return*/, RNPurchases.getPurchaserInfo()];
566
+ }
567
+ });
568
+ });
343
569
  };
344
570
  /**
345
571
  * This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation
346
572
  * for subscriptions anytime a sync is needed, like after a successful purchase.
347
573
  *
348
- * @warning This function should only be called if you're not calling makePurchase.
574
+ * @warning This function should only be called if you're not calling purchaseProduct/purchasePackage.
575
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
576
+ * syncing purchases.
349
577
  */
350
578
  Purchases.syncPurchases = function () {
351
- RNPurchases.syncPurchases();
579
+ return __awaiter(this, void 0, void 0, function () {
580
+ return __generator(this, function (_a) {
581
+ switch (_a.label) {
582
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
583
+ case 1:
584
+ _a.sent();
585
+ RNPurchases.syncPurchases();
586
+ return [2 /*return*/];
587
+ }
588
+ });
589
+ });
352
590
  };
353
591
  /**
354
592
  * Enable automatic collection of Apple Search Ad attribution. Disabled by default
355
593
  * @param {boolean} enabled Enable or not automatic apple search ads attribution collection
594
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
356
595
  */
357
596
  Purchases.setAutomaticAppleSearchAdsAttributionCollection = function (enabled) {
358
- if (react_native_2.Platform.OS === "ios") {
359
- RNPurchases.setAutomaticAppleSearchAdsAttributionCollection(enabled);
360
- }
597
+ return __awaiter(this, void 0, void 0, function () {
598
+ return __generator(this, function (_a) {
599
+ if (react_native_2.Platform.OS === "ios") {
600
+ RNPurchases.setAutomaticAppleSearchAdsAttributionCollection(enabled);
601
+ }
602
+ return [2 /*return*/];
603
+ });
604
+ });
361
605
  };
362
606
  /**
363
607
  * @returns { Promise<boolean> } If the `appUserID` has been generated by RevenueCat or not.
608
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
364
609
  */
365
610
  Purchases.isAnonymous = function () {
366
- return RNPurchases.isAnonymous();
611
+ return __awaiter(this, void 0, void 0, function () {
612
+ return __generator(this, function (_a) {
613
+ switch (_a.label) {
614
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
615
+ case 1:
616
+ _a.sent();
617
+ return [2 /*return*/, RNPurchases.isAnonymous()];
618
+ }
619
+ });
620
+ });
367
621
  };
368
622
  /**
369
- * iOS only. Computes whether or not a user is eligible for the introductory pricing period of a given product.
370
- * You should use this method to determine whether or not you show the user the normal product price or the
371
- * introductory price. This also applies to trials (trials are considered a type of introductory pricing).
623
+ * iOS only. Computes whether or not a user is eligible for the introductory pricing period of a given product.
624
+ * You should use this method to determine whether or not you show the user the normal product price or the
625
+ * introductory price. This also applies to trials (trials are considered a type of introductory pricing).
372
626
  *
373
- * @note Subscription groups are automatically collected for determining eligibility. If RevenueCat can't
374
- * definitively compute the eligibility, most likely because of missing group information, it will return
375
- * `INTRO_ELIGIBILITY_STATUS_UNKNOWN`. The best course of action on unknown status is to display the non-intro
376
- * pricing, to not create a misleading situation. To avoid this, make sure you are testing with the latest version of
377
- * iOS so that the subscription group can be collected by the SDK. Android always returns INTRO_ELIGIBILITY_STATUS_UNKNOWN.
627
+ * @note Subscription groups are automatically collected for determining eligibility. If RevenueCat can't
628
+ * definitively compute the eligibility, most likely because of missing group information, it will return
629
+ * `INTRO_ELIGIBILITY_STATUS_UNKNOWN`. The best course of action on unknown status is to display the non-intro
630
+ * pricing, to not create a misleading situation. To avoid this, make sure you are testing with the latest version of
631
+ * iOS so that the subscription group can be collected by the SDK. Android always returns INTRO_ELIGIBILITY_STATUS_UNKNOWN.
378
632
  *
379
- * @param productIdentifiers Array of product identifiers for which you want to compute eligibility
380
- * @returns { Promise<[productId: string]: IntroEligibility> } A map of IntroEligility per productId
633
+ * @param productIdentifiers Array of product identifiers for which you want to compute eligibility
634
+ * @returns { Promise<[productId: string]: IntroEligibility> } A map of IntroEligility per productId. The promise
635
+ * will be rejected if setup has not been called yet or if there's in an error checking eligibility.
381
636
  */
382
637
  Purchases.checkTrialOrIntroductoryPriceEligibility = function (productIdentifiers) {
383
- return RNPurchases.checkTrialOrIntroductoryPriceEligibility(productIdentifiers);
638
+ return __awaiter(this, void 0, void 0, function () {
639
+ return __generator(this, function (_a) {
640
+ switch (_a.label) {
641
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
642
+ case 1:
643
+ _a.sent();
644
+ return [2 /*return*/, RNPurchases.checkTrialOrIntroductoryPriceEligibility(productIdentifiers)];
645
+ }
646
+ });
647
+ });
384
648
  };
385
649
  /**
386
- * iOS only. Use this function to retrieve the `PurchasesPaymentDiscount` for a given `PurchasesPackage`.
650
+ * iOS only. Use this function to retrieve the `PurchasesPaymentDiscount` for a given `PurchasesPackage`.
387
651
  *
388
- * @param product The `PurchasesProduct` the user intends to purchase.
389
- * @param discount The `PurchasesDiscount` to apply to the product.
390
- * @returns { Promise<PurchasesPaymentDiscount> } Returns when the `PurchasesPaymentDiscount` is returned. Null is returned for Android and incompatible iOS versions.
652
+ * @param product The `PurchasesProduct` the user intends to purchase.
653
+ * @param discount The `PurchasesDiscount` to apply to the product.
654
+ * @returns { Promise<PurchasesPaymentDiscount> } Returns when the `PurchasesPaymentDiscount` is returned.
655
+ * Null is returned for Android and incompatible iOS versions. The promise will be rejected if setup has not been
656
+ * called yet or if there's an error getting the payment discount.
391
657
  */
392
658
  Purchases.getPaymentDiscount = function (product, discount) {
393
- if (react_native_2.Platform.OS === "android") {
394
- return Promise.resolve(undefined);
395
- }
396
- if (typeof discount === "undefined" || discount == null) {
397
- throw new Error("A discount is required");
398
- }
399
- return RNPurchases.getPaymentDiscount(product.identifier, discount.identifier);
659
+ return __awaiter(this, void 0, void 0, function () {
660
+ return __generator(this, function (_a) {
661
+ switch (_a.label) {
662
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
663
+ case 1:
664
+ _a.sent();
665
+ if (react_native_2.Platform.OS === "android") {
666
+ return [2 /*return*/, Promise.resolve(undefined)];
667
+ }
668
+ if (typeof discount === "undefined" || discount == null) {
669
+ throw new Error("A discount is required");
670
+ }
671
+ return [2 /*return*/, RNPurchases.getPaymentDiscount(product.identifier, discount.identifier)];
672
+ }
673
+ });
674
+ });
400
675
  };
401
676
  /**
402
677
  * Invalidates the cache for purchaser information.
@@ -407,18 +682,43 @@ var Purchases = /** @class */ (function () {
407
682
  *
408
683
  * This is useful for cases where purchaser information might have been updated outside of the app, like if a
409
684
  * promotional subscription is granted through the RevenueCat dashboard.
685
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or there's an error
686
+ * invalidating the purchaser info cache.
410
687
  */
411
688
  Purchases.invalidatePurchaserInfoCache = function () {
412
- RNPurchases.invalidatePurchaserInfoCache();
689
+ return __awaiter(this, void 0, void 0, function () {
690
+ return __generator(this, function (_a) {
691
+ switch (_a.label) {
692
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
693
+ case 1:
694
+ _a.sent();
695
+ RNPurchases.invalidatePurchaserInfoCache();
696
+ return [2 /*return*/];
697
+ }
698
+ });
699
+ });
413
700
  };
414
701
  /** iOS only. Presents a code redemption sheet, useful for redeeming offer codes
415
702
  * Refer to https://docs.revenuecat.com/docs/ios-subscription-offers#offer-codes for more information on how
416
703
  * to configure and use offer codes
704
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or there's an error
705
+ * presenting the code redemption sheet.
417
706
  */
418
707
  Purchases.presentCodeRedemptionSheet = function () {
419
- if (react_native_2.Platform.OS === "ios") {
420
- RNPurchases.presentCodeRedemptionSheet();
421
- }
708
+ return __awaiter(this, void 0, void 0, function () {
709
+ return __generator(this, function (_a) {
710
+ switch (_a.label) {
711
+ case 0:
712
+ if (!(react_native_2.Platform.OS === "ios")) return [3 /*break*/, 2];
713
+ return [4 /*yield*/, Purchases.throwIfNotConfigured()];
714
+ case 1:
715
+ _a.sent();
716
+ RNPurchases.presentCodeRedemptionSheet();
717
+ _a.label = 2;
718
+ case 2: return [2 /*return*/];
719
+ }
720
+ });
721
+ });
422
722
  };
423
723
  /**
424
724
  * Subscriber attributes are useful for storing additional, structured information on a user.
@@ -429,147 +729,385 @@ var Purchases = /** @class */ (function () {
429
729
  * restrictions refer to our guide: https://docs.revenuecat.com/docs/subscriber-attributes
430
730
  *
431
731
  * @param attributes Map of attributes by key. Set the value as an empty string to delete an attribute.
732
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or there's an error
733
+ * setting the subscriber attributes.
432
734
  */
433
735
  Purchases.setAttributes = function (attributes) {
434
- RNPurchases.setAttributes(attributes);
736
+ return __awaiter(this, void 0, void 0, function () {
737
+ return __generator(this, function (_a) {
738
+ switch (_a.label) {
739
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
740
+ case 1:
741
+ _a.sent();
742
+ RNPurchases.setAttributes(attributes);
743
+ return [2 /*return*/];
744
+ }
745
+ });
746
+ });
435
747
  };
436
748
  /**
437
749
  * Subscriber attribute associated with the email address for the user
438
750
  *
439
751
  * @param email Empty String or null will delete the subscriber attribute.
752
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
753
+ * setting the email.
440
754
  */
441
755
  Purchases.setEmail = function (email) {
442
- RNPurchases.setEmail(email);
756
+ return __awaiter(this, void 0, void 0, function () {
757
+ return __generator(this, function (_a) {
758
+ switch (_a.label) {
759
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
760
+ case 1:
761
+ _a.sent();
762
+ RNPurchases.setEmail(email);
763
+ return [2 /*return*/];
764
+ }
765
+ });
766
+ });
443
767
  };
444
768
  /**
445
769
  * Subscriber attribute associated with the phone number for the user
446
770
  *
447
771
  * @param phoneNumber Empty String or null will delete the subscriber attribute.
772
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
773
+ * setting the phone number.
448
774
  */
449
775
  Purchases.setPhoneNumber = function (phoneNumber) {
450
- RNPurchases.setPhoneNumber(phoneNumber);
776
+ return __awaiter(this, void 0, void 0, function () {
777
+ return __generator(this, function (_a) {
778
+ switch (_a.label) {
779
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
780
+ case 1:
781
+ _a.sent();
782
+ RNPurchases.setPhoneNumber(phoneNumber);
783
+ return [2 /*return*/];
784
+ }
785
+ });
786
+ });
451
787
  };
452
788
  /**
453
789
  * Subscriber attribute associated with the display name for the user
454
790
  *
455
791
  * @param displayName Empty String or null will delete the subscriber attribute.
792
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
793
+ * setting the display name.
456
794
  */
457
795
  Purchases.setDisplayName = function (displayName) {
458
- RNPurchases.setDisplayName(displayName);
796
+ return __awaiter(this, void 0, void 0, function () {
797
+ return __generator(this, function (_a) {
798
+ switch (_a.label) {
799
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
800
+ case 1:
801
+ _a.sent();
802
+ RNPurchases.setDisplayName(displayName);
803
+ return [2 /*return*/];
804
+ }
805
+ });
806
+ });
459
807
  };
460
808
  /**
461
809
  * Subscriber attribute associated with the push token for the user
462
810
  *
463
811
  * @param pushToken null will delete the subscriber attribute.
812
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
813
+ * setting the push token.
464
814
  */
465
815
  Purchases.setPushToken = function (pushToken) {
466
- RNPurchases.setPushToken(pushToken);
816
+ return __awaiter(this, void 0, void 0, function () {
817
+ return __generator(this, function (_a) {
818
+ switch (_a.label) {
819
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
820
+ case 1:
821
+ _a.sent();
822
+ RNPurchases.setPushToken(pushToken);
823
+ return [2 /*return*/];
824
+ }
825
+ });
826
+ });
467
827
  };
468
828
  /**
469
- * Set this property to your proxy URL before configuring Purchases *only* if you've received a proxy key value from your RevenueCat contact.
829
+ * Set this property to your proxy URL before configuring Purchases *only* if you've received a proxy key value
830
+ * from your RevenueCat contact.
831
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
832
+ * setting the proxy url.
470
833
  */
471
834
  Purchases.setProxyURL = function (url) {
472
- RNPurchases.setProxyURLString(url);
835
+ return __awaiter(this, void 0, void 0, function () {
836
+ return __generator(this, function (_a) {
837
+ switch (_a.label) {
838
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
839
+ case 1:
840
+ _a.sent();
841
+ RNPurchases.setProxyURLString(url);
842
+ return [2 /*return*/];
843
+ }
844
+ });
845
+ });
473
846
  };
474
847
  /**
475
848
  * Automatically collect subscriber attributes associated with the device identifiers.
476
849
  * $idfa, $idfv, $ip on iOS
477
850
  * $gpsAdId, $androidId, $ip on Android
851
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
852
+ * setting collecting the device identifiers.
478
853
  */
479
854
  Purchases.collectDeviceIdentifiers = function () {
480
- RNPurchases.collectDeviceIdentifiers();
855
+ return __awaiter(this, void 0, void 0, function () {
856
+ return __generator(this, function (_a) {
857
+ switch (_a.label) {
858
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
859
+ case 1:
860
+ _a.sent();
861
+ RNPurchases.collectDeviceIdentifiers();
862
+ return [2 /*return*/];
863
+ }
864
+ });
865
+ });
481
866
  };
482
867
  /**
483
868
  * Subscriber attribute associated with the Adjust Id for the user
484
869
  * Required for the RevenueCat Adjust integration
485
870
  *
486
871
  * @param adjustID Empty String or null will delete the subscriber attribute.
872
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
873
+ * setting Adjust ID.
487
874
  */
488
875
  Purchases.setAdjustID = function (adjustID) {
489
- RNPurchases.setAdjustID(adjustID);
876
+ return __awaiter(this, void 0, void 0, function () {
877
+ return __generator(this, function (_a) {
878
+ switch (_a.label) {
879
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
880
+ case 1:
881
+ _a.sent();
882
+ RNPurchases.setAdjustID(adjustID);
883
+ return [2 /*return*/];
884
+ }
885
+ });
886
+ });
490
887
  };
491
888
  /**
492
889
  * Subscriber attribute associated with the AppsFlyer Id for the user
493
890
  * Required for the RevenueCat AppsFlyer integration
494
891
  * @param appsflyerID Empty String or null will delete the subscriber attribute.
892
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
893
+ * setting the Appsflyer ID.
495
894
  */
496
895
  Purchases.setAppsflyerID = function (appsflyerID) {
497
- RNPurchases.setAppsflyerID(appsflyerID);
896
+ return __awaiter(this, void 0, void 0, function () {
897
+ return __generator(this, function (_a) {
898
+ switch (_a.label) {
899
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
900
+ case 1:
901
+ _a.sent();
902
+ RNPurchases.setAppsflyerID(appsflyerID);
903
+ return [2 /*return*/];
904
+ }
905
+ });
906
+ });
498
907
  };
499
908
  /**
500
909
  * Subscriber attribute associated with the Facebook SDK Anonymous Id for the user
501
910
  * Recommended for the RevenueCat Facebook integration
502
911
  *
503
912
  * @param fbAnonymousID Empty String or null will delete the subscriber attribute.
913
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
914
+ * setting the Facebook Anonymous ID.
504
915
  */
505
916
  Purchases.setFBAnonymousID = function (fbAnonymousID) {
506
- RNPurchases.setFBAnonymousID(fbAnonymousID);
917
+ return __awaiter(this, void 0, void 0, function () {
918
+ return __generator(this, function (_a) {
919
+ switch (_a.label) {
920
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
921
+ case 1:
922
+ _a.sent();
923
+ RNPurchases.setFBAnonymousID(fbAnonymousID);
924
+ return [2 /*return*/];
925
+ }
926
+ });
927
+ });
507
928
  };
508
929
  /**
509
930
  * Subscriber attribute associated with the mParticle Id for the user
510
931
  * Recommended for the RevenueCat mParticle integration
511
932
  *
512
933
  * @param mparticleID Empty String or null will delete the subscriber attribute.
934
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
935
+ * setting the Mparticle ID.
513
936
  */
514
937
  Purchases.setMparticleID = function (mparticleID) {
515
- RNPurchases.setMparticleID(mparticleID);
938
+ return __awaiter(this, void 0, void 0, function () {
939
+ return __generator(this, function (_a) {
940
+ switch (_a.label) {
941
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
942
+ case 1:
943
+ _a.sent();
944
+ RNPurchases.setMparticleID(mparticleID);
945
+ return [2 /*return*/];
946
+ }
947
+ });
948
+ });
516
949
  };
517
950
  /**
518
951
  * Subscriber attribute associated with the OneSignal Player Id for the user
519
952
  * Required for the RevenueCat OneSignal integration
520
953
  *
521
954
  * @param onesignalID Empty String or null will delete the subscriber attribute.
955
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
956
+ * setting the Onesignal ID.
522
957
  */
523
958
  Purchases.setOnesignalID = function (onesignalID) {
524
- RNPurchases.setOnesignalID(onesignalID);
959
+ return __awaiter(this, void 0, void 0, function () {
960
+ return __generator(this, function (_a) {
961
+ switch (_a.label) {
962
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
963
+ case 1:
964
+ _a.sent();
965
+ RNPurchases.setOnesignalID(onesignalID);
966
+ return [2 /*return*/];
967
+ }
968
+ });
969
+ });
970
+ };
971
+ /**
972
+ * Subscriber attribute associated with the Airship Channel Id for the user
973
+ * Required for the RevenueCat Airship integration
974
+ *
975
+ * @param airshipChannelID Empty String or null will delete the subscriber attribute.
976
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
977
+ * setting the Airship Channel ID.
978
+ */
979
+ Purchases.setAirshipChannelID = function (airshipChannelID) {
980
+ return __awaiter(this, void 0, void 0, function () {
981
+ return __generator(this, function (_a) {
982
+ switch (_a.label) {
983
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
984
+ case 1:
985
+ _a.sent();
986
+ RNPurchases.setAirshipChannelID(airshipChannelID);
987
+ return [2 /*return*/];
988
+ }
989
+ });
990
+ });
525
991
  };
526
992
  /**
527
993
  * Subscriber attribute associated with the install media source for the user
528
994
  *
529
995
  * @param mediaSource Empty String or null will delete the subscriber attribute.
996
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
997
+ * setting the media source.
530
998
  */
531
999
  Purchases.setMediaSource = function (mediaSource) {
532
- RNPurchases.setMediaSource(mediaSource);
1000
+ return __awaiter(this, void 0, void 0, function () {
1001
+ return __generator(this, function (_a) {
1002
+ switch (_a.label) {
1003
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1004
+ case 1:
1005
+ _a.sent();
1006
+ RNPurchases.setMediaSource(mediaSource);
1007
+ return [2 /*return*/];
1008
+ }
1009
+ });
1010
+ });
533
1011
  };
534
1012
  /**
535
1013
  * Subscriber attribute associated with the install campaign for the user
536
1014
  *
537
1015
  * @param campaign Empty String or null will delete the subscriber attribute.
1016
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
1017
+ * setting the campaign.
538
1018
  */
539
1019
  Purchases.setCampaign = function (campaign) {
540
- RNPurchases.setCampaign(campaign);
1020
+ return __awaiter(this, void 0, void 0, function () {
1021
+ return __generator(this, function (_a) {
1022
+ switch (_a.label) {
1023
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1024
+ case 1:
1025
+ _a.sent();
1026
+ RNPurchases.setCampaign(campaign);
1027
+ return [2 /*return*/];
1028
+ }
1029
+ });
1030
+ });
541
1031
  };
542
1032
  /**
543
1033
  * Subscriber attribute associated with the install ad group for the user
544
1034
  *
545
1035
  * @param adGroup Empty String or null will delete the subscriber attribute.
1036
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
1037
+ * setting ad group.
546
1038
  */
547
1039
  Purchases.setAdGroup = function (adGroup) {
548
- RNPurchases.setAdGroup(adGroup);
1040
+ return __awaiter(this, void 0, void 0, function () {
1041
+ return __generator(this, function (_a) {
1042
+ switch (_a.label) {
1043
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1044
+ case 1:
1045
+ _a.sent();
1046
+ RNPurchases.setAdGroup(adGroup);
1047
+ return [2 /*return*/];
1048
+ }
1049
+ });
1050
+ });
549
1051
  };
550
1052
  /**
551
1053
  * Subscriber attribute associated with the install ad for the user
552
1054
  *
553
1055
  * @param ad Empty String or null will delete the subscriber attribute.
1056
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
1057
+ * setting the ad subscriber attribute.
554
1058
  */
555
1059
  Purchases.setAd = function (ad) {
556
- RNPurchases.setAd(ad);
1060
+ return __awaiter(this, void 0, void 0, function () {
1061
+ return __generator(this, function (_a) {
1062
+ switch (_a.label) {
1063
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1064
+ case 1:
1065
+ _a.sent();
1066
+ RNPurchases.setAd(ad);
1067
+ return [2 /*return*/];
1068
+ }
1069
+ });
1070
+ });
557
1071
  };
558
1072
  /**
559
1073
  * Subscriber attribute associated with the install keyword for the user
560
1074
  *
561
1075
  * @param keyword Empty String or null will delete the subscriber attribute.
1076
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
1077
+ * setting the keyword.
562
1078
  */
563
1079
  Purchases.setKeyword = function (keyword) {
564
- RNPurchases.setKeyword(keyword);
1080
+ return __awaiter(this, void 0, void 0, function () {
1081
+ return __generator(this, function (_a) {
1082
+ switch (_a.label) {
1083
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1084
+ case 1:
1085
+ _a.sent();
1086
+ RNPurchases.setKeyword(keyword);
1087
+ return [2 /*return*/];
1088
+ }
1089
+ });
1090
+ });
565
1091
  };
566
1092
  /**
567
1093
  * Subscriber attribute associated with the install ad creative for the user
568
1094
  *
569
1095
  * @param creative Empty String or null will delete the subscriber attribute.
1096
+ * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or if there's an error
1097
+ * setting the creative subscriber attribute.
570
1098
  */
571
1099
  Purchases.setCreative = function (creative) {
572
- RNPurchases.setCreative(creative);
1100
+ return __awaiter(this, void 0, void 0, function () {
1101
+ return __generator(this, function (_a) {
1102
+ switch (_a.label) {
1103
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1104
+ case 1:
1105
+ _a.sent();
1106
+ RNPurchases.setCreative(creative);
1107
+ return [2 /*return*/];
1108
+ }
1109
+ });
1110
+ });
573
1111
  };
574
1112
  /**
575
1113
  * Check if billing is supported for the current user (meaning IN-APP purchases are supported)
@@ -577,14 +1115,39 @@ var Purchases = /** @class */ (function () {
577
1115
  *
578
1116
  * Note: Billing features are only relevant to Google Play Android users.
579
1117
  * For other stores and platforms, billing features won't be checked.
1118
+ *
580
1119
  * @param feature An array of feature types to check for support. Feature types must be one of
581
1120
  * [BILLING_FEATURE]. By default, is an empty list and no specific feature support will be checked.
582
- * @returns {Promise<Boolean>} promise with boolean response
1121
+ * @returns {Promise<Boolean>} promise with boolean response. True if billing is supported, false otherwise.
583
1122
  */
584
1123
  Purchases.canMakePayments = function (features) {
585
1124
  if (features === void 0) { features = []; }
586
1125
  return RNPurchases.canMakePayments(features);
587
1126
  };
1127
+ /**
1128
+ * Check if setup has finished and Purchases has been configured.
1129
+ *
1130
+ * @returns {Promise<Boolean>} promise with boolean response
1131
+ */
1132
+ Purchases.isConfigured = function () {
1133
+ return RNPurchases.isConfigured();
1134
+ };
1135
+ Purchases.throwIfNotConfigured = function () {
1136
+ return __awaiter(this, void 0, void 0, function () {
1137
+ var isConfigured;
1138
+ return __generator(this, function (_a) {
1139
+ switch (_a.label) {
1140
+ case 0: return [4 /*yield*/, Purchases.isConfigured()];
1141
+ case 1:
1142
+ isConfigured = _a.sent();
1143
+ if (!isConfigured) {
1144
+ throw new errors_1.UninitializedPurchasesError();
1145
+ }
1146
+ return [2 /*return*/];
1147
+ }
1148
+ });
1149
+ });
1150
+ };
588
1151
  /**
589
1152
  * Enum for attribution networks
590
1153
  * @readonly
@@ -637,6 +1200,7 @@ var Purchases = /** @class */ (function () {
637
1200
  * @enum {string}
638
1201
  */
639
1202
  Purchases.PURCHASES_ERROR_CODE = errors_1.PURCHASES_ERROR_CODE;
1203
+ Purchases.UninitializedPurchasesError = errors_1.UninitializedPurchasesError;
640
1204
  return Purchases;
641
1205
  }());
642
1206
  exports.default = Purchases;