@chainrails/common 0.0.21 → 0.0.23
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.
|
@@ -1,38 +1,25 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(s || {}), c = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(c || {}), o = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(o || {});
|
|
2
2
|
class e {
|
|
3
|
-
constructor({ api_key:
|
|
4
|
-
this.api_key =
|
|
3
|
+
constructor({ api_key: r, env: n, seesion_token: a }) {
|
|
4
|
+
this.api_key = r || "", this.sessionToken = a || "", this.env = n ?? o.PRODUCTION;
|
|
5
5
|
}
|
|
6
|
-
static async config(
|
|
6
|
+
static async config(r) {
|
|
7
7
|
if (!e.app) {
|
|
8
|
-
if (!
|
|
8
|
+
if (!r)
|
|
9
9
|
throw new Error("Please provide an api_key");
|
|
10
|
-
e.app = new e(
|
|
11
|
-
}
|
|
12
|
-
return a && (e.app.api_key = a.api_key, a.env !== void 0 && (e.app.env = a.env), await this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
|
|
13
|
-
}
|
|
14
|
-
static async updateJWT() {
|
|
15
|
-
try {
|
|
16
|
-
const i = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
|
|
17
|
-
method: "POST",
|
|
18
|
-
headers: {
|
|
19
|
-
"content-type": "application/json"
|
|
20
|
-
},
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
apiKey: e.app.api_key
|
|
23
|
-
})
|
|
24
|
-
})).json();
|
|
25
|
-
this.app.jwt = i.token;
|
|
26
|
-
} catch {
|
|
10
|
+
e.app = new e(r);
|
|
27
11
|
}
|
|
12
|
+
return r && (r.api_key !== void 0 && (e.app.api_key = r.api_key), r.seesion_token !== void 0 && (e.app.sessionToken = r.seesion_token), r.env !== void 0 && (e.app.env = r.env)), e.app;
|
|
28
13
|
}
|
|
29
14
|
static getApiKey() {
|
|
30
15
|
if (!e.app)
|
|
31
16
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
32
17
|
return e.app.api_key;
|
|
33
18
|
}
|
|
34
|
-
static
|
|
35
|
-
|
|
19
|
+
static getSessionToken() {
|
|
20
|
+
if (!e.app)
|
|
21
|
+
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
22
|
+
return e.app.sessionToken;
|
|
36
23
|
}
|
|
37
24
|
static getEnv() {
|
|
38
25
|
if (!e.app)
|
|
@@ -53,18 +40,16 @@ class e {
|
|
|
53
40
|
return "https://api.chainrails.io/api/v1";
|
|
54
41
|
}
|
|
55
42
|
}
|
|
56
|
-
static getPayModalUrl(
|
|
43
|
+
static getPayModalUrl(r, n, a, i) {
|
|
57
44
|
if (!e.app)
|
|
58
45
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const E = `_chain_/${a}/_token_/${i}/_to_/${o}${r && "/_amount_/" + r * 100}`;
|
|
62
|
-
return s + p + E;
|
|
46
|
+
const E = e.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app" : "https://app.chainrails.io", T = i && i > 0 ? "/pay/" : "/deposit/", p = `_chain_/${r}/_token_/${n}/_to_/${a}${i ? "/_amount_/" + i * 100 : ""}`;
|
|
47
|
+
return E + T + p;
|
|
63
48
|
}
|
|
64
49
|
}
|
|
65
50
|
export {
|
|
66
51
|
e as Chainrails,
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
s as chains,
|
|
53
|
+
o as environment,
|
|
69
54
|
c as tokens
|
|
70
55
|
};
|
|
@@ -1,38 +1,25 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(s || {}), c = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(c || {}), o = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(o || {});
|
|
2
2
|
class e {
|
|
3
|
-
constructor({ api_key:
|
|
4
|
-
this.api_key =
|
|
3
|
+
constructor({ api_key: r, env: n, seesion_token: a }) {
|
|
4
|
+
this.api_key = r || "", this.sessionToken = a || "", this.env = n ?? o.PRODUCTION;
|
|
5
5
|
}
|
|
6
|
-
static async config(
|
|
6
|
+
static async config(r) {
|
|
7
7
|
if (!e.app) {
|
|
8
|
-
if (!
|
|
8
|
+
if (!r)
|
|
9
9
|
throw new Error("Please provide an api_key");
|
|
10
|
-
e.app = new e(
|
|
11
|
-
}
|
|
12
|
-
return a && (e.app.api_key = a.api_key, a.env !== void 0 && (e.app.env = a.env), await this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
|
|
13
|
-
}
|
|
14
|
-
static async updateJWT() {
|
|
15
|
-
try {
|
|
16
|
-
const i = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
|
|
17
|
-
method: "POST",
|
|
18
|
-
headers: {
|
|
19
|
-
"content-type": "application/json"
|
|
20
|
-
},
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
apiKey: e.app.api_key
|
|
23
|
-
})
|
|
24
|
-
})).json();
|
|
25
|
-
this.app.jwt = i.token;
|
|
26
|
-
} catch {
|
|
10
|
+
e.app = new e(r);
|
|
27
11
|
}
|
|
12
|
+
return r && (r.api_key !== void 0 && (e.app.api_key = r.api_key), r.seesion_token !== void 0 && (e.app.sessionToken = r.seesion_token), r.env !== void 0 && (e.app.env = r.env)), e.app;
|
|
28
13
|
}
|
|
29
14
|
static getApiKey() {
|
|
30
15
|
if (!e.app)
|
|
31
16
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
32
17
|
return e.app.api_key;
|
|
33
18
|
}
|
|
34
|
-
static
|
|
35
|
-
|
|
19
|
+
static getSessionToken() {
|
|
20
|
+
if (!e.app)
|
|
21
|
+
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
22
|
+
return e.app.sessionToken;
|
|
36
23
|
}
|
|
37
24
|
static getEnv() {
|
|
38
25
|
if (!e.app)
|
|
@@ -53,18 +40,16 @@ class e {
|
|
|
53
40
|
return "https://api.chainrails.io/api/v1";
|
|
54
41
|
}
|
|
55
42
|
}
|
|
56
|
-
static getPayModalUrl(
|
|
43
|
+
static getPayModalUrl(r, n, a, i) {
|
|
57
44
|
if (!e.app)
|
|
58
45
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const E = `_chain_/${a}/_token_/${i}/_to_/${o}${r && "/_amount_/" + r * 100}`;
|
|
62
|
-
return s + p + E;
|
|
46
|
+
const E = e.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app" : "https://app.chainrails.io", T = i && i > 0 ? "/pay/" : "/deposit/", p = `_chain_/${r}/_token_/${n}/_to_/${a}${i ? "/_amount_/" + i * 100 : ""}`;
|
|
47
|
+
return E + T + p;
|
|
63
48
|
}
|
|
64
49
|
}
|
|
65
50
|
export {
|
|
66
51
|
e as Chainrails,
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
s as chains,
|
|
53
|
+
o as environment,
|
|
69
54
|
c as tokens
|
|
70
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.Chainrails={}))})(this,(function(i){"use strict";var r=(t=>(t.ARBITRUM="ARBITRUM_MAINNET",t.ARBITRUM_TESTNET="ARBITRUM_TESTNET",t.AVALANCHE="AVALANCHE_MAINNET",t.AVALANCHE_TESTNET="AVALANCHE_TESTNET",t.BASE="BASE_MAINNET",t.BASE_TESTNET="BASE_TESTNET",t.BSC="BSC_MAINNET",t.ETHEREUM="ETHEREUM_MAINNET",t.ETHEREUM_TESTNET="ETHEREUM_TESTNET",t.STARKNET="STARKNET_MAINNET",t))(r||{}),p=(t=>(t.USDC="USDC",t))(p||{}),o=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(o||{});class e{constructor({api_key:n,env:s,seesion_token:T}){this.api_key=n||"",this.sessionToken=T||"",this.env=s??o.PRODUCTION}static async config(n){if(!e.app){if(!n)throw new Error("Please provide an api_key");e.app=new e(n)}return n&&(n.api_key!==void 0&&(e.app.api_key=n.api_key),n.seesion_token!==void 0&&(e.app.sessionToken=n.seesion_token),n.env!==void 0&&(e.app.env=n.env)),e.app}static getApiKey(){if(!e.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return e.app.api_key}static getSessionToken(){if(!e.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return e.app.sessionToken}static getEnv(){if(!e.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return e.app.env==="internal"?"staging":e.app.env}static getBaseUrl(){if(!e.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(e.app.env){case"production":return"https://api.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";case"internal":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}static getPayModalUrl(n,s,T,a){if(!e.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const E=e.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app":"https://app.chainrails.io",f=a&&a>0?"/pay/":"/deposit/",c=`_chain_/${n}/_token_/${s}/_to_/${T}${a?"/_amount_/"+a*100:""}`;return E+f+c}}i.Chainrails=e,i.chains=r,i.environment=o,i.tokens=p,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/src/app/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { EnvType } from "../environment";
|
|
2
2
|
interface ChainrailsConfig {
|
|
3
|
-
api_key
|
|
3
|
+
api_key?: string;
|
|
4
4
|
env?: EnvType;
|
|
5
|
+
seesion_token?: string;
|
|
5
6
|
}
|
|
6
7
|
export declare class Chainrails {
|
|
7
8
|
private static app;
|
|
8
9
|
api_key: string;
|
|
9
10
|
env: EnvType;
|
|
10
|
-
|
|
11
|
+
sessionToken: string;
|
|
11
12
|
private constructor();
|
|
12
13
|
static config(props?: ChainrailsConfig): Promise<Chainrails>;
|
|
13
|
-
static updateJWT(): Promise<void>;
|
|
14
14
|
static getApiKey(): string;
|
|
15
|
-
static
|
|
15
|
+
static getSessionToken(): string;
|
|
16
16
|
static getEnv(): EnvType;
|
|
17
17
|
static getBaseUrl(): string;
|
|
18
18
|
static getPayModalUrl(chain: string, token: string, to: string, amount?: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEtD,UAAU,gBAAgB;IACxB,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEtD,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAa;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IAErB,OAAO;WAMa,MAAM,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;WAqB3D,SAAS,IAAI,MAAM;WAOnB,eAAe,IAAI,MAAM;WAOzB,MAAM,IAAI,OAAO;WAQjB,UAAU,IAAI,MAAM;WAgBpB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;CAehG"}
|