@lifi/sdk 2.2.2 → 2.3.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.
@@ -14,32 +14,38 @@ exports.requestSettings = {
14
14
  const request = async (url, options = {
15
15
  retries: exports.requestSettings.retries,
16
16
  }) => {
17
- const { userId, integrator, widgetVersion } = ConfigService_1.default.getInstance().getConfig();
17
+ const { userId, integrator, widgetVersion, apiKey } = ConfigService_1.default.getInstance().getConfig();
18
18
  options.retries = options.retries ?? exports.requestSettings.retries;
19
19
  try {
20
20
  if (!options.skipTrackingHeaders) {
21
+ if (apiKey) {
22
+ options.headers = {
23
+ ...options?.headers,
24
+ 'x-lifi-api-key': apiKey,
25
+ };
26
+ }
21
27
  if (userId) {
22
28
  options.headers = {
23
29
  ...options?.headers,
24
- 'X-LIFI-UserId': userId,
30
+ 'x-lifi-userid': userId,
25
31
  };
26
32
  }
27
33
  if (widgetVersion) {
28
34
  options.headers = {
29
35
  ...options?.headers,
30
- 'X-LIFI-Widget': widgetVersion,
36
+ 'x-lifi-widget': widgetVersion,
31
37
  };
32
38
  }
33
39
  if (version_1.version) {
34
40
  options.headers = {
35
41
  ...options?.headers,
36
- 'X-LIFI-SDK': version_1.version,
42
+ 'x-lifi-sdk': version_1.version,
37
43
  };
38
44
  }
39
45
  // integrator is mandatory during SDK initialization
40
46
  options.headers = {
41
47
  ...options?.headers,
42
- 'X-LIFI-Integrator': integrator,
48
+ 'x-lifi-integrator': integrator,
43
49
  };
44
50
  }
45
51
  const response = await fetch(url, options);
@@ -279,10 +279,10 @@ const getAvailableConnections = async (connectionRequest) => {
279
279
  url.searchParams.append('fromToken', fromToken);
280
280
  }
281
281
  if (toChain) {
282
- url.searchParams.append('fromToken', toChain);
282
+ url.searchParams.append('toChain', toChain);
283
283
  }
284
284
  if (toToken) {
285
- url.searchParams.append('fromToken', toToken);
285
+ url.searchParams.append('toToken', toToken);
286
286
  }
287
287
  const connectionRequestArrayParams = [
288
288
  'allowBridges',
@@ -38,6 +38,7 @@ class ConfigService {
38
38
  this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
39
39
  // OPTIONS
40
40
  this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
41
+ this.config.apiKey = configUpdate.apiKey || this.config.apiKey;
41
42
  this.config.userId = configUpdate.userId || this.config.userId;
42
43
  this.config.integrator = configUpdate.integrator || this.config.integrator;
43
44
  this.config.defaultRouteOptions.integrator =
@@ -27,6 +27,7 @@ export type UpdateRouteHook = (updatedRoute: Route) => void;
27
27
  export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
28
28
  export type Config = {
29
29
  apiUrl: string;
30
+ apiKey?: string;
30
31
  rpcs: Record<ChainId, string[]>;
31
32
  multicallAddresses: Record<ChainId, string | undefined>;
32
33
  defaultExecutionSettings: InternalExecutionSettings;
@@ -57,6 +58,7 @@ export interface MultisigConfig {
57
58
  }
58
59
  export type ConfigUpdate = {
59
60
  apiUrl?: string;
61
+ apiKey?: string;
60
62
  rpcs?: Record<number, string[]>;
61
63
  multicallAddresses?: Record<number, string | undefined>;
62
64
  defaultExecutionSettings?: ExecutionSettings;
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.2.2";
2
+ export declare const version = "2.3.0";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/sdk';
5
- exports.version = '2.2.2';
5
+ exports.version = '2.3.0';
package/dist/request.js CHANGED
@@ -8,32 +8,38 @@ export const requestSettings = {
8
8
  export const request = async (url, options = {
9
9
  retries: requestSettings.retries,
10
10
  }) => {
11
- const { userId, integrator, widgetVersion } = ConfigService.getInstance().getConfig();
11
+ const { userId, integrator, widgetVersion, apiKey } = ConfigService.getInstance().getConfig();
12
12
  options.retries = options.retries ?? requestSettings.retries;
13
13
  try {
14
14
  if (!options.skipTrackingHeaders) {
15
+ if (apiKey) {
16
+ options.headers = {
17
+ ...options?.headers,
18
+ 'x-lifi-api-key': apiKey,
19
+ };
20
+ }
15
21
  if (userId) {
16
22
  options.headers = {
17
23
  ...options?.headers,
18
- 'X-LIFI-UserId': userId,
24
+ 'x-lifi-userid': userId,
19
25
  };
20
26
  }
21
27
  if (widgetVersion) {
22
28
  options.headers = {
23
29
  ...options?.headers,
24
- 'X-LIFI-Widget': widgetVersion,
30
+ 'x-lifi-widget': widgetVersion,
25
31
  };
26
32
  }
27
33
  if (version) {
28
34
  options.headers = {
29
35
  ...options?.headers,
30
- 'X-LIFI-SDK': version,
36
+ 'x-lifi-sdk': version,
31
37
  };
32
38
  }
33
39
  // integrator is mandatory during SDK initialization
34
40
  options.headers = {
35
41
  ...options?.headers,
36
- 'X-LIFI-Integrator': integrator,
42
+ 'x-lifi-integrator': integrator,
37
43
  };
38
44
  }
39
45
  const response = await fetch(url, options);
@@ -274,10 +274,10 @@ const getAvailableConnections = async (connectionRequest) => {
274
274
  url.searchParams.append('fromToken', fromToken);
275
275
  }
276
276
  if (toChain) {
277
- url.searchParams.append('fromToken', toChain);
277
+ url.searchParams.append('toChain', toChain);
278
278
  }
279
279
  if (toToken) {
280
- url.searchParams.append('fromToken', toToken);
280
+ url.searchParams.append('toToken', toToken);
281
281
  }
282
282
  const connectionRequestArrayParams = [
283
283
  'allowBridges',
@@ -36,6 +36,7 @@ class ConfigService {
36
36
  this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
37
37
  // OPTIONS
38
38
  this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
39
+ this.config.apiKey = configUpdate.apiKey || this.config.apiKey;
39
40
  this.config.userId = configUpdate.userId || this.config.userId;
40
41
  this.config.integrator = configUpdate.integrator || this.config.integrator;
41
42
  this.config.defaultRouteOptions.integrator =
@@ -27,6 +27,7 @@ export type UpdateRouteHook = (updatedRoute: Route) => void;
27
27
  export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
28
28
  export type Config = {
29
29
  apiUrl: string;
30
+ apiKey?: string;
30
31
  rpcs: Record<ChainId, string[]>;
31
32
  multicallAddresses: Record<ChainId, string | undefined>;
32
33
  defaultExecutionSettings: InternalExecutionSettings;
@@ -57,6 +58,7 @@ export interface MultisigConfig {
57
58
  }
58
59
  export type ConfigUpdate = {
59
60
  apiUrl?: string;
61
+ apiKey?: string;
60
62
  rpcs?: Record<number, string[]>;
61
63
  multicallAddresses?: Record<number, string | undefined>;
62
64
  defaultExecutionSettings?: ExecutionSettings;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "2.2.2";
2
+ export declare const version = "2.3.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk';
2
- export const version = '2.2.2';
2
+ export const version = '2.3.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/index.js",
@@ -77,7 +77,7 @@
77
77
  "dependencies": {
78
78
  "@ethersproject/abi": "^5.7.0",
79
79
  "@ethersproject/contracts": "^5.7.0",
80
- "@lifi/types": "^8.0.4",
80
+ "@lifi/types": "^8.4.0",
81
81
  "bignumber.js": "^9.1.1",
82
82
  "eth-rpc-errors": "^4.0.3",
83
83
  "ethers": "^5.7.2"