@chainrails/common 0.0.17 → 0.0.18

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.
@@ -3,13 +3,13 @@ class e {
3
3
  constructor({ api_key: a, env: r }) {
4
4
  this.api_key = a, this.jwt = "", this.env = r ?? i.PRODUCTION;
5
5
  }
6
- static config(a) {
6
+ static async config(a) {
7
7
  if (!e.app) {
8
8
  if (!a)
9
9
  throw new Error("Please provide an api_key");
10
10
  e.app = new e(a);
11
11
  }
12
- return a && (e.app.api_key = a.api_key, a.env !== void 0 && (e.app.env = a.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
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
13
  }
14
14
  static async updateJWT() {
15
15
  try {
@@ -3,13 +3,13 @@ class e {
3
3
  constructor({ api_key: a, env: r }) {
4
4
  this.api_key = a, this.jwt = "", this.env = r ?? i.PRODUCTION;
5
5
  }
6
- static config(a) {
6
+ static async config(a) {
7
7
  if (!e.app) {
8
8
  if (!a)
9
9
  throw new Error("Please provide an api_key");
10
10
  e.app = new e(a);
11
11
  }
12
- return a && (e.app.api_key = a.api_key, a.env !== void 0 && (e.app.env = a.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), e.app;
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
13
  }
14
14
  static async updateJWT() {
15
15
  try {
@@ -1 +1 @@
1
- (function(n,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(n=typeof globalThis<"u"?globalThis:n||self,a(n.Chainrails={}))})(this,(function(n){"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||{}),o=(e=>(e.USDC="USDC",e))(o||{}),p=(e=>(e.PRODUCTION="production",e.STAGING="staging",e))(p||{});class t{constructor({api_key:i,env:r}){this.api_key=i,this.jwt="",this.env=r??p.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),this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),t.app}static async updateJWT(){try{const r=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({apiKey:t.app.api_key})})).json();this.app.jwt=r.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==="internal"?"staging":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";case"internal":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}static getPayModalUrl(i,r,s,T){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const E=t.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/":"https://app.chainrails.io/pay/",c=`_chain_/${i}/_token_/${r}/_to_/${s}/_amount_/${T*100}`;return E+c}}n.Chainrails=t,n.chains=a,n.environment=p,n.tokens=o,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.Chainrails={}))})(this,(function(i){"use strict";var n=(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))(n||{}),o=(e=>(e.USDC="USDC",e))(o||{}),p=(e=>(e.PRODUCTION="production",e.STAGING="staging",e))(p||{});class t{constructor({api_key:a,env:r}){this.api_key=a,this.jwt="",this.env=r??p.PRODUCTION}static async config(a){if(!t.app){if(!a)throw new Error("Please provide an api_key");t.app=new t(a)}return a&&(t.app.api_key=a.api_key,a.env!==void 0&&(t.app.env=a.env),await this.updateJWT(),setInterval(this.updateJWT.bind(this),1500*1e3)),t.app}static async updateJWT(){try{const r=await(await fetch(this.getBaseUrl()+"/client/api-keys/session-token",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({apiKey:t.app.api_key})})).json();this.app.jwt=r.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==="internal"?"staging":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";case"internal":return"https://dev.chainrails.io/api/v1";default:return"https://api.chainrails.io/api/v1"}}static getPayModalUrl(a,r,s,T){if(!t.app)throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");const E=t.app.env==="internal"?"https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/":"https://app.chainrails.io/pay/",c=`_chain_/${a}/_token_/${r}/_to_/${s}/_amount_/${T*100}`;return E+c}}i.Chainrails=t,i.chains=n,i.environment=p,i.tokens=o,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
@@ -9,7 +9,7 @@ export declare class Chainrails {
9
9
  env: EnvType;
10
10
  jwt: string;
11
11
  private constructor();
12
- static config(props?: ChainrailsConfig): Chainrails;
12
+ static config(props?: ChainrailsConfig): Promise<Chainrails>;
13
13
  static updateJWT(): Promise<void>;
14
14
  static getApiKey(): string;
15
15
  static getSessionKey(): 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;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;WAkBtC,SAAS;WAgBf,SAAS,IAAI,MAAM;WAOnB,aAAa,IAAI,MAAM;WAIvB,MAAM,IAAI,OAAO;WAQjB,UAAU,IAAI,MAAM;WAgBpB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAa/F"}
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;WAMa,MAAM,CAAC,KAAK,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;WAkBrD,SAAS;WAgBf,SAAS,IAAI,MAAM;WAOnB,aAAa,IAAI,MAAM;WAIvB,MAAM,IAAI,OAAO;WAQjB,UAAU,IAAI,MAAM;WAgBpB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAa/F"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chainrails/common",
3
3
  "sideEffects": false,
4
- "version": "0.0.17",
4
+ "version": "0.0.18",
5
5
  "main": "./dist/chainrails-common.umd.js",
6
6
  "module": "./dist/chainrails-common.es.mjs",
7
7
  "license": "MIT",