@chainrails/sdk 0.0.29 → 0.0.31
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,8 +1,8 @@
|
|
|
1
1
|
import g from "ky";
|
|
2
|
-
var h = /* @__PURE__ */ ((e) => (e.ARBITRUM = "ARBITRUM_MAINNET", e.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", e.AVALANCHE = "AVALANCHE_MAINNET", e.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", e.BASE = "BASE_MAINNET", e.BASE_TESTNET = "BASE_TESTNET", e.BSC = "BSC_MAINNET", e.ETHEREUM = "ETHEREUM_MAINNET", e.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", e.STARKNET = "STARKNET_MAINNET", e))(h || {}), E = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(E || {}),
|
|
2
|
+
var h = /* @__PURE__ */ ((e) => (e.ARBITRUM = "ARBITRUM_MAINNET", e.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", e.AVALANCHE = "AVALANCHE_MAINNET", e.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", e.BASE = "BASE_MAINNET", e.BASE_TESTNET = "BASE_TESTNET", e.BSC = "BSC_MAINNET", e.ETHEREUM = "ETHEREUM_MAINNET", e.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", e.STARKNET = "STARKNET_MAINNET", e))(h || {}), E = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(E || {}), p = /* @__PURE__ */ ((e) => (e.PRODUCTION = "production", e.STAGING = "staging", e))(p || {});
|
|
3
3
|
class a {
|
|
4
4
|
constructor({ api_key: t, env: n }) {
|
|
5
|
-
this.api_key = t, this.jwt = "", this.env = n ??
|
|
5
|
+
this.api_key = t, this.jwt = "", this.env = n ?? p.PRODUCTION;
|
|
6
6
|
}
|
|
7
7
|
static async config(t) {
|
|
8
8
|
if (!a.app) {
|
|
@@ -54,11 +54,13 @@ class a {
|
|
|
54
54
|
return "https://api.chainrails.io/api/v1";
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
static getPayModalUrl(t, n,
|
|
57
|
+
static getPayModalUrl(t, n, c, r) {
|
|
58
58
|
if (!a.app)
|
|
59
59
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const l = a.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app" : "https://app.chainrails.io", o = r && r > 0 ? "/pay/" : "/deposit/";
|
|
61
|
+
console.log({ mode: o, mode2: r ? "/pay/" : "/deposit/", amount: r });
|
|
62
|
+
const u = `_chain_/${t}/_token_/${n}/_to_/${c}${r && "/_amount_/" + r * 100}`;
|
|
63
|
+
return l + o + u;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
let i = null;
|
|
@@ -157,6 +159,6 @@ export {
|
|
|
157
159
|
a as Chainrails,
|
|
158
160
|
h as chains,
|
|
159
161
|
N as crapi,
|
|
160
|
-
|
|
162
|
+
p as environment,
|
|
161
163
|
E as tokens
|
|
162
164
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import g from "ky";
|
|
2
|
-
var h = /* @__PURE__ */ ((e) => (e.ARBITRUM = "ARBITRUM_MAINNET", e.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", e.AVALANCHE = "AVALANCHE_MAINNET", e.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", e.BASE = "BASE_MAINNET", e.BASE_TESTNET = "BASE_TESTNET", e.BSC = "BSC_MAINNET", e.ETHEREUM = "ETHEREUM_MAINNET", e.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", e.STARKNET = "STARKNET_MAINNET", e))(h || {}), E = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(E || {}),
|
|
2
|
+
var h = /* @__PURE__ */ ((e) => (e.ARBITRUM = "ARBITRUM_MAINNET", e.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", e.AVALANCHE = "AVALANCHE_MAINNET", e.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", e.BASE = "BASE_MAINNET", e.BASE_TESTNET = "BASE_TESTNET", e.BSC = "BSC_MAINNET", e.ETHEREUM = "ETHEREUM_MAINNET", e.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", e.STARKNET = "STARKNET_MAINNET", e))(h || {}), E = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(E || {}), p = /* @__PURE__ */ ((e) => (e.PRODUCTION = "production", e.STAGING = "staging", e))(p || {});
|
|
3
3
|
class a {
|
|
4
4
|
constructor({ api_key: t, env: n }) {
|
|
5
|
-
this.api_key = t, this.jwt = "", this.env = n ??
|
|
5
|
+
this.api_key = t, this.jwt = "", this.env = n ?? p.PRODUCTION;
|
|
6
6
|
}
|
|
7
7
|
static async config(t) {
|
|
8
8
|
if (!a.app) {
|
|
@@ -54,11 +54,13 @@ class a {
|
|
|
54
54
|
return "https://api.chainrails.io/api/v1";
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
static getPayModalUrl(t, n,
|
|
57
|
+
static getPayModalUrl(t, n, c, r) {
|
|
58
58
|
if (!a.app)
|
|
59
59
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const l = a.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app" : "https://app.chainrails.io", o = r && r > 0 ? "/pay/" : "/deposit/";
|
|
61
|
+
console.log({ mode: o, mode2: r ? "/pay/" : "/deposit/", amount: r });
|
|
62
|
+
const u = `_chain_/${t}/_token_/${n}/_to_/${c}${r && "/_amount_/" + r * 100}`;
|
|
63
|
+
return l + o + u;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
let i = null;
|
|
@@ -157,6 +159,6 @@ export {
|
|
|
157
159
|
a as Chainrails,
|
|
158
160
|
h as chains,
|
|
159
161
|
N as crapi,
|
|
160
|
-
|
|
162
|
+
p as environment,
|
|
161
163
|
E as tokens
|
|
162
164
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,
|
|
1
|
+
(function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("ky")):typeof define=="function"&&define.amd?define(["exports","ky"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s.Chainrails={},s.Ky))})(this,(function(s,o){"use strict";var u=(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))(u||{}),l=(t=>(t.USDC="USDC",t))(l||{}),p=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(p||{});class n{constructor({api_key:e,env:i}){this.api_key=e,this.jwt="",this.env=i??p.PRODUCTION}static async config(e){if(!n.app){if(!e)throw new Error("Please provide an api_key");n.app=new n(e)}return e&&(n.app.api_key=e.api_key,e.env!==void 0&&(n.app.env=e.env),await this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),n.app}static async updateJWT(){try{const e=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({apiKey:n.app.api_key})})).json();this.app.jwt=e.token}catch{}}static getApiKey(){if(!n.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return n.app.api_key}static getSessionKey(){return n.app.jwt}static getEnv(){if(!n.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return n.app.env==="internal"?"staging":n.app.env}static getBaseUrl(){if(!n.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(n.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(e,i,A,r){if(!n.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const S=n.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app":"https://app.chainrails.io",g=r&&r>0?"/pay/":"/deposit/";console.log({mode:g,mode2:r?"/pay/":"/deposit/",amount:r});const N=`_chain_/${e}/_token_/${i}/_to_/${A}${r&&"/_amount_/"+r*100}`;return S+g+N}}let c=null;function h(){c=o.create({prefixUrl:n.getBaseUrl(),headers:{"Content-Type":"application/json"},hooks:{beforeRequest:[t=>{const e=n.getSessionKey();t.headers.set("Authorization",`Bearer ${e}`)}],afterResponse:[(t,e,i)=>i]},retry:{limit:2}})}function a(){return c||h(),c}class d{async getById(e){return await a().get("intents/"+e).json()}async getForSender(e){return await a().get("intents/user/"+e).json()}async getForAddress(e){return await a().get("intents/address/"+e).json()}async getAll(e){return await a().get("intents",{searchParams:e}).json()}async create(e){return await a().post("intents",{json:e}).json()}async update(e,i){return await a().post("intents",{json:i}).json()}async triggerProcessing(e){return await a().post(`intents/${e}/trigger-processing`).json()}}class T{async getFromSpecificBridge(e){return await a().get("quotes/single",{searchParams:e}).json()}async getFromAllBridges(e){return await a().get("quotes/multiple",{searchParams:e}).json()}async getBestAcrossBridges(e){return await a().get("quotes/best",{searchParams:e}).json()}async getAll(e){return await a().get("quotes/multi-source",{searchParams:e}).json()}}class E{async getOptimalRoutes(e){return await a().get("router/optimal-route",{searchParams:e}).json()}async getAllSupportedBridges(){return await a().get("router/supported-bridges/all").json()}async getSupportedBridges(e){return await a().get("router/supported-bridges/route",{searchParams:e}).json()}async getSupportedRoutes(e,i){return await a().get("router/supported-bridges/bridge/"+e,{searchParams:i}).json()}}class y{async getSupported(e){return await a().get("chains",{searchParams:e}).json()}}class f{async getClientInfo(){return await a().get("client/auth/client-info").json()}}const w={router:new E,quotes:new T,intents:new d,chains:new y,client:new f};s.Chainrails=n,s.chains=u,s.crapi=w,s.environment=p,s.tokens=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainrails/sdk",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.31",
|
|
5
5
|
"main": "./dist/chainrails-sdk.umd.js",
|
|
6
6
|
"module": "./dist/chainrails-sdk.es.mjs",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@chainrails/common": "^0.0.
|
|
38
|
+
"@chainrails/common": "^0.0.21",
|
|
39
39
|
"ky": "^1.14.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|