@crimson-crawler/crimson-crawler-client 4.1.1
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/LICENSE +202 -0
- package/NOTICE +14 -0
- package/README.md +940 -0
- package/dist/.package-build.json +29 -0
- package/dist/_generated/client.gen.cjs +11 -0
- package/dist/_generated/client.gen.d.cts +15 -0
- package/dist/_generated/client.gen.d.ts +15 -0
- package/dist/_generated/client.gen.js +2 -0
- package/dist/_generated/index.cjs +140 -0
- package/dist/_generated/index.d.cts +3 -0
- package/dist/_generated/index.d.ts +3 -0
- package/dist/_generated/index.js +3 -0
- package/dist/_generated/sdk.gen.cjs +140 -0
- package/dist/_generated/sdk.gen.d.cts +946 -0
- package/dist/_generated/sdk.gen.d.ts +946 -0
- package/dist/_generated/sdk.gen.js +3 -0
- package/dist/_generated/types.gen.cjs +2 -0
- package/dist/_generated/types.gen.d.cts +9950 -0
- package/dist/_generated/types.gen.d.ts +9950 -0
- package/dist/_generated/types.gen.js +1 -0
- package/dist/chunk-2X3CCE46.js +294 -0
- package/dist/chunk-4CXMKUDH.cjs +783 -0
- package/dist/chunk-4HSWOQA6.cjs +328 -0
- package/dist/chunk-4PCL3ANB.cjs +190 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-C53EHGN4.js +170 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-QU4MM663.js +780 -0
- package/dist/index.cjs +2507 -0
- package/dist/index.d.cts +1283 -0
- package/dist/index.d.ts +1283 -0
- package/dist/index.js +2487 -0
- package/dist/presets-BMN8jy08.d.cts +110 -0
- package/dist/presets-BMN8jy08.d.ts +110 -0
- package/dist/presets.cjs +79 -0
- package/dist/presets.d.cts +1 -0
- package/dist/presets.d.ts +1 -0
- package/dist/presets.js +2 -0
- package/dist/types.gen-ObPczyUH.d.cts +327 -0
- package/dist/types.gen-ObPczyUH.d.ts +327 -0
- package/package.json +131 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2507 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk4PCL3ANB_cjs = require('./chunk-4PCL3ANB.cjs');
|
|
4
|
+
var chunk4HSWOQA6_cjs = require('./chunk-4HSWOQA6.cjs');
|
|
5
|
+
var chunk4CXMKUDH_cjs = require('./chunk-4CXMKUDH.cjs');
|
|
6
|
+
require('./chunk-75ZPJI57.cjs');
|
|
7
|
+
|
|
8
|
+
// src/exceptions.ts
|
|
9
|
+
var CrawlerClientError = class extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "CrawlerClientError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var MissingCredentials = class extends CrawlerClientError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "MissingCredentials";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var UnexpectedStatus = class extends CrawlerClientError {
|
|
22
|
+
constructor(status, body, message) {
|
|
23
|
+
super(message ?? `Unexpected response status ${status}`);
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.body = body;
|
|
26
|
+
this.name = "UnexpectedStatus";
|
|
27
|
+
}
|
|
28
|
+
status;
|
|
29
|
+
body;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/_auth.ts
|
|
33
|
+
function withApiKeyHeader(input, init, headerName, apiKey, origin) {
|
|
34
|
+
const inherited = init?.headers ?? (input instanceof Request ? input.headers : void 0);
|
|
35
|
+
const headers = new Headers(inherited);
|
|
36
|
+
const raw = typeof input === "string" ? input : input instanceof URL ? input.href : input instanceof Request ? input.url : String(input);
|
|
37
|
+
let sameOrigin;
|
|
38
|
+
try {
|
|
39
|
+
sameOrigin = new URL(raw).origin === origin;
|
|
40
|
+
} catch {
|
|
41
|
+
sameOrigin = true;
|
|
42
|
+
}
|
|
43
|
+
if (sameOrigin) {
|
|
44
|
+
headers.set(headerName, apiKey);
|
|
45
|
+
}
|
|
46
|
+
return headers;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/url.ts
|
|
50
|
+
function pathSegment(value) {
|
|
51
|
+
return encodeURIComponent(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/ai-reports.ts
|
|
55
|
+
var MAX_BUFFERED_RAW_BYTES = 1e7;
|
|
56
|
+
async function readBufferedText(resp) {
|
|
57
|
+
const declared = Number(resp.headers.get("content-length"));
|
|
58
|
+
if (Number.isFinite(declared) && declared > MAX_BUFFERED_RAW_BYTES) {
|
|
59
|
+
await resp.body?.cancel().catch(() => void 0);
|
|
60
|
+
throw new RangeError(
|
|
61
|
+
`raw response exceeds the ${MAX_BUFFERED_RAW_BYTES}-byte buffer limit`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (!resp.body) return "";
|
|
65
|
+
const reader = resp.body.getReader();
|
|
66
|
+
const decoder = new TextDecoder();
|
|
67
|
+
const parts = [];
|
|
68
|
+
let size = 0;
|
|
69
|
+
for (; ; ) {
|
|
70
|
+
const { done, value } = await reader.read();
|
|
71
|
+
if (done) break;
|
|
72
|
+
size += value.byteLength;
|
|
73
|
+
if (size > MAX_BUFFERED_RAW_BYTES) {
|
|
74
|
+
await reader.cancel().catch(() => void 0);
|
|
75
|
+
throw new RangeError(
|
|
76
|
+
`raw response exceeds the ${MAX_BUFFERED_RAW_BYTES}-byte buffer limit`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
parts.push(decoder.decode(value, { stream: true }));
|
|
80
|
+
}
|
|
81
|
+
parts.push(decoder.decode());
|
|
82
|
+
return parts.join("");
|
|
83
|
+
}
|
|
84
|
+
function downloadFilename(disposition, fallback) {
|
|
85
|
+
let candidate;
|
|
86
|
+
const encoded = disposition.match(/filename\*\s*=\s*UTF-8''([^;]+)/i)?.[1]?.trim();
|
|
87
|
+
if (encoded) {
|
|
88
|
+
try {
|
|
89
|
+
candidate = decodeURIComponent(encoded);
|
|
90
|
+
} catch {
|
|
91
|
+
candidate = void 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
candidate ??= disposition.match(/filename\s*=\s*"([^"]*)"/i)?.[1];
|
|
95
|
+
candidate ??= disposition.match(/filename\s*=\s*([^;\s]+)/i)?.[1];
|
|
96
|
+
const basename = candidate?.replace(/\\/g, "/").split("/").at(-1)?.trim();
|
|
97
|
+
const hasControl = basename !== void 0 && Array.from(basename).some((ch) => ch < " " || ch === "\x7F");
|
|
98
|
+
if (!basename || basename === "." || basename === ".." || hasControl) {
|
|
99
|
+
return fallback;
|
|
100
|
+
}
|
|
101
|
+
return basename;
|
|
102
|
+
}
|
|
103
|
+
var AiReportsApi = class {
|
|
104
|
+
baseUrl;
|
|
105
|
+
// True ES2022 private field, not TypeScript `private`: `private` is erased at compile
|
|
106
|
+
// time, leaving an enumerable own property that JSON.stringify and
|
|
107
|
+
// util.inspect (so console.log) print in cleartext. `#` is enforced by the
|
|
108
|
+
// runtime and invisible to both.
|
|
109
|
+
#apiKey;
|
|
110
|
+
doFetch;
|
|
111
|
+
constructor(baseUrl, apiKey, doFetch) {
|
|
112
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
113
|
+
this.#apiKey = apiKey;
|
|
114
|
+
this.doFetch = doFetch;
|
|
115
|
+
}
|
|
116
|
+
async request(method, path, opts = {}) {
|
|
117
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
118
|
+
for (const [k, v] of Object.entries(opts.params ?? {}))
|
|
119
|
+
url.searchParams.set(k, v);
|
|
120
|
+
const resp = await this.doFetch(url, {
|
|
121
|
+
method,
|
|
122
|
+
headers: {
|
|
123
|
+
apikey: this.#apiKey,
|
|
124
|
+
...opts.json !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
125
|
+
},
|
|
126
|
+
...opts.json !== void 0 ? { body: JSON.stringify(opts.json) } : {}
|
|
127
|
+
});
|
|
128
|
+
if (!resp.ok) {
|
|
129
|
+
const body = await resp.text().catch(() => "");
|
|
130
|
+
throw new UnexpectedStatus(
|
|
131
|
+
resp.status,
|
|
132
|
+
body,
|
|
133
|
+
`Report Generator API ${resp.status} on ${path}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return resp;
|
|
137
|
+
}
|
|
138
|
+
// -- Discovery + templates --------------------------------------------- //
|
|
139
|
+
/** `GET /ai-reports` — the self-documenting endpoint map + your account context. */
|
|
140
|
+
async discovery() {
|
|
141
|
+
return await (await this.request("GET", "/ai-reports")).json();
|
|
142
|
+
}
|
|
143
|
+
/** The built-in report templates — each `{id, name, description?, ai_sections:[{section_type, label}], needs?}`. */
|
|
144
|
+
async listTemplates() {
|
|
145
|
+
const data = await (await this.request("GET", "/ai-reports/templates")).json();
|
|
146
|
+
return data.templates;
|
|
147
|
+
}
|
|
148
|
+
// -- Reports ----------------------------------------------------------- //
|
|
149
|
+
/** Your saved reports (newest first, no content) — `kind=report` artifacts. */
|
|
150
|
+
async listReports() {
|
|
151
|
+
const data = await (await this.request("GET", "/ai-reports/reports")).json();
|
|
152
|
+
return data.reports;
|
|
153
|
+
}
|
|
154
|
+
/** One report in full, including inline `content` (the report HTML). */
|
|
155
|
+
async getReport(reportId) {
|
|
156
|
+
const data = await (await this.request("GET", `/ai-reports/reports/${pathSegment(reportId)}`)).json();
|
|
157
|
+
return data.report;
|
|
158
|
+
}
|
|
159
|
+
/** Read a report's raw HTML into a string buffer (maximum 10,000,000 bytes; not a streaming return type).
|
|
160
|
+
* Resolves `{ content, id, kind, name, format, createdAt }`. */
|
|
161
|
+
async getReportRaw(reportId) {
|
|
162
|
+
const resp = await this.request(
|
|
163
|
+
"GET",
|
|
164
|
+
`/ai-reports/reports/${pathSegment(reportId)}`,
|
|
165
|
+
{ params: { raw: "1" } }
|
|
166
|
+
);
|
|
167
|
+
return {
|
|
168
|
+
content: await readBufferedText(resp),
|
|
169
|
+
id: resp.headers.get("x-artifact-id") ?? reportId,
|
|
170
|
+
kind: resp.headers.get("x-artifact-kind") ?? "",
|
|
171
|
+
name: resp.headers.get("x-artifact-name") ?? "",
|
|
172
|
+
format: resp.headers.get("x-artifact-format") ?? "",
|
|
173
|
+
createdAt: resp.headers.get("x-artifact-created") ?? ""
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Create a DRAFT report from a template + source artifacts. Renders the scaffold (static +
|
|
178
|
+
* deterministic data sections) and returns the list of AI sections still to fill.
|
|
179
|
+
*
|
|
180
|
+
* Resolves `{ id, name, html, ai_sections: [{section_type, label, ...}], skipped: [...] }`.
|
|
181
|
+
*/
|
|
182
|
+
async createDraft(template, options = {}) {
|
|
183
|
+
const body = { template };
|
|
184
|
+
if (options.sourceIds !== void 0) body.source_ids = options.sourceIds;
|
|
185
|
+
if (options.name !== void 0) body.name = options.name;
|
|
186
|
+
return await (await this.request("POST", "/ai-reports/reports", { json: body })).json();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Generate ONE grounded AI section of a draft (omit `sectionType` to fill the next pending one).
|
|
190
|
+
* Resolves `{ section_type, filled, truncated, remaining: [...], complete }`. Throws
|
|
191
|
+
* `UnexpectedStatus` (409) when no sections remain or (502) on a copilot failure.
|
|
192
|
+
*/
|
|
193
|
+
async fillSection(reportId, sectionType) {
|
|
194
|
+
const body = {};
|
|
195
|
+
if (sectionType !== void 0) body.section_type = sectionType;
|
|
196
|
+
return await (await this.request(
|
|
197
|
+
"POST",
|
|
198
|
+
`/ai-reports/reports/${pathSegment(reportId)}/sections`,
|
|
199
|
+
{ json: body }
|
|
200
|
+
)).json();
|
|
201
|
+
}
|
|
202
|
+
/** Rename a report. Resolves the updated report. */
|
|
203
|
+
async renameReport(reportId, name) {
|
|
204
|
+
const data = await (await this.request(
|
|
205
|
+
"PATCH",
|
|
206
|
+
`/ai-reports/reports/${pathSegment(reportId)}`,
|
|
207
|
+
{ json: { name } }
|
|
208
|
+
)).json();
|
|
209
|
+
return data.report;
|
|
210
|
+
}
|
|
211
|
+
/** Delete a report. Resolves `true` on success (404 throws). */
|
|
212
|
+
async deleteReport(reportId) {
|
|
213
|
+
const resp = await this.request(
|
|
214
|
+
"DELETE",
|
|
215
|
+
`/ai-reports/reports/${pathSegment(reportId)}`
|
|
216
|
+
);
|
|
217
|
+
const data = await resp.json();
|
|
218
|
+
return Boolean(data.deleted);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generate a single grounded section ad-hoc (NOT tied to a stored report) from `sourceIds`.
|
|
222
|
+
* Provide `sectionType` (a template section) and/or a free-text `instruction`. Resolves
|
|
223
|
+
* `{ text, truncated, grounded, unsupported_ids }`.
|
|
224
|
+
*/
|
|
225
|
+
async section(sourceIds, options = {}) {
|
|
226
|
+
const body = { source_ids: sourceIds };
|
|
227
|
+
if (options.sectionType !== void 0)
|
|
228
|
+
body.section_type = options.sectionType;
|
|
229
|
+
if (options.instruction !== void 0)
|
|
230
|
+
body.instruction = options.instruction;
|
|
231
|
+
if (options.selection !== void 0) body.selection = options.selection;
|
|
232
|
+
if (options.verbosity !== void 0) body.verbosity = options.verbosity;
|
|
233
|
+
return await (await this.request("POST", "/ai-reports/section", { json: body })).json();
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Export a report as `html` or `md`. The body IS the export file.
|
|
237
|
+
*
|
|
238
|
+
* Resolves `{ content, bytes, filename, contentType }`. `filename` is a sanitized basename from
|
|
239
|
+
* `Content-Disposition`. PDF/DOCX are browser-editor-only; browser-authored reports throw 422 here.
|
|
240
|
+
*/
|
|
241
|
+
async exportReport(reportId, fmt = "html") {
|
|
242
|
+
const resp = await this.request(
|
|
243
|
+
"GET",
|
|
244
|
+
`/ai-reports/reports/${pathSegment(reportId)}/export/${pathSegment(fmt)}`
|
|
245
|
+
);
|
|
246
|
+
const disposition = resp.headers.get("content-disposition") ?? "";
|
|
247
|
+
const filename = downloadFilename(disposition, `${reportId}.${fmt}`);
|
|
248
|
+
const bytes = new Uint8Array(await resp.arrayBuffer());
|
|
249
|
+
return {
|
|
250
|
+
content: new TextDecoder().decode(bytes),
|
|
251
|
+
bytes,
|
|
252
|
+
filename,
|
|
253
|
+
contentType: resp.headers.get("content-type") ?? ""
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Generate a report end-to-end: create the draft, fill every AI section, return the finished
|
|
258
|
+
* report. The convenience over `createDraft` + `fillSection`.
|
|
259
|
+
*
|
|
260
|
+
* If a section's copilot call fails (502), generation stops there and returns what filled so far:
|
|
261
|
+
* the report keeps the sections completed before the failure, the failed section is recorded in
|
|
262
|
+
* `sections` as `{ error: "generation failed", status: 502 }`, and that section plus any after it
|
|
263
|
+
* stay unfilled cards. Re-run `generateReport` or fill the rest individually with `fillSection`.
|
|
264
|
+
*
|
|
265
|
+
* Resolves `{ report, sections: [<fill result per section>], skipped: [...] }`.
|
|
266
|
+
*/
|
|
267
|
+
async generateReport(template, options = {}) {
|
|
268
|
+
const draft = await this.createDraft(template, options);
|
|
269
|
+
const reportId = String(draft.id);
|
|
270
|
+
const pending = Array.isArray(draft.ai_sections) ? draft.ai_sections : [];
|
|
271
|
+
const sections = [];
|
|
272
|
+
for (let i = 0; i < pending.length; i++) {
|
|
273
|
+
let result;
|
|
274
|
+
try {
|
|
275
|
+
result = await this.fillSection(reportId);
|
|
276
|
+
} catch (err) {
|
|
277
|
+
if (err instanceof UnexpectedStatus && err.status === 409) break;
|
|
278
|
+
if (err instanceof UnexpectedStatus && err.status === 502) {
|
|
279
|
+
sections.push({ error: "generation failed", status: 502 });
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
throw err;
|
|
283
|
+
}
|
|
284
|
+
sections.push(result);
|
|
285
|
+
if (result.complete) break;
|
|
286
|
+
}
|
|
287
|
+
const report = await this.getReport(reportId);
|
|
288
|
+
return { report, sections, skipped: draft.skipped ?? [] };
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// src/artifact-manager.ts
|
|
293
|
+
var MAX_BUFFERED_RAW_BYTES2 = 1e7;
|
|
294
|
+
async function readBufferedText2(resp) {
|
|
295
|
+
const declared = Number(resp.headers.get("content-length"));
|
|
296
|
+
if (Number.isFinite(declared) && declared > MAX_BUFFERED_RAW_BYTES2) {
|
|
297
|
+
await resp.body?.cancel().catch(() => void 0);
|
|
298
|
+
throw new RangeError(
|
|
299
|
+
`raw response exceeds the ${MAX_BUFFERED_RAW_BYTES2}-byte buffer limit`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (!resp.body) return "";
|
|
303
|
+
const reader = resp.body.getReader();
|
|
304
|
+
const decoder = new TextDecoder();
|
|
305
|
+
const parts = [];
|
|
306
|
+
let size = 0;
|
|
307
|
+
for (; ; ) {
|
|
308
|
+
const { done, value } = await reader.read();
|
|
309
|
+
if (done) break;
|
|
310
|
+
size += value.byteLength;
|
|
311
|
+
if (size > MAX_BUFFERED_RAW_BYTES2) {
|
|
312
|
+
await reader.cancel().catch(() => void 0);
|
|
313
|
+
throw new RangeError(
|
|
314
|
+
`raw response exceeds the ${MAX_BUFFERED_RAW_BYTES2}-byte buffer limit`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
parts.push(decoder.decode(value, { stream: true }));
|
|
318
|
+
}
|
|
319
|
+
parts.push(decoder.decode());
|
|
320
|
+
return parts.join("");
|
|
321
|
+
}
|
|
322
|
+
function decodeHeader(value, fallback) {
|
|
323
|
+
if (!value) return fallback;
|
|
324
|
+
try {
|
|
325
|
+
return decodeURIComponent(value);
|
|
326
|
+
} catch {
|
|
327
|
+
return fallback;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function downloadFilename2(disposition, fallback) {
|
|
331
|
+
let candidate;
|
|
332
|
+
const encoded = disposition.match(/filename\*\s*=\s*UTF-8''([^;]+)/i)?.[1]?.trim();
|
|
333
|
+
if (encoded) {
|
|
334
|
+
try {
|
|
335
|
+
candidate = decodeURIComponent(encoded);
|
|
336
|
+
} catch {
|
|
337
|
+
candidate = void 0;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
candidate ??= disposition.match(/filename\s*=\s*"([^"]*)"/i)?.[1];
|
|
341
|
+
candidate ??= disposition.match(/filename\s*=\s*([^;\s]+)/i)?.[1];
|
|
342
|
+
const basename = candidate?.replace(/\\/g, "/").split("/").at(-1)?.trim();
|
|
343
|
+
const hasControl = basename !== void 0 && Array.from(basename).some((ch) => ch < " " || ch === "\x7F");
|
|
344
|
+
if (!basename || basename === "." || basename === ".." || hasControl) {
|
|
345
|
+
return fallback;
|
|
346
|
+
}
|
|
347
|
+
return basename;
|
|
348
|
+
}
|
|
349
|
+
var ArtifactManagerApi = class {
|
|
350
|
+
baseUrl;
|
|
351
|
+
// True ES2022 private field, not TypeScript `private`: `private` is erased at compile
|
|
352
|
+
// time, leaving an enumerable own property that JSON.stringify and
|
|
353
|
+
// util.inspect (so console.log) print in cleartext. `#` is enforced by the
|
|
354
|
+
// runtime and invisible to both.
|
|
355
|
+
#apiKey;
|
|
356
|
+
doFetch;
|
|
357
|
+
constructor(baseUrl, apiKey, doFetch) {
|
|
358
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
359
|
+
this.#apiKey = apiKey;
|
|
360
|
+
this.doFetch = doFetch;
|
|
361
|
+
}
|
|
362
|
+
async request(method, path, opts = {}) {
|
|
363
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
364
|
+
for (const [k, v] of Object.entries(opts.params ?? {}))
|
|
365
|
+
url.searchParams.set(k, v);
|
|
366
|
+
const resp = await this.doFetch(url, {
|
|
367
|
+
method,
|
|
368
|
+
headers: {
|
|
369
|
+
apikey: this.#apiKey,
|
|
370
|
+
...opts.json !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
371
|
+
},
|
|
372
|
+
...opts.json !== void 0 ? { body: JSON.stringify(opts.json) } : {}
|
|
373
|
+
});
|
|
374
|
+
if (!resp.ok) {
|
|
375
|
+
const body = await resp.text().catch(() => "");
|
|
376
|
+
throw new UnexpectedStatus(
|
|
377
|
+
resp.status,
|
|
378
|
+
body,
|
|
379
|
+
`Artifact Manager API ${resp.status} on ${path}`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
return resp;
|
|
383
|
+
}
|
|
384
|
+
// -- Discovery ---------------------------------------------------------- //
|
|
385
|
+
/** `GET /artifact-manager` — the self-documenting endpoint map + your account context. */
|
|
386
|
+
async discovery() {
|
|
387
|
+
return (await this.request("GET", "/artifact-manager")).json();
|
|
388
|
+
}
|
|
389
|
+
// -- Artifacts ---------------------------------------------------------- //
|
|
390
|
+
/**
|
|
391
|
+
* List your artifacts (newest first, no content).
|
|
392
|
+
*
|
|
393
|
+
* @param options `kind` (input|enrichment|report) · `folder` (UUID or `"__root__"`)
|
|
394
|
+
* · `since`/`until` (ISO `created_at` window).
|
|
395
|
+
*/
|
|
396
|
+
async listArtifacts(options = {}) {
|
|
397
|
+
const params = {};
|
|
398
|
+
if (options.kind) params.kind = options.kind;
|
|
399
|
+
if (options.folder) params.folder = options.folder;
|
|
400
|
+
if (options.since) params.since = options.since;
|
|
401
|
+
if (options.until) params.until = options.until;
|
|
402
|
+
const resp = await this.request("GET", "/artifact-manager/artifacts", {
|
|
403
|
+
params
|
|
404
|
+
});
|
|
405
|
+
return (await resp.json()).artifacts;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Upload input artifacts (max 20/call, ≤10 MB content each).
|
|
409
|
+
*
|
|
410
|
+
* @param artifacts Each `{ name, content, format: "paste"|"file", mime? }`.
|
|
411
|
+
* @param options File into an existing `folderId`, or create one via `newFolderName`.
|
|
412
|
+
* @returns `{ ids, folderId }` — the new artifact ids.
|
|
413
|
+
*/
|
|
414
|
+
async uploadArtifacts(artifacts, options = {}) {
|
|
415
|
+
const body = { artifacts };
|
|
416
|
+
if (options.folderId !== void 0) body.folderId = options.folderId;
|
|
417
|
+
if (options.newFolderName !== void 0)
|
|
418
|
+
body.newFolderName = options.newFolderName;
|
|
419
|
+
const resp = await this.request("POST", "/artifact-manager/artifacts", {
|
|
420
|
+
json: body
|
|
421
|
+
});
|
|
422
|
+
return await resp.json();
|
|
423
|
+
}
|
|
424
|
+
/** One artifact in full, including inline `content`. */
|
|
425
|
+
async getArtifact(artifactId) {
|
|
426
|
+
const resp = await this.request(
|
|
427
|
+
"GET",
|
|
428
|
+
`/artifact-manager/artifacts/${pathSegment(artifactId)}`
|
|
429
|
+
);
|
|
430
|
+
return (await resp.json()).artifact;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Read an artifact's raw body into a string buffer (maximum 10,000,000 bytes; this is not a
|
|
434
|
+
* streaming return type). Metadata rides `X-Artifact-*` headers.
|
|
435
|
+
*/
|
|
436
|
+
async getArtifactRaw(artifactId) {
|
|
437
|
+
const resp = await this.request(
|
|
438
|
+
"GET",
|
|
439
|
+
`/artifact-manager/artifacts/${pathSegment(artifactId)}`,
|
|
440
|
+
{
|
|
441
|
+
params: { raw: "1" }
|
|
442
|
+
}
|
|
443
|
+
);
|
|
444
|
+
return {
|
|
445
|
+
content: await readBufferedText2(resp),
|
|
446
|
+
id: resp.headers.get("x-artifact-id") ?? artifactId,
|
|
447
|
+
kind: resp.headers.get("x-artifact-kind") ?? "",
|
|
448
|
+
name: decodeHeader(resp.headers.get("x-artifact-name"), artifactId),
|
|
449
|
+
format: resp.headers.get("x-artifact-format") ?? "",
|
|
450
|
+
mime: resp.headers.get("x-artifact-mime") ?? "",
|
|
451
|
+
created_at: resp.headers.get("x-artifact-created") ?? ""
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Partial update: rename, star/unstar, and/or move between folders.
|
|
456
|
+
*
|
|
457
|
+
* `folderId: null` moves the artifact back to root; omit it to leave the
|
|
458
|
+
* folder unchanged.
|
|
459
|
+
*/
|
|
460
|
+
async updateArtifact(artifactId, update) {
|
|
461
|
+
const body = {};
|
|
462
|
+
if (update.name !== void 0) body.name = update.name;
|
|
463
|
+
if (update.favorite !== void 0) body.favorite = update.favorite;
|
|
464
|
+
if ("folderId" in update) body.folderId = update.folderId;
|
|
465
|
+
const resp = await this.request(
|
|
466
|
+
"PATCH",
|
|
467
|
+
`/artifact-manager/artifacts/${pathSegment(artifactId)}`,
|
|
468
|
+
{ json: body }
|
|
469
|
+
);
|
|
470
|
+
return (await resp.json()).artifact;
|
|
471
|
+
}
|
|
472
|
+
/** Delete one artifact. Resolves `true` on success (404 throws). */
|
|
473
|
+
async deleteArtifact(artifactId) {
|
|
474
|
+
const resp = await this.request(
|
|
475
|
+
"DELETE",
|
|
476
|
+
`/artifact-manager/artifacts/${pathSegment(artifactId)}`
|
|
477
|
+
);
|
|
478
|
+
return Boolean((await resp.json()).deleted);
|
|
479
|
+
}
|
|
480
|
+
/** Duplicate an artifact as "Copy of …". Resolves to the new artifact id. */
|
|
481
|
+
async copyArtifact(artifactId) {
|
|
482
|
+
const resp = await this.request(
|
|
483
|
+
"POST",
|
|
484
|
+
`/artifact-manager/artifacts/${pathSegment(artifactId)}/copy`
|
|
485
|
+
);
|
|
486
|
+
return (await resp.json()).id;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Persist a COMPLETED artifact enrichment into your library, by its engine `enrichmentId`.
|
|
490
|
+
*
|
|
491
|
+
* The programmatic equivalent of the portal's "Save enrichment" button. Run `client.enricher.enrich`
|
|
492
|
+
* (`POST /v1/artifact-enrich` → poll), then pass the returned `enrichment_id` here to file the finished
|
|
493
|
+
* report as a `kind=artifact_enrichment` artifact on your account (or use `enrich({ save: true })` to do both in
|
|
494
|
+
* one call). The engine returns the report but never persists it — this is the only way to add it to the
|
|
495
|
+
* Artifact Manager. Idempotent (a repeat returns `{ already_persisted: true }`). Optionally file it into
|
|
496
|
+
* a folder by id (`folderId`) or create one (`newFolderName`). Usage-exempt. Resolves to
|
|
497
|
+
* `{ enrichment_artifact_id }` (or `{ already_persisted: true }`). Save within ~1 h of completion.
|
|
498
|
+
*/
|
|
499
|
+
async saveEnrichment(enrichmentId, opts = {}) {
|
|
500
|
+
const body = { enrichment_id: enrichmentId };
|
|
501
|
+
if (opts.folderId || opts.newFolderName) {
|
|
502
|
+
body.folder = {
|
|
503
|
+
folder_id: opts.folderId ?? null,
|
|
504
|
+
new_folder_name: opts.newFolderName ?? null
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
const resp = await this.request(
|
|
508
|
+
"POST",
|
|
509
|
+
"/artifact-manager/artifacts/from-enrichment",
|
|
510
|
+
{ json: body }
|
|
511
|
+
);
|
|
512
|
+
return await resp.json();
|
|
513
|
+
}
|
|
514
|
+
// -- Bulk operations ---------------------------------------------------- //
|
|
515
|
+
/** Delete many artifacts in one call (≤200/call). Resolves to the number removed. */
|
|
516
|
+
async bulkDelete(artifactIds) {
|
|
517
|
+
const resp = await this.request(
|
|
518
|
+
"POST",
|
|
519
|
+
"/artifact-manager/artifacts/bulk",
|
|
520
|
+
{
|
|
521
|
+
json: { op: "delete", ids: artifactIds }
|
|
522
|
+
}
|
|
523
|
+
);
|
|
524
|
+
return (await resp.json()).count;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Move many artifacts into a folder (≤200/call). `folderId: null` un-files them
|
|
528
|
+
* to root. Resolves to the number moved.
|
|
529
|
+
*/
|
|
530
|
+
async moveToFolder(artifactIds, folderId = null) {
|
|
531
|
+
const resp = await this.request(
|
|
532
|
+
"POST",
|
|
533
|
+
"/artifact-manager/artifacts/bulk",
|
|
534
|
+
{
|
|
535
|
+
json: { op: "move", ids: artifactIds, folder_id: folderId }
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
return (await resp.json()).count;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Star (`favorite: true`) or unstar (`false`) many artifacts at once (≤200/call).
|
|
542
|
+
* Resolves to the number updated.
|
|
543
|
+
*/
|
|
544
|
+
async bulkSetFavorite(artifactIds, favorite) {
|
|
545
|
+
const resp = await this.request(
|
|
546
|
+
"POST",
|
|
547
|
+
"/artifact-manager/artifacts/bulk",
|
|
548
|
+
{
|
|
549
|
+
json: { op: "favorite", ids: artifactIds, favorite }
|
|
550
|
+
}
|
|
551
|
+
);
|
|
552
|
+
return (await resp.json()).count;
|
|
553
|
+
}
|
|
554
|
+
/** Bundle an explicit set of your artifacts into one `.zip` (the bulk "Download .zip"). Enrichments
|
|
555
|
+
* contribute their machine exports under a per-enrichment subfolder; every other kind contributes its raw
|
|
556
|
+
* deliverable. Returns the raw `.zip` bytes. See {@link downloadFolder} for the whole-folder twin. */
|
|
557
|
+
async downloadBundle(artifactIds) {
|
|
558
|
+
const resp = await this.request(
|
|
559
|
+
"POST",
|
|
560
|
+
"/artifact-manager/artifacts/bundle",
|
|
561
|
+
{ json: { ids: artifactIds } }
|
|
562
|
+
);
|
|
563
|
+
return new Uint8Array(await resp.arrayBuffer());
|
|
564
|
+
}
|
|
565
|
+
// -- Enrichment ratings ------------------------------------------------------- //
|
|
566
|
+
/** Your thumbs rating on an enrichment + the aggregate counts. */
|
|
567
|
+
async getRating(enrichmentId) {
|
|
568
|
+
const resp = await this.request(
|
|
569
|
+
"GET",
|
|
570
|
+
`/artifact-manager/artifacts/${pathSegment(enrichmentId)}/rating`
|
|
571
|
+
);
|
|
572
|
+
return await resp.json();
|
|
573
|
+
}
|
|
574
|
+
/** Rate an enrichment `"up"`/`"down"`, or clear your rating with `null`. */
|
|
575
|
+
async setRating(enrichmentId, rating) {
|
|
576
|
+
const resp = await this.request(
|
|
577
|
+
"POST",
|
|
578
|
+
`/artifact-manager/artifacts/${pathSegment(enrichmentId)}/rating`,
|
|
579
|
+
{
|
|
580
|
+
json: { rating }
|
|
581
|
+
}
|
|
582
|
+
);
|
|
583
|
+
return await resp.json();
|
|
584
|
+
}
|
|
585
|
+
// -- Enrichment exports ------------------------------------------------------- //
|
|
586
|
+
/** A saved enrichment's machine-export formats (`stix`, `misp`, `csaf`, `vex`, `csv`, …). */
|
|
587
|
+
async listExports(enrichmentId) {
|
|
588
|
+
const resp = await this.request(
|
|
589
|
+
"GET",
|
|
590
|
+
`/artifact-manager/artifacts/${pathSegment(enrichmentId)}/exports`
|
|
591
|
+
);
|
|
592
|
+
return (await resp.json()).formats;
|
|
593
|
+
}
|
|
594
|
+
/** Download one export. The body is the export file; `filename` is a sanitized basename from
|
|
595
|
+
* `Content-Disposition`. Text formats land in `content`; binary XLSX formats in `bytes`. */
|
|
596
|
+
async getExport(enrichmentId, format) {
|
|
597
|
+
const resp = await this.request(
|
|
598
|
+
"GET",
|
|
599
|
+
`/artifact-manager/artifacts/${pathSegment(enrichmentId)}/exports/${pathSegment(format)}`
|
|
600
|
+
);
|
|
601
|
+
const disposition = resp.headers.get("content-disposition") ?? "";
|
|
602
|
+
const filename = downloadFilename2(disposition, format);
|
|
603
|
+
const bytes = new Uint8Array(await resp.arrayBuffer());
|
|
604
|
+
return {
|
|
605
|
+
content: new TextDecoder().decode(bytes),
|
|
606
|
+
bytes,
|
|
607
|
+
filename,
|
|
608
|
+
contentType: resp.headers.get("content-type") ?? ""
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
/** Download EVERY machine export of a saved artifact as one `.zip` (one file per format —
|
|
612
|
+
* `stix.json`, `vex.json`, `emass.xlsx`, …). The bulk twin of {@link getExport}, matching the export
|
|
613
|
+
* panel's "Download all (.zip)" button. Works for any saved enrichment / inventory-enrichment /
|
|
614
|
+
* inventory id. Returns the raw `.zip` bytes. */
|
|
615
|
+
async downloadAllExports(enrichmentId) {
|
|
616
|
+
const resp = await this.request(
|
|
617
|
+
"GET",
|
|
618
|
+
`/artifact-manager/artifacts/${pathSegment(enrichmentId)}/exports/all`
|
|
619
|
+
);
|
|
620
|
+
return new Uint8Array(await resp.arrayBuffer());
|
|
621
|
+
}
|
|
622
|
+
// -- Enrichment compare ------------------------------------------------------- //
|
|
623
|
+
/**
|
|
624
|
+
* Difference matrix across 2–12 of your saved enrichments (oldest → newest). Each
|
|
625
|
+
* row is one finding's trajectory: new / resolved / changed / persistent.
|
|
626
|
+
*/
|
|
627
|
+
async compareEnrichments(enrichmentIds) {
|
|
628
|
+
const resp = await this.request(
|
|
629
|
+
"GET",
|
|
630
|
+
"/artifact-manager/enrichment-compare",
|
|
631
|
+
{
|
|
632
|
+
params: { ids: enrichmentIds.join(",") }
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
return (await resp.json()).matrix;
|
|
636
|
+
}
|
|
637
|
+
// -- Folders ------------------------------------------------------------ //
|
|
638
|
+
/** Your folders, each with a live `artifact_count`. */
|
|
639
|
+
async listFolders() {
|
|
640
|
+
const resp = await this.request("GET", "/artifact-manager/folders");
|
|
641
|
+
return (await resp.json()).folders;
|
|
642
|
+
}
|
|
643
|
+
/** Create a folder. Resolves to its id. */
|
|
644
|
+
async createFolder(name) {
|
|
645
|
+
const resp = await this.request("POST", "/artifact-manager/folders", {
|
|
646
|
+
json: { name }
|
|
647
|
+
});
|
|
648
|
+
return (await resp.json()).id;
|
|
649
|
+
}
|
|
650
|
+
/** Rename a folder. */
|
|
651
|
+
async renameFolder(folderId, name) {
|
|
652
|
+
const resp = await this.request(
|
|
653
|
+
"PATCH",
|
|
654
|
+
`/artifact-manager/folders/${pathSegment(folderId)}`,
|
|
655
|
+
{ json: { name } }
|
|
656
|
+
);
|
|
657
|
+
return await resp.json();
|
|
658
|
+
}
|
|
659
|
+
/** Delete a folder — its artifacts move back to root, never deleted with it. */
|
|
660
|
+
async deleteFolder(folderId) {
|
|
661
|
+
const resp = await this.request(
|
|
662
|
+
"DELETE",
|
|
663
|
+
`/artifact-manager/folders/${pathSegment(folderId)}`
|
|
664
|
+
);
|
|
665
|
+
return Boolean((await resp.json()).deleted);
|
|
666
|
+
}
|
|
667
|
+
/** Download every artifact filed under a folder as one `<folder>.zip` (the folder "Download .zip").
|
|
668
|
+
* Enrichments contribute their machine exports under a per-enrichment subfolder; every other kind
|
|
669
|
+
* contributes its raw deliverable. Returns the raw `.zip` bytes. */
|
|
670
|
+
async downloadFolder(folderId) {
|
|
671
|
+
const resp = await this.request(
|
|
672
|
+
"GET",
|
|
673
|
+
`/artifact-manager/folders/${pathSegment(folderId)}/exports/all`
|
|
674
|
+
);
|
|
675
|
+
return new Uint8Array(await resp.arrayBuffer());
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// src/_poll.ts
|
|
680
|
+
function timeoutError(enrichmentId) {
|
|
681
|
+
return new Error(
|
|
682
|
+
`enrichment ${enrichmentId} did not finish within the timeout`
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
function remainingMs(deadline) {
|
|
686
|
+
return deadline - performance.now();
|
|
687
|
+
}
|
|
688
|
+
var TIMED_OUT = /* @__PURE__ */ Symbol("poll-deadline-elapsed");
|
|
689
|
+
async function beforeDeadline(operation, remaining, enrichmentId) {
|
|
690
|
+
if (remaining <= 0) throw timeoutError(enrichmentId);
|
|
691
|
+
let cancelDeadline = () => {
|
|
692
|
+
};
|
|
693
|
+
const deadline = new Promise((resolve) => {
|
|
694
|
+
const timer = setTimeout(() => resolve(TIMED_OUT), remaining);
|
|
695
|
+
cancelDeadline = () => clearTimeout(timer);
|
|
696
|
+
});
|
|
697
|
+
void Promise.resolve(operation).catch(() => void 0);
|
|
698
|
+
try {
|
|
699
|
+
const outcome = await Promise.race([operation, deadline]);
|
|
700
|
+
if (outcome === TIMED_OUT) throw timeoutError(enrichmentId);
|
|
701
|
+
return outcome;
|
|
702
|
+
} finally {
|
|
703
|
+
cancelDeadline();
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
async function emit(onProgress, job, remaining, enrichmentId) {
|
|
707
|
+
if (!onProgress) return;
|
|
708
|
+
const callback = Promise.resolve().then(() => onProgress(job)).then(() => void 0).catch(() => void 0);
|
|
709
|
+
await beforeDeadline(callback, remaining, enrichmentId);
|
|
710
|
+
}
|
|
711
|
+
function validatePollOptions(pollIntervalMs, timeoutMs) {
|
|
712
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
713
|
+
throw new RangeError("timeoutMs must be finite and non-negative");
|
|
714
|
+
}
|
|
715
|
+
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs < 0) {
|
|
716
|
+
throw new RangeError("pollIntervalMs must be finite and non-negative");
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
async function pollUntilDone(request, enrichmentId, statusPath, opts) {
|
|
720
|
+
validatePollOptions(opts.pollIntervalMs, opts.timeoutMs);
|
|
721
|
+
const deadline = performance.now() + opts.timeoutMs;
|
|
722
|
+
for (; ; ) {
|
|
723
|
+
let remaining = remainingMs(deadline);
|
|
724
|
+
const resp = await beforeDeadline(
|
|
725
|
+
request("GET", statusPath, remaining),
|
|
726
|
+
remaining,
|
|
727
|
+
enrichmentId
|
|
728
|
+
);
|
|
729
|
+
remaining = remainingMs(deadline);
|
|
730
|
+
const job = await beforeDeadline(
|
|
731
|
+
resp.json(),
|
|
732
|
+
remaining,
|
|
733
|
+
enrichmentId
|
|
734
|
+
);
|
|
735
|
+
remaining = remainingMs(deadline);
|
|
736
|
+
await emit(opts.onProgress, job, remaining, enrichmentId);
|
|
737
|
+
if (remainingMs(deadline) <= 0) throw timeoutError(enrichmentId);
|
|
738
|
+
if (job.status === "done") return job;
|
|
739
|
+
if (job.status === "error") {
|
|
740
|
+
throw new UnexpectedStatus(
|
|
741
|
+
502,
|
|
742
|
+
"",
|
|
743
|
+
`enrichment ${enrichmentId} errored: ${String(job.error)}`
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
remaining = remainingMs(deadline);
|
|
747
|
+
await beforeDeadline(
|
|
748
|
+
new Promise(
|
|
749
|
+
(resolve) => setTimeout(resolve, Math.min(opts.pollIntervalMs, remaining))
|
|
750
|
+
),
|
|
751
|
+
remaining,
|
|
752
|
+
enrichmentId
|
|
753
|
+
);
|
|
754
|
+
if (remainingMs(deadline) <= 0) throw timeoutError(enrichmentId);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/ingest.ts
|
|
759
|
+
function assembleBriefing(report, meta) {
|
|
760
|
+
const seen = /* @__PURE__ */ new Map();
|
|
761
|
+
const assets = Array.isArray(report.assets) ? report.assets : [];
|
|
762
|
+
for (const asset of assets) {
|
|
763
|
+
const product = asset.product || asset.name || "\u2014";
|
|
764
|
+
const cves = Array.isArray(asset.top_cves) ? asset.top_cves : [];
|
|
765
|
+
for (const cve of cves) {
|
|
766
|
+
const cid = cve.cve_id;
|
|
767
|
+
if (!cid) continue;
|
|
768
|
+
const weap = cve.weaponization_score || 0;
|
|
769
|
+
const prev = seen.get(cid);
|
|
770
|
+
if (!prev || weap > (prev.weaponization_score || 0)) {
|
|
771
|
+
seen.set(cid, {
|
|
772
|
+
cve_id: cid,
|
|
773
|
+
product,
|
|
774
|
+
weaponization_score: weap,
|
|
775
|
+
kev: Boolean(cve.kev),
|
|
776
|
+
reason: cve.kev ? "KEV-listed \u2014 patch now" : "High weaponization"
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const actions = [...seen.values()].sort(
|
|
782
|
+
(a, b) => (a.kev ? 0 : 1) - (b.kev ? 0 : 1) || (b.weaponization_score || 0) - (a.weaponization_score || 0)
|
|
783
|
+
).slice(0, 10);
|
|
784
|
+
const out = {
|
|
785
|
+
format: meta.format,
|
|
786
|
+
parsed_count: meta.parsedCount,
|
|
787
|
+
enrichment_id: meta.enrichmentId,
|
|
788
|
+
report,
|
|
789
|
+
recommended_actions: actions
|
|
790
|
+
};
|
|
791
|
+
if (meta.truncated) out.truncated = meta.truncated;
|
|
792
|
+
return out;
|
|
793
|
+
}
|
|
794
|
+
async function ingestScan(invApi, content, format, options = {}) {
|
|
795
|
+
const parsed = await invApi.parseScan(content, format);
|
|
796
|
+
const items = Array.isArray(parsed.items) ? parsed.items : [];
|
|
797
|
+
const fmt = typeof parsed.format === "string" ? parsed.format : format;
|
|
798
|
+
if (items.length === 0)
|
|
799
|
+
return { format: fmt, parsed_count: 0, enrichment_id: null, empty: true };
|
|
800
|
+
const result = await invApi.enrichItems(items, options);
|
|
801
|
+
return assembleBriefing(result.report || {}, {
|
|
802
|
+
format: fmt,
|
|
803
|
+
parsedCount: items.length,
|
|
804
|
+
truncated: parsed.truncated,
|
|
805
|
+
enrichmentId: result.enrichment_id
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// src/inventory-manager.ts
|
|
810
|
+
function wireContent(content) {
|
|
811
|
+
if (typeof content === "string") return content;
|
|
812
|
+
if (typeof Buffer !== "undefined")
|
|
813
|
+
return Buffer.from(content).toString("base64");
|
|
814
|
+
let bin = "";
|
|
815
|
+
const chunk = 32768;
|
|
816
|
+
for (let i = 0; i < content.length; i += chunk)
|
|
817
|
+
bin += String.fromCharCode(...content.subarray(i, i + chunk));
|
|
818
|
+
return btoa(bin);
|
|
819
|
+
}
|
|
820
|
+
function wireSources(sources) {
|
|
821
|
+
return sources.map((s) => ({ ...s, content: wireContent(s.content) }));
|
|
822
|
+
}
|
|
823
|
+
function inventoryBody(inventoryName, o) {
|
|
824
|
+
const body = { inventory_name: inventoryName };
|
|
825
|
+
if (o.description !== void 0) body.description = o.description;
|
|
826
|
+
if (o.items !== void 0) body.items = o.items;
|
|
827
|
+
if (o.monitoring !== void 0) body.monitoring = o.monitoring;
|
|
828
|
+
if (o.linkedArtifactIds !== void 0)
|
|
829
|
+
body.linked_artifact_ids = o.linkedArtifactIds;
|
|
830
|
+
return body;
|
|
831
|
+
}
|
|
832
|
+
var InventoryManagerApi = class {
|
|
833
|
+
baseUrl;
|
|
834
|
+
// True ES2022 private field, not TypeScript `private`: `private` is erased at compile
|
|
835
|
+
// time, leaving an enumerable own property that JSON.stringify and
|
|
836
|
+
// util.inspect (so console.log) print in cleartext. `#` is enforced by the
|
|
837
|
+
// runtime and invisible to both.
|
|
838
|
+
#apiKey;
|
|
839
|
+
doFetch;
|
|
840
|
+
constructor(baseUrl, apiKey, doFetch) {
|
|
841
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
842
|
+
this.#apiKey = apiKey;
|
|
843
|
+
this.doFetch = doFetch;
|
|
844
|
+
}
|
|
845
|
+
async request(method, path, opts = {}) {
|
|
846
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
847
|
+
for (const [k, v] of Object.entries(opts.params ?? {}))
|
|
848
|
+
url.searchParams.set(k, v);
|
|
849
|
+
const init = {
|
|
850
|
+
method,
|
|
851
|
+
headers: {
|
|
852
|
+
apikey: this.#apiKey,
|
|
853
|
+
...opts.json !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
854
|
+
},
|
|
855
|
+
...opts.json !== void 0 ? { body: JSON.stringify(opts.json) } : {}
|
|
856
|
+
};
|
|
857
|
+
const resp = opts.timeoutMs === void 0 ? await this.doFetch(url, init) : await this.doFetch(
|
|
858
|
+
new Request(url, {
|
|
859
|
+
...init,
|
|
860
|
+
signal: AbortSignal.timeout(
|
|
861
|
+
Math.max(1, Math.ceil(opts.timeoutMs))
|
|
862
|
+
)
|
|
863
|
+
})
|
|
864
|
+
);
|
|
865
|
+
if (!resp.ok) {
|
|
866
|
+
const body = await resp.text().catch(() => "");
|
|
867
|
+
throw new UnexpectedStatus(
|
|
868
|
+
resp.status,
|
|
869
|
+
body,
|
|
870
|
+
`Inventory Manager API ${resp.status} on ${path}`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
return resp;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* List your Inventory Manager inventories — each a continuously-monitored context window
|
|
877
|
+
* (asset inventory + attached artifacts + saved enrichment history). Newest first, no content.
|
|
878
|
+
*/
|
|
879
|
+
async listInventories() {
|
|
880
|
+
const resp = await this.request("GET", "/inventory-manager/inventories");
|
|
881
|
+
return (await resp.json()).inventories;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* One inventory as a manifest: `{ inventory_name, description, monitoring, inventory[], attached[],
|
|
885
|
+
* enrichments[] }`. Pull specific artifacts/enrichments via the Artifact Manager API.
|
|
886
|
+
*/
|
|
887
|
+
async getInventory(inventoryId) {
|
|
888
|
+
const resp = await this.request(
|
|
889
|
+
"GET",
|
|
890
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}`
|
|
891
|
+
);
|
|
892
|
+
return await resp.json();
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* An inventory as a one-shot, bounded context bundle with artifact provenance and delimiters.
|
|
896
|
+
* Returns `{ id, name, inventory_name, description, monitoring, stats, context }`. `context`
|
|
897
|
+
* starts with a safe prompt preamble that labels the enclosed inventory and artifact text as
|
|
898
|
+
* untrusted data.
|
|
899
|
+
*/
|
|
900
|
+
async getInventoryContext(inventoryId) {
|
|
901
|
+
const resp = await this.request(
|
|
902
|
+
"GET",
|
|
903
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/context`
|
|
904
|
+
);
|
|
905
|
+
return await resp.json();
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* List an inventory's saved enrichment history — the inventory's `inventory_enrichment` artifacts (newest first,
|
|
909
|
+
* no content; each row's `meta` carries the card stats: asset/CVE/KEV counts, scanned-at, monitoring
|
|
910
|
+
* delta). The data behind the UI's "Previous enrichments" strip.
|
|
911
|
+
*/
|
|
912
|
+
async listEnrichments(inventoryId) {
|
|
913
|
+
const resp = await this.request(
|
|
914
|
+
"GET",
|
|
915
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/enrichments`
|
|
916
|
+
);
|
|
917
|
+
return (await resp.json()).enrichments;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* CVE-matched difference matrix across 2–12 of your saved INVENTORY enrichments (oldest → newest). The
|
|
921
|
+
* inventory counterpart of `client.artifactManager.compareEnrichments`: each row is one CVE's trajectory —
|
|
922
|
+
* new / resolved / changed / persistent — across the selected inventory enrichments. Returns the `matrix`
|
|
923
|
+
* object (`columns`, `rows`, `counts`).
|
|
924
|
+
*/
|
|
925
|
+
async compareEnrichments(enrichmentIds) {
|
|
926
|
+
const resp = await this.request(
|
|
927
|
+
"GET",
|
|
928
|
+
"/inventory-manager/inventories/compare",
|
|
929
|
+
{
|
|
930
|
+
params: { ids: enrichmentIds.join(",") }
|
|
931
|
+
}
|
|
932
|
+
);
|
|
933
|
+
return (await resp.json()).matrix;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Create an Inventory Manager inventory (a continuously-monitored context window).
|
|
937
|
+
*
|
|
938
|
+
* @param inventoryName The inventory's display name.
|
|
939
|
+
* @param options `description`, `items` (asset inventory — each `{ product, vendor?, versions?,
|
|
940
|
+
* ecosystem?, category?, criticality?, notes? }`), `monitoring` (always full depth — no fast/lite
|
|
941
|
+
* mode), `linkedArtifactIds`.
|
|
942
|
+
* @returns `{ id, item_count }`.
|
|
943
|
+
*/
|
|
944
|
+
async createInventory(inventoryName, options = {}) {
|
|
945
|
+
const resp = await this.request("POST", "/inventory-manager/inventories", {
|
|
946
|
+
json: inventoryBody(inventoryName, options)
|
|
947
|
+
});
|
|
948
|
+
return await resp.json();
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Update an inventory's definition (name, description, inventory, monitoring, attachments).
|
|
952
|
+
* This is a **partial merge** (PATCH): only the fields you pass change — omitted fields are PRESERVED,
|
|
953
|
+
* including the asset-group metadata and daily-report config this method doesn't expose. `inventoryName`
|
|
954
|
+
* is still required by the API. Resolves `{ id, item_count }`.
|
|
955
|
+
*/
|
|
956
|
+
async updateInventory(inventoryId, options) {
|
|
957
|
+
const resp = await this.request(
|
|
958
|
+
"PATCH",
|
|
959
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}`,
|
|
960
|
+
{ json: inventoryBody(options.inventoryName, options) }
|
|
961
|
+
);
|
|
962
|
+
return await resp.json();
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Create an inventory by IMPORTING an asset-inventory file (you PICK the format — no auto-detect).
|
|
966
|
+
*
|
|
967
|
+
* @param options `format` — one of `json` (asset JSON), `sbom` (CycloneDX / SPDX SBOM), `csv`,
|
|
968
|
+
* `nmap` (nmap `-sV` XML), `list` (CPE / purl list), `grype`, `trivy` (SCA JSON), `depcheck`
|
|
969
|
+
* (OWASP Dependency-Check JSON), `nessus` (`.nessus` XML), `gvm` (OpenVAS / Greenbone XML);
|
|
970
|
+
* `content` — the file's text; optional `inventoryName` / `description` (override
|
|
971
|
+
* anything the file carries).
|
|
972
|
+
* @returns `{ id, item_count, imported, format, truncated? }`.
|
|
973
|
+
*/
|
|
974
|
+
async importInventory(options) {
|
|
975
|
+
const body = {
|
|
976
|
+
format: options.format,
|
|
977
|
+
content: wireContent(options.content)
|
|
978
|
+
};
|
|
979
|
+
if (options.inventoryName !== void 0)
|
|
980
|
+
body.inventory_name = options.inventoryName;
|
|
981
|
+
if (options.description !== void 0)
|
|
982
|
+
body.description = options.description;
|
|
983
|
+
if (options.inventoryId !== void 0) {
|
|
984
|
+
body.inventory_id = options.inventoryId;
|
|
985
|
+
body.mode = options.mode ?? "replace";
|
|
986
|
+
}
|
|
987
|
+
const resp = await this.request(
|
|
988
|
+
"POST",
|
|
989
|
+
"/inventory-manager/inventories/import",
|
|
990
|
+
{ json: body }
|
|
991
|
+
);
|
|
992
|
+
return await resp.json();
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Parse + COMBINE several scan / inventory files into ONE deduped asset set WITHOUT saving (the
|
|
996
|
+
* multi-source twin of {@link parseScan}). Stage a CSV + an nmap scan + an SBOM and merge them; duplicate
|
|
997
|
+
* assets are deduped across sources, versions + named groups unioned, the set capped at 200.
|
|
998
|
+
*
|
|
999
|
+
* @param sources A list of `{ content, format?, label? }`. The `format` is **optional** — omit it and the
|
|
1000
|
+
* file's format is auto-detected from its content (+ `label` as a filename hint); pin a `format` only to
|
|
1001
|
+
* override. A binary `xlsx` source can't be sniffed, so it needs `format: "xlsx"` + `Uint8Array` content
|
|
1002
|
+
* (base64-encoded on the wire). A source that fails to parse is ISOLATED (it appears in `per_source` with
|
|
1003
|
+
* its `error`, contributing nothing — never failing the whole call).
|
|
1004
|
+
* @returns `{ items, count, asset_groups, truncated?, per_source: [{ label, contributed, truncated?, error? }] }`.
|
|
1005
|
+
*/
|
|
1006
|
+
async parseMulti(sources) {
|
|
1007
|
+
const resp = await this.request(
|
|
1008
|
+
"POST",
|
|
1009
|
+
"/inventory-manager/inventories/parse-multi",
|
|
1010
|
+
{ json: { sources: wireSources(sources) } }
|
|
1011
|
+
);
|
|
1012
|
+
return await resp.json();
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Import + COMBINE several files into ONE inventory in a single call (the multi-source twin of
|
|
1016
|
+
* {@link importInventory}). Each source parses in isolation then merges via the same dedup brain as
|
|
1017
|
+
* {@link parseMulti}. No `inventoryId` CREATES a new inventory; with `inventoryId` the combined assets go
|
|
1018
|
+
* INTO it (`mode` replace / append), preserving attachments / monitoring.
|
|
1019
|
+
*/
|
|
1020
|
+
async importMulti(options) {
|
|
1021
|
+
const body = {
|
|
1022
|
+
sources: wireSources(options.sources)
|
|
1023
|
+
};
|
|
1024
|
+
if (options.inventoryName !== void 0)
|
|
1025
|
+
body.inventory_name = options.inventoryName;
|
|
1026
|
+
if (options.description !== void 0)
|
|
1027
|
+
body.description = options.description;
|
|
1028
|
+
if (options.inventoryId !== void 0) {
|
|
1029
|
+
body.inventory_id = options.inventoryId;
|
|
1030
|
+
body.mode = options.mode ?? "replace";
|
|
1031
|
+
}
|
|
1032
|
+
const resp = await this.request(
|
|
1033
|
+
"POST",
|
|
1034
|
+
"/inventory-manager/inventories/import",
|
|
1035
|
+
{ json: body }
|
|
1036
|
+
);
|
|
1037
|
+
return await resp.json();
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* REPLACE an inventory's asset inventory, PRESERVING its name / description / attached artifacts /
|
|
1041
|
+
* monitoring / alert-prefs (the safe alternative to {@link updateInventory}, which resets omitted
|
|
1042
|
+
* fields). To edit one field of one asset: {@link getInventory}, change the item in `inventory`, and
|
|
1043
|
+
* replace it back. Resolves `{ id, item_count, mode }`.
|
|
1044
|
+
*/
|
|
1045
|
+
async replaceAssets(inventoryId, items) {
|
|
1046
|
+
const resp = await this.request(
|
|
1047
|
+
"PATCH",
|
|
1048
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/assets`,
|
|
1049
|
+
{
|
|
1050
|
+
json: { items, mode: "replace" }
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
return await resp.json();
|
|
1054
|
+
}
|
|
1055
|
+
/** APPEND assets to an inventory's inventory, preserving everything else. Resolves `{ id, item_count, mode }`. */
|
|
1056
|
+
async addAssets(inventoryId, items) {
|
|
1057
|
+
const resp = await this.request(
|
|
1058
|
+
"PATCH",
|
|
1059
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/assets`,
|
|
1060
|
+
{
|
|
1061
|
+
json: { items, mode: "append" }
|
|
1062
|
+
}
|
|
1063
|
+
);
|
|
1064
|
+
return await resp.json();
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Apply a recommended upgrade — set the matched asset's version to the published fix the Inventory
|
|
1068
|
+
* Enricher surfaced (`recommended_fix_version` / `recommended_fix_version_kev`), PRESERVING everything
|
|
1069
|
+
* else on the inventory. Match is by `product` (case-insensitive; `vendor` disambiguates duplicate
|
|
1070
|
+
* product names). Writes the inventory only — it does NOT re-enrich (the next enrichment / daily monitor
|
|
1071
|
+
* confirms the CVEs cleared). Resolves `{ id, product, version, item_count }` (404 when no asset matches).
|
|
1072
|
+
*/
|
|
1073
|
+
async applyAssetFix(inventoryId, product, version, vendor) {
|
|
1074
|
+
const json = { product, version };
|
|
1075
|
+
if (vendor !== void 0) json.vendor = vendor;
|
|
1076
|
+
const resp = await this.request(
|
|
1077
|
+
"PATCH",
|
|
1078
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/asset-version`,
|
|
1079
|
+
{ json }
|
|
1080
|
+
);
|
|
1081
|
+
return await resp.json();
|
|
1082
|
+
}
|
|
1083
|
+
/** List an inventory's asset-inventory export formats (`json` / `csv` / `cyclonedx` / `spdx`). */
|
|
1084
|
+
async listExportFormats(inventoryId) {
|
|
1085
|
+
const resp = await this.request(
|
|
1086
|
+
"GET",
|
|
1087
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/export`
|
|
1088
|
+
);
|
|
1089
|
+
return (await resp.json()).formats;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Export an inventory's asset inventory as a file — the resolved value IS the file. Resolves a
|
|
1093
|
+
* `string` for the text formats and a `Uint8Array` for the binary `workbook` (write it straight to
|
|
1094
|
+
* a `.xlsx` file).
|
|
1095
|
+
*
|
|
1096
|
+
* @param inventoryId The inventory id.
|
|
1097
|
+
* @param format `json` / `csv` / `list` (CPE/purl) / `cyclonedx` / `spdx` (3.0.1) / `spdx2` (SPDX 2.3)
|
|
1098
|
+
* / `workbook` (binary Excel .xlsx). `json` / `csv` / `list` round-trip back through
|
|
1099
|
+
* {@link importInventory}. Defaults to `json`.
|
|
1100
|
+
*/
|
|
1101
|
+
async exportInventory(inventoryId, format = "json") {
|
|
1102
|
+
const resp = await this.request(
|
|
1103
|
+
"GET",
|
|
1104
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/export/${pathSegment(format)}`
|
|
1105
|
+
);
|
|
1106
|
+
return format === "workbook" ? new Uint8Array(await resp.arrayBuffer()) : await resp.text();
|
|
1107
|
+
}
|
|
1108
|
+
/** Delete an inventory. Resolves `true` on success (404 throws). */
|
|
1109
|
+
async deleteInventory(inventoryId) {
|
|
1110
|
+
const resp = await this.request(
|
|
1111
|
+
"DELETE",
|
|
1112
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}`
|
|
1113
|
+
);
|
|
1114
|
+
return Boolean((await resp.json()).deleted);
|
|
1115
|
+
}
|
|
1116
|
+
/** Link an existing artifact to an inventory. Resolves to `{ ok, linked, already }`. */
|
|
1117
|
+
async attachToInventory(inventoryId, artifactId) {
|
|
1118
|
+
const resp = await this.request(
|
|
1119
|
+
"POST",
|
|
1120
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/attach`,
|
|
1121
|
+
{
|
|
1122
|
+
json: { artifactId }
|
|
1123
|
+
}
|
|
1124
|
+
);
|
|
1125
|
+
return await resp.json();
|
|
1126
|
+
}
|
|
1127
|
+
/** Remove one attached artifact from an inventory (the inverse of {@link attachToInventory}).
|
|
1128
|
+
* Atomic server-side operation that preserves every other field; idempotent. Resolves
|
|
1129
|
+
* `{ ok, linked, removed }`. */
|
|
1130
|
+
async detachFromInventory(inventoryId, artifactId) {
|
|
1131
|
+
const resp = await this.request(
|
|
1132
|
+
"POST",
|
|
1133
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/detach`,
|
|
1134
|
+
{ json: { artifactId } }
|
|
1135
|
+
);
|
|
1136
|
+
return await resp.json();
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* REPLACE an inventory's attached reference artifacts in one call (the bulk twin of
|
|
1140
|
+
* {@link attachToInventory}), PRESERVING its inventory / monitoring / alert-prefs. Only attachable
|
|
1141
|
+
* kinds (`input` / `enrichment` / `report`) are kept; inventories and inventory enrichments are skipped. Deduped +
|
|
1142
|
+
* capped at 100. Resolves `{ id, linked_count, attached, skipped, mode }`.
|
|
1143
|
+
*/
|
|
1144
|
+
async setAttachments(inventoryId, artifactIds) {
|
|
1145
|
+
const resp = await this.request(
|
|
1146
|
+
"PATCH",
|
|
1147
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/attachments`,
|
|
1148
|
+
{
|
|
1149
|
+
json: { artifact_ids: artifactIds, mode: "replace" }
|
|
1150
|
+
}
|
|
1151
|
+
);
|
|
1152
|
+
return await resp.json();
|
|
1153
|
+
}
|
|
1154
|
+
/** APPEND several artifacts to an inventory's attachments in one call (bulk {@link attachToInventory});
|
|
1155
|
+
* same filtering/cap/return as {@link setAttachments}. */
|
|
1156
|
+
async addAttachments(inventoryId, artifactIds) {
|
|
1157
|
+
const resp = await this.request(
|
|
1158
|
+
"PATCH",
|
|
1159
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/attachments`,
|
|
1160
|
+
{
|
|
1161
|
+
json: { artifact_ids: artifactIds, mode: "append" }
|
|
1162
|
+
}
|
|
1163
|
+
);
|
|
1164
|
+
return await resp.json();
|
|
1165
|
+
}
|
|
1166
|
+
/** Toggle an inventory's daily monitoring (= daily enrichment). Routes through the automation endpoint
|
|
1167
|
+
* (partial read-modify-write) so assets, attachments, asset groups, AND the daily-report config are
|
|
1168
|
+
* all preserved. Enrichments always run at full depth. Resolves `{ id, automation }`. */
|
|
1169
|
+
async setMonitoring(inventoryId, monitoring) {
|
|
1170
|
+
return this.setAutomation(inventoryId, { monitoring });
|
|
1171
|
+
}
|
|
1172
|
+
/** Star (`favorite: true`) or unstar (`false`) an inventory — the same ★ the inventory cards show. A
|
|
1173
|
+
* favorite-only PATCH that leaves the asset inventory / attachments / monitoring / automation untouched.
|
|
1174
|
+
* `listInventories` + `getInventory` echo `favorite` back. Usage-exempt. Resolves `{ id, favorite }`. */
|
|
1175
|
+
async setFavorite(inventoryId, favorite = true) {
|
|
1176
|
+
const resp = await this.request(
|
|
1177
|
+
"PATCH",
|
|
1178
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}`,
|
|
1179
|
+
{ json: { favorite } }
|
|
1180
|
+
);
|
|
1181
|
+
return await resp.json();
|
|
1182
|
+
}
|
|
1183
|
+
/** Read an inventory's DAILY-AUTOMATION config (the programmatic twin of the Automation modal):
|
|
1184
|
+
* `{ monitoring, daily_enrichment_email, daily_report, daily_report_email,
|
|
1185
|
+
* daily_report_template, daily_enrichment_next_run_at, custom_template_pinned }`. ONE pipeline on ONE
|
|
1186
|
+
* timer: `daily_enrichment_next_run_at` is the epoch-ms countdown (null when monitoring is off); the
|
|
1187
|
+
* daily report rides the same pipeline (right after the enrichment), no timer of its own. Usage-exempt. */
|
|
1188
|
+
async getAutomation(inventoryId) {
|
|
1189
|
+
const resp = await this.request(
|
|
1190
|
+
"GET",
|
|
1191
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/automation`
|
|
1192
|
+
);
|
|
1193
|
+
return await resp.json();
|
|
1194
|
+
}
|
|
1195
|
+
/** Manage an inventory's daily automation — set ONLY the fields you pass (partial read-modify-write,
|
|
1196
|
+
* preserving assets/attachments). `monitoring` = the daily enrichment; `dailyReport` = ALSO generate a
|
|
1197
|
+
* Report-Generator report from `dailyReportTemplate` (a built-in template id, e.g. `project_brief`) right
|
|
1198
|
+
* after each daily enrichment, off its fresh findings. ONE pipeline: `dailyReport` REQUIRES `monitoring` —
|
|
1199
|
+
* enabling it while monitoring is off rejects with a 400 (`UnexpectedStatus`); turning monitoring off
|
|
1200
|
+
* cascades the report off. Each job's `*Email` toggle controls whether it emails the owner. The pipeline
|
|
1201
|
+
* runs on the owner's key when the daily cron fires (the enrichment counts toward usage then). Resolves
|
|
1202
|
+
* `{ id, automation }`. */
|
|
1203
|
+
async setAutomation(inventoryId, options) {
|
|
1204
|
+
const body = {};
|
|
1205
|
+
if (options.monitoring !== void 0) body.monitoring = options.monitoring;
|
|
1206
|
+
if (options.dailyEnrichmentEmail !== void 0)
|
|
1207
|
+
body.daily_enrichment_email = options.dailyEnrichmentEmail;
|
|
1208
|
+
if (options.dailyReport !== void 0)
|
|
1209
|
+
body.daily_report = options.dailyReport;
|
|
1210
|
+
if (options.dailyReportEmail !== void 0)
|
|
1211
|
+
body.daily_report_email = options.dailyReportEmail;
|
|
1212
|
+
if (options.dailyReportTemplate !== void 0)
|
|
1213
|
+
body.daily_report_template = options.dailyReportTemplate;
|
|
1214
|
+
const resp = await this.request(
|
|
1215
|
+
"PUT",
|
|
1216
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/automation`,
|
|
1217
|
+
{ json: body }
|
|
1218
|
+
);
|
|
1219
|
+
return await resp.json();
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Enrich an inventory's inventory end-to-end against the /v1 engine: submit → poll → return the report.
|
|
1223
|
+
*
|
|
1224
|
+
* Reads the inventory's asset inventory (`GET /inventory-manager/inventories/{id}`), submits those assets
|
|
1225
|
+
* to the Threat Inventory Enricher (`POST /v1/inventory-enrich`, always full depth — there is no fast/lite
|
|
1226
|
+
* mode), polls until done, and resolves to the enrichment report.
|
|
1227
|
+
*
|
|
1228
|
+
* The enrichment submit is enrichment compute and **counts toward your usage** (it rides your key to
|
|
1229
|
+
* `/v1/inventory-enrich`); reading the inventory and polling do not.
|
|
1230
|
+
*
|
|
1231
|
+
* Resolves to `{ enrichment_id, report }`. If the inventory's inventory is empty this short-circuits and
|
|
1232
|
+
* resolves to `{ enrichment_id: null, empty: true }` without submitting. Throws `UnexpectedStatus` on a
|
|
1233
|
+
* non-2xx (or enrichment error), or `Error` if the enrichment doesn't finish within `timeoutMs`.
|
|
1234
|
+
*/
|
|
1235
|
+
async enrichInventory(inventoryId, options = {}) {
|
|
1236
|
+
validatePollOptions(
|
|
1237
|
+
options.pollIntervalMs ?? 3e3,
|
|
1238
|
+
options.timeoutMs ?? 3e5
|
|
1239
|
+
);
|
|
1240
|
+
const manifest = await this.getInventory(inventoryId);
|
|
1241
|
+
const items = Array.isArray(manifest.inventory) ? manifest.inventory : [];
|
|
1242
|
+
if (items.length === 0) return { enrichment_id: null, empty: true };
|
|
1243
|
+
const doAttach = options.enrichAttachments ?? manifest.enrich_attachments === true;
|
|
1244
|
+
let attachmentsText;
|
|
1245
|
+
let attachmentsFiles;
|
|
1246
|
+
let attachmentOmissions = [];
|
|
1247
|
+
if (doAttach) {
|
|
1248
|
+
const ids = (Array.isArray(manifest.attached) ? manifest.attached : []).map((a) => a?.id).filter((x) => typeof x === "string");
|
|
1249
|
+
const resolved = await this.resolveAttachments(ids);
|
|
1250
|
+
attachmentsText = resolved.text;
|
|
1251
|
+
if (resolved.files.length) attachmentsFiles = resolved.files;
|
|
1252
|
+
attachmentOmissions = resolved.omissions;
|
|
1253
|
+
if (options.strictAttachments && attachmentOmissions.length) {
|
|
1254
|
+
throw new Error(
|
|
1255
|
+
`unable to resolve ${attachmentOmissions.length} requested attachment(s): ${attachmentOmissions.map((omission) => omission.attachment_id).join(", ")}`
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
const result = await this.enrichItems(items, {
|
|
1260
|
+
...options,
|
|
1261
|
+
attachmentsText,
|
|
1262
|
+
attachmentsFiles
|
|
1263
|
+
});
|
|
1264
|
+
if (doAttach) result.attachment_omissions = attachmentOmissions;
|
|
1265
|
+
if (options.save && result.enrichment_id) {
|
|
1266
|
+
result.saved = await this.saveEnrichment(
|
|
1267
|
+
inventoryId,
|
|
1268
|
+
result.enrichment_id
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
return result;
|
|
1272
|
+
}
|
|
1273
|
+
/** Fetch the inventory's attached artifacts (≤20) and split them for the engine. Resolution is
|
|
1274
|
+
* permissive: every skipped attachment is returned in `omissions`; callers that need complete
|
|
1275
|
+
* evidence should use `enrichInventory({ strictAttachments: true })`. */
|
|
1276
|
+
async resolveAttachments(attachmentIds) {
|
|
1277
|
+
const parts = [];
|
|
1278
|
+
const files = [];
|
|
1279
|
+
const omissions = attachmentIds.slice(20).map((attachmentId) => ({
|
|
1280
|
+
attachment_id: attachmentId,
|
|
1281
|
+
reason: "attachment limit exceeded (maximum 20)"
|
|
1282
|
+
}));
|
|
1283
|
+
let total = 0;
|
|
1284
|
+
for (const aid of attachmentIds.slice(0, 20)) {
|
|
1285
|
+
try {
|
|
1286
|
+
const resp = await this.request(
|
|
1287
|
+
"GET",
|
|
1288
|
+
`/artifact-manager/artifacts/${pathSegment(aid)}`,
|
|
1289
|
+
{ params: { raw: "1" } }
|
|
1290
|
+
);
|
|
1291
|
+
const content = await resp.text();
|
|
1292
|
+
if (!content) {
|
|
1293
|
+
omissions.push({ attachment_id: aid, reason: "empty response body" });
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
let name = aid;
|
|
1297
|
+
const encodedName = resp.headers.get("X-Artifact-Name");
|
|
1298
|
+
if (encodedName) {
|
|
1299
|
+
try {
|
|
1300
|
+
name = decodeURIComponent(encodedName);
|
|
1301
|
+
} catch {
|
|
1302
|
+
name = aid;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
if (resp.headers.get("X-Artifact-Format") === "file") {
|
|
1306
|
+
files.push({ filename: name, content_b64: content });
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
if (total >= 5e5) {
|
|
1310
|
+
omissions.push({
|
|
1311
|
+
attachment_id: aid,
|
|
1312
|
+
reason: "combined attachment text limit exceeded"
|
|
1313
|
+
});
|
|
1314
|
+
continue;
|
|
1315
|
+
}
|
|
1316
|
+
const chunk = content.slice(0, Math.min(8e4, 5e5 - total));
|
|
1317
|
+
parts.push(`--- Attached: ${name} ---
|
|
1318
|
+
${chunk}`);
|
|
1319
|
+
total += chunk.length;
|
|
1320
|
+
} catch (error) {
|
|
1321
|
+
omissions.push({
|
|
1322
|
+
attachment_id: aid,
|
|
1323
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
const text = parts.join("\n\n");
|
|
1328
|
+
return { text: text.trim() ? text : void 0, files, omissions };
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Persist a COMPLETED inventory enrichment into this inventory's saved history, by its engine
|
|
1332
|
+
* `enrichmentId`.
|
|
1333
|
+
*
|
|
1334
|
+
* The programmatic equivalent of the workbench's "Save enrichment" button. Run `enrichInventory`
|
|
1335
|
+
* (`POST /v1/inventory-enrich` → poll), then pass the returned `enrichment_id` here to file the finished
|
|
1336
|
+
* findings as a `kind=inventory_enrichment` artifact linked to the inventory (or use
|
|
1337
|
+
* `enrichInventory({ save: true })` to do both in one call). The engine returns the report but never
|
|
1338
|
+
* persists it — this is the only way to add it to the inventory's history. Idempotent (a repeat returns
|
|
1339
|
+
* `{ ok: true, deduped: true }`). Usage-exempt. Resolves to `{ artifact_id }`. Save within ~1 h of completion.
|
|
1340
|
+
*/
|
|
1341
|
+
async saveEnrichment(inventoryId, enrichmentId) {
|
|
1342
|
+
const resp = await this.request(
|
|
1343
|
+
"POST",
|
|
1344
|
+
`/inventory-manager/inventories/${pathSegment(inventoryId)}/enrichments`,
|
|
1345
|
+
{ json: { enrichment_id: enrichmentId } }
|
|
1346
|
+
);
|
|
1347
|
+
return await resp.json();
|
|
1348
|
+
}
|
|
1349
|
+
/** Submit a raw asset list to the `/v1/inventory-enrich` engine, poll until done, resolve
|
|
1350
|
+
* `{ enrichment_id, report }`. The shared submit→poll core behind `enrichInventory` and the `ingest`
|
|
1351
|
+
* component. Throws `UnexpectedStatus` on an engine error, or `Error` on timeout. (Internal — used by
|
|
1352
|
+
* `ingest.ts`; not part of the documented public surface.) */
|
|
1353
|
+
async enrichItems(items, options = {}) {
|
|
1354
|
+
validatePollOptions(
|
|
1355
|
+
options.pollIntervalMs ?? 3e3,
|
|
1356
|
+
options.timeoutMs ?? 3e5
|
|
1357
|
+
);
|
|
1358
|
+
const body = { items };
|
|
1359
|
+
if (options.include) body.include = options.include;
|
|
1360
|
+
if (options.attachmentsText)
|
|
1361
|
+
body.attachments_text = options.attachmentsText;
|
|
1362
|
+
if (options.attachmentsFiles?.length)
|
|
1363
|
+
body.attachments_files = options.attachmentsFiles;
|
|
1364
|
+
const submit = await (await this.request("POST", "/v1/inventory-enrich", { json: body })).json();
|
|
1365
|
+
const enrichmentId = submit.enrichment_id;
|
|
1366
|
+
const job = await pollUntilDone(
|
|
1367
|
+
(m, p, timeoutMs) => this.request(m, p, { timeoutMs }),
|
|
1368
|
+
enrichmentId,
|
|
1369
|
+
`/v1/inventory-enrich/${pathSegment(enrichmentId)}`,
|
|
1370
|
+
{
|
|
1371
|
+
pollIntervalMs: options.pollIntervalMs ?? 3e3,
|
|
1372
|
+
timeoutMs: options.timeoutMs ?? 3e5,
|
|
1373
|
+
onProgress: options.onProgress
|
|
1374
|
+
}
|
|
1375
|
+
);
|
|
1376
|
+
return { enrichment_id: enrichmentId, report: job.result };
|
|
1377
|
+
}
|
|
1378
|
+
/** Parse a scan / inventory FILE into canonical asset items WITHOUT saving anything (the parse-only twin
|
|
1379
|
+
* of `importInventory`). You PICK the `format` — one of json/sbom/csv/nmap/list/grype/trivy/depcheck/nessus/gvm/xlsx
|
|
1380
|
+
* (no auto-detect; pass a `Uint8Array` for the binary `xlsx`). Resolves
|
|
1381
|
+
* `{ format, items, count, inventory_name?, truncated? }`. Usage-exempt — the building block for `ingestScan`. */
|
|
1382
|
+
async parseScan(content, format) {
|
|
1383
|
+
const resp = await this.request(
|
|
1384
|
+
"POST",
|
|
1385
|
+
"/inventory-manager/inventories/parse",
|
|
1386
|
+
{ json: { format, content: wireContent(content) } }
|
|
1387
|
+
);
|
|
1388
|
+
return await resp.json();
|
|
1389
|
+
}
|
|
1390
|
+
/** Scan → briefing in one call: parse the scan FILE (`parseScan`), enrich the discovered assets against
|
|
1391
|
+
* the `/v1/inventory-enrich` ranking engine, and assemble a structured briefing. `format` is one of
|
|
1392
|
+
* json/sbom/csv/nmap/list/grype/trivy/depcheck/nessus/gvm/xlsx. The parse is usage-exempt; the enrichment **submit counts
|
|
1393
|
+
* toward usage** (one `/v1/inventory-enrich` request). Resolves
|
|
1394
|
+
* `{ format, parsed_count, truncated?, enrichment_id, report, recommended_actions }` (report = the
|
|
1395
|
+
* engine's KEV-first-ranked findings + rollup). An empty parse short-circuits to
|
|
1396
|
+
* `{ format, parsed_count: 0, enrichment_id: null, empty: true }`. */
|
|
1397
|
+
async ingestScan(content, format, options = {}) {
|
|
1398
|
+
return ingestScan(this, content, format, options);
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
// src/enricher.ts
|
|
1403
|
+
var EnricherApi = class {
|
|
1404
|
+
baseUrl;
|
|
1405
|
+
// True ES2022 private field, not TypeScript `private`: `private` is erased at compile
|
|
1406
|
+
// time, leaving an enumerable own property that JSON.stringify and
|
|
1407
|
+
// util.inspect (so console.log) print in cleartext. `#` is enforced by the
|
|
1408
|
+
// runtime and invisible to both.
|
|
1409
|
+
#apiKey;
|
|
1410
|
+
doFetch;
|
|
1411
|
+
constructor(baseUrl, apiKey, doFetch) {
|
|
1412
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1413
|
+
this.#apiKey = apiKey;
|
|
1414
|
+
this.doFetch = doFetch;
|
|
1415
|
+
}
|
|
1416
|
+
async request(method, path, opts = {}) {
|
|
1417
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
1418
|
+
for (const [k, v] of Object.entries(opts.params ?? {}))
|
|
1419
|
+
url.searchParams.set(k, v);
|
|
1420
|
+
const init = {
|
|
1421
|
+
method,
|
|
1422
|
+
headers: {
|
|
1423
|
+
apikey: this.#apiKey,
|
|
1424
|
+
...opts.json !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
1425
|
+
},
|
|
1426
|
+
...opts.json !== void 0 ? { body: JSON.stringify(opts.json) } : {}
|
|
1427
|
+
};
|
|
1428
|
+
const resp = opts.timeoutMs === void 0 ? await this.doFetch(url, init) : await this.doFetch(
|
|
1429
|
+
new Request(url, {
|
|
1430
|
+
...init,
|
|
1431
|
+
signal: AbortSignal.timeout(
|
|
1432
|
+
Math.max(1, Math.ceil(opts.timeoutMs))
|
|
1433
|
+
)
|
|
1434
|
+
})
|
|
1435
|
+
);
|
|
1436
|
+
if (!resp.ok) {
|
|
1437
|
+
const body = await resp.text().catch(() => "");
|
|
1438
|
+
throw new UnexpectedStatus(
|
|
1439
|
+
resp.status,
|
|
1440
|
+
body,
|
|
1441
|
+
`Enricher API ${resp.status} on ${path}`
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
return resp;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Run an artifact enrichment end-to-end against the /v1 engine: submit → poll → return the report.
|
|
1448
|
+
*
|
|
1449
|
+
* Stages pasted `text` + base64 `files` (`[{ filename, content_b64 }]`), submits to
|
|
1450
|
+
* `/v1/artifact-enrich`, polls the job until done, and resolves to the enrichment report.
|
|
1451
|
+
*
|
|
1452
|
+
* `stakeholder` is the optional SSVC stakeholder context applied to every reference when `include`
|
|
1453
|
+
* contains `"ssvc"` (`{ method, exposure, human_impact, mission_prevalence, public_wellbeing_impact }`;
|
|
1454
|
+
* omit to use the engine's CISA-coordinator defaults).
|
|
1455
|
+
*
|
|
1456
|
+
* Counts toward your API usage (it's `/v1/artifact-enrich` compute). Throws `UnexpectedStatus` on a
|
|
1457
|
+
* non-2xx (or enrichment error), or `Error` if the enrichment doesn't finish within `timeoutMs`.
|
|
1458
|
+
* Resolves to `{ enrichment_id, report }`.
|
|
1459
|
+
*/
|
|
1460
|
+
async enrich(options = {}) {
|
|
1461
|
+
validatePollOptions(
|
|
1462
|
+
options.pollIntervalMs ?? 3e3,
|
|
1463
|
+
options.timeoutMs ?? 3e5
|
|
1464
|
+
);
|
|
1465
|
+
const body = {};
|
|
1466
|
+
if (options.text) body.text = options.text;
|
|
1467
|
+
if (options.files) body.files = options.files;
|
|
1468
|
+
if (options.formats) body.formats = options.formats;
|
|
1469
|
+
if (options.include) body.include = options.include;
|
|
1470
|
+
if (options.stakeholder) body.stakeholder = options.stakeholder;
|
|
1471
|
+
const submit = await (await this.request("POST", "/v1/artifact-enrich", { json: body })).json();
|
|
1472
|
+
const enrichmentId = submit.enrichment_id;
|
|
1473
|
+
const job = await pollUntilDone(
|
|
1474
|
+
(m, p, timeoutMs) => this.request(m, p, { timeoutMs }),
|
|
1475
|
+
enrichmentId,
|
|
1476
|
+
`/v1/artifact-enrich/${pathSegment(enrichmentId)}`,
|
|
1477
|
+
{
|
|
1478
|
+
pollIntervalMs: options.pollIntervalMs ?? 3e3,
|
|
1479
|
+
timeoutMs: options.timeoutMs ?? 3e5,
|
|
1480
|
+
onProgress: options.onProgress
|
|
1481
|
+
}
|
|
1482
|
+
);
|
|
1483
|
+
const result = {
|
|
1484
|
+
enrichment_id: enrichmentId,
|
|
1485
|
+
report: job.result
|
|
1486
|
+
};
|
|
1487
|
+
if (options.save) {
|
|
1488
|
+
const saveBody = { enrichment_id: enrichmentId };
|
|
1489
|
+
if (options.folderId || options.newFolderName) {
|
|
1490
|
+
saveBody.folder = {
|
|
1491
|
+
folder_id: options.folderId ?? null,
|
|
1492
|
+
new_folder_name: options.newFolderName ?? null
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
result.saved = await (await this.request(
|
|
1496
|
+
"POST",
|
|
1497
|
+
"/artifact-manager/artifacts/from-enrichment",
|
|
1498
|
+
{ json: saveBody }
|
|
1499
|
+
)).json();
|
|
1500
|
+
}
|
|
1501
|
+
return result;
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
// src/retry.ts
|
|
1506
|
+
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
1507
|
+
429,
|
|
1508
|
+
502,
|
|
1509
|
+
503,
|
|
1510
|
+
504
|
|
1511
|
+
]);
|
|
1512
|
+
var RETRY_BASE_DELAY = 0.5;
|
|
1513
|
+
var RETRY_MAX_DELAY = 8;
|
|
1514
|
+
var RETRY_JITTER_RATIO = 0.25;
|
|
1515
|
+
var RETRY_AFTER_MAX = 60;
|
|
1516
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
1517
|
+
var defaultSleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
1518
|
+
function computeBackoff(attempt, rng = Math.random) {
|
|
1519
|
+
const raw = RETRY_BASE_DELAY * 2 ** attempt;
|
|
1520
|
+
const jitter = raw * RETRY_JITTER_RATIO * (rng() * 2 - 1);
|
|
1521
|
+
const delay = Math.min(RETRY_MAX_DELAY, raw + jitter);
|
|
1522
|
+
return Math.max(0, delay);
|
|
1523
|
+
}
|
|
1524
|
+
function parseRetryAfter(header, now = Date.now()) {
|
|
1525
|
+
if (header == null) return null;
|
|
1526
|
+
const trimmed = header.trim();
|
|
1527
|
+
if (trimmed === "") return null;
|
|
1528
|
+
if (/^\d+$/.test(trimmed)) {
|
|
1529
|
+
return Math.min(RETRY_AFTER_MAX, Number(trimmed));
|
|
1530
|
+
}
|
|
1531
|
+
const when = Date.parse(trimmed);
|
|
1532
|
+
if (Number.isNaN(when)) return null;
|
|
1533
|
+
const seconds = Math.max(0, (when - now) / 1e3);
|
|
1534
|
+
return Math.min(RETRY_AFTER_MAX, seconds);
|
|
1535
|
+
}
|
|
1536
|
+
function resolveDelay(attempt, retryAfter, rng = Math.random) {
|
|
1537
|
+
const parsed = parseRetryAfter(retryAfter);
|
|
1538
|
+
if (parsed !== null) return parsed;
|
|
1539
|
+
return computeBackoff(attempt, rng);
|
|
1540
|
+
}
|
|
1541
|
+
function isRetryableFetchError(err, userSignal) {
|
|
1542
|
+
if (userSignal) return false;
|
|
1543
|
+
if (err instanceof TypeError) return true;
|
|
1544
|
+
if (typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "TimeoutError") {
|
|
1545
|
+
return true;
|
|
1546
|
+
}
|
|
1547
|
+
if (err != null && typeof err === "object" && err.name === "TimeoutError") {
|
|
1548
|
+
return true;
|
|
1549
|
+
}
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
async function sleepBackoff(attempt, retryAfter, cfg) {
|
|
1553
|
+
const delay = resolveDelay(attempt, retryAfter, cfg.rng ?? Math.random);
|
|
1554
|
+
await (cfg.sleep ?? defaultSleep)(delay);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
// src/client.ts
|
|
1558
|
+
var BASE_URL = "https://crimsoncrawler.com";
|
|
1559
|
+
var DEFAULT_TIMEOUT_MS = 9e4;
|
|
1560
|
+
var RETRYABLE_METHODS = {
|
|
1561
|
+
GET: true,
|
|
1562
|
+
HEAD: true,
|
|
1563
|
+
OPTIONS: true
|
|
1564
|
+
};
|
|
1565
|
+
var ENV_API_KEY = "CRIMSON_CRAWLER_API_KEY";
|
|
1566
|
+
var ENV_BASE_URL = "CRIMSON_CRAWLER_BASE_URL";
|
|
1567
|
+
var ENV_VERIFY_SSL = "CRIMSON_CRAWLER_VERIFY_SSL";
|
|
1568
|
+
function resolveVerifySsl(verifySsl) {
|
|
1569
|
+
if (verifySsl !== void 0) return verifySsl;
|
|
1570
|
+
const raw = globalThis.process?.env?.[ENV_VERIFY_SSL]?.trim().toLowerCase() ?? "true";
|
|
1571
|
+
return !(raw === "false" || raw === "0" || raw === "no");
|
|
1572
|
+
}
|
|
1573
|
+
function validateBaseUrl(baseUrl) {
|
|
1574
|
+
const invalidUrlMessage = "baseUrl must be a valid HTTPS URL or an HTTP loopback URL";
|
|
1575
|
+
if (!baseUrl || baseUrl !== baseUrl.trim() || /\s/u.test(baseUrl) || !/^[A-Za-z][A-Za-z\d+.-]*:\/\//u.test(baseUrl)) {
|
|
1576
|
+
throw new RangeError(invalidUrlMessage);
|
|
1577
|
+
}
|
|
1578
|
+
let parsed;
|
|
1579
|
+
try {
|
|
1580
|
+
parsed = new URL(baseUrl);
|
|
1581
|
+
} catch {
|
|
1582
|
+
throw new RangeError(invalidUrlMessage);
|
|
1583
|
+
}
|
|
1584
|
+
const authority = baseUrl.slice(baseUrl.indexOf("://") + 3).split(/[/?#]/u, 1)[0];
|
|
1585
|
+
if (!parsed.hostname || authority.includes("@")) {
|
|
1586
|
+
throw new RangeError(invalidUrlMessage);
|
|
1587
|
+
}
|
|
1588
|
+
if (parsed.pathname !== "" && parsed.pathname !== "/" || parsed.search || parsed.hash) {
|
|
1589
|
+
throw new RangeError(
|
|
1590
|
+
"baseUrl must contain only an origin, without a path, query, or fragment"
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
1594
|
+
const loopback = hostname === "localhost" || /^127(?:\.\d{1,3}){3}$/u.test(hostname) || hostname === "[::1]";
|
|
1595
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && loopback)) {
|
|
1596
|
+
throw new RangeError("baseUrl must use HTTPS unless its host is loopback");
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
var CrawlerClient = class {
|
|
1600
|
+
baseUrl;
|
|
1601
|
+
verifySsl;
|
|
1602
|
+
maxRetries;
|
|
1603
|
+
_client;
|
|
1604
|
+
_artifactManager;
|
|
1605
|
+
_inventoryManager;
|
|
1606
|
+
_enricher;
|
|
1607
|
+
_aiReports;
|
|
1608
|
+
constructor(opts = {}) {
|
|
1609
|
+
const apiKey = opts.apiKey ?? globalThis.process?.env?.[ENV_API_KEY];
|
|
1610
|
+
if (!apiKey) {
|
|
1611
|
+
throw new MissingCredentials(
|
|
1612
|
+
`Set ${ENV_API_KEY} or pass apiKey explicitly.`
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
this.baseUrl = opts.baseUrl ?? globalThis.process?.env?.[ENV_BASE_URL] ?? BASE_URL;
|
|
1616
|
+
validateBaseUrl(this.baseUrl);
|
|
1617
|
+
this.verifySsl = resolveVerifySsl(opts.verifySsl);
|
|
1618
|
+
const maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1619
|
+
if (!Number.isInteger(maxRetries) || maxRetries < 0) {
|
|
1620
|
+
throw new RangeError(
|
|
1621
|
+
`maxRetries must be a non-negative integer, got ${maxRetries}.`
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
this.maxRetries = maxRetries;
|
|
1625
|
+
let insecureDispatcher;
|
|
1626
|
+
const fetchWithTls = async (input, init) => {
|
|
1627
|
+
if (this.verifySsl) {
|
|
1628
|
+
return globalThis.fetch(input, init);
|
|
1629
|
+
}
|
|
1630
|
+
if (typeof globalThis.process?.versions?.node !== "string") {
|
|
1631
|
+
throw new Error(
|
|
1632
|
+
"verifySsl=false is only supported in Node.js; this runtime cannot disable TLS verification per client."
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
insecureDispatcher ??= import('undici').then(
|
|
1636
|
+
({ Agent }) => new Agent({ connect: { rejectUnauthorized: false } })
|
|
1637
|
+
);
|
|
1638
|
+
const dispatcher = await insecureDispatcher;
|
|
1639
|
+
const scopedInit = { ...init, dispatcher };
|
|
1640
|
+
return globalThis.fetch(input, scopedInit);
|
|
1641
|
+
};
|
|
1642
|
+
const retryCfg = { maxRetries };
|
|
1643
|
+
const authOrigin = new URL(this.baseUrl).origin;
|
|
1644
|
+
const retryFetch = async (input, init) => {
|
|
1645
|
+
const initSignal = init?.signal;
|
|
1646
|
+
const requestSignal = !initSignal && input instanceof Request ? input.signal : void 0;
|
|
1647
|
+
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
1648
|
+
const retryable = RETRYABLE_METHODS[method] === true;
|
|
1649
|
+
let attempt = 0;
|
|
1650
|
+
for (; ; ) {
|
|
1651
|
+
const timeoutSignal = AbortSignal.timeout(DEFAULT_TIMEOUT_MS);
|
|
1652
|
+
const signal = initSignal ?? (requestSignal ? AbortSignal.any([requestSignal, timeoutSignal]) : timeoutSignal);
|
|
1653
|
+
try {
|
|
1654
|
+
const resp = await fetchWithTls(input, {
|
|
1655
|
+
...init,
|
|
1656
|
+
signal,
|
|
1657
|
+
redirect: "manual",
|
|
1658
|
+
// Stamped per request, and only for our own origin, so the key
|
|
1659
|
+
// never lives on the client config nor travels to another host.
|
|
1660
|
+
headers: withApiKeyHeader(
|
|
1661
|
+
input,
|
|
1662
|
+
init,
|
|
1663
|
+
"apikey",
|
|
1664
|
+
apiKey,
|
|
1665
|
+
authOrigin
|
|
1666
|
+
)
|
|
1667
|
+
});
|
|
1668
|
+
if (retryable && RETRYABLE_STATUS.has(resp.status) && attempt < maxRetries) {
|
|
1669
|
+
try {
|
|
1670
|
+
await resp.body?.cancel();
|
|
1671
|
+
} catch {
|
|
1672
|
+
}
|
|
1673
|
+
await sleepBackoff(
|
|
1674
|
+
attempt,
|
|
1675
|
+
resp.headers.get("retry-after"),
|
|
1676
|
+
retryCfg
|
|
1677
|
+
);
|
|
1678
|
+
attempt++;
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
return resp;
|
|
1682
|
+
} catch (err) {
|
|
1683
|
+
const requestSignalAborted = requestSignal?.aborted === true;
|
|
1684
|
+
if (!requestSignalAborted && retryable && isRetryableFetchError(err, initSignal) && attempt < maxRetries) {
|
|
1685
|
+
await sleepBackoff(attempt, null, retryCfg);
|
|
1686
|
+
attempt++;
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
throw err;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
};
|
|
1693
|
+
const clientConfig = {
|
|
1694
|
+
baseUrl: this.baseUrl,
|
|
1695
|
+
// Deliberately no `headers: { apikey }` — the generated client would keep
|
|
1696
|
+
// it in a reachable `Headers` object that `util.inspect` prints in full.
|
|
1697
|
+
// `retryFetch` stamps it onto each request instead (see ./_auth.ts).
|
|
1698
|
+
fetch: retryFetch
|
|
1699
|
+
};
|
|
1700
|
+
this._client = chunk4CXMKUDH_cjs.createClient(clientConfig);
|
|
1701
|
+
if (opts.configureGlobalClient) {
|
|
1702
|
+
chunk4CXMKUDH_cjs.client.setConfig(clientConfig);
|
|
1703
|
+
}
|
|
1704
|
+
this._artifactManager = new ArtifactManagerApi(
|
|
1705
|
+
this.baseUrl,
|
|
1706
|
+
apiKey,
|
|
1707
|
+
retryFetch
|
|
1708
|
+
);
|
|
1709
|
+
this._inventoryManager = new InventoryManagerApi(
|
|
1710
|
+
this.baseUrl,
|
|
1711
|
+
apiKey,
|
|
1712
|
+
retryFetch
|
|
1713
|
+
);
|
|
1714
|
+
this._enricher = new EnricherApi(this.baseUrl, apiKey, retryFetch);
|
|
1715
|
+
this._aiReports = new AiReportsApi(this.baseUrl, apiKey, retryFetch);
|
|
1716
|
+
}
|
|
1717
|
+
/** Underlying Hey API client, scoped to this instance. Use to call any of the 33 endpoints directly. */
|
|
1718
|
+
get api() {
|
|
1719
|
+
return this._client;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* The Artifact Manager API (Artifact Manager) — your stored artifacts, enrichment exports,
|
|
1723
|
+
* ratings, enrichment-compare, and folders over the same key. Hand-written (the
|
|
1724
|
+
* `/artifact-manager/*` surface lives outside the `/v1` OpenAPI contract) and
|
|
1725
|
+
* **usage-exempt** — artifactManager calls never count toward your API usage.
|
|
1726
|
+
*/
|
|
1727
|
+
get artifactManager() {
|
|
1728
|
+
return this._artifactManager;
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* The Inventory Manager API — your monitored inventory context windows (asset inventory + attached
|
|
1732
|
+
* artifacts + saved enrichment history) over the same key. Its own section at
|
|
1733
|
+
* `/inventory-manager/inventories/*` (outside the `/v1` OpenAPI contract). **Usage-exempt** except
|
|
1734
|
+
* `enrichInventory`'s submit, which is enrichment compute and counts toward your usage.
|
|
1735
|
+
*/
|
|
1736
|
+
get inventoryManager() {
|
|
1737
|
+
return this._inventoryManager;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* The Enricher API — the async artifact-enrichment lifecycle (submit → poll → report) over the same
|
|
1741
|
+
* key, straight against the `/v1/artifact-enrich` engine. The enrichment submit counts toward usage;
|
|
1742
|
+
* polling is the engine's own status read.
|
|
1743
|
+
*/
|
|
1744
|
+
get enricher() {
|
|
1745
|
+
return this._enricher;
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* The Report Generator API — generate + manage grounded intelligence reports from
|
|
1749
|
+
* your saved artifacts, at `/ai-reports/*` (its own section, outside the `/v1` OpenAPI contract).
|
|
1750
|
+
* **Usage-exempt**, including the LLM generation.
|
|
1751
|
+
*/
|
|
1752
|
+
get aiReports() {
|
|
1753
|
+
return this._aiReports;
|
|
1754
|
+
}
|
|
1755
|
+
// -- Convenience methods for the most common enrichment chains --------- //
|
|
1756
|
+
/**
|
|
1757
|
+
* Walk the full CVE → CWE → CAPEC → ATT&CK → TIE chain plus MISP/knowledge base/web.
|
|
1758
|
+
*
|
|
1759
|
+
* @param cveId CVE identifier (e.g. `CVE-2024-3400`).
|
|
1760
|
+
* @param include Override the default `CVE_FULL_WALK` chain.
|
|
1761
|
+
*/
|
|
1762
|
+
async enrichCveFull(cveId, include = chunk4PCL3ANB_cjs.CVE_FULL_WALK) {
|
|
1763
|
+
const result = await chunk4HSWOQA6_cjs.enrichCve({
|
|
1764
|
+
client: this._client,
|
|
1765
|
+
body: { cve_id: cveId, include: [...include] }
|
|
1766
|
+
});
|
|
1767
|
+
return ensureOk(result);
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Enrich an IOC against MISP, link to ATT&CK, and add knowledge base/web context.
|
|
1771
|
+
*
|
|
1772
|
+
* @param value Indicator value (hash, IP, domain, URL).
|
|
1773
|
+
* @param iocType MISP-style attribute type — `ip-dst`, `ip-src`, `domain`,
|
|
1774
|
+
* `hostname`, `md5`, `sha1`, `sha256`, `url`, etc. Defaults to `ip-dst`.
|
|
1775
|
+
* @param include Override the default `IOC_FULL_WALK` chain.
|
|
1776
|
+
*/
|
|
1777
|
+
async enrichIocFull(value, iocType = "ip-dst", include = chunk4PCL3ANB_cjs.IOC_FULL_WALK) {
|
|
1778
|
+
const result = await chunk4HSWOQA6_cjs.enrichIoc({
|
|
1779
|
+
client: this._client,
|
|
1780
|
+
body: { value, type: iocType, include: [...include] }
|
|
1781
|
+
});
|
|
1782
|
+
return ensureOk(result);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Walk CWE → CAPEC → ATT&CK with TIE predictions.
|
|
1786
|
+
*
|
|
1787
|
+
* @param cweId CWE identifier (e.g. `CWE-79`).
|
|
1788
|
+
* @param include Override the default `CWE_FULL_WALK` chain.
|
|
1789
|
+
*/
|
|
1790
|
+
async enrichCweFull(cweId, include = chunk4PCL3ANB_cjs.CWE_FULL_WALK) {
|
|
1791
|
+
const result = await chunk4HSWOQA6_cjs.enrichCwe({
|
|
1792
|
+
client: this._client,
|
|
1793
|
+
body: { cwe_id: cweId, include: [...include] }
|
|
1794
|
+
});
|
|
1795
|
+
return ensureOk(result);
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Enrich one or more ATT&CK techniques with TIE, adversary attribution,
|
|
1799
|
+
* and Navigator JSON.
|
|
1800
|
+
*
|
|
1801
|
+
* @param techniqueIds ATT&CK technique IDs (e.g. `["T1190", "T1059.001"]`).
|
|
1802
|
+
* @param framework ATT&CK matrix variant — `enterprise`, `ics`, or `mobile`.
|
|
1803
|
+
* @param include Override the default `TECHNIQUE_FULL` chain.
|
|
1804
|
+
*/
|
|
1805
|
+
async enrichTechniqueFull(techniqueIds, framework = "enterprise", include = chunk4PCL3ANB_cjs.TECHNIQUE_FULL) {
|
|
1806
|
+
const result = await chunk4HSWOQA6_cjs.enrichTechnique({
|
|
1807
|
+
client: this._client,
|
|
1808
|
+
body: {
|
|
1809
|
+
technique_ids: techniqueIds,
|
|
1810
|
+
framework,
|
|
1811
|
+
include: [...include]
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
return ensureOk(result);
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Find vulnerabilities affecting a product/version and enrich each matched CVE.
|
|
1818
|
+
*
|
|
1819
|
+
* @param product Product name (e.g. `"Apache HTTP Server"`, `"nginx"`).
|
|
1820
|
+
* @param options Optional `version`, `vendor`, and `include` overrides.
|
|
1821
|
+
*/
|
|
1822
|
+
async enrichProductFull(product, options = {}) {
|
|
1823
|
+
const result = await chunk4HSWOQA6_cjs.enrichProduct({
|
|
1824
|
+
client: this._client,
|
|
1825
|
+
body: {
|
|
1826
|
+
product,
|
|
1827
|
+
...options.version !== void 0 && { version: options.version },
|
|
1828
|
+
...options.vendor !== void 0 && { vendor: options.vendor },
|
|
1829
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.PRODUCT_FULL]
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
return ensureOk(result);
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Enrich an open-source package — OSV.dev advisories + full CVE enrichment.
|
|
1836
|
+
*
|
|
1837
|
+
* The package-ecosystem sibling of {@link enrichProductFull}: OSV.dev supplies the
|
|
1838
|
+
* package's advisories, and the CVEs they alias are enriched through the same
|
|
1839
|
+
* CWE→CAPEC→ATT&CK + EPSS/KEV chain. Covers the dependency-vuln surface (npm /
|
|
1840
|
+
* PyPI / Go / Maven / crates.io / …) the CPE-keyed product endpoint can't reach.
|
|
1841
|
+
*
|
|
1842
|
+
* @param ecosystem Package ecosystem (e.g. `"PyPI"`, `"npm"`, `"Go"`).
|
|
1843
|
+
* @param packageName Package name as published in its registry (e.g. `"django"`).
|
|
1844
|
+
* @param options Optional `version` and `include` overrides.
|
|
1845
|
+
*/
|
|
1846
|
+
async enrichPackageFull(ecosystem, packageName, options = {}) {
|
|
1847
|
+
const result = await chunk4HSWOQA6_cjs.enrichPackage({
|
|
1848
|
+
client: this._client,
|
|
1849
|
+
body: {
|
|
1850
|
+
ecosystem,
|
|
1851
|
+
package: packageName,
|
|
1852
|
+
...options.version !== void 0 && { version: options.version },
|
|
1853
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.PACKAGE_FULL]
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
return ensureOk(result);
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Keyword-search the ATT&CK knowledge base for matching techniques.
|
|
1860
|
+
*
|
|
1861
|
+
* A convenience wrapper over the generated `search_cti` endpoint, scoped to
|
|
1862
|
+
* ATT&CK attack-patterns. Replaces the raw escape hatch callers previously
|
|
1863
|
+
* used to hand-build the request.
|
|
1864
|
+
*
|
|
1865
|
+
* @param keyword Free-text query (e.g. `"phishing"`, `"credential dumping"`).
|
|
1866
|
+
* @param options Optional `limit` (1-100, default 20).
|
|
1867
|
+
*/
|
|
1868
|
+
async searchTechniques(keyword, options = {}) {
|
|
1869
|
+
const result = await chunk4HSWOQA6_cjs.searchCti({
|
|
1870
|
+
client: this._client,
|
|
1871
|
+
body: {
|
|
1872
|
+
query: keyword,
|
|
1873
|
+
sources: ["attack"],
|
|
1874
|
+
types: ["attack-pattern"],
|
|
1875
|
+
limit: options.limit ?? 20
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
return ensureOk(result);
|
|
1879
|
+
}
|
|
1880
|
+
// -- Entity enrichment: full-walk chains ------------------------------- //
|
|
1881
|
+
//
|
|
1882
|
+
// Each endpoint accepts either its own ID or a `search` keyword, both
|
|
1883
|
+
// optional. Neither is enforced client-side: the server's validator answers
|
|
1884
|
+
// a request carrying neither with `422`, which surfaces as UnexpectedStatus
|
|
1885
|
+
// like every other rejection.
|
|
1886
|
+
/**
|
|
1887
|
+
* Walk an ATLAS adversarial-ML technique to its ATT&CK mappings and adversary graph.
|
|
1888
|
+
*
|
|
1889
|
+
* @param techniqueId ATLAS technique ID (e.g. `AML.T0043`).
|
|
1890
|
+
* @param options Optional `search` keyword and `include` override (default `ATLAS_FULL`).
|
|
1891
|
+
*/
|
|
1892
|
+
async enrichAtlasFull(techniqueId, options = {}) {
|
|
1893
|
+
const result = await chunk4HSWOQA6_cjs.enrichAtlas({
|
|
1894
|
+
client: this._client,
|
|
1895
|
+
body: {
|
|
1896
|
+
...techniqueId !== void 0 && { technique_id: techniqueId },
|
|
1897
|
+
...options.search !== void 0 && { search: options.search },
|
|
1898
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.ATLAS_FULL]
|
|
1899
|
+
}
|
|
1900
|
+
});
|
|
1901
|
+
return ensureOk(result);
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* Walk a threat campaign to its techniques, the groups behind it, and the CVEs it exploited.
|
|
1905
|
+
*
|
|
1906
|
+
* @param campaignId ATT&CK campaign ID (e.g. `C0011`).
|
|
1907
|
+
* @param options Optional `search` keyword, `framework` matrix, and `include`
|
|
1908
|
+
* override (default `CAMPAIGN_FULL`).
|
|
1909
|
+
*/
|
|
1910
|
+
async enrichCampaignFull(campaignId, options = {}) {
|
|
1911
|
+
const result = await chunk4HSWOQA6_cjs.enrichCampaign({
|
|
1912
|
+
client: this._client,
|
|
1913
|
+
body: {
|
|
1914
|
+
...campaignId !== void 0 && { campaign_id: campaignId },
|
|
1915
|
+
...options.search !== void 0 && { search: options.search },
|
|
1916
|
+
framework: options.framework ?? "enterprise",
|
|
1917
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.CAMPAIGN_FULL]
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
return ensureOk(result);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Walk a CAPEC attack pattern to its ATT&CK techniques, exploitable CVEs, and adversaries.
|
|
1924
|
+
*
|
|
1925
|
+
* @param capecId CAPEC identifier (e.g. `CAPEC-66`).
|
|
1926
|
+
* @param options Optional `search` keyword and `include` override (default `CAPEC_FULL`).
|
|
1927
|
+
*/
|
|
1928
|
+
async enrichCapecFull(capecId, options = {}) {
|
|
1929
|
+
const result = await chunk4HSWOQA6_cjs.enrichCapec({
|
|
1930
|
+
client: this._client,
|
|
1931
|
+
body: {
|
|
1932
|
+
...capecId !== void 0 && { capec_id: capecId },
|
|
1933
|
+
...options.search !== void 0 && { search: options.search },
|
|
1934
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.CAPEC_FULL]
|
|
1935
|
+
}
|
|
1936
|
+
});
|
|
1937
|
+
return ensureOk(result);
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Resolve a D3FEND defensive technique and the offensive techniques it counters.
|
|
1941
|
+
*
|
|
1942
|
+
* @param d3fendId D3FEND identifier (e.g. `D3-NTA`).
|
|
1943
|
+
* @param options Optional `search` keyword and `include` override (default `DEFEND_FULL`).
|
|
1944
|
+
*/
|
|
1945
|
+
async enrichDefendFull(d3fendId, options = {}) {
|
|
1946
|
+
const result = await chunk4HSWOQA6_cjs.enrichDefend({
|
|
1947
|
+
client: this._client,
|
|
1948
|
+
body: {
|
|
1949
|
+
...d3fendId !== void 0 && { d3fend_id: d3fendId },
|
|
1950
|
+
...options.search !== void 0 && { search: options.search },
|
|
1951
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.DEFEND_FULL]
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
return ensureOk(result);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Walk a DISARM disinformation technique to its countermeasures and ATT&CK mappings.
|
|
1958
|
+
*
|
|
1959
|
+
* @param techniqueId DISARM technique ID (e.g. `T0086`).
|
|
1960
|
+
* @param options Optional `search` keyword and `include` override (default `DISARM_FULL`).
|
|
1961
|
+
*/
|
|
1962
|
+
async enrichDisarmFull(techniqueId, options = {}) {
|
|
1963
|
+
const result = await chunk4HSWOQA6_cjs.enrichDisarm({
|
|
1964
|
+
client: this._client,
|
|
1965
|
+
body: {
|
|
1966
|
+
...techniqueId !== void 0 && { technique_id: techniqueId },
|
|
1967
|
+
...options.search !== void 0 && { search: options.search },
|
|
1968
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.DISARM_FULL]
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
return ensureOk(result);
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Profile a threat actor: techniques, tooling, campaigns, exploited CVEs, and targeting.
|
|
1975
|
+
*
|
|
1976
|
+
* @param groupId ATT&CK group ID (e.g. `G0016`).
|
|
1977
|
+
* @param options Optional `search` keyword, `framework` matrix, and `include`
|
|
1978
|
+
* override (default `GROUP_FULL`).
|
|
1979
|
+
*/
|
|
1980
|
+
async enrichGroupFull(groupId, options = {}) {
|
|
1981
|
+
const result = await chunk4HSWOQA6_cjs.enrichGroup({
|
|
1982
|
+
client: this._client,
|
|
1983
|
+
body: {
|
|
1984
|
+
...groupId !== void 0 && { group_id: groupId },
|
|
1985
|
+
...options.search !== void 0 && { search: options.search },
|
|
1986
|
+
framework: options.framework ?? "enterprise",
|
|
1987
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.GROUP_FULL]
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
return ensureOk(result);
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Map a region's threat landscape — active groups, their techniques, and affected sectors.
|
|
1994
|
+
*
|
|
1995
|
+
* @param locationId Region identifier (e.g. `UA`, or an ATT&CK location STIX ID).
|
|
1996
|
+
* @param options Optional `search` keyword and `include` override (default `LOCATION_FULL`).
|
|
1997
|
+
*/
|
|
1998
|
+
async enrichLocationFull(locationId, options = {}) {
|
|
1999
|
+
const result = await chunk4HSWOQA6_cjs.enrichLocation({
|
|
2000
|
+
client: this._client,
|
|
2001
|
+
body: {
|
|
2002
|
+
...locationId !== void 0 && { location_id: locationId },
|
|
2003
|
+
...options.search !== void 0 && { search: options.search },
|
|
2004
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.LOCATION_FULL]
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
return ensureOk(result);
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Map an industry sector's threat landscape — who targets it, how, and from where.
|
|
2011
|
+
*
|
|
2012
|
+
* @param sectorId Sector identifier (e.g. `energy`, or an ATT&CK sector STIX ID).
|
|
2013
|
+
* @param options Optional `search` keyword and `include` override (default `SECTOR_FULL`).
|
|
2014
|
+
*/
|
|
2015
|
+
async enrichSectorFull(sectorId, options = {}) {
|
|
2016
|
+
const result = await chunk4HSWOQA6_cjs.enrichSector({
|
|
2017
|
+
client: this._client,
|
|
2018
|
+
body: {
|
|
2019
|
+
...sectorId !== void 0 && { sector_id: sectorId },
|
|
2020
|
+
...options.search !== void 0 && { search: options.search },
|
|
2021
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.SECTOR_FULL]
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
return ensureOk(result);
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Profile malware or a tool: the techniques it implements, who uses it, what it exploits.
|
|
2028
|
+
*
|
|
2029
|
+
* @param softwareId ATT&CK software ID (e.g. `S0002`).
|
|
2030
|
+
* @param options Optional `search` keyword, `framework` matrix, and `include`
|
|
2031
|
+
* override (default `SOFTWARE_FULL`).
|
|
2032
|
+
*/
|
|
2033
|
+
async enrichSoftwareFull(softwareId, options = {}) {
|
|
2034
|
+
const result = await chunk4HSWOQA6_cjs.enrichSoftware({
|
|
2035
|
+
client: this._client,
|
|
2036
|
+
body: {
|
|
2037
|
+
...softwareId !== void 0 && { software_id: softwareId },
|
|
2038
|
+
...options.search !== void 0 && { search: options.search },
|
|
2039
|
+
framework: options.framework ?? "enterprise",
|
|
2040
|
+
include: [...options.include ?? chunk4PCL3ANB_cjs.SOFTWARE_FULL]
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
return ensureOk(result);
|
|
2044
|
+
}
|
|
2045
|
+
// -- Enrichment: batch and PoC source ---------------------------------- //
|
|
2046
|
+
/**
|
|
2047
|
+
* Enrich a heterogeneous list of artifacts in one round trip.
|
|
2048
|
+
*
|
|
2049
|
+
* Each item carries its own `type` discriminator and per-item `include`, so a
|
|
2050
|
+
* single call can mix CVEs, products, packages, techniques, IOCs, and more.
|
|
2051
|
+
* Prefer this over N single-artifact calls: the server fans out internally and
|
|
2052
|
+
* shares upstream lookups across the batch.
|
|
2053
|
+
*
|
|
2054
|
+
* @param items Discriminated batch items (`{ type: "cve", cve_id: "..." }`, …).
|
|
2055
|
+
*/
|
|
2056
|
+
async enrichBatch(items) {
|
|
2057
|
+
const result = await chunk4HSWOQA6_cjs.enrichBatch({
|
|
2058
|
+
client: this._client,
|
|
2059
|
+
body: { items }
|
|
2060
|
+
});
|
|
2061
|
+
return ensureOk(result);
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Fetch the source of a public proof-of-concept exploit repository.
|
|
2065
|
+
*
|
|
2066
|
+
* Retrieves the code behind a PoC reference (as surfaced by the `poc` enrichment
|
|
2067
|
+
* layer) so it can be reviewed without leaving the API.
|
|
2068
|
+
*
|
|
2069
|
+
* @param repoUrl Public repository URL of the PoC.
|
|
2070
|
+
*/
|
|
2071
|
+
async enrichPocSource(repoUrl) {
|
|
2072
|
+
const result = await chunk4HSWOQA6_cjs.enrichPocSource({
|
|
2073
|
+
client: this._client,
|
|
2074
|
+
body: { repo_url: repoUrl }
|
|
2075
|
+
});
|
|
2076
|
+
return ensureOk(result);
|
|
2077
|
+
}
|
|
2078
|
+
// -- Assessments ------------------------------------------------------- //
|
|
2079
|
+
//
|
|
2080
|
+
// Assessment endpoints score a portfolio rather than enrich one artifact.
|
|
2081
|
+
// `include` has no full-walk preset here — omit it to take the server's
|
|
2082
|
+
// per-endpoint default, or pass an explicit layer list.
|
|
2083
|
+
/**
|
|
2084
|
+
* Score your exposure to specific threat actors.
|
|
2085
|
+
*
|
|
2086
|
+
* Supply `groupIds`, `search` terms, or both; the server rejects a request
|
|
2087
|
+
* carrying neither with `422`.
|
|
2088
|
+
*
|
|
2089
|
+
* @param options `groupIds`, `search` terms, `framework` matrix, and `include` layers.
|
|
2090
|
+
*/
|
|
2091
|
+
async assessGroupExposure(options = {}) {
|
|
2092
|
+
const result = await chunk4HSWOQA6_cjs.assessGroupExposure({
|
|
2093
|
+
client: this._client,
|
|
2094
|
+
body: {
|
|
2095
|
+
...options.groupIds !== void 0 && {
|
|
2096
|
+
group_ids: [...options.groupIds]
|
|
2097
|
+
},
|
|
2098
|
+
...options.search !== void 0 && { search: [...options.search] },
|
|
2099
|
+
framework: options.framework ?? "enterprise",
|
|
2100
|
+
...options.include !== void 0 && { include: [...options.include] }
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
return ensureOk(result);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Assess a portfolio of indicators — MISP corroboration, linked techniques, attribution.
|
|
2107
|
+
*
|
|
2108
|
+
* @param indicators Indicator objects, each `{ value, type? }` (`type` defaults to `ip-dst`).
|
|
2109
|
+
* @param options Optional `include` layers.
|
|
2110
|
+
*/
|
|
2111
|
+
async assessIocPortfolio(indicators, options = {}) {
|
|
2112
|
+
const result = await chunk4HSWOQA6_cjs.assessIocPortfolio({
|
|
2113
|
+
client: this._client,
|
|
2114
|
+
body: {
|
|
2115
|
+
indicators,
|
|
2116
|
+
...options.include !== void 0 && { include: [...options.include] }
|
|
2117
|
+
}
|
|
2118
|
+
});
|
|
2119
|
+
return ensureOk(result);
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Score detection and mitigation coverage across a set of ATT&CK techniques.
|
|
2123
|
+
*
|
|
2124
|
+
* @param techniqueIds ATT&CK technique IDs (e.g. `["T1190", "T1059.001"]`).
|
|
2125
|
+
* @param options Optional `framework` matrix and `include` layers.
|
|
2126
|
+
*/
|
|
2127
|
+
async assessTechniqueCoverage(techniqueIds, options = {}) {
|
|
2128
|
+
const result = await chunk4HSWOQA6_cjs.assessTechniqueCoverage({
|
|
2129
|
+
client: this._client,
|
|
2130
|
+
body: {
|
|
2131
|
+
technique_ids: [...techniqueIds],
|
|
2132
|
+
framework: options.framework ?? "enterprise",
|
|
2133
|
+
...options.include !== void 0 && { include: [...options.include] }
|
|
2134
|
+
}
|
|
2135
|
+
});
|
|
2136
|
+
return ensureOk(result);
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Prioritize a set of CVEs — weaponization, exploit chains, and remediation order.
|
|
2140
|
+
*
|
|
2141
|
+
* @param cveIds CVE identifiers to assess.
|
|
2142
|
+
* @param options Optional `include` layers and an SSVC `stakeholder` profile that
|
|
2143
|
+
* tunes the decision to your deployment.
|
|
2144
|
+
*/
|
|
2145
|
+
async assessVulnerabilityExposure(cveIds, options = {}) {
|
|
2146
|
+
const result = await chunk4HSWOQA6_cjs.assessVulnerabilityExposure({
|
|
2147
|
+
client: this._client,
|
|
2148
|
+
body: {
|
|
2149
|
+
cve_ids: [...cveIds],
|
|
2150
|
+
...options.include !== void 0 && { include: [...options.include] },
|
|
2151
|
+
...options.stakeholder !== void 0 && {
|
|
2152
|
+
stakeholder: options.stakeholder
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
return ensureOk(result);
|
|
2157
|
+
}
|
|
2158
|
+
// -- Search ------------------------------------------------------------ //
|
|
2159
|
+
//
|
|
2160
|
+
// Search endpoints query a corpus and return matches; they never walk an
|
|
2161
|
+
// enrichment chain, so none of them takes a full-walk preset. `include` (where
|
|
2162
|
+
// the corpus offers it) is a plain passthrough.
|
|
2163
|
+
/**
|
|
2164
|
+
* Search the CTI knowledge bases — ATT&CK, CWE, CAPEC, ATLAS, DISARM, and more.
|
|
2165
|
+
*
|
|
2166
|
+
* The unscoped sibling of {@link searchTechniques}: use this to reach any object
|
|
2167
|
+
* type across any source, and `searchTechniques` for the common ATT&CK-only case.
|
|
2168
|
+
*
|
|
2169
|
+
* @param query Free-text query.
|
|
2170
|
+
* @param options `sources`, `types`, `limit`, `page`, and the `deprecated`/`revoked` filters.
|
|
2171
|
+
*/
|
|
2172
|
+
async searchCti(query, options = {}) {
|
|
2173
|
+
const result = await chunk4HSWOQA6_cjs.searchCti({
|
|
2174
|
+
client: this._client,
|
|
2175
|
+
body: {
|
|
2176
|
+
query,
|
|
2177
|
+
...options.sources !== void 0 && { sources: [...options.sources] },
|
|
2178
|
+
...options.types !== void 0 && { types: options.types },
|
|
2179
|
+
limit: options.limit ?? 20,
|
|
2180
|
+
page: options.page ?? 1,
|
|
2181
|
+
...options.deprecated !== void 0 && {
|
|
2182
|
+
deprecated: options.deprecated
|
|
2183
|
+
},
|
|
2184
|
+
...options.revoked !== void 0 && { revoked: options.revoked }
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
return ensureOk(result);
|
|
2188
|
+
}
|
|
2189
|
+
/**
|
|
2190
|
+
* Search the vulnerability corpus by identifier, mapping, score, or date window.
|
|
2191
|
+
*
|
|
2192
|
+
* Every filter is optional and they compose: a bare call returns the newest
|
|
2193
|
+
* CVEs, while `{ kevOnly: true, epssMin: 0.5 }` narrows to actively exploited,
|
|
2194
|
+
* high-probability ones.
|
|
2195
|
+
*
|
|
2196
|
+
* @param query Free-text query. Omit it to filter purely on the structured fields.
|
|
2197
|
+
* @param options Any combination of the corpus filters, plus `sort`, `limit`, `page`.
|
|
2198
|
+
*/
|
|
2199
|
+
async searchCve(query, options = {}) {
|
|
2200
|
+
const result = await chunk4HSWOQA6_cjs.searchCve({
|
|
2201
|
+
client: this._client,
|
|
2202
|
+
body: {
|
|
2203
|
+
...query !== void 0 && { query },
|
|
2204
|
+
...options.cveId !== void 0 && { cve_id: options.cveId },
|
|
2205
|
+
...options.stixId !== void 0 && { stix_id: options.stixId },
|
|
2206
|
+
...options.cweId !== void 0 && { cwe_id: options.cweId },
|
|
2207
|
+
...options.capecId !== void 0 && { capec_id: options.capecId },
|
|
2208
|
+
...options.attackId !== void 0 && { attack_id: options.attackId },
|
|
2209
|
+
...options.cpe !== void 0 && { cpe: options.cpe },
|
|
2210
|
+
...options.cpesNotVulnerable !== void 0 && {
|
|
2211
|
+
cpes_not_vulnerable: options.cpesNotVulnerable
|
|
2212
|
+
},
|
|
2213
|
+
...options.createdByRef !== void 0 && {
|
|
2214
|
+
created_by_ref: options.createdByRef
|
|
2215
|
+
},
|
|
2216
|
+
...options.createdMin !== void 0 && {
|
|
2217
|
+
created_min: options.createdMin
|
|
2218
|
+
},
|
|
2219
|
+
...options.createdMax !== void 0 && {
|
|
2220
|
+
created_max: options.createdMax
|
|
2221
|
+
},
|
|
2222
|
+
...options.modifiedMin !== void 0 && {
|
|
2223
|
+
modified_min: options.modifiedMin
|
|
2224
|
+
},
|
|
2225
|
+
...options.modifiedMax !== void 0 && {
|
|
2226
|
+
modified_max: options.modifiedMax
|
|
2227
|
+
},
|
|
2228
|
+
...options.cvssMin !== void 0 && { cvss_min: options.cvssMin },
|
|
2229
|
+
...options.cvssV2Min !== void 0 && {
|
|
2230
|
+
cvss_v2_min: options.cvssV2Min
|
|
2231
|
+
},
|
|
2232
|
+
...options.cvssV4Min !== void 0 && {
|
|
2233
|
+
cvss_v4_min: options.cvssV4Min
|
|
2234
|
+
},
|
|
2235
|
+
...options.epssMin !== void 0 && { epss_min: options.epssMin },
|
|
2236
|
+
...options.epssPercentileMin !== void 0 && {
|
|
2237
|
+
epss_percentile_min: options.epssPercentileMin
|
|
2238
|
+
},
|
|
2239
|
+
kev_only: options.kevOnly ?? false,
|
|
2240
|
+
...options.vulnStatus !== void 0 && {
|
|
2241
|
+
vuln_status: options.vulnStatus
|
|
2242
|
+
},
|
|
2243
|
+
...options.sort !== void 0 && { sort: options.sort },
|
|
2244
|
+
...options.include !== void 0 && { include: [...options.include] },
|
|
2245
|
+
limit: options.limit ?? 50,
|
|
2246
|
+
page: options.page ?? 1
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
return ensureOk(result);
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Search the D3FEND defensive-countermeasure ontology.
|
|
2253
|
+
*
|
|
2254
|
+
* @param query Free-text query (e.g. `"network traffic analysis"`).
|
|
2255
|
+
* @param options `d3fendForm` to scope to a tactic/mitigation/artifact, plus `limit`, `page`.
|
|
2256
|
+
*/
|
|
2257
|
+
async searchD3fend(query, options = {}) {
|
|
2258
|
+
const result = await chunk4HSWOQA6_cjs.searchD3Fend({
|
|
2259
|
+
client: this._client,
|
|
2260
|
+
body: {
|
|
2261
|
+
query,
|
|
2262
|
+
...options.d3fendForm !== void 0 && {
|
|
2263
|
+
d3fend_form: options.d3fendForm
|
|
2264
|
+
},
|
|
2265
|
+
limit: options.limit ?? 20,
|
|
2266
|
+
page: options.page ?? 1
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
return ensureOk(result);
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Search CISA's Known Exploited Vulnerabilities catalog.
|
|
2273
|
+
*
|
|
2274
|
+
* An empty call pages the whole catalog; `cveId` checks one CVE's KEV status.
|
|
2275
|
+
*
|
|
2276
|
+
* @param options `cveId`, `ransomwareStatus`, `limit`, `page`.
|
|
2277
|
+
*/
|
|
2278
|
+
async searchKev(options = {}) {
|
|
2279
|
+
const result = await chunk4HSWOQA6_cjs.searchKev({
|
|
2280
|
+
client: this._client,
|
|
2281
|
+
body: {
|
|
2282
|
+
...options.cveId !== void 0 && { cve_id: options.cveId },
|
|
2283
|
+
...options.ransomwareStatus !== void 0 && {
|
|
2284
|
+
ransomware_status: options.ransomwareStatus
|
|
2285
|
+
},
|
|
2286
|
+
limit: options.limit ?? 50,
|
|
2287
|
+
page: options.page ?? 1
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
return ensureOk(result);
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Hybrid-search the curated security knowledge base.
|
|
2294
|
+
*
|
|
2295
|
+
* @param query Natural-language question or keyword set.
|
|
2296
|
+
* @param options `collections` to search, `alpha` to trade keyword vs. vector
|
|
2297
|
+
* weighting (0 = pure vector, 1 = pure keyword), and `limit`.
|
|
2298
|
+
*/
|
|
2299
|
+
async searchKnowledgebase(query, options = {}) {
|
|
2300
|
+
const result = await chunk4HSWOQA6_cjs.searchKnowledgebase({
|
|
2301
|
+
client: this._client,
|
|
2302
|
+
body: {
|
|
2303
|
+
query,
|
|
2304
|
+
...options.collections !== void 0 && {
|
|
2305
|
+
collections: options.collections
|
|
2306
|
+
},
|
|
2307
|
+
alpha: options.alpha ?? 0.7,
|
|
2308
|
+
limit: options.limit ?? 10
|
|
2309
|
+
}
|
|
2310
|
+
});
|
|
2311
|
+
return ensureOk(result);
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* Search MISP events and attributes.
|
|
2315
|
+
*
|
|
2316
|
+
* @param options Attribute filters (`value`, `typeAttribute`, `category`, `toIds`),
|
|
2317
|
+
* event filters (`eventId`, `eventinfo`, `tags`, `threatLevelId`, `published`),
|
|
2318
|
+
* a `dateFrom`/`dateTo` window, plus `limit` and `page`.
|
|
2319
|
+
*/
|
|
2320
|
+
async searchMisp(options = {}) {
|
|
2321
|
+
const result = await chunk4HSWOQA6_cjs.searchMisp({
|
|
2322
|
+
client: this._client,
|
|
2323
|
+
body: {
|
|
2324
|
+
...options.value !== void 0 && { value: options.value },
|
|
2325
|
+
...options.typeAttribute !== void 0 && {
|
|
2326
|
+
type_attribute: options.typeAttribute
|
|
2327
|
+
},
|
|
2328
|
+
...options.category !== void 0 && { category: options.category },
|
|
2329
|
+
...options.toIds !== void 0 && { to_ids: options.toIds },
|
|
2330
|
+
...options.eventId !== void 0 && { event_id: options.eventId },
|
|
2331
|
+
...options.eventinfo !== void 0 && {
|
|
2332
|
+
eventinfo: options.eventinfo
|
|
2333
|
+
},
|
|
2334
|
+
...options.tags !== void 0 && { tags: [...options.tags] },
|
|
2335
|
+
...options.threatLevelId !== void 0 && {
|
|
2336
|
+
threat_level_id: options.threatLevelId
|
|
2337
|
+
},
|
|
2338
|
+
...options.published !== void 0 && {
|
|
2339
|
+
published: options.published
|
|
2340
|
+
},
|
|
2341
|
+
...options.dateFrom !== void 0 && { date_from: options.dateFrom },
|
|
2342
|
+
...options.dateTo !== void 0 && { date_to: options.dateTo },
|
|
2343
|
+
limit: options.limit ?? 50,
|
|
2344
|
+
page: options.page ?? 1
|
|
2345
|
+
}
|
|
2346
|
+
});
|
|
2347
|
+
return ensureOk(result);
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Find public proof-of-concept exploits for a CVE.
|
|
2351
|
+
*
|
|
2352
|
+
* Pair with {@link enrichPocSource} to pull the code behind a match.
|
|
2353
|
+
*
|
|
2354
|
+
* @param cveId CVE identifier (e.g. `CVE-2024-3400`).
|
|
2355
|
+
* @param options Optional `limit` (default 25).
|
|
2356
|
+
*/
|
|
2357
|
+
async searchPoc(cveId, options = {}) {
|
|
2358
|
+
const result = await chunk4HSWOQA6_cjs.searchPoc({
|
|
2359
|
+
client: this._client,
|
|
2360
|
+
body: {
|
|
2361
|
+
cve_id: cveId,
|
|
2362
|
+
limit: options.limit ?? 25
|
|
2363
|
+
}
|
|
2364
|
+
});
|
|
2365
|
+
return ensureOk(result);
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* List the products a vendor ships, as known to the CPE dictionary.
|
|
2369
|
+
*
|
|
2370
|
+
* Use it to resolve the exact product string {@link enrichProductFull} expects.
|
|
2371
|
+
*
|
|
2372
|
+
* @param vendor Vendor name (e.g. `"microsoft"`).
|
|
2373
|
+
* @param options Optional `limit` (default 50).
|
|
2374
|
+
*/
|
|
2375
|
+
async searchVendor(vendor, options = {}) {
|
|
2376
|
+
const result = await chunk4HSWOQA6_cjs.searchVendor({
|
|
2377
|
+
client: this._client,
|
|
2378
|
+
body: {
|
|
2379
|
+
vendor,
|
|
2380
|
+
limit: options.limit ?? 50
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2383
|
+
return ensureOk(result);
|
|
2384
|
+
}
|
|
2385
|
+
// -- Async enrichment engines ------------------------------------------ //
|
|
2386
|
+
//
|
|
2387
|
+
// Both engines are submit-then-poll: the submit returns an `enrichment_id`,
|
|
2388
|
+
// and the matching `*Status` read reports progress until the report is ready.
|
|
2389
|
+
// `client.enricher` wraps the artifact engine's full lifecycle (submit, poll,
|
|
2390
|
+
// fetch) for callers who want the loop written for them; these two pairs are
|
|
2391
|
+
// the raw operations.
|
|
2392
|
+
/**
|
|
2393
|
+
* Submit documents and/or text to the async artifact-enrichment engine.
|
|
2394
|
+
*
|
|
2395
|
+
* Returns immediately with an `enrichment_id` — poll {@link artifactEnrichStatus}
|
|
2396
|
+
* for the result, or use {@link enricher} to run the whole lifecycle.
|
|
2397
|
+
*
|
|
2398
|
+
* @param options `text` and/or base64 `files` to analyze, output `formats`,
|
|
2399
|
+
* report `include` sections, and an SSVC `stakeholder` profile.
|
|
2400
|
+
*/
|
|
2401
|
+
async artifactEnrich(options = {}) {
|
|
2402
|
+
const result = await chunk4HSWOQA6_cjs.artifactEnrich({
|
|
2403
|
+
client: this._client,
|
|
2404
|
+
body: {
|
|
2405
|
+
...options.text !== void 0 && { text: options.text },
|
|
2406
|
+
...options.files !== void 0 && { files: options.files },
|
|
2407
|
+
...options.formats !== void 0 && { formats: options.formats },
|
|
2408
|
+
...options.include !== void 0 && { include: [...options.include] },
|
|
2409
|
+
...options.stakeholder !== void 0 && {
|
|
2410
|
+
stakeholder: options.stakeholder
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
return ensureOk(result);
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Read the progress or result of an artifact enrichment.
|
|
2418
|
+
*
|
|
2419
|
+
* @param enrichmentId The `enrichment_id` returned by {@link artifactEnrich}.
|
|
2420
|
+
*/
|
|
2421
|
+
async artifactEnrichStatus(enrichmentId) {
|
|
2422
|
+
const result = await chunk4HSWOQA6_cjs.artifactEnrichStatus({
|
|
2423
|
+
client: this._client,
|
|
2424
|
+
path: { enrichment_id: enrichmentId }
|
|
2425
|
+
});
|
|
2426
|
+
return ensureOk(result);
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Submit an asset inventory to the async inventory-enrichment engine.
|
|
2430
|
+
*
|
|
2431
|
+
* Returns immediately with an `enrichment_id` — poll {@link inventoryEnrichStatus}
|
|
2432
|
+
* for the result. Enriches each asset's CVEs and rolls the findings up to a
|
|
2433
|
+
* fleet-level risk picture.
|
|
2434
|
+
*
|
|
2435
|
+
* @param items Assets to enrich, each at minimum `{ product }`.
|
|
2436
|
+
* @param options Optional `attachmentsText`/`attachmentsFiles` for extra context
|
|
2437
|
+
* and per-asset CVE `include` layers.
|
|
2438
|
+
*/
|
|
2439
|
+
async inventoryEnrich(items, options = {}) {
|
|
2440
|
+
const result = await chunk4HSWOQA6_cjs.inventoryEnrich({
|
|
2441
|
+
client: this._client,
|
|
2442
|
+
body: {
|
|
2443
|
+
items: [...items],
|
|
2444
|
+
...options.attachmentsText !== void 0 && {
|
|
2445
|
+
attachments_text: options.attachmentsText
|
|
2446
|
+
},
|
|
2447
|
+
...options.attachmentsFiles !== void 0 && {
|
|
2448
|
+
attachments_files: options.attachmentsFiles
|
|
2449
|
+
},
|
|
2450
|
+
...options.include !== void 0 && { include: [...options.include] }
|
|
2451
|
+
}
|
|
2452
|
+
});
|
|
2453
|
+
return ensureOk(result);
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* Read the progress or result of an inventory enrichment.
|
|
2457
|
+
*
|
|
2458
|
+
* @param enrichmentId The `enrichment_id` returned by {@link inventoryEnrich}.
|
|
2459
|
+
*/
|
|
2460
|
+
async inventoryEnrichStatus(enrichmentId) {
|
|
2461
|
+
const result = await chunk4HSWOQA6_cjs.inventoryEnrichStatus({
|
|
2462
|
+
client: this._client,
|
|
2463
|
+
path: { enrichment_id: enrichmentId }
|
|
2464
|
+
});
|
|
2465
|
+
return ensureOk(result);
|
|
2466
|
+
}
|
|
2467
|
+
};
|
|
2468
|
+
function ensureOk(result) {
|
|
2469
|
+
if (result.data !== void 0 && result.error === void 0) {
|
|
2470
|
+
return result.data;
|
|
2471
|
+
}
|
|
2472
|
+
const status = result.response?.status ?? 0;
|
|
2473
|
+
const url = result.response?.url ?? "(no url)";
|
|
2474
|
+
throw new UnexpectedStatus(
|
|
2475
|
+
status,
|
|
2476
|
+
result.error ?? result.data,
|
|
2477
|
+
`Crimson Crawler API ${status} on ${url}`
|
|
2478
|
+
);
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
// package.json
|
|
2482
|
+
var package_default = {
|
|
2483
|
+
version: "4.1.1"};
|
|
2484
|
+
|
|
2485
|
+
// src/index.ts
|
|
2486
|
+
var __version__ = package_default.version;
|
|
2487
|
+
|
|
2488
|
+
Object.defineProperty(exports, "presets", {
|
|
2489
|
+
enumerable: true,
|
|
2490
|
+
get: function () { return chunk4PCL3ANB_cjs.presets_exports; }
|
|
2491
|
+
});
|
|
2492
|
+
exports.AiReportsApi = AiReportsApi;
|
|
2493
|
+
exports.ArtifactManagerApi = ArtifactManagerApi;
|
|
2494
|
+
exports.BASE_URL = BASE_URL;
|
|
2495
|
+
exports.CrawlerClient = CrawlerClient;
|
|
2496
|
+
exports.CrawlerClientError = CrawlerClientError;
|
|
2497
|
+
exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
2498
|
+
exports.ENV_API_KEY = ENV_API_KEY;
|
|
2499
|
+
exports.ENV_BASE_URL = ENV_BASE_URL;
|
|
2500
|
+
exports.ENV_VERIFY_SSL = ENV_VERIFY_SSL;
|
|
2501
|
+
exports.EnricherApi = EnricherApi;
|
|
2502
|
+
exports.InventoryManagerApi = InventoryManagerApi;
|
|
2503
|
+
exports.MissingCredentials = MissingCredentials;
|
|
2504
|
+
exports.UnexpectedStatus = UnexpectedStatus;
|
|
2505
|
+
exports.__version__ = __version__;
|
|
2506
|
+
exports.assembleBriefing = assembleBriefing;
|
|
2507
|
+
exports.ingestScan = ingestScan;
|