@verdaccio/middleware 6.0.0-6-next.34 → 6.0.0-6-next.35
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/.babelrc +12 -1
- package/CHANGELOG.md +13 -0
- package/build/index.d.ts +12 -1
- package/build/index.js +130 -4
- package/build/index.js.map +1 -1
- package/build/middlewares/allow.d.ts +1 -0
- package/build/middlewares/allow.js +39 -0
- package/build/middlewares/allow.js.map +1 -0
- package/build/middlewares/antiLoop.d.ts +7 -0
- package/build/middlewares/antiLoop.js +35 -0
- package/build/middlewares/antiLoop.js.map +1 -0
- package/build/middlewares/encode-pkg.d.ts +8 -0
- package/build/middlewares/encode-pkg.js +20 -0
- package/build/middlewares/encode-pkg.js.map +1 -0
- package/build/middlewares/error.d.ts +4 -0
- package/build/middlewares/error.js +75 -0
- package/build/middlewares/error.js.map +1 -0
- package/build/middlewares/final.d.ts +4 -0
- package/build/middlewares/final.js +52 -0
- package/build/middlewares/final.js.map +1 -0
- package/build/middlewares/json.d.ts +2 -0
- package/build/middlewares/json.js +15 -0
- package/build/middlewares/json.js.map +1 -0
- package/build/middlewares/log.d.ts +5 -0
- package/build/middlewares/log.js +101 -0
- package/build/middlewares/log.js.map +1 -0
- package/build/middlewares/match.d.ts +1 -0
- package/build/middlewares/match.js +16 -0
- package/build/middlewares/match.js.map +1 -0
- package/build/middlewares/media.d.ts +1 -0
- package/build/middlewares/media.js +17 -0
- package/build/middlewares/media.js.map +1 -0
- package/build/middlewares/security-headers.d.ts +2 -0
- package/build/middlewares/security-headers.js +21 -0
- package/build/middlewares/security-headers.js.map +1 -0
- package/build/middlewares/validation.d.ts +3 -0
- package/build/middlewares/validation.js +30 -0
- package/build/middlewares/validation.js.map +1 -0
- package/build/types.d.ts +13 -0
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/jest.config.js +10 -1
- package/package.json +11 -7
- package/src/index.ts +17 -1
- package/src/middlewares/allow.ts +40 -0
- package/src/middlewares/antiLoop.ts +30 -0
- package/src/middlewares/encode-pkg.ts +19 -0
- package/src/middlewares/error.ts +78 -0
- package/src/middlewares/final.ts +60 -0
- package/src/middlewares/json.ts +15 -0
- package/src/middlewares/log.ts +103 -0
- package/src/middlewares/match.ts +16 -0
- package/src/middlewares/media.ts +18 -0
- package/src/middlewares/security-headers.ts +21 -0
- package/src/middlewares/validation.ts +41 -0
- package/src/types.ts +11 -0
- package/test/allow.spec.ts +82 -0
- package/test/encode.spec.ts +21 -0
- package/test/final.spec.ts +60 -0
- package/test/helper.ts +14 -0
- package/test/json.spec.ts +32 -0
- package/test/log.spec.ts +28 -0
- package/test/loop.spec.ts +31 -0
- package/test/media.spec.ts +33 -0
- package/test/params.spec.ts +83 -0
- package/test/security.spec.ts +54 -0
- package/build/middleware-utils.d.ts +0 -6
- package/build/middleware-utils.js +0 -16
- package/build/middleware-utils.js.map +0 -1
- package/build/middleware.d.ts +0 -32
- package/build/middleware.js +0 -332
- package/build/middleware.js.map +0 -1
- package/src/middleware-utils.ts +0 -10
- package/src/middleware.ts +0 -413
- package/test/middleware-utils.spec.ts +0 -18
package/.babelrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.35
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a1986e09: feat: expose middleware utils
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [a1986e09]
|
|
12
|
+
- @verdaccio/utils@6.0.0-6-next.24
|
|
13
|
+
- @verdaccio/core@6.0.0-6-next.56
|
|
14
|
+
- @verdaccio/logger@6.0.0-6-next.24
|
|
15
|
+
|
|
3
16
|
## 6.0.0-6-next.34
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/build/index.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { match } from './middlewares/match';
|
|
2
|
+
export { setSecurityWebHeaders } from './middlewares/security-headers';
|
|
3
|
+
export { validateName, validatePackage } from './middlewares/validation';
|
|
4
|
+
export { media } from './middlewares/media';
|
|
5
|
+
export { encodeScopePackage } from './middlewares/encode-pkg';
|
|
6
|
+
export { expectJson } from './middlewares/json';
|
|
7
|
+
export { antiLoop } from './middlewares/antiLoop';
|
|
8
|
+
export { final } from './middlewares/final';
|
|
9
|
+
export { allow } from './middlewares/allow';
|
|
10
|
+
export { errorReportingMiddleware, handleError } from './middlewares/error';
|
|
11
|
+
export { log, LOG_STATUS_MESSAGE, LOG_VERDACCIO_BYTES, LOG_VERDACCIO_ERROR, } from './middlewares/log';
|
|
12
|
+
export * from './types';
|
package/build/index.js
CHANGED
|
@@ -3,14 +3,140 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
match: true,
|
|
8
|
+
setSecurityWebHeaders: true,
|
|
9
|
+
validateName: true,
|
|
10
|
+
validatePackage: true,
|
|
11
|
+
media: true,
|
|
12
|
+
encodeScopePackage: true,
|
|
13
|
+
expectJson: true,
|
|
14
|
+
antiLoop: true,
|
|
15
|
+
final: true,
|
|
16
|
+
allow: true,
|
|
17
|
+
errorReportingMiddleware: true,
|
|
18
|
+
handleError: true,
|
|
19
|
+
log: true,
|
|
20
|
+
LOG_STATUS_MESSAGE: true,
|
|
21
|
+
LOG_VERDACCIO_BYTES: true,
|
|
22
|
+
LOG_VERDACCIO_ERROR: true
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "LOG_STATUS_MESSAGE", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _log.LOG_STATUS_MESSAGE;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "LOG_VERDACCIO_BYTES", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _log.LOG_VERDACCIO_BYTES;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "LOG_VERDACCIO_ERROR", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _log.LOG_VERDACCIO_ERROR;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "allow", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _allow.allow;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "antiLoop", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _antiLoop.antiLoop;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "encodeScopePackage", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _encodePkg.encodeScopePackage;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "errorReportingMiddleware", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _error.errorReportingMiddleware;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "expectJson", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _json.expectJson;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "final", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _final.final;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "handleError", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _error.handleError;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "log", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _log.log;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "match", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _match.match;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "media", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _media.media;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(exports, "setSecurityWebHeaders", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () {
|
|
105
|
+
return _securityHeaders.setSecurityWebHeaders;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(exports, "validateName", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _validation.validateName;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(exports, "validatePackage", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () {
|
|
117
|
+
return _validation.validatePackage;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
var _match = require("./middlewares/match");
|
|
121
|
+
var _securityHeaders = require("./middlewares/security-headers");
|
|
122
|
+
var _validation = require("./middlewares/validation");
|
|
123
|
+
var _media = require("./middlewares/media");
|
|
124
|
+
var _encodePkg = require("./middlewares/encode-pkg");
|
|
125
|
+
var _json = require("./middlewares/json");
|
|
126
|
+
var _antiLoop = require("./middlewares/antiLoop");
|
|
127
|
+
var _final = require("./middlewares/final");
|
|
128
|
+
var _allow = require("./middlewares/allow");
|
|
129
|
+
var _error = require("./middlewares/error");
|
|
130
|
+
var _log = require("./middlewares/log");
|
|
131
|
+
var _types = require("./types");
|
|
132
|
+
Object.keys(_types).forEach(function (key) {
|
|
8
133
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (
|
|
134
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
135
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
10
136
|
Object.defineProperty(exports, key, {
|
|
11
137
|
enumerable: true,
|
|
12
138
|
get: function () {
|
|
13
|
-
return
|
|
139
|
+
return _types[key];
|
|
14
140
|
}
|
|
15
141
|
});
|
|
16
142
|
});
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { match } from './middlewares/match';\nexport { setSecurityWebHeaders } from './middlewares/security-headers';\nexport { validateName, validatePackage } from './middlewares/validation';\nexport { media } from './middlewares/media';\nexport { encodeScopePackage } from './middlewares/encode-pkg';\nexport { expectJson } from './middlewares/json';\nexport { antiLoop } from './middlewares/antiLoop';\nexport { final } from './middlewares/final';\nexport { allow } from './middlewares/allow';\nexport { errorReportingMiddleware, handleError } from './middlewares/error';\nexport {\n log,\n LOG_STATUS_MESSAGE,\n LOG_VERDACCIO_BYTES,\n LOG_VERDACCIO_ERROR,\n} from './middlewares/log';\nexport * from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function allow<T>(auth: T): Function;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allow = allow;
|
|
7
|
+
var _core = require("@verdaccio/core");
|
|
8
|
+
var _logger = require("@verdaccio/logger");
|
|
9
|
+
var _utils = require("@verdaccio/utils");
|
|
10
|
+
function allow(auth) {
|
|
11
|
+
return function (action) {
|
|
12
|
+
return function (req, res, next) {
|
|
13
|
+
req.pause();
|
|
14
|
+
const packageName = req.params.scope ? `@${req.params.scope}/${req.params.package}` : req.params.package;
|
|
15
|
+
const packageVersion = req.params.filename ? (0, _utils.getVersionFromTarball)(req.params.filename) : undefined;
|
|
16
|
+
const remote = req.remote_user;
|
|
17
|
+
_logger.logger.trace({
|
|
18
|
+
action,
|
|
19
|
+
user: remote === null || remote === void 0 ? void 0 : remote.name
|
|
20
|
+
}, `[middleware/allow][@{action}] allow for @{user}`);
|
|
21
|
+
auth['allow_' + action]({
|
|
22
|
+
packageName,
|
|
23
|
+
packageVersion
|
|
24
|
+
}, remote, function (error, allowed) {
|
|
25
|
+
req.resume();
|
|
26
|
+
if (error) {
|
|
27
|
+
next(error);
|
|
28
|
+
} else if (allowed) {
|
|
29
|
+
next();
|
|
30
|
+
} else {
|
|
31
|
+
// last plugin (that's our built-in one) returns either
|
|
32
|
+
// cb(err) or cb(null, true), so this should never happen
|
|
33
|
+
throw _core.errorUtils.getInternalError(_core.API_ERROR.PLUGIN_ERROR);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=allow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow.js","names":["allow","auth","action","req","res","next","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","undefined","remote","remote_user","logger","trace","user","name","error","allowed","resume","errorUtils","getInternalError","API_ERROR","PLUGIN_ERROR"],"sources":["../../src/middlewares/allow.ts"],"sourcesContent":["import { API_ERROR, errorUtils } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { getVersionFromTarball } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function allow<T>(auth: T): Function {\n return function (action: string): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.pause();\n const packageName = req.params.scope\n ? `@${req.params.scope}/${req.params.package}`\n : req.params.package;\n const packageVersion = req.params.filename\n ? getVersionFromTarball(req.params.filename)\n : undefined;\n const remote = req.remote_user;\n logger.trace(\n { action, user: remote?.name },\n `[middleware/allow][@{action}] allow for @{user}`\n );\n auth['allow_' + action](\n { packageName, packageVersion },\n remote,\n function (error, allowed): void {\n req.resume();\n if (error) {\n next(error);\n } else if (allowed) {\n next();\n } else {\n // last plugin (that's our built-in one) returns either\n // cb(err) or cb(null, true), so this should never happen\n throw errorUtils.getInternalError(API_ERROR.PLUGIN_ERROR);\n }\n }\n );\n };\n };\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAIO,SAASA,KAAK,CAAIC,IAAO,EAAY;EAC1C,OAAO,UAAUC,MAAc,EAAY;IACzC,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;MACxFF,GAAG,CAACG,KAAK,EAAE;MACX,MAAMC,WAAW,GAAGJ,GAAG,CAACK,MAAM,CAACC,KAAK,GAC/B,IAAGN,GAAG,CAACK,MAAM,CAACC,KAAM,IAAGN,GAAG,CAACK,MAAM,CAACE,OAAQ,EAAC,GAC5CP,GAAG,CAACK,MAAM,CAACE,OAAO;MACtB,MAAMC,cAAc,GAAGR,GAAG,CAACK,MAAM,CAACI,QAAQ,GACtC,IAAAC,4BAAqB,EAACV,GAAG,CAACK,MAAM,CAACI,QAAQ,CAAC,GAC1CE,SAAS;MACb,MAAMC,MAAM,GAAGZ,GAAG,CAACa,WAAW;MAC9BC,cAAM,CAACC,KAAK,CACV;QAAEhB,MAAM;QAAEiB,IAAI,EAAEJ,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEK;MAAK,CAAC,EAC7B,iDAAgD,CAClD;MACDnB,IAAI,CAAC,QAAQ,GAAGC,MAAM,CAAC,CACrB;QAAEK,WAAW;QAAEI;MAAe,CAAC,EAC/BI,MAAM,EACN,UAAUM,KAAK,EAAEC,OAAO,EAAQ;QAC9BnB,GAAG,CAACoB,MAAM,EAAE;QACZ,IAAIF,KAAK,EAAE;UACThB,IAAI,CAACgB,KAAK,CAAC;QACb,CAAC,MAAM,IAAIC,OAAO,EAAE;UAClBjB,IAAI,EAAE;QACR,CAAC,MAAM;UACL;UACA;UACA,MAAMmB,gBAAU,CAACC,gBAAgB,CAACC,eAAS,CAACC,YAAY,CAAC;QAC3D;MACF,CAAC,CACF;IACH,CAAC;EACH,CAAC;AACH"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.antiLoop = antiLoop;
|
|
7
|
+
var _core = require("@verdaccio/core");
|
|
8
|
+
/**
|
|
9
|
+
* A middleware that avoid a registry points itself as proxy and avoid create infinite loops.
|
|
10
|
+
* @param config
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
function antiLoop(config) {
|
|
14
|
+
return function (req, res, next) {
|
|
15
|
+
var _req$headers;
|
|
16
|
+
if ((req === null || req === void 0 ? void 0 : (_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers.via) != null) {
|
|
17
|
+
var _req$get;
|
|
18
|
+
const arr = (_req$get = req.get('via')) === null || _req$get === void 0 ? void 0 : _req$get.split(',');
|
|
19
|
+
if (Array.isArray(arr)) {
|
|
20
|
+
for (let i = 0; i < arr.length; i++) {
|
|
21
|
+
// the "via" header must contains an specific headers, this has to be on sync
|
|
22
|
+
// with the proxy request
|
|
23
|
+
// match eg: Server 1 or Server 2
|
|
24
|
+
// TODO: improve this RegEX
|
|
25
|
+
const m = arr[i].trim().match(/\s*(\S+)\s+(\S+)/);
|
|
26
|
+
if (m && m[2] === config.server_id) {
|
|
27
|
+
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.LOOP_DETECTED, 'loop detected'));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
next();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=antiLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"antiLoop.js","names":["antiLoop","config","req","res","next","headers","via","arr","get","split","Array","isArray","i","length","m","trim","match","server_id","errorUtils","getCode","HTTP_STATUS","LOOP_DETECTED"],"sources":["../../src/middlewares/antiLoop.ts"],"sourcesContent":["import { HTTP_STATUS, errorUtils } from '@verdaccio/core';\nimport { Config } from '@verdaccio/types';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n/**\n * A middleware that avoid a registry points itself as proxy and avoid create infinite loops.\n * @param config\n * @returns\n */\nexport function antiLoop(config: Config): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req?.headers?.via != null) {\n const arr = req.get('via')?.split(',');\n if (Array.isArray(arr)) {\n for (let i = 0; i < arr.length; i++) {\n // the \"via\" header must contains an specific headers, this has to be on sync\n // with the proxy request\n // match eg: Server 1 or Server 2\n // TODO: improve this RegEX\n const m = arr[i].trim().match(/\\s*(\\S+)\\s+(\\S+)/);\n if (m && m[2] === config.server_id) {\n return next(errorUtils.getCode(HTTP_STATUS.LOOP_DETECTED, 'loop detected'));\n }\n }\n }\n }\n next();\n };\n}\n"],"mappings":";;;;;;AAAA;AAKA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAQ,CAACC,MAAc,EAAY;EACjD,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IAAA;IACxF,IAAI,CAAAF,GAAG,aAAHA,GAAG,uCAAHA,GAAG,CAAEG,OAAO,iDAAZ,aAAcC,GAAG,KAAI,IAAI,EAAE;MAAA;MAC7B,MAAMC,GAAG,eAAGL,GAAG,CAACM,GAAG,CAAC,KAAK,CAAC,6CAAd,SAAgBC,KAAK,CAAC,GAAG,CAAC;MACtC,IAAIC,KAAK,CAACC,OAAO,CAACJ,GAAG,CAAC,EAAE;QACtB,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,GAAG,CAACM,MAAM,EAAED,CAAC,EAAE,EAAE;UACnC;UACA;UACA;UACA;UACA,MAAME,CAAC,GAAGP,GAAG,CAACK,CAAC,CAAC,CAACG,IAAI,EAAE,CAACC,KAAK,CAAC,kBAAkB,CAAC;UACjD,IAAIF,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAKb,MAAM,CAACgB,SAAS,EAAE;YAClC,OAAOb,IAAI,CAACc,gBAAU,CAACC,OAAO,CAACC,iBAAW,CAACC,aAAa,EAAE,eAAe,CAAC,CAAC;UAC7E;QACF;MACF;IACF;IACAjB,IAAI,EAAE;EACR,CAAC;AACH"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Encode / in a scoped package name to be matched as a single parameter in routes
|
|
4
|
+
* @param req
|
|
5
|
+
* @param res
|
|
6
|
+
* @param next
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeScopePackage(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.encodeScopePackage = encodeScopePackage;
|
|
7
|
+
/**
|
|
8
|
+
* Encode / in a scoped package name to be matched as a single parameter in routes
|
|
9
|
+
* @param req
|
|
10
|
+
* @param res
|
|
11
|
+
* @param next
|
|
12
|
+
*/
|
|
13
|
+
function encodeScopePackage(req, res, next) {
|
|
14
|
+
if (req.url.indexOf('@') !== -1) {
|
|
15
|
+
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
|
|
16
|
+
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F');
|
|
17
|
+
}
|
|
18
|
+
next();
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=encode-pkg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-pkg.js","names":["encodeScopePackage","req","res","next","url","indexOf","replace"],"sources":["../../src/middlewares/encode-pkg.ts"],"sourcesContent":["import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n/**\n * Encode / in a scoped package name to be matched as a single parameter in routes\n * @param req\n * @param res\n * @param next\n */\nexport function encodeScopePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (req.url.indexOf('@') !== -1) {\n // e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3\n req.url = req.url.replace(/^(\\/@[^\\/%]+)\\/(?!$)/, '$1%2F');\n }\n next();\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAkB,CAChCC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN,IAAIF,GAAG,CAACG,GAAG,CAACC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;IAC/B;IACAJ,GAAG,CAACG,GAAG,GAAGH,GAAG,CAACG,GAAG,CAACE,OAAO,CAAC,sBAAsB,EAAE,OAAO,CAAC;EAC5D;EACAH,IAAI,EAAE;AACR"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { HttpError } from 'http-errors';
|
|
2
|
+
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
3
|
+
export declare function handleError(err: HttpError, req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): any;
|
|
4
|
+
export declare function errorReportingMiddleware(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.errorReportingMiddleware = errorReportingMiddleware;
|
|
7
|
+
exports.handleError = handleError;
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
+
var _core = require("@verdaccio/core");
|
|
11
|
+
var _logger = require("@verdaccio/logger");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
const debug = (0, _debug.default)('verdaccio:middleware:error');
|
|
14
|
+
function handleError(err, req, res, next) {
|
|
15
|
+
debug('error handler init');
|
|
16
|
+
if (_lodash.default.isError(err)) {
|
|
17
|
+
debug('is native error');
|
|
18
|
+
if (err.code === 'ECONNABORT' && res.statusCode === _core.HTTP_STATUS.NOT_MODIFIED) {
|
|
19
|
+
return next();
|
|
20
|
+
}
|
|
21
|
+
if (_lodash.default.isFunction(res.locals.report_error) === false) {
|
|
22
|
+
debug('is locals error report ref');
|
|
23
|
+
// in case of very early error this middleware may not be loaded before error is generated
|
|
24
|
+
// fixing that
|
|
25
|
+
errorReportingMiddleware(req, res, _lodash.default.noop);
|
|
26
|
+
}
|
|
27
|
+
debug('set locals error report ref');
|
|
28
|
+
res.locals.report_error(err);
|
|
29
|
+
} else {
|
|
30
|
+
// Fall to Middleware.final
|
|
31
|
+
debug('no error to report, jump next layer');
|
|
32
|
+
return next(err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Middleware
|
|
37
|
+
function errorReportingMiddleware(req, res, next) {
|
|
38
|
+
debug('error report middleware');
|
|
39
|
+
res.locals.report_error = res.locals.report_error || function (err) {
|
|
40
|
+
if (err.status && err.status >= _core.HTTP_STATUS.BAD_REQUEST && err.status < 600) {
|
|
41
|
+
debug('is error > 409 %o', err === null || err === void 0 ? void 0 : err.status);
|
|
42
|
+
if (_lodash.default.isNil(res.headersSent) === false) {
|
|
43
|
+
debug('send status %o', err === null || err === void 0 ? void 0 : err.status);
|
|
44
|
+
res.status(err.status);
|
|
45
|
+
debug('next layer %o', err === null || err === void 0 ? void 0 : err.message);
|
|
46
|
+
next({
|
|
47
|
+
error: err.message || _core.API_ERROR.UNKNOWN_ERROR
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
debug('is error < 409 %o', err === null || err === void 0 ? void 0 : err.status);
|
|
52
|
+
_logger.logger.error({
|
|
53
|
+
err: err
|
|
54
|
+
}, 'unexpected error: @{!err.message}\n@{err.stack}');
|
|
55
|
+
if (!res.status || !res.send) {
|
|
56
|
+
// TODO: decide which debug keep
|
|
57
|
+
_logger.logger.error('this is an error in express.js, please report this');
|
|
58
|
+
debug('this is an error in express.js, please report this, destroy response %o', err);
|
|
59
|
+
res.destroy();
|
|
60
|
+
} else if (!res.headersSent) {
|
|
61
|
+
debug('report internal error %o', err);
|
|
62
|
+
res.status(_core.HTTP_STATUS.INTERNAL_ERROR);
|
|
63
|
+
next({
|
|
64
|
+
error: _core.API_ERROR.INTERNAL_SERVER_ERROR
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
// socket should be already closed
|
|
68
|
+
debug('this should not happen, otherwise report %o', err);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
debug('error report middleware next()');
|
|
73
|
+
next();
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","names":["debug","buildDebug","handleError","err","req","res","next","_","isError","code","statusCode","HTTP_STATUS","NOT_MODIFIED","isFunction","locals","report_error","errorReportingMiddleware","noop","status","BAD_REQUEST","isNil","headersSent","message","error","API_ERROR","UNKNOWN_ERROR","logger","send","destroy","INTERNAL_ERROR","INTERNAL_SERVER_ERROR"],"sources":["../../src/middlewares/error.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { HttpError } from 'http-errors';\nimport _ from 'lodash';\n\nimport { API_ERROR, HTTP_STATUS, VerdaccioError } from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:error');\n\nexport function handleError(\n err: HttpError,\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n) {\n debug('error handler init');\n if (_.isError(err)) {\n debug('is native error');\n if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n return next();\n }\n if (_.isFunction(res.locals.report_error) === false) {\n debug('is locals error report ref');\n // in case of very early error this middleware may not be loaded before error is generated\n // fixing that\n errorReportingMiddleware(req, res, _.noop);\n }\n debug('set locals error report ref');\n res.locals.report_error(err);\n } else {\n // Fall to Middleware.final\n debug('no error to report, jump next layer');\n return next(err);\n }\n}\n\n// Middleware\nexport function errorReportingMiddleware(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n debug('error report middleware');\n res.locals.report_error =\n res.locals.report_error ||\n function (err: VerdaccioError): void {\n if (err.status && err.status >= HTTP_STATUS.BAD_REQUEST && err.status < 600) {\n debug('is error > 409 %o', err?.status);\n if (_.isNil(res.headersSent) === false) {\n debug('send status %o', err?.status);\n res.status(err.status);\n debug('next layer %o', err?.message);\n next({ error: err.message || API_ERROR.UNKNOWN_ERROR });\n }\n } else {\n debug('is error < 409 %o', err?.status);\n logger.error({ err: err }, 'unexpected error: @{!err.message}\\n@{err.stack}');\n if (!res.status || !res.send) {\n // TODO: decide which debug keep\n logger.error('this is an error in express.js, please report this');\n debug('this is an error in express.js, please report this, destroy response %o', err);\n res.destroy();\n } else if (!res.headersSent) {\n debug('report internal error %o', err);\n res.status(HTTP_STATUS.INTERNAL_ERROR);\n next({ error: API_ERROR.INTERNAL_SERVER_ERROR });\n } else {\n // socket should be already closed\n debug('this should not happen, otherwise report %o', err);\n }\n }\n };\n\n debug('error report middleware next()');\n next();\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Manifest } from '@verdaccio/types';
|
|
2
|
+
import { $NextFunctionVer, $RequestExtend, $ResponseExtend, MiddlewareError } from '../types';
|
|
3
|
+
export type FinalBody = Manifest | MiddlewareError | string;
|
|
4
|
+
export declare function final(body: FinalBody, req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.final = final;
|
|
7
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
|
+
var _core = require("@verdaccio/core");
|
|
9
|
+
var _utils = require("@verdaccio/utils");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function final(body, req, res,
|
|
12
|
+
// if we remove `next` breaks test
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
next) {
|
|
15
|
+
if (res.statusCode === _core.HTTP_STATUS.UNAUTHORIZED && !res.getHeader(_core.HEADERS.WWW_AUTH)) {
|
|
16
|
+
res.header(_core.HEADERS.WWW_AUTH, `${_core.TOKEN_BASIC}, ${_core.TOKEN_BEARER}`);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
if (_lodash.default.isString(body) || _lodash.default.isObject(body)) {
|
|
20
|
+
if (!res.get(_core.HEADERS.CONTENT_TYPE)) {
|
|
21
|
+
res.header(_core.HEADERS.CONTENT_TYPE, _core.HEADERS.JSON);
|
|
22
|
+
}
|
|
23
|
+
if (typeof body === 'object' && _lodash.default.isNil(body) === false) {
|
|
24
|
+
if (typeof body.error === 'string') {
|
|
25
|
+
res.locals._verdaccio_error = body.error;
|
|
26
|
+
}
|
|
27
|
+
body = JSON.stringify(body, undefined, ' ') + '\n';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// don't send etags with errors
|
|
31
|
+
if (!res.statusCode || res.statusCode >= _core.HTTP_STATUS.OK && res.statusCode < _core.HTTP_STATUS.MULTIPLE_CHOICES) {
|
|
32
|
+
res.header(_core.HEADERS.ETAG, '"' + (0, _utils.stringToMD5)(body) + '"');
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
// send(null), send(204), etc.
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
// if verdaccio sends headers first, and then calls res.send()
|
|
39
|
+
// as an error handler, we can't report error properly,
|
|
40
|
+
// and should just close socket
|
|
41
|
+
if (err.message.match(/set headers after they are sent/)) {
|
|
42
|
+
if (_lodash.default.isNil(res.socket) === false) {
|
|
43
|
+
var _res$socket;
|
|
44
|
+
(_res$socket = res.socket) === null || _res$socket === void 0 ? void 0 : _res$socket.destroy();
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
res.send(body);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=final.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"final.js","names":["final","body","req","res","next","statusCode","HTTP_STATUS","UNAUTHORIZED","getHeader","HEADERS","WWW_AUTH","header","TOKEN_BASIC","TOKEN_BEARER","_","isString","isObject","get","CONTENT_TYPE","JSON","isNil","error","locals","_verdaccio_error","stringify","undefined","OK","MULTIPLE_CHOICES","ETAG","stringToMD5","err","message","match","socket","destroy","send"],"sources":["../../src/middlewares/final.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport { HEADERS, HTTP_STATUS, TOKEN_BASIC, TOKEN_BEARER } from '@verdaccio/core';\nimport { Manifest } from '@verdaccio/types';\nimport { stringToMD5 } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend, MiddlewareError } from '../types';\n\nexport type FinalBody = Manifest | MiddlewareError | string;\n\nexport function final(\n body: FinalBody,\n req: $RequestExtend,\n res: $ResponseExtend,\n // if we remove `next` breaks test\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: $NextFunctionVer\n): void {\n if (res.statusCode === HTTP_STATUS.UNAUTHORIZED && !res.getHeader(HEADERS.WWW_AUTH)) {\n res.header(HEADERS.WWW_AUTH, `${TOKEN_BASIC}, ${TOKEN_BEARER}`);\n }\n\n try {\n if (_.isString(body) || _.isObject(body)) {\n if (!res.get(HEADERS.CONTENT_TYPE)) {\n res.header(HEADERS.CONTENT_TYPE, HEADERS.JSON);\n }\n\n if (typeof body === 'object' && _.isNil(body) === false) {\n if (typeof (body as MiddlewareError).error === 'string') {\n res.locals._verdaccio_error = (body as MiddlewareError).error;\n }\n body = JSON.stringify(body, undefined, ' ') + '\\n';\n }\n\n // don't send etags with errors\n if (\n !res.statusCode ||\n (res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)\n ) {\n res.header(HEADERS.ETAG, '\"' + stringToMD5(body as string) + '\"');\n }\n } else {\n // send(null), send(204), etc.\n }\n } catch (err: any) {\n // if verdaccio sends headers first, and then calls res.send()\n // as an error handler, we can't report error properly,\n // and should just close socket\n if (err.message.match(/set headers after they are sent/)) {\n if (_.isNil(res.socket) === false) {\n res.socket?.destroy();\n }\n return;\n }\n throw err;\n }\n\n res.send(body);\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAEA;AAA+C;AAMxC,SAASA,KAAK,CACnBC,IAAe,EACfC,GAAmB,EACnBC,GAAoB;AACpB;AACA;AACAC,IAAsB,EAChB;EACN,IAAID,GAAG,CAACE,UAAU,KAAKC,iBAAW,CAACC,YAAY,IAAI,CAACJ,GAAG,CAACK,SAAS,CAACC,aAAO,CAACC,QAAQ,CAAC,EAAE;IACnFP,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACC,QAAQ,EAAG,GAAEE,iBAAY,KAAIC,kBAAa,EAAC,CAAC;EACjE;EAEA,IAAI;IACF,IAAIC,eAAC,CAACC,QAAQ,CAACd,IAAI,CAAC,IAAIa,eAAC,CAACE,QAAQ,CAACf,IAAI,CAAC,EAAE;MACxC,IAAI,CAACE,GAAG,CAACc,GAAG,CAACR,aAAO,CAACS,YAAY,CAAC,EAAE;QAClCf,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACS,YAAY,EAAET,aAAO,CAACU,IAAI,CAAC;MAChD;MAEA,IAAI,OAAOlB,IAAI,KAAK,QAAQ,IAAIa,eAAC,CAACM,KAAK,CAACnB,IAAI,CAAC,KAAK,KAAK,EAAE;QACvD,IAAI,OAAQA,IAAI,CAAqBoB,KAAK,KAAK,QAAQ,EAAE;UACvDlB,GAAG,CAACmB,MAAM,CAACC,gBAAgB,GAAItB,IAAI,CAAqBoB,KAAK;QAC/D;QACApB,IAAI,GAAGkB,IAAI,CAACK,SAAS,CAACvB,IAAI,EAAEwB,SAAS,EAAE,IAAI,CAAC,GAAG,IAAI;MACrD;;MAEA;MACA,IACE,CAACtB,GAAG,CAACE,UAAU,IACdF,GAAG,CAACE,UAAU,IAAIC,iBAAW,CAACoB,EAAE,IAAIvB,GAAG,CAACE,UAAU,GAAGC,iBAAW,CAACqB,gBAAiB,EACnF;QACAxB,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACmB,IAAI,EAAE,GAAG,GAAG,IAAAC,kBAAW,EAAC5B,IAAI,CAAW,GAAG,GAAG,CAAC;MACnE;IACF,CAAC,MAAM;MACL;IAAA;EAEJ,CAAC,CAAC,OAAO6B,GAAQ,EAAE;IACjB;IACA;IACA;IACA,IAAIA,GAAG,CAACC,OAAO,CAACC,KAAK,CAAC,iCAAiC,CAAC,EAAE;MACxD,IAAIlB,eAAC,CAACM,KAAK,CAACjB,GAAG,CAAC8B,MAAM,CAAC,KAAK,KAAK,EAAE;QAAA;QACjC,eAAA9B,GAAG,CAAC8B,MAAM,gDAAV,YAAYC,OAAO,EAAE;MACvB;MACA;IACF;IACA,MAAMJ,GAAG;EACX;EAEA3B,GAAG,CAACgC,IAAI,CAAClC,IAAI,CAAC;AAChB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.expectJson = expectJson;
|
|
7
|
+
var _core = require("@verdaccio/core");
|
|
8
|
+
var _utils = require("@verdaccio/utils");
|
|
9
|
+
function expectJson(req, res, next) {
|
|
10
|
+
if (!(0, _utils.isObject)(req.body)) {
|
|
11
|
+
return next(_core.errorUtils.getBadRequest("can't parse incoming json"));
|
|
12
|
+
}
|
|
13
|
+
next();
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","names":["expectJson","req","res","next","isObject","body","errorUtils","getBadRequest"],"sources":["../../src/middlewares/json.ts"],"sourcesContent":["import { errorUtils } from '@verdaccio/core';\nimport { isObject } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function expectJson(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (!isObject(req.body)) {\n return next(errorUtils.getBadRequest(\"can't parse incoming json\"));\n }\n next();\n}\n"],"mappings":";;;;;;AAAA;AACA;AAIO,SAASA,UAAU,CACxBC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN,IAAI,CAAC,IAAAC,eAAQ,EAACH,GAAG,CAACI,IAAI,CAAC,EAAE;IACvB,OAAOF,IAAI,CAACG,gBAAU,CAACC,aAAa,CAAC,2BAA2B,CAAC,CAAC;EACpE;EACAJ,IAAI,EAAE;AACR"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
2
|
+
export declare const LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
3
|
+
export declare const LOG_VERDACCIO_ERROR: string;
|
|
4
|
+
export declare const LOG_VERDACCIO_BYTES: string;
|
|
5
|
+
export declare function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LOG_VERDACCIO_ERROR = exports.LOG_VERDACCIO_BYTES = exports.LOG_STATUS_MESSAGE = void 0;
|
|
7
|
+
exports.log = log;
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
var _logger = require("@verdaccio/logger");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
// FIXME: deprecated, moved to @verdaccio/dev-commons
|
|
12
|
+
const LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
13
|
+
exports.LOG_STATUS_MESSAGE = LOG_STATUS_MESSAGE;
|
|
14
|
+
const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
|
|
15
|
+
exports.LOG_VERDACCIO_ERROR = LOG_VERDACCIO_ERROR;
|
|
16
|
+
const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
|
|
17
|
+
exports.LOG_VERDACCIO_BYTES = LOG_VERDACCIO_BYTES;
|
|
18
|
+
function log(req, res, next) {
|
|
19
|
+
// logger
|
|
20
|
+
req.log = _logger.logger.child({
|
|
21
|
+
sub: 'in'
|
|
22
|
+
});
|
|
23
|
+
const _auth = req.headers.authorization;
|
|
24
|
+
if (_lodash.default.isNil(_auth) === false) {
|
|
25
|
+
req.headers.authorization = '<Classified>';
|
|
26
|
+
}
|
|
27
|
+
const _cookie = req.get('cookie');
|
|
28
|
+
if (_lodash.default.isNil(_cookie) === false) {
|
|
29
|
+
req.headers.cookie = '<Classified>';
|
|
30
|
+
}
|
|
31
|
+
req.url = req.originalUrl;
|
|
32
|
+
req.log.info({
|
|
33
|
+
req: req,
|
|
34
|
+
ip: req.ip
|
|
35
|
+
}, "@{ip} requested '@{req.method} @{req.url}'");
|
|
36
|
+
req.originalUrl = req.url;
|
|
37
|
+
if (_lodash.default.isNil(_auth) === false) {
|
|
38
|
+
req.headers.authorization = _auth;
|
|
39
|
+
}
|
|
40
|
+
if (_lodash.default.isNil(_cookie) === false) {
|
|
41
|
+
req.headers.cookie = _cookie;
|
|
42
|
+
}
|
|
43
|
+
let bytesin = 0;
|
|
44
|
+
req.on('data', function (chunk) {
|
|
45
|
+
bytesin += chunk.length;
|
|
46
|
+
});
|
|
47
|
+
let bytesout = 0;
|
|
48
|
+
const _write = res.write;
|
|
49
|
+
// FIXME: res.write should return boolean
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
res.write = function (buf) {
|
|
52
|
+
bytesout += buf.length;
|
|
53
|
+
/* eslint prefer-rest-params: "off" */
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
_write.apply(res, arguments);
|
|
56
|
+
};
|
|
57
|
+
const log = function () {
|
|
58
|
+
var _req$remote_user;
|
|
59
|
+
const forwardedFor = req.get('x-forwarded-for');
|
|
60
|
+
const remoteAddress = req.connection.remoteAddress;
|
|
61
|
+
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
62
|
+
let message;
|
|
63
|
+
if (res.locals._verdaccio_error) {
|
|
64
|
+
message = LOG_VERDACCIO_ERROR;
|
|
65
|
+
} else {
|
|
66
|
+
message = LOG_VERDACCIO_BYTES;
|
|
67
|
+
}
|
|
68
|
+
req.url = req.originalUrl;
|
|
69
|
+
req.log.http({
|
|
70
|
+
request: {
|
|
71
|
+
method: req.method,
|
|
72
|
+
url: req.url
|
|
73
|
+
},
|
|
74
|
+
user: ((_req$remote_user = req.remote_user) === null || _req$remote_user === void 0 ? void 0 : _req$remote_user.name) || null,
|
|
75
|
+
remoteIP,
|
|
76
|
+
status: res.statusCode,
|
|
77
|
+
error: res.locals._verdaccio_error,
|
|
78
|
+
bytes: {
|
|
79
|
+
in: bytesin,
|
|
80
|
+
out: bytesout
|
|
81
|
+
}
|
|
82
|
+
}, message);
|
|
83
|
+
req.originalUrl = req.url;
|
|
84
|
+
};
|
|
85
|
+
req.on('close', function () {
|
|
86
|
+
log();
|
|
87
|
+
});
|
|
88
|
+
const _end = res.end;
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
res.end = function (buf) {
|
|
91
|
+
if (buf) {
|
|
92
|
+
bytesout += buf.length;
|
|
93
|
+
}
|
|
94
|
+
/* eslint prefer-rest-params: "off" */
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
_end.apply(res, arguments);
|
|
97
|
+
log();
|
|
98
|
+
};
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=log.js.map
|