@verdaccio/middleware 8.0.7 → 8.1.0

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 (119) hide show
  1. package/build/_virtual/_rolldown/runtime.js +23 -0
  2. package/build/index.js +62 -229
  3. package/build/index.mjs +23 -0
  4. package/build/middlewares/allow.js +42 -50
  5. package/build/middlewares/allow.js.map +1 -1
  6. package/build/middlewares/allow.mjs +44 -0
  7. package/build/middlewares/allow.mjs.map +1 -0
  8. package/build/middlewares/antiLoop.js +21 -40
  9. package/build/middlewares/antiLoop.js.map +1 -1
  10. package/build/middlewares/antiLoop.mjs +25 -0
  11. package/build/middlewares/antiLoop.mjs.map +1 -0
  12. package/build/middlewares/api_urls.js +66 -59
  13. package/build/middlewares/api_urls.js.map +1 -1
  14. package/build/middlewares/api_urls.mjs +59 -0
  15. package/build/middlewares/api_urls.mjs.map +1 -0
  16. package/build/middlewares/body-parser.js +24 -32
  17. package/build/middlewares/body-parser.js.map +1 -1
  18. package/build/middlewares/body-parser.mjs +28 -0
  19. package/build/middlewares/body-parser.mjs.map +1 -0
  20. package/build/middlewares/encode-pkg.js +20 -36
  21. package/build/middlewares/encode-pkg.js.map +1 -1
  22. package/build/middlewares/encode-pkg.mjs +22 -0
  23. package/build/middlewares/encode-pkg.mjs.map +1 -0
  24. package/build/middlewares/error.js +53 -71
  25. package/build/middlewares/error.js.map +1 -1
  26. package/build/middlewares/error.mjs +53 -0
  27. package/build/middlewares/error.mjs.map +1 -0
  28. package/build/middlewares/final.js +46 -57
  29. package/build/middlewares/final.js.map +1 -1
  30. package/build/middlewares/final.mjs +46 -0
  31. package/build/middlewares/final.mjs.map +1 -0
  32. package/build/middlewares/json.js +7 -11
  33. package/build/middlewares/json.js.map +1 -1
  34. package/build/middlewares/json.mjs +10 -0
  35. package/build/middlewares/json.mjs.map +1 -0
  36. package/build/middlewares/log.js +73 -94
  37. package/build/middlewares/log.js.map +1 -1
  38. package/build/middlewares/log.mjs +71 -0
  39. package/build/middlewares/log.mjs.map +1 -0
  40. package/build/middlewares/make-url-relative.js +26 -41
  41. package/build/middlewares/make-url-relative.js.map +1 -1
  42. package/build/middlewares/make-url-relative.mjs +28 -0
  43. package/build/middlewares/make-url-relative.mjs.map +1 -0
  44. package/build/middlewares/match.js +8 -13
  45. package/build/middlewares/match.js.map +1 -1
  46. package/build/middlewares/match.mjs +11 -0
  47. package/build/middlewares/match.mjs.map +1 -0
  48. package/build/middlewares/media.js +14 -19
  49. package/build/middlewares/media.js.map +1 -1
  50. package/build/middlewares/media.mjs +17 -0
  51. package/build/middlewares/media.mjs.map +1 -0
  52. package/build/middlewares/rate-limit.js +8 -10
  53. package/build/middlewares/rate-limit.js.map +1 -1
  54. package/build/middlewares/rate-limit.mjs +9 -0
  55. package/build/middlewares/rate-limit.mjs.map +1 -0
  56. package/build/middlewares/request-options.js +18 -27
  57. package/build/middlewares/request-options.js.map +1 -1
  58. package/build/middlewares/request-options.mjs +19 -0
  59. package/build/middlewares/request-options.mjs.map +1 -0
  60. package/build/middlewares/token-auth.js +90 -105
  61. package/build/middlewares/token-auth.js.map +1 -1
  62. package/build/middlewares/token-auth.mjs +100 -0
  63. package/build/middlewares/token-auth.mjs.map +1 -0
  64. package/build/middlewares/user-agent.js +10 -12
  65. package/build/middlewares/user-agent.js.map +1 -1
  66. package/build/middlewares/user-agent.mjs +13 -0
  67. package/build/middlewares/user-agent.mjs.map +1 -0
  68. package/build/middlewares/validation.js +10 -18
  69. package/build/middlewares/validation.js.map +1 -1
  70. package/build/middlewares/validation.mjs +14 -0
  71. package/build/middlewares/validation.mjs.map +1 -0
  72. package/build/middlewares/web/index.js +4 -35
  73. package/build/middlewares/web/index.mjs +4 -0
  74. package/build/middlewares/web/render-web.js +86 -113
  75. package/build/middlewares/web/render-web.js.map +1 -1
  76. package/build/middlewares/web/render-web.mjs +85 -0
  77. package/build/middlewares/web/render-web.mjs.map +1 -0
  78. package/build/middlewares/web/security.js +29 -41
  79. package/build/middlewares/web/security.js.map +1 -1
  80. package/build/middlewares/web/security.mjs +30 -0
  81. package/build/middlewares/web/security.mjs.map +1 -0
  82. package/build/middlewares/web/utils/manifest.js +17 -18
  83. package/build/middlewares/web/utils/manifest.js.map +1 -1
  84. package/build/middlewares/web/utils/manifest.mjs +21 -0
  85. package/build/middlewares/web/utils/manifest.mjs.map +1 -0
  86. package/build/middlewares/web/utils/renderHTML.js +46 -50
  87. package/build/middlewares/web/utils/renderHTML.js.map +1 -1
  88. package/build/middlewares/web/utils/renderHTML.mjs +48 -0
  89. package/build/middlewares/web/utils/renderHTML.mjs.map +1 -0
  90. package/build/middlewares/web/utils/template.js +19 -20
  91. package/build/middlewares/web/utils/template.js.map +1 -1
  92. package/build/middlewares/web/utils/template.mjs +33 -0
  93. package/build/middlewares/web/utils/template.mjs.map +1 -0
  94. package/build/middlewares/web/utils/ui-options.js +66 -82
  95. package/build/middlewares/web/utils/ui-options.js.map +1 -1
  96. package/build/middlewares/web/utils/ui-options.mjs +69 -0
  97. package/build/middlewares/web/utils/ui-options.mjs.map +1 -0
  98. package/build/middlewares/web/utils/web-utils.js +17 -18
  99. package/build/middlewares/web/utils/web-utils.js.map +1 -1
  100. package/build/middlewares/web/utils/web-utils.mjs +18 -0
  101. package/build/middlewares/web/utils/web-utils.mjs.map +1 -0
  102. package/build/middlewares/web/web-api.js +18 -27
  103. package/build/middlewares/web/web-api.js.map +1 -1
  104. package/build/middlewares/web/web-api.mjs +19 -0
  105. package/build/middlewares/web/web-api.mjs.map +1 -0
  106. package/build/middlewares/web/web-middleware.d.ts +1 -1
  107. package/build/middlewares/web/web-middleware.js +16 -23
  108. package/build/middlewares/web/web-middleware.js.map +1 -1
  109. package/build/middlewares/web/web-middleware.mjs +16 -0
  110. package/build/middlewares/web/web-middleware.mjs.map +1 -0
  111. package/build/middlewares/web/web-urls.js +28 -29
  112. package/build/middlewares/web/web-urls.js.map +1 -1
  113. package/build/middlewares/web/web-urls.mjs +32 -0
  114. package/build/middlewares/web/web-urls.mjs.map +1 -0
  115. package/package.json +24 -11
  116. package/build/index.js.map +0 -1
  117. package/build/middlewares/web/index.js.map +0 -1
  118. package/build/types.js +0 -6
  119. package/build/types.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ import { setSecurityWebHeaders } from "./security.mjs";
2
+ import renderHTML from "./utils/renderHTML.mjs";
3
+ import { getUIOptions } from "./utils/ui-options.mjs";
4
+ import { WebUrlsNamespace } from "./web-urls.mjs";
5
+ import { HEADERS, HTTP_STATUS } from "@verdaccio/core";
6
+ import buildDebug from "debug";
7
+ import express from "express";
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import { isURLhasValidProtocol } from "@verdaccio/url";
11
+ //#region src/middlewares/web/render-web.ts
12
+ var debug = buildDebug("verdaccio:web:render");
13
+ var sendFileCallback = (next) => (err) => {
14
+ if (!err) return;
15
+ if (err.status === HTTP_STATUS.NOT_FOUND) next();
16
+ else next(err);
17
+ };
18
+ function renderWebMiddleware(config, tokenMiddleware, pluginOptions) {
19
+ const { staticPath, manifest, manifestFiles } = pluginOptions;
20
+ debug("static path %o", staticPath);
21
+ const router = express.Router();
22
+ if (typeof tokenMiddleware === "function") router.use(tokenMiddleware);
23
+ router.use(setSecurityWebHeaders);
24
+ router.get(WebUrlsNamespace.static + "*", function(req, res, next) {
25
+ const filename = req.params[0];
26
+ let file = `${staticPath}/${filename}`;
27
+ if (filename === "favicon.ico" && config?.web?.favicon) {
28
+ file = config?.web?.favicon;
29
+ if (isURLhasValidProtocol(file)) {
30
+ debug("redirect to favicon %s", file);
31
+ req.url = file;
32
+ return next();
33
+ }
34
+ }
35
+ debug("render static file %o", file);
36
+ res.sendFile(file, sendFileCallback(next));
37
+ });
38
+ function renderLogo(logo) {
39
+ if (logo && !isURLhasValidProtocol(logo)) {
40
+ const absoluteLocalFile = path.posix.resolve(logo);
41
+ debug("serve local logo %s", absoluteLocalFile);
42
+ try {
43
+ if (fs.existsSync(absoluteLocalFile) && typeof fs.accessSync(absoluteLocalFile, fs.constants.R_OK) === "undefined") {
44
+ logo = path.posix.join(WebUrlsNamespace.static, path.basename(logo));
45
+ router.get(logo, function(_req, res, next) {
46
+ debug("serve custom logo web:%s - local:%s", logo, absoluteLocalFile);
47
+ res.sendFile(absoluteLocalFile, sendFileCallback(next));
48
+ });
49
+ debug("enabled custom logo %s", logo);
50
+ } else {
51
+ logo = void 0;
52
+ debug(`web logo is wrong, path ${absoluteLocalFile} does not exist or is not readable`);
53
+ }
54
+ } catch {
55
+ logo = void 0;
56
+ debug(`web logo is wrong, path ${absoluteLocalFile} does not exist or is not readable`);
57
+ }
58
+ }
59
+ return logo;
60
+ }
61
+ const logo = renderLogo(config?.web?.logo);
62
+ if (config?.web?.logo) config.web.logo = logo;
63
+ const logoDark = renderLogo(config?.web?.logoDark);
64
+ if (config?.web?.logoDark) config.web.logoDark = logoDark;
65
+ router.get(WebUrlsNamespace.static + "ui-options.js", function(req, res) {
66
+ const options = getUIOptions(config, req, res);
67
+ const script = `window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(options)};`;
68
+ res.setHeader(HEADERS.CACHE_CONTROL, HEADERS.NO_CACHE);
69
+ res.setHeader(HEADERS.CONTENT_TYPE, HEADERS.JAVASCRIPT_CHARSET);
70
+ res.send(script);
71
+ });
72
+ router.get(WebUrlsNamespace.web + "*", function(req, res) {
73
+ renderHTML(config, manifest, manifestFiles, getUIOptions(config, req, res), res);
74
+ debug("render html section");
75
+ });
76
+ router.get(WebUrlsNamespace.root, function(req, res) {
77
+ renderHTML(config, manifest, manifestFiles, getUIOptions(config, req, res), res);
78
+ debug("render root");
79
+ });
80
+ return router;
81
+ }
82
+ //#endregion
83
+ export { renderWebMiddleware };
84
+
85
+ //# sourceMappingURL=render-web.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-web.mjs","names":[],"sources":["../../../src/middlewares/web/render-web.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport express from 'express';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { HEADERS, HTTP_STATUS } from '@verdaccio/core';\nimport { isURLhasValidProtocol } from '@verdaccio/url';\n\nimport { setSecurityWebHeaders } from './security';\nimport renderHTML from './utils/renderHTML';\nimport { getUIOptions } from './utils/ui-options';\nimport { WebUrlsNamespace } from './web-urls';\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 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(WebUrlsNamespace.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(WebUrlsNamespace.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 // Serve external script that loads UI options\n router.get(WebUrlsNamespace.static + 'ui-options.js', function (req, res) {\n const options = getUIOptions(config, req, res);\n const script = `window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(options)};`;\n res.setHeader(HEADERS.CACHE_CONTROL, HEADERS.NO_CACHE);\n res.setHeader(HEADERS.CONTENT_TYPE, HEADERS.JAVASCRIPT_CHARSET);\n res.send(script);\n });\n\n // Handle all web routes including security routes\n router.get(WebUrlsNamespace.web + '*', function (req, res) {\n const options = getUIOptions(config, req, res);\n renderHTML(config, manifest, manifestFiles, options, res);\n debug('render html section');\n });\n\n router.get(WebUrlsNamespace.root, function (req, res) {\n const options = getUIOptions(config, req, res);\n renderHTML(config, manifest, manifestFiles, options, res);\n debug('render root');\n });\n\n return router;\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,QAAQ,WAAW,sBAAsB;AAE/C,IAAM,oBAAoB,UAAU,QAAQ;CAC1C,IAAI,CAAC,KACH;CAEF,IAAI,IAAI,WAAW,YAAY,WAC7B,KAAK;MAEL,KAAK,GAAG;AAEZ;AAEA,SAAgB,oBAAoB,QAAQ,iBAAiB,eAAe;CAC1E,MAAM,EAAE,YAAY,UAAU,kBAAkB;CAChD,MAAM,kBAAkB,UAAU;CAElC,MAAM,SAAS,QAAQ,OAAO;CAC9B,IAAI,OAAO,oBAAoB,YAC7B,OAAO,IAAI,eAAe;CAG5B,OAAO,IAAI,qBAAqB;CAGhC,OAAO,IAAI,iBAAiB,SAAS,KAAK,SAAU,KAAK,KAAK,MAAM;EAClE,MAAM,WAAW,IAAI,OAAO;EAC5B,IAAI,OAAO,GAAG,WAAW,GAAG;EAC5B,IAAI,aAAa,iBAAiB,QAAQ,KAAK,SAAS;GACtD,OAAO,QAAQ,KAAK;GACpB,IAAI,sBAAsB,IAAI,GAAG;IAC/B,MAAM,0BAA0B,IAAI;IACpC,IAAI,MAAM;IACV,OAAO,KAAK;GACd;EACF;EACA,MAAM,yBAAyB,IAAI;EACnC,IAAI,SAAS,MAAM,iBAAiB,IAAI,CAAC;CAC3C,CAAC;CAED,SAAS,WAAW,MAA8C;EAEhE,IAAI,QAAQ,CAAC,sBAAsB,IAAI,GAAG;GAExC,MAAM,oBAAoB,KAAK,MAAM,QAAQ,IAAI;GACjD,MAAM,uBAAuB,iBAAiB;GAC9C,IAAI;IAEF,IACE,GAAG,WAAW,iBAAiB,KAC/B,OAAO,GAAG,WAAW,mBAAmB,GAAG,UAAU,IAAI,MAAM,aAC/D;KAGA,OAAO,KAAK,MAAM,KAAK,iBAAiB,QAAQ,KAAK,SAAS,IAAI,CAAC;KACnE,OAAO,IAAI,MAAM,SAAU,MAAM,KAAK,MAAM;MAE1C,MAAM,wCAAwC,MAAM,iBAAiB;MACrE,IAAI,SAAS,mBAAmB,iBAAiB,IAAI,CAAC;KACxD,CAAC;KACD,MAAM,0BAA0B,IAAI;IACtC,OAAO;KACL,OAAO,KAAA;KACP,MAAM,2BAA2B,kBAAkB,mCAAmC;IACxF;GACF,QAAQ;IACN,OAAO,KAAA;IACP,MAAM,2BAA2B,kBAAkB,mCAAmC;GACxF;EACF;EACA,OAAO;CACT;CAEA,MAAM,OAAO,WAAW,QAAQ,KAAK,IAAI;CACzC,IAAI,QAAQ,KAAK,MACf,OAAO,IAAI,OAAO;CAEpB,MAAM,WAAW,WAAW,QAAQ,KAAK,QAAQ;CACjD,IAAI,QAAQ,KAAK,UACf,OAAO,IAAI,WAAW;CAIxB,OAAO,IAAI,iBAAiB,SAAS,iBAAiB,SAAU,KAAK,KAAK;EACxE,MAAM,UAAU,aAAa,QAAQ,KAAK,GAAG;EAC7C,MAAM,SAAS,0CAA0C,KAAK,UAAU,OAAO,EAAE;EACjF,IAAI,UAAU,QAAQ,eAAe,QAAQ,QAAQ;EACrD,IAAI,UAAU,QAAQ,cAAc,QAAQ,kBAAkB;EAC9D,IAAI,KAAK,MAAM;CACjB,CAAC;CAGD,OAAO,IAAI,iBAAiB,MAAM,KAAK,SAAU,KAAK,KAAK;EAEzD,WAAW,QAAQ,UAAU,eADb,aAAa,QAAQ,KAAK,GACE,GAAS,GAAG;EACxD,MAAM,qBAAqB;CAC7B,CAAC;CAED,OAAO,IAAI,iBAAiB,MAAM,SAAU,KAAK,KAAK;EAEpD,WAAW,QAAQ,UAAU,eADb,aAAa,QAAQ,KAAK,GACE,GAAS,GAAG;EACxD,MAAM,aAAa;CACrB,CAAC;CAED,OAAO;AACT"}
@@ -1,44 +1,32 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setSecurityWebHeaders = setSecurityWebHeaders;
7
- var _debug = _interopRequireDefault(require("debug"));
8
- var _core = require("@verdaccio/core");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const debug = (0, _debug.default)('verdaccio:middleware:web:security');
1
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
2
+ let _verdaccio_core = require("@verdaccio/core");
3
+ let debug = require("debug");
4
+ debug = require_runtime.__toESM(debug);
5
+ //#region src/middlewares/web/security.ts
6
+ var debug$1 = (0, debug.default)("verdaccio:middleware:web:security");
11
7
  function setSecurityWebHeaders(_req, res, next) {
12
- // disable loading in frames (clickjacking, etc.)
13
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options
14
- const framesOptions = res.getHeader(_core.HEADERS.FRAMES_OPTIONS);
15
- if (!framesOptions || !(framesOptions === 'deny' || framesOptions === 'sameorigin')) {
16
- debug('Missing or invalid X-Frame-Options header; setting to "deny"');
17
- res.header(_core.HEADERS.FRAMES_OPTIONS, 'deny');
18
- }
19
-
20
- // avoid establishing connections outside of domain
21
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy
22
- if (!res.getHeader(_core.HEADERS.CSP)) {
23
- debug('Missing Content-Security-Policy header; setting to "connect-src \'self\'"');
24
- res.header(_core.HEADERS.CSP, "connect-src 'self'");
25
- }
26
-
27
- // respect the content type of the response
28
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Content-Type-Options
29
- const cto = res.getHeader(_core.HEADERS.CTO);
30
- if (!cto || cto !== 'nosniff') {
31
- debug('Missing or invalid X-Content-Type-Options header; setting to "nosniff"');
32
- res.header(_core.HEADERS.CTO, 'nosniff');
33
- }
34
-
35
- // block rendering of the page in case of XSS attack
36
- // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection
37
- const xss = res.getHeader(_core.HEADERS.XSS);
38
- if (!xss || !(xss === '0' || xss.startsWith('1'))) {
39
- debug('Missing or invalid X-XSS-Protection header; setting to "1; mode=block"');
40
- res.header(_core.HEADERS.XSS, '1; mode=block');
41
- }
42
- next();
8
+ const framesOptions = res.getHeader(_verdaccio_core.HEADERS.FRAMES_OPTIONS);
9
+ if (!framesOptions || !(framesOptions === "deny" || framesOptions === "sameorigin")) {
10
+ debug$1("Missing or invalid X-Frame-Options header; setting to \"deny\"");
11
+ res.header(_verdaccio_core.HEADERS.FRAMES_OPTIONS, "deny");
12
+ }
13
+ if (!res.getHeader(_verdaccio_core.HEADERS.CSP)) {
14
+ debug$1("Missing Content-Security-Policy header; setting to \"connect-src 'self'\"");
15
+ res.header(_verdaccio_core.HEADERS.CSP, "connect-src 'self'");
16
+ }
17
+ const cto = res.getHeader(_verdaccio_core.HEADERS.CTO);
18
+ if (!cto || cto !== "nosniff") {
19
+ debug$1("Missing or invalid X-Content-Type-Options header; setting to \"nosniff\"");
20
+ res.header(_verdaccio_core.HEADERS.CTO, "nosniff");
21
+ }
22
+ const xss = res.getHeader(_verdaccio_core.HEADERS.XSS);
23
+ if (!xss || !(xss === "0" || xss.startsWith("1"))) {
24
+ debug$1("Missing or invalid X-XSS-Protection header; setting to \"1; mode=block\"");
25
+ res.header(_verdaccio_core.HEADERS.XSS, "1; mode=block");
26
+ }
27
+ next();
43
28
  }
29
+ //#endregion
30
+ exports.setSecurityWebHeaders = setSecurityWebHeaders;
31
+
44
32
  //# sourceMappingURL=security.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"security.js","names":["_debug","_interopRequireDefault","require","_core","e","__esModule","default","debug","buildDebug","setSecurityWebHeaders","_req","res","next","framesOptions","getHeader","HEADERS","FRAMES_OPTIONS","header","CSP","cto","CTO","xss","XSS","startsWith"],"sources":["../../../src/middlewares/web/security.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:middleware:web:security');\n\nexport function setSecurityWebHeaders(_req, res, next): void {\n // disable loading in frames (clickjacking, etc.)\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options\n const framesOptions = res.getHeader(HEADERS.FRAMES_OPTIONS);\n if (!framesOptions || !(framesOptions === 'deny' || framesOptions === 'sameorigin')) {\n debug('Missing or invalid X-Frame-Options header; setting to \"deny\"');\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n }\n\n // avoid establishing connections outside of domain\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy\n if (!res.getHeader(HEADERS.CSP)) {\n debug('Missing Content-Security-Policy header; setting to \"connect-src \\'self\\'\"');\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n }\n\n // respect the content type of the response\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Content-Type-Options\n const cto = res.getHeader(HEADERS.CTO);\n if (!cto || cto !== 'nosniff') {\n debug('Missing or invalid X-Content-Type-Options header; setting to \"nosniff\"');\n res.header(HEADERS.CTO, 'nosniff');\n }\n\n // block rendering of the page in case of XSS attack\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection\n const xss = res.getHeader(HEADERS.XSS);\n if (!xss || !(xss === '0' || xss.startsWith('1'))) {\n debug('Missing or invalid X-XSS-Protection header; setting to \"1; mode=block\"');\n res.header(HEADERS.XSS, '1; mode=block');\n }\n next();\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAA0C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,mCAAmC,CAAC;AAEtD,SAASC,qBAAqBA,CAACC,IAAI,EAAEC,GAAG,EAAEC,IAAI,EAAQ;EAC3D;EACA;EACA,MAAMC,aAAa,GAAGF,GAAG,CAACG,SAAS,CAACC,aAAO,CAACC,cAAc,CAAC;EAC3D,IAAI,CAACH,aAAa,IAAI,EAAEA,aAAa,KAAK,MAAM,IAAIA,aAAa,KAAK,YAAY,CAAC,EAAE;IACnFN,KAAK,CAAC,8DAA8D,CAAC;IACrEI,GAAG,CAACM,MAAM,CAACF,aAAO,CAACC,cAAc,EAAE,MAAM,CAAC;EAC5C;;EAEA;EACA;EACA,IAAI,CAACL,GAAG,CAACG,SAAS,CAACC,aAAO,CAACG,GAAG,CAAC,EAAE;IAC/BX,KAAK,CAAC,2EAA2E,CAAC;IAClFI,GAAG,CAACM,MAAM,CAACF,aAAO,CAACG,GAAG,EAAE,oBAAoB,CAAC;EAC/C;;EAEA;EACA;EACA,MAAMC,GAAG,GAAGR,GAAG,CAACG,SAAS,CAACC,aAAO,CAACK,GAAG,CAAC;EACtC,IAAI,CAACD,GAAG,IAAIA,GAAG,KAAK,SAAS,EAAE;IAC7BZ,KAAK,CAAC,wEAAwE,CAAC;IAC/EI,GAAG,CAACM,MAAM,CAACF,aAAO,CAACK,GAAG,EAAE,SAAS,CAAC;EACpC;;EAEA;EACA;EACA,MAAMC,GAAG,GAAGV,GAAG,CAACG,SAAS,CAACC,aAAO,CAACO,GAAG,CAAC;EACtC,IAAI,CAACD,GAAG,IAAI,EAAEA,GAAG,KAAK,GAAG,IAAIA,GAAG,CAACE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE;IACjDhB,KAAK,CAAC,wEAAwE,CAAC;IAC/EI,GAAG,CAACM,MAAM,CAACF,aAAO,CAACO,GAAG,EAAE,eAAe,CAAC;EAC1C;EACAV,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"file":"security.js","names":[],"sources":["../../../src/middlewares/web/security.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:middleware:web:security');\n\nexport function setSecurityWebHeaders(_req, res, next): void {\n // disable loading in frames (clickjacking, etc.)\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options\n const framesOptions = res.getHeader(HEADERS.FRAMES_OPTIONS);\n if (!framesOptions || !(framesOptions === 'deny' || framesOptions === 'sameorigin')) {\n debug('Missing or invalid X-Frame-Options header; setting to \"deny\"');\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n }\n\n // avoid establishing connections outside of domain\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy\n if (!res.getHeader(HEADERS.CSP)) {\n debug('Missing Content-Security-Policy header; setting to \"connect-src \\'self\\'\"');\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n }\n\n // respect the content type of the response\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Content-Type-Options\n const cto = res.getHeader(HEADERS.CTO);\n if (!cto || cto !== 'nosniff') {\n debug('Missing or invalid X-Content-Type-Options header; setting to \"nosniff\"');\n res.header(HEADERS.CTO, 'nosniff');\n }\n\n // block rendering of the page in case of XSS attack\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection\n const xss = res.getHeader(HEADERS.XSS);\n if (!xss || !(xss === '0' || xss.startsWith('1'))) {\n debug('Missing or invalid X-XSS-Protection header; setting to \"1; mode=block\"');\n res.header(HEADERS.XSS, '1; mode=block');\n }\n next();\n}\n"],"mappings":";;;;;AAIA,IAAM,WAAA,GAAA,MAAA,SAAmB,mCAAmC;AAE5D,SAAgB,sBAAsB,MAAM,KAAK,MAAY;CAG3D,MAAM,gBAAgB,IAAI,UAAU,gBAAA,QAAQ,cAAc;CAC1D,IAAI,CAAC,iBAAiB,EAAE,kBAAkB,UAAU,kBAAkB,eAAe;EACnF,QAAM,gEAA8D;EACpE,IAAI,OAAO,gBAAA,QAAQ,gBAAgB,MAAM;CAC3C;CAIA,IAAI,CAAC,IAAI,UAAU,gBAAA,QAAQ,GAAG,GAAG;EAC/B,QAAM,2EAA2E;EACjF,IAAI,OAAO,gBAAA,QAAQ,KAAK,oBAAoB;CAC9C;CAIA,MAAM,MAAM,IAAI,UAAU,gBAAA,QAAQ,GAAG;CACrC,IAAI,CAAC,OAAO,QAAQ,WAAW;EAC7B,QAAM,0EAAwE;EAC9E,IAAI,OAAO,gBAAA,QAAQ,KAAK,SAAS;CACnC;CAIA,MAAM,MAAM,IAAI,UAAU,gBAAA,QAAQ,GAAG;CACrC,IAAI,CAAC,OAAO,EAAE,QAAQ,OAAO,IAAI,WAAW,GAAG,IAAI;EACjD,QAAM,0EAAwE;EAC9E,IAAI,OAAO,gBAAA,QAAQ,KAAK,eAAe;CACzC;CACA,KAAK;AACP"}
@@ -0,0 +1,30 @@
1
+ import { HEADERS } from "@verdaccio/core";
2
+ import buildDebug from "debug";
3
+ //#region src/middlewares/web/security.ts
4
+ var debug = buildDebug("verdaccio:middleware:web:security");
5
+ function setSecurityWebHeaders(_req, res, next) {
6
+ const framesOptions = res.getHeader(HEADERS.FRAMES_OPTIONS);
7
+ if (!framesOptions || !(framesOptions === "deny" || framesOptions === "sameorigin")) {
8
+ debug("Missing or invalid X-Frame-Options header; setting to \"deny\"");
9
+ res.header(HEADERS.FRAMES_OPTIONS, "deny");
10
+ }
11
+ if (!res.getHeader(HEADERS.CSP)) {
12
+ debug("Missing Content-Security-Policy header; setting to \"connect-src 'self'\"");
13
+ res.header(HEADERS.CSP, "connect-src 'self'");
14
+ }
15
+ const cto = res.getHeader(HEADERS.CTO);
16
+ if (!cto || cto !== "nosniff") {
17
+ debug("Missing or invalid X-Content-Type-Options header; setting to \"nosniff\"");
18
+ res.header(HEADERS.CTO, "nosniff");
19
+ }
20
+ const xss = res.getHeader(HEADERS.XSS);
21
+ if (!xss || !(xss === "0" || xss.startsWith("1"))) {
22
+ debug("Missing or invalid X-XSS-Protection header; setting to \"1; mode=block\"");
23
+ res.header(HEADERS.XSS, "1; mode=block");
24
+ }
25
+ next();
26
+ }
27
+ //#endregion
28
+ export { setSecurityWebHeaders };
29
+
30
+ //# sourceMappingURL=security.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.mjs","names":[],"sources":["../../../src/middlewares/web/security.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport { HEADERS } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:middleware:web:security');\n\nexport function setSecurityWebHeaders(_req, res, next): void {\n // disable loading in frames (clickjacking, etc.)\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Frame-Options\n const framesOptions = res.getHeader(HEADERS.FRAMES_OPTIONS);\n if (!framesOptions || !(framesOptions === 'deny' || framesOptions === 'sameorigin')) {\n debug('Missing or invalid X-Frame-Options header; setting to \"deny\"');\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n }\n\n // avoid establishing connections outside of domain\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy\n if (!res.getHeader(HEADERS.CSP)) {\n debug('Missing Content-Security-Policy header; setting to \"connect-src \\'self\\'\"');\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n }\n\n // respect the content type of the response\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Content-Type-Options\n const cto = res.getHeader(HEADERS.CTO);\n if (!cto || cto !== 'nosniff') {\n debug('Missing or invalid X-Content-Type-Options header; setting to \"nosniff\"');\n res.header(HEADERS.CTO, 'nosniff');\n }\n\n // block rendering of the page in case of XSS attack\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-XSS-Protection\n const xss = res.getHeader(HEADERS.XSS);\n if (!xss || !(xss === '0' || xss.startsWith('1'))) {\n debug('Missing or invalid X-XSS-Protection header; setting to \"1; mode=block\"');\n res.header(HEADERS.XSS, '1; mode=block');\n }\n next();\n}\n"],"mappings":";;;AAIA,IAAM,QAAQ,WAAW,mCAAmC;AAE5D,SAAgB,sBAAsB,MAAM,KAAK,MAAY;CAG3D,MAAM,gBAAgB,IAAI,UAAU,QAAQ,cAAc;CAC1D,IAAI,CAAC,iBAAiB,EAAE,kBAAkB,UAAU,kBAAkB,eAAe;EACnF,MAAM,gEAA8D;EACpE,IAAI,OAAO,QAAQ,gBAAgB,MAAM;CAC3C;CAIA,IAAI,CAAC,IAAI,UAAU,QAAQ,GAAG,GAAG;EAC/B,MAAM,2EAA2E;EACjF,IAAI,OAAO,QAAQ,KAAK,oBAAoB;CAC9C;CAIA,MAAM,MAAM,IAAI,UAAU,QAAQ,GAAG;CACrC,IAAI,CAAC,OAAO,QAAQ,WAAW;EAC7B,MAAM,0EAAwE;EAC9E,IAAI,OAAO,QAAQ,KAAK,SAAS;CACnC;CAIA,MAAM,MAAM,IAAI,UAAU,QAAQ,GAAG;CACrC,IAAI,CAAC,OAAO,EAAE,QAAQ,OAAO,IAAI,WAAW,GAAG,IAAI;EACjD,MAAM,0EAAwE;EAC9E,IAAI,OAAO,QAAQ,KAAK,eAAe;CACzC;CACA,KAAK;AACP"}
@@ -1,24 +1,23 @@
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(e) { return e && e.__esModule ? e : { default: e }; }
9
- const debug = (0, _debug.default)('verdaccio:middleware:web:render:manifest');
10
- function getManifestValue(manifestItems, manifest, basePath = '') {
11
- return manifestItems?.map(item => {
12
- debug('resolve item %o', item);
13
- const resolvedItem = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;
14
- debug('resolved item %o', resolvedItem);
15
- return resolvedItem;
16
- });
1
+ const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
2
+ let debug = require("debug");
3
+ debug = require_runtime.__toESM(debug);
4
+ //#region src/middlewares/web/utils/manifest.ts
5
+ var debug$1 = (0, debug.default)("verdaccio:middleware:web:render:manifest");
6
+ function getManifestValue(manifestItems, manifest, basePath = "") {
7
+ return manifestItems?.map((item) => {
8
+ debug$1("resolve item %o", item);
9
+ const resolvedItem = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;
10
+ debug$1("resolved item %o", resolvedItem);
11
+ return resolvedItem;
12
+ });
17
13
  }
18
14
  function stripTrailingSlash(path) {
19
- return path.replace(/\/$/, '');
15
+ return path.replace(/\/$/, "");
20
16
  }
21
17
  function stripLeadingSlash(path) {
22
- return path.replace(/^\//, '');
18
+ return path.replace(/^\//, "");
23
19
  }
20
+ //#endregion
21
+ exports.getManifestValue = getManifestValue;
22
+
24
23
  //# sourceMappingURL=manifest.js.map
@@ -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,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":[]}
1
+ {"version":3,"file":"manifest.js","names":[],"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":";;;;AASA,IAAM,WAAA,GAAA,MAAA,SAAmB,0CAA0C;AAEnE,SAAgB,iBACd,eACA,UACA,WAAmB,IACT;CACV,OAAO,eAAe,KAAK,SAAS;EAClC,QAAM,mBAAmB,IAAI;EAC7B,MAAM,eAAe,GAAG,mBAAmB,QAAQ,EAAE,GAAG,kBAAkB,SAAS,KAAK;EACxF,QAAM,oBAAoB,YAAY;EACtC,OAAO;CACT,CAAC;AACH;AAEA,SAAS,mBAAmB,MAAsB;CAChD,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B;AAEA,SAAS,kBAAkB,MAAsB;CAC/C,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B"}
@@ -0,0 +1,21 @@
1
+ import buildDebug from "debug";
2
+ //#region src/middlewares/web/utils/manifest.ts
3
+ var debug = buildDebug("verdaccio:middleware:web:render:manifest");
4
+ function getManifestValue(manifestItems, manifest, basePath = "") {
5
+ return manifestItems?.map((item) => {
6
+ debug("resolve item %o", item);
7
+ const resolvedItem = `${stripTrailingSlash(basePath)}/${stripLeadingSlash(manifest[item])}`;
8
+ debug("resolved item %o", resolvedItem);
9
+ return resolvedItem;
10
+ });
11
+ }
12
+ function stripTrailingSlash(path) {
13
+ return path.replace(/\/$/, "");
14
+ }
15
+ function stripLeadingSlash(path) {
16
+ return path.replace(/^\//, "");
17
+ }
18
+ //#endregion
19
+ export { getManifestValue };
20
+
21
+ //# sourceMappingURL=manifest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.mjs","names":[],"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":";;AASA,IAAM,QAAQ,WAAW,0CAA0C;AAEnE,SAAgB,iBACd,eACA,UACA,WAAmB,IACT;CACV,OAAO,eAAe,KAAK,SAAS;EAClC,MAAM,mBAAmB,IAAI;EAC7B,MAAM,eAAe,GAAG,mBAAmB,QAAQ,EAAE,GAAG,kBAAkB,SAAS,KAAK;EACxF,MAAM,oBAAoB,YAAY;EACtC,OAAO;CACT,CAAC;AACH;AAEA,SAAS,mBAAmB,MAAsB;CAChD,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B;AAEA,SAAS,kBAAkB,MAAsB;CAC/C,OAAO,KAAK,QAAQ,OAAO,EAAE;AAC/B"}
@@ -1,55 +1,51 @@
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 _core = require("@verdaccio/core");
10
- var _template = _interopRequireDefault(require("./template"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- // Cache for rendered HTML templates: max 500 entries, 1 hour TTL
13
- const cache = new _lruCache.default({
14
- max: 500,
15
- ttl: 1000 * 60 * 60
1
+ const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
2
+ const require_template = require("./template.js");
3
+ let _verdaccio_core = require("@verdaccio/core");
4
+ let debug = require("debug");
5
+ debug = require_runtime.__toESM(debug);
6
+ let lru_cache = require("lru-cache");
7
+ lru_cache = require_runtime.__toESM(lru_cache);
8
+ //#region src/middlewares/web/utils/renderHTML.ts
9
+ var cache = new lru_cache.default({
10
+ max: 500,
11
+ ttl: 1e3 * 60 * 60
16
12
  });
17
- const debug = (0, _debug.default)('verdaccio:web:render');
18
- const defaultManifestFiles = {
19
- js: ['vendors.js', 'main.js'],
20
- ico: 'favicon.ico',
21
- css: []
13
+ var debug$1 = (0, debug.default)("verdaccio:web:render");
14
+ var defaultManifestFiles = {
15
+ js: ["vendors.js", "main.js"],
16
+ ico: "favicon.ico",
17
+ css: []
22
18
  };
23
19
  function renderHTML(config, manifest, manifestFiles, options, res) {
24
- // @ts-ignore
25
- const needHtmlCache = [undefined, null].includes(config?.web?.html_cache) ? true : config?.web?.html_cache;
26
- const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];
27
- const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];
28
- const metaScripts = config?.web?.metaScripts || [];
29
- let webPage;
30
- const cacheKey = `template:${JSON.stringify(options)}`;
31
- try {
32
- webPage = cache.get(cacheKey);
33
- if (!webPage) {
34
- webPage = (0, _template.default)({
35
- manifest: manifestFiles ?? defaultManifestFiles,
36
- options,
37
- scriptsBodyAfter,
38
- metaScripts,
39
- scriptsBodyBefore
40
- }, manifest);
41
- if (needHtmlCache) {
42
- cache.set(cacheKey, webPage);
43
- debug('set template cache');
44
- }
45
- } else {
46
- debug('reuse template cache');
47
- }
48
- } catch (error) {
49
- throw new Error(`theme could not be load, stack ${error.stack}`);
50
- }
51
- res.setHeader('Content-Type', _core.HEADERS.TEXT_HTML);
52
- res.send(webPage);
53
- debug('web rendered');
20
+ const needHtmlCache = [void 0, null].includes(config?.web?.html_cache) ? true : config?.web?.html_cache;
21
+ const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];
22
+ const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];
23
+ const metaScripts = config?.web?.metaScripts || [];
24
+ let webPage;
25
+ const cacheKey = `template:${JSON.stringify(options)}`;
26
+ try {
27
+ webPage = cache.get(cacheKey);
28
+ if (!webPage) {
29
+ webPage = require_template.default({
30
+ manifest: manifestFiles ?? defaultManifestFiles,
31
+ options,
32
+ scriptsBodyAfter,
33
+ metaScripts,
34
+ scriptsBodyBefore
35
+ }, manifest);
36
+ if (needHtmlCache) {
37
+ cache.set(cacheKey, webPage);
38
+ debug$1("set template cache");
39
+ }
40
+ } else debug$1("reuse template cache");
41
+ } catch (error) {
42
+ throw new Error(`theme could not be load, stack ${error.stack}`);
43
+ }
44
+ res.setHeader("Content-Type", _verdaccio_core.HEADERS.TEXT_HTML);
45
+ res.send(webPage);
46
+ debug$1("web rendered");
54
47
  }
48
+ //#endregion
49
+ exports.default = renderHTML;
50
+
55
51
  //# sourceMappingURL=renderHTML.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderHTML.js","names":["_debug","_interopRequireDefault","require","_lruCache","_core","_template","e","__esModule","default","cache","LRUCache","max","ttl","debug","buildDebug","defaultManifestFiles","js","ico","css","renderHTML","config","manifest","manifestFiles","options","res","needHtmlCache","undefined","includes","web","html_cache","scriptsBodyBefore","scriptsbodyBefore","scriptsBodyAfter","metaScripts","webPage","cacheKey","JSON","stringify","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 LRUCache from 'lru-cache';\n\nimport { HEADERS } from '@verdaccio/core';\nimport type { ConfigYaml, TemplateUIOptions } from '@verdaccio/types';\n\nimport type { Manifest } from './manifest';\nimport renderTemplate from './template';\nimport type { AssetManifest } from './template';\n\n// Cache for rendered HTML templates: max 500 entries, 1 hour TTL\nconst cache = new LRUCache({ max: 500, ttl: 1000 * 60 * 60 });\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst defaultManifestFiles: Manifest = {\n js: ['vendors.js', 'main.js'],\n ico: 'favicon.ico',\n css: [],\n};\n\nexport default function renderHTML(\n config: ConfigYaml,\n manifest: AssetManifest,\n manifestFiles: Manifest | null | undefined,\n options: TemplateUIOptions,\n res: Response\n) {\n // @ts-ignore\n const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)\n ? true\n : config?.web?.html_cache;\n\n const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];\n const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];\n const metaScripts = config?.web?.metaScripts || [];\n\n let webPage;\n\n const cacheKey = `template:${JSON.stringify(options)}`;\n\n try {\n webPage = cache.get(cacheKey);\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(cacheKey, 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;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAIA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAwC,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGxC;AACA,MAAMG,KAAK,GAAG,IAAIC,iBAAQ,CAAC;EAAEC,GAAG,EAAE,GAAG;EAAEC,GAAG,EAAE,IAAI,GAAG,EAAE,GAAG;AAAG,CAAC,CAAC;AAE7D,MAAMC,KAAK,GAAG,IAAAC,cAAU,EAAC,sBAAsB,CAAC;AAEhD,MAAMC,oBAA8B,GAAG;EACrCC,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;EAC7BC,GAAG,EAAE,aAAa;EAClBC,GAAG,EAAE;AACP,CAAC;AAEc,SAASC,UAAUA,CAChCC,MAAkB,EAClBC,QAAuB,EACvBC,aAA0C,EAC1CC,OAA0B,EAC1BC,GAAa,EACb;EACA;EACA,MAAMC,aAAa,GAAG,CAACC,SAAS,EAAE,IAAI,CAAC,CAACC,QAAQ,CAACP,MAAM,EAAEQ,GAAG,EAAEC,UAAU,CAAC,GACrE,IAAI,GACJT,MAAM,EAAEQ,GAAG,EAAEC,UAAU;EAE3B,MAAMC,iBAAiB,GAAGV,MAAM,EAAEQ,GAAG,EAAEE,iBAAiB,IAAIV,MAAM,EAAEQ,GAAG,EAAEG,iBAAiB,IAAI,EAAE;EAChG,MAAMC,gBAAgB,GAAGZ,MAAM,EAAEQ,GAAG,EAAEI,gBAAgB,IAAI,EAAE;EAC5D,MAAMC,WAAW,GAAGb,MAAM,EAAEQ,GAAG,EAAEK,WAAW,IAAI,EAAE;EAElD,IAAIC,OAAO;EAEX,MAAMC,QAAQ,GAAG,YAAYC,IAAI,CAACC,SAAS,CAACd,OAAO,CAAC,EAAE;EAEtD,IAAI;IACFW,OAAO,GAAGzB,KAAK,CAAC6B,GAAG,CAACH,QAAQ,CAAC;IAC7B,IAAI,CAACD,OAAO,EAAE;MACZA,OAAO,GAAG,IAAAK,iBAAc,EACtB;QACElB,QAAQ,EAAEC,aAAa,IAAIP,oBAAoB;QAC/CQ,OAAO;QACPS,gBAAgB;QAChBC,WAAW;QACXH;MACF,CAAC,EACDT,QACF,CAAC;MAED,IAAII,aAAa,EAAE;QACjBhB,KAAK,CAAC+B,GAAG,CAACL,QAAQ,EAAED,OAAO,CAAC;QAC5BrB,KAAK,CAAC,oBAAoB,CAAC;MAC7B;IACF,CAAC,MAAM;MACLA,KAAK,CAAC,sBAAsB,CAAC;IAC/B;EACF,CAAC,CAAC,OAAO4B,KAAU,EAAE;IACnB,MAAM,IAAIC,KAAK,CAAC,kCAAkCD,KAAK,CAACE,KAAK,EAAE,CAAC;EAClE;EACAnB,GAAG,CAACoB,SAAS,CAAC,cAAc,EAAEC,aAAO,CAACC,SAAS,CAAC;EAChDtB,GAAG,CAACuB,IAAI,CAACb,OAAO,CAAC;EACjBrB,KAAK,CAAC,cAAc,CAAC;AACvB","ignoreList":[]}
1
+ {"version":3,"file":"renderHTML.js","names":[],"sources":["../../../../src/middlewares/web/utils/renderHTML.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Response } from 'express';\nimport LRUCache from 'lru-cache';\n\nimport { HEADERS } from '@verdaccio/core';\nimport type { ConfigYaml, TemplateUIOptions } from '@verdaccio/types';\n\nimport type { Manifest } from './manifest';\nimport renderTemplate from './template';\nimport type { AssetManifest } from './template';\n\n// Cache for rendered HTML templates: max 500 entries, 1 hour TTL\nconst cache = new LRUCache({ max: 500, ttl: 1000 * 60 * 60 });\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst defaultManifestFiles: Manifest = {\n js: ['vendors.js', 'main.js'],\n ico: 'favicon.ico',\n css: [],\n};\n\nexport default function renderHTML(\n config: ConfigYaml,\n manifest: AssetManifest,\n manifestFiles: Manifest | null | undefined,\n options: TemplateUIOptions,\n res: Response\n) {\n // @ts-ignore\n const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)\n ? true\n : config?.web?.html_cache;\n\n const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];\n const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];\n const metaScripts = config?.web?.metaScripts || [];\n\n let webPage;\n\n const cacheKey = `template:${JSON.stringify(options)}`;\n\n try {\n webPage = cache.get(cacheKey);\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(cacheKey, 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":";;;;;;;;AAYA,IAAM,QAAQ,IAAI,UAAA,QAAS;CAAE,KAAK;CAAK,KAAK,MAAO,KAAK;AAAG,CAAC;AAE5D,IAAM,WAAA,GAAA,MAAA,SAAmB,sBAAsB;AAE/C,IAAM,uBAAiC;CACrC,IAAI,CAAC,cAAc,SAAS;CAC5B,KAAK;CACL,KAAK,CAAC;AACR;AAEA,SAAwB,WACtB,QACA,UACA,eACA,SACA,KACA;CAEA,MAAM,gBAAgB,CAAC,KAAA,GAAW,IAAI,EAAE,SAAS,QAAQ,KAAK,UAAU,IACpE,OACA,QAAQ,KAAK;CAEjB,MAAM,oBAAoB,QAAQ,KAAK,qBAAqB,QAAQ,KAAK,qBAAqB,CAAC;CAC/F,MAAM,mBAAmB,QAAQ,KAAK,oBAAoB,CAAC;CAC3D,MAAM,cAAc,QAAQ,KAAK,eAAe,CAAC;CAEjD,IAAI;CAEJ,MAAM,WAAW,YAAY,KAAK,UAAU,OAAO;CAEnD,IAAI;EACF,UAAU,MAAM,IAAI,QAAQ;EAC5B,IAAI,CAAC,SAAS;GACZ,UAAU,iBAAA,QACR;IACE,UAAU,iBAAiB;IAC3B;IACA;IACA;IACA;GACF,GACA,QACF;GAEA,IAAI,eAAe;IACjB,MAAM,IAAI,UAAU,OAAO;IAC3B,QAAM,oBAAoB;GAC5B;EACF,OACE,QAAM,sBAAsB;CAEhC,SAAS,OAAY;EACnB,MAAM,IAAI,MAAM,kCAAkC,MAAM,OAAO;CACjE;CACA,IAAI,UAAU,gBAAgB,gBAAA,QAAQ,SAAS;CAC/C,IAAI,KAAK,OAAO;CAChB,QAAM,cAAc;AACtB"}
@@ -0,0 +1,48 @@
1
+ import renderTemplate from "./template.mjs";
2
+ import { HEADERS } from "@verdaccio/core";
3
+ import buildDebug from "debug";
4
+ import LRUCache from "lru-cache";
5
+ //#region src/middlewares/web/utils/renderHTML.ts
6
+ var cache = new LRUCache({
7
+ max: 500,
8
+ ttl: 1e3 * 60 * 60
9
+ });
10
+ var debug = buildDebug("verdaccio:web:render");
11
+ var defaultManifestFiles = {
12
+ js: ["vendors.js", "main.js"],
13
+ ico: "favicon.ico",
14
+ css: []
15
+ };
16
+ function renderHTML(config, manifest, manifestFiles, options, res) {
17
+ const needHtmlCache = [void 0, null].includes(config?.web?.html_cache) ? true : config?.web?.html_cache;
18
+ const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];
19
+ const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];
20
+ const metaScripts = config?.web?.metaScripts || [];
21
+ let webPage;
22
+ const cacheKey = `template:${JSON.stringify(options)}`;
23
+ try {
24
+ webPage = cache.get(cacheKey);
25
+ if (!webPage) {
26
+ webPage = renderTemplate({
27
+ manifest: manifestFiles ?? defaultManifestFiles,
28
+ options,
29
+ scriptsBodyAfter,
30
+ metaScripts,
31
+ scriptsBodyBefore
32
+ }, manifest);
33
+ if (needHtmlCache) {
34
+ cache.set(cacheKey, webPage);
35
+ debug("set template cache");
36
+ }
37
+ } else debug("reuse template cache");
38
+ } catch (error) {
39
+ throw new Error(`theme could not be load, stack ${error.stack}`);
40
+ }
41
+ res.setHeader("Content-Type", HEADERS.TEXT_HTML);
42
+ res.send(webPage);
43
+ debug("web rendered");
44
+ }
45
+ //#endregion
46
+ export { renderHTML as default };
47
+
48
+ //# sourceMappingURL=renderHTML.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderHTML.mjs","names":[],"sources":["../../../../src/middlewares/web/utils/renderHTML.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { Response } from 'express';\nimport LRUCache from 'lru-cache';\n\nimport { HEADERS } from '@verdaccio/core';\nimport type { ConfigYaml, TemplateUIOptions } from '@verdaccio/types';\n\nimport type { Manifest } from './manifest';\nimport renderTemplate from './template';\nimport type { AssetManifest } from './template';\n\n// Cache for rendered HTML templates: max 500 entries, 1 hour TTL\nconst cache = new LRUCache({ max: 500, ttl: 1000 * 60 * 60 });\n\nconst debug = buildDebug('verdaccio:web:render');\n\nconst defaultManifestFiles: Manifest = {\n js: ['vendors.js', 'main.js'],\n ico: 'favicon.ico',\n css: [],\n};\n\nexport default function renderHTML(\n config: ConfigYaml,\n manifest: AssetManifest,\n manifestFiles: Manifest | null | undefined,\n options: TemplateUIOptions,\n res: Response\n) {\n // @ts-ignore\n const needHtmlCache = [undefined, null].includes(config?.web?.html_cache)\n ? true\n : config?.web?.html_cache;\n\n const scriptsBodyBefore = config?.web?.scriptsBodyBefore || config?.web?.scriptsbodyBefore || [];\n const scriptsBodyAfter = config?.web?.scriptsBodyAfter || [];\n const metaScripts = config?.web?.metaScripts || [];\n\n let webPage;\n\n const cacheKey = `template:${JSON.stringify(options)}`;\n\n try {\n webPage = cache.get(cacheKey);\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(cacheKey, 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":";;;;;AAYA,IAAM,QAAQ,IAAI,SAAS;CAAE,KAAK;CAAK,KAAK,MAAO,KAAK;AAAG,CAAC;AAE5D,IAAM,QAAQ,WAAW,sBAAsB;AAE/C,IAAM,uBAAiC;CACrC,IAAI,CAAC,cAAc,SAAS;CAC5B,KAAK;CACL,KAAK,CAAC;AACR;AAEA,SAAwB,WACtB,QACA,UACA,eACA,SACA,KACA;CAEA,MAAM,gBAAgB,CAAC,KAAA,GAAW,IAAI,EAAE,SAAS,QAAQ,KAAK,UAAU,IACpE,OACA,QAAQ,KAAK;CAEjB,MAAM,oBAAoB,QAAQ,KAAK,qBAAqB,QAAQ,KAAK,qBAAqB,CAAC;CAC/F,MAAM,mBAAmB,QAAQ,KAAK,oBAAoB,CAAC;CAC3D,MAAM,cAAc,QAAQ,KAAK,eAAe,CAAC;CAEjD,IAAI;CAEJ,MAAM,WAAW,YAAY,KAAK,UAAU,OAAO;CAEnD,IAAI;EACF,UAAU,MAAM,IAAI,QAAQ;EAC5B,IAAI,CAAC,SAAS;GACZ,UAAU,eACR;IACE,UAAU,iBAAiB;IAC3B;IACA;IACA;IACA;GACF,GACA,QACF;GAEA,IAAI,eAAe;IACjB,MAAM,IAAI,UAAU,OAAO;IAC3B,MAAM,oBAAoB;GAC5B;EACF,OACE,MAAM,sBAAsB;CAEhC,SAAS,OAAY;EACnB,MAAM,IAAI,MAAM,kCAAkC,MAAM,OAAO;CACjE;CACA,IAAI,UAAU,gBAAgB,QAAQ,SAAS;CAC/C,IAAI,KAAK,OAAO;CAChB,MAAM,cAAc;AACtB"}
@@ -1,36 +1,35 @@
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("./manifest");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const debug = (0, _debug.default)('verdaccio:web:render:template');
1
+ const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
2
+ const require_manifest = require("./manifest.js");
3
+ let debug = require("debug");
4
+ debug = require_runtime.__toESM(debug);
5
+ //#region src/middlewares/web/utils/template.ts
6
+ var debug$1 = (0, debug.default)("verdaccio:web:render:template");
11
7
  function renderTemplate(template, manifest) {
12
- debug('template %o', template);
13
- debug('manifest %o', manifest);
14
- return `
8
+ debug$1("template %o", template);
9
+ debug$1("manifest %o", manifest);
10
+ return `
15
11
  <!DOCTYPE html>
16
12
  <html lang="en-us">
17
13
  <head>
18
14
  <meta charset="utf-8">
19
15
  <base href="${template?.options.base}">
20
- <title>${template?.options?.title ?? ''}</title>
16
+ <title>${template?.options?.title ?? ""}</title>
21
17
  <link rel="icon" href="${template?.options.base}-/static/favicon.ico">
22
18
  <meta name="viewport" content="width=device-width, initial-scale=1">
23
- <script src="${template?.options.base}-/static/ui-options.js"></script>
24
- ${template.manifest.css?.length ? (0, _manifest.getManifestValue)(template.manifest.css, manifest, template?.options.base).map(item => `<link rel="stylesheet" href="${item}">`).join('\n ') : ''}
25
- ${template?.metaScripts ? template.metaScripts.join('') : ''}
19
+ <script src="${template?.options.base}-/static/ui-options.js"><\/script>
20
+ ${template.manifest.css?.length ? require_manifest.getManifestValue(template.manifest.css, manifest, template?.options.base).map((item) => `<link rel="stylesheet" href="${item}">`).join("\n ") : ""}
21
+ ${template?.metaScripts ? template.metaScripts.join("") : ""}
26
22
  </head>
27
23
  <body class="body">
28
- ${template?.scriptsBodyBefore ? template.scriptsBodyBefore.join('') : ''}
24
+ ${template?.scriptsBodyBefore ? template.scriptsBodyBefore.join("") : ""}
29
25
  <div id="root"></div>
30
- ${(0, _manifest.getManifestValue)(template.manifest.js, manifest, template?.options.base).map(item => `<script type="module" src="${item}"></script>`).join(`\n `)}
31
- ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
26
+ ${require_manifest.getManifestValue(template.manifest.js, manifest, template?.options.base).map((item) => `<script type="module" src="${item}"><\/script>`).join(`\n `)}
27
+ ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join("") : ""}
32
28
  </body>
33
29
  </html>
34
30
  `;
35
31
  }
32
+ //#endregion
33
+ exports.default = renderTemplate;
34
+
36
35
  //# sourceMappingURL=template.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","names":["_debug","_interopRequireDefault","require","_manifest","e","__esModule","default","debug","buildDebug","renderTemplate","template","manifest","options","base","title","css","length","getManifestValue","map","item","join","metaScripts","scriptsBodyBefore","js","scriptsBodyAfter"],"sources":["../../../../src/middlewares/web/utils/template.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { TemplateUIOptions } from '@verdaccio/types';\n\nimport type { Manifest } from './manifest';\nimport { 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\nexport interface AssetManifest {\n [key: string]: string;\n}\n\nexport default function renderTemplate(template: Template, manifest: AssetManifest) {\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 src=\"${template?.options.base}-/static/ui-options.js\"></script>\n ${\n template.manifest.css?.length\n ? getManifestValue(template.manifest.css, manifest, template?.options.base)\n .map((item) => `<link rel=\"stylesheet\" href=\"${item}\">`)\n .join('\\n ')\n : ''\n }\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 type=\"module\" 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;AAKA,IAAAC,SAAA,GAAAD,OAAA;AAA8C,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE9C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;AAc1C,SAASC,cAAcA,CAACC,QAAkB,EAAEC,QAAuB,EAAE;EAClFJ,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,uBAAuBH,QAAQ,EAAEE,OAAO,CAACC,IAAI;AAC7C,UACUH,QAAQ,CAACC,QAAQ,CAACI,GAAG,EAAEC,MAAM,GACzB,IAAAC,0BAAgB,EAACP,QAAQ,CAACC,QAAQ,CAACI,GAAG,EAAEJ,QAAQ,EAAED,QAAQ,EAAEE,OAAO,CAACC,IAAI,CAAC,CACtEK,GAAG,CAAEC,IAAI,IAAK,gCAAgCA,IAAI,IAAI,CAAC,CACvDC,IAAI,CAAC,YAAY,CAAC,GACrB,EAAE;AAChB,UACUV,QAAQ,EAAEW,WAAW,GAAGX,QAAQ,CAACW,WAAW,CAACD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AACpE;AACA;AACA,UAAUV,QAAQ,EAAEY,iBAAiB,GAAGZ,QAAQ,CAACY,iBAAiB,CAACF,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AAChF;AACA,UAAU,IAAAH,0BAAgB,EAACP,QAAQ,CAACC,QAAQ,CAACY,EAAE,EAAEZ,QAAQ,EAAED,QAAQ,EAAEE,OAAO,CAACC,IAAI,CAAC,CACvEK,GAAG,CAAEC,IAAI,IAAK,8BAA8BA,IAAI,aAAa,CAAC,CAC9DC,IAAI,CAAC,YAAY,CAAC;AAC7B,UAAUV,QAAQ,EAAEc,gBAAgB,GAAGd,QAAQ,CAACc,gBAAgB,CAACJ,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;AAC9E;AACA;AACA,GAAG;AACH","ignoreList":[]}
1
+ {"version":3,"file":"template.js","names":[],"sources":["../../../../src/middlewares/web/utils/template.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { TemplateUIOptions } from '@verdaccio/types';\n\nimport type { Manifest } from './manifest';\nimport { 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\nexport interface AssetManifest {\n [key: string]: string;\n}\n\nexport default function renderTemplate(template: Template, manifest: AssetManifest) {\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 src=\"${template?.options.base}-/static/ui-options.js\"></script>\n ${\n template.manifest.css?.length\n ? getManifestValue(template.manifest.css, manifest, template?.options.base)\n .map((item) => `<link rel=\"stylesheet\" href=\"${item}\">`)\n .join('\\n ')\n : ''\n }\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 type=\"module\" src=\"${item}\"></script>`)\n .join(`\\n `)}\n ${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}\n </body>\n </html>\n `;\n}\n"],"mappings":";;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,+BAA+B;AAcxD,SAAwB,eAAe,UAAoB,UAAyB;CAClF,QAAM,eAAe,QAAQ;CAC7B,QAAM,eAAe,QAAQ;CAE7B,OAAO;;;;;sBAKa,UAAU,QAAQ,KAAK;iBAC5B,UAAU,SAAS,SAAS,GAAG;iCACf,UAAU,QAAQ,KAAK;;uBAEjC,UAAU,QAAQ,KAAK;UAEpC,SAAS,SAAS,KAAK,SACnB,iBAAA,iBAAiB,SAAS,SAAS,KAAK,UAAU,UAAU,QAAQ,IAAI,EACrE,KAAK,SAAS,gCAAgC,KAAK,GAAG,EACtD,KAAK,YAAY,IACpB,GACL;UACC,UAAU,cAAc,SAAS,YAAY,KAAK,EAAE,IAAI,GAAG;;;UAG3D,UAAU,oBAAoB,SAAS,kBAAkB,KAAK,EAAE,IAAI,GAAG;;UAEvE,iBAAA,iBAAiB,SAAS,SAAS,IAAI,UAAU,UAAU,QAAQ,IAAI,EACtE,KAAK,SAAS,8BAA8B,KAAK,aAAY,EAC7D,KAAK,YAAY,EAAE;UACpB,UAAU,mBAAmB,SAAS,iBAAiB,KAAK,EAAE,IAAI,GAAG;;;;AAI/E"}