@cyvest/cyvest-js 2.0.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.
@@ -0,0 +1,1210 @@
1
+ /**
2
+ * Security level classification from NONE (lowest) to MALICIOUS (highest).
3
+ */
4
+ type Level = "NONE" | "TRUSTED" | "INFO" | "SAFE" | "NOTABLE" | "SUSPICIOUS" | "MALICIOUS";
5
+ /**
6
+ * Direction of a relationship between observables.
7
+ */
8
+ type RelationshipDirection = "outbound" | "inbound" | "bidirectional";
9
+ /**
10
+ * Score computation policy: 'auto' calculates from level, 'manual' uses explicit score.
11
+ */
12
+ type ScorePolicy = "auto" | "manual";
13
+ /**
14
+ * Score aggregation mode: 'max' takes highest score, 'sum' adds all scores.
15
+ */
16
+ type ScoreMode = "max" | "sum";
17
+ interface CyvestInvestigation {
18
+ score: number;
19
+ level: Level;
20
+ whitelisted: boolean;
21
+ whitelists: Whitelist[];
22
+ observables: {
23
+ [k: string]: Observable;
24
+ };
25
+ checks: {
26
+ [k: string]: Check[];
27
+ };
28
+ checks_by_level: {
29
+ [k: string]: string[];
30
+ };
31
+ threat_intels: {
32
+ [k: string]: ThreatIntel;
33
+ };
34
+ enrichments: {
35
+ [k: string]: Enrichment;
36
+ };
37
+ containers: {
38
+ [k: string]: Container;
39
+ };
40
+ stats: Statistics;
41
+ stats_checks: StatsChecks;
42
+ data_extraction: DataExtraction;
43
+ }
44
+ interface Whitelist {
45
+ identifier: string;
46
+ name: string;
47
+ justification?: string | null;
48
+ }
49
+ interface Observable {
50
+ key: string;
51
+ /**
52
+ * Observable type (e.g., ipv4-addr, url). Custom values are allowed.
53
+ */
54
+ type: string;
55
+ value: string;
56
+ internal: boolean;
57
+ whitelisted: boolean;
58
+ comment: string;
59
+ extra: {
60
+ [k: string]: unknown;
61
+ } | null;
62
+ score: number;
63
+ level: Level;
64
+ relationships: Relationship[];
65
+ threat_intels: string[];
66
+ generated_by_checks: string[];
67
+ }
68
+ interface Relationship {
69
+ target_key: string;
70
+ /**
71
+ * Relationship label; defaults to related-to.
72
+ */
73
+ relationship_type: string;
74
+ direction: RelationshipDirection;
75
+ }
76
+ interface Check {
77
+ key: string;
78
+ check_id: string;
79
+ scope: string;
80
+ description: string;
81
+ comment: string;
82
+ extra: {
83
+ [k: string]: unknown;
84
+ } | null;
85
+ score: number;
86
+ level: Level;
87
+ score_policy: ScorePolicy;
88
+ observables: string[];
89
+ }
90
+ interface ThreatIntel {
91
+ key: string;
92
+ source: string;
93
+ observable_key: string;
94
+ comment: string;
95
+ extra: {
96
+ [k: string]: unknown;
97
+ } | null;
98
+ score: number;
99
+ level: Level;
100
+ taxonomies: {
101
+ [k: string]: unknown;
102
+ }[];
103
+ }
104
+ interface Enrichment {
105
+ key: string;
106
+ name: string;
107
+ data: {
108
+ [k: string]: unknown;
109
+ };
110
+ context: string;
111
+ }
112
+ interface Container {
113
+ key: string;
114
+ path: string;
115
+ description: string;
116
+ checks: string[];
117
+ sub_containers: {
118
+ [k: string]: Container;
119
+ };
120
+ aggregated_score: number;
121
+ aggregated_level: Level;
122
+ }
123
+ interface Statistics {
124
+ total_observables: number;
125
+ internal_observables: number;
126
+ external_observables: number;
127
+ whitelisted_observables: number;
128
+ observables_by_type: {
129
+ [k: string]: number;
130
+ };
131
+ observables_by_level: {
132
+ [k: string]: number;
133
+ };
134
+ observables_by_type_and_level: {
135
+ [k: string]: {
136
+ [k: string]: number;
137
+ };
138
+ };
139
+ total_checks: number;
140
+ applied_checks: number;
141
+ checks_by_scope: {
142
+ [k: string]: number;
143
+ };
144
+ checks_by_level: {
145
+ [k: string]: number;
146
+ };
147
+ total_threat_intel: number;
148
+ threat_intel_by_source: {
149
+ [k: string]: number;
150
+ };
151
+ threat_intel_by_level: {
152
+ [k: string]: number;
153
+ };
154
+ total_containers: number;
155
+ }
156
+ interface StatsChecks {
157
+ checks: number;
158
+ applied: number;
159
+ }
160
+ interface DataExtraction {
161
+ /**
162
+ * Root observable type used during data extraction.
163
+ */
164
+ root_type: string | null;
165
+ score_mode: ScoreMode;
166
+ }
167
+
168
+ declare function parseCyvest(json: unknown): CyvestInvestigation;
169
+ declare function isCyvest(json: unknown): json is CyvestInvestigation;
170
+
171
+ /**
172
+ * Key generation utilities for Cyvest objects.
173
+ *
174
+ * Provides deterministic, unique key generation for all object types.
175
+ * Keys are used for object identification, retrieval, and merging.
176
+ */
177
+ /**
178
+ * Key type prefixes used in Cyvest.
179
+ */
180
+ type KeyType = "obs" | "chk" | "ti" | "enr" | "ctr";
181
+ /**
182
+ * Generate a unique key for an observable.
183
+ *
184
+ * Format: obs:{type}:{normalized_value}
185
+ *
186
+ * @param obsType - Type of observable (ip, url, domain, hash, etc.)
187
+ * @param value - Value of the observable
188
+ * @returns Unique observable key
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * generateObservableKey("ipv4-addr", "192.168.1.1")
193
+ * // => "obs:ipv4-addr:192.168.1.1"
194
+ * ```
195
+ */
196
+ declare function generateObservableKey(obsType: string, value: string): string;
197
+ /**
198
+ * Generate a unique key for a check.
199
+ *
200
+ * Format: chk:{check_id}:{scope}
201
+ *
202
+ * @param checkId - Identifier of the check
203
+ * @param scope - Scope of the check
204
+ * @returns Unique check key
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * generateCheckKey("sender_verification", "email_headers")
209
+ * // => "chk:sender_verification:email_headers"
210
+ * ```
211
+ */
212
+ declare function generateCheckKey(checkId: string, scope: string): string;
213
+ /**
214
+ * Generate a unique key for threat intelligence.
215
+ *
216
+ * Format: ti:{normalized_source}:{observable_key}
217
+ *
218
+ * @param source - Name of the threat intel source
219
+ * @param observableKey - Key of the related observable
220
+ * @returns Unique threat intel key
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * generateThreatIntelKey("virustotal", "obs:ipv4-addr:192.168.1.1")
225
+ * // => "ti:virustotal:obs:ipv4-addr:192.168.1.1"
226
+ * ```
227
+ */
228
+ declare function generateThreatIntelKey(source: string, observableKey: string): string;
229
+ /**
230
+ * Generate a unique key for an enrichment.
231
+ *
232
+ * Format: enr:{name} or enr:{name}:{context_hash}
233
+ *
234
+ * @param name - Name of the enrichment
235
+ * @param context - Optional context string for disambiguation
236
+ * @returns Unique enrichment key
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * generateEnrichmentKey("whois_data")
241
+ * // => "enr:whois_data"
242
+ *
243
+ * generateEnrichmentKey("whois_data", "domain:example.com")
244
+ * // => "enr:whois_data:a1b2c3d4"
245
+ * ```
246
+ */
247
+ declare function generateEnrichmentKey(name: string, context?: string): string;
248
+ /**
249
+ * Generate a unique key for a container.
250
+ *
251
+ * Format: ctr:{normalized_path}
252
+ *
253
+ * @param path - Path of the container (can use / or . as separator)
254
+ * @returns Unique container key
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * generateContainerKey("email/headers")
259
+ * // => "ctr:email/headers"
260
+ * ```
261
+ */
262
+ declare function generateContainerKey(path: string): string;
263
+ /**
264
+ * Extract the type prefix from a key.
265
+ *
266
+ * @param key - The key to parse
267
+ * @returns Type prefix (obs, chk, ti, enr, ctr) or null if invalid
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * parseKeyType("obs:ipv4-addr:192.168.1.1") // => "obs"
272
+ * parseKeyType("invalid") // => null
273
+ * ```
274
+ */
275
+ declare function parseKeyType(key: string): KeyType | null;
276
+ /**
277
+ * Validate a key format and optionally check its type.
278
+ *
279
+ * @param key - The key to validate
280
+ * @param expectedType - Optional expected type prefix
281
+ * @returns True if valid, false otherwise
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * validateKey("obs:ipv4-addr:192.168.1.1") // => true
286
+ * validateKey("obs:ipv4-addr:192.168.1.1", "obs") // => true
287
+ * validateKey("obs:ipv4-addr:192.168.1.1", "chk") // => false
288
+ * validateKey("invalid") // => false
289
+ * ```
290
+ */
291
+ declare function validateKey(key: string, expectedType?: KeyType): boolean;
292
+ /**
293
+ * Extract components from an observable key.
294
+ *
295
+ * @param key - Observable key to parse
296
+ * @returns Object with type and value, or null if invalid
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * parseObservableKey("obs:ipv4-addr:192.168.1.1")
301
+ * // => { type: "ipv4-addr", value: "192.168.1.1" }
302
+ * ```
303
+ */
304
+ declare function parseObservableKey(key: string): {
305
+ type: string;
306
+ value: string;
307
+ } | null;
308
+ /**
309
+ * Extract components from a check key.
310
+ *
311
+ * @param key - Check key to parse
312
+ * @returns Object with checkId and scope, or null if invalid
313
+ *
314
+ * @example
315
+ * ```ts
316
+ * parseCheckKey("chk:sender_verification:email_headers")
317
+ * // => { checkId: "sender_verification", scope: "email_headers" }
318
+ * ```
319
+ */
320
+ declare function parseCheckKey(key: string): {
321
+ checkId: string;
322
+ scope: string;
323
+ } | null;
324
+ /**
325
+ * Extract components from a threat intel key.
326
+ *
327
+ * @param key - Threat intel key to parse
328
+ * @returns Object with source and observableKey, or null if invalid
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * parseThreatIntelKey("ti:virustotal:obs:ipv4-addr:192.168.1.1")
333
+ * // => { source: "virustotal", observableKey: "obs:ipv4-addr:192.168.1.1" }
334
+ * ```
335
+ */
336
+ declare function parseThreatIntelKey(key: string): {
337
+ source: string;
338
+ observableKey: string;
339
+ } | null;
340
+
341
+ /**
342
+ * Level enumeration and scoring logic for Cyvest.
343
+ *
344
+ * This module defines the security level classification system and the algorithm
345
+ * for determining levels from scores.
346
+ */
347
+
348
+ /**
349
+ * Ordered array of levels from lowest to highest severity.
350
+ */
351
+ declare const LEVEL_ORDER: readonly Level[];
352
+ /**
353
+ * Numeric values for each level (for comparison purposes).
354
+ */
355
+ declare const LEVEL_VALUES: Record<Level, number>;
356
+ /**
357
+ * Color mapping for display purposes.
358
+ */
359
+ declare const LEVEL_COLORS: Record<Level, string>;
360
+ /**
361
+ * Normalize a level input to the Level type.
362
+ *
363
+ * Accepts a case-insensitive string and returns the normalized Level.
364
+ *
365
+ * @param level - Level string (e.g., "malicious", "MALICIOUS")
366
+ * @returns The normalized Level
367
+ * @throws Error if the string does not match a valid Level
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * normalizeLevel("malicious") // => "MALICIOUS"
372
+ * normalizeLevel("TRUSTED") // => "TRUSTED"
373
+ * ```
374
+ */
375
+ declare function normalizeLevel(level: string): Level;
376
+ /**
377
+ * Check if a string is a valid Level.
378
+ *
379
+ * @param level - String to check
380
+ * @returns True if valid Level
381
+ */
382
+ declare function isValidLevel(level: string): level is Level;
383
+ /**
384
+ * Calculate the security level from a numeric score.
385
+ *
386
+ * Algorithm:
387
+ * - score < 0.0 -> TRUSTED
388
+ * - score === 0.0 -> INFO
389
+ * - score < 3.0 -> NOTABLE
390
+ * - score < 5.0 -> SUSPICIOUS
391
+ * - score >= 5.0 -> MALICIOUS
392
+ *
393
+ * @param score - The numeric score to evaluate
394
+ * @returns The appropriate Level based on the score
395
+ *
396
+ * @example
397
+ * ```ts
398
+ * getLevelFromScore(-1) // => "TRUSTED"
399
+ * getLevelFromScore(0) // => "INFO"
400
+ * getLevelFromScore(2.5) // => "NOTABLE"
401
+ * getLevelFromScore(4) // => "SUSPICIOUS"
402
+ * getLevelFromScore(5) // => "MALICIOUS"
403
+ * ```
404
+ */
405
+ declare function getLevelFromScore(score: number): Level;
406
+ /**
407
+ * Compare two levels.
408
+ *
409
+ * @param a - First level
410
+ * @param b - Second level
411
+ * @returns -1 if a < b, 0 if a === b, 1 if a > b
412
+ *
413
+ * @example
414
+ * ```ts
415
+ * compareLevels("INFO", "MALICIOUS") // => -1
416
+ * compareLevels("MALICIOUS", "INFO") // => 1
417
+ * compareLevels("INFO", "INFO") // => 0
418
+ * ```
419
+ */
420
+ declare function compareLevels(a: Level, b: Level): -1 | 0 | 1;
421
+ /**
422
+ * Check if level a is higher (more severe) than level b.
423
+ *
424
+ * @param a - First level
425
+ * @param b - Second level
426
+ * @returns True if a is higher than b
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * isLevelHigherThan("MALICIOUS", "SUSPICIOUS") // => true
431
+ * isLevelHigherThan("INFO", "MALICIOUS") // => false
432
+ * ```
433
+ */
434
+ declare function isLevelHigherThan(a: Level, b: Level): boolean;
435
+ /**
436
+ * Check if level a is lower (less severe) than level b.
437
+ *
438
+ * @param a - First level
439
+ * @param b - Second level
440
+ * @returns True if a is lower than b
441
+ */
442
+ declare function isLevelLowerThan(a: Level, b: Level): boolean;
443
+ /**
444
+ * Check if level a is at least as severe as level b.
445
+ *
446
+ * @param a - Level to check
447
+ * @param minLevel - Minimum required level
448
+ * @returns True if a is at least minLevel
449
+ *
450
+ * @example
451
+ * ```ts
452
+ * isLevelAtLeast("MALICIOUS", "SUSPICIOUS") // => true
453
+ * isLevelAtLeast("SUSPICIOUS", "SUSPICIOUS") // => true
454
+ * isLevelAtLeast("INFO", "SUSPICIOUS") // => false
455
+ * ```
456
+ */
457
+ declare function isLevelAtLeast(a: Level, minLevel: Level): boolean;
458
+ /**
459
+ * Get the maximum (most severe) level from an array of levels.
460
+ *
461
+ * @param levels - Array of levels
462
+ * @returns The most severe level, or "NONE" if array is empty
463
+ */
464
+ declare function maxLevel(levels: Level[]): Level;
465
+ /**
466
+ * Get the minimum (least severe) level from an array of levels.
467
+ *
468
+ * @param levels - Array of levels
469
+ * @returns The least severe level, or "MALICIOUS" if array is empty
470
+ */
471
+ declare function minLevel(levels: Level[]): Level;
472
+ /**
473
+ * Get the color associated with a level for display purposes.
474
+ *
475
+ * @param level - Level to get color for
476
+ * @returns Hex color string
477
+ */
478
+ declare function getColorForLevel(level: Level): string;
479
+ /**
480
+ * Get the color associated with a score for display purposes.
481
+ *
482
+ * @param score - Score to get color for
483
+ * @returns Hex color string
484
+ */
485
+ declare function getColorForScore(score: number): string;
486
+ /**
487
+ * Type guard to check if an object has a level property.
488
+ */
489
+ declare function hasLevel(obj: unknown): obj is {
490
+ level: Level;
491
+ };
492
+ /**
493
+ * Extract level from an entity (Observable, Check, ThreatIntel, Container).
494
+ */
495
+ declare function getEntityLevel(entity: Observable | Check | ThreatIntel | Container): Level;
496
+
497
+ /**
498
+ * Get an observable by its key.
499
+ *
500
+ * @param inv - The investigation to search
501
+ * @param key - Observable key (e.g., "obs:ipv4-addr:192.168.1.1")
502
+ * @returns The observable or undefined if not found
503
+ *
504
+ * @example
505
+ * ```ts
506
+ * const obs = getObservable(investigation, "obs:ipv4-addr:192.168.1.1");
507
+ * if (obs) {
508
+ * console.log(obs.value, obs.level);
509
+ * }
510
+ * ```
511
+ */
512
+ declare function getObservable(inv: CyvestInvestigation, key: string): Observable | undefined;
513
+ /**
514
+ * Get an observable by type and value.
515
+ *
516
+ * @param inv - The investigation to search
517
+ * @param type - Observable type (e.g., "ipv4-addr", "url")
518
+ * @param value - Observable value
519
+ * @returns The observable or undefined if not found
520
+ *
521
+ * @example
522
+ * ```ts
523
+ * const obs = getObservableByTypeValue(investigation, "ipv4-addr", "192.168.1.1");
524
+ * ```
525
+ */
526
+ declare function getObservableByTypeValue(inv: CyvestInvestigation, type: string, value: string): Observable | undefined;
527
+ /**
528
+ * Get a check by its key.
529
+ *
530
+ * @param inv - The investigation to search
531
+ * @param key - Check key (e.g., "chk:sender_verification:email_headers")
532
+ * @returns The check or undefined if not found
533
+ *
534
+ * @example
535
+ * ```ts
536
+ * const check = getCheck(investigation, "chk:sender_verification:email_headers");
537
+ * ```
538
+ */
539
+ declare function getCheck(inv: CyvestInvestigation, key: string): Check | undefined;
540
+ /**
541
+ * Get a check by its ID and scope.
542
+ *
543
+ * @param inv - The investigation to search
544
+ * @param checkId - Check identifier
545
+ * @param scope - Check scope
546
+ * @returns The check or undefined if not found
547
+ *
548
+ * @example
549
+ * ```ts
550
+ * const check = getCheckByIdScope(investigation, "sender_verification", "email_headers");
551
+ * ```
552
+ */
553
+ declare function getCheckByIdScope(inv: CyvestInvestigation, checkId: string, scope: string): Check | undefined;
554
+ /**
555
+ * Get all checks as a flat array (not grouped by scope).
556
+ *
557
+ * @param inv - The investigation
558
+ * @returns Array of all checks
559
+ *
560
+ * @example
561
+ * ```ts
562
+ * const allChecks = getAllChecks(investigation);
563
+ * console.log(`Total checks: ${allChecks.length}`);
564
+ * ```
565
+ */
566
+ declare function getAllChecks(inv: CyvestInvestigation): Check[];
567
+ /**
568
+ * Get a threat intel entry by its key.
569
+ *
570
+ * @param inv - The investigation to search
571
+ * @param key - Threat intel key (e.g., "ti:virustotal:obs:ipv4-addr:192.168.1.1")
572
+ * @returns The threat intel or undefined if not found
573
+ */
574
+ declare function getThreatIntel(inv: CyvestInvestigation, key: string): ThreatIntel | undefined;
575
+ /**
576
+ * Get a threat intel entry by source and observable key.
577
+ *
578
+ * @param inv - The investigation to search
579
+ * @param source - Threat intel source name
580
+ * @param observableKey - Key of the related observable
581
+ * @returns The threat intel or undefined if not found
582
+ */
583
+ declare function getThreatIntelBySourceObservable(inv: CyvestInvestigation, source: string, observableKey: string): ThreatIntel | undefined;
584
+ /**
585
+ * Get all threat intel entries as an array.
586
+ *
587
+ * @param inv - The investigation
588
+ * @returns Array of all threat intel entries
589
+ */
590
+ declare function getAllThreatIntels(inv: CyvestInvestigation): ThreatIntel[];
591
+ /**
592
+ * Get an enrichment by its key.
593
+ *
594
+ * @param inv - The investigation to search
595
+ * @param key - Enrichment key (e.g., "enr:whois_data")
596
+ * @returns The enrichment or undefined if not found
597
+ */
598
+ declare function getEnrichment(inv: CyvestInvestigation, key: string): Enrichment | undefined;
599
+ /**
600
+ * Get an enrichment by name.
601
+ *
602
+ * @param inv - The investigation to search
603
+ * @param name - Enrichment name
604
+ * @returns The first matching enrichment or undefined if not found
605
+ */
606
+ declare function getEnrichmentByName(inv: CyvestInvestigation, name: string): Enrichment | undefined;
607
+ /**
608
+ * Get all enrichments as an array.
609
+ *
610
+ * @param inv - The investigation
611
+ * @returns Array of all enrichments
612
+ */
613
+ declare function getAllEnrichments(inv: CyvestInvestigation): Enrichment[];
614
+ /**
615
+ * Get a container by its key.
616
+ *
617
+ * @param inv - The investigation to search
618
+ * @param key - Container key (e.g., "ctr:email/headers")
619
+ * @returns The container or undefined if not found
620
+ */
621
+ declare function getContainer(inv: CyvestInvestigation, key: string): Container | undefined;
622
+ /**
623
+ * Get a container by its path.
624
+ *
625
+ * @param inv - The investigation to search
626
+ * @param path - Container path
627
+ * @returns The container or undefined if not found
628
+ */
629
+ declare function getContainerByPath(inv: CyvestInvestigation, path: string): Container | undefined;
630
+ /**
631
+ * Get all containers as a flat array (including sub-containers).
632
+ *
633
+ * @param inv - The investigation
634
+ * @returns Array of all containers
635
+ */
636
+ declare function getAllContainers(inv: CyvestInvestigation): Container[];
637
+ /**
638
+ * Get all observables as an array.
639
+ *
640
+ * @param inv - The investigation
641
+ * @returns Array of all observables
642
+ */
643
+ declare function getAllObservables(inv: CyvestInvestigation): Observable[];
644
+ /**
645
+ * Get all whitelists from the investigation.
646
+ *
647
+ * @param inv - The investigation
648
+ * @returns Array of all whitelists
649
+ */
650
+ declare function getWhitelists(inv: CyvestInvestigation): Whitelist[];
651
+ /**
652
+ * Get the investigation statistics.
653
+ *
654
+ * @param inv - The investigation
655
+ * @returns Statistics object
656
+ */
657
+ declare function getStats(inv: CyvestInvestigation): Statistics;
658
+ /**
659
+ * Get the investigation check statistics.
660
+ *
661
+ * @param inv - The investigation
662
+ * @returns Check statistics object
663
+ */
664
+ declare function getStatsChecks(inv: CyvestInvestigation): StatsChecks;
665
+ /**
666
+ * Get the data extraction configuration.
667
+ *
668
+ * @param inv - The investigation
669
+ * @returns Data extraction config
670
+ */
671
+ declare function getDataExtraction(inv: CyvestInvestigation): DataExtraction;
672
+ /**
673
+ * Count entities in the investigation.
674
+ */
675
+ interface InvestigationCounts {
676
+ observables: number;
677
+ checks: number;
678
+ threatIntels: number;
679
+ enrichments: number;
680
+ containers: number;
681
+ whitelists: number;
682
+ }
683
+ /**
684
+ * Get counts of all entities in the investigation.
685
+ *
686
+ * @param inv - The investigation
687
+ * @returns Object with counts for each entity type
688
+ */
689
+ declare function getCounts(inv: CyvestInvestigation): InvestigationCounts;
690
+
691
+ /**
692
+ * Finder utilities for querying and filtering Cyvest Investigation data.
693
+ *
694
+ * These functions provide filtering, searching, and cross-referencing
695
+ * capabilities for observables, checks, and threat intel.
696
+ */
697
+
698
+ /**
699
+ * Find all observables of a specific type.
700
+ *
701
+ * @param inv - The investigation to search
702
+ * @param type - Observable type (e.g., "ipv4-addr", "url", "domain-name")
703
+ * @returns Array of matching observables
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * const ips = findObservablesByType(investigation, "ipv4-addr");
708
+ * const urls = findObservablesByType(investigation, "url");
709
+ * ```
710
+ */
711
+ declare function findObservablesByType(inv: CyvestInvestigation, type: string): Observable[];
712
+ /**
713
+ * Find all observables at a specific level.
714
+ *
715
+ * @param inv - The investigation to search
716
+ * @param level - Security level to filter by
717
+ * @returns Array of matching observables
718
+ *
719
+ * @example
720
+ * ```ts
721
+ * const malicious = findObservablesByLevel(investigation, "MALICIOUS");
722
+ * ```
723
+ */
724
+ declare function findObservablesByLevel(inv: CyvestInvestigation, level: Level): Observable[];
725
+ /**
726
+ * Find all observables at or above a minimum level.
727
+ *
728
+ * @param inv - The investigation to search
729
+ * @param minLevel - Minimum security level
730
+ * @returns Array of matching observables
731
+ *
732
+ * @example
733
+ * ```ts
734
+ * const suspicious = findObservablesAtLeast(investigation, "SUSPICIOUS");
735
+ * // Returns SUSPICIOUS and MALICIOUS observables
736
+ * ```
737
+ */
738
+ declare function findObservablesAtLeast(inv: CyvestInvestigation, minLevel: Level): Observable[];
739
+ /**
740
+ * Find observables by exact value match.
741
+ *
742
+ * @param inv - The investigation to search
743
+ * @param value - Value to search for
744
+ * @param caseSensitive - Whether to perform case-sensitive match (default: false)
745
+ * @returns Array of matching observables
746
+ */
747
+ declare function findObservablesByValue(inv: CyvestInvestigation, value: string, caseSensitive?: boolean): Observable[];
748
+ /**
749
+ * Find observables containing a substring in their value.
750
+ *
751
+ * @param inv - The investigation to search
752
+ * @param substring - Substring to search for
753
+ * @param caseSensitive - Whether to perform case-sensitive match (default: false)
754
+ * @returns Array of matching observables
755
+ */
756
+ declare function findObservablesContaining(inv: CyvestInvestigation, substring: string, caseSensitive?: boolean): Observable[];
757
+ /**
758
+ * Find observables matching a regular expression.
759
+ *
760
+ * @param inv - The investigation to search
761
+ * @param pattern - Regular expression pattern
762
+ * @returns Array of matching observables
763
+ */
764
+ declare function findObservablesMatching(inv: CyvestInvestigation, pattern: RegExp): Observable[];
765
+ /**
766
+ * Find internal observables.
767
+ *
768
+ * @param inv - The investigation to search
769
+ * @returns Array of internal observables
770
+ */
771
+ declare function findInternalObservables(inv: CyvestInvestigation): Observable[];
772
+ /**
773
+ * Find external (non-internal) observables.
774
+ *
775
+ * @param inv - The investigation to search
776
+ * @returns Array of external observables
777
+ */
778
+ declare function findExternalObservables(inv: CyvestInvestigation): Observable[];
779
+ /**
780
+ * Find whitelisted observables.
781
+ *
782
+ * @param inv - The investigation to search
783
+ * @returns Array of whitelisted observables
784
+ */
785
+ declare function findWhitelistedObservables(inv: CyvestInvestigation): Observable[];
786
+ /**
787
+ * Find observables with threat intelligence data.
788
+ *
789
+ * @param inv - The investigation to search
790
+ * @returns Array of observables that have associated threat intel
791
+ */
792
+ declare function findObservablesWithThreatIntel(inv: CyvestInvestigation): Observable[];
793
+ /**
794
+ * Find all checks in a specific scope.
795
+ *
796
+ * @param inv - The investigation to search
797
+ * @param scope - Check scope
798
+ * @returns Array of checks in the scope
799
+ *
800
+ * @example
801
+ * ```ts
802
+ * const emailChecks = findChecksByScope(investigation, "email_headers");
803
+ * ```
804
+ */
805
+ declare function findChecksByScope(inv: CyvestInvestigation, scope: string): Check[];
806
+ /**
807
+ * Find all checks at a specific level.
808
+ *
809
+ * @param inv - The investigation to search
810
+ * @param level - Security level to filter by
811
+ * @returns Array of matching checks
812
+ */
813
+ declare function findChecksByLevel(inv: CyvestInvestigation, level: Level): Check[];
814
+ /**
815
+ * Find all checks at or above a minimum level.
816
+ *
817
+ * @param inv - The investigation to search
818
+ * @param minLevel - Minimum security level
819
+ * @returns Array of matching checks
820
+ */
821
+ declare function findChecksAtLeast(inv: CyvestInvestigation, minLevel: Level): Check[];
822
+ /**
823
+ * Find checks by check ID (across all scopes).
824
+ *
825
+ * @param inv - The investigation to search
826
+ * @param checkId - Check identifier to search for
827
+ * @returns Array of matching checks
828
+ */
829
+ declare function findChecksByCheckId(inv: CyvestInvestigation, checkId: string): Check[];
830
+ /**
831
+ * Find checks with score policy set to manual.
832
+ *
833
+ * @param inv - The investigation to search
834
+ * @returns Array of manually scored checks
835
+ */
836
+ declare function findManuallyScored(inv: CyvestInvestigation): Check[];
837
+ /**
838
+ * Find all threat intel from a specific source.
839
+ *
840
+ * @param inv - The investigation to search
841
+ * @param source - Source name (e.g., "virustotal", "otx")
842
+ * @returns Array of threat intel from the source
843
+ */
844
+ declare function findThreatIntelBySource(inv: CyvestInvestigation, source: string): ThreatIntel[];
845
+ /**
846
+ * Find all threat intel at a specific level.
847
+ *
848
+ * @param inv - The investigation to search
849
+ * @param level - Security level to filter by
850
+ * @returns Array of matching threat intel
851
+ */
852
+ declare function findThreatIntelByLevel(inv: CyvestInvestigation, level: Level): ThreatIntel[];
853
+ /**
854
+ * Find all threat intel at or above a minimum level.
855
+ *
856
+ * @param inv - The investigation to search
857
+ * @param minLevel - Minimum security level
858
+ * @returns Array of matching threat intel
859
+ */
860
+ declare function findThreatIntelAtLeast(inv: CyvestInvestigation, minLevel: Level): ThreatIntel[];
861
+ /**
862
+ * Find containers at a specific aggregated level.
863
+ *
864
+ * @param inv - The investigation to search
865
+ * @param level - Aggregated level to filter by
866
+ * @returns Array of matching containers
867
+ */
868
+ declare function findContainersByLevel(inv: CyvestInvestigation, level: Level): Container[];
869
+ /**
870
+ * Find containers at or above a minimum aggregated level.
871
+ *
872
+ * @param inv - The investigation to search
873
+ * @param minLevel - Minimum aggregated level
874
+ * @returns Array of matching containers
875
+ */
876
+ declare function findContainersAtLeast(inv: CyvestInvestigation, minLevel: Level): Container[];
877
+ /**
878
+ * Get all checks that generated or reference a specific observable.
879
+ *
880
+ * @param inv - The investigation to search
881
+ * @param observableKey - Key of the observable
882
+ * @returns Array of checks that reference this observable
883
+ *
884
+ * @example
885
+ * ```ts
886
+ * const checks = getChecksForObservable(investigation, "obs:ipv4-addr:192.168.1.1");
887
+ * ```
888
+ */
889
+ declare function getChecksForObservable(inv: CyvestInvestigation, observableKey: string): Check[];
890
+ /**
891
+ * Get all threat intel entries for a specific observable.
892
+ *
893
+ * @param inv - The investigation to search
894
+ * @param observableKey - Key of the observable
895
+ * @returns Array of threat intel for this observable
896
+ */
897
+ declare function getThreatIntelsForObservable(inv: CyvestInvestigation, observableKey: string): ThreatIntel[];
898
+ /**
899
+ * Get all observables referenced by a specific check.
900
+ *
901
+ * @param inv - The investigation to search
902
+ * @param checkKey - Key of the check
903
+ * @returns Array of observables referenced by this check
904
+ */
905
+ declare function getObservablesForCheck(inv: CyvestInvestigation, checkKey: string): Observable[];
906
+ /**
907
+ * Get all checks for a specific container.
908
+ *
909
+ * @param inv - The investigation to search
910
+ * @param containerKey - Key of the container
911
+ * @param recursive - Include checks from sub-containers (default: false)
912
+ * @returns Array of checks in the container
913
+ */
914
+ declare function getChecksForContainer(inv: CyvestInvestigation, containerKey: string, recursive?: boolean): Check[];
915
+ /**
916
+ * Sort observables by score (descending - highest first).
917
+ *
918
+ * @param observables - Array of observables to sort
919
+ * @returns Sorted array (new array, doesn't mutate input)
920
+ */
921
+ declare function sortObservablesByScore(observables: Observable[]): Observable[];
922
+ /**
923
+ * Sort checks by score (descending - highest first).
924
+ *
925
+ * @param checks - Array of checks to sort
926
+ * @returns Sorted array (new array, doesn't mutate input)
927
+ */
928
+ declare function sortChecksByScore(checks: Check[]): Check[];
929
+ /**
930
+ * Sort observables by level (descending - most severe first).
931
+ *
932
+ * @param observables - Array of observables to sort
933
+ * @returns Sorted array (new array, doesn't mutate input)
934
+ */
935
+ declare function sortObservablesByLevel(observables: Observable[]): Observable[];
936
+ /**
937
+ * Sort checks by level (descending - most severe first).
938
+ *
939
+ * @param checks - Array of checks to sort
940
+ * @returns Sorted array (new array, doesn't mutate input)
941
+ */
942
+ declare function sortChecksByLevel(checks: Check[]): Check[];
943
+ /**
944
+ * Get the highest scoring observables.
945
+ *
946
+ * @param inv - The investigation to search
947
+ * @param n - Number of results to return (default: 10)
948
+ * @returns Array of highest scoring observables
949
+ */
950
+ declare function getHighestScoringObservables(inv: CyvestInvestigation, n?: number): Observable[];
951
+ /**
952
+ * Get the highest scoring checks.
953
+ *
954
+ * @param inv - The investigation to search
955
+ * @param n - Number of results to return (default: 10)
956
+ * @returns Array of highest scoring checks
957
+ */
958
+ declare function getHighestScoringChecks(inv: CyvestInvestigation, n?: number): Check[];
959
+ /**
960
+ * Get all malicious observables (convenience function).
961
+ *
962
+ * @param inv - The investigation to search
963
+ * @returns Array of malicious observables
964
+ */
965
+ declare function getMaliciousObservables(inv: CyvestInvestigation): Observable[];
966
+ /**
967
+ * Get all suspicious observables (convenience function).
968
+ *
969
+ * @param inv - The investigation to search
970
+ * @returns Array of suspicious observables
971
+ */
972
+ declare function getSuspiciousObservables(inv: CyvestInvestigation): Observable[];
973
+ /**
974
+ * Get all malicious checks (convenience function).
975
+ *
976
+ * @param inv - The investigation to search
977
+ * @returns Array of malicious checks
978
+ */
979
+ declare function getMaliciousChecks(inv: CyvestInvestigation): Check[];
980
+ /**
981
+ * Get all suspicious checks (convenience function).
982
+ *
983
+ * @param inv - The investigation to search
984
+ * @returns Array of suspicious checks
985
+ */
986
+ declare function getSuspiciousChecks(inv: CyvestInvestigation): Check[];
987
+ /**
988
+ * Get all scopes that have checks.
989
+ *
990
+ * @param inv - The investigation
991
+ * @returns Array of scope names
992
+ */
993
+ declare function getAllScopes(inv: CyvestInvestigation): string[];
994
+ /**
995
+ * Get all observable types present in the investigation.
996
+ *
997
+ * @param inv - The investigation
998
+ * @returns Array of unique observable types
999
+ */
1000
+ declare function getAllObservableTypes(inv: CyvestInvestigation): string[];
1001
+ /**
1002
+ * Get all threat intel sources present in the investigation.
1003
+ *
1004
+ * @param inv - The investigation
1005
+ * @returns Array of unique source names
1006
+ */
1007
+ declare function getAllThreatIntelSources(inv: CyvestInvestigation): string[];
1008
+
1009
+ /**
1010
+ * Graph and relationship traversal utilities for Cyvest Investigation.
1011
+ *
1012
+ * These functions provide graph-like traversal of observable relationships,
1013
+ * useful for understanding connections and preparing data for visualization.
1014
+ */
1015
+
1016
+ /**
1017
+ * Edge representation for graph operations.
1018
+ */
1019
+ interface GraphEdge {
1020
+ /** Source observable key */
1021
+ source: string;
1022
+ /** Target observable key */
1023
+ target: string;
1024
+ /** Relationship type label */
1025
+ type: string;
1026
+ /** Relationship direction */
1027
+ direction: RelationshipDirection;
1028
+ }
1029
+ /**
1030
+ * Graph node representation.
1031
+ */
1032
+ interface GraphNode {
1033
+ /** Observable key (unique identifier) */
1034
+ id: string;
1035
+ /** Observable type */
1036
+ type: string;
1037
+ /** Observable value */
1038
+ value: string;
1039
+ /** Security level */
1040
+ level: Level;
1041
+ /** Numeric score */
1042
+ score: number;
1043
+ /** Whether internal */
1044
+ internal: boolean;
1045
+ /** Whether whitelisted */
1046
+ whitelisted: boolean;
1047
+ }
1048
+ /**
1049
+ * Full graph representation of an investigation.
1050
+ */
1051
+ interface InvestigationGraph {
1052
+ /** All nodes (observables) */
1053
+ nodes: GraphNode[];
1054
+ /** All edges (relationships) */
1055
+ edges: GraphEdge[];
1056
+ }
1057
+ /**
1058
+ * Get all related observables for a given observable.
1059
+ *
1060
+ * Returns observables that are directly connected via any relationship,
1061
+ * regardless of direction.
1062
+ *
1063
+ * @param inv - The investigation to search
1064
+ * @param observableKey - Key of the source observable
1065
+ * @returns Array of related observables
1066
+ *
1067
+ * @example
1068
+ * ```ts
1069
+ * const related = getRelatedObservables(investigation, "obs:email-addr:test@example.com");
1070
+ * ```
1071
+ */
1072
+ declare function getRelatedObservables(inv: CyvestInvestigation, observableKey: string): Observable[];
1073
+ /**
1074
+ * Get observables related by outbound relationships (children).
1075
+ *
1076
+ * @param inv - The investigation to search
1077
+ * @param observableKey - Key of the source observable
1078
+ * @returns Array of child observables
1079
+ */
1080
+ declare function getObservableChildren(inv: CyvestInvestigation, observableKey: string): Observable[];
1081
+ /**
1082
+ * Get observables related by inbound relationships (parents).
1083
+ *
1084
+ * @param inv - The investigation to search
1085
+ * @param observableKey - Key of the target observable
1086
+ * @returns Array of parent observables
1087
+ */
1088
+ declare function getObservableParents(inv: CyvestInvestigation, observableKey: string): Observable[];
1089
+ /**
1090
+ * Get related observables filtered by relationship type.
1091
+ *
1092
+ * @param inv - The investigation to search
1093
+ * @param observableKey - Key of the source observable
1094
+ * @param relationshipType - Type of relationship to filter (e.g., "related-to", "uses")
1095
+ * @returns Array of related observables
1096
+ */
1097
+ declare function getRelatedObservablesByType(inv: CyvestInvestigation, observableKey: string, relationshipType: string): Observable[];
1098
+ /**
1099
+ * Get related observables filtered by direction.
1100
+ *
1101
+ * @param inv - The investigation to search
1102
+ * @param observableKey - Key of the source observable
1103
+ * @param direction - Direction to filter by
1104
+ * @returns Array of related observables
1105
+ */
1106
+ declare function getRelatedObservablesByDirection(inv: CyvestInvestigation, observableKey: string, direction: RelationshipDirection): Observable[];
1107
+ /**
1108
+ * Build a graph representation of all observables and their relationships.
1109
+ *
1110
+ * Useful for visualization libraries like vis.js, d3, or cytoscape.
1111
+ *
1112
+ * @param inv - The investigation
1113
+ * @returns Graph with nodes and edges
1114
+ *
1115
+ * @example
1116
+ * ```ts
1117
+ * const graph = getObservableGraph(investigation);
1118
+ * console.log(`Nodes: ${graph.nodes.length}, Edges: ${graph.edges.length}`);
1119
+ *
1120
+ * // Use with vis.js:
1121
+ * const network = new vis.Network(container, {
1122
+ * nodes: graph.nodes.map(n => ({ id: n.id, label: n.value })),
1123
+ * edges: graph.edges.map(e => ({ from: e.source, to: e.target, label: e.type }))
1124
+ * });
1125
+ * ```
1126
+ */
1127
+ declare function getObservableGraph(inv: CyvestInvestigation): InvestigationGraph;
1128
+ /**
1129
+ * Find the root observable(s) of the investigation.
1130
+ *
1131
+ * Root observables are those that have no incoming relationships
1132
+ * (nothing points to them as a target).
1133
+ *
1134
+ * @param inv - The investigation
1135
+ * @returns Array of root observables
1136
+ */
1137
+ declare function findRootObservables(inv: CyvestInvestigation): Observable[];
1138
+ /**
1139
+ * Find orphan observables (not connected to any other observable).
1140
+ *
1141
+ * @param inv - The investigation
1142
+ * @returns Array of orphan observables
1143
+ */
1144
+ declare function findOrphanObservables(inv: CyvestInvestigation): Observable[];
1145
+ /**
1146
+ * Find leaf observables (have incoming but no outgoing relationships).
1147
+ *
1148
+ * @param inv - The investigation
1149
+ * @returns Array of leaf observables
1150
+ */
1151
+ declare function findLeafObservables(inv: CyvestInvestigation): Observable[];
1152
+ /**
1153
+ * Check if two observables are connected (directly or transitively).
1154
+ *
1155
+ * @param inv - The investigation
1156
+ * @param sourceKey - Starting observable key
1157
+ * @param targetKey - Target observable key
1158
+ * @returns True if a path exists from source to target
1159
+ */
1160
+ declare function areConnected(inv: CyvestInvestigation, sourceKey: string, targetKey: string): boolean;
1161
+ /**
1162
+ * Find the shortest path between two observables.
1163
+ *
1164
+ * @param inv - The investigation
1165
+ * @param sourceKey - Starting observable key
1166
+ * @param targetKey - Target observable key
1167
+ * @returns Array of observable keys representing the path, or null if no path exists
1168
+ */
1169
+ declare function findPath(inv: CyvestInvestigation, sourceKey: string, targetKey: string): string[] | null;
1170
+ /**
1171
+ * Get all observables reachable from a starting point.
1172
+ *
1173
+ * @param inv - The investigation
1174
+ * @param startKey - Starting observable key
1175
+ * @param maxDepth - Maximum traversal depth (default: Infinity)
1176
+ * @returns Array of reachable observables
1177
+ */
1178
+ declare function getReachableObservables(inv: CyvestInvestigation, startKey: string, maxDepth?: number): Observable[];
1179
+ /**
1180
+ * Get all unique relationship types used in the investigation.
1181
+ *
1182
+ * @param inv - The investigation
1183
+ * @returns Array of unique relationship type strings
1184
+ */
1185
+ declare function getAllRelationshipTypes(inv: CyvestInvestigation): string[];
1186
+ /**
1187
+ * Count relationships by type.
1188
+ *
1189
+ * @param inv - The investigation
1190
+ * @returns Object mapping relationship type to count
1191
+ */
1192
+ declare function countRelationshipsByType(inv: CyvestInvestigation): Record<string, number>;
1193
+ /**
1194
+ * Get all relationships for an observable.
1195
+ *
1196
+ * @param inv - The investigation
1197
+ * @param observableKey - Observable key
1198
+ * @returns Object with outbound, inbound, and all relationships
1199
+ */
1200
+ declare function getRelationshipsForObservable(inv: CyvestInvestigation, observableKey: string): {
1201
+ outbound: Relationship[];
1202
+ inbound: Array<Relationship & {
1203
+ source_key: string;
1204
+ }>;
1205
+ all: Array<Relationship & {
1206
+ source_key?: string;
1207
+ }>;
1208
+ };
1209
+
1210
+ export { type Check, type Container, type CyvestInvestigation, type DataExtraction, type Enrichment, type GraphEdge, type GraphNode, type InvestigationCounts, type InvestigationGraph, type KeyType, LEVEL_COLORS, LEVEL_ORDER, LEVEL_VALUES, type Level, type Observable, type Relationship, type RelationshipDirection, type ScoreMode, type ScorePolicy, type Statistics, type StatsChecks, type ThreatIntel, type Whitelist, areConnected, compareLevels, countRelationshipsByType, findChecksAtLeast, findChecksByCheckId, findChecksByLevel, findChecksByScope, findContainersAtLeast, findContainersByLevel, findExternalObservables, findInternalObservables, findLeafObservables, findManuallyScored, findObservablesAtLeast, findObservablesByLevel, findObservablesByType, findObservablesByValue, findObservablesContaining, findObservablesMatching, findObservablesWithThreatIntel, findOrphanObservables, findPath, findRootObservables, findThreatIntelAtLeast, findThreatIntelByLevel, findThreatIntelBySource, findWhitelistedObservables, generateCheckKey, generateContainerKey, generateEnrichmentKey, generateObservableKey, generateThreatIntelKey, getAllChecks, getAllContainers, getAllEnrichments, getAllObservableTypes, getAllObservables, getAllRelationshipTypes, getAllScopes, getAllThreatIntelSources, getAllThreatIntels, getCheck, getCheckByIdScope, getChecksForContainer, getChecksForObservable, getColorForLevel, getColorForScore, getContainer, getContainerByPath, getCounts, getDataExtraction, getEnrichment, getEnrichmentByName, getEntityLevel, getHighestScoringChecks, getHighestScoringObservables, getLevelFromScore, getMaliciousChecks, getMaliciousObservables, getObservable, getObservableByTypeValue, getObservableChildren, getObservableGraph, getObservableParents, getObservablesForCheck, getReachableObservables, getRelatedObservables, getRelatedObservablesByDirection, getRelatedObservablesByType, getRelationshipsForObservable, getStats, getStatsChecks, getSuspiciousChecks, getSuspiciousObservables, getThreatIntel, getThreatIntelBySourceObservable, getThreatIntelsForObservable, getWhitelists, hasLevel, isCyvest, isLevelAtLeast, isLevelHigherThan, isLevelLowerThan, isValidLevel, maxLevel, minLevel, normalizeLevel, parseCheckKey, parseCyvest, parseKeyType, parseObservableKey, parseThreatIntelKey, sortChecksByLevel, sortChecksByScore, sortObservablesByLevel, sortObservablesByScore, validateKey };