react-native-purchases 4.6.0 → 5.0.0-beta.2

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
@@ -36,17 +36,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.BILLING_FEATURE = exports.PURCHASE_TYPE = exports.ATTRIBUTION_NETWORK = void 0;
39
+ exports.BILLING_FEATURE = exports.PURCHASE_TYPE = void 0;
40
40
  var react_native_1 = require("react-native");
41
41
  var errors_1 = require("./errors");
42
42
  var offerings_1 = require("./offerings");
43
43
  var react_native_2 = require("react-native");
44
44
  var RNPurchases = react_native_1.NativeModules.RNPurchases;
45
45
  var eventEmitter = new react_native_1.NativeEventEmitter(RNPurchases);
46
- var purchaserInfoUpdateListeners = [];
46
+ var customerInfoUpdateListeners = [];
47
47
  var shouldPurchasePromoProductListeners = [];
48
- eventEmitter.addListener("Purchases-PurchaserInfoUpdated", function (purchaserInfo) {
49
- purchaserInfoUpdateListeners.forEach(function (listener) { return listener(purchaserInfo); });
48
+ eventEmitter.addListener("Purchases-CustomerInfoUpdated", function (customerInfo) {
49
+ customerInfoUpdateListeners.forEach(function (listener) { return listener(customerInfo); });
50
50
  });
51
51
  eventEmitter.addListener("Purchases-ShouldPurchasePromoProduct", function (_a) {
52
52
  var callbackID = _a.callbackID;
@@ -54,15 +54,6 @@ eventEmitter.addListener("Purchases-ShouldPurchasePromoProduct", function (_a) {
54
54
  return listener(function () { return RNPurchases.makeDeferredPurchase(callbackID); });
55
55
  });
56
56
  });
57
- var ATTRIBUTION_NETWORK;
58
- (function (ATTRIBUTION_NETWORK) {
59
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["APPLE_SEARCH_ADS"] = 0] = "APPLE_SEARCH_ADS";
60
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["ADJUST"] = 1] = "ADJUST";
61
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["APPSFLYER"] = 2] = "APPSFLYER";
62
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["BRANCH"] = 3] = "BRANCH";
63
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["TENJIN"] = 4] = "TENJIN";
64
- ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["FACEBOOK"] = 5] = "FACEBOOK";
65
- })(ATTRIBUTION_NETWORK = exports.ATTRIBUTION_NETWORK || (exports.ATTRIBUTION_NETWORK = {}));
66
57
  var PURCHASE_TYPE;
67
58
  (function (PURCHASE_TYPE) {
68
59
  /**
@@ -109,17 +100,19 @@ var Purchases = /** @class */ (function () {
109
100
  * Sets up Purchases with your API key and an app user id.
110
101
  * @param {String} apiKey RevenueCat API Key. Needs to be a String
111
102
  * @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
112
- * @param {boolean?} observerMode An optional boolean. Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat's backend. Default is FALSE.
103
+ * @param {boolean} [observerMode=false] An optional boolean. Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat's backend. Default is FALSE.
104
+ * @param {boolean} [usesStoreKit2IfAvailable=false] An optional boolean. iOS-only. Set this to TRUE to enable StoreKit2 on compatible devices.
113
105
  * @param {String?} userDefaultsSuiteName An optional string. iOS-only, will be ignored for Android.
114
106
  * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
115
107
  * Default is null, which will make the SDK use standardUserDefaults.
116
108
  */
117
- Purchases.setup = function (apiKey, appUserID, observerMode, userDefaultsSuiteName) {
109
+ Purchases.configure = function (apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable) {
118
110
  if (observerMode === void 0) { observerMode = false; }
111
+ if (usesStoreKit2IfAvailable === void 0) { usesStoreKit2IfAvailable = false; }
119
112
  if (appUserID !== null && typeof appUserID !== "undefined" && typeof appUserID !== "string") {
120
113
  throw new Error("appUserID needs to be a string");
121
114
  }
122
- RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName);
115
+ RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable);
123
116
  };
124
117
  /**
125
118
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
@@ -177,23 +170,23 @@ var Purchases = /** @class */ (function () {
177
170
  });
178
171
  };
179
172
  /**
180
- * Sets a function to be called on updated purchaser info
181
- * @param {PurchaserInfoUpdateListener} purchaserInfoUpdateListener PurchaserInfo update listener
173
+ * Sets a function to be called on updated customer info
174
+ * @param {CustomerInfoUpdateListener} customerInfoUpdateListener CustomerInfo update listener
182
175
  */
183
- Purchases.addPurchaserInfoUpdateListener = function (purchaserInfoUpdateListener) {
184
- if (typeof purchaserInfoUpdateListener !== "function") {
185
- throw new Error("addPurchaserInfoUpdateListener needs a function");
176
+ Purchases.addCustomerInfoUpdateListener = function (customerInfoUpdateListener) {
177
+ if (typeof customerInfoUpdateListener !== "function") {
178
+ throw new Error("addCustomerInfoUpdateListener needs a function");
186
179
  }
187
- purchaserInfoUpdateListeners.push(purchaserInfoUpdateListener);
180
+ customerInfoUpdateListeners.push(customerInfoUpdateListener);
188
181
  };
189
182
  /**
190
- * Removes a given PurchaserInfoUpdateListener
191
- * @param {PurchaserInfoUpdateListener} listenerToRemove PurchaserInfoUpdateListener reference of the listener to remove
183
+ * Removes a given CustomerInfoUpdateListener
184
+ * @param {CustomerInfoUpdateListener} listenerToRemove CustomerInfoUpdateListener reference of the listener to remove
192
185
  * @returns {boolean} True if listener was removed, false otherwise
193
186
  */
194
- Purchases.removePurchaserInfoUpdateListener = function (listenerToRemove) {
195
- if (purchaserInfoUpdateListeners.includes(listenerToRemove)) {
196
- purchaserInfoUpdateListeners = purchaserInfoUpdateListeners.filter(function (listener) { return listenerToRemove !== listener; });
187
+ Purchases.removeCustomerInfoUpdateListener = function (listenerToRemove) {
188
+ if (customerInfoUpdateListeners.includes(listenerToRemove)) {
189
+ customerInfoUpdateListeners = customerInfoUpdateListeners.filter(function (listener) { return listenerToRemove !== listener; });
197
190
  return true;
198
191
  }
199
192
  return false;
@@ -226,23 +219,6 @@ var Purchases = /** @class */ (function () {
226
219
  }
227
220
  return false;
228
221
  };
229
- /**
230
- * @deprecated, use set<NetworkId> methods instead.
231
- *
232
- * Add a dict of attribution information
233
- * @param {Dict} data Attribution data from AppsFlyer, Adjust, or Branch
234
- * @param {ATTRIBUTION_NETWORKS} network Which network, see Purchases.ATTRIBUTION_NETWORKS
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.
237
- */
238
- Purchases.addAttributionData = function (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
- });
245
- };
246
222
  /**
247
223
  * Gets the map of entitlements -> offerings -> products
248
224
  * @returns {Promise<PurchasesOfferings>} Promise of entitlements structure. The promise will be rejected if setup
@@ -264,7 +240,7 @@ var Purchases = /** @class */ (function () {
264
240
  * Fetch the product info
265
241
  * @param {String[]} productIdentifiers Array of product identifiers
266
242
  * @param {String} type Optional type of products to fetch, can be inapp or subs. Subs by default
267
- * @returns {Promise<PurchasesProduct[]>} A promise containing an array of products. The promise will be rejected
243
+ * @returns {Promise<PurchasesStoreProduct[]>} A promise containing an array of products. The promise will be rejected
268
244
  * if the products are not properly configured in RevenueCat or if there is another error retrieving them.
269
245
  * Rejections return an error code, and a userInfo object with more information. The promise will also be rejected
270
246
  * if setup has not been called yet.
@@ -289,8 +265,8 @@ var Purchases = /** @class */ (function () {
289
265
  * @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
290
266
  * and the optional prorationMode.
291
267
  * @param {String} type Optional type of product, can be inapp or subs. Subs by default
292
- * @returns {Promise<{ productIdentifier: string, purchaserInfo:PurchaserInfo }>} A promise of an object containing
293
- * a purchaser info object and a product identifier. Rejections return an error code,
268
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
269
+ * a customer info object and a product identifier. Rejections return an error code,
294
270
  * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will
295
271
  * also be rejected if setup has not been called yet.
296
272
  */
@@ -313,10 +289,10 @@ var Purchases = /** @class */ (function () {
313
289
  /**
314
290
  * iOS only. Purchase a product applying a given discount.
315
291
  *
316
- * @param {PurchasesProduct} product The product you want to purchase
317
- * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
318
- * @returns {Promise<{ productIdentifier: string, purchaserInfo:PurchaserInfo }>} A promise of an object containing
319
- * a purchaser info object and a product identifier. Rejections return an error code,
292
+ * @param {PurchasesStoreProduct} product The product you want to purchase
293
+ * @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
294
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
295
+ * a customer info object and a product identifier. Rejections return an error code,
320
296
  * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
321
297
  * rejected if setup has not been called yet.
322
298
  */
@@ -344,8 +320,8 @@ var Purchases = /** @class */ (function () {
344
320
  * @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
345
321
  * @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
346
322
  * and the optional prorationMode.
347
- * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
348
- * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
323
+ * @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
324
+ * a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
349
325
  * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
350
326
  * has not been called yet.
351
327
  */
@@ -368,9 +344,9 @@ var Purchases = /** @class */ (function () {
368
344
  * iOS only. Purchase a package applying a given discount.
369
345
  *
370
346
  * @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
371
- * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
372
- * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
373
- * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
347
+ * @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
348
+ * @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
349
+ * a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
374
350
  * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
375
351
  * has not been called yet.
376
352
  */
@@ -394,7 +370,7 @@ var Purchases = /** @class */ (function () {
394
370
  };
395
371
  /**
396
372
  * Restores a user's previous purchases and links their appUserIDs to any user's also using those purchases.
397
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
373
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
398
374
  * userInfo object with more information. The promise will be also be rejected if setup has not been called yet.
399
375
  */
400
376
  Purchases.restoreTransactions = function () {
@@ -429,7 +405,7 @@ var Purchases = /** @class */ (function () {
429
405
  * This function will logIn the current user with an appUserID. Typically this would be used after a log in
430
406
  * to identify a user without calling configure.
431
407
  * @param {String} appUserID The appUserID that should be linked to the currently user
432
- * @returns {Promise<LogInResult>} A promise of an object that contains the purchaserInfo after logging in, as well
408
+ * @returns {Promise<LogInResult>} A promise of an object that contains the customerInfo after logging in, as well
433
409
  * as a boolean indicating whether the user has just been created for the first time in the RevenueCat backend. The
434
410
  * promise will be rejected if setup has not been called yet or if there's an issue logging in.
435
411
  */
@@ -451,7 +427,7 @@ var Purchases = /** @class */ (function () {
451
427
  };
452
428
  /**
453
429
  * Logs out the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.
454
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code,
430
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code,
455
431
  * and a userInfo object with more information. The promise will be rejected if setup has not been called yet or if
456
432
  * there's an issue logging out.
457
433
  */
@@ -467,76 +443,6 @@ var Purchases = /** @class */ (function () {
467
443
  });
468
444
  });
469
445
  };
470
- /**
471
- * @deprecated, use logIn instead.
472
- * This function will alias two appUserIDs together.
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.
478
- */
479
- Purchases.createAlias = function (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
- });
494
- };
495
- /**
496
- * @deprecated, use logIn instead.
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
499
- * @param {String} newAppUserID The appUserID that should be linked to the currently user
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.
503
- */
504
- Purchases.identify = function (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
- });
519
- };
520
- /**
521
- * @deprecated, use logOut instead.
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.
527
- */
528
- Purchases.reset = function () {
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
- });
539
- };
540
446
  /**
541
447
  * Enables/Disables debugs logs
542
448
  * @param {boolean} enabled Enable or not debug logs
@@ -550,19 +456,19 @@ var Purchases = /** @class */ (function () {
550
456
  });
551
457
  };
552
458
  /**
553
- * Gets current purchaser info
554
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
459
+ * Gets current customer info
460
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
555
461
  * 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.
462
+ * there's an issue getting the customer information.
557
463
  */
558
- Purchases.getPurchaserInfo = function () {
464
+ Purchases.getCustomerInfo = function () {
559
465
  return __awaiter(this, void 0, void 0, function () {
560
466
  return __generator(this, function (_a) {
561
467
  switch (_a.label) {
562
468
  case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
563
469
  case 1:
564
470
  _a.sent();
565
- return [2 /*return*/, RNPurchases.getPurchaserInfo()];
471
+ return [2 /*return*/, RNPurchases.getCustomerInfo()];
566
472
  }
567
473
  });
568
474
  });
@@ -647,15 +553,15 @@ var Purchases = /** @class */ (function () {
647
553
  });
648
554
  };
649
555
  /**
650
- * iOS only. Use this function to retrieve the `PurchasesPaymentDiscount` for a given `PurchasesPackage`.
556
+ * iOS only. Use this function to retrieve the `PurchasesPromotionalOffer` for a given `PurchasesPackage`.
651
557
  *
652
558
  * @param product The `PurchasesProduct` the user intends to purchase.
653
559
  * @param discount The `PurchasesDiscount` to apply to the product.
654
- * @returns { Promise<PurchasesPaymentDiscount> } Returns when the `PurchasesPaymentDiscount` is returned.
560
+ * @returns { Promise<PurchasesPromotionalOffer> } Returns when the `PurchasesPaymentDiscount` is returned.
655
561
  * Null is returned for Android and incompatible iOS versions. The promise will be rejected if setup has not been
656
562
  * called yet or if there's an error getting the payment discount.
657
563
  */
658
- Purchases.getPaymentDiscount = function (product, discount) {
564
+ Purchases.getPromotionalOffer = function (product, discount) {
659
565
  return __awaiter(this, void 0, void 0, function () {
660
566
  return __generator(this, function (_a) {
661
567
  switch (_a.label) {
@@ -668,31 +574,31 @@ var Purchases = /** @class */ (function () {
668
574
  if (typeof discount === "undefined" || discount == null) {
669
575
  throw new Error("A discount is required");
670
576
  }
671
- return [2 /*return*/, RNPurchases.getPaymentDiscount(product.identifier, discount.identifier)];
577
+ return [2 /*return*/, RNPurchases.getPromotionalOffer(product.identifier, discount.identifier)];
672
578
  }
673
579
  });
674
580
  });
675
581
  };
676
582
  /**
677
- * Invalidates the cache for purchaser information.
583
+ * Invalidates the cache for customer information.
678
584
  *
679
585
  * Most apps will not need to use this method; invalidating the cache can leave your app in an invalid state.
680
- * Refer to https://docs.revenuecat.com/docs/purchaserinfo#section-get-user-information for more information on
586
+ * Refer to https://docs.revenuecat.com/docs/customer-info#section-get-user-information for more information on
681
587
  * using the cache properly.
682
588
  *
683
- * This is useful for cases where purchaser information might have been updated outside of the app, like if a
589
+ * This is useful for cases where customer information might have been updated outside of the app, like if a
684
590
  * promotional subscription is granted through the RevenueCat dashboard.
685
591
  * @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.
592
+ * invalidating the customer info cache.
687
593
  */
688
- Purchases.invalidatePurchaserInfoCache = function () {
594
+ Purchases.invalidateCustomerInfoCache = function () {
689
595
  return __awaiter(this, void 0, void 0, function () {
690
596
  return __generator(this, function (_a) {
691
597
  switch (_a.label) {
692
598
  case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
693
599
  case 1:
694
600
  _a.sent();
695
- RNPurchases.invalidatePurchaserInfoCache();
601
+ RNPurchases.invalidateCustomerInfoCache();
696
602
  return [2 /*return*/];
697
603
  }
698
604
  });
@@ -1116,9 +1022,9 @@ var Purchases = /** @class */ (function () {
1116
1022
  * Note: Billing features are only relevant to Google Play Android users.
1117
1023
  * For other stores and platforms, billing features won't be checked.
1118
1024
  *
1119
- * @param feature An array of feature types to check for support. Feature types must be one of
1025
+ * @param features An array of feature types to check for support. Feature types must be one of
1120
1026
  * [BILLING_FEATURE]. By default, is an empty list and no specific feature support will be checked.
1121
- * @returns {Promise<Boolean>} promise with boolean response. True if billing is supported, false otherwise.
1027
+ * @returns {Promise<boolean>} promise with boolean response. True if billing is supported, false otherwise.
1122
1028
  */
1123
1029
  Purchases.canMakePayments = function (features) {
1124
1030
  if (features === void 0) { features = []; }
@@ -1148,20 +1054,6 @@ var Purchases = /** @class */ (function () {
1148
1054
  });
1149
1055
  });
1150
1056
  };
1151
- /**
1152
- * Enum for attribution networks
1153
- * @readonly
1154
- * @enum {number}
1155
- */
1156
- Purchases.ATTRIBUTION_NETWORK = ATTRIBUTION_NETWORK;
1157
- /**
1158
- * @deprecated use ATTRIBUTION_NETWORK instead
1159
- *
1160
- * Enum for attribution networks
1161
- * @readonly
1162
- * @enum {number}
1163
- */
1164
- Purchases.ATTRIBUTION_NETWORKS = ATTRIBUTION_NETWORK;
1165
1057
  /**
1166
1058
  * Supported SKU types.
1167
1059
  * @readonly
@@ -1200,6 +1092,9 @@ var Purchases = /** @class */ (function () {
1200
1092
  * @enum {string}
1201
1093
  */
1202
1094
  Purchases.PURCHASES_ERROR_CODE = errors_1.PURCHASES_ERROR_CODE;
1095
+ /**
1096
+ * @internal
1097
+ */
1203
1098
  Purchases.UninitializedPurchasesError = errors_1.UninitializedPurchasesError;
1204
1099
  return Purchases;
1205
1100
  }());
package/ios/RNPurchases.h CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  #import <React/RCTEventEmitter.h>
7
7
 
8
- #import <Purchases/RCPurchases.h>
9
- #import <PurchasesHybridCommon/PurchasesHybridCommon.h>
8
+ @import PurchasesHybridCommon;
9
+ @import RevenueCat;
10
10
 
11
11
  @interface RNPurchases : RCTEventEmitter <RCTBridgeModule>
12
12
 
package/ios/RNPurchases.m CHANGED
@@ -8,15 +8,17 @@
8
8
 
9
9
  @import StoreKit;
10
10
 
11
+ typedef void (^PurchaseCompletedBlock)(RCStoreTransaction *, RCCustomerInfo *, NSError *, BOOL);
12
+ typedef void (^StartPurchaseBlock)(PurchaseCompletedBlock);
11
13
 
12
14
  @interface RNPurchases () <RCPurchasesDelegate>
13
15
 
14
- @property (nonatomic, retain) NSMutableArray<RCDeferredPromotionalPurchaseBlock> *defermentBlocks;
16
+ @property (nonatomic, retain) NSMutableArray<StartPurchaseBlock> *defermentBlocks;
15
17
 
16
18
  @end
17
19
 
18
20
 
19
- NSString *RNPurchasesPurchaserInfoUpdatedEvent = @"Purchases-PurchaserInfoUpdated";
21
+ NSString *RNPurchasesCustomerInfoUpdatedEvent = @"Purchases-CustomerInfoUpdated";
20
22
  NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchasePromoProduct";
21
23
 
22
24
 
@@ -27,7 +29,7 @@ NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchas
27
29
  }
28
30
 
29
31
  - (NSArray<NSString *> *)supportedEvents {
30
- return @[RNPurchasesPurchaserInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
32
+ return @[RNPurchasesCustomerInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
31
33
  }
32
34
 
33
35
  RCT_EXPORT_MODULE();
@@ -35,16 +37,17 @@ RCT_EXPORT_MODULE();
35
37
  RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
36
38
  appUserID:(nullable NSString *)appUserID
37
39
  observerMode:(BOOL)observerMode
38
- userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName) {
39
- [RCPurchases configureWithAPIKey:apiKey
40
- appUserID:appUserID
41
- observerMode:observerMode
42
- userDefaultsSuiteName:userDefaultsSuiteName
43
- platformFlavor:self.platformFlavor
44
- platformFlavorVersion:self.platformFlavorVersion
45
- dangerousSettings:nil];
46
- RCPurchases.sharedPurchases.delegate = self;
47
- [RCCommonFunctionality configure];
40
+ userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
41
+ usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable) {
42
+ RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
43
+ appUserID:appUserID
44
+ observerMode:observerMode
45
+ userDefaultsSuiteName:userDefaultsSuiteName
46
+ platformFlavor:self.platformFlavor
47
+ platformFlavorVersion:self.platformFlavorVersion
48
+ usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
49
+ dangerousSettings:nil];
50
+ purchases.delegate = self;
48
51
  }
49
52
 
50
53
  RCT_EXPORT_METHOD(setAllowSharingStoreAccount:(BOOL)allowSharingStoreAccount) {
@@ -58,15 +61,6 @@ RCT_EXPORT_METHOD(setFinishTransactions:(BOOL)finishTransactions) {
58
61
  [RCCommonFunctionality setFinishTransactions:finishTransactions];
59
62
  }
60
63
 
61
- RCT_EXPORT_METHOD(addAttributionData:(NSDictionary *)data
62
- forNetwork:(NSInteger)network
63
- forNetworkUserId:(nullable NSString *)networkUserId) {
64
- #pragma GCC diagnostic push
65
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
66
- [RCCommonFunctionality addAttributionData:data network:network networkUserId:networkUserId];
67
- #pragma GCC diagnostic pop
68
- }
69
-
70
64
  RCT_REMAP_METHOD(getOfferings,
71
65
  getOfferingsWithResolve:(RCTPromiseResolveBlock)resolve
72
66
  reject:(RCTPromiseRejectBlock)reject) {
@@ -109,11 +103,11 @@ RCT_REMAP_METHOD(purchasePackage,
109
103
  completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
110
104
  }
111
105
 
112
- RCT_REMAP_METHOD(restoreTransactions,
113
- restoreTransactionsWithResolve:(RCTPromiseResolveBlock)resolve
106
+ RCT_REMAP_METHOD(restorePurchases,
107
+ restorePurchasesWithResolve:(RCTPromiseResolveBlock)resolve
114
108
  reject:(RCTPromiseRejectBlock)reject) {
115
- [RCCommonFunctionality restoreTransactionsWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
116
- reject:reject]];
109
+ [RCCommonFunctionality restorePurchasesWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
110
+ reject:reject]];
117
111
  }
118
112
 
119
113
  RCT_EXPORT_METHOD(syncPurchases) {
@@ -126,13 +120,6 @@ RCT_REMAP_METHOD(getAppUserID,
126
120
  resolve([RCCommonFunctionality appUserID]);
127
121
  }
128
122
 
129
- RCT_EXPORT_METHOD(createAlias:(nullable NSString *)newAppUserID
130
- resolve:(RCTPromiseResolveBlock)resolve
131
- reject:(RCTPromiseRejectBlock)reject) {
132
- [RCCommonFunctionality createAlias:newAppUserID
133
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
134
- }
135
-
136
123
  RCT_EXPORT_METHOD(logIn:(nonnull NSString *)appUserID
137
124
  resolve:(RCTPromiseResolveBlock)resolve
138
125
  reject:(RCTPromiseRejectBlock)reject) {
@@ -146,25 +133,6 @@ RCT_REMAP_METHOD(logOut,
146
133
  [RCCommonFunctionality logOutWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
147
134
  }
148
135
 
149
- RCT_EXPORT_METHOD(identify:(nullable NSString *)appUserID
150
- resolve:(RCTPromiseResolveBlock)resolve
151
- reject:(RCTPromiseRejectBlock)reject) {
152
- #pragma GCC diagnostic push
153
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
154
- [RCCommonFunctionality identify:appUserID
155
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
156
- #pragma GCC diagnostic pop
157
- }
158
-
159
- RCT_REMAP_METHOD(reset,
160
- resetWithResolve:(RCTPromiseResolveBlock)resolve
161
- reject:(RCTPromiseRejectBlock)reject) {
162
- #pragma GCC diagnostic push
163
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
164
- [RCCommonFunctionality resetWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
165
- #pragma GCC diagnostic pop
166
- }
167
-
168
136
  RCT_REMAP_METHOD(setDebugLogsEnabled,
169
137
  debugLogsEnabled:(BOOL)enabled) {
170
138
  [RCCommonFunctionality setDebugLogsEnabled:enabled];
@@ -175,10 +143,10 @@ RCT_EXPORT_METHOD(setSimulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox
175
143
  [RCCommonFunctionality setSimulatesAskToBuyInSandbox:simulatesAskToBuyInSandbox];
176
144
  }
177
145
 
178
- RCT_REMAP_METHOD(getPurchaserInfo,
179
- purchaserInfoWithResolve:(RCTPromiseResolveBlock)resolve
146
+ RCT_REMAP_METHOD(getCustomerInfo,
147
+ customerInfoWithResolve:(RCTPromiseResolveBlock)resolve
180
148
  reject:(RCTPromiseRejectBlock)reject) {
181
- [RCCommonFunctionality getPurchaserInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
149
+ [RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
182
150
  }
183
151
 
184
152
  RCT_EXPORT_METHOD(setAutomaticAppleSearchAdsAttributionCollection:(BOOL)automaticAppleSearchAdsAttributionCollection)
@@ -195,7 +163,7 @@ RCT_REMAP_METHOD(isAnonymous,
195
163
  RCT_EXPORT_METHOD(makeDeferredPurchase:(nonnull NSNumber *)callbackID
196
164
  resolve:(RCTPromiseResolveBlock)resolve
197
165
  reject:(RCTPromiseRejectBlock)reject) {
198
- RCDeferredPromotionalPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
166
+ StartPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
199
167
  [RCCommonFunctionality makeDeferredPurchase:defermentBlock
200
168
  completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
201
169
  }
@@ -209,19 +177,18 @@ RCT_EXPORT_METHOD(checkTrialOrIntroductoryPriceEligibility:(NSArray *)products
209
177
  }];
210
178
  }
211
179
 
212
- RCT_REMAP_METHOD(getPaymentDiscount,
213
- getPaymentDiscountForProductIdentifier:(NSString *)productIdentifier
214
- discountIdentifier:(nullable NSString *)discountIdentifier
215
- resolve:(RCTPromiseResolveBlock)resolve
216
- reject:(RCTPromiseRejectBlock)reject) {
217
- [RCCommonFunctionality paymentDiscountForProductIdentifier:productIdentifier
218
- discount:discountIdentifier
219
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve
220
- reject:reject]];
180
+ RCT_EXPORT_METHOD(invalidateCustomerInfoCache) {
181
+ [RCCommonFunctionality invalidateCustomerInfoCache];
221
182
  }
222
183
 
223
- RCT_EXPORT_METHOD(invalidatePurchaserInfoCache) {
224
- [RCCommonFunctionality invalidatePurchaserInfoCache];
184
+ RCT_REMAP_METHOD(getPromotionalOffer,
185
+ getPromotionalOfferForProductIdentifier:(NSString *)productIdentifier
186
+ discount:(NSString *)discount
187
+ resolve:(RCTPromiseResolveBlock)resolve
188
+ reject:(RCTPromiseRejectBlock)reject) {
189
+ [RCCommonFunctionality promotionalOfferForProductIdentifier:productIdentifier
190
+ discount:discount
191
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
225
192
  }
226
193
 
227
194
  RCT_EXPORT_METHOD(presentCodeRedemptionSheet) {
@@ -329,17 +296,17 @@ RCT_REMAP_METHOD(isConfigured,
329
296
 
330
297
  #pragma mark -
331
298
  #pragma mark Delegate Methods
332
- - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo {
333
- [self sendEventWithName:RNPurchasesPurchaserInfoUpdatedEvent body:purchaserInfo.dictionary];
299
+ - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
300
+ [self sendEventWithName:RNPurchasesCustomerInfoUpdatedEvent body:customerInfo.dictionary];
334
301
  }
335
302
 
336
- - (void) purchases:(RCPurchases *)purchases
337
- shouldPurchasePromoProduct:(SKProduct *)product
338
- defermentBlock:(RCDeferredPromotionalPurchaseBlock)makeDeferredPurchase {
303
+ - (void)purchases:(RCPurchases *)purchases
304
+ readyForPromotedProduct:(RCStoreProduct *)product
305
+ purchase:(void (^)(void (^ _Nonnull)(RCStoreTransaction * _Nullable, RCCustomerInfo * _Nullable, NSError * _Nullable, BOOL)))startPurchase {
339
306
  if (!self.defermentBlocks) {
340
307
  self.defermentBlocks = [NSMutableArray array];
341
308
  }
342
- [self.defermentBlocks addObject:makeDeferredPurchase];
309
+ [self.defermentBlocks addObject:startPurchase];
343
310
  NSInteger position = [self.defermentBlocks count] - 1;
344
311
  [self sendEventWithName:RNPurchasesShouldPurchasePromoProductEvent body:@{@"callbackID": @(position)}];
345
312
  }
@@ -369,7 +336,7 @@ shouldPurchasePromoProduct:(SKProduct *)product
369
336
  }
370
337
 
371
338
  - (NSString *)platformFlavorVersion {
372
- return @"4.6.0";
339
+ return @"5.0.0-beta.2";
373
340
  }
374
341
 
375
342
  @end