@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/index.cjs
CHANGED
|
@@ -61,7 +61,7 @@ class ImmutableConfiguration {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const API_KEY_PREFIX = 'sk_imapik-';
|
|
64
|
-
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
64
|
+
const PUBLISHABLE_KEY_PREFIX$1 = 'pk_imapik-';
|
|
65
65
|
const addApiKeyToAxiosHeader = (apiKey) => {
|
|
66
66
|
if (!apiKey.startsWith(API_KEY_PREFIX)) {
|
|
67
67
|
throw new Error('Invalid API key. Create your api key in Immutable developer hub. https://hub.immutable.com');
|
|
@@ -69,7 +69,7 @@ const addApiKeyToAxiosHeader = (apiKey) => {
|
|
|
69
69
|
globalAxios$1.defaults.headers.common['x-immutable-api-key'] = apiKey;
|
|
70
70
|
};
|
|
71
71
|
const addPublishableKeyToAxiosHeader = (publishableKey) => {
|
|
72
|
-
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
|
|
72
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX$1)) {
|
|
73
73
|
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
74
74
|
+ ' https://hub.immutable.com');
|
|
75
75
|
}
|
|
@@ -4256,7 +4256,7 @@ class MultiRollupApiClients {
|
|
|
4256
4256
|
}
|
|
4257
4257
|
|
|
4258
4258
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4259
|
-
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.
|
|
4259
|
+
const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.38.0' };
|
|
4260
4260
|
const createConfig = ({ basePath, headers, }) => {
|
|
4261
4261
|
if (!basePath.trim()) {
|
|
4262
4262
|
throw Error('basePath can not be empty');
|
|
@@ -4316,7 +4316,7 @@ class APIError extends Error {
|
|
|
4316
4316
|
|
|
4317
4317
|
/* eslint-disable implicit-arrow-linebreak */
|
|
4318
4318
|
const defaultHeaders = {
|
|
4319
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.
|
|
4319
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.38.0',
|
|
4320
4320
|
};
|
|
4321
4321
|
/**
|
|
4322
4322
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -4755,7 +4755,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
|
|
|
4755
4755
|
chainID,
|
|
4756
4756
|
coreContractAddress,
|
|
4757
4757
|
registrationContractAddress,
|
|
4758
|
-
sdkVersion: 'ts-immutable-sdk-0.
|
|
4758
|
+
sdkVersion: 'ts-immutable-sdk-0.38.0',
|
|
4759
4759
|
});
|
|
4760
4760
|
/**
|
|
4761
4761
|
* Sets `sdkVersion` at the time of build
|
|
@@ -34802,6 +34802,7 @@ var ConnectEventType;
|
|
|
34802
34802
|
ConnectEventType["CLOSE_WIDGET"] = "close-widget";
|
|
34803
34803
|
ConnectEventType["SUCCESS"] = "success";
|
|
34804
34804
|
ConnectEventType["FAILURE"] = "failure";
|
|
34805
|
+
ConnectEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34805
34806
|
})(ConnectEventType || (ConnectEventType = {}));
|
|
34806
34807
|
|
|
34807
34808
|
/**
|
|
@@ -34812,6 +34813,7 @@ var WalletEventType;
|
|
|
34812
34813
|
WalletEventType["CLOSE_WIDGET"] = "close-widget";
|
|
34813
34814
|
WalletEventType["NETWORK_SWITCH"] = "network-switch";
|
|
34814
34815
|
WalletEventType["DISCONNECT_WALLET"] = "disconnect-wallet";
|
|
34816
|
+
WalletEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34815
34817
|
})(WalletEventType || (WalletEventType = {}));
|
|
34816
34818
|
|
|
34817
34819
|
/**
|
|
@@ -34823,6 +34825,7 @@ var SwapEventType;
|
|
|
34823
34825
|
SwapEventType["SUCCESS"] = "success";
|
|
34824
34826
|
SwapEventType["FAILURE"] = "failure";
|
|
34825
34827
|
SwapEventType["REJECTED"] = "rejected";
|
|
34828
|
+
SwapEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34826
34829
|
})(SwapEventType || (SwapEventType = {}));
|
|
34827
34830
|
|
|
34828
34831
|
/**
|
|
@@ -34835,6 +34838,7 @@ var SaleEventType;
|
|
|
34835
34838
|
SaleEventType["FAILURE"] = "failure";
|
|
34836
34839
|
SaleEventType["REJECTED"] = "rejected";
|
|
34837
34840
|
SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
|
|
34841
|
+
SaleEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34838
34842
|
})(SaleEventType || (SaleEventType = {}));
|
|
34839
34843
|
|
|
34840
34844
|
/**
|
|
@@ -34845,6 +34849,7 @@ var BridgeEventType;
|
|
|
34845
34849
|
BridgeEventType["CLOSE_WIDGET"] = "close-widget";
|
|
34846
34850
|
BridgeEventType["FAILURE"] = "failure";
|
|
34847
34851
|
BridgeEventType["TRANSACTION_SENT"] = "transaction-sent";
|
|
34852
|
+
BridgeEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34848
34853
|
})(BridgeEventType || (BridgeEventType = {}));
|
|
34849
34854
|
|
|
34850
34855
|
/**
|
|
@@ -34867,6 +34872,7 @@ var OnRampEventType;
|
|
|
34867
34872
|
OnRampEventType["CLOSE_WIDGET"] = "close-widget";
|
|
34868
34873
|
OnRampEventType["SUCCESS"] = "success";
|
|
34869
34874
|
OnRampEventType["FAILURE"] = "failure";
|
|
34875
|
+
OnRampEventType["LANGUAGE_CHANGED"] = "language-changed";
|
|
34870
34876
|
})(OnRampEventType || (OnRampEventType = {}));
|
|
34871
34877
|
|
|
34872
34878
|
/**
|
|
@@ -35695,32 +35701,21 @@ const GAS_OVERRIDES = {
|
|
|
35695
35701
|
maxPriorityFeePerGas: ethers.BigNumber.from(101e9),
|
|
35696
35702
|
};
|
|
35697
35703
|
|
|
35698
|
-
const SDK_VERSION_MARKER = '0.
|
|
35704
|
+
const SDK_VERSION_MARKER = '0.38.0';
|
|
35699
35705
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
35700
35706
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
35701
35707
|
|
|
35702
35708
|
class RemoteConfigFetcher {
|
|
35709
|
+
httpClient;
|
|
35703
35710
|
isDevelopment;
|
|
35704
35711
|
isProduction;
|
|
35705
35712
|
configCache;
|
|
35706
35713
|
tokensCache;
|
|
35707
35714
|
version = 'v1';
|
|
35708
|
-
constructor(params) {
|
|
35715
|
+
constructor(httpClient, params) {
|
|
35709
35716
|
this.isDevelopment = params.isDevelopment;
|
|
35710
35717
|
this.isProduction = params.isProduction;
|
|
35711
|
-
|
|
35712
|
-
static async makeHttpRequest(url) {
|
|
35713
|
-
let response;
|
|
35714
|
-
try {
|
|
35715
|
-
response = await globalAxios$1.get(url);
|
|
35716
|
-
}
|
|
35717
|
-
catch (error) {
|
|
35718
|
-
throw new CheckoutError(`Error fetching from api: ${error.message}`, CheckoutErrorType.API_ERROR);
|
|
35719
|
-
}
|
|
35720
|
-
if (response.status !== 200) {
|
|
35721
|
-
throw new CheckoutError(`Error fetching from api: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
35722
|
-
}
|
|
35723
|
-
return response;
|
|
35718
|
+
this.httpClient = httpClient;
|
|
35724
35719
|
}
|
|
35725
35720
|
getEndpoint = () => {
|
|
35726
35721
|
if (this.isDevelopment)
|
|
@@ -35732,14 +35727,14 @@ class RemoteConfigFetcher {
|
|
|
35732
35727
|
async loadConfig() {
|
|
35733
35728
|
if (this.configCache)
|
|
35734
35729
|
return this.configCache;
|
|
35735
|
-
const response = await
|
|
35730
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config`);
|
|
35736
35731
|
this.configCache = response.data;
|
|
35737
35732
|
return this.configCache;
|
|
35738
35733
|
}
|
|
35739
35734
|
async loadConfigTokens() {
|
|
35740
35735
|
if (this.tokensCache)
|
|
35741
35736
|
return this.tokensCache;
|
|
35742
|
-
const response = await
|
|
35737
|
+
const response = await this.httpClient.get(`${this.getEndpoint()}/${this.version}/config/tokens`);
|
|
35743
35738
|
this.tokensCache = response.data;
|
|
35744
35739
|
return this.tokensCache;
|
|
35745
35740
|
}
|
|
@@ -35757,6 +35752,7 @@ class RemoteConfigFetcher {
|
|
|
35757
35752
|
return {};
|
|
35758
35753
|
return config[chainId] ?? [];
|
|
35759
35754
|
}
|
|
35755
|
+
getHttpClient = () => this.httpClient;
|
|
35760
35756
|
}
|
|
35761
35757
|
|
|
35762
35758
|
class CheckoutConfigurationError extends Error {
|
|
@@ -35807,7 +35803,7 @@ class CheckoutConfiguration {
|
|
|
35807
35803
|
remote;
|
|
35808
35804
|
environment;
|
|
35809
35805
|
networkMap;
|
|
35810
|
-
constructor(config) {
|
|
35806
|
+
constructor(config, httpClient) {
|
|
35811
35807
|
if (!Object.values(Environment$1).includes(config.baseConfig.environment)) {
|
|
35812
35808
|
throw new CheckoutConfigurationError('Invalid checkout configuration of environment');
|
|
35813
35809
|
}
|
|
@@ -35818,7 +35814,7 @@ class CheckoutConfiguration {
|
|
|
35818
35814
|
this.isSwapEnabled = config.swap?.enable ?? DEFAULT_SWAP_ENABLED;
|
|
35819
35815
|
this.isBridgeEnabled = config.bridge?.enable ?? DEFAULT_BRIDGE_ENABLED;
|
|
35820
35816
|
this.networkMap = networkMap(this.isProduction, this.isDevelopment);
|
|
35821
|
-
this.remote = new RemoteConfigFetcher({
|
|
35817
|
+
this.remote = new RemoteConfigFetcher(httpClient, {
|
|
35822
35818
|
isDevelopment: this.isDevelopment,
|
|
35823
35819
|
isProduction: this.isProduction,
|
|
35824
35820
|
});
|
|
@@ -35883,9 +35879,7 @@ class Blockscout {
|
|
|
35883
35879
|
ttl;
|
|
35884
35880
|
chainId;
|
|
35885
35881
|
cacheMap;
|
|
35886
|
-
|
|
35887
|
-
return globalAxios$1.get(url);
|
|
35888
|
-
}
|
|
35882
|
+
httpClient;
|
|
35889
35883
|
setCache(key, data) {
|
|
35890
35884
|
this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
|
|
35891
35885
|
}
|
|
@@ -35897,11 +35891,13 @@ class Blockscout {
|
|
|
35897
35891
|
}
|
|
35898
35892
|
/**
|
|
35899
35893
|
* Blockscout constructor
|
|
35894
|
+
* @param httpClient Client used for http requests
|
|
35900
35895
|
* @param chainId target chain
|
|
35901
35896
|
* @param ttl cache TTL
|
|
35902
35897
|
*/
|
|
35903
|
-
constructor(
|
|
35904
|
-
this.
|
|
35898
|
+
constructor(httpClient, chainId, ttl) {
|
|
35899
|
+
this.httpClient = httpClient;
|
|
35900
|
+
this.chainId = chainId;
|
|
35905
35901
|
this.url = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].url;
|
|
35906
35902
|
const native = BLOCKSCOUT_CHAIN_URL_MAP[this.chainId].nativeToken;
|
|
35907
35903
|
this.nativeToken = {
|
|
@@ -35911,7 +35907,7 @@ class Blockscout {
|
|
|
35911
35907
|
symbol: native.symbol,
|
|
35912
35908
|
};
|
|
35913
35909
|
this.cacheMap = {};
|
|
35914
|
-
this.ttl =
|
|
35910
|
+
this.ttl = ttl !== undefined ? ttl : CACHE_DATA_TTL;
|
|
35915
35911
|
}
|
|
35916
35912
|
/**
|
|
35917
35913
|
* isChainSupported verifies if the chain is supported by Blockscout
|
|
@@ -35939,7 +35935,7 @@ class Blockscout {
|
|
|
35939
35935
|
const cached = this.getCache(url);
|
|
35940
35936
|
if (cached)
|
|
35941
35937
|
return Promise.resolve(cached);
|
|
35942
|
-
const response = await
|
|
35938
|
+
const response = await this.httpClient.get(url);
|
|
35943
35939
|
if (response.status >= 400) {
|
|
35944
35940
|
return Promise.reject({
|
|
35945
35941
|
code: response.status,
|
|
@@ -35980,7 +35976,7 @@ class Blockscout {
|
|
|
35980
35976
|
const cached = this.getCache(url);
|
|
35981
35977
|
if (cached)
|
|
35982
35978
|
return Promise.resolve(cached);
|
|
35983
|
-
const response = await
|
|
35979
|
+
const response = await this.httpClient.get(url);
|
|
35984
35980
|
if (response.status >= 400) {
|
|
35985
35981
|
return Promise.reject({
|
|
35986
35982
|
code: response.status,
|
|
@@ -36065,7 +36061,7 @@ const blockscoutClientMap = new Map();
|
|
|
36065
36061
|
// This function is a utility function that can be used to reset the
|
|
36066
36062
|
// blockscout map and therefore clear all the cache.
|
|
36067
36063
|
const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
|
|
36068
|
-
const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
36064
|
+
const getIndexerBalance = async (config, walletAddress, chainId, filterTokens) => {
|
|
36069
36065
|
// Shuffle the mapping of the tokens configuration so it is a hashmap
|
|
36070
36066
|
// for faster access to tokens config objects.
|
|
36071
36067
|
const shouldFilter = filterTokens !== undefined;
|
|
@@ -36073,7 +36069,8 @@ const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
|
|
|
36073
36069
|
// Get blockscout client for the given chain
|
|
36074
36070
|
let blockscoutClient = blockscoutClientMap.get(chainId);
|
|
36075
36071
|
if (!blockscoutClient) {
|
|
36076
|
-
|
|
36072
|
+
const httpClient = config.remote.getHttpClient();
|
|
36073
|
+
blockscoutClient = new Blockscout(httpClient, chainId);
|
|
36077
36074
|
blockscoutClientMap.set(chainId, blockscoutClient);
|
|
36078
36075
|
}
|
|
36079
36076
|
// Hold the items in an array for post-fetching processing
|
|
@@ -36208,7 +36205,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
|
|
|
36208
36205
|
const isL1Chain = getL1ChainId(config) === chainId;
|
|
36209
36206
|
if (!address)
|
|
36210
36207
|
address = await web3Provider?.getSigner().getAddress();
|
|
36211
|
-
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(address, chainId, isL1Chain ? tokens : undefined));
|
|
36208
|
+
return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(config, address, chainId, isL1Chain ? tokens : undefined));
|
|
36212
36209
|
}
|
|
36213
36210
|
if (!web3Provider) {
|
|
36214
36211
|
throw new CheckoutError('indexer is disabled for this chain, you must provide a provider.', CheckoutErrorType.MISSING_PARAMS);
|
|
@@ -39201,6 +39198,90 @@ function loadUnresolved(version) {
|
|
|
39201
39198
|
return { loaded: false, element: tag };
|
|
39202
39199
|
}
|
|
39203
39200
|
|
|
39201
|
+
const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
|
|
39202
|
+
const publishableKeyDomainAllowlist = [
|
|
39203
|
+
'https://checkout-api.dev.immutable.com',
|
|
39204
|
+
'https://checkout-api.sandbox.immutable.com',
|
|
39205
|
+
'https://checkout-api.immutable.com',
|
|
39206
|
+
];
|
|
39207
|
+
class HttpClient {
|
|
39208
|
+
config;
|
|
39209
|
+
axiosInstance;
|
|
39210
|
+
constructor(config) {
|
|
39211
|
+
this.config = config;
|
|
39212
|
+
this.axiosInstance = globalAxios$1.create();
|
|
39213
|
+
this.setupInterceptors();
|
|
39214
|
+
}
|
|
39215
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39216
|
+
shouldAddPublishableKey(url) {
|
|
39217
|
+
// Check if the request is going to a whitelisted domain
|
|
39218
|
+
return publishableKeyDomainAllowlist.some((domain) => url.startsWith(domain));
|
|
39219
|
+
}
|
|
39220
|
+
setupInterceptors() {
|
|
39221
|
+
this.axiosInstance.interceptors.request.use((config) => {
|
|
39222
|
+
const publishableKey = this.config?.baseConfig?.publishableKey;
|
|
39223
|
+
if (publishableKey && this.shouldAddPublishableKey(config.url || '')) {
|
|
39224
|
+
if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {
|
|
39225
|
+
throw new Error('Invalid Publishable key. Create your Publishable key in Immutable developer hub.'
|
|
39226
|
+
+ ' https://hub.immutable.com');
|
|
39227
|
+
}
|
|
39228
|
+
// Add publishable key header for whitelisted domains
|
|
39229
|
+
// eslint-disable-next-line no-param-reassign
|
|
39230
|
+
config.headers['x-immutable-publishable-key'] = publishableKey;
|
|
39231
|
+
}
|
|
39232
|
+
return config;
|
|
39233
|
+
}, (error) => Promise.reject(error));
|
|
39234
|
+
}
|
|
39235
|
+
// eslint-disable-next-line class-methods-use-this
|
|
39236
|
+
processResponse(response) {
|
|
39237
|
+
if (response && response?.status !== 200) {
|
|
39238
|
+
throw new CheckoutError(`Error: ${response.status} ${response.statusText}`, CheckoutErrorType.API_ERROR);
|
|
39239
|
+
}
|
|
39240
|
+
}
|
|
39241
|
+
async request(config) {
|
|
39242
|
+
let response;
|
|
39243
|
+
try {
|
|
39244
|
+
response = await this.axiosInstance.request(config);
|
|
39245
|
+
}
|
|
39246
|
+
catch (error) {
|
|
39247
|
+
throw new CheckoutError(error.message, CheckoutErrorType.API_ERROR);
|
|
39248
|
+
}
|
|
39249
|
+
this.processResponse(response);
|
|
39250
|
+
return response;
|
|
39251
|
+
}
|
|
39252
|
+
async get(url, config) {
|
|
39253
|
+
const requestConfig = {
|
|
39254
|
+
...config,
|
|
39255
|
+
url,
|
|
39256
|
+
};
|
|
39257
|
+
return await this.request(requestConfig);
|
|
39258
|
+
}
|
|
39259
|
+
async post(url, data, config) {
|
|
39260
|
+
const requestConfig = {
|
|
39261
|
+
...config,
|
|
39262
|
+
data,
|
|
39263
|
+
url,
|
|
39264
|
+
};
|
|
39265
|
+
return await this.request(requestConfig);
|
|
39266
|
+
}
|
|
39267
|
+
async put(url, data, config) {
|
|
39268
|
+
const requestConfig = {
|
|
39269
|
+
...config,
|
|
39270
|
+
data,
|
|
39271
|
+
url,
|
|
39272
|
+
};
|
|
39273
|
+
return await this.request(requestConfig);
|
|
39274
|
+
}
|
|
39275
|
+
async delete(url, data, config) {
|
|
39276
|
+
const requestConfig = {
|
|
39277
|
+
...config,
|
|
39278
|
+
data,
|
|
39279
|
+
url,
|
|
39280
|
+
};
|
|
39281
|
+
return await this.request(requestConfig);
|
|
39282
|
+
}
|
|
39283
|
+
}
|
|
39284
|
+
|
|
39204
39285
|
const SANDBOX_CONFIGURATION = {
|
|
39205
39286
|
baseConfig: {
|
|
39206
39287
|
environment: Environment$1.SANDBOX,
|
|
@@ -39211,6 +39292,7 @@ const WIDGETS_SCRIPT_TIMEOUT = 100;
|
|
|
39211
39292
|
// Checkout SDK
|
|
39212
39293
|
class Checkout {
|
|
39213
39294
|
readOnlyProviders;
|
|
39295
|
+
httpClient;
|
|
39214
39296
|
config;
|
|
39215
39297
|
fiatRampService;
|
|
39216
39298
|
availability;
|
|
@@ -39220,7 +39302,8 @@ class Checkout {
|
|
|
39220
39302
|
* @param {CheckoutModuleConfiguration} [config=SANDBOX_CONFIGURATION] - The configuration object for the CheckoutModule.
|
|
39221
39303
|
*/
|
|
39222
39304
|
constructor(config = SANDBOX_CONFIGURATION) {
|
|
39223
|
-
this.
|
|
39305
|
+
this.httpClient = new HttpClient(config);
|
|
39306
|
+
this.config = new CheckoutConfiguration(config, this.httpClient);
|
|
39224
39307
|
this.fiatRampService = new FiatRampService(this.config);
|
|
39225
39308
|
this.readOnlyProviders = new Map();
|
|
39226
39309
|
this.availability = availabilityService(this.config.isDevelopment, this.config.isProduction);
|