@verdaccio/proxy 6.0.0-6-next.36 → 6.0.0-6-next.38
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/CHANGELOG.md +26 -0
- package/build/proxy.d.ts +4 -4
- package/build/proxy.js +3 -3
- package/build/proxy.js.map +1 -1
- package/package.json +7 -7
- package/src/proxy.ts +5 -5
- package/test/proxy.metadata.spec.ts +17 -17
- package/test/proxy.tarball.spec.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @verdaccio/proxy
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.38
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 45c03819: refactor: render html middleware
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [45c03819]
|
|
12
|
+
- @verdaccio/config@6.0.0-6-next.60
|
|
13
|
+
- @verdaccio/local-storage@11.0.0-6-next.30
|
|
14
|
+
- @verdaccio/core@6.0.0-6-next.60
|
|
15
|
+
- @verdaccio/logger@6.0.0-6-next.28
|
|
16
|
+
- @verdaccio/utils@6.0.0-6-next.28
|
|
17
|
+
|
|
18
|
+
## 6.0.0-6-next.37
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [65f88b82]
|
|
23
|
+
- @verdaccio/logger@6.0.0-6-next.27
|
|
24
|
+
- @verdaccio/local-storage@11.0.0-6-next.29
|
|
25
|
+
- @verdaccio/core@6.0.0-6-next.59
|
|
26
|
+
- @verdaccio/config@6.0.0-6-next.59
|
|
27
|
+
- @verdaccio/utils@6.0.0-6-next.27
|
|
28
|
+
|
|
3
29
|
## 6.0.0-6-next.36
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/build/proxy.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface IProxy {
|
|
|
35
35
|
fail_timeout: number;
|
|
36
36
|
upname: string;
|
|
37
37
|
search(options: ProxySearchParams): Promise<Stream.Readable>;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
getRemoteMetadata(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;
|
|
39
|
+
fetchTarball(url: string, options: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>): PassThrough;
|
|
40
40
|
}
|
|
41
41
|
export { Options as FetchOptions };
|
|
42
42
|
export interface ISyncUplinksOptions extends Options {
|
|
@@ -113,8 +113,8 @@ declare class ProxyStorage implements IProxy {
|
|
|
113
113
|
*/
|
|
114
114
|
private _overrideWithUpLinkConfLocaligHeaders;
|
|
115
115
|
private applyUplinkHeaders;
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
getRemoteMetadata(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;
|
|
117
|
+
fetchTarball(url: string, overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>): any;
|
|
118
118
|
/**
|
|
119
119
|
* Perform a stream search.
|
|
120
120
|
* @param {*} options request options
|
package/build/proxy.js
CHANGED
|
@@ -43,7 +43,7 @@ class ProxyStorage {
|
|
|
43
43
|
constructor(config, mainConfig, agent) {
|
|
44
44
|
this.config = config;
|
|
45
45
|
this.failed_requests = 0;
|
|
46
|
-
this.userAgent = mainConfig.user_agent;
|
|
46
|
+
this.userAgent = mainConfig.user_agent ?? 'hidden';
|
|
47
47
|
this.ca = config.ca;
|
|
48
48
|
this.logger = LoggerApi.logger.child({
|
|
49
49
|
sub: 'out'
|
|
@@ -208,7 +208,7 @@ class ProxyStorage {
|
|
|
208
208
|
}
|
|
209
209
|
return headers;
|
|
210
210
|
}
|
|
211
|
-
async
|
|
211
|
+
async getRemoteMetadata(name, options) {
|
|
212
212
|
if (this._ifRequestFailure()) {
|
|
213
213
|
throw _core.errorUtils.getInternalError(_core.API_ERROR.UPLINK_OFFLINE);
|
|
214
214
|
}
|
|
@@ -334,7 +334,7 @@ class ProxyStorage {
|
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
// FIXME: handle stream and retry
|
|
337
|
-
|
|
337
|
+
fetchTarball(url, overrideOptions) {
|
|
338
338
|
debug('fetching url for %s', url);
|
|
339
339
|
const options = {
|
|
340
340
|
...this.config,
|
package/build/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","names":["LoggerApi","require","debug","buildDebug","encode","thing","encodeURIComponent","replace","jsonContentType","HEADERS","JSON","contentTypeAccept","setConfig","config","key","def","_","isNil","ProxyStorage","constructor","mainConfig","agent","failed_requests","userAgent","user_agent","ca","logger","child","sub","server_id","agent_options","keepAlive","maxSockets","maxFreeSockets","url","URL","isHTTPS","protocol","_setupProxy","hostname","getAgent","timeout","Number","warn","join","maxage","parseInterval","max_fails","fail_timeout","strict_ssl","Boolean","retry","limit","agentInstance","CustomAgents","proxy","get","getHeadersNext","headers","accept","ACCEPT","acceptEncoding","ACCEPT_ENCODING","USER_AGENT","setAuthNext","auth","AUTHORIZATION","isObject","token","_throwErrorAuth","tokenConf","isString","token_env","process","env","NPM_TOKEN","error","constants","ERROR_CODE","token_required","type","TOKEN_BASIC","_setHeaderAuthorization","message","Error","_type","toLowerCase","TOKEN_BEARER","upperFirst","buildToken","_overrideWithUpLinkConfLocaligHeaders","applyUplinkHeaders","getRemoteMetadataNext","name","options","_ifRequestFailure","errorUtils","getInternalError","API_ERROR","UPLINK_OFFLINE","addProxyHeaders","remoteAddress","etag","NONE_MATCH","method","uri","response","responseLength","got","responseType","request","hooks","afterResponse","code","statusCode","HTTP_STATUS","OK","MULTIPLE_CHOICES","host","beforeRetry","_options","count","info","retryCount","on","last_request_time","Date","now","eventResponse","http","status","isNull","progress","total","data","body","NOT_MODIFIED","getCode","NOT_MODIFIED_NO_DATA","bytes","in","json","stringify","length","out","err","NOT_FOUND","getNotFound","NOT_PACKAGE_UPLINK","BAD_STATUS_CODE","remoteStatus","fetchTarballNext","overrideOptions","readStream","stream","search","abort","fullURL","href","uplink","upname","undiciFetch","signal","BAD_REQUEST","streamSearch","PassThrough","objectMode","res","text","streamResponse","Readable","from","pipe","JSONStream","parse","end","errorMessage","FORWARDED_FOR","Math","abs","mainconfig","noProxyList","proxy_key","no_proxy","split","isArray","i","noProxyItem","endsWith","rule","undefined"],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport got, { RequiredRetryOptions, Headers as gotHeaders } from 'got';\nimport type { Agents, Options } from 'got';\nimport _ from 'lodash';\nimport Stream, { PassThrough, Readable } from 'stream';\nimport { Headers, fetch as undiciFetch } from 'undici';\nimport { URL } from 'url';\n\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n constants,\n errorUtils,\n searchUtils,\n} from '@verdaccio/core';\nimport { Manifest } from '@verdaccio/types';\nimport { Config, Logger, UpLinkConf } from '@verdaccio/types';\nimport { buildToken } from '@verdaccio/utils';\n\nimport CustomAgents, { AgentOptionsConf } from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst LoggerApi = require('@verdaccio/logger');\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 headers?: Headers;\n url: string;\n query?: searchUtils.SearchQuery;\n abort: AbortController;\n};\nexport interface IProxy {\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: number;\n max_fails: number;\n fail_timeout: number;\n upname: string;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadataNext(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;\n fetchTarballNext(\n url: string,\n options: 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 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: number;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n // FIXME: upname is assigned to each instance\n // @ts-ignore\n public upname: string;\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<RequiredRetryOptions> | number;\n\n public constructor(config: UpLinkConfLocal, mainConfig: Config, agent?: Agents) {\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent;\n this.ca = config.ca;\n this.logger = LoggerApi.logger.child({ sub: 'out' });\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 = parseInterval(setConfig(this.config, 'timeout', '30s'));\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 getHeadersNext(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.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 token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\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 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 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 type = _.upperFirst(type);\n headers[HEADERS.AUTHORIZATION] = 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 * @deprecated use applyUplinkHeaders\n */\n private _overrideWithUpLinkConfLocaligHeaders(headers: Headers): any {\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 }\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 getRemoteMetadataNext(\n name: string,\n options: 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('get metadata for %s', name);\n let headers = this.getHeadersNext(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('request uri for %s retry %s', uri);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry times %s for %s', retry, uri);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n // @ts-ignore\n timeout: { request: options?.timeout ?? this.timeout },\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('code response %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 // FUTURE: got 12.0.0, the option arg should be removed\n (_options, error: any, 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('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\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n throw errorUtils.getCode(HTTP_STATUS.NOT_MODIFIED, API_ERROR.NOT_MODIFIED_NO_DATA);\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('uri %s fail', uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(errorUtils.API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(\n `${errorUtils.API_ERROR.BAD_STATUS_CODE}: ${code}`\n );\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\n }\n throw err;\n }\n }\n\n // FIXME: handle stream and retry\n public fetchTarballNext(\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.getHeadersNext(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 }: ProxySearchParams): Promise<Stream.Readable> {\n debug('search url %o', url);\n\n let response;\n try {\n const fullURL = new URL(`${this.url}${url}`);\n // FIXME: a better way to remove duplicate slashes?\n const uri = fullURL.href.replace(/([^:]\\/)\\/+/g, '$1');\n this.logger.http({ uri, uplink: this.upname }, 'search request to uplink @{uplink} - @{uri}');\n response = await undiciFetch(uri, {\n method: 'GET',\n // FUTURE: whitelist domains what we are sending not need it headers, security check\n // headers: new Headers({\n // ...headers,\n // connection: 'keep-alive',\n // }),\n signal: abort?.signal,\n });\n debug('response.status %o', response.status);\n\n if (response.status >= HTTP_STATUS.BAD_REQUEST) {\n throw errorUtils.getInternalError(`bad status code ${response.status} from uplink`);\n }\n\n const streamSearch = new PassThrough({ objectMode: true });\n const res = await response.text();\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 this.logger.error(\n { errorMessage: err?.message, name: this.upname },\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 * 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\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\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 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 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":";;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAYA;AAEA;AACA;AAA8C;AAE9C,MAAMA,SAAS,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAE9C,MAAMC,KAAK,GAAG,IAAAC,cAAU,EAAC,iBAAiB,CAAC;AAE3C,MAAMC,MAAM,GAAG,UAAUC,KAAK,EAAU;EACtC,OAAOC,kBAAkB,CAACD,KAAK,CAAC,CAACE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;AACvD,CAAC;AAED,MAAMC,eAAe,GAAGC,aAAO,CAACC,IAAI;AACpC,MAAMC,iBAAiB,GAAI,GAAEH,eAAgB,GAAE;;AAE/C;AACA;AACA;AACA,MAAMI,SAAS,GAAG,CAACC,MAAuB,EAAEC,GAAW,EAAEC,GAAG,KAAa;EACvE,OAAOC,eAAC,CAACC,KAAK,CAACJ,MAAM,CAACC,GAAG,CAAC,CAAC,KAAK,KAAK,GAAGD,MAAM,CAACC,GAAG,CAAC,GAAGC,GAAG;AAC3D,CAAC;AA8CD;AACA;AACA;AACA;AACA,MAAMG,YAAY,CAAmB;EAanC;EACA;;EAIA;;EAKOC,WAAW,CAACN,MAAuB,EAAEO,UAAkB,EAAEC,KAAc,EAAE;IAC9E,IAAI,CAACR,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACS,eAAe,GAAG,CAAC;IACxB,IAAI,CAACC,SAAS,GAAGH,UAAU,CAACI,UAAU;IACtC,IAAI,CAACC,EAAE,GAAGZ,MAAM,CAACY,EAAE;IACnB,IAAI,CAACC,MAAM,GAAG1B,SAAS,CAAC0B,MAAM,CAACC,KAAK,CAAC;MAAEC,GAAG,EAAE;IAAM,CAAC,CAAC;IACpD,IAAI,CAACC,SAAS,GAAGT,UAAU,CAACS,SAAS;IACrC,I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,CAAC,CAAC;QAChC,IAAIC,WAAW,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;UAC1BA,WAAW,GAAG,GAAG,GAAGA,WAAW;QACjC;QACA,IAAIpJ,QAAQ,CAACqJ,QAAQ,CAACD,WAAW,CAAC,EAAE;UAClC,IAAI,IAAI,CAACpI,KAAK,EAAE;YACd,IAAI,CAAC7B,MAAM,CAACxB,KAAK,CACf;cAAEgC,GAAG,EAAE,IAAI,CAACA,GAAG,CAAC4H,IAAI;cAAE+B,IAAI,EAAEF;YAAY,CAAC,EACzC,sDAAsD,CACvD;YACD,IAAI,CAACpI,KAAK,GAAGuI,SAAS;UACxB;UACA;QACF;MACF;IACF;IAEA,IAAI,OAAO,IAAI,CAACvI,KAAK,KAAK,QAAQ,EAAE;MAClC,IAAI,CAAC7B,MAAM,CAACxB,KAAK,CACf;QAAEgC,GAAG,EAAE,IAAI,CAACA,GAAG,CAAC4H,IAAI;QAAEvG,KAAK,EAAE,IAAI,CAACA;MAAM,CAAC,EACzC,iCAAiC,CAClC;IACH;EACF;AACF;AAAC"}
|
|
1
|
+
{"version":3,"file":"proxy.js","names":["LoggerApi","require","debug","buildDebug","encode","thing","encodeURIComponent","replace","jsonContentType","HEADERS","JSON","contentTypeAccept","setConfig","config","key","def","_","isNil","ProxyStorage","constructor","mainConfig","agent","failed_requests","userAgent","user_agent","ca","logger","child","sub","server_id","agent_options","keepAlive","maxSockets","maxFreeSockets","url","URL","isHTTPS","protocol","_setupProxy","hostname","getAgent","timeout","Number","warn","join","maxage","parseInterval","max_fails","fail_timeout","strict_ssl","Boolean","retry","limit","agentInstance","CustomAgents","proxy","get","getHeadersNext","headers","accept","ACCEPT","acceptEncoding","ACCEPT_ENCODING","USER_AGENT","setAuthNext","auth","AUTHORIZATION","isObject","token","_throwErrorAuth","tokenConf","isString","token_env","process","env","NPM_TOKEN","error","constants","ERROR_CODE","token_required","type","TOKEN_BASIC","_setHeaderAuthorization","message","Error","_type","toLowerCase","TOKEN_BEARER","upperFirst","buildToken","_overrideWithUpLinkConfLocaligHeaders","applyUplinkHeaders","getRemoteMetadata","name","options","_ifRequestFailure","errorUtils","getInternalError","API_ERROR","UPLINK_OFFLINE","addProxyHeaders","remoteAddress","etag","NONE_MATCH","method","uri","response","responseLength","got","responseType","request","hooks","afterResponse","code","statusCode","HTTP_STATUS","OK","MULTIPLE_CHOICES","host","beforeRetry","_options","count","info","retryCount","on","last_request_time","Date","now","eventResponse","http","status","isNull","progress","total","data","body","NOT_MODIFIED","getCode","NOT_MODIFIED_NO_DATA","bytes","in","json","stringify","length","out","err","NOT_FOUND","getNotFound","NOT_PACKAGE_UPLINK","BAD_STATUS_CODE","remoteStatus","fetchTarball","overrideOptions","readStream","stream","search","abort","fullURL","href","uplink","upname","undiciFetch","signal","BAD_REQUEST","streamSearch","PassThrough","objectMode","res","text","streamResponse","Readable","from","pipe","JSONStream","parse","end","errorMessage","FORWARDED_FOR","Math","abs","mainconfig","noProxyList","proxy_key","no_proxy","split","isArray","i","noProxyItem","endsWith","rule","undefined"],"sources":["../src/proxy.ts"],"sourcesContent":["import JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport got, { RequiredRetryOptions, Headers as gotHeaders } from 'got';\nimport type { Agents, Options } from 'got';\nimport _ from 'lodash';\nimport Stream, { PassThrough, Readable } from 'stream';\nimport { Headers, fetch as undiciFetch } from 'undici';\nimport { URL } from 'url';\n\nimport {\n API_ERROR,\n HEADERS,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n constants,\n errorUtils,\n searchUtils,\n} from '@verdaccio/core';\nimport { Manifest } from '@verdaccio/types';\nimport { Config, Logger, UpLinkConf } from '@verdaccio/types';\nimport { buildToken } from '@verdaccio/utils';\n\nimport CustomAgents, { AgentOptionsConf } from './agent';\nimport { parseInterval } from './proxy-utils';\n\nconst LoggerApi = require('@verdaccio/logger');\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 headers?: Headers;\n url: string;\n query?: searchUtils.SearchQuery;\n abort: AbortController;\n};\nexport interface IProxy {\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: number;\n max_fails: number;\n fail_timeout: number;\n upname: string;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;\n fetchTarball(\n url: string,\n options: 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 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: number;\n public max_fails: number;\n public fail_timeout: number;\n public agent_options: AgentOptionsConf;\n // FIXME: upname is assigned to each instance\n // @ts-ignore\n public upname: string;\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<RequiredRetryOptions> | number;\n\n public constructor(config: UpLinkConfLocal, mainConfig: Config, agent?: Agents) {\n this.config = config;\n this.failed_requests = 0;\n this.userAgent = mainConfig.user_agent ?? 'hidden';\n this.ca = config.ca;\n this.logger = LoggerApi.logger.child({ sub: 'out' });\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 = parseInterval(setConfig(this.config, 'timeout', '30s'));\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 getHeadersNext(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.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 token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (typeof tokenConf.token_env === 'string') {\n token = process.env[tokenConf.token_env];\n } else if (typeof tokenConf.token_env === 'boolean' && tokenConf.token_env) {\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 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 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 type = _.upperFirst(type);\n headers[HEADERS.AUTHORIZATION] = 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 * @deprecated use applyUplinkHeaders\n */\n private _overrideWithUpLinkConfLocaligHeaders(headers: Headers): any {\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 }\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: 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('get metadata for %s', name);\n let headers = this.getHeadersNext(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('request uri for %s retry %s', uri);\n let response;\n let responseLength = 0;\n try {\n const retry = options?.retry ?? this.retry;\n debug('retry times %s for %s', retry, uri);\n response = await got(uri, {\n headers,\n responseType: 'json',\n method,\n agent: this.agent,\n retry,\n // @ts-ignore\n timeout: { request: options?.timeout ?? this.timeout },\n hooks: {\n afterResponse: [\n (afterResponse) => {\n const code = afterResponse.statusCode;\n debug('code response %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 // FUTURE: got 12.0.0, the option arg should be removed\n (_options, error: any, 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('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\n if (response?.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n throw errorUtils.getCode(HTTP_STATUS.NOT_MODIFIED, API_ERROR.NOT_MODIFIED_NO_DATA);\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('uri %s fail', uri);\n if (err.code === 'ERR_NON_2XX_3XX_RESPONSE') {\n const code = err.response.statusCode;\n if (code === HTTP_STATUS.NOT_FOUND) {\n throw errorUtils.getNotFound(errorUtils.API_ERROR.NOT_PACKAGE_UPLINK);\n }\n\n if (!(code >= HTTP_STATUS.OK && code < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(\n `${errorUtils.API_ERROR.BAD_STATUS_CODE}: ${code}`\n );\n // we need this code to identify outside which status code triggered the error\n error.remoteStatus = code;\n throw error;\n }\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.getHeadersNext(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 }: ProxySearchParams): Promise<Stream.Readable> {\n debug('search url %o', url);\n\n let response;\n try {\n const fullURL = new URL(`${this.url}${url}`);\n // FIXME: a better way to remove duplicate slashes?\n const uri = fullURL.href.replace(/([^:]\\/)\\/+/g, '$1');\n this.logger.http({ uri, uplink: this.upname }, 'search request to uplink @{uplink} - @{uri}');\n response = await undiciFetch(uri, {\n method: 'GET',\n // FUTURE: whitelist domains what we are sending not need it headers, security check\n // headers: new Headers({\n // ...headers,\n // connection: 'keep-alive',\n // }),\n signal: abort?.signal,\n });\n debug('response.status %o', response.status);\n\n if (response.status >= HTTP_STATUS.BAD_REQUEST) {\n throw errorUtils.getInternalError(`bad status code ${response.status} from uplink`);\n }\n\n const streamSearch = new PassThrough({ objectMode: true });\n const res = await response.text();\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 this.logger.error(\n { errorMessage: err?.message, name: this.upname },\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 * 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\n // get http_proxy and no_proxy configs\n if (proxy_key in config) {\n this.proxy = config[proxy_key];\n } else if (proxy_key in mainconfig) {\n this.proxy = mainconfig[proxy_key];\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 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 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":";;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAYA;AAEA;AACA;AAA8C;AAE9C,MAAMA,SAAS,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAE9C,MAAMC,KAAK,GAAG,IAAAC,cAAU,EAAC,iBAAiB,CAAC;AAE3C,MAAMC,MAAM,GAAG,UAAUC,KAAK,EAAU;EACtC,OAAOC,kBAAkB,CAACD,KAAK,CAAC,CAACE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;AACvD,CAAC;AAED,MAAMC,eAAe,GAAGC,aAAO,CAACC,IAAI;AACpC,MAAMC,iBAAiB,GAAI,GAAEH,eAAgB,GAAE;;AAE/C;AACA;AACA;AACA,MAAMI,SAAS,GAAG,CAACC,MAAuB,EAAEC,GAAW,EAAEC,GAAG,KAAa;EACvE,OAAOC,eAAC,CAACC,KAAK,CAACJ,MAAM,CAACC,GAAG,CAAC,CAAC,KAAK,KAAK,GAAGD,MAAM,CAACC,GAAG,CAAC,GAAGC,GAAG;AAC3D,CAAC;AA8CD;AACA;AACA;AACA;AACA,MAAMG,YAAY,CAAmB;EAan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0.0-6-next.38",
|
|
4
4
|
"description": "verdaccio proxy fetcher",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"npm": ">=6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/config": "6.0.0-6-next.
|
|
34
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
35
|
-
"@verdaccio/local-storage": "11.0.0-6-next.
|
|
36
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
37
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
33
|
+
"@verdaccio/config": "6.0.0-6-next.60",
|
|
34
|
+
"@verdaccio/core": "6.0.0-6-next.60",
|
|
35
|
+
"@verdaccio/local-storage": "11.0.0-6-next.30",
|
|
36
|
+
"@verdaccio/logger": "6.0.0-6-next.28",
|
|
37
|
+
"@verdaccio/utils": "6.0.0-6-next.28",
|
|
38
38
|
"JSONStream": "1.3.5",
|
|
39
39
|
"debug": "4.3.4",
|
|
40
40
|
"lodash": "4.17.21",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "16.18.10",
|
|
47
47
|
"p-cancelable": "2.1.1",
|
|
48
|
-
"@verdaccio/types": "11.0.0-6-next.
|
|
48
|
+
"@verdaccio/types": "11.0.0-6-next.20",
|
|
49
49
|
"get-stream": "^6.0.1",
|
|
50
50
|
"nock": "13.2.9",
|
|
51
51
|
"node-mocks-http": "1.12.1",
|
package/src/proxy.ts
CHANGED
|
@@ -70,8 +70,8 @@ export interface IProxy {
|
|
|
70
70
|
fail_timeout: number;
|
|
71
71
|
upname: string;
|
|
72
72
|
search(options: ProxySearchParams): Promise<Stream.Readable>;
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
getRemoteMetadata(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;
|
|
74
|
+
fetchTarball(
|
|
75
75
|
url: string,
|
|
76
76
|
options: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>
|
|
77
77
|
): PassThrough;
|
|
@@ -116,7 +116,7 @@ class ProxyStorage implements IProxy {
|
|
|
116
116
|
public constructor(config: UpLinkConfLocal, mainConfig: Config, agent?: Agents) {
|
|
117
117
|
this.config = config;
|
|
118
118
|
this.failed_requests = 0;
|
|
119
|
-
this.userAgent = mainConfig.user_agent;
|
|
119
|
+
this.userAgent = mainConfig.user_agent ?? 'hidden';
|
|
120
120
|
this.ca = config.ca;
|
|
121
121
|
this.logger = LoggerApi.logger.child({ sub: 'out' });
|
|
122
122
|
this.server_id = mainConfig.server_id;
|
|
@@ -294,7 +294,7 @@ class ProxyStorage implements IProxy {
|
|
|
294
294
|
return headers;
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
public async
|
|
297
|
+
public async getRemoteMetadata(
|
|
298
298
|
name: string,
|
|
299
299
|
options: ISyncUplinksOptions
|
|
300
300
|
): Promise<[Manifest, string]> {
|
|
@@ -443,7 +443,7 @@ class ProxyStorage implements IProxy {
|
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
// FIXME: handle stream and retry
|
|
446
|
-
public
|
|
446
|
+
public fetchTarball(
|
|
447
447
|
url: string,
|
|
448
448
|
overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>
|
|
449
449
|
): any {
|
|
@@ -59,7 +59,7 @@ describe('proxy', () => {
|
|
|
59
59
|
const proxyPath = getConf('proxy1.yaml');
|
|
60
60
|
const conf = new Config(parseConfigFile(proxyPath));
|
|
61
61
|
|
|
62
|
-
describe('
|
|
62
|
+
describe('getRemoteMetadata', () => {
|
|
63
63
|
beforeEach(() => {
|
|
64
64
|
nock.cleanAll();
|
|
65
65
|
nock.abortPendingRequests();
|
|
@@ -78,7 +78,7 @@ describe('proxy', () => {
|
|
|
78
78
|
.get('/jquery')
|
|
79
79
|
.reply(200, { body: 'test' });
|
|
80
80
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
81
|
-
const [manifest] = await prox1.
|
|
81
|
+
const [manifest] = await prox1.getRemoteMetadata('jquery', {
|
|
82
82
|
remoteAddress: '127.0.0.1',
|
|
83
83
|
});
|
|
84
84
|
expect(manifest).toEqual({ body: 'test' });
|
|
@@ -104,7 +104,7 @@ describe('proxy', () => {
|
|
|
104
104
|
}
|
|
105
105
|
);
|
|
106
106
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
107
|
-
const [manifest, etag] = await prox1.
|
|
107
|
+
const [manifest, etag] = await prox1.getRemoteMetadata('jquery', {
|
|
108
108
|
remoteAddress: '127.0.0.1',
|
|
109
109
|
});
|
|
110
110
|
expect(etag).toEqual('_ref_4444');
|
|
@@ -131,7 +131,7 @@ describe('proxy', () => {
|
|
|
131
131
|
}
|
|
132
132
|
);
|
|
133
133
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
134
|
-
const [manifest, etag] = await prox1.
|
|
134
|
+
const [manifest, etag] = await prox1.getRemoteMetadata('jquery', {
|
|
135
135
|
etag: 'foo',
|
|
136
136
|
remoteAddress: '127.0.0.1',
|
|
137
137
|
});
|
|
@@ -146,7 +146,7 @@ describe('proxy', () => {
|
|
|
146
146
|
.get('/jquery')
|
|
147
147
|
.reply(200, { body: { name: 'foo', version: '1.0.0' } }, {});
|
|
148
148
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
149
|
-
await prox1.
|
|
149
|
+
await prox1.getRemoteMetadata('jquery', {
|
|
150
150
|
remoteAddress: '127.0.0.1',
|
|
151
151
|
});
|
|
152
152
|
expect(mockHttp).toHaveBeenCalledTimes(2);
|
|
@@ -175,7 +175,7 @@ describe('proxy', () => {
|
|
|
175
175
|
test('proxy call with 304', async () => {
|
|
176
176
|
nock(domain).get('/jquery').reply(304);
|
|
177
177
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
178
|
-
await expect(prox1.
|
|
178
|
+
await expect(prox1.getRemoteMetadata('jquery', { etag: 'rev_3333' })).rejects.toThrow(
|
|
179
179
|
'no data'
|
|
180
180
|
);
|
|
181
181
|
});
|
|
@@ -184,7 +184,7 @@ describe('proxy', () => {
|
|
|
184
184
|
nock(domain).get('/jquery').replyWithError('something awful happened');
|
|
185
185
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
186
186
|
await expect(
|
|
187
|
-
prox1.
|
|
187
|
+
prox1.getRemoteMetadata('jquery', {
|
|
188
188
|
remoteAddress: '127.0.0.1',
|
|
189
189
|
})
|
|
190
190
|
).rejects.toThrowError(new Error('something awful happened'));
|
|
@@ -193,7 +193,7 @@ describe('proxy', () => {
|
|
|
193
193
|
test('reply with 409 error', async () => {
|
|
194
194
|
nock(domain).get('/jquery').reply(409);
|
|
195
195
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
196
|
-
await expect(prox1.
|
|
196
|
+
await expect(prox1.getRemoteMetadata('jquery', { retry: 0 })).rejects.toThrow(
|
|
197
197
|
new Error('bad status code: 409')
|
|
198
198
|
);
|
|
199
199
|
});
|
|
@@ -202,7 +202,7 @@ describe('proxy', () => {
|
|
|
202
202
|
nock(domain).get('/jquery').reply(200, 'some-text');
|
|
203
203
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
204
204
|
await expect(
|
|
205
|
-
prox1.
|
|
205
|
+
prox1.getRemoteMetadata('jquery', {
|
|
206
206
|
remoteAddress: '127.0.0.1',
|
|
207
207
|
})
|
|
208
208
|
).rejects.toThrowError(
|
|
@@ -216,7 +216,7 @@ describe('proxy', () => {
|
|
|
216
216
|
nock(domain).get('/jquery').reply(409);
|
|
217
217
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
218
218
|
await expect(
|
|
219
|
-
prox1.
|
|
219
|
+
prox1.getRemoteMetadata('jquery', {
|
|
220
220
|
remoteAddress: '127.0.0.1',
|
|
221
221
|
})
|
|
222
222
|
).rejects.toThrowError(
|
|
@@ -228,7 +228,7 @@ describe('proxy', () => {
|
|
|
228
228
|
nock(domain).get('/jquery').reply(404);
|
|
229
229
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
230
230
|
await expect(
|
|
231
|
-
prox1.
|
|
231
|
+
prox1.getRemoteMetadata('jquery', {
|
|
232
232
|
remoteAddress: '127.0.0.1',
|
|
233
233
|
})
|
|
234
234
|
).rejects.toThrowError(errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK));
|
|
@@ -254,7 +254,7 @@ describe('proxy', () => {
|
|
|
254
254
|
.reply(200, { body: { name: 'foo', version: '1.0.0' } });
|
|
255
255
|
|
|
256
256
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
257
|
-
const [manifest] = await prox1.
|
|
257
|
+
const [manifest] = await prox1.getRemoteMetadata('jquery', {
|
|
258
258
|
retry: { limit: 2 },
|
|
259
259
|
});
|
|
260
260
|
expect(manifest).toEqual({ body: { name: 'foo', version: '1.0.0' } });
|
|
@@ -274,13 +274,13 @@ describe('proxy', () => {
|
|
|
274
274
|
|
|
275
275
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
276
276
|
await expect(
|
|
277
|
-
prox1.
|
|
277
|
+
prox1.getRemoteMetadata('jquery', {
|
|
278
278
|
remoteAddress: '127.0.0.1',
|
|
279
279
|
retry: { limit: 2 },
|
|
280
280
|
})
|
|
281
281
|
).rejects.toThrowError();
|
|
282
282
|
await expect(
|
|
283
|
-
prox1.
|
|
283
|
+
prox1.getRemoteMetadata('jquery', {
|
|
284
284
|
remoteAddress: '127.0.0.1',
|
|
285
285
|
retry: { limit: 2 },
|
|
286
286
|
})
|
|
@@ -311,14 +311,14 @@ describe('proxy', () => {
|
|
|
311
311
|
);
|
|
312
312
|
// force retry
|
|
313
313
|
await expect(
|
|
314
|
-
prox1.
|
|
314
|
+
prox1.getRemoteMetadata('jquery', {
|
|
315
315
|
remoteAddress: '127.0.0.1',
|
|
316
316
|
retry: { limit: 2 },
|
|
317
317
|
})
|
|
318
318
|
).rejects.toThrowError();
|
|
319
319
|
// display offline error on exausted retry
|
|
320
320
|
await expect(
|
|
321
|
-
prox1.
|
|
321
|
+
prox1.getRemoteMetadata('jquery', {
|
|
322
322
|
remoteAddress: '127.0.0.1',
|
|
323
323
|
retry: { limit: 2 },
|
|
324
324
|
})
|
|
@@ -338,7 +338,7 @@ describe('proxy', () => {
|
|
|
338
338
|
);
|
|
339
339
|
// this is based on max_fails, if change that also change here acordingly
|
|
340
340
|
await setTimeout(3000);
|
|
341
|
-
const [manifest] = await prox1.
|
|
341
|
+
const [manifest] = await prox1.getRemoteMetadata('jquery', {
|
|
342
342
|
retry: { limit: 2 },
|
|
343
343
|
});
|
|
344
344
|
expect(manifest).toEqual({ body: { name: 'foo', version: '1.0.0' } });
|
|
@@ -39,13 +39,13 @@ describe('tarball proxy', () => {
|
|
|
39
39
|
const proxyPath = getConf('proxy1.yaml');
|
|
40
40
|
const conf = new Config(parseConfigFile(proxyPath));
|
|
41
41
|
|
|
42
|
-
describe('
|
|
42
|
+
describe('fetchTarball', () => {
|
|
43
43
|
test('get file tarball fetch', (done) => {
|
|
44
44
|
nock('https://registry.verdaccio.org')
|
|
45
45
|
.get('/jquery/-/jquery-0.0.1.tgz')
|
|
46
46
|
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
|
47
47
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
48
|
-
const stream = prox1.
|
|
48
|
+
const stream = prox1.fetchTarball(
|
|
49
49
|
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
|
50
50
|
{}
|
|
51
51
|
);
|
|
@@ -66,7 +66,7 @@ describe('tarball proxy', () => {
|
|
|
66
66
|
.once()
|
|
67
67
|
.replyWithFile(201, path.join(__dirname, 'partials/jquery-0.0.1.tgz'));
|
|
68
68
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
69
|
-
const stream = prox1.
|
|
69
|
+
const stream = prox1.fetchTarball(
|
|
70
70
|
'https://registry.verdaccio.org/jquery/-/jquery-0.0.1.tgz',
|
|
71
71
|
{ retry: { limit: 2 } }
|
|
72
72
|
);
|