@verdaccio/middleware 7.0.0-next.4 → 7.0.0-next.6
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 +24 -0
- package/LICENSE +1 -1
- package/build/middlewares/error.js +3 -3
- package/build/middlewares/error.js.map +1 -1
- package/build/middlewares/final.js +11 -1
- package/build/middlewares/final.js.map +1 -1
- package/build/middlewares/web/utils/manifest.js +1 -1
- package/build/middlewares/web/utils/manifest.js.map +1 -1
- package/package.json +6 -6
- package/src/middlewares/error.ts +3 -3
- package/src/middlewares/final.ts +12 -1
- package/src/middlewares/web/utils/manifest.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4d96324]
|
|
8
|
+
- @verdaccio/config@7.0.0-next.6
|
|
9
|
+
- @verdaccio/core@7.0.0-next.6
|
|
10
|
+
- @verdaccio/url@12.0.0-next.6
|
|
11
|
+
- @verdaccio/utils@7.0.0-next.6
|
|
12
|
+
|
|
13
|
+
## 7.0.0-next.5
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- f047cc8: refactor: auth with legacy sign support
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [f047cc8]
|
|
22
|
+
- @verdaccio/core@7.0.0-next.5
|
|
23
|
+
- @verdaccio/url@12.0.0-next.5
|
|
24
|
+
- @verdaccio/config@7.0.0-next.5
|
|
25
|
+
- @verdaccio/utils@7.0.0-next.5
|
|
26
|
+
|
|
3
27
|
## 7.0.0-next.4
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/LICENSE
CHANGED
|
@@ -34,7 +34,7 @@ const handleError = logger => function handleError(err, req, res, next) {
|
|
|
34
34
|
// Middleware
|
|
35
35
|
exports.handleError = handleError;
|
|
36
36
|
const errorReportingMiddleware = logger => function errorReportingMiddleware(req, res, next) {
|
|
37
|
-
debug('error report middleware');
|
|
37
|
+
debug('error report middleware start');
|
|
38
38
|
res.locals.report_error = res.locals.report_error || function (err) {
|
|
39
39
|
if (err.status && err.status >= _core.HTTP_STATUS.BAD_REQUEST && err.status < 600) {
|
|
40
40
|
debug('is error > 409 %o', err === null || err === void 0 ? void 0 : err.status);
|
|
@@ -57,7 +57,7 @@ const errorReportingMiddleware = logger => function errorReportingMiddleware(req
|
|
|
57
57
|
debug('this is an error in express.js, please report this, destroy response %o', err);
|
|
58
58
|
res.destroy();
|
|
59
59
|
} else if (!res.headersSent) {
|
|
60
|
-
debug('
|
|
60
|
+
debug('send internal error %o', err);
|
|
61
61
|
res.status(_core.HTTP_STATUS.INTERNAL_ERROR);
|
|
62
62
|
next({
|
|
63
63
|
error: _core.API_ERROR.INTERNAL_SERVER_ERROR
|
|
@@ -68,7 +68,7 @@ const errorReportingMiddleware = logger => function errorReportingMiddleware(req
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
debug('error report middleware next()');
|
|
71
|
+
debug('error report middleware end (skip next layer) next()');
|
|
72
72
|
next();
|
|
73
73
|
};
|
|
74
74
|
exports.errorReportingMiddleware = errorReportingMiddleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","obj","__esModule","default","debug","buildDebug","handleError","logger","err","req","res","next","_","isError","code","statusCode","HTTP_STATUS","NOT_MODIFIED","isFunction","locals","report_error","errorReportingMiddleware","noop","exports","status","BAD_REQUEST","isNil","headersSent","message","error","API_ERROR","UNKNOWN_ERROR","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';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:error');\n\nexport const handleError = (logger) =>\n 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(logger)(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 const errorReportingMiddleware = (logger) =>\n 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('
|
|
1
|
+
{"version":3,"file":"error.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","obj","__esModule","default","debug","buildDebug","handleError","logger","err","req","res","next","_","isError","code","statusCode","HTTP_STATUS","NOT_MODIFIED","isFunction","locals","report_error","errorReportingMiddleware","noop","exports","status","BAD_REQUEST","isNil","headersSent","message","error","API_ERROR","UNKNOWN_ERROR","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';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:error');\n\nexport const handleError = (logger) =>\n 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(logger)(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 const errorReportingMiddleware = (logger) =>\n function errorReportingMiddleware(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n ): void {\n debug('error report middleware start');\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('send 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 end (skip next layer) next()');\n next();\n };\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAAyE,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIzE,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,4BAA4B,CAAC;AAE/C,MAAMC,WAAW,GAAIC,MAAM,IAChC,SAASD,WAAWA,CAClBE,GAAc,EACdC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EACtB;EACAP,KAAK,CAAC,oBAAoB,CAAC;EAC3B,IAAIQ,eAAC,CAACC,OAAO,CAACL,GAAG,CAAC,EAAE;IAClBJ,KAAK,CAAC,iBAAiB,CAAC;IACxB,IAAII,GAAG,CAACM,IAAI,KAAK,YAAY,IAAIJ,GAAG,CAACK,UAAU,KAAKC,iBAAW,CAACC,YAAY,EAAE;MAC5E,OAAON,IAAI,CAAC,CAAC;IACf;IACA,IAAIC,eAAC,CAACM,UAAU,CAACR,GAAG,CAACS,MAAM,CAACC,YAAY,CAAC,KAAK,KAAK,EAAE;MACnDhB,KAAK,CAAC,4BAA4B,CAAC;MACnC;MACA;MACAiB,wBAAwB,CAACd,MAAM,CAAC,CAACE,GAAG,EAAEC,GAAG,EAAEE,eAAC,CAACU,IAAI,CAAC;IACpD;IACAlB,KAAK,CAAC,6BAA6B,CAAC;IACpCM,GAAG,CA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QAAErB,GAAG,EAAEA;MAAI,CAAC,EAAE,iDAAiD,CAAC;MAC7E,IAAI,CAACE,GAAG,CAACc,MAAM,IAAI,CAACd,GAAG,CAACsB,IAAI,EAAE;QAC5B;QACAzB,MAAM,CAACsB,KAAK,CAAC,oDAAoD,CAAC;QAClEzB,KAAK,CAAC,yEAAyE,EAAEI,GAAG,CAAC;QACrFE,GAAG,CAACuB,OAAO,CAAC,CAAC;MACf,CAAC,MAAM,IAAI,CAACvB,GAAG,CAACiB,WAAW,EAAE;QAC3BvB,KAAK,CAAC,wBAAwB,EAAEI,GAAG,CAAC;QACpCE,GAAG,CAACc,MAAM,CAACR,iBAAW,CAACkB,cAAc,CAAC;QACtCvB,IAAI,CAAC;UAAEkB,KAAK,EAAEC,eAAS,CAACK;QAAsB,CAAC,CAAC;MAClD,CAAC,MAAM;QACL;QACA/B,KAAK,CAAC,6CAA6C,EAAEI,GAAG,CAAC;MAC3D;IACF;EACF,CAAC;EAEHJ,KAAK,CAAC,sDAAsD,CAAC;EAC7DO,IAAI,CAAC,CAAC;AACR,CAAC;AAACY,OAAA,CAAAF,wBAAA,GAAAA,wBAAA"}
|
|
@@ -4,24 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.final = final;
|
|
7
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
7
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
9
|
var _core = require("@verdaccio/core");
|
|
9
10
|
var _utils = require("@verdaccio/utils");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const debug = (0, _debug.default)('verdaccio:middleware:final');
|
|
11
13
|
function final(body, req, res,
|
|
12
14
|
// if we remove `next` breaks test
|
|
13
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
16
|
next) {
|
|
15
17
|
if (res.statusCode === _core.HTTP_STATUS.UNAUTHORIZED && !res.getHeader(_core.HEADERS.WWW_AUTH)) {
|
|
18
|
+
debug('set auth header support');
|
|
16
19
|
res.header(_core.HEADERS.WWW_AUTH, `${_core.TOKEN_BASIC}, ${_core.TOKEN_BEARER}`);
|
|
17
20
|
}
|
|
18
21
|
try {
|
|
19
22
|
if (_lodash.default.isString(body) || _lodash.default.isObject(body)) {
|
|
20
23
|
if (!res.get(_core.HEADERS.CONTENT_TYPE)) {
|
|
24
|
+
debug('set json type header support');
|
|
21
25
|
res.header(_core.HEADERS.CONTENT_TYPE, _core.HEADERS.JSON);
|
|
22
26
|
}
|
|
23
27
|
if (typeof body === 'object' && _lodash.default.isNil(body) === false) {
|
|
24
28
|
if (typeof body.error === 'string') {
|
|
29
|
+
debug('set verdaccio_error method');
|
|
25
30
|
res.locals._verdaccio_error = body.error;
|
|
26
31
|
}
|
|
27
32
|
body = JSON.stringify(body, undefined, ' ') + '\n';
|
|
@@ -29,9 +34,12 @@ next) {
|
|
|
29
34
|
|
|
30
35
|
// don't send etags with errors
|
|
31
36
|
if (!res.statusCode || res.statusCode >= _core.HTTP_STATUS.OK && res.statusCode < _core.HTTP_STATUS.MULTIPLE_CHOICES) {
|
|
32
|
-
|
|
37
|
+
const etag = (0, _utils.stringToMD5)(body);
|
|
38
|
+
debug('set etag header %s', etag);
|
|
39
|
+
res.header(_core.HEADERS.ETAG, '"' + etag + '"');
|
|
33
40
|
}
|
|
34
41
|
} else {
|
|
42
|
+
debug('this line should never be visible, if does report');
|
|
35
43
|
// send(null), send(204), etc.
|
|
36
44
|
}
|
|
37
45
|
} catch (err) {
|
|
@@ -39,8 +47,10 @@ next) {
|
|
|
39
47
|
// as an error handler, we can't report error properly,
|
|
40
48
|
// and should just close socket
|
|
41
49
|
if (err.message.match(/set headers after they are sent/)) {
|
|
50
|
+
debug('set headers after they are sent');
|
|
42
51
|
if (_lodash.default.isNil(res.socket) === false) {
|
|
43
52
|
var _res$socket;
|
|
53
|
+
debug('force destroy socket');
|
|
44
54
|
(_res$socket = res.socket) === null || _res$socket === void 0 ? void 0 : _res$socket.destroy();
|
|
45
55
|
}
|
|
46
56
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"final.js","names":["
|
|
1
|
+
{"version":3,"file":"final.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","_utils","obj","__esModule","default","debug","buildDebug","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","ETAG","err","message","match","socket","_res$socket","destroy","send"],"sources":["../../src/middlewares/final.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ 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\nconst debug = buildDebug('verdaccio:middleware:final');\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 debug('set auth header support');\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 debug('set json type header support');\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 debug('set verdaccio_error method');\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 const etag = stringToMD5(body as string);\n debug('set etag header %s', etag);\n res.header(HEADERS.ETAG, '\"' + etag + '\"');\n }\n } else {\n debug('this line should never be visible, if does report');\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 debug('set headers after they are sent');\n if (_.isNil(res.socket) === false) {\n debug('force destroy socket');\n res.socket?.destroy();\n }\n return;\n }\n throw err;\n }\n\n res.send(body);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAA+C,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAM/C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,4BAA4B,CAAC;AAE/C,SAASC,KAAKA,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;IACnFZ,KAAK,CAAC,yBAAyB,CAAC;IAChCK,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACC,QAAQ,EAAG,GAAEE,iBAAY,KAAIC,kBAAa,EAAC,CAAC;EACjE;EAEA,IAAI;IACF,IAA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C,iCAAiC,CAAC;MACxC,IAAIgB,eAAC,CAACM,KAAK,CAACjB,GAAG,CAAC+B,MAAM,CAAC,KAAK,KAAK,EAAE;QAAA,IAAAC,WAAA;QACjCrC,KAAK,CAAC,sBAAsB,CAAC;QAC7B,CAAAqC,WAAA,GAAAhC,GAAG,CAAC+B,MAAM,cAAAC,WAAA,uBAAVA,WAAA,CAAYC,OAAO,CAAC,CAAC;MACvB;MACA;IACF;IACA,MAAML,GAAG;EACX;EAEA5B,GAAG,CAACkC,IAAI,CAACpC,IAAI,CAAC;AAChB"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getManifestValue = getManifestValue;
|
|
7
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const debug = (0, _debug.default)('verdaccio:web:render:manifest');
|
|
9
|
+
const debug = (0, _debug.default)('verdaccio:middleware:web:render:manifest');
|
|
10
10
|
function getManifestValue(manifestItems, manifest, basePath = '') {
|
|
11
11
|
return manifestItems === null || manifestItems === void 0 ? void 0 : manifestItems.map(item => {
|
|
12
12
|
debug('resolve item %o', item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","names":["_debug","_interopRequireDefault","require","obj","__esModule","default","debug","buildDebug","getManifestValue","manifestItems","manifest","basePath","map","item","resolvedItem"],"sources":["../../../../src/middlewares/web/utils/manifest.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nexport type Manifest = {\n // goes on first place at the header\n ico: string;\n css: string[];\n js: string[];\n};\n\nconst debug = buildDebug('verdaccio:web:render:manifest');\n\nexport function getManifestValue(\n manifestItems: string[],\n manifest,\n basePath: string = ''\n): string[] {\n return manifestItems?.map((item) => {\n debug('resolve item %o', item);\n const resolvedItem = `${basePath}${manifest[item]}`;\n debug('resolved item %o', resolvedItem);\n return resolvedItem;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAS/B,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC
|
|
1
|
+
{"version":3,"file":"manifest.js","names":["_debug","_interopRequireDefault","require","obj","__esModule","default","debug","buildDebug","getManifestValue","manifestItems","manifest","basePath","map","item","resolvedItem"],"sources":["../../../../src/middlewares/web/utils/manifest.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nexport type Manifest = {\n // goes on first place at the header\n ico: string;\n css: string[];\n js: string[];\n};\n\nconst debug = buildDebug('verdaccio:middleware:web:render:manifest');\n\nexport function getManifestValue(\n manifestItems: string[],\n manifest,\n basePath: string = ''\n): string[] {\n return manifestItems?.map((item) => {\n debug('resolve item %o', item);\n const resolvedItem = `${basePath}${manifest[item]}`;\n debug('resolved item %o', resolvedItem);\n return resolvedItem;\n });\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAS/B,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,0CAA0C,CAAC;AAE7D,SAASC,gBAAgBA,CAC9BC,aAAuB,EACvBC,QAAQ,EACRC,QAAgB,GAAG,EAAE,EACX;EACV,OAAOF,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEG,GAAG,CAAEC,IAAI,IAAK;IAClCP,KAAK,CAAC,iBAAiB,EAAEO,IAAI,CAAC;IAC9B,MAAMC,YAAY,GAAI,GAAEH,QAAS,GAAED,QAAQ,CAACG,IAAI,CAAE,EAAC;IACnDP,KAAK,CAAC,kBAAkB,EAAEQ,YAAY,CAAC;IACvC,OAAOA,YAAY;EACrB,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/middleware",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.6",
|
|
4
4
|
"description": "express middleware utils",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"node": ">=12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@verdaccio/core": "7.0.0-next.
|
|
33
|
-
"@verdaccio/utils": "7.0.0-next.
|
|
34
|
-
"@verdaccio/config": "7.0.0-next.
|
|
35
|
-
"@verdaccio/url": "12.0.0-next.
|
|
32
|
+
"@verdaccio/core": "7.0.0-next.6",
|
|
33
|
+
"@verdaccio/utils": "7.0.0-next.6",
|
|
34
|
+
"@verdaccio/config": "7.0.0-next.6",
|
|
35
|
+
"@verdaccio/url": "12.0.0-next.6",
|
|
36
36
|
"debug": "4.3.4",
|
|
37
37
|
"lru-cache": "7.18.3",
|
|
38
38
|
"express": "4.18.2",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"url": "https://opencollective.com/verdaccio"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@verdaccio/logger": "7.0.0-next.
|
|
48
|
+
"@verdaccio/logger": "7.0.0-next.6",
|
|
49
49
|
"body-parser": "1.20.2",
|
|
50
50
|
"supertest": "6.3.3"
|
|
51
51
|
},
|
package/src/middlewares/error.ts
CHANGED
|
@@ -43,7 +43,7 @@ export const errorReportingMiddleware = (logger) =>
|
|
|
43
43
|
res: $ResponseExtend,
|
|
44
44
|
next: $NextFunctionVer
|
|
45
45
|
): void {
|
|
46
|
-
debug('error report middleware');
|
|
46
|
+
debug('error report middleware start');
|
|
47
47
|
res.locals.report_error =
|
|
48
48
|
res.locals.report_error ||
|
|
49
49
|
function (err: VerdaccioError): void {
|
|
@@ -64,7 +64,7 @@ export const errorReportingMiddleware = (logger) =>
|
|
|
64
64
|
debug('this is an error in express.js, please report this, destroy response %o', err);
|
|
65
65
|
res.destroy();
|
|
66
66
|
} else if (!res.headersSent) {
|
|
67
|
-
debug('
|
|
67
|
+
debug('send internal error %o', err);
|
|
68
68
|
res.status(HTTP_STATUS.INTERNAL_ERROR);
|
|
69
69
|
next({ error: API_ERROR.INTERNAL_SERVER_ERROR });
|
|
70
70
|
} else {
|
|
@@ -74,6 +74,6 @@ export const errorReportingMiddleware = (logger) =>
|
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
debug('error report middleware next()');
|
|
77
|
+
debug('error report middleware end (skip next layer) next()');
|
|
78
78
|
next();
|
|
79
79
|
};
|
package/src/middlewares/final.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import buildDebug from 'debug';
|
|
1
2
|
import _ from 'lodash';
|
|
2
3
|
|
|
3
4
|
import { HEADERS, HTTP_STATUS, TOKEN_BASIC, TOKEN_BEARER } from '@verdaccio/core';
|
|
@@ -8,6 +9,8 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend, MiddlewareError } fr
|
|
|
8
9
|
|
|
9
10
|
export type FinalBody = Manifest | MiddlewareError | string;
|
|
10
11
|
|
|
12
|
+
const debug = buildDebug('verdaccio:middleware:final');
|
|
13
|
+
|
|
11
14
|
export function final(
|
|
12
15
|
body: FinalBody,
|
|
13
16
|
req: $RequestExtend,
|
|
@@ -17,17 +20,20 @@ export function final(
|
|
|
17
20
|
next: $NextFunctionVer
|
|
18
21
|
): void {
|
|
19
22
|
if (res.statusCode === HTTP_STATUS.UNAUTHORIZED && !res.getHeader(HEADERS.WWW_AUTH)) {
|
|
23
|
+
debug('set auth header support');
|
|
20
24
|
res.header(HEADERS.WWW_AUTH, `${TOKEN_BASIC}, ${TOKEN_BEARER}`);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
try {
|
|
24
28
|
if (_.isString(body) || _.isObject(body)) {
|
|
25
29
|
if (!res.get(HEADERS.CONTENT_TYPE)) {
|
|
30
|
+
debug('set json type header support');
|
|
26
31
|
res.header(HEADERS.CONTENT_TYPE, HEADERS.JSON);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
if (typeof body === 'object' && _.isNil(body) === false) {
|
|
30
35
|
if (typeof (body as MiddlewareError).error === 'string') {
|
|
36
|
+
debug('set verdaccio_error method');
|
|
31
37
|
res.locals._verdaccio_error = (body as MiddlewareError).error;
|
|
32
38
|
}
|
|
33
39
|
body = JSON.stringify(body, undefined, ' ') + '\n';
|
|
@@ -38,9 +44,12 @@ export function final(
|
|
|
38
44
|
!res.statusCode ||
|
|
39
45
|
(res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)
|
|
40
46
|
) {
|
|
41
|
-
|
|
47
|
+
const etag = stringToMD5(body as string);
|
|
48
|
+
debug('set etag header %s', etag);
|
|
49
|
+
res.header(HEADERS.ETAG, '"' + etag + '"');
|
|
42
50
|
}
|
|
43
51
|
} else {
|
|
52
|
+
debug('this line should never be visible, if does report');
|
|
44
53
|
// send(null), send(204), etc.
|
|
45
54
|
}
|
|
46
55
|
} catch (err: any) {
|
|
@@ -48,7 +57,9 @@ export function final(
|
|
|
48
57
|
// as an error handler, we can't report error properly,
|
|
49
58
|
// and should just close socket
|
|
50
59
|
if (err.message.match(/set headers after they are sent/)) {
|
|
60
|
+
debug('set headers after they are sent');
|
|
51
61
|
if (_.isNil(res.socket) === false) {
|
|
62
|
+
debug('force destroy socket');
|
|
52
63
|
res.socket?.destroy();
|
|
53
64
|
}
|
|
54
65
|
return;
|