@shieldaai/security-watch 0.0.0-stage → 1.0.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 +170 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +202 -0
- package/README.md +394 -2
- package/SECURITY.md +62 -0
- package/dist/assessment.d.ts +16 -0
- package/dist/assessment.js +569 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1105 -0
- package/dist/config.d.ts +302 -0
- package/dist/config.js +381 -0
- package/dist/coverage.d.ts +4 -0
- package/dist/coverage.js +11 -0
- package/dist/cve-now.d.ts +35 -0
- package/dist/cve-now.js +1002 -0
- package/dist/cvss4.d.ts +3 -0
- package/dist/cvss4.js +39 -0
- package/dist/delivery.d.ts +58 -0
- package/dist/delivery.js +687 -0
- package/dist/ecosystems.d.ts +48 -0
- package/dist/ecosystems.js +332 -0
- package/dist/engine.d.ts +80 -0
- package/dist/engine.js +388 -0
- package/dist/everyday-words.d.ts +11 -0
- package/dist/everyday-words.js +256 -0
- package/dist/health.d.ts +24 -0
- package/dist/health.js +122 -0
- package/dist/heartbeat.d.ts +13 -0
- package/dist/heartbeat.js +74 -0
- package/dist/http.d.ts +15 -0
- package/dist/http.js +280 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +23 -0
- package/dist/inventory-evidence.d.ts +10 -0
- package/dist/inventory-evidence.js +206 -0
- package/dist/inventory.d.ts +276 -0
- package/dist/inventory.js +336 -0
- package/dist/lock.d.ts +3 -0
- package/dist/lock.js +112 -0
- package/dist/maintenance.d.ts +48 -0
- package/dist/maintenance.js +295 -0
- package/dist/matching.d.ts +29 -0
- package/dist/matching.js +537 -0
- package/dist/models.d.ts +33 -0
- package/dist/models.js +932 -0
- package/dist/operations.d.ts +17 -0
- package/dist/operations.js +117 -0
- package/dist/pilot-cases.d.ts +171 -0
- package/dist/pilot-cases.js +330 -0
- package/dist/pilot-input.d.ts +16 -0
- package/dist/pilot-input.js +125 -0
- package/dist/pilot-recall.d.ts +166 -0
- package/dist/pilot-recall.js +231 -0
- package/dist/pilot-report.d.ts +113 -0
- package/dist/pilot-report.js +279 -0
- package/dist/pilot-responses.d.ts +111 -0
- package/dist/pilot-responses.js +159 -0
- package/dist/providers.d.ts +209 -0
- package/dist/providers.js +459 -0
- package/dist/python-version.d.ts +3 -0
- package/dist/python-version.js +30 -0
- package/dist/rehearsal.d.ts +440 -0
- package/dist/rehearsal.js +372 -0
- package/dist/sbom.d.ts +13 -0
- package/dist/sbom.js +193 -0
- package/dist/setup.d.ts +113 -0
- package/dist/setup.js +100 -0
- package/dist/source-error.d.ts +38 -0
- package/dist/source-error.js +71 -0
- package/dist/sources.d.ts +3 -0
- package/dist/sources.js +1725 -0
- package/dist/store.d.ts +96 -0
- package/dist/store.js +953 -0
- package/dist/types.d.ts +404 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +29 -0
- package/dist/util.js +94 -0
- package/dist/vendor/cvss4-reference.d.ts +2 -0
- package/dist/vendor/cvss4-reference.js +789 -0
- package/dist/vendor-sources.d.ts +24 -0
- package/dist/vendor-sources.js +56 -0
- package/dist/word-filter.d.ts +3 -0
- package/dist/word-filter.js +3291 -0
- package/docs/alert-outcome-evaluation.md +150 -0
- package/docs/compatibility.md +35 -0
- package/docs/configuration.md +666 -0
- package/docs/cvss-v4-support.md +41 -0
- package/docs/offline-advisory-preview.md +114 -0
- package/docs/offline-rehearsal.md +44 -0
- package/docs/pilot-cases.md +58 -0
- package/docs/pilot-recall.md +124 -0
- package/docs/pilot-report.md +52 -0
- package/docs/validation/alert-outcome-evaluation-2026-11-05.json +2935 -0
- package/docs/validation/cvss-v4-reference-parity-2026-11-05.json +93 -0
- package/docs/validation/rehearsal-accepted-2026-11-05.json +175 -0
- package/docs/validation/rehearsal-unknown-2026-11-05.json +175 -0
- package/docs/vendor/cvss-v4-LICENSE.txt +22 -0
- package/docs/vendor/cvss-v4-provenance.json +38 -0
- package/examples/advisories.json +17 -0
- package/examples/agent-advisories-2026.json +145 -0
- package/examples/agent-advisory-cases-2026.json +397 -0
- package/examples/common-systems.yaml +243 -0
- package/examples/libraries.example.txt +18 -0
- package/examples/libraries.example.yaml +40 -0
- package/examples/library-watch.example.yaml +27 -0
- package/examples/offline-advisory-preview.mjs +42 -0
- package/examples/rehearsal.json +75 -0
- package/examples/security-watch.example.yaml +86 -0
- package/examples/systems.example.yaml +35 -0
- package/package.json +85 -4
package/dist/setup.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export declare const SYSTEM_TEMPLATES: readonly [{
|
|
2
|
+
readonly id: 'nodejs';
|
|
3
|
+
readonly name: 'Node.js';
|
|
4
|
+
readonly keywords: readonly ['NodeJS', 'Node.js runtime'];
|
|
5
|
+
}, {
|
|
6
|
+
readonly id: 'python';
|
|
7
|
+
readonly name: 'Python';
|
|
8
|
+
readonly keywords: readonly ['CPython'];
|
|
9
|
+
}, {
|
|
10
|
+
readonly id: 'java';
|
|
11
|
+
readonly name: 'Java';
|
|
12
|
+
readonly keywords: readonly ['OpenJDK', 'Java SE', 'Oracle JDK'];
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: 'go';
|
|
15
|
+
readonly name: 'Go';
|
|
16
|
+
readonly keywords: readonly ['Golang', 'Go runtime', 'Go standard library'];
|
|
17
|
+
}, {
|
|
18
|
+
readonly id: 'rust';
|
|
19
|
+
readonly name: 'Rust';
|
|
20
|
+
readonly keywords: readonly ['rustc', 'Cargo'];
|
|
21
|
+
}, {
|
|
22
|
+
readonly id: 'php';
|
|
23
|
+
readonly name: 'PHP';
|
|
24
|
+
readonly keywords: readonly [];
|
|
25
|
+
}, {
|
|
26
|
+
readonly id: 'ruby';
|
|
27
|
+
readonly name: 'Ruby';
|
|
28
|
+
readonly keywords: readonly ['Ruby on Rails'];
|
|
29
|
+
}, {
|
|
30
|
+
readonly id: 'dotnet';
|
|
31
|
+
readonly name: '.NET';
|
|
32
|
+
readonly keywords: readonly ['ASP.NET', '.NET Core'];
|
|
33
|
+
}, {
|
|
34
|
+
readonly id: 'linux';
|
|
35
|
+
readonly name: 'Linux';
|
|
36
|
+
readonly keywords: readonly ['Linux kernel'];
|
|
37
|
+
}, {
|
|
38
|
+
readonly id: 'windows';
|
|
39
|
+
readonly name: 'Windows';
|
|
40
|
+
readonly keywords: readonly ['Windows Server'];
|
|
41
|
+
}, {
|
|
42
|
+
readonly id: 'docker';
|
|
43
|
+
readonly name: 'Docker';
|
|
44
|
+
readonly keywords: readonly ['Docker Engine', 'Docker Desktop', 'Moby'];
|
|
45
|
+
}, {
|
|
46
|
+
readonly id: 'kubernetes';
|
|
47
|
+
readonly name: 'Kubernetes';
|
|
48
|
+
readonly keywords: readonly ['kubelet', 'kube-apiserver'];
|
|
49
|
+
}, {
|
|
50
|
+
readonly id: 'nginx';
|
|
51
|
+
readonly name: 'NGINX';
|
|
52
|
+
readonly keywords: readonly [];
|
|
53
|
+
}, {
|
|
54
|
+
readonly id: 'apache-http';
|
|
55
|
+
readonly name: 'Apache HTTP Server';
|
|
56
|
+
readonly keywords: readonly ['Apache httpd'];
|
|
57
|
+
}, {
|
|
58
|
+
readonly id: 'openssl';
|
|
59
|
+
readonly name: 'OpenSSL';
|
|
60
|
+
readonly keywords: readonly [];
|
|
61
|
+
}, {
|
|
62
|
+
readonly id: 'openssh';
|
|
63
|
+
readonly name: 'OpenSSH';
|
|
64
|
+
readonly keywords: readonly [];
|
|
65
|
+
}, {
|
|
66
|
+
readonly id: 'postgresql';
|
|
67
|
+
readonly name: 'PostgreSQL';
|
|
68
|
+
readonly keywords: readonly ['Postgres'];
|
|
69
|
+
}, {
|
|
70
|
+
readonly id: 'mysql';
|
|
71
|
+
readonly name: 'MySQL';
|
|
72
|
+
readonly keywords: readonly [];
|
|
73
|
+
}, {
|
|
74
|
+
readonly id: 'redis';
|
|
75
|
+
readonly name: 'Redis';
|
|
76
|
+
readonly keywords: readonly [];
|
|
77
|
+
}, {
|
|
78
|
+
readonly id: 'mongodb';
|
|
79
|
+
readonly name: 'MongoDB';
|
|
80
|
+
readonly keywords: readonly [];
|
|
81
|
+
}, {
|
|
82
|
+
readonly id: 'git';
|
|
83
|
+
readonly name: 'Git';
|
|
84
|
+
readonly keywords: readonly [];
|
|
85
|
+
}, {
|
|
86
|
+
readonly id: 'jenkins';
|
|
87
|
+
readonly name: 'Jenkins';
|
|
88
|
+
readonly keywords: readonly [];
|
|
89
|
+
}, {
|
|
90
|
+
readonly id: 'elasticsearch';
|
|
91
|
+
readonly name: 'Elasticsearch';
|
|
92
|
+
readonly keywords: readonly [];
|
|
93
|
+
}, {
|
|
94
|
+
readonly id: 'sqlite';
|
|
95
|
+
readonly name: 'SQLite';
|
|
96
|
+
readonly keywords: readonly [];
|
|
97
|
+
}];
|
|
98
|
+
export declare function starterSystems(selection: string, now?: number): {
|
|
99
|
+
id: "apache-http" | "docker" | "dotnet" | "elasticsearch" | "git" | "go" | "java" | "jenkins" | "kubernetes" | "linux" | "mongodb" | "mysql" | "nginx" | "nodejs" | "openssh" | "openssl" | "php" | "postgresql" | "python" | "redis" | "ruby" | "rust" | "sqlite" | "windows";
|
|
100
|
+
name: ".NET" | "Apache HTTP Server" | "Docker" | "Elasticsearch" | "Git" | "Go" | "Java" | "Jenkins" | "Kubernetes" | "Linux" | "MongoDB" | "MySQL" | "NGINX" | "Node.js" | "OpenSSH" | "OpenSSL" | "PHP" | "PostgreSQL" | "Python" | "Redis" | "Ruby" | "Rust" | "SQLite" | "Windows";
|
|
101
|
+
environment: string;
|
|
102
|
+
exposure: string;
|
|
103
|
+
criticality: string;
|
|
104
|
+
updated_at: string;
|
|
105
|
+
components: never[];
|
|
106
|
+
products: {
|
|
107
|
+
name: ".NET" | "Apache HTTP Server" | "Docker" | "Elasticsearch" | "Git" | "Go" | "Java" | "Jenkins" | "Kubernetes" | "Linux" | "MongoDB" | "MySQL" | "NGINX" | "Node.js" | "OpenSSH" | "OpenSSL" | "PHP" | "PostgreSQL" | "Python" | "Redis" | "Ruby" | "Rust" | "SQLite" | "Windows";
|
|
108
|
+
keywords: (".NET Core" | "ASP.NET" | "Apache httpd" | "CPython" | "Cargo" | "Docker Desktop" | "Docker Engine" | "Go runtime" | "Go standard library" | "Golang" | "Java SE" | "Linux kernel" | "Moby" | "Node.js runtime" | "NodeJS" | "OpenJDK" | "Oracle JDK" | "Postgres" | "Ruby on Rails" | "Windows Server" | "kube-apiserver" | "kubelet" | "rustc")[];
|
|
109
|
+
}[];
|
|
110
|
+
keywords: never[];
|
|
111
|
+
}[];
|
|
112
|
+
/** Load dotenv data only when requested. Existing environment values take precedence. */
|
|
113
|
+
export declare function loadEnvFile(path: string): void;
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
|
|
2
|
+
import { parseEnv } from 'node:util';
|
|
3
|
+
export const SYSTEM_TEMPLATES = [
|
|
4
|
+
{ id: 'nodejs', name: 'Node.js', keywords: ['NodeJS', 'Node.js runtime'] },
|
|
5
|
+
{ id: 'python', name: 'Python', keywords: ['CPython'] },
|
|
6
|
+
{ id: 'java', name: 'Java', keywords: ['OpenJDK', 'Java SE', 'Oracle JDK'] },
|
|
7
|
+
{ id: 'go', name: 'Go', keywords: ['Golang', 'Go runtime', 'Go standard library'] },
|
|
8
|
+
{ id: 'rust', name: 'Rust', keywords: ['rustc', 'Cargo'] },
|
|
9
|
+
{ id: 'php', name: 'PHP', keywords: [] },
|
|
10
|
+
{ id: 'ruby', name: 'Ruby', keywords: ['Ruby on Rails'] },
|
|
11
|
+
{ id: 'dotnet', name: '.NET', keywords: ['ASP.NET', '.NET Core'] },
|
|
12
|
+
{ id: 'linux', name: 'Linux', keywords: ['Linux kernel'] },
|
|
13
|
+
{ id: 'windows', name: 'Windows', keywords: ['Windows Server'] },
|
|
14
|
+
{ id: 'docker', name: 'Docker', keywords: ['Docker Engine', 'Docker Desktop', 'Moby'] },
|
|
15
|
+
{ id: 'kubernetes', name: 'Kubernetes', keywords: ['kubelet', 'kube-apiserver'] },
|
|
16
|
+
{ id: 'nginx', name: 'NGINX', keywords: [] },
|
|
17
|
+
{ id: 'apache-http', name: 'Apache HTTP Server', keywords: ['Apache httpd'] },
|
|
18
|
+
{ id: 'openssl', name: 'OpenSSL', keywords: [] },
|
|
19
|
+
{ id: 'openssh', name: 'OpenSSH', keywords: [] },
|
|
20
|
+
{ id: 'postgresql', name: 'PostgreSQL', keywords: ['Postgres'] },
|
|
21
|
+
{ id: 'mysql', name: 'MySQL', keywords: [] },
|
|
22
|
+
{ id: 'redis', name: 'Redis', keywords: [] },
|
|
23
|
+
{ id: 'mongodb', name: 'MongoDB', keywords: [] },
|
|
24
|
+
{ id: 'git', name: 'Git', keywords: [] },
|
|
25
|
+
{ id: 'jenkins', name: 'Jenkins', keywords: [] },
|
|
26
|
+
{ id: 'elasticsearch', name: 'Elasticsearch', keywords: [] },
|
|
27
|
+
{ id: 'sqlite', name: 'SQLite', keywords: [] },
|
|
28
|
+
];
|
|
29
|
+
export function starterSystems(selection, now = Date.now()) {
|
|
30
|
+
const ids = selection.split(',').map((id) => id.trim());
|
|
31
|
+
if (!ids.length || ids.some((id) => !SYSTEM_TEMPLATES.some((template) => template.id === id)))
|
|
32
|
+
throw new Error('Unknown system template. Run security-watch templates for the available names.');
|
|
33
|
+
return [...new Set(ids)].map((id) => {
|
|
34
|
+
const template = SYSTEM_TEMPLATES.find((entry) => entry.id === id);
|
|
35
|
+
return {
|
|
36
|
+
id: template.id,
|
|
37
|
+
name: template.name,
|
|
38
|
+
environment: 'unknown',
|
|
39
|
+
exposure: 'unknown',
|
|
40
|
+
criticality: 'unknown',
|
|
41
|
+
updated_at: new Date(now).toISOString(),
|
|
42
|
+
components: [],
|
|
43
|
+
products: [{ name: template.name, keywords: [...template.keywords] }],
|
|
44
|
+
keywords: [],
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Load dotenv data only when requested. Existing environment values take precedence. */
|
|
49
|
+
export function loadEnvFile(path) {
|
|
50
|
+
let fd;
|
|
51
|
+
try {
|
|
52
|
+
if (!lstatSync(path).isFile())
|
|
53
|
+
throw new Error('Not a regular file');
|
|
54
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new Error('Cannot open the env file. Use a regular private file.');
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const stat = fstatSync(fd);
|
|
61
|
+
if (!stat.isFile() || stat.size > 131_072)
|
|
62
|
+
throw new Error('The env file must be a regular file no larger than 128 KiB.');
|
|
63
|
+
if (process.platform !== 'win32' && (stat.mode & 0o077) !== 0)
|
|
64
|
+
throw new Error('The env file is readable by other users. Run chmod 600 on it first.');
|
|
65
|
+
const buffer = Buffer.alloc(131_073);
|
|
66
|
+
let size = 0;
|
|
67
|
+
while (size < buffer.length) {
|
|
68
|
+
const count = readSync(fd, buffer, size, buffer.length - size, null);
|
|
69
|
+
if (!count)
|
|
70
|
+
break;
|
|
71
|
+
size += count;
|
|
72
|
+
}
|
|
73
|
+
if (size > 131_072)
|
|
74
|
+
throw new Error('The env file exceeds 128 KiB.');
|
|
75
|
+
const text = buffer.toString('utf8', 0, size);
|
|
76
|
+
const values = parseEnv(text);
|
|
77
|
+
if (Object.keys(values)
|
|
78
|
+
.map((name) => name.toUpperCase())
|
|
79
|
+
.some((name) => /^(LD_|DYLD_)/.test(name) ||
|
|
80
|
+
[
|
|
81
|
+
'PATH',
|
|
82
|
+
'HOME',
|
|
83
|
+
'SHELL',
|
|
84
|
+
'NODE_OPTIONS',
|
|
85
|
+
'NODE_TLS_REJECT_UNAUTHORIZED',
|
|
86
|
+
'NODE_EXTRA_CA_CERTS',
|
|
87
|
+
'NODE_USE_SYSTEM_CA',
|
|
88
|
+
'NODE_USE_ENV_PROXY',
|
|
89
|
+
'SSL_CERT_FILE',
|
|
90
|
+
'SSL_CERT_DIR',
|
|
91
|
+
].includes(name)))
|
|
92
|
+
throw new Error('Use the env file for application settings and credentials, not shell or TLS runtime settings.');
|
|
93
|
+
for (const [name, value] of Object.entries(values))
|
|
94
|
+
if (process.env[name] === undefined)
|
|
95
|
+
process.env[name] = value;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
closeSync(fd);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Evidence } from './types.js';
|
|
2
|
+
/** Source diagnostics safe to display without exposing transport credentials. */
|
|
3
|
+
export declare class SourceError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export declare class SourceHttpError extends SourceError {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
constructor(source: string, status: number);
|
|
8
|
+
}
|
|
9
|
+
export declare function sourceCanceled(error: unknown): boolean;
|
|
10
|
+
export declare class PartialSourceError extends SourceError {
|
|
11
|
+
readonly evidence: Evidence[];
|
|
12
|
+
/** How far an ordered collection got. The source continues from here on its next run. */
|
|
13
|
+
readonly resume?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Set when everything the source knows about the inventory's own packages was read, and only
|
|
16
|
+
* other records are missing. Version exclusions drawn from the source then still hold.
|
|
17
|
+
*/
|
|
18
|
+
readonly packageResults?: 'complete' | undefined;
|
|
19
|
+
constructor(message: string, evidence: Evidence[],
|
|
20
|
+
/** How far an ordered collection got. The source continues from here on its next run. */
|
|
21
|
+
resume?: string | undefined,
|
|
22
|
+
/**
|
|
23
|
+
* Set when everything the source knows about the inventory's own packages was read, and only
|
|
24
|
+
* other records are missing. Version exclusions drawn from the source then still hold.
|
|
25
|
+
*/
|
|
26
|
+
packageResults?: 'complete' | undefined);
|
|
27
|
+
}
|
|
28
|
+
export declare function throwSourceFailure(error: unknown, evidence: Evidence[]): never;
|
|
29
|
+
/** Isolate malformed records without accepting a partially validated record. */
|
|
30
|
+
export declare class SourceItemFailures {
|
|
31
|
+
private count;
|
|
32
|
+
private first;
|
|
33
|
+
read<T>(parse: () => T): T | undefined;
|
|
34
|
+
/** What was skipped, for a source that decides for itself how far its checkpoint moves. */
|
|
35
|
+
summary(source: string): string | undefined;
|
|
36
|
+
message(source: string): string | undefined;
|
|
37
|
+
finish(source: string, evidence: Evidence[]): Evidence[];
|
|
38
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Source diagnostics safe to display without exposing transport credentials. */
|
|
2
|
+
export class SourceError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export class SourceHttpError extends SourceError {
|
|
5
|
+
status;
|
|
6
|
+
constructor(source, status) {
|
|
7
|
+
super(`${source} returned HTTP ${status}.`);
|
|
8
|
+
this.status = status;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function sourceCanceled(error) {
|
|
12
|
+
return (error instanceof Error &&
|
|
13
|
+
(error.name === 'AbortError' ||
|
|
14
|
+
('code' in error && ['ABORT_ERR', 'REQUEST_ABORTED'].includes(String(error.code)))));
|
|
15
|
+
}
|
|
16
|
+
export class PartialSourceError extends SourceError {
|
|
17
|
+
evidence;
|
|
18
|
+
resume;
|
|
19
|
+
packageResults;
|
|
20
|
+
constructor(message, evidence,
|
|
21
|
+
/** How far an ordered collection got. The source continues from here on its next run. */
|
|
22
|
+
resume,
|
|
23
|
+
/**
|
|
24
|
+
* Set when everything the source knows about the inventory's own packages was read, and only
|
|
25
|
+
* other records are missing. Version exclusions drawn from the source then still hold.
|
|
26
|
+
*/
|
|
27
|
+
packageResults) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.evidence = evidence;
|
|
30
|
+
this.resume = resume;
|
|
31
|
+
this.packageResults = packageResults;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function throwSourceFailure(error, evidence) {
|
|
35
|
+
if (sourceCanceled(error) || !evidence.length || error instanceof PartialSourceError)
|
|
36
|
+
throw error;
|
|
37
|
+
const message = error instanceof SourceError ? error.message : 'Source request failed.';
|
|
38
|
+
throw new PartialSourceError(`${message} Valid records were retained; collection remains incomplete and its checkpoint was not advanced.`, evidence);
|
|
39
|
+
}
|
|
40
|
+
/** Isolate malformed records without accepting a partially validated record. */
|
|
41
|
+
export class SourceItemFailures {
|
|
42
|
+
count = 0;
|
|
43
|
+
first;
|
|
44
|
+
read(parse) {
|
|
45
|
+
try {
|
|
46
|
+
return parse();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!(error instanceof SourceError) || error instanceof PartialSourceError)
|
|
50
|
+
throw error;
|
|
51
|
+
this.count++;
|
|
52
|
+
this.first ??= error.message;
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** What was skipped, for a source that decides for itself how far its checkpoint moves. */
|
|
57
|
+
summary(source) {
|
|
58
|
+
return this.count
|
|
59
|
+
? `${source}: ${this.count} invalid item(s) were skipped. ${this.first} Collection remains incomplete.`
|
|
60
|
+
: undefined;
|
|
61
|
+
}
|
|
62
|
+
message(source) {
|
|
63
|
+
return this.summary(source)?.replace(/\.$/, ' and its checkpoint was not advanced.');
|
|
64
|
+
}
|
|
65
|
+
finish(source, evidence) {
|
|
66
|
+
const message = this.message(source);
|
|
67
|
+
if (message)
|
|
68
|
+
throw new PartialSourceError(message, evidence);
|
|
69
|
+
return evidence;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Config, CoverageReceipt, Evidence, HttpClient, Inventory, SourceResult } from './types.js';
|
|
2
|
+
/** Collect source evidence and report failures without advancing failed sources' checkpoints. */
|
|
3
|
+
export declare function collectSources(inventory: Inventory, config: Config, checkpoints: Record<string, string>, http: HttpClient, now?: number, previousEvidence?: Evidence[], previousCoverage?: CoverageReceipt[]): Promise<SourceResult>;
|