@verdaccio/store 9.0.0-next-9.17 → 9.0.0-next-9.19

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.
@@ -4,7 +4,7 @@ debug = require_runtime.__toESM(debug);
4
4
  let _verdaccio_core = require("@verdaccio/core");
5
5
  let _verdaccio_loaders = require("@verdaccio/loaders");
6
6
  //#region src/filter-pipeline.ts
7
- var debug$1 = (0, debug.default)("verdaccio:filter-pipeline");
7
+ var debug$1 = (0, debug.default)("verdaccio:storage:filter-pipeline");
8
8
  /**
9
9
  * Apply all loaded filter plugins to a manifest in sequence.
10
10
  * Each filter receives the output of the previous one.
@@ -1 +1 @@
1
- {"version":3,"file":"filter-pipeline.js","names":[],"sources":["../src/filter-pipeline.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY, PLUGIN_PREFIX, pluginUtils as pluginSanity } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:filter-pipeline');\n\nexport type Filters = pluginUtils.ManifestFilter<Config>[];\n\n/**\n * Apply all loaded filter plugins to a manifest in sequence.\n * Each filter receives the output of the previous one.\n */\nexport async function applyManifestFilters(\n manifest: Manifest,\n filters: pluginUtils.ManifestFilter<unknown>[],\n logger: Logger\n): Promise<[Manifest, any[]]> {\n if (!filters || filters.length === 0) {\n return [manifest, []];\n }\n\n const filterPluginErrors: any[] = [];\n let filteredManifest = { ...manifest };\n for (const filter of filters) {\n try {\n filteredManifest = await filter.filter_metadata(filteredManifest);\n } catch (err: any) {\n logger.error({ err }, 'filter has failed: @{err.message}');\n filterPluginErrors.push(err);\n }\n }\n return [filteredManifest, filterPluginErrors];\n}\n\n/**\n * Load filter plugins using the same loader Verdaccio uses at startup.\n */\nexport async function loadFilterPlugins(config: Config, logger: Logger): Promise<Filters> {\n const filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n config.filters,\n {\n config,\n logger,\n },\n pluginSanity.filterSanityCheck,\n false,\n config.server?.pluginPrefix ?? PLUGIN_PREFIX,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', filters.length);\n return filters;\n}\n"],"mappings":";;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,4BAA4B;;;;;AAQrD,eAAsB,qBACpB,UACA,SACA,QAC4B;AAC5B,KAAI,CAAC,WAAW,QAAQ,WAAW,EACjC,QAAO,CAAC,UAAU,EAAE,CAAC;CAGvB,MAAM,qBAA4B,EAAE;CACpC,IAAI,mBAAmB,EAAE,GAAG,UAAU;AACtC,MAAK,MAAM,UAAU,QACnB,KAAI;AACF,qBAAmB,MAAM,OAAO,gBAAgB,iBAAiB;UAC1D,KAAU;AACjB,SAAO,MAAM,EAAE,KAAK,EAAE,oCAAoC;AAC1D,qBAAmB,KAAK,IAAI;;AAGhC,QAAO,CAAC,kBAAkB,mBAAmB;;;;;AAM/C,eAAsB,kBAAkB,QAAgB,QAAkC;CACxF,MAAM,UAAU,OAAA,GAAA,mBAAA,iBACd,OAAO,SACP;EACE;EACA;EACD,EACD,gBAAA,YAAa,mBACb,OACA,OAAO,QAAQ,gBAAgB,gBAAA,eAC/B,gBAAA,gBAAgB,OACjB;AACD,SAAM,wBAAwB,QAAQ,OAAO;AAC7C,QAAO"}
1
+ {"version":3,"file":"filter-pipeline.js","names":[],"sources":["../src/filter-pipeline.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY, PLUGIN_PREFIX, pluginUtils as pluginSanity } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:filter-pipeline');\n\nexport type Filters = pluginUtils.ManifestFilter<Config>[];\n\n/**\n * Apply all loaded filter plugins to a manifest in sequence.\n * Each filter receives the output of the previous one.\n */\nexport async function applyManifestFilters(\n manifest: Manifest,\n filters: pluginUtils.ManifestFilter<unknown>[],\n logger: Logger\n): Promise<[Manifest, any[]]> {\n if (!filters || filters.length === 0) {\n return [manifest, []];\n }\n\n const filterPluginErrors: any[] = [];\n let filteredManifest = { ...manifest };\n for (const filter of filters) {\n try {\n filteredManifest = await filter.filter_metadata(filteredManifest);\n } catch (err: any) {\n logger.error({ err }, 'filter has failed: @{err.message}');\n filterPluginErrors.push(err);\n }\n }\n return [filteredManifest, filterPluginErrors];\n}\n\n/**\n * Load filter plugins using the same loader Verdaccio uses at startup.\n */\nexport async function loadFilterPlugins(config: Config, logger: Logger): Promise<Filters> {\n const filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n config.filters,\n {\n config,\n logger,\n },\n pluginSanity.filterSanityCheck,\n false,\n config.server?.pluginPrefix ?? PLUGIN_PREFIX,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', filters.length);\n return filters;\n}\n"],"mappings":";;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,mCAAmC;;;;;AAQ5D,eAAsB,qBACpB,UACA,SACA,QAC4B;CAC5B,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,OAAO,CAAC,UAAU,CAAC,CAAC;CAGtB,MAAM,qBAA4B,CAAC;CACnC,IAAI,mBAAmB,EAAE,GAAG,SAAS;CACrC,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,mBAAmB,MAAM,OAAO,gBAAgB,gBAAgB;CAClE,SAAS,KAAU;EACjB,OAAO,MAAM,EAAE,IAAI,GAAG,mCAAmC;EACzD,mBAAmB,KAAK,GAAG;CAC7B;CAEF,OAAO,CAAC,kBAAkB,kBAAkB;AAC9C;;;;AAKA,eAAsB,kBAAkB,QAAgB,QAAkC;CACxF,MAAM,UAAU,OAAA,GAAA,mBAAA,iBACd,OAAO,SACP;EACE;EACA;CACF,GACA,gBAAA,YAAa,mBACb,OACA,OAAO,QAAQ,gBAAgB,gBAAA,eAC/B,gBAAA,gBAAgB,MAClB;CACA,QAAM,wBAAwB,QAAQ,MAAM;CAC5C,OAAO;AACT"}
@@ -2,7 +2,7 @@ import buildDebug from "debug";
2
2
  import { PLUGIN_CATEGORY, PLUGIN_PREFIX, pluginUtils } from "@verdaccio/core";
3
3
  import { asyncLoadPlugin } from "@verdaccio/loaders";
4
4
  //#region src/filter-pipeline.ts
5
- var debug = buildDebug("verdaccio:filter-pipeline");
5
+ var debug = buildDebug("verdaccio:storage:filter-pipeline");
6
6
  /**
7
7
  * Apply all loaded filter plugins to a manifest in sequence.
8
8
  * Each filter receives the output of the previous one.
@@ -1 +1 @@
1
- {"version":3,"file":"filter-pipeline.mjs","names":[],"sources":["../src/filter-pipeline.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY, PLUGIN_PREFIX, pluginUtils as pluginSanity } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:filter-pipeline');\n\nexport type Filters = pluginUtils.ManifestFilter<Config>[];\n\n/**\n * Apply all loaded filter plugins to a manifest in sequence.\n * Each filter receives the output of the previous one.\n */\nexport async function applyManifestFilters(\n manifest: Manifest,\n filters: pluginUtils.ManifestFilter<unknown>[],\n logger: Logger\n): Promise<[Manifest, any[]]> {\n if (!filters || filters.length === 0) {\n return [manifest, []];\n }\n\n const filterPluginErrors: any[] = [];\n let filteredManifest = { ...manifest };\n for (const filter of filters) {\n try {\n filteredManifest = await filter.filter_metadata(filteredManifest);\n } catch (err: any) {\n logger.error({ err }, 'filter has failed: @{err.message}');\n filterPluginErrors.push(err);\n }\n }\n return [filteredManifest, filterPluginErrors];\n}\n\n/**\n * Load filter plugins using the same loader Verdaccio uses at startup.\n */\nexport async function loadFilterPlugins(config: Config, logger: Logger): Promise<Filters> {\n const filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n config.filters,\n {\n config,\n logger,\n },\n pluginSanity.filterSanityCheck,\n false,\n config.server?.pluginPrefix ?? PLUGIN_PREFIX,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', filters.length);\n return filters;\n}\n"],"mappings":";;;;AAOA,IAAM,QAAQ,WAAW,4BAA4B;;;;;AAQrD,eAAsB,qBACpB,UACA,SACA,QAC4B;AAC5B,KAAI,CAAC,WAAW,QAAQ,WAAW,EACjC,QAAO,CAAC,UAAU,EAAE,CAAC;CAGvB,MAAM,qBAA4B,EAAE;CACpC,IAAI,mBAAmB,EAAE,GAAG,UAAU;AACtC,MAAK,MAAM,UAAU,QACnB,KAAI;AACF,qBAAmB,MAAM,OAAO,gBAAgB,iBAAiB;UAC1D,KAAU;AACjB,SAAO,MAAM,EAAE,KAAK,EAAE,oCAAoC;AAC1D,qBAAmB,KAAK,IAAI;;AAGhC,QAAO,CAAC,kBAAkB,mBAAmB;;;;;AAM/C,eAAsB,kBAAkB,QAAgB,QAAkC;CACxF,MAAM,UAAU,MAAM,gBACpB,OAAO,SACP;EACE;EACA;EACD,EACD,YAAa,mBACb,OACA,OAAO,QAAQ,gBAAgB,eAC/B,gBAAgB,OACjB;AACD,OAAM,wBAAwB,QAAQ,OAAO;AAC7C,QAAO"}
1
+ {"version":3,"file":"filter-pipeline.mjs","names":[],"sources":["../src/filter-pipeline.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_CATEGORY, PLUGIN_PREFIX, pluginUtils as pluginSanity } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport type { Config, Logger, Manifest } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:filter-pipeline');\n\nexport type Filters = pluginUtils.ManifestFilter<Config>[];\n\n/**\n * Apply all loaded filter plugins to a manifest in sequence.\n * Each filter receives the output of the previous one.\n */\nexport async function applyManifestFilters(\n manifest: Manifest,\n filters: pluginUtils.ManifestFilter<unknown>[],\n logger: Logger\n): Promise<[Manifest, any[]]> {\n if (!filters || filters.length === 0) {\n return [manifest, []];\n }\n\n const filterPluginErrors: any[] = [];\n let filteredManifest = { ...manifest };\n for (const filter of filters) {\n try {\n filteredManifest = await filter.filter_metadata(filteredManifest);\n } catch (err: any) {\n logger.error({ err }, 'filter has failed: @{err.message}');\n filterPluginErrors.push(err);\n }\n }\n return [filteredManifest, filterPluginErrors];\n}\n\n/**\n * Load filter plugins using the same loader Verdaccio uses at startup.\n */\nexport async function loadFilterPlugins(config: Config, logger: Logger): Promise<Filters> {\n const filters = await asyncLoadPlugin<pluginUtils.ManifestFilter<unknown>>(\n config.filters,\n {\n config,\n logger,\n },\n pluginSanity.filterSanityCheck,\n false,\n config.server?.pluginPrefix ?? PLUGIN_PREFIX,\n PLUGIN_CATEGORY.FILTER\n );\n debug('filters available %o', filters.length);\n return filters;\n}\n"],"mappings":";;;;AAOA,IAAM,QAAQ,WAAW,mCAAmC;;;;;AAQ5D,eAAsB,qBACpB,UACA,SACA,QAC4B;CAC5B,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,OAAO,CAAC,UAAU,CAAC,CAAC;CAGtB,MAAM,qBAA4B,CAAC;CACnC,IAAI,mBAAmB,EAAE,GAAG,SAAS;CACrC,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,mBAAmB,MAAM,OAAO,gBAAgB,gBAAgB;CAClE,SAAS,KAAU;EACjB,OAAO,MAAM,EAAE,IAAI,GAAG,mCAAmC;EACzD,mBAAmB,KAAK,GAAG;CAC7B;CAEF,OAAO,CAAC,kBAAkB,kBAAkB;AAC9C;;;;AAKA,eAAsB,kBAAkB,QAAgB,QAAkC;CACxF,MAAM,UAAU,MAAM,gBACpB,OAAO,SACP;EACE;EACA;CACF,GACA,YAAa,mBACb,OACA,OAAO,QAAQ,gBAAgB,eAC/B,gBAAgB,MAClB;CACA,MAAM,wBAAwB,QAAQ,MAAM;CAC5C,OAAO;AACT"}
package/build/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export { applyManifestFilters, loadFilterPlugins } from './filter-pipeline';
3
3
  export type { Filters } from './filter-pipeline';
4
4
  export * from './lib/storage-utils';
5
5
  export * from './lib/versions-utils';
6
- export * from './lib/star-utils';
6
+ export * from './lib/publish-utils';
7
7
  export * from './type';
package/build/index.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_filter_pipeline = require("./filter-pipeline.js");
6
- const require_star_utils = require("./lib/star-utils.js");
6
+ const require_publish_utils = require("./lib/publish-utils.js");
7
7
  const require_versions_utils = require("./lib/versions-utils.js");
8
8
  const require_storage_utils = require("./lib/storage-utils.js");
9
9
  const require_storage = require("./storage.js");
@@ -20,10 +20,8 @@ exports.getLatestReadme = require_storage_utils.getLatestReadme;
20
20
  exports.getVersion = require_versions_utils.getVersion;
21
21
  exports.hasDeprecatedVersions = require_storage_utils.hasDeprecatedVersions;
22
22
  exports.isDeprecatedManifest = require_storage_utils.isDeprecatedManifest;
23
- exports.isExecutingStarCommand = require_star_utils.isExecutingStarCommand;
24
23
  exports.isNewerVersion = require_versions_utils.isNewerVersion;
25
- exports.isPublishablePackage = require_star_utils.isPublishablePackage;
26
- exports.isStarManifest = require_star_utils.isStarManifest;
24
+ exports.isPublishablePackage = require_publish_utils.isPublishablePackage;
27
25
  exports.loadFilterPlugins = require_filter_pipeline.loadFilterPlugins;
28
26
  exports.mapManifestToSearchPackageBody = require_storage_utils.mapManifestToSearchPackageBody;
29
27
  exports.mergeUplinkTimeIntoLocal = require_storage_utils.mergeUplinkTimeIntoLocal;
package/build/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { applyManifestFilters, loadFilterPlugins } from "./filter-pipeline.mjs";
2
- import { isExecutingStarCommand, isPublishablePackage, isStarManifest } from "./lib/star-utils.mjs";
2
+ import { isPublishablePackage } from "./lib/publish-utils.mjs";
3
3
  import { getVersion, isNewerVersion, removeLowerVersions, sortVersionsAndFilterInvalid, tagVersion, tagVersionNext } from "./lib/versions-utils.mjs";
4
4
  import { STORAGE, WHITELIST, checkPackageRemote, cleanUpLinksRef, cleanUpReadme, generatePackageTemplate, generateRevision, getLatestReadme, hasDeprecatedVersions, isDeprecatedManifest, mapManifestToSearchPackageBody, mergeUplinkTimeIntoLocal, mergeUplinkTimeIntoLocalNext, mergeVersions, normalizeContributors, normalizeDistTags, normalizePackage, prepareSearchPackage, updateUpLinkMetadata } from "./lib/storage-utils.mjs";
5
5
  import { Storage } from "./storage.mjs";
6
- export { STORAGE, Storage, WHITELIST, applyManifestFilters, checkPackageRemote, cleanUpLinksRef, cleanUpReadme, generatePackageTemplate, generateRevision, getLatestReadme, getVersion, hasDeprecatedVersions, isDeprecatedManifest, isExecutingStarCommand, isNewerVersion, isPublishablePackage, isStarManifest, loadFilterPlugins, mapManifestToSearchPackageBody, mergeUplinkTimeIntoLocal, mergeUplinkTimeIntoLocalNext, mergeVersions, normalizeContributors, normalizeDistTags, normalizePackage, prepareSearchPackage, removeLowerVersions, sortVersionsAndFilterInvalid, tagVersion, tagVersionNext, updateUpLinkMetadata };
6
+ export { STORAGE, Storage, WHITELIST, applyManifestFilters, checkPackageRemote, cleanUpLinksRef, cleanUpReadme, generatePackageTemplate, generateRevision, getLatestReadme, getVersion, hasDeprecatedVersions, isDeprecatedManifest, isNewerVersion, isPublishablePackage, loadFilterPlugins, mapManifestToSearchPackageBody, mergeUplinkTimeIntoLocal, mergeUplinkTimeIntoLocalNext, mergeVersions, normalizeContributors, normalizeDistTags, normalizePackage, prepareSearchPackage, removeLowerVersions, sortVersionsAndFilterInvalid, tagVersion, tagVersionNext, updateUpLinkMetadata };
@@ -0,0 +1,6 @@
1
+ import { Manifest } from '@verdaccio/types';
2
+ /**
3
+ * Check whether the package metadata has enough data to be published
4
+ * @param pkg metadata
5
+ */
6
+ export declare function isPublishablePackage(pkg: Manifest): boolean;
@@ -0,0 +1,12 @@
1
+ //#region src/lib/publish-utils.ts
2
+ /**
3
+ * Check whether the package metadata has enough data to be published
4
+ * @param pkg metadata
5
+ */
6
+ function isPublishablePackage(pkg) {
7
+ return Object.keys(pkg).includes("versions");
8
+ }
9
+ //#endregion
10
+ exports.isPublishablePackage = isPublishablePackage;
11
+
12
+ //# sourceMappingURL=publish-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-utils.js","names":[],"sources":["../../src/lib/publish-utils.ts"],"sourcesContent":["import type { Manifest } from '@verdaccio/types';\n\n/**\n * Check whether the package metadata has enough data to be published\n * @param pkg metadata\n */\nexport function isPublishablePackage(pkg: Manifest): boolean {\n // TODO: we can do better, no need get keys\n const keys: string[] = Object.keys(pkg);\n\n return keys.includes('versions');\n}\n"],"mappings":";;;;;AAMA,SAAgB,qBAAqB,KAAwB;CAI3D,OAFuB,OAAO,KAAK,GAE5B,EAAK,SAAS,UAAU;AACjC"}
@@ -0,0 +1,12 @@
1
+ //#region src/lib/publish-utils.ts
2
+ /**
3
+ * Check whether the package metadata has enough data to be published
4
+ * @param pkg metadata
5
+ */
6
+ function isPublishablePackage(pkg) {
7
+ return Object.keys(pkg).includes("versions");
8
+ }
9
+ //#endregion
10
+ export { isPublishablePackage };
11
+
12
+ //# sourceMappingURL=publish-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-utils.mjs","names":[],"sources":["../../src/lib/publish-utils.ts"],"sourcesContent":["import type { Manifest } from '@verdaccio/types';\n\n/**\n * Check whether the package metadata has enough data to be published\n * @param pkg metadata\n */\nexport function isPublishablePackage(pkg: Manifest): boolean {\n // TODO: we can do better, no need get keys\n const keys: string[] = Object.keys(pkg);\n\n return keys.includes('versions');\n}\n"],"mappings":";;;;;AAMA,SAAgB,qBAAqB,KAAwB;CAI3D,OAFuB,OAAO,KAAK,GAE5B,EAAK,SAAS,UAAU;AACjC"}
@@ -65,6 +65,9 @@ export declare function updateUpLinkMetadata(uplinkName: string, manifest: Manif
65
65
  keywords?: string[];
66
66
  author?: import('@verdaccio/types').Person;
67
67
  _attachments: import('@verdaccio/types').AttachMents;
68
+ publisher?: import('@verdaccio/types').Publisher;
69
+ publishedPackage?: string;
70
+ publishType?: "publish" | "unpublish";
68
71
  };
69
72
  export declare function prepareSearchPackage(data: Manifest): any;
70
73
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.js","names":[],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import { isNil, trim } from 'lodash-es';\nimport semver from 'semver';\n\nimport {\n API_ERROR,\n DIST_TAGS,\n HTTP_STATUS,\n MAINTAINERS,\n USERS,\n cryptoUtils,\n errorUtils,\n pkgUtils,\n searchUtils,\n validationUtils,\n} from '@verdaccio/core';\nimport { Author, GenericBody, Manifest, ReadmeOptions, Version } from '@verdaccio/types';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n [MAINTAINERS]: [],\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validationUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + cryptoUtils.generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = trim(version.readme || readme);\n });\n return readme;\n}\n\n/**\n * Cleanup readme from package version\n *\n * By default, we don't keep readmes for package versions, only one readme per package.\n * Using publish.keep_readmes you can override this behavior and keep all readmes\n * or only readmes for tagged versions.\n */\nexport function cleanUpReadme(\n version: Version,\n distTags?: GenericBody,\n keepReadmes?: ReadmeOptions\n): Version {\n if (keepReadmes === 'all') {\n return version;\n } else if (keepReadmes === 'tagged') {\n if (distTags && Object.values(distTags).includes(version.version)) {\n return version;\n }\n }\n\n if (isNil(version) === false) {\n version.readme = '';\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n 'maintainers',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkName: string, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkName]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} cacheManifest\n * @param {*} remoteManifest\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions, time } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n // however, we can refresh the deprecated status\n for (const i in versions) {\n if (typeof _cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n } else if (versions[i].deprecated) {\n _cacheManifest.versions[i].deprecated = versions[i].deprecated;\n }\n }\n\n for (const i in time) {\n if (typeof _cacheManifest.time[i] === 'undefined') {\n _cacheManifest.time[i] = time[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n _cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n return _cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (Array.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (typeof manifest[DIST_TAGS][tag] === 'string') {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return (\n hasDeprecatedVersions(manifest) &&\n (typeof manifest._attachments === 'undefined' ||\n Object.keys(manifest._attachments).length === 0)\n );\n}\n\nexport function mapManifestToSearchPackageBody(\n pkg: Manifest,\n searchItem: searchUtils.SearchItem\n): searchUtils.SearchPackageBody {\n const latest = pkgUtils.getLatest(pkg);\n const version: Version = pkg.versions[latest];\n const result: searchUtils.SearchPackageBody = {\n name: version.name,\n scope: '',\n description: version.description,\n version: latest,\n keywords: version.keywords,\n date: pkg.time[latest],\n // FIXME: type\n author: version.author as any,\n // FIXME: not possible fill this out from a private package\n publisher: {},\n // FIXME: type\n maintainers: version.maintainers as any,\n links: {\n npm: '',\n homepage: version.homepage,\n repository: version.repository,\n bugs: version.bugs,\n },\n };\n\n if (typeof searchItem.package.scoped === 'string') {\n result.scope = searchItem.package.scoped;\n }\n\n return result;\n}\n\nexport function normalizeContributors(contributors: Author[]): Author[] {\n if (isNil(contributors)) {\n return [];\n } else if (contributors && !Array.isArray(contributors)) {\n return [contributors];\n } else if (typeof contributors === 'string') {\n return [\n {\n name: contributors,\n },\n ];\n }\n\n return contributors;\n}\n"],"mappings":";;;;;;;AAmBA,IAAa,UAAU;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,kBAAkB;CACnB;;;;;;AAOD,SAAgB,wBAAwB,MAAwB;AAC9D,QAAO;EAEL;EACA,UAAU,EAAE;EACZ,MAAM,EAAE;GACP,gBAAA,QAAQ,EAAE;GACV,gBAAA,YAAY,EAAE;GACd,gBAAA,cAAc,EAAE;EACjB,UAAU,EAAE;EACZ,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,MAAM;EACP;;;;;;AAOH,SAAgB,iBAAiB,KAAyB;AAClC;EAAC;EAAY;EAAa;EAAc;EAAgB;EAAY;EAAO,CAEnF,SAAS,QAAc;EACnC,MAAM,UAAU,IAAI;AAEpB,OAAA,GAAA,UAAA,OAAU,QAAQ,IAAI,gBAAA,gBAAgB,SAAS,QAAQ,KAAK,MAC1D,KAAI,OAAO,EAAE;GAEf;AAEF,KAAI,OAAO,KAAK,SAAS,SACvB,KAAI,OAAO,QAAQ;AAGrB,KAAI,OAAO,KAAK,QAAQ,SACtB,KAAI,MAAM,IAAI;AAI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E;UACA,gBAAgB,CAAC,MAAM,QAAQ,aAAa,CACrD,QAAO,CAAC,aAAa;UACZ,OAAO,iBAAiB,SACjC,QAAO,CACL,EACE,MAAM,cACP,CACF;AAGH,QAAO"}
1
+ {"version":3,"file":"storage-utils.js","names":[],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import { isNil, trim } from 'lodash-es';\nimport semver from 'semver';\n\nimport {\n API_ERROR,\n DIST_TAGS,\n HTTP_STATUS,\n MAINTAINERS,\n USERS,\n cryptoUtils,\n errorUtils,\n pkgUtils,\n searchUtils,\n validationUtils,\n} from '@verdaccio/core';\nimport { Author, GenericBody, Manifest, ReadmeOptions, Version } from '@verdaccio/types';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n [MAINTAINERS]: [],\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validationUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + cryptoUtils.generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = trim(version.readme || readme);\n });\n return readme;\n}\n\n/**\n * Cleanup readme from package version\n *\n * By default, we don't keep readmes for package versions, only one readme per package.\n * Using publish.keep_readmes you can override this behavior and keep all readmes\n * or only readmes for tagged versions.\n */\nexport function cleanUpReadme(\n version: Version,\n distTags?: GenericBody,\n keepReadmes?: ReadmeOptions\n): Version {\n if (keepReadmes === 'all') {\n return version;\n } else if (keepReadmes === 'tagged') {\n if (distTags && Object.values(distTags).includes(version.version)) {\n return version;\n }\n }\n\n if (isNil(version) === false) {\n version.readme = '';\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n 'maintainers',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkName: string, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkName]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} cacheManifest\n * @param {*} remoteManifest\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions, time } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n // however, we can refresh the deprecated status\n for (const i in versions) {\n if (typeof _cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n } else if (versions[i].deprecated) {\n _cacheManifest.versions[i].deprecated = versions[i].deprecated;\n }\n }\n\n for (const i in time) {\n if (typeof _cacheManifest.time[i] === 'undefined') {\n _cacheManifest.time[i] = time[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n _cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n return _cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (Array.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (typeof manifest[DIST_TAGS][tag] === 'string') {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return (\n hasDeprecatedVersions(manifest) &&\n (typeof manifest._attachments === 'undefined' ||\n Object.keys(manifest._attachments).length === 0)\n );\n}\n\nexport function mapManifestToSearchPackageBody(\n pkg: Manifest,\n searchItem: searchUtils.SearchItem\n): searchUtils.SearchPackageBody {\n const latest = pkgUtils.getLatest(pkg);\n const version: Version = pkg.versions[latest];\n const result: searchUtils.SearchPackageBody = {\n name: version.name,\n scope: '',\n description: version.description,\n version: latest,\n keywords: version.keywords,\n date: pkg.time[latest],\n // FIXME: type\n author: version.author as any,\n // FIXME: not possible fill this out from a private package\n publisher: {},\n // FIXME: type\n maintainers: version.maintainers as any,\n links: {\n npm: '',\n homepage: version.homepage,\n repository: version.repository,\n bugs: version.bugs,\n },\n };\n\n if (typeof searchItem.package.scoped === 'string') {\n result.scope = searchItem.package.scoped;\n }\n\n return result;\n}\n\nexport function normalizeContributors(contributors: Author[]): Author[] {\n if (isNil(contributors)) {\n return [];\n } else if (contributors && !Array.isArray(contributors)) {\n return [contributors];\n } else if (typeof contributors === 'string') {\n return [\n {\n name: contributors,\n },\n ];\n }\n\n return contributors;\n}\n"],"mappings":";;;;;;;AAmBA,IAAa,UAAU;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,kBAAkB;AACpB;;;;;;AAOA,SAAgB,wBAAwB,MAAwB;CAC9D,OAAO;EAEL;EACA,UAAU,CAAC;EACX,MAAM,CAAC;GACN,gBAAA,QAAQ,CAAC;GACT,gBAAA,YAAY,CAAC;GACb,gBAAA,cAAc,CAAC;EAChB,UAAU,CAAC;EACX,YAAY,CAAC;EACb,cAAc,CAAC;EACf,MAAM;CACR;AACF;;;;;AAMA,SAAgB,iBAAiB,KAAyB;CAGxD;EAFuB;EAAY;EAAa;EAAc;EAAgB;EAAY;CAE1F,EAAc,SAAS,QAAc;EACnC,MAAM,UAAU,IAAI;EAEpB,KAAA,GAAA,UAAA,OAAU,OAAO,KAAK,gBAAA,gBAAgB,SAAS,OAAO,MAAM,OAC1D,IAAI,OAAO,CAAC;CAEhB,CAAC;CAED,IAAI,OAAO,KAAK,SAAS,UACvB,IAAI,OAAO,QAAQ;CAGrB,IAAI,OAAO,KAAK,QAAQ,UACtB,IAAI,MAAM,IAAI;CAIhB,OAAO,kBAAkB,GAAG;AAC9B;AAEA,SAAgB,iBAAiB,KAAqB;CAGpD,QAAQ,CAFK,IAAI,MAAM,GAEd,EAAK,MAAM,KAAK,IAAI,MAAM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H,IAAI,gBAAgB,CAAC,MAAM,QAAQ,YAAY,GACpD,OAAO,CAAC,YAAY;MACf,IAAI,OAAO,iBAAiB,UACjC,OAAO,CACL,EACE,MAAM,aACR,CACF;CAGF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.mjs","names":[],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import { isNil, trim } from 'lodash-es';\nimport semver from 'semver';\n\nimport {\n API_ERROR,\n DIST_TAGS,\n HTTP_STATUS,\n MAINTAINERS,\n USERS,\n cryptoUtils,\n errorUtils,\n pkgUtils,\n searchUtils,\n validationUtils,\n} from '@verdaccio/core';\nimport { Author, GenericBody, Manifest, ReadmeOptions, Version } from '@verdaccio/types';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n [MAINTAINERS]: [],\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validationUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + cryptoUtils.generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = trim(version.readme || readme);\n });\n return readme;\n}\n\n/**\n * Cleanup readme from package version\n *\n * By default, we don't keep readmes for package versions, only one readme per package.\n * Using publish.keep_readmes you can override this behavior and keep all readmes\n * or only readmes for tagged versions.\n */\nexport function cleanUpReadme(\n version: Version,\n distTags?: GenericBody,\n keepReadmes?: ReadmeOptions\n): Version {\n if (keepReadmes === 'all') {\n return version;\n } else if (keepReadmes === 'tagged') {\n if (distTags && Object.values(distTags).includes(version.version)) {\n return version;\n }\n }\n\n if (isNil(version) === false) {\n version.readme = '';\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n 'maintainers',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkName: string, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkName]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} cacheManifest\n * @param {*} remoteManifest\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions, time } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n // however, we can refresh the deprecated status\n for (const i in versions) {\n if (typeof _cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n } else if (versions[i].deprecated) {\n _cacheManifest.versions[i].deprecated = versions[i].deprecated;\n }\n }\n\n for (const i in time) {\n if (typeof _cacheManifest.time[i] === 'undefined') {\n _cacheManifest.time[i] = time[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n _cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n return _cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (Array.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (typeof manifest[DIST_TAGS][tag] === 'string') {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return (\n hasDeprecatedVersions(manifest) &&\n (typeof manifest._attachments === 'undefined' ||\n Object.keys(manifest._attachments).length === 0)\n );\n}\n\nexport function mapManifestToSearchPackageBody(\n pkg: Manifest,\n searchItem: searchUtils.SearchItem\n): searchUtils.SearchPackageBody {\n const latest = pkgUtils.getLatest(pkg);\n const version: Version = pkg.versions[latest];\n const result: searchUtils.SearchPackageBody = {\n name: version.name,\n scope: '',\n description: version.description,\n version: latest,\n keywords: version.keywords,\n date: pkg.time[latest],\n // FIXME: type\n author: version.author as any,\n // FIXME: not possible fill this out from a private package\n publisher: {},\n // FIXME: type\n maintainers: version.maintainers as any,\n links: {\n npm: '',\n homepage: version.homepage,\n repository: version.repository,\n bugs: version.bugs,\n },\n };\n\n if (typeof searchItem.package.scoped === 'string') {\n result.scope = searchItem.package.scoped;\n }\n\n return result;\n}\n\nexport function normalizeContributors(contributors: Author[]): Author[] {\n if (isNil(contributors)) {\n return [];\n } else if (contributors && !Array.isArray(contributors)) {\n return [contributors];\n } else if (typeof contributors === 'string') {\n return [\n {\n name: contributors,\n },\n ];\n }\n\n return contributors;\n}\n"],"mappings":";;;;;AAmBA,IAAa,UAAU;CACrB,mBAAmB;CACnB,kBAAkB;CAClB,oBAAoB;CACpB,kBAAkB;CACnB;;;;;;AAOD,SAAgB,wBAAwB,MAAwB;AAC9D,QAAO;EAEL;EACA,UAAU,EAAE;EACZ,MAAM,EAAE;GACP,QAAQ,EAAE;GACV,YAAY,EAAE;GACd,cAAc,EAAE;EACjB,UAAU,EAAE;EACZ,YAAY,EAAE;EACd,cAAc,EAAE;EAChB,MAAM;EACP;;;;;;AAOH,SAAgB,iBAAiB,KAAyB;AAClC;EAAC;EAAY;EAAa;EAAc;EAAgB;EAAY;EAAO,CAEnF,SAAS,QAAc;EACnC,MAAM,UAAU,IAAI;AAEpB,MAAI,MAAM,QAAQ,IAAI,gBAAgB,SAAS,QAAQ,KAAK,MAC1D,KAAI,OAAO,EAAE;GAEf;AAEF,KAAI,OAAO,KAAK,SAAS,SACvB,KAAI,OAAO,QAAQ;AAGrB,KAAI,OAAO,KAAK,QAAQ,SACtB,KAAI,MAAM,IAAI;AAIhB,QAAO,kBAAkB,IAAI;;AAG/B,SAAgB,iBAAiB,KAAqB;AAGpD,SAAQ,CAFK,IAAI,MAAM,IAAI,CAEb,MAAM,KAAK,IAAI,MAAM,YAAY,yBAAyB;;AAG1E,SAA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ACrB,MAAK,MAAM,WAAW,SACpB,KAAI,OAAO,UAAU,eAAe,KAAK,SAAS,UAAU,aAAa,CACvE,QAAO;AAGX,QAAO;;AAGT,SAAgB,qBAAqB,UAA6B;AAChE,QACE,sBAAsB,SAAS,KAC9B,OAAO,SAAS,iBAAiB,eAChC,OAAO,KAAK,SAAS,aAAa,CAAC,WAAW;;AAIpD,SAAgB,+BACd,KACA,YAC+B;CAC/B,MAAM,SAAS,SAAS,UAAU,IAAI;CACtC,MAAM,UAAmB,IAAI,SAAS;CACtC,MAAM,SAAwC;EAC5C,MAAM,QAAQ;EACd,OAAO;EACP,aAAa,QAAQ;EACrB,SAAS;EACT,UAAU,QAAQ;EAClB,MAAM,IAAI,KAAK;EAEf,QAAQ,QAAQ;EAEhB,WAAW,EAAE;EAEb,aAAa,QAAQ;EACrB,OAAO;GACL,KAAK;GACL,UAAU,QAAQ;GAClB,YAAY,QAAQ;GACpB,MAAM,QAAQ;GACf;EACF;AAED,KAAI,OAAO,WAAW,QAAQ,WAAW,SACvC,QAAO,QAAQ,WAAW,QAAQ;AAGpC,QAAO;;AAGT,SAAgB,sBAAsB,cAAkC;AACtE,KAAI,MAAM,aAAa,CACrB,QAAO,EAAE;UACA,gBAAgB,CAAC,MAAM,QAAQ,aAAa,CACrD,QAAO,CAAC,aAAa;UACZ,OAAO,iBAAiB,SACjC,QAAO,CACL,EACE,MAAM,cACP,CACF;AAGH,QAAO"}
1
+ {"version":3,"file":"storage-utils.mjs","names":[],"sources":["../../src/lib/storage-utils.ts"],"sourcesContent":["import { isNil, trim } from 'lodash-es';\nimport semver from 'semver';\n\nimport {\n API_ERROR,\n DIST_TAGS,\n HTTP_STATUS,\n MAINTAINERS,\n USERS,\n cryptoUtils,\n errorUtils,\n pkgUtils,\n searchUtils,\n validationUtils,\n} from '@verdaccio/core';\nimport { Author, GenericBody, Manifest, ReadmeOptions, Version } from '@verdaccio/types';\n\nimport { sortVersionsAndFilterInvalid } from './versions-utils';\n\nexport const STORAGE = {\n PACKAGE_FILE_NAME: 'package.json',\n FILE_EXIST_ERROR: 'EEXISTS',\n NO_SUCH_FILE_ERROR: 'ENOENT',\n DEFAULT_REVISION: '0-0000000000000000',\n};\n\n/**\n * Create a new package in the storage, return a boilerplate package\n * @param name package name\n * @returns {Manifest}\n */\nexport function generatePackageTemplate(name: string): Manifest {\n return {\n // standard things\n name,\n versions: {},\n time: {},\n [USERS]: {},\n [DIST_TAGS]: {},\n [MAINTAINERS]: [],\n _uplinks: {},\n _distfiles: {},\n _attachments: {},\n _rev: '',\n };\n}\n\n/**\n * Normalize package properties, tags, revision id.\n * @param {Object} pkg package reference.\n */\nexport function normalizePackage(pkg: Manifest): Manifest {\n const pkgProperties = ['versions', 'dist-tags', '_distfiles', '_attachments', '_uplinks', 'time'];\n\n pkgProperties.forEach((key): void => {\n const pkgProp = pkg[key];\n\n if (isNil(pkgProp) || validationUtils.isObject(pkgProp) === false) {\n pkg[key] = {};\n }\n });\n\n if (typeof pkg?._rev !== 'string') {\n pkg._rev = STORAGE.DEFAULT_REVISION;\n }\n\n if (typeof pkg?._id !== 'string') {\n pkg._id = pkg.name;\n }\n\n // normalize dist-tags\n return normalizeDistTags(pkg);\n}\n\nexport function generateRevision(rev: string): string {\n const _rev = rev.split('-');\n\n return (+_rev[0] || 0) + 1 + '-' + cryptoUtils.generateRandomHexString();\n}\n\nexport function getLatestReadme(pkg: Manifest): string {\n const versions = pkg['versions'] || {};\n const distTags = pkg[DIST_TAGS] || {};\n // FIXME: here is a bit tricky add the types\n const latestVersion: Version | any = distTags['latest'] ? versions[distTags['latest']] || {} : {};\n let readme = trim(pkg.readme || latestVersion.readme || '');\n if (readme) {\n return readme;\n }\n\n // In case of empty readme - trying to get ANY readme in the following order:\n // 'next','beta','alpha','test','dev','canary'\n const readmeDistTagsPriority = ['next', 'beta', 'alpha', 'test', 'dev', 'canary'];\n readmeDistTagsPriority.forEach(function (tag): string | void {\n if (readme) {\n return readme;\n }\n const version: Version | any = distTags[tag] ? versions[distTags[tag]] || {} : {};\n readme = trim(version.readme || readme);\n });\n return readme;\n}\n\n/**\n * Cleanup readme from package version\n *\n * By default, we don't keep readmes for package versions, only one readme per package.\n * Using publish.keep_readmes you can override this behavior and keep all readmes\n * or only readmes for tagged versions.\n */\nexport function cleanUpReadme(\n version: Version,\n distTags?: GenericBody,\n keepReadmes?: ReadmeOptions\n): Version {\n if (keepReadmes === 'all') {\n return version;\n } else if (keepReadmes === 'tagged') {\n if (distTags && Object.values(distTags).includes(version.version)) {\n return version;\n }\n }\n\n if (isNil(version) === false) {\n version.readme = '';\n }\n\n return version;\n}\n\nexport const WHITELIST = [\n '_rev',\n 'name',\n 'versions',\n 'dist-tags',\n 'readme',\n 'time',\n '_id',\n 'users',\n 'maintainers',\n];\n\nexport function cleanUpLinksRef(result: Manifest, keepUpLinkData?: boolean): Manifest {\n const propertyToKeep = [...WHITELIST];\n if (keepUpLinkData === true) {\n propertyToKeep.push('_uplinks');\n }\n\n for (const i in result) {\n if (propertyToKeep.indexOf(i) === -1) {\n // Remove sections like '_uplinks' from response\n delete result[i];\n }\n }\n\n return result;\n}\n\n// TODO: move to abstract storage\n// @deprecated use abstract.storage.ts:checkPackageRemote\nexport function checkPackageRemote(\n name: string,\n isAllowPublishOffline: boolean,\n syncMetadata: Function\n): Promise<any> {\n return new Promise<void>((resolve, reject): void => {\n syncMetadata(name, null, {}, (err, packageJsonLocal, upLinksErrors): void => {\n // something weird\n if (err && err.status !== HTTP_STATUS.NOT_FOUND) {\n return reject(err);\n }\n\n // checking package exist already\n if (isNil(packageJsonLocal) === false) {\n return reject(errorUtils.getConflict(API_ERROR.PACKAGE_EXIST));\n }\n\n for (let errorItem = 0; errorItem < upLinksErrors.length; errorItem++) {\n // checking error\n // if uplink fails with a status other than 404, we report failure\n if (isNil(upLinksErrors[errorItem][0]) === false) {\n if (upLinksErrors[errorItem][0].status !== HTTP_STATUS.NOT_FOUND) {\n if (isAllowPublishOffline) {\n return resolve();\n }\n\n return reject(errorUtils.getServiceUnavailable(API_ERROR.UPLINK_OFFLINE_PUBLISH));\n }\n }\n }\n\n return resolve();\n });\n });\n}\n\n// @deprecated use export function mergeUplinkTimeIntoLocalNext\nexport function mergeUplinkTimeIntoLocal(localMetadata: Manifest, remoteMetadata: Manifest): any {\n if ('time' in remoteMetadata) {\n return Object.assign({}, localMetadata.time, remoteMetadata.time);\n }\n\n return localMetadata.time;\n}\n\nexport function mergeUplinkTimeIntoLocalNext(\n cacheManifest: Manifest,\n remoteManifest: Manifest\n): Manifest {\n if ('time' in remoteManifest) {\n // remote override cache time conflicts\n return { ...cacheManifest, time: { ...cacheManifest.time, ...remoteManifest.time } };\n }\n\n return cacheManifest;\n}\n\nexport function updateUpLinkMetadata(uplinkName: string, manifest: Manifest, etag: string) {\n const _uplinks = {\n ...manifest._uplinks,\n [uplinkName]: {\n etag,\n fetched: Date.now(),\n },\n };\n return {\n ...manifest,\n _uplinks,\n };\n}\n\nexport function prepareSearchPackage(data: Manifest): any {\n const latest = pkgUtils.getLatest(data);\n\n if (latest && data.versions[latest]) {\n const version: Version = data.versions[latest];\n const versions: any = { [latest]: 'latest' };\n const pkg: any = {\n name: version.name,\n description: version.description,\n [DIST_TAGS]: { latest },\n maintainers: version.maintainers || [version.author].filter(Boolean),\n author: version.author,\n repository: version.repository,\n readmeFilename: version.readmeFilename || '',\n homepage: version.homepage,\n keywords: version.keywords,\n bugs: version.bugs,\n license: version.license,\n // time: {\n // modified: time,\n // },\n versions,\n };\n\n return pkg;\n }\n}\n\n/**\n * Function gets a local info and an info from uplinks and tries to merge it\n exported for unit tests only.\n * @param {*} cacheManifest\n * @param {*} remoteManifest\n */\nexport function mergeVersions(cacheManifest: Manifest, remoteManifest: Manifest): Manifest {\n let _cacheManifest = { ...cacheManifest };\n const { versions, time } = remoteManifest;\n // copy new versions to a cache\n // NOTE: if a certain version was updated, we can't refresh it reliably\n // however, we can refresh the deprecated status\n for (const i in versions) {\n if (typeof _cacheManifest.versions[i] === 'undefined') {\n _cacheManifest.versions[i] = versions[i];\n } else if (versions[i].deprecated) {\n _cacheManifest.versions[i].deprecated = versions[i].deprecated;\n }\n }\n\n for (const i in time) {\n if (typeof _cacheManifest.time[i] === 'undefined') {\n _cacheManifest.time[i] = time[i];\n }\n }\n\n for (const distTag in remoteManifest[DIST_TAGS]) {\n if (_cacheManifest[DIST_TAGS][distTag] !== remoteManifest[DIST_TAGS][distTag]) {\n if (\n !_cacheManifest[DIST_TAGS][distTag] ||\n semver.lte(_cacheManifest[DIST_TAGS][distTag], remoteManifest[DIST_TAGS][distTag])\n ) {\n _cacheManifest[DIST_TAGS][distTag] = remoteManifest[DIST_TAGS][distTag];\n }\n if (\n distTag === 'latest' &&\n _cacheManifest[DIST_TAGS][distTag] === remoteManifest[DIST_TAGS][distTag]\n ) {\n // NOTE: this override the latest publish readme from local cache with\n // the remote one\n _cacheManifest = { ..._cacheManifest, readme: remoteManifest.readme };\n }\n }\n }\n return _cacheManifest;\n}\n\n/**\n * Normalize dist-tags.\n *\n * There is a legacy behaviour where the dist-tags could be an array, in such\n * case, the array is orderded and the highest version becames the\n * latest.\n *\n * The dist-tag tags must be plain strigs, if the latest is empty (for whatever reason) is\n * normalized to be the highest version available.\n *\n * This function cleans up every invalid version on dist-tags, but does not remove\n * invalid versions from the manifest.\n *\n * @param {*} data\n */\nexport function normalizeDistTags(manifest: Manifest): Manifest {\n let sorted;\n // handle missing latest dist-tag\n if (!manifest[DIST_TAGS].latest) {\n // if there is no latest tag, set the highest known version based on semver sort\n sorted = sortVersionsAndFilterInvalid(Object.keys(manifest.versions));\n if (sorted?.length) {\n // get the highest published version\n manifest[DIST_TAGS].latest = sorted.pop();\n }\n }\n\n for (const tag in manifest[DIST_TAGS]) {\n // deprecated (will be removed un future majors)\n // this should not happen, tags should be plain strings, legacy fallback\n if (Array.isArray(manifest[DIST_TAGS][tag])) {\n if (manifest[DIST_TAGS][tag].length) {\n // sort array\n // FIXME: this is clearly wrong, we need to research why this is like this.\n // @ts-ignore\n sorted = sortVersionsAndFilterInvalid(manifest[DIST_TAGS][tag]);\n if (sorted.length) {\n // use highest version based on semver sort\n manifest[DIST_TAGS][tag] = sorted.pop();\n }\n } else {\n delete manifest[DIST_TAGS][tag];\n }\n } else if (typeof manifest[DIST_TAGS][tag] === 'string') {\n if (!semver.parse(manifest[DIST_TAGS][tag], true)) {\n // if the version is invalid, delete the dist-tag entry\n delete manifest[DIST_TAGS][tag];\n }\n }\n }\n\n return manifest;\n}\n\nexport function hasDeprecatedVersions(pkgInfo: Manifest): boolean {\n const { versions } = pkgInfo;\n for (const version in versions) {\n if (Object.prototype.hasOwnProperty.call(versions[version], 'deprecated')) {\n return true;\n }\n }\n return false;\n}\n\nexport function isDeprecatedManifest(manifest: Manifest): boolean {\n return (\n hasDeprecatedVersions(manifest) &&\n (typeof manifest._attachments === 'undefined' ||\n Object.keys(manifest._attachments).length === 0)\n );\n}\n\nexport function mapManifestToSearchPackageBody(\n pkg: Manifest,\n searchItem: searchUtils.SearchItem\n): searchUtils.SearchPackageBody {\n const latest = pkgUtils.getLatest(pkg);\n const version: Version = pkg.versions[latest];\n const result: searchUtils.SearchPackageBody = {\n name: version.name,\n scope: '',\n description: version.description,\n version: latest,\n keywords: version.keywords,\n date: pkg.time[latest],\n // FIXME: type\n author: version.author as any,\n // FIXME: not possible fill this out from a private package\n publisher: {},\n // FIXME: type\n maintainers: version.maintainers as any,\n links: {\n npm: '',\n homepage: version.homepage,\n repository: version.repository,\n bugs: version.bugs,\n },\n };\n\n if (typeof searchItem.package.scoped === 'string') {\n result.scope = searchItem.package.scoped;\n }\n\n return result;\n}\n\nexport function normalizeContributors(contributors: Author[]): Author[] {\n if (isNil(contributors)) {\n return [];\n } else if (contributors && !Array.isArray(contributors)) {\n return [contributors];\n } else if (typeof contributors === 'string') {\n return [\n {\n name: contributors,\n },\n ];\n }\n\n return contributors;\n}\n"],"mappings":";;;;;AAmBA,IAAa,UAAU;CACrB,mBAAmB;CACnB,kBAAkB;CACl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aAAa,QAAQ;EACrB,SAAS;EACT,UAAU,QAAQ;EAClB,MAAM,IAAI,KAAK;EAEf,QAAQ,QAAQ;EAEhB,WAAW,CAAC;EAEZ,aAAa,QAAQ;EACrB,OAAO;GACL,KAAK;GACL,UAAU,QAAQ;GAClB,YAAY,QAAQ;GACpB,MAAM,QAAQ;EAChB;CACF;CAEA,IAAI,OAAO,WAAW,QAAQ,WAAW,UACvC,OAAO,QAAQ,WAAW,QAAQ;CAGpC,OAAO;AACT;AAEA,SAAgB,sBAAsB,cAAkC;CACtE,IAAI,MAAM,YAAY,GACpB,OAAO,CAAC;MACH,IAAI,gBAAgB,CAAC,MAAM,QAAQ,YAAY,GACpD,OAAO,CAAC,YAAY;MACf,IAAI,OAAO,iBAAiB,UACjC,OAAO,CACL,EACE,MAAM,aACR,CACF;CAGF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"versions-utils.js","names":[],"sources":["../../src/lib/versions-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { isNil } from 'lodash-es';\nimport semver, { SemVer } from 'semver';\n\nimport { DIST_TAGS, searchUtils } from '@verdaccio/core';\nimport { Manifest, StringValue, Version, Versions } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:utils');\n\n/**\n * Gets version from a package object taking into account semver weirdness.\n * @return {String} return the semantic version of a package\n */\nexport function getVersion(versions: Versions, version: string): Version | undefined {\n if (!versions) {\n return;\n }\n\n // this condition must allow cast\n if (isNil(versions[version]) === false) {\n return versions[version];\n }\n\n const versionSemver: SemVer | null = semver.parse(version, true);\n if (versionSemver === null) {\n return;\n }\n\n for (const versionItem in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, versionItem)) {\n // @ts-ignore\n if (versionSemver.compare(semver.parse(versionItem, true)) === 0) {\n return versions[versionItem];\n }\n }\n }\n}\n\n/**\n * Function filters out bad semver versions and sorts the array.\n * @return {Array} sorted Array\n */\nexport function sortVersionsAndFilterInvalid(listVersions: string[] /* logger */): string[] {\n return listVersions\n .filter(function (version): boolean {\n if (!semver.parse(version, true)) {\n return false;\n }\n return true;\n })\n .sort(semver.compareLoose)\n .map(String);\n}\n\n/**\n * Create a tag for a package\n * @param {*} data\n * @param {*} version\n * @param {*} tag\n * @return {Boolean} whether a package has been tagged\n * @deprecated\n */\nexport function tagVersion(data: Manifest, version: string, tag: StringValue): boolean {\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n return true;\n }\n return false;\n}\n\n/**\n *\n * @param manifest\n * @param version\n * @param tag\n * @returns\n */\nexport function tagVersionNext(manifest: Manifest, version: string, tag: StringValue): Manifest {\n const data = { ...manifest };\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n }\n return data;\n}\n\n/**\n * Check if the version is newer than the older version.\n * @param newVersion\n * @param oldVersion\n * @returns\n */\nexport function isNewerVersion(newVersion, oldVersion) {\n const comparisonResult = semver.compare(newVersion, oldVersion);\n\n return comparisonResult === 1 || comparisonResult === 0;\n}\n\n/**\n * Remove duplicates from search results.\n * @param {Array} objects\n * @return {Array} filtered array\n */\nexport function removeLowerVersions(objects: searchUtils.SearchPackageItem[]) {\n const versionMap = new Map();\n\n // Iterate through the array and keep the highest version for each name\n objects.forEach((item) => {\n const { name, version } = item.package;\n const key = name;\n\n if (versionMap.has(name) === false || isNewerVersion(version, versionMap.get(name))) {\n debug('keeping %o@%o', name, version);\n versionMap.set(key, version);\n }\n });\n\n // Filter objects based on the version map\n return objects.reduce((acc, item) => {\n const { name, version } = item.package;\n if (\n versionMap.has(name) &&\n versionMap.get(name) === version &&\n acc.find((i) => i.package.name === name) === undefined\n ) {\n debug('adding %o@%o', name, version);\n acc.push(item);\n }\n return acc;\n }, [] as searchUtils.SearchPackageItem[]);\n}\n"],"mappings":";;;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,0BAA0B;;;;;AAMnD,S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M;AAEZ,MAAI,WAAW,IAAI,KAAK,KAAK,SAAS,eAAe,SAAS,WAAW,IAAI,KAAK,CAAC,EAAE;AACnF,WAAM,iBAAiB,MAAM,QAAQ;AACrC,cAAW,IAAI,KAAK,QAAQ;;GAE9B;AAGF,QAAO,QAAQ,QAAQ,KAAK,SAAS;EACnC,MAAM,EAAE,MAAM,YAAY,KAAK;AAC/B,MACE,WAAW,IAAI,KAAK,IACpB,WAAW,IAAI,KAAK,KAAK,WACzB,IAAI,MAAM,MAAM,EAAE,QAAQ,SAAS,KAAK,KAAK,KAAA,GAC7C;AACA,WAAM,gBAAgB,MAAM,QAAQ;AACpC,OAAI,KAAK,KAAK;;AAEhB,SAAO;IACN,EAAE,CAAoC"}
1
+ {"version":3,"file":"versions-utils.js","names":[],"sources":["../../src/lib/versions-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { isNil } from 'lodash-es';\nimport semver, { SemVer } from 'semver';\n\nimport { DIST_TAGS, searchUtils } from '@verdaccio/core';\nimport { Manifest, StringValue, Version, Versions } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:utils');\n\n/**\n * Gets version from a package object taking into account semver weirdness.\n * @return {String} return the semantic version of a package\n */\nexport function getVersion(versions: Versions, version: string): Version | undefined {\n if (!versions) {\n return;\n }\n\n // this condition must allow cast\n if (isNil(versions[version]) === false) {\n return versions[version];\n }\n\n const versionSemver: SemVer | null = semver.parse(version, true);\n if (versionSemver === null) {\n return;\n }\n\n for (const versionItem in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, versionItem)) {\n // @ts-ignore\n if (versionSemver.compare(semver.parse(versionItem, true)) === 0) {\n return versions[versionItem];\n }\n }\n }\n}\n\n/**\n * Function filters out bad semver versions and sorts the array.\n * @return {Array} sorted Array\n */\nexport function sortVersionsAndFilterInvalid(listVersions: string[] /* logger */): string[] {\n return listVersions\n .filter(function (version): boolean {\n if (!semver.parse(version, true)) {\n return false;\n }\n return true;\n })\n .sort(semver.compareLoose)\n .map(String);\n}\n\n/**\n * Create a tag for a package\n * @param {*} data\n * @param {*} version\n * @param {*} tag\n * @return {Boolean} whether a package has been tagged\n * @deprecated\n */\nexport function tagVersion(data: Manifest, version: string, tag: StringValue): boolean {\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n return true;\n }\n return false;\n}\n\n/**\n *\n * @param manifest\n * @param version\n * @param tag\n * @returns\n */\nexport function tagVersionNext(manifest: Manifest, version: string, tag: StringValue): Manifest {\n const data = { ...manifest };\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n }\n return data;\n}\n\n/**\n * Check if the version is newer than the older version.\n * @param newVersion\n * @param oldVersion\n * @returns\n */\nexport function isNewerVersion(newVersion, oldVersion) {\n const comparisonResult = semver.compare(newVersion, oldVersion);\n\n return comparisonResult === 1 || comparisonResult === 0;\n}\n\n/**\n * Remove duplicates from search results.\n * @param {Array} objects\n * @return {Array} filtered array\n */\nexport function removeLowerVersions(objects: searchUtils.SearchPackageItem[]) {\n const versionMap = new Map();\n\n // Iterate through the array and keep the highest version for each name\n objects.forEach((item) => {\n const { name, version } = item.package;\n const key = name;\n\n if (versionMap.has(name) === false || isNewerVersion(version, versionMap.get(name))) {\n debug('keeping %o@%o', name, version);\n versionMap.set(key, version);\n }\n });\n\n // Filter objects based on the version map\n return objects.reduce((acc, item) => {\n const { name, version } = item.package;\n if (\n versionMap.has(name) &&\n versionMap.get(name) === version &&\n acc.find((i) => i.package.name === name) === undefined\n ) {\n debug('adding %o@%o', name, version);\n acc.push(item);\n }\n return acc;\n }, [] as searchUtils.SearchPackageItem[]);\n}\n"],"mappings":";;;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,yBAAyB;;;;;AAMlD,SAAgB,WAAW,UAAoB,SAAsC;CACnF,IAAI,CAAC,UACH;CAIF,KAAA,GAAA,UAAA,OAAU,SAAS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e,SAAS,WAAW,IAAI,IAAI,CAAC,GAAG;GACnF,QAAM,iBAAiB,MAAM,OAAO;GACpC,WAAW,IAAI,KAAK,OAAO;EAC7B;CACF,CAAC;CAGD,OAAO,QAAQ,QAAQ,KAAK,SAAS;EACnC,MAAM,EAAE,MAAM,YAAY,KAAK;EAC/B,IACE,WAAW,IAAI,IAAI,KACnB,WAAW,IAAI,IAAI,MAAM,WACzB,IAAI,MAAM,MAAM,EAAE,QAAQ,SAAS,IAAI,MAAM,KAAA,GAC7C;GACA,QAAM,gBAAgB,MAAM,OAAO;GACnC,IAAI,KAAK,IAAI;EACf;EACA,OAAO;CACT,GAAG,CAAC,CAAoC;AAC1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"versions-utils.mjs","names":[],"sources":["../../src/lib/versions-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { isNil } from 'lodash-es';\nimport semver, { SemVer } from 'semver';\n\nimport { DIST_TAGS, searchUtils } from '@verdaccio/core';\nimport { Manifest, StringValue, Version, Versions } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:utils');\n\n/**\n * Gets version from a package object taking into account semver weirdness.\n * @return {String} return the semantic version of a package\n */\nexport function getVersion(versions: Versions, version: string): Version | undefined {\n if (!versions) {\n return;\n }\n\n // this condition must allow cast\n if (isNil(versions[version]) === false) {\n return versions[version];\n }\n\n const versionSemver: SemVer | null = semver.parse(version, true);\n if (versionSemver === null) {\n return;\n }\n\n for (const versionItem in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, versionItem)) {\n // @ts-ignore\n if (versionSemver.compare(semver.parse(versionItem, true)) === 0) {\n return versions[versionItem];\n }\n }\n }\n}\n\n/**\n * Function filters out bad semver versions and sorts the array.\n * @return {Array} sorted Array\n */\nexport function sortVersionsAndFilterInvalid(listVersions: string[] /* logger */): string[] {\n return listVersions\n .filter(function (version): boolean {\n if (!semver.parse(version, true)) {\n return false;\n }\n return true;\n })\n .sort(semver.compareLoose)\n .map(String);\n}\n\n/**\n * Create a tag for a package\n * @param {*} data\n * @param {*} version\n * @param {*} tag\n * @return {Boolean} whether a package has been tagged\n * @deprecated\n */\nexport function tagVersion(data: Manifest, version: string, tag: StringValue): boolean {\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n return true;\n }\n return false;\n}\n\n/**\n *\n * @param manifest\n * @param version\n * @param tag\n * @returns\n */\nexport function tagVersionNext(manifest: Manifest, version: string, tag: StringValue): Manifest {\n const data = { ...manifest };\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n }\n return data;\n}\n\n/**\n * Check if the version is newer than the older version.\n * @param newVersion\n * @param oldVersion\n * @returns\n */\nexport function isNewerVersion(newVersion, oldVersion) {\n const comparisonResult = semver.compare(newVersion, oldVersion);\n\n return comparisonResult === 1 || comparisonResult === 0;\n}\n\n/**\n * Remove duplicates from search results.\n * @param {Array} objects\n * @return {Array} filtered array\n */\nexport function removeLowerVersions(objects: searchUtils.SearchPackageItem[]) {\n const versionMap = new Map();\n\n // Iterate through the array and keep the highest version for each name\n objects.forEach((item) => {\n const { name, version } = item.package;\n const key = name;\n\n if (versionMap.has(name) === false || isNewerVersion(version, versionMap.get(name))) {\n debug('keeping %o@%o', name, version);\n versionMap.set(key, version);\n }\n });\n\n // Filter objects based on the version map\n return objects.reduce((acc, item) => {\n const { name, version } = item.package;\n if (\n versionMap.has(name) &&\n versionMap.get(name) === version &&\n acc.find((i) => i.package.name === name) === undefined\n ) {\n debug('adding %o@%o', name, version);\n acc.push(item);\n }\n return acc;\n }, [] as searchUtils.SearchPackageItem[]);\n}\n"],"mappings":";;;;;AAOA,IAAM,QAAQ,WAAW,0BAA0B;;;;;AAMnD,SAAgB,WAAW,UAAoB,SAAsC;AACnF,KAAI,CAAC,SACH;AAIF,KAAI,MAAM,SAAS,SAAS,KAAK,MAC/B,QAAO,SAAS;CAGlB,M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AS;EACnC,MAAM,EAAE,MAAM,YAAY,KAAK;AAC/B,MACE,WAAW,IAAI,KAAK,IACpB,WAAW,IAAI,KAAK,KAAK,WACzB,IAAI,MAAM,MAAM,EAAE,QAAQ,SAAS,KAAK,KAAK,KAAA,GAC7C;AACA,SAAM,gBAAgB,MAAM,QAAQ;AACpC,OAAI,KAAK,KAAK;;AAEhB,SAAO;IACN,EAAE,CAAoC"}
1
+ {"version":3,"file":"versions-utils.mjs","names":[],"sources":["../../src/lib/versions-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { isNil } from 'lodash-es';\nimport semver, { SemVer } from 'semver';\n\nimport { DIST_TAGS, searchUtils } from '@verdaccio/core';\nimport { Manifest, StringValue, Version, Versions } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:utils');\n\n/**\n * Gets version from a package object taking into account semver weirdness.\n * @return {String} return the semantic version of a package\n */\nexport function getVersion(versions: Versions, version: string): Version | undefined {\n if (!versions) {\n return;\n }\n\n // this condition must allow cast\n if (isNil(versions[version]) === false) {\n return versions[version];\n }\n\n const versionSemver: SemVer | null = semver.parse(version, true);\n if (versionSemver === null) {\n return;\n }\n\n for (const versionItem in versions) {\n if (Object.prototype.hasOwnProperty.call(versions, versionItem)) {\n // @ts-ignore\n if (versionSemver.compare(semver.parse(versionItem, true)) === 0) {\n return versions[versionItem];\n }\n }\n }\n}\n\n/**\n * Function filters out bad semver versions and sorts the array.\n * @return {Array} sorted Array\n */\nexport function sortVersionsAndFilterInvalid(listVersions: string[] /* logger */): string[] {\n return listVersions\n .filter(function (version): boolean {\n if (!semver.parse(version, true)) {\n return false;\n }\n return true;\n })\n .sort(semver.compareLoose)\n .map(String);\n}\n\n/**\n * Create a tag for a package\n * @param {*} data\n * @param {*} version\n * @param {*} tag\n * @return {Boolean} whether a package has been tagged\n * @deprecated\n */\nexport function tagVersion(data: Manifest, version: string, tag: StringValue): boolean {\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n return true;\n }\n return false;\n}\n\n/**\n *\n * @param manifest\n * @param version\n * @param tag\n * @returns\n */\nexport function tagVersionNext(manifest: Manifest, version: string, tag: StringValue): Manifest {\n const data = { ...manifest };\n if (tag && data[DIST_TAGS][tag] !== version && semver.parse(version, true)) {\n // valid version - store\n data[DIST_TAGS][tag] = version;\n }\n return data;\n}\n\n/**\n * Check if the version is newer than the older version.\n * @param newVersion\n * @param oldVersion\n * @returns\n */\nexport function isNewerVersion(newVersion, oldVersion) {\n const comparisonResult = semver.compare(newVersion, oldVersion);\n\n return comparisonResult === 1 || comparisonResult === 0;\n}\n\n/**\n * Remove duplicates from search results.\n * @param {Array} objects\n * @return {Array} filtered array\n */\nexport function removeLowerVersions(objects: searchUtils.SearchPackageItem[]) {\n const versionMap = new Map();\n\n // Iterate through the array and keep the highest version for each name\n objects.forEach((item) => {\n const { name, version } = item.package;\n const key = name;\n\n if (versionMap.has(name) === false || isNewerVersion(version, versionMap.get(name))) {\n debug('keeping %o@%o', name, version);\n versionMap.set(key, version);\n }\n });\n\n // Filter objects based on the version map\n return objects.reduce((acc, item) => {\n const { name, version } = item.package;\n if (\n versionMap.has(name) &&\n versionMap.get(name) === version &&\n acc.find((i) => i.package.name === name) === undefined\n ) {\n debug('adding %o@%o', name, version);\n acc.push(item);\n }\n return acc;\n }, [] as searchUtils.SearchPackageItem[]);\n}\n"],"mappings":";;;;;AAOA,IAAM,QAAQ,WAAW,yBAAyB;;;;;AAMlD,SAAgB,WAAW,UAAoB,SAAsC;CACnF,IAAI,CAAC,UACH;CAIF,IAAI,MAAM,SAAS,QAAQ,MAAM,OAC/B,OAAO,SAAS;CAGlB,MAAM,gBAA+B,OAAO,MAAM,SAAS,IAAI;CAC/D,IAAI,kBAAkB,MACpB;CAGF,KAAK,MAAM,eAAe,UACxB,IAAI,OAAO,UAAU,eAAe,KAAK,UAAU,WAAW;MAExD,cAAc,QAAQ,OAAO,MAAM,aAAa,IAAI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AAS,IAAI,MAAM,KAAA,GAC7C;GACA,MAAM,gBAAgB,MAAM,OAAO;GACnC,IAAI,KAAK,IAAI;EACf;EACA,OAAO;CACT,GAAG,CAAC,CAAoC;AAC1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.js","names":[],"sources":["../src/local-storage.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { head, isNil } from 'lodash-es';\nimport assert from 'node:assert';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport {\n PLUGIN_CATEGORY,\n PLUGIN_PREFIX,\n errorUtils,\n pluginUtils as pluginSanity,\n} from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabase from '@verdaccio/local-storage';\nimport type { Config, Logger } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:local');\n\nexport const noSuchFile = 'ENOENT';\nexport const resourceNotAvailable = 'EAGAIN';\nexport type PluginStorage = pluginUtils.Storage<Config>;\n\n/**\n * Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).\n */\nclass LocalStorage {\n public config: Config;\n public storagePlugin: PluginStorage;\n public logger: Logger;\n\n public constructor(config: Config, logger: Logger) {\n debug('local storage created');\n this.logger = logger.child({ sub: 'fs' });\n this.config = config;\n // @ts-expect-error\n this.storagePlugin = null;\n }\n\n public async init() {\n if (this.storagePlugin === null) {\n this.storagePlugin = await this.loadStorage(this.config, this.logger);\n debug('storage plugin init');\n await this.storagePlugin.init();\n debug('storage plugin initialized');\n } else {\n this.logger.warn('storage plugin has been already initialized');\n }\n return;\n }\n\n public getStoragePlugin(): PluginStorage {\n if (this.storagePlugin === null) {\n throw errorUtils.getInternalError('storage plugin is not initialized');\n }\n\n return this.storagePlugin;\n }\n\n public async getSecret(config: Config): Promise<void> {\n const secretKey = await this.storagePlugin.getSecret();\n\n return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));\n }\n\n private async loadStorage(config: Config, logger: Logger): Promise<PluginStorage> {\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 const localStorage = new LocalDatabase(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 PluginStorage;\n }\n\n private async loadStorePlugin(): Promise<PluginStorage | undefined> {\n const plugins: PluginStorage[] = await asyncLoadPlugin<pluginUtils.Storage<unknown>>(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n pluginSanity.storageSanityCheck,\n false,\n this.config.server?.pluginPrefix ?? PLUGIN_PREFIX,\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\nexport { LocalStorage };\n"],"mappings":";;;;;;;;;;;AAeA,IAAM,WAAA,GAAA,MAAA,SAAmB,0BAA0B;;;;AASnD,IAAM,eAAN,MAAmB;CACjB;CACA;CACA;CAEA,YAAmB,QAAgB,QAAgB;AACjD,UAAM,wBAAwB;AAC9B,OAAK,SAAS,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;AACzC,OAAK,SAAS;AAEd,OAAK,gBAAgB;;CAGvB,MAAa,OAAO;AAClB,MAAI,KAAK,kBAAkB,MAAM;AAC/B,QAAK,gBAAgB,MAAM,KAAK,YAAY,KAAK,QAAQ,KAAK,OAAO;AACrE,WAAM,sBAAsB;AAC5B,SAAM,KAAK,cAAc,MAAM;AAC/B,WAAM,6BAA6B;QAEnC,MAAK,OAAO,KAAK,8CAA8C;;CAKnE,mBAAyC;AACvC,MAAI,KAAK,kBAAkB,KACzB,OAAM,gBAAA,WAAW,iBAAiB,oCAAoC;AAGxE,SAAO,KAAK;;CAGd,MAAa,UAAU,QAA+B;EACpD,MAAM,YAAY,MAAM,KAAK,cAAc,WAAW;AAEtD,SAAO,KAAK,cAAc,UAAU,OAAO,eAAe,UAAU,CAAC;;CAGvE,MAAc,YAAY,QAAgB,QAAwC;EAChF,MAAM,UAAU,MAAM,KAAK,iBAAiB;AAC5C,OAAA,GAAA,UAAA,OAAU,QAAQ,EAAE;AAClB,IAAA,GAAA,YAAA,SAAO,KAAK,OAAO,SAAS,mCAAmC;AAC/D,WAAM,4EAA4E;GAClF,MAAM,eAAe,IAAI,yBAAA,QAAc,QAAQ,OAAO;AACtD,UAAO,KACL;IAAE,MAAM;IAA4B,gBAAgB,gBAAA,gBAAgB;IAAS,EAC7E,yDACD;AACD,UAAO;;AAET,SAAO;;CAGT,MAAc,kBAAsD;EAClE,MAAM,UAA2B,OAAA,GAAA,mBAAA,iBAC/B,KAAK,OAAO,OACZ;GACE,QAAQ,KAAK;GACb,QAAQ,KAAK;GACd,EACD,gBAAA,YAAa,oBACb,OACA,KAAK,OAAO,QAAQ,gBAAgB,gBAAA,eACpC,gBAAA,gBAAgB,QACjB;AAED,MAAI,QAAQ,SAAS,EACnB,MAAK,OAAO,KACV,0HACD;AAGH,UAAA,GAAA,UAAA,MAAY,QAAQ"}
1
+ {"version":3,"file":"local-storage.js","names":[],"sources":["../src/local-storage.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { head, isNil } from 'lodash-es';\nimport assert from 'node:assert';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport {\n PLUGIN_CATEGORY,\n PLUGIN_PREFIX,\n errorUtils,\n pluginUtils as pluginSanity,\n} from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabase from '@verdaccio/local-storage';\nimport type { Config, Logger } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:local');\n\nexport const noSuchFile = 'ENOENT';\nexport const resourceNotAvailable = 'EAGAIN';\nexport type PluginStorage = pluginUtils.Storage<Config>;\n\n/**\n * Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).\n */\nclass LocalStorage {\n public config: Config;\n public storagePlugin: PluginStorage;\n public logger: Logger;\n\n public constructor(config: Config, logger: Logger) {\n debug('local storage created');\n this.logger = logger.child({ sub: 'fs' });\n this.config = config;\n // @ts-expect-error\n this.storagePlugin = null;\n }\n\n public async init() {\n if (this.storagePlugin === null) {\n this.storagePlugin = await this.loadStorage(this.config, this.logger);\n debug('storage plugin init');\n await this.storagePlugin.init();\n debug('storage plugin initialized');\n } else {\n this.logger.warn('storage plugin has been already initialized');\n }\n return;\n }\n\n public getStoragePlugin(): PluginStorage {\n if (this.storagePlugin === null) {\n throw errorUtils.getInternalError('storage plugin is not initialized');\n }\n\n return this.storagePlugin;\n }\n\n public async getSecret(config: Config): Promise<void> {\n const secretKey = await this.storagePlugin.getSecret();\n\n return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));\n }\n\n private async loadStorage(config: Config, logger: Logger): Promise<PluginStorage> {\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 const localStorage = new LocalDatabase(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 PluginStorage;\n }\n\n private async loadStorePlugin(): Promise<PluginStorage | undefined> {\n const plugins: PluginStorage[] = await asyncLoadPlugin<pluginUtils.Storage<unknown>>(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n pluginSanity.storageSanityCheck,\n false,\n this.config.server?.pluginPrefix ?? PLUGIN_PREFIX,\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\nexport { LocalStorage };\n"],"mappings":";;;;;;;;;;;AAeA,IAAM,WAAA,GAAA,MAAA,S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,gBAAgB,OAClB;EAEA,IAAI,QAAQ,SAAS,GACnB,KAAK,OAAO,KACV,yHACF;EAGF,QAAA,GAAA,UAAA,MAAY,OAAO;CACrB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.mjs","names":[],"sources":["../src/local-storage.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { head, isNil } from 'lodash-es';\nimport assert from 'node:assert';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport {\n PLUGIN_CATEGORY,\n PLUGIN_PREFIX,\n errorUtils,\n pluginUtils as pluginSanity,\n} from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabase from '@verdaccio/local-storage';\nimport type { Config, Logger } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:local');\n\nexport const noSuchFile = 'ENOENT';\nexport const resourceNotAvailable = 'EAGAIN';\nexport type PluginStorage = pluginUtils.Storage<Config>;\n\n/**\n * Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).\n */\nclass LocalStorage {\n public config: Config;\n public storagePlugin: PluginStorage;\n public logger: Logger;\n\n public constructor(config: Config, logger: Logger) {\n debug('local storage created');\n this.logger = logger.child({ sub: 'fs' });\n this.config = config;\n // @ts-expect-error\n this.storagePlugin = null;\n }\n\n public async init() {\n if (this.storagePlugin === null) {\n this.storagePlugin = await this.loadStorage(this.config, this.logger);\n debug('storage plugin init');\n await this.storagePlugin.init();\n debug('storage plugin initialized');\n } else {\n this.logger.warn('storage plugin has been already initialized');\n }\n return;\n }\n\n public getStoragePlugin(): PluginStorage {\n if (this.storagePlugin === null) {\n throw errorUtils.getInternalError('storage plugin is not initialized');\n }\n\n return this.storagePlugin;\n }\n\n public async getSecret(config: Config): Promise<void> {\n const secretKey = await this.storagePlugin.getSecret();\n\n return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));\n }\n\n private async loadStorage(config: Config, logger: Logger): Promise<PluginStorage> {\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 const localStorage = new LocalDatabase(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 PluginStorage;\n }\n\n private async loadStorePlugin(): Promise<PluginStorage | undefined> {\n const plugins: PluginStorage[] = await asyncLoadPlugin<pluginUtils.Storage<unknown>>(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n pluginSanity.storageSanityCheck,\n false,\n this.config.server?.pluginPrefix ?? PLUGIN_PREFIX,\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\nexport { LocalStorage };\n"],"mappings":";;;;;;;AAeA,IAAM,QAAQ,WAAW,0BAA0B;;;;AASnD,IAAM,eAAN,MAAmB;CACjB;CACA;CACA;CAEA,YAAmB,QAAgB,QAAgB;AACjD,QAAM,wBAAwB;AAC9B,OAAK,SAAS,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;AACzC,OAAK,SAAS;AAEd,OAAK,gBAAgB;;CAGvB,MAAa,OAAO;AAClB,MAAI,KAAK,kBAAkB,MAAM;AAC/B,QAAK,gBAAgB,MAAM,KAAK,YAAY,KAAK,QAAQ,KAAK,OAAO;AACrE,SAAM,sBAAsB;AAC5B,SAAM,KAAK,cAAc,MAAM;AAC/B,SAAM,6BAA6B;QAEnC,MAAK,OAAO,KAAK,8CAA8C;;CAKnE,mBAAyC;AACvC,MAAI,KAAK,kBAAkB,KACzB,OAAM,WAAW,iBAAiB,oCAAoC;AAGxE,SAAO,KAAK;;CAGd,MAAa,UAAU,QAA+B;EACpD,MAAM,YAAY,MAAM,KAAK,cAAc,WAAW;AAEtD,SAAO,KAAK,cAAc,UAAU,OAAO,eAAe,UAAU,CAAC;;CAGvE,MAAc,YAAY,QAAgB,QAAwC;EAChF,MAAM,UAAU,MAAM,KAAK,iBAAiB;AAC5C,MAAI,MAAM,QAAQ,EAAE;AAClB,UAAO,KAAK,OAAO,SAAS,mCAAmC;AAC/D,SAAM,4EAA4E;GAClF,MAAM,eAAe,IAAI,cAAc,QAAQ,OAAO;AACtD,UAAO,KACL;IAAE,MAAM;IAA4B,gBAAgB,gBAAgB;IAAS,EAC7E,yDACD;AACD,UAAO;;AAET,SAAO;;CAGT,MAAc,kBAAsD;EAClE,MAAM,UAA2B,MAAM,gBACrC,KAAK,OAAO,OACZ;GACE,QAAQ,KAAK;GACb,QAAQ,KAAK;GACd,EACD,YAAa,oBACb,OACA,KAAK,OAAO,QAAQ,gBAAgB,eACpC,gBAAgB,QACjB;AAED,MAAI,QAAQ,SAAS,EACnB,MAAK,OAAO,KACV,0HACD;AAGH,SAAO,KAAK,QAAQ"}
1
+ {"version":3,"file":"local-storage.mjs","names":[],"sources":["../src/local-storage.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { head, isNil } from 'lodash-es';\nimport assert from 'node:assert';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport {\n PLUGIN_CATEGORY,\n PLUGIN_PREFIX,\n errorUtils,\n pluginUtils as pluginSanity,\n} from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport LocalDatabase from '@verdaccio/local-storage';\nimport type { Config, Logger } from '@verdaccio/types';\n\nconst debug = buildDebug('verdaccio:storage:local');\n\nexport const noSuchFile = 'ENOENT';\nexport const resourceNotAvailable = 'EAGAIN';\nexport type PluginStorage = pluginUtils.Storage<Config>;\n\n/**\n * Implements Storage interface (same for storage.js, local-storage.js, up-storage.js).\n */\nclass LocalStorage {\n public config: Config;\n public storagePlugin: PluginStorage;\n public logger: Logger;\n\n public constructor(config: Config, logger: Logger) {\n debug('local storage created');\n this.logger = logger.child({ sub: 'fs' });\n this.config = config;\n // @ts-expect-error\n this.storagePlugin = null;\n }\n\n public async init() {\n if (this.storagePlugin === null) {\n this.storagePlugin = await this.loadStorage(this.config, this.logger);\n debug('storage plugin init');\n await this.storagePlugin.init();\n debug('storage plugin initialized');\n } else {\n this.logger.warn('storage plugin has been already initialized');\n }\n return;\n }\n\n public getStoragePlugin(): PluginStorage {\n if (this.storagePlugin === null) {\n throw errorUtils.getInternalError('storage plugin is not initialized');\n }\n\n return this.storagePlugin;\n }\n\n public async getSecret(config: Config): Promise<void> {\n const secretKey = await this.storagePlugin.getSecret();\n\n return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));\n }\n\n private async loadStorage(config: Config, logger: Logger): Promise<PluginStorage> {\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 const localStorage = new LocalDatabase(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 PluginStorage;\n }\n\n private async loadStorePlugin(): Promise<PluginStorage | undefined> {\n const plugins: PluginStorage[] = await asyncLoadPlugin<pluginUtils.Storage<unknown>>(\n this.config.store,\n {\n config: this.config,\n logger: this.logger,\n },\n pluginSanity.storageSanityCheck,\n false,\n this.config.server?.pluginPrefix ?? PLUGIN_PREFIX,\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\nexport { LocalStorage };\n"],"mappings":";;;;;;;AAeA,IAAM,QAAQ,WAAW,yBAAyB;;;;AASlD,IAAM,eAAN,MAAmB;CACjB;CACA;CACA;CAEA,YAAmB,QAAgB,QAAgB;EACjD,MAAM,uBAAuB;EAC7B,KAAK,SAAS,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EACxC,KAAK,SAAS;EAEd,KAAK,gBAAgB;CACvB;CAEA,MAAa,OAAO;EAClB,IAAI,KAAK,kBAAkB,MAAM;GAC/B,KAAK,gBAAgB,MAAM,KAAK,YAAY,KAAK,QAAQ,KAAK,MAAM;GACpE,MAAM,qBAAqB;GAC3B,MAAM,KAAK,cAAc,KAAK;GAC9B,MAAM,4BAA4B;EACpC,OACE,KAAK,OAAO,KAAK,6CAA6C;CAGlE;CAEA,mBAAyC;EACvC,IAAI,KAAK,kBAAkB,MACzB,MAAM,WAAW,iBAAiB,mCAAmC;EAGvE,OAAO,KAAK;CACd;CAEA,MAAa,UAAU,QAA+B;EACpD,MAAM,YAAY,MAAM,KAAK,cAAc,UAAU;EAErD,OAAO,KAAK,cAAc,UAAU,OAAO,eAAe,SAAS,CAAC;CACtE;CAEA,MAAc,YAAY,QAAgB,QAAwC;EAChF,MAAM,UAAU,MAAM,KAAK,gBAAgB;EAC3C,IAAI,MAAM,OAAO,GAAG;GAClB,OAAO,KAAK,OAAO,SAAS,kCAAkC;GAC9D,MAAM,2EAA2E;GACjF,MAAM,eAAe,IAAI,cAAc,QAAQ,MAAM;GACrD,OAAO,KACL;IAAE,MAAM;IAA4B,gBAAgB,gBAAgB;GAAQ,GAC5E,wDACF;GACA,OAAO;EACT;EACA,OAAO;CACT;CAEA,MAAc,kBAAsD;EAClE,MAAM,UAA2B,MAAM,gBACrC,KAAK,OAAO,OACZ;GACE,QAAQ,KAAK;GACb,QAAQ,KAAK;EACf,GACA,YAAa,oBACb,OACA,KAAK,OAAO,QAAQ,gBAAgB,eACpC,gBAAgB,OAClB;EAEA,IAAI,QAAQ,SAAS,GACnB,KAAK,OAAO,KACV,yHACF;EAGF,OAAO,KAAK,OAAO;CACrB;AACF"}
@@ -5,7 +5,7 @@ import { AbbreviatedManifest, Config, Logger, Manifest, MergeTags, Token, TokenF
5
5
  import { UpdateManifestOptions } from '.';
6
6
  import { Filters } from './filter-pipeline';
7
7
  import { LocalStorage } from './local-storage';
8
- import { IGetPackageOptionsNext, OwnerManifestBody, StarManifestBody } from './type';
8
+ import { IGetPackageOptionsNext, OwnerManifestBody } from './type';
9
9
  export declare const noSuchFile = "ENOENT";
10
10
  export declare const resourceNotAvailable = "EAGAIN";
11
11
  export declare const PROTO_NAME = "__proto__";
@@ -110,9 +110,8 @@ declare class Storage {
110
110
  */
111
111
  mergeTagsNext(name: string, tags: MergeTags): Promise<Manifest>;
112
112
  private getUpLinkForDistFile;
113
- updateManifest(manifest: Manifest | StarManifestBody | OwnerManifestBody | UnPublishManifest, options: UpdateManifestOptions): Promise<string | undefined>;
113
+ updateManifest(manifest: Manifest | OwnerManifestBody | UnPublishManifest, options: UpdateManifestOptions): Promise<string | undefined>;
114
114
  private deprecate;
115
- private star;
116
115
  private unPublishAPackage;
117
116
  private changeOwners;
118
117
  /**
package/build/storage.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const require_runtime = require("./_virtual/_rolldown/runtime.js");
2
2
  const require_filter_pipeline = require("./filter-pipeline.js");
3
- const require_star_utils = require("./lib/star-utils.js");
3
+ const require_publish_utils = require("./lib/publish-utils.js");
4
4
  const require_versions_utils = require("./lib/versions-utils.js");
5
5
  const require_storage_utils = require("./lib/storage-utils.js");
6
6
  const require_local_storage = require("./local-storage.js");
@@ -604,11 +604,7 @@ var Storage = class {
604
604
  if (require_storage_utils.isDeprecatedManifest(manifest)) {
605
605
  debug$1("update manifest deprecate");
606
606
  await this.deprecate(manifest, { ...options });
607
- } else if (require_star_utils.isPublishablePackage(manifest) === false && _verdaccio_core.validationUtils.isObject(manifest.users)) {
608
- debug$1("update manifest star");
609
- await this.star(manifest, { ...options });
610
- return _verdaccio_core.API_MESSAGE.PKG_CHANGED;
611
- } else if (require_star_utils.isPublishablePackage(manifest) === false && Array.isArray(manifest.maintainers)) {
607
+ } else if (require_publish_utils.isPublishablePackage(manifest) === false && Array.isArray(manifest.maintainers)) {
612
608
  debug$1("update manifest owners");
613
609
  await this.changeOwners(manifest, { ...options });
614
610
  return _verdaccio_core.API_MESSAGE.PKG_CHANGED;
@@ -640,33 +636,6 @@ var Storage = class {
640
636
  debug$1("deprecating %s", name);
641
637
  return this.changePackage(name, manifest, options.revision);
642
638
  }
643
- async star(manifest, options) {
644
- const { users } = manifest;
645
- const { requestOptions, name } = options;
646
- debug$1("star %s", name);
647
- const { username } = requestOptions;
648
- if (!username) throw _verdaccio_core.errorUtils.getBadRequest("update users only allowed to logged users");
649
- const localPackage = await this.getPackageManifest({
650
- name,
651
- requestOptions,
652
- uplinksLook: false
653
- });
654
- const localStarUsers = localPackage.users || {};
655
- const userIsAddingStar = Object.keys(users).includes(username);
656
- if (!require_star_utils.isExecutingStarCommand(localPackage?.users, username, userIsAddingStar)) return _verdaccio_core.API_MESSAGE.PKG_CHANGED;
657
- const newUsers = userIsAddingStar ? {
658
- ...localStarUsers,
659
- [username]: true
660
- } : (0, lodash_es.reduce)(localStarUsers, (users, value, key) => {
661
- if (key !== username) users[key] = value;
662
- return users;
663
- }, {});
664
- await this.changePackage(name, {
665
- ...localPackage,
666
- users: newUsers
667
- }, options.revision);
668
- return _verdaccio_core.API_MESSAGE.PKG_CHANGED;
669
- }
670
639
  async unPublishAPackage(manifest, options) {
671
640
  const { requestOptions, name } = options;
672
641
  debug$1("unpublish a package of %o", name);