@verdaccio/package-filter 13.0.5 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/_rolldown/runtime.js +23 -0
- package/build/config/parser.d.ts +2 -0
- package/build/config/parser.js +56 -0
- package/build/config/parser.js.map +1 -0
- package/build/config/parser.mjs +54 -0
- package/build/config/parser.mjs.map +1 -0
- package/build/config/types.d.ts +39 -0
- package/build/filtering/matcher.d.ts +8 -0
- package/build/filtering/matcher.js +71 -0
- package/build/filtering/matcher.js.map +1 -0
- package/build/filtering/matcher.mjs +69 -0
- package/build/filtering/matcher.mjs.map +1 -0
- package/build/filtering/packageVersion.d.ts +20 -0
- package/build/filtering/packageVersion.js +129 -0
- package/build/filtering/packageVersion.js.map +1 -0
- package/build/filtering/packageVersion.mjs +127 -0
- package/build/filtering/packageVersion.mjs.map +1 -0
- package/build/filtering/publishDate.d.ts +6 -0
- package/build/filtering/publishDate.js +33 -0
- package/build/filtering/publishDate.js.map +1 -0
- package/build/filtering/publishDate.mjs +31 -0
- package/build/filtering/publishDate.mjs.map +1 -0
- package/build/filtering/types.d.ts +24 -0
- package/build/filtering/types.js +11 -0
- package/build/filtering/types.js.map +1 -0
- package/build/filtering/types.mjs +11 -0
- package/build/filtering/types.mjs.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +3 -490
- package/build/index.js.map +1 -1
- package/build/index.mjs +7 -0
- package/build/index.mjs.map +1 -0
- package/build/packageFilter.d.ts +10 -0
- package/build/packageFilter.js +86 -0
- package/build/packageFilter.js.map +1 -0
- package/build/packageFilter.mjs +84 -0
- package/build/packageFilter.mjs.map +1 -0
- package/build/utils/jsonUtils.d.ts +1 -0
- package/build/utils/jsonUtils.js +11 -0
- package/build/utils/jsonUtils.js.map +1 -0
- package/build/utils/jsonUtils.mjs +11 -0
- package/build/utils/jsonUtils.mjs.map +1 -0
- package/build/utils/manifestUtils.d.ts +36 -0
- package/build/utils/manifestUtils.js +129 -0
- package/build/utils/manifestUtils.js.map +1 -0
- package/build/utils/manifestUtils.mjs +121 -0
- package/build/utils/manifestUtils.mjs.map +1 -0
- package/package.json +25 -10
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { MatchType } from "./types.mjs";
|
|
2
|
+
import { matchRules } from "./matcher.mjs";
|
|
3
|
+
import buildDebug from "debug";
|
|
4
|
+
import { Range, satisfies } from "semver";
|
|
5
|
+
//#region src/filtering/packageVersion.ts
|
|
6
|
+
var debug = buildDebug("verdaccio:plugin:package-filter:filter");
|
|
7
|
+
/**
|
|
8
|
+
* Filter out all blocked package versions.
|
|
9
|
+
* If package or scope is blocked, then block all versions.
|
|
10
|
+
*
|
|
11
|
+
* TODO: consider adding a `prerelease` filter option to block/allow
|
|
12
|
+
* prerelease versions independently. Currently prereleases are matched by
|
|
13
|
+
* semver ranges with `includePrerelease: true`, but there's no dedicated toggle.
|
|
14
|
+
*
|
|
15
|
+
* Example config (not yet implemented):
|
|
16
|
+
* block:
|
|
17
|
+
* - package: 'foo'
|
|
18
|
+
* prerelease: true # block 1.0.0-beta.1, 2.0.0-rc.1, keep 1.0.0, 2.0.0
|
|
19
|
+
* - package: 'bar'
|
|
20
|
+
* prerelease: false # block 1.0.0, 2.0.0, keep 1.0.0-beta.1
|
|
21
|
+
*
|
|
22
|
+
* Today the only workaround is using awkward ranges like ">=1.0.0-0 <1.0.0".
|
|
23
|
+
*/
|
|
24
|
+
function filterBlockedVersions(manifest, blockRules, allowRules, logger) {
|
|
25
|
+
const allowMatch = matchRules(manifest, allowRules);
|
|
26
|
+
if (allowMatch && (allowMatch.type === MatchType.SCOPE || allowMatch.type === MatchType.PACKAGE)) {
|
|
27
|
+
logger.trace({ name: manifest.name }, "package @{name} is allow-listed, skipping block rules");
|
|
28
|
+
return manifest;
|
|
29
|
+
}
|
|
30
|
+
const blockMatch = matchRules(manifest, blockRules);
|
|
31
|
+
if (!blockMatch) return manifest;
|
|
32
|
+
logger.trace({
|
|
33
|
+
name: manifest.name,
|
|
34
|
+
type: blockMatch.type
|
|
35
|
+
}, "block rule matched for @{name} (type: @{type})");
|
|
36
|
+
const whitelistedVersions = allowMatch ? allowMatch.versions : [];
|
|
37
|
+
let blockRule = {
|
|
38
|
+
versions: [new Range("*")],
|
|
39
|
+
strategy: "block"
|
|
40
|
+
};
|
|
41
|
+
if (blockMatch.type === MatchType.SCOPE) {
|
|
42
|
+
if (whitelistedVersions.length === 0) {
|
|
43
|
+
debug("blocking all versions of %s (scope %s blocked)", manifest.name, blockMatch.scope);
|
|
44
|
+
logger.trace({
|
|
45
|
+
name: manifest.name,
|
|
46
|
+
scope: blockMatch.scope
|
|
47
|
+
}, "all versions of @{name} blocked (scope @{scope})");
|
|
48
|
+
return {
|
|
49
|
+
...manifest,
|
|
50
|
+
versions: {},
|
|
51
|
+
readme: `All packages in scope ${blockMatch.scope} are blocked by rule`
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
} else if (blockMatch.type === MatchType.PACKAGE) {
|
|
55
|
+
if (whitelistedVersions.length === 0) {
|
|
56
|
+
debug("blocking all versions of %s (package blocked)", manifest.name);
|
|
57
|
+
logger.trace({ name: manifest.name }, "all versions of @{name} blocked (package rule)");
|
|
58
|
+
return {
|
|
59
|
+
...manifest,
|
|
60
|
+
versions: {},
|
|
61
|
+
readme: `All package versions are blocked by rule`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
} else blockRule = {
|
|
65
|
+
...blockRule,
|
|
66
|
+
...blockMatch.rule
|
|
67
|
+
};
|
|
68
|
+
const versionRanges = blockRule.versions;
|
|
69
|
+
if (blockRule.strategy === "block") {
|
|
70
|
+
const blockedVersions = blockMatch.versions.filter((v) => !whitelistedVersions.includes(v));
|
|
71
|
+
for (const version of blockedVersions) delete manifest.versions[version];
|
|
72
|
+
if (blockedVersions.length > 0) {
|
|
73
|
+
debug("blocked %d versions of %s: %o", blockedVersions.length, manifest.name, blockedVersions);
|
|
74
|
+
logger.trace({
|
|
75
|
+
name: manifest.name,
|
|
76
|
+
count: blockedVersions.length,
|
|
77
|
+
versions: blockedVersions.join(", ")
|
|
78
|
+
}, "@{count} versions of @{name} blocked: @{versions}");
|
|
79
|
+
manifest.readme = (manifest.readme || "") + `\nSome versions(${blockedVersions.length}) of package are blocked by rules: ${versionRanges.map((range) => range.raw)}`;
|
|
80
|
+
}
|
|
81
|
+
return manifest;
|
|
82
|
+
}
|
|
83
|
+
const nonBlockedVersions = { ...manifest.versions };
|
|
84
|
+
const newVersionsMapping = {};
|
|
85
|
+
versionRanges.forEach((versionRange) => {
|
|
86
|
+
const allVersions = Object.keys(nonBlockedVersions);
|
|
87
|
+
let lastNonBlockedVersion = null;
|
|
88
|
+
allVersions.forEach((version) => {
|
|
89
|
+
if (!whitelistedVersions.includes(version) && satisfies(version, versionRange, {
|
|
90
|
+
includePrerelease: true,
|
|
91
|
+
loose: true
|
|
92
|
+
})) {
|
|
93
|
+
delete nonBlockedVersions[version];
|
|
94
|
+
newVersionsMapping[version] = lastNonBlockedVersion;
|
|
95
|
+
} else lastNonBlockedVersion = version;
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
debug("replacing versions for %s: %o", manifest.name, newVersionsMapping);
|
|
99
|
+
const removedVersions = Object.entries(newVersionsMapping).filter(([_, replace]) => replace === null);
|
|
100
|
+
const replacedVersions = Object.entries(newVersionsMapping).filter(([_, replace]) => replace !== null);
|
|
101
|
+
removedVersions.forEach(([version]) => {
|
|
102
|
+
debug("no version to replace %s in %s", version, manifest.name);
|
|
103
|
+
logger.trace({
|
|
104
|
+
name: manifest.name,
|
|
105
|
+
version
|
|
106
|
+
}, "version @{version} of @{name} removed (no replacement available)");
|
|
107
|
+
delete manifest.versions[version];
|
|
108
|
+
});
|
|
109
|
+
replacedVersions.forEach(([version, replaceVersion]) => {
|
|
110
|
+
logger.trace({
|
|
111
|
+
name: manifest.name,
|
|
112
|
+
version,
|
|
113
|
+
replaceVersion
|
|
114
|
+
}, "version @{version} of @{name} replaced with @{replaceVersion}");
|
|
115
|
+
manifest.versions[version] = {
|
|
116
|
+
...manifest.versions[replaceVersion],
|
|
117
|
+
version
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
if (removedVersions.length > 0) manifest.readme += `\nSome versions of package could not be replaced and thus are fully blocked (${removedVersions.length}): ${removedVersions.map((a) => a[0])}`;
|
|
121
|
+
if (replacedVersions.length > 0) manifest.readme += `\nSome versions of package are replaced by other(${replacedVersions.length}): ${replacedVersions.map((a) => `${a[0]} => ${a[1]}`)}`;
|
|
122
|
+
return manifest;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { filterBlockedVersions };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=packageVersion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.mjs","names":[],"sources":["../../src/filtering/packageVersion.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { Range, satisfies } from 'semver';\n\nimport type { Logger, Manifest } from '@verdaccio/types';\n\nimport type { ParsedConfigRule, ParsedRule } from '../config/types';\nimport { matchRules } from './matcher';\nimport { MatchType } from './types';\n\nconst debug = buildDebug('verdaccio:plugin:package-filter:filter');\n\n/**\n * Filter out all blocked package versions.\n * If package or scope is blocked, then block all versions.\n *\n * TODO: consider adding a `prerelease` filter option to block/allow\n * prerelease versions independently. Currently prereleases are matched by\n * semver ranges with `includePrerelease: true`, but there's no dedicated toggle.\n *\n * Example config (not yet implemented):\n * block:\n * - package: 'foo'\n * prerelease: true # block 1.0.0-beta.1, 2.0.0-rc.1, keep 1.0.0, 2.0.0\n * - package: 'bar'\n * prerelease: false # block 1.0.0, 2.0.0, keep 1.0.0-beta.1\n *\n * Today the only workaround is using awkward ranges like \">=1.0.0-0 <1.0.0\".\n */\nexport function filterBlockedVersions(\n manifest: Manifest,\n blockRules: Map<string, ParsedRule>,\n allowRules: Map<string, ParsedRule>,\n logger: Logger\n): Manifest {\n const allowMatch = matchRules(manifest, allowRules);\n if (\n allowMatch &&\n (allowMatch.type === MatchType.SCOPE || allowMatch.type === MatchType.PACKAGE)\n ) {\n // An entire scope or package is whitelisted\n logger.trace({ name: manifest.name }, 'package @{name} is allow-listed, skipping block rules');\n return manifest;\n }\n\n const blockMatch = matchRules(manifest, blockRules);\n if (!blockMatch) {\n // No rule is blocking this package\n return manifest;\n }\n\n logger.trace(\n { name: manifest.name, type: blockMatch.type },\n 'block rule matched for @{name} (type: @{type})'\n );\n\n const whitelistedVersions: string[] = allowMatch ? allowMatch.versions : [];\n let blockRule: ParsedConfigRule = {\n versions: [new Range('*')],\n strategy: 'block',\n };\n\n if (blockMatch.type === MatchType.SCOPE) {\n if (whitelistedVersions.length === 0) {\n debug('blocking all versions of %s (scope %s blocked)', manifest.name, blockMatch.scope);\n logger.trace(\n { name: manifest.name, scope: blockMatch.scope },\n 'all versions of @{name} blocked (scope @{scope})'\n );\n return {\n ...manifest,\n versions: {},\n readme: `All packages in scope ${blockMatch.scope} are blocked by rule`,\n };\n }\n } else if (blockMatch.type === MatchType.PACKAGE) {\n if (whitelistedVersions.length === 0) {\n debug('blocking all versions of %s (package blocked)', manifest.name);\n logger.trace({ name: manifest.name }, 'all versions of @{name} blocked (package rule)');\n return {\n ...manifest,\n versions: {},\n readme: `All package versions are blocked by rule`,\n };\n }\n } else {\n blockRule = { ...blockRule, ...blockMatch.rule };\n }\n\n const versionRanges = blockRule.versions;\n\n if (blockRule.strategy === 'block') {\n const blockedVersions = blockMatch.versions.filter((v) => !whitelistedVersions.includes(v));\n for (const version of blockedVersions) {\n delete manifest.versions[version];\n }\n\n if (blockedVersions.length > 0) {\n debug(\n 'blocked %d versions of %s: %o',\n blockedVersions.length,\n manifest.name,\n blockedVersions\n );\n logger.trace(\n {\n name: manifest.name,\n count: blockedVersions.length,\n versions: blockedVersions.join(', '),\n },\n '@{count} versions of @{name} blocked: @{versions}'\n );\n // Add debug info for devs\n manifest.readme =\n (manifest.readme || '') +\n `\\nSome versions(${blockedVersions.length}) of package are blocked by rules: ${versionRanges.map(\n (range) => range.raw\n )}`;\n }\n\n return manifest;\n }\n\n // Process block rule strategy 'replace'.\n // We assume that the order of versions is already sorted.\n const nonBlockedVersions = { ...manifest.versions };\n const newVersionsMapping: Record<string, string | null> = {};\n\n versionRanges.forEach((versionRange) => {\n const allVersions = Object.keys(nonBlockedVersions);\n\n let lastNonBlockedVersion: string | null = null;\n\n allVersions.forEach((version) => {\n if (\n !whitelistedVersions.includes(version) &&\n satisfies(version, versionRange, {\n includePrerelease: true,\n loose: true,\n })\n ) {\n delete nonBlockedVersions[version];\n newVersionsMapping[version] = lastNonBlockedVersion;\n } else {\n lastNonBlockedVersion = version;\n }\n });\n });\n\n debug('replacing versions for %s: %o', manifest.name, newVersionsMapping);\n\n const removedVersions = Object.entries(newVersionsMapping).filter(\n ([_, replace]) => replace === null\n ) as [string, null][];\n const replacedVersions = Object.entries(newVersionsMapping).filter(\n ([_, replace]) => replace !== null\n ) as [string, string][];\n\n removedVersions.forEach(([version]) => {\n debug('no version to replace %s in %s', version, manifest.name);\n logger.trace(\n { name: manifest.name, version },\n 'version @{version} of @{name} removed (no replacement available)'\n );\n delete manifest.versions[version];\n });\n\n replacedVersions.forEach(([version, replaceVersion]) => {\n logger.trace(\n { name: manifest.name, version, replaceVersion },\n 'version @{version} of @{name} replaced with @{replaceVersion}'\n );\n manifest.versions[version] = {\n ...manifest.versions[replaceVersion],\n version,\n };\n });\n\n if (removedVersions.length > 0) {\n manifest.readme +=\n `\\nSome versions of package could not be replaced and thus are fully blocked (${removedVersions.length}):` +\n ` ${removedVersions.map((a) => a[0])}`;\n }\n\n if (replacedVersions.length > 0) {\n manifest.readme +=\n `\\nSome versions of package are replaced by other(${replacedVersions.length}):` +\n ` ${replacedVersions.map((a) => `${a[0]} => ${a[1]}`)}`;\n }\n\n return manifest;\n}\n"],"mappings":";;;;;AASA,IAAM,QAAQ,WAAW,wCAAwC;;;;;;;;;;;;;;;;;;AAm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O,KACnG,gBAAgB,KAAK,MAAM,EAAE,EAAE;CAGvC,IAAI,iBAAiB,SAAS,GAC5B,SAAS,UACP,oDAAoD,iBAAiB,OAAO,KACxE,iBAAiB,KAAK,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI;CAGxD,OAAO;AACT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Manifest } from '@verdaccio/types';
|
|
2
|
+
import type { ParsedRule } from '../config/types';
|
|
3
|
+
/**
|
|
4
|
+
* Filter out all package versions that were published after dateThreshold.
|
|
5
|
+
*/
|
|
6
|
+
export declare function filterVersionsByPublishDate(manifest: Manifest, dateThreshold: Date, allowRules: Map<string, ParsedRule>): Manifest;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
const require_types = require("./types.js");
|
|
3
|
+
const require_matcher = require("./matcher.js");
|
|
4
|
+
let debug = require("debug");
|
|
5
|
+
debug = require_runtime.__toESM(debug);
|
|
6
|
+
//#region src/filtering/publishDate.ts
|
|
7
|
+
var debug$1 = (0, debug.default)("verdaccio:plugin:package-filter:filter");
|
|
8
|
+
/**
|
|
9
|
+
* Filter out all package versions that were published after dateThreshold.
|
|
10
|
+
*/
|
|
11
|
+
function filterVersionsByPublishDate(manifest, dateThreshold, allowRules) {
|
|
12
|
+
const allowMatch = require_matcher.matchRules(manifest, allowRules);
|
|
13
|
+
if (allowMatch && (allowMatch.type === require_types.MatchType.SCOPE || allowMatch.type === require_types.MatchType.PACKAGE)) return manifest;
|
|
14
|
+
const { versions, time, name } = manifest;
|
|
15
|
+
if (!time) throw new TypeError(`Time of publication was not provided for package ${name}`);
|
|
16
|
+
const whitelistedVersions = allowMatch ? allowMatch.versions : [];
|
|
17
|
+
const clearVersions = [];
|
|
18
|
+
Object.keys(versions).forEach((version) => {
|
|
19
|
+
if (whitelistedVersions.includes(version)) return;
|
|
20
|
+
const publishTime = time[version];
|
|
21
|
+
if (!publishTime) throw new TypeError(`Time of publication was not provided for package ${name}, version ${version}`);
|
|
22
|
+
if (new Date(publishTime) > dateThreshold) clearVersions.push(version);
|
|
23
|
+
});
|
|
24
|
+
clearVersions.forEach((version) => {
|
|
25
|
+
delete manifest.versions[version];
|
|
26
|
+
});
|
|
27
|
+
if (clearVersions.length > 0) debug$1("date filter removed %d versions from %s: %o", clearVersions.length, manifest.name, clearVersions);
|
|
28
|
+
return manifest;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.filterVersionsByPublishDate = filterVersionsByPublishDate;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=publishDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publishDate.js","names":[],"sources":["../../src/filtering/publishDate.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { Manifest } from '@verdaccio/types';\n\nimport type { ParsedRule } from '../config/types';\nimport { matchRules } from './matcher';\nimport { MatchType } from './types';\n\nconst debug = buildDebug('verdaccio:plugin:package-filter:filter');\n\n/**\n * Filter out all package versions that were published after dateThreshold.\n */\nexport function filterVersionsByPublishDate(\n manifest: Manifest,\n dateThreshold: Date,\n allowRules: Map<string, ParsedRule>\n): Manifest {\n const allowMatch = matchRules(manifest, allowRules);\n if (\n allowMatch &&\n (allowMatch.type === MatchType.SCOPE || allowMatch.type === MatchType.PACKAGE)\n ) {\n // An entire scope or package is whitelisted\n return manifest;\n }\n\n const { versions, time, name } = manifest;\n\n if (!time) {\n throw new TypeError(`Time of publication was not provided for package ${name}`);\n }\n\n const whitelistedVersions: string[] = allowMatch ? allowMatch.versions : [];\n const clearVersions: string[] = [];\n\n Object.keys(versions).forEach((version) => {\n if (whitelistedVersions.includes(version)) {\n return;\n }\n\n const publishTime = time[version];\n\n if (!publishTime) {\n throw new TypeError(\n `Time of publication was not provided for package ${name}, version ${version}`\n );\n }\n\n if (new Date(publishTime) > dateThreshold) {\n // clear untrusted version\n clearVersions.push(version);\n }\n });\n\n // delete version from versions\n clearVersions.forEach((version) => {\n delete manifest.versions[version];\n });\n\n if (clearVersions.length > 0) {\n debug(\n 'date filter removed %d versions from %s: %o',\n clearVersions.length,\n manifest.name,\n clearVersions\n );\n }\n\n return manifest;\n}\n"],"mappings":";;;;;;AAQA,IAAM,WAAA,GAAA,MAAA,SAAmB,wCAAwC;;;;AAKjE,SAAgB,4BACd,UACA,eACA,YACU;CACV,MAAM,aAAa,gBAAA,WAAW,UAAU,UAAU;CAClD,IACE,eACC,WAAW,SAAS,cAAA,UAAU,SAAS,WAAW,SAAS,cAAA,UAAU,UAGtE,OAAO;CAGT,MAAM,EAAE,UAAU,MAAM,SAAS;CAEjC,IAAI,CAAC,MACH,MAAM,IAAI,UAAU,oDAAoD,MAAM;CAGhF,MAAM,sBAAgC,aAAa,WAAW,WAAW,CAAC;CAC1E,MAAM,gBAA0B,CAAC;CAEjC,OAAO,KAAK,QAAQ,EAAE,SAAS,YAAY;EACzC,IAAI,oBAAoB,SAAS,OAAO,GACtC;EAGF,MAAM,cAAc,KAAK;EAEzB,IAAI,CAAC,aACH,MAAM,IAAI,UACR,oDAAoD,KAAK,YAAY,SACvE;EAGF,IAAI,IAAI,KAAK,WAAW,IAAI,eAE1B,cAAc,KAAK,OAAO;CAE9B,CAAC;CAGD,cAAc,SAAS,YAAY;EACjC,OAAO,SAAS,SAAS;CAC3B,CAAC;CAED,IAAI,cAAc,SAAS,GACzB,QACE,+CACA,cAAc,QACd,SAAS,MACT,aACF;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MatchType } from "./types.mjs";
|
|
2
|
+
import { matchRules } from "./matcher.mjs";
|
|
3
|
+
import buildDebug from "debug";
|
|
4
|
+
//#region src/filtering/publishDate.ts
|
|
5
|
+
var debug = buildDebug("verdaccio:plugin:package-filter:filter");
|
|
6
|
+
/**
|
|
7
|
+
* Filter out all package versions that were published after dateThreshold.
|
|
8
|
+
*/
|
|
9
|
+
function filterVersionsByPublishDate(manifest, dateThreshold, allowRules) {
|
|
10
|
+
const allowMatch = matchRules(manifest, allowRules);
|
|
11
|
+
if (allowMatch && (allowMatch.type === MatchType.SCOPE || allowMatch.type === MatchType.PACKAGE)) return manifest;
|
|
12
|
+
const { versions, time, name } = manifest;
|
|
13
|
+
if (!time) throw new TypeError(`Time of publication was not provided for package ${name}`);
|
|
14
|
+
const whitelistedVersions = allowMatch ? allowMatch.versions : [];
|
|
15
|
+
const clearVersions = [];
|
|
16
|
+
Object.keys(versions).forEach((version) => {
|
|
17
|
+
if (whitelistedVersions.includes(version)) return;
|
|
18
|
+
const publishTime = time[version];
|
|
19
|
+
if (!publishTime) throw new TypeError(`Time of publication was not provided for package ${name}, version ${version}`);
|
|
20
|
+
if (new Date(publishTime) > dateThreshold) clearVersions.push(version);
|
|
21
|
+
});
|
|
22
|
+
clearVersions.forEach((version) => {
|
|
23
|
+
delete manifest.versions[version];
|
|
24
|
+
});
|
|
25
|
+
if (clearVersions.length > 0) debug("date filter removed %d versions from %s: %o", clearVersions.length, manifest.name, clearVersions);
|
|
26
|
+
return manifest;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { filterVersionsByPublishDate };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=publishDate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publishDate.mjs","names":[],"sources":["../../src/filtering/publishDate.ts"],"sourcesContent":["import buildDebug from 'debug';\n\nimport type { Manifest } from '@verdaccio/types';\n\nimport type { ParsedRule } from '../config/types';\nimport { matchRules } from './matcher';\nimport { MatchType } from './types';\n\nconst debug = buildDebug('verdaccio:plugin:package-filter:filter');\n\n/**\n * Filter out all package versions that were published after dateThreshold.\n */\nexport function filterVersionsByPublishDate(\n manifest: Manifest,\n dateThreshold: Date,\n allowRules: Map<string, ParsedRule>\n): Manifest {\n const allowMatch = matchRules(manifest, allowRules);\n if (\n allowMatch &&\n (allowMatch.type === MatchType.SCOPE || allowMatch.type === MatchType.PACKAGE)\n ) {\n // An entire scope or package is whitelisted\n return manifest;\n }\n\n const { versions, time, name } = manifest;\n\n if (!time) {\n throw new TypeError(`Time of publication was not provided for package ${name}`);\n }\n\n const whitelistedVersions: string[] = allowMatch ? allowMatch.versions : [];\n const clearVersions: string[] = [];\n\n Object.keys(versions).forEach((version) => {\n if (whitelistedVersions.includes(version)) {\n return;\n }\n\n const publishTime = time[version];\n\n if (!publishTime) {\n throw new TypeError(\n `Time of publication was not provided for package ${name}, version ${version}`\n );\n }\n\n if (new Date(publishTime) > dateThreshold) {\n // clear untrusted version\n clearVersions.push(version);\n }\n });\n\n // delete version from versions\n clearVersions.forEach((version) => {\n delete manifest.versions[version];\n });\n\n if (clearVersions.length > 0) {\n debug(\n 'date filter removed %d versions from %s: %o',\n clearVersions.length,\n manifest.name,\n clearVersions\n );\n }\n\n return manifest;\n}\n"],"mappings":";;;;AAQA,IAAM,QAAQ,WAAW,wCAAwC;;;;AAKjE,SAAgB,4BACd,UACA,eACA,YACU;CACV,MAAM,aAAa,WAAW,UAAU,UAAU;CAClD,IACE,eACC,WAAW,SAAS,UAAU,SAAS,WAAW,SAAS,UAAU,UAGtE,OAAO;CAGT,MAAM,EAAE,UAAU,MAAM,SAAS;CAEjC,IAAI,CAAC,MACH,MAAM,IAAI,UAAU,oDAAoD,MAAM;CAGhF,MAAM,sBAAgC,aAAa,WAAW,WAAW,CAAC;CAC1E,MAAM,gBAA0B,CAAC;CAEjC,OAAO,KAAK,QAAQ,EAAE,SAAS,YAAY;EACzC,IAAI,oBAAoB,SAAS,OAAO,GACtC;EAGF,MAAM,cAAc,KAAK;EAEzB,IAAI,CAAC,aACH,MAAM,IAAI,UACR,oDAAoD,KAAK,YAAY,SACvE;EAGF,IAAI,IAAI,KAAK,WAAW,IAAI,eAE1B,cAAc,KAAK,OAAO;CAE9B,CAAC;CAGD,cAAc,SAAS,YAAY;EACjC,OAAO,SAAS,SAAS;CAC3B,CAAC;CAED,IAAI,cAAc,SAAS,GACzB,MACE,+CACA,cAAc,QACd,SAAS,MACT,aACF;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PackageScopeLevel, ParsedConfigRule } from '../config/types';
|
|
2
|
+
export declare enum MatchType {
|
|
3
|
+
SCOPE = "scope",
|
|
4
|
+
PACKAGE = "package",
|
|
5
|
+
VERSIONS = "versions"
|
|
6
|
+
}
|
|
7
|
+
export interface MatchResultVersions {
|
|
8
|
+
versions: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface MatchScopeResult extends MatchResultVersions {
|
|
11
|
+
type: MatchType.SCOPE;
|
|
12
|
+
rule: PackageScopeLevel;
|
|
13
|
+
scope: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MatchPackageResult extends MatchResultVersions {
|
|
16
|
+
type: MatchType.PACKAGE;
|
|
17
|
+
rule: PackageScopeLevel;
|
|
18
|
+
package: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MatchVersionsResult extends MatchResultVersions {
|
|
21
|
+
type: MatchType.VERSIONS;
|
|
22
|
+
rule: ParsedConfigRule;
|
|
23
|
+
}
|
|
24
|
+
export type MatchResult = MatchScopeResult | MatchPackageResult | MatchVersionsResult;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/filtering/types.ts
|
|
2
|
+
var MatchType = /* @__PURE__ */ function(MatchType) {
|
|
3
|
+
MatchType["SCOPE"] = "scope";
|
|
4
|
+
MatchType["PACKAGE"] = "package";
|
|
5
|
+
MatchType["VERSIONS"] = "versions";
|
|
6
|
+
return MatchType;
|
|
7
|
+
}({});
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.MatchType = MatchType;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/filtering/types.ts"],"sourcesContent":["import type { PackageScopeLevel, ParsedConfigRule } from '../config/types';\n\nexport enum MatchType {\n SCOPE = 'scope',\n PACKAGE = 'package',\n VERSIONS = 'versions',\n}\n\nexport interface MatchResultVersions {\n versions: string[];\n}\n\nexport interface MatchScopeResult extends MatchResultVersions {\n type: MatchType.SCOPE;\n rule: PackageScopeLevel;\n scope: string;\n}\n\nexport interface MatchPackageResult extends MatchResultVersions {\n type: MatchType.PACKAGE;\n rule: PackageScopeLevel;\n package: string;\n}\n\nexport interface MatchVersionsResult extends MatchResultVersions {\n type: MatchType.VERSIONS;\n rule: ParsedConfigRule;\n}\n\nexport type MatchResult = MatchScopeResult | MatchPackageResult | MatchVersionsResult;\n"],"mappings":";AAEA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,WAAA;CACA,UAAA,aAAA;CACA,UAAA,cAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/filtering/types.ts
|
|
2
|
+
var MatchType = /* @__PURE__ */ function(MatchType) {
|
|
3
|
+
MatchType["SCOPE"] = "scope";
|
|
4
|
+
MatchType["PACKAGE"] = "package";
|
|
5
|
+
MatchType["VERSIONS"] = "versions";
|
|
6
|
+
return MatchType;
|
|
7
|
+
}({});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { MatchType };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/filtering/types.ts"],"sourcesContent":["import type { PackageScopeLevel, ParsedConfigRule } from '../config/types';\n\nexport enum MatchType {\n SCOPE = 'scope',\n PACKAGE = 'package',\n VERSIONS = 'versions',\n}\n\nexport interface MatchResultVersions {\n versions: string[];\n}\n\nexport interface MatchScopeResult extends MatchResultVersions {\n type: MatchType.SCOPE;\n rule: PackageScopeLevel;\n scope: string;\n}\n\nexport interface MatchPackageResult extends MatchResultVersions {\n type: MatchType.PACKAGE;\n rule: PackageScopeLevel;\n package: string;\n}\n\nexport interface MatchVersionsResult extends MatchResultVersions {\n type: MatchType.VERSIONS;\n rule: ParsedConfigRule;\n}\n\nexport type MatchResult = MatchScopeResult | MatchPackageResult | MatchVersionsResult;\n"],"mappings":";AAEA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,WAAA;CACA,UAAA,aAAA;CACA,UAAA,cAAA;;AACF,EAAA,CAAA,CAAA"}
|
package/build/index.d.ts
ADDED