@imtbl/sdk 0.37.0 → 0.38.0

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.
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ class ImmutableConfiguration {
39
39
  }
40
40
  }
41
41
  const API_KEY_PREFIX = 'sk_imapik-';
42
- const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
42
+ const PUBLISHABLE_KEY_PREFIX$1 = 'pk_imapik-';
43
43
  const addApiKeyToAxiosHeader = (apiKey) => {
44
44
  if (!apiKey.startsWith(API_KEY_PREFIX)) {
45
45
  throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
@@ -47,7 +47,7 @@ const addApiKeyToAxiosHeader = (apiKey) => {
47
47
  globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
48
48
  };
49
49
  const addPublishableKeyToAxiosHeader = (publishableKey) => {
50
- if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
50
+ if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX$1)) {
51
51
  throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
52
52
  + ' https://hub.immutable.com');
53
53
  }
@@ -4234,7 +4234,7 @@ class MultiRollupApiClients {
4234
4234
  }
4235
4235
 
4236
4236
  // eslint-disable-next-line @typescript-eslint/naming-convention
4237
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.37.0' };
4237
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.38.0' };
4238
4238
  const createConfig = ({ basePath, headers, }) => {
4239
4239
  if (!basePath.trim()) {
4240
4240
  throw Error('basePath can not be empty');
@@ -4294,7 +4294,7 @@ class APIError extends Error {
4294
4294
 
4295
4295
  /* eslint-disable implicit-arrow-linebreak */
4296
4296
  const defaultHeaders = {
4297
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.37.0',
4297
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.38.0',
4298
4298
  };
4299
4299
  /**
4300
4300
  * createAPIConfiguration to create a custom Configuration
@@ -4733,7 +4733,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4733
4733
  chainID,
4734
4734
  coreContractAddress,
4735
4735
  registrationContractAddress,
4736
- sdkVersion: 'ts-immutable-sdk-0.37.0',
4736
+ sdkVersion: 'ts-immutable-sdk-0.38.0',
4737
4737
  });
4738
4738
  /**
4739
4739
  * Sets `sdkVersion` at the time of build
@@ -34780,6 +34780,7 @@ var ConnectEventType;
34780
34780
  ConnectEventType["CLOSE_WIDGET"] = "close-widget";
34781
34781
  ConnectEventType["SUCCESS"] = "success";
34782
34782
  ConnectEventType["FAILURE"] = "failure";
34783
+ ConnectEventType["LANGUAGE_CHANGED"] = "language-changed";
34783
34784
  })(ConnectEventType || (ConnectEventType = {}));
34784
34785
 
34785
34786
  /**
@@ -34790,6 +34791,7 @@ var WalletEventType;
34790
34791
  WalletEventType["CLOSE_WIDGET"] = "close-widget";
34791
34792
  WalletEventType["NETWORK_SWITCH"] = "network-switch";
34792
34793
  WalletEventType["DISCONNECT_WALLET"] = "disconnect-wallet";
34794
+ WalletEventType["LANGUAGE_CHANGED"] = "language-changed";
34793
34795
  })(WalletEventType || (WalletEventType = {}));
34794
34796
 
34795
34797
  /**
@@ -34801,6 +34803,7 @@ var SwapEventType;
34801
34803
  SwapEventType["SUCCESS"] = "success";
34802
34804
  SwapEventType["FAILURE"] = "failure";
34803
34805
  SwapEventType["REJECTED"] = "rejected";
34806
+ SwapEventType["LANGUAGE_CHANGED"] = "language-changed";
34804
34807
  })(SwapEventType || (SwapEventType = {}));
34805
34808
 
34806
34809
  /**
@@ -34813,6 +34816,7 @@ var SaleEventType;
34813
34816
  SaleEventType["FAILURE"] = "failure";
34814
34817
  SaleEventType["REJECTED"] = "rejected";
34815
34818
  SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
34819
+ SaleEventType["LANGUAGE_CHANGED"] = "language-changed";
34816
34820
  })(SaleEventType || (SaleEventType = {}));
34817
34821
 
34818
34822
  /**
@@ -34823,6 +34827,7 @@ var BridgeEventType;
34823
34827
  BridgeEventType["CLOSE_WIDGET"] = "close-widget";
34824
34828
  BridgeEventType["FAILURE"] = "failure";
34825
34829
  BridgeEventType["TRANSACTION_SENT"] = "transaction-sent";
34830
+ BridgeEventType["LANGUAGE_CHANGED"] = "language-changed";
34826
34831
  })(BridgeEventType || (BridgeEventType = {}));
34827
34832
 
34828
34833
  /**
@@ -34845,6 +34850,7 @@ var OnRampEventType;
34845
34850
  OnRampEventType["CLOSE_WIDGET"] = "close-widget";
34846
34851
  OnRampEventType["SUCCESS"] = "success";
34847
34852
  OnRampEventType["FAILURE"] = "failure";
34853
+ OnRampEventType["LANGUAGE_CHANGED"] = "language-changed";
34848
34854
  })(OnRampEventType || (OnRampEventType = {}));
34849
34855
 
34850
34856
  /**
@@ -35673,32 +35679,21 @@ const GAS_OVERRIDES = {
35673
35679
  maxPriorityFeePerGas: BigNumber$1.from(101e9),
35674
35680
  };
35675
35681
 
35676
- const SDK_VERSION_MARKER = '0.37.0';
35682
+ const SDK_VERSION_MARKER = '0.38.0';
35677
35683
  // This SDK version is replaced by the `yarn build` command ran on the root level
35678
35684
  const globalPackageVersion = () => SDK_VERSION_MARKER;
35679
35685
 
35680
35686
  class RemoteConfigFetcher {
35687
+ httpClient;
35681
35688
  isDevelopment;
35682
35689
  isProduction;
35683
35690
  configCache;
35684
35691
  tokensCache;
35685
35692
  version = 'v1';
35686
- constructor(params) {
35693
+ constructor(httpClient, params) {
35687
35694
  this.isDevelopment = params.isDevelopment;
35688
35695
  this.isProduction = params.isProduction;
35689
- }
35690
- static async makeHttpRequest(url) {
35691
- let response;
35692
- try {
35693
- response = await globalAxios$1.get(url);
35694
- }
35695
- catch (error) {
35696
- throw new CheckoutError(`Error fetching from api: ${error.message}`, CheckoutErrorType.API_ERROR);
35697
- }
35698
- if (response.status !== 200) {
35699
- throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
35700
- }
35701
- return response;
35696
+ this.httpClient = httpClient;
35702
35697
  }
35703
35698
  getEndpoint = () => {
35704
35699
  if (this.isDevelopment)
@@ -35710,14 +35705,14 @@ class RemoteConfigFetcher {
35710
35705
  async loadConfig() {
35711
35706
  if (this.configCache)
35712
35707
  return this.configCache;
35713
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config`);
35708
+ const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
35714
35709
  this.configCache = response.data;
35715
35710
  return this.configCache;
35716
35711
  }
35717
35712
  async loadConfigTokens() {
35718
35713
  if (this.tokensCache)
35719
35714
  return this.tokensCache;
35720
- const response = await RemoteConfigFetcher.makeHttpRequest(`${this.getEndpoint()}/${this.version}/config/tokens`);
35715
+ const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
35721
35716
  this.tokensCache = response.data;
35722
35717
  return this.tokensCache;
35723
35718
  }
@@ -35735,6 +35730,7 @@ class RemoteConfigFetcher {
35735
35730
  return {};
35736
35731
  return config[chainId] ?? [];
35737
35732
  }
35733
+ getHttpClient = () => this.httpClient;
35738
35734
  }
35739
35735
 
35740
35736
  class CheckoutConfigurationError extends Error {
@@ -35785,7 +35781,7 @@ class CheckoutConfiguration {
35785
35781
  remote;
35786
35782
  environment;
35787
35783
  networkMap;
35788
- constructor(config) {
35784
+ constructor(config, httpClient) {
35789
35785
  if (!Object.values(Environment$1).includes(config.baseConfig.environment)) {
35790
35786
  throw new CheckoutConfigurationError('Invalid checkout configuration of environment');
35791
35787
  }
@@ -35796,7 +35792,7 @@ class CheckoutConfiguration {
35796
35792
  this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED;
35797
35793
  this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED;
35798
35794
  this.networkMap = networkMap(this.isProduction, this.isDevelopment);
35799
- this.remote = new RemoteConfigFetcher({
35795
+ this.remote = new RemoteConfigFetcher(httpClient, {
35800
35796
  isDevelopment: this.isDevelopment,
35801
35797
  isProduction: this.isProduction,
35802
35798
  });
@@ -35861,9 +35857,7 @@ class Blockscout {
35861
35857
  ttl;
35862
35858
  chainId;
35863
35859
  cacheMap;
35864
- static async makeHttpRequest(url) {
35865
- return globalAxios$1.get(url);
35866
- }
35860
+ httpClient;
35867
35861
  setCache(key, data) {
35868
35862
  this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
35869
35863
  }
@@ -35875,11 +35869,13 @@ class Blockscout {
35875
35869
  }
35876
35870
  /**
35877
35871
  * Blockscout constructor
35872
+ * @param httpClient Client used for http requests
35878
35873
  * @param chainId target chain
35879
35874
  * @param ttl cache TTL
35880
35875
  */
35881
- constructor(params) {
35882
- this.chainId = params.chainId;
35876
+ constructor(httpClient, chainId, ttl) {
35877
+ this.httpClient = httpClient;
35878
+ this.chainId = chainId;
35883
35879
  this.url = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].url;
35884
35880
  const native = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].nativeToken;
35885
35881
  this.nativeToken = {
@@ -35889,7 +35885,7 @@ class Blockscout {
35889
35885
  symbol: native.symbol,
35890
35886
  };
35891
35887
  this.cacheMap = {};
35892
- this.ttl = params.ttl !== undefined ? params.ttl : CACHE_DATA_TTL;
35888
+ this.ttl = ttl !== undefined ? ttl : CACHE_DATA_TTL;
35893
35889
  }
35894
35890
  /**
35895
35891
  * isChainSupported verifies if the chain is supported by Blockscout
@@ -35917,7 +35913,7 @@ class Blockscout {
35917
35913
  const cached = this.getCache(url);
35918
35914
  if (cached)
35919
35915
  return Promise.resolve(cached);
35920
- const response = await Blockscout.makeHttpRequest(url);
35916
+ const response = await this.httpClient.get(url);
35921
35917
  if (response.status >= 400) {
35922
35918
  return Promise.reject({
35923
35919
  code: response.status,
@@ -35958,7 +35954,7 @@ class Blockscout {
35958
35954
  const cached = this.getCache(url);
35959
35955
  if (cached)
35960
35956
  return Promise.resolve(cached);
35961
- const response = await Blockscout.makeHttpRequest(url);
35957
+ const response = await this.httpClient.get(url);
35962
35958
  if (response.status >= 400) {
35963
35959
  return Promise.reject({
35964
35960
  code: response.status,
@@ -36043,7 +36039,7 @@ const blockscoutClientMap = new Map();
36043
36039
  // This function is a utility function that can be used to reset the
36044
36040
  // blockscout map and therefore clear all the cache.
36045
36041
  const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
36046
- const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
36042
+ const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) => {
36047
36043
  // Shuffle the mapping of the tokens configuration so it is a hashmap
36048
36044
  // for faster access to tokens config objects.
36049
36045
  const shouldFilter = filterTokens !== undefined;
@@ -36051,7 +36047,8 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
36051
36047
  // Get blockscout client for the given chain
36052
36048
  let blockscoutClient = blockscoutClientMap.get(chainId);
36053
36049
  if (!blockscoutClient) {
36054
- blockscoutClient = new Blockscout({ chainId });
36050
+ const httpClient = config.remote.getHttpClient();
36051
+ blockscoutClient = new Blockscout(httpClient, chainId);
36055
36052
  blockscoutClientMap.set(chainId, blockscoutClient);
36056
36053
  }
36057
36054
  // Hold the items in an array for post-fetching processing
@@ -36186,7 +36183,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
36186
36183
  const isL1Chain = getL1ChainId(config) === chainId;
36187
36184
  if (!address)
36188
36185
  address = await web3Provider?.getSigner().getAddress();
36189
- return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(address, chainId, isL1Chain ? tokens : undefined));
36186
+ return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(config, address, chainId, isL1Chain ? tokens : undefined));
36190
36187
  }
36191
36188
  if (!web3Provider) {
36192
36189
  throw new CheckoutError('indexer is disabled for this chain, you must provide a provider.', CheckoutErrorType.MISSING_PARAMS);
@@ -39179,6 +39176,90 @@ function loadUnresolved(version) {
39179
39176
  return { loaded: false, element: tag };
39180
39177
  }
39181
39178
 
39179
+ const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
39180
+ const publishableKeyDomainAllowlist = [
39181
+ 'https://checkout-api.dev.immutable.com',
39182
+ 'https://checkout-api.sandbox.immutable.com',
39183
+ 'https://checkout-api.immutable.com',
39184
+ ];
39185
+ class HttpClient {
39186
+ config;
39187
+ axiosInstance;
39188
+ constructor(config) {
39189
+ this.config = config;
39190
+ this.axiosInstance = globalAxios$1.create();
39191
+ this.setupInterceptors();
39192
+ }
39193
+ // eslint-disable-next-line class-methods-use-this
39194
+ shouldAddPublishableKey(url) {
39195
+ // Check if the request is going to a whitelisted domain
39196
+ return publishableKeyDomainAllowlist.some((domain) => url.startsWith(domain));
39197
+ }
39198
+ setupInterceptors() {
39199
+ this.axiosInstance.interceptors.request.use((config) => {
39200
+ const publishableKey = this.config?.baseConfig?.publishableKey;
39201
+ if (publishableKey && this.shouldAddPublishableKey(config.url || '')) {
39202
+ if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
39203
+ throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
39204
+ + ' https://hub.immutable.com');
39205
+ }
39206
+ // Add publishable key header for whitelisted domains
39207
+ // eslint-disable-next-line no-param-reassign
39208
+ config.headers['x-immutable-publishable-key'] = publishableKey;
39209
+ }
39210
+ return config;
39211
+ }, (error) => Promise.reject(error));
39212
+ }
39213
+ // eslint-disable-next-line class-methods-use-this
39214
+ processResponse(response) {
39215
+ if (response && response?.status !== 200) {
39216
+ throw new CheckoutError(`Error: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
39217
+ }
39218
+ }
39219
+ async request(config) {
39220
+ let response;
39221
+ try {
39222
+ response = await this.axiosInstance.request(config);
39223
+ }
39224
+ catch (error) {
39225
+ throw new CheckoutError(error.message, CheckoutErrorType.API_ERROR);
39226
+ }
39227
+ this.processResponse(response);
39228
+ return response;
39229
+ }
39230
+ async get(url, config) {
39231
+ const requestConfig = {
39232
+ ...config,
39233
+ url,
39234
+ };
39235
+ return await this.request(requestConfig);
39236
+ }
39237
+ async post(url, data, config) {
39238
+ const requestConfig = {
39239
+ ...config,
39240
+ data,
39241
+ url,
39242
+ };
39243
+ return await this.request(requestConfig);
39244
+ }
39245
+ async put(url, data, config) {
39246
+ const requestConfig = {
39247
+ ...config,
39248
+ data,
39249
+ url,
39250
+ };
39251
+ return await this.request(requestConfig);
39252
+ }
39253
+ async delete(url, data, config) {
39254
+ const requestConfig = {
39255
+ ...config,
39256
+ data,
39257
+ url,
39258
+ };
39259
+ return await this.request(requestConfig);
39260
+ }
39261
+ }
39262
+
39182
39263
  const SANDBOX_CONFIGURATION = {
39183
39264
  baseConfig: {
39184
39265
  environment: Environment$1.SANDBOX,
@@ -39189,6 +39270,7 @@ const WIDGETS_SCRIPT_TIMEOUT = 100;
39189
39270
  // Checkout SDK
39190
39271
  class Checkout {
39191
39272
  readOnlyProviders;
39273
+ httpClient;
39192
39274
  config;
39193
39275
  fiatRampService;
39194
39276
  availability;
@@ -39198,7 +39280,8 @@ class Checkout {
39198
39280
  * @param {CheckoutModuleConfiguration} [config=SANDBOX_CONFIGURATION] - The configuration object for the CheckoutModule.
39199
39281
  */
39200
39282
  constructor(config = SANDBOX_CONFIGURATION) {
39201
- this.config = new CheckoutConfiguration(config);
39283
+ this.httpClient = new HttpClient(config);
39284
+ this.config = new CheckoutConfiguration(config, this.httpClient);
39202
39285
  this.fiatRampService = new FiatRampService(this.config);
39203
39286
  this.readOnlyProviders = new Map();
39204
39287
  this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
package/dist/passport.js CHANGED
@@ -2349,7 +2349,7 @@ class MultiRollupApiClients {
2349
2349
  }
2350
2350
 
2351
2351
  // eslint-disable-next-line @typescript-eslint/naming-convention
2352
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.37.0' };
2352
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.38.0' };
2353
2353
  const createConfig = ({ basePath, headers, }) => {
2354
2354
  if (!basePath.trim()) {
2355
2355
  throw Error('basePath can not be empty');
@@ -2405,7 +2405,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2405
2405
  chainID,
2406
2406
  coreContractAddress,
2407
2407
  registrationContractAddress,
2408
- sdkVersion: 'ts-immutable-sdk-0.37.0',
2408
+ sdkVersion: 'ts-immutable-sdk-0.38.0',
2409
2409
  });
2410
2410
  /**
2411
2411
  * Sets `sdkVersion` at the time of build
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.37.0",
4
+ "version": "0.38.0",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -31,11 +31,14 @@
31
31
  "enc-utils": "^3.0.0",
32
32
  "ethers": "^5.7.2",
33
33
  "https-browserify": "^1.0.0",
34
+ "i18next": "^23.7.6",
35
+ "i18next-browser-languagedetector": "^7.2.0",
34
36
  "jwt-decode": "^3.1.2",
35
37
  "magic-sdk": "^21.2.0",
36
38
  "oidc-client-ts": "^2.2.1",
37
39
  "os-browserify": "^0.3.0",
38
40
  "pako": "^2.1.0",
41
+ "react-i18next": "^13.5.0",
39
42
  "stream-browserify": "^3.0.0",
40
43
  "stream-http": "^3.2.0",
41
44
  "url": "^0.11.0"