@pnpm/exe 11.0.0-beta.2 → 11.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/node_modules/@gar/promise-retry/LICENSE +1 -0
  2. package/dist/node_modules/@gar/promise-retry/lib/index.js +43 -9
  3. package/dist/node_modules/@gar/promise-retry/lib/retry.js +109 -0
  4. package/dist/node_modules/@gar/promise-retry/package.json +1 -4
  5. package/dist/node_modules/@npmcli/redact/LICENSE +21 -0
  6. package/dist/node_modules/@npmcli/redact/lib/deep-map.js +71 -0
  7. package/dist/node_modules/@npmcli/redact/lib/error.js +28 -0
  8. package/dist/node_modules/@npmcli/redact/lib/index.js +44 -0
  9. package/dist/node_modules/@npmcli/redact/lib/matchers.js +88 -0
  10. package/dist/node_modules/@npmcli/redact/lib/server.js +59 -0
  11. package/dist/node_modules/@npmcli/redact/lib/utils.js +202 -0
  12. package/dist/node_modules/{unique-slug → @npmcli/redact}/package.json +21 -18
  13. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +3 -1
  14. package/dist/node_modules/brace-expansion/dist/esm/index.js +3 -1
  15. package/dist/node_modules/brace-expansion/package.json +1 -1
  16. package/dist/node_modules/cacache/lib/content/write.js +2 -2
  17. package/dist/node_modules/cacache/lib/entry-index.js +2 -2
  18. package/dist/node_modules/cacache/lib/util/tmp.js +6 -0
  19. package/dist/node_modules/cacache/package.json +4 -5
  20. package/dist/node_modules/make-fetch-happen/lib/remote.js +4 -2
  21. package/dist/node_modules/make-fetch-happen/package.json +2 -1
  22. package/dist/node_modules/picomatch/lib/constants.js +4 -0
  23. package/dist/node_modules/picomatch/lib/parse.js +301 -0
  24. package/dist/node_modules/picomatch/lib/picomatch.js +11 -3
  25. package/dist/node_modules/picomatch/package.json +2 -3
  26. package/dist/node_modules/tar/dist/commonjs/create.js +3 -4
  27. package/dist/node_modules/tar/dist/commonjs/get-write-flag.js +7 -4
  28. package/dist/node_modules/tar/dist/commonjs/header.js +14 -27
  29. package/dist/node_modules/tar/dist/commonjs/index.min.js +3 -3
  30. package/dist/node_modules/tar/dist/commonjs/list.js +2 -7
  31. package/dist/node_modules/tar/dist/commonjs/make-command.js +3 -12
  32. package/dist/node_modules/tar/dist/commonjs/mkdir.js +5 -6
  33. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js +1 -1
  34. package/dist/node_modules/tar/dist/commonjs/pack.js +3 -8
  35. package/dist/node_modules/tar/dist/commonjs/parse.js +12 -22
  36. package/dist/node_modules/tar/dist/commonjs/path-reservations.js +2 -2
  37. package/dist/node_modules/tar/dist/commonjs/read-entry.js +2 -6
  38. package/dist/node_modules/tar/dist/commonjs/replace.js +5 -10
  39. package/dist/node_modules/tar/dist/commonjs/unpack.js +38 -63
  40. package/dist/node_modules/tar/dist/commonjs/winchars.js +1 -1
  41. package/dist/node_modules/tar/dist/commonjs/write-entry.js +12 -13
  42. package/dist/node_modules/tar/dist/esm/create.js +3 -4
  43. package/dist/node_modules/tar/dist/esm/get-write-flag.js +7 -4
  44. package/dist/node_modules/tar/dist/esm/header.js +14 -27
  45. package/dist/node_modules/tar/dist/esm/index.min.js +3 -3
  46. package/dist/node_modules/tar/dist/esm/list.js +2 -7
  47. package/dist/node_modules/tar/dist/esm/make-command.js +3 -12
  48. package/dist/node_modules/tar/dist/esm/mkdir.js +5 -6
  49. package/dist/node_modules/tar/dist/esm/normalize-windows-path.js +1 -1
  50. package/dist/node_modules/tar/dist/esm/pack.js +4 -9
  51. package/dist/node_modules/tar/dist/esm/parse.js +13 -23
  52. package/dist/node_modules/tar/dist/esm/path-reservations.js +2 -2
  53. package/dist/node_modules/tar/dist/esm/read-entry.js +2 -6
  54. package/dist/node_modules/tar/dist/esm/replace.js +6 -11
  55. package/dist/node_modules/tar/dist/esm/unpack.js +38 -63
  56. package/dist/node_modules/tar/dist/esm/winchars.js +1 -1
  57. package/dist/node_modules/tar/dist/esm/write-entry.js +14 -15
  58. package/dist/node_modules/tar/package.json +9 -4
  59. package/dist/pnpm.mjs +7586 -6579
  60. package/dist/worker.js +140 -50
  61. package/package.json +12 -9
  62. package/pn +1 -0
  63. package/pnpx +1 -0
  64. package/pnx +1 -0
  65. package/prepare.js +12 -3
  66. package/setup.js +28 -1
  67. package/dist/node_modules/imurmurhash/imurmurhash.js +0 -138
  68. package/dist/node_modules/imurmurhash/imurmurhash.min.js +0 -12
  69. package/dist/node_modules/imurmurhash/package.json +0 -40
  70. package/dist/node_modules/retry/License +0 -21
  71. package/dist/node_modules/retry/index.js +0 -1
  72. package/dist/node_modules/retry/lib/retry.js +0 -100
  73. package/dist/node_modules/retry/lib/retry_operation.js +0 -162
  74. package/dist/node_modules/retry/package.json +0 -36
  75. package/dist/node_modules/unique-filename/LICENSE +0 -5
  76. package/dist/node_modules/unique-filename/lib/index.js +0 -7
  77. package/dist/node_modules/unique-filename/package.json +0 -53
  78. package/dist/node_modules/unique-slug/LICENSE +0 -15
  79. package/dist/node_modules/unique-slug/lib/index.js +0 -11
@@ -1,3 +1,4 @@
1
+ Copyright (c) 2011 Tim Koschützki (tim@debuggable.com), Felix Geisendörfer (felix@debuggable.com)
1
2
  Copyright (c) 2014 IndigoUnited
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,9 +1,44 @@
1
- const retry = require('retry')
1
+ const { RetryOperation } = require('./retry')
2
2
 
3
- const isRetryError = (err) => err?.code === 'EPROMISERETRY' && Object.hasOwn(err, 'retried')
3
+ const createTimeout = (attempt, opts) => Math.min(Math.round((1 + (opts.randomize ? Math.random() : 0)) * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt)), opts.maxTimeout)
4
+ const isRetryError = err => err?.code === 'EPROMISERETRY' && Object.hasOwn(err, 'retried')
4
5
 
5
- async function promiseRetry (fn, options = {}) {
6
- const operation = retry.operation(options)
6
+ const promiseRetry = async (fn, options = {}) => {
7
+ let timeouts = []
8
+ if (options instanceof Array) {
9
+ timeouts = [...options]
10
+ } else {
11
+ if (options.retries === Infinity) {
12
+ options.forever = true
13
+ delete options.retries
14
+ }
15
+ const opts = {
16
+ retries: 10,
17
+ factor: 2,
18
+ minTimeout: 1 * 1000,
19
+ maxTimeout: Infinity,
20
+ randomize: false,
21
+ ...options
22
+ }
23
+ if (opts.minTimeout > opts.maxTimeout) {
24
+ throw new Error('minTimeout is greater than maxTimeout')
25
+ }
26
+ if (opts.retries) {
27
+ for (let i = 0; i < opts.retries; i++) {
28
+ timeouts.push(createTimeout(i, opts))
29
+ }
30
+ // sort the array numerically ascending (since the timeouts may be out of order at factor < 1)
31
+ timeouts.sort((a, b) => a - b)
32
+ } else if (options.forever) {
33
+ timeouts.push(createTimeout(0, opts))
34
+ }
35
+ }
36
+
37
+ const operation = new RetryOperation(timeouts, {
38
+ forever: options.forever,
39
+ unref: options.unref,
40
+ maxRetryTime: options.maxRetryTime
41
+ })
7
42
 
8
43
  return new Promise(function (resolve, reject) {
9
44
  operation.attempt(async number => {
@@ -13,13 +48,12 @@ async function promiseRetry (fn, options = {}) {
13
48
  }, number, operation)
14
49
  return resolve(result)
15
50
  } catch (err) {
16
- if (isRetryError(err)) {
17
- if (operation.retry(err.retried || new Error())) {
18
- return
19
- }
51
+ if (!isRetryError(err)) {
52
+ return reject(err)
53
+ }
54
+ if (!operation.retry(err.retried || new Error())) {
20
55
  return reject(err.retried)
21
56
  }
22
- return reject(err)
23
57
  }
24
58
  })
25
59
  })
@@ -0,0 +1,109 @@
1
+ class RetryOperation {
2
+ #attempts = 1
3
+ #cachedTimeouts = null
4
+ #errors = []
5
+ #fn = null
6
+ #maxRetryTime
7
+ #operationStart = null
8
+ #originalTimeouts
9
+ #timeouts
10
+ #timer = null
11
+ #unref
12
+
13
+ constructor (timeouts, options = {}) {
14
+ this.#originalTimeouts = [...timeouts]
15
+ this.#timeouts = [...timeouts]
16
+ this.#unref = options.unref
17
+ this.#maxRetryTime = options.maxRetryTime || Infinity
18
+ if (options.forever) {
19
+ this.#cachedTimeouts = [...this.#timeouts]
20
+ }
21
+ }
22
+
23
+ get timeouts () {
24
+ return [...this.#timeouts]
25
+ }
26
+
27
+ get errors () {
28
+ return [...this.#errors]
29
+ }
30
+
31
+ get attempts () {
32
+ return this.#attempts
33
+ }
34
+
35
+ get mainError () {
36
+ let mainError = null
37
+ if (this.#errors.length) {
38
+ let mainErrorCount = 0
39
+ const counts = {}
40
+ for (let i = 0; i < this.#errors.length; i++) {
41
+ const error = this.#errors[i]
42
+ const { message } = error
43
+ if (!counts[message]) {
44
+ counts[message] = 0
45
+ }
46
+ counts[message]++
47
+
48
+ if (counts[message] >= mainErrorCount) {
49
+ mainError = error
50
+ mainErrorCount = counts[message]
51
+ }
52
+ }
53
+ }
54
+ return mainError
55
+ }
56
+
57
+ reset () {
58
+ this.#attempts = 1
59
+ this.#timeouts = [...this.#originalTimeouts]
60
+ }
61
+
62
+ stop () {
63
+ if (this.#timer) {
64
+ clearTimeout(this.#timer)
65
+ }
66
+
67
+ this.#timeouts = []
68
+ this.#cachedTimeouts = null
69
+ }
70
+
71
+ retry (err) {
72
+ this.#errors.push(err)
73
+ if (new Date().getTime() - this.#operationStart >= this.#maxRetryTime) {
74
+ // XXX This puts the timeout error first, meaning it will never show as mainError, there may be no way to ever see this
75
+ this.#errors.unshift(new Error('RetryOperation timeout occurred'))
76
+ return false
77
+ }
78
+
79
+ let timeout = this.#timeouts.shift()
80
+ if (timeout === undefined) {
81
+ // We're out of timeouts, clear the last error and repeat the final timeout
82
+ if (this.#cachedTimeouts) {
83
+ this.#errors.pop()
84
+ timeout = this.#cachedTimeouts.at(-1)
85
+ } else {
86
+ return false
87
+ }
88
+ }
89
+
90
+ // TODO what if there already is a timer?
91
+ this.#timer = setTimeout(() => {
92
+ this.#attempts++
93
+ this.#fn(this.#attempts)
94
+ }, timeout)
95
+
96
+ if (this.#unref) {
97
+ this.#timer.unref()
98
+ }
99
+
100
+ return true
101
+ }
102
+
103
+ attempt (fn) {
104
+ this.#fn = fn
105
+ this.#operationStart = new Date().getTime()
106
+ this.#fn(this.#attempts)
107
+ }
108
+ }
109
+ module.exports = { RetryOperation }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gar/promise-retry",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Retries a function that returns a promise, leveraging the power of the retry module.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -39,9 +39,6 @@
39
39
  "replay"
40
40
  ],
41
41
  "license": "MIT",
42
- "dependencies": {
43
- "retry": "^0.13.1"
44
- },
45
42
  "engines": {
46
43
  "node": "^20.17.0 || >=22.9.0"
47
44
  }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 npm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ const { serializeError } = require('./error')
2
+
3
+ const deepMap = (input, handler = v => v, path = ['$'], seen = new Set([input])) => {
4
+ // this is in an effort to maintain bole's error logging behavior
5
+ if (path.join('.') === '$' && input instanceof Error) {
6
+ return deepMap({ err: serializeError(input) }, handler, path, seen)
7
+ }
8
+ if (input instanceof Error) {
9
+ return deepMap(serializeError(input), handler, path, seen)
10
+ }
11
+ // allows for non-node js environments, sush as workers
12
+ if (typeof Buffer !== 'undefined' && input instanceof Buffer) {
13
+ return `[unable to log instanceof buffer]`
14
+ }
15
+ if (input instanceof Uint8Array) {
16
+ return `[unable to log instanceof Uint8Array]`
17
+ }
18
+
19
+ if (Array.isArray(input)) {
20
+ const result = []
21
+ for (let i = 0; i < input.length; i++) {
22
+ const element = input[i]
23
+ const elementPath = [...path, i]
24
+ if (element instanceof Object) {
25
+ if (!seen.has(element)) { // avoid getting stuck in circular reference
26
+ seen.add(element)
27
+ result.push(deepMap(handler(element, elementPath), handler, elementPath, seen))
28
+ }
29
+ } else {
30
+ result.push(handler(element, elementPath))
31
+ }
32
+ }
33
+ return result
34
+ }
35
+
36
+ if (input === null) {
37
+ return null
38
+ } else if (typeof input === 'object' || typeof input === 'function') {
39
+ const result = {}
40
+
41
+ for (const propertyName of Object.getOwnPropertyNames(input)) {
42
+ // skip logging internal properties
43
+ if (propertyName.startsWith('_')) {
44
+ continue
45
+ }
46
+
47
+ try {
48
+ const property = input[propertyName]
49
+ const propertyPath = [...path, propertyName]
50
+ if (property instanceof Object) {
51
+ if (!seen.has(property)) { // avoid getting stuck in circular reference
52
+ seen.add(property)
53
+ result[propertyName] = deepMap(
54
+ handler(property, propertyPath), handler, propertyPath, seen
55
+ )
56
+ }
57
+ } else {
58
+ result[propertyName] = handler(property, propertyPath)
59
+ }
60
+ } catch (err) {
61
+ // a getter may throw an error
62
+ result[propertyName] = `[error getting value: ${err.message}]`
63
+ }
64
+ }
65
+ return result
66
+ }
67
+
68
+ return handler(input, path)
69
+ }
70
+
71
+ module.exports = { deepMap }
@@ -0,0 +1,28 @@
1
+ /** takes an error object and serializes it to a plan object */
2
+ function serializeError (input) {
3
+ if (!(input instanceof Error)) {
4
+ if (typeof input === 'string') {
5
+ const error = new Error(`attempted to serialize a non-error, string String, "${input}"`)
6
+ return serializeError(error)
7
+ }
8
+ const error = new Error(`attempted to serialize a non-error, ${typeof input} ${input?.constructor?.name}`)
9
+ return serializeError(error)
10
+ }
11
+ // different error objects store status code differently
12
+ // AxiosError uses `status`, other services use `statusCode`
13
+ const statusCode = input.statusCode ?? input.status
14
+ // CAUTION: what we serialize here gets add to the size of logs
15
+ return {
16
+ errorType: input.errorType ?? input.constructor.name,
17
+ ...(input.message ? { message: input.message } : {}),
18
+ ...(input.stack ? { stack: input.stack } : {}),
19
+ // think of this as error code
20
+ ...(input.code ? { code: input.code } : {}),
21
+ // think of this as http status code
22
+ ...(statusCode ? { statusCode } : {}),
23
+ }
24
+ }
25
+
26
+ module.exports = {
27
+ serializeError,
28
+ }
@@ -0,0 +1,44 @@
1
+ const matchers = require('./matchers')
2
+ const { redactUrlPassword } = require('./utils')
3
+
4
+ const REPLACE = '***'
5
+
6
+ const redact = (value) => {
7
+ if (typeof value !== 'string' || !value) {
8
+ return value
9
+ }
10
+ return redactUrlPassword(value, REPLACE)
11
+ .replace(matchers.NPM_SECRET.pattern, `npm_${REPLACE}`)
12
+ .replace(matchers.UUID.pattern, REPLACE)
13
+ }
14
+
15
+ // split on \s|= similar to how nopt parses options
16
+ const splitAndRedact = (str) => {
17
+ // stateful regex, don't move out of this scope
18
+ const splitChars = /[\s=]/g
19
+
20
+ let match = null
21
+ let result = ''
22
+ let index = 0
23
+ while (match = splitChars.exec(str)) {
24
+ result += redact(str.slice(index, match.index)) + match[0]
25
+ index = splitChars.lastIndex
26
+ }
27
+
28
+ return result + redact(str.slice(index))
29
+ }
30
+
31
+ // replaces auth info in an array of arguments or in a strings
32
+ const redactLog = (arg) => {
33
+ if (typeof arg === 'string') {
34
+ return splitAndRedact(arg)
35
+ } else if (Array.isArray(arg)) {
36
+ return arg.map((a) => typeof a === 'string' ? splitAndRedact(a) : a)
37
+ }
38
+ return arg
39
+ }
40
+
41
+ module.exports = {
42
+ redact,
43
+ redactLog,
44
+ }
@@ -0,0 +1,88 @@
1
+ const TYPE_REGEX = 'regex'
2
+ const TYPE_URL = 'url'
3
+ const TYPE_PATH = 'path'
4
+
5
+ const NPM_SECRET = {
6
+ type: TYPE_REGEX,
7
+ pattern: /\b(npms?_)[a-zA-Z0-9]{36,48}\b/gi,
8
+ replacement: `[REDACTED_NPM_SECRET]`,
9
+ }
10
+
11
+ const AUTH_HEADER = {
12
+ type: TYPE_REGEX,
13
+ pattern: /\b(Basic\s+|Bearer\s+)[\w+=\-.]+\b/gi,
14
+ replacement: `[REDACTED_AUTH_HEADER]`,
15
+ }
16
+
17
+ const JSON_WEB_TOKEN = {
18
+ type: TYPE_REGEX,
19
+ pattern: /\b[A-Za-z0-9-_]{10,}(?!\.\d+\.)\.[A-Za-z0-9-_]{3,}\.[A-Za-z0-9-_]{20,}\b/gi,
20
+ replacement: `[REDACTED_JSON_WEB_TOKEN]`,
21
+ }
22
+
23
+ const UUID = {
24
+ type: TYPE_REGEX,
25
+ pattern: /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi,
26
+ replacement: `[REDACTED_UUID]`,
27
+ }
28
+
29
+ const URL_MATCHER = {
30
+ type: TYPE_REGEX,
31
+ pattern: /(?:https?|ftp):\/\/[^\s/"$.?#].[^\s"]*/gi,
32
+ replacement: '[REDACTED_URL]',
33
+ }
34
+
35
+ const DEEP_HEADER_AUTHORIZATION = {
36
+ type: TYPE_PATH,
37
+ predicate: ({ path }) => path.endsWith('.headers.authorization'),
38
+ replacement: '[REDACTED_HEADER_AUTHORIZATION]',
39
+ }
40
+
41
+ const DEEP_HEADER_SET_COOKIE = {
42
+ type: TYPE_PATH,
43
+ predicate: ({ path }) => path.endsWith('.headers.set-cookie'),
44
+ replacement: '[REDACTED_HEADER_SET_COOKIE]',
45
+ }
46
+
47
+ const DEEP_HEADER_COOKIE = {
48
+ type: TYPE_PATH,
49
+ predicate: ({ path }) => path.endsWith('.headers.cookie'),
50
+ replacement: '[REDACTED_HEADER_COOKIE]',
51
+ }
52
+
53
+ const REWRITE_REQUEST = {
54
+ type: TYPE_PATH,
55
+ predicate: ({ path }) => path.endsWith('.request'),
56
+ replacement: (input) => ({
57
+ method: input?.method,
58
+ path: input?.path,
59
+ headers: input?.headers,
60
+ url: input?.url,
61
+ }),
62
+ }
63
+
64
+ const REWRITE_RESPONSE = {
65
+ type: TYPE_PATH,
66
+ predicate: ({ path }) => path.endsWith('.response'),
67
+ replacement: (input) => ({
68
+ data: input?.data,
69
+ status: input?.status,
70
+ headers: input?.headers,
71
+ }),
72
+ }
73
+
74
+ module.exports = {
75
+ TYPE_REGEX,
76
+ TYPE_URL,
77
+ TYPE_PATH,
78
+ NPM_SECRET,
79
+ AUTH_HEADER,
80
+ JSON_WEB_TOKEN,
81
+ UUID,
82
+ URL_MATCHER,
83
+ DEEP_HEADER_AUTHORIZATION,
84
+ DEEP_HEADER_SET_COOKIE,
85
+ DEEP_HEADER_COOKIE,
86
+ REWRITE_REQUEST,
87
+ REWRITE_RESPONSE,
88
+ }
@@ -0,0 +1,59 @@
1
+ const {
2
+ AUTH_HEADER,
3
+ JSON_WEB_TOKEN,
4
+ NPM_SECRET,
5
+ DEEP_HEADER_AUTHORIZATION,
6
+ DEEP_HEADER_SET_COOKIE,
7
+ REWRITE_REQUEST,
8
+ REWRITE_RESPONSE,
9
+ DEEP_HEADER_COOKIE,
10
+ } = require('./matchers')
11
+
12
+ const {
13
+ redactUrlMatcher,
14
+ redactUrlPasswordMatcher,
15
+ redactMatchers,
16
+ } = require('./utils')
17
+
18
+ const { serializeError } = require('./error')
19
+
20
+ const { deepMap } = require('./deep-map')
21
+
22
+ const _redact = redactMatchers(
23
+ NPM_SECRET,
24
+ AUTH_HEADER,
25
+ JSON_WEB_TOKEN,
26
+ DEEP_HEADER_AUTHORIZATION,
27
+ DEEP_HEADER_SET_COOKIE,
28
+ DEEP_HEADER_COOKIE,
29
+ REWRITE_REQUEST,
30
+ REWRITE_RESPONSE,
31
+ redactUrlMatcher(
32
+ redactUrlPasswordMatcher()
33
+ )
34
+ )
35
+
36
+ const redact = (input) => deepMap(input, (value, path) => _redact(value, { path }))
37
+
38
+ /** takes an error returns new error keeping some custom properties */
39
+ function redactError (input) {
40
+ const { message, ...data } = serializeError(input)
41
+ const output = new Error(redact(message))
42
+ return Object.assign(output, redact(data))
43
+ }
44
+
45
+ /** runs a function within try / catch and throws error wrapped in redactError */
46
+ function redactThrow (func) {
47
+ if (typeof func !== 'function') {
48
+ throw new Error('redactThrow expects a function')
49
+ }
50
+ return async (...args) => {
51
+ try {
52
+ return await func(...args)
53
+ } catch (error) {
54
+ throw redactError(error)
55
+ }
56
+ }
57
+ }
58
+
59
+ module.exports = { redact, redactError, redactThrow }