From 2f9c2db3d20ee35e34ab97743fdb194c65a1ad9c Mon Sep 17 00:00:00 2001 From: Alon Bar Date: Mon, 11 Dec 2023 16:59:26 +0200 Subject: [PATCH] fixing COR-44075 - After the latest axios upgrade from 0.27.2 to 1.6.0 n urls with ? but not params the ? character is omitted and we get are reaching a siguration that we are signing https://path/to/somwehere? but sending the request with https://path/to/somewhere --- src/ncw-api-client.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ncw-api-client.ts b/src/ncw-api-client.ts index 592ab556..9e5deb67 100644 --- a/src/ncw-api-client.ts +++ b/src/ncw-api-client.ts @@ -11,6 +11,10 @@ export class NcwApiClient implements NcwSdk { constructor(private readonly apiClient: ApiClient) { } + public normalizePath(baseUrl: string, params: string): string { + return params ? `${baseUrl}?${params.toString()}` : baseUrl; + } + public async getSupportedAssets({ pageCursor, pageSize, onlyBaseAssets }: NCW.GetSupportedAssetsPayload): Promise> { const params = new URLSearchParams({ ...(pageCursor && { pageCursor }), @@ -18,7 +22,8 @@ export class NcwApiClient implements NcwSdk { ...(onlyBaseAssets !== undefined && { onlyBaseAssets: String(onlyBaseAssets) }), }); - return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}/supported_assets?${params.toString()}`); + const url = this.normalizePath(`${this.NCW_BASE_PATH}/supported_assets`, params.toString()); + return await this.apiClient.issueGetRequest(url); } public async createWallet(): Promise<{ walletId: string; enabled: boolean; }> { @@ -77,7 +82,8 @@ export class NcwApiClient implements NcwSdk { ...(order && { order }), }); - return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}?${params.toString()}`); + const url = this.normalizePath(this.NCW_BASE_PATH, params.toString()); + return await this.apiClient.issueGetRequest(url); } public async getWalletAccounts(walletId: string, { pageCursor, pageSize, sort, order }: NCW.GetWalletsPayload = {}): Promise { @@ -132,9 +138,8 @@ export class NcwApiClient implements NcwSdk { ...(sort && { sort }), ...(order && { order }), }); - - return await this.apiClient.issueGetRequest( - `${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`); + const url = this.normalizePath(`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses`, params.toString()); + return await this.apiClient.issueGetRequest(url); } public async getWalletAssetBalance(walletId: string, accountId: number, assetId: string): Promise {