@verdaccio/middleware 7.0.0-next.3 → 7.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @verdaccio/middleware
2
2
 
3
+ ## 7.0.0-next.5
4
+
5
+ ### Minor Changes
6
+
7
+ - f047cc8: refactor: auth with legacy sign support
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [f047cc8]
12
+ - @verdaccio/core@7.0.0-next.5
13
+ - @verdaccio/url@12.0.0-next.5
14
+ - @verdaccio/config@7.0.0-next.5
15
+ - @verdaccio/utils@7.0.0-next.5
16
+
17
+ ## 7.0.0-next.4
18
+
19
+ ### Patch Changes
20
+
21
+ - @verdaccio/core@7.0.0-next.4
22
+ - @verdaccio/config@7.0.0-next.4
23
+ - @verdaccio/url@12.0.0-next.4
24
+ - @verdaccio/utils@7.0.0-next.4
25
+
3
26
  ## 7.0.0-next.3
4
27
 
5
28
  ### Major Changes
@@ -1,7 +1,8 @@
1
1
  import { Config } from '@verdaccio/types';
2
+ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
2
3
  /**
3
4
  * A middleware that avoid a registry points itself as proxy and avoid create infinite loops.
4
5
  * @param config
5
6
  * @returns
6
7
  */
7
- export declare function antiLoop(config: Config): Function;
8
+ export declare function antiLoop(config: Config): (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"antiLoop.js","names":["_core","require","antiLoop","config","req","res","next","_req$headers","headers","via","_req$get","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,IAAAA,KAAA,GAAAC,OAAA;AAKA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CAACC,MAAc,EAAY;EACjD,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IAAA,IAAAC,YAAA;IACxF,IAAI,CAAAH,GAAG,aAAHA,GAAG,wBAAAG,YAAA,GAAHH,GAAG,CAAEI,OAAO,cAAAD,YAAA,uBAAZA,YAAA,CAAcE,GAAG,KAAI,IAAI,EAAE;MAAA,IAAAC,QAAA;MAC7B,MAAMC,GAAG,IAAAD,QAAA,GAAGN,GAAG,CAACQ,GAAG,CAAC,KAAK,CAAC,cAAAF,QAAA,uBAAdA,QAAA,CAAgBG,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,CAAC,CAAC,CAACC,KAAK,CAAC,kBAAkB,CAAC;UACjD,IAAIF,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAKf,MAAM,CAACkB,SAAS,EAAE;YAClC,OAAOf,IAAI,CAACgB,gBAAU,CAACC,OAAO,CAACC,iBAAW,CAACC,aAAa,EAAE,eAAe,CAAC,CAAC;UAC7E;QACF;MACF;IACF;IACAnB,IAAI,CAAC,CAAC;EACR,CAAC;AACH"}
1
+ {"version":3,"file":"antiLoop.js","names":["_core","require","antiLoop","config","req","res","next","_req$headers","headers","via","_req$get","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) {\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,IAAAA,KAAA,GAAAC,OAAA;AAKA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CAACC,MAAc,EAAE;EACvC,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IAAA,IAAAC,YAAA;IACxF,IAAI,CAAAH,GAAG,aAAHA,GAAG,wBAAAG,YAAA,GAAHH,GAAG,CAAEI,OAAO,cAAAD,YAAA,uBAAZA,YAAA,CAAcE,GAAG,KAAI,IAAI,EAAE;MAAA,IAAAC,QAAA;MAC7B,MAAMC,GAAG,IAAAD,QAAA,GAAGN,GAAG,CAACQ,GAAG,CAAC,KAAK,CAAC,cAAAF,QAAA,uBAAdA,QAAA,CAAgBG,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,CAAC,CAAC,CAACC,KAAK,CAAC,kBAAkB,CAAC;UACjD,IAAIF,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,KAAKf,MAAM,CAACkB,SAAS,EAAE;YAClC,OAAOf,IAAI,CAACgB,gBAAU,CAACC,OAAO,CAACC,iBAAW,CAACC,aAAa,EAAE,eAAe,CAAC,CAAC;UAC7E;QACF;MACF;IACF;IACAnB,IAAI,CAAC,CAAC;EACR,CAAC;AACH"}
@@ -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('report internal error %o', err);
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('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":";;;;;;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,I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AACc,MAAM,CAAChB,GAAG,CAACgB,MAAM,CAAC;QACtBpB,KAAK,CAAC,eAAe,EAAEI,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEoB,OAAO,CAAC;QACpCjB,IAAI,CAAC;UAAEkB,KAAK,EAAErB,GAAG,CAACoB,OAAO,IAAIE,eAAS,CAACC;QAAc,CAAC,CAAC;MACzD;IACF,CAAC,MAAM;MACL3B,KAAK,CAAC,mBAAmB,EAAEI,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEgB,MAAM,CAAC;MACvCjB,MAAM,CAACsB,KAAK,CAAC;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,0BAA0B,EAAEI,GAAG,CAAC;QACtCE,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,gCAAgC,CAAC;EACvCO,IAAI,CAAC,CAAC;AACR,CAAC;AAACY,OAAA,CAAAF,wBAAA,GAAAA,wBAAA"}
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,CAACS,MAAM,CAACC,YAAY,C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AI,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
- res.header(_core.HEADERS.ETAG, '"' + (0, _utils.stringToMD5)(body) + '"');
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":["_lodash","_interopRequireDefault","require","_core","_utils","obj","__esModule","default","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","_res$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,IAAAA,OAAA,GAAAC,sBAA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AACE,UAAU,GAAGC,iBAAW,CAACqB,gBAAiB,EACnF;QACAxB,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACmB,IAAI,EAAE,GAAG,GAAG,IAAAC,kBAAW,EAAC5B,IAAc,CAAC,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,IAAAC,WAAA;QACjC,CAAAA,WAAA,GAAA/B,GAAG,CAAC8B,MAAM,cAAAC,WAAA,uBAAVA,WAAA,CAAYC,OAAO,CAAC,CAAC;MACvB;MACA;IACF;IACA,MAAML,GAAG;EACX;EAEA3B,GAAG,CAACiC,IAAI,CAACnC,IAAI,CAAC;AAChB"}
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,CA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oB,EAAE,IAAIvB,GAAG,CAACE,UAAU,GAAGC,iBAAW,CAACqB,gBAAiB,EACnF;QACA,MAAMC,IAAI,GAAG,IAAAC,kBAAW,EAAC5B,IAAc,CAAC;QACxCH,KAAK,CAAC,oBAAoB,EAAE8B,IAAI,CAAC;QACjCzB,GAAG,CAACQ,MAAM,CAACF,aAAO,CAACqB,IAAI,EAAE,GAAG,GAAGF,IAAI,GAAG,GAAG,CAAC;MAC5C;IACF,CAAC,MAAM;MACL9B,KAAK,CAAC,mDAAmD,CAAC;MAC1D;IACF;EACF,CAAC,CAAC,OAAOiC,GAAQ,EAAE;IACjB;IACA;IACA;IACA,IAAIA,GAAG,CAACC,OAAO,CAACC,KAAK,CAAC,iCAAiC,CAAC,EAAE;MACxDnC,KAAK,CAAC,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"}
@@ -7,12 +7,9 @@ exports.log = exports.LOG_VERDACCIO_ERROR = exports.LOG_VERDACCIO_BYTES = export
7
7
  var _lodash = _interopRequireDefault(require("lodash"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  // FIXME: deprecated, moved to @verdaccio/dev-commons
10
- const LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
11
- exports.LOG_STATUS_MESSAGE = LOG_STATUS_MESSAGE;
12
- const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
13
- exports.LOG_VERDACCIO_ERROR = LOG_VERDACCIO_ERROR;
14
- const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
15
- exports.LOG_VERDACCIO_BYTES = LOG_VERDACCIO_BYTES;
10
+ const LOG_STATUS_MESSAGE = exports.LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
11
+ const LOG_VERDACCIO_ERROR = exports.LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
12
+ const LOG_VERDACCIO_BYTES = exports.LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
16
13
  const log = logger => {
17
14
  return function log(req, res, next) {
18
15
  // logger
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","names":["_lodash","_interopRequireDefault","require","obj","__esModule","default","LOG_STATUS_MESSAGE","exports","LOG_VERDACCIO_ERROR","LOG_VERDACCIO_BYTES","log","logger","req","res","next","child","sub","_auth","headers","authorization","_","isNil","_cookie","get","cookie","url","originalUrl","info","ip","bytesin","on","chunk","length","bytesout","_write","write","buf","apply","arguments","_req$remote_user","forwardedFor","remoteAddress","connection","remoteIP","message","locals","_verdaccio_error","http","request","method","user","remote_user","name","status","statusCode","error","bytes","in","out","_end","end"],"sources":["../../src/middlewares/log.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n// FIXME: deprecated, moved to @verdaccio/dev-commons\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport const log = (logger) => {\n return function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n // logger\n req.log = logger.child({ sub: 'in' });\n\n const _auth = req.headers.authorization;\n if (_.isNil(_auth) === false) {\n req.headers.authorization = '<Classified>';\n }\n\n const _cookie = req.get('cookie');\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = '<Classified>';\n }\n\n req.url = req.originalUrl;\n req.log.info({ req: req, ip: req.ip }, \"@{ip} requested '@{req.method} @{req.url}'\");\n req.originalUrl = req.url;\n\n if (_.isNil(_auth) === false) {\n req.headers.authorization = _auth;\n }\n\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = _cookie;\n }\n\n let bytesin = 0;\n req.on('data', function (chunk): void {\n bytesin += chunk.length;\n });\n\n let bytesout = 0;\n const _write = res.write;\n // FIXME: res.write should return boolean\n // @ts-ignore\n res.write = function (buf): boolean {\n bytesout += buf.length;\n /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _write.apply(res, arguments);\n };\n\n const log = function (): void {\n const forwardedFor = req.get('x-forwarded-for');\n const remoteAddress = req.connection.remoteAddress;\n const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;\n let message;\n if (res.locals._verdaccio_error) {\n message = LOG_VERDACCIO_ERROR;\n } else {\n message = LOG_VERDACCIO_BYTES;\n }\n\n req.url = req.originalUrl;\n req.log.http(\n {\n request: {\n method: req.method,\n url: req.url,\n },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: {\n in: bytesin,\n out: bytesout,\n },\n },\n message\n );\n req.originalUrl = req.url;\n };\n\n req.on('close', function (): void {\n log();\n });\n\n const _end = res.end;\n // @ts-ignore\n res.end = function (buf): void {\n if (buf) {\n bytesout += buf.length;\n }\n /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _end.apply(res, arguments);\n log();\n };\n next();\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuB,SAAAD,uBAA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EAAEb,GAAG,CAACa;QACX,CAAC;QACDyB,IAAI,EAAE,EAAAX,gBAAA,GAAA3B,GAAG,CAACuC,WAAW,cAAAZ,gBAAA,uBAAfA,gBAAA,CAAiBa,IAAI,KAAI,IAAI;QACnCT,QAAQ;QACRU,MAAM,EAAExC,GAAG,CAACyC,UAAU;QACtBC,KAAK,EAAE1C,GAAG,CAACgC,MAAM,CAACC,gBAAgB;QAClCU,KAAK,EAAE;UACLC,EAAE,EAAE5B,OAAO;UACX6B,GAAG,EAAEzB;QACP;MACF,CAAC,EACDW,OACF,CAAC;MACDhC,GAAG,CAACc,WAAW,GAAGd,GAAG,CAACa,GAAG;IAC3B,CAAC;IAEDb,GAAG,CAACkB,EAAE,CAAC,OAAO,EAAE,YAAkB;MAChCpB,GAAG,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,MAAMiD,IAAI,GAAG9C,GAAG,CAAC+C,GAAG;IACpB;IACA/C,GAAG,CAAC+C,GAAG,GAAG,UAAUxB,GAAG,EAAQ;MAC7B,IAAIA,GAAG,EAAE;QACPH,QAAQ,IAAIG,GAAG,CAACJ,MAAM;MACxB;MACA;MACA;MACA2B,IAAI,CAACtB,KAAK,CAACxB,GAAG,EAAEyB,SAAS,CAAC;MAC1B5B,GAAG,CAAC,CAAC;IACP,CAAC;IACDI,IAAI,CAAC,CAAC;EACR,CAAC;AACH,CAAC;AAACP,OAAA,CAAAG,GAAA,GAAAA,GAAA"}
1
+ {"version":3,"file":"log.js","names":["_lodash","_interopRequireDefault","require","obj","__esModule","default","LOG_STATUS_MESSAGE","exports","LOG_VERDACCIO_ERROR","LOG_VERDACCIO_BYTES","log","logger","req","res","next","child","sub","_auth","headers","authorization","_","isNil","_cookie","get","cookie","url","originalUrl","info","ip","bytesin","on","chunk","length","bytesout","_write","write","buf","apply","arguments","_req$remote_user","forwardedFor","remoteAddress","connection","remoteIP","message","locals","_verdaccio_error","http","request","method","user","remote_user","name","status","statusCode","error","bytes","in","out","_end","end"],"sources":["../../src/middlewares/log.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n// FIXME: deprecated, moved to @verdaccio/dev-commons\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport const log = (logger) => {\n return function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n // logger\n req.log = logger.child({ sub: 'in' });\n\n const _auth = req.headers.authorization;\n if (_.isNil(_auth) === false) {\n req.headers.authorization = '<Classified>';\n }\n\n const _cookie = req.get('cookie');\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = '<Classified>';\n }\n\n req.url = req.originalUrl;\n req.log.info({ req: req, ip: req.ip }, \"@{ip} requested '@{req.method} @{req.url}'\");\n req.originalUrl = req.url;\n\n if (_.isNil(_auth) === false) {\n req.headers.authorization = _auth;\n }\n\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = _cookie;\n }\n\n let bytesin = 0;\n req.on('data', function (chunk): void {\n bytesin += chunk.length;\n });\n\n let bytesout = 0;\n const _write = res.write;\n // FIXME: res.write should return boolean\n // @ts-ignore\n res.write = function (buf): boolean {\n bytesout += buf.length;\n /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _write.apply(res, arguments);\n };\n\n const log = function (): void {\n const forwardedFor = req.get('x-forwarded-for');\n const remoteAddress = req.connection.remoteAddress;\n const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;\n let message;\n if (res.locals._verdaccio_error) {\n message = LOG_VERDACCIO_ERROR;\n } else {\n message = LOG_VERDACCIO_BYTES;\n }\n\n req.url = req.originalUrl;\n req.log.http(\n {\n request: {\n method: req.method,\n url: req.url,\n },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: {\n in: bytesin,\n out: bytesout,\n },\n },\n message\n );\n req.originalUrl = req.url;\n };\n\n req.on('close', function (): void {\n log();\n });\n\n const _end = res.end;\n // @ts-ignore\n res.end = function (buf): void {\n if (buf) {\n bytesout += buf.length;\n }\n /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _end.apply(res, arguments);\n log();\n };\n next();\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuB,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAIvB;AACO,MAAMG,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAC7B,gFAAgF;AAC3E,MAAME,mBAAmB,GAAAD,OAAA,CAAAC,mBAAA,GAAI,GAAEF,kBAAmB,oBAAmB;AACrE,MAAMG,mBAAmB,GAAAF,OAAA,CAAAE,mBAAA,GAAI,GAAEH,kBAAmB,mCAAkC;AAEpF,MAAMI,GAAG,GAAIC,MAAM,IAAK;EAC7B,OAAO,SAASD,GAAGA,CAACE,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IAC3F;IACAF,GAAG,CAACF,GAAG,GAAGC,MAAM,CAACI,KAAK,CAAC;MAAEC,GAAG,EAAE;IAAK,CAAC,CAAC;IAErC,MAAMC,KAAK,GAAGL,GAAG,CAACM,OAAO,CAACC,aAAa;IACvC,IAAIC,eAAC,CAACC,KAAK,CAACJ,KAAK,CAAC,KAAK,KAAK,EAAE;MAC5BL,GAAG,CAACM,OAAO,CAACC,aAAa,GAAG,cAAc;IAC5C;IAEA,MAAMG,OAAO,GAAGV,GAAG,CAACW,GAAG,CAAC,QAAQ,CAAC;IACjC,IAAIH,eAAC,CAACC,KAAK,CAACC,OAAO,CAAC,KAAK,KAAK,EAA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,GAAA"}
@@ -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,+BAA+B,CAAC;AAElD,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"}
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"}
@@ -7,8 +7,8 @@ exports.webAPIMiddleware = webAPIMiddleware;
7
7
  var _express = _interopRequireWildcard(require("express"));
8
8
  var _validation = require("../validation");
9
9
  var _security = require("./security");
10
- 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); }
11
- 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; }
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
12
  function webAPIMiddleware(tokenMiddleware, webEndpointsApi) {
13
13
  // eslint-disable-next-line new-cap
14
14
  const route = (0, _express.Router)();
@@ -1 +1 @@
1
- {"version":3,"file":"web-api.js","names":["_express","_interopRequireWildcard","require","_validation","_security","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","webAPIMiddleware","tokenMiddleware","webEndpointsApi","route","Router","param","validatePackage","validateName","use","express","urlencoded","extended","setSecurityWebHeaders"],"sources":["../../../src/middlewares/web/web-api.ts"],"sourcesContent":["import express from 'express';\nimport { RequestHandler, Router } from 'express';\n\nimport { validateName, validatePackage } from '../validation';\nimport { setSecurityWebHeaders } from './security';\n\nexport function webAPIMiddleware(\n tokenMiddleware: RequestHandler,\n webEndpointsApi: RequestHandler\n): Router {\n // eslint-disable-next-line new-cap\n const route = Router();\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble=\n route.param('package', validatePackage);\n route.param('filename', validateName);\n route.param('version', validateName);\n route.use(express.urlencoded({ extended: false }));\n route.use(setSecurityWebHeaders);\n\n if (typeof tokenMiddleware === 'function') {\n route.use(tokenMiddleware);\n }\n\n if (typeof webEndpointsApi === 'function') {\n route.use(webEndpointsApi);\n }\n\n return route;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAAmD,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,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C;EAEhC,IAAI,OAAOX,eAAe,KAAK,UAAU,EAAE;IACzCE,KAAK,CAACK,GAAG,CAACP,eAAe,CAAC;EAC5B;EAEA,IAAI,OAAOC,eAAe,KAAK,UAAU,EAAE;IACzCC,KAAK,CAACK,GAAG,CAACN,eAAe,CAAC;EAC5B;EAEA,OAAOC,KAAK;AACd"}
1
+ {"version":3,"file":"web-api.js","names":["_express","_interopRequireWildcard","require","_validation","_security","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","webAPIMiddleware","tokenMiddleware","webEndpointsApi","route","Router","param","validatePackage","validateName","use","express","urlencoded","extended","setSecurityWebHeaders"],"sources":["../../../src/middlewares/web/web-api.ts"],"sourcesContent":["import express from 'express';\nimport { RequestHandler, Router } from 'express';\n\nimport { validateName, validatePackage } from '../validation';\nimport { setSecurityWebHeaders } from './security';\n\nexport function webAPIMiddleware(\n tokenMiddleware: RequestHandler,\n webEndpointsApi: RequestHandler\n): Router {\n // eslint-disable-next-line new-cap\n const route = Router();\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble=\n route.param('package', validatePackage);\n route.param('filename', validateName);\n route.param('version', validateName);\n route.use(express.urlencoded({ extended: false }));\n route.use(setSecurityWebHeaders);\n\n if (typeof tokenMiddleware === 'function') {\n route.use(tokenMiddleware);\n }\n\n if (typeof webEndpointsApi === 'function') {\n route.use(webEndpointsApi);\n }\n\n return route;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAAmD,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,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AC;EACpCJ,KAAK,CAACK,GAAG,CAACC,gBAAO,CAACC,UAAU,CAAC;IAAEC,QAAQ,EAAE;EAAM,CAAC,CAAC,CAAC;EAClDR,KAAK,CAACK,GAAG,CAACI,+BAAqB,CAAC;EAEhC,IAAI,OAAOX,eAAe,KAAK,UAAU,EAAE;IACzCE,KAAK,CAACK,GAAG,CAACP,eAAe,CAAC;EAC5B;EAEA,IAAI,OAAOC,eAAe,KAAK,UAAU,EAAE;IACzCC,KAAK,CAACK,GAAG,CAACN,eAAe,CAAC;EAC5B;EAEA,OAAOC,KAAK;AACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/middleware",
3
- "version": "7.0.0-next.3",
3
+ "version": "7.0.0-next.5",
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.3",
33
- "@verdaccio/utils": "7.0.0-next.3",
34
- "@verdaccio/config": "7.0.0-next.3",
35
- "@verdaccio/url": "12.0.0-next.3",
32
+ "@verdaccio/core": "7.0.0-next.5",
33
+ "@verdaccio/utils": "7.0.0-next.5",
34
+ "@verdaccio/config": "7.0.0-next.5",
35
+ "@verdaccio/url": "12.0.0-next.5",
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.3",
48
+ "@verdaccio/logger": "7.0.0-next.5",
49
49
  "body-parser": "1.20.2",
50
50
  "supertest": "6.3.3"
51
51
  },
@@ -8,7 +8,7 @@ import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
8
8
  * @param config
9
9
  * @returns
10
10
  */
11
- export function antiLoop(config: Config): Function {
11
+ export function antiLoop(config: Config) {
12
12
  return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
13
13
  if (req?.headers?.via != null) {
14
14
  const arr = req.get('via')?.split(',');
@@ -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('report internal error %o', err);
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
  };
@@ -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
- res.header(HEADERS.ETAG, '"' + stringToMD5(body as string) + '"');
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;
@@ -7,7 +7,7 @@ export type Manifest = {
7
7
  js: string[];
8
8
  };
9
9
 
10
- const debug = buildDebug('verdaccio:web:render:manifest');
10
+ const debug = buildDebug('verdaccio:middleware:web:render:manifest');
11
11
 
12
12
  export function getManifestValue(
13
13
  manifestItems: string[],