@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/blockchain_data.js +1 -1
- package/dist/browser/checkout/sdk.js +3 -3
- package/dist/browser/checkout/widgets.js +58 -58
- package/dist/checkout.d.ts +596 -173
- package/dist/checkout.js +115 -32
- package/dist/immutablex_client.js +1 -1
- package/dist/index.browser.js +12 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +119 -36
- package/dist/index.d.ts +467 -40
- package/dist/index.js +119 -36
- package/dist/passport.js +2 -2
- package/package.json +4 -1
package/dist/checkout.js
CHANGED
|
@@ -26051,7 +26051,7 @@ class APIError extends Error {
|
|
|
26051
26051
|
|
|
26052
26052
|
/* eslint-disable implicit-arrow-linebreak */
|
|
26053
26053
|
const defaultHeaders = {
|
|
26054
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
26054
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.38.0',
|
|
26055
26055
|
};
|
|
26056
26056
|
/**
|
|
26057
26057
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -26497,6 +26497,7 @@ var ConnectEventType;
|
|
|
26497
26497
|
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26498
26498
|
ConnectEventType["SUCCESS"] = "success";
|
|
26499
26499
|
ConnectEventType["FAILURE"] = "failure";
|
|
26500
|
+
ConnectEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26500
26501
|
})(ConnectEventType || (ConnectEventType = {}));
|
|
26501
26502
|
|
|
26502
26503
|
/**
|
|
@@ -26507,6 +26508,7 @@ var WalletEventType;
|
|
|
26507
26508
|
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26508
26509
|
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
26509
26510
|
WalletEventType["DISCONNECT_WALLET"] = "disconnect-wallet";
|
|
26511
|
+
WalletEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26510
26512
|
})(WalletEventType || (WalletEventType = {}));
|
|
26511
26513
|
|
|
26512
26514
|
/**
|
|
@@ -26518,6 +26520,7 @@ var SwapEventType;
|
|
|
26518
26520
|
SwapEventType["SUCCESS"] = "success";
|
|
26519
26521
|
SwapEventType["FAILURE"] = "failure";
|
|
26520
26522
|
SwapEventType["REJECTED"] = "rejected";
|
|
26523
|
+
SwapEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26521
26524
|
})(SwapEventType || (SwapEventType = {}));
|
|
26522
26525
|
|
|
26523
26526
|
/**
|
|
@@ -26530,6 +26533,7 @@ var SaleEventType;
|
|
|
26530
26533
|
SaleEventType["FAILURE"] = "failure";
|
|
26531
26534
|
SaleEventType["REJECTED"] = "rejected";
|
|
26532
26535
|
SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
|
|
26536
|
+
SaleEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26533
26537
|
})(SaleEventType || (SaleEventType = {}));
|
|
26534
26538
|
|
|
26535
26539
|
/**
|
|
@@ -26540,6 +26544,7 @@ var BridgeEventType;
|
|
|
26540
26544
|
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26541
26545
|
BridgeEventType["FAILURE"] = "failure";
|
|
26542
26546
|
BridgeEventType["TRANSACTION_SENT"] = "transaction-sent";
|
|
26547
|
+
BridgeEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26543
26548
|
})(BridgeEventType || (BridgeEventType = {}));
|
|
26544
26549
|
|
|
26545
26550
|
/**
|
|
@@ -26562,6 +26567,7 @@ var OnRampEventType;
|
|
|
26562
26567
|
OnRampEventType["CLOSE_WIDGET"] = "close-widget";
|
|
26563
26568
|
OnRampEventType["SUCCESS"] = "success";
|
|
26564
26569
|
OnRampEventType["FAILURE"] = "failure";
|
|
26570
|
+
OnRampEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
26565
26571
|
})(OnRampEventType || (OnRampEventType = {}));
|
|
26566
26572
|
|
|
26567
26573
|
/**
|
|
@@ -27390,32 +27396,21 @@ const GAS_OVERRIDES = {
|
|
|
27390
27396
|
maxPriorityFeePerGas: BigNumber$1.from(101e9),
|
|
27391
27397
|
};
|
|
27392
27398
|
|
|
27393
|
-
const SDK_VERSION_MARKER = '0.
|
|
27399
|
+
const SDK_VERSION_MARKER = '0.38.0';
|
|
27394
27400
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
27395
27401
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
27396
27402
|
|
|
27397
27403
|
class RemoteConfigFetcher {
|
|
27404
|
+
httpClient;
|
|
27398
27405
|
isDevelopment;
|
|
27399
27406
|
isProduction;
|
|
27400
27407
|
configCache;
|
|
27401
27408
|
tokensCache;
|
|
27402
27409
|
version = 'v1';
|
|
27403
|
-
constructor(params) {
|
|
27410
|
+
constructor(httpClient, params) {
|
|
27404
27411
|
this.isDevelopment = params.isDevelopment;
|
|
27405
27412
|
this.isProduction = params.isProduction;
|
|
27406
|
-
|
|
27407
|
-
static async makeHttpRequest(url) {
|
|
27408
|
-
let response;
|
|
27409
|
-
try {
|
|
27410
|
-
response = await globalAxios.get(url);
|
|
27411
|
-
}
|
|
27412
|
-
catch (error) {
|
|
27413
|
-
throw new CheckoutError(`Error fetching from api: ${error.message}`, CheckoutErrorType.API_ERROR);
|
|
27414
|
-
}
|
|
27415
|
-
if (response.status !== 200) {
|
|
27416
|
-
throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
27417
|
-
}
|
|
27418
|
-
return response;
|
|
27413
|
+
this.httpClient = httpClient;
|
|
27419
27414
|
}
|
|
27420
27415
|
getEndpoint = () => {
|
|
27421
27416
|
if (this.isDevelopment)
|
|
@@ -27427,14 +27422,14 @@ class RemoteConfigFetcher {
|
|
|
27427
27422
|
async loadConfig() {
|
|
27428
27423
|
if (this.configCache)
|
|
27429
27424
|
return this.configCache;
|
|
27430
|
-
const response = await
|
|
27425
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
|
|
27431
27426
|
this.configCache = response.data;
|
|
27432
27427
|
return this.configCache;
|
|
27433
27428
|
}
|
|
27434
27429
|
async loadConfigTokens() {
|
|
27435
27430
|
if (this.tokensCache)
|
|
27436
27431
|
return this.tokensCache;
|
|
27437
|
-
const response = await
|
|
27432
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
|
|
27438
27433
|
this.tokensCache = response.data;
|
|
27439
27434
|
return this.tokensCache;
|
|
27440
27435
|
}
|
|
@@ -27452,6 +27447,7 @@ class RemoteConfigFetcher {
|
|
|
27452
27447
|
return {};
|
|
27453
27448
|
return config[chainId] ?? [];
|
|
27454
27449
|
}
|
|
27450
|
+
getHttpClient = () => this.httpClient;
|
|
27455
27451
|
}
|
|
27456
27452
|
|
|
27457
27453
|
class CheckoutConfigurationError extends Error {
|
|
@@ -27502,7 +27498,7 @@ class CheckoutConfiguration {
|
|
|
27502
27498
|
remote;
|
|
27503
27499
|
environment;
|
|
27504
27500
|
networkMap;
|
|
27505
|
-
constructor(config) {
|
|
27501
|
+
constructor(config, httpClient) {
|
|
27506
27502
|
if (!Object.values(Environment$1).includes(config.baseConfig.environment)) {
|
|
27507
27503
|
throw new CheckoutConfigurationError('Invalid checkout configuration of environment');
|
|
27508
27504
|
}
|
|
@@ -27513,7 +27509,7 @@ class CheckoutConfiguration {
|
|
|
27513
27509
|
this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED;
|
|
27514
27510
|
this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED;
|
|
27515
27511
|
this.networkMap = networkMap(this.isProduction, this.isDevelopment);
|
|
27516
|
-
this.remote = new RemoteConfigFetcher({
|
|
27512
|
+
this.remote = new RemoteConfigFetcher(httpClient, {
|
|
27517
27513
|
isDevelopment: this.isDevelopment,
|
|
27518
27514
|
isProduction: this.isProduction,
|
|
27519
27515
|
});
|
|
@@ -27578,9 +27574,7 @@ class Blockscout {
|
|
|
27578
27574
|
ttl;
|
|
27579
27575
|
chainId;
|
|
27580
27576
|
cacheMap;
|
|
27581
|
-
|
|
27582
|
-
return globalAxios.get(url);
|
|
27583
|
-
}
|
|
27577
|
+
httpClient;
|
|
27584
27578
|
setCache(key, data) {
|
|
27585
27579
|
this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
|
|
27586
27580
|
}
|
|
@@ -27592,11 +27586,13 @@ class Blockscout {
|
|
|
27592
27586
|
}
|
|
27593
27587
|
/**
|
|
27594
27588
|
* Blockscout constructor
|
|
27589
|
+
* @param httpClient Client used for http requests
|
|
27595
27590
|
* @param chainId target chain
|
|
27596
27591
|
* @param ttl cache TTL
|
|
27597
27592
|
*/
|
|
27598
|
-
constructor(
|
|
27599
|
-
this.
|
|
27593
|
+
constructor(httpClient, chainId, ttl) {
|
|
27594
|
+
this.httpClient = httpClient;
|
|
27595
|
+
this.chainId = chainId;
|
|
27600
27596
|
this.url = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].url;
|
|
27601
27597
|
const native = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].nativeToken;
|
|
27602
27598
|
this.nativeToken = {
|
|
@@ -27606,7 +27602,7 @@ class Blockscout {
|
|
|
27606
27602
|
symbol: native.symbol,
|
|
27607
27603
|
};
|
|
27608
27604
|
this.cacheMap = {};
|
|
27609
|
-
this.ttl =
|
|
27605
|
+
this.ttl = ttl !== undefined ? ttl : CACHE_DATA_TTL;
|
|
27610
27606
|
}
|
|
27611
27607
|
/**
|
|
27612
27608
|
* isChainSupported verifies if the chain is supported by Blockscout
|
|
@@ -27634,7 +27630,7 @@ class Blockscout {
|
|
|
27634
27630
|
const cached = this.getCache(url);
|
|
27635
27631
|
if (cached)
|
|
27636
27632
|
return Promise.resolve(cached);
|
|
27637
|
-
const response = await
|
|
27633
|
+
const response = await this.httpClient.get(url);
|
|
27638
27634
|
if (response.status >= 400) {
|
|
27639
27635
|
return Promise.reject({
|
|
27640
27636
|
code: response.status,
|
|
@@ -27675,7 +27671,7 @@ class Blockscout {
|
|
|
27675
27671
|
const cached = this.getCache(url);
|
|
27676
27672
|
if (cached)
|
|
27677
27673
|
return Promise.resolve(cached);
|
|
27678
|
-
const response = await
|
|
27674
|
+
const response = await this.httpClient.get(url);
|
|
27679
27675
|
if (response.status >= 400) {
|
|
27680
27676
|
return Promise.reject({
|
|
27681
27677
|
code: response.status,
|
|
@@ -27760,7 +27756,7 @@ const blockscoutClientMap = new Map();
|
|
|
27760
27756
|
// This function is a utility function that can be used to reset the
|
|
27761
27757
|
// blockscout map and therefore clear all the cache.
|
|
27762
27758
|
const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
|
|
27763
|
-
const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
27759
|
+
const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) => {
|
|
27764
27760
|
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
27765
27761
|
// for faster access to tokens config objects.
|
|
27766
27762
|
const shouldFilter = filterTokens !== undefined;
|
|
@@ -27768,7 +27764,8 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
|
27768
27764
|
// Get blockscout client for the given chain
|
|
27769
27765
|
let blockscoutClient = blockscoutClientMap.get(chainId);
|
|
27770
27766
|
if (!blockscoutClient) {
|
|
27771
|
-
|
|
27767
|
+
const httpClient = config.remote.getHttpClient();
|
|
27768
|
+
blockscoutClient = new Blockscout(httpClient, chainId);
|
|
27772
27769
|
blockscoutClientMap.set(chainId, blockscoutClient);
|
|
27773
27770
|
}
|
|
27774
27771
|
// Hold the items in an array for post-fetching processing
|
|
@@ -27903,7 +27900,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
|
|
|
27903
27900
|
const isL1Chain = getL1ChainId(config) === chainId;
|
|
27904
27901
|
if (!address)
|
|
27905
27902
|
address = await web3Provider?.getSigner().getAddress();
|
|
27906
|
-
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(address, chainId, isL1Chain ? tokens : undefined));
|
|
27903
|
+
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(config, address, chainId, isL1Chain ? tokens : undefined));
|
|
27907
27904
|
}
|
|
27908
27905
|
if (!web3Provider) {
|
|
27909
27906
|
throw new CheckoutError('indexer is disabled for this chain, you must provide a provider.', CheckoutErrorType.MISSING_PARAMS);
|
|
@@ -30896,6 +30893,90 @@ function loadUnresolved(version) {
|
|
|
30896
30893
|
return { loaded: false, element: tag };
|
|
30897
30894
|
}
|
|
30898
30895
|
|
|
30896
|
+
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
30897
|
+
const publishableKeyDomainAllowlist = [
|
|
30898
|
+
'https://checkout-api.dev.immutable.com',
|
|
30899
|
+
'https://checkout-api.sandbox.immutable.com',
|
|
30900
|
+
'https://checkout-api.immutable.com',
|
|
30901
|
+
];
|
|
30902
|
+
class HttpClient {
|
|
30903
|
+
config;
|
|
30904
|
+
axiosInstance;
|
|
30905
|
+
constructor(config) {
|
|
30906
|
+
this.config = config;
|
|
30907
|
+
this.axiosInstance = globalAxios.create();
|
|
30908
|
+
this.setupInterceptors();
|
|
30909
|
+
}
|
|
30910
|
+
// eslint-disable-next-line class-methods-use-this
|
|
30911
|
+
shouldAddPublishableKey(url) {
|
|
30912
|
+
// Check if the request is going to a whitelisted domain
|
|
30913
|
+
return publishableKeyDomainAllowlist.some((domain) => url.startsWith(domain));
|
|
30914
|
+
}
|
|
30915
|
+
setupInterceptors() {
|
|
30916
|
+
this.axiosInstance.interceptors.request.use((config) => {
|
|
30917
|
+
const publishableKey = this.config?.baseConfig?.publishableKey;
|
|
30918
|
+
if (publishableKey && this.shouldAddPublishableKey(config.url || '')) {
|
|
30919
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
|
|
30920
|
+
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
30921
|
+
+ ' https://hub.immutable.com');
|
|
30922
|
+
}
|
|
30923
|
+
// Add publishable key header for whitelisted domains
|
|
30924
|
+
// eslint-disable-next-line no-param-reassign
|
|
30925
|
+
config.headers['x-immutable-publishable-key'] = publishableKey;
|
|
30926
|
+
}
|
|
30927
|
+
return config;
|
|
30928
|
+
}, (error) => Promise.reject(error));
|
|
30929
|
+
}
|
|
30930
|
+
// eslint-disable-next-line class-methods-use-this
|
|
30931
|
+
processResponse(response) {
|
|
30932
|
+
if (response && response?.status !== 200) {
|
|
30933
|
+
throw new CheckoutError(`Error: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
30934
|
+
}
|
|
30935
|
+
}
|
|
30936
|
+
async request(config) {
|
|
30937
|
+
let response;
|
|
30938
|
+
try {
|
|
30939
|
+
response = await this.axiosInstance.request(config);
|
|
30940
|
+
}
|
|
30941
|
+
catch (error) {
|
|
30942
|
+
throw new CheckoutError(error.message, CheckoutErrorType.API_ERROR);
|
|
30943
|
+
}
|
|
30944
|
+
this.processResponse(response);
|
|
30945
|
+
return response;
|
|
30946
|
+
}
|
|
30947
|
+
async get(url, config) {
|
|
30948
|
+
const requestConfig = {
|
|
30949
|
+
...config,
|
|
30950
|
+
url,
|
|
30951
|
+
};
|
|
30952
|
+
return await this.request(requestConfig);
|
|
30953
|
+
}
|
|
30954
|
+
async post(url, data, config) {
|
|
30955
|
+
const requestConfig = {
|
|
30956
|
+
...config,
|
|
30957
|
+
data,
|
|
30958
|
+
url,
|
|
30959
|
+
};
|
|
30960
|
+
return await this.request(requestConfig);
|
|
30961
|
+
}
|
|
30962
|
+
async put(url, data, config) {
|
|
30963
|
+
const requestConfig = {
|
|
30964
|
+
...config,
|
|
30965
|
+
data,
|
|
30966
|
+
url,
|
|
30967
|
+
};
|
|
30968
|
+
return await this.request(requestConfig);
|
|
30969
|
+
}
|
|
30970
|
+
async delete(url, data, config) {
|
|
30971
|
+
const requestConfig = {
|
|
30972
|
+
...config,
|
|
30973
|
+
data,
|
|
30974
|
+
url,
|
|
30975
|
+
};
|
|
30976
|
+
return await this.request(requestConfig);
|
|
30977
|
+
}
|
|
30978
|
+
}
|
|
30979
|
+
|
|
30899
30980
|
const SANDBOX_CONFIGURATION = {
|
|
30900
30981
|
baseConfig: {
|
|
30901
30982
|
environment: Environment$1.SANDBOX,
|
|
@@ -30906,6 +30987,7 @@ const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
|
30906
30987
|
// Checkout SDK
|
|
30907
30988
|
class Checkout {
|
|
30908
30989
|
readOnlyProviders;
|
|
30990
|
+
httpClient;
|
|
30909
30991
|
config;
|
|
30910
30992
|
fiatRampService;
|
|
30911
30993
|
availability;
|
|
@@ -30915,7 +30997,8 @@ class Checkout {
|
|
|
30915
30997
|
* @param {CheckoutModuleConfiguration} [config=SANDBOX_CONFIGURATION] - The configuration object for the CheckoutModule.
|
|
30916
30998
|
*/
|
|
30917
30999
|
constructor(config = SANDBOX_CONFIGURATION) {
|
|
30918
|
-
this.
|
|
31000
|
+
this.httpClient = new HttpClient(config);
|
|
31001
|
+
this.config = new CheckoutConfiguration(config, this.httpClient);
|
|
30919
31002
|
this.fiatRampService = new FiatRampService(this.config);
|
|
30920
31003
|
this.readOnlyProviders = new Map();
|
|
30921
31004
|
this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
|
|
@@ -17,7 +17,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
17
17
|
chainID,
|
|
18
18
|
coreContractAddress,
|
|
19
19
|
registrationContractAddress,
|
|
20
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
20
|
+
sdkVersion: 'ts-immutable-sdk-0.38.0',
|
|
21
21
|
});
|
|
22
22
|
/**
|
|
23
23
|
* Sets `sdkVersion` at the time of build
|