@revenuecat/purchases-js 0.0.15 → 0.0.17

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
@@ -55,10 +55,12 @@ By downloading the current Offerings you can easily build a Paywall page using t
55
55
  associated `rcBillingProduct` and price.
56
56
 
57
57
  ```typescript
58
- const appUserId = "the unique id of the user in your systems";
59
- const purchases = new Purchases("your RC_PUBLISHABLE_API_KEY");
58
+ const purchases = Purchases.configure(
59
+ "your RC_PUBLISHABLE_API_KEY",
60
+ "the unique id of the user in your systems",
61
+ );
60
62
 
61
- purchases.getOfferings(appUserId).then((offerings) => {
63
+ purchases.getOfferings().then((offerings) => {
62
64
  // Get current offering
63
65
  console.log(offerings.current);
64
66
  // Or a dictionary of all offerings
@@ -77,12 +79,15 @@ You can check the entitlements granted to your users throughout all the platform
77
79
  also on your website!
78
80
 
79
81
  ```typescript
80
- const appUserId = "the unique id of the user in your systems";
81
82
  const entitlementId = "the entitlementId you set up in RC";
82
83
 
83
- const purchases = new Purchases("your RC_PUBLISHABLE_API_KEY");
84
+ const purchases = Purchases.configure(
85
+ "your RC_PUBLISHABLE_API_KEY",
86
+ "the unique id of the user in your systems",
87
+ );
88
+ const appUserID = purchases.getAppUserId();
84
89
 
85
- purchases.isEntitledTo(appUserId, entitlementId).then((isEntitled) => {
90
+ purchases.isEntitledTo(entitlementId).then((isEntitled) => {
86
91
  if (isEntitled == true) {
87
92
  console.log(`User ${appUserID} is entitled to ${entitlementId}`);
88
93
  } else {
@@ -94,15 +99,21 @@ purchases.isEntitledTo(appUserId, entitlementId).then((isEntitled) => {
94
99
  As example, you can build a cool React component with it:
95
100
 
96
101
  ```tsx
97
- const WithEntitlement = ({ appUserId, entitlementId, children }) => {
102
+ Purchases.configure(
103
+ "your RC_PUBLISHABLE_API_KEY",
104
+ "the unique id of the user in your systems",
105
+ );
106
+
107
+ const WithEntitlement = ({ entitlementId, children }) => {
98
108
  const [isEntitled, setIsEntitled] = useState<boolean | null>(null);
99
109
 
100
110
  useEffect(() => {
101
- const purchases = new Purchases("your RC_PUBLISHABLE_API_KEY");
102
- purchases.isEntitledTo(appUserId, entitlementId).then((isEntitled) => {
103
- setIsEntitled(isEntitled);
104
- });
105
- }, [appUserId, entitlementId]);
111
+ Purchases.getSharedInstance()
112
+ .isEntitledTo(entitlementId)
113
+ .then((isEntitled) => {
114
+ setIsEntitled(isEntitled);
115
+ });
116
+ }, [entitlementId]);
106
117
 
107
118
  if (isEntitled === null) {
108
119
  return <>"loading..."</>;
@@ -121,7 +132,7 @@ And then use it in your app:
121
132
  ```tsx
122
133
  const App = () => (
123
134
  <>
124
- <WithEntitlement appUserId={"user12345"} entitlementId={"functionality5"}>
135
+ <WithEntitlement entitlementId={"functionality5"}>
125
136
  <Functionality5 />
126
137
  </WithEntitlement>
127
138
  </>
@@ -131,7 +142,7 @@ const App = () => (
131
142
  If you need further information about the user's entitlements, you can use the `getCustomerInfo` method:
132
143
 
133
144
  ```ts
134
- const customerInfo = await purchases.getCustomerInfo(appUserId);
145
+ const customerInfo = await purchases.getCustomerInfo();
135
146
  ```
136
147
 
137
148
  ### Important note
@@ -149,15 +160,17 @@ In this example we will show Stripe, more will be supported soon!
149
160
  You built your paywall, and your user just clicked on the offer they want to subscribe to.
150
161
 
151
162
  ```tsx
152
- const purchases = new Purchases("your RC_PUBLISHABLE_API_KEY");
163
+ const purchases = Purchases.configure(
164
+ "your RC_PUBLISHABLE_API_KEY",
165
+ "the unique id of the user in your systems",
166
+ );
153
167
  // You can retrieve the package from the offerings through `getOfferings`:
154
168
  const rcBillingPackage = offerings.current.availablePackages[0];
155
- const appUserId =
156
- "the unique id of the user that wants to subscribe to your product";
169
+ const appUserId = purchases.getAppUserId();
157
170
  const entitlementIdToCheck =
158
171
  "the entitlementId you set up in RC for your product"; // TODO: remove once this is not needed
159
172
 
160
- purchase.purchasePackage(appUserId, rcBillingPackage).then((response) => {
173
+ purchase.purchasePackage(rcBillingPackage).then((response) => {
161
174
  const isEntitled =
162
175
  entitlementIdToCheck in response.customerInfo.entitlements.active;
163
176
  if (isEntitled == true) {
@@ -215,24 +228,12 @@ This will update the files in `api-report` with the latest public API.
215
228
  If it has uncommited changes, CI tests will fail. Run this command and commit the changes if
216
229
  they are expected.
217
230
 
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
-
228
231
  # Publishing a new version
229
232
 
230
- - Update the version in `package.json`
231
- - Add a new entry in `CHANGELOG.md` including all the PR merged and crediting the authors
232
- - Commit the changes in main
233
- - Create a new tag with the version number and push:
233
+ New versions are automated weekly, but you can also trigger a new release through CircleCI or locally
234
+ following these steps:
234
235
 
235
- ```
236
- git tag v[version_number]
237
- git push origin v[version_number]
238
- ```
236
+ - Run `bundle exec fastlane bump` and follow the instructions
237
+ - A PR should be created with the changes and a hold job in CircleCI.
238
+ - Approve the hold job once tests pass. This will create a tag and continue the release in CircleCI
239
+ - Merge the PR once it's been released
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revenuecat/purchases-js",
3
3
  "private": false,
4
- "version": "0.0.15",
4
+ "version": "0.0.17",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -34,11 +34,9 @@
34
34
  "svelte-check": "svelte-check",
35
35
  "storybook": "storybook dev -p 6006",
36
36
  "build-storybook": "storybook build",
37
- "extract-api": "api-extractor run --local --verbose",
38
- "generate-docs": "api-documenter markdown --input-folder api-report --output-folder docs"
37
+ "extract-api": "api-extractor run --local --verbose"
39
38
  },
40
39
  "devDependencies": {
41
- "@microsoft/api-documenter": "^7.23.23",
42
40
  "@microsoft/api-extractor": "^7.40.1",
43
41
  "@storybook/addon-essentials": "^7.5.3",
44
42
  "@storybook/addon-interactions": "^7.5.3",
@@ -67,6 +65,7 @@
67
65
  "svelte": "^4.2.7",
68
66
  "svelte-check": "^3.6.3",
69
67
  "svelte-stripe": "^1.1.2",
68
+ "typedoc": "^0.25.8",
70
69
  "typescript": "^5.2.2",
71
70
  "vite": "^5.0.0",
72
71
  "vite-plugin-dts": "^3.6.3",
@@ -1,489 +0,0 @@
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
- */
9
- readonly entitlements: EntitlementInfos;
10
- /**
11
- * Map of productIds to expiration dates.
12
- */
13
- readonly allExpirationDatesByProduct: {
14
- [productIdentifier: string]: Date | null;
15
- };
16
- /**
17
- * Map of productIds to purchase dates.
18
- */
19
- readonly allPurchaseDatesByProduct: {
20
- [productIdentifier: string]: Date;
21
- };
22
- /**
23
- * Set of active subscription product identifiers.
24
- */
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
- */
33
- readonly managementURL: string | null;
34
- /**
35
- * Date when this info was requested.
36
- */
37
- readonly requestDate: Date;
38
- /**
39
- * The date this user was first seen in RevenueCat.
40
- */
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
- */
46
- readonly originalPurchaseDate: Date | null;
47
- /**
48
- * The original App User Id recorded for this user.
49
- */
50
- readonly originalAppUserId: string;
51
- }
52
-
53
- /**
54
- * This object gives you access to all the information about the status
55
- * of a user's entitlements.
56
- * @public
57
- */
58
- export declare interface EntitlementInfo {
59
- /**
60
- * The entitlement identifier configured in the RevenueCat dashboard.
61
- */
62
- readonly identifier: string;
63
- /**
64
- * True if the user has access to the entitlement.
65
- */
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
- */
72
- readonly willRenew: boolean;
73
- /**
74
- * The store where this entitlement was unlocked from.
75
- */
76
- readonly store: Store;
77
- /**
78
- * The first date this entitlement was purchased.
79
- */
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
- */
86
- readonly expirationDate: Date | null;
87
- /**
88
- * The product identifier that unlocked this entitlement.
89
- */
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
- */
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
- */
103
- readonly billingIssueDetectedAt: Date | null;
104
- /**
105
- * False if this entitlement is unlocked via a production purchase.
106
- */
107
- readonly isSandbox: boolean;
108
- /**
109
- * The last period type this entitlement was in.
110
- */
111
- readonly periodType: PeriodType;
112
- }
113
-
114
- /**
115
- * Contains all the entitlements associated to the user.
116
- * @public
117
- */
118
- export declare interface EntitlementInfos {
119
- /**
120
- * Map of all {@link EntitlementInfo} objects (active and inactive) keyed by
121
- * entitlement identifier.
122
- */
123
- readonly all: {
124
- [entitlementId: string]: EntitlementInfo;
125
- };
126
- /**
127
- * Dictionary of active {@link EntitlementInfo} keyed by entitlement identifier.
128
- */
129
- readonly active: {
130
- [entitlementId: string]: EntitlementInfo;
131
- };
132
- }
133
-
134
- /**
135
- * Error codes for the Purchases SDK.
136
- * @public
137
- */
138
- export declare enum ErrorCode {
139
- UnknownError = 0,
140
- UserCancelledError = 1,
141
- StoreProblemError = 2,
142
- PurchaseNotAllowedError = 3,
143
- PurchaseInvalidError = 4,
144
- ProductNotAvailableForPurchaseError = 5,
145
- ProductAlreadyPurchasedError = 6,
146
- ReceiptAlreadyInUseError = 7,
147
- InvalidReceiptError = 8,
148
- MissingReceiptFileError = 9,
149
- NetworkError = 10,
150
- InvalidCredentialsError = 11,
151
- UnexpectedBackendResponseError = 12,
152
- InvalidAppUserIdError = 14,
153
- OperationAlreadyInProgressError = 15,
154
- UnknownBackendError = 16,
155
- InvalidAppleSubscriptionKeyError = 17,
156
- IneligibleError = 18,
157
- InsufficientPermissionsError = 19,
158
- PaymentPendingError = 20,
159
- InvalidSubscriberAttributesError = 21,
160
- LogOutWithAnonymousUserError = 22,
161
- ConfigurationError = 23,
162
- UnsupportedError = 24,
163
- EmptySubscriberAttributesError = 25,
164
- CustomerInfoError = 28,
165
- SignatureVerificationError = 36
166
- }
167
-
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
- */
177
- readonly identifier: string;
178
- /**
179
- * Offering description defined in RevenueCat dashboard.
180
- */
181
- readonly serverDescription: string;
182
- /**
183
- * Offering metadata defined in RevenueCat dashboard.
184
- */
185
- readonly metadata: {
186
- [key: string]: unknown;
187
- } | null;
188
- /**
189
- * A map of all the packages available for purchase keyed by package ID.
190
- */
191
- readonly packagesById: {
192
- [key: string]: Package;
193
- };
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;
226
- }
227
-
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
- */
237
- readonly all: {
238
- [offeringId: string]: Offering;
239
- };
240
- /**
241
- * Current offering configured in the RevenueCat dashboard.
242
- */
243
- readonly current: Offering | null;
244
- }
245
-
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
- */
255
- readonly identifier: string;
256
- /**
257
- * The {@link Product} assigned to this package.
258
- */
259
- readonly rcBillingProduct: Product;
260
- /**
261
- * The type of package.
262
- */
263
- readonly packageType: PackageType;
264
- }
265
-
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
- */
274
- Unknown = "unknown",
275
- /**
276
- * A package that was defined with a custom identifier.
277
- */
278
- Custom = "custom",
279
- /**
280
- * A package configured with the predefined lifetime identifier.
281
- */
282
- Lifetime = "$rc_lifetime",
283
- /**
284
- * A package configured with the predefined annual identifier.
285
- */
286
- Annual = "$rc_annual",
287
- /**
288
- * A package configured with the predefined six month identifier.
289
- */
290
- SixMonth = "$rc_six_month",
291
- /**
292
- * A package configured with the predefined three month identifier.
293
- */
294
- ThreeMonth = "$rc_three_month",
295
- /**
296
- * A package configured with the predefined two month identifier.
297
- */
298
- TwoMonth = "$rc_two_month",
299
- /**
300
- * A package configured with the predefined monthly identifier.
301
- */
302
- Monthly = "$rc_monthly",
303
- /**
304
- * A package configured with the predefined weekly identifier.
305
- */
306
- Weekly = "$rc_weekly"
307
- }
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
- */
316
- export declare type PeriodType = "normal" | "intro" | "trial";
317
-
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
- */
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
- */
333
- readonly currency: string;
334
- }
335
-
336
- /**
337
- * Represents product's listing details.
338
- * @public
339
- */
340
- export declare interface Product {
341
- /**
342
- * The product ID.
343
- */
344
- readonly identifier: string;
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
- */
356
- readonly normalPeriodDuration: string | null;
357
- /**
358
- * The offering ID used to obtain this product.
359
- */
360
- readonly presentedOfferingIdentifier: string;
361
- }
362
-
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
- */
369
- export declare class Purchases {
370
- /**
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.
374
- */
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;
388
- /**
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}
400
- */
401
- isEntitledTo(entitlementIdentifier: string): Promise<boolean>;
402
- /**
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.
412
- */
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
-
442
- /**
443
- * Error class for Purchases SDK. You should handle these errors and react
444
- * accordingly in your app.
445
- * @public
446
- */
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
- }
475
-
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";
481
-
482
- /**
483
- * Error indicating that the SDK was accessed before it was initialized.
484
- */
485
- export declare class UninitializedPurchasesError extends Error {
486
- constructor();
487
- }
488
-
489
- export { }