From 7f4a46f4c35a795dba8f46a3fa41affdfbfa2958 Mon Sep 17 00:00:00 2001 From: Wojciech Duda <69160975+wojd0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:38:10 +0100 Subject: [PATCH] AAE-30882 Simplify typing of methods --- lib/js-api/src/superagentHttpClient.ts | 26 +++----------------- lib/js-api/test/superagentHttpClient.spec.ts | 18 ++++---------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/lib/js-api/src/superagentHttpClient.ts b/lib/js-api/src/superagentHttpClient.ts index c37f08c669..b501546ac0 100644 --- a/lib/js-api/src/superagentHttpClient.ts +++ b/lib/js-api/src/superagentHttpClient.ts @@ -45,20 +45,12 @@ export class SuperagentHttpClient implements HttpClient { } request(url: string, options: RequestOptions, securityOptions: SecurityOptions, emitters: Emitters): Promise { - const { httpMethod, queryParams, headerParams, formParams, bodyParam, contentType, accept, responseType, returnType } = options; + const { returnType } = options; const { eventEmitter, apiClientEmitter } = emitters; const { urlWithParams, fetchOptions } = this.buildRequest({ - httpMethod, + ...options, url, - queryParams, - headerParams, - formParams, - bodyParam, - contentType, - accept, - responseType, - returnType, securityOptions }); @@ -120,19 +112,7 @@ export class SuperagentHttpClient implements HttpClient { responseType, returnType, securityOptions - }: { - httpMethod: string; - url: string; - queryParams: { [key: string]: any }; - headerParams: { [key: string]: any }; - formParams: { [key: string]: any }; - bodyParam: string | object; - contentType: string; - accept: string; - responseType: string; - returnType: string; - securityOptions: SecurityOptions; - }) { + }: RequestOptions & { securityOptions: SecurityOptions }) { const urlWithParams = new URL(url); urlWithParams.search = new URLSearchParams(SuperagentHttpClient.normalizeParams(queryParams)).toString(); diff --git a/lib/js-api/test/superagentHttpClient.spec.ts b/lib/js-api/test/superagentHttpClient.spec.ts index d233673baa..9cb0d2a7ee 100644 --- a/lib/js-api/test/superagentHttpClient.spec.ts +++ b/lib/js-api/test/superagentHttpClient.spec.ts @@ -27,7 +27,7 @@ jest.mock('ofetch', () => ({ jest.mock('../src/utils', () => ({ isBrowser: jest.fn(() => true), - paramToString: (param: any) => String(param) + paramToString: (param: unknown) => String(param) })); describe('SuperagentHttpClient', () => { @@ -100,14 +100,10 @@ describe('SuperagentHttpClient', () => { const securityOptions = { ...defaultSecurityOptions }; const request = client['buildRequest']({ + ...options, + path: '', httpMethod, url, - queryParams: options.queryParams, - headerParams: options.headerParams, - formParams: options.formParams, - contentType: options.contentType, - accept: options.accept, - responseType: options.responseType, bodyParam: null, returnType: null, securityOptions @@ -134,14 +130,10 @@ describe('SuperagentHttpClient', () => { (isBrowser as jest.Mock).mockReturnValue(false); const request = client['buildRequest']({ + ...options, + path: '', httpMethod, url, - queryParams: options.queryParams, - headerParams: options.headerParams, - formParams: options.formParams, - contentType: options.contentType, - accept: options.accept, - responseType: options.responseType, bodyParam: null, returnType: null, securityOptions