renovate 42.19.10 → 42.20.1

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 (122) hide show
  1. package/dist/config/migrate-validate.js +1 -2
  2. package/dist/config/migrate-validate.js.map +1 -1
  3. package/dist/config/migration.js +0 -1
  4. package/dist/config/migration.js.map +1 -1
  5. package/dist/config/options/index.js +1 -1
  6. package/dist/config/options/index.js.map +1 -1
  7. package/dist/instrumentation/index.js +3 -4
  8. package/dist/instrumentation/index.js.map +1 -1
  9. package/dist/modules/datasource/crate/index.js +1 -1
  10. package/dist/modules/datasource/crate/index.js.map +1 -1
  11. package/dist/modules/datasource/docker/common.js +6 -0
  12. package/dist/modules/datasource/docker/common.js.map +1 -1
  13. package/dist/modules/datasource/docker/schema.js +1 -1
  14. package/dist/modules/datasource/docker/schema.js.map +1 -1
  15. package/dist/modules/datasource/go/index.js +1 -2
  16. package/dist/modules/datasource/go/index.js.map +1 -1
  17. package/dist/modules/datasource/maven/index.js +2 -2
  18. package/dist/modules/datasource/maven/index.js.map +1 -1
  19. package/dist/modules/datasource/maven/util.js +2 -2
  20. package/dist/modules/datasource/maven/util.js.map +1 -1
  21. package/dist/modules/manager/bazel/artifacts.js +2 -2
  22. package/dist/modules/manager/bazel/artifacts.js.map +1 -1
  23. package/dist/modules/manager/maven-wrapper/artifacts.js +2 -2
  24. package/dist/modules/manager/maven-wrapper/artifacts.js.map +1 -1
  25. package/dist/modules/manager/npm/extract/common/package-file.js +2 -2
  26. package/dist/modules/manager/npm/extract/common/package-file.js.map +1 -1
  27. package/dist/modules/manager/npm/extract/yarn.js +2 -2
  28. package/dist/modules/manager/npm/extract/yarn.js.map +1 -1
  29. package/dist/modules/manager/npm/post-update/index.js +14 -18
  30. package/dist/modules/manager/npm/post-update/index.js.map +1 -1
  31. package/dist/modules/manager/npm/post-update/npm.js +4 -4
  32. package/dist/modules/manager/npm/post-update/npm.js.map +1 -1
  33. package/dist/modules/manager/npm/post-update/pnpm.js +4 -4
  34. package/dist/modules/manager/npm/post-update/pnpm.js.map +1 -1
  35. package/dist/modules/manager/npm/post-update/yarn.js +6 -6
  36. package/dist/modules/manager/npm/post-update/yarn.js.map +1 -1
  37. package/dist/modules/manager/npm/update/dependency/index.js +3 -4
  38. package/dist/modules/manager/npm/update/dependency/index.js.map +1 -1
  39. package/dist/modules/manager/npm/update/dependency/pnpm.js +2 -2
  40. package/dist/modules/manager/npm/update/dependency/pnpm.js.map +1 -1
  41. package/dist/modules/manager/npm/update/index.js +1 -0
  42. package/dist/modules/manager/npm/update/index.js.map +1 -1
  43. package/dist/modules/manager/npm/update/locked-dependency/common/parent-version.js +8 -8
  44. package/dist/modules/manager/npm/update/locked-dependency/common/parent-version.js.map +1 -1
  45. package/dist/modules/manager/npm/update/locked-dependency/package-lock/dep-constraints.js +2 -2
  46. package/dist/modules/manager/npm/update/locked-dependency/package-lock/dep-constraints.js.map +1 -1
  47. package/dist/modules/manager/npm/update/locked-dependency/package-lock/index.js +5 -5
  48. package/dist/modules/manager/npm/update/locked-dependency/package-lock/index.js.map +1 -1
  49. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/get-locked.js +4 -4
  50. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/get-locked.js.map +1 -1
  51. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/index.js +2 -2
  52. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/index.js.map +1 -1
  53. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/replace.js +2 -2
  54. package/dist/modules/manager/npm/update/locked-dependency/yarn-lock/replace.js.map +1 -1
  55. package/dist/modules/manager/npm/update/package-version/index.js +1 -2
  56. package/dist/modules/manager/npm/update/package-version/index.js.map +1 -1
  57. package/dist/modules/manager/npm/utils.js +8 -8
  58. package/dist/modules/manager/npm/utils.js.map +1 -1
  59. package/dist/modules/platform/azure/azure-helper.js +2 -2
  60. package/dist/modules/platform/azure/azure-helper.js.map +1 -1
  61. package/dist/modules/platform/azure/index.js +14 -14
  62. package/dist/modules/platform/azure/index.js.map +1 -1
  63. package/dist/modules/platform/bitbucket/comments.js +4 -4
  64. package/dist/modules/platform/bitbucket/comments.js.map +1 -1
  65. package/dist/modules/platform/bitbucket/index.js +31 -31
  66. package/dist/modules/platform/bitbucket/index.js.map +1 -1
  67. package/dist/modules/platform/bitbucket/utils.js +2 -2
  68. package/dist/modules/platform/bitbucket/utils.js.map +1 -1
  69. package/dist/modules/platform/bitbucket-server/index.js +32 -34
  70. package/dist/modules/platform/bitbucket-server/index.js.map +1 -1
  71. package/dist/modules/platform/bitbucket-server/utils.js +2 -4
  72. package/dist/modules/platform/bitbucket-server/utils.js.map +1 -1
  73. package/dist/modules/platform/codecommit/codecommit-client.js +6 -6
  74. package/dist/modules/platform/codecommit/codecommit-client.js.map +1 -1
  75. package/dist/modules/platform/codecommit/index.js +24 -24
  76. package/dist/modules/platform/codecommit/index.js.map +1 -1
  77. package/dist/modules/platform/gitea/index.js +4 -4
  78. package/dist/modules/platform/gitea/index.js.map +1 -1
  79. package/dist/modules/platform/github/index.js +68 -68
  80. package/dist/modules/platform/github/index.js.map +1 -1
  81. package/dist/modules/platform/github/massage-markdown-links.js +2 -2
  82. package/dist/modules/platform/github/massage-markdown-links.js.map +1 -1
  83. package/dist/modules/platform/github/pr.js +2 -2
  84. package/dist/modules/platform/github/pr.js.map +1 -1
  85. package/dist/modules/platform/github/schema.js +1 -2
  86. package/dist/modules/platform/github/schema.js.map +1 -1
  87. package/dist/modules/platform/gitlab/index.js +29 -30
  88. package/dist/modules/platform/gitlab/index.js.map +1 -1
  89. package/dist/modules/platform/utils/pr-body.js +7 -3
  90. package/dist/modules/platform/utils/pr-body.js.map +1 -1
  91. package/dist/proxy.js +1 -2
  92. package/dist/proxy.js.map +1 -1
  93. package/dist/util/cache/package/index.js +2 -2
  94. package/dist/util/cache/package/index.js.map +1 -1
  95. package/dist/util/cache/package/namespaces.js +1 -1
  96. package/dist/util/cache/package/namespaces.js.map +1 -1
  97. package/dist/util/git/error.js +5 -4
  98. package/dist/util/git/error.js.map +1 -1
  99. package/dist/util/git/index.js +10 -12
  100. package/dist/util/git/index.js.map +1 -1
  101. package/dist/util/git/private-key.js +2 -0
  102. package/dist/util/git/private-key.js.map +1 -1
  103. package/dist/util/http/bitbucket.js +1 -2
  104. package/dist/util/http/bitbucket.js.map +1 -1
  105. package/dist/util/http/cache/abstract-http-cache-provider.js +2 -2
  106. package/dist/util/http/cache/abstract-http-cache-provider.js.map +1 -1
  107. package/dist/util/http/http.js +1 -1
  108. package/dist/util/http/http.js.map +1 -1
  109. package/dist/util/stats.js +1 -1
  110. package/dist/util/stats.js.map +1 -1
  111. package/dist/workers/global/config/parse/codespaces.js +1 -2
  112. package/dist/workers/global/config/parse/codespaces.js.map +1 -1
  113. package/dist/workers/repository/update/branch/auto-replace.js +4 -2
  114. package/dist/workers/repository/update/branch/auto-replace.js.map +1 -1
  115. package/dist/workers/repository/update/branch/automerge.js +4 -1
  116. package/dist/workers/repository/update/branch/automerge.js.map +1 -1
  117. package/dist/workers/repository/update/branch/execute-post-upgrade-commands.js +1 -0
  118. package/dist/workers/repository/update/branch/execute-post-upgrade-commands.js.map +1 -1
  119. package/dist/workers/repository/update/branch/index.js +16 -8
  120. package/dist/workers/repository/update/branch/index.js.map +1 -1
  121. package/package.json +3 -2
  122. package/renovate-schema.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"private-key.js","sourceRoot":"","sources":["../../../lib/util/git/private-key.ts"],"names":[],"mappings":";;AAoKA,sCAQC;AAED,0CAEC;AAED,4CAEC;;AApLD,8DAAyB;AACzB,yCAAoE;AACpE,gEAA0B;AAC1B,0DAA0B;AAC1B,mEAAqE;AACrE,yCAAsC;AACtC,kCAA+B;AAC/B,oCAA+C;AAC/C,0CAAqD;AACrD,sCAAiD;AAIjD,MAAM,WAAW,GAAG,IAAA,aAAK,EACvB,kFAAkF,EAClF,GAAG,CACJ,CAAC;AAEF,IAAI,aAA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onEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport fs from 'fs-extra';\nimport upath from 'upath';\nimport { PLATFORM_GPG_FAILED } from '../../constants/error-messages';\nimport { logger } from '../../logger';\nimport { exec } from '../exec';\nimport { newlineRegex, regEx } from '../regex';\nimport { addSecretForSanitizing } from '../sanitize';\nimport { fromBase64, toBase64 } from '../string';\n\ntype PrivateKeyFormat = 'gpg' | 'ssh';\n\nconst sshKeyRegex = regEx(\n /-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----.*?-----END (?:[A-Z]+ )?PRIVATE KEY-----/,\n 's',\n);\n\nlet gitPrivateKey: PrivateKey | undefined;\n\n/**\n * Decodes Base64 string if roundtrip encoding matches\n */\nfunction tryBase64(value: string): string | null {\n const decodedValue = fromBase64(value);\n const encodedValue = toBase64(decodedValue);\n if (value !== encodedValue) {\n return null;\n }\n\n return decodedValue;\n}\n\nabstract class PrivateKey {\n protected readonly key: string;\n protected readonly passphrase: string | undefined;\n protected keyId: string | undefined;\n protected abstract readonly gpgFormat: string;\n\n constructor(key: string, passphrase: string | undefined) {\n const decodedKey = tryBase64(key);\n\n if (decodedKey) {\n this.key = decodedKey;\n addSecretForSanitizing(key, 'global');\n logger.debug('gitPrivateKey: decoded key from Base64');\n } else {\n this.key = key;\n }\n addSecretForSanitizing(this.key, 'global');\n\n this.passphrase = passphrase;\n if (this.passphrase) {\n addSecretForSanitizing(this.passphrase, 'global');\n }\n logger.debug(\n 'gitPrivateKey: successfully set (but not yet written/configured)',\n );\n }\n\n async writeKey(): Promise<void> {\n try {\n this.keyId ??= await this.importKey();\n logger.debug('gitPrivateKey: imported');\n } catch (err) {\n logger.warn({ err }, 'gitPrivateKey: error importing');\n throw new Error(PLATFORM_GPG_FAILED);\n }\n }\n\n async configSigningKey(cwd: string): Promise<void> {\n logger.debug('gitPrivateKey: configuring commit signing');\n // TODO: types (#22198)\n await exec(`git config user.signingkey ${this.keyId!}`, { cwd });\n await exec(`git config commit.gpgsign true`, { cwd });\n await exec(`git config gpg.format ${this.gpgFormat}`, { cwd });\n }\n\n protected abstract importKey(): Promise<string | undefined>;\n}\n\nclass GPGKey extends PrivateKey {\n protected readonly gpgFormat = 'openpgp';\n\n constructor(key: string, passphrase: string | undefined) {\n super(key.trim(), passphrase);\n if (passphrase) {\n logger.warn(\n 'Passphrase is not yet supported for GPG keys, it will be ignored',\n );\n }\n }\n\n protected async importKey(): Promise<string | undefined> {\n const keyFileName = upath.join(os.tmpdir() + '/git-private-gpg.key');\n await fs.outputFile(keyFileName, this.key);\n const { stdout, stderr } = await exec(\n // --batch --no-tty flags allow Renovate to skip warnings about unsupported algorithms in the key\n `gpg --batch --no-tty --import ${keyFileName}`,\n );\n logger.debug({ stdout, stderr }, 'Private key import result');\n await fs.remove(keyFileName);\n return `${stdout}${stderr}`\n .split(newlineRegex)\n .find((line) => line.includes('secret key imported'))\n ?.replace('gpg: key ', '')\n .split(':')\n .shift();\n }\n}\n\nclass SSHKey extends PrivateKey {\n protected readonly gpgFormat = 'ssh';\n\n protected async importKey(): Promise<string | undefined> {\n const keyFileName = upath.join(os.tmpdir() + '/git-private-ssh.key');\n await fs.outputFile(keyFileName, this.key.replace(/\\n?$/, '\\n'));\n process.on('exit', () => fs.rmSync(keyFileName, { force: true }));\n await fs.chmod(keyFileName, 0o600);\n\n // If there's a passphrase, decrypt the private key and save without passphrase\n if (this.passphrase) {\n await exec(\n // -p: change passphrase\n // -f: key file\n // -P: old passphrase\n // -N: new passphrase (empty = no passphrase)\n `ssh-keygen -p -f ${keyFileName} -P \"${this.passphrase}\" -N \"\"`,\n );\n }\n\n // HACK: `git` calls `ssh-keygen -Y sign ...` internally for SSH-based\n // commit signing. Technically, only the private key is needed for signing,\n // but `ssh-keygen` has an implementation quirk which requires also the\n // public key file to exist. Therefore, we derive the public key from the\n // private key just to satisfy `ssh-keygen` until the problem has been\n // resolved.\n // https://github.com/renovatebot/renovate/issues/18197#issuecomment-2152333710\n const { stdout } = await exec(`ssh-keygen -y -f ${keyFileName}`);\n const pubFileName = `${keyFileName}.pub`;\n await fs.outputFile(pubFileName, stdout);\n process.on('exit', () => fs.rmSync(pubFileName, { force: true }));\n return keyFileName;\n }\n}\n\nfunction getPrivateKeyFormat(key: string): PrivateKeyFormat {\n return sshKeyRegex.test(key) ? 'ssh' : 'gpg';\n}\n\nfunction createPrivateKey(\n key: string,\n passphrase: string | undefined,\n): PrivateKey {\n switch (getPrivateKeyFormat(key)) {\n case 'gpg':\n logger.debug('gitPrivateKey: GPG key detected');\n return new GPGKey(key, passphrase);\n case 'ssh':\n logger.debug('gitPrivateKey: SSH key detected');\n return new SSHKey(key, passphrase);\n }\n}\n\nexport function setPrivateKey(\n key: string | undefined,\n passphrase: string | undefined,\n): void {\n if (!isNonEmptyStringAndNotWhitespace(key)) {\n return;\n }\n gitPrivateKey = createPrivateKey(key, passphrase);\n}\n\nexport async function writePrivateKey(): Promise<void> {\n await gitPrivateKey?.writeKey();\n}\n\nexport async function configSigningKey(cwd: string): Promise<void> {\n await gitPrivateKey?.configSigningKey(cwd);\n}\n"]}
1
+ {"version":3,"file":"private-key.js","sourceRoot":"","sources":["../../../lib/util/git/private-key.ts"],"names":[],"mappings":";;AAsKA,sCAQC;AAED,0CAEC;AAED,4CAEC;;AAtLD,8DAAyB;AACzB,yCAAoE;AACpE,gEAA0B;AAC1B,0DAA0B;AAC1B,mEAAqE;AACrE,yCAAsC;AACtC,kCAA+B;AAC/B,oCAA+C;AAC/C,0CAAqD;AACrD,sCAAiD;AAIjD,MAAM,WAAW,GAAG,IAAA,aAAK,EACvB,kFAAkF,EAClF,GAAG,CACJ,CAAC;AAEF,IAAI,aAAqC,CAAC;AAE1C;;GAEG;AACH,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,YAAY,GAAG,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,IAAA,iBAAQ,EAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,KAAK,KAAK,YAAY,E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,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAClE,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAED,SAAS,mBAAmB,CAAC,GAAW;IACtC,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/C,CAAC;AAED,SAAS,gBAAgB,CACvB,GAAW,EACX,UAA8B;IAE9B,QAAQ,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,KAAK,KAAK;YACR,eAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YAChD,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACrC,KAAK,KAAK;YACR,eAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YAChD,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,SAAgB,aAAa,CAC3B,GAAuB,EACvB,UAA8B;IAE9B,IAAI,CAAC,IAAA,qCAAgC,EAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAO;IACT,CAAC;IACD,aAAa,GAAG,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAEM,KAAK,UAAU,eAAe;IACnC,MAAM,aAAa,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC;AAEM,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,MAAM,aAAa,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import os from 'node:os';\nimport { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';\nimport fs from 'fs-extra';\nimport upath from 'upath';\nimport { PLATFORM_GPG_FAILED } from '../../constants/error-messages';\nimport { logger } from '../../logger';\nimport { exec } from '../exec';\nimport { newlineRegex, regEx } from '../regex';\nimport { addSecretForSanitizing } from '../sanitize';\nimport { fromBase64, toBase64 } from '../string';\n\ntype PrivateKeyFormat = 'gpg' | 'ssh';\n\nconst sshKeyRegex = regEx(\n /-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----.*?-----END (?:[A-Z]+ )?PRIVATE KEY-----/,\n 's',\n);\n\nlet gitPrivateKey: PrivateKey | undefined;\n\n/**\n * Decodes Base64 string if roundtrip encoding matches\n */\nfunction tryBase64(value: string): string | null {\n const decodedValue = fromBase64(value);\n const encodedValue = toBase64(decodedValue);\n if (value !== encodedValue) {\n return null;\n }\n\n return decodedValue;\n}\n\nabstract class PrivateKey {\n protected readonly key: string;\n protected readonly passphrase: string | undefined;\n protected keyId: string | undefined;\n protected abstract readonly gpgFormat: string;\n\n constructor(key: string, passphrase: string | undefined) {\n const decodedKey = tryBase64(key);\n\n if (decodedKey) {\n this.key = decodedKey;\n addSecretForSanitizing(key, 'global');\n logger.debug('gitPrivateKey: decoded key from Base64');\n } else {\n this.key = key;\n }\n addSecretForSanitizing(this.key, 'global');\n\n this.passphrase = passphrase;\n if (this.passphrase) {\n addSecretForSanitizing(this.passphrase, 'global');\n }\n logger.debug(\n 'gitPrivateKey: successfully set (but not yet written/configured)',\n );\n }\n\n async writeKey(): Promise<void> {\n try {\n this.keyId ??= await this.importKey();\n logger.debug('gitPrivateKey: imported');\n } catch (err) {\n logger.warn({ err }, 'gitPrivateKey: error importing');\n throw new Error(PLATFORM_GPG_FAILED);\n }\n }\n\n async configSigningKey(cwd: string): Promise<void> {\n logger.debug('gitPrivateKey: configuring commit signing');\n // TODO: types (#22198)\n await exec(`git config user.signingkey ${this.keyId!}`, { cwd });\n await exec(`git config commit.gpgsign true`, { cwd });\n await exec(`git config gpg.format ${this.gpgFormat}`, { cwd });\n }\n\n protected abstract importKey(): Promise<string | undefined>;\n}\n\nclass GPGKey extends PrivateKey {\n protected readonly gpgFormat = 'openpgp';\n\n constructor(key: string, passphrase: string | undefined) {\n super(key.trim(), passphrase);\n if (passphrase) {\n logger.warn(\n 'Passphrase is not yet supported for GPG keys, it will be ignored',\n );\n }\n }\n\n protected async importKey(): Promise<string | undefined> {\n const keyFileName = upath.join(os.tmpdir() + '/git-private-gpg.key');\n await fs.outputFile(keyFileName, this.key);\n const { stdout, stderr } = await exec(\n // --batch --no-tty flags allow Renovate to skip warnings about unsupported algorithms in the key\n `gpg --batch --no-tty --import ${keyFileName}`,\n );\n logger.debug({ stdout, stderr }, 'Private key import result');\n await fs.remove(keyFileName);\n return `${stdout}${stderr}`\n .split(newlineRegex)\n .find((line) => line.includes('secret key imported'))\n ?.replace('gpg: key ', '')\n .split(':')\n .shift();\n }\n}\n\nclass SSHKey extends PrivateKey {\n protected readonly gpgFormat = 'ssh';\n\n protected async importKey(): Promise<string | undefined> {\n const keyFileName = upath.join(os.tmpdir() + '/git-private-ssh.key');\n await fs.outputFile(keyFileName, this.key.replace(/\\n?$/, '\\n'));\n /* v8 ignore next -- not easily testable */\n process.on('exit', () => fs.rmSync(keyFileName, { force: true }));\n await fs.chmod(keyFileName, 0o600);\n\n // If there's a passphrase, decrypt the private key and save without passphrase\n if (this.passphrase) {\n await exec(\n // -p: change passphrase\n // -f: key file\n // -P: old passphrase\n // -N: new passphrase (empty = no passphrase)\n `ssh-keygen -p -f ${keyFileName} -P \"${this.passphrase}\" -N \"\"`,\n );\n }\n\n // HACK: `git` calls `ssh-keygen -Y sign ...` internally for SSH-based\n // commit signing. Technically, only the private key is needed for signing,\n // but `ssh-keygen` has an implementation quirk which requires also the\n // public key file to exist. Therefore, we derive the public key from the\n // private key just to satisfy `ssh-keygen` until the problem has been\n // resolved.\n // https://github.com/renovatebot/renovate/issues/18197#issuecomment-2152333710\n const { stdout } = await exec(`ssh-keygen -y -f ${keyFileName}`);\n const pubFileName = `${keyFileName}.pub`;\n await fs.outputFile(pubFileName, stdout);\n /* v8 ignore next -- not easily testable */\n process.on('exit', () => fs.rmSync(pubFileName, { force: true }));\n return keyFileName;\n }\n}\n\nfunction getPrivateKeyFormat(key: string): PrivateKeyFormat {\n return sshKeyRegex.test(key) ? 'ssh' : 'gpg';\n}\n\nfunction createPrivateKey(\n key: string,\n passphrase: string | undefined,\n): PrivateKey {\n switch (getPrivateKeyFormat(key)) {\n case 'gpg':\n logger.debug('gitPrivateKey: GPG key detected');\n return new GPGKey(key, passphrase);\n case 'ssh':\n logger.debug('gitPrivateKey: SSH key detected');\n return new SSHKey(key, passphrase);\n }\n}\n\nexport function setPrivateKey(\n key: string | undefined,\n passphrase: string | undefined,\n): void {\n if (!isNonEmptyStringAndNotWhitespace(key)) {\n return;\n }\n gitPrivateKey = createPrivateKey(key, passphrase);\n}\n\nexport async function writePrivateKey(): Promise<void> {\n await gitPrivateKey?.writeKey();\n}\n\nexport async function configSigningKey(cwd: string): Promise<void> {\n await gitPrivateKey?.configSigningKey(cwd);\n}\n"]}
@@ -44,11 +44,10 @@ class BitbucketHttp extends http_1.HttpBase {
44
44
  }
45
45
  // Override other page-related attributes
46
46
  resultBody.pagelen = resultBody.values.length;
47
- /* v8 ignore start -- hard to test all branches */
47
+ /* v8 ignore next -- hard to test all branches */
48
48
  resultBody.size =
49
49
  page <= MAX_PAGES ? resultBody.values.length : undefined;
50
50
  resultBody.next = page <= MAX_PAGES ? nextURL : undefined;
51
- /* v8 ignore stop */
52
51
  }
53
52
  return result;
54
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../../lib/util/http/bitbucket.ts"],"names":[],"mappings":";;;AAUA,gCAEC;AAZD,yCAAuE;AAEvE,iCAAkE;AAGlE,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,IAAI,OAAO,GAAG,4BAA4B,CAAC;AAE3C,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,GAAG,CAAC;AAChB,CAAC;AAOD,MAAa,aAAc,SAAQ,eAA8B;IAC/D,IAAuB,OAAO;QAC5B,OAAO,OAAO,CA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AAC,iBAAiB,CAC9C,MAAM,EACN,IAAI,CACL,CAAC;gBAEF,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAClD,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YACjC,CAAC;YAED,yCAAyC;YACzC,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;YAC9C,kDAAkD;YAClD,UAAU,CAAC,IAAI;gBACb,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;YAC3D,UAAU,CAAC,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1D,oBAAoB;QACtB,CAAC;QAED,OAAO,MAAyB,CAAC;IACnC,CAAC;CACF;AA5DD,sCA4DC;AAED,SAAS,UAAU,CAAC,GAAQ;IAC1B,OAAO,CAAC,IAAA,sBAAiB,EAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,aAAa,CAAI,GAAQ;IAChC,OAAO,IAAA,qBAAgB,EAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import { isNonEmptyObject, isNullOrUndefined } from '@sindresorhus/is';\nimport type { PagedResult } from '../../modules/platform/bitbucket/types';\nimport { HttpBase, type InternalJsonUnsafeOptions } from './http';\nimport type { HttpMethod, HttpOptions, HttpResponse } from './types';\n\nconst MAX_PAGES = 100;\nconst MAX_PAGELEN = 100;\n\nlet baseUrl = 'https://api.bitbucket.org/';\n\nexport function setBaseUrl(url: string): void {\n baseUrl = url;\n}\n\nexport interface BitbucketHttpOptions extends HttpOptions {\n paginate?: boolean;\n pagelen?: number;\n}\n\nexport class BitbucketHttp extends HttpBase<BitbucketHttpOptions> {\n protected override get baseUrl(): string | undefined {\n return baseUrl;\n }\n\n constructor(type = 'bitbucket', options?: BitbucketHttpOptions) {\n super(type, options);\n }\n\n protected override async requestJsonUnsafe<T>(\n method: HttpMethod,\n options: InternalJsonUnsafeOptions<BitbucketHttpOptions>,\n ): Promise<HttpResponse<T>> {\n const resolvedUrl = this.resolveUrl(options.url, options.httpOptions);\n const opts: InternalJsonUnsafeOptions<BitbucketHttpOptions> = {\n ...options,\n url: resolvedUrl,\n };\n const paginate = opts.httpOptions?.paginate;\n\n if (paginate && !hasPagelen(resolvedUrl)) {\n const pagelen = opts.httpOptions!.pagelen ?? MAX_PAGELEN;\n resolvedUrl.searchParams.set('pagelen', pagelen.toString());\n }\n\n const result = await super.requestJsonUnsafe<T | PagedResult<T>>(\n method,\n opts,\n );\n\n if (paginate && isPagedResult(result.body)) {\n if (opts.httpOptions) {\n opts.httpOptions.memCache = false;\n }\n const resultBody = result.body;\n let nextURL = result.body.next;\n let page = 1;\n\n for (; nextURL && page <= MAX_PAGES; page++) {\n opts.url = nextURL;\n const nextResult = await super.requestJsonUnsafe<PagedResult<T>>(\n method,\n opts,\n );\n\n resultBody.values.push(...nextResult.body.values);\n nextURL = nextResult.body.next;\n }\n\n // Override other page-related attributes\n resultBody.pagelen = resultBody.values.length;\n /* v8 ignore start -- hard to test all branches */\n resultBody.size =\n page <= MAX_PAGES ? resultBody.values.length : undefined;\n resultBody.next = page <= MAX_PAGES ? nextURL : undefined;\n /* v8 ignore stop */\n }\n\n return result as HttpResponse<T>;\n }\n}\n\nfunction hasPagelen(url: URL): boolean {\n return !isNullOrUndefined(url.searchParams.get('pagelen'));\n}\n\nfunction isPagedResult<T>(obj: any): obj is PagedResult<T> {\n return isNonEmptyObject(obj) && Array.isArray(obj.values);\n}\n"]}
1
+ {"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../../lib/util/http/bitbucket.ts"],"names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ject, isNullOrUndefined } from '@sindresorhus/is';\nimport type { PagedResult } from '../../modules/platform/bitbucket/types';\nimport { HttpBase, type InternalJsonUnsafeOptions } from './http';\nimport type { HttpMethod, HttpOptions, HttpResponse } from './types';\n\nconst MAX_PAGES = 100;\nconst MAX_PAGELEN = 100;\n\nlet baseUrl = 'https://api.bitbucket.org/';\n\nexport function setBaseUrl(url: string): void {\n baseUrl = url;\n}\n\nexport interface BitbucketHttpOptions extends HttpOptions {\n paginate?: boolean;\n pagelen?: number;\n}\n\nexport class BitbucketHttp extends HttpBase<BitbucketHttpOptions> {\n protected override get baseUrl(): string | undefined {\n return baseUrl;\n }\n\n constructor(type = 'bitbucket', options?: BitbucketHttpOptions) {\n super(type, options);\n }\n\n protected override async requestJsonUnsafe<T>(\n method: HttpMethod,\n options: InternalJsonUnsafeOptions<BitbucketHttpOptions>,\n ): Promise<HttpResponse<T>> {\n const resolvedUrl = this.resolveUrl(options.url, options.httpOptions);\n const opts: InternalJsonUnsafeOptions<BitbucketHttpOptions> = {\n ...options,\n url: resolvedUrl,\n };\n const paginate = opts.httpOptions?.paginate;\n\n if (paginate && !hasPagelen(resolvedUrl)) {\n const pagelen = opts.httpOptions!.pagelen ?? MAX_PAGELEN;\n resolvedUrl.searchParams.set('pagelen', pagelen.toString());\n }\n\n const result = await super.requestJsonUnsafe<T | PagedResult<T>>(\n method,\n opts,\n );\n\n if (paginate && isPagedResult(result.body)) {\n if (opts.httpOptions) {\n opts.httpOptions.memCache = false;\n }\n const resultBody = result.body;\n let nextURL = result.body.next;\n let page = 1;\n\n for (; nextURL && page <= MAX_PAGES; page++) {\n opts.url = nextURL;\n const nextResult = await super.requestJsonUnsafe<PagedResult<T>>(\n method,\n opts,\n );\n\n resultBody.values.push(...nextResult.body.values);\n nextURL = nextResult.body.next;\n }\n\n // Override other page-related attributes\n resultBody.pagelen = resultBody.values.length;\n /* v8 ignore next -- hard to test all branches */\n resultBody.size =\n page <= MAX_PAGES ? resultBody.values.length : undefined;\n resultBody.next = page <= MAX_PAGES ? nextURL : undefined;\n }\n\n return result as HttpResponse<T>;\n }\n}\n\nfunction hasPagelen(url: URL): boolean {\n return !isNullOrUndefined(url.searchParams.get('pagelen'));\n}\n\nfunction isPagedResult<T>(obj: any): obj is PagedResult<T> {\n return isNonEmptyObject(obj) && Array.isArray(obj.values);\n}\n"]}
@@ -43,11 +43,11 @@ class AbstractHttpCacheProvider {
43
43
  httpResponse,
44
44
  timestamp,
45
45
  });
46
- /* v8 ignore start: should never happen */
46
+ /* v8 ignore next: should never happen */
47
47
  if (!newHttpCache) {
48
48
  logger_1.logger.debug(`http cache: failed to persist cache for ${url}`);
49
49
  return resp;
50
- } /* v8 ignore stop */
50
+ }
51
51
  logger_1.logger.debug(`http cache: saving ${url} (etag=${etag}, lastModified=${lastModified})`);
52
52
  await this.persist(method, url, newHttpCache);
53
53
  return resp;
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-http-cache-provider.js","sourceRoot":"","sources":["../../../../lib/util/http/cache/abstract-http-cache-provider.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,uCAA6C;AAE7C,kCAAuC;AACvC,qCAAqC;AAGrC,MAAsB,yBAAyB;IAQ7C,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,GAAW;QACnC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,kBAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,MAAc,EACd,GAAW,EACX,IAAO;QAEP,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OA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AY,GAAG,CACzE,CAAC;YACF,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,YAAyB,CAAC,CAAC;YAC3D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;YACtC,eAAM,CAAC,KAAK,CACV,sCAAsC,GAAG,SAAS,SAAS,EAAE,CAC9D,CAAC;YACF,SAAS,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAC/C,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;YAE3C,sBAAc,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,UAAU,GAAG,IAAA,mBAAY,EAC7B,SAAS,CAAC,YAA+B,EACzC,IAAI,CACL,CAAC;YACF,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;YAC9C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzGD,8DAyGC","sourcesContent":["import { logger } from '../../../logger';\nimport { HttpCacheStats } from '../../stats';\nimport type { GotOptions, HttpResponse } from '../types';\nimport { copyResponse } from '../util';\nimport { HttpCache } from './schema';\nimport type { HttpCacheProvider } from './types';\n\nexport abstract class AbstractHttpCacheProvider implements HttpCacheProvider {\n protected abstract load(method: string, url: string): Promise<unknown>;\n protected abstract persist(\n method: string,\n url: string,\n data: HttpCache,\n ): Promise<void>;\n\n async get(method: string, url: string): Promise<HttpCache | null> {\n const cache = await this.load(method, url);\n const httpCache = HttpCache.parse(cache);\n if (!httpCache) {\n return null;\n }\n\n return httpCache;\n }\n\n async setCacheHeaders<T extends Pick<GotOptions, 'headers'>>(\n method: string,\n url: string,\n opts: T,\n ): Promise<void> {\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return;\n }\n\n opts.headers ??= {};\n\n if (httpCache.etag) {\n opts.headers['If-None-Match'] = httpCache.etag;\n }\n\n if (httpCache.lastModified) {\n opts.headers['If-Modified-Since'] = httpCache.lastModified;\n }\n }\n\n bypassServer<T>(\n _method: string,\n _url: string,\n _ignoreSoftTtl: boolean,\n ): Promise<HttpResponse<T> | null> {\n return Promise.resolve(null);\n }\n\n async wrapServerResponse<T>(\n method: string,\n url: string,\n resp: HttpResponse<T>,\n ): Promise<HttpResponse<T>> {\n if (resp.statusCode === 200) {\n const etag = resp.headers?.etag;\n const lastModified = resp.headers?.['last-modified'];\n\n HttpCacheStats.incRemoteMisses(url);\n\n const httpResponse = copyResponse(resp, true);\n const timestamp = new Date().toISOString();\n\n const newHttpCache = HttpCache.parse({\n etag,\n lastModified,\n httpResponse,\n timestamp,\n });\n\n /* v8 ignore start: should never happen */\n if (!newHttpCache) {\n logger.debug(`http cache: failed to persist cache for ${url}`);\n return resp;\n } /* v8 ignore stop */\n\n logger.debug(\n `http cache: saving ${url} (etag=${etag}, lastModified=${lastModified})`,\n );\n await this.persist(method, url, newHttpCache as HttpCache);\n return resp;\n }\n\n if (resp.statusCode === 304) {\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return resp;\n }\n\n const timestamp = httpCache.timestamp;\n logger.debug(\n `http cache: Using cached response: ${url} from ${timestamp}`,\n );\n httpCache.timestamp = new Date().toISOString();\n await this.persist(method, url, httpCache);\n\n HttpCacheStats.incRemoteHits(url);\n const cachedResp = copyResponse(\n httpCache.httpResponse as HttpResponse<T>,\n true,\n );\n cachedResp.authorization = resp.authorization;\n return cachedResp;\n }\n\n return resp;\n }\n}\n"]}
1
+ {"version":3,"file":"abstract-http-cache-provider.js","sour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C,CAAC;YAE3C,sBAAc,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,UAAU,GAAG,IAAA,mBAAY,EAC7B,SAAS,CAAC,YAA+B,EACzC,IAAI,CACL,CAAC;YACF,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;YAC9C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzGD,8DAyGC","sourcesContent":["import { logger } from '../../../logger';\nimport { HttpCacheStats } from '../../stats';\nimport type { GotOptions, HttpResponse } from '../types';\nimport { copyResponse } from '../util';\nimport { HttpCache } from './schema';\nimport type { HttpCacheProvider } from './types';\n\nexport abstract class AbstractHttpCacheProvider implements HttpCacheProvider {\n protected abstract load(method: string, url: string): Promise<unknown>;\n protected abstract persist(\n method: string,\n url: string,\n data: HttpCache,\n ): Promise<void>;\n\n async get(method: string, url: string): Promise<HttpCache | null> {\n const cache = await this.load(method, url);\n const httpCache = HttpCache.parse(cache);\n if (!httpCache) {\n return null;\n }\n\n return httpCache;\n }\n\n async setCacheHeaders<T extends Pick<GotOptions, 'headers'>>(\n method: string,\n url: string,\n opts: T,\n ): Promise<void> {\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return;\n }\n\n opts.headers ??= {};\n\n if (httpCache.etag) {\n opts.headers['If-None-Match'] = httpCache.etag;\n }\n\n if (httpCache.lastModified) {\n opts.headers['If-Modified-Since'] = httpCache.lastModified;\n }\n }\n\n bypassServer<T>(\n _method: string,\n _url: string,\n _ignoreSoftTtl: boolean,\n ): Promise<HttpResponse<T> | null> {\n return Promise.resolve(null);\n }\n\n async wrapServerResponse<T>(\n method: string,\n url: string,\n resp: HttpResponse<T>,\n ): Promise<HttpResponse<T>> {\n if (resp.statusCode === 200) {\n const etag = resp.headers?.etag;\n const lastModified = resp.headers?.['last-modified'];\n\n HttpCacheStats.incRemoteMisses(url);\n\n const httpResponse = copyResponse(resp, true);\n const timestamp = new Date().toISOString();\n\n const newHttpCache = HttpCache.parse({\n etag,\n lastModified,\n httpResponse,\n timestamp,\n });\n\n /* v8 ignore next: should never happen */\n if (!newHttpCache) {\n logger.debug(`http cache: failed to persist cache for ${url}`);\n return resp;\n }\n\n logger.debug(\n `http cache: saving ${url} (etag=${etag}, lastModified=${lastModified})`,\n );\n await this.persist(method, url, newHttpCache as HttpCache);\n return resp;\n }\n\n if (resp.statusCode === 304) {\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return resp;\n }\n\n const timestamp = httpCache.timestamp;\n logger.debug(\n `http cache: Using cached response: ${url} from ${timestamp}`,\n );\n httpCache.timestamp = new Date().toISOString();\n await this.persist(method, url, httpCache);\n\n HttpCacheStats.incRemoteHits(url);\n const cachedResp = copyResponse(\n httpCache.httpResponse as HttpResponse<T>,\n true,\n );\n cachedResp.authorization = resp.authorization;\n return cachedResp;\n }\n\n return resp;\n }\n}\n"]}
@@ -101,7 +101,7 @@ class HttpBase {
101
101
  // Cache GET requests unless memCache=false
102
102
  if (memCacheKey) {
103
103
  resPromise = memCache.get(memCacheKey);
104
- /* v8 ignore start: temporary code */
104
+ /* v8 ignore next: temporary code */
105
105
  if (resPromise && !cacheProvider) {
106
106
  stats_1.ObsoleteCacheHitLogger.write(url);
107
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../lib/util/http/http.ts"],"names":[],"mappings":";;;AA+DA,kDAQC;;AAvED,yCAA8D;AAC9D,kEAA8B;AAI9B,6BAA8B;AAC9B,gDAAmD;AACnD,mEAA+D;AAC/D,iDAAuC;AACvC,yCAAsC;AACtC,gFAA2E;AAC3E,kEAA4C;AAC5C,gCAAgC;AAChC,kCAA+B;AAC/B,sCAAqD;AACrD,kDAAuC;AACvC,oCAAkD;AAClD,gCAA6D;AAC7D,kCAA0C;AAC1C,iCAAiE;AAEjE,+BAAsC;AACtC,6CAA+D;AAE/D,mCAAmC;AACnC,+CAA6D;AAC7D,yCAAyC;AAUzC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BAwnBC","sourcesContent":["import { isPlainObject, isUndefined } from '@sindresorhus/is';\nimport merge from 'deepmerge';\nimport type { Options, RetryObject } from 'got';\nimport type { Merge, SetRequired } from 'type-fest';\nimport type { infer as Infer } from 'zod';\nimport { ZodType } from 'zod';\nimport { GlobalConfig } from '../../config/global';\nimport { HOST_DISABLED } from '../../constants/error-messages';\nimport { pkg } from '../../expose.cjs';\nimport { logger } from '../../logger';\nimport { ExternalHostError } from '../../types/errors/external-host-error';\nimport * as memCache from '../cache/memory';\nimport { getEnv } from '../env';\nimport { hash } from '../hash';\nimport { type AsyncResult, Result } from '../result';\nimport { Toml } from '../schema-utils';\nimport { ObsoleteCacheHitLogger } from '../stats';\nimport { isHttpUrl, parseUrl, resolveBaseUrl } from '../url';\nimport { parseSingleYaml } from '../yaml';\nimport { applyAuthorization, removeAuthorization } from './auth';\nimport type { HttpCacheProvider } from './cache/types';\nimport { fetch, stream } from './got';\nimport { applyHostRule, findMatchingRule } from './host-rules';\n\nimport { getQueue } from './queue';\nimport { getRetryAfter, wrapWithRetry } from './retry-after';\nimport { getThrottle } from './throttle';\nimport type {\n GotOptions,\n GotStreamOptions,\n GotTask,\n HttpMethod,\n HttpOptions,\n HttpResponse,\n SafeJsonError,\n} from './types';\nimport { copyResponse } from './util';\n\nexport interface InternalJsonUnsafeOptions<\n Opts extends HttpOptions = HttpOptions,\n> {\n url: string | URL;\n httpOptions?: Opts;\n}\n\nexport interface InternalJsonOptions<\n Opts extends HttpOptions,\n ResT = unknown,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n> extends InternalJsonUnsafeOptions<Opts> {\n schema?: Schema;\n}\n\nexport type InternalGotOptions = SetRequired<GotOptions, 'method' | 'context'>;\n\nexport interface InternalHttpOptions extends HttpOptions {\n json?: HttpOptions['body'];\n\n method?: HttpMethod;\n\n parseJson?: Options['parseJson'];\n}\n\nexport function applyDefaultHeaders(options: Options): void {\n const renovateVersion = pkg.version;\n options.headers = {\n ...options.headers,\n 'user-agent':\n GlobalConfig.get('userAgent') ??\n `Renovate/${renovateVersion} (https://github.com/renovatebot/renovate)`,\n };\n}\n\nexport abstract class HttpBase<\n JSONOpts extends HttpOptions = HttpOptions,\n Opts extends HttpOptions = HttpOptions,\n> {\n private readonly options: InternalGotOptions;\n\n protected get baseUrl(): string | undefined {\n return undefined;\n }\n\n constructor(\n protected hostType: string,\n options: HttpOptions = {},\n ) {\n const retryLimit = getEnv().NODE_ENV === 'test' ? 0 : 2;\n this.options = merge<InternalGotOptions>(\n options,\n {\n method: 'get',\n context: { hostType },\n retry: {\n calculateDelay: (retryObject) =>\n this.calculateRetryDelay(retryObject),\n limit: retryLimit,\n maxRetryAfter: 0, // Don't rely on `got` retry-after handling, just let it fail and then we'll handle it\n },\n },\n { isMergeableObject: isPlainObject },\n );\n }\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions,\n ): Promise<HttpResponse<string>>;\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'text' },\n ): Promise<HttpResponse<string>>;\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'buffer' },\n ): Promise<HttpResponse<Buffer>>;\n private async request<T = unknown>(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'json' },\n ): Promise<HttpResponse<T>>;\n\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions,\n ): Promise<HttpResponse<unknown>> {\n const resolvedUrl = this.resolveUrl(requestUrl, httpOptions);\n const url = resolvedUrl.toString();\n\n this.processOptions(resolvedUrl, httpOptions);\n\n let options = merge<InternalGotOptions, InternalHttpOptions>(\n {\n ...this.options,\n hostType: this.hostType,\n },\n httpOptions,\n { isMergeableObject: isPlainObject },\n );\n\n const method = options.method.toLowerCase();\n const isReadMethod = ['head', 'get'].includes(method);\n\n logger.trace(`HTTP request: ${method.toUpperCase()} ${url}`);\n\n options.hooks = {\n beforeRedirect: [removeAuthorization],\n };\n\n applyDefaultHeaders(options);\n\n if (isUndefined(options.readOnly) && isReadMethod) {\n options.readOnly = true;\n }\n\n const hostRule = findMatchingRule(url, options);\n options = applyHostRule(url, options, hostRule);\n if (options.enabled === false) {\n logger.debug(`Host is disabled - rejecting request. HostUrl: ${url}`);\n throw new Error(HOST_DISABLED);\n }\n options = applyAuthorization(options);\n options.timeout ??= 60000;\n\n let cacheProvider: HttpCacheProvider | undefined;\n if (isReadMethod && options.cacheProvider) {\n cacheProvider = options.cacheProvider;\n }\n\n const memCacheKey =\n !process.env.RENOVATE_X_DISABLE_HTTP_MEMCACHE &&\n !cacheProvider &&\n options.memCache !== false &&\n isReadMethod\n ? hash(\n `got-${JSON.stringify({\n url,\n headers: options.headers,\n method,\n })}`,\n )\n : null;\n\n const cachedResponse = await cacheProvider?.bypassServer<unknown>(\n method,\n url,\n );\n if (cachedResponse) {\n return cachedResponse;\n }\n\n let resPromise: Promise<HttpResponse<unknown>> | null = null;\n\n // Cache GET requests unless memCache=false\n if (memCacheKey) {\n resPromise = memCache.get(memCacheKey);\n\n /* v8 ignore start: temporary code */\n if (resPromise && !cacheProvider) {\n ObsoleteCacheHitLogger.write(url);\n }\n /* v8 ignore stop: temporary code */\n }\n\n if (!resPromise) {\n if (cacheProvider) {\n await cacheProvider.setCacheHeaders(method, url, options);\n }\n\n const startTime = Date.now();\n const httpTask: GotTask = () => {\n const queueMs = Date.now() - startTime;\n return fetch(url, options, { queueMs });\n };\n\n const throttle = getThrottle(url);\n const throttledTask = throttle ? () => throttle.add(httpTask) : httpTask;\n\n const queue = getQueue(url);\n const queuedTask = queue ? () => queue.add(throttledTask) : throttledTask;\n\n const { maxRetryAfter = 60 } = hostRule;\n resPromise = wrapWithRetry(queuedTask, url, getRetryAfter, maxRetryAfter);\n\n if (memCacheKey) {\n memCache.set(memCacheKey, resPromise);\n }\n }\n\n try {\n const res = await resPromise;\n const deepCopyNeeded = !!memCacheKey && res.statusCode !== 304;\n const resCopy = copyResponse(res, deepCopyNeeded);\n resCopy.authorization = !!options?.headers?.authorization;\n\n if (cacheProvider) {\n return await cacheProvider.wrapServerResponse(method, url, resCopy);\n }\n\n return resCopy;\n } catch (err) {\n const { abortOnError, abortIgnoreStatusCodes } = options;\n if (abortOnError && !abortIgnoreStatusCodes?.includes(err.statusCode)) {\n throw new ExternalHostError(err);\n }\n\n const staleResponse = await cacheProvider?.bypassServer<string | Buffer>(\n method,\n url,\n true,\n );\n if (staleResponse) {\n logger.debug(\n { err },\n `Request error: returning stale cache instead for ${url}`,\n );\n return staleResponse;\n }\n\n this.handleError(requestUrl, httpOptions, err);\n }\n }\n\n protected processOptions(_url: URL, _options: InternalHttpOptions): void {\n // noop\n }\n\n protected handleError(\n _url: string | URL,\n _httpOptions: HttpOptions,\n err: Error,\n ): never {\n throw err;\n }\n\n resolveUrl(\n requestUrl: string | URL,\n options: HttpOptions | undefined = undefined,\n ): URL {\n let url = requestUrl;\n\n if (url instanceof URL) {\n // already a aboslute URL\n return url;\n }\n\n const baseUrl = options?.baseUrl ?? this.baseUrl;\n if (baseUrl) {\n url = resolveBaseUrl(baseUrl, url);\n }\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl || !isHttpUrl(parsedUrl)) {\n logger.error(\n { url: requestUrl, baseUrl, resolvedUrl: url },\n 'Request Error: cannot parse url',\n );\n throw new Error('Invalid URL');\n }\n return parsedUrl;\n }\n\n protected calculateRetryDelay({ computedValue }: RetryObject): number {\n return computedValue;\n }\n\n get(\n url: string,\n options: HttpOptions = {},\n ): Promise<HttpResponse<string | Buffer>> {\n return this.request(url, options);\n }\n\n head(url: string, options: HttpOptions = {}): Promise<HttpResponse<never>> {\n // to complex to validate\n return this.request(url, {\n ...options,\n responseType: 'text',\n method: 'head',\n }) as Promise<HttpResponse<never>>;\n }\n\n getText(\n url: string | URL,\n options: HttpOptions = {},\n ): Promise<HttpResponse<string>> {\n return this.request(url, { ...options, responseType: 'text' });\n }\n\n getBuffer(\n url: string | URL,\n options: HttpOptions = {},\n ): Promise<HttpResponse<Buffer>> {\n return this.request(url, { ...options, responseType: 'buffer' });\n }\n\n protected requestJsonUnsafe<ResT>(\n method: HttpMethod,\n { url, httpOptions: requestOptions }: InternalJsonUnsafeOptions<JSONOpts>,\n ): Promise<HttpResponse<ResT>> {\n const { body: json, ...httpOptions } = { ...requestOptions };\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method,\n };\n // signal that we expect a json response\n opts.headers = {\n accept: 'application/json',\n ...opts.headers,\n };\n if (json) {\n opts.json = json;\n }\n return this.request<ResT>(url, { ...opts, responseType: 'json' });\n }\n\n private async requestJson<ResT, Schema extends ZodType<ResT> = ZodType<ResT>>(\n method: HttpMethod,\n options: InternalJsonOptions<JSONOpts, ResT, Schema>,\n ): Promise<HttpResponse<ResT>> {\n const res = await this.requestJsonUnsafe<ResT>(method, options);\n\n if (options.schema) {\n res.body = await options.schema.parseAsync(res.body);\n }\n\n return res;\n }\n\n private resolveArgs<ResT = unknown>(\n arg1: string,\n arg2: JSONOpts | ZodType<ResT> | undefined,\n arg3: ZodType<ResT> | undefined,\n ): InternalJsonOptions<JSONOpts, ResT> {\n const res: InternalJsonOptions<JSONOpts, ResT> = { url: arg1 };\n\n if (arg2 instanceof ZodType) {\n res.schema = arg2;\n } else if (arg2) {\n res.httpOptions = arg2;\n }\n\n if (arg3) {\n res.schema = arg3;\n }\n\n return res;\n }\n\n async getPlain(url: string, options?: Opts): Promise<HttpResponse> {\n const opt = options ?? {};\n return await this.getText(url, {\n headers: {\n Accept: 'text/plain',\n },\n ...opt,\n });\n }\n\n /**\n * @deprecated use `getYaml` instead\n */\n async getYamlUnchecked<ResT>(\n url: string,\n options?: Opts,\n ): Promise<HttpResponse<ResT>> {\n const res = await this.getText(url, options);\n const body = parseSingleYaml<ResT>(res.body);\n return { ...res, body };\n }\n\n async getYaml<Schema extends ZodType<any, any, any>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getYaml<Schema extends ZodType<any, any, any>>(\n url: string,\n options: Opts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getYaml<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: Opts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const url = arg1;\n let schema: Schema;\n let httpOptions: Opts | undefined;\n if (arg3) {\n schema = arg3;\n httpOptions = arg2 as Opts;\n } else {\n schema = arg2 as Schema;\n }\n\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method: 'get',\n };\n\n const res = await this.getText(url, opts);\n const body = await schema.parseAsync(parseSingleYaml(res.body));\n return { ...res, body };\n }\n\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(url: string, schema: Schema): AsyncResult<Infer<Schema>, SafeJsonError>;\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(\n url: string,\n options: Opts,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(\n arg1: string,\n arg2: Opts | Schema,\n arg3?: Schema,\n ): AsyncResult<ResT, SafeJsonError> {\n const url = arg1;\n let schema: Schema;\n let httpOptions: Opts | undefined;\n if (arg3) {\n schema = arg3;\n httpOptions = arg2 as Opts;\n } else {\n schema = arg2 as Schema;\n }\n\n let res: AsyncResult<HttpResponse<ResT>, SafeJsonError>;\n if (httpOptions) {\n res = Result.wrap(this.getYaml(url, httpOptions, schema));\n } else {\n res = Result.wrap(this.getYaml(url, schema));\n }\n\n return res.transform((response) => Result.ok(response.body));\n }\n\n /**\n * Request JSON and return the response without any validation.\n *\n * The usage of this method is discouraged, please use `getJson` instead.\n *\n * If you're new to Zod schema validation library:\n * - consult the [documentation of Zod library](https://github.com/colinhacks/zod?tab=readme-ov-file#basic-usage)\n * - search the Renovate codebase for 'zod' module usage\n * - take a look at the `schema-utils.ts` file for Renovate-specific schemas and utilities\n */\n getJsonUnchecked<ResT = unknown>(\n url: string,\n options?: JSONOpts,\n ): Promise<HttpResponse<ResT>> {\n return this.requestJson<ResT>('get', { url, httpOptions: options });\n }\n\n /**\n * Request JSON with a Zod schema for the response,\n * throwing an error if the response is not valid.\n *\n * @param url\n * @param schema Zod schema for the response\n */\n getJson<Schema extends ZodType<any, any, any>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n getJson<Schema extends ZodType<any, any, any>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n getJson<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const args = this.resolveArgs<Infer<Schema>>(arg1, arg2, arg3);\n return this.requestJson<Infer<Schema>>('get', args);\n }\n\n /**\n * Request JSON with a Zod schema for the response,\n * wrapping response data in a `Result` class.\n *\n * @param url\n * @param schema Zod schema for the response\n */\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n url: string,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): AsyncResult<ResT, SafeJsonError> {\n const args = this.resolveArgs<ResT>(arg1, arg2, arg3);\n return Result.wrap(this.requestJson<ResT>('get', args)).transform(\n (response) => Result.ok(response.body),\n );\n }\n\n /**\n * @deprecated use `head` instead\n */\n headJson(url: string, httpOptions?: JSONOpts): Promise<HttpResponse<never>> {\n return this.requestJson<never>('head', { url, httpOptions });\n }\n\n postJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n postJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n postJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n postJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('post', args);\n }\n\n putJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n putJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n putJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n putJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: ZodType,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('put', args);\n }\n\n patchJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n patchJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n patchJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n patchJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('patch', args);\n }\n\n deleteJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n deleteJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n deleteJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n deleteJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('delete', args);\n }\n\n stream(url: string, options?: HttpOptions): NodeJS.ReadableStream {\n let combinedOptions: Merge<\n GotStreamOptions,\n SetRequired<InternalHttpOptions, 'method'>\n > = {\n ...this.options,\n hostType: this.hostType,\n ...options,\n method: 'get',\n };\n\n const resolvedUrl = this.resolveUrl(url, options).toString();\n\n applyDefaultHeaders(combinedOptions);\n\n if (\n isUndefined(combinedOptions.readOnly) &&\n ['head', 'get'].includes(combinedOptions.method)\n ) {\n combinedOptions.readOnly = true;\n }\n\n const hostRule = findMatchingRule(url, combinedOptions);\n combinedOptions = applyHostRule(resolvedUrl, combinedOptions, hostRule);\n if (combinedOptions.enabled === false) {\n throw new Error(HOST_DISABLED);\n }\n combinedOptions = applyAuthorization(combinedOptions);\n\n return stream(resolvedUrl, combinedOptions);\n }\n\n async getToml<Schema extends ZodType<any, any, any>>(\n url: string,\n schema?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getToml<Schema extends ZodType<any, any, any>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getToml<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const { url, schema, httpOptions } = this.resolveArgs<Infer<Schema>>(\n arg1,\n arg2,\n arg3,\n );\n\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method: 'get',\n headers: {\n 'Content-Type': 'application/toml',\n ...httpOptions?.headers,\n },\n };\n\n const res = await this.getText(url, opts);\n if (schema) {\n res.body = await Toml.pipe(schema).parseAsync(res.body);\n } else {\n res.body = (await Toml.parseAsync(res.body)) as Infer<Schema>;\n }\n\n return res;\n }\n}\n"]}
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../../lib/util/http/http.ts"],"names":[],"mappings":";;;AA+DA,kDAQC;;AAvED,yCAA8D;AAC9D,kEAA8B;AAI9B,6BAA8B;AAC9B,gDAAmD;AACnD,mEAA+D;AAC/D,iDAAuC;AACvC,yCAAsC;AACtC,gFAA2E;AAC3E,kEAA4C;AAC5C,gCAAgC;AAChC,kCAA+B;AAC/B,sCAAqD;AACrD,kDAAuC;AACvC,oCAAkD;AAClD,gCAA6D;AAC7D,kCAA0C;AAC1C,iCAAiE;AAEjE,+BAAsC;AACtC,6CAA+D;AAE/D,mCAAmC;AACnC,+CAA6D;AAC7D,yCAAyC;AAUzC,iCAAsC;AA2BtC,SAAgB,mBAAmB,CAAC,OAAgB;IAClD,MAAM,eAAe,GAAG,gBAAG,CAAC,OAAO,CAAC;IACpC,OAAO,CAAC,OAAO,GAAG;QAChB,GAAG,OAAO,CAAC,OAAO;QAClB,YAAY,EACV,qBAAY,CAAC,GAAG,CAAC,WAAW,CAAC;YAC7B,YAAY,eAAe,4CAA4C;KAC1E,CAAC;AACJ,CAAC;AAED,MAAsB,QAAQ;IAWhB;IAPK,OAAO,CAAqB;IAE7C,IAAc,OAAO;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,YACY,QAAgB,EAC1B,UAAuB,EAAE;QADf,aAAQ,GAAR,QAAQ,CAAQ;QAG1B,MAAM,UAAU,GAAG,IAAA,YAAM,GAAE,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAK,EAClB,OAAO,EACP;YACE,MAAM,EAAE,KA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I,CACL,CAAC;QAEF,MAAM,IAAI,GAAwB;YAChC,GAAG,WAAW;YACd,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,WAAW,EAAE,OAAO;aACxB;SACF,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,GAAG,MAAM,mBAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,mBAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAkB,CAAC;QAChE,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAxnBD,4BAwnBC","sourcesContent":["import { isPlainObject, isUndefined } from '@sindresorhus/is';\nimport merge from 'deepmerge';\nimport type { Options, RetryObject } from 'got';\nimport type { Merge, SetRequired } from 'type-fest';\nimport type { infer as Infer } from 'zod';\nimport { ZodType } from 'zod';\nimport { GlobalConfig } from '../../config/global';\nimport { HOST_DISABLED } from '../../constants/error-messages';\nimport { pkg } from '../../expose.cjs';\nimport { logger } from '../../logger';\nimport { ExternalHostError } from '../../types/errors/external-host-error';\nimport * as memCache from '../cache/memory';\nimport { getEnv } from '../env';\nimport { hash } from '../hash';\nimport { type AsyncResult, Result } from '../result';\nimport { Toml } from '../schema-utils';\nimport { ObsoleteCacheHitLogger } from '../stats';\nimport { isHttpUrl, parseUrl, resolveBaseUrl } from '../url';\nimport { parseSingleYaml } from '../yaml';\nimport { applyAuthorization, removeAuthorization } from './auth';\nimport type { HttpCacheProvider } from './cache/types';\nimport { fetch, stream } from './got';\nimport { applyHostRule, findMatchingRule } from './host-rules';\n\nimport { getQueue } from './queue';\nimport { getRetryAfter, wrapWithRetry } from './retry-after';\nimport { getThrottle } from './throttle';\nimport type {\n GotOptions,\n GotStreamOptions,\n GotTask,\n HttpMethod,\n HttpOptions,\n HttpResponse,\n SafeJsonError,\n} from './types';\nimport { copyResponse } from './util';\n\nexport interface InternalJsonUnsafeOptions<\n Opts extends HttpOptions = HttpOptions,\n> {\n url: string | URL;\n httpOptions?: Opts;\n}\n\nexport interface InternalJsonOptions<\n Opts extends HttpOptions,\n ResT = unknown,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n> extends InternalJsonUnsafeOptions<Opts> {\n schema?: Schema;\n}\n\nexport type InternalGotOptions = SetRequired<GotOptions, 'method' | 'context'>;\n\nexport interface InternalHttpOptions extends HttpOptions {\n json?: HttpOptions['body'];\n\n method?: HttpMethod;\n\n parseJson?: Options['parseJson'];\n}\n\nexport function applyDefaultHeaders(options: Options): void {\n const renovateVersion = pkg.version;\n options.headers = {\n ...options.headers,\n 'user-agent':\n GlobalConfig.get('userAgent') ??\n `Renovate/${renovateVersion} (https://github.com/renovatebot/renovate)`,\n };\n}\n\nexport abstract class HttpBase<\n JSONOpts extends HttpOptions = HttpOptions,\n Opts extends HttpOptions = HttpOptions,\n> {\n private readonly options: InternalGotOptions;\n\n protected get baseUrl(): string | undefined {\n return undefined;\n }\n\n constructor(\n protected hostType: string,\n options: HttpOptions = {},\n ) {\n const retryLimit = getEnv().NODE_ENV === 'test' ? 0 : 2;\n this.options = merge<InternalGotOptions>(\n options,\n {\n method: 'get',\n context: { hostType },\n retry: {\n calculateDelay: (retryObject) =>\n this.calculateRetryDelay(retryObject),\n limit: retryLimit,\n maxRetryAfter: 0, // Don't rely on `got` retry-after handling, just let it fail and then we'll handle it\n },\n },\n { isMergeableObject: isPlainObject },\n );\n }\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions,\n ): Promise<HttpResponse<string>>;\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'text' },\n ): Promise<HttpResponse<string>>;\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'buffer' },\n ): Promise<HttpResponse<Buffer>>;\n private async request<T = unknown>(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions & { responseType: 'json' },\n ): Promise<HttpResponse<T>>;\n\n private async request(\n requestUrl: string | URL,\n httpOptions: InternalHttpOptions,\n ): Promise<HttpResponse<unknown>> {\n const resolvedUrl = this.resolveUrl(requestUrl, httpOptions);\n const url = resolvedUrl.toString();\n\n this.processOptions(resolvedUrl, httpOptions);\n\n let options = merge<InternalGotOptions, InternalHttpOptions>(\n {\n ...this.options,\n hostType: this.hostType,\n },\n httpOptions,\n { isMergeableObject: isPlainObject },\n );\n\n const method = options.method.toLowerCase();\n const isReadMethod = ['head', 'get'].includes(method);\n\n logger.trace(`HTTP request: ${method.toUpperCase()} ${url}`);\n\n options.hooks = {\n beforeRedirect: [removeAuthorization],\n };\n\n applyDefaultHeaders(options);\n\n if (isUndefined(options.readOnly) && isReadMethod) {\n options.readOnly = true;\n }\n\n const hostRule = findMatchingRule(url, options);\n options = applyHostRule(url, options, hostRule);\n if (options.enabled === false) {\n logger.debug(`Host is disabled - rejecting request. HostUrl: ${url}`);\n throw new Error(HOST_DISABLED);\n }\n options = applyAuthorization(options);\n options.timeout ??= 60000;\n\n let cacheProvider: HttpCacheProvider | undefined;\n if (isReadMethod && options.cacheProvider) {\n cacheProvider = options.cacheProvider;\n }\n\n const memCacheKey =\n !process.env.RENOVATE_X_DISABLE_HTTP_MEMCACHE &&\n !cacheProvider &&\n options.memCache !== false &&\n isReadMethod\n ? hash(\n `got-${JSON.stringify({\n url,\n headers: options.headers,\n method,\n })}`,\n )\n : null;\n\n const cachedResponse = await cacheProvider?.bypassServer<unknown>(\n method,\n url,\n );\n if (cachedResponse) {\n return cachedResponse;\n }\n\n let resPromise: Promise<HttpResponse<unknown>> | null = null;\n\n // Cache GET requests unless memCache=false\n if (memCacheKey) {\n resPromise = memCache.get(memCacheKey);\n\n /* v8 ignore next: temporary code */\n if (resPromise && !cacheProvider) {\n ObsoleteCacheHitLogger.write(url);\n }\n /* v8 ignore stop: temporary code */\n }\n\n if (!resPromise) {\n if (cacheProvider) {\n await cacheProvider.setCacheHeaders(method, url, options);\n }\n\n const startTime = Date.now();\n const httpTask: GotTask = () => {\n const queueMs = Date.now() - startTime;\n return fetch(url, options, { queueMs });\n };\n\n const throttle = getThrottle(url);\n const throttledTask = throttle ? () => throttle.add(httpTask) : httpTask;\n\n const queue = getQueue(url);\n const queuedTask = queue ? () => queue.add(throttledTask) : throttledTask;\n\n const { maxRetryAfter = 60 } = hostRule;\n resPromise = wrapWithRetry(queuedTask, url, getRetryAfter, maxRetryAfter);\n\n if (memCacheKey) {\n memCache.set(memCacheKey, resPromise);\n }\n }\n\n try {\n const res = await resPromise;\n const deepCopyNeeded = !!memCacheKey && res.statusCode !== 304;\n const resCopy = copyResponse(res, deepCopyNeeded);\n resCopy.authorization = !!options?.headers?.authorization;\n\n if (cacheProvider) {\n return await cacheProvider.wrapServerResponse(method, url, resCopy);\n }\n\n return resCopy;\n } catch (err) {\n const { abortOnError, abortIgnoreStatusCodes } = options;\n if (abortOnError && !abortIgnoreStatusCodes?.includes(err.statusCode)) {\n throw new ExternalHostError(err);\n }\n\n const staleResponse = await cacheProvider?.bypassServer<string | Buffer>(\n method,\n url,\n true,\n );\n if (staleResponse) {\n logger.debug(\n { err },\n `Request error: returning stale cache instead for ${url}`,\n );\n return staleResponse;\n }\n\n this.handleError(requestUrl, httpOptions, err);\n }\n }\n\n protected processOptions(_url: URL, _options: InternalHttpOptions): void {\n // noop\n }\n\n protected handleError(\n _url: string | URL,\n _httpOptions: HttpOptions,\n err: Error,\n ): never {\n throw err;\n }\n\n resolveUrl(\n requestUrl: string | URL,\n options: HttpOptions | undefined = undefined,\n ): URL {\n let url = requestUrl;\n\n if (url instanceof URL) {\n // already a aboslute URL\n return url;\n }\n\n const baseUrl = options?.baseUrl ?? this.baseUrl;\n if (baseUrl) {\n url = resolveBaseUrl(baseUrl, url);\n }\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl || !isHttpUrl(parsedUrl)) {\n logger.error(\n { url: requestUrl, baseUrl, resolvedUrl: url },\n 'Request Error: cannot parse url',\n );\n throw new Error('Invalid URL');\n }\n return parsedUrl;\n }\n\n protected calculateRetryDelay({ computedValue }: RetryObject): number {\n return computedValue;\n }\n\n get(\n url: string,\n options: HttpOptions = {},\n ): Promise<HttpResponse<string | Buffer>> {\n return this.request(url, options);\n }\n\n head(url: string, options: HttpOptions = {}): Promise<HttpResponse<never>> {\n // to complex to validate\n return this.request(url, {\n ...options,\n responseType: 'text',\n method: 'head',\n }) as Promise<HttpResponse<never>>;\n }\n\n getText(\n url: string | URL,\n options: HttpOptions = {},\n ): Promise<HttpResponse<string>> {\n return this.request(url, { ...options, responseType: 'text' });\n }\n\n getBuffer(\n url: string | URL,\n options: HttpOptions = {},\n ): Promise<HttpResponse<Buffer>> {\n return this.request(url, { ...options, responseType: 'buffer' });\n }\n\n protected requestJsonUnsafe<ResT>(\n method: HttpMethod,\n { url, httpOptions: requestOptions }: InternalJsonUnsafeOptions<JSONOpts>,\n ): Promise<HttpResponse<ResT>> {\n const { body: json, ...httpOptions } = { ...requestOptions };\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method,\n };\n // signal that we expect a json response\n opts.headers = {\n accept: 'application/json',\n ...opts.headers,\n };\n if (json) {\n opts.json = json;\n }\n return this.request<ResT>(url, { ...opts, responseType: 'json' });\n }\n\n private async requestJson<ResT, Schema extends ZodType<ResT> = ZodType<ResT>>(\n method: HttpMethod,\n options: InternalJsonOptions<JSONOpts, ResT, Schema>,\n ): Promise<HttpResponse<ResT>> {\n const res = await this.requestJsonUnsafe<ResT>(method, options);\n\n if (options.schema) {\n res.body = await options.schema.parseAsync(res.body);\n }\n\n return res;\n }\n\n private resolveArgs<ResT = unknown>(\n arg1: string,\n arg2: JSONOpts | ZodType<ResT> | undefined,\n arg3: ZodType<ResT> | undefined,\n ): InternalJsonOptions<JSONOpts, ResT> {\n const res: InternalJsonOptions<JSONOpts, ResT> = { url: arg1 };\n\n if (arg2 instanceof ZodType) {\n res.schema = arg2;\n } else if (arg2) {\n res.httpOptions = arg2;\n }\n\n if (arg3) {\n res.schema = arg3;\n }\n\n return res;\n }\n\n async getPlain(url: string, options?: Opts): Promise<HttpResponse> {\n const opt = options ?? {};\n return await this.getText(url, {\n headers: {\n Accept: 'text/plain',\n },\n ...opt,\n });\n }\n\n /**\n * @deprecated use `getYaml` instead\n */\n async getYamlUnchecked<ResT>(\n url: string,\n options?: Opts,\n ): Promise<HttpResponse<ResT>> {\n const res = await this.getText(url, options);\n const body = parseSingleYaml<ResT>(res.body);\n return { ...res, body };\n }\n\n async getYaml<Schema extends ZodType<any, any, any>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getYaml<Schema extends ZodType<any, any, any>>(\n url: string,\n options: Opts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getYaml<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: Opts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const url = arg1;\n let schema: Schema;\n let httpOptions: Opts | undefined;\n if (arg3) {\n schema = arg3;\n httpOptions = arg2 as Opts;\n } else {\n schema = arg2 as Schema;\n }\n\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method: 'get',\n };\n\n const res = await this.getText(url, opts);\n const body = await schema.parseAsync(parseSingleYaml(res.body));\n return { ...res, body };\n }\n\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(url: string, schema: Schema): AsyncResult<Infer<Schema>, SafeJsonError>;\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(\n url: string,\n options: Opts,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getYamlSafe<\n ResT extends NonNullable<unknown>,\n Schema extends ZodType<ResT> = ZodType<ResT>,\n >(\n arg1: string,\n arg2: Opts | Schema,\n arg3?: Schema,\n ): AsyncResult<ResT, SafeJsonError> {\n const url = arg1;\n let schema: Schema;\n let httpOptions: Opts | undefined;\n if (arg3) {\n schema = arg3;\n httpOptions = arg2 as Opts;\n } else {\n schema = arg2 as Schema;\n }\n\n let res: AsyncResult<HttpResponse<ResT>, SafeJsonError>;\n if (httpOptions) {\n res = Result.wrap(this.getYaml(url, httpOptions, schema));\n } else {\n res = Result.wrap(this.getYaml(url, schema));\n }\n\n return res.transform((response) => Result.ok(response.body));\n }\n\n /**\n * Request JSON and return the response without any validation.\n *\n * The usage of this method is discouraged, please use `getJson` instead.\n *\n * If you're new to Zod schema validation library:\n * - consult the [documentation of Zod library](https://github.com/colinhacks/zod?tab=readme-ov-file#basic-usage)\n * - search the Renovate codebase for 'zod' module usage\n * - take a look at the `schema-utils.ts` file for Renovate-specific schemas and utilities\n */\n getJsonUnchecked<ResT = unknown>(\n url: string,\n options?: JSONOpts,\n ): Promise<HttpResponse<ResT>> {\n return this.requestJson<ResT>('get', { url, httpOptions: options });\n }\n\n /**\n * Request JSON with a Zod schema for the response,\n * throwing an error if the response is not valid.\n *\n * @param url\n * @param schema Zod schema for the response\n */\n getJson<Schema extends ZodType<any, any, any>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n getJson<Schema extends ZodType<any, any, any>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n getJson<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const args = this.resolveArgs<Infer<Schema>>(arg1, arg2, arg3);\n return this.requestJson<Infer<Schema>>('get', args);\n }\n\n /**\n * Request JSON with a Zod schema for the response,\n * wrapping response data in a `Result` class.\n *\n * @param url\n * @param schema Zod schema for the response\n */\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n url: string,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): AsyncResult<Infer<Schema>, SafeJsonError>;\n getJsonSafe<ResT extends NonNullable<unknown>, Schema extends ZodType<ResT>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): AsyncResult<ResT, SafeJsonError> {\n const args = this.resolveArgs<ResT>(arg1, arg2, arg3);\n return Result.wrap(this.requestJson<ResT>('get', args)).transform(\n (response) => Result.ok(response.body),\n );\n }\n\n /**\n * @deprecated use `head` instead\n */\n headJson(url: string, httpOptions?: JSONOpts): Promise<HttpResponse<never>> {\n return this.requestJson<never>('head', { url, httpOptions });\n }\n\n postJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n postJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n postJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n postJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('post', args);\n }\n\n putJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n putJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n putJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n putJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: ZodType,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('put', args);\n }\n\n patchJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n patchJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n patchJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n patchJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('patch', args);\n }\n\n deleteJson<T>(url: string, options?: JSONOpts): Promise<HttpResponse<T>>;\n deleteJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n deleteJson<T, Schema extends ZodType<T> = ZodType<T>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n deleteJson<T = unknown, Schema extends ZodType<T> = ZodType<T>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<T>> {\n const args = this.resolveArgs(arg1, arg2, arg3);\n return this.requestJson<T>('delete', args);\n }\n\n stream(url: string, options?: HttpOptions): NodeJS.ReadableStream {\n let combinedOptions: Merge<\n GotStreamOptions,\n SetRequired<InternalHttpOptions, 'method'>\n > = {\n ...this.options,\n hostType: this.hostType,\n ...options,\n method: 'get',\n };\n\n const resolvedUrl = this.resolveUrl(url, options).toString();\n\n applyDefaultHeaders(combinedOptions);\n\n if (\n isUndefined(combinedOptions.readOnly) &&\n ['head', 'get'].includes(combinedOptions.method)\n ) {\n combinedOptions.readOnly = true;\n }\n\n const hostRule = findMatchingRule(url, combinedOptions);\n combinedOptions = applyHostRule(resolvedUrl, combinedOptions, hostRule);\n if (combinedOptions.enabled === false) {\n throw new Error(HOST_DISABLED);\n }\n combinedOptions = applyAuthorization(combinedOptions);\n\n return stream(resolvedUrl, combinedOptions);\n }\n\n async getToml<Schema extends ZodType<any, any, any>>(\n url: string,\n schema?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getToml<Schema extends ZodType<any, any, any>>(\n url: string,\n options: JSONOpts,\n schema: Schema,\n ): Promise<HttpResponse<Infer<Schema>>>;\n async getToml<Schema extends ZodType<any, any, any>>(\n arg1: string,\n arg2?: JSONOpts | Schema,\n arg3?: Schema,\n ): Promise<HttpResponse<Infer<Schema>>> {\n const { url, schema, httpOptions } = this.resolveArgs<Infer<Schema>>(\n arg1,\n arg2,\n arg3,\n );\n\n const opts: InternalHttpOptions = {\n ...httpOptions,\n method: 'get',\n headers: {\n 'Content-Type': 'application/toml',\n ...httpOptions?.headers,\n },\n };\n\n const res = await this.getText(url, opts);\n if (schema) {\n res.body = await Toml.pipe(schema).parseAsync(res.body);\n } else {\n res.body = (await Toml.parseAsync(res.body)) as Infer<Schema>;\n }\n\n return res;\n }\n}\n"]}
@@ -324,7 +324,7 @@ class HttpCacheStats {
324
324
  }
325
325
  }
326
326
  exports.HttpCacheStats = HttpCacheStats;
327
- /* v8 ignore start: temporary code */
327
+ /* v8 ignore next: temporary code */
328
328
  class ObsoleteCacheHitLogger {
329
329
  static getData() {
330
330
  return memCache.get('obsolete-cache-stats') ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../lib/util/stats.ts"],"names":[],"mappings":";;;AAcA,4CAQC;;AAtBD,sCAAmC;AACnC,iEAA2C;AAC3C,+BAAiC;AAYjC,SAAgB,gBAAgB,CAAC,IAAc;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1B,MAAM,OAAO,GAAG,IAAI,CAA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CAAC,IAAI,EAAE,EAAE,CAAC;YACpD,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAC9B,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACjE,YAAY,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,CAAC,MAAM;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,eAAM,CAAC,KAAK,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AA7CD,sDA6CC","sourcesContent":["import { logger } from '../logger';\nimport * as memCache from './cache/memory';\nimport { parseUrl } from './url';\n\ntype LookupStatsData = Record<string, number[]>;\n\ninterface TimingStatsReport {\n count: number;\n avgMs: number;\n medianMs: number;\n maxMs: number;\n totalMs: number;\n}\n\nexport function makeTimingReport(data: number[]): TimingStatsReport {\n const count = data.length;\n const totalMs = data.reduce((a, c) => a + c, 0);\n const avgMs = count ? Math.round(totalMs / count) : 0;\n const maxMs = Math.max(0, ...data);\n const sorted = data.sort((a, b) => a - b);\n const medianMs = count ? sorted[Math.floor(count / 2)] : 0;\n return { count, avgMs, medianMs, maxMs, totalMs };\n}\n\nexport class LookupStats {\n static write(datasource: string, duration: number): void {\n const data = memCache.get<LookupStatsData>('lookup-stats') ?? {};\n data[datasource] ??= [];\n data[datasource].push(duration);\n memCache.set('lookup-stats', data);\n }\n\n static async wrap<T>(\n datasource: string,\n callback: () => Promise<T>,\n ): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n LookupStats.write(datasource, duration);\n return result;\n }\n\n static getReport(): Record<string, TimingStatsReport> {\n const report: Record<string, TimingStatsReport> = {};\n const data = memCache.get<LookupStatsData>('lookup-stats') ?? {};\n for (const [datasource, durations] of Object.entries(data)) {\n report[datasource] = makeTimingReport(durations);\n }\n return report;\n }\n\n static report(): void {\n const report = LookupStats.getReport();\n logger.debug(report, 'Lookup statistics');\n }\n}\n\ntype PackageCacheData = number[];\n\nexport class PackageCacheStats {\n static writeSet(duration: number): void {\n const data = memCache.get<PackageCacheData>('package-cache-sets') ?? [];\n data.push(duration);\n memCache.set('package-cache-sets', data);\n }\n\n static async wrapSet<T>(callback: () => Promise<T>): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n PackageCacheStats.writeSet(duration);\n return result;\n }\n\n static writeGet(duration: number): void {\n const data = memCache.get<PackageCacheData>('package-cache-gets') ?? [];\n data.push(duration);\n memCache.set('package-cache-gets', data);\n }\n\n static async wrapGet<T>(callback: () => Promise<T>): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n PackageCacheStats.writeGet(duration);\n return result;\n }\n\n static getReport(): { get: TimingStatsReport; set: TimingStatsReport } {\n const packageCacheGets =\n memCache.get<PackageCacheData>('package-cache-gets') ?? [];\n const get = makeTimingReport(packageCacheGets);\n\n const packageCacheSets =\n memCache.get<PackageCacheData>('package-cache-sets') ?? [];\n const set = makeTimingReport(packageCacheSets);\n\n return { get, set };\n }\n\n static report(): void {\n const report = PackageCacheStats.getReport();\n logger.debug(report, 'Package cache statistics');\n }\n}\n\ninterface DatasourceCacheDataPoint {\n datasource: string;\n registryUrl: string;\n packageName: string;\n action: 'hit' | 'miss' | 'set' | 'skip';\n}\n\n/* eslint-disable @typescript-eslint/consistent-indexed-object-style */\nexport interface DatasourceCacheReport {\n long: {\n [datasource in string]: {\n [registryUrl in string]: {\n [packageName in string]: {\n read?: 'hit' | 'miss';\n write?: 'set' | 'skip';\n };\n };\n };\n };\n short: {\n [datasource in string]: {\n [registryUrl in string]: {\n hit: number;\n miss: number;\n set: number;\n skip: number;\n };\n };\n };\n}\n/* eslint-enable @typescript-eslint/consistent-indexed-object-style */\n\nexport class DatasourceCacheStats {\n private static getData(): DatasourceCacheDataPoint[] {\n return (\n memCache.get<DatasourceCacheDataPoint[]>('datasource-cache-stats') ?? []\n );\n }\n\n private static setData(data: DatasourceCacheDataPoint[]): void {\n memCache.set('datasource-cache-stats', data);\n }\n\n static hit(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'hit' });\n this.setData(data);\n }\n\n static miss(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'miss' });\n this.setData(data);\n }\n\n static set(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'set' });\n this.setData(data);\n }\n\n static skip(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'skip' });\n this.setData(data);\n }\n\n static getReport(): DatasourceCacheReport {\n const data = this.getData();\n const result: DatasourceCacheReport = { long: {}, short: {} };\n for (const { datasource, registryUrl, packageName, action } of data) {\n result.long[datasource] ??= {};\n result.long[datasource][registryUrl] ??= {};\n result.long[datasource][registryUrl] ??= {};\n result.long[datasource][registryUrl][packageName] ??= {};\n\n result.short[datasource] ??= {};\n result.short[datasource][registryUrl] ??= {\n hit: 0,\n miss: 0,\n set: 0,\n skip: 0,\n };\n\n if (action === 'hit') {\n result.long[datasource][registryUrl][packageName].read = 'hit';\n result.short[datasource][registryUrl].hit += 1;\n continue;\n }\n\n if (action === 'miss') {\n result.long[datasource][registryUrl][packageName].read = 'miss';\n result.short[datasource][registryUrl].miss += 1;\n continue;\n }\n\n if (action === 'set') {\n result.long[datasource][registryUrl][packageName].write = 'set';\n result.short[datasource][registryUrl].set += 1;\n continue;\n }\n\n if (action === 'skip') {\n result.long[datasource][registryUrl][packageName].write = 'skip';\n result.short[datasource][registryUrl].skip += 1;\n continue;\n }\n }\n\n return result;\n }\n\n static report(): void {\n const { long, short } = this.getReport();\n\n if (Object.keys(short).length > 0) {\n logger.debug(short, 'Datasource cache statistics');\n }\n\n if (Object.keys(long).length > 0) {\n logger.trace(long, 'Datasource cache detailed statistics');\n }\n }\n}\n\nexport interface HttpRequestStatsDataPoint {\n method: string;\n url: string;\n reqMs: number;\n queueMs: number;\n status: number;\n}\n\ninterface HostStatsData {\n count: number;\n reqAvgMs: number;\n reqMedianMs: number;\n reqMaxMs: number;\n queueAvgMs: number;\n queueMedianMs: number;\n queueMaxMs: number;\n}\n\n// url -> method -> status -> count\ntype UrlHttpStat = Record<string, Record<string, Record<string, number>>>;\n\ninterface HttpStatsCollection {\n // debug data\n urls: UrlHttpStat;\n hosts: Record<string, HostStatsData>;\n requests: number;\n\n // trace data\n rawRequests: string[];\n hostRequests: Record<string, HttpRequestStatsDataPoint[]>;\n}\n\nexport class HttpStats {\n static write(data: HttpRequestStatsDataPoint): void {\n const httpRequests =\n memCache.get<HttpRequestStatsDataPoint[]>('http-requests') ?? [];\n httpRequests.push(data);\n memCache.set('http-requests', httpRequests);\n }\n\n static getDataPoints(): HttpRequestStatsDataPoint[] {\n const httpRequests =\n memCache.get<HttpRequestStatsDataPoint[]>('http-requests') ?? [];\n\n // istanbul ignore next: sorting is hard and not worth testing\n httpRequests.sort((a, b) => {\n if (a.url < b.url) {\n return -1;\n }\n\n if (a.url > b.url) {\n return 1;\n }\n\n return 0;\n });\n\n return httpRequests;\n }\n\n static getReport(): HttpStatsCollection {\n const dataPoints = HttpStats.getDataPoints();\n\n const requests = dataPoints.length;\n\n const urls: UrlHttpStat = {};\n const rawRequests: string[] = [];\n const hostRequests: Record<string, HttpRequestStatsDataPoint[]> = {};\n\n for (const dataPoint of dataPoints) {\n const { url, reqMs, queueMs, status } = dataPoint;\n const method = dataPoint.method.toUpperCase();\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.debug({ url }, 'Failed to parse URL during stats reporting');\n continue;\n }\n const { hostname, origin, pathname } = parsedUrl;\n const baseUrl = `${origin}${pathname}`;\n\n urls[baseUrl] ??= {};\n urls[baseUrl][method] ??= {};\n urls[baseUrl][method][status] ??= 0;\n urls[baseUrl][method][status] += 1;\n\n rawRequests.push(`${method} ${url} ${status} ${reqMs} ${queueMs}`);\n\n hostRequests[hostname] ??= [];\n hostRequests[hostname].push(dataPoint);\n }\n\n const hosts: Record<string, HostStatsData> = {};\n\n for (const [hostname, dataPoints] of Object.entries(hostRequests)) {\n const count = dataPoints.length;\n\n const reqTimes = dataPoints.map((r) => r.reqMs);\n const queueTimes = dataPoints.map((r) => r.queueMs);\n\n const reqReport = makeTimingReport(reqTimes);\n const queueReport = makeTimingReport(queueTimes);\n\n hosts[hostname] = {\n count,\n reqAvgMs: reqReport.avgMs,\n reqMedianMs: reqReport.medianMs,\n reqMaxMs: reqReport.maxMs,\n queueAvgMs: queueReport.avgMs,\n queueMedianMs: queueReport.medianMs,\n queueMaxMs: queueReport.maxMs,\n };\n }\n\n return {\n urls,\n rawRequests,\n hostRequests,\n hosts,\n requests,\n };\n }\n\n static report(): void {\n const { urls, rawRequests, hostRequests, hosts, requests } =\n HttpStats.getReport();\n logger.trace({ rawRequests, hostRequests }, 'HTTP full statistics');\n logger.debug({ hosts, requests }, 'HTTP statistics');\n logger.trace({ urls }, 'HTTP URL statistics');\n }\n}\n\ninterface HttpCacheHostStatsData {\n hit: number;\n miss: number;\n localHit?: number;\n localMiss?: number;\n}\n\ntype HttpCacheStatsData = Record<string, HttpCacheHostStatsData>;\n\nfunction sortObject<T>(obj: Record<string, T>): Record<string, T> {\n const result: Record<string, T> = {};\n for (const key of Object.keys(obj).sort()) {\n result[key] = obj[key];\n }\n return result;\n}\n\nexport class HttpCacheStats {\n static getData(): HttpCacheStatsData {\n return memCache.get<HttpCacheStatsData>('http-cache-stats') ?? {};\n }\n\n static read(key: string): HttpCacheHostStatsData {\n return (\n this.getData()?.[key] ?? {\n hit: 0,\n miss: 0,\n }\n );\n }\n\n static write(key: string, data: HttpCacheHostStatsData): void {\n const stats = memCache.get<HttpCacheStatsData>('http-cache-stats') ?? {};\n stats[key] = data;\n memCache.set('http-cache-stats', stats);\n }\n\n static getBaseUrl(url: string): string | null {\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.debug({ url }, 'Failed to parse URL during cache stats');\n return null;\n }\n const { origin, pathname } = parsedUrl;\n const baseUrl = `${origin}${pathname}`;\n return baseUrl;\n }\n\n static incLocalHits(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.localHit ??= 0;\n stats.localHit += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incLocalMisses(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.localMiss ??= 0;\n stats.localMiss += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incRemoteHits(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.hit += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incRemoteMisses(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.miss += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static report(): void {\n const data = HttpCacheStats.getData();\n let report: Record<string, Record<string, HttpCacheHostStatsData>> = {};\n for (const [url, stats] of Object.entries(data)) {\n const parsedUrl = parseUrl(url);\n if (parsedUrl) {\n const { origin, pathname } = parsedUrl;\n report[origin] ??= {};\n report[origin][pathname] = stats;\n }\n }\n\n for (const [host, hostStats] of Object.entries(report)) {\n report[host] = sortObject(hostStats);\n }\n report = sortObject(report);\n\n logger.debug(report, 'HTTP cache statistics');\n }\n}\n\ntype ObsoleteCacheStats = Record<\n string,\n {\n count: number;\n }\n>;\n\n/* v8 ignore start: temporary code */\nexport class ObsoleteCacheHitLogger {\n static getData(): ObsoleteCacheStats {\n return memCache.get<ObsoleteCacheStats>('obsolete-cache-stats') ?? {};\n }\n\n static write(url: string): void {\n const data = this.getData();\n if (!data[url]) {\n data[url] = { count: 0 };\n }\n data[url].count++;\n memCache.set('obsolete-cache-stats', data);\n }\n\n static report(): void {\n const hits = this.getData();\n logger.debug(\n { count: Object.keys(hits).length, hits },\n 'Cache fallback URLs',\n );\n }\n}\n/* v8 ignore stop: temporary code */\n\ninterface AbandonedPackage {\n datasource: string;\n packageName: string;\n mostRecentTimestamp: string;\n}\n\ntype AbandonedPackageReport = Record<string, Record<string, string>>;\n\nexport class AbandonedPackageStats {\n static getData(): AbandonedPackage[] {\n return memCache.get<AbandonedPackage[]>('abandonment-stats') ?? [];\n }\n\n private static setData(data: AbandonedPackage[]): void {\n memCache.set('abandonment-stats', data);\n }\n\n static write(\n datasource: string,\n packageName: string,\n mostRecentTimestamp: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, packageName, mostRecentTimestamp });\n this.setData(data);\n }\n\n static getReport(): AbandonedPackageReport {\n const data = this.getData();\n const result: AbandonedPackageReport = {};\n\n for (const { datasource, packageName, mostRecentTimestamp } of data) {\n result[datasource] ??= {};\n result[datasource][packageName] = mostRecentTimestamp;\n }\n\n const sortedResult: AbandonedPackageReport = {};\n for (const datasource of Object.keys(result).sort()) {\n sortedResult[datasource] = {};\n for (const packageName of Object.keys(result[datasource]).sort()) {\n sortedResult[datasource][packageName] = result[datasource][packageName];\n }\n }\n\n return sortedResult;\n }\n\n static report(): void {\n const report = this.getReport();\n if (Object.keys(report).length > 0) {\n logger.debug(report, 'Abandoned package statistics');\n }\n }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AAE,IAAI,IAAI,EAAE,CAAC;YACpE,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YAC1B,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,GAAG,mBAAmB,CAAC;QACxD,CAAC;QAED,MAAM,YAAY,GAA2B,EAAE,CAAC;QAChD,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACpD,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAC9B,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACjE,YAAY,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,CAAC,MAAM;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,eAAM,CAAC,KAAK,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AA7CD,sDA6CC","sourcesContent":["import { logger } from '../logger';\nimport * as memCache from './cache/memory';\nimport { parseUrl } from './url';\n\ntype LookupStatsData = Record<string, number[]>;\n\ninterface TimingStatsReport {\n count: number;\n avgMs: number;\n medianMs: number;\n maxMs: number;\n totalMs: number;\n}\n\nexport function makeTimingReport(data: number[]): TimingStatsReport {\n const count = data.length;\n const totalMs = data.reduce((a, c) => a + c, 0);\n const avgMs = count ? Math.round(totalMs / count) : 0;\n const maxMs = Math.max(0, ...data);\n const sorted = data.sort((a, b) => a - b);\n const medianMs = count ? sorted[Math.floor(count / 2)] : 0;\n return { count, avgMs, medianMs, maxMs, totalMs };\n}\n\nexport class LookupStats {\n static write(datasource: string, duration: number): void {\n const data = memCache.get<LookupStatsData>('lookup-stats') ?? {};\n data[datasource] ??= [];\n data[datasource].push(duration);\n memCache.set('lookup-stats', data);\n }\n\n static async wrap<T>(\n datasource: string,\n callback: () => Promise<T>,\n ): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n LookupStats.write(datasource, duration);\n return result;\n }\n\n static getReport(): Record<string, TimingStatsReport> {\n const report: Record<string, TimingStatsReport> = {};\n const data = memCache.get<LookupStatsData>('lookup-stats') ?? {};\n for (const [datasource, durations] of Object.entries(data)) {\n report[datasource] = makeTimingReport(durations);\n }\n return report;\n }\n\n static report(): void {\n const report = LookupStats.getReport();\n logger.debug(report, 'Lookup statistics');\n }\n}\n\ntype PackageCacheData = number[];\n\nexport class PackageCacheStats {\n static writeSet(duration: number): void {\n const data = memCache.get<PackageCacheData>('package-cache-sets') ?? [];\n data.push(duration);\n memCache.set('package-cache-sets', data);\n }\n\n static async wrapSet<T>(callback: () => Promise<T>): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n PackageCacheStats.writeSet(duration);\n return result;\n }\n\n static writeGet(duration: number): void {\n const data = memCache.get<PackageCacheData>('package-cache-gets') ?? [];\n data.push(duration);\n memCache.set('package-cache-gets', data);\n }\n\n static async wrapGet<T>(callback: () => Promise<T>): Promise<T> {\n const start = Date.now();\n const result = await callback();\n const duration = Date.now() - start;\n PackageCacheStats.writeGet(duration);\n return result;\n }\n\n static getReport(): { get: TimingStatsReport; set: TimingStatsReport } {\n const packageCacheGets =\n memCache.get<PackageCacheData>('package-cache-gets') ?? [];\n const get = makeTimingReport(packageCacheGets);\n\n const packageCacheSets =\n memCache.get<PackageCacheData>('package-cache-sets') ?? [];\n const set = makeTimingReport(packageCacheSets);\n\n return { get, set };\n }\n\n static report(): void {\n const report = PackageCacheStats.getReport();\n logger.debug(report, 'Package cache statistics');\n }\n}\n\ninterface DatasourceCacheDataPoint {\n datasource: string;\n registryUrl: string;\n packageName: string;\n action: 'hit' | 'miss' | 'set' | 'skip';\n}\n\n/* eslint-disable @typescript-eslint/consistent-indexed-object-style */\nexport interface DatasourceCacheReport {\n long: {\n [datasource in string]: {\n [registryUrl in string]: {\n [packageName in string]: {\n read?: 'hit' | 'miss';\n write?: 'set' | 'skip';\n };\n };\n };\n };\n short: {\n [datasource in string]: {\n [registryUrl in string]: {\n hit: number;\n miss: number;\n set: number;\n skip: number;\n };\n };\n };\n}\n/* eslint-enable @typescript-eslint/consistent-indexed-object-style */\n\nexport class DatasourceCacheStats {\n private static getData(): DatasourceCacheDataPoint[] {\n return (\n memCache.get<DatasourceCacheDataPoint[]>('datasource-cache-stats') ?? []\n );\n }\n\n private static setData(data: DatasourceCacheDataPoint[]): void {\n memCache.set('datasource-cache-stats', data);\n }\n\n static hit(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'hit' });\n this.setData(data);\n }\n\n static miss(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'miss' });\n this.setData(data);\n }\n\n static set(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'set' });\n this.setData(data);\n }\n\n static skip(\n datasource: string,\n registryUrl: string,\n packageName: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, registryUrl, packageName, action: 'skip' });\n this.setData(data);\n }\n\n static getReport(): DatasourceCacheReport {\n const data = this.getData();\n const result: DatasourceCacheReport = { long: {}, short: {} };\n for (const { datasource, registryUrl, packageName, action } of data) {\n result.long[datasource] ??= {};\n result.long[datasource][registryUrl] ??= {};\n result.long[datasource][registryUrl] ??= {};\n result.long[datasource][registryUrl][packageName] ??= {};\n\n result.short[datasource] ??= {};\n result.short[datasource][registryUrl] ??= {\n hit: 0,\n miss: 0,\n set: 0,\n skip: 0,\n };\n\n if (action === 'hit') {\n result.long[datasource][registryUrl][packageName].read = 'hit';\n result.short[datasource][registryUrl].hit += 1;\n continue;\n }\n\n if (action === 'miss') {\n result.long[datasource][registryUrl][packageName].read = 'miss';\n result.short[datasource][registryUrl].miss += 1;\n continue;\n }\n\n if (action === 'set') {\n result.long[datasource][registryUrl][packageName].write = 'set';\n result.short[datasource][registryUrl].set += 1;\n continue;\n }\n\n if (action === 'skip') {\n result.long[datasource][registryUrl][packageName].write = 'skip';\n result.short[datasource][registryUrl].skip += 1;\n continue;\n }\n }\n\n return result;\n }\n\n static report(): void {\n const { long, short } = this.getReport();\n\n if (Object.keys(short).length > 0) {\n logger.debug(short, 'Datasource cache statistics');\n }\n\n if (Object.keys(long).length > 0) {\n logger.trace(long, 'Datasource cache detailed statistics');\n }\n }\n}\n\nexport interface HttpRequestStatsDataPoint {\n method: string;\n url: string;\n reqMs: number;\n queueMs: number;\n status: number;\n}\n\ninterface HostStatsData {\n count: number;\n reqAvgMs: number;\n reqMedianMs: number;\n reqMaxMs: number;\n queueAvgMs: number;\n queueMedianMs: number;\n queueMaxMs: number;\n}\n\n// url -> method -> status -> count\ntype UrlHttpStat = Record<string, Record<string, Record<string, number>>>;\n\ninterface HttpStatsCollection {\n // debug data\n urls: UrlHttpStat;\n hosts: Record<string, HostStatsData>;\n requests: number;\n\n // trace data\n rawRequests: string[];\n hostRequests: Record<string, HttpRequestStatsDataPoint[]>;\n}\n\nexport class HttpStats {\n static write(data: HttpRequestStatsDataPoint): void {\n const httpRequests =\n memCache.get<HttpRequestStatsDataPoint[]>('http-requests') ?? [];\n httpRequests.push(data);\n memCache.set('http-requests', httpRequests);\n }\n\n static getDataPoints(): HttpRequestStatsDataPoint[] {\n const httpRequests =\n memCache.get<HttpRequestStatsDataPoint[]>('http-requests') ?? [];\n\n // istanbul ignore next: sorting is hard and not worth testing\n httpRequests.sort((a, b) => {\n if (a.url < b.url) {\n return -1;\n }\n\n if (a.url > b.url) {\n return 1;\n }\n\n return 0;\n });\n\n return httpRequests;\n }\n\n static getReport(): HttpStatsCollection {\n const dataPoints = HttpStats.getDataPoints();\n\n const requests = dataPoints.length;\n\n const urls: UrlHttpStat = {};\n const rawRequests: string[] = [];\n const hostRequests: Record<string, HttpRequestStatsDataPoint[]> = {};\n\n for (const dataPoint of dataPoints) {\n const { url, reqMs, queueMs, status } = dataPoint;\n const method = dataPoint.method.toUpperCase();\n\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.debug({ url }, 'Failed to parse URL during stats reporting');\n continue;\n }\n const { hostname, origin, pathname } = parsedUrl;\n const baseUrl = `${origin}${pathname}`;\n\n urls[baseUrl] ??= {};\n urls[baseUrl][method] ??= {};\n urls[baseUrl][method][status] ??= 0;\n urls[baseUrl][method][status] += 1;\n\n rawRequests.push(`${method} ${url} ${status} ${reqMs} ${queueMs}`);\n\n hostRequests[hostname] ??= [];\n hostRequests[hostname].push(dataPoint);\n }\n\n const hosts: Record<string, HostStatsData> = {};\n\n for (const [hostname, dataPoints] of Object.entries(hostRequests)) {\n const count = dataPoints.length;\n\n const reqTimes = dataPoints.map((r) => r.reqMs);\n const queueTimes = dataPoints.map((r) => r.queueMs);\n\n const reqReport = makeTimingReport(reqTimes);\n const queueReport = makeTimingReport(queueTimes);\n\n hosts[hostname] = {\n count,\n reqAvgMs: reqReport.avgMs,\n reqMedianMs: reqReport.medianMs,\n reqMaxMs: reqReport.maxMs,\n queueAvgMs: queueReport.avgMs,\n queueMedianMs: queueReport.medianMs,\n queueMaxMs: queueReport.maxMs,\n };\n }\n\n return {\n urls,\n rawRequests,\n hostRequests,\n hosts,\n requests,\n };\n }\n\n static report(): void {\n const { urls, rawRequests, hostRequests, hosts, requests } =\n HttpStats.getReport();\n logger.trace({ rawRequests, hostRequests }, 'HTTP full statistics');\n logger.debug({ hosts, requests }, 'HTTP statistics');\n logger.trace({ urls }, 'HTTP URL statistics');\n }\n}\n\ninterface HttpCacheHostStatsData {\n hit: number;\n miss: number;\n localHit?: number;\n localMiss?: number;\n}\n\ntype HttpCacheStatsData = Record<string, HttpCacheHostStatsData>;\n\nfunction sortObject<T>(obj: Record<string, T>): Record<string, T> {\n const result: Record<string, T> = {};\n for (const key of Object.keys(obj).sort()) {\n result[key] = obj[key];\n }\n return result;\n}\n\nexport class HttpCacheStats {\n static getData(): HttpCacheStatsData {\n return memCache.get<HttpCacheStatsData>('http-cache-stats') ?? {};\n }\n\n static read(key: string): HttpCacheHostStatsData {\n return (\n this.getData()?.[key] ?? {\n hit: 0,\n miss: 0,\n }\n );\n }\n\n static write(key: string, data: HttpCacheHostStatsData): void {\n const stats = memCache.get<HttpCacheStatsData>('http-cache-stats') ?? {};\n stats[key] = data;\n memCache.set('http-cache-stats', stats);\n }\n\n static getBaseUrl(url: string): string | null {\n const parsedUrl = parseUrl(url);\n if (!parsedUrl) {\n logger.debug({ url }, 'Failed to parse URL during cache stats');\n return null;\n }\n const { origin, pathname } = parsedUrl;\n const baseUrl = `${origin}${pathname}`;\n return baseUrl;\n }\n\n static incLocalHits(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.localHit ??= 0;\n stats.localHit += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incLocalMisses(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.localMiss ??= 0;\n stats.localMiss += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incRemoteHits(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.hit += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static incRemoteMisses(url: string): void {\n const baseUrl = HttpCacheStats.getBaseUrl(url);\n if (baseUrl) {\n const host = baseUrl;\n const stats = HttpCacheStats.read(host);\n stats.miss += 1;\n HttpCacheStats.write(host, stats);\n }\n }\n\n static report(): void {\n const data = HttpCacheStats.getData();\n let report: Record<string, Record<string, HttpCacheHostStatsData>> = {};\n for (const [url, stats] of Object.entries(data)) {\n const parsedUrl = parseUrl(url);\n if (parsedUrl) {\n const { origin, pathname } = parsedUrl;\n report[origin] ??= {};\n report[origin][pathname] = stats;\n }\n }\n\n for (const [host, hostStats] of Object.entries(report)) {\n report[host] = sortObject(hostStats);\n }\n report = sortObject(report);\n\n logger.debug(report, 'HTTP cache statistics');\n }\n}\n\ntype ObsoleteCacheStats = Record<\n string,\n {\n count: number;\n }\n>;\n\n/* v8 ignore next: temporary code */\nexport class ObsoleteCacheHitLogger {\n static getData(): ObsoleteCacheStats {\n return memCache.get<ObsoleteCacheStats>('obsolete-cache-stats') ?? {};\n }\n\n static write(url: string): void {\n const data = this.getData();\n if (!data[url]) {\n data[url] = { count: 0 };\n }\n data[url].count++;\n memCache.set('obsolete-cache-stats', data);\n }\n\n static report(): void {\n const hits = this.getData();\n logger.debug(\n { count: Object.keys(hits).length, hits },\n 'Cache fallback URLs',\n );\n }\n}\n/* v8 ignore stop: temporary code */\n\ninterface AbandonedPackage {\n datasource: string;\n packageName: string;\n mostRecentTimestamp: string;\n}\n\ntype AbandonedPackageReport = Record<string, Record<string, string>>;\n\nexport class AbandonedPackageStats {\n static getData(): AbandonedPackage[] {\n return memCache.get<AbandonedPackage[]>('abandonment-stats') ?? [];\n }\n\n private static setData(data: AbandonedPackage[]): void {\n memCache.set('abandonment-stats', data);\n }\n\n static write(\n datasource: string,\n packageName: string,\n mostRecentTimestamp: string,\n ): void {\n const data = this.getData();\n data.push({ datasource, packageName, mostRecentTimestamp });\n this.setData(data);\n }\n\n static getReport(): AbandonedPackageReport {\n const data = this.getData();\n const result: AbandonedPackageReport = {};\n\n for (const { datasource, packageName, mostRecentTimestamp } of data) {\n result[datasource] ??= {};\n result[datasource][packageName] = mostRecentTimestamp;\n }\n\n const sortedResult: AbandonedPackageReport = {};\n for (const datasource of Object.keys(result).sort()) {\n sortedResult[datasource] = {};\n for (const packageName of Object.keys(result[datasource]).sort()) {\n sortedResult[datasource][packageName] = result[datasource][packageName];\n }\n }\n\n return sortedResult;\n }\n\n static report(): void {\n const report = this.getReport();\n if (Object.keys(report).length > 0) {\n logger.debug(report, 'Abandoned package statistics');\n }\n }\n}\n"]}
@@ -4,7 +4,7 @@ exports.setConfig = setConfig;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_readline_1 = tslib_1.__importDefault(require("node:readline"));
6
6
  const env_1 = require("../../../../util/env");
7
- /* v8 ignore start */
7
+ /* v8 ignore next */
8
8
  async function setConfig(config) {
9
9
  const env = (0, env_1.getEnv)();
10
10
  if (env.CODESPACES !== 'true') {
@@ -23,5 +23,4 @@ async function setConfig(config) {
23
23
  }
24
24
  return config;
25
25
  }
26
- /* v8 ignore stop */
27
26
  //# sourceMappingURL=codespaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"codespaces.js","sourceRoot":"","sources":["../../../../../lib/workers/global/config/parse/codespaces.ts"],"names":[],"mappings":";;AAKA,8BAoBC;;AAzBD,0EAAqC;AAErC,8CAA8C;AAE9C,qBAAqB;AACd,KAAK,UAAU,SAAS,CAAC,MAAiB;IAC/C,MAAM,GAAG,GAAG,IAAA,YAAM,GAAE,CAAC;IACrB,IAAI,GAAG,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACtC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC;IAClC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,uBAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC3C,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC;QACxD,MAAM,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,oBAAoB","sourcesContent":["import readline from 'node:readline';\nimport type { AllConfig } from '../../../../config/types';\nimport { getEnv } from '../../../../util/env';\n\n/* v8 ignore start */\nexport async function setConfig(config: AllConfig): Promise<AllConfig> {\n const env = getEnv();\n if (env.CODESPACES !== 'true') {\n return config;\n }\n\n if (!config.token && env.GITHUB_TOKEN) {\n config.token = env.GITHUB_TOKEN;\n }\n\n if (!config.repositories?.length) {\n const rl = readline.promises.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const repo = await rl.question('\\n\\nRepository name: ');\n config.repositories = [repo];\n }\n\n return config;\n}\n/* v8 ignore stop */\n"]}
1
+ {"version":3,"file":"codespaces.js","sourceRoot":"","sources":["../../../../../lib/workers/global/config/parse/codespaces.ts"],"names":[],"mappings":";;AAKA,8BAoBC;;AAzBD,0EAAqC;AAErC,8CAA8C;AAE9C,oBAAoB;AACb,KAAK,UAAU,SAAS,CAAC,MAAiB;IAC/C,MAAM,GAAG,GAAG,IAAA,YAAM,GAAE,CAAC;IACrB,IAAI,GAAG,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACtC,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC;IAClC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,uBAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC;YAC3C,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC;QACxD,MAAM,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import readline from 'node:readline';\nimport type { AllConfig } from '../../../../config/types';\nimport { getEnv } from '../../../../util/env';\n\n/* v8 ignore next */\nexport async function setConfig(config: AllConfig): Promise<AllConfig> {\n const env = getEnv();\n if (env.CODESPACES !== 'true') {\n return config;\n }\n\n if (!config.token && env.GITHUB_TOKEN) {\n config.token = env.GITHUB_TOKEN;\n }\n\n if (!config.repositories?.length) {\n const rl = readline.promises.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const repo = await rl.question('\\n\\nRepository name: ');\n config.repositories = [repo];\n }\n\n return config;\n}\n"]}
@@ -36,7 +36,8 @@ async function confirmIfDepUpdated(upgrade, newContent) {
36
36
  }
37
37
  newUpgrade = newExtract.deps[depIndex];
38
38
  }
39
- catch (err) /* istanbul ignore next */ {
39
+ catch (err) {
40
+ /* istanbul ignore next */
40
41
  logger_1.logger.debug({ manager, packageFile, err }, 'Failed to parse newContent');
41
42
  }
42
43
  if (!newUpgrade) {
@@ -287,7 +288,8 @@ async function doAutoReplace(upgrade, existingContent, reuseExistingBranch, firs
287
288
  }
288
289
  }
289
290
  }
290
- catch (err) /* istanbul ignore next */ {
291
+ catch (err) {
292
+ /* istanbul ignore next */
291
293
  logger_1.logger.debug({ packageFile, depName, err }, 'doAutoReplace error');
292
294
  }
293
295
  // istanbul ignore next