react-native-purchases 4.6.1 → 5.0.0-beta.3

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.
@@ -1,25 +1,17 @@
1
1
  import { PURCHASES_ERROR_CODE, UninitializedPurchasesError } from "./errors";
2
- import { PurchaserInfo } from "./purchaserInfo";
3
- import { PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesProduct, UpgradeInfo, PurchasesPaymentDiscount, PurchasesPackage, IntroEligibility, PurchasesDiscount } from "./offerings";
2
+ import { CustomerInfo } from "./customerInfo";
3
+ import { PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount } from "./offerings";
4
4
  /**
5
- * Listener used on updated purchaser info
6
- * @callback PurchaserInfoUpdateListener
7
- * @param {Object} purchaserInfo Object containing info for the purchaser
5
+ * Listener used on updated customer info
6
+ * @callback CustomerInfoUpdateListener
7
+ * @param {Object} customerInfo Object containing info for the customer
8
8
  */
9
- export declare type PurchaserInfoUpdateListener = (purchaserInfo: PurchaserInfo) => void;
9
+ export declare type CustomerInfoUpdateListener = (customerInfo: CustomerInfo) => void;
10
10
  export declare type ShouldPurchasePromoProductListener = (deferredPurchase: () => Promise<MakePurchaseResult>) => void;
11
11
  export declare type MakePurchaseResult = {
12
12
  productIdentifier: string;
13
- purchaserInfo: PurchaserInfo;
13
+ customerInfo: CustomerInfo;
14
14
  };
15
- export declare enum ATTRIBUTION_NETWORK {
16
- APPLE_SEARCH_ADS = 0,
17
- ADJUST = 1,
18
- APPSFLYER = 2,
19
- BRANCH = 3,
20
- TENJIN = 4,
21
- FACEBOOK = 5
22
- }
23
15
  export declare enum PURCHASE_TYPE {
24
16
  /**
25
17
  * A type of SKU for in-app products.
@@ -62,29 +54,26 @@ export declare enum BILLING_FEATURE {
62
54
  */
63
55
  export interface LogInResult {
64
56
  /**
65
- * The Purchaser Info for the user.
57
+ * The Customer Info for the user.
66
58
  */
67
- readonly purchaserInfo: PurchaserInfo;
59
+ readonly customerInfo: CustomerInfo;
68
60
  /**
69
61
  * True if the call resulted in a new user getting created in the RevenueCat backend.
70
62
  */
71
63
  readonly created: boolean;
72
64
  }
65
+ /**
66
+ * Holds parameters to initialize the SDK.
67
+ */
68
+ export interface PurchasesConfiguration {
69
+ apiKey: string;
70
+ appUserID?: string | null;
71
+ observerMode?: boolean;
72
+ userDefaultsSuiteName?: string;
73
+ usesStoreKit2IfAvailable?: boolean;
74
+ useAmazon?: boolean;
75
+ }
73
76
  export default class Purchases {
74
- /**
75
- * Enum for attribution networks
76
- * @readonly
77
- * @enum {number}
78
- */
79
- static ATTRIBUTION_NETWORK: typeof ATTRIBUTION_NETWORK;
80
- /**
81
- * @deprecated use ATTRIBUTION_NETWORK instead
82
- *
83
- * Enum for attribution networks
84
- * @readonly
85
- * @enum {number}
86
- */
87
- static ATTRIBUTION_NETWORKS: typeof ATTRIBUTION_NETWORK;
88
77
  /**
89
78
  * Supported SKU types.
90
79
  * @readonly
@@ -123,17 +112,22 @@ export default class Purchases {
123
112
  * @enum {string}
124
113
  */
125
114
  static PURCHASES_ERROR_CODE: typeof PURCHASES_ERROR_CODE;
115
+ /**
116
+ * @internal
117
+ */
126
118
  static UninitializedPurchasesError: typeof UninitializedPurchasesError;
127
119
  /**
128
120
  * Sets up Purchases with your API key and an app user id.
129
121
  * @param {String} apiKey RevenueCat API Key. Needs to be a String
130
122
  * @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
131
- * @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.
123
+ * @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.
124
+ * @param {boolean} [usesStoreKit2IfAvailable=false] An optional boolean. iOS-only. Set this to TRUE to enable StoreKit2 on compatible devices.
125
+ * @param {boolean} [useAmazon=false] An optional boolean. Android-only. Set this to TRUE to enable Amazon on compatible devices.
132
126
  * @param {String?} userDefaultsSuiteName An optional string. iOS-only, will be ignored for Android.
133
127
  * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
134
128
  * Default is null, which will make the SDK use standardUserDefaults.
135
129
  */
136
- static setup(apiKey: string, appUserID?: string | null, observerMode?: boolean, userDefaultsSuiteName?: string): void;
130
+ static configure({ apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon }: PurchasesConfiguration): void;
137
131
  /**
138
132
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
139
133
  * If an user tries to purchase a product that is active on the current app store account,
@@ -157,16 +151,16 @@ export default class Purchases {
157
151
  */
158
152
  static setSimulatesAskToBuyInSandbox(simulatesAskToBuyInSandbox: boolean): Promise<void>;
159
153
  /**
160
- * Sets a function to be called on updated purchaser info
161
- * @param {PurchaserInfoUpdateListener} purchaserInfoUpdateListener PurchaserInfo update listener
154
+ * Sets a function to be called on updated customer info
155
+ * @param {CustomerInfoUpdateListener} customerInfoUpdateListener CustomerInfo update listener
162
156
  */
163
- static addPurchaserInfoUpdateListener(purchaserInfoUpdateListener: PurchaserInfoUpdateListener): void;
157
+ static addCustomerInfoUpdateListener(customerInfoUpdateListener: CustomerInfoUpdateListener): void;
164
158
  /**
165
- * Removes a given PurchaserInfoUpdateListener
166
- * @param {PurchaserInfoUpdateListener} listenerToRemove PurchaserInfoUpdateListener reference of the listener to remove
159
+ * Removes a given CustomerInfoUpdateListener
160
+ * @param {CustomerInfoUpdateListener} listenerToRemove CustomerInfoUpdateListener reference of the listener to remove
167
161
  * @returns {boolean} True if listener was removed, false otherwise
168
162
  */
169
- static removePurchaserInfoUpdateListener(listenerToRemove: PurchaserInfoUpdateListener): boolean;
163
+ static removeCustomerInfoUpdateListener(listenerToRemove: CustomerInfoUpdateListener): boolean;
170
164
  /**
171
165
  * Sets a function to be called on purchases initiated on the Apple App Store. This is only used in iOS.
172
166
  * @param {ShouldPurchasePromoProductListener} shouldPurchasePromoProductListener Called when a user initiates a
@@ -184,18 +178,6 @@ export default class Purchases {
184
178
  * @returns {boolean} True if listener was removed, false otherwise
185
179
  */
186
180
  static removeShouldPurchasePromoProductListener(listenerToRemove: ShouldPurchasePromoProductListener): boolean;
187
- /**
188
- * @deprecated, use set<NetworkId> methods instead.
189
- *
190
- * Add a dict of attribution information
191
- * @param {Dict} data Attribution data from AppsFlyer, Adjust, or Branch
192
- * @param {ATTRIBUTION_NETWORKS} network Which network, see Purchases.ATTRIBUTION_NETWORKS
193
- * @param {String?} networkUserId An optional unique id for identifying the user. Needs to be a string.
194
- * @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
195
- */
196
- static addAttributionData(data: {
197
- [key: string]: any;
198
- }, network: ATTRIBUTION_NETWORK, networkUserId?: string): Promise<void>;
199
181
  /**
200
182
  * Gets the map of entitlements -> offerings -> products
201
183
  * @returns {Promise<PurchasesOfferings>} Promise of entitlements structure. The promise will be rejected if setup
@@ -206,12 +188,12 @@ export default class Purchases {
206
188
  * Fetch the product info
207
189
  * @param {String[]} productIdentifiers Array of product identifiers
208
190
  * @param {String} type Optional type of products to fetch, can be inapp or subs. Subs by default
209
- * @returns {Promise<PurchasesProduct[]>} A promise containing an array of products. The promise will be rejected
191
+ * @returns {Promise<PurchasesStoreProduct[]>} A promise containing an array of products. The promise will be rejected
210
192
  * if the products are not properly configured in RevenueCat or if there is another error retrieving them.
211
193
  * Rejections return an error code, and a userInfo object with more information. The promise will also be rejected
212
194
  * if setup has not been called yet.
213
195
  */
214
- static getProducts(productIdentifiers: string[], type?: PURCHASE_TYPE): Promise<PurchasesProduct[]>;
196
+ static getProducts(productIdentifiers: string[], type?: PURCHASE_TYPE): Promise<PurchasesStoreProduct[]>;
215
197
  /**
216
198
  * Make a purchase
217
199
  *
@@ -219,8 +201,8 @@ export default class Purchases {
219
201
  * @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
220
202
  * and the optional prorationMode.
221
203
  * @param {String} type Optional type of product, can be inapp or subs. Subs by default
222
- * @returns {Promise<{ productIdentifier: string, purchaserInfo:PurchaserInfo }>} A promise of an object containing
223
- * a purchaser info object and a product identifier. Rejections return an error code,
204
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
205
+ * a customer info object and a product identifier. Rejections return an error code,
224
206
  * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will
225
207
  * also be rejected if setup has not been called yet.
226
208
  */
@@ -228,22 +210,22 @@ export default class Purchases {
228
210
  /**
229
211
  * iOS only. Purchase a product applying a given discount.
230
212
  *
231
- * @param {PurchasesProduct} product The product you want to purchase
232
- * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
233
- * @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,
213
+ * @param {PurchasesStoreProduct} product The product you want to purchase
214
+ * @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
215
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
216
+ * a customer info object and a product identifier. Rejections return an error code,
235
217
  * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
236
218
  * rejected if setup has not been called yet.
237
219
  */
238
- static purchaseDiscountedProduct(product: PurchasesProduct, discount: PurchasesPaymentDiscount): Promise<MakePurchaseResult>;
220
+ static purchaseDiscountedProduct(product: PurchasesStoreProduct, discount: PurchasesPromotionalOffer): Promise<MakePurchaseResult>;
239
221
  /**
240
222
  * Make a purchase
241
223
  *
242
224
  * @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
243
225
  * @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
244
226
  * and the optional prorationMode.
245
- * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
246
- * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
227
+ * @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
228
+ * a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
247
229
  * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
248
230
  * has not been called yet.
249
231
  */
@@ -252,19 +234,19 @@ export default class Purchases {
252
234
  * iOS only. Purchase a package applying a given discount.
253
235
  *
254
236
  * @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
255
- * @param {PurchasesPaymentDiscount} discount Discount to apply to this package. Retrieve this discount using getPaymentDiscount.
256
- * @returns {Promise<{ productIdentifier: string, purchaserInfo: PurchaserInfo }>} A promise of an object containing
257
- * a purchaser info object and a product identifier. Rejections return an error code, a boolean indicating if the
237
+ * @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
238
+ * @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
239
+ * a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
258
240
  * user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
259
241
  * has not been called yet.
260
242
  */
261
- static purchaseDiscountedPackage(aPackage: PurchasesPackage, discount: PurchasesPaymentDiscount): Promise<MakePurchaseResult>;
243
+ static purchaseDiscountedPackage(aPackage: PurchasesPackage, discount: PurchasesPromotionalOffer): Promise<MakePurchaseResult>;
262
244
  /**
263
245
  * Restores a user's previous purchases and links their appUserIDs to any user's also using those purchases.
264
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
246
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
265
247
  * userInfo object with more information. The promise will be also be rejected if setup has not been called yet.
266
248
  */
267
- static restoreTransactions(): Promise<PurchaserInfo>;
249
+ static restorePurchases(): Promise<CustomerInfo>;
268
250
  /**
269
251
  * Get the appUserID
270
252
  * @returns {Promise<string>} The app user id in a promise
@@ -274,59 +256,30 @@ export default class Purchases {
274
256
  * This function will logIn the current user with an appUserID. Typically this would be used after a log in
275
257
  * to identify a user without calling configure.
276
258
  * @param {String} appUserID The appUserID that should be linked to the currently user
277
- * @returns {Promise<LogInResult>} A promise of an object that contains the purchaserInfo after logging in, as well
259
+ * @returns {Promise<LogInResult>} A promise of an object that contains the customerInfo after logging in, as well
278
260
  * as a boolean indicating whether the user has just been created for the first time in the RevenueCat backend. The
279
261
  * promise will be rejected if setup has not been called yet or if there's an issue logging in.
280
262
  */
281
263
  static logIn(appUserID: string): Promise<LogInResult>;
282
264
  /**
283
265
  * Logs out the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.
284
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code,
266
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code,
285
267
  * and a userInfo object with more information. The promise will be rejected if setup has not been called yet or if
286
268
  * there's an issue logging out.
287
269
  */
288
- static logOut(): Promise<PurchaserInfo>;
289
- /**
290
- * @deprecated, use logIn instead.
291
- * This function will alias two appUserIDs together.
292
- * @param {String} newAppUserID The new appUserID that should be linked to the currently identified appUserID.
293
- * Needs to be a string.
294
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a
295
- * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
296
- * there's an issue creating the alias.
297
- */
298
- static createAlias(newAppUserID: string): Promise<PurchaserInfo>;
299
- /**
300
- * @deprecated, use logIn instead.
301
- * This function will identify the current user with an appUserID. Typically this would be used after a logout to
302
- * identify a new user without calling configure
303
- * @param {String} newAppUserID The appUserID that should be linked to the currently user
304
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
305
- * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
306
- * there's an issue identifying the user.
307
- */
308
- static identify(newAppUserID: string): Promise<PurchaserInfo>;
309
- /**
310
- * @deprecated, use logOut instead.
311
- * Resets the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the
312
- * cache.
313
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
314
- * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
315
- * there's an issue resetting the user.
316
- */
317
- static reset(): Promise<PurchaserInfo>;
270
+ static logOut(): Promise<CustomerInfo>;
318
271
  /**
319
272
  * Enables/Disables debugs logs
320
273
  * @param {boolean} enabled Enable or not debug logs
321
274
  */
322
275
  static setDebugLogsEnabled(enabled: boolean): Promise<void>;
323
276
  /**
324
- * Gets current purchaser info
325
- * @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
277
+ * Gets current customer info
278
+ * @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
326
279
  * userInfo object with more information. The promise will be rejected if setup has not been called yet or if
327
- * there's an issue getting the purchaser information.
280
+ * there's an issue getting the customer information.
328
281
  */
329
- static getPurchaserInfo(): Promise<PurchaserInfo>;
282
+ static getCustomerInfo(): Promise<CustomerInfo>;
330
283
  /**
331
284
  * This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation
332
285
  * for subscriptions anytime a sync is needed, like after a successful purchase.
@@ -366,28 +319,28 @@ export default class Purchases {
366
319
  [productId: string]: IntroEligibility;
367
320
  }>;
368
321
  /**
369
- * iOS only. Use this function to retrieve the `PurchasesPaymentDiscount` for a given `PurchasesPackage`.
322
+ * iOS only. Use this function to retrieve the `PurchasesPromotionalOffer` for a given `PurchasesPackage`.
370
323
  *
371
324
  * @param product The `PurchasesProduct` the user intends to purchase.
372
325
  * @param discount The `PurchasesDiscount` to apply to the product.
373
- * @returns { Promise<PurchasesPaymentDiscount> } Returns when the `PurchasesPaymentDiscount` is returned.
326
+ * @returns { Promise<PurchasesPromotionalOffer> } Returns when the `PurchasesPaymentDiscount` is returned.
374
327
  * Null is returned for Android and incompatible iOS versions. The promise will be rejected if setup has not been
375
328
  * called yet or if there's an error getting the payment discount.
376
329
  */
377
- static getPaymentDiscount(product: PurchasesProduct, discount: PurchasesDiscount): Promise<PurchasesPaymentDiscount | undefined>;
330
+ static getPromotionalOffer(product: PurchasesStoreProduct, discount: PurchasesStoreProductDiscount): Promise<PurchasesPromotionalOffer | undefined>;
378
331
  /**
379
- * Invalidates the cache for purchaser information.
332
+ * Invalidates the cache for customer information.
380
333
  *
381
334
  * Most apps will not need to use this method; invalidating the cache can leave your app in an invalid state.
382
- * Refer to https://docs.revenuecat.com/docs/purchaserinfo#section-get-user-information for more information on
335
+ * Refer to https://docs.revenuecat.com/docs/customer-info#section-get-user-information for more information on
383
336
  * using the cache properly.
384
337
  *
385
- * This is useful for cases where purchaser information might have been updated outside of the app, like if a
338
+ * This is useful for cases where customer information might have been updated outside of the app, like if a
386
339
  * promotional subscription is granted through the RevenueCat dashboard.
387
340
  * @returns {Promise<void>} The promise will be rejected if setup has not been called yet or there's an error
388
- * invalidating the purchaser info cache.
341
+ * invalidating the customer info cache.
389
342
  */
390
- static invalidatePurchaserInfoCache(): Promise<void>;
343
+ static invalidateCustomerInfoCache(): Promise<void>;
391
344
  /** iOS only. Presents a code redemption sheet, useful for redeeming offer codes
392
345
  * Refer to https://docs.revenuecat.com/docs/ios-subscription-offers#offer-codes for more information on how
393
346
  * to configure and use offer codes
@@ -565,9 +518,9 @@ export default class Purchases {
565
518
  * Note: Billing features are only relevant to Google Play Android users.
566
519
  * For other stores and platforms, billing features won't be checked.
567
520
  *
568
- * @param feature An array of feature types to check for support. Feature types must be one of
521
+ * @param features An array of feature types to check for support. Feature types must be one of
569
522
  * [BILLING_FEATURE]. By default, is an empty list and no specific feature support will be checked.
570
- * @returns {Promise<Boolean>} promise with boolean response. True if billing is supported, false otherwise.
523
+ * @returns {Promise<boolean>} promise with boolean response. True if billing is supported, false otherwise.
571
524
  */
572
525
  static canMakePayments(features?: BILLING_FEATURE[]): Promise<boolean>;
573
526
  /**