@revenuecat/purchases-js 0.0.2 → 0.0.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.
package/.eslintrc.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = {
2
+ plugins: ["prettier"],
2
3
  env: {
3
4
  browser: true,
4
5
  es2021: true,
@@ -0,0 +1,2 @@
1
+ package-lock.json
2
+ node_modules/
package/CHANGELOG ADDED
@@ -0,0 +1,23 @@
1
+ # 0.0.3
2
+
3
+ - Add prettier by @francocorreasosa in #13
4
+ - Bug: fix some types by @alfondotnet in #14
5
+
6
+ # 0.0.2
7
+
8
+ - Fix publishing to NPM by @alfondotnet in # 10
9
+ - BIL-40: Add subscribe method by @francocorreasosa in #11
10
+ - Only build ES modules by @alfondotnet in #12
11
+
12
+ # 0.0.1
13
+
14
+ Initial release 🐱🚀
15
+
16
+ - Add Vite by @alfondotnet in #1
17
+ - add README by @alfondotnet in #2
18
+ - Fon/add entrypoint by @alfondotnet in #3
19
+ - Simplify existing methods + MSW by @alfondotnet in #5
20
+ - Added the listOfferings method by @nicfix in #4
21
+ - Migrated to the new price naming by @nicfix in #6
22
+ - BIL-15: isEntitledTo method! by @nicfix in #7
23
+ - Rename / Clean up package prior to publishing to NPM by @alfondotnet in #9
package/README.md CHANGED
@@ -30,6 +30,7 @@ npm test
30
30
  # Publishing a new version
31
31
 
32
32
  - Update the version in `package.json`
33
+ - Add a new entry in `CHANGELOG.md` including all the PR merged and crediting the authors
33
34
  - Commit the changes in main
34
35
  - Create a new tag with the version number and push:
35
36
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revenuecat/purchases-js",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "types": "dist/main.d.ts",
7
7
  "main": "dist/purchases-js.js",
@@ -13,7 +13,8 @@
13
13
  "preview": "vite preview",
14
14
  "lint": "eslint . --ext .ts",
15
15
  "format": "eslint . --ext .ts --fix",
16
- "test": "vitest"
16
+ "test": "vitest",
17
+ "prettier:ci": "prettier --check ."
17
18
  },
18
19
  "devDependencies": {
19
20
  "@typescript-eslint/eslint-plugin": "^6.10.0",
@@ -26,12 +27,10 @@
26
27
  "eslint-plugin-promise": "^6.1.1",
27
28
  "jsdom": "^22.1.0",
28
29
  "msw": "^2.0.4",
30
+ "prettier": "^3.1.0",
29
31
  "typescript": "^5.2.2",
30
32
  "vite": "^4.4.5",
33
+ "vite-plugin-dts": "^3.6.3",
31
34
  "vitest": "^0.34.6"
32
- },
33
- "dependencies": {
34
- "prettier": "^3.0.3",
35
- "vite-plugin-dts": "^3.6.3"
36
35
  }
37
36
  }
package/test.html CHANGED
@@ -1,34 +1,38 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>RCBilling Example</title>
7
7
  <script src="./dist/rcbilling-js.iife.js"></script>
8
8
  <style>
9
- /* Some basic styling for our Stripe form */
10
- #payment-form {
11
- width: 300px;
12
- margin: 50px auto;
13
- padding: 20px;
14
- border: 1px solid #ddd;
15
- border-radius: 5px;
16
- }
9
+ /* Some basic styling for our Stripe form */
10
+ #payment-form {
11
+ width: 300px;
12
+ margin: 50px auto;
13
+ padding: 20px;
14
+ border: 1px solid #ddd;
15
+ border-radius: 5px;
16
+ }
17
17
  </style>
18
- </head>
19
- <body>
18
+ </head>
19
+ <body>
20
+ <div id="payment-form"></div>
20
21
 
21
- <div id="payment-form"></div>
22
-
23
- <script>
24
- document.addEventListener("DOMContentLoaded", function() {
25
- var billing = new RCBilling('web_tFpmIVwEGKNprbMOyiRRzZAbzIHX', 'test_rcbilling');
22
+ <script>
23
+ document.addEventListener("DOMContentLoaded", function () {
24
+ var billing = new RCBilling(
25
+ "web_tFpmIVwEGKNprbMOyiRRzZAbzIHX",
26
+ "test_rcbilling",
27
+ );
26
28
 
27
29
  setTimeout(() => {
28
- billing.renderForm(document.getElementById('payment-form'), "monthly.product_1234");
30
+ billing.renderForm(
31
+ document.getElementById("payment-form"),
32
+ "monthly.product_1234",
33
+ );
29
34
  }, 3000);
30
- });
31
- </script>
32
-
33
- </body>
35
+ });
36
+ </script>
37
+ </body>
34
38
  </html>
package/tsconfig.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "noUnusedLocals": true,
17
17
  "noUnusedParameters": true,
18
18
  "noFallthroughCasesInSwitch": true,
19
- "baseUrl": ".",
19
+ "baseUrl": "."
20
20
  },
21
21
  "include": ["./src/**/*.ts", "global.d.ts"],
22
22
  "exclude": ["node_modules", "*.test.ts"]
@@ -1,36 +0,0 @@
1
- import { ServerResponse } from "./types";
2
- export interface Price {
3
- amount: number;
4
- currency: string;
5
- }
6
- export interface Product {
7
- id: string;
8
- displayName: string;
9
- currentPrice: Price | null;
10
- normalPeriodDuration: string | null;
11
- }
12
- export interface Package {
13
- id: string;
14
- identifier: string;
15
- displayName: string;
16
- rcBillingProduct: Product | null;
17
- }
18
- export interface Offering {
19
- id: string;
20
- identifier: string;
21
- displayName: string;
22
- createdAt: Date;
23
- isCurrent: boolean;
24
- metadata: never;
25
- packages: Package[];
26
- }
27
- export interface OfferingsPage {
28
- offerings: Offering[];
29
- priceByPackageId: {
30
- [packageId: string]: number;
31
- };
32
- }
33
- export declare const toPrice: (data: ServerResponse) => Price;
34
- export declare const toProduct: (data: ServerResponse) => Product;
35
- export declare const toPackage: (data: ServerResponse) => Package;
36
- export declare const toOffering: (data: ServerResponse) => Offering;
@@ -1,8 +0,0 @@
1
- import { ServerResponse } from "./types";
2
- export interface SubscribeResponse {
3
- nextAction: string;
4
- data: {
5
- clientSecret?: string;
6
- };
7
- }
8
- export declare const toSubscribeResponse: (raw: ServerResponse) => SubscribeResponse;
@@ -1 +0,0 @@
1
- export type ServerResponse = any;
package/dist/main.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Offering as InnerOffering, OfferingsPage as InnerOfferingsPage, Package as InnerPackage } from "./entities/offerings";
2
- import { SubscribeResponse } from "./entities/subscribe-response";
3
- export type OfferingsPage = InnerOfferingsPage;
4
- export type Offering = InnerOffering;
5
- export type Package = InnerPackage;
6
- export declare class Purchases {
7
- _API_KEY: string | null;
8
- _APP_USER_ID: string | null;
9
- private static readonly _RC_ENDPOINT;
10
- private static readonly _BASE_PATH;
11
- constructor(apiKey: string);
12
- private toOfferingsPage;
13
- listOfferings(): Promise<OfferingsPage>;
14
- isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
15
- subscribe(appUserId: string, productId: string, environment?: "sandbox" | "production"): Promise<SubscribeResponse>;
16
- }
@@ -1,117 +0,0 @@
1
- var f = Object.defineProperty;
2
- var P = (e, t, n) => t in e ? f(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var s = (e, t, n) => (P(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- var l = (e, t, n) => new Promise((o, c) => {
5
- var _ = (r) => {
6
- try {
7
- a(n.next(r));
8
- } catch (u) {
9
- c(u);
10
- }
11
- }, p = (r) => {
12
- try {
13
- a(n.throw(r));
14
- } catch (u) {
15
- c(u);
16
- }
17
- }, a = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(_, p);
18
- a((n = n.apply(e, t)).next());
19
- });
20
- const m = (e) => ({
21
- amount: e.amount,
22
- currency: e.currency
23
- }), A = (e) => ({
24
- id: e.id,
25
- identifier: e.identifier,
26
- displayName: e.display_name,
27
- currentPrice: e.current_price ? m(e.current_price) : null,
28
- normalPeriodDuration: e.normal_period_duration
29
- }), g = (e) => ({
30
- id: e.id,
31
- identifier: e.identifier,
32
- displayName: e.display_name,
33
- rcBillingProduct: e.rc_billing_product ? A(e.rc_billing_product) : null
34
- }), y = (e) => ({
35
- id: e.id,
36
- identifier: e.identifier,
37
- displayName: e.display_name,
38
- packages: e.packages.map(g)
39
- }), b = (e) => {
40
- var t, n;
41
- return {
42
- nextAction: e.next_action,
43
- data: {
44
- clientSecret: (n = (t = e.data) == null ? void 0 : t.client_secret) != null ? n : void 0
45
- }
46
- };
47
- }, i = class i {
48
- constructor(t) {
49
- s(this, "_API_KEY", null);
50
- s(this, "_APP_USER_ID", null);
51
- s(this, "toOfferingsPage", (t) => ({
52
- offerings: t.offerings.map(y),
53
- priceByPackageId: t.prices_by_package_id
54
- }));
55
- this._API_KEY = t, i._RC_ENDPOINT === void 0 && console.error(
56
- "Project was build without some of the environment variables set"
57
- );
58
- }
59
- listOfferings() {
60
- return l(this, null, function* () {
61
- const n = yield (yield fetch(
62
- `${i._RC_ENDPOINT}/${i._BASE_PATH}/offerings`,
63
- {
64
- headers: {
65
- Authorization: `Bearer ${this._API_KEY}`,
66
- "Content-Type": "application/json",
67
- Accept: "application/json"
68
- }
69
- }
70
- )).json();
71
- return this.toOfferingsPage(n);
72
- });
73
- }
74
- isEntitledTo(t, n) {
75
- return l(this, null, function* () {
76
- const o = yield fetch(
77
- `${i._RC_ENDPOINT}/${i._BASE_PATH}/entitlements/${t}`,
78
- {
79
- headers: {
80
- Authorization: `Bearer ${this._API_KEY}`,
81
- "Content-Type": "application/json",
82
- Accept: "application/json"
83
- }
84
- }
85
- );
86
- return o.status === 404 ? !1 : (yield o.json()).entitlements.map(
87
- (a) => a.lookup_key
88
- ).includes(n);
89
- });
90
- }
91
- subscribe(t, n, o = "production") {
92
- return l(this, null, function* () {
93
- const c = o === "sandbox", p = yield (yield fetch(
94
- `${i._RC_ENDPOINT}/${i._BASE_PATH}/subscribe`,
95
- {
96
- method: "POST",
97
- headers: {
98
- Authorization: `Bearer ${this._API_KEY}`,
99
- "Content-Type": "application/json",
100
- Accept: "application/json"
101
- },
102
- body: JSON.stringify({
103
- app_user_id: t,
104
- product_id: n,
105
- is_sandbox: c
106
- })
107
- }
108
- )).json();
109
- return b(p);
110
- });
111
- }
112
- };
113
- s(i, "_RC_ENDPOINT", "https://api.revenuecat.com"), s(i, "_BASE_PATH", "rcbilling/v1");
114
- let d = i;
115
- export {
116
- d as Purchases
117
- };
Binary file