Skip to content

Commit eecaa74

Browse files
chore(common): fixes lint errors and clean up code (hoppscotch#5237)
Co-authored-by: nivedin <[email protected]>
1 parent fe5c07f commit eecaa74

File tree

6 files changed

+20
-41
lines changed

6 files changed

+20
-41
lines changed

packages/hoppscotch-common/src/components/http/Headers.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ watch([props.modelValue, aggregateEnvs], async () => {
576576
}
577577
})
578578
computedHeaders.value = (
579-
await getComputedHeaders(props.modelValue, resolvedEnvs, true)
579+
await getComputedHeaders(props.modelValue, resolvedEnvs)
580580
).map((header, index) => ({
581581
id: `header-${index}`,
582582
...header,

packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async function fetchUrlData() {
180180
const res = await urlFetchLogic(inputChooseGistToImportFrom.value)
181181
182182
if (E.isLeft(res)) {
183-
// @ts-ignore
183+
// @ts-expect-error Assuming error is of type Error
184184
if (isCorsError(res.left?.error)) {
185185
showCorsError.value = true
186186
} else {

packages/hoppscotch-common/src/helpers/auth/auth-types.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ export async function generateAuthHeaders(
4646
case "digest":
4747
return generateDigestAuthHeaders(auth, request, envVars, showKeyIfSecret)
4848
case "aws-signature":
49-
return generateAwsSignatureAuthHeaders(
50-
auth,
51-
request,
52-
envVars,
53-
showKeyIfSecret
54-
)
49+
return generateAwsSignatureAuthHeaders(auth, request, envVars)
5550
case "hawk":
5651
return generateHawkAuthHeaders(auth, request, envVars, showKeyIfSecret)
5752
case "jwt":
@@ -78,14 +73,9 @@ export async function generateAuthParams(
7873
case "oauth-2":
7974
return generateOAuth2AuthParams(auth, request, envVars, showKeyIfSecret)
8075
case "aws-signature":
81-
return generateAwsSignatureAuthParams(
82-
auth,
83-
request,
84-
envVars,
85-
showKeyIfSecret
86-
)
76+
return generateAwsSignatureAuthParams(auth, request, envVars)
8777
case "jwt":
88-
return generateJwtAuthParams(auth, request, envVars, showKeyIfSecret)
78+
return generateJwtAuthParams(auth, request, envVars)
8979
default:
9080
return []
9181
}

packages/hoppscotch-common/src/helpers/auth/types/aws-signature.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import {
2-
parseTemplateString,
3-
HoppRESTAuth,
4-
HoppRESTRequest,
52
Environment,
3+
HoppRESTAuth,
64
HoppRESTHeader,
75
HoppRESTParam,
6+
HoppRESTRequest,
7+
parseTemplateString,
88
} from "@hoppscotch/data"
99
import { AwsV4Signer } from "aws4fetch"
1010
import { getFinalBodyFromRequest } from "~/helpers/utils/EffectiveURL"
1111

1212
export async function generateAwsSignatureAuthHeaders(
1313
auth: HoppRESTAuth & { authType: "aws-signature" },
1414
request: HoppRESTRequest,
15-
envVars: Environment["variables"],
16-
showKeyIfSecret = false
15+
envVars: Environment["variables"]
1716
): Promise<HoppRESTHeader[]> {
1817
if (auth.addTo !== "HEADERS") return []
1918

@@ -54,8 +53,7 @@ export async function generateAwsSignatureAuthHeaders(
5453
export async function generateAwsSignatureAuthParams(
5554
auth: HoppRESTAuth & { authType: "aws-signature" },
5655
request: HoppRESTRequest,
57-
envVars: Environment["variables"],
58-
showKeyIfSecret = false
56+
envVars: Environment["variables"]
5957
): Promise<HoppRESTParam[]> {
6058
if (auth.addTo !== "QUERY_PARAMS") return []
6159

packages/hoppscotch-common/src/helpers/auth/types/jwt.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
2-
parseTemplateString,
2+
Environment,
33
generateJWTToken,
44
HoppRESTAuth,
5-
HoppRESTRequest,
6-
Environment,
75
HoppRESTHeader,
86
HoppRESTParam,
7+
HoppRESTRequest,
8+
parseTemplateString,
99
} from "@hoppscotch/data"
1010

1111
export async function generateJwtAuthHeaders(
@@ -48,8 +48,7 @@ export async function generateJwtAuthHeaders(
4848
export async function generateJwtAuthParams(
4949
auth: HoppRESTAuth & { authType: "jwt" },
5050
request: HoppRESTRequest,
51-
envVars: Environment["variables"],
52-
showKeyIfSecret = false
51+
envVars: Environment["variables"]
5352
): Promise<HoppRESTParam[]> {
5453
if (auth.addTo !== "QUERY_PARAMS") return []
5554

packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import qs from "qs"
2323
import { combineLatest, Observable } from "rxjs"
2424
import { map } from "rxjs/operators"
2525

26+
import { generateAuthHeaders, generateAuthParams } from "../auth/auth-types"
27+
import { stripComments } from "../editor/linting/jsonc"
2628
import { arrayFlatMap, arraySort } from "../functional/array"
2729
import { toFormData } from "../functional/formData"
2830
import { tupleWithSameKeysToRecord } from "../functional/record"
2931
import { isJSONContentType } from "./contenttypes"
30-
import { stripComments } from "../editor/linting/jsonc"
31-
import { generateAuthHeaders, generateAuthParams } from "../auth/auth-types"
3232

3333
export interface EffectiveHoppRESTRequest extends HoppRESTRequest {
3434
/**
@@ -61,7 +61,6 @@ export const getComputedAuthHeaders = async (
6161
headers: HoppRESTHeaders
6262
},
6363
auth?: HoppRESTRequest["auth"],
64-
parse = true,
6564
showKeyIfSecret = false
6665
) => {
6766
const request = auth ? { auth: auth ?? { authActive: false } } : req
@@ -160,18 +159,11 @@ export const getComputedHeaders = async (
160159
headers: HoppRESTHeaders
161160
},
162161
envVars: Environment["variables"],
163-
parse = true,
164162
showKeyIfSecret = false
165163
): Promise<ComputedHeader[]> => {
166164
return [
167165
...(
168-
await getComputedAuthHeaders(
169-
envVars,
170-
req,
171-
undefined,
172-
parse,
173-
showKeyIfSecret
174-
)
166+
await getComputedAuthHeaders(envVars, req, undefined, showKeyIfSecret)
175167
).map((header) => ({
176168
source: "auth" as const,
177169
header,
@@ -368,9 +360,9 @@ export async function getEffectiveRESTRequest(
368360
showKeyIfSecret = false
369361
): Promise<EffectiveHoppRESTRequest> {
370362
const effectiveFinalHeaders = pipe(
371-
(await getComputedHeaders(request, environment.variables)).map(
372-
(h) => h.header
373-
),
363+
(
364+
await getComputedHeaders(request, environment.variables, showKeyIfSecret)
365+
).map((h) => h.header),
374366
A.concat(request.headers),
375367
A.filter((x) => x.active && x.key !== ""),
376368
A.map((x) => ({

0 commit comments

Comments
 (0)