@revenuecat/purchases-js 0.0.1 → 0.0.2

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/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "trailingComma": "all",
3
+ "tabWidth": 2,
4
+ "semi": true,
5
+ "singleQuote": false
6
+ }
@@ -1,3 +1,4 @@
1
+ import { ServerResponse } from "./types";
1
2
  export interface Price {
2
3
  amount: number;
3
4
  currency: string;
@@ -29,7 +30,6 @@ export interface OfferingsPage {
29
30
  [packageId: string]: number;
30
31
  };
31
32
  }
32
- export type ServerResponse = any;
33
33
  export declare const toPrice: (data: ServerResponse) => Price;
34
34
  export declare const toProduct: (data: ServerResponse) => Product;
35
35
  export declare const toPackage: (data: ServerResponse) => Package;
@@ -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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Offering as InnerOffering, OfferingsPage as InnerOfferingsPage, Package as InnerPackage } from "./entities/offerings";
2
+ import { SubscribeResponse } from "./entities/subscribe-response";
2
3
  export type OfferingsPage = InnerOfferingsPage;
3
4
  export type Offering = InnerOffering;
4
5
  export type Package = InnerPackage;
@@ -11,4 +12,5 @@ export declare class Purchases {
11
12
  private toOfferingsPage;
12
13
  listOfferings(): Promise<OfferingsPage>;
13
14
  isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
15
+ subscribe(appUserId: string, productId: string, environment?: "sandbox" | "production"): Promise<SubscribeResponse>;
14
16
  }
@@ -1,56 +1,65 @@
1
- var d = Object.defineProperty;
2
- var m = (e, t, i) => t in e ? d(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var o = (e, t, i) => (m(e, typeof t != "symbol" ? t + "" : t, i), i);
4
- var p = (e, t, i) => new Promise((c, a) => {
5
- var u = (r) => {
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
6
  try {
7
- s(i.next(r));
8
- } catch (l) {
9
- a(l);
7
+ a(n.next(r));
8
+ } catch (u) {
9
+ c(u);
10
10
  }
11
- }, _ = (r) => {
11
+ }, p = (r) => {
12
12
  try {
13
- s(i.throw(r));
14
- } catch (l) {
15
- a(l);
13
+ a(n.throw(r));
14
+ } catch (u) {
15
+ c(u);
16
16
  }
17
- }, s = (r) => r.done ? c(r.value) : Promise.resolve(r.value).then(u, _);
18
- s((i = i.apply(e, t)).next());
17
+ }, a = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(_, p);
18
+ a((n = n.apply(e, t)).next());
19
19
  });
20
- const P = (e) => ({
20
+ const m = (e) => ({
21
21
  amount: e.amount,
22
22
  currency: e.currency
23
- }), g = (e) => ({
23
+ }), A = (e) => ({
24
24
  id: e.id,
25
+ identifier: e.identifier,
25
26
  displayName: e.display_name,
26
- currentPrice: e.current_price ? P(e.current_price) : null,
27
+ currentPrice: e.current_price ? m(e.current_price) : null,
27
28
  normalPeriodDuration: e.normal_period_duration
28
- }), y = (e) => ({
29
+ }), g = (e) => ({
29
30
  id: e.id,
30
31
  identifier: e.identifier,
31
32
  displayName: e.display_name,
32
- rcBillingProduct: e.rc_billing_product ? g(e.rc_billing_product) : null
33
- }), A = (e) => ({
33
+ rcBillingProduct: e.rc_billing_product ? A(e.rc_billing_product) : null
34
+ }), y = (e) => ({
34
35
  id: e.id,
35
36
  identifier: e.identifier,
36
37
  displayName: e.display_name,
37
- packages: e.packages.map(y)
38
- }), n = class n {
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 {
39
48
  constructor(t) {
40
- o(this, "_API_KEY", null);
41
- o(this, "_APP_USER_ID", null);
42
- o(this, "toOfferingsPage", (t) => ({
43
- offerings: t.offerings.map(A),
49
+ s(this, "_API_KEY", null);
50
+ s(this, "_APP_USER_ID", null);
51
+ s(this, "toOfferingsPage", (t) => ({
52
+ offerings: t.offerings.map(y),
44
53
  priceByPackageId: t.prices_by_package_id
45
54
  }));
46
- this._API_KEY = t, n._RC_ENDPOINT === void 0 && console.error(
55
+ this._API_KEY = t, i._RC_ENDPOINT === void 0 && console.error(
47
56
  "Project was build without some of the environment variables set"
48
57
  );
49
58
  }
50
59
  listOfferings() {
51
- return p(this, null, function* () {
52
- const i = yield (yield fetch(
53
- `${n._RC_ENDPOINT}/${n._BASE_PATH}/offerings`,
60
+ return l(this, null, function* () {
61
+ const n = yield (yield fetch(
62
+ `${i._RC_ENDPOINT}/${i._BASE_PATH}/offerings`,
54
63
  {
55
64
  headers: {
56
65
  Authorization: `Bearer ${this._API_KEY}`,
@@ -59,13 +68,13 @@ const P = (e) => ({
59
68
  }
60
69
  }
61
70
  )).json();
62
- return this.toOfferingsPage(i);
71
+ return this.toOfferingsPage(n);
63
72
  });
64
73
  }
65
- isEntitledTo(t, i) {
66
- return p(this, null, function* () {
67
- const c = yield fetch(
68
- `${n._RC_ENDPOINT}/${n._BASE_PATH}/entitlements/${t}`,
74
+ isEntitledTo(t, n) {
75
+ return l(this, null, function* () {
76
+ const o = yield fetch(
77
+ `${i._RC_ENDPOINT}/${i._BASE_PATH}/entitlements/${t}`,
69
78
  {
70
79
  headers: {
71
80
  Authorization: `Bearer ${this._API_KEY}`,
@@ -74,14 +83,35 @@ const P = (e) => ({
74
83
  }
75
84
  }
76
85
  );
77
- return c.status === 404 ? !1 : (yield c.json()).entitlements.map(
78
- (s) => s.lookup_key
79
- ).includes(i);
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);
80
110
  });
81
111
  }
82
112
  };
83
- o(n, "_RC_ENDPOINT", "https://api.revenuecat.com"), o(n, "_BASE_PATH", "rcbilling/v1");
84
- let f = n;
113
+ s(i, "_RC_ENDPOINT", "https://api.revenuecat.com"), s(i, "_BASE_PATH", "rcbilling/v1");
114
+ let d = i;
85
115
  export {
86
- f as Purchases
116
+ d as Purchases
87
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.1",
4
+ "version": "0.0.2",
5
5
  "type": "module",
6
6
  "types": "dist/main.d.ts",
7
7
  "main": "dist/purchases-js.js",
@@ -1 +0,0 @@
1
- var Purchases=function(i){"use strict";var d=Object.defineProperty;var P=(i,r,n)=>r in i?d(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n;var c=(i,r,n)=>(P(i,typeof r!="symbol"?r+"":r,n),n);var p=(i,r,n)=>new Promise((u,l)=>{var a=t=>{try{e(n.next(t))}catch(s){l(s)}},o=t=>{try{e(n.throw(t))}catch(s){l(s)}},e=t=>t.done?u(t.value):Promise.resolve(t.value).then(a,o);e((n=n.apply(i,r)).next())});const r=e=>({amount:e.amount,currency:e.currency}),n=e=>({id:e.id,displayName:e.display_name,currentPrice:e.current_price?r(e.current_price):null,normalPeriodDuration:e.normal_period_duration}),u=e=>({id:e.id,identifier:e.identifier,displayName:e.display_name,rcBillingProduct:e.rc_billing_product?n(e.rc_billing_product):null}),l=e=>({id:e.id,identifier:e.identifier,displayName:e.display_name,packages:e.packages.map(u)}),o=class o{constructor(t){c(this,"_API_KEY",null);c(this,"_APP_USER_ID",null);c(this,"toOfferingsPage",t=>({offerings:t.offerings.map(l),priceByPackageId:t.prices_by_package_id}));this._API_KEY=t,o._RC_ENDPOINT===void 0&&console.error("Project was build without some of the environment variables set")}listOfferings(){return p(this,null,function*(){const s=yield(yield fetch(`${o._RC_ENDPOINT}/${o._BASE_PATH}/offerings`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"}})).json();return this.toOfferingsPage(s)})}isEntitledTo(t,s){return p(this,null,function*(){const _=yield fetch(`${o._RC_ENDPOINT}/${o._BASE_PATH}/entitlements/${t}`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"}});return _.status===404?!1:(yield _.json()).entitlements.map(f=>f.lookup_key).includes(s)})}};c(o,"_RC_ENDPOINT","https://api.revenuecat.com"),c(o,"_BASE_PATH","rcbilling/v1");let a=o;return i.Purchases=a,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({});
@@ -1 +0,0 @@
1
- (function(i,t){typeof exports=="object"&&typeof module!="undefined"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(i=typeof globalThis!="undefined"?globalThis:i||self,t(i.Purchases={}))})(this,function(i){"use strict";var d=Object.defineProperty;var m=(i,t,r)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[t]=r;var c=(i,t,r)=>(m(i,typeof t!="symbol"?t+"":t,r),r);var u=(i,t,r)=>new Promise((p,l)=>{var a=n=>{try{e(r.next(n))}catch(s){l(s)}},o=n=>{try{e(r.throw(n))}catch(s){l(s)}},e=n=>n.done?p(n.value):Promise.resolve(n.value).then(a,o);e((r=r.apply(i,t)).next())});const t=e=>({amount:e.amount,currency:e.currency}),r=e=>({id:e.id,displayName:e.display_name,currentPrice:e.current_price?t(e.current_price):null,normalPeriodDuration:e.normal_period_duration}),p=e=>({id:e.id,identifier:e.identifier,displayName:e.display_name,rcBillingProduct:e.rc_billing_product?r(e.rc_billing_product):null}),l=e=>({id:e.id,identifier:e.identifier,displayName:e.display_name,packages:e.packages.map(p)}),o=class o{constructor(n){c(this,"_API_KEY",null);c(this,"_APP_USER_ID",null);c(this,"toOfferingsPage",n=>({offerings:n.offerings.map(l),priceByPackageId:n.prices_by_package_id}));this._API_KEY=n,o._RC_ENDPOINT===void 0&&console.error("Project was build without some of the environment variables set")}listOfferings(){return u(this,null,function*(){const s=yield(yield fetch(`${o._RC_ENDPOINT}/${o._BASE_PATH}/offerings`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"}})).json();return this.toOfferingsPage(s)})}isEntitledTo(n,s){return u(this,null,function*(){const f=yield fetch(`${o._RC_ENDPOINT}/${o._BASE_PATH}/entitlements/${n}`,{headers:{Authorization:`Bearer ${this._API_KEY}`,"Content-Type":"application/json",Accept:"application/json"}});return f.status===404?!1:(yield f.json()).entitlements.map(_=>_.lookup_key).includes(s)})}};c(o,"_RC_ENDPOINT","https://api.revenuecat.com"),c(o,"_BASE_PATH","rcbilling/v1");let a=o;i.Purchases=a,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
Binary file