@revenuecat/purchases-js 0.0.3 → 0.0.4

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/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.4
2
+
3
+ - Fix bug in 0.0.3 that didn't include the dist/ folder in the NPM package
4
+
1
5
  # 0.0.3
2
6
 
3
7
  - Add prettier by @francocorreasosa in #13
@@ -0,0 +1,34 @@
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
+ identifier: string;
10
+ currentPrice: Price | null;
11
+ normalPeriodDuration: string | null;
12
+ }
13
+ export interface Package {
14
+ id: string;
15
+ identifier: string;
16
+ displayName: string;
17
+ rcBillingProduct: Product | null;
18
+ }
19
+ export interface Offering {
20
+ id: string;
21
+ identifier: string;
22
+ displayName: string;
23
+ packages: Package[];
24
+ }
25
+ export interface OfferingsPage {
26
+ offerings: Offering[];
27
+ priceByPackageId: {
28
+ [packageId: string]: number;
29
+ };
30
+ }
31
+ export declare const toPrice: (data: ServerResponse) => Price;
32
+ export declare const toProduct: (data: ServerResponse) => Product;
33
+ export declare const toPackage: (data: ServerResponse) => Package;
34
+ export declare const toOffering: (data: ServerResponse) => Offering;
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1 @@
1
+ export type ServerResponse = any;
package/dist/main.d.ts ADDED
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,117 @@
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
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@revenuecat/purchases-js",
3
3
  "private": false,
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "types": "dist/main.d.ts",
7
7
  "main": "dist/purchases-js.js",
@@ -14,6 +14,7 @@
14
14
  "lint": "eslint . --ext .ts",
15
15
  "format": "eslint . --ext .ts --fix",
16
16
  "test": "vitest",
17
+ "prettier": "prettier --write .",
17
18
  "prettier:ci": "prettier --check ."
18
19
  },
19
20
  "devDependencies": {