mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Move getHeaderValueAsString to separate utils file
This commit is contained in:
parent
78c8da6fae
commit
9a1092199d
2 changed files with 20 additions and 18 deletions
17
packages/safe-chain/src/registryProxy/http-utils.js
Normal file
17
packages/safe-chain/src/registryProxy/http-utils.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* @param {NodeJS.Dict<string | string[]> | undefined} headers
|
||||
* @param {string} headerName
|
||||
*/
|
||||
export function getHeaderValueAsString(headers, headerName) {
|
||||
if (!headers) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let header = headers[headerName];
|
||||
|
||||
if (Array.isArray(header)) {
|
||||
return header.join(", ");
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { getMinimumPackageAgeHours } from "../../../config/settings.js";
|
||||
import { ui } from "../../../environment/userInteraction.js";
|
||||
import { getHeaderValueAsString } from "../../http-utils.js";
|
||||
|
||||
const state = {
|
||||
hasSuppressedVersions: false,
|
||||
|
|
@ -80,6 +81,8 @@ export function modifyNpmInfoResponse(body, headers) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Timestamps are compared as strings.
|
||||
// This can be done because they are formatted in ISO8601, which is sortable.
|
||||
if (timestamp > cutOff) {
|
||||
deleteVersionFromJson(bodyJson, version);
|
||||
if (headers) {
|
||||
|
|
@ -173,21 +176,3 @@ function getMostRecentTag(tagList) {
|
|||
export function getHasSuppressedVersions() {
|
||||
return state.hasSuppressedVersions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NodeJS.Dict<string | string[]> | undefined} headers
|
||||
* @param {string} headerName
|
||||
*/
|
||||
function getHeaderValueAsString(headers, headerName) {
|
||||
if (!headers) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let header = headers[headerName];
|
||||
|
||||
if (Array.isArray(header)) {
|
||||
return header.join(", ");
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue