@verdaccio/web 6.0.0-6-next.45 → 6.0.0-6-next.47

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/build/api/index.js +10 -1
  3. package/build/api/index.js.map +1 -1
  4. package/build/api/package.js +1 -1
  5. package/build/api/package.js.map +1 -1
  6. package/build/api/readme.d.ts +1 -1
  7. package/build/api/readme.js +1 -1
  8. package/build/api/readme.js.map +1 -1
  9. package/build/api/sidebar.d.ts +1 -1
  10. package/build/api/sidebar.js +1 -1
  11. package/build/api/sidebar.js.map +1 -1
  12. package/build/api/user.js +3 -2
  13. package/build/api/user.js.map +1 -1
  14. package/build/index.d.ts +1 -1
  15. package/build/index.js +2 -2
  16. package/build/index.js.map +1 -1
  17. package/build/{web-middleware.d.ts → middleware.d.ts} +1 -0
  18. package/build/middleware.js +45 -0
  19. package/build/middleware.js.map +1 -0
  20. package/build/{utils/web-utils.d.ts → web-utils.d.ts} +3 -4
  21. package/build/{utils/web-utils.js → web-utils.js} +11 -23
  22. package/build/web-utils.js.map +1 -0
  23. package/jest.config.js +1 -1
  24. package/package.json +16 -18
  25. package/src/api/index.ts +11 -1
  26. package/src/api/package.ts +1 -1
  27. package/src/api/readme.ts +1 -1
  28. package/src/api/sidebar.ts +1 -1
  29. package/src/api/user.ts +28 -22
  30. package/src/index.ts +1 -1
  31. package/src/middleware.ts +46 -0
  32. package/src/{utils/web-utils.ts → web-utils.ts} +12 -27
  33. package/test/helper.ts +1 -1
  34. package/test/web-utils.spec.ts +1 -1
  35. package/build/middleware/render-web.d.ts +0 -2
  36. package/build/middleware/render-web.js +0 -92
  37. package/build/middleware/render-web.js.map +0 -1
  38. package/build/middleware/security.d.ts +0 -2
  39. package/build/middleware/security.js +0 -19
  40. package/build/middleware/security.js.map +0 -1
  41. package/build/middleware/web-api.d.ts +0 -5
  42. package/build/middleware/web-api.js +0 -29
  43. package/build/middleware/web-api.js.map +0 -1
  44. package/build/renderHTML.d.ts +0 -1
  45. package/build/renderHTML.js +0 -108
  46. package/build/renderHTML.js.map +0 -1
  47. package/build/template.d.ts +0 -13
  48. package/build/template.js +0 -38
  49. package/build/template.js.map +0 -1
  50. package/build/utils/manifest.d.ts +0 -6
  51. package/build/utils/manifest.js +0 -18
  52. package/build/utils/manifest.js.map +0 -1
  53. package/build/utils/web-utils.js.map +0 -1
  54. package/build/web-middleware.js +0 -21
  55. package/build/web-middleware.js.map +0 -1
  56. package/src/middleware/render-web.ts +0 -91
  57. package/src/middleware/security.ts +0 -18
  58. package/src/middleware/web-api.ts +0 -25
  59. package/src/renderHTML.ts +0 -112
  60. package/src/template.ts +0 -50
  61. package/src/utils/manifest.ts +0 -23
  62. package/src/web-middleware.ts +0 -14
  63. package/test/__snapshots__/template.test.ts.snap +0 -151
  64. package/test/manifest.test.ts +0 -11
  65. package/test/render.test.ts +0 -108
  66. package/test/template.test.ts +0 -74
  67. package/test/utils.spec.ts +0 -13
package/src/api/user.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  errorUtils,
13
13
  validatioUtils,
14
14
  } from '@verdaccio/core';
15
+ import { rateLimit } from '@verdaccio/middleware';
15
16
  import { Config, JWTSignOptions, RemoteUser } from '@verdaccio/types';
16
17
 
17
18
  import { $NextFunctionVer } from './package';
@@ -20,33 +21,38 @@ const debug = buildDebug('verdaccio:web:api:user');
20
21
 
21
22
  function addUserAuthApi(auth: Auth, config: Config): Router {
22
23
  const route = Router(); /* eslint new-cap: 0 */
23
- route.post('/login', function (req: Request, res: Response, next: $NextFunctionVer): void {
24
- const { username, password } = req.body;
25
- debug('authenticate %o', username);
26
- auth.authenticate(
27
- username,
28
- password,
29
- async (err: VerdaccioError | null, user?: RemoteUser): Promise<void> => {
30
- if (err) {
31
- const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
32
- debug('error authenticate %o', errorCode);
33
- next(errorUtils.getCode(errorCode, err.message));
34
- } else {
35
- req.remote_user = user as RemoteUser;
36
- const jWTSignOptions: JWTSignOptions = config.security.web.sign;
37
- res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');
38
- next({
39
- token: await auth.jwtEncrypt(user as RemoteUser, jWTSignOptions),
40
- username: req.remote_user.name,
41
- });
24
+ route.post(
25
+ '/login',
26
+ rateLimit(config?.userRateLimit),
27
+ function (req: Request, res: Response, next: $NextFunctionVer): void {
28
+ const { username, password } = req.body;
29
+ debug('authenticate %o', username);
30
+ auth.authenticate(
31
+ username,
32
+ password,
33
+ async (err: VerdaccioError | null, user?: RemoteUser): Promise<void> => {
34
+ if (err) {
35
+ const errorCode = err.message ? HTTP_STATUS.UNAUTHORIZED : HTTP_STATUS.INTERNAL_ERROR;
36
+ debug('error authenticate %o', errorCode);
37
+ next(errorUtils.getCode(errorCode, err.message));
38
+ } else {
39
+ req.remote_user = user as RemoteUser;
40
+ const jWTSignOptions: JWTSignOptions = config.security.web.sign;
41
+ res.set(HEADERS.CACHE_CONTROL, 'no-cache, no-store');
42
+ next({
43
+ token: await auth.jwtEncrypt(user as RemoteUser, jWTSignOptions),
44
+ username: req.remote_user.name,
45
+ });
46
+ }
42
47
  }
43
- }
44
- );
45
- });
48
+ );
49
+ }
50
+ );
46
51
 
47
52
  if (config?.flags?.changePassword === true) {
48
53
  route.put(
49
54
  '/reset_password',
55
+ rateLimit(config?.userRateLimit),
50
56
  function (req: Request, res: Response, next: $NextFunctionVer): void {
51
57
  if (_.isNil(req.remote_user.name)) {
52
58
  res.status(HTTP_STATUS.UNAUTHORIZED);
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export { default } from './web-middleware';
1
+ export { default } from './middleware';
@@ -0,0 +1,46 @@
1
+ import express from 'express';
2
+ import _ from 'lodash';
3
+
4
+ import { asyncLoadPlugin } from '@verdaccio/loaders';
5
+ import { logger } from '@verdaccio/logger';
6
+ import { webMiddleware } from '@verdaccio/middleware';
7
+
8
+ import webEndpointsApi from './api';
9
+
10
+ export async function loadTheme(config: any) {
11
+ if (_.isNil(config.theme) === false) {
12
+ const plugin = await asyncLoadPlugin(
13
+ config.theme,
14
+ { config, logger },
15
+ // TODO: add types { staticPath: string; manifest: unknown; manifestFiles: unknown }
16
+ function (plugin: any) {
17
+ return plugin.staticPath && plugin.manifest && plugin.manifestFiles;
18
+ },
19
+ config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme'
20
+ );
21
+ if (plugin.length > 1) {
22
+ logger.warn('multiple ui themes are not supported , only the first plugin is used used');
23
+ }
24
+
25
+ return _.head(plugin);
26
+ }
27
+ }
28
+
29
+ export default async (config, auth, storage) => {
30
+ const pluginOptions = (await loadTheme(config)) || require('@verdaccio/ui-theme')();
31
+
32
+ // eslint-disable-next-line new-cap
33
+ const router = express.Router();
34
+ // load application
35
+ router.use(
36
+ webMiddleware(
37
+ config,
38
+ {
39
+ tokenMiddleware: auth.webUIJWTmiddleware(),
40
+ webEndpointsApi: webEndpointsApi(auth, storage, config),
41
+ },
42
+ pluginOptions
43
+ )
44
+ );
45
+ return router;
46
+ };
@@ -1,43 +1,28 @@
1
- import buildDebug from 'debug';
2
1
  import _ from 'lodash';
3
2
 
4
- // import { normalizeContributors } from '@verdaccio/store';
5
3
  import { Author, ConfigYaml } from '@verdaccio/types';
6
4
 
7
- export type AuthorAvatar = Author & { avatar?: string };
8
-
9
- const debug = buildDebug('verdaccio:web:utils');
10
-
11
- export function validatePrimaryColor(primaryColor) {
12
- const isHex = /^#([0-9A-F]{3}){1,2}$/i.test(primaryColor);
13
- if (!isHex) {
14
- debug('invalid primary color %o', primaryColor);
15
- return;
16
- }
17
-
18
- return primaryColor;
5
+ export function hasLogin(config: ConfigYaml) {
6
+ return _.isNil(config?.web?.login) || config?.web?.login === true;
19
7
  }
20
8
 
21
- export function deleteProperties(propertiesToDelete: string[], objectItem: any): any {
22
- debug('deleted unused version properties');
23
- _.forEach(propertiesToDelete, (property): any => {
24
- delete objectItem[property];
9
+ export function sortByName(packages: any[], orderAscending: boolean | void = true): string[] {
10
+ return packages.slice().sort(function (a, b): number {
11
+ const comparatorNames = a.name.toLowerCase() < b.name.toLowerCase();
12
+ return orderAscending ? (comparatorNames ? -1 : 1) : comparatorNames ? 1 : -1;
25
13
  });
26
-
27
- return objectItem;
28
14
  }
29
15
 
16
+ export type AuthorAvatar = Author & { avatar?: string };
17
+
30
18
  export function addScope(scope: string, packageName: string): string {
31
19
  return `@${scope}/${packageName}`;
32
20
  }
33
21
 
34
- export function sortByName(packages: any[], orderAscending: boolean | void = true): string[] {
35
- return packages.slice().sort(function (a, b): number {
36
- const comparatorNames = a.name.toLowerCase() < b.name.toLowerCase();
37
- return orderAscending ? (comparatorNames ? -1 : 1) : comparatorNames ? 1 : -1;
22
+ export function deleteProperties(propertiesToDelete: string[], objectItem: any): any {
23
+ _.forEach(propertiesToDelete, (property): any => {
24
+ delete objectItem[property];
38
25
  });
39
- }
40
26
 
41
- export function hasLogin(config: ConfigYaml) {
42
- return _.isNil(config?.web?.login) || config?.web?.login === true;
27
+ return objectItem;
43
28
  }
package/test/helper.ts CHANGED
@@ -9,7 +9,7 @@ import { initializeServer as initializeServerHelper } from '@verdaccio/test-help
9
9
 
10
10
  import routes from '../src';
11
11
 
12
- setup([]);
12
+ setup({});
13
13
 
14
14
  export const getConf = (configName: string) => {
15
15
  const configPath = path.join(__dirname, 'config', configName);
@@ -1,4 +1,4 @@
1
- import { sortByName } from '../src/utils/web-utils';
1
+ import { sortByName } from '../src/web-utils';
2
2
 
3
3
  describe('Utilities', () => {
4
4
  describe('Sort packages', () => {
@@ -1,2 +0,0 @@
1
- export declare function loadTheme(config: any): Promise<any>;
2
- export declare function renderWebMiddleware(config: any, auth: any): Promise<any>;
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadTheme = loadTheme;
7
- exports.renderWebMiddleware = renderWebMiddleware;
8
- var _debug = _interopRequireDefault(require("debug"));
9
- var _express = _interopRequireDefault(require("express"));
10
- var _lodash = _interopRequireDefault(require("lodash"));
11
- var _path = _interopRequireDefault(require("path"));
12
- var _core = require("@verdaccio/core");
13
- var _loaders = require("@verdaccio/loaders");
14
- var _logger = require("@verdaccio/logger");
15
- var _url = require("@verdaccio/url");
16
- var _renderHTML = _interopRequireDefault(require("../renderHTML"));
17
- var _security = require("./security");
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- const debug = (0, _debug.default)('verdaccio:web:render');
20
- async function loadTheme(config) {
21
- if (_lodash.default.isNil(config.theme) === false) {
22
- var _config$serverSetting;
23
- const plugin = await (0, _loaders.asyncLoadPlugin)(config.theme, {
24
- config,
25
- logger: _logger.logger
26
- },
27
- // TODO: add types { staticPath: string; manifest: unknown; manifestFiles: unknown }
28
- function (plugin) {
29
- return plugin.staticPath && plugin.manifest && plugin.manifestFiles;
30
- }, (config === null || config === void 0 ? void 0 : (_config$serverSetting = config.serverSettings) === null || _config$serverSetting === void 0 ? void 0 : _config$serverSetting.pluginPrefix) ?? 'verdaccio-theme');
31
- if (plugin.length > 1) {
32
- _logger.logger.warn('multiple ui themes has been detected and is not supported, only the first one will be used');
33
- }
34
- return _lodash.default.head(plugin);
35
- }
36
- }
37
- const sendFileCallback = next => err => {
38
- if (!err) {
39
- return;
40
- }
41
- if (err.status === _core.HTTP_STATUS.NOT_FOUND) {
42
- next();
43
- } else {
44
- next(err);
45
- }
46
- };
47
- async function renderWebMiddleware(config, auth) {
48
- var _config$web;
49
- const {
50
- staticPath,
51
- manifest,
52
- manifestFiles
53
- } = (await loadTheme(config)) || require('@verdaccio/ui-theme')();
54
- debug('static path %o', staticPath);
55
-
56
- /* eslint new-cap:off */
57
- const router = _express.default.Router();
58
- router.use(auth.webUIJWTmiddleware());
59
- router.use(_security.setSecurityWebHeaders);
60
-
61
- // Logo
62
- let logoURI = (config === null || config === void 0 ? void 0 : (_config$web = config.web) === null || _config$web === void 0 ? void 0 : _config$web.logo) ?? '';
63
- if (logoURI && !(0, _url.isURLhasValidProtocol)(logoURI)) {
64
- // URI related to a local file
65
-
66
- // Note: `path.join` will break on Windows, because it transforms `/` to `\`
67
- // Use POSIX version `path.posix.join` instead.
68
- logoURI = _path.default.posix.join('/-/static/', _path.default.basename(logoURI));
69
- router.get(logoURI, function (req, res, next) {
70
- res.sendFile(_path.default.resolve(config.web.logo), sendFileCallback(next));
71
- debug('render static');
72
- });
73
- }
74
-
75
- // Static
76
- router.get('/-/static/*', function (req, res, next) {
77
- const filename = req.params[0];
78
- const file = `${staticPath}/${filename}`;
79
- debug('render static file %o', file);
80
- res.sendFile(file, sendFileCallback(next));
81
- });
82
- router.get('/-/web/:section/*', function (req, res) {
83
- (0, _renderHTML.default)(config, manifest, manifestFiles, req, res);
84
- debug('render html section');
85
- });
86
- router.get('/', function (req, res) {
87
- (0, _renderHTML.default)(config, manifest, manifestFiles, req, res);
88
- debug('render root');
89
- });
90
- return router;
91
- }
92
- //# sourceMappingURL=render-web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render-web.js","names":["debug","buildDebug","loadTheme","config","_","isNil","theme","plugin","asyncLoadPlugin","logger","staticPath","manifest","manifestFiles","serverSettings","pluginPrefix","length","warn","head","sendFileCallback","next","err","status","HTTP_STATUS","NOT_FOUND","renderWebMiddleware","auth","require","router","express","Router","use","webUIJWTmiddleware","setSecurityWebHeaders","logoURI","web","logo","isURLhasValidProtocol","path","posix","join","basename","get","req","res","sendFile","resolve","filename","params","file","renderHTML"],"sources":["../../src/middleware/render-web.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express from 'express';\nimport _ from 'lodash';\nimport path from 'path';\n\nimport { HTTP_STATUS } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport { isURLhasValidProtocol } from '@verdaccio/url';\n\nimport renderHTML from '../renderHTML';\nimport { setSecurityWebHeaders } from './security';\n\nconst debug = buildDebug('verdaccio:web:render');\n\nexport async function loadTheme(config: any) {\n if (_.isNil(config.theme) === false) {\n const plugin = await asyncLoadPlugin(\n config.theme,\n { config, logger },\n // TODO: add types { staticPath: string; manifest: unknown; manifestFiles: unknown }\n function (plugin: any) {\n return plugin.staticPath && plugin.manifest && plugin.manifestFiles;\n },\n config?.serverSettings?.pluginPrefix ?? 'verdaccio-theme'\n );\n if (plugin.length > 1) {\n logger.warn(\n 'multiple ui themes has been detected and is not supported, only the first one will be used'\n );\n }\n\n return _.head(plugin);\n }\n}\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 async function renderWebMiddleware(config, auth): Promise<any> {\n const { staticPath, manifest, manifestFiles } =\n (await loadTheme(config)) || require('@verdaccio/ui-theme')();\n debug('static path %o', staticPath);\n\n /* eslint new-cap:off */\n const router = express.Router();\n router.use(auth.webUIJWTmiddleware());\n router.use(setSecurityWebHeaders);\n\n // Logo\n let logoURI = config?.web?.logo ?? '';\n if (logoURI && !isURLhasValidProtocol(logoURI)) {\n // URI related to a local file\n\n // Note: `path.join` will break on Windows, because it transforms `/` to `\\`\n // Use POSIX version `path.posix.join` instead.\n logoURI = path.posix.join('/-/static/', path.basename(logoURI));\n router.get(logoURI, function (req, res, next) {\n res.sendFile(path.resolve(config.web.logo), sendFileCallback(next));\n debug('render static');\n });\n }\n\n // Static\n router.get('/-/static/*', function (req, res, next) {\n const filename = req.params[0];\n const file = `${staticPath}/${filename}`;\n debug('render static file %o', file);\n res.sendFile(file, sendFileCallback(next));\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":";;;;;;;AAAA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;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AAM,EAAEQ,QAAQ,EAAEC,aAAa,EAAE8B,GAAG,EAAEC,GAAG,CAAC;IACrD3C,KAAK,CAAC,qBAAqB,CAAC;EAC9B,CAAC,CAAC;EAEF2B,MAAM,CAACc,GAAG,CAAC,GAAG,EAAE,UAAUC,GAAG,EAAEC,GAAG,EAAE;IAClC,IAAAM,mBAAU,EAAC9C,MAAM,EAAEQ,QAAQ,EAAEC,aAAa,EAAE8B,GAAG,EAAEC,GAAG,CAAC;IACrD3C,KAAK,CAAC,aAAa,CAAC;EACtB,CAAC,CAAC;EAEF,OAAO2B,MAAM;AACf"}
@@ -1,2 +0,0 @@
1
- import { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';
2
- export declare function setSecurityWebHeaders(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setSecurityWebHeaders = setSecurityWebHeaders;
7
- var _core = require("@verdaccio/core");
8
- function setSecurityWebHeaders(req, res, next) {
9
- // disable loading in frames (clickjacking, etc.)
10
- res.header(_core.HEADERS.FRAMES_OPTIONS, 'deny');
11
- // avoid stablish connections outside of domain
12
- res.header(_core.HEADERS.CSP, "connect-src 'self'");
13
- // https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff
14
- res.header(_core.HEADERS.CTO, 'nosniff');
15
- // https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection
16
- res.header(_core.HEADERS.XSS, '1; mode=block');
17
- next();
18
- }
19
- //# sourceMappingURL=security.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security.js","names":["setSecurityWebHeaders","req","res","next","header","HEADERS","FRAMES_OPTIONS","CSP","CTO","XSS"],"sources":["../../src/middleware/security.ts"],"sourcesContent":["import { HEADERS } from '@verdaccio/core';\nimport { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '@verdaccio/middleware';\n\nexport function setSecurityWebHeaders(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n // disable loading in frames (clickjacking, etc.)\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n // avoid stablish connections outside of domain\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n // https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff\n res.header(HEADERS.CTO, 'nosniff');\n // https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection\n res.header(HEADERS.XSS, '1; mode=block');\n next();\n}\n"],"mappings":";;;;;;AAAA;AAGO,SAASA,qBAAqB,CACnCC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN;EACAD,GAAG,CAACE,MAAM,CAACC,aAAO,CAACC,cAAc,EAAE,MAAM,CAAC;EAC1C;EACAJ,GAAG,CAACE,MAAM,CAACC,aAAO,CAACE,GAAG,EAAE,oBAAoB,CAAC;EAC7C;EACAL,GAAG,CAACE,MAAM,CAACC,aAAO,CAACG,GAAG,EAAE,SAAS,CAAC;EAClC;EACAN,GAAG,CAACE,MAAM,CAACC,aAAO,CAACI,GAAG,EAAE,eAAe,CAAC;EACxCN,IAAI,EAAE;AACR"}
@@ -1,5 +0,0 @@
1
- import { Router } from 'express';
2
- import { Auth } from '@verdaccio/auth';
3
- import { Storage } from '@verdaccio/store';
4
- import { Config } from '@verdaccio/types';
5
- export declare function webAPI(config: Config, auth: Auth, storage: Storage): Router;
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.webAPI = webAPI;
7
- var _bodyParser = _interopRequireDefault(require("body-parser"));
8
- var _express = require("express");
9
- var _middleware = require("@verdaccio/middleware");
10
- var _api = _interopRequireDefault(require("../api"));
11
- var _security = require("./security");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- function webAPI(config, auth, storage) {
14
- // eslint-disable-next-line new-cap
15
- const route = (0, _express.Router)();
16
- // validate all of these params as a package name
17
- // this might be too harsh, so ask if it causes trouble=
18
- route.param('package', _middleware.validatePackage);
19
- route.param('filename', _middleware.validateName);
20
- route.param('version', _middleware.validateName);
21
- route.use(_bodyParser.default.urlencoded({
22
- extended: false
23
- }));
24
- route.use(auth.webUIJWTmiddleware());
25
- route.use(_security.setSecurityWebHeaders);
26
- route.use((0, _api.default)(auth, storage, config));
27
- return route;
28
- }
29
- //# sourceMappingURL=web-api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-api.js","names":["webAPI","config","auth","storage","route","Router","param","validatePackage","validateName","use","bodyParser","urlencoded","extended","webUIJWTmiddleware","setSecurityWebHeaders","webEndpointsApi"],"sources":["../../src/middleware/web-api.ts"],"sourcesContent":["import bodyParser from 'body-parser';\nimport { Router } from 'express';\n\nimport { Auth } from '@verdaccio/auth';\nimport { validateName, validatePackage } from '@verdaccio/middleware';\nimport { Storage } from '@verdaccio/store';\nimport { Config } from '@verdaccio/types';\n\nimport webEndpointsApi from '../api';\nimport { setSecurityWebHeaders } from './security';\n\nexport function webAPI(config: Config, auth: Auth, storage: Storage): Router {\n // eslint-disable-next-line new-cap\n const route = Router();\n // validate all of these params as a package name\n // this might be too harsh, so ask if it causes trouble=\n route.param('package', validatePackage);\n route.param('filename', validateName);\n route.param('version', validateName);\n route.use(bodyParser.urlencoded({ extended: false }));\n route.use(auth.webUIJWTmiddleware());\n route.use(setSecurityWebHeaders);\n route.use(webEndpointsApi(auth, storage, config));\n return route;\n}\n"],"mappings":";;;;;;AAAA;AACA;AAGA;AAIA;AACA;AAAmD;AAE5C,SAASA,MAAM,CAACC,MAAc,EAAEC,IAAU,EAAEC,OAAgB,EAAU;EAC3E;EACA,MAAMC,KAAK,GAAG,IAAAC,eAAM,GAAE;EACtB;EACA;EACAD,KAAK,CAACE,KAAK,CAAC,SAAS,EAAEC,2BAAe,CAAC;EACvCH,KAAK,CAACE,KAAK,CAAC,UAAU,EAAEE,wBAAY,CAAC;EACrCJ,KAAK,CAACE,KAAK,CAAC,SAAS,EAAEE,wBAAY,CAAC;EACpCJ,KAAK,CAACK,GAAG,CAACC,mBAAU,CAACC,UAAU,CAAC;IAAEC,QAAQ,EAAE;EAAM,CAAC,CAAC,CAAC;EACrDR,KAAK,CAACK,GAAG,CAACP,IAAI,CAACW,kBAAkB,EAAE,CAAC;EACpCT,KAAK,CAACK,GAAG,CAACK,+BAAqB,CAAC;EAChCV,KAAK,CAACK,GAAG,CAAC,IAAAM,YAAe,EAACb,IAAI,EAAEC,OAAO,EAAEF,MAAM,CAAC,CAAC;EACjD,OAAOG,KAAK;AACd"}
@@ -1 +0,0 @@
1
- export default function renderHTML(config: any, manifest: any, manifestFiles: any, req: any, res: any): void;
@@ -1,108 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = renderHTML;
7
- var _debug = _interopRequireDefault(require("debug"));
8
- var _lruCache = _interopRequireDefault(require("lru-cache"));
9
- var _url = require("url");
10
- var _config = require("@verdaccio/config");
11
- var _core = require("@verdaccio/core");
12
- var _url2 = require("@verdaccio/url");
13
- var _template = _interopRequireDefault(require("./template"));
14
- var _webUtils = require("./utils/web-utils");
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- const pkgJSON = require('../package.json');
17
- const DEFAULT_LANGUAGE = 'es-US';
18
- const cache = new _lruCache.default({
19
- max: 500,
20
- ttl: 1000 * 60 * 60
21
- });
22
- const debug = (0, _debug.default)('verdaccio:web:render');
23
- const defaultManifestFiles = {
24
- js: ['runtime.js', 'vendors.js', 'main.js'],
25
- ico: 'favicon.ico'
26
- };
27
- function renderHTML(config, manifest, manifestFiles, req, res) {
28
- var _config$i18n, _config$web, _config$web2, _config$web3, _config$web4, _config$web5, _config$web6, _config$web7;
29
- const {
30
- url_prefix
31
- } = config;
32
- const base = (0, _url2.getPublicUrl)(config === null || config === void 0 ? void 0 : config.url_prefix, req);
33
- const basename = new _url.URL(base).pathname;
34
- const language = (config === null || config === void 0 ? void 0 : (_config$i18n = config.i18n) === null || _config$i18n === void 0 ? void 0 : _config$i18n.web) ?? DEFAULT_LANGUAGE;
35
- const needHtmlCache = [undefined, null].includes(config === null || config === void 0 ? void 0 : (_config$web = config.web) === null || _config$web === void 0 ? void 0 : _config$web.html_cache) ? true : config.web.html_cache;
36
- const darkMode = (config === null || config === void 0 ? void 0 : (_config$web2 = config.web) === null || _config$web2 === void 0 ? void 0 : _config$web2.darkMode) ?? false;
37
- const title = (config === null || config === void 0 ? void 0 : (_config$web3 = config.web) === null || _config$web3 === void 0 ? void 0 : _config$web3.title) ?? _config.WEB_TITLE;
38
- const login = (0, _webUtils.hasLogin)(config);
39
- const scope = (config === null || config === void 0 ? void 0 : (_config$web4 = config.web) === null || _config$web4 === void 0 ? void 0 : _config$web4.scope) ?? '';
40
- const logoURI = (config === null || config === void 0 ? void 0 : (_config$web5 = config.web) === null || _config$web5 === void 0 ? void 0 : _config$web5.logo) ?? '';
41
- const pkgManagers = (config === null || config === void 0 ? void 0 : (_config$web6 = config.web) === null || _config$web6 === void 0 ? void 0 : _config$web6.pkgManagers) ?? ['yarn', 'pnpm', 'npm'];
42
- const version = pkgJSON.version;
43
- const flags = {
44
- ...config.flags
45
- };
46
- const primaryColor = (0, _webUtils.validatePrimaryColor)(config === null || config === void 0 ? void 0 : (_config$web7 = config.web) === null || _config$web7 === void 0 ? void 0 : _config$web7.primary_color) ?? '#4b5e40';
47
- const {
48
- scriptsBodyAfter,
49
- metaScripts,
50
- scriptsbodyBefore,
51
- showInfo,
52
- showSettings,
53
- showThemeSwitch,
54
- showFooter,
55
- showSearch,
56
- showDownloadTarball
57
- } = Object.assign({}, {
58
- scriptsBodyAfter: [],
59
- bodyBefore: [],
60
- metaScripts: []
61
- }, config === null || config === void 0 ? void 0 : config.web);
62
- const options = {
63
- showInfo,
64
- showSettings,
65
- showThemeSwitch,
66
- showFooter,
67
- showSearch,
68
- showDownloadTarball,
69
- darkMode,
70
- url_prefix,
71
- basename,
72
- base,
73
- primaryColor,
74
- version,
75
- logoURI,
76
- flags,
77
- login,
78
- pkgManagers,
79
- title,
80
- scope,
81
- language
82
- };
83
- let webPage;
84
- try {
85
- webPage = cache.get('template');
86
- if (!webPage) {
87
- webPage = (0, _template.default)({
88
- manifest: manifestFiles ?? defaultManifestFiles,
89
- options,
90
- scriptsBodyAfter,
91
- metaScripts,
92
- scriptsbodyBefore
93
- }, manifest);
94
- if (needHtmlCache) {
95
- cache.set('template', webPage);
96
- debug('set template cache');
97
- }
98
- } else {
99
- debug('reuse template cache');
100
- }
101
- } catch (error) {
102
- throw new Error(`theme could not be load, stack ${error.stack}`);
103
- }
104
- res.setHeader('Content-Type', _core.HEADERS.TEXT_HTML);
105
- res.send(webPage);
106
- debug('web rendered');
107
- }
108
- //# sourceMappingURL=renderHTML.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderHTML.js","names":["pkgJSON","require","DEFAULT_LANGUAGE","cache","LRU","max","ttl","debug","buildDebug","defaultManifestFiles","js","ico","renderHTML","config","manifest","manifestFiles","req","res","url_prefix","base","getPublicUrl","basename","URL","pathname","language","i18n","web","needHtmlCache","undefined","includes","html_cache","darkMode","title","WEB_TITLE","login","hasLogin","scope","logoURI","logo","pkgManagers","version","flags","primaryColor","validatePrimaryColor","primary_color","scriptsBodyAfter","metaScripts","scriptsbodyBefore","showInfo","showSettings","showThemeSwitch","showFooter","showSearch","showDownloadTarball","Object","assign","bodyBefore","options","webPage","get","renderTemplate","set","error","Error","stack","setHeader","HEADERS","TEXT_HTML","send"],"sources":["../src/renderHTML.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport LRU from 'lru-cache';\nimport { URL } from 'url';\n\nimport { WEB_TITLE } from '@verdaccio/config';\nimport { HEADERS } from '@verdaccio/core';\nimport { TemplateUIOptions } from '@verdaccio/types';\nimport { getPublicUrl } from '@verdaccio/url';\n\nimport renderTemplate from './template';\nimport { hasLogin, validatePrimaryColor } from './utils/web-utils';\n\nconst pkgJSON = require('../package.json');\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 = {\n js: ['runtime.js', 'vendors.js', 'main.js'],\n ico: 'favicon.ico',\n};\n\nexport default function renderHTML(config, manifest, manifestFiles, req, res) {\n const { url_prefix } = config;\n const base = getPublicUrl(config?.url_prefix, req);\n const basename = new URL(base).pathname;\n const language = config?.i18n?.web ?? DEFAULT_LANGUAGE;\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 logoURI = config?.web?.logo ?? '';\n const pkgManagers = config?.web?.pkgManagers ?? ['yarn', 'pnpm', 'npm'];\n const version = pkgJSON.version;\n const flags = {\n ...config.flags,\n };\n const primaryColor = validatePrimaryColor(config?.web?.primary_color) ?? '#4b5e40';\n const {\n scriptsBodyAfter,\n metaScripts,\n scriptsbodyBefore,\n showInfo,\n showSettings,\n showThemeSwitch,\n showFooter,\n showSearch,\n showDownloadTarball,\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 darkMode,\n url_prefix,\n basename,\n base,\n primaryColor,\n version,\n logoURI,\n flags,\n login,\n pkgManagers,\n title,\n scope,\n language,\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 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;AACA;AACA;AAEA;AACA;AAEA;AAEA;AACA;AAAmE;AAEnE,MAAMA,OAAO,GAAGC,OAAO,CAAC,iBAAiB,CAAC;AAC1C,MAAMC,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,oBAAoB,GAAG;EAC3BC,EAAE,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,SAAS,CAAC;EAC3CC,GAAG,EAAE;AACP,CAAC;AAEc,SAASC,UAAU,CAACC,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,GAAG,EAAEC,GAAG,EAAE;EAAA;EAC5E,MAAM;IAAEC;EAAW,CAAC,GAAGL,MAAM;EAC7B,MAAMM,IAAI,GAAG,IAAAC,kBAAY,EAACP,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEK,UAAU,EAAEF,GAAG,CAAC;EAClD,MAAMK,QAAQ,GAAG,IAAIC,QAAG,CAACH,IAAI,CAAC,CAACI,QAAQ;EACvC,MAAMC,QAAQ,GAAG,CAAAX,MAAM,aAANA,MAAM,uCAANA,MAAM,CAAEY,IAAI,iDAAZ,aAAcC,GAAG,KAAIxB,gBAAgB;EACtD,MAAMyB,aAAa,GAAG,CAACC,SAAS,EAAE,IAAI,CAAC,CAACC,QAAQ,CAAChB,MAAM,aAANA,MAAM,sCAANA,MAAM,CAAEa,GAAG,gDAAX,YAAaI,UAAU,CAAC,GACrE,IAAI,GACJjB,MAAM,CA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,GAAG,CACZ;EACD,MAAM+B,OAA0B,GAAG;IACjCT,QAAQ;IACRC,YAAY;IACZC,eAAe;IACfC,UAAU;IACVC,UAAU;IACVC,mBAAmB;IACnBtB,QAAQ;IACRb,UAAU;IACVG,QAAQ;IACRF,IAAI;IACJuB,YAAY;IACZF,OAAO;IACPH,OAAO;IACPI,KAAK;IACLP,KAAK;IACLK,WAAW;IACXP,KAAK;IACLI,KAAK;IACLZ;EACF,CAAC;EAED,IAAIkC,OAAO;EAEX,IAAI;IACFA,OAAO,GAAGvD,KAAK,CAACwD,GAAG,CAAC,UAAU,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACZA,OAAO,GAAG,IAAAE,iBAAc,EACtB;QACE9C,QAAQ,EAAEC,aAAa,IAAIN,oBAAoB;QAC/CgD,OAAO;QACPZ,gBAAgB;QAChBC,WAAW;QACXC;MACF,CAAC,EACDjC,QAAQ,CACT;MACD,IAAIa,aAAa,EAAE;QACjBxB,KAAK,CAAC0D,GAAG,CAAC,UAAU,EAAEH,OAAO,CAAC;QAC9BnD,KAAK,CAAC,oBAAoB,CAAC;MAC7B;IACF,CAAC,MAAM;MACLA,KAAK,CAAC,sBAAsB,CAAC;IAC/B;EACF,CAAC,CAAC,OAAOuD,KAAU,EAAE;IACnB,MAAM,IAAIC,KAAK,CAAE,kCAAiCD,KAAK,CAACE,KAAM,EAAC,CAAC;EAClE;EACA/C,GAAG,CAACgD,SAAS,CAAC,cAAc,EAAEC,aAAO,CAACC,SAAS,CAAC;EAChDlD,GAAG,CAACmD,IAAI,CAACV,OAAO,CAAC;EACjBnD,KAAK,CAAC,cAAc,CAAC;AACvB"}
@@ -1,13 +0,0 @@
1
- import { TemplateUIOptions } from '@verdaccio/types';
2
- import { Manifest } from './utils/manifest';
3
- export type Template = {
4
- manifest: Manifest;
5
- options: TemplateUIOptions;
6
- metaScripts?: string[];
7
- scriptsBodyAfter?: string[];
8
- scriptsbodyBefore?: string[];
9
- };
10
- export interface WebpackManifest {
11
- [key: string]: string;
12
- }
13
- export default function renderTemplate(template: Template, manifest: WebpackManifest): string;
package/build/template.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = renderTemplate;
7
- var _debug = _interopRequireDefault(require("debug"));
8
- var _manifest = require("./utils/manifest");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const debug = (0, _debug.default)('verdaccio:web:render:template');
11
- function renderTemplate(template, manifest) {
12
- var _template$options;
13
- debug('template %o', template);
14
- debug('manifest %o', manifest);
15
- return `
16
- <!DOCTYPE html>
17
- <html lang="en-us">
18
- <head>
19
- <meta charset="utf-8">
20
- <base href="${template === null || template === void 0 ? void 0 : template.options.base}">
21
- <title>${(template === null || template === void 0 ? void 0 : (_template$options = template.options) === null || _template$options === void 0 ? void 0 : _template$options.title) ?? ''}</title>
22
- <link rel="icon" href="${template === null || template === void 0 ? void 0 : template.options.base}-/static/favicon.ico"/>
23
- <meta name="viewport" content="width=device-width, initial-scale=1" />
24
- <script>
25
- window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(template.options)}
26
- </script>
27
- ${template !== null && template !== void 0 && template.metaScripts ? template.metaScripts.join('') : ''}
28
- </head>
29
- <body class="body">
30
- ${template !== null && template !== void 0 && template.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
31
- <div id="root"></div>
32
- ${(0, _manifest.getManifestValue)(template.manifest.js, manifest, template === null || template === void 0 ? void 0 : template.options.base).map(item => `<script defer="defer" src="${item}"></script>`).join('')}
33
- ${template !== null && template !== void 0 && template.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
34
- </body>
35
- </html>
36
- `;
37
- }
38
- //# sourceMappingURL=template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.js","names":["debug","buildDebug","renderTemplate","template","manifest","options","base","title","JSON","stringify","metaScripts","join","scriptsbodyBefore","getManifestValue","js","map","item","scriptsBodyAfter"],"sources":["../src/template.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { TemplateUIOptions } from '@verdaccio/types';\n\nimport { Manifest, getManifestValue } from './utils/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 ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}\n </body>\n </html>\n `;\n}\n"],"mappings":";;;;;;AAAA;AAIA;AAA8D;AAE9D,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;AAe1C,SAASC,cAAc,CAACC,QAAkB,EAAEC,QAAyB,EAAE;EAAA;EACpFJ,KAAK,CAAC,aAAa,EAAEG,QAAQ,CAAC;EAC9BH,KAAK,CAAC,aAAa,EAAEI,QAAQ,CAAC;EAE9B,OAAQ;AACV;AACA;AACA;AACA;AACA,sBAAsBD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,OAAO,CAACC,IAAK;AAC7C,iBAAiB,CAAAH,QAAQ,aAARA,QAAQ,4CAARA,QAAQ,CAAEE,OAAO,sDAAjB,kBAAmBE,KAAK,KAAI,EAAG;AAChD,iCAAiCJ,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,OAAO,CAACC,IAAK;AACxD;AACA;AACA,qDAAqDE,IAAI,CAACC,SAAS,CAACN,QAAQ,CAACE,OAAO,CAAE;AACtF;AACA,UAAUF,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEO,WAAW,GAAGP,QAAQ,CAACO,WAAW,CAACC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAG;AACrE;AACA;AACA,QAAQR,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAES,iBAAiB,GAAGT,QAAQ,CAACS,iBAAiB,CAACD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAG;AAC/E;AACA,UAAU,IAAAE,0BAAgB,EAACV,QAAQ,CAACC,QAAQ,CAACU,EAAE,EAAEV,QAAQ,EAAED,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,OAAO,CAACC,IAAI,CAAC,CACvES,GAAG,CAAEC,IAAI,IAAM,8BAA6BA,IAAK,aAAY,CAAC,CAC9DL,IAAI,CAAC,EAAE,CAAE;AACpB,UAAUR,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEc,gBAAgB,GAAGd,QAAQ,CAACc,gBAAgB,CAACN,IAAI,CAAC,EAAE,CAAC,GAAG,EAAG;AAC/E;AACA;AACA,GAAG;AACH"}
@@ -1,6 +0,0 @@
1
- export type Manifest = {
2
- ico: string;
3
- css: string[];
4
- js: string[];
5
- };
6
- export declare function getManifestValue(manifestItems: string[], manifest: any, basePath?: string): string[];
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getManifestValue = getManifestValue;
7
- var _debug = _interopRequireDefault(require("debug"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const debug = (0, _debug.default)('verdaccio:web:render:manifest');
10
- function getManifestValue(manifestItems, manifest, basePath = '') {
11
- return manifestItems === null || manifestItems === void 0 ? void 0 : manifestItems.map(item => {
12
- debug('resolve item %o', item);
13
- const resolvedItem = `${basePath}${manifest[item]}`;
14
- debug('resolved item %o', resolvedItem);
15
- return resolvedItem;
16
- });
17
- }
18
- //# sourceMappingURL=manifest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest.js","names":["debug","buildDebug","getManifestValue","manifestItems","manifest","basePath","map","item","resolvedItem"],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nexport type Manifest = {\n // goes on first place at the header\n ico: string;\n css: string[];\n js: string[];\n};\n\nconst debug = buildDebug('verdaccio:web:render:manifest');\n\nexport function getManifestValue(\n manifestItems: string[],\n manifest,\n basePath: string = ''\n): string[] {\n return manifestItems?.map((item) => {\n debug('resolve item %o', item);\n const resolvedItem = `${basePath}${manifest[item]}`;\n debug('resolved item %o', resolvedItem);\n return resolvedItem;\n });\n}\n"],"mappings":";;;;;;AAAA;AAA+B;AAS/B,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;AAElD,SAASC,gBAAgB,CAC9BC,aAAuB,EACvBC,QAAQ,EACRC,QAAgB,GAAG,EAAE,EACX;EACV,OAAOF,aAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEG,GAAG,CAAEC,IAAI,IAAK;IAClCP,KAAK,CAAC,iBAAiB,EAAEO,IAAI,CAAC;IAC9B,MAAMC,YAAY,GAAI,GAAEH,QAAS,GAAED,QAAQ,CAACG,IAAI,CAAE,EAAC;IACnDP,KAAK,CAAC,kBAAkB,EAAEQ,YAAY,CAAC;IACvC,OAAOA,YAAY;EACrB,CAAC,CAAC;AACJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-utils.js","names":["debug","buildDebug","validatePrimaryColor","primaryColor","isHex","test","deleteProperties","propertiesToDelete","objectItem","_","forEach","property","addScope","scope","packageName","sortByName","packages","orderAscending","slice","sort","a","b","comparatorNames","name","toLowerCase","hasLogin","config","isNil","web","login"],"sources":["../../src/utils/web-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\n// import { normalizeContributors } from '@verdaccio/store';\nimport { Author, ConfigYaml } from '@verdaccio/types';\n\nexport type AuthorAvatar = Author & { avatar?: string };\n\nconst debug = buildDebug('verdaccio:web:utils');\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 deleteProperties(propertiesToDelete: string[], objectItem: any): any {\n debug('deleted unused version properties');\n _.forEach(propertiesToDelete, (property): any => {\n delete objectItem[property];\n });\n\n return objectItem;\n}\n\nexport function addScope(scope: string, packageName: string): string {\n return `@${scope}/${packageName}`;\n}\n\nexport function sortByName(packages: any[], orderAscending: boolean | void = true): string[] {\n return packages.slice().sort(function (a, b): number {\n const comparatorNames = a.name.toLowerCase() < b.name.toLowerCase();\n return orderAscending ? (comparatorNames ? -1 : 1) : comparatorNames ? 1 : -1;\n });\n}\n\nexport function hasLogin(config: ConfigYaml) {\n return _.isNil(config?.web?.login) || config?.web?.login === true;\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AAAuB;AAOvB,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,qBAAqB,CAAC;AAExC,SAASC,oBAAoB,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,SA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