@revenuecat/purchases-js 0.0.13 → 0.0.15

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.
@@ -198,31 +198,31 @@ export declare interface Offering {
198
198
  /**
199
199
  * Lifetime package type configured in the RevenueCat dashboard, if available.
200
200
  */
201
- readonly lifetimePackage: Package | null;
201
+ readonly lifetime: Package | null;
202
202
  /**
203
203
  * Annual package type configured in the RevenueCat dashboard, if available.
204
204
  */
205
- readonly annualPackage: Package | null;
205
+ readonly annual: Package | null;
206
206
  /**
207
207
  * Six month package type configured in the RevenueCat dashboard, if available.
208
208
  */
209
- readonly sixMonthPackage: Package | null;
209
+ readonly sixMonth: Package | null;
210
210
  /**
211
211
  * Three month package type configured in the RevenueCat dashboard, if available.
212
212
  */
213
- readonly threeMonthPackage: Package | null;
213
+ readonly threeMonth: Package | null;
214
214
  /**
215
215
  * Two month package type configured in the RevenueCat dashboard, if available.
216
216
  */
217
- readonly twoMonthPackage: Package | null;
217
+ readonly twoMonth: Package | null;
218
218
  /**
219
219
  * Monthly package type configured in the RevenueCat dashboard, if available.
220
220
  */
221
- readonly monthlyPackage: Package | null;
221
+ readonly monthly: Package | null;
222
222
  /**
223
223
  * Weekly package type configured in the RevenueCat dashboard, if available.
224
224
  */
225
- readonly weeklyPackage: Package | null;
225
+ readonly weekly: Package | null;
226
226
  }
227
227
 
228
228
  /**
@@ -368,92 +368,122 @@ export declare interface Product {
368
368
  */
369
369
  export declare class Purchases {
370
370
  /**
371
- * Constructor for Purchases.
372
- * @param apiKey - RevenueCat API Key. Can be obtained from the RevenueCat dashboard.
373
- */
374
- constructor(apiKey: string);
375
- /**
376
- * Fetch the configured offerings for this user. You can configure these
377
- * in the RevenueCat dashboard.
378
- * @param appUserId - Your app's user id in your system.
379
- */
380
- getOfferings(appUserId: string): Promise<Offerings>;
381
- /**
382
- * Convenience method to check whether a user is entitled to a specific
383
- * entitlement. This will use {@link Purchases.getCustomerInfo} under the hood.
384
- * @param appUserId - Your app's user id in your system.
385
- * @param entitlementIdentifier - The entitlement identifier you want to check.
386
- * @returns Whether the user is entitled to the specified entitlement
387
- * @throws {@link PurchasesError} if there is an error while fetching the customer info.
388
- * @see {@link Purchases.getCustomerInfo}
371
+ * Get the singleton instance of Purchases. It's preferred to use the instance
372
+ * obtained from the {@link Purchases.initializePurchases} method when possible.
373
+ * @throws {@link UninitializedPurchasesError} if the instance has not been initialized yet.
389
374
  */
390
- isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
375
+ static getInstance(): Purchases;
376
+ /**
377
+ * Returns whether the Purchases SDK is configured or not.
378
+ */
379
+ static isConfigured(): boolean;
380
+ /**
381
+ * Initializes the Purchases SDK. This should be called as soon as your app
382
+ * has a unique user id for your user. You should only call this once, and
383
+ * keep the returned instance around for use throughout your application.
384
+ * @param apiKey - RevenueCat API Key. Can be obtained from the RevenueCat dashboard.
385
+ * @param appUserId - Your unique id for identifying the user.
386
+ */
387
+ static initializePurchases(apiKey: string, appUserId: string): Purchases;
391
388
  /**
392
- * Method to perform a purchase for a given package. You can obtain the
393
- * package from {@link Purchases.getOfferings}. This method will present the purchase
394
- * form on your site, using the given HTML element as the mount point, if
395
- * provided, or as a modal if not.
396
- * @param appUserId - Your app's user id in your system.
397
- * @param rcPackage - The package you want to purchase. Obtained from {@link Purchases.getOfferings}.
398
- * @param customerEmail - The email of the user. If null, RevenueCat will ask the customer for their email.
399
- * @param htmlTarget - The HTML element where the billing view should be added. If null, a new div will be created at the root of the page and appended to the body.
400
- * @returns The customer info after the purchase is completed successfuly.
401
- * @throws {@link PurchasesError} if there is an error while performing the purchase. If the {@link PurchasesError.errorCode} is {@link ErrorCode.UserCancelledError}, the user cancelled the purchase.
389
+ * Fetch the configured offerings for this user. You can configure these
390
+ * in the RevenueCat dashboard.
391
+ */
392
+ getOfferings(): Promise<Offerings>;
393
+ /**
394
+ * Convenience method to check whether a user is entitled to a specific
395
+ * entitlement. This will use {@link Purchases.getCustomerInfo} under the hood.
396
+ * @param entitlementIdentifier - The entitlement identifier you want to check.
397
+ * @returns Whether the user is entitled to the specified entitlement
398
+ * @throws {@link PurchasesError} if there is an error while fetching the customer info.
399
+ * @see {@link Purchases.getCustomerInfo}
402
400
  */
403
- purchasePackage(appUserId: string, rcPackage: Package, customerEmail?: string, htmlTarget?: HTMLElement): Promise<{
404
- customerInfo: CustomerInfo;
405
- }>;
401
+ isEntitledTo(entitlementIdentifier: string): Promise<boolean>;
406
402
  /**
407
- * Gets latest available {@link CustomerInfo}.
408
- * @param appUserId - Your app's user id in your system.
409
- * @returns The latest {@link CustomerInfo}.
410
- * @throws {@link PurchasesError} if there is an error while fetching the customer info.
403
+ * Method to perform a purchase for a given package. You can obtain the
404
+ * package from {@link Purchases.getOfferings}. This method will present the purchase
405
+ * form on your site, using the given HTML element as the mount point, if
406
+ * provided, or as a modal if not.
407
+ * @param rcPackage - The package you want to purchase. Obtained from {@link Purchases.getOfferings}.
408
+ * @param customerEmail - The email of the user. If null, RevenueCat will ask the customer for their email.
409
+ * @param htmlTarget - The HTML element where the billing view should be added. If null, a new div will be created at the root of the page and appended to the body.
410
+ * @returns The customer info after the purchase is completed successfuly.
411
+ * @throws {@link PurchasesError} if there is an error while performing the purchase. If the {@link PurchasesError.errorCode} is {@link ErrorCode.UserCancelledError}, the user cancelled the purchase.
411
412
  */
412
- getCustomerInfo(appUserId: string): Promise<CustomerInfo>;
413
+ purchasePackage(rcPackage: Package, customerEmail?: string, htmlTarget?: HTMLElement): Promise<{
414
+ customerInfo: CustomerInfo;
415
+ }>;
416
+ /**
417
+ * Gets latest available {@link CustomerInfo}.
418
+ * @returns The latest {@link CustomerInfo}.
419
+ * @throws {@link PurchasesError} if there is an error while fetching the customer info.
420
+ */
421
+ getCustomerInfo(): Promise<CustomerInfo>;
422
+ /**
423
+ * Gets the current app user id.
424
+ */
425
+ getAppUserId(): string;
426
+ /**
427
+ * Change the current app user id. Returns the customer info for the new
428
+ * user id.
429
+ * @param newAppUserId - The user id to change to.
430
+ */
431
+ changeUser(newAppUserId: string): Promise<CustomerInfo>;
432
+ /**
433
+ * @returns Whether the SDK is using a sandbox API Key.
434
+ */
435
+ isSandbox(): boolean;
436
+ /**
437
+ * Closes the Purchases instance. You should never have to do this normally.
438
+ */
439
+ close(): void;
440
+ }
441
+
413
442
  /**
414
- * @returns Whether the SDK is using a sandbox API Key.
443
+ * Error class for Purchases SDK. You should handle these errors and react
444
+ * accordingly in your app.
445
+ * @public
415
446
  */
416
- isSandbox(): boolean;
417
- }
447
+ export declare class PurchasesError extends Error {
448
+ /**
449
+ * Error code for the error. This is useful to appropriately react to
450
+ * different error situations.
451
+ */
452
+ readonly errorCode: ErrorCode;
453
+ /**
454
+ * Underlying error message. This provides more details on the error and
455
+ * can be useful for debugging and logging.
456
+ */
457
+ readonly underlyingErrorMessage?: string | null | undefined;
458
+ constructor(
459
+ /**
460
+ * Error code for the error. This is useful to appropriately react to
461
+ * different error situations.
462
+ */
463
+ errorCode: ErrorCode,
464
+ /**
465
+ * Message for the error. This is useful for debugging and logging.
466
+ */
467
+ message?: string,
468
+ /**
469
+ * Underlying error message. This provides more details on the error and
470
+ * can be useful for debugging and logging.
471
+ */
472
+ underlyingErrorMessage?: string | null | undefined);
473
+ toString: () => string;
474
+ }
418
475
 
419
- /**
420
- * Error class for Purchases SDK. You should handle these errors and react
421
- * accordingly in your app.
422
- * @public
423
- */
424
- export declare class PurchasesError extends Error {
425
- /**
426
- * Error code for the error. This is useful to appropriately react to
427
- * different error situations.
428
- */
429
- readonly errorCode: ErrorCode;
430
- /**
431
- * Underlying error message. This provides more details on the error and
432
- * can be useful for debugging and logging.
433
- */
434
- readonly underlyingErrorMessage?: string | null | undefined;
435
- constructor(
436
- /**
437
- * Error code for the error. This is useful to appropriately react to
438
- * different error situations.
439
- */
440
- errorCode: ErrorCode,
441
- /**
442
- * Message for the error. This is useful for debugging and logging.
443
- */
444
- message?: string,
445
- /**
446
- * Underlying error message. This provides more details on the error and
447
- * can be useful for debugging and logging.
448
- */
449
- underlyingErrorMessage?: string | null | undefined);
450
- toString: () => string;
451
- }
476
+ /**
477
+ * The store where the user originally subscribed.
478
+ * @public
479
+ */
480
+ export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
452
481
 
453
- /**
454
- * The store where the user originally subscribed.
455
- * @public
456
- */
457
- export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
482
+ /**
483
+ * Error indicating that the SDK was accessed before it was initialized.
484
+ */
485
+ export declare class UninitializedPurchasesError extends Error {
486
+ constructor();
487
+ }
458
488
 
459
- export { }
489
+ export { }