@verdaccio/proxy 6.0.0-6-next.12 → 6.0.0-6-next.16
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 +53 -0
- package/build/up-storage.d.ts +4 -4
- package/build/up-storage.js +33 -70
- package/build/up-storage.js.map +1 -1
- package/package.json +14 -15
- package/src/up-storage.ts +23 -18
- package/test/headers.auth.spec.ts +4 -5
- package/test/proxy-utils.spec.ts +1 -0
- package/test/proxy.error.spec.ts +7 -6
- package/test/proxy.metadata.ts +5 -4
- package/test/proxy.search.spec.ts +4 -2
- package/test/proxy.tarball.spec.ts +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# @verdaccio/proxy
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a828271d]
|
|
8
|
+
- Updated dependencies [24b9be02]
|
|
9
|
+
- Updated dependencies [e75c0a3b]
|
|
10
|
+
- Updated dependencies [b13a3fef]
|
|
11
|
+
- @verdaccio/local-storage@11.0.0-6-next.11
|
|
12
|
+
- @verdaccio/utils@6.0.0-6-next.10
|
|
13
|
+
- @verdaccio/core@6.0.0-6-next.4
|
|
14
|
+
- @verdaccio/logger@6.0.0-6-next.8
|
|
15
|
+
- @verdaccio/config@6.0.0-6-next.12
|
|
16
|
+
- @verdaccio/streams@11.0.0-6-next.5
|
|
17
|
+
|
|
18
|
+
## 6.0.0-6-next.15
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [f86c31ed]
|
|
23
|
+
- @verdaccio/utils@6.0.0-6-next.9
|
|
24
|
+
- @verdaccio/config@6.0.0-6-next.11
|
|
25
|
+
- @verdaccio/local-storage@11.0.0-6-next.10
|
|
26
|
+
|
|
27
|
+
## 6.0.0-6-next.14
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [6c1eb021]
|
|
32
|
+
- @verdaccio/core@6.0.0-6-next.3
|
|
33
|
+
- @verdaccio/logger@6.0.0-6-next.7
|
|
34
|
+
- @verdaccio/config@6.0.0-6-next.10
|
|
35
|
+
- @verdaccio/local-storage@11.0.0-6-next.10
|
|
36
|
+
- @verdaccio/utils@6.0.0-6-next.8
|
|
37
|
+
|
|
38
|
+
## 6.0.0-6-next.13
|
|
39
|
+
|
|
40
|
+
### Minor Changes
|
|
41
|
+
|
|
42
|
+
- b702ea36: abort search request support for proxy
|
|
43
|
+
- 154b2ecd: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [794af76c]
|
|
48
|
+
- Updated dependencies [154b2ecd]
|
|
49
|
+
- @verdaccio/config@6.0.0-6-next.9
|
|
50
|
+
- @verdaccio/core@6.0.0-6-next.2
|
|
51
|
+
- @verdaccio/streams@11.0.0-6-next.5
|
|
52
|
+
- @verdaccio/logger@6.0.0-6-next.6
|
|
53
|
+
- @verdaccio/utils@6.0.0-6-next.7
|
|
54
|
+
- @verdaccio/local-storage@11.0.0-6-next.9
|
|
55
|
+
|
|
3
56
|
## 6.0.0-6-next.12
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
package/build/up-storage.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import Stream from 'stream';
|
|
3
|
-
import { URL } from 'url';
|
|
4
3
|
import { Headers } from 'undici-fetch';
|
|
5
|
-
import {
|
|
6
|
-
import { Config, Callback, Logger, UpLinkConf, IReadTarball } from '@verdaccio/types';
|
|
4
|
+
import { URL } from 'url';
|
|
7
5
|
import { searchUtils } from '@verdaccio/core';
|
|
6
|
+
import { ReadTarball } from '@verdaccio/streams';
|
|
7
|
+
import { Callback, Config, IReadTarball, Logger, UpLinkConf } from '@verdaccio/types';
|
|
8
8
|
export declare type UpLinkConfLocal = UpLinkConf & {
|
|
9
9
|
no_proxy?: string;
|
|
10
10
|
};
|
|
@@ -15,7 +15,7 @@ export declare type ProxySearchParams = {
|
|
|
15
15
|
headers?: Headers;
|
|
16
16
|
url: string;
|
|
17
17
|
query?: searchUtils.SearchQuery;
|
|
18
|
-
abort
|
|
18
|
+
abort: AbortController;
|
|
19
19
|
};
|
|
20
20
|
export interface IProxy {
|
|
21
21
|
config: UpLinkConfLocal;
|
package/build/up-storage.js
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.ProxyStorage = void 0;
|
|
9
7
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _url = require("url");
|
|
8
|
+
var _JSONStream = _interopRequireDefault(require("JSONStream"));
|
|
13
9
|
|
|
14
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
15
11
|
|
|
16
12
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
17
13
|
|
|
18
|
-
var _undiciFetch = require("undici-fetch");
|
|
19
|
-
|
|
20
|
-
var _JSONStream = _interopRequireDefault(require("JSONStream"));
|
|
21
|
-
|
|
22
14
|
var _request = _interopRequireDefault(require("request"));
|
|
23
15
|
|
|
24
|
-
var
|
|
16
|
+
var _stream = _interopRequireWildcard(require("stream"));
|
|
25
17
|
|
|
26
|
-
var
|
|
18
|
+
var _undiciFetch = require("undici-fetch");
|
|
27
19
|
|
|
28
|
-
var
|
|
20
|
+
var _url = require("url");
|
|
29
21
|
|
|
30
22
|
var _core = require("@verdaccio/core");
|
|
31
23
|
|
|
32
|
-
var
|
|
24
|
+
var _streams = require("@verdaccio/streams");
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
var _utils = require("@verdaccio/utils");
|
|
27
|
+
|
|
28
|
+
var _proxyUtils = require("./proxy-utils");
|
|
35
29
|
|
|
36
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
37
31
|
|
|
38
32
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
39
33
|
|
|
40
|
-
function
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
35
|
|
|
36
|
+
/* global AbortController */
|
|
42
37
|
const LoggerApi = require('@verdaccio/logger');
|
|
43
38
|
|
|
44
39
|
const fetch = require('undici-fetch');
|
|
@@ -49,7 +44,7 @@ const encode = function (thing) {
|
|
|
49
44
|
return encodeURIComponent(thing).replace(/^%40/, '@');
|
|
50
45
|
};
|
|
51
46
|
|
|
52
|
-
const jsonContentType =
|
|
47
|
+
const jsonContentType = _core.HEADERS.JSON;
|
|
53
48
|
const contentTypeAccept = `${jsonContentType};`;
|
|
54
49
|
/**
|
|
55
50
|
* Just a helper (`config[key] || default` doesn't work because of zeroes)
|
|
@@ -76,38 +71,6 @@ class ProxyStorage {
|
|
|
76
71
|
* @param {*} mainConfig
|
|
77
72
|
*/
|
|
78
73
|
constructor(config, mainConfig) {
|
|
79
|
-
_defineProperty(this, "config", void 0);
|
|
80
|
-
|
|
81
|
-
_defineProperty(this, "failed_requests", void 0);
|
|
82
|
-
|
|
83
|
-
_defineProperty(this, "userAgent", void 0);
|
|
84
|
-
|
|
85
|
-
_defineProperty(this, "ca", void 0);
|
|
86
|
-
|
|
87
|
-
_defineProperty(this, "logger", void 0);
|
|
88
|
-
|
|
89
|
-
_defineProperty(this, "server_id", void 0);
|
|
90
|
-
|
|
91
|
-
_defineProperty(this, "url", void 0);
|
|
92
|
-
|
|
93
|
-
_defineProperty(this, "maxage", void 0);
|
|
94
|
-
|
|
95
|
-
_defineProperty(this, "timeout", void 0);
|
|
96
|
-
|
|
97
|
-
_defineProperty(this, "max_fails", void 0);
|
|
98
|
-
|
|
99
|
-
_defineProperty(this, "fail_timeout", void 0);
|
|
100
|
-
|
|
101
|
-
_defineProperty(this, "agent_options", void 0);
|
|
102
|
-
|
|
103
|
-
_defineProperty(this, "upname", void 0);
|
|
104
|
-
|
|
105
|
-
_defineProperty(this, "proxy", void 0);
|
|
106
|
-
|
|
107
|
-
_defineProperty(this, "last_request_time", void 0);
|
|
108
|
-
|
|
109
|
-
_defineProperty(this, "strict_ssl", void 0);
|
|
110
|
-
|
|
111
74
|
this.config = config;
|
|
112
75
|
this.failed_requests = 0;
|
|
113
76
|
this.userAgent = mainConfig.user_agent;
|
|
@@ -184,7 +147,7 @@ class ProxyStorage {
|
|
|
184
147
|
|
|
185
148
|
if (_core.validatioUtils.isObject(options.json)) {
|
|
186
149
|
json = JSON.stringify(options.json);
|
|
187
|
-
headers['Content-Type'] = headers['Content-Type'] ||
|
|
150
|
+
headers['Content-Type'] = headers['Content-Type'] || _core.HEADERS.JSON;
|
|
188
151
|
}
|
|
189
152
|
|
|
190
153
|
const requestCallback = cb ? function (err, res, body) {
|
|
@@ -208,7 +171,7 @@ class ProxyStorage {
|
|
|
208
171
|
if (options.json && res.statusCode < 300) {
|
|
209
172
|
try {
|
|
210
173
|
// $FlowFixMe
|
|
211
|
-
body = JSON.parse(body.toString(
|
|
174
|
+
body = JSON.parse(body.toString(_core.CHARACTER_ENCODING.UTF8));
|
|
212
175
|
} catch (_err) {
|
|
213
176
|
body = {};
|
|
214
177
|
err = _err;
|
|
@@ -313,9 +276,9 @@ class ProxyStorage {
|
|
|
313
276
|
|
|
314
277
|
_setHeaders(options) {
|
|
315
278
|
const headers = options.headers || {};
|
|
316
|
-
const accept =
|
|
317
|
-
const acceptEncoding =
|
|
318
|
-
const userAgent =
|
|
279
|
+
const accept = _core.HEADERS.ACCEPT;
|
|
280
|
+
const acceptEncoding = _core.HEADERS.ACCEPT_ENCODING;
|
|
281
|
+
const userAgent = _core.HEADERS.USER_AGENT;
|
|
319
282
|
headers[accept] = headers[accept] || contentTypeAccept;
|
|
320
283
|
headers[acceptEncoding] = headers[acceptEncoding] || 'gzip'; // registry.npmjs.org will only return search result if user-agent include string 'npm'
|
|
321
284
|
|
|
@@ -335,7 +298,7 @@ class ProxyStorage {
|
|
|
335
298
|
auth
|
|
336
299
|
} = this.config;
|
|
337
300
|
|
|
338
|
-
if (_lodash.default.isNil(auth) || headers[
|
|
301
|
+
if (_lodash.default.isNil(auth) || headers[_core.HEADERS.AUTHORIZATION]) {
|
|
339
302
|
return headers;
|
|
340
303
|
}
|
|
341
304
|
|
|
@@ -357,20 +320,20 @@ class ProxyStorage {
|
|
|
357
320
|
} else if (_lodash.default.isBoolean(tokenConf.token_env) && tokenConf.token_env) {
|
|
358
321
|
token = process.env.NPM_TOKEN;
|
|
359
322
|
} else {
|
|
360
|
-
this.logger.error(_core.
|
|
323
|
+
this.logger.error(_core.constants.ERROR_CODE.token_required);
|
|
361
324
|
|
|
362
|
-
this._throwErrorAuth(_core.
|
|
325
|
+
this._throwErrorAuth(_core.constants.ERROR_CODE.token_required);
|
|
363
326
|
}
|
|
364
327
|
} else {
|
|
365
328
|
token = process.env.NPM_TOKEN;
|
|
366
329
|
}
|
|
367
330
|
|
|
368
331
|
if (_lodash.default.isNil(token)) {
|
|
369
|
-
this._throwErrorAuth(_core.
|
|
332
|
+
this._throwErrorAuth(_core.constants.ERROR_CODE.token_required);
|
|
370
333
|
} // define type Auth allow basic and bearer
|
|
371
334
|
|
|
372
335
|
|
|
373
|
-
const type = tokenConf.type ||
|
|
336
|
+
const type = tokenConf.type || _core.TOKEN_BASIC;
|
|
374
337
|
|
|
375
338
|
this._setHeaderAuthorization(headers, type, token);
|
|
376
339
|
|
|
@@ -399,12 +362,12 @@ class ProxyStorage {
|
|
|
399
362
|
_setHeaderAuthorization(headers, type, token) {
|
|
400
363
|
const _type = type.toLowerCase();
|
|
401
364
|
|
|
402
|
-
if (_type !==
|
|
365
|
+
if (_type !== _core.TOKEN_BEARER.toLowerCase() && _type !== _core.TOKEN_BASIC.toLowerCase()) {
|
|
403
366
|
this._throwErrorAuth(`Auth type '${_type}' not allowed`);
|
|
404
367
|
}
|
|
405
368
|
|
|
406
369
|
type = _lodash.default.upperFirst(type);
|
|
407
|
-
headers[
|
|
370
|
+
headers[_core.HEADERS.AUTHORIZATION] = (0, _utils.buildToken)(type, token);
|
|
408
371
|
}
|
|
409
372
|
/**
|
|
410
373
|
* It will add or override specified headers from config file.
|
|
@@ -451,7 +414,7 @@ class ProxyStorage {
|
|
|
451
414
|
|
|
452
415
|
if (_lodash.default.isNil(options.etag) === false) {
|
|
453
416
|
headers['If-None-Match'] = options.etag;
|
|
454
|
-
headers[
|
|
417
|
+
headers[_core.HEADERS.ACCEPT] = contentTypeAccept;
|
|
455
418
|
}
|
|
456
419
|
|
|
457
420
|
this.request({
|
|
@@ -464,11 +427,11 @@ class ProxyStorage {
|
|
|
464
427
|
return callback(err);
|
|
465
428
|
}
|
|
466
429
|
|
|
467
|
-
if (res.statusCode ===
|
|
430
|
+
if (res.statusCode === _core.HTTP_STATUS.NOT_FOUND) {
|
|
468
431
|
return callback(_core.errorUtils.getNotFound(_core.errorUtils.API_ERROR.NOT_PACKAGE_UPLINK));
|
|
469
432
|
}
|
|
470
433
|
|
|
471
|
-
if (!(res.statusCode >=
|
|
434
|
+
if (!(res.statusCode >= _core.HTTP_STATUS.OK && res.statusCode < _core.HTTP_STATUS.MULTIPLE_CHOICES)) {
|
|
472
435
|
const error = _core.errorUtils.getInternalError(`${_core.errorUtils.API_ERROR.BAD_STATUS_CODE}: ${res.statusCode}`);
|
|
473
436
|
|
|
474
437
|
error.remoteStatus = res.statusCode;
|
|
@@ -500,17 +463,17 @@ class ProxyStorage {
|
|
|
500
463
|
}
|
|
501
464
|
});
|
|
502
465
|
readStream.on('response', function (res) {
|
|
503
|
-
if (res.statusCode ===
|
|
466
|
+
if (res.statusCode === _core.HTTP_STATUS.NOT_FOUND) {
|
|
504
467
|
return stream.emit('error', _core.errorUtils.getNotFound(_core.errorUtils.API_ERROR.NOT_FILE_UPLINK));
|
|
505
468
|
}
|
|
506
469
|
|
|
507
|
-
if (!(res.statusCode >=
|
|
470
|
+
if (!(res.statusCode >= _core.HTTP_STATUS.OK && res.statusCode < _core.HTTP_STATUS.MULTIPLE_CHOICES)) {
|
|
508
471
|
return stream.emit('error', _core.errorUtils.getInternalError(`bad uplink status code: ${res.statusCode}`));
|
|
509
472
|
}
|
|
510
473
|
|
|
511
|
-
if (res.headers[
|
|
512
|
-
expected_length = res.headers[
|
|
513
|
-
stream.emit(
|
|
474
|
+
if (res.headers[_core.HEADER_TYPE.CONTENT_LENGTH]) {
|
|
475
|
+
expected_length = res.headers[_core.HEADER_TYPE.CONTENT_LENGTH];
|
|
476
|
+
stream.emit(_core.HEADER_TYPE.CONTENT_LENGTH, res.headers[_core.HEADER_TYPE.CONTENT_LENGTH]);
|
|
514
477
|
}
|
|
515
478
|
|
|
516
479
|
readStream.pipe(stream);
|
|
@@ -566,7 +529,7 @@ class ProxyStorage {
|
|
|
566
529
|
response = await fetch(request);
|
|
567
530
|
debug('response.status %o', response.status);
|
|
568
531
|
|
|
569
|
-
if (response.status >=
|
|
532
|
+
if (response.status >= _core.HTTP_STATUS.BAD_REQUEST) {
|
|
570
533
|
throw _core.errorUtils.getInternalError(`bad status code ${response.status} from uplink`);
|
|
571
534
|
}
|
|
572
535
|
|
|
@@ -606,7 +569,7 @@ class ProxyStorage {
|
|
|
606
569
|
// https://github.com/rlidwka/sinopia/issues/254
|
|
607
570
|
// @ts-ignore
|
|
608
571
|
if (!this.proxy) {
|
|
609
|
-
headers[
|
|
572
|
+
headers[_core.HEADERS.FORWARDED_FOR] = (req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'] + ', ' : '') + req.connection.remoteAddress;
|
|
610
573
|
}
|
|
611
574
|
} // always attach Via header to avoid loops, even if we're not proxying
|
|
612
575
|
|
package/build/up-storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/up-storage.ts"],"names":["LoggerApi","require","fetch","debug","encode","thing","encodeURIComponent","replace","jsonContentType","HEADERS","JSON","contentTypeAccept","setConfig","config","key","def","_","isNil","ProxyStorage","constructor","mainConfig","failed_requests","userAgent","user_agent","ca","logger","child","sub","server_id","url","URL","_setupProxy","hostname","protocol","timeout","Number","warn","join","maxage","max_fails","fail_timeout","strict_ssl","Boolean","agent_options","keepAlive","maxSockets","maxFreeSockets","request","options","cb","json","_statusCheck","streamRead","Stream","Readable","process","nextTick","errorUtils","getInternalError","API_ERROR","UPLINK_OFFLINE","emit","_read","on","self","headers","_setHeaders","_addProxyHeaders","req","_overrideWithUpLinkConfLocaligHeaders","method","uri","uri_full","info","validatioUtils","isObject","stringify","requestCallback","err","res","body","error","responseLength","length","processBody","logActivity","message","statusCode","parse","toString","CHARACTER_ENCODING","UTF8","_err","isString","http","undefined","status","bytes","in","out","requestOptions","proxy","encoding","gzip","strictSSL","agentOptions","Object","assign","statusCalled","_verdaccio_aborted","do_log","isNull","accept","ACCEPT","acceptEncoding","ACCEPT_ENCODING","USER_AGENT","_setAuth","auth","AUTHORIZATION","token","_throwErrorAuth","tokenConf","token_env","env","isBoolean","NPM_TOKEN","ERROR_CODE","token_required","type","TOKEN_BASIC","_setHeaderAuthorization","Error","_type","toLowerCase","TOKEN_BEARER","upperFirst","getRemoteMetadata","name","callback","etag","HTTP_STATUS","NOT_FOUND","getNotFound","NOT_PACKAGE_UPLINK","OK","MULTIPLE_CHOICES","BAD_STATUS_CODE","remoteStatus","fetchTarball","stream","ReadTarball","current_length","expected_length","abort","readStream","Accept","NOT_FILE_UPLINK","HEADER_TYPE","CONTENT_LENGTH","pipe","data","CONTENT_MISMATCH","search","response","fullURL","href","uplink","upname","Request","signal","BAD_REQUEST","streamSearch","PassThrough","objectMode","text","streamResponse","from","JSONStream","end","errorMessage","FORWARDED_FOR","connection","remoteAddress","alive","arguments","_ifRequestFailure","host","last_request_time","Date","now","Math","abs","mainconfig","isHTTPS","noProxyList","proxy_key","no_proxy","split","isArray","i","noProxyItem","lastIndexOf","rule"],"mappings":";;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA;;;;;;;;;;AACA,MAAMA,SAAS,GAAGC,OAAO,CAAC,mBAAD,CAAzB;;AAEA,MAAMC,KAAK,GAAGD,OAAO,CAAC,cAAD,CAArB;;AACA,MAAME,KAAK,GAAG,oBAAW,iBAAX,CAAd;;AAEA,MAAMC,MAAM,GAAG,UAAUC,KAAV,EAAyB;AACtC,SAAOC,kBAAkB,CAACD,KAAD,CAAlB,CAA0BE,OAA1B,CAAkC,MAAlC,EAA0C,GAA1C,CAAP;AACD,CAFD;;AAIA,MAAMC,eAAe,GAAGC,oBAAQC,IAAhC;AACA,MAAMC,iBAAiB,GAAI,GAAEH,eAAgB,GAA7C;AAEA;AACA;AACA;;AACA,MAAMI,SAAS,GAAG,CAACC,MAAD,EAASC,GAAT,EAAcC,GAAd,KAA8B;AAC9C,SAAOC,gBAAEC,KAAF,CAAQJ,MAAM,CAACC,GAAD,C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AAL,CAAYtB,KAAZ,CACE;AAAE0B,QAAAA,GAAG,EAAE,KAAKA,GAAL,CAASyI,IAAhB;AAAsBjE,QAAAA,KAAK,EAAE,KAAKA;AAAlC,OADF,EAEE,iCAFF;AAID;AACF;;AA3nBkC","sourcesContent":["/* global AbortController */\n\nimport Stream, { PassThrough, Readable } from 'stream';\nimport { URL } from 'url';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport { Request, Headers } from 'undici-fetch';\nimport JSONStream from 'JSONStream';\nimport request from 'request';\nimport { buildToken } from '@verdaccio/utils';\nimport { ReadTarball } from '@verdaccio/streams';\nimport {\n TOKEN_BASIC,\n TOKEN_BEARER,\n HEADERS,\n HTTP_STATUS,\n HEADER_TYPE,\n CHARACTER_ENCODING,\n} from '@verdaccio/commons-api';\nimport { Config, Callback, Logger, UpLinkConf, IReadTarball } from '@verdaccio/types';\nimport { errorUtils, validatioUtils, searchUtils } from '@verdaccio/core';\nimport { parseInterval } from './proxy-utils';\nconst LoggerApi = require('@verdaccio/logger');\n\nconst fetch = require('undici-fetch');\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, key, 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 fetchTarball(url: string): IReadTarball;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(name: string, options: any, callback: Callback): void;\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: any;\n // FIXME: upname is assigned to each instance\n // @ts-ignore\n public upname: string;\n // FIXME: proxy can be boolean or object, something smells here\n // @ts-ignore\n public proxy: any;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n\n /**\n * Constructor\n * @param {*} config\n * @param {*} mainConfig\n */\n public constructor(config: UpLinkConfLocal, mainConfig: Config) {\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\n this.url = new URL(this.config.url);\n this._setupProxy(this.url.hostname, config, mainConfig, this.url.protocol === 'https:');\n\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 this.timeout = parseInterval(setConfig(this.config, 'timeout', '30s'));\n this.max_fails = Number(setConfig(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.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n });\n }\n\n /**\n * Fetch an asset.\n * @param {*} options\n * @param {*} cb\n * @return {Request}\n */\n private request(options: any, cb?: Callback): Stream.Readable {\n let json;\n\n if (this._statusCheck() === false) {\n const streamRead = new Stream.Readable();\n\n process.nextTick(function (): void {\n if (cb) {\n cb(errorUtils.getInternalError(errorUtils.API_ERROR.UPLINK_OFFLINE));\n }\n streamRead.emit('error', errorUtils.getInternalError(errorUtils.API_ERROR.UPLINK_OFFLINE));\n });\n streamRead._read = function (): void {};\n // preventing 'Uncaught, unspecified \"error\" event'\n streamRead.on('error', function (): void {});\n return streamRead;\n }\n\n const self = this;\n const headers: Headers = this._setHeaders(options);\n\n this._addProxyHeaders(options.req, headers);\n this._overrideWithUpLinkConfLocaligHeaders(headers);\n\n const method = options.method || 'GET';\n const uri = options.uri_full || this.config.url + options.uri;\n\n self.logger.info(\n {\n method: method,\n headers: headers,\n uri: uri,\n },\n \"making request: '@{method} @{uri}'\"\n );\n\n if (validatioUtils.isObject(options.json)) {\n json = JSON.stringify(options.json);\n headers['Content-Type'] = headers['Content-Type'] || HEADERS.JSON;\n }\n\n const requestCallback = cb\n ? function (err, res, body): void {\n let error;\n const responseLength = err ? 0 : body.length;\n // $FlowFixMe\n processBody();\n logActivity();\n // $FlowFixMe\n cb(err, res, body);\n\n /**\n * Perform a decode.\n */\n function processBody(): void {\n if (err) {\n error = err.message;\n return;\n }\n\n if (options.json && res.statusCode < 300) {\n try {\n // $FlowFixMe\n body = JSON.parse(body.toString(CHARACTER_ENCODING.UTF8));\n } catch (_err: any) {\n body = {};\n err = _err;\n error = err.message;\n }\n }\n\n if (!err && validatioUtils.isObject(body)) {\n if (_.isString(body.error)) {\n error = body.error;\n }\n }\n }\n /**\n * Perform a log.\n */\n function logActivity(): void {\n let message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n // FIXME: use LOG_VERDACCIO_BYTES\n message += error ? ', error: @{!error}' : ', bytes: @{bytes.in}/@{bytes.out}';\n self.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n err: err || undefined,\n request: { method: method, url: uri },\n status: res != null ? res.statusCode : 'ERR',\n error: error,\n bytes: {\n in: json ? json.length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n }\n }\n : undefined;\n\n let requestOptions = {\n url: uri,\n method: method,\n headers: headers,\n body: json,\n proxy: this.proxy,\n encoding: null,\n gzip: true,\n timeout: this.timeout,\n strictSSL: this.strict_ssl,\n agentOptions: this.agent_options,\n };\n\n if (this.ca) {\n requestOptions = Object.assign({}, requestOptions, {\n ca: this.ca,\n });\n }\n\n const req = request(requestOptions, requestCallback);\n\n let statusCalled = false;\n req.on('response', function (res): void {\n // FIXME: _verdaccio_aborted seems not used\n // @ts-ignore\n if (!req._verdaccio_aborted && !statusCalled) {\n statusCalled = true;\n self._statusCheck(true);\n }\n\n if (_.isNil(requestCallback) === false) {\n (function do_log(): void {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n self.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(res) === false ? res.statusCode : 'ERR',\n },\n message\n );\n })();\n }\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n req.on('error', function (_err): void {\n // FIXME: _verdaccio_aborted seems not used\n // @ts-ignore\n if (!req._verdaccio_aborted && !statusCalled) {\n statusCalled = true;\n self._statusCheck(false);\n }\n });\n // @ts-ignore\n return req;\n }\n\n /**\n * Set default headers.\n * @param {Object} options\n * @return {Object}\n * @private\n */\n private _setHeaders(options: any): Headers {\n const headers = options.headers || {};\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\n return this._setAuth(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private _setAuth(headers: any): Headers {\n const { auth } = this.config;\n\n if (_.isNil(auth) || headers[HEADERS.AUTHORIZATION]) {\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\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (_.isString(tokenConf.token_env)) {\n token = process.env[tokenConf.token_env];\n } else if (_.isBoolean(tokenConf.token_env) && tokenConf.token_env) {\n token = process.env.NPM_TOKEN;\n } else {\n this.logger.error(errorUtils.ERROR_CODE.token_required);\n this._throwErrorAuth(errorUtils.ERROR_CODE.token_required);\n }\n } else {\n token = process.env.NPM_TOKEN;\n }\n\n if (_.isNil(token)) {\n this._throwErrorAuth(errorUtils.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 */\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 /**\n * Get a remote package metadata\n * @param {*} name package name\n * @param {*} options request options, eg: eTag.\n * @param {*} callback\n */\n public getRemoteMetadata(name: string, options: any, callback: Callback): void {\n const headers = {};\n if (_.isNil(options.etag) === false) {\n headers['If-None-Match'] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n\n this.request(\n {\n uri: `/${encode(name)}`,\n json: true,\n headers: headers,\n req: options.req,\n },\n (err, res, body): void => {\n if (err) {\n return callback(err);\n }\n if (res.statusCode === HTTP_STATUS.NOT_FOUND) {\n return callback(errorUtils.getNotFound(errorUtils.API_ERROR.NOT_PACKAGE_UPLINK));\n }\n if (!(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(\n `${errorUtils.API_ERROR.BAD_STATUS_CODE}: ${res.statusCode}`\n );\n\n error.remoteStatus = res.statusCode;\n return callback(error);\n }\n callback(null, body, res.headers.etag);\n }\n );\n }\n\n /**\n * Fetch a tarball from the uplink.\n * @param {String} url\n * @return {Stream}\n */\n public fetchTarball(url: string) {\n const stream = new ReadTarball({});\n let current_length = 0;\n let expected_length;\n\n stream.abort = () => {};\n const readStream = this.request({\n uri_full: url,\n encoding: null,\n headers: {\n Accept: contentTypeAccept,\n },\n });\n\n readStream.on('response', function (res: any) {\n if (res.statusCode === HTTP_STATUS.NOT_FOUND) {\n return stream.emit('error', errorUtils.getNotFound(errorUtils.API_ERROR.NOT_FILE_UPLINK));\n }\n if (!(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)) {\n return stream.emit(\n 'error',\n errorUtils.getInternalError(`bad uplink status code: ${res.statusCode}`)\n );\n }\n if (res.headers[HEADER_TYPE.CONTENT_LENGTH]) {\n expected_length = res.headers[HEADER_TYPE.CONTENT_LENGTH];\n stream.emit(HEADER_TYPE.CONTENT_LENGTH, res.headers[HEADER_TYPE.CONTENT_LENGTH]);\n }\n\n readStream.pipe(stream);\n });\n\n readStream.on('error', function (err) {\n stream.emit('error', err);\n });\n readStream.on('data', function (data) {\n current_length += data.length;\n });\n readStream.on('end', function (data) {\n if (data) {\n current_length += data.length;\n }\n if (expected_length && current_length != expected_length) {\n stream.emit('error', errorUtils.getInternalError(errorUtils.API_ERROR.CONTENT_MISMATCH));\n }\n });\n return stream;\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 const request = new Request(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 response = await fetch(request);\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({ errorMessage: err?.message }, 'proxy search error: @{errorMessage}');\n throw err;\n }\n }\n\n /**\n * Add proxy headers.\n * FIXME: object mutations, it should return an new object\n * @param {*} req the http request\n * @param {*} headers the request headers\n */\n private _addProxyHeaders(req: any, headers: any): void {\n if (req) {\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 // https://github.com/rlidwka/sinopia/issues/254\n // @ts-ignore\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'] + ', ' : '') +\n req.connection.remoteAddress;\n }\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['Via'] = req?.headers['via'] ? req.headers['via'] + ', ' : '';\n\n headers['Via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n }\n\n /**\n * Check whether the remote host is available.\n * @param {*} alive\n * @return {Boolean}\n */\n private _statusCheck(alive?: boolean): boolean | void {\n if (arguments.length === 0) {\n return this._ifRequestFailure() === false;\n }\n if (alive) {\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is back online'\n );\n }\n this.failed_requests = 0;\n } else {\n this.failed_requests++;\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 this.last_request_time = Date.now();\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.lastIndexOf(noProxyItem) === hostname.length - noProxyItem.length) {\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 // @ts-ignore\n this.proxy = false;\n }\n break;\n }\n }\n }\n\n // if it's non-string (i.e. \"false\"), don't use it\n if (_.isString(this.proxy) === false) {\n delete this.proxy;\n } else {\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"],"file":"up-storage.js"}
|
|
1
|
+
{"version":3,"sources":["../src/up-storage.ts"],"names":["LoggerApi","require","fetch","debug","encode","thing","encodeURIComponent","replace","jsonContentType","HEADERS","JSON","contentTypeAccept","setConfig","config","key","def","_","isNil","ProxyStorage","constructor","mainConfig","failed_requests","userAgent","user_agent","ca","logger","child","sub","server_id","url","URL","_setupProxy","hostname","protocol","timeout","Number","warn","join","maxage","max_fails","fail_timeout","strict_ssl","Boolean","agent_options","keepAlive","maxSockets","maxFreeSockets","request","options","cb","json","_statusCheck","streamRead","Stream","Readable","process","nextTick","errorUtils","getInternalError","API_ERROR","UPLINK_OFFLINE","emit","_read","on","self","headers","_setHeaders","_addProxyHeaders","req","_overrideWithUpLinkConfLocaligHeaders","method","uri","uri_full","info","validatioUtils","isObject","stringify","requestCallback","err","res","body","error","responseLength","length","processBody","logActivity","message","statusCode","parse","toString","CHARACTER_ENCODING","UTF8","_err","isString","http","undefined","status","bytes","in","out","requestOptions","proxy","encoding","gzip","strictSSL","agentOptions","Object","assign","statusCalled","_verdaccio_aborted","do_log","isNull","accept","ACCEPT","acceptEncoding","ACCEPT_ENCODING","USER_AGENT","_setAuth","auth","AUTHORIZATION","token","_throwErrorAuth","tokenConf","token_env","env","isBoolean","NPM_TOKEN","constants","ERROR_CODE","token_required","type","TOKEN_BASIC","_setHeaderAuthorization","Error","_type","toLowerCase","TOKEN_BEARER","upperFirst","getRemoteMetadata","name","callback","etag","HTTP_STATUS","NOT_FOUND","getNotFound","NOT_PACKAGE_UPLINK","OK","MULTIPLE_CHOICES","BAD_STATUS_CODE","remoteStatus","fetchTarball","stream","ReadTarball","current_length","expected_length","abort","readStream","Accept","NOT_FILE_UPLINK","HEADER_TYPE","CONTENT_LENGTH","pipe","data","CONTENT_MISMATCH","search","response","fullURL","href","uplink","upname","Request","signal","BAD_REQUEST","streamSearch","PassThrough","objectMode","text","streamResponse","from","JSONStream","end","errorMessage","FORWARDED_FOR","connection","remoteAddress","alive","arguments","_ifRequestFailure","host","last_request_time","Date","now","Math","abs","mainconfig","isHTTPS","noProxyList","proxy_key","no_proxy","split","isArray","i","noProxyItem","lastIndexOf","rule"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAYA;;AAEA;;AAEA;;;;;;;;AAzBA;AA2BA,MAAMA,SAAS,GAAGC,OAAO,CAAC,mBAAD,CAAzB;;AAEA,MAAMC,KAAK,GAAGD,OAAO,CAAC,cAAD,CAArB;;AACA,MAAME,KAAK,GAAG,oBAAW,iBAAX,CAAd;;AAEA,MAAMC,MAAM,GAAG,UAAUC,KAAV,EAAyB;AACtC,SAAOC,kBAAkB,CAACD,KAAD,CAAlB,CAA0BE,OAA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AACD;AACF;AACF,KA3CK,CA6CN;;;AACA,QAAIrF,gBAAE6E,QAAF,CAAW,KAAKQ,KAAhB,MAA2B,KAA/B,EAAsC;AACpC,aAAO,KAAKA,KAAZ;AACD,KAFD,MAEO;AACL,WAAK5E,MAAL,CAAYtB,KAAZ,CACE;AAAE0B,QAAAA,GAAG,EAAE,KAAKA,GAAL,CAAS0I,IAAhB;AAAsBlE,QAAAA,KAAK,EAAE,KAAKA;AAAlC,OADF,EAEE,iCAFF;AAID;AACF;;AA3nBkC","sourcesContent":["/* global AbortController */\nimport JSONStream from 'JSONStream';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport request from 'request';\nimport Stream, { PassThrough, Readable } from 'stream';\nimport { Headers, Request } from 'undici-fetch';\nimport { URL } from 'url';\n\nimport {\n CHARACTER_ENCODING,\n HEADERS,\n HEADER_TYPE,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n constants,\n errorUtils,\n searchUtils,\n validatioUtils,\n} from '@verdaccio/core';\nimport { ReadTarball } from '@verdaccio/streams';\nimport { Callback, Config, IReadTarball, Logger, UpLinkConf } from '@verdaccio/types';\nimport { buildToken } from '@verdaccio/utils';\n\nimport { parseInterval } from './proxy-utils';\n\nconst LoggerApi = require('@verdaccio/logger');\n\nconst fetch = require('undici-fetch');\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, key, 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 fetchTarball(url: string): IReadTarball;\n search(options: ProxySearchParams): Promise<Stream.Readable>;\n getRemoteMetadata(name: string, options: any, callback: Callback): void;\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: any;\n // FIXME: upname is assigned to each instance\n // @ts-ignore\n public upname: string;\n // FIXME: proxy can be boolean or object, something smells here\n // @ts-ignore\n public proxy: any;\n // @ts-ignore\n public last_request_time: number | null;\n public strict_ssl: boolean;\n\n /**\n * Constructor\n * @param {*} config\n * @param {*} mainConfig\n */\n public constructor(config: UpLinkConfLocal, mainConfig: Config) {\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\n this.url = new URL(this.config.url);\n this._setupProxy(this.url.hostname, config, mainConfig, this.url.protocol === 'https:');\n\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 this.timeout = parseInterval(setConfig(this.config, 'timeout', '30s'));\n this.max_fails = Number(setConfig(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.agent_options = setConfig(this.config, 'agent_options', {\n keepAlive: true,\n maxSockets: 40,\n maxFreeSockets: 10,\n });\n }\n\n /**\n * Fetch an asset.\n * @param {*} options\n * @param {*} cb\n * @return {Request}\n */\n private request(options: any, cb?: Callback): Stream.Readable {\n let json;\n\n if (this._statusCheck() === false) {\n const streamRead = new Stream.Readable();\n\n process.nextTick(function (): void {\n if (cb) {\n cb(errorUtils.getInternalError(errorUtils.API_ERROR.UPLINK_OFFLINE));\n }\n streamRead.emit('error', errorUtils.getInternalError(errorUtils.API_ERROR.UPLINK_OFFLINE));\n });\n streamRead._read = function (): void {};\n // preventing 'Uncaught, unspecified \"error\" event'\n streamRead.on('error', function (): void {});\n return streamRead;\n }\n\n const self = this;\n const headers: Headers = this._setHeaders(options);\n\n this._addProxyHeaders(options.req, headers);\n this._overrideWithUpLinkConfLocaligHeaders(headers);\n\n const method = options.method || 'GET';\n const uri = options.uri_full || this.config.url + options.uri;\n\n self.logger.info(\n {\n method: method,\n headers: headers,\n uri: uri,\n },\n \"making request: '@{method} @{uri}'\"\n );\n\n if (validatioUtils.isObject(options.json)) {\n json = JSON.stringify(options.json);\n headers['Content-Type'] = headers['Content-Type'] || HEADERS.JSON;\n }\n\n const requestCallback = cb\n ? function (err, res, body): void {\n let error;\n const responseLength = err ? 0 : body.length;\n // $FlowFixMe\n processBody();\n logActivity();\n // $FlowFixMe\n cb(err, res, body);\n\n /**\n * Perform a decode.\n */\n function processBody(): void {\n if (err) {\n error = err.message;\n return;\n }\n\n if (options.json && res.statusCode < 300) {\n try {\n // $FlowFixMe\n body = JSON.parse(body.toString(CHARACTER_ENCODING.UTF8));\n } catch (_err: any) {\n body = {};\n err = _err;\n error = err.message;\n }\n }\n\n if (!err && validatioUtils.isObject(body)) {\n if (_.isString(body.error)) {\n error = body.error;\n }\n }\n }\n /**\n * Perform a log.\n */\n function logActivity(): void {\n let message = \"@{!status}, req: '@{request.method} @{request.url}'\";\n // FIXME: use LOG_VERDACCIO_BYTES\n message += error ? ', error: @{!error}' : ', bytes: @{bytes.in}/@{bytes.out}';\n self.logger.http(\n {\n // if error is null/false change this to undefined so it wont log\n err: err || undefined,\n request: { method: method, url: uri },\n status: res != null ? res.statusCode : 'ERR',\n error: error,\n bytes: {\n in: json ? json.length : 0,\n out: responseLength || 0,\n },\n },\n message\n );\n }\n }\n : undefined;\n\n let requestOptions = {\n url: uri,\n method: method,\n headers: headers,\n body: json,\n proxy: this.proxy,\n encoding: null,\n gzip: true,\n timeout: this.timeout,\n strictSSL: this.strict_ssl,\n agentOptions: this.agent_options,\n };\n\n if (this.ca) {\n requestOptions = Object.assign({}, requestOptions, {\n ca: this.ca,\n });\n }\n\n const req = request(requestOptions, requestCallback);\n\n let statusCalled = false;\n req.on('response', function (res): void {\n // FIXME: _verdaccio_aborted seems not used\n // @ts-ignore\n if (!req._verdaccio_aborted && !statusCalled) {\n statusCalled = true;\n self._statusCheck(true);\n }\n\n if (_.isNil(requestCallback) === false) {\n (function do_log(): void {\n const message = \"@{!status}, req: '@{request.method} @{request.url}' (streaming)\";\n self.logger.http(\n {\n request: {\n method: method,\n url: uri,\n },\n status: _.isNull(res) === false ? res.statusCode : 'ERR',\n },\n message\n );\n })();\n }\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n req.on('error', function (_err): void {\n // FIXME: _verdaccio_aborted seems not used\n // @ts-ignore\n if (!req._verdaccio_aborted && !statusCalled) {\n statusCalled = true;\n self._statusCheck(false);\n }\n });\n // @ts-ignore\n return req;\n }\n\n /**\n * Set default headers.\n * @param {Object} options\n * @return {Object}\n * @private\n */\n private _setHeaders(options: any): Headers {\n const headers = options.headers || {};\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\n return this._setAuth(headers);\n }\n\n /**\n * Validate configuration auth and assign Header authorization\n * @param {Object} headers\n * @return {Object}\n * @private\n */\n private _setAuth(headers: any): Headers {\n const { auth } = this.config;\n\n if (_.isNil(auth) || headers[HEADERS.AUTHORIZATION]) {\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\n if (_.isNil(tokenConf.token) === false && _.isString(tokenConf.token)) {\n token = tokenConf.token;\n } else if (_.isNil(tokenConf.token_env) === false) {\n if (_.isString(tokenConf.token_env)) {\n token = process.env[tokenConf.token_env];\n } else if (_.isBoolean(tokenConf.token_env) && 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 (_.isNil(token)) {\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 */\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 /**\n * Get a remote package metadata\n * @param {*} name package name\n * @param {*} options request options, eg: eTag.\n * @param {*} callback\n */\n public getRemoteMetadata(name: string, options: any, callback: Callback): void {\n const headers = {};\n if (_.isNil(options.etag) === false) {\n headers['If-None-Match'] = options.etag;\n headers[HEADERS.ACCEPT] = contentTypeAccept;\n }\n\n this.request(\n {\n uri: `/${encode(name)}`,\n json: true,\n headers: headers,\n req: options.req,\n },\n (err, res, body): void => {\n if (err) {\n return callback(err);\n }\n if (res.statusCode === HTTP_STATUS.NOT_FOUND) {\n return callback(errorUtils.getNotFound(errorUtils.API_ERROR.NOT_PACKAGE_UPLINK));\n }\n if (!(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)) {\n const error = errorUtils.getInternalError(\n `${errorUtils.API_ERROR.BAD_STATUS_CODE}: ${res.statusCode}`\n );\n\n error.remoteStatus = res.statusCode;\n return callback(error);\n }\n callback(null, body, res.headers.etag);\n }\n );\n }\n\n /**\n * Fetch a tarball from the uplink.\n * @param {String} url\n * @return {Stream}\n */\n public fetchTarball(url: string) {\n const stream = new ReadTarball({});\n let current_length = 0;\n let expected_length;\n\n stream.abort = () => {};\n const readStream = this.request({\n uri_full: url,\n encoding: null,\n headers: {\n Accept: contentTypeAccept,\n },\n });\n\n readStream.on('response', function (res: any) {\n if (res.statusCode === HTTP_STATUS.NOT_FOUND) {\n return stream.emit('error', errorUtils.getNotFound(errorUtils.API_ERROR.NOT_FILE_UPLINK));\n }\n if (!(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)) {\n return stream.emit(\n 'error',\n errorUtils.getInternalError(`bad uplink status code: ${res.statusCode}`)\n );\n }\n if (res.headers[HEADER_TYPE.CONTENT_LENGTH]) {\n expected_length = res.headers[HEADER_TYPE.CONTENT_LENGTH];\n stream.emit(HEADER_TYPE.CONTENT_LENGTH, res.headers[HEADER_TYPE.CONTENT_LENGTH]);\n }\n\n readStream.pipe(stream);\n });\n\n readStream.on('error', function (err) {\n stream.emit('error', err);\n });\n readStream.on('data', function (data) {\n current_length += data.length;\n });\n readStream.on('end', function (data) {\n if (data) {\n current_length += data.length;\n }\n if (expected_length && current_length != expected_length) {\n stream.emit('error', errorUtils.getInternalError(errorUtils.API_ERROR.CONTENT_MISMATCH));\n }\n });\n return stream;\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 const request = new Request(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 response = await fetch(request);\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({ errorMessage: err?.message }, 'proxy search error: @{errorMessage}');\n throw err;\n }\n }\n\n /**\n * Add proxy headers.\n * FIXME: object mutations, it should return an new object\n * @param {*} req the http request\n * @param {*} headers the request headers\n */\n private _addProxyHeaders(req: any, headers: any): void {\n if (req) {\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 // https://github.com/rlidwka/sinopia/issues/254\n // @ts-ignore\n if (!this.proxy) {\n headers[HEADERS.FORWARDED_FOR] =\n (req.headers['x-forwarded-for'] ? req.headers['x-forwarded-for'] + ', ' : '') +\n req.connection.remoteAddress;\n }\n }\n\n // always attach Via header to avoid loops, even if we're not proxying\n headers['Via'] = req?.headers['via'] ? req.headers['via'] + ', ' : '';\n\n headers['Via'] += '1.1 ' + this.server_id + ' (Verdaccio)';\n }\n\n /**\n * Check whether the remote host is available.\n * @param {*} alive\n * @return {Boolean}\n */\n private _statusCheck(alive?: boolean): boolean | void {\n if (arguments.length === 0) {\n return this._ifRequestFailure() === false;\n }\n if (alive) {\n if (this.failed_requests >= this.max_fails) {\n this.logger.warn(\n {\n host: this.url.host,\n },\n 'host @{host} is back online'\n );\n }\n this.failed_requests = 0;\n } else {\n this.failed_requests++;\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 this.last_request_time = Date.now();\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.lastIndexOf(noProxyItem) === hostname.length - noProxyItem.length) {\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 // @ts-ignore\n this.proxy = false;\n }\n break;\n }\n }\n }\n\n // if it's non-string (i.e. \"false\"), don't use it\n if (_.isString(this.proxy) === false) {\n delete this.proxy;\n } else {\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"],"file":"up-storage.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/proxy",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.16",
|
|
4
4
|
"description": "verdaccio proxy fetcher",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,29 +26,28 @@
|
|
|
26
26
|
"verdaccio"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=14",
|
|
30
30
|
"npm": ">=6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/
|
|
34
|
-
"@verdaccio/
|
|
35
|
-
"@verdaccio/
|
|
36
|
-
"@verdaccio/
|
|
37
|
-
"@verdaccio/
|
|
38
|
-
"@verdaccio/
|
|
39
|
-
"@verdaccio/utils": "6.0.0-6-next.6",
|
|
33
|
+
"@verdaccio/config": "6.0.0-6-next.12",
|
|
34
|
+
"@verdaccio/core": "6.0.0-6-next.4",
|
|
35
|
+
"@verdaccio/local-storage": "11.0.0-6-next.11",
|
|
36
|
+
"@verdaccio/logger": "6.0.0-6-next.8",
|
|
37
|
+
"@verdaccio/streams": "11.0.0-6-next.5",
|
|
38
|
+
"@verdaccio/utils": "6.0.0-6-next.10",
|
|
40
39
|
"JSONStream": "1.3.5",
|
|
41
40
|
"abortcontroller-polyfill": "1.7.3",
|
|
42
|
-
"debug": "4.3.
|
|
43
|
-
"lodash": "4.17.
|
|
44
|
-
"node-fetch": "2.6.
|
|
41
|
+
"debug": "4.3.3",
|
|
42
|
+
"lodash": "4.17.21",
|
|
43
|
+
"node-fetch": "2.6.6",
|
|
45
44
|
"request": "2.87.0",
|
|
46
|
-
"undici": "4.
|
|
45
|
+
"undici": "4.7.3",
|
|
47
46
|
"undici-fetch": "1.0.0-rc.4"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"@types/node": "16.
|
|
51
|
-
"@verdaccio/types": "11.0.0-6-next.
|
|
49
|
+
"@types/node": "16.11.12",
|
|
50
|
+
"@verdaccio/types": "11.0.0-6-next.10",
|
|
52
51
|
"get-stream": "^6.0.1",
|
|
53
52
|
"nock": "13.0.11",
|
|
54
53
|
"node-mocks-http": "1.10.1",
|
package/src/up-storage.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
/* global AbortController */
|
|
2
|
-
|
|
3
|
-
import Stream, { PassThrough, Readable } from 'stream';
|
|
4
|
-
import { URL } from 'url';
|
|
2
|
+
import JSONStream from 'JSONStream';
|
|
5
3
|
import buildDebug from 'debug';
|
|
6
4
|
import _ from 'lodash';
|
|
7
|
-
import { Request, Headers } from 'undici-fetch';
|
|
8
|
-
import JSONStream from 'JSONStream';
|
|
9
5
|
import request from 'request';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
import Stream, { PassThrough, Readable } from 'stream';
|
|
7
|
+
import { Headers, Request } from 'undici-fetch';
|
|
8
|
+
import { URL } from 'url';
|
|
9
|
+
|
|
12
10
|
import {
|
|
13
|
-
|
|
14
|
-
TOKEN_BEARER,
|
|
11
|
+
CHARACTER_ENCODING,
|
|
15
12
|
HEADERS,
|
|
16
|
-
HTTP_STATUS,
|
|
17
13
|
HEADER_TYPE,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
HTTP_STATUS,
|
|
15
|
+
TOKEN_BASIC,
|
|
16
|
+
TOKEN_BEARER,
|
|
17
|
+
constants,
|
|
18
|
+
errorUtils,
|
|
19
|
+
searchUtils,
|
|
20
|
+
validatioUtils,
|
|
21
|
+
} from '@verdaccio/core';
|
|
22
|
+
import { ReadTarball } from '@verdaccio/streams';
|
|
23
|
+
import { Callback, Config, IReadTarball, Logger, UpLinkConf } from '@verdaccio/types';
|
|
24
|
+
import { buildToken } from '@verdaccio/utils';
|
|
25
|
+
|
|
22
26
|
import { parseInterval } from './proxy-utils';
|
|
27
|
+
|
|
23
28
|
const LoggerApi = require('@verdaccio/logger');
|
|
24
29
|
|
|
25
30
|
const fetch = require('undici-fetch');
|
|
@@ -51,7 +56,7 @@ export type ProxySearchParams = {
|
|
|
51
56
|
headers?: Headers;
|
|
52
57
|
url: string;
|
|
53
58
|
query?: searchUtils.SearchQuery;
|
|
54
|
-
abort
|
|
59
|
+
abort: AbortController;
|
|
55
60
|
};
|
|
56
61
|
export interface IProxy {
|
|
57
62
|
config: UpLinkConfLocal;
|
|
@@ -358,15 +363,15 @@ class ProxyStorage implements IProxy {
|
|
|
358
363
|
} else if (_.isBoolean(tokenConf.token_env) && tokenConf.token_env) {
|
|
359
364
|
token = process.env.NPM_TOKEN;
|
|
360
365
|
} else {
|
|
361
|
-
this.logger.error(
|
|
362
|
-
this._throwErrorAuth(
|
|
366
|
+
this.logger.error(constants.ERROR_CODE.token_required);
|
|
367
|
+
this._throwErrorAuth(constants.ERROR_CODE.token_required);
|
|
363
368
|
}
|
|
364
369
|
} else {
|
|
365
370
|
token = process.env.NPM_TOKEN;
|
|
366
371
|
}
|
|
367
372
|
|
|
368
373
|
if (_.isNil(token)) {
|
|
369
|
-
this._throwErrorAuth(
|
|
374
|
+
this._throwErrorAuth(constants.ERROR_CODE.token_required);
|
|
370
375
|
}
|
|
371
376
|
|
|
372
377
|
// define type Auth allow basic and bearer
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { buildToken } from '@verdaccio/utils';
|
|
2
|
-
|
|
3
|
-
import { ERROR_CODE, TOKEN_BASIC, TOKEN_BEARER, HEADERS } from '@verdaccio/commons-api';
|
|
4
|
-
import { setup } from '@verdaccio/logger';
|
|
5
1
|
import { DEFAULT_REGISTRY } from '@verdaccio/config';
|
|
2
|
+
import { HEADERS, TOKEN_BASIC, TOKEN_BEARER, constants } from '@verdaccio/core';
|
|
3
|
+
import { setup } from '@verdaccio/logger';
|
|
4
|
+
import { buildToken } from '@verdaccio/utils';
|
|
6
5
|
|
|
7
6
|
import { ProxyStorage } from '../src/up-storage';
|
|
8
7
|
|
|
@@ -150,6 +149,6 @@ describe('uplink headers auth test', () => {
|
|
|
150
149
|
|
|
151
150
|
expect(function () {
|
|
152
151
|
fnError();
|
|
153
|
-
}).toThrow(ERROR_CODE.token_required);
|
|
152
|
+
}).toThrow(constants.ERROR_CODE.token_required);
|
|
154
153
|
});
|
|
155
154
|
});
|
package/test/proxy-utils.spec.ts
CHANGED
package/test/proxy.error.spec.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import nock from 'nock';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
3
4
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError, errorUtils } from '@verdaccio/core';
|
|
6
|
+
|
|
6
7
|
import { ProxyStorage } from '../src/up-storage';
|
|
7
8
|
|
|
8
9
|
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
@@ -81,7 +82,7 @@ describe('proxy', () => {
|
|
|
81
82
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
82
83
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
83
84
|
stream.on('error', (response) => {
|
|
84
|
-
expect(response).toEqual(
|
|
85
|
+
expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK));
|
|
85
86
|
done();
|
|
86
87
|
});
|
|
87
88
|
});
|
|
@@ -101,7 +102,7 @@ describe('proxy', () => {
|
|
|
101
102
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
102
103
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
103
104
|
stream.on('error', (response) => {
|
|
104
|
-
expect(response).toEqual(
|
|
105
|
+
expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`));
|
|
105
106
|
done();
|
|
106
107
|
});
|
|
107
108
|
});
|
|
@@ -117,7 +118,7 @@ describe('proxy', () => {
|
|
|
117
118
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
118
119
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
119
120
|
stream.on('error', (response) => {
|
|
120
|
-
expect(response).toEqual(
|
|
121
|
+
expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH));
|
|
121
122
|
done();
|
|
122
123
|
});
|
|
123
124
|
});
|
package/test/proxy.metadata.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import nock from 'nock';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
3
4
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { API_ERROR, errorUtils } from '@verdaccio/core';
|
|
6
|
+
|
|
6
7
|
import { ProxyStorage } from '../src/up-storage';
|
|
7
8
|
|
|
8
9
|
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
@@ -82,7 +83,7 @@ describe('proxy', () => {
|
|
|
82
83
|
nock(domain).get('/jquery').reply(404);
|
|
83
84
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
84
85
|
prox1.getRemoteMetadata('jquery', { etag: 'rev_3333' }, (error) => {
|
|
85
|
-
expect(error).toEqual(
|
|
86
|
+
expect(error).toEqual(errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK));
|
|
86
87
|
done();
|
|
87
88
|
});
|
|
88
89
|
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
/* global AbortController */
|
|
3
2
|
|
|
3
|
+
/* global AbortController */
|
|
4
|
+
import getStream from 'get-stream';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import semver from 'semver';
|
|
6
|
-
|
|
7
|
+
|
|
7
8
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
8
9
|
import { streamUtils } from '@verdaccio/core';
|
|
10
|
+
|
|
9
11
|
import { ProxyStorage } from '../src/up-storage';
|
|
10
12
|
|
|
11
13
|
// FUTURE: remove me when v15 is the min required version
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import nock from 'nock';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
3
4
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError, errorUtils } from '@verdaccio/core';
|
|
6
|
+
|
|
6
7
|
import { ProxyStorage } from '../src/up-storage';
|
|
7
8
|
|
|
8
9
|
const getConf = (name) => path.join(__dirname, '/conf', name);
|
|
@@ -112,7 +113,7 @@ describe('proxy', () => {
|
|
|
112
113
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
113
114
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
114
115
|
stream.on('error', (response) => {
|
|
115
|
-
expect(response).toEqual(
|
|
116
|
+
expect(response).toEqual(errorUtils.getNotFound(API_ERROR.NOT_FILE_UPLINK));
|
|
116
117
|
done();
|
|
117
118
|
});
|
|
118
119
|
});
|
|
@@ -132,7 +133,7 @@ describe('proxy', () => {
|
|
|
132
133
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
133
134
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
134
135
|
stream.on('error', (response) => {
|
|
135
|
-
expect(response).toEqual(
|
|
136
|
+
expect(response).toEqual(errorUtils.getInternalError(`bad uplink status code: 409`));
|
|
136
137
|
done();
|
|
137
138
|
});
|
|
138
139
|
});
|
|
@@ -148,7 +149,7 @@ describe('proxy', () => {
|
|
|
148
149
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
149
150
|
const stream = prox1.fetchTarball('https://registry.npmjs.org/jquery/-/jquery-0.0.1.tgz');
|
|
150
151
|
stream.on('error', (response) => {
|
|
151
|
-
expect(response).toEqual(
|
|
152
|
+
expect(response).toEqual(errorUtils.getInternalError(API_ERROR.CONTENT_MISMATCH));
|
|
152
153
|
done();
|
|
153
154
|
});
|
|
154
155
|
});
|
|
@@ -197,7 +198,7 @@ describe('proxy', () => {
|
|
|
197
198
|
nock(domain).get('/jquery').reply(404);
|
|
198
199
|
const prox1 = new ProxyStorage(defaultRequestOptions, conf);
|
|
199
200
|
prox1.getRemoteMetadata('jquery', { etag: 'rev_3333' }, (error) => {
|
|
200
|
-
expect(error).toEqual(
|
|
201
|
+
expect(error).toEqual(errorUtils.getNotFound(API_ERROR.NOT_PACKAGE_UPLINK));
|
|
201
202
|
done();
|
|
202
203
|
});
|
|
203
204
|
});
|