@chainrails/sdk 0.0.22 → 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,157 +1,162 @@
1
- import o from "ky";
2
- var c = /* @__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))(c || {}), p = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(p || {}), i = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(i || {});
3
- class s {
4
- constructor({ api_key: e, env: n }) {
5
- this.api_key = e, this.jwt = "", this.env = n ?? i.PRODUCTION;
6
- }
7
- static config(e) {
8
- if (!s.app) {
9
- if (!e)
1
+ import u from "ky";
2
+ var g = /* @__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))(g || {}), h = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(h || {}), i = /* @__PURE__ */ ((e) => (e.PRODUCTION = "production", e.STAGING = "staging", e))(i || {});
3
+ class a {
4
+ constructor({ api_key: t, env: r }) {
5
+ this.api_key = t, this.jwt = "", this.env = r ?? i.PRODUCTION;
6
+ }
7
+ static config(t) {
8
+ if (!a.app) {
9
+ if (!t)
10
10
  throw new Error("Please provide an api_key");
11
- s.app = new s(e);
11
+ a.app = new a(t);
12
12
  }
13
- 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;
13
+ return t && (a.app.api_key = t.api_key, t.env !== void 0 && (a.app.env = t.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), a.app;
14
14
  }
15
15
  static async updateJWT() {
16
16
  try {
17
- const e = await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ const t = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
18
18
  method: "POST",
19
- headers: {
20
- Authorization: `Bearer ${s.app.api_key}`
21
- },
19
+ // headers: {
20
+ // Authorization: `Bearer ${Chainrails.app.api_key}`,
21
+ // },
22
22
  body: JSON.stringify({
23
- apiKey: s.app.api_key
23
+ apiKey: a.app.api_key
24
24
  })
25
- });
26
- console.log(e, this.getBaseUrl() + "/client/api-keys/session-token");
27
- const n = await e.json();
28
- console.log(n), this.app.jwt = n.token;
29
- } catch (e) {
30
- console.log(e);
25
+ })).json();
26
+ this.app.jwt = t.token;
27
+ } catch {
31
28
  }
32
29
  }
33
30
  static getApiKey() {
34
- if (!s.app)
31
+ if (!a.app)
35
32
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
36
- return s.app.api_key;
33
+ return a.app.api_key;
37
34
  }
38
35
  static getSessionKey() {
39
- return console.log("jwttt"), this.updateJWT(), console.log("jwttt2"), s.app.jwt;
36
+ return a.app.jwt;
40
37
  }
41
38
  static getEnv() {
42
- if (!s.app)
39
+ if (!a.app)
43
40
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
44
- return s.app.env;
41
+ return a.app.env === "internal" ? "staging" : a.app.env;
45
42
  }
46
43
  static getBaseUrl() {
47
- if (!s.app)
44
+ if (!a.app)
48
45
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
49
- switch (s.app.env) {
46
+ switch (a.app.env) {
50
47
  case "production":
51
48
  return "https://api.chainrails.io/api/v1";
52
49
  case "staging":
53
50
  return "https://dev.chainrails.io/api/v1";
51
+ case "internal":
52
+ return "https://dev.chainrails.io/api/v1";
54
53
  default:
55
54
  return "https://api.chainrails.io/api/v1";
56
55
  }
57
56
  }
57
+ static getPayModalUrl(t, r, o, p) {
58
+ if (!a.app)
59
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
60
+ const c = a.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/" : "https://app.chainrails.io/pay/", l = `${t}/_token_/${r}/_to_/${o}/_amount_/${p * 100}`;
61
+ return c + l;
62
+ }
58
63
  }
59
- let r = null;
60
- function l() {
61
- r = o.create({
62
- prefixUrl: s.getBaseUrl(),
64
+ let n = null;
65
+ function E() {
66
+ n = u.create({
67
+ prefixUrl: a.getBaseUrl(),
63
68
  headers: {
64
69
  "Content-Type": "application/json"
65
70
  },
66
71
  hooks: {
67
72
  beforeRequest: [
68
- (t) => {
69
- const e = s.getSessionKey();
70
- console.log({ Chainrails: s }, s.getApiKey(), s.getSessionKey()), t.headers.set("Authorization", `Bearer ${e}`);
73
+ (e) => {
74
+ const t = a.getSessionKey();
75
+ e.headers.set("Authorization", `Bearer ${t}`);
71
76
  }
72
77
  ],
73
- afterResponse: [(t, e, n) => n]
78
+ afterResponse: [(e, t, r) => r]
74
79
  },
75
80
  retry: {
76
81
  limit: 2
77
82
  }
78
83
  });
79
84
  }
80
- function a() {
81
- return r || l(), r;
85
+ function s() {
86
+ return n || E(), n;
82
87
  }
83
- class g {
84
- async getById(e) {
85
- return await a().get("intents/" + e).json();
88
+ class T {
89
+ async getById(t) {
90
+ return await s().get("intents/" + t).json();
86
91
  }
87
- async getForSender(e) {
88
- return await a().get("intents/user/" + e).json();
92
+ async getForSender(t) {
93
+ return await s().get("intents/user/" + t).json();
89
94
  }
90
- async getForAddress(e) {
91
- return await a().get("intents/address/" + e).json();
95
+ async getForAddress(t) {
96
+ return await s().get("intents/address/" + t).json();
92
97
  }
93
- async getAll(e) {
94
- return await a().get("intents", { searchParams: e }).json();
98
+ async getAll(t) {
99
+ return await s().get("intents", { searchParams: t }).json();
95
100
  }
96
- async create(e) {
97
- return await a().post("intents", { json: e }).json();
101
+ async create(t) {
102
+ return await s().post("intents", { json: t }).json();
98
103
  }
99
- async update(e, n) {
100
- return await a().post("intents", { json: n }).json();
104
+ async update(t, r) {
105
+ return await s().post("intents", { json: r }).json();
101
106
  }
102
- async triggerProcessing(e) {
103
- return await a().post(`intents/${e}/trigger-processing`).json();
107
+ async triggerProcessing(t) {
108
+ return await s().post(`intents/${t}/trigger-processing`).json();
104
109
  }
105
110
  }
106
- class u {
107
- async getFromSpecificBridge(e) {
108
- return await a().get("quotes/single", { searchParams: e }).json();
111
+ class d {
112
+ async getFromSpecificBridge(t) {
113
+ return await s().get("quotes/single", { searchParams: t }).json();
109
114
  }
110
- async getFromAllBridges(e) {
111
- return await a().get("quotes/multiple", { searchParams: e }).json();
115
+ async getFromAllBridges(t) {
116
+ return await s().get("quotes/multiple", { searchParams: t }).json();
112
117
  }
113
- async getBestAcrossBridges(e) {
114
- return await a().get("quotes/best", { searchParams: e }).json();
118
+ async getBestAcrossBridges(t) {
119
+ return await s().get("quotes/best", { searchParams: t }).json();
115
120
  }
116
- async getAll(e) {
117
- return await a().get("quotes/multi-source", { searchParams: e }).json();
121
+ async getAll(t) {
122
+ return await s().get("quotes/multi-source", { searchParams: t }).json();
118
123
  }
119
124
  }
120
- class T {
121
- async getOptimalRoutes(e) {
122
- return await a().get("router/optimal-route", { searchParams: e }).json();
125
+ class y {
126
+ async getOptimalRoutes(t) {
127
+ return await s().get("router/optimal-route", { searchParams: t }).json();
123
128
  }
124
129
  async getAllSupportedBridges() {
125
- return await a().get("router/supported-bridges/all").json();
130
+ return await s().get("router/supported-bridges/all").json();
126
131
  }
127
- async getSupportedBridges(e) {
128
- return await a().get("router/supported-bridges/route", { searchParams: e }).json();
132
+ async getSupportedBridges(t) {
133
+ return await s().get("router/supported-bridges/route", { searchParams: t }).json();
129
134
  }
130
- async getSupportedRoutes(e, n) {
131
- return await a().get("router/supported-bridges/bridge/" + e, { searchParams: n }).json();
135
+ async getSupportedRoutes(t, r) {
136
+ return await s().get("router/supported-bridges/bridge/" + t, { searchParams: r }).json();
132
137
  }
133
138
  }
134
- class h {
135
- async getSupported(e) {
136
- return await a().get("chains", { searchParams: e }).json();
139
+ class w {
140
+ async getSupported(t) {
141
+ return await s().get("chains", { searchParams: t }).json();
137
142
  }
138
143
  }
139
- class E {
144
+ class A {
140
145
  async getClientInfo() {
141
- return await a().get("client/auth/client-info").json();
146
+ return await s().get("client/auth/client-info").json();
142
147
  }
143
148
  }
144
- const y = {
145
- router: new T(),
146
- quotes: new u(),
147
- intents: new g(),
148
- chains: new h(),
149
- client: new E()
149
+ const S = {
150
+ router: new y(),
151
+ quotes: new d(),
152
+ intents: new T(),
153
+ chains: new w(),
154
+ client: new A()
150
155
  };
151
156
  export {
152
- s as Chainrails,
153
- c as chains,
154
- y as crapi,
157
+ a as Chainrails,
158
+ g as chains,
159
+ S as crapi,
155
160
  i as environment,
156
- p as tokens
161
+ h as tokens
157
162
  };
@@ -1,157 +1,162 @@
1
- import o from "ky";
2
- var c = /* @__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))(c || {}), p = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(p || {}), i = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(i || {});
3
- class s {
4
- constructor({ api_key: e, env: n }) {
5
- this.api_key = e, this.jwt = "", this.env = n ?? i.PRODUCTION;
6
- }
7
- static config(e) {
8
- if (!s.app) {
9
- if (!e)
1
+ import u from "ky";
2
+ var g = /* @__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))(g || {}), h = /* @__PURE__ */ ((e) => (e.USDC = "USDC", e))(h || {}), i = /* @__PURE__ */ ((e) => (e.PRODUCTION = "production", e.STAGING = "staging", e))(i || {});
3
+ class a {
4
+ constructor({ api_key: t, env: r }) {
5
+ this.api_key = t, this.jwt = "", this.env = r ?? i.PRODUCTION;
6
+ }
7
+ static config(t) {
8
+ if (!a.app) {
9
+ if (!t)
10
10
  throw new Error("Please provide an api_key");
11
- s.app = new s(e);
11
+ a.app = new a(t);
12
12
  }
13
- 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;
13
+ return t && (a.app.api_key = t.api_key, t.env !== void 0 && (a.app.env = t.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), a.app;
14
14
  }
15
15
  static async updateJWT() {
16
16
  try {
17
- const e = await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ const t = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
18
18
  method: "POST",
19
- headers: {
20
- Authorization: `Bearer ${s.app.api_key}`
21
- },
19
+ // headers: {
20
+ // Authorization: `Bearer ${Chainrails.app.api_key}`,
21
+ // },
22
22
  body: JSON.stringify({
23
- apiKey: s.app.api_key
23
+ apiKey: a.app.api_key
24
24
  })
25
- });
26
- console.log(e, this.getBaseUrl() + "/client/api-keys/session-token");
27
- const n = await e.json();
28
- console.log(n), this.app.jwt = n.token;
29
- } catch (e) {
30
- console.log(e);
25
+ })).json();
26
+ this.app.jwt = t.token;
27
+ } catch {
31
28
  }
32
29
  }
33
30
  static getApiKey() {
34
- if (!s.app)
31
+ if (!a.app)
35
32
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
36
- return s.app.api_key;
33
+ return a.app.api_key;
37
34
  }
38
35
  static getSessionKey() {
39
- return console.log("jwttt"), this.updateJWT(), console.log("jwttt2"), s.app.jwt;
36
+ return a.app.jwt;
40
37
  }
41
38
  static getEnv() {
42
- if (!s.app)
39
+ if (!a.app)
43
40
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
44
- return s.app.env;
41
+ return a.app.env === "internal" ? "staging" : a.app.env;
45
42
  }
46
43
  static getBaseUrl() {
47
- if (!s.app)
44
+ if (!a.app)
48
45
  throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
49
- switch (s.app.env) {
46
+ switch (a.app.env) {
50
47
  case "production":
51
48
  return "https://api.chainrails.io/api/v1";
52
49
  case "staging":
53
50
  return "https://dev.chainrails.io/api/v1";
51
+ case "internal":
52
+ return "https://dev.chainrails.io/api/v1";
54
53
  default:
55
54
  return "https://api.chainrails.io/api/v1";
56
55
  }
57
56
  }
57
+ static getPayModalUrl(t, r, o, p) {
58
+ if (!a.app)
59
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
60
+ const c = a.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/" : "https://app.chainrails.io/pay/", l = `${t}/_token_/${r}/_to_/${o}/_amount_/${p * 100}`;
61
+ return c + l;
62
+ }
58
63
  }
59
- let r = null;
60
- function l() {
61
- r = o.create({
62
- prefixUrl: s.getBaseUrl(),
64
+ let n = null;
65
+ function E() {
66
+ n = u.create({
67
+ prefixUrl: a.getBaseUrl(),
63
68
  headers: {
64
69
  "Content-Type": "application/json"
65
70
  },
66
71
  hooks: {
67
72
  beforeRequest: [
68
- (t) => {
69
- const e = s.getSessionKey();
70
- console.log({ Chainrails: s }, s.getApiKey(), s.getSessionKey()), t.headers.set("Authorization", `Bearer ${e}`);
73
+ (e) => {
74
+ const t = a.getSessionKey();
75
+ e.headers.set("Authorization", `Bearer ${t}`);
71
76
  }
72
77
  ],
73
- afterResponse: [(t, e, n) => n]
78
+ afterResponse: [(e, t, r) => r]
74
79
  },
75
80
  retry: {
76
81
  limit: 2
77
82
  }
78
83
  });
79
84
  }
80
- function a() {
81
- return r || l(), r;
85
+ function s() {
86
+ return n || E(), n;
82
87
  }
83
- class g {
84
- async getById(e) {
85
- return await a().get("intents/" + e).json();
88
+ class T {
89
+ async getById(t) {
90
+ return await s().get("intents/" + t).json();
86
91
  }
87
- async getForSender(e) {
88
- return await a().get("intents/user/" + e).json();
92
+ async getForSender(t) {
93
+ return await s().get("intents/user/" + t).json();
89
94
  }
90
- async getForAddress(e) {
91
- return await a().get("intents/address/" + e).json();
95
+ async getForAddress(t) {
96
+ return await s().get("intents/address/" + t).json();
92
97
  }
93
- async getAll(e) {
94
- return await a().get("intents", { searchParams: e }).json();
98
+ async getAll(t) {
99
+ return await s().get("intents", { searchParams: t }).json();
95
100
  }
96
- async create(e) {
97
- return await a().post("intents", { json: e }).json();
101
+ async create(t) {
102
+ return await s().post("intents", { json: t }).json();
98
103
  }
99
- async update(e, n) {
100
- return await a().post("intents", { json: n }).json();
104
+ async update(t, r) {
105
+ return await s().post("intents", { json: r }).json();
101
106
  }
102
- async triggerProcessing(e) {
103
- return await a().post(`intents/${e}/trigger-processing`).json();
107
+ async triggerProcessing(t) {
108
+ return await s().post(`intents/${t}/trigger-processing`).json();
104
109
  }
105
110
  }
106
- class u {
107
- async getFromSpecificBridge(e) {
108
- return await a().get("quotes/single", { searchParams: e }).json();
111
+ class d {
112
+ async getFromSpecificBridge(t) {
113
+ return await s().get("quotes/single", { searchParams: t }).json();
109
114
  }
110
- async getFromAllBridges(e) {
111
- return await a().get("quotes/multiple", { searchParams: e }).json();
115
+ async getFromAllBridges(t) {
116
+ return await s().get("quotes/multiple", { searchParams: t }).json();
112
117
  }
113
- async getBestAcrossBridges(e) {
114
- return await a().get("quotes/best", { searchParams: e }).json();
118
+ async getBestAcrossBridges(t) {
119
+ return await s().get("quotes/best", { searchParams: t }).json();
115
120
  }
116
- async getAll(e) {
117
- return await a().get("quotes/multi-source", { searchParams: e }).json();
121
+ async getAll(t) {
122
+ return await s().get("quotes/multi-source", { searchParams: t }).json();
118
123
  }
119
124
  }
120
- class T {
121
- async getOptimalRoutes(e) {
122
- return await a().get("router/optimal-route", { searchParams: e }).json();
125
+ class y {
126
+ async getOptimalRoutes(t) {
127
+ return await s().get("router/optimal-route", { searchParams: t }).json();
123
128
  }
124
129
  async getAllSupportedBridges() {
125
- return await a().get("router/supported-bridges/all").json();
130
+ return await s().get("router/supported-bridges/all").json();
126
131
  }
127
- async getSupportedBridges(e) {
128
- return await a().get("router/supported-bridges/route", { searchParams: e }).json();
132
+ async getSupportedBridges(t) {
133
+ return await s().get("router/supported-bridges/route", { searchParams: t }).json();
129
134
  }
130
- async getSupportedRoutes(e, n) {
131
- return await a().get("router/supported-bridges/bridge/" + e, { searchParams: n }).json();
135
+ async getSupportedRoutes(t, r) {
136
+ return await s().get("router/supported-bridges/bridge/" + t, { searchParams: r }).json();
132
137
  }
133
138
  }
134
- class h {
135
- async getSupported(e) {
136
- return await a().get("chains", { searchParams: e }).json();
139
+ class w {
140
+ async getSupported(t) {
141
+ return await s().get("chains", { searchParams: t }).json();
137
142
  }
138
143
  }
139
- class E {
144
+ class A {
140
145
  async getClientInfo() {
141
- return await a().get("client/auth/client-info").json();
146
+ return await s().get("client/auth/client-info").json();
142
147
  }
143
148
  }
144
- const y = {
145
- router: new T(),
146
- quotes: new u(),
147
- intents: new g(),
148
- chains: new h(),
149
- client: new E()
149
+ const S = {
150
+ router: new y(),
151
+ quotes: new d(),
152
+ intents: new T(),
153
+ chains: new w(),
154
+ client: new A()
150
155
  };
151
156
  export {
152
- s as Chainrails,
153
- c as chains,
154
- y as crapi,
157
+ a as Chainrails,
158
+ g as chains,
159
+ S as crapi,
155
160
  i as environment,
156
- p as tokens
161
+ h as tokens
157
162
  };
@@ -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 fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",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(e){console.log(e)}}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 console.log("jwttt"),this.updateJWT(),console.log("jwttt2"),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"})}));
1
+ (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("ky")):typeof define=="function"&&define.amd?define(["exports","ky"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.Chainrails={},s.Ky))})(this,(function(s,r){"use strict";var c=(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))(c||{}),u=(t=>(t.USDC="USDC",t))(u||{}),o=(t=>(t.PRODUCTION="production",t.STAGING="staging",t))(o||{});class n{constructor({api_key:e,env:i}){this.api_key=e,this.jwt="",this.env=i??o.PRODUCTION}static 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),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",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,f,w){if(!n.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const A=n.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/":"https://app.chainrails.io/pay/",S=`${e}/_token_/${i}/_to_/${f}/_amount_/${w*100}`;return A+S}}let p=null;function l(){p=r.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 p||l(),p}class g{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 h{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 d{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 T{async getSupported(e){return await a().get("chains",{searchParams:e}).json()}}class E{async getClientInfo(){return await a().get("client/auth/client-info").json()}}const y={router:new d,quotes:new h,intents:new g,chains:new T,client:new E};s.Chainrails=n,s.chains=c,s.crapi=y,s.environment=o,s.tokens=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
@@ -1 +1 @@
1
- {"version":3,"file":"req.d.ts","sourceRoot":"","sources":["../../src/req.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,cAAc,EAAE,OAAO,CAAC;KACzB;CACF;AAED,QAAA,IAAI,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,IAAW,CAAC;AAEpD,wBAAgB,UAAU,SAoBzB;AAED,wBAAgB,SAAS,4BAKxB;AAED,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"req.d.ts","sourceRoot":"","sources":["../../src/req.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,cAAc,EAAE,OAAO,CAAC;KACzB;CACF;AAED,QAAA,IAAI,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,IAAW,CAAC;AAEpD,wBAAgB,UAAU,SAmBzB;AAED,wBAAgB,SAAS,4BAKxB;AAED,eAAe,GAAG,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chainrails/sdk",
3
3
  "sideEffects": false,
4
- "version": "0.0.22",
4
+ "version": "0.0.23",
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.14",
38
+ "@chainrails/common": "^0.0.15",
39
39
  "ky": "^1.14.0"
40
40
  },
41
41
  "devDependencies": {