Skip to content

Commit

Permalink
deps: @npmcli/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Feb 18, 2025
1 parent 5df69b4 commit ee5e1aa
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 18 deletions.
14 changes: 3 additions & 11 deletions node_modules/@npmcli/redact/lib/deep-map.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
function filterError (input) {
return {
errorType: input.name,
message: input.message,
stack: input.stack,
...(input.code ? { code: input.code } : {}),
...(input.statusCode ? { statusCode: input.statusCode } : {}),
}
}
const { serializeError } = require('./error')

const deepMap = (input, handler = v => v, path = ['$'], seen = new Set([input])) => {
// this is in an effort to maintain bole's error logging behavior
if (path.join('.') === '$' && input instanceof Error) {
return deepMap({ err: filterError(input) }, handler, path, seen)
return deepMap({ err: serializeError(input) }, handler, path, seen)
}
if (input instanceof Error) {
return deepMap(filterError(input), handler, path, seen)
return deepMap(serializeError(input), handler, path, seen)
}
if (input instanceof Buffer) {
return `[unable to log instanceof buffer]`
Expand Down
28 changes: 28 additions & 0 deletions node_modules/@npmcli/redact/lib/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/** takes an error object and serializes it to a plan object */
function serializeError (input) {
if (!(input instanceof Error)) {
if (typeof input === 'string') {
const error = new Error(`attempted to serialize a non-error, string String, "${input}"`)
return serializeError(error)
}
const error = new Error(`attempted to serialize a non-error, ${typeof input} ${input?.constructor?.name}`)
return serializeError(error)
}
// different error objects store status code differently
// AxiosError uses `status`, other services use `statusCode`
const statusCode = input.statusCode ?? input.status
// CAUTION: what we serialize here gets add to the size of logs
return {
errorType: input.errorType ?? input.constructor.name,
...(input.message ? { message: input.message } : {}),
...(input.stack ? { stack: input.stack } : {}),
// think of this as error code
...(input.code ? { code: input.code } : {}),
// think of this as http status code
...(statusCode ? { statusCode } : {}),
}
}

module.exports = {
serializeError,
}
25 changes: 24 additions & 1 deletion node_modules/@npmcli/redact/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const {
redactMatchers,
} = require('./utils')

const { serializeError } = require('./error')

const { deepMap } = require('./deep-map')

const _redact = redactMatchers(
Expand All @@ -31,4 +33,25 @@ const _redact = redactMatchers(

const redact = (input) => deepMap(input, (value, path) => _redact(value, { path }))

module.exports = { redact }
/** takes an error returns new error keeping some custom properties */
function redactError (input) {
const { message, ...data } = serializeError(input)
const output = new Error(redact(message))
return Object.assign(output, redact(data))
}

/** runs a function within try / catch and throws error wrapped in redactError */
function redactThrow (func) {
if (typeof func !== 'function') {
throw new Error('redactThrow expects a function')
}
return async (...args) => {
try {
return await func(...args)
} catch (error) {
throw redactError(error)
}
}
}

module.exports = { redact, redactError, redactThrow }
2 changes: 1 addition & 1 deletion node_modules/@npmcli/redact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@npmcli/redact",
"version": "3.0.0",
"version": "3.1.1",
"description": "Redact sensitive npm information from output",
"main": "lib/index.js",
"exports": {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@npmcli/map-workspaces": "^4.0.2",
"@npmcli/package-json": "^6.1.1",
"@npmcli/promise-spawn": "^8.0.2",
"@npmcli/redact": "^3.0.0",
"@npmcli/redact": "^3.1.1",
"@npmcli/run-script": "^9.0.1",
"@sigstore/tuf": "^3.0.0",
"abbrev": "^3.0.0",
Expand Down Expand Up @@ -3716,9 +3716,9 @@
}
},
"node_modules/@npmcli/redact": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@npmcli/redact/-/redact-3.0.0.tgz",
"integrity": "sha512-/1uFzjVcfzqrgCeGW7+SZ4hv0qLWmKXVzFahZGJ6QuJBj6Myt9s17+JL86i76NV9YSnJRcGXJYQbAU0rn1YTCQ==",
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@npmcli/redact/-/redact-3.1.1.tgz",
"integrity": "sha512-3Hc2KGIkrvJWJqTbvueXzBeZlmvoOxc2jyX00yzr3+sNFquJg0N8hH4SAPLPVrkWIRQICVpVgjrss971awXVnA==",
"inBundle": true,
"license": "ISC",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@npmcli/map-workspaces": "^4.0.2",
"@npmcli/package-json": "^6.1.1",
"@npmcli/promise-spawn": "^8.0.2",
"@npmcli/redact": "^3.0.0",
"@npmcli/redact": "^3.1.1",
"@npmcli/run-script": "^9.0.1",
"@sigstore/tuf": "^3.0.0",
"abbrev": "^3.0.0",
Expand Down

0 comments on commit ee5e1aa

Please sign in to comment.