@revenuecat/purchases-js 0.0.12 → 0.0.14

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/README.md CHANGED
@@ -151,7 +151,7 @@ You built your paywall, and your user just clicked on the offer they want to sub
151
151
  ```tsx
152
152
  const purchases = new Purchases("your RC_PUBLISHABLE_API_KEY");
153
153
  // You can retrieve the package from the offerings through `getOfferings`:
154
- const rcBillingPackage = offerings.current.packages[0];
154
+ const rcBillingPackage = offerings.current.availablePackages[0];
155
155
  const appUserId =
156
156
  "the unique id of the user that wants to subscribe to your product";
157
157
  const entitlementIdToCheck =
@@ -193,9 +193,38 @@ npm i /path/to/rcbilling-js
193
193
  ## Running tests
194
194
 
195
195
  ```bash
196
- npm test
196
+ npm run test
197
197
  ```
198
198
 
199
+ ## Running linters
200
+
201
+ ```bash
202
+ npm run test:typeCheck
203
+ npm run svelte-check
204
+ npm run prettier
205
+ npm run lint
206
+ ```
207
+
208
+ ## Update API specs
209
+
210
+ ```bash
211
+ npm run extract-api
212
+ ```
213
+
214
+ This will update the files in `api-report` with the latest public API.
215
+ If it has uncommited changes, CI tests will fail. Run this command and commit the changes if
216
+ they are expected.
217
+
218
+ ## Update reference docs
219
+
220
+ ```bash
221
+ npm run generate-docs
222
+ ```
223
+
224
+ This will update the reference docs in the `docs` folder with the latest public API docs.
225
+ If it has uncommited changes, CI tests will fail. Run this command and commit the changes if
226
+ they are expected.
227
+
199
228
  # Publishing a new version
200
229
 
201
230
  - Update the version in `package.json`
@@ -1,68 +1,140 @@
1
- declare enum BackendErrorCode {
2
- BackendInvalidPlatform = 7000,
3
- BackendStoreProblem = 7101,
4
- BackendCannotTransferPurchase = 7102,
5
- BackendInvalidReceiptToken = 7103,
6
- BackendInvalidAppStoreSharedSecret = 7104,
7
- BackendInvalidPaymentModeOrIntroPriceNotProvided = 7105,
8
- BackendProductIdForGoogleReceiptNotProvided = 7106,
9
- BackendInvalidPlayStoreCredentials = 7107,
10
- BackendInternalServerError = 7110,
11
- BackendEmptyAppUserId = 7220,
12
- BackendInvalidAuthToken = 7224,
13
- BackendInvalidAPIKey = 7225,
14
- BackendBadRequest = 7226,
15
- BackendPlayStoreQuotaExceeded = 7229,
16
- BackendPlayStoreInvalidPackageName = 7230,
17
- BackendPlayStoreGenericError = 7231,
18
- BackendUserIneligibleForPromoOffer = 7232,
19
- BackendInvalidAppleSubscriptionKey = 7234,
20
- BackendInvalidSubscriberAttributes = 7263,
21
- BackendInvalidSubscriberAttributesBody = 7264,
22
- BackendProductIDsMalformed = 7662
23
- }
24
-
25
- export declare type CustomerInfo = CustomerInfo_2;
26
-
27
- declare interface CustomerInfo_2 {
1
+ /**
2
+ * Type containing all information regarding the customer.
3
+ * @public
4
+ */
5
+ export declare interface CustomerInfo {
6
+ /**
7
+ * Entitlements attached to this customer info.
8
+ */
28
9
  readonly entitlements: EntitlementInfos;
10
+ /**
11
+ * Map of productIds to expiration dates.
12
+ */
29
13
  readonly allExpirationDatesByProduct: {
30
14
  [productIdentifier: string]: Date | null;
31
15
  };
16
+ /**
17
+ * Map of productIds to purchase dates.
18
+ */
32
19
  readonly allPurchaseDatesByProduct: {
33
20
  [productIdentifier: string]: Date;
34
21
  };
22
+ /**
23
+ * Set of active subscription product identifiers.
24
+ */
35
25
  readonly activeSubscriptions: Set<string>;
26
+ /**
27
+ * URL to manage the active subscription of the user.
28
+ * If this user has an active RC Billing subscription, a link to the management page.
29
+ * If this user has an active iOS subscription, this will point to the App Store.
30
+ * If the user has an active Play Store subscription it will point there.
31
+ * If there are no active subscriptions it will be null.
32
+ */
36
33
  readonly managementURL: string | null;
34
+ /**
35
+ * Date when this info was requested.
36
+ */
37
37
  readonly requestDate: Date;
38
+ /**
39
+ * The date this user was first seen in RevenueCat.
40
+ */
38
41
  readonly firstSeenDate: Date;
42
+ /**
43
+ * The purchase date for the version of the application when the user bought the app.
44
+ * Use this for grandfathering users when migrating to subscriptions. This can be null.
45
+ */
39
46
  readonly originalPurchaseDate: Date | null;
47
+ /**
48
+ * The original App User Id recorded for this user.
49
+ */
40
50
  readonly originalAppUserId: string;
41
51
  }
42
52
 
53
+ /**
54
+ * This object gives you access to all the information about the status
55
+ * of a user's entitlements.
56
+ * @public
57
+ */
43
58
  export declare interface EntitlementInfo {
59
+ /**
60
+ * The entitlement identifier configured in the RevenueCat dashboard.
61
+ */
44
62
  readonly identifier: string;
63
+ /**
64
+ * True if the user has access to the entitlement.
65
+ */
45
66
  readonly isActive: boolean;
67
+ /**
68
+ * True if the underlying subscription is set to renew at the end of the
69
+ * billing period (expirationDate). Will always be True if entitlement is
70
+ * for lifetime access.
71
+ */
46
72
  readonly willRenew: boolean;
73
+ /**
74
+ * The store where this entitlement was unlocked from.
75
+ */
47
76
  readonly store: Store;
77
+ /**
78
+ * The first date this entitlement was purchased.
79
+ */
48
80
  readonly originalPurchaseDate: Date;
81
+ /**
82
+ * The expiration date for the entitlement, can be `null` for lifetime
83
+ * access. If the {@link EntitlementInfo.periodType} is `trial`, this is the trial
84
+ * expiration date.
85
+ */
49
86
  readonly expirationDate: Date | null;
87
+ /**
88
+ * The product identifier that unlocked this entitlement.
89
+ */
50
90
  readonly productIdentifier: string;
91
+ /**
92
+ * The date an unsubscribe was detected. Can be `null`.
93
+ * Note: Entitlement may still be active even if user has unsubscribed.
94
+ * Check the {@link EntitlementInfo.isActive} property.
95
+ */
51
96
  readonly unsubscribeDetectedAt: Date | null;
97
+ /**
98
+ * The date a billing issue was detected. Can be `null` if there is
99
+ * no billing issue or an issue has been resolved. Note: Entitlement may
100
+ * still be active even if there is a billing issue.
101
+ * Check the `isActive` property.
102
+ */
52
103
  readonly billingIssueDetectedAt: Date | null;
104
+ /**
105
+ * False if this entitlement is unlocked via a production purchase.
106
+ */
53
107
  readonly isSandbox: boolean;
108
+ /**
109
+ * The last period type this entitlement was in.
110
+ */
54
111
  readonly periodType: PeriodType;
55
112
  }
56
113
 
114
+ /**
115
+ * Contains all the entitlements associated to the user.
116
+ * @public
117
+ */
57
118
  export declare interface EntitlementInfos {
119
+ /**
120
+ * Map of all {@link EntitlementInfo} objects (active and inactive) keyed by
121
+ * entitlement identifier.
122
+ */
58
123
  readonly all: {
59
124
  [entitlementId: string]: EntitlementInfo;
60
125
  };
126
+ /**
127
+ * Dictionary of active {@link EntitlementInfo} keyed by entitlement identifier.
128
+ */
61
129
  readonly active: {
62
130
  [entitlementId: string]: EntitlementInfo;
63
131
  };
64
132
  }
65
133
 
134
+ /**
135
+ * Error codes for the Purchases SDK.
136
+ * @public
137
+ */
66
138
  export declare enum ErrorCode {
67
139
  UnknownError = 0,
68
140
  UserCancelledError = 1,
@@ -93,115 +165,295 @@ export declare enum ErrorCode {
93
165
  SignatureVerificationError = 36
94
166
  }
95
167
 
96
- export declare type Offering = Offering_2;
97
-
98
- declare interface Offering_2 {
99
- readonly id: string;
168
+ /**
169
+ * An offering is a collection of {@link Package} available for the user to purchase.
170
+ * For more info see https://docs.revenuecat.com/docs/entitlements
171
+ * @public
172
+ */
173
+ export declare interface Offering {
174
+ /**
175
+ * Unique identifier defined in RevenueCat dashboard.
176
+ */
100
177
  readonly identifier: string;
101
- readonly displayName: string;
178
+ /**
179
+ * Offering description defined in RevenueCat dashboard.
180
+ */
181
+ readonly serverDescription: string;
182
+ /**
183
+ * Offering metadata defined in RevenueCat dashboard.
184
+ */
102
185
  readonly metadata: {
103
186
  [key: string]: unknown;
104
187
  } | null;
105
- readonly packages: {
106
- [key: string]: Package_2;
188
+ /**
189
+ * A map of all the packages available for purchase keyed by package ID.
190
+ */
191
+ readonly packagesById: {
192
+ [key: string]: Package;
107
193
  };
108
- readonly lifetimePackage: Package_2 | null;
109
- readonly annualPackage: Package_2 | null;
110
- readonly sixMonthPackage: Package_2 | null;
111
- readonly threeMonthPackage: Package_2 | null;
112
- readonly twoMonthPackage: Package_2 | null;
113
- readonly monthlyPackage: Package_2 | null;
114
- readonly weeklyPackage: Package_2 | null;
194
+ /**
195
+ * A list of all the packages available for purchase.
196
+ */
197
+ readonly availablePackages: Package[];
198
+ /**
199
+ * Lifetime package type configured in the RevenueCat dashboard, if available.
200
+ */
201
+ readonly lifetime: Package | null;
202
+ /**
203
+ * Annual package type configured in the RevenueCat dashboard, if available.
204
+ */
205
+ readonly annual: Package | null;
206
+ /**
207
+ * Six month package type configured in the RevenueCat dashboard, if available.
208
+ */
209
+ readonly sixMonth: Package | null;
210
+ /**
211
+ * Three month package type configured in the RevenueCat dashboard, if available.
212
+ */
213
+ readonly threeMonth: Package | null;
214
+ /**
215
+ * Two month package type configured in the RevenueCat dashboard, if available.
216
+ */
217
+ readonly twoMonth: Package | null;
218
+ /**
219
+ * Monthly package type configured in the RevenueCat dashboard, if available.
220
+ */
221
+ readonly monthly: Package | null;
222
+ /**
223
+ * Weekly package type configured in the RevenueCat dashboard, if available.
224
+ */
225
+ readonly weekly: Package | null;
115
226
  }
116
227
 
117
- export declare type Offerings = Offerings_2;
118
-
119
- declare interface Offerings_2 {
228
+ /**
229
+ * This class contains all the offerings configured in RevenueCat dashboard.
230
+ * For more info see https://docs.revenuecat.com/docs/entitlements
231
+ * @public
232
+ */
233
+ export declare interface Offerings {
234
+ /**
235
+ * Dictionary of all {@link Offering} objects keyed by their identifier.
236
+ */
120
237
  readonly all: {
121
- [offeringId: string]: Offering_2;
238
+ [offeringId: string]: Offering;
122
239
  };
123
- readonly current: Offering_2 | null;
240
+ /**
241
+ * Current offering configured in the RevenueCat dashboard.
242
+ */
243
+ readonly current: Offering | null;
124
244
  }
125
245
 
126
- export declare type Package = Package_2;
127
-
128
- declare interface Package_2 {
129
- readonly id: string;
246
+ /**
247
+ * Contains information about the product available for the user to purchase.
248
+ * For more info see https://docs.revenuecat.com/docs/entitlements
249
+ * @public
250
+ */
251
+ export declare interface Package {
252
+ /**
253
+ * Unique identifier for this package. Can be one a predefined package type or a custom one.
254
+ */
130
255
  readonly identifier: string;
256
+ /**
257
+ * The {@link Product} assigned to this package.
258
+ */
131
259
  readonly rcBillingProduct: Product;
260
+ /**
261
+ * The type of package.
262
+ */
132
263
  readonly packageType: PackageType;
133
264
  }
134
265
 
135
- declare enum PackageType {
266
+ /**
267
+ * Enumeration of all possible Package types.
268
+ * @public
269
+ */
270
+ export declare enum PackageType {
271
+ /**
272
+ * A package that was defined with an unrecognized RC identifier.
273
+ */
136
274
  Unknown = "unknown",
275
+ /**
276
+ * A package that was defined with a custom identifier.
277
+ */
137
278
  Custom = "custom",
279
+ /**
280
+ * A package configured with the predefined lifetime identifier.
281
+ */
138
282
  Lifetime = "$rc_lifetime",
283
+ /**
284
+ * A package configured with the predefined annual identifier.
285
+ */
139
286
  Annual = "$rc_annual",
287
+ /**
288
+ * A package configured with the predefined six month identifier.
289
+ */
140
290
  SixMonth = "$rc_six_month",
291
+ /**
292
+ * A package configured with the predefined three month identifier.
293
+ */
141
294
  ThreeMonth = "$rc_three_month",
295
+ /**
296
+ * A package configured with the predefined two month identifier.
297
+ */
142
298
  TwoMonth = "$rc_two_month",
299
+ /**
300
+ * A package configured with the predefined monthly identifier.
301
+ */
143
302
  Monthly = "$rc_monthly",
303
+ /**
304
+ * A package configured with the predefined weekly identifier.
305
+ */
144
306
  Weekly = "$rc_weekly"
145
307
  }
146
308
 
309
+ /**
310
+ * Supported period types for an entitlement.
311
+ * - "normal" If the entitlement is not under an introductory or trial period.
312
+ * - "intro" If the entitlement is under an introductory period.
313
+ * - "trial" If the entitlement is under a trial period.
314
+ * @public
315
+ */
147
316
  export declare type PeriodType = "normal" | "intro" | "trial";
148
317
 
149
- declare interface Price {
318
+ /**
319
+ * Price information for a product.
320
+ * @public
321
+ */
322
+ export declare interface Price {
323
+ /**
324
+ * Price in full units of the currency.
325
+ */
150
326
  readonly amount: number;
327
+ /**
328
+ * Returns ISO 4217 currency code for price.
329
+ * For example, if price is specified in British pounds sterling,
330
+ * currency is "GBP".
331
+ * If currency code cannot be determined, currency symbol is returned.
332
+ */
151
333
  readonly currency: string;
152
334
  }
153
335
 
154
- declare interface Product {
155
- readonly id: string;
156
- readonly displayName: string;
336
+ /**
337
+ * Represents product's listing details.
338
+ * @public
339
+ */
340
+ export declare interface Product {
341
+ /**
342
+ * The product ID.
343
+ */
157
344
  readonly identifier: string;
158
- readonly currentPrice: Price | null;
345
+ /**
346
+ * Name of the product.
347
+ */
348
+ readonly displayName: string;
349
+ /**
350
+ * Price of the product.
351
+ */
352
+ readonly currentPrice: Price;
353
+ /**
354
+ * The period duration for a subscription product.
355
+ */
159
356
  readonly normalPeriodDuration: string | null;
357
+ /**
358
+ * The offering ID used to obtain this product.
359
+ */
160
360
  readonly presentedOfferingIdentifier: string;
161
361
  }
162
362
 
163
- declare class PurchaseFlowError extends Error {
164
- readonly errorCode: PurchaseFlowErrorCode;
165
- readonly underlyingErrorMessage?: string | null | undefined;
166
- constructor(errorCode: PurchaseFlowErrorCode, message?: string, underlyingErrorMessage?: string | null | undefined);
167
- }
168
-
169
- declare enum PurchaseFlowErrorCode {
170
- ErrorSettingUpPurchase = 0,
171
- ErrorChargingPayment = 1,
172
- UnknownError = 2,
173
- NetworkError = 3,
174
- StripeError = 4,
175
- MissingEmailError = 5
176
- }
177
-
363
+ /**
364
+ * Entry point for Purchases SDK. It should be instantiated as soon as your
365
+ * app is started. Only one instance of Purchases should be instantiated
366
+ * at a time!
367
+ * @public
368
+ */
178
369
  export declare class Purchases {
179
- private readonly backend;
180
- private readonly purchaseOperationHelper;
370
+ /**
371
+ * Constructor for Purchases.
372
+ * @param apiKey - RevenueCat API Key. Can be obtained from the RevenueCat dashboard.
373
+ */
181
374
  constructor(apiKey: string);
182
- private toOfferings;
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
+ */
183
380
  getOfferings(appUserId: string): Promise<Offerings>;
184
- isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
185
- purchasePackage(appUserId: string, rcPackage: Package, { customerEmail, htmlTarget, }?: {
186
- customerEmail?: string;
187
- htmlTarget?: HTMLElement;
188
- }): Promise<{
189
- customerInfo: CustomerInfo;
190
- }>;
191
- getCustomerInfo(appUserId: string): Promise<CustomerInfo>;
192
- private logMissingProductIds;
193
- isSandbox(): boolean;
194
- }
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}
389
+ */
390
+ isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
391
+ /**
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.
402
+ */
403
+ purchasePackage(appUserId: string, rcPackage: Package, customerEmail?: string, htmlTarget?: HTMLElement): Promise<{
404
+ customerInfo: CustomerInfo;
405
+ }>;
406
+ /**
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.
411
+ */
412
+ getCustomerInfo(appUserId: string): Promise<CustomerInfo>;
413
+ /**
414
+ * @returns Whether the SDK is using a sandbox API Key.
415
+ */
416
+ isSandbox(): boolean;
417
+ }
195
418
 
196
- export declare class PurchasesError extends Error {
197
- readonly errorCode: ErrorCode;
198
- readonly underlyingErrorMessage?: string | null | undefined;
199
- static getForBackendError(backendErrorCode: BackendErrorCode, backendErrorMessage: string | null): PurchasesError;
200
- static getForPurchasesFlowError(purchasesFlowError: PurchaseFlowError): PurchasesError;
201
- constructor(errorCode: ErrorCode, message?: string, underlyingErrorMessage?: string | null | undefined);
202
- toString: () => string;
203
- }
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
+ }
204
452
 
205
- export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
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";
206
458
 
207
- export { }
459
+ export { }