verdaccio 6.10.2 → 6.10.4

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.
@@ -27,7 +27,7 @@ let cors = require("cors");
27
27
  cors = require_runtime.__toESM(cors);
28
28
  let _verdaccio_loaders = require("@verdaccio/loaders");
29
29
  //#region src/api/index.ts
30
- var version = "6.10.2";
30
+ var version = "6.10.4";
31
31
  var defineAPI = async function(config, storage) {
32
32
  const auth = new _verdaccio_auth.Auth(config, require_lib_logger_index.logger, { legacyMergeConfigs: true });
33
33
  await auth.init();
@@ -56,6 +56,7 @@ var defineAPI = async function(config, storage) {
56
56
  }, function(plugin) {
57
57
  return typeof plugin.register_middlewares !== "undefined";
58
58
  }, true, config?.serverSettings?.pluginPrefix ?? "verdaccio", _verdaccio_core.PLUGIN_CATEGORY.MIDDLEWARE);
59
+ (0, _verdaccio_middleware.registerBodyParser)(app, config);
59
60
  app.use(auth.apiJWTmiddleware());
60
61
  plugins.forEach((plugin) => {
61
62
  plugin.register_middlewares(app, auth, storage);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport type { Application } from 'express';\nimport express from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { getUserAgent } from '@verdaccio/config';\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { errorReportingMiddleware, final, handleError, log } from '@verdaccio/middleware';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport type { ConfigYaml, Config as IConfig } from '@verdaccio/types';\n\nimport AppConfig from '../lib/config';\nimport { API_ERROR } from '../lib/constants';\nimport { logger } from '../lib/logger';\nimport Storage from '../lib/storage';\nimport { ErrorCode } from '../lib/utils';\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\nimport hookDebug from './debug';\nimport apiEndpoint from './endpoint';\nimport { serveFavicon } from './middleware';\nimport webMiddleware from './web';\n\nconst version = process.env.PACKAGE_VERSION || 'dev';\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<express.Application> {\n const auth = new Auth(config, logger, { legacyMergeConfigs: true });\n await auth.init();\n const app: Application = express();\n SearchMemoryIndexer.configureStorage(storage);\n await SearchMemoryIndexer.init(logger);\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n\n // Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer\n // See: https://expressjs.com/en/guide/behind-proxies.html\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n\n app.use(cors());\n\n // // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddleware(logger));\n if (config.user_agent) {\n app.use(function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('X-Powered-By', getUserAgent(config.user_agent));\n next();\n });\n } else {\n app.disable('x-powered-by');\n }\n\n // mime-db marks application/octet-stream as compressible, so the default\n // compression() filter would re-gzip every (already gzipped) .tgz tarball\n // for clients that accept gzip — npm and undici do by default. That wastes\n // CPU on every download and strips the Content-Length header. Skip\n // compression for tarball responses; JSON metadata stays compressed.\n app.use(\n compression({\n filter: (req, res): boolean => {\n const contentType = String(res.getHeader('Content-Type') ?? '');\n if (contentType.startsWith('application/octet-stream')) {\n return false;\n }\n return compression.filter(req, res);\n },\n })\n );\n\n app.get('/-/static/favicon.ico', serveFavicon(config));\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, '', Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n true,\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n // Register JWT middleware so middleware plugins can access req.remote_user\n app.use(auth.apiJWTmiddleware());\n\n plugins.forEach((plugin: any) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // // For npm request\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage, logger);\n app.use(middleware);\n } else {\n app.get('/', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n app.get('/*', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.FILE_NOT_FOUND));\n });\n app.use(handleError(logger));\n app.use(final);\n\n return app;\n};\n\nexport default (async function (configHash: ConfigYaml): Promise<express.Application> {\n const config: IConfig = new AppConfig(_.cloneDeep(configHash));\n\n const storage = new Storage(config);\n // waits until init calls have been initialized\n await storage.init(config);\n return await defineAPI(config, storage);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAM,UAAA;AAEN,IAAM,YAAY,eAAgB,QAAiB,SAAgD;CACjG,MAAM,OAAO,IAAI,gBAAA,KAAK,QAAQ,yBAAA,QAAQ,EAAE,oBAAoB,KAAK,CAAC;CAClE,MAAM,KAAK,KAAK;CAChB,MAAM,OAAA,GAAA,QAAA,QAAA,CAA2B;CACjC,0BAAA,oBAAoB,iBAAiB,OAAO;CAC5C,MAAM,0BAAA,oBAAoB,KAAK,yBAAA,MAAM;CAGrC,IAAI,IAAI,OAAA,QAAA,IAAA,YAA+B,YAAY;CAInD,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI,eAAe,OAAO,OAAO,UAAU;CAGjD,IAAI,KAAA,GAAA,KAAA,QAAA,CAAS,CAAC;CAGd,IAAI,KAAA,GAAA,sBAAA,IAAA,CAAQ,yBAAA,MAAM,CAAC;CACnB,IA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B;EACpD,KAAK,kBAAA,UAAU,YAAY,gBAAA,UAAU,YAAY,CAAC;CACpD,CAAC;CAGH,IAAI,IAAI,MAAM,SAAU,GAAG,IAAI,MAAwB;EACrD,KAAK,kBAAA,UAAU,YAAY,gBAAA,UAAU,cAAc,CAAC;CACtD,CAAC;CACD,IAAI,KAAA,GAAA,sBAAA,YAAA,CAAgB,yBAAA,MAAM,CAAC;CAC3B,IAAI,IAAI,sBAAA,KAAK;CAEb,OAAO;AACT;AAEA,IAAA,eAAgB,eAAgB,YAAsD;CACpF,MAAM,SAAkB,IAAI,mBAAA,QAAU,OAAA,QAAE,UAAU,UAAU,CAAC;CAE7D,MAAM,UAAU,IAAI,oBAAA,QAAQ,MAAM;CAElC,MAAM,QAAQ,KAAK,MAAM;CACzB,OAAO,MAAM,UAAU,QAAQ,OAAO;AACxC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport type { Application } from 'express';\nimport express from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { getUserAgent } from '@verdaccio/config';\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport {\n errorReportingMiddleware,\n final,\n handleError,\n log,\n registerBodyParser,\n} from '@verdaccio/middleware';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport type { ConfigYaml, Config as IConfig } from '@verdaccio/types';\n\nimport AppConfig from '../lib/config';\nimport { API_ERROR } from '../lib/constants';\nimport { logger } from '../lib/logger';\nimport Storage from '../lib/storage';\nimport { ErrorCode } from '../lib/utils';\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\nimport hookDebug from './debug';\nimport apiEndpoint from './endpoint';\nimport { serveFavicon } from './middleware';\nimport webMiddleware from './web';\n\nconst version = process.env.PACKAGE_VERSION || 'dev';\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<express.Application> {\n const auth = new Auth(config, logger, { legacyMergeConfigs: true });\n await auth.init();\n const app: Application = express();\n SearchMemoryIndexer.configureStorage(storage);\n await SearchMemoryIndexer.init(logger);\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n\n // Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer\n // See: https://expressjs.com/en/guide/behind-proxies.html\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n\n app.use(cors());\n\n // // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddleware(logger));\n if (config.user_agent) {\n app.use(function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('X-Powered-By', getUserAgent(config.user_agent));\n next();\n });\n } else {\n app.disable('x-powered-by');\n }\n\n // mime-db marks application/octet-stream as compressible, so the default\n // compression() filter would re-gzip every (already gzipped) .tgz tarball\n // for clients that accept gzip — npm and undici do by default. That wastes\n // CPU on every download and strips the Content-Length header. Skip\n // compression for tarball responses; JSON metadata stays compressed.\n app.use(\n compression({\n filter: (req, res): boolean => {\n const contentType = String(res.getHeader('Content-Type') ?? '');\n if (contentType.startsWith('application/octet-stream')) {\n return false;\n }\n return compression.filter(req, res);\n },\n })\n );\n\n app.get('/-/static/favicon.ico', serveFavicon(config));\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, '', Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n true,\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n // Buffer the request body before anything that can suspend the request.\n // apiJWTmiddleware() pauses the stream, and the API router's\n // enforceGeneratedTokenMetadata() awaits a storage lookup for tokens minted\n // via `npm token create` -- both run ahead of the router's own body parser,\n // so without this the parser sees fewer bytes than Content-Length announced\n // and the request is rejected. Registering here also lets middleware plugins\n // read req.body.\n registerBodyParser(app, config);\n\n // Register JWT middleware so middleware plugins can access req.remote_user\n app.use(auth.apiJWTmiddleware());\n\n plugins.forEach((plugin: any) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // // For npm request\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage, logger);\n app.use(middleware);\n } else {\n app.get('/', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n app.get('/*', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.FILE_NOT_FOUND));\n });\n app.use(handleError(logger));\n app.use(final);\n\n return app;\n};\n\nexport default (async function (configHash: ConfigYaml): Promise<express.Application> {\n const config: IConfig = new AppConfig(_.cloneDeep(configHash));\n\n const storage = new Storage(config);\n // waits until init calls have been initialized\n await storage.init(config);\n return await defineAPI(config, storage);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAM,UAAA;AAEN,IAAM,YAAY,eAAgB,QAAiB,SAAgD;CACjG,MAAM,OAAO,IAAI,gBAAA,KAAK,QAAQ,yBAAA,QAAQ,EAAE,oBAAoB,KAAK,CAAC;CAClE,MAAM,KAAK,KAAK;CAChB,MAAM,OAAA,GAAA,QAAA,QAAA,CAA2B;CACjC,0BAAA,oBAAoB,iBAAiB,OAAO;CAC5C,MAAM,0BAAA,oBAAoB,KAAK,yBAAA,MAAM;CAGrC,IAAI,IAAI,OAAA,QAAA,IAAA,YAA+B,YAAY;CAInD,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI,eAAe,OAAO,OAAO,UAAU;CAGjD,IAAI,KAAA,GAAA,KA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;EACD,MAAM,aAAa,MAAM,sBAAA,QAAc,QAAQ,MAAM,SAAS,yBAAA,MAAM;EACpE,IAAI,IAAI,UAAU;CACpB,OACE,IAAI,IAAI,KAAK,SAAU,GAAG,IAAI,MAAwB;EACpD,KAAK,kBAAA,UAAU,YAAY,gBAAA,UAAU,YAAY,CAAC;CACpD,CAAC;CAGH,IAAI,IAAI,MAAM,SAAU,GAAG,IAAI,MAAwB;EACrD,KAAK,kBAAA,UAAU,YAAY,gBAAA,UAAU,cAAc,CAAC;CACtD,CAAC;CACD,IAAI,KAAA,GAAA,sBAAA,YAAA,CAAgB,yBAAA,MAAM,CAAC;CAC3B,IAAI,IAAI,sBAAA,KAAK;CAEb,OAAO;AACT;AAEA,IAAA,eAAgB,eAAgB,YAAsD;CACpF,MAAM,SAAkB,IAAI,mBAAA,QAAU,OAAA,QAAE,UAAU,UAAU,CAAC;CAE7D,MAAM,UAAU,IAAI,oBAAA,QAAQ,MAAM;CAElC,MAAM,QAAQ,KAAK,MAAM;CACzB,OAAO,MAAM,UAAU,QAAQ,OAAO;AACxC"}
@@ -8,7 +8,7 @@ import Storage from "../lib/storage.mjs";
8
8
  import { serveFavicon } from "./middleware.mjs";
9
9
  import web_default from "./web/index.mjs";
10
10
  import _ from "lodash";
11
- import { errorReportingMiddleware, final, handleError, log } from "@verdaccio/middleware";
11
+ import { errorReportingMiddleware, final, handleError, log, registerBodyParser } from "@verdaccio/middleware";
12
12
  import { PLUGIN_CATEGORY } from "@verdaccio/core";
13
13
  import { getUserAgent } from "@verdaccio/config";
14
14
  import { SearchMemoryIndexer } from "@verdaccio/search-indexer";
@@ -18,7 +18,7 @@ import compression from "compression";
18
18
  import cors from "cors";
19
19
  import { asyncLoadPlugin } from "@verdaccio/loaders";
20
20
  //#region src/api/index.ts
21
- var version = "6.10.2";
21
+ var version = "6.10.4";
22
22
  var defineAPI = async function(config, storage) {
23
23
  const auth = new Auth(config, logger, { legacyMergeConfigs: true });
24
24
  await auth.init();
@@ -47,6 +47,7 @@ var defineAPI = async function(config, storage) {
47
47
  }, function(plugin) {
48
48
  return typeof plugin.register_middlewares !== "undefined";
49
49
  }, true, config?.serverSettings?.pluginPrefix ?? "verdaccio", PLUGIN_CATEGORY.MIDDLEWARE);
50
+ registerBodyParser(app, config);
50
51
  app.use(auth.apiJWTmiddleware());
51
52
  plugins.forEach((plugin) => {
52
53
  plugin.register_middlewares(app, auth, storage);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport type { Application } from 'express';\nimport express from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { getUserAgent } from '@verdaccio/config';\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { errorReportingMiddleware, final, handleError, log } from '@verdaccio/middleware';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport type { ConfigYaml, Config as IConfig } from '@verdaccio/types';\n\nimport AppConfig from '../lib/config';\nimport { API_ERROR } from '../lib/constants';\nimport { logger } from '../lib/logger';\nimport Storage from '../lib/storage';\nimport { ErrorCode } from '../lib/utils';\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\nimport hookDebug from './debug';\nimport apiEndpoint from './endpoint';\nimport { serveFavicon } from './middleware';\nimport webMiddleware from './web';\n\nconst version = process.env.PACKAGE_VERSION || 'dev';\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<express.Application> {\n const auth = new Auth(config, logger, { legacyMergeConfigs: true });\n await auth.init();\n const app: Application = express();\n SearchMemoryIndexer.configureStorage(storage);\n await SearchMemoryIndexer.init(logger);\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n\n // Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer\n // See: https://expressjs.com/en/guide/behind-proxies.html\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n\n app.use(cors());\n\n // // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddleware(logger));\n if (config.user_agent) {\n app.use(function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('X-Powered-By', getUserAgent(config.user_agent));\n next();\n });\n } else {\n app.disable('x-powered-by');\n }\n\n // mime-db marks application/octet-stream as compressible, so the default\n // compression() filter would re-gzip every (already gzipped) .tgz tarball\n // for clients that accept gzip — npm and undici do by default. That wastes\n // CPU on every download and strips the Content-Length header. Skip\n // compression for tarball responses; JSON metadata stays compressed.\n app.use(\n compression({\n filter: (req, res): boolean => {\n const contentType = String(res.getHeader('Content-Type') ?? '');\n if (contentType.startsWith('application/octet-stream')) {\n return false;\n }\n return compression.filter(req, res);\n },\n })\n );\n\n app.get('/-/static/favicon.ico', serveFavicon(config));\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, '', Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n true,\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n // Register JWT middleware so middleware plugins can access req.remote_user\n app.use(auth.apiJWTmiddleware());\n\n plugins.forEach((plugin: any) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // // For npm request\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage, logger);\n app.use(middleware);\n } else {\n app.get('/', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n app.get('/*', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.FILE_NOT_FOUND));\n });\n app.use(handleError(logger));\n app.use(final);\n\n return app;\n};\n\nexport default (async function (configHash: ConfigYaml): Promise<express.Application> {\n const config: IConfig = new AppConfig(_.cloneDeep(configHash));\n\n const storage = new Storage(config);\n // waits until init calls have been initialized\n await storage.init(config);\n return await defineAPI(config, storage);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,IAAM,UAAA;AAEN,IAAM,YAAY,eAAgB,QAAiB,SAAgD;CACjG,MAAM,OAAO,IAAI,KAAK,QAAQ,QAAQ,EAAE,oBAAoB,KAAK,CAAC;CAClE,MAAM,KAAK,KAAK;CAChB,MAAM,MAAmB,QAAQ;CACjC,oBAAoB,iBAAiB,OAAO;CAC5C,MAAM,oBAAoB,KAAK,MAAM;CAGrC,IAAI,IAAI,OAAA,QAAA,IAAA,YAA+B,YAAY;CAInD,IAAI,OAAO,QAAQ,YACjB,IAAI,IAAI,eAAe,OAAO,OAAO,UAAU;CAGjD,IAAI,IAAI,KAAK,CAAC;CAGd,IAAI,IAAI,IAAI,MAAM,CAAC;CACnB,IAAI,IAAI,yBAAyB,MAAM,CAAC;CACxC,IAAI,OAAO,YACT,IAAI,IAAI,SAAU,MAAsB,KAAsB,MAA8B;EAC1F,IAAI,UAAU,gBAAgB,aAAa,OAAO,UAAU,CAAC;EAC7D,KAAK;CACP,CAAC;MAED,IAAI,QAAQ,cAAc;CAQ5B,IAAI,IACF,YAAY,EACV,SAAS,KAAK,QAAiB;EAE7B,IADoB,OAAO,IAAI,UAAU,cAAc,KAAK,EACxD,CAAA,CAAY,WAAW,0BAA0B,GACnD,OAAO;EAET,OAAO,YAAY,OAAO,KAAK,GAAG;CACpC,EACF,CAAC,CACH;CAEA,IAAI,IAAI,yBAAyB,aAAa,MAAM,CAAC;CAGrD,IAAI,OAAO,QACT,cAAU,KAAK,OAAO,UAAU;CAGlC,MAAM,UAA8D,MAAM,gBACxE,OAAO,aACP;EACE;EACA;CACF,GACA,SAAU,QAAQ;EAChB,OAAO,OAAO,OAAO,yBAAyB;CAChD,GACA,MACA,QAAQ,gBAAgB,gBAAgB,aACxC,gBAAgB,UAClB;CAGA,IAAI,IAAI,KAAK,iBAAiB,CAAC;CAE/B,QAAQ,SAAS,WAAgB;EAC/B,OAAO,qBAAqB,KAAK,MAAM,OAAO;CAChD,CAAC;CAGD,IAAI,IAAI,iBAAY,QAAQ,MAAM,OAAO,CAAC;CAG1C,IAAI,EAAE,IAAI,QAAQ,cAAc,IAAI,GAAG;EACrC,IAAI,KAAK,MAAM,KAAK,SAAS;GAC3B,IAAI,OAAO,cAAc;GACzB,KAAK;EACP,CAAC;EACD,MAAM,aAAa,MAAM,YAAc,QAAQ,MAAM,SAAS,MAAM;EACpE,IAAI,IAAI,UAAU;CACpB,OACE,IAAI,IAAI,KAAK,SAAU,GAAG,IAAI,MAAwB;EACpD,KAAK,UAAU,YAAY,UAAU,YAAY,CAAC;CACpD,CAAC;CAGH,IAAI,IAAI,MAAM,SAAU,GAAG,IAAI,MAAwB;EACrD,KAAK,UAAU,YAAY,UAAU,cAAc,CAAC;CACtD,CAAC;CACD,IAAI,IAAI,YAAY,MAAM,CAAC;CAC3B,IAAI,IAAI,KAAK;CAEb,OAAO;AACT;AAEA,IAAA,eAAgB,eAAgB,YAAsD;CACpF,MAAM,SAAkB,IAAI,SAAU,EAAE,UAAU,UAAU,CAAC;CAE7D,MAAM,UAAU,IAAI,QAAQ,MAAM;CAElC,MAAM,QAAQ,KAAK,MAAM;CACzB,OAAO,MAAM,UAAU,QAAQ,OAAO;AACxC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/api/index.ts"],"sourcesContent":["import compression from 'compression';\nimport cors from 'cors';\nimport type { Application } from 'express';\nimport express from 'express';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport { getUserAgent } from '@verdaccio/config';\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport {\n errorReportingMiddleware,\n final,\n handleError,\n log,\n registerBodyParser,\n} from '@verdaccio/middleware';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport type { ConfigYaml, Config as IConfig } from '@verdaccio/types';\n\nimport AppConfig from '../lib/config';\nimport { API_ERROR } from '../lib/constants';\nimport { logger } from '../lib/logger';\nimport Storage from '../lib/storage';\nimport { ErrorCode } from '../lib/utils';\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\nimport hookDebug from './debug';\nimport apiEndpoint from './endpoint';\nimport { serveFavicon } from './middleware';\nimport webMiddleware from './web';\n\nconst version = process.env.PACKAGE_VERSION || 'dev';\n\nconst defineAPI = async function (config: IConfig, storage: Storage): Promise<express.Application> {\n const auth = new Auth(config, logger, { legacyMergeConfigs: true });\n await auth.init();\n const app: Application = express();\n SearchMemoryIndexer.configureStorage(storage);\n await SearchMemoryIndexer.init(logger);\n // run in production mode by default, just in case\n // it shouldn't make any difference anyway\n app.set('env', process.env.NODE_ENV || 'production');\n\n // Allow `req.ip` to resolve properly when Verdaccio is behind a proxy or load-balancer\n // See: https://expressjs.com/en/guide/behind-proxies.html\n if (config.server?.trustProxy) {\n app.set('trust proxy', config.server.trustProxy);\n }\n\n app.use(cors());\n\n // // Router setup\n app.use(log(logger));\n app.use(errorReportingMiddleware(logger));\n if (config.user_agent) {\n app.use(function (_req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n res.setHeader('X-Powered-By', getUserAgent(config.user_agent));\n next();\n });\n } else {\n app.disable('x-powered-by');\n }\n\n // mime-db marks application/octet-stream as compressible, so the default\n // compression() filter would re-gzip every (already gzipped) .tgz tarball\n // for clients that accept gzip — npm and undici do by default. That wastes\n // CPU on every download and strips the Content-Length header. Skip\n // compression for tarball responses; JSON metadata stays compressed.\n app.use(\n compression({\n filter: (req, res): boolean => {\n const contentType = String(res.getHeader('Content-Type') ?? '');\n if (contentType.startsWith('application/octet-stream')) {\n return false;\n }\n return compression.filter(req, res);\n },\n })\n );\n\n app.get('/-/static/favicon.ico', serveFavicon(config));\n\n // Hook for tests only\n if (config._debug) {\n hookDebug(app, config.configPath);\n }\n\n const plugins: pluginUtils.ExpressMiddleware<IConfig, '', Auth>[] = await asyncLoadPlugin(\n config.middlewares,\n {\n config,\n logger,\n },\n function (plugin) {\n return typeof plugin.register_middlewares !== 'undefined';\n },\n true,\n config?.serverSettings?.pluginPrefix ?? 'verdaccio',\n PLUGIN_CATEGORY.MIDDLEWARE\n );\n\n // Buffer the request body before anything that can suspend the request.\n // apiJWTmiddleware() pauses the stream, and the API router's\n // enforceGeneratedTokenMetadata() awaits a storage lookup for tokens minted\n // via `npm token create` -- both run ahead of the router's own body parser,\n // so without this the parser sees fewer bytes than Content-Length announced\n // and the request is rejected. Registering here also lets middleware plugins\n // read req.body.\n registerBodyParser(app, config);\n\n // Register JWT middleware so middleware plugins can access req.remote_user\n app.use(auth.apiJWTmiddleware());\n\n plugins.forEach((plugin: any) => {\n plugin.register_middlewares(app, auth, storage);\n });\n\n // // For npm request\n app.use(apiEndpoint(config, auth, storage));\n\n // For WebUI & WebUI API\n if (_.get(config, 'web.enable', true)) {\n app.use((_req, res, next) => {\n res.locals.app_version = version ?? '';\n next();\n });\n const middleware = await webMiddleware(config, auth, storage, logger);\n app.use(middleware);\n } else {\n app.get('/', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.WEB_DISABLED));\n });\n }\n\n app.get('/*', function (_, __, next: $NextFunctionVer) {\n next(ErrorCode.getNotFound(API_ERROR.FILE_NOT_FOUND));\n });\n app.use(handleError(logger));\n app.use(final);\n\n return app;\n};\n\nexport default (async function (configHash: ConfigYaml): Promise<express.Application> {\n const config: IConfig = new AppConfig(_.cloneDeep(configHash));\n\n const storage = new Storage(config);\n // waits until init calls have been initialized\n await storage.init(config);\n return await defineAPI(config, storage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BAAqB,KAAK,MAAM,OAAO;CAChD,CAAC;CAGD,IAAI,IAAI,iBAAY,QAAQ,MAAM,OAAO,CAAC;CAG1C,IAAI,EAAE,IAAI,QAAQ,cAAc,IAAI,GAAG;EACrC,IAAI,KAAK,MAAM,KAAK,SAAS;GAC3B,IAAI,OAAO,cAAc;GACzB,KAAK;EACP,CAAC;EACD,MAAM,aAAa,MAAM,YAAc,QAAQ,MAAM,SAAS,MAAM;EACpE,IAAI,IAAI,UAAU;CACpB,OACE,IAAI,IAAI,KAAK,SAAU,GAAG,IAAI,MAAwB;EACpD,KAAK,UAAU,YAAY,UAAU,YAAY,CAAC;CACpD,CAAC;CAGH,IAAI,IAAI,MAAM,SAAU,GAAG,IAAI,MAAwB;EACrD,KAAK,UAAU,YAAY,UAAU,cAAc,CAAC;CACtD,CAAC;CACD,IAAI,IAAI,YAAY,MAAM,CAAC;CAC3B,IAAI,IAAI,KAAK;CAEb,OAAO;AACT;AAEA,IAAA,eAAgB,eAAgB,YAAsD;CACpF,MAAM,SAAkB,IAAI,SAAU,EAAE,UAAU,UAAU,CAAC;CAE7D,MAAM,UAAU,IAAI,QAAQ,MAAM;CAElC,MAAM,QAAQ,KAAK,MAAM;CACzB,OAAO,MAAM,UAAU,QAAQ,OAAO;AACxC"}
@@ -5,7 +5,7 @@ const require_lib_cli_commands_init = require("./commands/init.js");
5
5
  const require_lib_cli_commands_version = require("./commands/version.js");
6
6
  let clipanion = require("clipanion");
7
7
  //#region src/lib/cli/cli.ts
8
- var pkgVersion = "6.10.2";
8
+ var pkgVersion = "6.10.4";
9
9
  if (process.getuid && process.getuid() === 0) process.emitWarning(`Verdaccio doesn't need superuser privileges. don't run it under root`);
10
10
  if (!require_lib_cli_utils.isVersionValid(process.version)) throw new Error(`Verdaccio requires at least Node.js v22 or higher and you have installed ${process.version},
11
11
  please upgrade your Node.js distribution`);
@@ -4,7 +4,7 @@ import { InitCommand } from "./commands/init.mjs";
4
4
  import { VersionCommand } from "./commands/version.mjs";
5
5
  import { Cli } from "clipanion";
6
6
  //#region src/lib/cli/cli.ts
7
- var pkgVersion = "6.10.2";
7
+ var pkgVersion = "6.10.4";
8
8
  if (process.getuid && process.getuid() === 0) process.emitWarning(`Verdaccio doesn't need superuser privileges. don't run it under root`);
9
9
  if (!isVersionValid(process.version)) throw new Error(`Verdaccio requires at least Node.js v22 or higher and you have installed ${process.version},
10
10
  please upgrade your Node.js distribution`);
@@ -10,7 +10,7 @@ let path = require("path");
10
10
  path = require_runtime.__toESM(path);
11
11
  let clipanion = require("clipanion");
12
12
  //#region src/lib/cli/commands/init.ts
13
- var pkgVersion = "6.10.2";
13
+ var pkgVersion = "6.10.4";
14
14
  var pkgName = "verdaccio";
15
15
  var DEFAULT_PROCESS_NAME = "verdaccio";
16
16
  var InitCommand = class extends clipanion.Command {
@@ -7,7 +7,7 @@ import { findConfigFile, getListenAddress } from "@verdaccio/config";
7
7
  import Path from "path";
8
8
  import { Command, Option } from "clipanion";
9
9
  //#region src/lib/cli/commands/init.ts
10
- var pkgVersion = "6.10.2";
10
+ var pkgVersion = "6.10.4";
11
11
  var pkgName = "verdaccio";
12
12
  var DEFAULT_PROCESS_NAME = "verdaccio";
13
13
  var InitCommand = class extends Command {
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let clipanion = require("clipanion");
3
3
  //#region src/lib/cli/commands/version.ts
4
- var pkgVersion = "6.10.2";
4
+ var pkgVersion = "6.10.4";
5
5
  var VersionCommand = class extends clipanion.Command {
6
6
  static paths = [[`--version`], [`-v`]];
7
7
  async execute() {
@@ -1,6 +1,6 @@
1
1
  import { Command } from "clipanion";
2
2
  //#region src/lib/cli/commands/version.ts
3
- var pkgVersion = "6.10.2";
3
+ var pkgVersion = "6.10.4";
4
4
  var VersionCommand = class extends Command {
5
5
  static paths = [[`--version`], [`-v`]];
6
6
  async execute() {
@@ -294,14 +294,14 @@ var Storage = class {
294
294
  return readStream.emit("error", err404);
295
295
  }
296
296
  debug$1("dist file found, using it %o", distFile.url);
297
- serveFile(distFile);
297
+ serveFile(distFile, syncInfo);
298
298
  });
299
299
  };
300
300
  self.localStorage.getPackageMetadataAsync(name).then((info) => {
301
301
  const distFile = require_lib_storage_utils.lookupDistFile(info, filename);
302
302
  if (lodash.default.isNil(distFile) === false) {
303
303
  debug$1("dist file found, using it %o", distFile.url);
304
- serveFile(distFile);
304
+ serveFile(distFile, info);
305
305
  } else {
306
306
  debug$1("dist file not found, proceed update upstream");
307
307
  lookupFromUplinks(info);
@@ -323,26 +323,38 @@ var Storage = class {
323
323
  * Stream the tarball from the uplink serving the distfile, caching it
324
324
  * locally (and restoring the distfile record) when the uplink has the
325
325
  * cache enabled.
326
+ *
327
+ * Off-uplink URLs on a locally published package are not fetched: the
328
+ * client's `dist.tarball` is stored verbatim, and fetching it would be
329
+ * SSRF (and would attach uplink credentials when only one uplink is
330
+ * configured). Uplink-synced packages may still use an autogenerated
331
+ * proxy without credentials for CDN-hosted tarballs.
326
332
  * @param {DistFile} file distfile record resolved for the tarball
333
+ * @param {Manifest} origin package metadata the distfile was resolved from
327
334
  */
328
- function serveFile(file) {
335
+ function serveFile(file, origin) {
329
336
  let uplink = null;
337
+ const candidates = [];
338
+ for (const uplinkId in self.uplinks) if ((0, _verdaccio_config.hasProxyTo)(name, uplinkId, self.config.packages)) candidates.push(self.uplinks[uplinkId]);
330
339
  if (file.registry && self.uplinks[file.registry]) {
331
- uplink = self.uplinks[file.registry];
332
- debug$1("tarball %o is served by the recorded uplink %o", filename, file.registry);
333
- } else {
334
- const candidates = [];
335
- for (const uplinkId in self.uplinks) if ((0, _verdaccio_config.hasProxyTo)(name, uplinkId, self.config.packages)) candidates.push(self.uplinks[uplinkId]);
340
+ const recorded = self.uplinks[file.registry];
341
+ if (recorded.isUplinkValid(file.url)) {
342
+ uplink = recorded;
343
+ debug$1("tarball %o is served by the recorded uplink %o", filename, file.registry);
344
+ }
345
+ }
346
+ if (uplink === null) {
336
347
  debug$1("tarball %o has %o candidate uplinks", filename, candidates.length);
337
348
  for (const candidate of candidates) if (candidate.isUplinkValid(file.url)) uplink = candidate;
338
349
  if (uplink !== null) debug$1("uplink %o url matches tarball %o", uplink.upname, file.url);
339
- else if (candidates.length === 1) {
340
- uplink = candidates[0];
341
- debug$1("using the single configured uplink %o for tarball %o hosted elsewhere", uplink.upname, file.url);
342
- }
343
350
  }
344
351
  if (uplink == null) {
345
- debug$1("upstream not found, creating one for %o", name);
352
+ if (!Boolean(origin?._distfiles?.[filename])) {
353
+ debug$1("refusing off-uplink tarball fetch for locally published %o (%o)", name, file.url);
354
+ readStream.emit("error", require_lib_utils.ErrorCode.getNotFound(_verdaccio_core.API_ERROR.NO_SUCH_FILE));
355
+ return;
356
+ }
357
+ debug$1("upstream not found, creating one for %o without uplink credentials", name);
346
358
  uplink = new require_lib_up_storage.default({
347
359
  url: file.url,
348
360
  cache: true,
@@ -1 +1 @@
1
- {"version":3,"file":"storage.js","names":[],"sources":["../../src/lib/storage.ts"],"sourcesContent":["import assert from 'assert';\nimport async from 'async';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport Stream from 'stream';\n\nimport { hasProxyTo } from '@verdaccio/config';\nimport { PLUGIN_CATEGORY, pluginUtils, validationUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabasePluginModule from '@verdaccio/local-storage-legacy';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport { ReadTarball } from '@verdaccio/streams';\nimport {\n Callback,\n Config,\n DistFile,\n Logger,\n Manifest,\n MergeTags,\n Version,\n Versions,\n} from '@verdaccio/types';\nimport { GenericBody, Token, TokenFilter } from '@verdaccio/types';\n\nimport { StoragePluginLegacy } from '../../types/custom';\nimport { logger } from '../lib/logger';\nimport { IPluginFilters, ISyncUplinks, StringValue } from '../types';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS } from './constants';\nimport LocalStorage, { StoragePlugin } from './local-storage';\nimport { mergeVersions } from './metadata-utils';\nimport {\n checkPackageLocal,\n checkPackageRemote,\n cleanUpLinksRef,\n convertAbbreviatedManifest,\n generatePackageTemplate,\n lookupDistFile,\n mergeUplinkTimeIntoLocal,\n publishPackage,\n} from './storage-utils';\nimport ProxyStorage from './up-storage';\nimport { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';\nimport { ErrorCode, hasTarball, isObject, normalizeDistTags } from './utils';\n\nconst debug = buildDebug('verdaccio:storage');\n\nclass Storage {\n public localStorage: LocalStorage;\n public config: Config;\n public logger: Logger;\n public uplinks: Record<string, ProxyStorage>;\n public filters: IPluginFilters | undefined;\n\n public constructor(config: Config) {\n this.config = config;\n this.uplinks = setupUpLinks(config);\n this.logger = logger;\n // @ts-ignore\n this.localStorage = null;\n }\n\n /**\n * Initialize the storage: load the storage plugin (or the default\n * local storage) and the filter plugins. Safe to call once; subsequent\n * calls only reload missing filters.\n * @param {Config} config verdaccio configuration\n * @param {IPluginFilters} filters preloaded filter plugins; when omitted they are loaded from the configuration\n */\n public async init(config: Config, filters?: IPluginFilters): Promise<void> {\n if (this.localStorage === null) {\n this.filters = filters;\n const storageInstance = await this.loadStorage(config, this.logger);\n this.localStorage = new LocalStorage(this.config, logger, storageInstance);\n await this.localStorage.getSecret(config);\n debug('initialization completed');\n } else {\n debug('storage has been already initialized');\n }\n\n if (!this.filters) {\n this.filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n this.config.filters,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin: pluginUtils.ManifestFilter<Config>) => {\n return typeof plugin.filter_metadata !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', this.filters.length);\n }\n }\n\n /**\n * Resolve the storage backend: a configured storage plugin when available,\n * otherwise the default `@verdaccio/local-storage` on the configured path.\n * @return {Promise<StoragePlugin>} the storage plugin instance\n */\n private async loadStorage(config: Config, logger: Logger): Promise<StoragePlugin> {\n const Storage = await this.loadStorePlugin();\n if (_.isNil(Storage)) {\n assert(this.config.storage, 'CONFIG: storage path not defined');\n debug('no custom storage found, loading default storage @verdaccio/local-storage');\n // the package is CJS with an `exports.default`; in the ESM build the default\n // import is the whole `module.exports`, so unwrap `.default` when present\n const LocalDatabasePlugin =\n (LocalDatabasePluginModule as unknown as { default?: typeof LocalDatabasePluginModule })\n .default ?? LocalDatabasePluginModule;\n const localStorage = new LocalDatabasePlugin(config, logger);\n logger.info(\n { name: '@verdaccio/local-storage', pluginCategory: PLUGIN_CATEGORY.STORAGE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n return localStorage;\n }\n return Storage as StoragePlugin;\n }\n\n /**\n * Load the storage plugins declared under `store` in the configuration.\n * Only one storage is supported: with several plugins configured the\n * first loaded one wins and a warning is logged.\n * @return {Promise<StoragePluginLegacy<Config> | undefined>} the selected plugin, or undefined when none is configured\n */\n private async loadStorePlugin(): Promise<StoragePluginLegacy<Config> | undefined> {\n const plugins: StoragePluginLegacy<Config>[] = await asyncLoadPlugin<\n pluginUtils.Storage<unknown>\n >(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin) => {\n return typeof plugin.getPackageStorage !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.STORAGE\n );\n\n if (plugins.length > 1) {\n this.logger.warn(\n 'more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically'\n );\n }\n\n return _.head(plugins);\n }\n\n /**\n * Add a package to the system (publish flow).\n * Verifies the package does not exist locally nor on any uplink before\n * creating it locally; uplinks being offline rejects the publish unless\n * `publish.allow_offline` is enabled.\n * Used storages: local (write) && uplinks\n * @param {String} name package name\n * @param {Object} metadata package manifest to publish\n * @param {Function} callback invoked with an error when the publish is rejected\n */\n public async addPackage(name: string, metadata: any, callback: any): Promise<void> {\n debug('add package %o', name);\n try {\n await checkPackageLocal(name, this.localStorage);\n await checkPackageRemote(\n name,\n this._isAllowPublishOffline(),\n this._syncUplinksMetadata.bind(this)\n );\n await publishPackage(name, metadata, this.localStorage);\n callback();\n } catch (err: any) {\n callback(err);\n }\n }\n\n /**\n * Whether `publish.allow_offline` is enabled in the configuration.\n * @return {Boolean} true when publishing with unreachable uplinks is allowed\n */\n private _isAllowPublishOffline(): boolean {\n return (\n typeof this.config.publish !== 'undefined' &&\n _.isBoolean(this.config.publish.allow_offline) &&\n this.config.publish.allow_offline\n );\n }\n\n /**\n * Read the npm tokens matching the filter from the token storage.\n * Used storages: local (read)\n */\n public readTokens(filter: TokenFilter): Promise<Token[]> {\n return this.localStorage.readTokens(filter);\n }\n\n /**\n * Save an npm token to the token storage.\n * Used storages: local (write)\n */\n public saveToken(token: Token): Promise<void> {\n return this.localStorage.saveToken(token);\n }\n\n /**\n * Delete an npm token from the token storage.\n * Used storages: local (write)\n */\n public deleteToken(user: string, tokenKey: string): Promise<any> {\n return this.localStorage.deleteToken(user, tokenKey);\n }\n\n /**\n * Add a new version of a package to the system.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} version version id, eg. 1.0.0\n * @param {Version} metadata version metadata\n * @param {String} tag dist-tag pointing to the version\n * @param {Function} callback\n */\n public addVersion(\n name: string,\n version: string,\n metadata: Version,\n tag: StringValue,\n callback: Callback\n ): void {\n debug('add version %s package for %s', version, name);\n this.localStorage.addVersion(name, version, metadata, tag, callback);\n }\n\n /**\n * Tag package versions with the provided dist-tags.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {MergeTags} tagHash dist-tag to version mapping to merge\n * @param {Function} callback\n */\n public mergeTags(name: string, tagHash: MergeTags, callback: Callback): void {\n debug('merge tags for %o', name);\n this.localStorage.mergeTags(name, tagHash, callback);\n }\n\n /**\n * Change an existing package (eg. unpublish one version).\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Manifest} metadata updated package manifest\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public changePackage(\n name: string,\n metadata: Manifest,\n revision: string,\n callback: Callback\n ): void {\n debug('change existing package for package %o revision %o', name, revision);\n this.localStorage.changePackage(name, metadata, revision, callback);\n }\n\n /**\n * Remove a package from the local storage and the search indexer.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Function} callback\n */\n public removePackage(name: string, callback: Callback): void {\n debug('remove package %o', name);\n this.localStorage.removePackage(name, callback);\n // update the indexer\n SearchMemoryIndexer.remove(name).catch((reason) => {\n debug('indexer has failed on remove item %o', reason);\n logger.error('indexer has failed on remove item');\n });\n }\n\n /**\n * Remove a tarball from the local storage. The tarball must not be\n * linked by any existing version, ie. the version should be\n * unpublished first.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public removeTarball(name: string, filename: string, revision: string, callback: Callback): void {\n debug('remove tarball %s for %s', filename, name);\n this.localStorage.removeTarball(name, filename, revision, callback);\n }\n\n /**\n * Upload a tarball (publish flow). Synchronous, returns a writable\n * stream the tarball body is piped into.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} writable upload stream\n */\n public addTarball(name: string, filename: string) {\n debug('add a tarball for %o', name);\n return this.localStorage.addTarball(name, filename);\n }\n\n /**\n * Whether a tarball exists in the local storage, without reading it\n * (the stream is aborted as soon as it opens).\n * Used storages: local (read)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Promise<Boolean>} true when the tarball is stored locally\n */\n public hasLocalTarball(name: string, filename: string): Promise<boolean> {\n const self = this;\n return new Promise<boolean>((resolve, reject): void => {\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n reject(err);\n }\n // local reported 404 or request was aborted already\n if (localStream) {\n localStream.abort();\n localStream = null;\n }\n resolve(false);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.abort();\n localStream = null;\n resolve(true);\n });\n });\n }\n\n /**\n * Get a tarball. Synchronous, returns a readable stream.\n * The tarball is read locally first; on a local miss the distfile record\n * is resolved from the package metadata (see lookupDistFile), syncing the\n * uplinks when the local metadata does not know the file, and the tarball\n * is then fetched from the uplink that serves the distfile url.\n * Used storages: local || uplink (just one)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} readable tarball stream\n */\n public getTarball(name: string, filename: string) {\n debug('get tarball for package %o filename %o', name, filename);\n const readStream = new ReadTarball({});\n readStream.abort = function () {};\n\n const self = this;\n\n // Check if the tarball is allowed by filter plugins before serving.\n // Filters may block specific versions, so we verify the tarball's version\n // still exists in the filtered metadata.\n this._isTarballAllowedByFilters(name, filename).then(async (allowed) => {\n if (!allowed) {\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_PACKAGE));\n return;\n }\n\n // trying local first\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n return readStream.emit('error', err);\n }\n\n // local reported 404\n const err404 = err;\n localStream.abort();\n localStream = null; // we force for garbage collector\n\n const lookupFromUplinks = (info: Manifest | null): void => {\n self._syncUplinksMetadata(\n name,\n info as Manifest,\n {},\n (syncErr, syncInfo: Manifest): any => {\n if (_.isNil(syncErr) === false) {\n return readStream.emit('error', syncErr);\n }\n // _syncUplinksMetadata returns filter-applied metadata; if the\n // version was removed by a filter, surface a 404 like a missing tarball.\n if (self.filters?.length && !hasTarball(syncInfo, filename)) {\n return readStream.emit('error', err404);\n }\n const distFile = lookupDistFile(syncInfo, filename);\n if (_.isNil(distFile)) {\n debug('remote tarball not found');\n return readStream.emit('error', err404);\n }\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile);\n }\n );\n };\n\n self.localStorage.getPackageMetadataAsync(name).then(\n (info) => {\n const distFile = lookupDistFile(info, filename);\n if (_.isNil(distFile) === false) {\n // information about this file exists locally\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile);\n } else {\n // we know nothing about this file, trying to get information elsewhere\n debug('dist file not found, proceed update upstream');\n lookupFromUplinks(info);\n }\n },\n () => {\n // we know nothing about this file, trying to get information elsewhere\n lookupFromUplinks(null);\n }\n );\n });\n localStream.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.pipe(readStream);\n });\n });\n\n return readStream;\n\n /**\n * Stream the tarball from the uplink serving the distfile, caching it\n * locally (and restoring the distfile record) when the uplink has the\n * cache enabled.\n * @param {DistFile} file distfile record resolved for the tarball\n */\n function serveFile(file: DistFile): void {\n let uplink: any = null;\n\n if (file.registry && self.uplinks[file.registry]) {\n // the distfile records which uplink it was merged from\n // (see LocalStorage._updateUplinkToRemoteProtocol)\n uplink = self.uplinks[file.registry];\n debug('tarball %o is served by the recorded uplink %o', filename, file.registry);\n } else {\n const candidates: any[] = [];\n for (const uplinkId in self.uplinks) {\n if (hasProxyTo(name, uplinkId, self.config.packages)) {\n candidates.push(self.uplinks[uplinkId]);\n }\n }\n debug('tarball %o has %o candidate uplinks', filename, candidates.length);\n\n // pick the uplink that actually serves the distfile url, so the\n // request carries the settings of the registry hosting it; with\n // several matching uplinks (duplicated urls) the last configured\n // one keeps winning, exactly like the previous selection did\n for (const candidate of candidates) {\n if (candidate.isUplinkValid(file.url)) {\n uplink = candidate;\n }\n }\n\n if (uplink !== null) {\n debug('uplink %o url matches tarball %o', uplink.upname, file.url);\n } else if (candidates.length === 1) {\n // a single configured uplink keeps the legacy behavior: tarballs\n // hosted elsewhere (a CDN) may still need its agent/proxy settings\n uplink = candidates[0];\n debug(\n 'using the single configured uplink %o for tarball %o hosted elsewhere',\n uplink.upname,\n file.url\n );\n }\n }\n\n if (uplink == null) {\n debug('upstream not found, creating one for %o', name);\n uplink = new ProxyStorage(\n {\n url: file.url,\n cache: true,\n _autogenerated: true,\n },\n self.config\n );\n }\n\n let savestream: any = null;\n if (uplink.config.cache) {\n // persist which configured uplink served the tarball, so future\n // fetches can pick it directly (autogenerated proxies have no name)\n debug('cache remote tarball enabled');\n let distFile: DistFile = file;\n if (!file.registry && uplink.upname) {\n debug('recording uplink %o on the persisted distfile for %o', uplink.upname, filename);\n distFile = { ...file, registry: uplink.upname };\n }\n savestream = self.localStorage.addTarball(name, filename, distFile);\n } else {\n debug('cache remote tarball disabled');\n }\n\n let on_open = function (): void {\n // prevent it from being called twice\n on_open = function () {};\n const rstream2 = uplink.fetchTarball(file.url);\n rstream2.on('error', function (err): void {\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n readStream.emit('error', err);\n });\n rstream2.on('end', function (): void {\n if (savestream) {\n savestream.done();\n }\n });\n\n rstream2.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n if (savestream) {\n savestream.emit('content-length', v);\n }\n });\n rstream2.pipe(readStream);\n if (savestream) {\n rstream2.pipe(savestream);\n }\n };\n\n if (savestream) {\n savestream.on('open', function (): void {\n on_open();\n });\n\n savestream.on('error', function (err): void {\n self.logger.warn(\n { err: err, fileName: file },\n 'error saving file @{fileName}: @{err.message}\\n@{err.stack}'\n );\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n on_open();\n });\n } else {\n on_open();\n }\n }\n }\n\n /**\n * Retrieve the package metadata: the local manifest merged with the\n * manifest of every uplink with proxy access to the package.\n * Used storages: local && uplink (proxy_access)\n * @param {Object} options\n * @property {String} options.name package name\n * @property {Object} options.req Express `req` object\n * @property {Boolean} options.keepUpLinkData keep the uplink info (last update, etc.) in the package metadata\n * @property {Boolean} options.abbreviated serve the abbreviated manifest (npm install)\n * @property {Function} options.callback invoked with the merged manifest and any uplink errors\n */\n public getPackage(options): void {\n debug('get package for %o', options.name);\n this.localStorage.getPackageMetadata(options.name, (err, data): void => {\n if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {\n // report internal errors right away\n return options.callback(err);\n }\n\n this._syncUplinksMetadata(\n options.name,\n data,\n { req: options.req, uplinksLook: options.uplinksLook },\n function getPackageSynUpLinksCallback(err, result: Manifest, uplinkErrors): void {\n if (err) {\n return options.callback(err);\n }\n\n normalizeDistTags(cleanUpLinksRef(options.keepUpLinkData, result));\n\n // npm can throw if this field doesn't exist\n result._attachments = {};\n if (options.abbreviated === true) {\n debug('get abbreviated manifest');\n options.callback(null, convertAbbreviatedManifest(result), uplinkErrors);\n } else {\n debug('get full package manifest');\n options.callback(null, result, uplinkErrors);\n }\n }\n );\n });\n }\n\n /**\n * Retrieve remote and local packages more recent than the start key.\n * All uplinks are streamed first, then the local packages; local\n * packages can override registry ones just because they appear in the\n * JSON last — a trade-off made to avoid memory issues.\n * Used storages: local && uplink (proxy_access)\n * @param {String} startkey timestamp to search from\n * @param {Object} options request options; `local=1` in the query skips the uplinks\n * @return {Stream} object stream of search results\n */\n public search(startkey: string, options: any) {\n const self = this;\n const searchStream: any = new Stream.PassThrough({ objectMode: true });\n async.eachSeries(\n Object.keys(this.uplinks),\n function (up_name, cb): void {\n // shortcut: if `local=1` is supplied, don't call uplinks\n if (options.req?.query?.local !== undefined) {\n return cb();\n }\n logger.info(`search for uplink ${up_name}`);\n // search by keyword for each uplink\n const uplinkStream = self.uplinks[up_name].search(options);\n // join uplink stream with streams PassThrough\n uplinkStream.pipe(searchStream, { end: false });\n uplinkStream.on('error', function (err): void {\n self.logger.error({ err: err }, 'uplink error: @{err.message}');\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n uplinkStream.on('end', function (): void {\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n\n searchStream.abort = function (): void {\n if (uplinkStream.abort) {\n uplinkStream.abort();\n }\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n };\n },\n // executed after all series\n function (): void {\n // attach a local search results\n const localSearchStream = self.localStorage.search(startkey, options);\n searchStream.abort = function (): void {\n localSearchStream.abort();\n };\n localSearchStream.pipe(searchStream, { end: true });\n localSearchStream.on('error', function (err: any): void {\n self.logger.error({ err: err }, 'search error: @{err.message}');\n searchStream.end();\n });\n }\n );\n\n return searchStream;\n }\n\n /**\n * Retrieve only private local packages, as the latest version of each.\n * Used storages: local (read)\n * @param {Function} callback invoked with the list of latest versions\n */\n public getLocalDatabase(callback: Callback): void {\n this.localStorage.storagePlugin.get((err, locals): void => {\n if (err) {\n return callback(err);\n }\n\n this._collectLocalPackages(locals).then(\n (packages) => callback(null, packages),\n (err) => callback(err)\n );\n });\n }\n\n /**\n * Read each local package name, apply filters, and collect the latest version.\n */\n private async _collectLocalPackages(locals: string[]): Promise<Version[]> {\n const packages: Version[] = [];\n for (const name of locals) {\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const latest = filteredPackage[DIST_TAGS]?.latest;\n if (latest && filteredPackage.versions[latest]) {\n const version: Version = filteredPackage.versions[latest];\n const timeList = filteredPackage.time as GenericBody;\n const time = timeList[latest];\n // @ts-ignore\n version.time = time;\n\n // Add for stars api\n // @ts-ignore\n version.users = filteredPackage.users;\n\n packages.push(version);\n } else {\n this.logger.warn({ package: name }, 'package @{package} does not have a \"latest\" tag?');\n }\n } catch (err) {\n this.logger.error({ err, package: name }, 'error reading package @{package}');\n }\n }\n return packages;\n }\n\n /**\n * Fetch the package metadata from every uplink with proxy access and\n * synchronize it with the local data; filter plugins are applied to the\n * merged result.\n * @param {String} name package name\n * @param {Manifest} packageInfo local manifest; MUST be provided when the package exists locally\n * @param {ISyncUplinks} options uplink request options\n * @param {Function} callback invoked with (err, mergedManifest, uplinkErrors)\n */\n public _syncUplinksMetadata(\n name: string,\n packageInfo: Manifest,\n options: ISyncUplinks,\n callback: Callback\n ): void {\n let found = true;\n const self = this;\n const upLinks: ProxyStorage[] = [];\n const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;\n\n debug('sync uplinks for %o', name);\n debug('is sync uplink enabled %o', hasToLookIntoUplinks);\n if (!packageInfo) {\n debug('local package %s not found', name);\n found = false;\n packageInfo = generatePackageTemplate(name);\n }\n\n for (const uplink in this.uplinks) {\n if (hasProxyTo(name, uplink, this.config.packages) && hasToLookIntoUplinks) {\n upLinks.push(this.uplinks[uplink]);\n }\n }\n debug('uplinks found for %o: %o', name, upLinks.length);\n\n async.map(\n upLinks,\n (upLink: ProxyStorage, cb): void => {\n const _options = Object.assign({}, options);\n const upLinkMeta = packageInfo._uplinks[upLink.upname];\n\n if (isObject(upLinkMeta)) {\n const fetched = upLinkMeta.fetched;\n\n if (fetched && Date.now() - fetched < upLink.maxage) {\n debug('returning cached manifest for %o', upLink.upname);\n return cb();\n }\n\n _options.etag = upLinkMeta.etag;\n }\n\n upLink.getRemoteMetadata(name, _options, (err, upLinkResponse, eTag): void => {\n if (err && err.remoteStatus === 304) {\n debug('uplink %o responded 304 for %o, cache is up to date', upLink.upname, name);\n upLinkMeta.fetched = Date.now();\n }\n\n if (err || !upLinkResponse) {\n debug('error captured on uplink %o for %o: %o', upLink.upname, name, err?.message);\n return cb(null, [err || ErrorCode.getInternalError('no data')]);\n }\n\n try {\n upLinkResponse = validationUtils.normalizeMetadata(upLinkResponse, name);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json validating error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n packageInfo._uplinks[upLink.upname] = {\n etag: eTag,\n fetched: Date.now(),\n };\n\n packageInfo = mergeUplinkTimeIntoLocal(packageInfo, upLinkResponse);\n\n updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);\n\n try {\n mergeVersions(packageInfo, upLinkResponse);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json parsing error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n // if we got to this point, assume that the correct package exists\n // on the uplink\n debug('syncing on uplink %o', upLink.upname);\n found = true;\n cb();\n });\n },\n // @ts-ignore\n async (err: Error, upLinksErrors: any): Promise<void> => {\n assert(!err && Array.isArray(upLinksErrors));\n\n // Check for connection timeout or reset errors with uplink(s)\n // (these should be handled differently from the package not being found)\n if (!found) {\n let uplinkTimeoutError;\n for (let i = 0; i < upLinksErrors.length; i++) {\n if (upLinksErrors[i]) {\n for (let j = 0; j < upLinksErrors[i].length; j++) {\n if (upLinksErrors[i][j]) {\n const code = upLinksErrors[i][j].code;\n if (code === 'ETIMEDOUT' || code === 'ESOCKETTIMEDOUT' || code === 'ECONNRESET') {\n uplinkTimeoutError = true;\n break;\n }\n }\n }\n }\n }\n\n if (uplinkTimeoutError) {\n debug('uplinks sync failed with timeout error');\n return callback(ErrorCode.getServiceUnavailable(), null, upLinksErrors);\n }\n debug('uplinks sync failed with no package found');\n return callback(ErrorCode.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors);\n }\n\n if (upLinks.length === 0) {\n debug('no uplinks found for %o, upstream update aborted', name);\n const { filteredPackage, filterErrors } = await self._applyFilters(\n packageInfo as Manifest\n );\n return callback(null, filteredPackage, filterErrors);\n }\n\n try {\n const packageJsonLocal = await self.localStorage.updateVersionsAsync(name, packageInfo);\n const { filteredPackage, filterErrors } = await self._applyFilters(packageJsonLocal);\n callback(null, filteredPackage, _.concat(upLinksErrors, filterErrors));\n } catch (err) {\n callback(err);\n }\n }\n );\n }\n\n /**\n * Apply all configured filter plugins to a package manifest sequentially.\n * Each filter's output is passed as input to the next filter.\n * Returns the filtered manifest and any errors that occurred.\n */\n private async _applyFilters(\n packageInfo: Manifest\n ): Promise<{ filteredPackage: Manifest; filterErrors: Error[] }> {\n const filterErrors: Error[] = [];\n let filteredPackage = packageInfo;\n for (const filter of this.filters ?? []) {\n try {\n filteredPackage = await filter.filter_metadata(filteredPackage);\n } catch (err: any) {\n debug('filter plugin has failed on %o: %o', packageInfo.name, err?.message);\n filterErrors.push(err);\n }\n }\n return { filteredPackage, filterErrors };\n }\n\n /**\n * Check if a tarball should be served based on filter plugins, using only\n * local metadata. Returns true (defer) when the version isn't cached locally\n * — the uplink-sync path in getTarball re-checks filters after sync, which\n * avoids a redundant uplink round-trip and double filter application.\n */\n private async _isTarballAllowedByFilters(name: string, filename: string): Promise<boolean> {\n if (!this.filters?.length) {\n return true;\n }\n\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n if (!hasTarball(pkgMetadata, filename)) {\n return true;\n }\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const allowed = hasTarball(filteredPackage, filename);\n if (allowed === false) {\n debug('tarball %o of %o is blocked by a filter plugin', filename, name);\n }\n return allowed;\n } catch (err: any) {\n if (err?.status === HTTP_STATUS.NOT_FOUND) {\n return true;\n }\n this.logger.error(\n { package: name, fileName: filename, err },\n 'error checking filters for tarball @{fileName} of package @{package}: @{err.message}'\n );\n return true;\n }\n }\n\n /**\n * Tag each version with the uplink it was fetched from, under a hidden\n * (symbol) key. The local storage uses the tag to record the registry\n * on the distfile records it creates.\n * @param {Versions} versions versions fetched from the uplink\n * @param {ProxyStorage} upLink uplink the versions were fetched from\n */\n public _updateVersionsHiddenUpLink(versions: Versions, upLink: ProxyStorage): void {\n for (const i in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, i)) {\n const version = versions[i];\n\n // holds a \"hidden\" value to be used by the package storage.\n version[Symbol.for('__verdaccio_uplink')] = upLink.upname;\n }\n }\n }\n}\n\nexport default Storage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,WAAA,GAAA,MAAA,QAAA,CAAmB,mBAAmB;AAE5C,IAAM,UAAN,MAAc;CACZ;CACA;CACA;CACA;CACA;CAEA,YAAmB,QAAgB;EACjC,KAAK,SAAS;EACd,KAAK,UAAU,wBAAA,aAAa,MAAM;EAClC,KAAK,SAAS,yBAAA;EAEd,KAAK,eAAe;CACtB;;;;;;;;CASA,MAAa,KAAK,QAAgB,SAAyC;EACzE,IAAI,KAAK,iBAAiB,MAAM;GAC9B,KAAK,UAAU;GACf,MAAM,kBAAkB,MAAM,KAAK,YAAY,QAAQ,KAAK,MA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Aa,wBAAwB,IAAI;GACxE,IAAI,CAAC,kBAAA,WAAW,aAAa,QAAQ,GACnC,OAAO;GAET,MAAM,EAAE,oBAAoB,MAAM,KAAK,cAAc,WAAW;GAChE,MAAM,UAAU,kBAAA,WAAW,iBAAiB,QAAQ;GACpD,IAAI,YAAY,OACd,QAAM,kDAAkD,UAAU,IAAI;GAExE,OAAO;EACT,SAAS,KAAU;GACjB,IAAI,KAAK,WAAW,gBAAA,YAAY,WAC9B,OAAO;GAET,KAAK,OAAO,MACV;IAAE,SAAS;IAAM,UAAU;IAAU;GAAI,GACzC,sFACF;GACA,OAAO;EACT;CACF;;;;;;;;CASA,4BAAmC,UAAoB,QAA4B;EACjF,KAAK,MAAM,KAAK,UACd,IAAI,OAAO,UAAU,eAAe,KAAK,UAAU,CAAC,GAAG;GACrD,MAAM,UAAU,SAAS;GAGzB,QAAQ,OAAO,IAAI,oBAAoB,KAAK,OAAO;EACrD;CAEJ;AACF"}
1
+ {"version":3,"file":"storage.js","names":[],"sources":["../../src/lib/storage.ts"],"sourcesContent":["import assert from 'assert';\nimport async from 'async';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport Stream from 'stream';\n\nimport { hasProxyTo } from '@verdaccio/config';\nimport { PLUGIN_CATEGORY, pluginUtils, validationUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabasePluginModule from '@verdaccio/local-storage-legacy';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport { ReadTarball } from '@verdaccio/streams';\nimport {\n Callback,\n Config,\n DistFile,\n Logger,\n Manifest,\n MergeTags,\n Version,\n Versions,\n} from '@verdaccio/types';\nimport { GenericBody, Token, TokenFilter } from '@verdaccio/types';\n\nimport { StoragePluginLegacy } from '../../types/custom';\nimport { logger } from '../lib/logger';\nimport { IPluginFilters, ISyncUplinks, StringValue } from '../types';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS } from './constants';\nimport LocalStorage, { StoragePlugin } from './local-storage';\nimport { mergeVersions } from './metadata-utils';\nimport {\n checkPackageLocal,\n checkPackageRemote,\n cleanUpLinksRef,\n convertAbbreviatedManifest,\n generatePackageTemplate,\n lookupDistFile,\n mergeUplinkTimeIntoLocal,\n publishPackage,\n} from './storage-utils';\nimport ProxyStorage from './up-storage';\nimport { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';\nimport { ErrorCode, hasTarball, isObject, normalizeDistTags } from './utils';\n\nconst debug = buildDebug('verdaccio:storage');\n\nclass Storage {\n public localStorage: LocalStorage;\n public config: Config;\n public logger: Logger;\n public uplinks: Record<string, ProxyStorage>;\n public filters: IPluginFilters | undefined;\n\n public constructor(config: Config) {\n this.config = config;\n this.uplinks = setupUpLinks(config);\n this.logger = logger;\n // @ts-ignore\n this.localStorage = null;\n }\n\n /**\n * Initialize the storage: load the storage plugin (or the default\n * local storage) and the filter plugins. Safe to call once; subsequent\n * calls only reload missing filters.\n * @param {Config} config verdaccio configuration\n * @param {IPluginFilters} filters preloaded filter plugins; when omitted they are loaded from the configuration\n */\n public async init(config: Config, filters?: IPluginFilters): Promise<void> {\n if (this.localStorage === null) {\n this.filters = filters;\n const storageInstance = await this.loadStorage(config, this.logger);\n this.localStorage = new LocalStorage(this.config, logger, storageInstance);\n await this.localStorage.getSecret(config);\n debug('initialization completed');\n } else {\n debug('storage has been already initialized');\n }\n\n if (!this.filters) {\n this.filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n this.config.filters,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin: pluginUtils.ManifestFilter<Config>) => {\n return typeof plugin.filter_metadata !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', this.filters.length);\n }\n }\n\n /**\n * Resolve the storage backend: a configured storage plugin when available,\n * otherwise the default `@verdaccio/local-storage` on the configured path.\n * @return {Promise<StoragePlugin>} the storage plugin instance\n */\n private async loadStorage(config: Config, logger: Logger): Promise<StoragePlugin> {\n const Storage = await this.loadStorePlugin();\n if (_.isNil(Storage)) {\n assert(this.config.storage, 'CONFIG: storage path not defined');\n debug('no custom storage found, loading default storage @verdaccio/local-storage');\n // the package is CJS with an `exports.default`; in the ESM build the default\n // import is the whole `module.exports`, so unwrap `.default` when present\n const LocalDatabasePlugin =\n (LocalDatabasePluginModule as unknown as { default?: typeof LocalDatabasePluginModule })\n .default ?? LocalDatabasePluginModule;\n const localStorage = new LocalDatabasePlugin(config, logger);\n logger.info(\n { name: '@verdaccio/local-storage', pluginCategory: PLUGIN_CATEGORY.STORAGE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n return localStorage;\n }\n return Storage as StoragePlugin;\n }\n\n /**\n * Load the storage plugins declared under `store` in the configuration.\n * Only one storage is supported: with several plugins configured the\n * first loaded one wins and a warning is logged.\n * @return {Promise<StoragePluginLegacy<Config> | undefined>} the selected plugin, or undefined when none is configured\n */\n private async loadStorePlugin(): Promise<StoragePluginLegacy<Config> | undefined> {\n const plugins: StoragePluginLegacy<Config>[] = await asyncLoadPlugin<\n pluginUtils.Storage<unknown>\n >(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin) => {\n return typeof plugin.getPackageStorage !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.STORAGE\n );\n\n if (plugins.length > 1) {\n this.logger.warn(\n 'more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically'\n );\n }\n\n return _.head(plugins);\n }\n\n /**\n * Add a package to the system (publish flow).\n * Verifies the package does not exist locally nor on any uplink before\n * creating it locally; uplinks being offline rejects the publish unless\n * `publish.allow_offline` is enabled.\n * Used storages: local (write) && uplinks\n * @param {String} name package name\n * @param {Object} metadata package manifest to publish\n * @param {Function} callback invoked with an error when the publish is rejected\n */\n public async addPackage(name: string, metadata: any, callback: any): Promise<void> {\n debug('add package %o', name);\n try {\n await checkPackageLocal(name, this.localStorage);\n await checkPackageRemote(\n name,\n this._isAllowPublishOffline(),\n this._syncUplinksMetadata.bind(this)\n );\n await publishPackage(name, metadata, this.localStorage);\n callback();\n } catch (err: any) {\n callback(err);\n }\n }\n\n /**\n * Whether `publish.allow_offline` is enabled in the configuration.\n * @return {Boolean} true when publishing with unreachable uplinks is allowed\n */\n private _isAllowPublishOffline(): boolean {\n return (\n typeof this.config.publish !== 'undefined' &&\n _.isBoolean(this.config.publish.allow_offline) &&\n this.config.publish.allow_offline\n );\n }\n\n /**\n * Read the npm tokens matching the filter from the token storage.\n * Used storages: local (read)\n */\n public readTokens(filter: TokenFilter): Promise<Token[]> {\n return this.localStorage.readTokens(filter);\n }\n\n /**\n * Save an npm token to the token storage.\n * Used storages: local (write)\n */\n public saveToken(token: Token): Promise<void> {\n return this.localStorage.saveToken(token);\n }\n\n /**\n * Delete an npm token from the token storage.\n * Used storages: local (write)\n */\n public deleteToken(user: string, tokenKey: string): Promise<any> {\n return this.localStorage.deleteToken(user, tokenKey);\n }\n\n /**\n * Add a new version of a package to the system.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} version version id, eg. 1.0.0\n * @param {Version} metadata version metadata\n * @param {String} tag dist-tag pointing to the version\n * @param {Function} callback\n */\n public addVersion(\n name: string,\n version: string,\n metadata: Version,\n tag: StringValue,\n callback: Callback\n ): void {\n debug('add version %s package for %s', version, name);\n this.localStorage.addVersion(name, version, metadata, tag, callback);\n }\n\n /**\n * Tag package versions with the provided dist-tags.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {MergeTags} tagHash dist-tag to version mapping to merge\n * @param {Function} callback\n */\n public mergeTags(name: string, tagHash: MergeTags, callback: Callback): void {\n debug('merge tags for %o', name);\n this.localStorage.mergeTags(name, tagHash, callback);\n }\n\n /**\n * Change an existing package (eg. unpublish one version).\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Manifest} metadata updated package manifest\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public changePackage(\n name: string,\n metadata: Manifest,\n revision: string,\n callback: Callback\n ): void {\n debug('change existing package for package %o revision %o', name, revision);\n this.localStorage.changePackage(name, metadata, revision, callback);\n }\n\n /**\n * Remove a package from the local storage and the search indexer.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Function} callback\n */\n public removePackage(name: string, callback: Callback): void {\n debug('remove package %o', name);\n this.localStorage.removePackage(name, callback);\n // update the indexer\n SearchMemoryIndexer.remove(name).catch((reason) => {\n debug('indexer has failed on remove item %o', reason);\n logger.error('indexer has failed on remove item');\n });\n }\n\n /**\n * Remove a tarball from the local storage. The tarball must not be\n * linked by any existing version, ie. the version should be\n * unpublished first.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public removeTarball(name: string, filename: string, revision: string, callback: Callback): void {\n debug('remove tarball %s for %s', filename, name);\n this.localStorage.removeTarball(name, filename, revision, callback);\n }\n\n /**\n * Upload a tarball (publish flow). Synchronous, returns a writable\n * stream the tarball body is piped into.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} writable upload stream\n */\n public addTarball(name: string, filename: string) {\n debug('add a tarball for %o', name);\n return this.localStorage.addTarball(name, filename);\n }\n\n /**\n * Whether a tarball exists in the local storage, without reading it\n * (the stream is aborted as soon as it opens).\n * Used storages: local (read)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Promise<Boolean>} true when the tarball is stored locally\n */\n public hasLocalTarball(name: string, filename: string): Promise<boolean> {\n const self = this;\n return new Promise<boolean>((resolve, reject): void => {\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n reject(err);\n }\n // local reported 404 or request was aborted already\n if (localStream) {\n localStream.abort();\n localStream = null;\n }\n resolve(false);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.abort();\n localStream = null;\n resolve(true);\n });\n });\n }\n\n /**\n * Get a tarball. Synchronous, returns a readable stream.\n * The tarball is read locally first; on a local miss the distfile record\n * is resolved from the package metadata (see lookupDistFile), syncing the\n * uplinks when the local metadata does not know the file, and the tarball\n * is then fetched from the uplink that serves the distfile url.\n * Used storages: local || uplink (just one)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} readable tarball stream\n */\n public getTarball(name: string, filename: string) {\n debug('get tarball for package %o filename %o', name, filename);\n const readStream = new ReadTarball({});\n readStream.abort = function () {};\n\n const self = this;\n\n // Check if the tarball is allowed by filter plugins before serving.\n // Filters may block specific versions, so we verify the tarball's version\n // still exists in the filtered metadata.\n this._isTarballAllowedByFilters(name, filename).then(async (allowed) => {\n if (!allowed) {\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_PACKAGE));\n return;\n }\n\n // trying local first\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n return readStream.emit('error', err);\n }\n\n // local reported 404\n const err404 = err;\n localStream.abort();\n localStream = null; // we force for garbage collector\n\n const lookupFromUplinks = (info: Manifest | null): void => {\n self._syncUplinksMetadata(\n name,\n info as Manifest,\n {},\n (syncErr, syncInfo: Manifest): any => {\n if (_.isNil(syncErr) === false) {\n return readStream.emit('error', syncErr);\n }\n // _syncUplinksMetadata returns filter-applied metadata; if the\n // version was removed by a filter, surface a 404 like a missing tarball.\n if (self.filters?.length && !hasTarball(syncInfo, filename)) {\n return readStream.emit('error', err404);\n }\n const distFile = lookupDistFile(syncInfo, filename);\n if (_.isNil(distFile)) {\n debug('remote tarball not found');\n return readStream.emit('error', err404);\n }\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile, syncInfo);\n }\n );\n };\n\n self.localStorage.getPackageMetadataAsync(name).then(\n (info) => {\n const distFile = lookupDistFile(info, filename);\n if (_.isNil(distFile) === false) {\n // information about this file exists locally\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile, info);\n } else {\n // we know nothing about this file, trying to get information elsewhere\n debug('dist file not found, proceed update upstream');\n lookupFromUplinks(info);\n }\n },\n () => {\n // we know nothing about this file, trying to get information elsewhere\n lookupFromUplinks(null);\n }\n );\n });\n localStream.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.pipe(readStream);\n });\n });\n\n return readStream;\n\n /**\n * Stream the tarball from the uplink serving the distfile, caching it\n * locally (and restoring the distfile record) when the uplink has the\n * cache enabled.\n *\n * Off-uplink URLs on a locally published package are not fetched: the\n * client's `dist.tarball` is stored verbatim, and fetching it would be\n * SSRF (and would attach uplink credentials when only one uplink is\n * configured). Uplink-synced packages may still use an autogenerated\n * proxy without credentials for CDN-hosted tarballs.\n * @param {DistFile} file distfile record resolved for the tarball\n * @param {Manifest} origin package metadata the distfile was resolved from\n */\n function serveFile(file: DistFile, origin?: Manifest | null): void {\n let uplink: any = null;\n\n const candidates: any[] = [];\n for (const uplinkId in self.uplinks) {\n if (hasProxyTo(name, uplinkId, self.config.packages)) {\n candidates.push(self.uplinks[uplinkId]);\n }\n }\n\n // recorded uplink is only used when it actually serves this URL, so\n // its Authorization header is never sent to an unrelated host\n if (file.registry && self.uplinks[file.registry]) {\n const recorded = self.uplinks[file.registry];\n if (recorded.isUplinkValid(file.url)) {\n uplink = recorded;\n debug('tarball %o is served by the recorded uplink %o', filename, file.registry);\n }\n }\n\n if (uplink === null) {\n debug('tarball %o has %o candidate uplinks', filename, candidates.length);\n for (const candidate of candidates) {\n if (candidate.isUplinkValid(file.url)) {\n uplink = candidate;\n }\n }\n if (uplink !== null) {\n debug('uplink %o url matches tarball %o', uplink.upname, file.url);\n }\n }\n\n if (uplink == null) {\n // `_distfiles` is written when metadata is merged from an uplink.\n // Local publish only stores versions[].dist.tarball, so a version\n // fallback to an off-uplink URL is client-controlled — do not fetch.\n const fromDistfiles = Boolean(origin?._distfiles?.[filename]);\n if (!fromDistfiles) {\n debug('refusing off-uplink tarball fetch for locally published %o (%o)', name, file.url);\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_SUCH_FILE));\n return;\n }\n debug('upstream not found, creating one for %o without uplink credentials', name);\n uplink = new ProxyStorage(\n {\n url: file.url,\n cache: true,\n _autogenerated: true,\n },\n self.config\n );\n }\n\n let savestream: any = null;\n if (uplink.config.cache) {\n // persist which configured uplink served the tarball, so future\n // fetches can pick it directly (autogenerated proxies have no name)\n debug('cache remote tarball enabled');\n let distFile: DistFile = file;\n if (!file.registry && uplink.upname) {\n debug('recording uplink %o on the persisted distfile for %o', uplink.upname, filename);\n distFile = { ...file, registry: uplink.upname };\n }\n savestream = self.localStorage.addTarball(name, filename, distFile);\n } else {\n debug('cache remote tarball disabled');\n }\n\n let on_open = function (): void {\n // prevent it from being called twice\n on_open = function () {};\n const rstream2 = uplink.fetchTarball(file.url);\n rstream2.on('error', function (err): void {\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n readStream.emit('error', err);\n });\n rstream2.on('end', function (): void {\n if (savestream) {\n savestream.done();\n }\n });\n\n rstream2.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n if (savestream) {\n savestream.emit('content-length', v);\n }\n });\n rstream2.pipe(readStream);\n if (savestream) {\n rstream2.pipe(savestream);\n }\n };\n\n if (savestream) {\n savestream.on('open', function (): void {\n on_open();\n });\n\n savestream.on('error', function (err): void {\n self.logger.warn(\n { err: err, fileName: file },\n 'error saving file @{fileName}: @{err.message}\\n@{err.stack}'\n );\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n on_open();\n });\n } else {\n on_open();\n }\n }\n }\n\n /**\n * Retrieve the package metadata: the local manifest merged with the\n * manifest of every uplink with proxy access to the package.\n * Used storages: local && uplink (proxy_access)\n * @param {Object} options\n * @property {String} options.name package name\n * @property {Object} options.req Express `req` object\n * @property {Boolean} options.keepUpLinkData keep the uplink info (last update, etc.) in the package metadata\n * @property {Boolean} options.abbreviated serve the abbreviated manifest (npm install)\n * @property {Function} options.callback invoked with the merged manifest and any uplink errors\n */\n public getPackage(options): void {\n debug('get package for %o', options.name);\n this.localStorage.getPackageMetadata(options.name, (err, data): void => {\n if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {\n // report internal errors right away\n return options.callback(err);\n }\n\n this._syncUplinksMetadata(\n options.name,\n data,\n { req: options.req, uplinksLook: options.uplinksLook },\n function getPackageSynUpLinksCallback(err, result: Manifest, uplinkErrors): void {\n if (err) {\n return options.callback(err);\n }\n\n normalizeDistTags(cleanUpLinksRef(options.keepUpLinkData, result));\n\n // npm can throw if this field doesn't exist\n result._attachments = {};\n if (options.abbreviated === true) {\n debug('get abbreviated manifest');\n options.callback(null, convertAbbreviatedManifest(result), uplinkErrors);\n } else {\n debug('get full package manifest');\n options.callback(null, result, uplinkErrors);\n }\n }\n );\n });\n }\n\n /**\n * Retrieve remote and local packages more recent than the start key.\n * All uplinks are streamed first, then the local packages; local\n * packages can override registry ones just because they appear in the\n * JSON last — a trade-off made to avoid memory issues.\n * Used storages: local && uplink (proxy_access)\n * @param {String} startkey timestamp to search from\n * @param {Object} options request options; `local=1` in the query skips the uplinks\n * @return {Stream} object stream of search results\n */\n public search(startkey: string, options: any) {\n const self = this;\n const searchStream: any = new Stream.PassThrough({ objectMode: true });\n async.eachSeries(\n Object.keys(this.uplinks),\n function (up_name, cb): void {\n // shortcut: if `local=1` is supplied, don't call uplinks\n if (options.req?.query?.local !== undefined) {\n return cb();\n }\n logger.info(`search for uplink ${up_name}`);\n // search by keyword for each uplink\n const uplinkStream = self.uplinks[up_name].search(options);\n // join uplink stream with streams PassThrough\n uplinkStream.pipe(searchStream, { end: false });\n uplinkStream.on('error', function (err): void {\n self.logger.error({ err: err }, 'uplink error: @{err.message}');\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n uplinkStream.on('end', function (): void {\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n\n searchStream.abort = function (): void {\n if (uplinkStream.abort) {\n uplinkStream.abort();\n }\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n };\n },\n // executed after all series\n function (): void {\n // attach a local search results\n const localSearchStream = self.localStorage.search(startkey, options);\n searchStream.abort = function (): void {\n localSearchStream.abort();\n };\n localSearchStream.pipe(searchStream, { end: true });\n localSearchStream.on('error', function (err: any): void {\n self.logger.error({ err: err }, 'search error: @{err.message}');\n searchStream.end();\n });\n }\n );\n\n return searchStream;\n }\n\n /**\n * Retrieve only private local packages, as the latest version of each.\n * Used storages: local (read)\n * @param {Function} callback invoked with the list of latest versions\n */\n public getLocalDatabase(callback: Callback): void {\n this.localStorage.storagePlugin.get((err, locals): void => {\n if (err) {\n return callback(err);\n }\n\n this._collectLocalPackages(locals).then(\n (packages) => callback(null, packages),\n (err) => callback(err)\n );\n });\n }\n\n /**\n * Read each local package name, apply filters, and collect the latest version.\n */\n private async _collectLocalPackages(locals: string[]): Promise<Version[]> {\n const packages: Version[] = [];\n for (const name of locals) {\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const latest = filteredPackage[DIST_TAGS]?.latest;\n if (latest && filteredPackage.versions[latest]) {\n const version: Version = filteredPackage.versions[latest];\n const timeList = filteredPackage.time as GenericBody;\n const time = timeList[latest];\n // @ts-ignore\n version.time = time;\n\n // Add for stars api\n // @ts-ignore\n version.users = filteredPackage.users;\n\n packages.push(version);\n } else {\n this.logger.warn({ package: name }, 'package @{package} does not have a \"latest\" tag?');\n }\n } catch (err) {\n this.logger.error({ err, package: name }, 'error reading package @{package}');\n }\n }\n return packages;\n }\n\n /**\n * Fetch the package metadata from every uplink with proxy access and\n * synchronize it with the local data; filter plugins are applied to the\n * merged result.\n * @param {String} name package name\n * @param {Manifest} packageInfo local manifest; MUST be provided when the package exists locally\n * @param {ISyncUplinks} options uplink request options\n * @param {Function} callback invoked with (err, mergedManifest, uplinkErrors)\n */\n public _syncUplinksMetadata(\n name: string,\n packageInfo: Manifest,\n options: ISyncUplinks,\n callback: Callback\n ): void {\n let found = true;\n const self = this;\n const upLinks: ProxyStorage[] = [];\n const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;\n\n debug('sync uplinks for %o', name);\n debug('is sync uplink enabled %o', hasToLookIntoUplinks);\n if (!packageInfo) {\n debug('local package %s not found', name);\n found = false;\n packageInfo = generatePackageTemplate(name);\n }\n\n for (const uplink in this.uplinks) {\n if (hasProxyTo(name, uplink, this.config.packages) && hasToLookIntoUplinks) {\n upLinks.push(this.uplinks[uplink]);\n }\n }\n debug('uplinks found for %o: %o', name, upLinks.length);\n\n async.map(\n upLinks,\n (upLink: ProxyStorage, cb): void => {\n const _options = Object.assign({}, options);\n const upLinkMeta = packageInfo._uplinks[upLink.upname];\n\n if (isObject(upLinkMeta)) {\n const fetched = upLinkMeta.fetched;\n\n if (fetched && Date.now() - fetched < upLink.maxage) {\n debug('returning cached manifest for %o', upLink.upname);\n return cb();\n }\n\n _options.etag = upLinkMeta.etag;\n }\n\n upLink.getRemoteMetadata(name, _options, (err, upLinkResponse, eTag): void => {\n if (err && err.remoteStatus === 304) {\n debug('uplink %o responded 304 for %o, cache is up to date', upLink.upname, name);\n upLinkMeta.fetched = Date.now();\n }\n\n if (err || !upLinkResponse) {\n debug('error captured on uplink %o for %o: %o', upLink.upname, name, err?.message);\n return cb(null, [err || ErrorCode.getInternalError('no data')]);\n }\n\n try {\n upLinkResponse = validationUtils.normalizeMetadata(upLinkResponse, name);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json validating error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n packageInfo._uplinks[upLink.upname] = {\n etag: eTag,\n fetched: Date.now(),\n };\n\n packageInfo = mergeUplinkTimeIntoLocal(packageInfo, upLinkResponse);\n\n updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);\n\n try {\n mergeVersions(packageInfo, upLinkResponse);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json parsing error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n // if we got to this point, assume that the correct package exists\n // on the uplink\n debug('syncing on uplink %o', upLink.upname);\n found = true;\n cb();\n });\n },\n // @ts-ignore\n async (err: Error, upLinksErrors: any): Promise<void> => {\n assert(!err && Array.isArray(upLinksErrors));\n\n // Check for connection timeout or reset errors with uplink(s)\n // (these should be handled differently from the package not being found)\n if (!found) {\n let uplinkTimeoutError;\n for (let i = 0; i < upLinksErrors.length; i++) {\n if (upLinksErrors[i]) {\n for (let j = 0; j < upLinksErrors[i].length; j++) {\n if (upLinksErrors[i][j]) {\n const code = upLinksErrors[i][j].code;\n if (code === 'ETIMEDOUT' || code === 'ESOCKETTIMEDOUT' || code === 'ECONNRESET') {\n uplinkTimeoutError = true;\n break;\n }\n }\n }\n }\n }\n\n if (uplinkTimeoutError) {\n debug('uplinks sync failed with timeout error');\n return callback(ErrorCode.getServiceUnavailable(), null, upLinksErrors);\n }\n debug('uplinks sync failed with no package found');\n return callback(ErrorCode.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors);\n }\n\n if (upLinks.length === 0) {\n debug('no uplinks found for %o, upstream update aborted', name);\n const { filteredPackage, filterErrors } = await self._applyFilters(\n packageInfo as Manifest\n );\n return callback(null, filteredPackage, filterErrors);\n }\n\n try {\n const packageJsonLocal = await self.localStorage.updateVersionsAsync(name, packageInfo);\n const { filteredPackage, filterErrors } = await self._applyFilters(packageJsonLocal);\n callback(null, filteredPackage, _.concat(upLinksErrors, filterErrors));\n } catch (err) {\n callback(err);\n }\n }\n );\n }\n\n /**\n * Apply all configured filter plugins to a package manifest sequentially.\n * Each filter's output is passed as input to the next filter.\n * Returns the filtered manifest and any errors that occurred.\n */\n private async _applyFilters(\n packageInfo: Manifest\n ): Promise<{ filteredPackage: Manifest; filterErrors: Error[] }> {\n const filterErrors: Error[] = [];\n let filteredPackage = packageInfo;\n for (const filter of this.filters ?? []) {\n try {\n filteredPackage = await filter.filter_metadata(filteredPackage);\n } catch (err: any) {\n debug('filter plugin has failed on %o: %o', packageInfo.name, err?.message);\n filterErrors.push(err);\n }\n }\n return { filteredPackage, filterErrors };\n }\n\n /**\n * Check if a tarball should be served based on filter plugins, using only\n * local metadata. Returns true (defer) when the version isn't cached locally\n * — the uplink-sync path in getTarball re-checks filters after sync, which\n * avoids a redundant uplink round-trip and double filter application.\n */\n private async _isTarballAllowedByFilters(name: string, filename: string): Promise<boolean> {\n if (!this.filters?.length) {\n return true;\n }\n\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n if (!hasTarball(pkgMetadata, filename)) {\n return true;\n }\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const allowed = hasTarball(filteredPackage, filename);\n if (allowed === false) {\n debug('tarball %o of %o is blocked by a filter plugin', filename, name);\n }\n return allowed;\n } catch (err: any) {\n if (err?.status === HTTP_STATUS.NOT_FOUND) {\n return true;\n }\n this.logger.error(\n { package: name, fileName: filename, err },\n 'error checking filters for tarball @{fileName} of package @{package}: @{err.message}'\n );\n return true;\n }\n }\n\n /**\n * Tag each version with the uplink it was fetched from, under a hidden\n * (symbol) key. The local storage uses the tag to record the registry\n * on the distfile records it creates.\n * @param {Versions} versions versions fetched from the uplink\n * @param {ProxyStorage} upLink uplink the versions were fetched from\n */\n public _updateVersionsHiddenUpLink(versions: Versions, upLink: ProxyStorage): void {\n for (const i in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, i)) {\n const version = versions[i];\n\n // holds a \"hidden\" value to be used by the package storage.\n version[Symbol.for('__verdaccio_uplink')] = upLink.upname;\n }\n }\n }\n}\n\nexport default Storage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,WAAA,GAAA,MAAA,QAAA,CAAmB,mBAAmB;AAE5C,IAAM,UAAN,MAAc;CACZ;CACA;CACA;CACA;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AS,GAAG;GACd;EACF,CACF;CACF;;;;;;CAOA,MAAc,cACZ,aAC+D;EAC/D,MAAM,eAAwB,CAAC;EAC/B,IAAI,kBAAkB;EACtB,KAAK,MAAM,UAAU,KAAK,WAAW,CAAC,GACpC,IAAI;GACF,kBAAkB,MAAM,OAAO,gBAAgB,eAAe;EAChE,SAAS,KAAU;GACjB,QAAM,sCAAsC,YAAY,MAAM,KAAK,OAAO;GAC1E,aAAa,KAAK,GAAG;EACvB;EAEF,OAAO;GAAE;GAAiB;EAAa;CACzC;;;;;;;CAQA,MAAc,2BAA2B,MAAc,UAAoC;EACzF,IAAI,CAAC,KAAK,SAAS,QACjB,OAAO;EAGT,IAAI;GACF,MAAM,cAAc,MAAM,KAAK,aAAa,wBAAwB,IAAI;GACxE,IAAI,CAAC,kBAAA,WAAW,aAAa,QAAQ,GACnC,OAAO;GAET,MAAM,EAAE,oBAAoB,MAAM,KAAK,cAAc,WAAW;GAChE,MAAM,UAAU,kBAAA,WAAW,iBAAiB,QAAQ;GACpD,IAAI,YAAY,OACd,QAAM,kDAAkD,UAAU,IAAI;GAExE,OAAO;EACT,SAAS,KAAU;GACjB,IAAI,KAAK,WAAW,gBAAA,YAAY,WAC9B,OAAO;GAET,KAAK,OAAO,MACV;IAAE,SAAS;IAAM,UAAU;IAAU;GAAI,GACzC,sFACF;GACA,OAAO;EACT;CACF;;;;;;;;CASA,4BAAmC,UAAoB,QAA4B;EACjF,KAAK,MAAM,KAAK,UACd,IAAI,OAAO,UAAU,eAAe,KAAK,UAAU,CAAC,GAAG;GACrD,MAAM,UAAU,SAAS;GAGzB,QAAQ,OAAO,IAAI,oBAAoB,KAAK,OAAO;EACrD;CAEJ;AACF"}
@@ -283,14 +283,14 @@ var Storage = class {
283
283
  return readStream.emit("error", err404);
284
284
  }
285
285
  debug("dist file found, using it %o", distFile.url);
286
- serveFile(distFile);
286
+ serveFile(distFile, syncInfo);
287
287
  });
288
288
  };
289
289
  self.localStorage.getPackageMetadataAsync(name).then((info) => {
290
290
  const distFile = lookupDistFile(info, filename);
291
291
  if (_.isNil(distFile) === false) {
292
292
  debug("dist file found, using it %o", distFile.url);
293
- serveFile(distFile);
293
+ serveFile(distFile, info);
294
294
  } else {
295
295
  debug("dist file not found, proceed update upstream");
296
296
  lookupFromUplinks(info);
@@ -312,26 +312,38 @@ var Storage = class {
312
312
  * Stream the tarball from the uplink serving the distfile, caching it
313
313
  * locally (and restoring the distfile record) when the uplink has the
314
314
  * cache enabled.
315
+ *
316
+ * Off-uplink URLs on a locally published package are not fetched: the
317
+ * client's `dist.tarball` is stored verbatim, and fetching it would be
318
+ * SSRF (and would attach uplink credentials when only one uplink is
319
+ * configured). Uplink-synced packages may still use an autogenerated
320
+ * proxy without credentials for CDN-hosted tarballs.
315
321
  * @param {DistFile} file distfile record resolved for the tarball
322
+ * @param {Manifest} origin package metadata the distfile was resolved from
316
323
  */
317
- function serveFile(file) {
324
+ function serveFile(file, origin) {
318
325
  let uplink = null;
326
+ const candidates = [];
327
+ for (const uplinkId in self.uplinks) if (hasProxyTo(name, uplinkId, self.config.packages)) candidates.push(self.uplinks[uplinkId]);
319
328
  if (file.registry && self.uplinks[file.registry]) {
320
- uplink = self.uplinks[file.registry];
321
- debug("tarball %o is served by the recorded uplink %o", filename, file.registry);
322
- } else {
323
- const candidates = [];
324
- for (const uplinkId in self.uplinks) if (hasProxyTo(name, uplinkId, self.config.packages)) candidates.push(self.uplinks[uplinkId]);
329
+ const recorded = self.uplinks[file.registry];
330
+ if (recorded.isUplinkValid(file.url)) {
331
+ uplink = recorded;
332
+ debug("tarball %o is served by the recorded uplink %o", filename, file.registry);
333
+ }
334
+ }
335
+ if (uplink === null) {
325
336
  debug("tarball %o has %o candidate uplinks", filename, candidates.length);
326
337
  for (const candidate of candidates) if (candidate.isUplinkValid(file.url)) uplink = candidate;
327
338
  if (uplink !== null) debug("uplink %o url matches tarball %o", uplink.upname, file.url);
328
- else if (candidates.length === 1) {
329
- uplink = candidates[0];
330
- debug("using the single configured uplink %o for tarball %o hosted elsewhere", uplink.upname, file.url);
331
- }
332
339
  }
333
340
  if (uplink == null) {
334
- debug("upstream not found, creating one for %o", name);
341
+ if (!Boolean(origin?._distfiles?.[filename])) {
342
+ debug("refusing off-uplink tarball fetch for locally published %o (%o)", name, file.url);
343
+ readStream.emit("error", ErrorCode.getNotFound(API_ERROR.NO_SUCH_FILE));
344
+ return;
345
+ }
346
+ debug("upstream not found, creating one for %o without uplink credentials", name);
335
347
  uplink = new ProxyStorage({
336
348
  url: file.url,
337
349
  cache: true,
@@ -1 +1 @@
1
- {"version":3,"file":"storage.mjs","names":[],"sources":["../../src/lib/storage.ts"],"sourcesContent":["import assert from 'assert';\nimport async from 'async';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport Stream from 'stream';\n\nimport { hasProxyTo } from '@verdaccio/config';\nimport { PLUGIN_CATEGORY, pluginUtils, validationUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabasePluginModule from '@verdaccio/local-storage-legacy';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport { ReadTarball } from '@verdaccio/streams';\nimport {\n Callback,\n Config,\n DistFile,\n Logger,\n Manifest,\n MergeTags,\n Version,\n Versions,\n} from '@verdaccio/types';\nimport { GenericBody, Token, TokenFilter } from '@verdaccio/types';\n\nimport { StoragePluginLegacy } from '../../types/custom';\nimport { logger } from '../lib/logger';\nimport { IPluginFilters, ISyncUplinks, StringValue } from '../types';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS } from './constants';\nimport LocalStorage, { StoragePlugin } from './local-storage';\nimport { mergeVersions } from './metadata-utils';\nimport {\n checkPackageLocal,\n checkPackageRemote,\n cleanUpLinksRef,\n convertAbbreviatedManifest,\n generatePackageTemplate,\n lookupDistFile,\n mergeUplinkTimeIntoLocal,\n publishPackage,\n} from './storage-utils';\nimport ProxyStorage from './up-storage';\nimport { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';\nimport { ErrorCode, hasTarball, isObject, normalizeDistTags } from './utils';\n\nconst debug = buildDebug('verdaccio:storage');\n\nclass Storage {\n public localStorage: LocalStorage;\n public config: Config;\n public logger: Logger;\n public uplinks: Record<string, ProxyStorage>;\n public filters: IPluginFilters | undefined;\n\n public constructor(config: Config) {\n this.config = config;\n this.uplinks = setupUpLinks(config);\n this.logger = logger;\n // @ts-ignore\n this.localStorage = null;\n }\n\n /**\n * Initialize the storage: load the storage plugin (or the default\n * local storage) and the filter plugins. Safe to call once; subsequent\n * calls only reload missing filters.\n * @param {Config} config verdaccio configuration\n * @param {IPluginFilters} filters preloaded filter plugins; when omitted they are loaded from the configuration\n */\n public async init(config: Config, filters?: IPluginFilters): Promise<void> {\n if (this.localStorage === null) {\n this.filters = filters;\n const storageInstance = await this.loadStorage(config, this.logger);\n this.localStorage = new LocalStorage(this.config, logger, storageInstance);\n await this.localStorage.getSecret(config);\n debug('initialization completed');\n } else {\n debug('storage has been already initialized');\n }\n\n if (!this.filters) {\n this.filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n this.config.filters,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin: pluginUtils.ManifestFilter<Config>) => {\n return typeof plugin.filter_metadata !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', this.filters.length);\n }\n }\n\n /**\n * Resolve the storage backend: a configured storage plugin when available,\n * otherwise the default `@verdaccio/local-storage` on the configured path.\n * @return {Promise<StoragePlugin>} the storage plugin instance\n */\n private async loadStorage(config: Config, logger: Logger): Promise<StoragePlugin> {\n const Storage = await this.loadStorePlugin();\n if (_.isNil(Storage)) {\n assert(this.config.storage, 'CONFIG: storage path not defined');\n debug('no custom storage found, loading default storage @verdaccio/local-storage');\n // the package is CJS with an `exports.default`; in the ESM build the default\n // import is the whole `module.exports`, so unwrap `.default` when present\n const LocalDatabasePlugin =\n (LocalDatabasePluginModule as unknown as { default?: typeof LocalDatabasePluginModule })\n .default ?? LocalDatabasePluginModule;\n const localStorage = new LocalDatabasePlugin(config, logger);\n logger.info(\n { name: '@verdaccio/local-storage', pluginCategory: PLUGIN_CATEGORY.STORAGE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n return localStorage;\n }\n return Storage as StoragePlugin;\n }\n\n /**\n * Load the storage plugins declared under `store` in the configuration.\n * Only one storage is supported: with several plugins configured the\n * first loaded one wins and a warning is logged.\n * @return {Promise<StoragePluginLegacy<Config> | undefined>} the selected plugin, or undefined when none is configured\n */\n private async loadStorePlugin(): Promise<StoragePluginLegacy<Config> | undefined> {\n const plugins: StoragePluginLegacy<Config>[] = await asyncLoadPlugin<\n pluginUtils.Storage<unknown>\n >(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin) => {\n return typeof plugin.getPackageStorage !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.STORAGE\n );\n\n if (plugins.length > 1) {\n this.logger.warn(\n 'more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically'\n );\n }\n\n return _.head(plugins);\n }\n\n /**\n * Add a package to the system (publish flow).\n * Verifies the package does not exist locally nor on any uplink before\n * creating it locally; uplinks being offline rejects the publish unless\n * `publish.allow_offline` is enabled.\n * Used storages: local (write) && uplinks\n * @param {String} name package name\n * @param {Object} metadata package manifest to publish\n * @param {Function} callback invoked with an error when the publish is rejected\n */\n public async addPackage(name: string, metadata: any, callback: any): Promise<void> {\n debug('add package %o', name);\n try {\n await checkPackageLocal(name, this.localStorage);\n await checkPackageRemote(\n name,\n this._isAllowPublishOffline(),\n this._syncUplinksMetadata.bind(this)\n );\n await publishPackage(name, metadata, this.localStorage);\n callback();\n } catch (err: any) {\n callback(err);\n }\n }\n\n /**\n * Whether `publish.allow_offline` is enabled in the configuration.\n * @return {Boolean} true when publishing with unreachable uplinks is allowed\n */\n private _isAllowPublishOffline(): boolean {\n return (\n typeof this.config.publish !== 'undefined' &&\n _.isBoolean(this.config.publish.allow_offline) &&\n this.config.publish.allow_offline\n );\n }\n\n /**\n * Read the npm tokens matching the filter from the token storage.\n * Used storages: local (read)\n */\n public readTokens(filter: TokenFilter): Promise<Token[]> {\n return this.localStorage.readTokens(filter);\n }\n\n /**\n * Save an npm token to the token storage.\n * Used storages: local (write)\n */\n public saveToken(token: Token): Promise<void> {\n return this.localStorage.saveToken(token);\n }\n\n /**\n * Delete an npm token from the token storage.\n * Used storages: local (write)\n */\n public deleteToken(user: string, tokenKey: string): Promise<any> {\n return this.localStorage.deleteToken(user, tokenKey);\n }\n\n /**\n * Add a new version of a package to the system.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} version version id, eg. 1.0.0\n * @param {Version} metadata version metadata\n * @param {String} tag dist-tag pointing to the version\n * @param {Function} callback\n */\n public addVersion(\n name: string,\n version: string,\n metadata: Version,\n tag: StringValue,\n callback: Callback\n ): void {\n debug('add version %s package for %s', version, name);\n this.localStorage.addVersion(name, version, metadata, tag, callback);\n }\n\n /**\n * Tag package versions with the provided dist-tags.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {MergeTags} tagHash dist-tag to version mapping to merge\n * @param {Function} callback\n */\n public mergeTags(name: string, tagHash: MergeTags, callback: Callback): void {\n debug('merge tags for %o', name);\n this.localStorage.mergeTags(name, tagHash, callback);\n }\n\n /**\n * Change an existing package (eg. unpublish one version).\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Manifest} metadata updated package manifest\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public changePackage(\n name: string,\n metadata: Manifest,\n revision: string,\n callback: Callback\n ): void {\n debug('change existing package for package %o revision %o', name, revision);\n this.localStorage.changePackage(name, metadata, revision, callback);\n }\n\n /**\n * Remove a package from the local storage and the search indexer.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Function} callback\n */\n public removePackage(name: string, callback: Callback): void {\n debug('remove package %o', name);\n this.localStorage.removePackage(name, callback);\n // update the indexer\n SearchMemoryIndexer.remove(name).catch((reason) => {\n debug('indexer has failed on remove item %o', reason);\n logger.error('indexer has failed on remove item');\n });\n }\n\n /**\n * Remove a tarball from the local storage. The tarball must not be\n * linked by any existing version, ie. the version should be\n * unpublished first.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public removeTarball(name: string, filename: string, revision: string, callback: Callback): void {\n debug('remove tarball %s for %s', filename, name);\n this.localStorage.removeTarball(name, filename, revision, callback);\n }\n\n /**\n * Upload a tarball (publish flow). Synchronous, returns a writable\n * stream the tarball body is piped into.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} writable upload stream\n */\n public addTarball(name: string, filename: string) {\n debug('add a tarball for %o', name);\n return this.localStorage.addTarball(name, filename);\n }\n\n /**\n * Whether a tarball exists in the local storage, without reading it\n * (the stream is aborted as soon as it opens).\n * Used storages: local (read)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Promise<Boolean>} true when the tarball is stored locally\n */\n public hasLocalTarball(name: string, filename: string): Promise<boolean> {\n const self = this;\n return new Promise<boolean>((resolve, reject): void => {\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n reject(err);\n }\n // local reported 404 or request was aborted already\n if (localStream) {\n localStream.abort();\n localStream = null;\n }\n resolve(false);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.abort();\n localStream = null;\n resolve(true);\n });\n });\n }\n\n /**\n * Get a tarball. Synchronous, returns a readable stream.\n * The tarball is read locally first; on a local miss the distfile record\n * is resolved from the package metadata (see lookupDistFile), syncing the\n * uplinks when the local metadata does not know the file, and the tarball\n * is then fetched from the uplink that serves the distfile url.\n * Used storages: local || uplink (just one)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} readable tarball stream\n */\n public getTarball(name: string, filename: string) {\n debug('get tarball for package %o filename %o', name, filename);\n const readStream = new ReadTarball({});\n readStream.abort = function () {};\n\n const self = this;\n\n // Check if the tarball is allowed by filter plugins before serving.\n // Filters may block specific versions, so we verify the tarball's version\n // still exists in the filtered metadata.\n this._isTarballAllowedByFilters(name, filename).then(async (allowed) => {\n if (!allowed) {\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_PACKAGE));\n return;\n }\n\n // trying local first\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n return readStream.emit('error', err);\n }\n\n // local reported 404\n const err404 = err;\n localStream.abort();\n localStream = null; // we force for garbage collector\n\n const lookupFromUplinks = (info: Manifest | null): void => {\n self._syncUplinksMetadata(\n name,\n info as Manifest,\n {},\n (syncErr, syncInfo: Manifest): any => {\n if (_.isNil(syncErr) === false) {\n return readStream.emit('error', syncErr);\n }\n // _syncUplinksMetadata returns filter-applied metadata; if the\n // version was removed by a filter, surface a 404 like a missing tarball.\n if (self.filters?.length && !hasTarball(syncInfo, filename)) {\n return readStream.emit('error', err404);\n }\n const distFile = lookupDistFile(syncInfo, filename);\n if (_.isNil(distFile)) {\n debug('remote tarball not found');\n return readStream.emit('error', err404);\n }\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile);\n }\n );\n };\n\n self.localStorage.getPackageMetadataAsync(name).then(\n (info) => {\n const distFile = lookupDistFile(info, filename);\n if (_.isNil(distFile) === false) {\n // information about this file exists locally\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile);\n } else {\n // we know nothing about this file, trying to get information elsewhere\n debug('dist file not found, proceed update upstream');\n lookupFromUplinks(info);\n }\n },\n () => {\n // we know nothing about this file, trying to get information elsewhere\n lookupFromUplinks(null);\n }\n );\n });\n localStream.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.pipe(readStream);\n });\n });\n\n return readStream;\n\n /**\n * Stream the tarball from the uplink serving the distfile, caching it\n * locally (and restoring the distfile record) when the uplink has the\n * cache enabled.\n * @param {DistFile} file distfile record resolved for the tarball\n */\n function serveFile(file: DistFile): void {\n let uplink: any = null;\n\n if (file.registry && self.uplinks[file.registry]) {\n // the distfile records which uplink it was merged from\n // (see LocalStorage._updateUplinkToRemoteProtocol)\n uplink = self.uplinks[file.registry];\n debug('tarball %o is served by the recorded uplink %o', filename, file.registry);\n } else {\n const candidates: any[] = [];\n for (const uplinkId in self.uplinks) {\n if (hasProxyTo(name, uplinkId, self.config.packages)) {\n candidates.push(self.uplinks[uplinkId]);\n }\n }\n debug('tarball %o has %o candidate uplinks', filename, candidates.length);\n\n // pick the uplink that actually serves the distfile url, so the\n // request carries the settings of the registry hosting it; with\n // several matching uplinks (duplicated urls) the last configured\n // one keeps winning, exactly like the previous selection did\n for (const candidate of candidates) {\n if (candidate.isUplinkValid(file.url)) {\n uplink = candidate;\n }\n }\n\n if (uplink !== null) {\n debug('uplink %o url matches tarball %o', uplink.upname, file.url);\n } else if (candidates.length === 1) {\n // a single configured uplink keeps the legacy behavior: tarballs\n // hosted elsewhere (a CDN) may still need its agent/proxy settings\n uplink = candidates[0];\n debug(\n 'using the single configured uplink %o for tarball %o hosted elsewhere',\n uplink.upname,\n file.url\n );\n }\n }\n\n if (uplink == null) {\n debug('upstream not found, creating one for %o', name);\n uplink = new ProxyStorage(\n {\n url: file.url,\n cache: true,\n _autogenerated: true,\n },\n self.config\n );\n }\n\n let savestream: any = null;\n if (uplink.config.cache) {\n // persist which configured uplink served the tarball, so future\n // fetches can pick it directly (autogenerated proxies have no name)\n debug('cache remote tarball enabled');\n let distFile: DistFile = file;\n if (!file.registry && uplink.upname) {\n debug('recording uplink %o on the persisted distfile for %o', uplink.upname, filename);\n distFile = { ...file, registry: uplink.upname };\n }\n savestream = self.localStorage.addTarball(name, filename, distFile);\n } else {\n debug('cache remote tarball disabled');\n }\n\n let on_open = function (): void {\n // prevent it from being called twice\n on_open = function () {};\n const rstream2 = uplink.fetchTarball(file.url);\n rstream2.on('error', function (err): void {\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n readStream.emit('error', err);\n });\n rstream2.on('end', function (): void {\n if (savestream) {\n savestream.done();\n }\n });\n\n rstream2.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n if (savestream) {\n savestream.emit('content-length', v);\n }\n });\n rstream2.pipe(readStream);\n if (savestream) {\n rstream2.pipe(savestream);\n }\n };\n\n if (savestream) {\n savestream.on('open', function (): void {\n on_open();\n });\n\n savestream.on('error', function (err): void {\n self.logger.warn(\n { err: err, fileName: file },\n 'error saving file @{fileName}: @{err.message}\\n@{err.stack}'\n );\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n on_open();\n });\n } else {\n on_open();\n }\n }\n }\n\n /**\n * Retrieve the package metadata: the local manifest merged with the\n * manifest of every uplink with proxy access to the package.\n * Used storages: local && uplink (proxy_access)\n * @param {Object} options\n * @property {String} options.name package name\n * @property {Object} options.req Express `req` object\n * @property {Boolean} options.keepUpLinkData keep the uplink info (last update, etc.) in the package metadata\n * @property {Boolean} options.abbreviated serve the abbreviated manifest (npm install)\n * @property {Function} options.callback invoked with the merged manifest and any uplink errors\n */\n public getPackage(options): void {\n debug('get package for %o', options.name);\n this.localStorage.getPackageMetadata(options.name, (err, data): void => {\n if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {\n // report internal errors right away\n return options.callback(err);\n }\n\n this._syncUplinksMetadata(\n options.name,\n data,\n { req: options.req, uplinksLook: options.uplinksLook },\n function getPackageSynUpLinksCallback(err, result: Manifest, uplinkErrors): void {\n if (err) {\n return options.callback(err);\n }\n\n normalizeDistTags(cleanUpLinksRef(options.keepUpLinkData, result));\n\n // npm can throw if this field doesn't exist\n result._attachments = {};\n if (options.abbreviated === true) {\n debug('get abbreviated manifest');\n options.callback(null, convertAbbreviatedManifest(result), uplinkErrors);\n } else {\n debug('get full package manifest');\n options.callback(null, result, uplinkErrors);\n }\n }\n );\n });\n }\n\n /**\n * Retrieve remote and local packages more recent than the start key.\n * All uplinks are streamed first, then the local packages; local\n * packages can override registry ones just because they appear in the\n * JSON last — a trade-off made to avoid memory issues.\n * Used storages: local && uplink (proxy_access)\n * @param {String} startkey timestamp to search from\n * @param {Object} options request options; `local=1` in the query skips the uplinks\n * @return {Stream} object stream of search results\n */\n public search(startkey: string, options: any) {\n const self = this;\n const searchStream: any = new Stream.PassThrough({ objectMode: true });\n async.eachSeries(\n Object.keys(this.uplinks),\n function (up_name, cb): void {\n // shortcut: if `local=1` is supplied, don't call uplinks\n if (options.req?.query?.local !== undefined) {\n return cb();\n }\n logger.info(`search for uplink ${up_name}`);\n // search by keyword for each uplink\n const uplinkStream = self.uplinks[up_name].search(options);\n // join uplink stream with streams PassThrough\n uplinkStream.pipe(searchStream, { end: false });\n uplinkStream.on('error', function (err): void {\n self.logger.error({ err: err }, 'uplink error: @{err.message}');\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n uplinkStream.on('end', function (): void {\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n\n searchStream.abort = function (): void {\n if (uplinkStream.abort) {\n uplinkStream.abort();\n }\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n };\n },\n // executed after all series\n function (): void {\n // attach a local search results\n const localSearchStream = self.localStorage.search(startkey, options);\n searchStream.abort = function (): void {\n localSearchStream.abort();\n };\n localSearchStream.pipe(searchStream, { end: true });\n localSearchStream.on('error', function (err: any): void {\n self.logger.error({ err: err }, 'search error: @{err.message}');\n searchStream.end();\n });\n }\n );\n\n return searchStream;\n }\n\n /**\n * Retrieve only private local packages, as the latest version of each.\n * Used storages: local (read)\n * @param {Function} callback invoked with the list of latest versions\n */\n public getLocalDatabase(callback: Callback): void {\n this.localStorage.storagePlugin.get((err, locals): void => {\n if (err) {\n return callback(err);\n }\n\n this._collectLocalPackages(locals).then(\n (packages) => callback(null, packages),\n (err) => callback(err)\n );\n });\n }\n\n /**\n * Read each local package name, apply filters, and collect the latest version.\n */\n private async _collectLocalPackages(locals: string[]): Promise<Version[]> {\n const packages: Version[] = [];\n for (const name of locals) {\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const latest = filteredPackage[DIST_TAGS]?.latest;\n if (latest && filteredPackage.versions[latest]) {\n const version: Version = filteredPackage.versions[latest];\n const timeList = filteredPackage.time as GenericBody;\n const time = timeList[latest];\n // @ts-ignore\n version.time = time;\n\n // Add for stars api\n // @ts-ignore\n version.users = filteredPackage.users;\n\n packages.push(version);\n } else {\n this.logger.warn({ package: name }, 'package @{package} does not have a \"latest\" tag?');\n }\n } catch (err) {\n this.logger.error({ err, package: name }, 'error reading package @{package}');\n }\n }\n return packages;\n }\n\n /**\n * Fetch the package metadata from every uplink with proxy access and\n * synchronize it with the local data; filter plugins are applied to the\n * merged result.\n * @param {String} name package name\n * @param {Manifest} packageInfo local manifest; MUST be provided when the package exists locally\n * @param {ISyncUplinks} options uplink request options\n * @param {Function} callback invoked with (err, mergedManifest, uplinkErrors)\n */\n public _syncUplinksMetadata(\n name: string,\n packageInfo: Manifest,\n options: ISyncUplinks,\n callback: Callback\n ): void {\n let found = true;\n const self = this;\n const upLinks: ProxyStorage[] = [];\n const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;\n\n debug('sync uplinks for %o', name);\n debug('is sync uplink enabled %o', hasToLookIntoUplinks);\n if (!packageInfo) {\n debug('local package %s not found', name);\n found = false;\n packageInfo = generatePackageTemplate(name);\n }\n\n for (const uplink in this.uplinks) {\n if (hasProxyTo(name, uplink, this.config.packages) && hasToLookIntoUplinks) {\n upLinks.push(this.uplinks[uplink]);\n }\n }\n debug('uplinks found for %o: %o', name, upLinks.length);\n\n async.map(\n upLinks,\n (upLink: ProxyStorage, cb): void => {\n const _options = Object.assign({}, options);\n const upLinkMeta = packageInfo._uplinks[upLink.upname];\n\n if (isObject(upLinkMeta)) {\n const fetched = upLinkMeta.fetched;\n\n if (fetched && Date.now() - fetched < upLink.maxage) {\n debug('returning cached manifest for %o', upLink.upname);\n return cb();\n }\n\n _options.etag = upLinkMeta.etag;\n }\n\n upLink.getRemoteMetadata(name, _options, (err, upLinkResponse, eTag): void => {\n if (err && err.remoteStatus === 304) {\n debug('uplink %o responded 304 for %o, cache is up to date', upLink.upname, name);\n upLinkMeta.fetched = Date.now();\n }\n\n if (err || !upLinkResponse) {\n debug('error captured on uplink %o for %o: %o', upLink.upname, name, err?.message);\n return cb(null, [err || ErrorCode.getInternalError('no data')]);\n }\n\n try {\n upLinkResponse = validationUtils.normalizeMetadata(upLinkResponse, name);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json validating error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n packageInfo._uplinks[upLink.upname] = {\n etag: eTag,\n fetched: Date.now(),\n };\n\n packageInfo = mergeUplinkTimeIntoLocal(packageInfo, upLinkResponse);\n\n updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);\n\n try {\n mergeVersions(packageInfo, upLinkResponse);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json parsing error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n // if we got to this point, assume that the correct package exists\n // on the uplink\n debug('syncing on uplink %o', upLink.upname);\n found = true;\n cb();\n });\n },\n // @ts-ignore\n async (err: Error, upLinksErrors: any): Promise<void> => {\n assert(!err && Array.isArray(upLinksErrors));\n\n // Check for connection timeout or reset errors with uplink(s)\n // (these should be handled differently from the package not being found)\n if (!found) {\n let uplinkTimeoutError;\n for (let i = 0; i < upLinksErrors.length; i++) {\n if (upLinksErrors[i]) {\n for (let j = 0; j < upLinksErrors[i].length; j++) {\n if (upLinksErrors[i][j]) {\n const code = upLinksErrors[i][j].code;\n if (code === 'ETIMEDOUT' || code === 'ESOCKETTIMEDOUT' || code === 'ECONNRESET') {\n uplinkTimeoutError = true;\n break;\n }\n }\n }\n }\n }\n\n if (uplinkTimeoutError) {\n debug('uplinks sync failed with timeout error');\n return callback(ErrorCode.getServiceUnavailable(), null, upLinksErrors);\n }\n debug('uplinks sync failed with no package found');\n return callback(ErrorCode.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors);\n }\n\n if (upLinks.length === 0) {\n debug('no uplinks found for %o, upstream update aborted', name);\n const { filteredPackage, filterErrors } = await self._applyFilters(\n packageInfo as Manifest\n );\n return callback(null, filteredPackage, filterErrors);\n }\n\n try {\n const packageJsonLocal = await self.localStorage.updateVersionsAsync(name, packageInfo);\n const { filteredPackage, filterErrors } = await self._applyFilters(packageJsonLocal);\n callback(null, filteredPackage, _.concat(upLinksErrors, filterErrors));\n } catch (err) {\n callback(err);\n }\n }\n );\n }\n\n /**\n * Apply all configured filter plugins to a package manifest sequentially.\n * Each filter's output is passed as input to the next filter.\n * Returns the filtered manifest and any errors that occurred.\n */\n private async _applyFilters(\n packageInfo: Manifest\n ): Promise<{ filteredPackage: Manifest; filterErrors: Error[] }> {\n const filterErrors: Error[] = [];\n let filteredPackage = packageInfo;\n for (const filter of this.filters ?? []) {\n try {\n filteredPackage = await filter.filter_metadata(filteredPackage);\n } catch (err: any) {\n debug('filter plugin has failed on %o: %o', packageInfo.name, err?.message);\n filterErrors.push(err);\n }\n }\n return { filteredPackage, filterErrors };\n }\n\n /**\n * Check if a tarball should be served based on filter plugins, using only\n * local metadata. Returns true (defer) when the version isn't cached locally\n * — the uplink-sync path in getTarball re-checks filters after sync, which\n * avoids a redundant uplink round-trip and double filter application.\n */\n private async _isTarballAllowedByFilters(name: string, filename: string): Promise<boolean> {\n if (!this.filters?.length) {\n return true;\n }\n\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n if (!hasTarball(pkgMetadata, filename)) {\n return true;\n }\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const allowed = hasTarball(filteredPackage, filename);\n if (allowed === false) {\n debug('tarball %o of %o is blocked by a filter plugin', filename, name);\n }\n return allowed;\n } catch (err: any) {\n if (err?.status === HTTP_STATUS.NOT_FOUND) {\n return true;\n }\n this.logger.error(\n { package: name, fileName: filename, err },\n 'error checking filters for tarball @{fileName} of package @{package}: @{err.message}'\n );\n return true;\n }\n }\n\n /**\n * Tag each version with the uplink it was fetched from, under a hidden\n * (symbol) key. The local storage uses the tag to record the registry\n * on the distfile records it creates.\n * @param {Versions} versions versions fetched from the uplink\n * @param {ProxyStorage} upLink uplink the versions were fetched from\n */\n public _updateVersionsHiddenUpLink(versions: Versions, upLink: ProxyStorage): void {\n for (const i in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, i)) {\n const version = versions[i];\n\n // holds a \"hidden\" value to be used by the package storage.\n version[Symbol.for('__verdaccio_uplink')] = upLink.upname;\n }\n }\n }\n}\n\nexport default Storage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,QAAQ,YAAW,mBAAmB;AAE5C,IAAM,UAAN,MAAc;CACZ;CACA;CACA;CACA;CACA;CAEA,YAAmB,QAAgB;EACjC,KAAK,SAAS;EACd,KAAK,UAAU,aAAa,MAAM;EAClC,KAAK,SAAS;EAEd,KAAK,eAAe;CACtB;;;;;;;;CASA,MAAa,KAAK,QAAgB,SAAyC;EACzE,IAAI,KAAK,iBAAiB,MAAM;GAC9B,KAAK,UAAU;GACf,MAAM,kBAAkB,MAAM,KAAK,YAAY,QAAQ,KAAK,MAAM;GAClE,KAAK,eAAe,IAAI,aAAa,KAAK,QAAQ,QAAQ,eAAe;GACzE,MAAM,KAAK,aAAa,UAAU,MAAM;GACxC,MAAM,0BAA0B;EAClC,OACE,MAAM,sCAAsC;EAG9C,IAAI,CAAC,KAAK,SAAS;GACjB,KAAK,UAAU,MAAM,gBACnB,KAAK,OAAO,SACZ;IACE,QAAQ,KAAK;IACb,QAAQ,KAAK;GACf,IACC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OAAO,eAAe,YAAY,CAAC;GACvE,SAAS,KAAK;IACZ,SAAS,GAAG;GACd;EACF,CACF;CACF;;;;;;CAOA,MAAc,cACZ,aAC+D;EAC/D,MAAM,eAAwB,CAAC;EAC/B,IAAI,kBAAkB;EACtB,KAAK,MAAM,UAAU,KAAK,WAAW,CAAC,GACpC,IAAI;GACF,kBAAkB,MAAM,OAAO,gBAAgB,eAAe;EAChE,SAAS,KAAU;GACjB,MAAM,sCAAsC,YAAY,MAAM,KAAK,OAAO;GAC1E,aAAa,KAAK,GAAG;EACvB;EAEF,OAAO;GAAE;GAAiB;EAAa;CACzC;;;;;;;CAQA,MAAc,2BAA2B,MAAc,UAAoC;EACzF,IAAI,CAAC,KAAK,SAAS,QACjB,OAAO;EAGT,IAAI;GACF,MAAM,cAAc,MAAM,KAAK,aAAa,wBAAwB,IAAI;GACxE,IAAI,CAAC,WAAW,aAAa,QAAQ,GACnC,OAAO;GAET,MAAM,EAAE,oBAAoB,MAAM,KAAK,cAAc,WAAW;GAChE,MAAM,UAAU,WAAW,iBAAiB,QAAQ;GACpD,IAAI,YAAY,OACd,MAAM,kDAAkD,UAAU,IAAI;GAExE,OAAO;EACT,SAAS,KAAU;GACjB,IAAI,KAAK,WAAW,YAAY,WAC9B,OAAO;GAET,KAAK,OAAO,MACV;IAAE,SAAS;IAAM,UAAU;IAAU;GAAI,GACzC,sFACF;GACA,OAAO;EACT;CACF;;;;;;;;CASA,4BAAmC,UAAoB,QAA4B;EACjF,KAAK,MAAM,KAAK,UACd,IAAI,OAAO,UAAU,eAAe,KAAK,UAAU,CAAC,GAAG;GACrD,MAAM,UAAU,SAAS;GAGzB,QAAQ,OAAO,IAAI,oBAAoB,KAAK,OAAO;EACrD;CAEJ;AACF"}
1
+ {"version":3,"file":"storage.mjs","names":[],"sources":["../../src/lib/storage.ts"],"sourcesContent":["import assert from 'assert';\nimport async from 'async';\nimport buildDebug from 'debug';\nimport _ from 'lodash';\nimport Stream from 'stream';\n\nimport { hasProxyTo } from '@verdaccio/config';\nimport { PLUGIN_CATEGORY, pluginUtils, validationUtils } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabasePluginModule from '@verdaccio/local-storage-legacy';\nimport { SearchMemoryIndexer } from '@verdaccio/search-indexer';\nimport { ReadTarball } from '@verdaccio/streams';\nimport {\n Callback,\n Config,\n DistFile,\n Logger,\n Manifest,\n MergeTags,\n Version,\n Versions,\n} from '@verdaccio/types';\nimport { GenericBody, Token, TokenFilter } from '@verdaccio/types';\n\nimport { StoragePluginLegacy } from '../../types/custom';\nimport { logger } from '../lib/logger';\nimport { IPluginFilters, ISyncUplinks, StringValue } from '../types';\nimport { API_ERROR, DIST_TAGS, HTTP_STATUS } from './constants';\nimport LocalStorage, { StoragePlugin } from './local-storage';\nimport { mergeVersions } from './metadata-utils';\nimport {\n checkPackageLocal,\n checkPackageRemote,\n cleanUpLinksRef,\n convertAbbreviatedManifest,\n generatePackageTemplate,\n lookupDistFile,\n mergeUplinkTimeIntoLocal,\n publishPackage,\n} from './storage-utils';\nimport ProxyStorage from './up-storage';\nimport { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';\nimport { ErrorCode, hasTarball, isObject, normalizeDistTags } from './utils';\n\nconst debug = buildDebug('verdaccio:storage');\n\nclass Storage {\n public localStorage: LocalStorage;\n public config: Config;\n public logger: Logger;\n public uplinks: Record<string, ProxyStorage>;\n public filters: IPluginFilters | undefined;\n\n public constructor(config: Config) {\n this.config = config;\n this.uplinks = setupUpLinks(config);\n this.logger = logger;\n // @ts-ignore\n this.localStorage = null;\n }\n\n /**\n * Initialize the storage: load the storage plugin (or the default\n * local storage) and the filter plugins. Safe to call once; subsequent\n * calls only reload missing filters.\n * @param {Config} config verdaccio configuration\n * @param {IPluginFilters} filters preloaded filter plugins; when omitted they are loaded from the configuration\n */\n public async init(config: Config, filters?: IPluginFilters): Promise<void> {\n if (this.localStorage === null) {\n this.filters = filters;\n const storageInstance = await this.loadStorage(config, this.logger);\n this.localStorage = new LocalStorage(this.config, logger, storageInstance);\n await this.localStorage.getSecret(config);\n debug('initialization completed');\n } else {\n debug('storage has been already initialized');\n }\n\n if (!this.filters) {\n this.filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n this.config.filters,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin: pluginUtils.ManifestFilter<Config>) => {\n return typeof plugin.filter_metadata !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', this.filters.length);\n }\n }\n\n /**\n * Resolve the storage backend: a configured storage plugin when available,\n * otherwise the default `@verdaccio/local-storage` on the configured path.\n * @return {Promise<StoragePlugin>} the storage plugin instance\n */\n private async loadStorage(config: Config, logger: Logger): Promise<StoragePlugin> {\n const Storage = await this.loadStorePlugin();\n if (_.isNil(Storage)) {\n assert(this.config.storage, 'CONFIG: storage path not defined');\n debug('no custom storage found, loading default storage @verdaccio/local-storage');\n // the package is CJS with an `exports.default`; in the ESM build the default\n // import is the whole `module.exports`, so unwrap `.default` when present\n const LocalDatabasePlugin =\n (LocalDatabasePluginModule as unknown as { default?: typeof LocalDatabasePluginModule })\n .default ?? LocalDatabasePluginModule;\n const localStorage = new LocalDatabasePlugin(config, logger);\n logger.info(\n { name: '@verdaccio/local-storage', pluginCategory: PLUGIN_CATEGORY.STORAGE },\n 'plugin @{name} successfully loaded (@{pluginCategory})'\n );\n return localStorage;\n }\n return Storage as StoragePlugin;\n }\n\n /**\n * Load the storage plugins declared under `store` in the configuration.\n * Only one storage is supported: with several plugins configured the\n * first loaded one wins and a warning is logged.\n * @return {Promise<StoragePluginLegacy<Config> | undefined>} the selected plugin, or undefined when none is configured\n */\n private async loadStorePlugin(): Promise<StoragePluginLegacy<Config> | undefined> {\n const plugins: StoragePluginLegacy<Config>[] = await asyncLoadPlugin<\n pluginUtils.Storage<unknown>\n >(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n (plugin) => {\n return typeof plugin.getPackageStorage !== 'undefined';\n },\n true,\n this.config?.serverSettings?.pluginPrefix,\n PLUGIN_CATEGORY.STORAGE\n );\n\n if (plugins.length > 1) {\n this.logger.warn(\n 'more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically'\n );\n }\n\n return _.head(plugins);\n }\n\n /**\n * Add a package to the system (publish flow).\n * Verifies the package does not exist locally nor on any uplink before\n * creating it locally; uplinks being offline rejects the publish unless\n * `publish.allow_offline` is enabled.\n * Used storages: local (write) && uplinks\n * @param {String} name package name\n * @param {Object} metadata package manifest to publish\n * @param {Function} callback invoked with an error when the publish is rejected\n */\n public async addPackage(name: string, metadata: any, callback: any): Promise<void> {\n debug('add package %o', name);\n try {\n await checkPackageLocal(name, this.localStorage);\n await checkPackageRemote(\n name,\n this._isAllowPublishOffline(),\n this._syncUplinksMetadata.bind(this)\n );\n await publishPackage(name, metadata, this.localStorage);\n callback();\n } catch (err: any) {\n callback(err);\n }\n }\n\n /**\n * Whether `publish.allow_offline` is enabled in the configuration.\n * @return {Boolean} true when publishing with unreachable uplinks is allowed\n */\n private _isAllowPublishOffline(): boolean {\n return (\n typeof this.config.publish !== 'undefined' &&\n _.isBoolean(this.config.publish.allow_offline) &&\n this.config.publish.allow_offline\n );\n }\n\n /**\n * Read the npm tokens matching the filter from the token storage.\n * Used storages: local (read)\n */\n public readTokens(filter: TokenFilter): Promise<Token[]> {\n return this.localStorage.readTokens(filter);\n }\n\n /**\n * Save an npm token to the token storage.\n * Used storages: local (write)\n */\n public saveToken(token: Token): Promise<void> {\n return this.localStorage.saveToken(token);\n }\n\n /**\n * Delete an npm token from the token storage.\n * Used storages: local (write)\n */\n public deleteToken(user: string, tokenKey: string): Promise<any> {\n return this.localStorage.deleteToken(user, tokenKey);\n }\n\n /**\n * Add a new version of a package to the system.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} version version id, eg. 1.0.0\n * @param {Version} metadata version metadata\n * @param {String} tag dist-tag pointing to the version\n * @param {Function} callback\n */\n public addVersion(\n name: string,\n version: string,\n metadata: Version,\n tag: StringValue,\n callback: Callback\n ): void {\n debug('add version %s package for %s', version, name);\n this.localStorage.addVersion(name, version, metadata, tag, callback);\n }\n\n /**\n * Tag package versions with the provided dist-tags.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {MergeTags} tagHash dist-tag to version mapping to merge\n * @param {Function} callback\n */\n public mergeTags(name: string, tagHash: MergeTags, callback: Callback): void {\n debug('merge tags for %o', name);\n this.localStorage.mergeTags(name, tagHash, callback);\n }\n\n /**\n * Change an existing package (eg. unpublish one version).\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Manifest} metadata updated package manifest\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public changePackage(\n name: string,\n metadata: Manifest,\n revision: string,\n callback: Callback\n ): void {\n debug('change existing package for package %o revision %o', name, revision);\n this.localStorage.changePackage(name, metadata, revision, callback);\n }\n\n /**\n * Remove a package from the local storage and the search indexer.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {Function} callback\n */\n public removePackage(name: string, callback: Callback): void {\n debug('remove package %o', name);\n this.localStorage.removePackage(name, callback);\n // update the indexer\n SearchMemoryIndexer.remove(name).catch((reason) => {\n debug('indexer has failed on remove item %o', reason);\n logger.error('indexer has failed on remove item');\n });\n }\n\n /**\n * Remove a tarball from the local storage. The tarball must not be\n * linked by any existing version, ie. the version should be\n * unpublished first.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @param {String} revision expected revision of the stored manifest\n * @param {Function} callback\n */\n public removeTarball(name: string, filename: string, revision: string, callback: Callback): void {\n debug('remove tarball %s for %s', filename, name);\n this.localStorage.removeTarball(name, filename, revision, callback);\n }\n\n /**\n * Upload a tarball (publish flow). Synchronous, returns a writable\n * stream the tarball body is piped into.\n * Used storages: local (write)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} writable upload stream\n */\n public addTarball(name: string, filename: string) {\n debug('add a tarball for %o', name);\n return this.localStorage.addTarball(name, filename);\n }\n\n /**\n * Whether a tarball exists in the local storage, without reading it\n * (the stream is aborted as soon as it opens).\n * Used storages: local (read)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Promise<Boolean>} true when the tarball is stored locally\n */\n public hasLocalTarball(name: string, filename: string): Promise<boolean> {\n const self = this;\n return new Promise<boolean>((resolve, reject): void => {\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n reject(err);\n }\n // local reported 404 or request was aborted already\n if (localStream) {\n localStream.abort();\n localStream = null;\n }\n resolve(false);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.abort();\n localStream = null;\n resolve(true);\n });\n });\n }\n\n /**\n * Get a tarball. Synchronous, returns a readable stream.\n * The tarball is read locally first; on a local miss the distfile record\n * is resolved from the package metadata (see lookupDistFile), syncing the\n * uplinks when the local metadata does not know the file, and the tarball\n * is then fetched from the uplink that serves the distfile url.\n * Used storages: local || uplink (just one)\n * @param {String} name package name\n * @param {String} filename tarball file name\n * @return {Stream} readable tarball stream\n */\n public getTarball(name: string, filename: string) {\n debug('get tarball for package %o filename %o', name, filename);\n const readStream = new ReadTarball({});\n readStream.abort = function () {};\n\n const self = this;\n\n // Check if the tarball is allowed by filter plugins before serving.\n // Filters may block specific versions, so we verify the tarball's version\n // still exists in the filtered metadata.\n this._isTarballAllowedByFilters(name, filename).then(async (allowed) => {\n if (!allowed) {\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_PACKAGE));\n return;\n }\n\n // trying local first\n let localStream: any = self.localStorage.getTarball(name, filename);\n let isOpen = false;\n localStream.on('error', (err): any => {\n if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {\n return readStream.emit('error', err);\n }\n\n // local reported 404\n const err404 = err;\n localStream.abort();\n localStream = null; // we force for garbage collector\n\n const lookupFromUplinks = (info: Manifest | null): void => {\n self._syncUplinksMetadata(\n name,\n info as Manifest,\n {},\n (syncErr, syncInfo: Manifest): any => {\n if (_.isNil(syncErr) === false) {\n return readStream.emit('error', syncErr);\n }\n // _syncUplinksMetadata returns filter-applied metadata; if the\n // version was removed by a filter, surface a 404 like a missing tarball.\n if (self.filters?.length && !hasTarball(syncInfo, filename)) {\n return readStream.emit('error', err404);\n }\n const distFile = lookupDistFile(syncInfo, filename);\n if (_.isNil(distFile)) {\n debug('remote tarball not found');\n return readStream.emit('error', err404);\n }\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile, syncInfo);\n }\n );\n };\n\n self.localStorage.getPackageMetadataAsync(name).then(\n (info) => {\n const distFile = lookupDistFile(info, filename);\n if (_.isNil(distFile) === false) {\n // information about this file exists locally\n debug('dist file found, using it %o', (distFile as DistFile).url);\n serveFile(distFile as DistFile, info);\n } else {\n // we know nothing about this file, trying to get information elsewhere\n debug('dist file not found, proceed update upstream');\n lookupFromUplinks(info);\n }\n },\n () => {\n // we know nothing about this file, trying to get information elsewhere\n lookupFromUplinks(null);\n }\n );\n });\n localStream.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n });\n localStream.on('open', function (): void {\n isOpen = true;\n localStream.pipe(readStream);\n });\n });\n\n return readStream;\n\n /**\n * Stream the tarball from the uplink serving the distfile, caching it\n * locally (and restoring the distfile record) when the uplink has the\n * cache enabled.\n *\n * Off-uplink URLs on a locally published package are not fetched: the\n * client's `dist.tarball` is stored verbatim, and fetching it would be\n * SSRF (and would attach uplink credentials when only one uplink is\n * configured). Uplink-synced packages may still use an autogenerated\n * proxy without credentials for CDN-hosted tarballs.\n * @param {DistFile} file distfile record resolved for the tarball\n * @param {Manifest} origin package metadata the distfile was resolved from\n */\n function serveFile(file: DistFile, origin?: Manifest | null): void {\n let uplink: any = null;\n\n const candidates: any[] = [];\n for (const uplinkId in self.uplinks) {\n if (hasProxyTo(name, uplinkId, self.config.packages)) {\n candidates.push(self.uplinks[uplinkId]);\n }\n }\n\n // recorded uplink is only used when it actually serves this URL, so\n // its Authorization header is never sent to an unrelated host\n if (file.registry && self.uplinks[file.registry]) {\n const recorded = self.uplinks[file.registry];\n if (recorded.isUplinkValid(file.url)) {\n uplink = recorded;\n debug('tarball %o is served by the recorded uplink %o', filename, file.registry);\n }\n }\n\n if (uplink === null) {\n debug('tarball %o has %o candidate uplinks', filename, candidates.length);\n for (const candidate of candidates) {\n if (candidate.isUplinkValid(file.url)) {\n uplink = candidate;\n }\n }\n if (uplink !== null) {\n debug('uplink %o url matches tarball %o', uplink.upname, file.url);\n }\n }\n\n if (uplink == null) {\n // `_distfiles` is written when metadata is merged from an uplink.\n // Local publish only stores versions[].dist.tarball, so a version\n // fallback to an off-uplink URL is client-controlled — do not fetch.\n const fromDistfiles = Boolean(origin?._distfiles?.[filename]);\n if (!fromDistfiles) {\n debug('refusing off-uplink tarball fetch for locally published %o (%o)', name, file.url);\n readStream.emit('error', ErrorCode.getNotFound(API_ERROR.NO_SUCH_FILE));\n return;\n }\n debug('upstream not found, creating one for %o without uplink credentials', name);\n uplink = new ProxyStorage(\n {\n url: file.url,\n cache: true,\n _autogenerated: true,\n },\n self.config\n );\n }\n\n let savestream: any = null;\n if (uplink.config.cache) {\n // persist which configured uplink served the tarball, so future\n // fetches can pick it directly (autogenerated proxies have no name)\n debug('cache remote tarball enabled');\n let distFile: DistFile = file;\n if (!file.registry && uplink.upname) {\n debug('recording uplink %o on the persisted distfile for %o', uplink.upname, filename);\n distFile = { ...file, registry: uplink.upname };\n }\n savestream = self.localStorage.addTarball(name, filename, distFile);\n } else {\n debug('cache remote tarball disabled');\n }\n\n let on_open = function (): void {\n // prevent it from being called twice\n on_open = function () {};\n const rstream2 = uplink.fetchTarball(file.url);\n rstream2.on('error', function (err): void {\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n readStream.emit('error', err);\n });\n rstream2.on('end', function (): void {\n if (savestream) {\n savestream.done();\n }\n });\n\n rstream2.on('content-length', function (v): void {\n readStream.emit('content-length', v);\n if (savestream) {\n savestream.emit('content-length', v);\n }\n });\n rstream2.pipe(readStream);\n if (savestream) {\n rstream2.pipe(savestream);\n }\n };\n\n if (savestream) {\n savestream.on('open', function (): void {\n on_open();\n });\n\n savestream.on('error', function (err): void {\n self.logger.warn(\n { err: err, fileName: file },\n 'error saving file @{fileName}: @{err.message}\\n@{err.stack}'\n );\n if (savestream) {\n savestream.abort();\n }\n savestream = null;\n on_open();\n });\n } else {\n on_open();\n }\n }\n }\n\n /**\n * Retrieve the package metadata: the local manifest merged with the\n * manifest of every uplink with proxy access to the package.\n * Used storages: local && uplink (proxy_access)\n * @param {Object} options\n * @property {String} options.name package name\n * @property {Object} options.req Express `req` object\n * @property {Boolean} options.keepUpLinkData keep the uplink info (last update, etc.) in the package metadata\n * @property {Boolean} options.abbreviated serve the abbreviated manifest (npm install)\n * @property {Function} options.callback invoked with the merged manifest and any uplink errors\n */\n public getPackage(options): void {\n debug('get package for %o', options.name);\n this.localStorage.getPackageMetadata(options.name, (err, data): void => {\n if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {\n // report internal errors right away\n return options.callback(err);\n }\n\n this._syncUplinksMetadata(\n options.name,\n data,\n { req: options.req, uplinksLook: options.uplinksLook },\n function getPackageSynUpLinksCallback(err, result: Manifest, uplinkErrors): void {\n if (err) {\n return options.callback(err);\n }\n\n normalizeDistTags(cleanUpLinksRef(options.keepUpLinkData, result));\n\n // npm can throw if this field doesn't exist\n result._attachments = {};\n if (options.abbreviated === true) {\n debug('get abbreviated manifest');\n options.callback(null, convertAbbreviatedManifest(result), uplinkErrors);\n } else {\n debug('get full package manifest');\n options.callback(null, result, uplinkErrors);\n }\n }\n );\n });\n }\n\n /**\n * Retrieve remote and local packages more recent than the start key.\n * All uplinks are streamed first, then the local packages; local\n * packages can override registry ones just because they appear in the\n * JSON last — a trade-off made to avoid memory issues.\n * Used storages: local && uplink (proxy_access)\n * @param {String} startkey timestamp to search from\n * @param {Object} options request options; `local=1` in the query skips the uplinks\n * @return {Stream} object stream of search results\n */\n public search(startkey: string, options: any) {\n const self = this;\n const searchStream: any = new Stream.PassThrough({ objectMode: true });\n async.eachSeries(\n Object.keys(this.uplinks),\n function (up_name, cb): void {\n // shortcut: if `local=1` is supplied, don't call uplinks\n if (options.req?.query?.local !== undefined) {\n return cb();\n }\n logger.info(`search for uplink ${up_name}`);\n // search by keyword for each uplink\n const uplinkStream = self.uplinks[up_name].search(options);\n // join uplink stream with streams PassThrough\n uplinkStream.pipe(searchStream, { end: false });\n uplinkStream.on('error', function (err): void {\n self.logger.error({ err: err }, 'uplink error: @{err.message}');\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n uplinkStream.on('end', function (): void {\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n });\n\n searchStream.abort = function (): void {\n if (uplinkStream.abort) {\n uplinkStream.abort();\n }\n cb();\n // to avoid call callback more than once\n cb = function (): void {};\n };\n },\n // executed after all series\n function (): void {\n // attach a local search results\n const localSearchStream = self.localStorage.search(startkey, options);\n searchStream.abort = function (): void {\n localSearchStream.abort();\n };\n localSearchStream.pipe(searchStream, { end: true });\n localSearchStream.on('error', function (err: any): void {\n self.logger.error({ err: err }, 'search error: @{err.message}');\n searchStream.end();\n });\n }\n );\n\n return searchStream;\n }\n\n /**\n * Retrieve only private local packages, as the latest version of each.\n * Used storages: local (read)\n * @param {Function} callback invoked with the list of latest versions\n */\n public getLocalDatabase(callback: Callback): void {\n this.localStorage.storagePlugin.get((err, locals): void => {\n if (err) {\n return callback(err);\n }\n\n this._collectLocalPackages(locals).then(\n (packages) => callback(null, packages),\n (err) => callback(err)\n );\n });\n }\n\n /**\n * Read each local package name, apply filters, and collect the latest version.\n */\n private async _collectLocalPackages(locals: string[]): Promise<Version[]> {\n const packages: Version[] = [];\n for (const name of locals) {\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const latest = filteredPackage[DIST_TAGS]?.latest;\n if (latest && filteredPackage.versions[latest]) {\n const version: Version = filteredPackage.versions[latest];\n const timeList = filteredPackage.time as GenericBody;\n const time = timeList[latest];\n // @ts-ignore\n version.time = time;\n\n // Add for stars api\n // @ts-ignore\n version.users = filteredPackage.users;\n\n packages.push(version);\n } else {\n this.logger.warn({ package: name }, 'package @{package} does not have a \"latest\" tag?');\n }\n } catch (err) {\n this.logger.error({ err, package: name }, 'error reading package @{package}');\n }\n }\n return packages;\n }\n\n /**\n * Fetch the package metadata from every uplink with proxy access and\n * synchronize it with the local data; filter plugins are applied to the\n * merged result.\n * @param {String} name package name\n * @param {Manifest} packageInfo local manifest; MUST be provided when the package exists locally\n * @param {ISyncUplinks} options uplink request options\n * @param {Function} callback invoked with (err, mergedManifest, uplinkErrors)\n */\n public _syncUplinksMetadata(\n name: string,\n packageInfo: Manifest,\n options: ISyncUplinks,\n callback: Callback\n ): void {\n let found = true;\n const self = this;\n const upLinks: ProxyStorage[] = [];\n const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;\n\n debug('sync uplinks for %o', name);\n debug('is sync uplink enabled %o', hasToLookIntoUplinks);\n if (!packageInfo) {\n debug('local package %s not found', name);\n found = false;\n packageInfo = generatePackageTemplate(name);\n }\n\n for (const uplink in this.uplinks) {\n if (hasProxyTo(name, uplink, this.config.packages) && hasToLookIntoUplinks) {\n upLinks.push(this.uplinks[uplink]);\n }\n }\n debug('uplinks found for %o: %o', name, upLinks.length);\n\n async.map(\n upLinks,\n (upLink: ProxyStorage, cb): void => {\n const _options = Object.assign({}, options);\n const upLinkMeta = packageInfo._uplinks[upLink.upname];\n\n if (isObject(upLinkMeta)) {\n const fetched = upLinkMeta.fetched;\n\n if (fetched && Date.now() - fetched < upLink.maxage) {\n debug('returning cached manifest for %o', upLink.upname);\n return cb();\n }\n\n _options.etag = upLinkMeta.etag;\n }\n\n upLink.getRemoteMetadata(name, _options, (err, upLinkResponse, eTag): void => {\n if (err && err.remoteStatus === 304) {\n debug('uplink %o responded 304 for %o, cache is up to date', upLink.upname, name);\n upLinkMeta.fetched = Date.now();\n }\n\n if (err || !upLinkResponse) {\n debug('error captured on uplink %o for %o: %o', upLink.upname, name, err?.message);\n return cb(null, [err || ErrorCode.getInternalError('no data')]);\n }\n\n try {\n upLinkResponse = validationUtils.normalizeMetadata(upLinkResponse, name);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json validating error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n packageInfo._uplinks[upLink.upname] = {\n etag: eTag,\n fetched: Date.now(),\n };\n\n packageInfo = mergeUplinkTimeIntoLocal(packageInfo, upLinkResponse);\n\n updateVersionsHiddenUpLink(upLinkResponse.versions, upLink);\n\n try {\n mergeVersions(packageInfo, upLinkResponse);\n } catch (err) {\n self.logger.error(\n {\n sub: 'out',\n err: err,\n },\n 'package.json parsing error @{!err.message}\\n@{err.stack}'\n );\n return cb(null, [err]);\n }\n\n // if we got to this point, assume that the correct package exists\n // on the uplink\n debug('syncing on uplink %o', upLink.upname);\n found = true;\n cb();\n });\n },\n // @ts-ignore\n async (err: Error, upLinksErrors: any): Promise<void> => {\n assert(!err && Array.isArray(upLinksErrors));\n\n // Check for connection timeout or reset errors with uplink(s)\n // (these should be handled differently from the package not being found)\n if (!found) {\n let uplinkTimeoutError;\n for (let i = 0; i < upLinksErrors.length; i++) {\n if (upLinksErrors[i]) {\n for (let j = 0; j < upLinksErrors[i].length; j++) {\n if (upLinksErrors[i][j]) {\n const code = upLinksErrors[i][j].code;\n if (code === 'ETIMEDOUT' || code === 'ESOCKETTIMEDOUT' || code === 'ECONNRESET') {\n uplinkTimeoutError = true;\n break;\n }\n }\n }\n }\n }\n\n if (uplinkTimeoutError) {\n debug('uplinks sync failed with timeout error');\n return callback(ErrorCode.getServiceUnavailable(), null, upLinksErrors);\n }\n debug('uplinks sync failed with no package found');\n return callback(ErrorCode.getNotFound(API_ERROR.NO_PACKAGE), null, upLinksErrors);\n }\n\n if (upLinks.length === 0) {\n debug('no uplinks found for %o, upstream update aborted', name);\n const { filteredPackage, filterErrors } = await self._applyFilters(\n packageInfo as Manifest\n );\n return callback(null, filteredPackage, filterErrors);\n }\n\n try {\n const packageJsonLocal = await self.localStorage.updateVersionsAsync(name, packageInfo);\n const { filteredPackage, filterErrors } = await self._applyFilters(packageJsonLocal);\n callback(null, filteredPackage, _.concat(upLinksErrors, filterErrors));\n } catch (err) {\n callback(err);\n }\n }\n );\n }\n\n /**\n * Apply all configured filter plugins to a package manifest sequentially.\n * Each filter's output is passed as input to the next filter.\n * Returns the filtered manifest and any errors that occurred.\n */\n private async _applyFilters(\n packageInfo: Manifest\n ): Promise<{ filteredPackage: Manifest; filterErrors: Error[] }> {\n const filterErrors: Error[] = [];\n let filteredPackage = packageInfo;\n for (const filter of this.filters ?? []) {\n try {\n filteredPackage = await filter.filter_metadata(filteredPackage);\n } catch (err: any) {\n debug('filter plugin has failed on %o: %o', packageInfo.name, err?.message);\n filterErrors.push(err);\n }\n }\n return { filteredPackage, filterErrors };\n }\n\n /**\n * Check if a tarball should be served based on filter plugins, using only\n * local metadata. Returns true (defer) when the version isn't cached locally\n * — the uplink-sync path in getTarball re-checks filters after sync, which\n * avoids a redundant uplink round-trip and double filter application.\n */\n private async _isTarballAllowedByFilters(name: string, filename: string): Promise<boolean> {\n if (!this.filters?.length) {\n return true;\n }\n\n try {\n const pkgMetadata = await this.localStorage.getPackageMetadataAsync(name);\n if (!hasTarball(pkgMetadata, filename)) {\n return true;\n }\n const { filteredPackage } = await this._applyFilters(pkgMetadata);\n const allowed = hasTarball(filteredPackage, filename);\n if (allowed === false) {\n debug('tarball %o of %o is blocked by a filter plugin', filename, name);\n }\n return allowed;\n } catch (err: any) {\n if (err?.status === HTTP_STATUS.NOT_FOUND) {\n return true;\n }\n this.logger.error(\n { package: name, fileName: filename, err },\n 'error checking filters for tarball @{fileName} of package @{package}: @{err.message}'\n );\n return true;\n }\n }\n\n /**\n * Tag each version with the uplink it was fetched from, under a hidden\n * (symbol) key. The local storage uses the tag to record the registry\n * on the distfile records it creates.\n * @param {Versions} versions versions fetched from the uplink\n * @param {ProxyStorage} upLink uplink the versions were fetched from\n */\n public _updateVersionsHiddenUpLink(versions: Versions, upLink: ProxyStorage): void {\n for (const i in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, i)) {\n const version = versions[i];\n\n // holds a \"hidden\" value to be used by the package storage.\n version[Symbol.for('__verdaccio_uplink')] = upLink.upname;\n }\n }\n }\n}\n\nexport default Storage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,QAAQ,YAAW,mBAAmB;AAE5C,IAAM,UAAN,MAAc;CACZ;CACA;CACA;CACA;CACA;CAEA,YAAmB,QAAgB;EACjC,KAAK,SAAS;EACd,KAAK,UAAU,aAAa,MAAM;EAClC,KAAK,SAAS;EAEd,KAAK,eAAe;CACtB;;;;;;;;CASA,MAAa,KAAK,QAAgB,SAAyC;EACzE,IAAI,KAAK,iBAAiB,MAAM;GAC9B,KAAK,UAAU;GACf,MAAM,kBAAkB,MAAM,KAAK,YAAY,QAAQ,KAAK,MAAM;GAClE,KAAK,eAAe,IAAI,aAAa,KAAK,QAAQ,QAAQ,eAAe;GACzE,MAAM,KAAK,aAAa,UAAU,MAAM;GACxC,MAAM,0BAA0B;EAClC,OACE,MAAM,sCAAsC;EAG9C,IAAI,CAAC,KAAK,SAAS;GACjB,KAAK,UAAU,MAAM,gBACnB,KAAK,OAAO,SACZ;IACE,QAAQ,KAAK;IACb,QAAQ,KAAK;GACf,IACC,WAA+C;IAC9C,OAAO,OAAO,OAAO,oBAAoB;GAC3C,GACA,MACA,KAAK,QAAQ,gBAAgB,cAC7B,gBAAgB,MAClB;GACA,MAAM,wBAAwB,KAAK,QAAQ,MAAM;EACnD;CACF;;;;;;CAOA,MAAc,YAAY,QAAgB,QAAwC;EAChF,MAAM,UAAU,MAAM,KAAK,gBAAgB;EAC3C,IAAI,EAAE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CACF;;;;;;CAOA,MAAc,cACZ,aAC+D;EAC/D,MAAM,eAAwB,CAAC;EAC/B,IAAI,kBAAkB;EACtB,KAAK,MAAM,UAAU,KAAK,WAAW,CAAC,GACpC,IAAI;GACF,kBAAkB,MAAM,OAAO,gBAAgB,eAAe;EAChE,SAAS,KAAU;GACjB,MAAM,sCAAsC,YAAY,MAAM,KAAK,OAAO;GAC1E,aAAa,KAAK,GAAG;EACvB;EAEF,OAAO;GAAE;GAAiB;EAAa;CACzC;;;;;;;CAQA,MAAc,2BAA2B,MAAc,UAAoC;EACzF,IAAI,CAAC,KAAK,SAAS,QACjB,OAAO;EAGT,IAAI;GACF,MAAM,cAAc,MAAM,KAAK,aAAa,wBAAwB,IAAI;GACxE,IAAI,CAAC,WAAW,aAAa,QAAQ,GACnC,OAAO;GAET,MAAM,EAAE,oBAAoB,MAAM,KAAK,cAAc,WAAW;GAChE,MAAM,UAAU,WAAW,iBAAiB,QAAQ;GACpD,IAAI,YAAY,OACd,MAAM,kDAAkD,UAAU,IAAI;GAExE,OAAO;EACT,SAAS,KAAU;GACjB,IAAI,KAAK,WAAW,YAAY,WAC9B,OAAO;GAET,KAAK,OAAO,MACV;IAAE,SAAS;IAAM,UAAU;IAAU;GAAI,GACzC,sFACF;GACA,OAAO;EACT;CACF;;;;;;;;CASA,4BAAmC,UAAoB,QAA4B;EACjF,KAAK,MAAM,KAAK,UACd,IAAI,OAAO,UAAU,eAAe,KAAK,UAAU,CAAC,GAAG;GACrD,MAAM,UAAU,SAAS;GAGzB,QAAQ,OAAO,IAAI,oBAAoB,KAAK,OAAO;EACrD;CAEJ;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verdaccio",
3
- "version": "6.10.2",
3
+ "version": "6.10.4",
4
4
  "description": "A lightweight private npm proxy registry",
5
5
  "keywords": [
6
6
  "enterprise",
@@ -85,13 +85,13 @@
85
85
  "@verdaccio/loaders": "8.1.3",
86
86
  "@verdaccio/local-storage-legacy": "11.4.3",
87
87
  "@verdaccio/logger": "8.1.3",
88
- "@verdaccio/middleware": "8.1.3",
88
+ "@verdaccio/middleware": "8.1.4",
89
89
  "@verdaccio/package-filter": "13.2.1",
90
90
  "@verdaccio/search-indexer": "8.1.0",
91
91
  "@verdaccio/signature": "8.1.3",
92
92
  "@verdaccio/streams": "10.3.0",
93
93
  "@verdaccio/tarball": "13.1.3",
94
- "@verdaccio/ui-theme": "9.0.0-next-9.30",
94
+ "@verdaccio/ui-theme": "9.0.0-next-9.31",
95
95
  "@verdaccio/url": "13.1.3",
96
96
  "JSONStream": "1.3.5",
97
97
  "async": "3.2.6",
@@ -100,12 +100,12 @@
100
100
  "cors": "2.8.6",
101
101
  "debug": "4.4.3",
102
102
  "envinfo": "7.21.0",
103
- "express": "4.22.2",
103
+ "express": "4.22.3",
104
104
  "lodash": "4.18.1",
105
105
  "lru-cache": "7.18.3",
106
106
  "mime": "3.0.0",
107
107
  "semver": "7.8.5",
108
- "verdaccio-audit": "13.1.3",
108
+ "verdaccio-audit": "13.1.4",
109
109
  "verdaccio-htpasswd": "13.1.3"
110
110
  },
111
111
  "devDependencies": {
@@ -126,10 +126,10 @@
126
126
  "@types/supertest": "6.0.3",
127
127
  "@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
128
128
  "@verdaccio/e2e-cli": "3.2.0",
129
- "@verdaccio/e2e-ui": "2.5.0",
130
- "@verdaccio/test-helper": "4.1.0",
129
+ "@verdaccio/e2e-ui": "2.7.0",
130
+ "@verdaccio/test-helper": "4.1.4",
131
131
  "@verdaccio/types": "13.0.6",
132
- "@vitest/coverage-v8": "4.1.8",
132
+ "@vitest/coverage-v8": "4.1.11",
133
133
  "cross-env": "10.1.0",
134
134
  "cypress": "15.16.0",
135
135
  "fs-extra": "11.3.5",
@@ -147,13 +147,14 @@
147
147
  "verdaccio-auth-memory": "13.1.0",
148
148
  "verdaccio-memory": "10.5.0",
149
149
  "vite": "8.1.4",
150
- "vitest": "4.1.10"
150
+ "vitest": "4.1.11"
151
151
  },
152
152
  "resolutions": {
153
153
  "@cypress/request/form-data": "4.0.6",
154
154
  "@types/express-serve-static-core": "4.19.9",
155
155
  "@types/serve-static": "1.15.10",
156
156
  "ajv/fast-uri": "3.1.6",
157
+ "body-parser/qs": "6.16.0",
157
158
  "express/path-to-regexp": "0.1.13",
158
159
  "lowdb/lodash": "4.18.1"
159
160
  },