@verdaccio/proxy 9.0.0-next-9.6 → 9.0.0-next-9.7
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.
- package/build/agent.d.ts +0 -1
- package/build/agent.js.map +1 -1
- package/build/agent.mjs.map +1 -1
- package/build/index.js +2 -2
- package/build/proxy.d.ts +1 -1
- package/build/proxy.js +5 -5
- package/build/proxy.js.map +1 -1
- package/build/proxy.mjs +1 -1
- package/build/proxy.mjs.map +1 -1
- package/package.json +6 -6
package/build/agent.d.ts
CHANGED
package/build/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","names":[],"sources":["../src/agent.ts"],"sourcesContent":["import type { Agents } from 'got
|
|
1
|
+
{"version":3,"file":"agent.js","names":[],"sources":["../src/agent.ts"],"sourcesContent":["import type { Agents } from 'got';\nimport { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { URL } from 'node:url';\n\nimport type { AgentOptionsConf } from '@verdaccio/types';\n\nclass CustomAgents {\n private url: string;\n private proxy: string | undefined;\n private agentOptions: AgentOptionsConf;\n private agent: Agents;\n public constructor(url: string, proxy: string | undefined, agentOptions: AgentOptionsConf) {\n this.proxy = proxy;\n this.url = url;\n this.agentOptions = agentOptions;\n // Type of agent depends on the protocol of the server URL (no on the proxy)\n // See https://www.npmjs.com/package/hpagent\n const { protocol } = new URL(this.url);\n this.agent = this.getAgent(protocol);\n }\n\n public get() {\n return this.agent;\n }\n\n private getAgent(protocol: string): Agents {\n const isHTTPS = protocol === 'https:';\n if (this.proxy) {\n const options = {\n proxy: this.proxy,\n ...this.agentOptions,\n };\n // use hpagent\n return isHTTPS\n ? { https: new HttpsProxyAgent(options) }\n : { http: new HttpProxyAgent(options) };\n } else {\n // use native http/https agent\n return isHTTPS\n ? { https: new HttpsAgent(this.agentOptions) }\n : { http: new HttpAgent(this.agentOptions) };\n }\n }\n}\n\nexport default CustomAgents;\n"],"mappings":";;;;;;AAQA,IAAM,eAAN,MAAmB;CACjB;CACA;CACA;CACA;CACA,YAAmB,KAAa,OAA2B,cAAgC;AACzF,OAAK,QAAQ;AACb,OAAK,MAAM;AACX,OAAK,eAAe;EAGpB,MAAM,EAAE,aAAa,IAAI,SAAA,IAAI,KAAK,IAAI;AACtC,OAAK,QAAQ,KAAK,SAAS,SAAS;;CAGtC,MAAa;AACX,SAAO,KAAK;;CAGd,SAAiB,UAA0B;EACzC,MAAM,UAAU,aAAa;AAC7B,MAAI,KAAK,OAAO;GACd,MAAM,UAAU;IACd,OAAO,KAAK;IACZ,GAAG,KAAK;IACT;AAED,UAAO,UACH,EAAE,OAAO,IAAI,QAAA,gBAAgB,QAAQ,EAAE,GACvC,EAAE,MAAM,IAAI,QAAA,eAAe,QAAQ,EAAE;QAGzC,QAAO,UACH,EAAE,OAAO,IAAI,WAAA,MAAW,KAAK,aAAa,EAAE,GAC5C,EAAE,MAAM,IAAI,UAAA,MAAU,KAAK,aAAa,EAAE"}
|
package/build/agent.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.mjs","names":[],"sources":["../src/agent.ts"],"sourcesContent":["import type { Agents } from 'got
|
|
1
|
+
{"version":3,"file":"agent.mjs","names":[],"sources":["../src/agent.ts"],"sourcesContent":["import type { Agents } from 'got';\nimport { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { URL } from 'node:url';\n\nimport type { AgentOptionsConf } from '@verdaccio/types';\n\nclass CustomAgents {\n private url: string;\n private proxy: string | undefined;\n private agentOptions: AgentOptionsConf;\n private agent: Agents;\n public constructor(url: string, proxy: string | undefined, agentOptions: AgentOptionsConf) {\n this.proxy = proxy;\n this.url = url;\n this.agentOptions = agentOptions;\n // Type of agent depends on the protocol of the server URL (no on the proxy)\n // See https://www.npmjs.com/package/hpagent\n const { protocol } = new URL(this.url);\n this.agent = this.getAgent(protocol);\n }\n\n public get() {\n return this.agent;\n }\n\n private getAgent(protocol: string): Agents {\n const isHTTPS = protocol === 'https:';\n if (this.proxy) {\n const options = {\n proxy: this.proxy,\n ...this.agentOptions,\n };\n // use hpagent\n return isHTTPS\n ? { https: new HttpsProxyAgent(options) }\n : { http: new HttpProxyAgent(options) };\n } else {\n // use native http/https agent\n return isHTTPS\n ? { https: new HttpsAgent(this.agentOptions) }\n : { http: new HttpAgent(this.agentOptions) };\n }\n }\n}\n\nexport default CustomAgents;\n"],"mappings":";;;;;AAQA,IAAM,eAAN,MAAmB;CACjB;CACA;CACA;CACA;CACA,YAAmB,KAAa,OAA2B,cAAgC;AACzF,OAAK,QAAQ;AACb,OAAK,MAAM;AACX,OAAK,eAAe;EAGpB,MAAM,EAAE,aAAa,IAAI,IAAI,KAAK,IAAI;AACtC,OAAK,QAAQ,KAAK,SAAS,SAAS;;CAGtC,MAAa;AACX,SAAO,KAAK;;CAGd,SAAiB,UAA0B;EACzC,MAAM,UAAU,aAAa;AAC7B,MAAI,KAAK,OAAO;GACd,MAAM,UAAU;IACd,OAAO,KAAK;IACZ,GAAG,KAAK;IACT;AAED,UAAO,UACH,EAAE,OAAO,IAAI,gBAAgB,QAAQ,EAAE,GACvC,EAAE,MAAM,IAAI,eAAe,QAAQ,EAAE;QAGzC,QAAO,UACH,EAAE,OAAO,IAAI,QAAW,KAAK,aAAa,EAAE,GAC5C,EAAE,MAAM,IAAI,MAAU,KAAK,aAAa,EAAE"}
|
package/build/index.js
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperties(exports, {
|
|
|
5
5
|
require("./_virtual/_rolldown/runtime.js");
|
|
6
6
|
const require_proxy = require("./proxy.js");
|
|
7
7
|
const require_uplink_util = require("./uplink-util.js");
|
|
8
|
-
let
|
|
9
|
-
exports.FetchOptions =
|
|
8
|
+
let got = require("got");
|
|
9
|
+
exports.FetchOptions = got.Options;
|
|
10
10
|
exports.ProxyStorage = require_proxy.ProxyStorage;
|
|
11
11
|
exports.setupUpLinks = require_uplink_util.setupUpLinks;
|
|
12
12
|
exports.updateVersionsHiddenUpLinkNext = require_uplink_util.updateVersionsHiddenUpLinkNext;
|
package/build/proxy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agents, Delays, RetryOptions, Headers as gotHeaders, Options } from 'got
|
|
1
|
+
import { Agents, Delays, RetryOptions, Headers as gotHeaders, Options } from 'got';
|
|
2
2
|
import { default as Stream, PassThrough } from 'node:stream';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
4
|
import { searchUtils } from '@verdaccio/core';
|
package/build/proxy.js
CHANGED
|
@@ -5,8 +5,8 @@ let JSONStream = require("JSONStream");
|
|
|
5
5
|
JSONStream = require_runtime.__toESM(JSONStream);
|
|
6
6
|
let debug = require("debug");
|
|
7
7
|
debug = require_runtime.__toESM(debug);
|
|
8
|
-
let
|
|
9
|
-
|
|
8
|
+
let got = require("got");
|
|
9
|
+
got = require_runtime.__toESM(got);
|
|
10
10
|
let lodash = require("lodash");
|
|
11
11
|
lodash = require_runtime.__toESM(lodash);
|
|
12
12
|
let node_stream = require("node:stream");
|
|
@@ -190,7 +190,7 @@ var ProxyStorage = class {
|
|
|
190
190
|
try {
|
|
191
191
|
const retry = options?.retry ?? this.retry;
|
|
192
192
|
debug$1("retry initial count %s", retry);
|
|
193
|
-
response = await (0,
|
|
193
|
+
response = await (0, got.default)(uri, {
|
|
194
194
|
headers,
|
|
195
195
|
responseType: "json",
|
|
196
196
|
method,
|
|
@@ -292,7 +292,7 @@ var ProxyStorage = class {
|
|
|
292
292
|
}
|
|
293
293
|
const method = "GET";
|
|
294
294
|
debug$1("request uri for %s", url);
|
|
295
|
-
return
|
|
295
|
+
return got.default.stream(url, {
|
|
296
296
|
headers,
|
|
297
297
|
method,
|
|
298
298
|
agent: this.agent,
|
|
@@ -315,7 +315,7 @@ var ProxyStorage = class {
|
|
|
315
315
|
uplink: this.uplinkName
|
|
316
316
|
}, "search request to uplink @{uplink} - @{uri}");
|
|
317
317
|
debug$1("searching on %o", uri);
|
|
318
|
-
const res = await (0,
|
|
318
|
+
const res = await (0, got.default)(uri, {
|
|
319
319
|
signal: abort ? abort.signal : {},
|
|
320
320
|
agent: this.agent,
|
|
321
321
|
timeout: this.timeout,
|
package/build/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","names":[],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport type { Agents, Delays, RequestError, RetryOptions, Headers as gotHeaders } from 'got-cjs';\nimport got, { Options } from 'got-cjs';\nimport _ from 'lodash';\nimport type Stream from 'node:stream';\nimport { PassThrough, Readable } from 'node:stream';\nimport { URL } from 'node:url';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n authUtils,\n constants,\n errorUtils,\n} from '@verdaccio/core';\nimport type { AgentOptionsConf, Config, Logger, Manifest, UpLinkConf } from '@verdaccio/types';\n\nimport CustomAgents from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst debug = buildDebug('verdaccio:proxy');\n\nconst encode = function (thing): string {\n return encodeURIComponent(thing).replace(/^%40/, '@');\n};\n\nconst jsonContentType = HEADERS.JSON;\nconst contentTypeAccept = `${jsonContentType};`;\n\n/**\n * Just a helper (`config[key] || default` doesn't work because of zeroes)\n */\nconst setConfig = (config: UpLinkConfLocal, key: string, def): string => {\n return _.isNil(config[key]) === false ? config[key] : def;\n};\n\nexport type UpLinkConfLocal = UpLinkConf & {\n no_proxy?: string;\n};\n\nexport interface ProxyList {\n [key: string]: IProxy;\n}\n\nexport type ProxySearchParams = {\n url: string;\n abort: AbortController;\n query?: searchUtils.SearchQuery;\n headers?: Headers;\n retry?: Partial<RetryOptions>;\n};\nexport interface IProxy {\n uplinkName: string;\n config: UpLinkConfLocal;\n failed_requests: number;\n userAgent: string;\n ca?: string | void;\n logger: Logger;\n server_id: string;\n url: URL;\n maxage: number;\n timeout: Delays;\n max_fails: number;\n fail_timeout: number;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]>;\n fetchTarball(\n url: string,\n options: Partial<Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>>\n ): PassThrough;\n}\n\n// this type is need it by storage\nexport { Options as FetchOptions };\n\nexport interface ISyncUplinksOptions extends Options {\n uplinksLook?: boolean;\n etag?: string;\n remoteAddress?: string;\n}\n\n/**\n * Implements Storage interface\n * (same for storage.js, local-storage.js, up-storage.js)\n */\nclass ProxyStorage implements IProxy {\n public uplinkName: string;\n public config: UpLinkConfLocal;\n public failed_requests: number;\n public userAgent: string;\n public ca: string | void;\n public logger: Logger;\n public server_id: string;\n public url: URL;\n public maxage: number;\n public timeout: Delays;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n public proxy: string | undefined;\n private agent: Agents;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n private retry: Partial<RetryOptions>;\n\n public constructor(\n uplinkName: string,\n config: UpLinkConfLocal,\n mainConfig: Config,\n logger: Logger,\n agent?: Agents\n ) {\n this.uplinkName = uplinkName;\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent ?? 'hidden';\n this.ca = config.ca;\n this.logger = logger;\n this.server_id = mainConfig.server_id;\n this.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n }) as AgentOptionsConf;\n this.url = new URL(this.config.url);\n const isHTTPS = this.url.protocol === 'https:';\n this._setupProxy(this.url.hostname, config, mainConfig, isHTTPS);\n this.agent = agent ?? this.getAgent();\n this.config.url = this.config.url.replace(/\\/$/, '');\n\n if (this.config.timeout && Number(this.config.timeout) >= 1000) {\n this.logger.warn(\n [\n 'Too big timeout value: ' + this.config.timeout,\n 'We changed time format to nginx-like one',\n '(see http://nginx.org/en/docs/syntax.html)',\n 'so please update your config accordingly',\n ].join('\\n')\n );\n }\n\n // a bunch of different configurable timers\n this.maxage = parseInterval(setConfig(this.config, 'maxage', '2m'));\n // https://github.com/sindresorhus/got/blob/main/documentation/6-timeout.md\n this.timeout = {\n request: parseInterval(setConfig(this.config, 'timeout', '30s')),\n };\n debug('set timeout %s', this.timeout);\n this.max_fails = Number(setConfig(this.config, 'max_fails', this.config.max_fails ?? 2));\n this.fail_timeout = parseInterval(setConfig(this.config, 'fail_timeout', '5m'));\n this.strict_ssl = Boolean(setConfig(this.config, 'strict_ssl', true));\n this.retry = { limit: this.max_fails ?? 2 };\n }\n\n private getAgent() {\n if (!this.agent) {\n // TODO: the config.ca (certificates) is not yet injected here\n const agentInstance = new CustomAgents(this.config.url, this.proxy, this.agent_options);\n return agentInstance.get();\n } else {\n return this.agent;\n }\n }\n\n public getHeaders(headers = {}): gotHeaders {\n const accept = HEADERS.ACCEPT;\n const acceptEncoding = HEADERS.ACCEPT_ENCODING;\n const userAgent = HEADERS.USER_AGENT;\n\n headers[accept] = headers[accept] || contentTypeAccept;\n headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';\n // registry.npmjs.org will only return search result if user-agent include string 'npm'\n headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;\n return this.setAuthNext(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private setAuthNext(headers: gotHeaders): gotHeaders {\n const { auth } = this.config;\n if (typeof auth === 'undefined' || typeof headers[HEADERS.AUTHORIZATION] === 'string') {\n return headers;\n }\n\n if (_.isObject(auth) === false && _.isObject((auth as any).token) === false) {\n this._throwErrorAuth('Auth invalid');\n }\n\n // get NPM_TOKEN http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules\n // or get other variable export in env\n // https://github.com/verdaccio/verdaccio/releases/tag/v2.5.0\n let token: any;\n const tokenConf: any = auth;\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n debug('use token from config');\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n debug('use token from env %o', tokenConf.token_env);\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n } else {\n this.logger.error(constants.ERROR_CODE.token_required);\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n } else {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n }\n\n if (typeof token === 'undefined') {\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n\n // define type Auth allow basic and bearer\n const type = tokenConf.type || TOKEN_BASIC;\n debug('token type %o', type);\n this._setHeaderAuthorization(headers, type, token);\n\n return headers;\n }\n\n /**\n * @param {string} message\n * @throws {Error}\n * @private\n */\n private _throwErrorAuth(message: string): Error {\n this.logger.error(message);\n throw new Error(message);\n }\n\n /**\n * Assign Header authorization with type authentication\n * @param {Object} headers\n * @param {string} type\n * @param {string} token\n * @private\n */\n private _setHeaderAuthorization(headers: any, type: string, token: any): void {\n const _type: string = type.toLowerCase();\n\n if (_type !== TOKEN_BEARER.toLowerCase() && _type !== TOKEN_BASIC.toLowerCase()) {\n this._throwErrorAuth(`Auth type '${_type}' not allowed`);\n }\n\n headers[HEADERS.AUTHORIZATION] = authUtils.buildToken(type, token);\n }\n\n /**\n * It will add or override specified headers from config file.\n *\n * Eg:\n *\n * uplinks:\n npmjs:\n url: https://registry.npmjs.org/\n headers:\n Accept: \"application/vnd.npm.install-v2+json; q=1.0\"\n verdaccio-staging:\n url: https://mycompany.com/npm\n headers:\n Accept: \"application/json\"\n authorization: \"Basic YourBase64EncodedCredentials==\"\n\n * @param {Object} headers\n * @private\n */\n private applyUplinkHeaders(headers: gotHeaders): gotHeaders {\n if (!this.config.headers) {\n return headers;\n }\n\n // add/override headers specified in the config\n /* eslint guard-for-in: 0 */\n for (const key in this.config.headers) {\n headers[key] = this.config.headers[key];\n }\n return headers;\n }\n\n public async getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]> {\n if (this._ifRequestFailure()) {\n throw errorUtils.getInternalError(API_ERROR.UPLINK_OFFLINE);\n }\n\n // FUTURE: allow mix headers that comes from the client\n debug('getting metadata for package %s', name);\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = options.method || 'GET';\n const uri = this.config.url + `/${encode(name)}`;\n debug('set retry limit is %s', this.retry.limit);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry initial count %s', retry);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n timeout: this.timeout,\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('after response code is %s', code);\n if (code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES) {\n if (this.failed_requests >= this.max_fails) {\n this.failed_requests = 0;\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now online'\n );\n }\n }\n\n return afterResponse;\n },\n ],\n beforeRetry: [\n (error: RequestError, count: number) => {\n debug('retry %s count: %s', uri, count);\n this.failed_requests = count ?? 0;\n this.logger.info(\n {\n request: {\n method: method,\n url: uri,\n },\n error: error.message,\n retryCount: this.failed_requests,\n },\n \"retry @{retryCount} req: '@{request.method} @{request.url}'\"\n );\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now offline'\n );\n }\n },\n ],\n },\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n })\n .on<any>('response', (eventResponse) => {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n this.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(eventResponse) === false ? eventResponse.statusCode : 'ERR',\n },\n message\n );\n })\n .on('downloadProgress', (progress) => {\n if (progress.total) {\n debug('responseLength %s', progress.total);\n responseLength = progress.total;\n }\n });\n const etag = response.headers.etag as string;\n const data = response.body;\n\n // not modified status (304) registry does not return any payload\n // it is handled as an error with the original 304 status preserved\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n const err = errorUtils.getNotFound(API_ERROR.NOT_MODIFIED_NO_DATA);\n err.code = HTTP_STATUS.NOT_MODIFIED;\n throw err;\n }\n\n debug('uri %s success', uri);\n const message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n this.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n request: { method: method, url: uri },\n status: response.statusCode,\n bytes: {\n in: options?.json ? JSON.stringify(options?.json).length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n return [data, etag];\n } catch (err: any) {\n debug('error %s on uri %s', err.code, uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n debug('error code %s', code);\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(`${API_ERROR.BAD_STATUS_CODE}: ${code}`);\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\n } else if (this._isRequestTimeout(err)) {\n debug('error code timeout');\n throw errorUtils.getServiceUnavailable(API_ERROR.SERVER_TIME_OUT);\n }\n throw err;\n }\n }\n\n // FIXME: handle stream and retry\n public fetchTarball(\n url: string,\n overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>\n ): any {\n debug('fetching url for %s', url);\n const options = { ...this.config, ...overrideOptions };\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = 'GET';\n // const uri = this.config.url + `/${encode(name)}`;\n debug('request uri for %s', url);\n\n const readStream = got\n .stream(url, {\n headers,\n method,\n agent: this.agent,\n // FIXME: this should be taken from construtor as priority\n retry: this.retry ?? options?.retry,\n timeout: this.timeout,\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n });\n\n return readStream;\n }\n\n /**\n * Perform a stream search.\n * @param {*} options request options\n * @return {Stream}\n */\n public async search({ url, abort, retry }: ProxySearchParams): Promise<Stream.Readable> {\n try {\n // Incoming URL is relative ie /-/v1/search...\n const uri = new URL(url, this.url).href;\n this.logger.http(\n { uri, uplink: this.uplinkName },\n 'search request to uplink @{uplink} - @{uri}'\n );\n debug('searching on %o', uri);\n const response = got(uri, {\n signal: abort ? abort.signal : {},\n agent: this.agent,\n timeout: this.timeout,\n retry: retry ?? this.retry,\n });\n\n const res = await response.text();\n const total = JSON.parse(res).total;\n debug('number of packages found: %o', total);\n const streamSearch = new PassThrough({ objectMode: true });\n const streamResponse = Readable.from(res);\n // objects is one of the properties on the body, it ignores date and total\n streamResponse.pipe(JSONStream.parse('objects')).pipe(streamSearch, { end: true });\n return streamSearch;\n } catch (err: any) {\n debug('search error %s', err);\n if (err.response.statusCode === 409) {\n throw errorUtils.getInternalError(`bad status code ${err.response.statusCode} from uplink`);\n }\n this.logger.error(\n { errorMessage: err?.message, name: this.uplinkName },\n 'proxy uplink @{name} search error: @{errorMessage}'\n );\n throw err;\n }\n }\n\n private addProxyHeaders(headers: gotHeaders, remoteAddress?: string): gotHeaders {\n // Only submit X-Forwarded-For field if we don't have a proxy selected\n // in the config file.\n //\n // Otherwise misconfigured proxy could return 407\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (headers['x-forwarded-for'] ? headers['x-forwarded-for'] + ', ' : '') + remoteAddress;\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['via'] = headers['via'] ? headers['via'] + ', ' : '';\n headers['via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n\n return headers;\n }\n\n /**\n * If the request failure.\n * @return {boolean}\n * @private\n */\n private _ifRequestFailure(): boolean {\n return (\n this.failed_requests >= this.max_fails &&\n Math.abs(Date.now() - (this.last_request_time as number)) < this.fail_timeout\n );\n }\n\n /**\n * Check if the request timed out (network or http errors).\n * @param {RequestError} err\n * @return {boolean}\n */\n private _isRequestTimeout(err: RequestError): boolean {\n const code = err?.response?.statusCode;\n return (\n err.code === 'ETIMEDOUT' ||\n err.code === 'ESOCKETTIMEDOUT' ||\n err.code === 'ECONNRESET' ||\n code === HTTP_STATUS.REQUEST_TIMEOUT ||\n code === HTTP_STATUS.BAD_GATEWAY ||\n code === HTTP_STATUS.SERVICE_UNAVAILABLE ||\n code === HTTP_STATUS.GATEWAY_TIMEOUT\n );\n }\n\n /**\n * Set up a proxy.\n * @param {*} hostname\n * @param {*} config\n * @param {*} mainconfig\n * @param {*} isHTTPS\n */\n private _setupProxy(\n hostname: string,\n config: UpLinkConfLocal,\n mainconfig: Config,\n isHTTPS: boolean\n ): void {\n let noProxyList;\n const proxy_key: string = isHTTPS ? 'https_proxy' : 'http_proxy';\n debug('looking for %o', proxy_key);\n\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n debug('found %o in uplink config', this.proxy);\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\n debug('found %o in main config', this.proxy);\n }\n if ('no_proxy' in config) {\n noProxyList = config.no_proxy;\n } else if ('no_proxy' in mainconfig) {\n noProxyList = mainconfig.no_proxy;\n }\n\n // use wget-like algorithm to determine if proxy shouldn't be used\n if (hostname[0] !== '.') {\n hostname = '.' + hostname;\n }\n\n if (_.isString(noProxyList) && noProxyList.length) {\n noProxyList = noProxyList.split(',');\n }\n\n if (_.isArray(noProxyList)) {\n for (let i = 0; i < noProxyList.length; i++) {\n let noProxyItem = noProxyList[i];\n if (noProxyItem[0] !== '.') {\n noProxyItem = '.' + noProxyItem;\n }\n if (hostname.endsWith(noProxyItem)) {\n if (this.proxy) {\n debug('not using proxy, excluded by @{rule}', noProxyItem);\n this.logger.debug(\n { url: this.url.href, rule: noProxyItem },\n 'not using proxy for @{url}, excluded by @{rule} rule'\n );\n this.proxy = undefined;\n }\n break;\n }\n }\n }\n\n if (typeof this.proxy === 'string') {\n debug('using proxy @{proxy} for @{url}', this.proxy, this.url.href);\n this.logger.debug(\n { url: this.url.href, proxy: this.proxy },\n 'using proxy @{proxy} for @{url}'\n );\n }\n }\n}\n\nexport { ProxyStorage };\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,IAAM,WAAA,GAAA,MAAA,SAAmB,kBAAkB;AAE3C,IAAM,SAAS,SAAU,OAAe;AACtC,QAAO,mBAAmB,MAAM,CAAC,QAAQ,QAAQ,IAAI;;AAIvD,IAAM,oBAAoB,GADF,gBAAA,QAAQ,KACa;;;;AAK7C,IAAM,aAAa,QAAyB,KAAa,QAAgB;AACvE,QAAO,OAAA,QAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,OAAO,OAAO;;;;;;AAuDxD,IAAM,eAAN,MAAqC;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA,YACE,YACA,QACA,YACA,QACA,OACA;AACA,OAAK,aAAa;AAClB,OAAK,SAAS;AACd,OAAK,kBAAkB;AACvB,OAAK,YAAY,WAAW,cAAc;AAC1C,OAAK,KAAK,OAAO;A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C,kCACD"}
|
|
1
|
+
{"version":3,"file":"proxy.js","names":[],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport type { Agents, Delays, RequestError, RetryOptions, Headers as gotHeaders } from 'got';\nimport got, { Options } from 'got';\nimport _ from 'lodash';\nimport type Stream from 'node:stream';\nimport { PassThrough, Readable } from 'node:stream';\nimport { URL } from 'node:url';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n authUtils,\n constants,\n errorUtils,\n} from '@verdaccio/core';\nimport type { AgentOptionsConf, Config, Logger, Manifest, UpLinkConf } from '@verdaccio/types';\n\nimport CustomAgents from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst debug = buildDebug('verdaccio:proxy');\n\nconst encode = function (thing): string {\n return encodeURIComponent(thing).replace(/^%40/, '@');\n};\n\nconst jsonContentType = HEADERS.JSON;\nconst contentTypeAccept = `${jsonContentType};`;\n\n/**\n * Just a helper (`config[key] || default` doesn't work because of zeroes)\n */\nconst setConfig = (config: UpLinkConfLocal, key: string, def): string => {\n return _.isNil(config[key]) === false ? config[key] : def;\n};\n\nexport type UpLinkConfLocal = UpLinkConf & {\n no_proxy?: string;\n};\n\nexport interface ProxyList {\n [key: string]: IProxy;\n}\n\nexport type ProxySearchParams = {\n url: string;\n abort: AbortController;\n query?: searchUtils.SearchQuery;\n headers?: Headers;\n retry?: Partial<RetryOptions>;\n};\nexport interface IProxy {\n uplinkName: string;\n config: UpLinkConfLocal;\n failed_requests: number;\n userAgent: string;\n ca?: string | void;\n logger: Logger;\n server_id: string;\n url: URL;\n maxage: number;\n timeout: Delays;\n max_fails: number;\n fail_timeout: number;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]>;\n fetchTarball(\n url: string,\n options: Partial<Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>>\n ): PassThrough;\n}\n\n// this type is need it by storage\nexport { Options as FetchOptions };\n\nexport interface ISyncUplinksOptions extends Options {\n uplinksLook?: boolean;\n etag?: string;\n remoteAddress?: string;\n}\n\n/**\n * Implements Storage interface\n * (same for storage.js, local-storage.js, up-storage.js)\n */\nclass ProxyStorage implements IProxy {\n public uplinkName: string;\n public config: UpLinkConfLocal;\n public failed_requests: number;\n public userAgent: string;\n public ca: string | void;\n public logger: Logger;\n public server_id: string;\n public url: URL;\n public maxage: number;\n public timeout: Delays;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n public proxy: string | undefined;\n private agent: Agents;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n private retry: Partial<RetryOptions>;\n\n public constructor(\n uplinkName: string,\n config: UpLinkConfLocal,\n mainConfig: Config,\n logger: Logger,\n agent?: Agents\n ) {\n this.uplinkName = uplinkName;\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent ?? 'hidden';\n this.ca = config.ca;\n this.logger = logger;\n this.server_id = mainConfig.server_id;\n this.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n }) as AgentOptionsConf;\n this.url = new URL(this.config.url);\n const isHTTPS = this.url.protocol === 'https:';\n this._setupProxy(this.url.hostname, config, mainConfig, isHTTPS);\n this.agent = agent ?? this.getAgent();\n this.config.url = this.config.url.replace(/\\/$/, '');\n\n if (this.config.timeout && Number(this.config.timeout) >= 1000) {\n this.logger.warn(\n [\n 'Too big timeout value: ' + this.config.timeout,\n 'We changed time format to nginx-like one',\n '(see http://nginx.org/en/docs/syntax.html)',\n 'so please update your config accordingly',\n ].join('\\n')\n );\n }\n\n // a bunch of different configurable timers\n this.maxage = parseInterval(setConfig(this.config, 'maxage', '2m'));\n // https://github.com/sindresorhus/got/blob/main/documentation/6-timeout.md\n this.timeout = {\n request: parseInterval(setConfig(this.config, 'timeout', '30s')),\n };\n debug('set timeout %s', this.timeout);\n this.max_fails = Number(setConfig(this.config, 'max_fails', this.config.max_fails ?? 2));\n this.fail_timeout = parseInterval(setConfig(this.config, 'fail_timeout', '5m'));\n this.strict_ssl = Boolean(setConfig(this.config, 'strict_ssl', true));\n this.retry = { limit: this.max_fails ?? 2 };\n }\n\n private getAgent() {\n if (!this.agent) {\n // TODO: the config.ca (certificates) is not yet injected here\n const agentInstance = new CustomAgents(this.config.url, this.proxy, this.agent_options);\n return agentInstance.get();\n } else {\n return this.agent;\n }\n }\n\n public getHeaders(headers = {}): gotHeaders {\n const accept = HEADERS.ACCEPT;\n const acceptEncoding = HEADERS.ACCEPT_ENCODING;\n const userAgent = HEADERS.USER_AGENT;\n\n headers[accept] = headers[accept] || contentTypeAccept;\n headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';\n // registry.npmjs.org will only return search result if user-agent include string 'npm'\n headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;\n return this.setAuthNext(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private setAuthNext(headers: gotHeaders): gotHeaders {\n const { auth } = this.config;\n if (typeof auth === 'undefined' || typeof headers[HEADERS.AUTHORIZATION] === 'string') {\n return headers;\n }\n\n if (_.isObject(auth) === false && _.isObject((auth as any).token) === false) {\n this._throwErrorAuth('Auth invalid');\n }\n\n // get NPM_TOKEN http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules\n // or get other variable export in env\n // https://github.com/verdaccio/verdaccio/releases/tag/v2.5.0\n let token: any;\n const tokenConf: any = auth;\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n debug('use token from config');\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n debug('use token from env %o', tokenConf.token_env);\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n } else {\n this.logger.error(constants.ERROR_CODE.token_required);\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n } else {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n }\n\n if (typeof token === 'undefined') {\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n\n // define type Auth allow basic and bearer\n const type = tokenConf.type || TOKEN_BASIC;\n debug('token type %o', type);\n this._setHeaderAuthorization(headers, type, token);\n\n return headers;\n }\n\n /**\n * @param {string} message\n * @throws {Error}\n * @private\n */\n private _throwErrorAuth(message: string): Error {\n this.logger.error(message);\n throw new Error(message);\n }\n\n /**\n * Assign Header authorization with type authentication\n * @param {Object} headers\n * @param {string} type\n * @param {string} token\n * @private\n */\n private _setHeaderAuthorization(headers: any, type: string, token: any): void {\n const _type: string = type.toLowerCase();\n\n if (_type !== TOKEN_BEARER.toLowerCase() && _type !== TOKEN_BASIC.toLowerCase()) {\n this._throwErrorAuth(`Auth type '${_type}' not allowed`);\n }\n\n headers[HEADERS.AUTHORIZATION] = authUtils.buildToken(type, token);\n }\n\n /**\n * It will add or override specified headers from config file.\n *\n * Eg:\n *\n * uplinks:\n npmjs:\n url: https://registry.npmjs.org/\n headers:\n Accept: \"application/vnd.npm.install-v2+json; q=1.0\"\n verdaccio-staging:\n url: https://mycompany.com/npm\n headers:\n Accept: \"application/json\"\n authorization: \"Basic YourBase64EncodedCredentials==\"\n\n * @param {Object} headers\n * @private\n */\n private applyUplinkHeaders(headers: gotHeaders): gotHeaders {\n if (!this.config.headers) {\n return headers;\n }\n\n // add/override headers specified in the config\n /* eslint guard-for-in: 0 */\n for (const key in this.config.headers) {\n headers[key] = this.config.headers[key];\n }\n return headers;\n }\n\n public async getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]> {\n if (this._ifRequestFailure()) {\n throw errorUtils.getInternalError(API_ERROR.UPLINK_OFFLINE);\n }\n\n // FUTURE: allow mix headers that comes from the client\n debug('getting metadata for package %s', name);\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = options.method || 'GET';\n const uri = this.config.url + `/${encode(name)}`;\n debug('set retry limit is %s', this.retry.limit);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry initial count %s', retry);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n timeout: this.timeout,\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('after response code is %s', code);\n if (code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES) {\n if (this.failed_requests >= this.max_fails) {\n this.failed_requests = 0;\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now online'\n );\n }\n }\n\n return afterResponse;\n },\n ],\n beforeRetry: [\n (error: RequestError, count: number) => {\n debug('retry %s count: %s', uri, count);\n this.failed_requests = count ?? 0;\n this.logger.info(\n {\n request: {\n method: method,\n url: uri,\n },\n error: error.message,\n retryCount: this.failed_requests,\n },\n \"retry @{retryCount} req: '@{request.method} @{request.url}'\"\n );\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now offline'\n );\n }\n },\n ],\n },\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n })\n .on<any>('response', (eventResponse) => {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n this.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(eventResponse) === false ? eventResponse.statusCode : 'ERR',\n },\n message\n );\n })\n .on('downloadProgress', (progress) => {\n if (progress.total) {\n debug('responseLength %s', progress.total);\n responseLength = progress.total;\n }\n });\n const etag = response.headers.etag as string;\n const data = response.body;\n\n // not modified status (304) registry does not return any payload\n // it is handled as an error with the original 304 status preserved\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n const err = errorUtils.getNotFound(API_ERROR.NOT_MODIFIED_NO_DATA);\n err.code = HTTP_STATUS.NOT_MODIFIED;\n throw err;\n }\n\n debug('uri %s success', uri);\n const message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n this.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n request: { method: method, url: uri },\n status: response.statusCode,\n bytes: {\n in: options?.json ? JSON.stringify(options?.json).length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n return [data, etag];\n } catch (err: any) {\n debug('error %s on uri %s', err.code, uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n debug('error code %s', code);\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(`${API_ERROR.BAD_STATUS_CODE}: ${code}`);\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\n } else if (this._isRequestTimeout(err)) {\n debug('error code timeout');\n throw errorUtils.getServiceUnavailable(API_ERROR.SERVER_TIME_OUT);\n }\n throw err;\n }\n }\n\n // FIXME: handle stream and retry\n public fetchTarball(\n url: string,\n overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>\n ): any {\n debug('fetching url for %s', url);\n const options = { ...this.config, ...overrideOptions };\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = 'GET';\n // const uri = this.config.url + `/${encode(name)}`;\n debug('request uri for %s', url);\n\n const readStream = got\n .stream(url, {\n headers,\n method,\n agent: this.agent,\n // FIXME: this should be taken from construtor as priority\n retry: this.retry ?? options?.retry,\n timeout: this.timeout,\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n });\n\n return readStream;\n }\n\n /**\n * Perform a stream search.\n * @param {*} options request options\n * @return {Stream}\n */\n public async search({ url, abort, retry }: ProxySearchParams): Promise<Stream.Readable> {\n try {\n // Incoming URL is relative ie /-/v1/search...\n const uri = new URL(url, this.url).href;\n this.logger.http(\n { uri, uplink: this.uplinkName },\n 'search request to uplink @{uplink} - @{uri}'\n );\n debug('searching on %o', uri);\n const response = got(uri, {\n signal: abort ? abort.signal : {},\n agent: this.agent,\n timeout: this.timeout,\n retry: retry ?? this.retry,\n });\n\n const res = await response.text();\n const total = JSON.parse(res).total;\n debug('number of packages found: %o', total);\n const streamSearch = new PassThrough({ objectMode: true });\n const streamResponse = Readable.from(res);\n // objects is one of the properties on the body, it ignores date and total\n streamResponse.pipe(JSONStream.parse('objects')).pipe(streamSearch, { end: true });\n return streamSearch;\n } catch (err: any) {\n debug('search error %s', err);\n if (err.response.statusCode === 409) {\n throw errorUtils.getInternalError(`bad status code ${err.response.statusCode} from uplink`);\n }\n this.logger.error(\n { errorMessage: err?.message, name: this.uplinkName },\n 'proxy uplink @{name} search error: @{errorMessage}'\n );\n throw err;\n }\n }\n\n private addProxyHeaders(headers: gotHeaders, remoteAddress?: string): gotHeaders {\n // Only submit X-Forwarded-For field if we don't have a proxy selected\n // in the config file.\n //\n // Otherwise misconfigured proxy could return 407\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (headers['x-forwarded-for'] ? headers['x-forwarded-for'] + ', ' : '') + remoteAddress;\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['via'] = headers['via'] ? headers['via'] + ', ' : '';\n headers['via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n\n return headers;\n }\n\n /**\n * If the request failure.\n * @return {boolean}\n * @private\n */\n private _ifRequestFailure(): boolean {\n return (\n this.failed_requests >= this.max_fails &&\n Math.abs(Date.now() - (this.last_request_time as number)) < this.fail_timeout\n );\n }\n\n /**\n * Check if the request timed out (network or http errors).\n * @param {RequestError} err\n * @return {boolean}\n */\n private _isRequestTimeout(err: RequestError): boolean {\n const code = err?.response?.statusCode;\n return (\n err.code === 'ETIMEDOUT' ||\n err.code === 'ESOCKETTIMEDOUT' ||\n err.code === 'ECONNRESET' ||\n code === HTTP_STATUS.REQUEST_TIMEOUT ||\n code === HTTP_STATUS.BAD_GATEWAY ||\n code === HTTP_STATUS.SERVICE_UNAVAILABLE ||\n code === HTTP_STATUS.GATEWAY_TIMEOUT\n );\n }\n\n /**\n * Set up a proxy.\n * @param {*} hostname\n * @param {*} config\n * @param {*} mainconfig\n * @param {*} isHTTPS\n */\n private _setupProxy(\n hostname: string,\n config: UpLinkConfLocal,\n mainconfig: Config,\n isHTTPS: boolean\n ): void {\n let noProxyList;\n const proxy_key: string = isHTTPS ? 'https_proxy' : 'http_proxy';\n debug('looking for %o', proxy_key);\n\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n debug('found %o in uplink config', this.proxy);\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\n debug('found %o in main config', this.proxy);\n }\n if ('no_proxy' in config) {\n noProxyList = config.no_proxy;\n } else if ('no_proxy' in mainconfig) {\n noProxyList = mainconfig.no_proxy;\n }\n\n // use wget-like algorithm to determine if proxy shouldn't be used\n if (hostname[0] !== '.') {\n hostname = '.' + hostname;\n }\n\n if (_.isString(noProxyList) && noProxyList.length) {\n noProxyList = noProxyList.split(',');\n }\n\n if (_.isArray(noProxyList)) {\n for (let i = 0; i < noProxyList.length; i++) {\n let noProxyItem = noProxyList[i];\n if (noProxyItem[0] !== '.') {\n noProxyItem = '.' + noProxyItem;\n }\n if (hostname.endsWith(noProxyItem)) {\n if (this.proxy) {\n debug('not using proxy, excluded by @{rule}', noProxyItem);\n this.logger.debug(\n { url: this.url.href, rule: noProxyItem },\n 'not using proxy for @{url}, excluded by @{rule} rule'\n );\n this.proxy = undefined;\n }\n break;\n }\n }\n }\n\n if (typeof this.proxy === 'string') {\n debug('using proxy @{proxy} for @{url}', this.proxy, this.url.href);\n this.logger.debug(\n { url: this.url.href, proxy: this.proxy },\n 'using proxy @{proxy} for @{url}'\n );\n }\n }\n}\n\nexport { ProxyStorage };\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,IAAM,WAAA,GAAA,MAAA,SAAmB,kBAAkB;AAE3C,IAAM,SAAS,SAAU,OAAe;AACtC,QAAO,mBAAmB,MAAM,CAAC,QAAQ,QAAQ,IAAI;;AAIvD,IAAM,oBAAoB,GADF,gBAAA,QAAQ,KACa;;;;AAK7C,IAAM,aAAa,QAAyB,KAAa,QAAgB;AACvE,QAAO,OAAA,QAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,OAAO,OAAO;;;;;;AAuDxD,IAAM,eAAN,MAAqC;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA,YACE,YACA,QACA,YACA,QACA,OACA;AACA,OAAK,aAAa;AAClB,OAAK,SAAS;AACd,OAAK,kBAAkB;AACvB,OAAK,YAAY,WAAW,cAAc;AAC1C,OAAK,KAAK,OAAO;AACjB,OAAK,SAAS;AACd,OAAK,YAAY,WAAW;AAC5B,OAAK,gBAAgB,UAAU,KAAK,QAAQ,iBAAiB;GAC3D,WAAW;GACX,YAAY;GACZ,gBAAgB;GACjB,CAAC;AACF,OAAK,MAAM,IAAI,SAAA,IAAI,KAAK,OAAO,IAAI;EACnC,MAAM,UAAU,KAAK,IAAI,aAAa;AACtC,OAAK,YAAY,KAAK,IAAI,UAAU,QAAQ,YAAY,QAAQ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ACM;EACN,IAAI;EACJ,MAAM,YAAoB,UAAU,gBAAgB;AACpD,UAAM,kBAAkB,UAAU;AAGlC,MAAI,aAAa,QAAQ;AACvB,QAAK,QAAQ,OAAO;AACpB,WAAM,6BAA6B,KAAK,MAAM;aACrC,aAAa,YAAY;AAClC,QAAK,QAAQ,WAAW;AACxB,WAAM,2BAA2B,KAAK,MAAM;;AAE9C,MAAI,cAAc,OAChB,eAAc,OAAO;WACZ,cAAc,WACvB,eAAc,WAAW;AAI3B,MAAI,SAAS,OAAO,IAClB,YAAW,MAAM;AAGnB,MAAI,OAAA,QAAE,SAAS,YAAY,IAAI,YAAY,OACzC,eAAc,YAAY,MAAM,IAAI;AAGtC,MAAI,OAAA,QAAE,QAAQ,YAAY,CACxB,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;GAC3C,IAAI,cAAc,YAAY;AAC9B,OAAI,YAAY,OAAO,IACrB,eAAc,MAAM;AAEtB,OAAI,SAAS,SAAS,YAAY,EAAE;AAClC,QAAI,KAAK,OAAO;AACd,aAAM,wCAAwC,YAAY;AAC1D,UAAK,OAAO,MACV;MAAE,KAAK,KAAK,IAAI;MAAM,MAAM;MAAa,EACzC,uDACD;AACD,UAAK,QAAQ,KAAA;;AAEf;;;AAKN,MAAI,OAAO,KAAK,UAAU,UAAU;AAClC,WAAM,mCAAmC,KAAK,OAAO,KAAK,IAAI,KAAK;AACnE,QAAK,OAAO,MACV;IAAE,KAAK,KAAK,IAAI;IAAM,OAAO,KAAK;IAAO,EACzC,kCACD"}
|
package/build/proxy.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import CustomAgents from "./agent.mjs";
|
|
|
2
2
|
import { parseInterval } from "./proxy-utils.mjs";
|
|
3
3
|
import JSONStream from "JSONStream";
|
|
4
4
|
import buildDebug from "debug";
|
|
5
|
-
import got, { Options } from "got
|
|
5
|
+
import got, { Options } from "got";
|
|
6
6
|
import _ from "lodash";
|
|
7
7
|
import { PassThrough, Readable } from "node:stream";
|
|
8
8
|
import { URL } from "node:url";
|
package/build/proxy.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.mjs","names":[],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport type { Agents, Delays, RequestError, RetryOptions, Headers as gotHeaders } from 'got-cjs';\nimport got, { Options } from 'got-cjs';\nimport _ from 'lodash';\nimport type Stream from 'node:stream';\nimport { PassThrough, Readable } from 'node:stream';\nimport { URL } from 'node:url';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n authUtils,\n constants,\n errorUtils,\n} from '@verdaccio/core';\nimport type { AgentOptionsConf, Config, Logger, Manifest, UpLinkConf } from '@verdaccio/types';\n\nimport CustomAgents from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst debug = buildDebug('verdaccio:proxy');\n\nconst encode = function (thing): string {\n return encodeURIComponent(thing).replace(/^%40/, '@');\n};\n\nconst jsonContentType = HEADERS.JSON;\nconst contentTypeAccept = `${jsonContentType};`;\n\n/**\n * Just a helper (`config[key] || default` doesn't work because of zeroes)\n */\nconst setConfig = (config: UpLinkConfLocal, key: string, def): string => {\n return _.isNil(config[key]) === false ? config[key] : def;\n};\n\nexport type UpLinkConfLocal = UpLinkConf & {\n no_proxy?: string;\n};\n\nexport interface ProxyList {\n [key: string]: IProxy;\n}\n\nexport type ProxySearchParams = {\n url: string;\n abort: AbortController;\n query?: searchUtils.SearchQuery;\n headers?: Headers;\n retry?: Partial<RetryOptions>;\n};\nexport interface IProxy {\n uplinkName: string;\n config: UpLinkConfLocal;\n failed_requests: number;\n userAgent: string;\n ca?: string | void;\n logger: Logger;\n server_id: string;\n url: URL;\n maxage: number;\n timeout: Delays;\n max_fails: number;\n fail_timeout: number;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]>;\n fetchTarball(\n url: string,\n options: Partial<Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>>\n ): PassThrough;\n}\n\n// this type is need it by storage\nexport { Options as FetchOptions };\n\nexport interface ISyncUplinksOptions extends Options {\n uplinksLook?: boolean;\n etag?: string;\n remoteAddress?: string;\n}\n\n/**\n * Implements Storage interface\n * (same for storage.js, local-storage.js, up-storage.js)\n */\nclass ProxyStorage implements IProxy {\n public uplinkName: string;\n public config: UpLinkConfLocal;\n public failed_requests: number;\n public userAgent: string;\n public ca: string | void;\n public logger: Logger;\n public server_id: string;\n public url: URL;\n public maxage: number;\n public timeout: Delays;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n public proxy: string | undefined;\n private agent: Agents;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n private retry: Partial<RetryOptions>;\n\n public constructor(\n uplinkName: string,\n config: UpLinkConfLocal,\n mainConfig: Config,\n logger: Logger,\n agent?: Agents\n ) {\n this.uplinkName = uplinkName;\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent ?? 'hidden';\n this.ca = config.ca;\n this.logger = logger;\n this.server_id = mainConfig.server_id;\n this.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n }) as AgentOptionsConf;\n this.url = new URL(this.config.url);\n const isHTTPS = this.url.protocol === 'https:';\n this._setupProxy(this.url.hostname, config, mainConfig, isHTTPS);\n this.agent = agent ?? this.getAgent();\n this.config.url = this.config.url.replace(/\\/$/, '');\n\n if (this.config.timeout && Number(this.config.timeout) >= 1000) {\n this.logger.warn(\n [\n 'Too big timeout value: ' + this.config.timeout,\n 'We changed time format to nginx-like one',\n '(see http://nginx.org/en/docs/syntax.html)',\n 'so please update your config accordingly',\n ].join('\\n')\n );\n }\n\n // a bunch of different configurable timers\n this.maxage = parseInterval(setConfig(this.config, 'maxage', '2m'));\n // https://github.com/sindresorhus/got/blob/main/documentation/6-timeout.md\n this.timeout = {\n request: parseInterval(setConfig(this.config, 'timeout', '30s')),\n };\n debug('set timeout %s', this.timeout);\n this.max_fails = Number(setConfig(this.config, 'max_fails', this.config.max_fails ?? 2));\n this.fail_timeout = parseInterval(setConfig(this.config, 'fail_timeout', '5m'));\n this.strict_ssl = Boolean(setConfig(this.config, 'strict_ssl', true));\n this.retry = { limit: this.max_fails ?? 2 };\n }\n\n private getAgent() {\n if (!this.agent) {\n // TODO: the config.ca (certificates) is not yet injected here\n const agentInstance = new CustomAgents(this.config.url, this.proxy, this.agent_options);\n return agentInstance.get();\n } else {\n return this.agent;\n }\n }\n\n public getHeaders(headers = {}): gotHeaders {\n const accept = HEADERS.ACCEPT;\n const acceptEncoding = HEADERS.ACCEPT_ENCODING;\n const userAgent = HEADERS.USER_AGENT;\n\n headers[accept] = headers[accept] || contentTypeAccept;\n headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';\n // registry.npmjs.org will only return search result if user-agent include string 'npm'\n headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;\n return this.setAuthNext(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private setAuthNext(headers: gotHeaders): gotHeaders {\n const { auth } = this.config;\n if (typeof auth === 'undefined' || typeof headers[HEADERS.AUTHORIZATION] === 'string') {\n return headers;\n }\n\n if (_.isObject(auth) === false && _.isObject((auth as any).token) === false) {\n this._throwErrorAuth('Auth invalid');\n }\n\n // get NPM_TOKEN http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules\n // or get other variable export in env\n // https://github.com/verdaccio/verdaccio/releases/tag/v2.5.0\n let token: any;\n const tokenConf: any = auth;\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n debug('use token from config');\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n debug('use token from env %o', tokenConf.token_env);\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n } else {\n this.logger.error(constants.ERROR_CODE.token_required);\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n } else {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n }\n\n if (typeof token === 'undefined') {\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n\n // define type Auth allow basic and bearer\n const type = tokenConf.type || TOKEN_BASIC;\n debug('token type %o', type);\n this._setHeaderAuthorization(headers, type, token);\n\n return headers;\n }\n\n /**\n * @param {string} message\n * @throws {Error}\n * @private\n */\n private _throwErrorAuth(message: string): Error {\n this.logger.error(message);\n throw new Error(message);\n }\n\n /**\n * Assign Header authorization with type authentication\n * @param {Object} headers\n * @param {string} type\n * @param {string} token\n * @private\n */\n private _setHeaderAuthorization(headers: any, type: string, token: any): void {\n const _type: string = type.toLowerCase();\n\n if (_type !== TOKEN_BEARER.toLowerCase() && _type !== TOKEN_BASIC.toLowerCase()) {\n this._throwErrorAuth(`Auth type '${_type}' not allowed`);\n }\n\n headers[HEADERS.AUTHORIZATION] = authUtils.buildToken(type, token);\n }\n\n /**\n * It will add or override specified headers from config file.\n *\n * Eg:\n *\n * uplinks:\n npmjs:\n url: https://registry.npmjs.org/\n headers:\n Accept: \"application/vnd.npm.install-v2+json; q=1.0\"\n verdaccio-staging:\n url: https://mycompany.com/npm\n headers:\n Accept: \"application/json\"\n authorization: \"Basic YourBase64EncodedCredentials==\"\n\n * @param {Object} headers\n * @private\n */\n private applyUplinkHeaders(headers: gotHeaders): gotHeaders {\n if (!this.config.headers) {\n return headers;\n }\n\n // add/override headers specified in the config\n /* eslint guard-for-in: 0 */\n for (const key in this.config.headers) {\n headers[key] = this.config.headers[key];\n }\n return headers;\n }\n\n public async getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]> {\n if (this._ifRequestFailure()) {\n throw errorUtils.getInternalError(API_ERROR.UPLINK_OFFLINE);\n }\n\n // FUTURE: allow mix headers that comes from the client\n debug('getting metadata for package %s', name);\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = options.method || 'GET';\n const uri = this.config.url + `/${encode(name)}`;\n debug('set retry limit is %s', this.retry.limit);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry initial count %s', retry);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n timeout: this.timeout,\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('after response code is %s', code);\n if (code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES) {\n if (this.failed_requests >= this.max_fails) {\n this.failed_requests = 0;\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now online'\n );\n }\n }\n\n return afterResponse;\n },\n ],\n beforeRetry: [\n (error: RequestError, count: number) => {\n debug('retry %s count: %s', uri, count);\n this.failed_requests = count ?? 0;\n this.logger.info(\n {\n request: {\n method: method,\n url: uri,\n },\n error: error.message,\n retryCount: this.failed_requests,\n },\n \"retry @{retryCount} req: '@{request.method} @{request.url}'\"\n );\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now offline'\n );\n }\n },\n ],\n },\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n })\n .on<any>('response', (eventResponse) => {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n this.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(eventResponse) === false ? eventResponse.statusCode : 'ERR',\n },\n message\n );\n })\n .on('downloadProgress', (progress) => {\n if (progress.total) {\n debug('responseLength %s', progress.total);\n responseLength = progress.total;\n }\n });\n const etag = response.headers.etag as string;\n const data = response.body;\n\n // not modified status (304) registry does not return any payload\n // it is handled as an error with the original 304 status preserved\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n const err = errorUtils.getNotFound(API_ERROR.NOT_MODIFIED_NO_DATA);\n err.code = HTTP_STATUS.NOT_MODIFIED;\n throw err;\n }\n\n debug('uri %s success', uri);\n const message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n this.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n request: { method: method, url: uri },\n status: response.statusCode,\n bytes: {\n in: options?.json ? JSON.stringify(options?.json).length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n return [data, etag];\n } catch (err: any) {\n debug('error %s on uri %s', err.code, uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n debug('error code %s', code);\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(`${API_ERROR.BAD_STATUS_CODE}: ${code}`);\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\n } else if (this._isRequestTimeout(err)) {\n debug('error code timeout');\n throw errorUtils.getServiceUnavailable(API_ERROR.SERVER_TIME_OUT);\n }\n throw err;\n }\n }\n\n // FIXME: handle stream and retry\n public fetchTarball(\n url: string,\n overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>\n ): any {\n debug('fetching url for %s', url);\n const options = { ...this.config, ...overrideOptions };\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = 'GET';\n // const uri = this.config.url + `/${encode(name)}`;\n debug('request uri for %s', url);\n\n const readStream = got\n .stream(url, {\n headers,\n method,\n agent: this.agent,\n // FIXME: this should be taken from construtor as priority\n retry: this.retry ?? options?.retry,\n timeout: this.timeout,\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n });\n\n return readStream;\n }\n\n /**\n * Perform a stream search.\n * @param {*} options request options\n * @return {Stream}\n */\n public async search({ url, abort, retry }: ProxySearchParams): Promise<Stream.Readable> {\n try {\n // Incoming URL is relative ie /-/v1/search...\n const uri = new URL(url, this.url).href;\n this.logger.http(\n { uri, uplink: this.uplinkName },\n 'search request to uplink @{uplink} - @{uri}'\n );\n debug('searching on %o', uri);\n const response = got(uri, {\n signal: abort ? abort.signal : {},\n agent: this.agent,\n timeout: this.timeout,\n retry: retry ?? this.retry,\n });\n\n const res = await response.text();\n const total = JSON.parse(res).total;\n debug('number of packages found: %o', total);\n const streamSearch = new PassThrough({ objectMode: true });\n const streamResponse = Readable.from(res);\n // objects is one of the properties on the body, it ignores date and total\n streamResponse.pipe(JSONStream.parse('objects')).pipe(streamSearch, { end: true });\n return streamSearch;\n } catch (err: any) {\n debug('search error %s', err);\n if (err.response.statusCode === 409) {\n throw errorUtils.getInternalError(`bad status code ${err.response.statusCode} from uplink`);\n }\n this.logger.error(\n { errorMessage: err?.message, name: this.uplinkName },\n 'proxy uplink @{name} search error: @{errorMessage}'\n );\n throw err;\n }\n }\n\n private addProxyHeaders(headers: gotHeaders, remoteAddress?: string): gotHeaders {\n // Only submit X-Forwarded-For field if we don't have a proxy selected\n // in the config file.\n //\n // Otherwise misconfigured proxy could return 407\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (headers['x-forwarded-for'] ? headers['x-forwarded-for'] + ', ' : '') + remoteAddress;\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['via'] = headers['via'] ? headers['via'] + ', ' : '';\n headers['via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n\n return headers;\n }\n\n /**\n * If the request failure.\n * @return {boolean}\n * @private\n */\n private _ifRequestFailure(): boolean {\n return (\n this.failed_requests >= this.max_fails &&\n Math.abs(Date.now() - (this.last_request_time as number)) < this.fail_timeout\n );\n }\n\n /**\n * Check if the request timed out (network or http errors).\n * @param {RequestError} err\n * @return {boolean}\n */\n private _isRequestTimeout(err: RequestError): boolean {\n const code = err?.response?.statusCode;\n return (\n err.code === 'ETIMEDOUT' ||\n err.code === 'ESOCKETTIMEDOUT' ||\n err.code === 'ECONNRESET' ||\n code === HTTP_STATUS.REQUEST_TIMEOUT ||\n code === HTTP_STATUS.BAD_GATEWAY ||\n code === HTTP_STATUS.SERVICE_UNAVAILABLE ||\n code === HTTP_STATUS.GATEWAY_TIMEOUT\n );\n }\n\n /**\n * Set up a proxy.\n * @param {*} hostname\n * @param {*} config\n * @param {*} mainconfig\n * @param {*} isHTTPS\n */\n private _setupProxy(\n hostname: string,\n config: UpLinkConfLocal,\n mainconfig: Config,\n isHTTPS: boolean\n ): void {\n let noProxyList;\n const proxy_key: string = isHTTPS ? 'https_proxy' : 'http_proxy';\n debug('looking for %o', proxy_key);\n\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n debug('found %o in uplink config', this.proxy);\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\n debug('found %o in main config', this.proxy);\n }\n if ('no_proxy' in config) {\n noProxyList = config.no_proxy;\n } else if ('no_proxy' in mainconfig) {\n noProxyList = mainconfig.no_proxy;\n }\n\n // use wget-like algorithm to determine if proxy shouldn't be used\n if (hostname[0] !== '.') {\n hostname = '.' + hostname;\n }\n\n if (_.isString(noProxyList) && noProxyList.length) {\n noProxyList = noProxyList.split(',');\n }\n\n if (_.isArray(noProxyList)) {\n for (let i = 0; i < noProxyList.length; i++) {\n let noProxyItem = noProxyList[i];\n if (noProxyItem[0] !== '.') {\n noProxyItem = '.' + noProxyItem;\n }\n if (hostname.endsWith(noProxyItem)) {\n if (this.proxy) {\n debug('not using proxy, excluded by @{rule}', noProxyItem);\n this.logger.debug(\n { url: this.url.href, rule: noProxyItem },\n 'not using proxy for @{url}, excluded by @{rule} rule'\n );\n this.proxy = undefined;\n }\n break;\n }\n }\n }\n\n if (typeof this.proxy === 'string') {\n debug('using proxy @{proxy} for @{url}', this.proxy, this.url.href);\n this.logger.debug(\n { url: this.url.href, proxy: this.proxy },\n 'using proxy @{proxy} for @{url}'\n );\n }\n }\n}\n\nexport { ProxyStorage };\n"],"mappings":";;;;;;;;;;AAyBA,IAAM,QAAQ,WAAW,kBAAkB;AAE3C,IAAM,SAAS,SAAU,OAAe;AACtC,QAAO,mBAAmB,MAAM,CAAC,QAAQ,QAAQ,IAAI;;AAIvD,IAAM,oBAAoB,GADF,QAAQ,KACa;;;;AAK7C,IAAM,aAAa,QAAyB,KAAa,QAAgB;AACvE,QAAO,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,OAAO,OAAO;;;;;;AAuDxD,IAAM,eAAN,MAAqC;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA,YACE,YACA,QACA,YACA,QACA,OACA;AACA,OAAK,aAAa;AAClB,OAAK,SAAS;AACd,OAAK,kBAAkB;AACvB,OAAK,YAAY,WAAW,cAAc;AAC1C,OAAK,KAAK,OAAO;AACjB,OAAK,SAAS;AACd,OAAK,YAAY,WAAW;AAC5B,OAAK,gBAAgB,UAAU,KAAK,QAAQ,iBAAiB;GAC3D,WAAW;GACX,YAAY;GACZ,gBAAgB;GACjB,CAAC;AACF,OAAK,MAAM,IAAI,IAAI,KAAK,OAAO,IAAI;EACnC,MAAM,UAAU,KAAK,IAAI,aAAa;AACtC,OAAK,YA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,YAAY,IAAI,YAAY,OACzC,eAAc,YAAY,MAAM,IAAI;AAGtC,MAAI,EAAE,QAAQ,YAAY,CACxB,MAAK,IAAI,IAAI,GAAG,IAAI,YAAY,QAAQ,KAAK;GAC3C,IAAI,cAAc,YAAY;AAC9B,OAAI,YAAY,OAAO,IACrB,eAAc,MAAM;AAEtB,OAAI,SAAS,SAAS,YAAY,EAAE;AAClC,QAAI,KAAK,OAAO;AACd,WAAM,wCAAwC,YAAY;AAC1D,UAAK,OAAO,MACV;MAAE,KAAK,KAAK,IAAI;MAAM,MAAM;MAAa,EACzC,uDACD;AACD,UAAK,QAAQ,KAAA;;AAEf;;;AAKN,MAAI,OAAO,KAAK,UAAU,UAAU;AAClC,SAAM,mCAAmC,KAAK,OAAO,KAAK,IAAI,KAAK;AACnE,QAAK,OAAO,MACV;IAAE,KAAK,KAAK,IAAI;IAAM,OAAO,KAAK;IAAO,EACzC,kCACD"}
|
|
1
|
+
{"version":3,"file":"proxy.mjs","names":[],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport type { Agents, Delays, RequestError, RetryOptions, Headers as gotHeaders } from 'got';\nimport got, { Options } from 'got';\nimport _ from 'lodash';\nimport type Stream from 'node:stream';\nimport { PassThrough, Readable } from 'node:stream';\nimport { URL } from 'node:url';\n\nimport type { searchUtils } from '@verdaccio/core';\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n authUtils,\n constants,\n errorUtils,\n} from '@verdaccio/core';\nimport type { AgentOptionsConf, Config, Logger, Manifest, UpLinkConf } from '@verdaccio/types';\n\nimport CustomAgents from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst debug = buildDebug('verdaccio:proxy');\n\nconst encode = function (thing): string {\n return encodeURIComponent(thing).replace(/^%40/, '@');\n};\n\nconst jsonContentType = HEADERS.JSON;\nconst contentTypeAccept = `${jsonContentType};`;\n\n/**\n * Just a helper (`config[key] || default` doesn't work because of zeroes)\n */\nconst setConfig = (config: UpLinkConfLocal, key: string, def): string => {\n return _.isNil(config[key]) === false ? config[key] : def;\n};\n\nexport type UpLinkConfLocal = UpLinkConf & {\n no_proxy?: string;\n};\n\nexport interface ProxyList {\n [key: string]: IProxy;\n}\n\nexport type ProxySearchParams = {\n url: string;\n abort: AbortController;\n query?: searchUtils.SearchQuery;\n headers?: Headers;\n retry?: Partial<RetryOptions>;\n};\nexport interface IProxy {\n uplinkName: string;\n config: UpLinkConfLocal;\n failed_requests: number;\n userAgent: string;\n ca?: string | void;\n logger: Logger;\n server_id: string;\n url: URL;\n maxage: number;\n timeout: Delays;\n max_fails: number;\n fail_timeout: number;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]>;\n fetchTarball(\n url: string,\n options: Partial<Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>>\n ): PassThrough;\n}\n\n// this type is need it by storage\nexport { Options as FetchOptions };\n\nexport interface ISyncUplinksOptions extends Options {\n uplinksLook?: boolean;\n etag?: string;\n remoteAddress?: string;\n}\n\n/**\n * Implements Storage interface\n * (same for storage.js, local-storage.js, up-storage.js)\n */\nclass ProxyStorage implements IProxy {\n public uplinkName: string;\n public config: UpLinkConfLocal;\n public failed_requests: number;\n public userAgent: string;\n public ca: string | void;\n public logger: Logger;\n public server_id: string;\n public url: URL;\n public maxage: number;\n public timeout: Delays;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n public proxy: string | undefined;\n private agent: Agents;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n private retry: Partial<RetryOptions>;\n\n public constructor(\n uplinkName: string,\n config: UpLinkConfLocal,\n mainConfig: Config,\n logger: Logger,\n agent?: Agents\n ) {\n this.uplinkName = uplinkName;\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent ?? 'hidden';\n this.ca = config.ca;\n this.logger = logger;\n this.server_id = mainConfig.server_id;\n this.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n }) as AgentOptionsConf;\n this.url = new URL(this.config.url);\n const isHTTPS = this.url.protocol === 'https:';\n this._setupProxy(this.url.hostname, config, mainConfig, isHTTPS);\n this.agent = agent ?? this.getAgent();\n this.config.url = this.config.url.replace(/\\/$/, '');\n\n if (this.config.timeout && Number(this.config.timeout) >= 1000) {\n this.logger.warn(\n [\n 'Too big timeout value: ' + this.config.timeout,\n 'We changed time format to nginx-like one',\n '(see http://nginx.org/en/docs/syntax.html)',\n 'so please update your config accordingly',\n ].join('\\n')\n );\n }\n\n // a bunch of different configurable timers\n this.maxage = parseInterval(setConfig(this.config, 'maxage', '2m'));\n // https://github.com/sindresorhus/got/blob/main/documentation/6-timeout.md\n this.timeout = {\n request: parseInterval(setConfig(this.config, 'timeout', '30s')),\n };\n debug('set timeout %s', this.timeout);\n this.max_fails = Number(setConfig(this.config, 'max_fails', this.config.max_fails ?? 2));\n this.fail_timeout = parseInterval(setConfig(this.config, 'fail_timeout', '5m'));\n this.strict_ssl = Boolean(setConfig(this.config, 'strict_ssl', true));\n this.retry = { limit: this.max_fails ?? 2 };\n }\n\n private getAgent() {\n if (!this.agent) {\n // TODO: the config.ca (certificates) is not yet injected here\n const agentInstance = new CustomAgents(this.config.url, this.proxy, this.agent_options);\n return agentInstance.get();\n } else {\n return this.agent;\n }\n }\n\n public getHeaders(headers = {}): gotHeaders {\n const accept = HEADERS.ACCEPT;\n const acceptEncoding = HEADERS.ACCEPT_ENCODING;\n const userAgent = HEADERS.USER_AGENT;\n\n headers[accept] = headers[accept] || contentTypeAccept;\n headers[acceptEncoding] = headers[acceptEncoding] || 'gzip';\n // registry.npmjs.org will only return search result if user-agent include string 'npm'\n headers[userAgent] = headers[userAgent] || `npm (${this.userAgent})`;\n return this.setAuthNext(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private setAuthNext(headers: gotHeaders): gotHeaders {\n const { auth } = this.config;\n if (typeof auth === 'undefined' || typeof headers[HEADERS.AUTHORIZATION] === 'string') {\n return headers;\n }\n\n if (_.isObject(auth) === false && _.isObject((auth as any).token) === false) {\n this._throwErrorAuth('Auth invalid');\n }\n\n // get NPM_TOKEN http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules\n // or get other variable export in env\n // https://github.com/verdaccio/verdaccio/releases/tag/v2.5.0\n let token: any;\n const tokenConf: any = auth;\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n debug('use token from config');\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n debug('use token from env %o', tokenConf.token_env);\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n } else {\n this.logger.error(constants.ERROR_CODE.token_required);\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n } else {\n debug('use token from env NPM_TOKEN');\n token = process.env.NPM_TOKEN;\n }\n\n if (typeof token === 'undefined') {\n this._throwErrorAuth(constants.ERROR_CODE.token_required);\n }\n\n // define type Auth allow basic and bearer\n const type = tokenConf.type || TOKEN_BASIC;\n debug('token type %o', type);\n this._setHeaderAuthorization(headers, type, token);\n\n return headers;\n }\n\n /**\n * @param {string} message\n * @throws {Error}\n * @private\n */\n private _throwErrorAuth(message: string): Error {\n this.logger.error(message);\n throw new Error(message);\n }\n\n /**\n * Assign Header authorization with type authentication\n * @param {Object} headers\n * @param {string} type\n * @param {string} token\n * @private\n */\n private _setHeaderAuthorization(headers: any, type: string, token: any): void {\n const _type: string = type.toLowerCase();\n\n if (_type !== TOKEN_BEARER.toLowerCase() && _type !== TOKEN_BASIC.toLowerCase()) {\n this._throwErrorAuth(`Auth type '${_type}' not allowed`);\n }\n\n headers[HEADERS.AUTHORIZATION] = authUtils.buildToken(type, token);\n }\n\n /**\n * It will add or override specified headers from config file.\n *\n * Eg:\n *\n * uplinks:\n npmjs:\n url: https://registry.npmjs.org/\n headers:\n Accept: \"application/vnd.npm.install-v2+json; q=1.0\"\n verdaccio-staging:\n url: https://mycompany.com/npm\n headers:\n Accept: \"application/json\"\n authorization: \"Basic YourBase64EncodedCredentials==\"\n\n * @param {Object} headers\n * @private\n */\n private applyUplinkHeaders(headers: gotHeaders): gotHeaders {\n if (!this.config.headers) {\n return headers;\n }\n\n // add/override headers specified in the config\n /* eslint guard-for-in: 0 */\n for (const key in this.config.headers) {\n headers[key] = this.config.headers[key];\n }\n return headers;\n }\n\n public async getRemoteMetadata(\n name: string,\n options: Partial<ISyncUplinksOptions>\n ): Promise<[Manifest, string]> {\n if (this._ifRequestFailure()) {\n throw errorUtils.getInternalError(API_ERROR.UPLINK_OFFLINE);\n }\n\n // FUTURE: allow mix headers that comes from the client\n debug('getting metadata for package %s', name);\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = options.method || 'GET';\n const uri = this.config.url + `/${encode(name)}`;\n debug('set retry limit is %s', this.retry.limit);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry initial count %s', retry);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n timeout: this.timeout,\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('after response code is %s', code);\n if (code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES) {\n if (this.failed_requests >= this.max_fails) {\n this.failed_requests = 0;\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now online'\n );\n }\n }\n\n return afterResponse;\n },\n ],\n beforeRetry: [\n (error: RequestError, count: number) => {\n debug('retry %s count: %s', uri, count);\n this.failed_requests = count ?? 0;\n this.logger.info(\n {\n request: {\n method: method,\n url: uri,\n },\n error: error.message,\n retryCount: this.failed_requests,\n },\n \"retry @{retryCount} req: '@{request.method} @{request.url}'\"\n );\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is now offline'\n );\n }\n },\n ],\n },\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n })\n .on<any>('response', (eventResponse) => {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n this.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(eventResponse) === false ? eventResponse.statusCode : 'ERR',\n },\n message\n );\n })\n .on('downloadProgress', (progress) => {\n if (progress.total) {\n debug('responseLength %s', progress.total);\n responseLength = progress.total;\n }\n });\n const etag = response.headers.etag as string;\n const data = response.body;\n\n // not modified status (304) registry does not return any payload\n // it is handled as an error with the original 304 status preserved\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n const err = errorUtils.getNotFound(API_ERROR.NOT_MODIFIED_NO_DATA);\n err.code = HTTP_STATUS.NOT_MODIFIED;\n throw err;\n }\n\n debug('uri %s success', uri);\n const message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n this.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n request: { method: method, url: uri },\n status: response.statusCode,\n bytes: {\n in: options?.json ? JSON.stringify(options?.json).length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n return [data, etag];\n } catch (err: any) {\n debug('error %s on uri %s', err.code, uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n debug('error code %s', code);\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(`${API_ERROR.BAD_STATUS_CODE}: ${code}`);\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\n } else if (this._isRequestTimeout(err)) {\n debug('error code timeout');\n throw errorUtils.getServiceUnavailable(API_ERROR.SERVER_TIME_OUT);\n }\n throw err;\n }\n }\n\n // FIXME: handle stream and retry\n public fetchTarball(\n url: string,\n overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>\n ): any {\n debug('fetching url for %s', url);\n const options = { ...this.config, ...overrideOptions };\n let headers = this.getHeaders(options?.headers);\n headers = this.addProxyHeaders(headers, options.remoteAddress);\n headers = this.applyUplinkHeaders(headers);\n // the following headers cannot be overwritten\n if (_.isNil(options.etag) === false) {\n headers[HEADERS.NONE_MATCH] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n const method = 'GET';\n // const uri = this.config.url + `/${encode(name)}`;\n debug('request uri for %s', url);\n\n const readStream = got\n .stream(url, {\n headers,\n method,\n agent: this.agent,\n // FIXME: this should be taken from construtor as priority\n retry: this.retry ?? options?.retry,\n timeout: this.timeout,\n })\n .on('request', () => {\n this.last_request_time = Date.now();\n });\n\n return readStream;\n }\n\n /**\n * Perform a stream search.\n * @param {*} options request options\n * @return {Stream}\n */\n public async search({ url, abort, retry }: ProxySearchParams): Promise<Stream.Readable> {\n try {\n // Incoming URL is relative ie /-/v1/search...\n const uri = new URL(url, this.url).href;\n this.logger.http(\n { uri, uplink: this.uplinkName },\n 'search request to uplink @{uplink} - @{uri}'\n );\n debug('searching on %o', uri);\n const response = got(uri, {\n signal: abort ? abort.signal : {},\n agent: this.agent,\n timeout: this.timeout,\n retry: retry ?? this.retry,\n });\n\n const res = await response.text();\n const total = JSON.parse(res).total;\n debug('number of packages found: %o', total);\n const streamSearch = new PassThrough({ objectMode: true });\n const streamResponse = Readable.from(res);\n // objects is one of the properties on the body, it ignores date and total\n streamResponse.pipe(JSONStream.parse('objects')).pipe(streamSearch, { end: true });\n return streamSearch;\n } catch (err: any) {\n debug('search error %s', err);\n if (err.response.statusCode === 409) {\n throw errorUtils.getInternalError(`bad status code ${err.response.statusCode} from uplink`);\n }\n this.logger.error(\n { errorMessage: err?.message, name: this.uplinkName },\n 'proxy uplink @{name} search error: @{errorMessage}'\n );\n throw err;\n }\n }\n\n private addProxyHeaders(headers: gotHeaders, remoteAddress?: string): gotHeaders {\n // Only submit X-Forwarded-For field if we don't have a proxy selected\n // in the config file.\n //\n // Otherwise misconfigured proxy could return 407\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (headers['x-forwarded-for'] ? headers['x-forwarded-for'] + ', ' : '') + remoteAddress;\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['via'] = headers['via'] ? headers['via'] + ', ' : '';\n headers['via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n\n return headers;\n }\n\n /**\n * If the request failure.\n * @return {boolean}\n * @private\n */\n private _ifRequestFailure(): boolean {\n return (\n this.failed_requests >= this.max_fails &&\n Math.abs(Date.now() - (this.last_request_time as number)) < this.fail_timeout\n );\n }\n\n /**\n * Check if the request timed out (network or http errors).\n * @param {RequestError} err\n * @return {boolean}\n */\n private _isRequestTimeout(err: RequestError): boolean {\n const code = err?.response?.statusCode;\n return (\n err.code === 'ETIMEDOUT' ||\n err.code === 'ESOCKETTIMEDOUT' ||\n err.code === 'ECONNRESET' ||\n code === HTTP_STATUS.REQUEST_TIMEOUT ||\n code === HTTP_STATUS.BAD_GATEWAY ||\n code === HTTP_STATUS.SERVICE_UNAVAILABLE ||\n code === HTTP_STATUS.GATEWAY_TIMEOUT\n );\n }\n\n /**\n * Set up a proxy.\n * @param {*} hostname\n * @param {*} config\n * @param {*} mainconfig\n * @param {*} isHTTPS\n */\n private _setupProxy(\n hostname: string,\n config: UpLinkConfLocal,\n mainconfig: Config,\n isHTTPS: boolean\n ): void {\n let noProxyList;\n const proxy_key: string = isHTTPS ? 'https_proxy' : 'http_proxy';\n debug('looking for %o', proxy_key);\n\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n debug('found %o in uplink config', this.proxy);\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\n debug('found %o in main config', this.proxy);\n }\n if ('no_proxy' in config) {\n noProxyList = config.no_proxy;\n } else if ('no_proxy' in mainconfig) {\n noProxyList = mainconfig.no_proxy;\n }\n\n // use wget-like algorithm to determine if proxy shouldn't be used\n if (hostname[0] !== '.') {\n hostname = '.' + hostname;\n }\n\n if (_.isString(noProxyList) && noProxyList.length) {\n noProxyList = noProxyList.split(',');\n }\n\n if (_.isArray(noProxyList)) {\n for (let i = 0; i < noProxyList.length; i++) {\n let noProxyItem = noProxyList[i];\n if (noProxyItem[0] !== '.') {\n noProxyItem = '.' + noProxyItem;\n }\n if (hostname.endsWith(noProxyItem)) {\n if (this.proxy) {\n debug('not using proxy, excluded by @{rule}', noProxyItem);\n this.logger.debug(\n { url: this.url.href, rule: noProxyItem },\n 'not using proxy for @{url}, excluded by @{rule} rule'\n );\n this.proxy = undefined;\n }\n break;\n }\n }\n }\n\n if (typeof this.proxy === 'string') {\n debug('using proxy @{proxy} for @{url}', this.proxy, this.url.href);\n this.logger.debug(\n { url: this.url.href, proxy: this.proxy },\n 'using proxy @{proxy} for @{url}'\n );\n }\n }\n}\n\nexport { ProxyStorage };\n"],"mappings":";;;;;;;;;;AAyBA,IAAM,QAAQ,WAAW,kBAAkB;AAE3C,IAAM,SAAS,SAAU,OAAe;AACtC,QAAO,mBAAmB,MAAM,CAAC,QAAQ,QAAQ,IAAI;;AAIvD,IAAM,oBAAoB,GADF,QAAQ,KACa;;;;AAK7C,IAAM,aAAa,QAAyB,KAAa,QAAgB;AACvE,QAAO,EAAE,MAAM,OAAO,KAAK,KAAK,QAAQ,OAAO,OAAO;;;;;;AAuDxD,I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Verdaccio Proxy Fetcher",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"node": ">=24"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@verdaccio/config": "9.0.0-next-9.
|
|
37
|
-
"@verdaccio/core": "9.0.0-next-9.
|
|
36
|
+
"@verdaccio/config": "9.0.0-next-9.7",
|
|
37
|
+
"@verdaccio/core": "9.0.0-next-9.7",
|
|
38
38
|
"JSONStream": "1.3.5",
|
|
39
39
|
"debug": "4.4.3",
|
|
40
|
-
"got
|
|
40
|
+
"got": "14.6.6",
|
|
41
41
|
"hpagent": "1.2.0",
|
|
42
42
|
"lodash": "4.17.23"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@verdaccio/logger": "9.0.0-next-9.
|
|
46
|
-
"@verdaccio/types": "14.0.0-next-9.
|
|
45
|
+
"@verdaccio/logger": "9.0.0-next-9.7",
|
|
46
|
+
"@verdaccio/types": "14.0.0-next-9.4",
|
|
47
47
|
"get-stream": "6.0.1",
|
|
48
48
|
"nock": "13.5.6",
|
|
49
49
|
"vitest": "4.1.0"
|