@verdaccio/server 8.0.0-next-8.3 → 8.0.0-next-8.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,56 @@
1
1
  # @verdaccio/server
2
2
 
3
+ ## 8.0.0-next-8.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 9041b0f: chore: add info to log when audit, htpasswd, theme are used
8
+ - Updated dependencies [ba71932]
9
+ - Updated dependencies [64a7fc0]
10
+ - Updated dependencies [b2339e2]
11
+ - Updated dependencies [9041b0f]
12
+ - Updated dependencies [eca6259]
13
+ - Updated dependencies [4adaa83]
14
+ - Updated dependencies [80e4cb8]
15
+ - Updated dependencies [5cbee6f]
16
+ - Updated dependencies [538bb8f]
17
+ - Updated dependencies [a049bba]
18
+ - Updated dependencies [6e344d0]
19
+ - Updated dependencies [3967a52]
20
+ - @verdaccio/loaders@8.0.0-next-8.4
21
+ - @verdaccio/config@8.0.0-next-8.5
22
+ - @verdaccio/core@8.0.0-next-8.5
23
+ - @verdaccio/web@8.1.0-next-8.5
24
+ - @verdaccio/store@8.0.0-next-8.5
25
+ - @verdaccio/auth@8.0.0-next-8.5
26
+ - @verdaccio/api@8.1.0-next-8.5
27
+ - @verdaccio/logger@8.0.0-next-8.5
28
+ - verdaccio-audit@13.0.0-next-8.5
29
+ - @verdaccio/middleware@8.0.0-next-8.5
30
+ - @verdaccio/utils@8.1.0-next-8.5
31
+
32
+ ## 8.0.0-next-8.4
33
+
34
+ ### Patch Changes
35
+
36
+ - 48aa89f: chore: request header constants
37
+ - e93d6a3: chore: auth package requires logger as parameter
38
+ - Updated dependencies [48aa89f]
39
+ - Updated dependencies [58e0d95]
40
+ - Updated dependencies [1076a89]
41
+ - Updated dependencies [e93d6a3]
42
+ - @verdaccio/middleware@8.0.0-next-8.4
43
+ - @verdaccio/core@8.0.0-next-8.4
44
+ - @verdaccio/api@8.1.0-next-8.4
45
+ - @verdaccio/auth@8.0.0-next-8.4
46
+ - @verdaccio/web@8.1.0-next-8.4
47
+ - @verdaccio/config@8.0.0-next-8.4
48
+ - @verdaccio/loaders@8.0.0-next-8.3
49
+ - verdaccio-audit@13.0.0-next-8.4
50
+ - @verdaccio/store@8.0.0-next-8.4
51
+ - @verdaccio/utils@8.1.0-next-8.4
52
+ - @verdaccio/logger@8.0.0-next-8.4
53
+
3
54
  ## 8.0.0-next-8.3
4
55
 
5
56
  ### Patch Changes
package/build/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { default } from './server';
1
+ export { default, startServer } from './server';
package/build/index.js CHANGED
@@ -9,6 +9,13 @@ Object.defineProperty(exports, "default", {
9
9
  return _server.default;
10
10
  }
11
11
  });
12
- var _server = _interopRequireDefault(require("./server"));
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ Object.defineProperty(exports, "startServer", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _server.startServer;
16
+ }
17
+ });
18
+ var _server = _interopRequireWildcard(require("./server"));
19
+ 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); }
20
+ 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 && {}.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; }
14
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_server","_interopRequireDefault","require","e","__esModule","default"],"sources":["../src/index.ts"],"sourcesContent":["export { default } from './server';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAmC,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_server","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set"],"sources":["../src/index.ts"],"sourcesContent":["export { default, startServer } from './server';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAgD,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA","ignoreList":[]}
package/build/server.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Express } from 'express';
1
2
  import { ConfigYaml } from '@verdaccio/types';
2
- declare const _default: (configHash: ConfigYaml) => Promise<any>;
3
- export default _default;
3
+ declare const startServer: (configHash: ConfigYaml) => Promise<Express>;
4
+ export { startServer };
5
+ export default startServer;
package/build/server.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.startServer = exports.default = void 0;
7
7
  var _compression = _interopRequireDefault(require("compression"));
8
8
  var _cors = _interopRequireDefault(require("cors"));
9
9
  var _debug = _interopRequireDefault(require("debug"));
@@ -26,7 +26,7 @@ const {
26
26
  version
27
27
  } = require('../package.json');
28
28
  const defineAPI = async function (config, storage) {
29
- const auth = new _auth.Auth(config);
29
+ const auth = new _auth.Auth(config, _logger.logger);
30
30
  await auth.init();
31
31
  const app = (0, _express.default)();
32
32
  // run in production mode by default, just in case
@@ -60,15 +60,18 @@ const defineAPI = async function (config, storage) {
60
60
  return typeof plugin.register_middlewares !== 'undefined';
61
61
  }, config?.serverSettings?.pluginPrefix ?? 'verdaccio', _core.PLUGIN_CATEGORY.MIDDLEWARE);
62
62
  if (plugins.length === 0) {
63
- _logger.logger.info('none middleware plugins has been defined, adding audit middleware by default');
64
- // @ts-ignore
65
- plugins.push(new _verdaccioAudit.default({
63
+ const auditPlugin = new _verdaccioAudit.default({
66
64
  enabled: true,
67
65
  strict_ssl: true
68
66
  }, {
69
67
  config,
70
68
  logger: _logger.logger
71
- }));
69
+ });
70
+ _logger.logger.info({
71
+ name: 'verdaccio-audit',
72
+ pluginCategory: _core.PLUGIN_CATEGORY.MIDDLEWARE
73
+ }, 'plugin @{name} successfully loaded (@{pluginCategory})');
74
+ plugins.push(auditPlugin);
72
75
  }
73
76
  plugins.forEach(plugin => {
74
77
  plugin.register_middlewares(app, auth, storage);
@@ -76,7 +79,7 @@ const defineAPI = async function (config, storage) {
76
79
 
77
80
  // For npm request
78
81
  // @ts-ignore
79
- app.use((0, _api.default)(config, auth, storage));
82
+ app.use((0, _api.default)(config, auth, storage, _logger.logger));
80
83
 
81
84
  // For WebUI & WebUI API
82
85
  if (_lodash.default.get(config, 'web.enable', true)) {
@@ -84,7 +87,7 @@ const defineAPI = async function (config, storage) {
84
87
  res.locals.app_version = version ?? '';
85
88
  next();
86
89
  });
87
- const middleware = await (0, _web.default)(config, auth, storage);
90
+ const middleware = await (0, _web.default)(config, auth, storage, _logger.logger);
88
91
  app.use(middleware);
89
92
  } else {
90
93
  app.get('/', function (req, res, next) {
@@ -125,7 +128,7 @@ const defineAPI = async function (config, storage) {
125
128
  app.use(_middleware.final);
126
129
  return app;
127
130
  };
128
- var startServer = exports.default = async function startServer(configHash) {
131
+ const startServer = exports.startServer = async function startServer(configHash) {
129
132
  debug('start server');
130
133
  const config = new _config.Config({
131
134
  ...configHash
@@ -147,4 +150,5 @@ var startServer = exports.default = async function startServer(configHash) {
147
150
  }
148
151
  return await defineAPI(config, storage);
149
152
  };
153
+ var _default = exports.default = startServer;
150
154
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":["_compression","_interopRequireDefault","require","_cors","_debug","_express","_lodash","_verdaccioAudit","_api","_auth","_config","_core","_loaders","_logger","_middleware","_store","_web","_debug2","e","__esModule","default","debug","buildDebug","version","defineAPI","config","storage","auth","Auth","init","app","express","set","process","env","NODE_ENV","server","trustProxy","use","cors","rateLimit","serverSettings","errorReportingMiddlewareWrap","errorReportingMiddleware","logger","log","userAgent","compression","get","req","res","next","url","hookDebug","configPath","plugins","asyncLoadPlugin","middlewares","plugin","register_middlewares","pluginPrefix","PLUGIN_CATEGORY","MIDDLEWARE","length","info","push","AuditMiddleware","enabled","strict_ssl","forEach","apiEndpoint","_","_req","locals","app_version","middleware","webMiddleware","errorUtils","getNotFound","API_ERROR","WEB_DISABLED","handleError","final","startServer","exports","configHash","AppConfig","Storage","err","error","msg","Error"],"sources":["../src/server.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport buildDebug from 'debug';\nimport express from 'express';\nimport _ from 'lodash';\nimport AuditMiddleware from 'verdaccio-audit';\n\nimport apiEndpoint from '@verdaccio/api';\nimport { Auth } from '@verdaccio/auth';\nimport { Config as AppConfig } from '@verdaccio/config';\nimport { API_ERROR, PLUGIN_CATEGORY, errorUtils, pluginUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport {\n errorReportingMiddleware,\n final,\n handleError,\n log,\n rateLimit,\n userAgent,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { ConfigYaml } from '@verdaccio/types';\nimport { Config as IConfig } from '@verdaccio/types';\nimport webMiddleware from '@verdaccio/web';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\nimport hookDebug from './debug';\n\nconst debug = buildDebug('verdaccio:server');\nconst { version } = require('../package.json');\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<any> {\n const auth: Auth = new Auth(config);\n await auth.init();\n const app = express();\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n app.use(cors());\n app.use(rateLimit(config.serverSettings.rateLimit));\n\n const errorReportingMiddlewareWrap = errorReportingMiddleware(logger);\n\n // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddlewareWrap);\n app.use(userAgent(config));\n app.use(compression());\n\n app.get(\n '/favicon.ico',\n function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.url = '/-/static/favicon.ico';\n next();\n }\n );\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n if (plugins.length === 0) {\n logger.info('none middleware plugins has been defined, adding audit middleware by default');\n // @ts-ignore\n plugins.push(new AuditMiddleware({ enabled: true, strict_ssl: true }, { config, logger }));\n }\n\n plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // For npm request\n // @ts-ignore\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage);\n app.use(middleware);\n } else {\n app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n // Catch 404\n app.get('/*', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound('resource not found'));\n });\n\n // @ts-ignore\n app.use(handleError(logger));\n\n // app.use(function (\n // err: HttpError,\n // req: $RequestExtend,\n // res: $ResponseExtend,\n // next: $NextFunctionVer\n // ) {\n // if (_.isError(err)) {\n // if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n // return next();\n // }\n // if (_.isFunction(res.locals.report_error) === false) {\n // // in case of very early error this middleware may not be loaded before error is generated\n // // fixing that\n // errorReportingMiddlewareWrap(req, res, _.noop);\n // }\n // res.locals.report_error(err);\n // } else {\n // // Fall to Middleware.final\n // return next(err);\n // }\n // });\n\n app.use(final);\n\n return app;\n};\n\nexport default (async function startServer(configHash: ConfigYaml): Promise<any> {\n debug('start server');\n const config: IConfig = new AppConfig({ ...configHash } as any);\n // register middleware plugins\n debug('loaded filter plugin');\n // @ts-ignore\n const storage: Storage = new Storage(config, logger);\n try {\n // waits until init calls have been initialized\n debug('storage init start');\n await storage.init(config);\n debug('storage init end');\n } catch (err: any) {\n logger.error({ error: err.msg }, 'storage has failed: @{error}');\n throw new Error(err);\n }\n return await defineAPI(config, storage);\n});\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,eAAA,GAAAN,sBAAA,CAAAC,OAAA;AAEA,IAAAM,IAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,KAAA,GAAAT,OAAA;AACA,IAAAU,QAAA,GAAAV,OAAA;AACA,IAAAW,OAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AAQA,IAAAa,MAAA,GAAAb,OAAA;AAGA,IAAAc,IAAA,GAAAf,sBAAA,CAAAC,OAAA;AAGA,IAAAe,OAAA,GAAAhB,sBAAA,CAAAC,OAAA;AAAgC,SAAAD,uBAAAiB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhC,MAAM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C;IAC1BJ,KAAK,CAAC,kBAAkB,CAAC;EAC3B,CAAC,CAAC,OAAOmE,GAAQ,EAAE;IACjB5C,cAAM,CAAC6C,KAAK,CAAC;MAAEA,KAAK,EAAED,GAAG,CAACE;IAAI,CAAC,EAAE,8BAA8B,CAAC;IAChE,MAAM,IAAIC,KAAK,CAACH,GAAG,CAAC;EACtB;EACA,OAAO,MAAMhE,SAAS,CAACC,MAAM,EAAEC,OAAO,CAAC;AACzC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"server.js","names":["_compression","_interopRequireDefault","require","_cors","_debug","_express","_lodash","_verdaccioAudit","_api","_auth","_config","_core","_loaders","_logger","_middleware","_store","_web","_debug2","e","__esModule","default","debug","buildDebug","version","defineAPI","config","storage","auth","Auth","logger","init","app","express","set","process","env","NODE_ENV","server","trustProxy","use","cors","rateLimit","serverSettings","errorReportingMiddlewareWrap","errorReportingMiddleware","log","userAgent","compression","get","req","res","next","url","hookDebug","configPath","plugins","asyncLoadPlugin","middlewares","plugin","register_middlewares","pluginPrefix","PLUGIN_CATEGORY","MIDDLEWARE","length","auditPlugin","AuditMiddleware","enabled","strict_ssl","info","name","pluginCategory","push","forEach","apiEndpoint","_","_req","locals","app_version","middleware","webMiddleware","errorUtils","getNotFound","API_ERROR","WEB_DISABLED","handleError","final","startServer","exports","configHash","AppConfig","Storage","err","error","msg","Error","_default"],"sources":["../src/server.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport buildDebug from 'debug';\nimport express, { Express } from 'express';\nimport _ from 'lodash';\nimport AuditMiddleware from 'verdaccio-audit';\n\nimport apiEndpoint from '@verdaccio/api';\nimport { Auth } from '@verdaccio/auth';\nimport { Config as AppConfig } from '@verdaccio/config';\nimport { API_ERROR, PLUGIN_CATEGORY, errorUtils, pluginUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport {\n errorReportingMiddleware,\n final,\n handleError,\n log,\n rateLimit,\n userAgent,\n} from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { ConfigYaml } from '@verdaccio/types';\nimport { Config as IConfig } from '@verdaccio/types';\nimport webMiddleware from '@verdaccio/web';\n\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types/custom';\nimport hookDebug from './debug';\n\nconst debug = buildDebug('verdaccio:server');\nconst { version } = require('../package.json');\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<Express> {\n const auth: Auth = new Auth(config, logger);\n await auth.init();\n const app = express();\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n app.use(cors());\n app.use(rateLimit(config.serverSettings.rateLimit));\n\n const errorReportingMiddlewareWrap = errorReportingMiddleware(logger);\n\n // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddlewareWrap);\n app.use(userAgent(config));\n app.use(compression());\n\n app.get(\n '/favicon.ico',\n function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.url = '/-/static/favicon.ico';\n next();\n }\n );\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n if (plugins.length === 0) {\n const auditPlugin = new AuditMiddleware(\n { enabled: true, strict_ssl: true },\n { config, logger }\n );\n logger.info(\n { name: 'verdaccio-audit', pluginCategory: PLUGIN_CATEGORY.MIDDLEWARE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n plugins.push(auditPlugin);\n }\n\n plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // For npm request\n // @ts-ignore\n app.use(apiEndpoint(config, auth, storage, logger));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage, logger);\n app.use(middleware);\n } else {\n app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n // Catch 404\n app.get('/*', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {\n next(errorUtils.getNotFound('resource not found'));\n });\n\n // @ts-ignore\n app.use(handleError(logger));\n\n // app.use(function (\n // err: HttpError,\n // req: $RequestExtend,\n // res: $ResponseExtend,\n // next: $NextFunctionVer\n // ) {\n // if (_.isError(err)) {\n // if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n // return next();\n // }\n // if (_.isFunction(res.locals.report_error) === false) {\n // // in case of very early error this middleware may not be loaded before error is generated\n // // fixing that\n // errorReportingMiddlewareWrap(req, res, _.noop);\n // }\n // res.locals.report_error(err);\n // } else {\n // // Fall to Middleware.final\n // return next(err);\n // }\n // });\n\n app.use(final);\n\n return app;\n};\n\nconst startServer = async function startServer(configHash: ConfigYaml): Promise<Express> {\n debug('start server');\n const config: IConfig = new AppConfig({ ...configHash } as any);\n // register middleware plugins\n debug('loaded filter plugin');\n // @ts-ignore\n const storage: Storage = new Storage(config, logger);\n try {\n // waits until init calls have been initialized\n debug('storage init start');\n await storage.init(config);\n debug('storage init end');\n } catch (err: any) {\n logger.error({ error: err.msg }, 'storage has failed: @{error}');\n throw new Error(err);\n }\n return await defineAPI(config, storage);\n};\n\nexport { startServer };\nexport default startServer;\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC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ccio/server",
3
- "version": "8.0.0-next-8.3",
3
+ "version": "8.0.0-next-8.5",
4
4
  "description": "server logic",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -29,26 +29,26 @@
29
29
  "node": ">=18"
30
30
  },
31
31
  "dependencies": {
32
- "@verdaccio/api": "8.1.0-next-8.3",
33
- "@verdaccio/auth": "8.0.0-next-8.3",
34
- "@verdaccio/core": "8.0.0-next-8.3",
35
- "@verdaccio/config": "8.0.0-next-8.3",
36
- "@verdaccio/loaders": "8.0.0-next-8.3",
37
- "@verdaccio/logger": "8.0.0-next-8.3",
38
- "@verdaccio/middleware": "8.0.0-next-8.3",
39
- "@verdaccio/store": "8.0.0-next-8.3",
40
- "@verdaccio/utils": "8.1.0-next-8.3",
41
- "@verdaccio/web": "8.1.0-next-8.3",
42
- "verdaccio-audit": "13.0.0-next-8.3",
43
- "compression": "1.7.4",
32
+ "@verdaccio/api": "8.1.0-next-8.5",
33
+ "@verdaccio/auth": "8.0.0-next-8.5",
34
+ "@verdaccio/core": "8.0.0-next-8.5",
35
+ "@verdaccio/config": "8.0.0-next-8.5",
36
+ "@verdaccio/loaders": "8.0.0-next-8.4",
37
+ "@verdaccio/logger": "8.0.0-next-8.5",
38
+ "@verdaccio/middleware": "8.0.0-next-8.5",
39
+ "@verdaccio/store": "8.0.0-next-8.5",
40
+ "@verdaccio/utils": "8.1.0-next-8.5",
41
+ "@verdaccio/web": "8.1.0-next-8.5",
42
+ "verdaccio-audit": "13.0.0-next-8.5",
43
+ "compression": "1.7.5",
44
44
  "cors": "2.8.5",
45
45
  "debug": "4.3.7",
46
- "express": "4.21.0",
46
+ "express": "4.21.1",
47
47
  "lodash": "4.17.21"
48
48
  },
49
49
  "devDependencies": {
50
- "@verdaccio/proxy": "8.0.0-next-8.3",
51
- "@verdaccio/test-helper": "4.0.0-next-8.0",
50
+ "@verdaccio/proxy": "8.0.0-next-8.5",
51
+ "@verdaccio/test-helper": "4.0.0-next-8.2",
52
52
  "http-errors": "2.0.0"
53
53
  },
54
54
  "funding": {
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "scripts": {
59
59
  "clean": "rimraf ./build",
60
- "test": "jest",
60
+ "test": "vitest run",
61
61
  "type-check": "tsc --noEmit -p tsconfig.build.json",
62
62
  "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
63
63
  "watch": "pnpm build:js -- --watch",
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export { default } from './server';
1
+ export { default, startServer } from './server';
package/src/server.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import compression from 'compression';
2
2
  import cors from 'cors';
3
3
  import buildDebug from 'debug';
4
- import express from 'express';
4
+ import express, { Express } from 'express';
5
5
  import _ from 'lodash';
6
6
  import AuditMiddleware from 'verdaccio-audit';
7
7
 
@@ -30,8 +30,8 @@ import hookDebug from './debug';
30
30
  const debug = buildDebug('verdaccio:server');
31
31
  const { version } = require('../package.json');
32
32
 
33
- const defineAPI = async function (config: IConfig, storage: Storage): Promise<any> {
34
- const auth: Auth = new Auth(config);
33
+ const defineAPI = async function (config: IConfig, storage: Storage): Promise<Express> {
34
+ const auth: Auth = new Auth(config, logger);
35
35
  await auth.init();
36
36
  const app = express();
37
37
  // run in production mode by default, just in case
@@ -78,9 +78,15 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
78
78
  );
79
79
 
80
80
  if (plugins.length === 0) {
81
- logger.info('none middleware plugins has been defined, adding audit middleware by default');
82
- // @ts-ignore
83
- plugins.push(new AuditMiddleware({ enabled: true, strict_ssl: true }, { config, logger }));
81
+ const auditPlugin = new AuditMiddleware(
82
+ { enabled: true, strict_ssl: true },
83
+ { config, logger }
84
+ );
85
+ logger.info(
86
+ { name: 'verdaccio-audit', pluginCategory: PLUGIN_CATEGORY.MIDDLEWARE },
87
+ 'plugin @{name} successfully loaded (@{pluginCategory})'
88
+ );
89
+ plugins.push(auditPlugin);
84
90
  }
85
91
 
86
92
  plugins.forEach((plugin: pluginUtils.ExpressMiddleware<IConfig, {}, Auth>) => {
@@ -89,7 +95,7 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
89
95
 
90
96
  // For npm request
91
97
  // @ts-ignore
92
- app.use(apiEndpoint(config, auth, storage));
98
+ app.use(apiEndpoint(config, auth, storage, logger));
93
99
 
94
100
  // For WebUI & WebUI API
95
101
  if (_.get(config, 'web.enable', true)) {
@@ -97,7 +103,7 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
97
103
  res.locals.app_version = version ?? '';
98
104
  next();
99
105
  });
100
- const middleware = await webMiddleware(config, auth, storage);
106
+ const middleware = await webMiddleware(config, auth, storage, logger);
101
107
  app.use(middleware);
102
108
  } else {
103
109
  app.get('/', function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
@@ -140,7 +146,7 @@ const defineAPI = async function (config: IConfig, storage: Storage): Promise<an
140
146
  return app;
141
147
  };
142
148
 
143
- export default (async function startServer(configHash: ConfigYaml): Promise<any> {
149
+ const startServer = async function startServer(configHash: ConfigYaml): Promise<Express> {
144
150
  debug('start server');
145
151
  const config: IConfig = new AppConfig({ ...configHash } as any);
146
152
  // register middleware plugins
@@ -157,4 +163,7 @@ export default (async function startServer(configHash: ConfigYaml): Promise<any>
157
163
  throw new Error(err);
158
164
  }
159
165
  return await defineAPI(config, storage);
160
- });
166
+ };
167
+
168
+ export { startServer };
169
+ export default startServer;
package/test/_helper.ts CHANGED
@@ -8,8 +8,6 @@ import { generateRandomHexString } from '@verdaccio/utils';
8
8
 
9
9
  import apiMiddleware from '../src';
10
10
 
11
- setup({});
12
-
13
11
  export const getConf = async (conf) => {
14
12
  const configPath = path.join(__dirname, 'config', conf);
15
13
  const config = parseConfigFile(configPath);
@@ -25,5 +23,7 @@ export const getConf = async (conf) => {
25
23
  };
26
24
 
27
25
  export async function initializeServer(configName): Promise<Application> {
28
- return apiMiddleware(await getConf(configName));
26
+ const config = await getConf(configName);
27
+ setup(config.log ?? {});
28
+ return apiMiddleware(config);
29
29
  }
@@ -1,113 +1,119 @@
1
1
  import supertest from 'supertest';
2
+ import { describe, expect, test } from 'vitest';
2
3
 
3
4
  import { API_ERROR, HEADERS, HEADER_TYPE, HTTP_STATUS } from '@verdaccio/core';
5
+ import { setup } from '@verdaccio/logger';
4
6
 
5
7
  import { initializeServer } from './_helper';
6
8
 
7
- test('should request any package', async () => {
8
- const app = await initializeServer('conf.yaml');
9
- await supertest(app)
10
- .get('/jquery')
11
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
12
- .expect(HTTP_STATUS.NOT_FOUND);
13
- });
9
+ setup({});
14
10
 
15
- test('should able to catch non defined routes with 404', async () => {
16
- const app = await initializeServer('conf.yaml');
17
- await supertest(app)
18
- .get('/-/this-does-not-exist-anywhere')
19
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
20
- .expect(HTTP_STATUS.NOT_FOUND);
21
- });
11
+ describe('server api', () => {
12
+ test('should request any package', async () => {
13
+ const app = await initializeServer('conf.yaml');
14
+ await supertest(app)
15
+ .get('/jquery')
16
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
17
+ .expect(HTTP_STATUS.NOT_FOUND);
18
+ });
22
19
 
23
- test('should return index page if web is enabled', async () => {
24
- const app = await initializeServer('conf.yaml');
25
- const response = await supertest(app)
26
- .get('/')
27
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
28
- .expect(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP)
29
- .expect(HTTP_STATUS.OK);
30
- expect(response.text).toMatch('<title>verdaccio</title>');
31
- });
20
+ test('should able to catch non defined routes with 404', async () => {
21
+ const app = await initializeServer('conf.yaml');
22
+ await supertest(app)
23
+ .get('/-/this-does-not-exist-anywhere')
24
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
25
+ .expect(HTTP_STATUS.NOT_FOUND);
26
+ });
32
27
 
33
- test('should define rate limit headers', async () => {
34
- const app = await initializeServer('conf.yaml');
35
- await supertest(app)
36
- .get('/')
37
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
38
- .expect('x-ratelimit-limit', '10000')
39
- .expect('x-ratelimit-remaining', '9999')
40
- .expect(HTTP_STATUS.OK);
41
- });
28
+ test('should return index page if web is enabled', async () => {
29
+ const app = await initializeServer('conf.yaml');
30
+ const response = await supertest(app)
31
+ .get('/')
32
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
33
+ .expect(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP)
34
+ .expect(HTTP_STATUS.OK);
35
+ expect(response.text).toMatch('<title>verdaccio</title>');
36
+ });
42
37
 
43
- test('should contains cors headers', async () => {
44
- const app = await initializeServer('conf.yaml');
45
- await supertest(app).get('/').expect('access-control-allow-origin', '*').expect(HTTP_STATUS.OK);
46
- });
38
+ test('should define rate limit headers', async () => {
39
+ const app = await initializeServer('conf.yaml');
40
+ await supertest(app)
41
+ .get('/')
42
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
43
+ .expect(HEADERS.RATELIMIT_LIMIT, '10000')
44
+ .expect(HEADERS.RATELIMIT_REMAINING, '9999')
45
+ .expect(HTTP_STATUS.OK);
46
+ });
47
47
 
48
- test('should contains etag', async () => {
49
- const app = await initializeServer('conf.yaml');
50
- const response = await supertest(app)
51
- .get('/')
52
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
53
- .expect(HTTP_STATUS.OK);
54
- const etag = response.get(HEADERS.ETAG);
55
- expect(typeof etag === 'string').toBeTruthy();
56
- });
48
+ test('should contains cors headers', async () => {
49
+ const app = await initializeServer('conf.yaml');
50
+ await supertest(app).get('/').expect('access-control-allow-origin', '*').expect(HTTP_STATUS.OK);
51
+ });
57
52
 
58
- test('should be hidden by default', async () => {
59
- const app = await initializeServer('conf.yaml');
60
- const response = await supertest(app)
61
- .get('/')
62
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
63
- .expect(HTTP_STATUS.OK);
64
- const powered = response.get('x-powered-by');
65
- expect(powered).toMatch('hidden');
66
- }, 40000);
53
+ test('should contains etag', async () => {
54
+ const app = await initializeServer('conf.yaml');
55
+ const response = await supertest(app)
56
+ .get('/')
57
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
58
+ .expect(HTTP_STATUS.OK);
59
+ const etag = response.get(HEADERS.ETAG);
60
+ expect(typeof etag === 'string').toBeTruthy();
61
+ });
67
62
 
68
- test('should not contains powered header', async () => {
69
- const app = await initializeServer('powered-disabled.yaml');
70
- const response = await supertest(app)
71
- .get('/')
72
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
73
- .expect(HTTP_STATUS.OK);
74
- const powered = response.get('x-powered-by');
75
- expect(powered).toEqual('hidden');
76
- });
63
+ test('should be hidden by default', async () => {
64
+ const app = await initializeServer('conf.yaml');
65
+ const response = await supertest(app)
66
+ .get('/')
67
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
68
+ .expect(HTTP_STATUS.OK);
69
+ const powered = response.get(HEADERS.POWERED_BY);
70
+ expect(powered).toMatch('hidden');
71
+ }, 40000);
77
72
 
78
- test('should contains custom powered header', async () => {
79
- const app = await initializeServer('powered-custom.yaml');
80
- const response = await supertest(app)
81
- .get('/')
82
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
83
- .expect(HTTP_STATUS.OK);
84
- const powered = response.get('x-powered-by');
85
- expect(powered).toEqual('custom user agent');
86
- });
73
+ test('should not contains powered header', async () => {
74
+ const app = await initializeServer('powered-disabled.yaml');
75
+ const response = await supertest(app)
76
+ .get('/')
77
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
78
+ .expect(HTTP_STATUS.OK);
79
+ const powered = response.get(HEADERS.POWERED_BY);
80
+ expect(powered).toEqual('hidden');
81
+ });
87
82
 
88
- test('should return 404 if web is disabled', async () => {
89
- const app = await initializeServer('web-disabled.yaml');
90
- const response = await supertest(app)
91
- .get('/')
92
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
93
- .expect(HTTP_STATUS.NOT_FOUND);
94
- expect(response.body.error).toEqual(API_ERROR.WEB_DISABLED);
95
- });
83
+ test('should contains custom powered header', async () => {
84
+ const app = await initializeServer('powered-custom.yaml');
85
+ const response = await supertest(app)
86
+ .get('/')
87
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_HTML_UTF8)
88
+ .expect(HTTP_STATUS.OK);
89
+ const powered = response.get(HEADERS.POWERED_BY);
90
+ expect(powered).toEqual('custom user agent');
91
+ });
96
92
 
97
- test('should not display debug hook disabled by default', async () => {
98
- const app = await initializeServer('no_debug.yaml');
99
- await supertest(app)
100
- .get('/-/_debug')
101
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
102
- .expect(HTTP_STATUS.NOT_FOUND);
103
- });
93
+ test('should return 404 if web is disabled', async () => {
94
+ const app = await initializeServer('web-disabled.yaml');
95
+ const response = await supertest(app)
96
+ .get('/')
97
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
98
+ .expect(HTTP_STATUS.NOT_FOUND);
99
+ expect(response.body.error).toEqual(API_ERROR.WEB_DISABLED);
100
+ });
101
+
102
+ test('should not display debug hook disabled by default', async () => {
103
+ const app = await initializeServer('no_debug.yaml');
104
+ await supertest(app)
105
+ .get('/-/_debug')
106
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
107
+ .expect(HTTP_STATUS.NOT_FOUND);
108
+ });
104
109
 
105
- test('should display debug hook if directly enabled', async () => {
106
- const app = await initializeServer('conf.yaml');
107
- const res = await supertest(app)
108
- .get('/-/_debug')
109
- .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
110
- .expect(HTTP_STATUS.OK);
111
- expect(res.body.pid).toEqual(process.pid);
112
- expect(res.body.mem).toBeDefined();
110
+ test('should display debug hook if directly enabled', async () => {
111
+ const app = await initializeServer('conf.yaml');
112
+ const res = await supertest(app)
113
+ .get('/-/_debug')
114
+ .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
115
+ .expect(HTTP_STATUS.OK);
116
+ expect(res.body.pid).toEqual(process.pid);
117
+ expect(res.body.mem).toBeDefined();
118
+ });
113
119
  });
package/jest.config.js DELETED
@@ -1,10 +0,0 @@
1
- const config = require('../../../jest/config');
2
-
3
- module.exports = Object.assign({}, config, {
4
- coverageThreshold: {
5
- global: {
6
- // FIXME: increase to 90
7
- lines: 84,
8
- },
9
- },
10
- });