@chainrails/common 0.0.8 → 0.0.10

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,48 +1,56 @@
1
- var A = /* @__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))(A || {}), N = /* @__PURE__ */ ((E) => (E.USDC = "USDC", E))(N || {}), T = /* @__PURE__ */ ((E) => (E.PRODUCTION = "production", E.STAGING = "staging", E))(T || {});
1
+ var a = /* @__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))(a || {}), i = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(i || {}), T = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(T || {});
2
2
  class e {
3
- constructor({ api_key: t, env: r }) {
4
- this.api_key = t, this.env = r ?? T.PRODUCTION;
3
+ constructor({ api_key: E, env: r }) {
4
+ this.api_key = E, this.jwt = "", this.env = r ?? T.PRODUCTION;
5
5
  }
6
- static config(t) {
6
+ static config(E) {
7
7
  if (!e.app) {
8
- if (!t)
8
+ if (!E)
9
9
  throw new Error("Please provide an api_key");
10
- e.app = new e(t);
10
+ e.app = new e(E);
11
+ }
12
+ return E && (e.app.api_key = E.api_key, E.env !== void 0 && (e.app.env = E.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
13
+ }
14
+ static async updateJWT() {
15
+ try {
16
+ const r = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ body: JSON.stringify({
18
+ apiKey: e.app.api_key
19
+ })
20
+ })).json();
21
+ this.app.jwt = r.token;
22
+ } catch {
11
23
  }
12
- return t && (e.app.api_key = t.api_key, t.env !== void 0 && (e.app.env = t.env)), e.app;
13
24
  }
14
25
  static getApiKey() {
15
26
  if (!e.app)
16
- throw new Error(
17
- "Chainrails SDK not configured. Please call Chainrails.config() first."
18
- );
27
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
19
28
  return e.app.api_key;
20
29
  }
30
+ static getSessionKey() {
31
+ return e.app.jwt;
32
+ }
21
33
  static getEnv() {
22
34
  if (!e.app)
23
- throw new Error(
24
- "Chainrails SDK not configured. Please call Chainrails.config() first."
25
- );
35
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
26
36
  return e.app.env;
27
37
  }
28
38
  static getBaseUrl() {
29
39
  if (!e.app)
30
- throw new Error(
31
- "Chainrails SDK not configured. Please call Chainrails.config() first."
32
- );
40
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
33
41
  switch (e.app.env) {
34
42
  case "production":
35
- return "https://dev.chainrails.io/api/v1";
43
+ return "https://api.chainrails.io/api/v1";
36
44
  case "staging":
37
45
  return "https://dev.chainrails.io/api/v1";
38
46
  default:
39
- return "https://dev.chainrails.io/api/v1";
47
+ return "https://api.chainrails.io/api/v1";
40
48
  }
41
49
  }
42
50
  }
43
51
  export {
44
52
  e as Chainrails,
45
- A as chains,
53
+ a as chains,
46
54
  T as environment,
47
- N as tokens
55
+ i as tokens
48
56
  };
@@ -1,48 +1,56 @@
1
- var A = /* @__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))(A || {}), N = /* @__PURE__ */ ((E) => (E.USDC = "USDC", E))(N || {}), T = /* @__PURE__ */ ((E) => (E.PRODUCTION = "production", E.STAGING = "staging", E))(T || {});
1
+ var a = /* @__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))(a || {}), i = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(i || {}), T = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(T || {});
2
2
  class e {
3
- constructor({ api_key: t, env: r }) {
4
- this.api_key = t, this.env = r ?? T.PRODUCTION;
3
+ constructor({ api_key: E, env: r }) {
4
+ this.api_key = E, this.jwt = "", this.env = r ?? T.PRODUCTION;
5
5
  }
6
- static config(t) {
6
+ static config(E) {
7
7
  if (!e.app) {
8
- if (!t)
8
+ if (!E)
9
9
  throw new Error("Please provide an api_key");
10
- e.app = new e(t);
10
+ e.app = new e(E);
11
+ }
12
+ return E && (e.app.api_key = E.api_key, E.env !== void 0 && (e.app.env = E.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
13
+ }
14
+ static async updateJWT() {
15
+ try {
16
+ const r = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
17
+ body: JSON.stringify({
18
+ apiKey: e.app.api_key
19
+ })
20
+ })).json();
21
+ this.app.jwt = r.token;
22
+ } catch {
11
23
  }
12
- return t && (e.app.api_key = t.api_key, t.env !== void 0 && (e.app.env = t.env)), e.app;
13
24
  }
14
25
  static getApiKey() {
15
26
  if (!e.app)
16
- throw new Error(
17
- "Chainrails SDK not configured. Please call Chainrails.config() first."
18
- );
27
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
19
28
  return e.app.api_key;
20
29
  }
30
+ static getSessionKey() {
31
+ return e.app.jwt;
32
+ }
21
33
  static getEnv() {
22
34
  if (!e.app)
23
- throw new Error(
24
- "Chainrails SDK not configured. Please call Chainrails.config() first."
25
- );
35
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
26
36
  return e.app.env;
27
37
  }
28
38
  static getBaseUrl() {
29
39
  if (!e.app)
30
- throw new Error(
31
- "Chainrails SDK not configured. Please call Chainrails.config() first."
32
- );
40
+ throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
33
41
  switch (e.app.env) {
34
42
  case "production":
35
- return "https://dev.chainrails.io/api/v1";
43
+ return "https://api.chainrails.io/api/v1";
36
44
  case "staging":
37
45
  return "https://dev.chainrails.io/api/v1";
38
46
  default:
39
- return "https://dev.chainrails.io/api/v1";
47
+ return "https://api.chainrails.io/api/v1";
40
48
  }
41
49
  }
42
50
  }
43
51
  export {
44
52
  e as Chainrails,
45
- A as chains,
53
+ a as chains,
46
54
  T as environment,
47
- N as tokens
55
+ i as tokens
48
56
  };
@@ -1 +1 @@
1
- (function(E,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(E=typeof globalThis<"u"?globalThis:E||self,T(E.Chainrails={}))})(this,(function(E){"use strict";var T=(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))(T||{}),r=(e=>(e.USDC="USDC",e))(r||{}),n=(e=>(e.PRODUCTION="production",e.STAGING="staging",e))(n||{});class t{constructor({api_key:i,env:o}){this.api_key=i,this.env=o??n.PRODUCTION}static config(i){if(!t.app){if(!i)throw new Error("Please provide an api_key");t.app=new t(i)}return i&&(t.app.api_key=i.api_key,i.env!==void 0&&(t.app.env=i.env)),t.app}static getApiKey(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return t.app.api_key}static getEnv(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return t.app.env}static getBaseUrl(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(t.app.env){case"production":return"https://dev.chainrails.io/api/v1";case"staging":return"https://dev.chainrails.io/api/v1";default:return"https://dev.chainrails.io/api/v1"}}}E.Chainrails=t,E.chains=T,E.environment=n,E.tokens=r,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.Chainrails={}))})(this,(function(i){"use strict";var a=(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))(a||{}),E=(e=>(e.USDC="USDC",e))(E||{}),r=(e=>(e.PRODUCTION="production",e.STAGING="staging",e))(r||{});class t{constructor({api_key:n,env:T}){this.api_key=n,this.jwt="",this.env=T??r.PRODUCTION}static config(n){if(!t.app){if(!n)throw new Error("Please provide an api_key");t.app=new t(n)}return n&&(t.app.api_key=n.api_key,n.env!==void 0&&(t.app.env=n.env),this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),t.app}static async updateJWT(){try{const T=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{body:JSON.stringify({apiKey:t.app.api_key})})).json();this.app.jwt=T.token}catch{}}static getApiKey(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return t.app.api_key}static getSessionKey(){return t.app.jwt}static getEnv(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");return t.app.env}static getBaseUrl(){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");switch(t.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"}}}i.Chainrails=t,i.chains=a,i.environment=r,i.tokens=E,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
@@ -7,9 +7,12 @@ export declare class Chainrails {
7
7
  private static app;
8
8
  api_key: string;
9
9
  env: EnvType;
10
+ jwt: string;
10
11
  private constructor();
11
12
  static config(props?: ChainrailsConfig): Chainrails;
13
+ static updateJWT(): Promise<void>;
12
14
  static getApiKey(): string;
15
+ static getSessionKey(): string;
13
16
  static getEnv(): EnvType;
14
17
  static getBaseUrl(): string;
15
18
  }
@@ -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;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAa;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IAEb,OAAO;WAKO,MAAM,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,UAAU;WAiB5C,SAAS,IAAI,MAAM;WASnB,MAAM,IAAI,OAAO;WASjB,UAAU,IAAI,MAAM;CAenC"}
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;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAa;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IAEZ,OAAO;WAMO,MAAM,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,UAAU;WAmBtC,SAAS;WAYf,SAAS,IAAI,MAAM;WAMnB,aAAa,IAAI,MAAM;WAIvB,MAAM,IAAI,OAAO;WAOjB,UAAU,IAAI,MAAM;CAanC"}
@@ -1,4 +1,4 @@
1
- export type EnvType = "internal" | "production" | "staging";
1
+ export type EnvType = "production" | "staging";
2
2
  export declare enum environment {
3
3
  PRODUCTION = "production",
4
4
  STAGING = "staging"
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/environment/index.tsx"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;AAE5D,oBAAY,WAAW;IACrB,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/environment/index.tsx"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;AAE/C,oBAAY,WAAW;IACrB,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chainrails/common",
3
3
  "sideEffects": false,
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "main": "./dist/chainrails-common.umd.js",
6
6
  "module": "./dist/chainrails-common.es.mjs",
7
7
  "license": "MIT",