@verdaccio/middleware 8.0.0-next-8.0 → 8.0.0-next-8.2
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 +1 -1
- package/CHANGELOG.md +24 -0
- package/build/middlewares/allow.js +13 -7
- package/build/middlewares/allow.js.map +1 -1
- package/build/middlewares/antiLoop.js +2 -4
- package/build/middlewares/antiLoop.js.map +1 -1
- package/build/middlewares/error.js +4 -4
- package/build/middlewares/error.js.map +1 -1
- package/build/middlewares/final.js +1 -2
- package/build/middlewares/final.js.map +1 -1
- package/build/middlewares/log.js +1 -2
- package/build/middlewares/log.js.map +1 -1
- package/build/middlewares/user-agent.js +1 -1
- package/build/middlewares/user-agent.js.map +1 -1
- package/build/middlewares/web/render-web.js +6 -9
- package/build/middlewares/web/render-web.js.map +1 -1
- package/build/middlewares/web/utils/manifest.js +1 -1
- package/build/middlewares/web/utils/manifest.js.map +1 -1
- package/build/middlewares/web/utils/renderHTML.js +15 -16
- package/build/middlewares/web/utils/renderHTML.js.map +1 -1
- package/build/middlewares/web/utils/template.js +7 -8
- package/build/middlewares/web/utils/template.js.map +1 -1
- package/build/middlewares/web/utils/web-utils.js +1 -2
- package/build/middlewares/web/utils/web-utils.js.map +1 -1
- package/package.json +7 -7
- package/src/middlewares/allow.ts +20 -5
- package/test/allow.spec.ts +50 -38
package/.babelrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 8.0.0-next-8.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6a8154c: feat: update logger pino to latest
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- e850690: fix(middleware): pass version to allow check
|
|
12
|
+
- Updated dependencies [6a8154c]
|
|
13
|
+
- @verdaccio/config@8.0.0-next-8.2
|
|
14
|
+
- @verdaccio/core@8.0.0-next-8.2
|
|
15
|
+
- @verdaccio/url@13.0.0-next-8.2
|
|
16
|
+
- @verdaccio/utils@7.1.0-next-8.2
|
|
17
|
+
|
|
18
|
+
## 8.0.0-next-8.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- @verdaccio/core@8.0.0-next-8.1
|
|
23
|
+
- @verdaccio/config@8.0.0-next-8.1
|
|
24
|
+
- @verdaccio/url@13.0.0-next-8.1
|
|
25
|
+
- @verdaccio/utils@7.0.1-next-8.1
|
|
26
|
+
|
|
3
27
|
## 8.0.0-next-8.0
|
|
4
28
|
|
|
5
29
|
### Major Changes
|
|
@@ -4,8 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.allow = allow;
|
|
7
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
7
8
|
var _core = require("@verdaccio/core");
|
|
8
9
|
var _utils = require("@verdaccio/utils");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const debug = (0, _debug.default)('verdaccio:middleware:allow');
|
|
9
12
|
function allow(auth, options = {
|
|
10
13
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
14
|
beforeAll: (_a, _b) => {},
|
|
@@ -20,23 +23,26 @@ function allow(auth, options = {
|
|
|
20
23
|
return function (req, res, next) {
|
|
21
24
|
req.pause();
|
|
22
25
|
const packageName = req.params.scope ? `@${req.params.scope}/${req.params.package}` : req.params.package;
|
|
23
|
-
const packageVersion = req.params.filename ? (0, _utils.getVersionFromTarball)(req.params.filename) : undefined;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
+
const packageVersion = req.params.filename ? (0, _utils.getVersionFromTarball)(req.params.filename) : req.params.version ? req.params.version : undefined;
|
|
27
|
+
const remote_user = req.remote_user;
|
|
28
|
+
debug('check if user %o can %o package %o version %o', remote_user?.name, action, packageName, packageVersion);
|
|
29
|
+
beforeAll?.({
|
|
26
30
|
action,
|
|
27
|
-
user:
|
|
31
|
+
user: remote_user?.name
|
|
28
32
|
}, `[middleware/allow][@{action}] allow for @{user}`);
|
|
29
33
|
auth['allow_' + action]({
|
|
30
34
|
packageName,
|
|
31
35
|
packageVersion
|
|
32
|
-
},
|
|
36
|
+
}, remote_user, function (error, allowed) {
|
|
33
37
|
req.resume();
|
|
34
38
|
if (error) {
|
|
39
|
+
debug('user is NOT allowed to %o', action);
|
|
35
40
|
next(error);
|
|
36
41
|
} else if (allowed) {
|
|
37
|
-
|
|
42
|
+
debug('user is allowed to %o', action);
|
|
43
|
+
afterAll?.({
|
|
38
44
|
action,
|
|
39
|
-
user:
|
|
45
|
+
user: remote_user?.name
|
|
40
46
|
}, `[middleware/allow][@{action}] allowed for @{user}`);
|
|
41
47
|
next();
|
|
42
48
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allow.js","names":["
|
|
1
|
+
{"version":3,"file":"allow.js","names":["_debug","_interopRequireDefault","require","_core","_utils","e","__esModule","default","debug","buildDebug","allow","auth","options","beforeAll","_a","_b","afterAll","action","req","res","next","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","version","undefined","remote_user","name","user","error","allowed","resume","errorUtils","getInternalError","API_ERROR","PLUGIN_ERROR"],"sources":["../../src/middlewares/allow.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { API_ERROR, errorUtils } from '@verdaccio/core';\nimport { getVersionFromTarball } from '@verdaccio/utils';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:allow');\n\nexport function allow<T>(\n auth: T,\n options = {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n beforeAll: (_a: any, _b: any) => {},\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n afterAll: (_a: any, _b: any) => {},\n }\n): Function {\n const { beforeAll, afterAll } = options;\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 : req.params.version\n ? req.params.version\n : undefined;\n const remote_user = req.remote_user;\n debug(\n 'check if user %o can %o package %o version %o',\n remote_user?.name,\n action,\n packageName,\n packageVersion\n );\n beforeAll?.(\n { action, user: remote_user?.name },\n `[middleware/allow][@{action}] allow for @{user}`\n );\n auth['allow_' + action](\n { packageName, packageVersion },\n remote_user,\n function (error, allowed): void {\n req.resume();\n if (error) {\n debug('user is NOT allowed to %o', action);\n next(error);\n } else if (allowed) {\n debug('user is allowed to %o', action);\n afterAll?.(\n { action, user: remote_user?.name },\n `[middleware/allow][@{action}] allowed for @{user}`\n );\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAAyD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIzD,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,4BAA4B,CAAC;AAE/C,SAASC,KAAKA,CACnBC,IAAO,EACPC,OAAO,GAAG;EACR;EACAC,SAAS,EAAEA,CAACC,EAAO,EAAEC,EAAO,KAAK,CAAC,CAAC;EACnC;EACAC,QAAQ,EAAEA,CAACF,EAAO,EAAEC,EAAO,KAAK,CAAC;AACnC,CAAC,EACS;EACV,MAAM;IAAEF,SAAS;IAAEG;EAAS,CAAC,GAAGJ,OAAO;EACvC,OAAO,UAAUK,MAAc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AC,MAAM;UACL;UACA;UACA,MAAMiB,gBAAU,CAACC,gBAAgB,CAACC,eAAS,CAACC,YAAY,CAAC;QAC3D;MACF,CACF,CAAC;IACH,CAAC;EACH,CAAC;AACH","ignoreList":[]}
|
|
@@ -12,10 +12,8 @@ var _core = require("@verdaccio/core");
|
|
|
12
12
|
*/
|
|
13
13
|
function antiLoop(config) {
|
|
14
14
|
return function (req, res, next) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var _req$get;
|
|
18
|
-
const arr = (_req$get = req.get('via')) === null || _req$get === void 0 ? void 0 : _req$get.split(',');
|
|
15
|
+
if (req?.headers?.via != null) {
|
|
16
|
+
const arr = req.get('via')?.split(',');
|
|
19
17
|
if (Array.isArray(arr)) {
|
|
20
18
|
for (let i = 0; i < arr.length; i++) {
|
|
21
19
|
// the "via" header must contains an specific headers, this has to be on sync
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antiLoop.js","names":["_core","require","antiLoop","config","req","res","next","
|
|
1
|
+
{"version":3,"file":"antiLoop.js","names":["_core","require","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) {\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;IACxF,IAAIF,GAAG,EAAEG,OAAO,EAAEC,GAAG,IAAI,IAAI,EAAE;MAC7B,MAAMC,GAAG,GAAGL,GAAG,CAACM,GAAG,CAAC,KAAK,CAAC,EAAEC,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,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,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -37,17 +37,17 @@ const errorReportingMiddleware = logger => function errorReportingMiddleware(req
|
|
|
37
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
|
-
debug('is error > 409 %o', err
|
|
40
|
+
debug('is error > 409 %o', err?.status);
|
|
41
41
|
if (_lodash.default.isNil(res.headersSent) === false) {
|
|
42
|
-
debug('send status %o', err
|
|
42
|
+
debug('send status %o', err?.status);
|
|
43
43
|
res.status(err.status);
|
|
44
|
-
debug('next layer %o', err
|
|
44
|
+
debug('next layer %o', err?.message);
|
|
45
45
|
next({
|
|
46
46
|
error: err.message || _core.API_ERROR.UNKNOWN_ERROR
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
|
-
debug('is error < 409 %o', err
|
|
50
|
+
debug('is error < 409 %o', err?.status);
|
|
51
51
|
logger.error({
|
|
52
52
|
err: err
|
|
53
53
|
}, 'unexpected error: @{!err.message}\n@{err.stack}');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","e","__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,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIzE,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,4BAA4B,CAAC;AAE/C,MAAMC,WAAW,GAAIC,MAAM,IAChC,SAASD,WAAWA,CAClBE,GAAc,EACdC,GAAm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names":["_debug","_interopRequireDefault","require","_lodash","_core","e","__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,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;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,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G,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","ignoreList":[]}
|
|
@@ -49,9 +49,8 @@ next) {
|
|
|
49
49
|
if (err.message.match(/set headers after they are sent/)) {
|
|
50
50
|
debug('set headers after they are sent');
|
|
51
51
|
if (_lodash.default.isNil(res.socket) === false) {
|
|
52
|
-
var _res$socket;
|
|
53
52
|
debug('force destroy socket');
|
|
54
|
-
|
|
53
|
+
res.socket?.destroy();
|
|
55
54
|
}
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"final.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","_utils","e","__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","
|
|
1
|
+
{"version":3,"file":"final.js","names":["_debug","_interopRequireDefault","require","_lodash","_core","_utils","e","__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","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,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;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,EAAE,GAAGE,iBAAW,KAAKC,kBAAY,EAAE,CAAC;EACjE;EAEA,IAAI;IACF,IAAIC,eAAC,CAACC,QAAQ,CAACd,IAAI,CAAC,IAAIa,eAAC,CAACE,QAAQ,CAACf,IAA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CAAC,KAAK,KAAK,EAAE;QACjCpC,KAAK,CAAC,sBAAsB,CAAC;QAC7BK,GAAG,CAAC+B,MAAM,EAAEC,OAAO,CAAC,CAAC;MACvB;MACA;IACF;IACA,MAAMJ,GAAG;EACX;EAEA5B,GAAG,CAACiC,IAAI,CAACnC,IAAI,CAAC;AAChB","ignoreList":[]}
|
package/build/middlewares/log.js
CHANGED
|
@@ -51,7 +51,6 @@ const log = logger => {
|
|
|
51
51
|
_write.apply(res, arguments);
|
|
52
52
|
};
|
|
53
53
|
const log = function () {
|
|
54
|
-
var _req$remote_user;
|
|
55
54
|
const forwardedFor = req.get('x-forwarded-for');
|
|
56
55
|
const remoteAddress = req.connection.remoteAddress;
|
|
57
56
|
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
@@ -67,7 +66,7 @@ const log = logger => {
|
|
|
67
66
|
method: req.method,
|
|
68
67
|
url: req.url
|
|
69
68
|
},
|
|
70
|
-
user:
|
|
69
|
+
user: req.remote_user?.name || null,
|
|
71
70
|
remoteIP,
|
|
72
71
|
status: res.statusCode,
|
|
73
72
|
error: res.locals._verdaccio_error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","names":["_lodash","_interopRequireDefault","require","e","__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","
|
|
1
|
+
{"version":3,"file":"log.js","names":["_lodash","_interopRequireDefault","require","e","__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","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,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIvB;AACO,MAAMG,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAC7B,gFAAgF;AAC3E,MAAME,mBAAmB,GAAAD,OAAA,CAAAC,mBAAA,GAAG,GAAGF,kBAAkB,oBAAoB;AACrE,MAAMG,mBAAmB,GAAAF,OAAA,CAAAE,mBAAA,GAAG,GAAGH,kBAAkB,mCAAmC;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,Q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GAAAA,GAAA","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ exports.userAgent = userAgent;
|
|
|
7
7
|
var _config = require("@verdaccio/config");
|
|
8
8
|
function userAgent(config) {
|
|
9
9
|
return function (_req, res, next) {
|
|
10
|
-
res.setHeader('x-powered-by', (0, _config.getUserAgent)(config
|
|
10
|
+
res.setHeader('x-powered-by', (0, _config.getUserAgent)(config?.user_agent));
|
|
11
11
|
next();
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-agent.js","names":["_config","require","userAgent","config","_req","res","next","setHeader","getUserAgent","user_agent"],"sources":["../../src/middlewares/user-agent.ts"],"sourcesContent":["import { getUserAgent } from '@verdaccio/config';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function userAgent(config) {\n return function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('x-powered-by', getUserAgent(config?.user_agent));\n next();\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIO,SAASC,SAASA,CAACC,MAAM,EAAE;EAChC,OAAO,UAAUC,IAAoB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IACzFD,GAAG,CAACE,SAAS,CAAC,cAAc,EAAE,IAAAC,oBAAY,EAACL,MAAM,
|
|
1
|
+
{"version":3,"file":"user-agent.js","names":["_config","require","userAgent","config","_req","res","next","setHeader","getUserAgent","user_agent"],"sources":["../../src/middlewares/user-agent.ts"],"sourcesContent":["import { getUserAgent } from '@verdaccio/config';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function userAgent(config) {\n return function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('x-powered-by', getUserAgent(config?.user_agent));\n next();\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIO,SAASC,SAASA,CAACC,MAAM,EAAE;EAChC,OAAO,UAAUC,IAAoB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IACzFD,GAAG,CAACE,SAAS,CAAC,cAAc,EAAE,IAAAC,oBAAY,EAACL,MAAM,EAAEM,UAAU,CAAC,CAAC;IAC/DH,IAAI,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
|
|
@@ -25,7 +25,6 @@ const sendFileCallback = next => err => {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|
28
|
-
var _config$web3, _config$web4, _config$web5, _config$web6;
|
|
29
28
|
const {
|
|
30
29
|
staticPath,
|
|
31
30
|
manifest,
|
|
@@ -42,12 +41,10 @@ function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|
|
42
41
|
|
|
43
42
|
// any match within the static is routed to the file system
|
|
44
43
|
router.get('/-/static/*', function (req, res, next) {
|
|
45
|
-
var _config$web;
|
|
46
44
|
const filename = req.params[0];
|
|
47
45
|
let file = `${staticPath}/${filename}`;
|
|
48
|
-
if (filename === 'favicon.ico' && config
|
|
49
|
-
|
|
50
|
-
file = config === null || config === void 0 || (_config$web2 = config.web) === null || _config$web2 === void 0 ? void 0 : _config$web2.favicon;
|
|
46
|
+
if (filename === 'favicon.ico' && config?.web?.favicon) {
|
|
47
|
+
file = config?.web?.favicon;
|
|
51
48
|
if ((0, _url.isURLhasValidProtocol)(file)) {
|
|
52
49
|
debug('redirect to favicon %s', file);
|
|
53
50
|
req.url = file;
|
|
@@ -86,12 +83,12 @@ function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
|
|
|
86
83
|
}
|
|
87
84
|
return logo;
|
|
88
85
|
}
|
|
89
|
-
const logo = renderLogo(config
|
|
90
|
-
if (config
|
|
86
|
+
const logo = renderLogo(config?.web?.logo);
|
|
87
|
+
if (config?.web?.logo) {
|
|
91
88
|
config.web.logo = logo;
|
|
92
89
|
}
|
|
93
|
-
const logoDark = renderLogo(config
|
|
94
|
-
if (config
|
|
90
|
+
const logoDark = renderLogo(config?.web?.logoDark);
|
|
91
|
+
if (config?.web?.logoDark) {
|
|
95
92
|
config.web.logoDark = logoDark;
|
|
96
93
|
}
|
|
97
94
|
router.get('/-/web/:section/*', function (req, res) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-web.js","names":["_debug","_interopRequireDefault","require","_express","_fs","_path","_core","_url","_security","_renderHTML","e","__esModule","default","debug","buildDebug","sendFileCallback","next","err","status","HTTP_STATUS","NOT_FOUND","renderWebMiddleware","config","tokenMiddleware","pluginOptions","
|
|
1
|
+
{"version":3,"file":"render-web.js","names":["_debug","_interopRequireDefault","require","_express","_fs","_path","_core","_url","_security","_renderHTML","e","__esModule","default","debug","buildDebug","sendFileCallback","next","err","status","HTTP_STATUS","NOT_FOUND","renderWebMiddleware","config","tokenMiddleware","pluginOptions","staticPath","manifest","manifestFiles","router","express","Router","use","setSecurityWebHeaders","get","req","res","filename","params","file","web","favicon","isURLhasValidProtocol","url","sendFile","renderLogo","logo","absoluteLocalFile","path","posix","resolve","fs","existsSync","accessSync","constants","R_OK","join","basename","_req","undefined","logoDark","renderHTML"],"sources":["../../../src/middlewares/web/render-web.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express from 'express';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { isURLhasValidProtocol } from '@verdaccio/url';\n\nimport { setSecurityWebHeaders } from './security';\nimport renderHTML from './utils/renderHTML';\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst sendFileCallback = (next) => (err) => {\n if (!err) {\n return;\n }\n if (err.status === HTTP_STATUS.NOT_FOUND) {\n next();\n } else {\n next(err);\n }\n};\n\nexport function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {\n const { staticPath, manifest, manifestFiles } = pluginOptions;\n debug('static path %o', staticPath);\n\n /* eslint new-cap:off */\n const router = express.Router();\n if (typeof tokenMiddleware === 'function') {\n router.use(tokenMiddleware);\n }\n\n router.use(setSecurityWebHeaders);\n\n // any match within the static is routed to the file system\n router.get('/-/static/*', function (req, res, next) {\n const filename = req.params[0];\n let file = `${staticPath}/${filename}`;\n if (filename === 'favicon.ico' && config?.web?.favicon) {\n file = config?.web?.favicon;\n if (isURLhasValidProtocol(file)) {\n debug('redirect to favicon %s', file);\n req.url = file;\n return next();\n }\n }\n debug('render static file %o', file);\n res.sendFile(file, sendFileCallback(next));\n });\n\n function renderLogo(logo: string | undefined): string | undefined {\n // check the origin of the logo\n if (logo && !isURLhasValidProtocol(logo)) {\n // URI related to a local file\n const absoluteLocalFile = path.posix.resolve(logo);\n debug('serve local logo %s', absoluteLocalFile);\n try {\n // TODO: replace existsSync by async alternative\n if (\n fs.existsSync(absoluteLocalFile) &&\n typeof fs.accessSync(absoluteLocalFile, fs.constants.R_OK) === 'undefined'\n ) {\n // Note: `path.join` will break on Windows, because it transforms `/` to `\\`\n // Use POSIX version `path.posix.join` instead.\n logo = path.posix.join('/-/static/', path.basename(logo));\n router.get(logo, function (_req, res, next) {\n // @ts-ignore\n debug('serve custom logo web:%s - local:%s', logo, absoluteLocalFile);\n res.sendFile(absoluteLocalFile, sendFileCallback(next));\n });\n debug('enabled custom logo %s', logo);\n } else {\n logo = undefined;\n debug(`web logo is wrong, path ${absoluteLocalFile} does not exist or is not readable`);\n }\n } catch {\n logo = undefined;\n debug(`web logo is wrong, path ${absoluteLocalFile} does not exist or is not readable`);\n }\n }\n return logo;\n }\n\n const logo = renderLogo(config?.web?.logo);\n if (config?.web?.logo) {\n config.web.logo = logo;\n }\n const logoDark = renderLogo(config?.web?.logoDark);\n if (config?.web?.logoDark) {\n config.web.logoDark = logoDark;\n }\n\n router.get('/-/web/:section/*', function (req, res) {\n renderHTML(config, manifest, manifestFiles, req, res);\n debug('render html section');\n });\n\n router.get('/', function (req, res) {\n renderHTML(config, manifest, manifestFiles, req, res);\n debug('render root');\n });\n\n return router;\n}\n"],"mappings":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EAAEO,GAAG,EAAEC,GAAG,CAAC;IACrDtB,KAAK,CAAC,aAAa,CAAC;EACtB,CAAC,CAAC;EAEF,OAAOe,MAAM;AACf","ignoreList":[]}
|
|
@@ -8,7 +8,7 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
const debug = (0, _debug.default)('verdaccio:middleware:web:render:manifest');
|
|
10
10
|
function getManifestValue(manifestItems, manifest, basePath = '') {
|
|
11
|
-
return manifestItems
|
|
11
|
+
return manifestItems?.map(item => {
|
|
12
12
|
debug('resolve item %o', item);
|
|
13
13
|
const resolvedItem = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;
|
|
14
14
|
debug('resolved item %o', resolvedItem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","names":["_debug","_interopRequireDefault","require","e","__esModule","default","debug","buildDebug","getManifestValue","manifestItems","manifest","basePath","map","item","resolvedItem","stripTrailingSlash","stripLeadingSlash","path","replace"],"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 = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;\n debug('resolved item %o', resolvedItem);\n return resolvedItem;\n });\n}\n\nfunction stripTrailingSlash(path: string): string {\n return path.replace(/\\/$/, '');\n}\n\nfunction stripLeadingSlash(path: string): string {\n return path.replace(/^\\//, '');\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;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,
|
|
1
|
+
{"version":3,"file":"manifest.js","names":["_debug","_interopRequireDefault","require","e","__esModule","default","debug","buildDebug","getManifestValue","manifestItems","manifest","basePath","map","item","resolvedItem","stripTrailingSlash","stripLeadingSlash","path","replace"],"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 = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;\n debug('resolved item %o', resolvedItem);\n return resolvedItem;\n });\n}\n\nfunction stripTrailingSlash(path: string): string {\n return path.replace(/\\/$/, '');\n}\n\nfunction stripLeadingSlash(path: string): string {\n return path.replace(/^\\//, '');\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;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,EAAEG,GAAG,CAAEC,IAAI,IAAK;IAClCP,KAAK,CAAC,iBAAiB,EAAEO,IAAI,CAAC;IAC9B,MAAMC,YAAY,GAAG,GAAGC,kBAAkB,CAACJ,QAAQ,CAAC,IAAIK,iBAAiB,CAACN,QAAQ,CAACG,IAAI,CAAC,CAAC,EAAE;IAC3FP,KAAK,CAAC,kBAAkB,EAAEQ,YAAY,CAAC;IACvC,OAAOA,YAAY;EACrB,CAAC,CAAC;AACJ;AAEA,SAASC,kBAAkBA,CAACE,IAAY,EAAU;EAChD,OAAOA,IAAI,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAChC;AAEA,SAASF,iBAAiBA,CAACC,IAAY,EAAU;EAC/C,OAAOA,IAAI,CAACC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAChC","ignoreList":[]}
|
|
@@ -40,31 +40,30 @@ function resolveLogo(logo, url_prefix, requestOptions) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
function renderHTML(config, manifest, manifestFiles, requestOptions, res) {
|
|
43
|
-
var _config$i18n$web, _config$i18n, _config$web$hideDepre, _config$web, _config$web2, _config$web3, _config$web$darkMode, _config$web4, _config$web$title, _config$web5, _config$web$scope, _config$web6, _config$web7, _config$web8, _config$web9, _config$web$pkgManage, _config$web10, _res$locals$app_versi, _validatePrimaryColor, _config$web$primary_c, _config$web11, _config$web12;
|
|
44
43
|
const {
|
|
45
44
|
url_prefix
|
|
46
45
|
} = config;
|
|
47
|
-
const base = (0, _url2.getPublicUrl)(config
|
|
46
|
+
const base = (0, _url2.getPublicUrl)(config?.url_prefix, requestOptions);
|
|
48
47
|
const basename = new _url.URL(base).pathname;
|
|
49
|
-
const language =
|
|
50
|
-
const hideDeprecatedVersions =
|
|
48
|
+
const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;
|
|
49
|
+
const hideDeprecatedVersions = config?.web?.hideDeprecatedVersions ?? false;
|
|
51
50
|
// @ts-ignore
|
|
52
|
-
const needHtmlCache = [undefined, null].includes(config
|
|
53
|
-
const darkMode =
|
|
54
|
-
const title =
|
|
51
|
+
const needHtmlCache = [undefined, null].includes(config?.web?.html_cache) ? true : config?.web?.html_cache;
|
|
52
|
+
const darkMode = config?.web?.darkMode ?? false;
|
|
53
|
+
const title = config?.web?.title ?? _config.WEB_TITLE;
|
|
55
54
|
const login = (0, _webUtils.hasLogin)(config);
|
|
56
|
-
const scope =
|
|
57
|
-
const favicon = resolveLogo(config
|
|
58
|
-
const logo = resolveLogo(config
|
|
59
|
-
const logoDark = resolveLogo(config
|
|
60
|
-
const pkgManagers =
|
|
61
|
-
const version =
|
|
55
|
+
const scope = config?.web?.scope ?? '';
|
|
56
|
+
const favicon = resolveLogo(config?.web?.favicon, config?.url_prefix, requestOptions);
|
|
57
|
+
const logo = resolveLogo(config?.web?.logo, config?.url_prefix, requestOptions);
|
|
58
|
+
const logoDark = resolveLogo(config?.web?.logoDark, config?.url_prefix, requestOptions);
|
|
59
|
+
const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];
|
|
60
|
+
const version = res.locals.app_version ?? '';
|
|
62
61
|
const flags = {
|
|
63
62
|
...config.flags,
|
|
64
63
|
// legacy from 5.x
|
|
65
64
|
...config.experiments
|
|
66
65
|
};
|
|
67
|
-
const primaryColor = (
|
|
66
|
+
const primaryColor = (0, _webUtils.validatePrimaryColor)(config?.web?.primary_color ?? config?.web?.primaryColor) ?? '#4b5e40';
|
|
68
67
|
const {
|
|
69
68
|
scriptsBodyAfter,
|
|
70
69
|
metaScripts,
|
|
@@ -81,7 +80,7 @@ function renderHTML(config, manifest, manifestFiles, requestOptions, res) {
|
|
|
81
80
|
scriptsBodyAfter: [],
|
|
82
81
|
bodyBefore: [],
|
|
83
82
|
metaScripts: []
|
|
84
|
-
}, config
|
|
83
|
+
}, config?.web);
|
|
85
84
|
const options = {
|
|
86
85
|
showInfo,
|
|
87
86
|
showSettings,
|
|
@@ -113,7 +112,7 @@ function renderHTML(config, manifest, manifestFiles, requestOptions, res) {
|
|
|
113
112
|
webPage = cache.get('template');
|
|
114
113
|
if (!webPage) {
|
|
115
114
|
webPage = (0, _template.default)({
|
|
116
|
-
manifest: manifestFiles
|
|
115
|
+
manifest: manifestFiles ?? defaultManifestFiles,
|
|
117
116
|
options,
|
|
118
117
|
scriptsBodyAfter,
|
|
119
118
|
metaScripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderHTML.js","names":["_debug","_interopRequireDefault","require","_lruCache","_path","_url","_config","_core","_url2","_template","_webUtils","e","__esModule","default","DEFAULT_LANGUAGE","cache","LRU","max","ttl","debug","buildDebug","defaultManifestFiles","js","ico","css","resolveLogo","logo","url_prefix","requestOptions","isLocalFile","isURLhasValidProtocol","getPublicUrl","path","basename","renderHTML","config","manifest","manifestFiles","res","_config$i18n$web","_config$i18n","_config$web$hideDepre","_config$web","_config$web2","_config$web3","_config$web$darkMode","_config$web4","_config$web$title","_config$web5","_config$web$scope","_config$web6","_config$web7","_config$web8","_config$web9","_config$web$pkgManage","_config$web10","_res$locals$app_versi","_validatePrimaryColor","_config$web$primary_c","_config$web11","_config$web12","base","URL","pathname","language","i18n","web","hideDeprecatedVersions","needHtmlCache","undefined","includes","html_cache","darkMode","title","WEB_TITLE","login","hasLogin","scope","favicon","logoDark","pkgManagers","version","locals","app_version","flags","experiments","primaryColor","validatePrimaryColor","primary_color","scriptsBodyAfter","metaScripts","scriptsbodyBefore","showInfo","showSettings","showThemeSwitch","showFooter","showSearch","showDownloadTarball","showRaw","showUplinks","Object","assign","bodyBefore","options","webPage","get","renderTemplate","set","error","Error","stack","setHeader","HEADERS","TEXT_HTML","send"],"sources":["../../../../src/middlewares/web/utils/renderHTML.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Response } from 'express';\nimport LRU from 'lru-cache';\nimport path from 'path';\nimport { URL } from 'url';\n\nimport { WEB_TITLE } from '@verdaccio/config';\nimport { HEADERS } from '@verdaccio/core';\nimport { ConfigYaml, TemplateUIOptions } from '@verdaccio/types';\nimport type { RequestOptions } from '@verdaccio/url';\nimport { getPublicUrl, isURLhasValidProtocol } from '@verdaccio/url';\n\nimport type { Manifest } from './manifest';\nimport renderTemplate from './template';\nimport type { WebpackManifest } from './template';\nimport { hasLogin, validatePrimaryColor } from './web-utils';\n\nconst DEFAULT_LANGUAGE = 'es-US';\nconst cache = new LRU({ max: 500, ttl: 1000 * 60 * 60 });\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst defaultManifestFiles: Manifest = {\n js: ['runtime.js', 'vendors.js', 'main.js'],\n ico: 'favicon.ico',\n css: [],\n};\n\nexport function resolveLogo(\n logo: string | undefined,\n url_prefix: string | undefined,\n requestOptions: RequestOptions\n) {\n if (typeof logo !== 'string') {\n return '';\n }\n const isLocalFile = logo && !isURLhasValidProtocol(logo);\n\n if (isLocalFile) {\n return `${getPublicUrl(url_prefix, requestOptions)}-/static/${path.basename(logo)}`;\n } else if (isURLhasValidProtocol(logo)) {\n return logo;\n } else {\n return '';\n }\n}\n\nexport default function renderHTML(\n config: ConfigYaml,\n manifest: WebpackManifest,\n manifestFiles: Manifest | null | undefined,\n requestOptions: RequestOptions,\n res: Response\n) {\n const { url_prefix } = config;\n const base = getPublicUrl(config?.url_prefix, requestOptions);\n const basename = new URL(base).pathname;\n const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;\n const hideDeprecatedVersions = config?.web?.hideDeprecatedVersions ?? false;\n // @ts-ignore\n const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)\n ? true\n : config?.web?.html_cache;\n const darkMode = config?.web?.darkMode ?? false;\n const title = config?.web?.title ?? WEB_TITLE;\n const login = hasLogin(config);\n const scope = config?.web?.scope ?? '';\n const favicon = resolveLogo(config?.web?.favicon, config?.url_prefix, requestOptions);\n const logo = resolveLogo(config?.web?.logo, config?.url_prefix, requestOptions);\n const logoDark = resolveLogo(config?.web?.logoDark, config?.url_prefix, requestOptions);\n const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];\n const version = res.locals.app_version ?? '';\n const flags = {\n ...config.flags,\n // legacy from 5.x\n ...config.experiments,\n };\n const primaryColor =\n validatePrimaryColor(config?.web?.primary_color ?? config?.web?.primaryColor) ?? '#4b5e40';\n const {\n scriptsBodyAfter,\n metaScripts,\n scriptsbodyBefore,\n showInfo,\n showSettings,\n showThemeSwitch,\n showFooter,\n showSearch,\n showDownloadTarball,\n showRaw,\n showUplinks,\n } = Object.assign(\n {},\n {\n scriptsBodyAfter: [],\n bodyBefore: [],\n metaScripts: [],\n },\n config?.web\n );\n const options: TemplateUIOptions = {\n showInfo,\n showSettings,\n showThemeSwitch,\n showFooter,\n showSearch,\n showDownloadTarball,\n showRaw,\n showUplinks,\n darkMode,\n url_prefix,\n basename,\n base,\n primaryColor,\n version,\n logo,\n logoDark,\n favicon,\n flags,\n login,\n pkgManagers,\n title,\n scope,\n language,\n hideDeprecatedVersions,\n };\n\n let webPage;\n\n try {\n webPage = cache.get('template');\n if (!webPage) {\n webPage = renderTemplate(\n {\n manifest: manifestFiles ?? defaultManifestFiles,\n options,\n scriptsBodyAfter,\n metaScripts,\n scriptsbodyBefore,\n },\n manifest\n );\n\n if (needHtmlCache) {\n cache.set('template', webPage);\n debug('set template cache');\n }\n } else {\n debug('reuse template cache');\n }\n } catch (error: any) {\n throw new Error(`theme could not be load, stack ${error.stack}`);\n }\n res.setHeader('Content-Type', HEADERS.TEXT_HTML);\n res.send(webPage);\n debug('web rendered');\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAGA,IAAAM,KAAA,GAAAN,OAAA;AAGA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEA,IAAAQ,SAAA,GAAAR,OAAA;AA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AI;IACJyB,YAAY;IACZL,OAAO;IACPvD,IAAI;IACJqD,QAAQ;IACRD,OAAO;IACPM,KAAK;IACLT,KAAK;IACLK,WAAW;IACXP,KAAK;IACLI,KAAK;IACLb,QAAQ;IACRG;EACF,CAAC;EAED,IAAIqC,OAAO;EAEX,IAAI;IACFA,OAAO,GAAGzF,KAAK,CAAC0F,GAAG,CAAC,UAAU,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACZA,OAAO,GAAG,IAAAE,iBAAc,EACtB;QACEtE,QAAQ,EAAEC,aAAa,aAAbA,aAAa,cAAbA,aAAa,GAAIhB,oBAAoB;QAC/CkF,OAAO;QACPd,gBAAgB;QAChBC,WAAW;QACXC;MACF,CAAC,EACDvD,QACF,CAAC;MAED,IAAIgC,aAAa,EAAE;QACjBrD,KAAK,CAAC4F,GAAG,CAAC,UAAU,EAAEH,OAAO,CAAC;QAC9BrF,KAAK,CAAC,oBAAoB,CAAC;MAC7B;IACF,CAAC,MAAM;MACLA,KAAK,CAAC,sBAAsB,CAAC;IAC/B;EACF,CAAC,CAAC,OAAOyF,KAAU,EAAE;IACnB,MAAM,IAAIC,KAAK,CAAC,kCAAkCD,KAAK,CAACE,KAAK,EAAE,CAAC;EAClE;EACAxE,GAAG,CAACyE,SAAS,CAAC,cAAc,EAAEC,aAAO,CAACC,SAAS,CAAC;EAChD3E,GAAG,CAAC4E,IAAI,CAACV,OAAO,CAAC;EACjBrF,KAAK,CAAC,cAAc,CAAC;AACvB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"renderHTML.js","names":["_debug","_interopRequireDefault","require","_lruCache","_path","_url","_config","_core","_url2","_template","_webUtils","e","__esModule","default","DEFAULT_LANGUAGE","cache","LRU","max","ttl","debug","buildDebug","defaultManifestFiles","js","ico","css","resolveLogo","logo","url_prefix","requestOptions","isLocalFile","isURLhasValidProtocol","getPublicUrl","path","basename","renderHTML","config","manifest","manifestFiles","res","base","URL","pathname","language","i18n","web","hideDeprecatedVersions","needHtmlCache","undefined","includes","html_cache","darkMode","title","WEB_TITLE","login","hasLogin","scope","favicon","logoDark","pkgManagers","version","locals","app_version","flags","experiments","primaryColor","validatePrimaryColor","primary_color","scriptsBodyAfter","metaScripts","scriptsbodyBefore","showInfo","showSettings","showThemeSwitch","showFooter","showSearch","showDownloadTarball","showRaw","showUplinks","Object","assign","bodyBefore","options","webPage","get","renderTemplate","set","error","Error","stack","setHeader","HEADERS","TEXT_HTML","send"],"sources":["../../../../src/middlewares/web/utils/renderHTML.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Response } from 'express';\nimport LRU from 'lru-cache';\nimport path from 'path';\nimport { URL } from 'url';\n\nimport { WEB_TITLE } from '@verdaccio/config';\nimport { HEADERS } from '@verdaccio/core';\nimport { ConfigYaml, TemplateUIOptions } from '@verdaccio/types';\nimport type { RequestOptions } from '@verdaccio/url';\nimport { getPublicUrl, isURLhasValidProtocol } from '@verdaccio/url';\n\nimport type { Manifest } from './manifest';\nimport renderTemplate from './template';\nimport type { WebpackManifest } from './template';\nimport { hasLogin, validatePrimaryColor } from './web-utils';\n\nconst DEFAULT_LANGUAGE = 'es-US';\nconst cache = new LRU({ max: 500, ttl: 1000 * 60 * 60 });\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst defaultManifestFiles: Manifest = {\n js: ['runtime.js', 'vendors.js', 'main.js'],\n ico: 'favicon.ico',\n css: [],\n};\n\nexport function resolveLogo(\n logo: string | undefined,\n url_prefix: string | undefined,\n requestOptions: RequestOptions\n) {\n if (typeof logo !== 'string') {\n return '';\n }\n const isLocalFile = logo && !isURLhasValidProtocol(logo);\n\n if (isLocalFile) {\n return `${getPublicUrl(url_prefix, requestOptions)}-/static/${path.basename(logo)}`;\n } else if (isURLhasValidProtocol(logo)) {\n return logo;\n } else {\n return '';\n }\n}\n\nexport default function renderHTML(\n config: ConfigYaml,\n manifest: WebpackManifest,\n manifestFiles: Manifest | null | undefined,\n requestOptions: RequestOptions,\n res: Response\n) {\n const { url_prefix } = config;\n const base = getPublicUrl(config?.url_prefix, requestOptions);\n const basename = new URL(base).pathname;\n const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;\n const hideDeprecatedVersions = config?.web?.hideDeprecatedVersions ?? false;\n // @ts-ignore\n const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)\n ? true\n : config?.web?.html_cache;\n const darkMode = config?.web?.darkMode ?? false;\n const title = config?.web?.title ?? WEB_TITLE;\n const login = hasLogin(config);\n const scope = config?.web?.scope ?? '';\n const favicon = resolveLogo(config?.web?.favicon, config?.url_prefix, requestOptions);\n const logo = resolveLogo(config?.web?.logo, config?.url_prefix, requestOptions);\n const logoDark = resolveLogo(config?.web?.logoDark, config?.url_prefix, requestOptions);\n const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];\n const version = res.locals.app_version ?? '';\n const flags = {\n ...config.flags,\n // legacy from 5.x\n ...config.experiments,\n };\n const primaryColor =\n validatePrimaryColor(config?.web?.primary_color ?? config?.web?.primaryColor) ?? '#4b5e40';\n const {\n scriptsBodyAfter,\n metaScripts,\n scriptsbodyBefore,\n showInfo,\n showSettings,\n showThemeSwitch,\n showFooter,\n showSearch,\n showDownloadTarball,\n showRaw,\n showUplinks,\n } = Object.assign(\n {},\n {\n scriptsBodyAfter: [],\n bodyBefore: [],\n metaScripts: [],\n },\n config?.web\n );\n const options: TemplateUIOptions = {\n showInfo,\n showSettings,\n showThemeSwitch,\n showFooter,\n showSearch,\n showDownloadTarball,\n showRaw,\n showUplinks,\n darkMode,\n url_prefix,\n basename,\n base,\n primaryColor,\n version,\n logo,\n logoDark,\n favicon,\n flags,\n login,\n pkgManagers,\n title,\n scope,\n language,\n hideDeprecatedVersions,\n };\n\n let webPage;\n\n try {\n webPage = cache.get('template');\n if (!webPage) {\n webPage = renderTemplate(\n {\n manifest: manifestFiles ?? defaultManifestFiles,\n options,\n scriptsBodyAfter,\n metaScripts,\n scriptsbodyBefore,\n },\n manifest\n );\n\n if (needHtmlCache) {\n cache.set('template', webPage);\n debug('set template cache');\n }\n } else {\n debug('reuse template cache');\n }\n } catch (error: any) {\n throw new Error(`theme could not be load, stack ${error.stack}`);\n }\n res.setHeader('Content-Type', HEADERS.TEXT_HTML);\n res.send(webPage);\n debug('web rendered');\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAGA,IAAAM,KAAA,GAAAN,OAAA;AAGA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEA,IAAAQ,SAAA,GAAAR,OAAA;AAA6D,SAAAD,uBAAAU,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE7D,MAAMG,gBAAgB,GAAG,OAAO;AAChC,MAAMC,KAAK,GAAG,IAAIC,iBAAG,CAAC;EAAEC,GAAG,EAAE,GAAG;EAAEC,GAAG,EAAE,IAAI,GAAG,EAAE,GAAG;AAAG,CAAC,CAAC;AAExD,MAAMC,KAAK,GAAG,IAAAC,cAAU,EAAC,sBAAsB,CAAC;AAEhD,MAAMC,oBAA8B,GAAG;EACrCC,EAAE,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,SAAS,CAAC;EAC3CC,GAAG,EAAE,aAAa;EAClBC,GAAG,EAAE;AACP,CAAC;AAEM,SAASC,WAAWA,CACzBC,IAAwB,EACxBC,UAA8B,EAC9BC,cAA8B,EAC9B;EACA,IAAI,OAAOF,IAAI,KAAK,QAAQ,EAAE;IAC5B,OAAO,EAAE;EACX;EACA,MAAMG,WAAW,GAAGH,IAAI,IAAI,CAAC,IAAAI,2BAAqB,EAACJ,IA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B,YAAY;IACZL,OAAO;IACPjC,IAAI;IACJ+B,QAAQ;IACRD,OAAO;IACPM,KAAK;IACLT,KAAK;IACLK,WAAW;IACXP,KAAK;IACLI,KAAK;IACLb,QAAQ;IACRG;EACF,CAAC;EAED,IAAIqC,OAAO;EAEX,IAAI;IACFA,OAAO,GAAGnE,KAAK,CAACoE,GAAG,CAAC,UAAU,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACZA,OAAO,GAAG,IAAAE,iBAAc,EACtB;QACEhD,QAAQ,EAAEC,aAAa,IAAIhB,oBAAoB;QAC/C4D,OAAO;QACPd,gBAAgB;QAChBC,WAAW;QACXC;MACF,CAAC,EACDjC,QACF,CAAC;MAED,IAAIU,aAAa,EAAE;QACjB/B,KAAK,CAACsE,GAAG,CAAC,UAAU,EAAEH,OAAO,CAAC;QAC9B/D,KAAK,CAAC,oBAAoB,CAAC;MAC7B;IACF,CAAC,MAAM;MACLA,KAAK,CAAC,sBAAsB,CAAC;IAC/B;EACF,CAAC,CAAC,OAAOmE,KAAU,EAAE;IACnB,MAAM,IAAIC,KAAK,CAAC,kCAAkCD,KAAK,CAACE,KAAK,EAAE,CAAC;EAClE;EACAlD,GAAG,CAACmD,SAAS,CAAC,cAAc,EAAEC,aAAO,CAACC,SAAS,CAAC;EAChDrD,GAAG,CAACsD,IAAI,CAACV,OAAO,CAAC;EACjB/D,KAAK,CAAC,cAAc,CAAC;AACvB","ignoreList":[]}
|
|
@@ -12,7 +12,6 @@ const debug = (0, _debug.default)('verdaccio:web:render:template');
|
|
|
12
12
|
// the outcome of the Webpack Manifest Plugin
|
|
13
13
|
|
|
14
14
|
function renderTemplate(template, manifest) {
|
|
15
|
-
var _template$options$tit, _template$options;
|
|
16
15
|
debug('template %o', template);
|
|
17
16
|
debug('manifest %o', manifest);
|
|
18
17
|
return `
|
|
@@ -20,20 +19,20 @@ function renderTemplate(template, manifest) {
|
|
|
20
19
|
<html lang="en-us">
|
|
21
20
|
<head>
|
|
22
21
|
<meta charset="utf-8">
|
|
23
|
-
<base href="${template
|
|
24
|
-
<title>${
|
|
25
|
-
<link rel="icon" href="${template
|
|
22
|
+
<base href="${template?.options.base}">
|
|
23
|
+
<title>${template?.options?.title ?? ''}</title>
|
|
24
|
+
<link rel="icon" href="${template?.options.base}-/static/favicon.ico"/>
|
|
26
25
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
27
26
|
<script>
|
|
28
27
|
window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(template.options)}
|
|
29
28
|
</script>
|
|
30
|
-
${template
|
|
29
|
+
${template?.metaScripts ? template.metaScripts.join('') : ''}
|
|
31
30
|
</head>
|
|
32
31
|
<body class="body">
|
|
33
|
-
${template
|
|
32
|
+
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
|
|
34
33
|
<div id="root"></div>
|
|
35
|
-
${(0, _manifest.getManifestValue)(template.manifest.js, manifest, template
|
|
36
|
-
${template
|
|
34
|
+
${(0, _manifest.getManifestValue)(template.manifest.js, manifest, template?.options.base).map(item => `<script defer="defer" src="${item}"></script>`).join(`\n `)}
|
|
35
|
+
${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
|
|
37
36
|
</body>
|
|
38
37
|
</html>
|
|
39
38
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","names":["_debug","_interopRequireDefault","require","_manifest","e","__esModule","default","debug","buildDebug","renderTemplate","template","manifest","
|
|
1
|
+
{"version":3,"file":"template.js","names":["_debug","_interopRequireDefault","require","_manifest","e","__esModule","default","debug","buildDebug","renderTemplate","template","manifest","options","base","title","JSON","stringify","metaScripts","join","scriptsbodyBefore","getManifestValue","js","map","item","scriptsBodyAfter"],"sources":["../../../../src/middlewares/web/utils/template.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { TemplateUIOptions } from '@verdaccio/types';\n\nimport { Manifest, getManifestValue } from './manifest';\n\nconst debug = buildDebug('verdaccio:web:render:template');\n\nexport type Template = {\n manifest: Manifest;\n options: TemplateUIOptions;\n metaScripts?: string[];\n scriptsBodyAfter?: string[];\n scriptsbodyBefore?: string[];\n};\n\n// the outcome of the Webpack Manifest Plugin\nexport interface WebpackManifest {\n [key: string]: string;\n}\n\nexport default function renderTemplate(template: Template, manifest: WebpackManifest) {\n debug('template %o', template);\n debug('manifest %o', manifest);\n\n return `\n <!DOCTYPE html>\n <html lang=\"en-us\">\n <head>\n <meta charset=\"utf-8\">\n <base href=\"${template?.options.base}\">\n <title>${template?.options?.title ?? ''}</title>\n <link rel=\"icon\" href=\"${template?.options.base}-/static/favicon.ico\"/>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <script>\n window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(template.options)}\n </script>\n ${template?.metaScripts ? template.metaScripts.join('') : ''}\n </head>\n <body class=\"body\">\n ${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}\n <div id=\"root\"></div>\n ${getManifestValue(template.manifest.js, manifest, template?.options.base)\n .map((item) => `<script defer=\"defer\" src=\"${item}\"></script>`)\n .join(`\\n `)}\n ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}\n </body>\n </html>\n `;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AAAwD,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAExD,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;;AAUzD;;AAKe,SAASC,cAAcA,CAACC,QAAkB,EAAEC,QAAyB,EAAE;EACpFJ,KAAK,CAAC,aAAa,EAAEG,QAAQ,CAAC;EAC9BH,KAAK,CAAC,aAAa,EAAEI,QAAQ,CAAC;EAE9B,OAAO;AACT;AACA;AACA;AACA;AACA,sBAAsBD,QAAQ,EAAEE,OAAO,CAACC,IAAI;AAC5C,iBAAiBH,QAAQ,EAAEE,OAAO,EAAEE,KAAK,IAAI,EAAE;AAC/C,iCAAiCJ,QAAQ,EAAEE,OAAO,CAACC,IAAI;AACvD;AACA;AACA,qDAAqDE,IAAI,CAACC,SAAS,CAACN,QAAQ,CAACE,OAAO,CAAC;AACrF;AACA,UAAUF,QAAQ,EAAEO,WAAW,GAAGP,QAAQ,CAACO,WAAW,CAACC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AACpE;AACA;AACA,UAAUR,QAAQ,EAAES,iBAAiB,GAAGT,QAAQ,CAACS,iBAAiB,CAACD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AAChF;AACA,UAAU,IAAAE,0BAAgB,EAACV,QAAQ,CAACC,QAAQ,CAACU,EAAE,EAAEV,QAAQ,EAAED,QAAQ,EAAEE,OAAO,CAACC,IAAI,CAAC,CACvES,GAAG,CAAEC,IAAI,IAAK,8BAA8BA,IAAI,aAAa,CAAC,CAC9DL,IAAI,CAAC,YAAY,CAAC;AAC7B,UAAUR,QAAQ,EAAEc,gBAAgB,GAAGd,QAAQ,CAACc,gBAAgB,CAACN,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AAC9E;AACA;AACA,GAAG;AACH","ignoreList":[]}
|
|
@@ -18,7 +18,6 @@ function validatePrimaryColor(primaryColor) {
|
|
|
18
18
|
return primaryColor;
|
|
19
19
|
}
|
|
20
20
|
function hasLogin(config) {
|
|
21
|
-
|
|
22
|
-
return _lodash.default.isNil(config === null || config === void 0 || (_config$web = config.web) === null || _config$web === void 0 ? void 0 : _config$web.login) || (config === null || config === void 0 || (_config$web2 = config.web) === null || _config$web2 === void 0 ? void 0 : _config$web2.login) === true;
|
|
21
|
+
return _lodash.default.isNil(config?.web?.login) || config?.web?.login === true;
|
|
23
22
|
}
|
|
24
23
|
//# sourceMappingURL=web-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-utils.js","names":["_debug","_interopRequireDefault","require","_lodash","e","__esModule","default","debug","buildDebug","validatePrimaryColor","primaryColor","isHex","test","hasLogin","config","
|
|
1
|
+
{"version":3,"file":"web-utils.js","names":["_debug","_interopRequireDefault","require","_lodash","e","__esModule","default","debug","buildDebug","validatePrimaryColor","primaryColor","isHex","test","hasLogin","config","_","isNil","web","login"],"sources":["../../../../src/middlewares/web/utils/web-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nconst debug = buildDebug('verdaccio:web:middlwares');\n\nexport function validatePrimaryColor(primaryColor) {\n const isHex = /^#([0-9A-F]{3}){1,2}$/i.test(primaryColor);\n if (!isHex) {\n debug('invalid primary color %o', primaryColor);\n return;\n }\n\n return primaryColor;\n}\n\nexport function hasLogin(config: any) {\n return _.isNil(config?.web?.login) || config?.web?.login === true;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAuB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEvB,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,0BAA0B,CAAC;AAE7C,SAASC,oBAAoBA,CAACC,YAAY,EAAE;EACjD,MAAMC,KAAK,GAAG,wBAAwB,CAACC,IAAI,CAACF,YAAY,CAAC;EACzD,IAAI,CAACC,KAAK,EAAE;IACVJ,KAAK,CAAC,0BAA0B,EAAEG,YAAY,CAAC;IAC/C;EACF;EAEA,OAAOA,YAAY;AACrB;AAEO,SAASG,QAAQA,CAACC,MAAW,EAAE;EACpC,OAAOC,eAAC,CAACC,KAAK,CAACF,MAAM,EAAEG,GAAG,EAAEC,KAAK,CAAC,IAAIJ,MAAM,EAAEG,GAAG,EAAEC,KAAK,KAAK,IAAI;AACnE","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/middleware",
|
|
3
|
-
"version": "8.0.0-next-8.
|
|
3
|
+
"version": "8.0.0-next-8.2",
|
|
4
4
|
"description": "express middleware utils",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"verdaccio"
|
|
27
27
|
],
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=18"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@verdaccio/config": "8.0.0-next-8.
|
|
33
|
-
"@verdaccio/core": "8.0.0-next-8.
|
|
34
|
-
"@verdaccio/url": "13.0.0-next-8.
|
|
35
|
-
"@verdaccio/utils": "7.0
|
|
32
|
+
"@verdaccio/config": "8.0.0-next-8.2",
|
|
33
|
+
"@verdaccio/core": "8.0.0-next-8.2",
|
|
34
|
+
"@verdaccio/url": "13.0.0-next-8.2",
|
|
35
|
+
"@verdaccio/utils": "7.1.0-next-8.2",
|
|
36
36
|
"debug": "4.3.7",
|
|
37
37
|
"express": "4.21.0",
|
|
38
38
|
"express-rate-limit": "5.5.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"url": "https://opencollective.com/verdaccio"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@verdaccio/logger": "8.0.0-next-8.
|
|
48
|
+
"@verdaccio/logger": "8.0.0-next-8.2",
|
|
49
49
|
"body-parser": "1.20.3",
|
|
50
50
|
"supertest": "7.0.0"
|
|
51
51
|
},
|
package/src/middlewares/allow.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import buildDebug from 'debug';
|
|
2
|
+
|
|
1
3
|
import { API_ERROR, errorUtils } from '@verdaccio/core';
|
|
2
4
|
import { getVersionFromTarball } from '@verdaccio/utils';
|
|
3
5
|
|
|
4
6
|
import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';
|
|
5
7
|
|
|
8
|
+
const debug = buildDebug('verdaccio:middleware:allow');
|
|
9
|
+
|
|
6
10
|
export function allow<T>(
|
|
7
11
|
auth: T,
|
|
8
12
|
options = {
|
|
@@ -21,22 +25,33 @@ export function allow<T>(
|
|
|
21
25
|
: req.params.package;
|
|
22
26
|
const packageVersion = req.params.filename
|
|
23
27
|
? getVersionFromTarball(req.params.filename)
|
|
24
|
-
:
|
|
25
|
-
|
|
28
|
+
: req.params.version
|
|
29
|
+
? req.params.version
|
|
30
|
+
: undefined;
|
|
31
|
+
const remote_user = req.remote_user;
|
|
32
|
+
debug(
|
|
33
|
+
'check if user %o can %o package %o version %o',
|
|
34
|
+
remote_user?.name,
|
|
35
|
+
action,
|
|
36
|
+
packageName,
|
|
37
|
+
packageVersion
|
|
38
|
+
);
|
|
26
39
|
beforeAll?.(
|
|
27
|
-
{ action, user:
|
|
40
|
+
{ action, user: remote_user?.name },
|
|
28
41
|
`[middleware/allow][@{action}] allow for @{user}`
|
|
29
42
|
);
|
|
30
43
|
auth['allow_' + action](
|
|
31
44
|
{ packageName, packageVersion },
|
|
32
|
-
|
|
45
|
+
remote_user,
|
|
33
46
|
function (error, allowed): void {
|
|
34
47
|
req.resume();
|
|
35
48
|
if (error) {
|
|
49
|
+
debug('user is NOT allowed to %o', action);
|
|
36
50
|
next(error);
|
|
37
51
|
} else if (allowed) {
|
|
52
|
+
debug('user is allowed to %o', action);
|
|
38
53
|
afterAll?.(
|
|
39
|
-
{ action, user:
|
|
54
|
+
{ action, user: remote_user?.name },
|
|
40
55
|
`[middleware/allow][@{action}] allowed for @{user}`
|
|
41
56
|
);
|
|
42
57
|
next();
|
package/test/allow.spec.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import request from 'supertest';
|
|
2
2
|
|
|
3
3
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
4
|
-
import { logger, setup } from '@verdaccio/logger';
|
|
5
4
|
|
|
6
5
|
import { allow } from '../src';
|
|
7
6
|
import { getApp } from './helper';
|
|
8
7
|
|
|
9
|
-
setup({});
|
|
10
|
-
|
|
11
8
|
test('should allow request', async () => {
|
|
12
|
-
const can = allow(
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
return cb(null, true);
|
|
16
|
-
},
|
|
9
|
+
const can = allow({
|
|
10
|
+
allow_publish: (params, remove, cb) => {
|
|
11
|
+
return cb(null, true);
|
|
17
12
|
},
|
|
18
|
-
|
|
19
|
-
);
|
|
13
|
+
});
|
|
20
14
|
const app = getApp([]);
|
|
21
15
|
// @ts-ignore
|
|
22
16
|
app.get('/:package', can('publish'), (req, res) => {
|
|
@@ -27,14 +21,11 @@ test('should allow request', async () => {
|
|
|
27
21
|
});
|
|
28
22
|
|
|
29
23
|
test('should allow scope request', async () => {
|
|
30
|
-
const can = allow(
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
return cb(null, true);
|
|
34
|
-
},
|
|
24
|
+
const can = allow({
|
|
25
|
+
allow_publish: (params, remove, cb) => {
|
|
26
|
+
return cb(null, true);
|
|
35
27
|
},
|
|
36
|
-
|
|
37
|
-
);
|
|
28
|
+
});
|
|
38
29
|
const app = getApp([]);
|
|
39
30
|
// @ts-ignore
|
|
40
31
|
app.get('/:package/:scope', can('publish'), (req, res) => {
|
|
@@ -45,14 +36,11 @@ test('should allow scope request', async () => {
|
|
|
45
36
|
});
|
|
46
37
|
|
|
47
38
|
test('should allow filename request', async () => {
|
|
48
|
-
const can = allow(
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
return cb(null, true);
|
|
52
|
-
},
|
|
39
|
+
const can = allow({
|
|
40
|
+
allow_publish: (params, remove, cb) => {
|
|
41
|
+
return cb(null, true);
|
|
53
42
|
},
|
|
54
|
-
|
|
55
|
-
);
|
|
43
|
+
});
|
|
56
44
|
const app = getApp([]);
|
|
57
45
|
// @ts-ignore
|
|
58
46
|
app.get('/:filename', can('publish'), (req, res) => {
|
|
@@ -63,14 +51,11 @@ test('should allow filename request', async () => {
|
|
|
63
51
|
});
|
|
64
52
|
|
|
65
53
|
test('should not allow request', async () => {
|
|
66
|
-
const can = allow(
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
return cb(null, false);
|
|
70
|
-
},
|
|
54
|
+
const can = allow({
|
|
55
|
+
allow_publish: (params, remove, cb) => {
|
|
56
|
+
return cb(null, false);
|
|
71
57
|
},
|
|
72
|
-
|
|
73
|
-
);
|
|
58
|
+
});
|
|
74
59
|
const app = getApp([]);
|
|
75
60
|
// @ts-ignore
|
|
76
61
|
app.get('/sec', can('publish'), (req, res) => {
|
|
@@ -81,17 +66,44 @@ test('should not allow request', async () => {
|
|
|
81
66
|
});
|
|
82
67
|
|
|
83
68
|
test('should handle error request', async () => {
|
|
84
|
-
const can = allow(
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
return cb(Error('foo error'));
|
|
88
|
-
},
|
|
69
|
+
const can = allow({
|
|
70
|
+
allow_publish: (params, remove, cb) => {
|
|
71
|
+
return cb(Error('foo error'));
|
|
89
72
|
},
|
|
90
|
-
|
|
91
|
-
);
|
|
73
|
+
});
|
|
92
74
|
const app = getApp([]);
|
|
93
75
|
// @ts-ignore
|
|
94
76
|
app.get('/err', can('publish'));
|
|
95
77
|
|
|
96
78
|
return request(app).get('/err').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
97
79
|
});
|
|
80
|
+
|
|
81
|
+
test('should allow request with version', async () => {
|
|
82
|
+
const can = allow({
|
|
83
|
+
allow_publish: (params, remove, cb) => {
|
|
84
|
+
return params.packageVersion === '1.0.0' ? cb(null, true) : cb(null, false);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const app = getApp([]);
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
app.get('/:package/:version', can('publish'), (req, res) => {
|
|
90
|
+
res.status(HTTP_STATUS.OK).json({});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return request(app).get('/pacman/1.0.0').expect(HTTP_STATUS.OK);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('should not allow request with version', async () => {
|
|
97
|
+
const can = allow({
|
|
98
|
+
allow_publish: (params, remove, cb) => {
|
|
99
|
+
return params.packageVersion === '1.0.0' ? cb(null, true) : cb(null, false);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const app = getApp([]);
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
app.get('/:package/:version', can('publish'), (req, res) => {
|
|
105
|
+
res.status(HTTP_STATUS.OK).json({});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return request(app).get('/pacman/2.0.0').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
109
|
+
});
|