From eecaa745af697fbb1238e12199fd4080bde5e51a Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Fri, 11 Jul 2025 13:26:03 +0600 Subject: [PATCH] chore(common): fixes lint errors and clean up code (#5237) Co-authored-by: nivedin --- .../src/components/http/Headers.vue | 2 +- .../ImportExportSteps/UrlImport.vue | 2 +- .../src/helpers/auth/auth-types.ts | 16 +++------------ .../src/helpers/auth/types/aws-signature.ts | 12 +++++------ .../src/helpers/auth/types/jwt.ts | 9 ++++----- .../src/helpers/utils/EffectiveURL.ts | 20 ++++++------------- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/packages/hoppscotch-common/src/components/http/Headers.vue b/packages/hoppscotch-common/src/components/http/Headers.vue index 20b74b4e..11c35048 100644 --- a/packages/hoppscotch-common/src/components/http/Headers.vue +++ b/packages/hoppscotch-common/src/components/http/Headers.vue @@ -576,7 +576,7 @@ watch([props.modelValue, aggregateEnvs], async () => { } }) computedHeaders.value = ( - await getComputedHeaders(props.modelValue, resolvedEnvs, true) + await getComputedHeaders(props.modelValue, resolvedEnvs) ).map((header, index) => ({ id: `header-${index}`, ...header, diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue index 591f8381..d9aa75a6 100644 --- a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue +++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue @@ -180,7 +180,7 @@ async function fetchUrlData() { const res = await urlFetchLogic(inputChooseGistToImportFrom.value) if (E.isLeft(res)) { - // @ts-ignore + // @ts-expect-error Assuming error is of type Error if (isCorsError(res.left?.error)) { showCorsError.value = true } else { diff --git a/packages/hoppscotch-common/src/helpers/auth/auth-types.ts b/packages/hoppscotch-common/src/helpers/auth/auth-types.ts index d73c5735..520e247d 100644 --- a/packages/hoppscotch-common/src/helpers/auth/auth-types.ts +++ b/packages/hoppscotch-common/src/helpers/auth/auth-types.ts @@ -46,12 +46,7 @@ export async function generateAuthHeaders( case "digest": return generateDigestAuthHeaders(auth, request, envVars, showKeyIfSecret) case "aws-signature": - return generateAwsSignatureAuthHeaders( - auth, - request, - envVars, - showKeyIfSecret - ) + return generateAwsSignatureAuthHeaders(auth, request, envVars) case "hawk": return generateHawkAuthHeaders(auth, request, envVars, showKeyIfSecret) case "jwt": @@ -78,14 +73,9 @@ export async function generateAuthParams( case "oauth-2": return generateOAuth2AuthParams(auth, request, envVars, showKeyIfSecret) case "aws-signature": - return generateAwsSignatureAuthParams( - auth, - request, - envVars, - showKeyIfSecret - ) + return generateAwsSignatureAuthParams(auth, request, envVars) case "jwt": - return generateJwtAuthParams(auth, request, envVars, showKeyIfSecret) + return generateJwtAuthParams(auth, request, envVars) default: return [] } diff --git a/packages/hoppscotch-common/src/helpers/auth/types/aws-signature.ts b/packages/hoppscotch-common/src/helpers/auth/types/aws-signature.ts index 8ebfefcb..4b253c9b 100644 --- a/packages/hoppscotch-common/src/helpers/auth/types/aws-signature.ts +++ b/packages/hoppscotch-common/src/helpers/auth/types/aws-signature.ts @@ -1,10 +1,10 @@ import { - parseTemplateString, - HoppRESTAuth, - HoppRESTRequest, Environment, + HoppRESTAuth, HoppRESTHeader, HoppRESTParam, + HoppRESTRequest, + parseTemplateString, } from "@hoppscotch/data" import { AwsV4Signer } from "aws4fetch" import { getFinalBodyFromRequest } from "~/helpers/utils/EffectiveURL" @@ -12,8 +12,7 @@ import { getFinalBodyFromRequest } from "~/helpers/utils/EffectiveURL" export async function generateAwsSignatureAuthHeaders( auth: HoppRESTAuth & { authType: "aws-signature" }, request: HoppRESTRequest, - envVars: Environment["variables"], - showKeyIfSecret = false + envVars: Environment["variables"] ): Promise { if (auth.addTo !== "HEADERS") return [] @@ -54,8 +53,7 @@ export async function generateAwsSignatureAuthHeaders( export async function generateAwsSignatureAuthParams( auth: HoppRESTAuth & { authType: "aws-signature" }, request: HoppRESTRequest, - envVars: Environment["variables"], - showKeyIfSecret = false + envVars: Environment["variables"] ): Promise { if (auth.addTo !== "QUERY_PARAMS") return [] diff --git a/packages/hoppscotch-common/src/helpers/auth/types/jwt.ts b/packages/hoppscotch-common/src/helpers/auth/types/jwt.ts index f9bcf0f3..86d92630 100644 --- a/packages/hoppscotch-common/src/helpers/auth/types/jwt.ts +++ b/packages/hoppscotch-common/src/helpers/auth/types/jwt.ts @@ -1,11 +1,11 @@ import { - parseTemplateString, + Environment, generateJWTToken, HoppRESTAuth, - HoppRESTRequest, - Environment, HoppRESTHeader, HoppRESTParam, + HoppRESTRequest, + parseTemplateString, } from "@hoppscotch/data" export async function generateJwtAuthHeaders( @@ -48,8 +48,7 @@ export async function generateJwtAuthHeaders( export async function generateJwtAuthParams( auth: HoppRESTAuth & { authType: "jwt" }, request: HoppRESTRequest, - envVars: Environment["variables"], - showKeyIfSecret = false + envVars: Environment["variables"] ): Promise { if (auth.addTo !== "QUERY_PARAMS") return [] diff --git a/packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts b/packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts index a92f9f6e..0d8a868d 100644 --- a/packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts +++ b/packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts @@ -23,12 +23,12 @@ import qs from "qs" import { combineLatest, Observable } from "rxjs" import { map } from "rxjs/operators" +import { generateAuthHeaders, generateAuthParams } from "../auth/auth-types" +import { stripComments } from "../editor/linting/jsonc" import { arrayFlatMap, arraySort } from "../functional/array" import { toFormData } from "../functional/formData" import { tupleWithSameKeysToRecord } from "../functional/record" import { isJSONContentType } from "./contenttypes" -import { stripComments } from "../editor/linting/jsonc" -import { generateAuthHeaders, generateAuthParams } from "../auth/auth-types" export interface EffectiveHoppRESTRequest extends HoppRESTRequest { /** @@ -61,7 +61,6 @@ export const getComputedAuthHeaders = async ( headers: HoppRESTHeaders }, auth?: HoppRESTRequest["auth"], - parse = true, showKeyIfSecret = false ) => { const request = auth ? { auth: auth ?? { authActive: false } } : req @@ -160,18 +159,11 @@ export const getComputedHeaders = async ( headers: HoppRESTHeaders }, envVars: Environment["variables"], - parse = true, showKeyIfSecret = false ): Promise => { return [ ...( - await getComputedAuthHeaders( - envVars, - req, - undefined, - parse, - showKeyIfSecret - ) + await getComputedAuthHeaders(envVars, req, undefined, showKeyIfSecret) ).map((header) => ({ source: "auth" as const, header, @@ -368,9 +360,9 @@ export async function getEffectiveRESTRequest( showKeyIfSecret = false ): Promise { const effectiveFinalHeaders = pipe( - (await getComputedHeaders(request, environment.variables)).map( - (h) => h.header - ), + ( + await getComputedHeaders(request, environment.variables, showKeyIfSecret) + ).map((h) => h.header), A.concat(request.headers), A.filter((x) => x.active && x.key !== ""), A.map((x) => ({