@revenuecat/purchases-js 0.0.1
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 +29 -0
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/entities/offerings.d.ts +36 -0
- package/dist/main.d.ts +14 -0
- package/dist/purchases-js.iife.js +1 -0
- package/dist/purchases-js.js +87 -0
- package/dist/purchases-js.umd.cjs +1 -0
- package/global.d.ts +3 -0
- package/package.json +37 -0
- package/revenuecat-purchases-js-0.0.1.tgz +0 -0
- package/test.html +34 -0
- package/tsconfig.json +23 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
},
|
|
6
|
+
extends: [
|
|
7
|
+
"plugin:@typescript-eslint/recommended",
|
|
8
|
+
"plugin:prettier/recommended",
|
|
9
|
+
],
|
|
10
|
+
overrides: [
|
|
11
|
+
{
|
|
12
|
+
env: {
|
|
13
|
+
node: true,
|
|
14
|
+
},
|
|
15
|
+
files: [".eslintrc.{js,cjs}"],
|
|
16
|
+
parserOptions: {
|
|
17
|
+
sourceType: "script",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
parserOptions: {
|
|
22
|
+
ecmaVersion: "latest",
|
|
23
|
+
sourceType: "module",
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
"prettier/prettier": "error",
|
|
27
|
+
},
|
|
28
|
+
ignorePatterns: ["vite.config.js", "vitest.config.js", "dist/"],
|
|
29
|
+
};
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 RevenueCat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# RCBilling JS
|
|
2
|
+
|
|
3
|
+
JS SDK for RC Billing.
|
|
4
|
+
|
|
5
|
+
# Development
|
|
6
|
+
|
|
7
|
+
## Install the library in a local project
|
|
8
|
+
|
|
9
|
+
- Clone the repository
|
|
10
|
+
- Install dependencies
|
|
11
|
+
- Build the library
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install
|
|
15
|
+
npm run build:dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then in your local project you can do:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm i ../path/to/rcbilling-js
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Running tests
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Publishing a new version
|
|
31
|
+
|
|
32
|
+
- Update the version in `package.json`
|
|
33
|
+
- Commit the changes in main
|
|
34
|
+
- Create a new tag with the version number and push:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
git tag v[version_number]
|
|
38
|
+
git push origin v[version_number]
|
|
39
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Price {
|
|
2
|
+
amount: number;
|
|
3
|
+
currency: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Product {
|
|
6
|
+
id: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
currentPrice: Price | null;
|
|
9
|
+
normalPeriodDuration: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface Package {
|
|
12
|
+
id: string;
|
|
13
|
+
identifier: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
rcBillingProduct: Product | null;
|
|
16
|
+
}
|
|
17
|
+
export interface Offering {
|
|
18
|
+
id: string;
|
|
19
|
+
identifier: string;
|
|
20
|
+
displayName: string;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
isCurrent: boolean;
|
|
23
|
+
metadata: never;
|
|
24
|
+
packages: Package[];
|
|
25
|
+
}
|
|
26
|
+
export interface OfferingsPage {
|
|
27
|
+
offerings: Offering[];
|
|
28
|
+
priceByPackageId: {
|
|
29
|
+
[packageId: string]: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type ServerResponse = any;
|
|
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;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Offering as InnerOffering, OfferingsPage as InnerOfferingsPage, Package as InnerPackage } from "./entities/offerings";
|
|
2
|
+
export type OfferingsPage = InnerOfferingsPage;
|
|
3
|
+
export type Offering = InnerOffering;
|
|
4
|
+
export type Package = InnerPackage;
|
|
5
|
+
export declare class Purchases {
|
|
6
|
+
_API_KEY: string | null;
|
|
7
|
+
_APP_USER_ID: string | null;
|
|
8
|
+
private static readonly _RC_ENDPOINT;
|
|
9
|
+
private static readonly _BASE_PATH;
|
|
10
|
+
constructor(apiKey: string);
|
|
11
|
+
private toOfferingsPage;
|
|
12
|
+
listOfferings(): Promise<OfferingsPage>;
|
|
13
|
+
isEntitledTo(appUserId: string, entitlementIdentifier: string): Promise<boolean>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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}({});
|
|
@@ -0,0 +1,87 @@
|
|
|
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) => {
|
|
6
|
+
try {
|
|
7
|
+
s(i.next(r));
|
|
8
|
+
} catch (l) {
|
|
9
|
+
a(l);
|
|
10
|
+
}
|
|
11
|
+
}, _ = (r) => {
|
|
12
|
+
try {
|
|
13
|
+
s(i.throw(r));
|
|
14
|
+
} catch (l) {
|
|
15
|
+
a(l);
|
|
16
|
+
}
|
|
17
|
+
}, s = (r) => r.done ? c(r.value) : Promise.resolve(r.value).then(u, _);
|
|
18
|
+
s((i = i.apply(e, t)).next());
|
|
19
|
+
});
|
|
20
|
+
const P = (e) => ({
|
|
21
|
+
amount: e.amount,
|
|
22
|
+
currency: e.currency
|
|
23
|
+
}), g = (e) => ({
|
|
24
|
+
id: e.id,
|
|
25
|
+
displayName: e.display_name,
|
|
26
|
+
currentPrice: e.current_price ? P(e.current_price) : null,
|
|
27
|
+
normalPeriodDuration: e.normal_period_duration
|
|
28
|
+
}), y = (e) => ({
|
|
29
|
+
id: e.id,
|
|
30
|
+
identifier: e.identifier,
|
|
31
|
+
displayName: e.display_name,
|
|
32
|
+
rcBillingProduct: e.rc_billing_product ? g(e.rc_billing_product) : null
|
|
33
|
+
}), A = (e) => ({
|
|
34
|
+
id: e.id,
|
|
35
|
+
identifier: e.identifier,
|
|
36
|
+
displayName: e.display_name,
|
|
37
|
+
packages: e.packages.map(y)
|
|
38
|
+
}), n = class n {
|
|
39
|
+
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),
|
|
44
|
+
priceByPackageId: t.prices_by_package_id
|
|
45
|
+
}));
|
|
46
|
+
this._API_KEY = t, n._RC_ENDPOINT === void 0 && console.error(
|
|
47
|
+
"Project was build without some of the environment variables set"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
listOfferings() {
|
|
51
|
+
return p(this, null, function* () {
|
|
52
|
+
const i = yield (yield fetch(
|
|
53
|
+
`${n._RC_ENDPOINT}/${n._BASE_PATH}/offerings`,
|
|
54
|
+
{
|
|
55
|
+
headers: {
|
|
56
|
+
Authorization: `Bearer ${this._API_KEY}`,
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
Accept: "application/json"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
)).json();
|
|
62
|
+
return this.toOfferingsPage(i);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
isEntitledTo(t, i) {
|
|
66
|
+
return p(this, null, function* () {
|
|
67
|
+
const c = yield fetch(
|
|
68
|
+
`${n._RC_ENDPOINT}/${n._BASE_PATH}/entitlements/${t}`,
|
|
69
|
+
{
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Bearer ${this._API_KEY}`,
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
Accept: "application/json"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
return c.status === 404 ? !1 : (yield c.json()).entitlements.map(
|
|
78
|
+
(s) => s.lookup_key
|
|
79
|
+
).includes(i);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
o(n, "_RC_ENDPOINT", "https://api.revenuecat.com"), o(n, "_BASE_PATH", "rcbilling/v1");
|
|
84
|
+
let f = n;
|
|
85
|
+
export {
|
|
86
|
+
f as Purchases
|
|
87
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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"})});
|
package/global.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revenuecat/purchases-js",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "dist/main.d.ts",
|
|
7
|
+
"main": "dist/purchases-js.js",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite",
|
|
11
|
+
"build": "tsc && vite build",
|
|
12
|
+
"build:dev": "tsc && vite build --mode development",
|
|
13
|
+
"preview": "vite preview",
|
|
14
|
+
"lint": "eslint . --ext .ts",
|
|
15
|
+
"format": "eslint . --ext .ts --fix",
|
|
16
|
+
"test": "vitest"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
20
|
+
"eslint": "^8.53.0",
|
|
21
|
+
"eslint-config-prettier": "^9.0.0",
|
|
22
|
+
"eslint-config-standard-with-typescript": "^39.1.1",
|
|
23
|
+
"eslint-plugin-import": "^2.29.0",
|
|
24
|
+
"eslint-plugin-n": "^16.2.0",
|
|
25
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
26
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
27
|
+
"jsdom": "^22.1.0",
|
|
28
|
+
"msw": "^2.0.4",
|
|
29
|
+
"typescript": "^5.2.2",
|
|
30
|
+
"vite": "^4.4.5",
|
|
31
|
+
"vitest": "^0.34.6"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"prettier": "^3.0.3",
|
|
35
|
+
"vite-plugin-dts": "^3.6.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
Binary file
|
package/test.html
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>RCBilling Example</title>
|
|
7
|
+
<script src="./dist/rcbilling-js.iife.js"></script>
|
|
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
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<div id="payment-form"></div>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
document.addEventListener("DOMContentLoaded", function() {
|
|
25
|
+
var billing = new RCBilling('web_tFpmIVwEGKNprbMOyiRRzZAbzIHX', 'test_rcbilling');
|
|
26
|
+
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
billing.renderForm(document.getElementById('payment-form'), "monthly.product_1234");
|
|
29
|
+
}, 3000);
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"types": ["vite/client"],
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
8
|
+
// /* Bundler mode */
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
|
|
14
|
+
/* Linting */
|
|
15
|
+
"strict": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
"baseUrl": ".",
|
|
20
|
+
},
|
|
21
|
+
"include": ["./src/**/*.ts", "global.d.ts"],
|
|
22
|
+
"exclude": ["node_modules", "*.test.ts"]
|
|
23
|
+
}
|