vigievuln 1.2.0 → 1.3.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/CHANGELOG.md +23 -2
- package/README.md +13 -7
- package/lib/advisory-freshness.js +2 -0
- package/lib/airgap-project.js +35 -7
- package/lib/applicability-evidence.js +12 -0
- package/lib/artifacts/applications.js +54 -0
- package/lib/artifacts/cve-view.js +108 -0
- package/lib/artifacts/enrichment.js +86 -0
- package/lib/artifacts/go-main-identity.js +45 -0
- package/lib/artifacts/go-publisher-advisories.js +24 -0
- package/lib/artifacts/index.js +272 -0
- package/lib/artifacts/publisher-advisories.js +12 -0
- package/lib/artifacts/remediation-report.js +48 -0
- package/lib/artifacts/report-inventory.js +26 -0
- package/lib/artifacts/report.js +191 -0
- package/lib/artifacts/risk-report.js +120 -0
- package/lib/artifacts/sbom.js +68 -0
- package/lib/artifacts/scan.js +401 -0
- package/lib/cache-archive-sqlite.js +41 -25
- package/lib/certs/analyze.js +49 -13
- package/lib/charts.js +124 -32
- package/lib/cli-command-routing.js +20 -6
- package/lib/cli-groups.js +2 -1
- package/lib/cli-image.js +206 -0
- package/lib/codecs/binary/elf-metadata.js +42 -0
- package/lib/codecs/binary/go-buildinfo.js +37 -0
- package/lib/codecs/binary/metadata.js +7 -0
- package/lib/codecs/binary/pe-metadata.js +27 -1
- package/lib/codecs/binary/scan.js +44 -26
- package/lib/codecs/binary/sniff.js +16 -15
- package/lib/codecs/binary.codec.js +27 -4
- package/lib/codecs/go/parse.js +10 -4
- package/lib/codecs/go.codec.js +23 -6
- package/lib/codecs/gradle/parse.js +63 -2
- package/lib/codecs/gradle/versionless.js +175 -0
- package/lib/codecs/gradle.codec.js +20 -3
- package/lib/codecs/index.js +2 -2
- package/lib/codecs/maven.codec.js +9 -4
- package/lib/codecs/npm/collect.js +6 -11
- package/lib/codecs/nuget/parse.js +16 -5
- package/lib/codecs/nuget.codec.js +2 -1
- package/lib/codecs/pypi/parse.js +56 -15
- package/lib/codecs/pypi.codec.js +2 -0
- package/lib/csaf-export.js +46 -11
- package/lib/cve-download.js +33 -29
- package/lib/cve-match.js +10 -0
- package/lib/cve-packages-proxy.js +19 -0
- package/lib/cve-report.js +273 -165
- package/lib/deps-descriptor.js +25 -3
- package/lib/diagnostics.js +12 -0
- package/lib/diff.js +0 -0
- package/lib/epss.js +6 -6
- package/lib/euvd.js +34 -4
- package/lib/finding-enrichment.js +165 -0
- package/lib/finding-summary.js +4 -3
- package/lib/i18n.js +35 -9
- package/lib/image-network.js +54 -0
- package/lib/image-references.js +203 -0
- package/lib/image-registry.js +385 -0
- package/lib/image-update.js +39 -0
- package/lib/json-export.js +100 -10
- package/lib/kev.js +6 -6
- package/lib/maven-bom.js +2 -1
- package/lib/merge-sources.js +3 -0
- package/lib/native-advisories.js +9 -7
- package/lib/native-cna-identities.js +12 -0
- package/lib/native-package-match.js +159 -0
- package/lib/native-source-prepare.js +60 -0
- package/lib/nvd.js +34 -23
- package/lib/osv.js +33 -14
- package/lib/project-descriptor.js +3 -2
- package/lib/provenance.js +8 -2
- package/lib/providers/alpine.js +8 -0
- package/lib/providers/common.js +11 -3
- package/lib/providers/debian.js +11 -0
- package/lib/providers/euvd.js +2 -1
- package/lib/providers/freexian.js +13 -0
- package/lib/providers/github.js +1 -0
- package/lib/providers/go.js +2 -1
- package/lib/providers/index.js +18 -14
- package/lib/providers/nginx.js +5 -0
- package/lib/providers/nvd.js +1 -1
- package/lib/providers/osv.js +1 -1
- package/lib/providers/osvdb.js +2 -2
- package/lib/proxy-throttle.js +89 -29
- package/lib/purl.js +10 -2
- package/lib/record-freshness.js +22 -0
- package/lib/report-notices.js +47 -0
- package/lib/report-time.js +45 -0
- package/lib/request-failure.js +22 -0
- package/lib/resource-cache/engine.js +130 -26
- package/lib/resource-cache/snapshot-projection.js +33 -0
- package/lib/resource-cache/validate.js +22 -5
- package/lib/risk-evidence.js +18 -0
- package/lib/sarif-export.js +17 -9
- package/lib/sbom-export.js +38 -12
- package/lib/source-health.js +25 -8
- package/lib/source-image-scan.js +57 -0
- package/lib/source-profile.js +6 -3
- package/lib/sqlite-driver.js +15 -1
- package/lib/suppress.js +34 -13
- package/lib/system-inventory/advisories.js +169 -0
- package/lib/system-inventory/alpine-tracker.js +47 -0
- package/lib/system-inventory/collect.js +118 -0
- package/lib/system-inventory/current-debian.js +99 -0
- package/lib/system-inventory/distribution-sources.js +132 -0
- package/lib/system-inventory/freexian-ela.js +32 -0
- package/lib/system-inventory/freexian-release-evidence.js +35 -0
- package/lib/system-inventory/freexian-tracker.js +72 -0
- package/lib/system-inventory/historical-debian.js +196 -0
- package/lib/system-inventory/index.js +2 -0
- package/lib/system-inventory/nginx-advisories.js +39 -0
- package/lib/system-inventory/rpm-storage.js +86 -0
- package/lib/system-inventory/targeted.js +70 -0
- package/lib/system-inventory/versions.js +59 -0
- package/lib/transitive.js +11 -2
- package/lib/ui.js +8 -5
- package/lib/unmanaged.js +1 -1
- package/lib/xlsx-export.js +8 -2
- package/package.json +12 -3
- package/vigievuln.js +279 -127
package/lib/proxy-throttle.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
// The hosted service permits 7200 requests/minute per key. Leave headroom for
|
|
4
4
|
// concurrent scans and preflight, and coordinate all providers in this process.
|
|
5
|
-
function createProxyThrottle({ intervalMs = 10, maxPerMinute = 6000, sleep = (ms, signal) => require('node:timers/promises').setTimeout(ms, undefined, {signal}), now = Date.now, warn =
|
|
6
|
-
let next = 0, blockedUntil = 0, warnedPacing = false, requests = 0, window = -1, count = 0;
|
|
7
|
-
const
|
|
5
|
+
function createProxyThrottle({ intervalMs = 10, maxPerMinute = 6000, maxWaitMs = 45000, maxRateRetries = 15, sleep = (ms, signal) => require('node:timers/promises').setTimeout(ms, undefined, {signal}), now = Date.now, warn = msg => require('./ui').networkNotice(msg), subscribeSkip = ttySkipSubscription } = {}) {
|
|
6
|
+
let next = 0, blockedUntil = 0, warnedPacing = false, requests = 0, window = -1, count = 0, skipped = false, stopListening = null;
|
|
7
|
+
const skipWaiters=new Set();
|
|
8
|
+
function skipRetries() { skipped=true;next=now();for(const resolve of skipWaiters)resolve(); }
|
|
8
9
|
function reserve(earliest) {
|
|
9
|
-
let slot = Math.max(now(), next, blockedUntil, earliest);
|
|
10
|
+
let slot = Math.max(now(), next, skipped ? 0 : blockedUntil, earliest);
|
|
10
11
|
let current = Math.floor(slot / 60000);
|
|
11
12
|
if (current !== window) { window = current; count = 0; }
|
|
12
13
|
if (count >= maxPerMinute) {
|
|
@@ -18,54 +19,113 @@ function createProxyThrottle({ intervalMs = 10, maxPerMinute = 6000, sleep = (ms
|
|
|
18
19
|
return slot;
|
|
19
20
|
}
|
|
20
21
|
function abortError() { const error = new Error('Proxy request aborted while waiting for rate limit.'); error.name = 'AbortError'; return error; }
|
|
21
|
-
async function wait(ms, signal) {
|
|
22
|
+
async function wait(ms, signal, canSkip = false) {
|
|
22
23
|
if (signal?.aborted) throw abortError();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const controller=new AbortController();let onAbort,resolveSkip;
|
|
25
|
+
if(canSkip && skipped)return false;
|
|
26
|
+
if(canSkip && !stopListening)stopListening=subscribeSkip(skipRetries) || (()=>{});
|
|
27
|
+
const choices=[Promise.resolve().then(()=>sleep(ms,controller.signal)).then(()=>true)];
|
|
28
|
+
if(signal)choices.push(new Promise((_,reject)=>{onAbort=()=>reject(abortError());signal.addEventListener('abort',onAbort,{once:true});}));
|
|
29
|
+
if(canSkip)choices.push(new Promise(resolve=>{resolveSkip=()=>resolve(false);skipWaiters.add(resolveSkip);}));
|
|
30
|
+
try { return await Promise.race(choices); }
|
|
31
|
+
finally {controller.abort();if(onAbort)signal.removeEventListener('abort',onAbort);if(resolveSkip){skipWaiters.delete(resolveSkip);if(!skipWaiters.size && stopListening){stopListening();stopListening=null;}}}
|
|
27
32
|
}
|
|
28
33
|
async function acquire(signal) {
|
|
34
|
+
if (signal?.aborted) throw abortError();
|
|
29
35
|
let slot = reserve(0);
|
|
30
36
|
if (++requests === 10 && !warnedPacing) { warnedPacing = true; warn('Proxy: pacing requests to respect the server rate limit.'); }
|
|
31
37
|
for (;;) {
|
|
32
|
-
if (slot < blockedUntil) slot = reserve(blockedUntil);
|
|
38
|
+
if (!skipped && slot < blockedUntil) slot = reserve(blockedUntil);
|
|
33
39
|
const delay = slot - now();
|
|
34
40
|
if (delay <= 0) break;
|
|
35
|
-
await wait(delay, signal);
|
|
41
|
+
if(await wait(delay, signal, !skipped && blockedUntil > now())===false)return false;
|
|
36
42
|
}
|
|
43
|
+
return true;
|
|
37
44
|
}
|
|
38
45
|
function delayFrom(response) {
|
|
39
46
|
const raw = response.headers?.get?.('retry-after');
|
|
40
47
|
const seconds = raw && /^\d+$/.test(raw) ? Number(raw) : null;
|
|
41
48
|
const date = raw && seconds === null ? Date.parse(raw) : NaN;
|
|
42
|
-
return Math.max(
|
|
49
|
+
return Math.max(3000, seconds !== null ? seconds * 1000 : Number.isFinite(date) ? date - now() : 3000);
|
|
43
50
|
}
|
|
44
|
-
async function request(fetcher, signal, {retryDenied = true, retryTransient = true} = {}) {
|
|
45
|
-
|
|
51
|
+
async function request(fetcher, signal, {retryDenied = true, retryTransient = true, waitBudgetMs = maxWaitMs, rateRetries = maxRateRetries, label = null} = {}) {
|
|
52
|
+
if (!Number.isSafeInteger(waitBudgetMs) || waitBudgetMs < 0 || !Number.isSafeInteger(rateRetries) || rateRetries < 0) throw new Error('Invalid proxy retry budget');
|
|
53
|
+
let limitRetries = 0, transientRetries = 0, waitedMs = 0;
|
|
54
|
+
const context = label ? ` [${label}]` : '';
|
|
55
|
+
// Retry allowance belongs to this lookup. Cooldowns remain coordinated across
|
|
56
|
+
// concurrent lookups, but one resource cannot disable retries for the scan.
|
|
57
|
+
function scheduleCooldown(delay) {
|
|
58
|
+
if (delay > waitBudgetMs - waitedMs) {
|
|
59
|
+
warn(`Proxy retry wait budget exhausted${context}: another ${Math.ceil(delay / 1000)}s would exceed this request's budget. Continuing with cached data when available; other requests retain their retries.`);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
waitedMs += delay;
|
|
63
|
+
blockedUntil = Math.max(blockedUntil, now() + delay);
|
|
64
|
+
next = Math.max(next, blockedUntil);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
let lastLimited = null;
|
|
46
68
|
for (;;) {
|
|
47
|
-
await acquire(signal)
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
if (!(await acquire(signal))) {
|
|
70
|
+
next = now();
|
|
71
|
+
if (lastLimited && (!skipped || lastLimited.status===200)) return lastLimited;
|
|
72
|
+
if(skipped){const error=new Error('Proxy rate-limit retry skipped by user.');error.code='PROXY_RETRY_SKIPPED';if(lastLimited)error.status=lastLimited.status;throw error;}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let response;
|
|
76
|
+
try { response=await fetcher(); }
|
|
77
|
+
catch(error) {
|
|
78
|
+
if(signal?.aborted)throw abortError();
|
|
79
|
+
if(error?.name==='AbortError')throw error;
|
|
80
|
+
if(lastLimited?.status===200)return lastLimited;
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const stale=response.status===200 && response.headers?.get?.('x-fad-proxy')==='stale' && response.headers?.get?.('x-fad-proxy-reason')==='refresh-failed';
|
|
84
|
+
const cause=response.headers?.get?.('x-fad-proxy-refresh-cause'), refreshStatus=response.headers?.get?.('x-fad-proxy-refresh-status');
|
|
85
|
+
const staleLimit=stale && ((cause==='rate-limit' && refreshStatus==='429') || (retryDenied && cause==='admission' && refreshStatus==='503'));
|
|
86
|
+
const limited = staleLimit || response.status === 429 || (retryDenied && response.status === 503 && response.headers?.get?.('x-fad-proxy') === 'denied');
|
|
50
87
|
if (!limited) {
|
|
51
|
-
if (!retryTransient || ![502,503,504].includes(response.status) || transientRetries
|
|
88
|
+
if (skipped || !retryTransient || ![502,503,504].includes(response.status) || transientRetries >= 2 || limitRetries + transientRetries >= rateRetries || (response.status === 503 && !retryDenied && response.headers?.get?.('x-fad-proxy') === 'denied')) {
|
|
89
|
+
if(response.status!==200 && lastLimited?.status===200)return lastLimited;
|
|
90
|
+
if (lastLimited?.body && !lastLimited.body.locked) void lastLimited.body.cancel().catch(()=>{});
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
93
|
+
if(!scheduleCooldown(3000))return lastLimited?.status===200?lastLimited:response;
|
|
94
|
+
transientRetries++;
|
|
52
95
|
if (response.body && !response.body.locked) void response.body.cancel().catch(() => {});
|
|
53
|
-
await wait(transientRetries * 500, signal);
|
|
54
96
|
continue;
|
|
55
97
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
next = Math.max(next, blockedUntil);
|
|
62
|
-
if (!lastWarning.has(response.status) || now() - lastWarning.get(response.status) >= 10000) {
|
|
63
|
-
lastWarning.set(response.status, now());
|
|
64
|
-
warn(`Proxy rate limit (HTTP ${response.status}): waiting ${Math.ceil(delay / 1000)}s before retrying (attempt ${limitRetries}/3).`);
|
|
98
|
+
if (skipped) {
|
|
99
|
+
// A provider admission denial may leave other cached resources usable.
|
|
100
|
+
// A global 429 still receives a minimum probe interval, without retries.
|
|
101
|
+
if (response.status === 429 || refreshStatus === '429') next = Math.max(next, now() + 1000);
|
|
102
|
+
return response.status !== 200 && lastLimited?.status === 200 ? lastLimited : response;
|
|
65
103
|
}
|
|
104
|
+
const delay = delayFrom(response);
|
|
105
|
+
if (limitRetries + transientRetries >= rateRetries) return response.status !== 200 && lastLimited?.status === 200 ? lastLimited : response;
|
|
106
|
+
limitRetries++;
|
|
107
|
+
if (!scheduleCooldown(delay)) return response.status !== 200 && lastLimited?.status === 200 ? lastLimited : response;
|
|
108
|
+
const status = staleLimit ? `refresh HTTP ${refreshStatus}; cached response available` : `HTTP ${response.status}`;
|
|
109
|
+
const reason = response.status === 503 || refreshStatus === '503'
|
|
110
|
+
? 'Proxy upstream request temporarily deferred' : 'Proxy rate limit';
|
|
111
|
+
warn(`${reason}${context} (${status}): waiting ${Math.ceil(delay / 1000)}s before retrying (retry ${limitRetries + transientRetries}/${rateRetries} for this request).${process.stdin?.isTTY?' Press S or Esc to skip retries.':''}`);
|
|
112
|
+
if (lastLimited?.body && !lastLimited.body.locked) void lastLimited.body.cancel().catch(()=>{});
|
|
113
|
+
lastLimited = staleLimit ? response.clone() : response;
|
|
66
114
|
if (response.body && !response.body.locked) void response.body.cancel().catch(() => {});
|
|
67
115
|
}
|
|
68
116
|
}
|
|
69
117
|
return { request };
|
|
70
118
|
}
|
|
71
|
-
|
|
119
|
+
function ttySkipSubscription(skip, input=process.stdin, signalInterrupt=()=>process.kill(process.pid,'SIGINT')) {
|
|
120
|
+
if(!input?.isTTY || typeof input.setRawMode!=='function')return null;
|
|
121
|
+
const wasRaw=!!input.isRaw,wasPaused=input.isPaused();
|
|
122
|
+
const parser=new (require('node:stream').PassThrough)();require('node:readline').emitKeypressEvents(parser);
|
|
123
|
+
let multi=false,disposed=false;
|
|
124
|
+
const dispose=()=>{if(disposed)return;disposed=true;input.removeListener('data',onData);parser.removeAllListeners('keypress');parser.destroy();if(!wasRaw && input.isRaw)input.setRawMode(false);if(wasPaused)input.pause();};
|
|
125
|
+
parser.on('keypress',(str,key)=>{if(key?.ctrl && key.name==='c' && !wasRaw){dispose();signalInterrupt();return;}if(key?.name==='escape'||(!multi&&(str==='s'||str==='S')))skip();});
|
|
126
|
+
const onData=chunk=>{const text=String(chunk);multi=text.length>1 && !text.startsWith('\u001b');parser.write(chunk);multi=false;};
|
|
127
|
+
try{if(!wasRaw)input.setRawMode(true);input.on('data',onData);if(wasPaused)input.resume();}
|
|
128
|
+
catch{dispose();return null;}
|
|
129
|
+
return dispose;
|
|
130
|
+
}
|
|
131
|
+
module.exports = { createProxyThrottle, ttySkipSubscription };
|
package/lib/purl.js
CHANGED
|
@@ -43,7 +43,7 @@ function normalizePypi(name) {
|
|
|
43
43
|
function purlFor(dep) {
|
|
44
44
|
if (!dep || typeof dep !== "object") return null;
|
|
45
45
|
const eco = dep.ecosystem || dep.ecosystemType;
|
|
46
|
-
const type = TYPE[eco];
|
|
46
|
+
const type = eco === "system" && /^[a-z][a-z0-9.+-]*$/.test(dep.packageType || "") ? dep.packageType : TYPE[eco];
|
|
47
47
|
if (!type) return null;
|
|
48
48
|
|
|
49
49
|
const rawName = dep.name || dep.artifactId;
|
|
@@ -72,7 +72,15 @@ function purlFor(dep) {
|
|
|
72
72
|
// segment but keep the separators.
|
|
73
73
|
const nsPart = namespace ? `${String(namespace).split("/").map(enc).join("/")}/` : "";
|
|
74
74
|
const verPart = dep.version ? `@${enc(dep.version)}` : "";
|
|
75
|
-
|
|
75
|
+
let qualifiers = "";
|
|
76
|
+
if (eco === "system") {
|
|
77
|
+
const values = {};
|
|
78
|
+
if (dep.architecture) values.arch = dep.architecture;
|
|
79
|
+
if (dep.distribution?.id && dep.distribution?.versionId) values.distro = `${dep.distribution.id}-${dep.distribution.versionId}`;
|
|
80
|
+
const pairs = Object.entries(values).sort(([a],[b]) => a.localeCompare(b)).map(([k,v]) => `${k}=${enc(v)}`);
|
|
81
|
+
if (pairs.length) qualifiers = `?${pairs.join("&")}`;
|
|
82
|
+
}
|
|
83
|
+
return `pkg:${type}/${nsPart}${enc(name)}${verPart}${qualifiers}`;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
module.exports = { purlFor };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Versioned record metadata: dates describe the source record, never its cache fetch.
|
|
4
|
+
const METADATA_VERSION = 1;
|
|
5
|
+
const DAY_MS = 86400000;
|
|
6
|
+
const extractors = {
|
|
7
|
+
nvd: record => ({published:record?.published, modified:record?.modified}),
|
|
8
|
+
osv: record => ({published:record?.published, modified:record?.modified}),
|
|
9
|
+
euvd: record => ({published:record?.published, modified:record?.modified}),
|
|
10
|
+
};
|
|
11
|
+
function stableRecord(source, record, options = {}) {
|
|
12
|
+
if (options.reuseStableAdvisories === false || options.forceUpdate || require('./cache-policy').shouldForceUpdate()) return false;
|
|
13
|
+
const days = options.stableAdvisoryAgeDays ?? 365;
|
|
14
|
+
if (!Number.isFinite(days) || days <= 0 || days > Number.MAX_SAFE_INTEGER / DAY_MS) return false;
|
|
15
|
+
const now = options.now ?? Date.now(), extract = (options.recordMetadataExtractors || extractors)[source];
|
|
16
|
+
if (!Number.isFinite(now) || typeof extract !== 'function') return false;
|
|
17
|
+
const metadata = extract(record);
|
|
18
|
+
if (!metadata?.modified) return false;
|
|
19
|
+
const dates = [metadata.modified, metadata.published].filter(x => x != null && x !== '').map(x => typeof x === 'string' ? Date.parse(x) : NaN);
|
|
20
|
+
return dates.length > 0 && dates.every(x => Number.isFinite(x) && x <= now) && now - Math.max(...dates) >= days * DAY_MS;
|
|
21
|
+
}
|
|
22
|
+
module.exports = { METADATA_VERSION, extractors, stableRecord };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const {isInformational}=require('./diagnostics');
|
|
3
|
+
// Older data did not mark ordinary cached observations as informational. Only
|
|
4
|
+
// this exact dated, neutral wording is a compatibility notice; refresh failures,
|
|
5
|
+
// stale/unknown-age data and explicit warning severities remain warnings.
|
|
6
|
+
function legacyFreshness(w){
|
|
7
|
+
if(w?.severity && w.severity!=='info')return null;
|
|
8
|
+
if(w?.type!=='source-stale' || typeof w.message!=='string')return null;
|
|
9
|
+
const match=/^([A-Za-z][\w.-]*): cached data from (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z) was used\.$/.exec(w.message);
|
|
10
|
+
return match ? {source:match[1],at:match[2],message:w.message}:null;
|
|
11
|
+
}
|
|
12
|
+
function partitionReportNotices(values=[]){
|
|
13
|
+
const warnings=[],notices=[],freshness=[];
|
|
14
|
+
for(const item of values){
|
|
15
|
+
if(isInformational(item)){notices.push(item);continue;}
|
|
16
|
+
const legacy=legacyFreshness(item);if(legacy){freshness.push(legacy);continue;}
|
|
17
|
+
warnings.push(item);
|
|
18
|
+
}
|
|
19
|
+
return {warnings,notices,freshness};
|
|
20
|
+
}
|
|
21
|
+
// Group causes for presentation, retaining every distinct location and detail.
|
|
22
|
+
// Raw diagnostics remain available in JSON; unrelated causes never collapse
|
|
23
|
+
// merely because they share a broad warning type.
|
|
24
|
+
function groupReportWarnings(values=[]) {
|
|
25
|
+
const groups=new Map(),out=[];
|
|
26
|
+
for(const item of values) {
|
|
27
|
+
if(item._groupedDiagnostics){out.push(item);continue;}
|
|
28
|
+
const perManifest=item.type==='no-lockfile'||item.type==='parse-error';
|
|
29
|
+
const cause=perManifest ? null : item.reason||item.code||item.message;
|
|
30
|
+
const key=JSON.stringify([item.type,item.severity,item.source||item.sourceId,item.capability,item.applicationId,cause,item.cause,item.status,item.refreshFailure]);
|
|
31
|
+
if(!groups.has(key)){const group=[];groups.set(key,group);out.push(group);}
|
|
32
|
+
groups.get(key).push(item);
|
|
33
|
+
}
|
|
34
|
+
return out.map(group=>{
|
|
35
|
+
if(!Array.isArray(group))return group;
|
|
36
|
+
if(group.length===1)return group[0];
|
|
37
|
+
const messages=new Set(group.map(w=>w.message||'')),items=[],seen=new Set();
|
|
38
|
+
for(const w of group){
|
|
39
|
+
const entries=[...(w.items||[])];
|
|
40
|
+
if(w.manifestPath||w.path||w.artifactTargetId||messages.size>1)entries.unshift({id:w.manifestPath||w.path||w.artifactId||w.artifactTargetId||'',...(w.artifactTargetId?{artifactTargetId:w.artifactTargetId,...((w.manifestPath||w.path)?{manifestPaths:[w.manifestPath||w.path]}:{})}:{}),...((w.manifestPath||w.path)?{pathItem:true}:{}),...(messages.size>1?{detail:w.message||''}:{})});
|
|
41
|
+
for(const entry of entries){const key=JSON.stringify(entry);if(!seen.has(key)){seen.add(key);items.push(entry);}}
|
|
42
|
+
}
|
|
43
|
+
const {manifestPath,path,artifactTargetId,...first}=group[0];
|
|
44
|
+
return {...first,artifactTargetIds:[...new Set(group.map(w=>w.artifactTargetId).filter(Boolean))],message:messages.size===1?first.message:'',count:group.reduce((n,w)=>n+(w.count||1),0),items,_groupedDiagnostics:true};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
module.exports={legacyFreshness,partitionReportNotices,groupReportWarnings};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const esc = value => String(value ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
4
|
+
|
|
5
|
+
// A calendar date is not an instant. Never shift it across days when changing
|
|
6
|
+
// time zones; likewise, do not invent a zone for a timestamp without an offset.
|
|
7
|
+
function renderTime(value, locale = 'en') {
|
|
8
|
+
const epoch = typeof value === 'number' && Number.isFinite(value) ? new Date(value) : null;
|
|
9
|
+
const raw = epoch && Number.isFinite(epoch.getTime()) ? epoch.toISOString() : String(value ?? '');
|
|
10
|
+
const match = /^(\d{4}-\d{2}-\d{2})(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/.exec(raw);
|
|
11
|
+
if (!match) return esc(raw);
|
|
12
|
+
const day = new Date(match[1] + 'T00:00:00Z');
|
|
13
|
+
if (!Number.isFinite(day.getTime()) || day.toISOString().slice(0, 10) !== match[1]) return esc(raw);
|
|
14
|
+
const dateOnly = raw === match[1];
|
|
15
|
+
const clock = /T(\d{2}):(\d{2})(?::(\d{2}))?/.exec(raw);
|
|
16
|
+
if (clock && (+clock[1] > 23 || +clock[2] > 59 || +(clock[3] || 0) > 59)) return esc(raw);
|
|
17
|
+
if (dateOnly) return `<time datetime="${raw}">${raw}</time>`;
|
|
18
|
+
if (!dateOnly && !match[2]) {
|
|
19
|
+
if (!Number.isFinite(Date.parse(raw + 'Z'))) return esc(raw);
|
|
20
|
+
return `<time datetime="${esc(raw)}">${esc(raw.replace('T', ' '))}</time>`;
|
|
21
|
+
}
|
|
22
|
+
const date = dateOnly ? day : new Date(raw);
|
|
23
|
+
if (!Number.isFinite(date.getTime())) return esc(raw);
|
|
24
|
+
const options = { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'UTC' };
|
|
25
|
+
if (!dateOnly) Object.assign(options, { hour: '2-digit', minute: '2-digit', timeZoneName: 'short' });
|
|
26
|
+
return `<time datetime="${esc(raw)}">${esc(new Intl.DateTimeFormat(locale, options).format(date))}</time>`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Serialized into standalone HTML, and exercised with actual Intl time zones.
|
|
30
|
+
function localizeReportTimes(root = document) {
|
|
31
|
+
const locale = root.documentElement.lang || undefined;
|
|
32
|
+
root.querySelectorAll('time[datetime]').forEach(function (el) {
|
|
33
|
+
const raw = el.getAttribute('datetime');
|
|
34
|
+
const dateOnly = /^\d{4}-\d{2}-\d{2}$/.test(raw);
|
|
35
|
+
if (!dateOnly && !/(?:Z|[+-]\d{2}:\d{2})$/.test(raw)) return;
|
|
36
|
+
const date = new Date(raw);
|
|
37
|
+
if (Number.isNaN(date.getTime())) return;
|
|
38
|
+
const options = { year: 'numeric', month: '2-digit', day: '2-digit' };
|
|
39
|
+
if (dateOnly) options.timeZone = 'UTC';
|
|
40
|
+
else Object.assign(options, { hour: '2-digit', minute: '2-digit', timeZoneName: 'short' });
|
|
41
|
+
el.textContent = new Intl.DateTimeFormat(locale, options).format(date);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = { renderTime, localizeReportTimes };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Explain the observed transport failure without treating a proxy refusal as an
|
|
3
|
+
// upstream outage. Never render response bodies, URLs or arbitrary header text.
|
|
4
|
+
function responseFailure(response, { viaProxy = false, now = Date.now() } = {}) {
|
|
5
|
+
const status=Number(response?.status)||null,tag=response?.headers?.get?.('x-fad-proxy');
|
|
6
|
+
const proxy=viaProxy||!!tag;
|
|
7
|
+
const raw=response?.headers?.get?.('retry-after');
|
|
8
|
+
const date=raw ? Date.parse(raw) : NaN;
|
|
9
|
+
const seconds=raw && /^\d+$/.test(raw)?Number(raw):Number.isFinite(date)?Math.max(0,Math.ceil((date-now)/1000)):null;
|
|
10
|
+
const retryAfterSeconds=Number.isSafeInteger(seconds)&&seconds>=0?seconds:null;
|
|
11
|
+
const budget=tag==='denied';
|
|
12
|
+
const origin=budget?'proxy request budget exhausted':proxy&&tag!=='pass'&&tag!=='negative'?'proxy request failed':'source request failed';
|
|
13
|
+
return {code:budget?'proxy-budget-exhausted':proxy&&tag!=='pass'&&tag!=='negative'?'proxy-request-failed':'source-request-failed',
|
|
14
|
+
status,layer:budget||proxy&&tag!=='pass'&&tag!=='negative'?'proxy':'source',
|
|
15
|
+
...(retryAfterSeconds!==null?{retryAfterSeconds}:{}),
|
|
16
|
+
reason:`${origin} (HTTP ${status??'unknown'})${retryAfterSeconds!==null?`; retry after ${retryAfterSeconds}s`:''}`};
|
|
17
|
+
}
|
|
18
|
+
function responseError(label,response,options){
|
|
19
|
+
const failure=responseFailure(response,options),error=Error(`${label}: ${failure.reason}`);
|
|
20
|
+
Object.assign(error,failure);return error;
|
|
21
|
+
}
|
|
22
|
+
module.exports={responseFailure,responseError};
|