@verdaccio/url 14.0.0-next-9.20 → 14.0.0-next-9.21

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/index.d.ts CHANGED
@@ -37,6 +37,10 @@ export type RequestOptions = {
37
37
  * Logged username the request, usually after token verification.
38
38
  */
39
39
  username?: string;
40
+ /**
41
+ * Request bypass cache.
42
+ */
43
+ byPassCache?: boolean;
40
44
  };
41
45
  export declare function getPublicUrl(url_prefix: string | undefined, requestOptions: RequestOptions): string;
42
46
  export declare const isURL: typeof import('validator/lib/isURL').default;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\nimport { URL } from 'node:url';\nimport validator from 'validator';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:core:url');\n\nconst validProtocols = ['https', 'http'];\n\n/**\n * Check if URI is starting with \"http://\", \"https://\" or \"//\"\n * @param {string} uri\n */\nexport function isURLhasValidProtocol(uri: string): boolean {\n return /^(https?:)?\\/\\//.test(uri);\n}\n\nexport function isHost(url: string = '', options = {}): boolean {\n return validator.isURL(url, {\n require_host: true,\n allow_trailing_dot: false,\n require_valid_protocol: false,\n // @ts-ignore\n require_port: false,\n require_tld: false,\n ...options,\n });\n}\n\n/**\n * Detect running protocol (http or https)\n */\nexport function getWebProtocol(headerProtocol: string | undefined, protocol: string): string {\n let returnProtocol;\n const [, defaultProtocol] = validProtocols;\n // HAProxy variant might return http,http with X-Forwarded-Proto\n if (typeof headerProtocol === 'string' && headerProtocol !== '') {\n debug('header protocol: %o', protocol);\n const commaIndex = headerProtocol.indexOf(',');\n returnProtocol = commaIndex > 0 ? headerProtocol.slice(0, commaIndex) : headerProtocol;\n } else {\n debug('req protocol: %o', headerProtocol);\n returnProtocol = protocol;\n }\n\n return validProtocols.includes(returnProtocol) ? returnProtocol : defaultProtocol;\n}\n\nexport function wrapPrefix(prefix: string | void): string {\n if (prefix === '' || typeof prefix === 'undefined' || prefix === null) {\n return '';\n } else if (!prefix.startsWith('/') && prefix.endsWith('/')) {\n return `/${prefix}`;\n } else if (!prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `/${prefix}/`;\n } else if (prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `${prefix}/`;\n } else {\n return prefix;\n }\n}\n\n/**\n * Create base url for registry.\n * @return {String} base registry url\n */\nexport function combineBaseUrl(protocol: string, host: string, prefix: string = ''): string {\n debug('combined protocol %o', protocol);\n debug('combined host %o', host);\n const newPrefix = wrapPrefix(prefix);\n debug('combined prefix %o', newPrefix);\n const groupedURI = new URL(wrapPrefix(prefix), `${protocol}://${host}`);\n const result = groupedURI.href;\n debug('combined url %o', result);\n return result;\n}\n\nexport function validateURL(publicUrl: string | void) {\n try {\n const parsed = new URL(publicUrl as string);\n if (!validProtocols.includes(parsed.protocol.replace(':', ''))) {\n throw Error('invalid protocol');\n }\n return true;\n } catch {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host (without port in Express 4).\n */\n host: string;\n /**\n * Request protocol, usually http or https.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: IncomingHttpHeaders;\n /**\n * Request remote address. This is the IPv4 or IPv6 address of the client.\n */\n remoteAddress?: string;\n /**\n * Logged username the request, usually after token verification.\n */\n username?: string;\n};\n\nexport function getPublicUrl(url_prefix: string = '', requestOptions: RequestOptions): string {\n if (validateURL(process.env.VERDACCIO_PUBLIC_URL as string)) {\n const envURL = new URL(wrapPrefix(url_prefix), process.env.VERDACCIO_PUBLIC_URL as string).href;\n debug('public url by env %o', envURL);\n return envURL;\n } else if (requestOptions.headers['host']) {\n const host = requestOptions.headers['host'];\n if (!isHost(host)) {\n throw new Error('invalid host');\n }\n\n // 'X-Forwarded-Proto' is the default header\n const protoHeader: string =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const forwardedProtocolHeaderValue = requestOptions.headers[protoHeader];\n\n if (Array.isArray(forwardedProtocolHeaderValue)) {\n // This really should never happen - only set-cookie is allowed to have\n // multiple values.\n throw new Error('invalid forwarded protocol header value. Reading header ' + protoHeader);\n }\n\n const protocol = getWebProtocol(forwardedProtocolHeaderValue, requestOptions.protocol);\n const combinedUrl = combineBaseUrl(protocol, host, url_prefix);\n debug('public url by request %o', combinedUrl);\n return combinedUrl;\n } else {\n return '/';\n }\n}\n\nexport const isURL = validator.isURL;\n"],"mappings":";;;;;;;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,oBAAoB;AAE7C,IAAM,iBAAiB,CAAC,SAAS,MAAM;;;;;AAMvC,SAAgB,sBAAsB,KAAsB;CAC1D,OAAO,kBAAkB,KAAK,GAAG;AACnC;AAEA,SAAgB,OAAO,MAAc,IAAI,UAAU,CAAC,GAAY;CAC9D,OAAO,UAAA,QAAU,MAAM,KAAK;EAC1B,cAAc;EACd,oBAAoB;EACpB,wBAAwB;EAExB,cAAc;EACd,aAAa;EACb,GAAG;CACL,CAAC;AACH;;;;AAKA,SAAgB,eAAe,gBAAoC,UAA0B;CAC3F,IAAI;CACJ,MAAM,GAAG,mBAAmB;CAE5B,IAAI,OAAO,mBAAmB,YAAY,mBAAmB,IAAI;EAC/D,QAAM,uBAAuB,QAAQ;EACrC,MAAM,aAAa,eAAe,QAAQ,GAAG;EAC7C,iBAAiB,aAAa,IAAI,eAAe,MAAM,GAAG,UAAU,IAAI;CAC1E,OAAO;EACL,QAAM,oBAAoB,cAAc;EACxC,iBAAiB;CACnB;CAEA,OAAO,eAAe,SAAS,cAAc,IAAI,iBAAiB;AACpE;AAEA,SAAgB,WAAW,QAA+B;CACxD,IAAI,WAAW,MAAM,OAAO,WAAW,eAAe,WAAW,MAC/D,OAAO;MACF,IAAI,CAAC,OAAO,WAAW,GAAG,KAAK,OAAO,SAAS,GAAG,GAC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;EAI1F,MAAM,cAAc,eADH,eAAe,8BAA8B,eAAe,QAC1C,GAAU,MAAM,UAAU;EAC7D,QAAM,4BAA4B,WAAW;EAC7C,OAAO;CACT,OACE,OAAO;AAEX;AAEA,IAAa,QAAQ,UAAA,QAAU"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\nimport { URL } from 'node:url';\nimport validator from 'validator';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:core:url');\n\nconst validProtocols = ['https', 'http'];\n\n/**\n * Check if URI is starting with \"http://\", \"https://\" or \"//\"\n * @param {string} uri\n */\nexport function isURLhasValidProtocol(uri: string): boolean {\n return /^(https?:)?\\/\\//.test(uri);\n}\n\nexport function isHost(url: string = '', options = {}): boolean {\n return validator.isURL(url, {\n require_host: true,\n allow_trailing_dot: false,\n require_valid_protocol: false,\n // @ts-ignore\n require_port: false,\n require_tld: false,\n ...options,\n });\n}\n\n/**\n * Detect running protocol (http or https)\n */\nexport function getWebProtocol(headerProtocol: string | undefined, protocol: string): string {\n let returnProtocol;\n const [, defaultProtocol] = validProtocols;\n // HAProxy variant might return http,http with X-Forwarded-Proto\n if (typeof headerProtocol === 'string' && headerProtocol !== '') {\n debug('header protocol: %o', protocol);\n const commaIndex = headerProtocol.indexOf(',');\n returnProtocol = commaIndex > 0 ? headerProtocol.slice(0, commaIndex) : headerProtocol;\n } else {\n debug('req protocol: %o', headerProtocol);\n returnProtocol = protocol;\n }\n\n return validProtocols.includes(returnProtocol) ? returnProtocol : defaultProtocol;\n}\n\nexport function wrapPrefix(prefix: string | void): string {\n if (prefix === '' || typeof prefix === 'undefined' || prefix === null) {\n return '';\n } else if (!prefix.startsWith('/') && prefix.endsWith('/')) {\n return `/${prefix}`;\n } else if (!prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `/${prefix}/`;\n } else if (prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `${prefix}/`;\n } else {\n return prefix;\n }\n}\n\n/**\n * Create base url for registry.\n * @return {String} base registry url\n */\nexport function combineBaseUrl(protocol: string, host: string, prefix: string = ''): string {\n debug('combined protocol %o', protocol);\n debug('combined host %o', host);\n const newPrefix = wrapPrefix(prefix);\n debug('combined prefix %o', newPrefix);\n const groupedURI = new URL(wrapPrefix(prefix), `${protocol}://${host}`);\n const result = groupedURI.href;\n debug('combined url %o', result);\n return result;\n}\n\nexport function validateURL(publicUrl: string | void) {\n try {\n const parsed = new URL(publicUrl as string);\n if (!validProtocols.includes(parsed.protocol.replace(':', ''))) {\n throw Error('invalid protocol');\n }\n return true;\n } catch {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host (without port in Express 4).\n */\n host: string;\n /**\n * Request protocol, usually http or https.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: IncomingHttpHeaders;\n /**\n * Request remote address. This is the IPv4 or IPv6 address of the client.\n */\n remoteAddress?: string;\n /**\n * Logged username the request, usually after token verification.\n */\n username?: string;\n /**\n * Request bypass cache.\n */\n byPassCache?: boolean;\n};\n\nexport function getPublicUrl(url_prefix: string = '', requestOptions: RequestOptions): string {\n if (validateURL(process.env.VERDACCIO_PUBLIC_URL as string)) {\n const envURL = new URL(wrapPrefix(url_prefix), process.env.VERDACCIO_PUBLIC_URL as string).href;\n debug('public url by env %o', envURL);\n return envURL;\n } else if (requestOptions.headers['host']) {\n const host = requestOptions.headers['host'];\n if (!isHost(host)) {\n throw new Error('invalid host');\n }\n\n // 'X-Forwarded-Proto' is the default header\n const protoHeader: string =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const forwardedProtocolHeaderValue = requestOptions.headers[protoHeader];\n\n if (Array.isArray(forwardedProtocolHeaderValue)) {\n // This really should never happen - only set-cookie is allowed to have\n // multiple values.\n throw new Error('invalid forwarded protocol header value. Reading header ' + protoHeader);\n }\n\n const protocol = getWebProtocol(forwardedProtocolHeaderValue, requestOptions.protocol);\n const combinedUrl = combineBaseUrl(protocol, host, url_prefix);\n debug('public url by request %o', combinedUrl);\n return combinedUrl;\n } else {\n return '/';\n }\n}\n\nexport const isURL = validator.isURL;\n"],"mappings":";;;;;;;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,oBAAoB;AAE7C,IAAM,iBAAiB,CAAC,SAAS,MAAM;;;;;AAMvC,SAAgB,sBAAsB,KAAsB;CAC1D,OAAO,kBAAkB,KAAK,GAAG;AACnC;AAEA,SAAgB,OAAO,MAAc,IAAI,UAAU,CAAC,GAAY;CAC9D,OAAO,UAAA,QAAU,MAAM,KAAK;EAC1B,cAAc;EACd,oBAAoB;EACpB,wBAAwB;EAExB,cAAc;EACd,aAAa;EACb,GAAG;CACL,CAAC;AACH;;;;AAKA,SAAgB,eAAe,gBAAoC,UAA0B;CAC3F,IAAI;CACJ,MAAM,GAAG,mBAAmB;CAE5B,IAAI,OAAO,mBAAmB,YAAY,mBAAmB,IAAI;EAC/D,QAAM,uBAAuB,QAAQ;EACrC,MAAM,aAAa,eAAe,QAAQ,GAAG;EAC7C,iBAAiB,aAAa,IAAI,eAAe,MAAM,GAAG,UAAU,IAAI;CAC1E,OAAO;EACL,QAAM,oBAAoB,cAAc;EACxC,iBAAiB;CACnB;CAEA,OAAO,eAAe,SAAS,cAAc,IAAI,iBAAiB;AACpE;AAEA,SAAgB,WAAW,QAA+B;CACxD,IAAI,WAAW,MAAM,OAAO,WAAW,eAAe,WAAW,MAC/D,OAAO;MACF,IAAI,CAAC,OAAO,WAAW,GAAG,KAAK,OAAO,SAAS,GAAG,GACvD,OAAO,IAAI;MACN,IAAI,CAAC,OAAO,WAAW,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GACxD,OAAO,IAAI,OAAO;MACb,IAAI,OAAO,WAAW,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GACvD,OAAO,GAAG,OA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- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\nimport { URL } from 'node:url';\nimport validator from 'validator';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:core:url');\n\nconst validProtocols = ['https', 'http'];\n\n/**\n * Check if URI is starting with \"http://\", \"https://\" or \"//\"\n * @param {string} uri\n */\nexport function isURLhasValidProtocol(uri: string): boolean {\n return /^(https?:)?\\/\\//.test(uri);\n}\n\nexport function isHost(url: string = '', options = {}): boolean {\n return validator.isURL(url, {\n require_host: true,\n allow_trailing_dot: false,\n require_valid_protocol: false,\n // @ts-ignore\n require_port: false,\n require_tld: false,\n ...options,\n });\n}\n\n/**\n * Detect running protocol (http or https)\n */\nexport function getWebProtocol(headerProtocol: string | undefined, protocol: string): string {\n let returnProtocol;\n const [, defaultProtocol] = validProtocols;\n // HAProxy variant might return http,http with X-Forwarded-Proto\n if (typeof headerProtocol === 'string' && headerProtocol !== '') {\n debug('header protocol: %o', protocol);\n const commaIndex = headerProtocol.indexOf(',');\n returnProtocol = commaIndex > 0 ? headerProtocol.slice(0, commaIndex) : headerProtocol;\n } else {\n debug('req protocol: %o', headerProtocol);\n returnProtocol = protocol;\n }\n\n return validProtocols.includes(returnProtocol) ? returnProtocol : defaultProtocol;\n}\n\nexport function wrapPrefix(prefix: string | void): string {\n if (prefix === '' || typeof prefix === 'undefined' || prefix === null) {\n return '';\n } else if (!prefix.startsWith('/') && prefix.endsWith('/')) {\n return `/${prefix}`;\n } else if (!prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `/${prefix}/`;\n } else if (prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `${prefix}/`;\n } else {\n return prefix;\n }\n}\n\n/**\n * Create base url for registry.\n * @return {String} base registry url\n */\nexport function combineBaseUrl(protocol: string, host: string, prefix: string = ''): string {\n debug('combined protocol %o', protocol);\n debug('combined host %o', host);\n const newPrefix = wrapPrefix(prefix);\n debug('combined prefix %o', newPrefix);\n const groupedURI = new URL(wrapPrefix(prefix), `${protocol}://${host}`);\n const result = groupedURI.href;\n debug('combined url %o', result);\n return result;\n}\n\nexport function validateURL(publicUrl: string | void) {\n try {\n const parsed = new URL(publicUrl as string);\n if (!validProtocols.includes(parsed.protocol.replace(':', ''))) {\n throw Error('invalid protocol');\n }\n return true;\n } catch {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host (without port in Express 4).\n */\n host: string;\n /**\n * Request protocol, usually http or https.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: IncomingHttpHeaders;\n /**\n * Request remote address. This is the IPv4 or IPv6 address of the client.\n */\n remoteAddress?: string;\n /**\n * Logged username the request, usually after token verification.\n */\n username?: string;\n};\n\nexport function getPublicUrl(url_prefix: string = '', requestOptions: RequestOptions): string {\n if (validateURL(process.env.VERDACCIO_PUBLIC_URL as string)) {\n const envURL = new URL(wrapPrefix(url_prefix), process.env.VERDACCIO_PUBLIC_URL as string).href;\n debug('public url by env %o', envURL);\n return envURL;\n } else if (requestOptions.headers['host']) {\n const host = requestOptions.headers['host'];\n if (!isHost(host)) {\n throw new Error('invalid host');\n }\n\n // 'X-Forwarded-Proto' is the default header\n const protoHeader: string =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const forwardedProtocolHeaderValue = requestOptions.headers[protoHeader];\n\n if (Array.isArray(forwardedProtocolHeaderValue)) {\n // This really should never happen - only set-cookie is allowed to have\n // multiple values.\n throw new Error('invalid forwarded protocol header value. Reading header ' + protoHeader);\n }\n\n const protocol = getWebProtocol(forwardedProtocolHeaderValue, requestOptions.protocol);\n const combinedUrl = combineBaseUrl(protocol, host, url_prefix);\n debug('public url by request %o', combinedUrl);\n return combinedUrl;\n } else {\n return '/';\n }\n}\n\nexport const isURL = validator.isURL;\n"],"mappings":";;;;;AAOA,IAAM,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ACjD,EAAW;CAC1B,MAAM,mBAAmB,MAAM;CAC/B,OAAO;AACT;AAEA,SAAgB,YAAY,WAA0B;CACpD,IAAI;EACF,MAAM,SAAS,IAAI,IAAI,SAAmB;EAC1C,IAAI,CAAC,eAAe,SAAS,OAAO,SAAS,QAAQ,KAAK,EAAE,CAAC,GAC3D,MAAM,MAAM,kBAAkB;EAEhC,OAAO;CACT,QAAQ;EAEN,OAAO;CACT;AACF;AAyBA,SAAgB,aAAa,aAAqB,IAAI,gBAAwC;CAC5F,IAAI,YAAY,QAAQ,IAAI,oBAA8B,GAAG;EAC3D,MAAM,SAAS,IAAI,IAAI,WAAW,UAAU,GAAG,QAAQ,IAAI,oBAA8B,EAAE;EAC3F,MAAM,wBAAwB,MAAM;EACpC,OAAO;CACT,OAAO,IAAI,eAAe,QAAQ,SAAS;EACzC,MAAM,OAAO,eAAe,QAAQ;EACpC,IAAI,CAAC,OAAO,IAAI,GACd,MAAM,IAAI,MAAM,cAAc;EAIhC,MAAM,cACJ,QAAQ,IAAI,2BAA2B,kBAAkB,KACzD,QAAQ,gBAAgB,YAAY;EACtC,MAAM,+BAA+B,eAAe,QAAQ;EAE5D,IAAI,MAAM,QAAQ,4BAA4B,GAG5C,MAAM,IAAI,MAAM,6DAA6D,WAAW;EAI1F,MAAM,cAAc,eADH,eAAe,8BAA8B,eAAe,QAC1C,GAAU,MAAM,UAAU;EAC7D,MAAM,4BAA4B,WAAW;EAC7C,OAAO;CACT,OACE,OAAO;AAEX;AAEA,IAAa,QAAQ,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\nimport { URL } from 'node:url';\nimport validator from 'validator';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:core:url');\n\nconst validProtocols = ['https', 'http'];\n\n/**\n * Check if URI is starting with \"http://\", \"https://\" or \"//\"\n * @param {string} uri\n */\nexport function isURLhasValidProtocol(uri: string): boolean {\n return /^(https?:)?\\/\\//.test(uri);\n}\n\nexport function isHost(url: string = '', options = {}): boolean {\n return validator.isURL(url, {\n require_host: true,\n allow_trailing_dot: false,\n require_valid_protocol: false,\n // @ts-ignore\n require_port: false,\n require_tld: false,\n ...options,\n });\n}\n\n/**\n * Detect running protocol (http or https)\n */\nexport function getWebProtocol(headerProtocol: string | undefined, protocol: string): string {\n let returnProtocol;\n const [, defaultProtocol] = validProtocols;\n // HAProxy variant might return http,http with X-Forwarded-Proto\n if (typeof headerProtocol === 'string' && headerProtocol !== '') {\n debug('header protocol: %o', protocol);\n const commaIndex = headerProtocol.indexOf(',');\n returnProtocol = commaIndex > 0 ? headerProtocol.slice(0, commaIndex) : headerProtocol;\n } else {\n debug('req protocol: %o', headerProtocol);\n returnProtocol = protocol;\n }\n\n return validProtocols.includes(returnProtocol) ? returnProtocol : defaultProtocol;\n}\n\nexport function wrapPrefix(prefix: string | void): string {\n if (prefix === '' || typeof prefix === 'undefined' || prefix === null) {\n return '';\n } else if (!prefix.startsWith('/') && prefix.endsWith('/')) {\n return `/${prefix}`;\n } else if (!prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `/${prefix}/`;\n } else if (prefix.startsWith('/') && !prefix.endsWith('/')) {\n return `${prefix}/`;\n } else {\n return prefix;\n }\n}\n\n/**\n * Create base url for registry.\n * @return {String} base registry url\n */\nexport function combineBaseUrl(protocol: string, host: string, prefix: string = ''): string {\n debug('combined protocol %o', protocol);\n debug('combined host %o', host);\n const newPrefix = wrapPrefix(prefix);\n debug('combined prefix %o', newPrefix);\n const groupedURI = new URL(wrapPrefix(prefix), `${protocol}://${host}`);\n const result = groupedURI.href;\n debug('combined url %o', result);\n return result;\n}\n\nexport function validateURL(publicUrl: string | void) {\n try {\n const parsed = new URL(publicUrl as string);\n if (!validProtocols.includes(parsed.protocol.replace(':', ''))) {\n throw Error('invalid protocol');\n }\n return true;\n } catch {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host (without port in Express 4).\n */\n host: string;\n /**\n * Request protocol, usually http or https.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: IncomingHttpHeaders;\n /**\n * Request remote address. This is the IPv4 or IPv6 address of the client.\n */\n remoteAddress?: string;\n /**\n * Logged username the request, usually after token verification.\n */\n username?: string;\n /**\n * Request bypass cache.\n */\n byPassCache?: boolean;\n};\n\nexport function getPublicUrl(url_prefix: string = '', requestOptions: RequestOptions): string {\n if (validateURL(process.env.VERDACCIO_PUBLIC_URL as string)) {\n const envURL = new URL(wrapPrefix(url_prefix), process.env.VERDACCIO_PUBLIC_URL as string).href;\n debug('public url by env %o', envURL);\n return envURL;\n } else if (requestOptions.headers['host']) {\n const host = requestOptions.headers['host'];\n if (!isHost(host)) {\n throw new Error('invalid host');\n }\n\n // 'X-Forwarded-Proto' is the default header\n const protoHeader: string =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const forwardedProtocolHeaderValue = requestOptions.headers[protoHeader];\n\n if (Array.isArray(forwardedProtocolHeaderValue)) {\n // This really should never happen - only set-cookie is allowed to have\n // multiple values.\n throw new Error('invalid forwarded protocol header value. Reading header ' + protoHeader);\n }\n\n const protocol = getWebProtocol(forwardedProtocolHeaderValue, requestOptions.protocol);\n const combinedUrl = combineBaseUrl(protocol, host, url_prefix);\n debug('public url by request %o', combinedUrl);\n return combinedUrl;\n } else {\n return '/';\n }\n}\n\nexport const isURL = validator.isURL;\n"],"mappings":";;;;;AAOA,IAAM,QAAQ,WAAW,oBAAoB;AAE7C,IAAM,iBAAiB,CAAC,SAAS,MAAM;;;;;AAMvC,SAAgB,sBAAsB,KAAsB;CAC1D,OAAO,kBAAkB,KAAK,GAAG;AACnC;AAEA,SAAgB,OAAO,MAAc,IAAI,UAAU,CAAC,GAAY;CAC9D,OAAO,UAAU,MAAM,KAAK;EAC1B,cAAc;EACd,oBAA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;CACT,QAAQ;EAEN,OAAO;CACT;AACF;AA6BA,SAAgB,aAAa,aAAqB,IAAI,gBAAwC;CAC5F,IAAI,YAAY,QAAQ,IAAI,oBAA8B,GAAG;EAC3D,MAAM,SAAS,IAAI,IAAI,WAAW,UAAU,GAAG,QAAQ,IAAI,oBAA8B,EAAE;EAC3F,MAAM,wBAAwB,MAAM;EACpC,OAAO;CACT,OAAO,IAAI,eAAe,QAAQ,SAAS;EACzC,MAAM,OAAO,eAAe,QAAQ;EACpC,IAAI,CAAC,OAAO,IAAI,GACd,MAAM,IAAI,MAAM,cAAc;EAIhC,MAAM,cACJ,QAAQ,IAAI,2BAA2B,kBAAkB,KACzD,QAAQ,gBAAgB,YAAY;EACtC,MAAM,+BAA+B,eAAe,QAAQ;EAE5D,IAAI,MAAM,QAAQ,4BAA4B,GAG5C,MAAM,IAAI,MAAM,6DAA6D,WAAW;EAI1F,MAAM,cAAc,eADH,eAAe,8BAA8B,eAAe,QAC1C,GAAU,MAAM,UAAU;EAC7D,MAAM,4BAA4B,WAAW;EAC7C,OAAO;CACT,OACE,OAAO;AAEX;AAEA,IAAa,QAAQ,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/url",
3
- "version": "14.0.0-next-9.20",
3
+ "version": "14.0.0-next-9.21",
4
4
  "description": "Verdaccio URL Utilities",
5
5
  "keywords": [
6
6
  "private",
@@ -33,14 +33,14 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@verdaccio/core": "9.0.0-next-9.20",
36
+ "@verdaccio/core": "9.0.0-next-9.21",
37
37
  "debug": "4.4.3",
38
38
  "validator": "13.15.35"
39
39
  },
40
40
  "devDependencies": {
41
41
  "node-mocks-http": "1.14.1",
42
42
  "rimraf": "6.1.3",
43
- "vite": "8.0.14",
43
+ "vite": "8.0.16",
44
44
  "vitest": "4.1.7"
45
45
  },
46
46
  "funding": {