@chainrails/sdk 0.0.18 → 0.0.19

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.
@@ -14,12 +14,17 @@ class s {
14
14
  }
15
15
  static async updateJWT() {
16
16
  try {
17
- const e = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ const e = await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
18
+ headers: {
19
+ Authorization: `Bearer ${s.app.api_key}`
20
+ },
18
21
  body: JSON.stringify({
19
22
  apiKey: s.app.api_key
20
23
  })
21
- })).json();
22
- this.app.jwt = e.token;
24
+ });
25
+ console.log(e, this.getBaseUrl() + "/client/api-keys/session-token");
26
+ const r = await e.json();
27
+ console.log(r), this.app.jwt = r.token;
23
28
  } catch {
24
29
  }
25
30
  }
@@ -110,7 +115,7 @@ class l {
110
115
  return await a().get("quotes/multi-source", { searchParams: e }).json();
111
116
  }
112
117
  }
113
- class T {
118
+ class E {
114
119
  async getOptimalRoutes(e) {
115
120
  return await a().get("router/optimal-route", { searchParams: e }).json();
116
121
  }
@@ -124,27 +129,27 @@ class T {
124
129
  return await a().get("router/supported-bridges/bridge/" + e, { searchParams: r }).json();
125
130
  }
126
131
  }
127
- class h {
132
+ class T {
128
133
  async getSupported(e) {
129
134
  return await a().get("chains", { searchParams: e }).json();
130
135
  }
131
136
  }
132
- class E {
137
+ class h {
133
138
  async getClientInfo() {
134
139
  return await a().get("client/auth/client-info").json();
135
140
  }
136
141
  }
137
- const y = {
138
- router: new T(),
142
+ const d = {
143
+ router: new E(),
139
144
  quotes: new l(),
140
145
  intents: new g(),
141
- chains: new h(),
142
- client: new E()
146
+ chains: new T(),
147
+ client: new h()
143
148
  };
144
149
  export {
145
150
  s as Chainrails,
146
151
  p as chains,
147
- y as crapi,
152
+ d as crapi,
148
153
  i as environment,
149
154
  c as tokens
150
155
  };
@@ -14,12 +14,17 @@ class s {
14
14
  }
15
15
  static async updateJWT() {
16
16
  try {
17
- const e = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ const e = await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
18
+ headers: {
19
+ Authorization: `Bearer ${s.app.api_key}`
20
+ },
18
21
  body: JSON.stringify({
19
22
  apiKey: s.app.api_key
20
23
  })
21
- })).json();
22
- this.app.jwt = e.token;
24
+ });
25
+ console.log(e, this.getBaseUrl() + "/client/api-keys/session-token");
26
+ const r = await e.json();
27
+ console.log(r), this.app.jwt = r.token;
23
28
  } catch {
24
29
  }
25
30
  }
@@ -110,7 +115,7 @@ class l {
110
115
  return await a().get("quotes/multi-source", { searchParams: e }).json();
111
116
  }
112
117
  }
113
- class T {
118
+ class E {
114
119
  async getOptimalRoutes(e) {
115
120
  return await a().get("router/optimal-route", { searchParams: e }).json();
116
121
  }
@@ -124,27 +129,27 @@ class T {
124
129
  return await a().get("router/supported-bridges/bridge/" + e, { searchParams: r }).json();
125
130
  }
126
131
  }
127
- class h {
132
+ class T {
128
133
  async getSupported(e) {
129
134
  return await a().get("chains", { searchParams: e }).json();
130
135
  }
131
136
  }
132
- class E {
137
+ class h {
133
138
  async getClientInfo() {
134
139
  return await a().get("client/auth/client-info").json();
135
140
  }
136
141
  }
137
- const y = {
138
- router: new T(),
142
+ const d = {
143
+ router: new E(),
139
144
  quotes: new l(),
140
145
  intents: new g(),
141
- chains: new h(),
142
- client: new E()
146
+ chains: new T(),
147
+ client: new h()
143
148
  };
144
149
  export {
145
150
  s as Chainrails,
146
151
  p as chains,
147
- y as crapi,
152
+ d as crapi,
148
153
  i as environment,
149
154
  c as tokens
150
155
  };
@@ -1 +1 @@
1
- (function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("ky")):typeof define=="function"&&define.amd?define(["exports","ky"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.Chainrails={},a.Ky))})(this,(function(a,r){"use strict";var p=(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))(p||{}),u=(t=>(t.USDC="USDC",t))(u||{}),o=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(o||{});class s{constructor({api_key:e,env:i}){this.api_key=e,this.jwt="",this.env=i??o.PRODUCTION}static config(e){if(!s.app){if(!e)throw new Error("Please provide an api_key");s.app=new s(e)}return e&&(s.app.api_key=e.api_key,e.env!==void 0&&(s.app.env=e.env),this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),s.app}static async updateJWT(){try{const e=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{body:JSON.stringify({apiKey:s.app.api_key})})).json();this.app.jwt=e.token}catch{}}static getApiKey(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return s.app.api_key}static getSessionKey(){return s.app.jwt}static getEnv(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return s.app.env}static getBaseUrl(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(s.app.env){case"production":return"https://api.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}}let c=null;function g(){c=r.create({prefixUrl:s.getBaseUrl(),headers:{"Content-Type":"application/json"},hooks:{beforeRequest:[t=>{const e=s.getSessionKey();console.log({Chainrails:s},s.getApiKey(),s.getSessionKey()),t.headers.set("Authorization",`Bearer ${e}`)}],afterResponse:[(t,e,i)=>i]},retry:{limit:2}})}function n(){return c||g(),c}class l{async getById(e){return await n().get("intents/"+e).json()}async getForSender(e){return await n().get("intents/user/"+e).json()}async getForAddress(e){return await n().get("intents/address/"+e).json()}async getAll(e){return await n().get("intents",{searchParams:e}).json()}async create(e){return await n().post("intents",{json:e}).json()}async update(e,i){return await n().post("intents",{json:i}).json()}async triggerProcessing(e){return await n().post(`intents/${e}/trigger-processing`).json()}}class T{async getFromSpecificBridge(e){return await n().get("quotes/single",{searchParams:e}).json()}async getFromAllBridges(e){return await n().get("quotes/multiple",{searchParams:e}).json()}async getBestAcrossBridges(e){return await n().get("quotes/best",{searchParams:e}).json()}async getAll(e){return await n().get("quotes/multi-source",{searchParams:e}).json()}}class d{async getOptimalRoutes(e){return await n().get("router/optimal-route",{searchParams:e}).json()}async getAllSupportedBridges(){return await n().get("router/supported-bridges/all").json()}async getSupportedBridges(e){return await n().get("router/supported-bridges/route",{searchParams:e}).json()}async getSupportedRoutes(e,i){return await n().get("router/supported-bridges/bridge/"+e,{searchParams:i}).json()}}class h{async getSupported(e){return await n().get("chains",{searchParams:e}).json()}}class y{async getClientInfo(){return await n().get("client/auth/client-info").json()}}const E={router:new d,quotes:new T,intents:new l,chains:new h,client:new y};a.Chainrails=s,a.chains=p,a.crapi=E,a.environment=o,a.tokens=u,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("ky")):typeof define=="function"&&define.amd?define(["exports","ky"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.Chainrails={},a.Ky))})(this,(function(a,r){"use strict";var p=(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))(p||{}),u=(t=>(t.USDC="USDC",t))(u||{}),o=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(o||{});class s{constructor({api_key:e,env:i}){this.api_key=e,this.jwt="",this.env=i??o.PRODUCTION}static config(e){if(!s.app){if(!e)throw new Error("Please provide an api_key");s.app=new s(e)}return e&&(s.app.api_key=e.api_key,e.env!==void 0&&(s.app.env=e.env),this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),s.app}static async updateJWT(){try{const e=await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{headers:{Authorization:`Bearer ${s.app.api_key}`},body:JSON.stringify({apiKey:s.app.api_key})});console.log(e,this.getBaseUrl()+"/client/api-keys/session-token");const i=await e.json();console.log(i),this.app.jwt=i.token}catch{}}static getApiKey(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return s.app.api_key}static getSessionKey(){return s.app.jwt}static getEnv(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return s.app.env}static getBaseUrl(){if(!s.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(s.app.env){case"production":return"https://api.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}}let c=null;function l(){c=r.create({prefixUrl:s.getBaseUrl(),headers:{"Content-Type":"application/json"},hooks:{beforeRequest:[t=>{const e=s.getSessionKey();console.log({Chainrails:s},s.getApiKey(),s.getSessionKey()),t.headers.set("Authorization",`Bearer ${e}`)}],afterResponse:[(t,e,i)=>i]},retry:{limit:2}})}function n(){return c||l(),c}class g{async getById(e){return await n().get("intents/"+e).json()}async getForSender(e){return await n().get("intents/user/"+e).json()}async getForAddress(e){return await n().get("intents/address/"+e).json()}async getAll(e){return await n().get("intents",{searchParams:e}).json()}async create(e){return await n().post("intents",{json:e}).json()}async update(e,i){return await n().post("intents",{json:i}).json()}async triggerProcessing(e){return await n().post(`intents/${e}/trigger-processing`).json()}}class h{async getFromSpecificBridge(e){return await n().get("quotes/single",{searchParams:e}).json()}async getFromAllBridges(e){return await n().get("quotes/multiple",{searchParams:e}).json()}async getBestAcrossBridges(e){return await n().get("quotes/best",{searchParams:e}).json()}async getAll(e){return await n().get("quotes/multi-source",{searchParams:e}).json()}}class T{async getOptimalRoutes(e){return await n().get("router/optimal-route",{searchParams:e}).json()}async getAllSupportedBridges(){return await n().get("router/supported-bridges/all").json()}async getSupportedBridges(e){return await n().get("router/supported-bridges/route",{searchParams:e}).json()}async getSupportedRoutes(e,i){return await n().get("router/supported-bridges/bridge/"+e,{searchParams:i}).json()}}class d{async getSupported(e){return await n().get("chains",{searchParams:e}).json()}}class E{async getClientInfo(){return await n().get("client/auth/client-info").json()}}const y={router:new T,quotes:new h,intents:new g,chains:new d,client:new E};a.Chainrails=s,a.chains=p,a.crapi=y,a.environment=o,a.tokens=u,Object.defineProperty(a,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.18",
4
+ "version": "0.0.19",
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.10",
38
+ "@chainrails/common": "^0.0.11",
39
39
  "ky": "^1.14.0"
40
40
  },
41
41
  "devDependencies": {