@verdaccio/proxy 6.0.0-6-next.19 → 6.0.0-6-next.22

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,63 @@
1
1
  # @verdaccio/proxy
2
2
 
3
+ ## 6.0.0-6-next.22
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [37274e4c]
8
+ - @verdaccio/local-storage@11.0.0-6-next.14
9
+ - @verdaccio/core@6.0.0-6-next.6
10
+ - @verdaccio/logger@6.0.0-6-next.12
11
+
12
+ ## 6.0.0-6-next.21
13
+
14
+ ### Major Changes
15
+
16
+ - 292c0a37: feat!: replace deprecated request dependency by got
17
+
18
+ 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.
19
+
20
+ ## Notes
21
+
22
+ - Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
23
+ - Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
24
+ - Refactor with promises instead callback wherever is possible
25
+ - ~Document the API~
26
+ - Improve testing, integration tests
27
+ - Bugfix
28
+ - Clean up old validations
29
+ - Improve performance
30
+
31
+ ## 💥 Breaking changes
32
+
33
+ - Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
34
+ - 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));`
35
+ - `@verdaccio/streams` stream abort support is legacy is being deprecated removed
36
+ - Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [292c0a37]
41
+ - Updated dependencies [a3a209b5]
42
+ - Updated dependencies [00d1d2a1]
43
+ - @verdaccio/config@6.0.0-6-next.15
44
+ - @verdaccio/core@6.0.0-6-next.6
45
+ - @verdaccio/logger@6.0.0-6-next.12
46
+ - @verdaccio/local-storage@11.0.0-6-next.13
47
+ - @verdaccio/utils@6.0.0-6-next.12
48
+
49
+ ## 6.0.0-6-next.20
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [d43894e8]
54
+ - Updated dependencies [d08fe29d]
55
+ - @verdaccio/config@6.0.0-6-next.14
56
+ - @verdaccio/local-storage@11.0.0-6-next.12
57
+ - @verdaccio/core@6.0.0-6-next.5
58
+ - @verdaccio/streams@11.0.0-6-next.5
59
+ - @verdaccio/logger@6.0.0-6-next.11
60
+
3
61
  ## 6.0.0-6-next.19
4
62
 
5
63
  ### Major Changes
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Agents } from 'got';
4
+ import { AgentOptions as HttpAgentOptions } from 'http';
5
+ import { AgentOptions as HttpsAgentOptions } from 'https';
6
+ export declare type AgentOptionsConf = HttpAgentOptions | HttpsAgentOptions;
7
+ declare class CustomAgents {
8
+ private url;
9
+ private proxy;
10
+ private agentOptions;
11
+ private agent;
12
+ constructor(url: string, proxy: string | undefined, agentOptions: HttpAgentOptions | HttpsAgentOptions);
13
+ get(): Agents;
14
+ private getAgent;
15
+ private getParsedUrl;
16
+ }
17
+ export default CustomAgents;
package/build/agent.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _hpagent = require("hpagent");
9
+
10
+ var _http = require("http");
11
+
12
+ var _https = require("https");
13
+
14
+ var _url = require("url");
15
+
16
+ class CustomAgents {
17
+ constructor(url, proxy, agentOptions) {
18
+ this.proxy = proxy;
19
+ this.url = url;
20
+ this.agentOptions = agentOptions;
21
+ const {
22
+ protocol
23
+ } = this.getParsedUrl();
24
+ this.agent = this.getAgent(protocol);
25
+ }
26
+
27
+ get() {
28
+ return this.agent;
29
+ }
30
+
31
+ getAgent(protocol) {
32
+ const isHTTPS = protocol === 'https:';
33
+
34
+ if (this.proxy) {
35
+ const options = {
36
+ proxy: this.proxy,
37
+ ...this.agentOptions
38
+ }; // use hpagent
39
+
40
+ return isHTTPS ? {
41
+ https: new _hpagent.HttpsProxyAgent(options)
42
+ } : {
43
+ http: new _hpagent.HttpProxyAgent(options)
44
+ };
45
+ } else {
46
+ // use native http/https agent
47
+ return isHTTPS ? {
48
+ https: new _https.Agent(this.agentOptions)
49
+ } : {
50
+ http: new _http.Agent(this.agentOptions)
51
+ };
52
+ }
53
+ }
54
+
55
+ getParsedUrl() {
56
+ return this.proxy ? new _url.URL(this.proxy) : new _url.URL(this.url);
57
+ }
58
+
59
+ }
60
+
61
+ var _default = CustomAgents;
62
+ exports.default = _default;
63
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","names":["CustomAgents","constructor","url","proxy","agentOptions","protocol","getParsedUrl","agent","getAgent","get","isHTTPS","options","https","HttpsProxyAgent","http","HttpProxyAgent","HttpsAgent","HttpAgent","URL"],"sources":["../src/agent.ts"],"sourcesContent":["import { Agents } from 'got';\nimport { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';\nimport { Agent as HttpAgent, AgentOptions as HttpAgentOptions } from 'http';\nimport { Agent as HttpsAgent, AgentOptions as HttpsAgentOptions } from 'https';\nimport { URL } from 'url';\n\nexport type AgentOptionsConf = HttpAgentOptions | HttpsAgentOptions;\n\nclass CustomAgents {\n private url: string;\n private proxy: string | undefined;\n private agentOptions: HttpAgentOptions | HttpsAgentOptions;\n private agent: Agents;\n public constructor(\n url: string,\n proxy: string | undefined,\n agentOptions: HttpAgentOptions | HttpsAgentOptions\n ) {\n this.proxy = proxy;\n this.url = url;\n this.agentOptions = agentOptions;\n const { protocol } = this.getParsedUrl();\n this.agent = this.getAgent(protocol);\n }\n\n public get() {\n return this.agent;\n }\n\n private getAgent(protocol: string): Agents {\n const isHTTPS = protocol === 'https:';\n if (this.proxy) {\n const options = {\n proxy: this.proxy,\n ...this.agentOptions,\n };\n // use hpagent\n return isHTTPS\n ? { https: new HttpsProxyAgent(options) }\n : { http: new HttpProxyAgent(options) };\n } else {\n // use native http/https agent\n return isHTTPS\n ? { https: new HttpsAgent(this.agentOptions) }\n : { http: new HttpAgent(this.agentOptions) };\n }\n }\n\n private getParsedUrl() {\n return this.proxy ? new URL(this.proxy) : new URL(this.url);\n }\n}\n\nexport default CustomAgents;\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AAIA,MAAMA,YAAN,CAAmB;EAKVC,WAAW,CAChBC,GADgB,EAEhBC,KAFgB,EAGhBC,YAHgB,EAIhB;IACA,KAAKD,KAAL,GAAaA,KAAb;IACA,KAAKD,GAAL,GAAWA,GAAX;IACA,KAAKE,YAAL,GAAoBA,YAApB;IACA,MAAM;MAAEC;IAAF,IAAe,KAAKC,YAAL,EAArB;IACA,KAAKC,KAAL,GAAa,KAAKC,QAAL,CAAcH,QAAd,CAAb;EACD;;EAEMI,GAAG,GAAG;IACX,OAAO,KAAKF,KAAZ;EACD;;EAEOC,QAAQ,CAACH,QAAD,EAA2B;IACzC,MAAMK,OAAO,GAAGL,QAAQ,KAAK,QAA7B;;IACA,IAAI,KAAKF,KAAT,EAAgB;MACd,MAAMQ,OAAO,GAAG;QACdR,KAAK,EAAE,KAAKA,KADE;QAEd,GAAG,KAAKC;MAFM,CAAhB,CADc,CAKd;;MACA,OAAOM,OAAO,GACV;QAAEE,KAAK,EAAE,IAAIC,wBAAJ,CAAoBF,OAApB;MAAT,CADU,GAEV;QAAEG,IAAI,EAAE,IAAIC,uBAAJ,CAAmBJ,OAAnB;MAAR,CAFJ;IAGD,CATD,MASO;MACL;MACA,OAAOD,OAAO,GACV;QAAEE,KAAK,EAAE,IAAII,YAAJ,CAAe,KAAKZ,YAApB;MAAT,CADU,GAEV;QAAEU,IAAI,EAAE,IAAIG,WAAJ,CAAc,KAAKb,YAAnB;MAAR,CAFJ;IAGD;EACF;;EAEOE,YAAY,GAAG;IACrB,OAAO,KAAKH,KAAL,GAAa,IAAIe,QAAJ,CAAQ,KAAKf,KAAb,CAAb,GAAmC,IAAIe,QAAJ,CAAQ,KAAKhB,GAAb,CAA1C;EACD;;AA1CgB;;eA6CJF,Y"}
package/build/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './up-storage';
1
+ export * from './proxy';
package/build/index.js CHANGED
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _upStorage = require("./up-storage");
7
+ var _proxy = require("./proxy");
8
8
 
9
- Object.keys(_upStorage).forEach(function (key) {
9
+ Object.keys(_proxy).forEach(function (key) {
10
10
  if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _upStorage[key]) return;
11
+ if (key in exports && exports[key] === _proxy[key]) return;
12
12
  Object.defineProperty(exports, key, {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _upStorage[key];
15
+ return _proxy[key];
16
16
  }
17
17
  });
18
18
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './up-storage';\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './proxy';\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/proxy-utils.ts"],"names":["parseIntervalTable","ms","s","m","h","d","w","M","y","parseInterval","interval","result","last_suffix","Infinity","split","forEach","x","match","Error","Number"],"mappings":";;;;;;AAAA,MAAMA,kBAAkB,GAAG;AACzB,MAAI,IADqB;AAEzBC,EAAAA,EAAE,EAAE,CAFqB;AAGzBC,EAAAA,CAAC,EAAE,IAHsB;AAIzBC,EA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86400000,\n y: 365 * 86400000,\n};\n\n/**\n * Parse an internal string to number\n * @param {*} interval\n * @return {Number}\n * @deprecated\n */\nexport function parseInterval(interval: any): number {\n if (typeof interval === 'number') {\n return interval * 1000;\n }\n let result = 0;\n let last_suffix = Infinity;\n interval.split(/\\s+/).forEach(function (x): void {\n if (!x) {\n return;\n }\n const m = x.match(/^((0|[1-9][0-9]*)(\\.[0-9]+)?)(ms|s|m|h|d|w|M|y|)$/);\n if (\n !m ||\n parseIntervalTable[m[4]] >= last_suffix ||\n (m[4] === '' && last_suffix !== Infinity)\n ) {\n throw Error('invalid interval: ' + interval);\n }\n last_suffix = parseIntervalTable[m[4]];\n result += Number(m[1]) * parseIntervalTable[m[4]];\n });\n return result;\n}\n"],"file":"proxy-utils.js"}
1
+ {"version":3,"file":"proxy-utils.js","names":["parseIntervalTable","ms","s","m","h","d","w","M","y","parseInterval","interval","result","last_suffix","Infinity","split","forEach","x","match","Error","Number"],"sources":["../src/proxy-utils.ts"],"sourcesContent":["const parseIntervalTable = {\n '': 1000,\n ms: 1,\n s: 1000,\n m: 60 * 1000,\n h: 60 * 60 * 1000,\n d: 86400000,\n w: 7 * 86400000,\n M: 30 * 86400000,\n y: 365 * 86400000,\n};\n\n/**\n * Parse an internal string to number\n * @param {*} interval\n * @return {Number}\n * @deprecated\n */\nexport function parseInterval(interval: any): number {\n if (typeof interval === 'number') {\n return interval * 1000;\n }\n let result = 0;\n let last_suffix = Infinity;\n interval.split(/\\s+/).forEach(function (x): void {\n if (!x) {\n return;\n }\n const m = x.match(/^((0|[1-9][0-9]*)(\\.[0-9]+)?)(ms|s|m|h|d|w|M|y|)$/);\n if (\n !m ||\n parseIntervalTable[m[4]] >= last_suffix ||\n (m[4] === '' && last_suffix !== Infinity)\n ) {\n throw Error('invalid interval: ' + interval);\n }\n last_suffix = parseIntervalTable[m[4]];\n result += Number(m[1]) * parseIntervalTable[m[4]];\n });\n return result;\n}\n"],"mappings":";;;;;;AAAA,MAAMA,kBAAkB,GAAG;EACzB,IAAI,IADqB;EAEzBC,EAAE,EAAE,CAFqB;EAGzBC,CAAC,EAAE,IAHsB;EAIzBC,CAAC,EAAE,KAAK,IAJiB;EAKzBC,CAAC,EAAE,KAAK,EAAL,GAAU,IALY;EAMzBC,CAAC,EAAE,QANsB;EAOzBC,CAAC,EAAE,IAAI,QAPkB;EAQzBC,CAAC,EAAE,KAAK,QARiB;EASzBC,CAAC,EAAE,MAAM;AATgB,CAA3B;AAYA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,aAAT,CAAuBC,QAAvB,EAA8C;EACnD,IAAI,OAAOA,QAAP,KAAoB,QAAxB,EAAkC;IAChC,OAAOA,QAAQ,GAAG,IAAlB;EACD;;EACD,IAAIC,MAAM,GAAG,CAAb;EACA,IAAIC,WAAW,GAAGC,QAAlB;EACAH,QAAQ,CAACI,KAAT,CAAe,KAAf,EAAsBC,OAAtB,CAA8B,UAAUC,CAAV,EAAmB;IAC/C,IAAI,CAACA,CAAL,EAAQ;MACN;IACD;;IACD,MAAMb,CAAC,GAAGa,CAAC,CAACC,KAAF,CAAQ,mDAAR,CAAV;;IACA,IACE,CAACd,CAAD,IACAH,kBAAkB,CAACG,CAAC,CAAC,CAAD,CAAF,CAAlB,IAA4BS,WAD5B,IAECT,CAAC,CAAC,CAAD,CAAD,KAAS,EAAT,IAAeS,WAAW,KAAKC,QAHlC,EAIE;MACA,MAAMK,KAAK,CAAC,uBAAuBR,QAAxB,CAAX;IACD;;IACDE,WAAW,GAAGZ,kBAAkB,CAACG,CAAC,CAAC,CAAD,CAAF,CAAhC;IACAQ,MAAM,IAAIQ,MAAM,CAAChB,CAAC,CAAC,CAAD,CAAF,CAAN,GAAeH,kBAAkB,CAACG,CAAC,CAAC,CAAD,CAAF,CAA3C;EACD,CAdD;EAeA,OAAOQ,MAAP;AACD"}
@@ -1,10 +1,14 @@
1
1
  /// <reference types="node" />
2
- import Stream from 'stream';
2
+ /// <reference types="node" />
3
+ import { Headers as gotHeaders } from 'got';
4
+ import type { Agents, Options } from 'got';
5
+ import Stream, { PassThrough } from 'stream';
3
6
  import { Headers } from 'undici';
4
7
  import { URL } from 'url';
5
8
  import { searchUtils } from '@verdaccio/core';
6
- import { ReadTarball } from '@verdaccio/streams';
7
- import { Callback, Config, IReadTarball, Logger, UpLinkConf } from '@verdaccio/types';
9
+ import { Manifest } from '@verdaccio/types';
10
+ import { Config, Logger, UpLinkConf } from '@verdaccio/types';
11
+ import { AgentOptionsConf } from './agent';
8
12
  export declare type UpLinkConfLocal = UpLinkConf & {
9
13
  no_proxy?: string;
10
14
  };
@@ -30,9 +34,15 @@ export interface IProxy {
30
34
  max_fails: number;
31
35
  fail_timeout: number;
32
36
  upname: string;
33
- fetchTarball(url: string): IReadTarball;
34
37
  search(options: ProxySearchParams): Promise<Stream.Readable>;
35
- getRemoteMetadata(name: string, options: any, callback: Callback): void;
38
+ getRemoteMetadataNext(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;
39
+ fetchTarballNext(url: string, options: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>): PassThrough;
40
+ }
41
+ export { Options as FetchOptions };
42
+ export interface ISyncUplinksOptions extends Options {
43
+ uplinksLook?: boolean;
44
+ etag?: string;
45
+ remoteAddress?: string;
36
46
  }
37
47
  /**
38
48
  * Implements Storage interface
@@ -50,38 +60,23 @@ declare class ProxyStorage implements IProxy {
50
60
  timeout: number;
51
61
  max_fails: number;
52
62
  fail_timeout: number;
53
- agent_options: any;
63
+ agent_options: AgentOptionsConf;
54
64
  upname: string;
55
- proxy: any;
65
+ proxy: string | undefined;
66
+ private agent;
56
67
  last_request_time: number | null;
57
68
  strict_ssl: boolean;
58
- /**
59
- * Constructor
60
- * @param {*} config
61
- * @param {*} mainConfig
62
- */
63
- constructor(config: UpLinkConfLocal, mainConfig: Config);
64
- /**
65
- * Fetch an asset.
66
- * @param {*} options
67
- * @param {*} cb
68
- * @return {Request}
69
- */
70
- private request;
71
- /**
72
- * Set default headers.
73
- * @param {Object} options
74
- * @return {Object}
75
- * @private
76
- */
77
- private _setHeaders;
69
+ private retry;
70
+ constructor(config: UpLinkConfLocal, mainConfig: Config, agent?: Agents);
71
+ private getAgent;
72
+ getHeadersNext(headers?: {}): gotHeaders;
78
73
  /**
79
74
  * Validate configuration auth and assign Header authorization
80
75
  * @param {Object} headers
81
76
  * @return {Object}
82
77
  * @private
83
78
  */
84
- private _setAuth;
79
+ private setAuthNext;
85
80
  /**
86
81
  * @param {string} message
87
82
  * @throws {Error}
@@ -114,40 +109,19 @@ declare class ProxyStorage implements IProxy {
114
109
 
115
110
  * @param {Object} headers
116
111
  * @private
112
+ * @deprecated use applyUplinkHeaders
117
113
  */
118
114
  private _overrideWithUpLinkConfLocaligHeaders;
119
- /**
120
- * Get a remote package metadata
121
- * @param {*} name package name
122
- * @param {*} options request options, eg: eTag.
123
- * @param {*} callback
124
- */
125
- getRemoteMetadata(name: string, options: any, callback: Callback): void;
126
- /**
127
- * Fetch a tarball from the uplink.
128
- * @param {String} url
129
- * @return {Stream}
130
- */
131
- fetchTarball(url: string): ReadTarball;
115
+ private applyUplinkHeaders;
116
+ getRemoteMetadataNext(name: string, options: ISyncUplinksOptions): Promise<[Manifest, string]>;
117
+ fetchTarballNext(url: string, overrideOptions: Pick<ISyncUplinksOptions, 'remoteAddress' | 'etag' | 'retry'>): any;
132
118
  /**
133
119
  * Perform a stream search.
134
120
  * @param {*} options request options
135
121
  * @return {Stream}
136
122
  */
137
123
  search({ url, abort }: ProxySearchParams): Promise<Stream.Readable>;
138
- /**
139
- * Add proxy headers.
140
- * FIXME: object mutations, it should return an new object
141
- * @param {*} req the http request
142
- * @param {*} headers the request headers
143
- */
144
- private _addProxyHeaders;
145
- /**
146
- * Check whether the remote host is available.
147
- * @param {*} alive
148
- * @return {Boolean}
149
- */
150
- private _statusCheck;
124
+ private addProxyHeaders;
151
125
  /**
152
126
  * If the request failure.
153
127
  * @return {boolean}