@verdaccio/url 11.0.0-6-next.41 → 12.0.0-next-7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,171 @@
1
1
  # Change Log
2
2
 
3
+ ## 12.0.0-next-7.7
4
+
5
+ ### Patch Changes
6
+
7
+ - @verdaccio/core@7.0.0-next-7.7
8
+
9
+ ## 12.0.0-next.6
10
+
11
+ ### Patch Changes
12
+
13
+ - @verdaccio/core@7.0.0-next.6
14
+
15
+ ## 12.0.0-next.5
16
+
17
+ ### Minor Changes
18
+
19
+ - f047cc8: refactor: auth with legacy sign support
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [f047cc8]
24
+ - @verdaccio/core@7.0.0-next.5
25
+
26
+ ## 12.0.0-next.4
27
+
28
+ ### Patch Changes
29
+
30
+ - @verdaccio/core@7.0.0-next.4
31
+
32
+ ## 12.0.0-next.3
33
+
34
+ ### Major Changes
35
+
36
+ - e7ebccb61: update major dependencies, remove old nodejs support
37
+
38
+ ### Minor Changes
39
+
40
+ - daceb6d87: restore legacy support
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [daceb6d87]
45
+ - Updated dependencies [e7ebccb61]
46
+ - @verdaccio/core@7.0.0-next.3
47
+
48
+ ## 12.0.0-next.2
49
+
50
+ ### Patch Changes
51
+
52
+ - @verdaccio/core@7.0.0-next.2
53
+
54
+ ## 12.0.0-next.1
55
+
56
+ ### Patch Changes
57
+
58
+ - @verdaccio/core@7.0.0-next.1
59
+
60
+ ## 12.0.0-next.0
61
+
62
+ ### Major Changes
63
+
64
+ - feat!: bump to v7
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies
69
+ - @verdaccio/core@7.0.0-next.0
70
+
71
+ ## 11.0.0
72
+
73
+ ### Major Changes
74
+
75
+ - 292c0a37f: feat!: replace deprecated request dependency by got
76
+
77
+ This is a big refactoring of the core, fetching dependencies, improve code, more tests and better stability. This is essential for the next release, will take some time but would allow modularize more the core.
78
+
79
+ ## Notes
80
+
81
+ - Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
82
+ - Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
83
+ - Refactor with promises instead callback wherever is possible
84
+ - ~Document the API~
85
+ - Improve testing, integration tests
86
+ - Bugfix
87
+ - Clean up old validations
88
+ - Improve performance
89
+
90
+ ## 💥 Breaking changes
91
+
92
+ - Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
93
+ - Write Tarball, Read Tarball methods parameters change, a new set of options like `AbortController` signals are being provided to the `addAbortSignal` can be internally used with Streams when a request is aborted. eg: `addAbortSignal(signal, fs.createReadStream(pathName));`
94
+ - `@verdaccio/streams` stream abort support is legacy is being deprecated removed
95
+ - Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
96
+
97
+ - dc05edfe6: # async storage plugin bootstrap
98
+
99
+ Gives a storage plugin the ability to perform asynchronous tasks on initialization
100
+
101
+ ## Breaking change
102
+
103
+ Plugin must have an init method in which asynchronous tasks can be executed
104
+
105
+ ```js
106
+ public async init(): Promise<void> {
107
+ this.data = await this._fetchLocalPackages();
108
+ this._sync();
109
+ }
110
+ ```
111
+
112
+ - 794af76c5: Remove Node 12 support
113
+
114
+ - We need move to the new `undici` and does not support Node.js 12
115
+
116
+ ### Minor Changes
117
+
118
+ - ef88da3b4: feat: improve support for fs promises older nodejs
119
+ - 154b2ecd3: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
120
+ - ce013d2fc: refactor: npm star command support reimplemented
121
+ - 4b29d715b: chore: move improvements from v5 to v6
122
+
123
+ Migrate improvements form v5 to v6:
124
+
125
+ - https://github.com/verdaccio/verdaccio/pull/3158
126
+ - https://github.com/verdaccio/verdaccio/pull/3151
127
+ - https://github.com/verdaccio/verdaccio/pull/2271
128
+ - https://github.com/verdaccio/verdaccio/pull/2787
129
+ - https://github.com/verdaccio/verdaccio/pull/2791
130
+ - https://github.com/verdaccio/verdaccio/pull/2205
131
+
132
+ ### Patch Changes
133
+
134
+ - 351aeeaa8: fix(deps): @verdaccio/utils should be a prod dep of local-storage
135
+ - 9718e0330: fix: build targets for 5x modules
136
+ - Updated dependencies [292c0a37f]
137
+ - Updated dependencies [974cd8c19]
138
+ - Updated dependencies [ef88da3b4]
139
+ - Updated dependencies [43f32687c]
140
+ - Updated dependencies [a3a209b5e]
141
+ - Updated dependencies [459b6fa72]
142
+ - Updated dependencies [24b9be020]
143
+ - Updated dependencies [794af76c5]
144
+ - Updated dependencies [351aeeaa8]
145
+ - Updated dependencies [9718e0330]
146
+ - Updated dependencies [a1da11308]
147
+ - Updated dependencies [00d1d2a17]
148
+ - Updated dependencies [154b2ecd3]
149
+ - Updated dependencies [378e907d5]
150
+ - Updated dependencies [16e38df8a]
151
+ - Updated dependencies [82cb0f2bf]
152
+ - Updated dependencies [dc571aabd]
153
+ - Updated dependencies [f859d2b1a]
154
+ - Updated dependencies [6c1eb021b]
155
+ - Updated dependencies [62c24b632]
156
+ - Updated dependencies [0a6412ca9]
157
+ - Updated dependencies [5167bb528]
158
+ - Updated dependencies [c9d1af0e5]
159
+ - Updated dependencies [4b29d715b]
160
+ - Updated dependencies [b849128de]
161
+ - @verdaccio/core@6.0.0
162
+
163
+ ## 11.0.0-6-next.42
164
+
165
+ ### Patch Changes
166
+
167
+ - @verdaccio/core@6.0.0-6-next.76
168
+
3
169
  ## 11.0.0-6-next.41
4
170
 
5
171
  ### Patch Changes
package/build/index.d.ts CHANGED
@@ -37,3 +37,4 @@ export type RequestOptions = {
37
37
  username?: string;
38
38
  };
39
39
  export declare function getPublicUrl(url_prefix: string | undefined, requestOptions: RequestOptions): string;
40
+ export declare const isURL: typeof import("validator/lib/isURL").default;
package/build/index.js CHANGED
@@ -7,12 +7,13 @@ exports.combineBaseUrl = combineBaseUrl;
7
7
  exports.getPublicUrl = getPublicUrl;
8
8
  exports.getWebProtocol = getWebProtocol;
9
9
  exports.isHost = isHost;
10
+ exports.isURL = void 0;
10
11
  exports.isURLhasValidProtocol = isURLhasValidProtocol;
11
12
  exports.validateURL = validateURL;
12
13
  exports.wrapPrefix = wrapPrefix;
13
14
  var _debug = _interopRequireDefault(require("debug"));
14
15
  var _url = require("url");
15
- var _isURL = _interopRequireDefault(require("validator/lib/isURL"));
16
+ var _validator = _interopRequireDefault(require("validator"));
16
17
  var _core = require("@verdaccio/core");
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  const debug = (0, _debug.default)('verdaccio:core:url');
@@ -26,7 +27,7 @@ function isURLhasValidProtocol(uri) {
26
27
  return /^(https?:)?\/\//.test(uri);
27
28
  }
28
29
  function isHost(url = '', options = {}) {
29
- return (0, _isURL.default)(url, {
30
+ return _validator.default.isURL(url, {
30
31
  require_host: true,
31
32
  allow_trailing_dot: false,
32
33
  require_valid_protocol: false,
@@ -114,4 +115,5 @@ function getPublicUrl(url_prefix = '', requestOptions) {
114
115
  return '/';
115
116
  }
116
117
  }
118
+ const isURL = exports.isURL = _validator.default.isURL;
117
119
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_url","_isURL","_core","obj","__esModule","default","debug","buildDebug","validProtocols","isURLhasValidProtocol","uri","test","isHost","url","options","isURLValidator","require_host","allow_trailing_dot","require_valid_protocol","require_port","require_tld","getWebProtocol","headerProtocol","protocol","returnProtocol","defaultProtocol","commaIndex","indexOf","slice","includes","wrapPrefix","prefix","startsWith","endsWith","combineBaseUrl","host","newPrefix","groupedURI","URL","result","href","validateURL","publicUrl","parsed","replace","Error","err","getPublicUrl","url_prefix","requestOptions","process","env","VERDACCIO_PUBLIC_URL","envURL","headers","_process$env$VERDACCI","_process$env$VERDACCI2","protoHeader","VERDACCIO_FORWARDED_PROTO","toLocaleLowerCase","HEADERS","FORWARDED_PROTO","toLowerCase","combinedUrl"],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from 'url';\nimport isURLValidator from 'validator/lib/isURL';\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 isURLValidator(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 | void, 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 (err: any) {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host.\n */\n host: string;\n /**\n * Request protocol.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: { [key: string]: string };\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 const protoHeader =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const protocol = getWebProtocol(requestOptions.headers[protoHeader], 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"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAA0C,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE1C,MAAMG,KAAK,GAAG,IAAAC,cAAU,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AAK,CAAC,0BAA0B,EAAEyD,WAAW,CAAC;IAC9C,OAAOA,WAAW;EACpB,CAAC,MAAM;IACL,OAAO,GAAG;EACZ;AACF"}
1
+ {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_url","_validator","_core","obj","__esModule","default","debug","buildDebug","validProtocols","isURLhasValidProtocol","uri","test","isHost","url","options","validator","isURL","require_host","allow_trailing_dot","require_valid_protocol","require_port","require_tld","getWebProtocol","headerProtocol","protocol","returnProtocol","defaultProtocol","commaIndex","indexOf","slice","includes","wrapPrefix","prefix","startsWith","endsWith","combineBaseUrl","host","newPrefix","groupedURI","URL","result","href","validateURL","publicUrl","parsed","replace","Error","err","getPublicUrl","url_prefix","requestOptions","process","env","VERDACCIO_PUBLIC_URL","envURL","headers","_process$env$VERDACCI","_process$env$VERDACCI2","protoHeader","VERDACCIO_FORWARDED_PROTO","toLocaleLowerCase","HEADERS","FORWARDED_PROTO","toLowerCase","combinedUrl","exports"],"sources":["../src/index.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from '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 | void, 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 (err: any) {\n // TODO: add error logger here\n return false;\n }\n}\n\nexport type RequestOptions = {\n /**\n * Request host.\n */\n host: string;\n /**\n * Request protocol.\n */\n protocol: string;\n /**\n * Request headers.\n */\n headers: { [key: string]: string };\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 const protoHeader =\n process.env.VERDACCIO_FORWARDED_PROTO?.toLocaleLowerCase() ??\n HEADERS.FORWARDED_PROTO.toLowerCase();\n const protocol = getWebProtocol(requestOptions.headers[protoHeader], 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":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAA0C,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE1C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,oBAAoB,CAAC;AAE9C,MAAMC,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC;;AAExC;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAACC,GAAW,EAAW;EAC1D,OAAO,iBAAiB,CAACC,IAAI,CAACD,GAAG,CAAC;AACpC;AAEO,SAASE,MAAMA,CAACC,GAAW,GAAG,EAAE,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAW;EAC9D,OAAOC,kBAAS,CAACC,KAAK,CAACH,GAAG,EAAE;IAC1BI,YAAY,EAAE,IAAI;IAClBC,kBAAkB,EAAE,KAAK;IACzBC,sBAAsB,EAAE,KAAK;IAC7B;IACAC,YAAY,EAAE,KAAK;IACnBC,WAAW,EAAE,KAAK;IAClB,GAAGP;EACL,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACO,SAASQ,cAAcA,CAACC,cAA6B,EAAEC,QAAgB,EAAU;EACtF,IAAIC,cAAc;EAClB,MAAM,GAAGC,eAAe,CAAC,GAAGlB,cAAc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C,sBAAA;IACzC,MAAMrB,IAAI,GAAGc,cAAc,CAACK,OAAO,CAAC,MAAM,CAAC;IAC3C,IAAI,CAAC3C,MAAM,CAACwB,IAAI,CAAC,EAAE;MACjB,MAAM,IAAIU,KAAK,CAAC,cAAc,CAAC;IACjC;IACA,MAAMY,WAAW,IAAAF,qBAAA,IAAAC,sBAAA,GACfN,OAAO,CAACC,GAAG,CAACO,yBAAyB,cAAAF,sBAAA,uBAArCA,sBAAA,CAAuCG,iBAAiB,CAAC,CAAC,cAAAJ,qBAAA,cAAAA,qBAAA,GAC1DK,aAAO,CAACC,eAAe,CAACC,WAAW,CAAC,CAAC;IACvC,MAAMvC,QAAQ,GAAGF,cAAc,CAAC4B,cAAc,CAACK,OAAO,CAACG,WAAW,CAAC,EAAER,cAAc,CAAC1B,QAAQ,CAAC;IAC7F,MAAMwC,WAAW,GAAG7B,cAAc,CAACX,QAAQ,EAAEY,IAAI,EAAEa,UAAU,CAAC;IAC9D3C,KAAK,CAAC,0BAA0B,EAAE0D,WAAW,CAAC;IAC9C,OAAOA,WAAW;EACpB,CAAC,MAAM;IACL,OAAO,GAAG;EACZ;AACF;AAEO,MAAMhD,KAAK,GAAAiD,OAAA,CAAAjD,KAAA,GAAGD,kBAAS,CAACC,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/url",
3
- "version": "11.0.0-6-next.41",
3
+ "version": "12.0.0-next-7.7",
4
4
  "description": "url utilities resolver",
5
5
  "keywords": [
6
6
  "private",
@@ -33,14 +33,14 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@verdaccio/core": "6.0.0-6-next.75",
36
+ "@verdaccio/core": "7.0.0-next-7.7",
37
37
  "debug": "4.3.4",
38
38
  "lodash": "4.17.21",
39
- "validator": "13.9.0"
39
+ "validator": "13.11.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@verdaccio/types": "11.0.0-6-next.25",
43
- "node-mocks-http": "1.12.1"
42
+ "@verdaccio/types": "12.0.0-next.2",
43
+ "node-mocks-http": "1.14.1"
44
44
  },
45
45
  "funding": {
46
46
  "type": "opencollective",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import buildDebug from 'debug';
2
2
  import { URL } from 'url';
3
- import isURLValidator from 'validator/lib/isURL';
3
+ import validator from 'validator';
4
4
 
5
5
  import { HEADERS } from '@verdaccio/core';
6
6
 
@@ -17,7 +17,7 @@ export function isURLhasValidProtocol(uri: string): boolean {
17
17
  }
18
18
 
19
19
  export function isHost(url: string = '', options = {}): boolean {
20
- return isURLValidator(url, {
20
+ return validator.isURL(url, {
21
21
  require_host: true,
22
22
  allow_trailing_dot: false,
23
23
  require_valid_protocol: false,
@@ -130,3 +130,5 @@ export function getPublicUrl(url_prefix: string = '', requestOptions: RequestOpt
130
130
  return '/';
131
131
  }
132
132
  }
133
+
134
+ export const isURL = validator.isURL;