@oneuptime/common 14.0.97 → 14.0.98

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.
Files changed (75) hide show
  1. package/Models/DatabaseModels/CodeRepository.d.mts +3 -0
  2. package/Models/DatabaseModels/CodeRepository.d.ts +3 -0
  3. package/Models/DatabaseModels/CodeRepository.js +104 -0
  4. package/Models/DatabaseModels/Index.js +2 -0
  5. package/Models/DatabaseModels/SecurityCaseEvidence.d.mts +4 -0
  6. package/Models/DatabaseModels/SecurityCaseEvidence.d.ts +4 -0
  7. package/Models/DatabaseModels/SecurityCaseEvidence.js +64 -5
  8. package/Models/DatabaseModels/SecurityHunt.d.mts +34 -0
  9. package/Models/DatabaseModels/SecurityHunt.d.ts +34 -0
  10. package/Models/DatabaseModels/SecurityHunt.js +608 -0
  11. package/Models/DatabaseModels/SecurityHunt.mjs +2 -0
  12. package/Types/AI/AIChatTypes.d.mts +1 -0
  13. package/Types/AI/AIChatTypes.d.ts +1 -0
  14. package/Types/AI/AIRunEventType.d.mts +1 -0
  15. package/Types/AI/AIRunEventType.d.ts +1 -0
  16. package/Types/AI/AIRunEventType.js +8 -0
  17. package/Types/AI/AiTokenCount.d.mts +22 -1
  18. package/Types/AI/AiTokenCount.d.ts +22 -1
  19. package/Types/AI/AiTokenCount.js +126 -57
  20. package/Types/AI/AiTokenCount.mjs +2 -0
  21. package/Types/AI/CodeFixTaskContext.d.mts +1 -0
  22. package/Types/AI/CodeFixTaskContext.d.ts +1 -0
  23. package/Types/CodeRepository/CodeRepositorySetting.d.mts +1 -0
  24. package/Types/CodeRepository/CodeRepositorySetting.d.ts +1 -0
  25. package/Types/CodeRepository/CodeRepositorySetting.js +2 -0
  26. package/Types/Email/EmailTemplateType.d.mts +1 -0
  27. package/Types/Email/EmailTemplateType.d.ts +1 -0
  28. package/Types/Email/EmailTemplateType.js +2 -0
  29. package/Types/Link.d.mts +1 -0
  30. package/Types/Link.d.ts +1 -0
  31. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.mts +1 -0
  32. package/Types/NotificationSetting/NotificationEmailRollupCategory.d.ts +1 -0
  33. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +9 -0
  34. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +1 -0
  35. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +1 -0
  36. package/Types/NotificationSetting/NotificationSettingEventType.js +6 -0
  37. package/Types/SecurityCase/SecurityCaseEventEvidence.d.mts +67 -0
  38. package/Types/SecurityCase/SecurityCaseEventEvidence.d.ts +67 -0
  39. package/Types/SecurityCase/SecurityCaseEventEvidence.js +271 -0
  40. package/Types/SecurityCase/SecurityCaseEventEvidence.mjs +13 -0
  41. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.mts +2 -1
  42. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.ts +2 -1
  43. package/Types/SecurityCase/SecurityCaseEvidenceKind.js +11 -1
  44. package/Types/SecurityEvent/SecurityHunt.d.mts +122 -0
  45. package/Types/SecurityEvent/SecurityHunt.d.ts +122 -0
  46. package/Types/SecurityEvent/SecurityHunt.js +391 -0
  47. package/Types/SecurityEvent/SecurityHunt.mjs +32 -0
  48. package/Types/Workflow/RunRecord.d.mts +3 -14
  49. package/Types/Workflow/RunRecord.d.ts +3 -14
  50. package/Types/Workflow/RunRecord.js +10 -51
  51. package/Utils/AI/InvestigationLogStall.d.mts +38 -0
  52. package/Utils/AI/InvestigationLogStall.d.ts +38 -0
  53. package/Utils/AI/InvestigationLogStall.js +163 -0
  54. package/Utils/AI/InvestigationLogStall.mjs +11 -0
  55. package/Utils/Project/RecordNumber.d.mts +43 -0
  56. package/Utils/Project/RecordNumber.d.ts +43 -0
  57. package/Utils/Project/RecordNumber.js +151 -0
  58. package/Utils/Project/RecordNumber.mjs +6 -0
  59. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +9 -0
  60. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +9 -0
  61. package/Utils/SecurityCase/SecurityCaseMarkdown.js +20 -0
  62. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +2 -0
  63. package/Utils/SecurityEvent/SecurityEventSearch.d.mts +56 -0
  64. package/Utils/SecurityEvent/SecurityEventSearch.d.ts +56 -0
  65. package/Utils/SecurityEvent/SecurityEventSearch.js +422 -0
  66. package/Utils/SecurityEvent/SecurityEventSearch.mjs +21 -0
  67. package/Utils/SecurityEvent/SecurityHuntSearch.d.mts +12 -0
  68. package/Utils/SecurityEvent/SecurityHuntSearch.d.ts +12 -0
  69. package/Utils/SecurityEvent/SecurityHuntSearch.js +51 -0
  70. package/Utils/SecurityEvent/SecurityHuntSearch.mjs +3 -0
  71. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.mts +9 -0
  72. package/Utils/Suggestions/TracePerformanceFixSuggestion.d.ts +9 -0
  73. package/Utils/Suggestions/TracePerformanceFixSuggestion.js +69 -1
  74. package/Utils/Suggestions/TracePerformanceFixSuggestion.mjs +4 -0
  75. package/package.json +1 -1
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SECURITY_EVENT_FACET_COLUMNS = exports.SECURITY_EVENT_SOURCE_FACET_KEY = exports.SECURITY_EVENT_EXCLUDE_FACET_PREFIX = exports.SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX = exports.EMPTY_SECURITY_EVENT_SEARCH_FILTERS = exports.SECURITY_EVENT_CONTAINS_FIELDS = exports.SECURITY_EVENT_NUMERIC_FIELDS = exports.SECURITY_EVENT_SEARCH_FIELD_KEYS = exports.SECURITY_EVENT_FIELD_ALIASES = void 0;
7
+ exports.parseSecurityEventSearch = parseSecurityEventSearch;
8
+ exports.applySecurityEventSearchToQuery = applySecurityEventSearchToQuery;
9
+ exports.hasSecurityEventSearch = hasSecurityEventSearch;
10
+ exports.isSecurityEventExcludeFacetKey = isSecurityEventExcludeFacetKey;
11
+ exports.toSecurityEventExcludeFacetKey = toSecurityEventExcludeFacetKey;
12
+ exports.getSecurityEventBaseFacetKey = getSecurityEventBaseFacetKey;
13
+ exports.isSecurityEventAttributeFacetKey = isSecurityEventAttributeFacetKey;
14
+ exports.getSecurityEventAttributeKey = getSecurityEventAttributeKey;
15
+ exports.isSecurityEventChipKey = isSecurityEventChipKey;
16
+ exports.applySecurityEventFacetFiltersToQuery = applySecurityEventFacetFiltersToQuery;
17
+ exports.buildSecurityEventSearchQuery = buildSecurityEventSearchQuery;
18
+ const Includes_1 = __importDefault(require("../../Types/BaseDatabase/Includes"));
19
+ const IncludesNone_1 = __importDefault(require("../../Types/BaseDatabase/IncludesNone"));
20
+ const NotEqual_1 = __importDefault(require("../../Types/BaseDatabase/NotEqual"));
21
+ const Search_1 = __importDefault(require("../../Types/BaseDatabase/Search"));
22
+ const TelemetrySearchQuery_1 = require("../../Types/Telemetry/TelemetrySearchQuery");
23
+ /*
24
+ * THE SECURITY EVENTS SEARCH, COMPILED: the search bar's text and the facet
25
+ * sidebar's chips, as the query a read of the SecurityEvent table sends.
26
+ *
27
+ * One compile for every reader: the Events page lists, charts and counts
28
+ * with it, and a saved hunt's scheduled run (SecurityHuntScheduler) counts
29
+ * with it on the server, so a hunt finds on its schedule exactly what its
30
+ * page shows. Pure and React-free.
31
+ *
32
+ * The search speaks the shared telemetry grammar
33
+ * (Types/Telemetry/TelemetrySearchQuery), so `severity:High`,
34
+ * `-@threat.matched:true`, `user:(alice OR bob)` and `@device.hostname:web-*`
35
+ * mean here exactly what their counterparts mean in the logs, traces and
36
+ * exceptions explorers. This module only supplies the three things the
37
+ * grammar cannot know - which field names this signal has, which of its
38
+ * columns are numeric, and how a parsed token lands on a SecurityEvent
39
+ * query - and how a chip compiles.
40
+ */
41
+ /*
42
+ * What a user may type on the left of the colon -> the column it filters.
43
+ *
44
+ * Both the friendly name and the column's own name are accepted: `severity:`
45
+ * is what somebody types, `severityName:` is what they see in the detail
46
+ * panel and copy. Looked up lowercased by the shared parser.
47
+ */
48
+ exports.SECURITY_EVENT_FIELD_ALIASES = {
49
+ severity: "severityName",
50
+ severityname: "severityName",
51
+ severityid: "severityId",
52
+ class: "className",
53
+ eventclass: "className",
54
+ classname: "className",
55
+ classuid: "classUid",
56
+ category: "categoryName",
57
+ categoryname: "categoryName",
58
+ categoryuid: "categoryUid",
59
+ activity: "activityName",
60
+ activityname: "activityName",
61
+ status: "statusName",
62
+ outcome: "statusName",
63
+ statusname: "statusName",
64
+ message: "message",
65
+ vendor: "vendorName",
66
+ vendorname: "vendorName",
67
+ product: "productName",
68
+ productname: "productName",
69
+ rule: "ruleName",
70
+ rulename: "ruleName",
71
+ ruleid: "ruleId",
72
+ user: "principalUser",
73
+ principaluser: "principalUser",
74
+ host: "principalHost",
75
+ principalhost: "principalHost",
76
+ ip: "principalIp",
77
+ principalip: "principalIp",
78
+ process: "principalProcess",
79
+ principalprocess: "principalProcess",
80
+ /*
81
+ * The process the event is about and its parent, by their own names and
82
+ * by Sigma's: `image:` is the executable's path and `commandline:` its
83
+ * command line, as in a detection rule. `process:` stays the acting
84
+ * process (principalProcess) the searches written before read.
85
+ */
86
+ processname: "processName",
87
+ image: "processPath",
88
+ processpath: "processPath",
89
+ commandline: "processCommandLine",
90
+ cmdline: "processCommandLine",
91
+ processcommandline: "processCommandLine",
92
+ parentprocessname: "parentProcessName",
93
+ parentimage: "parentProcessPath",
94
+ parentprocesspath: "parentProcessPath",
95
+ parentcommandline: "parentProcessCommandLine",
96
+ parentprocesscommandline: "parentProcessCommandLine",
97
+ targetuser: "targetUser",
98
+ targethost: "targetHost",
99
+ targetip: "targetIp",
100
+ targetport: "targetPort",
101
+ resource: "targetResource",
102
+ targetresource: "targetResource",
103
+ observable: "observables",
104
+ observables: "observables",
105
+ tactic: "mitreTactics",
106
+ mitretactics: "mitreTactics",
107
+ technique: "mitreTechniques",
108
+ mitretechniques: "mitreTechniques",
109
+ uid: "eventUid",
110
+ eventuid: "eventUid",
111
+ /*
112
+ * The request an event happened in, and how far it got. `trace:` and
113
+ * `session:` are what a person pastes from the trace or session they came
114
+ * from; `outcome:` stays the OCSF status it always was.
115
+ */
116
+ trace: "traceId",
117
+ traceid: "traceId",
118
+ span: "spanId",
119
+ spanid: "spanId",
120
+ session: "sessionId",
121
+ sessionid: "sessionId",
122
+ requestoutcome: "requestOutcome",
123
+ };
124
+ /*
125
+ * The field names the parser will glue back together across a space — the
126
+ * difference between `severity: High` being a filter and `note: check this`
127
+ * staying prose. Every alias key is one; nothing else is.
128
+ */
129
+ exports.SECURITY_EVENT_SEARCH_FIELD_KEYS = new Set(Object.keys(exports.SECURITY_EVENT_FIELD_ALIASES));
130
+ /*
131
+ * Columns stored as numbers. An equality typed against one of these has to
132
+ * reach ClickHouse as a number: the column is UInt/Int, and comparing it to
133
+ * the string "443" is a type error rather than a miss.
134
+ *
135
+ * Only equality needs the coercion — every comparison operator
136
+ * (`>`, `<=`, ...) is already parsed numerically by the shared grammar.
137
+ */
138
+ exports.SECURITY_EVENT_NUMERIC_FIELDS = new Set(["severityId", "categoryUid", "classUid", "targetPort"]);
139
+ /*
140
+ * Columns whose free-text-ish nature makes an exact match almost always the
141
+ * wrong reading of what the user typed.
142
+ *
143
+ * `message` is a sentence — `message:refused` means "mentions refused".
144
+ * `observables`, `mitreTactics` and `mitreTechniques` are arrays, where the
145
+ * analytics compiler's substring match over the joined array is how "this
146
+ * event mentions X" is asked (the same predicate the Correlate page pivots
147
+ * on). A command line or a path is searched for a part of it:
148
+ * `commandline:-enc`, `image:powershell.exe`. An explicit operator the user
149
+ * typed (`!`, `~`, `>`, a glob, a list) always wins over this default.
150
+ */
151
+ exports.SECURITY_EVENT_CONTAINS_FIELDS = new Set([
152
+ "message",
153
+ "observables",
154
+ "mitreTactics",
155
+ "mitreTechniques",
156
+ "principalProcess",
157
+ "processPath",
158
+ "processCommandLine",
159
+ "parentProcessPath",
160
+ "parentProcessCommandLine",
161
+ "targetResource",
162
+ ]);
163
+ exports.EMPTY_SECURITY_EVENT_SEARCH_FILTERS = {
164
+ freeText: null,
165
+ fields: {},
166
+ attributes: {},
167
+ };
168
+ function compileFieldValue(column, token) {
169
+ const compiled = (0, TelemetrySearchQuery_1.predicateToQueryValue)(token.predicate);
170
+ /*
171
+ * Only a bare equality is re-read here; every other operator already
172
+ * carries its own type decision out of the shared grammar.
173
+ */
174
+ if (typeof compiled !== "string") {
175
+ return compiled;
176
+ }
177
+ if (exports.SECURITY_EVENT_NUMERIC_FIELDS.has(column)) {
178
+ const numeric = Number(compiled);
179
+ return Number.isFinite(numeric) ? numeric : compiled;
180
+ }
181
+ if (exports.SECURITY_EVENT_CONTAINS_FIELDS.has(column) &&
182
+ token.predicate.operator === TelemetrySearchQuery_1.SearchValueOperator.Equals &&
183
+ !token.negated) {
184
+ return new Search_1.default(compiled);
185
+ }
186
+ return compiled;
187
+ }
188
+ /**
189
+ * Parse a search string into the predicates it stands for.
190
+ *
191
+ * Later tokens on the same key win — a user editing `severity:Low` into
192
+ * `severity:Low severity:High` means the second one.
193
+ */
194
+ function parseSecurityEventSearch(raw) {
195
+ const tokens = (0, TelemetrySearchQuery_1.parseSearchQuery)(raw || "", {
196
+ knownFieldKeys: exports.SECURITY_EVENT_SEARCH_FIELD_KEYS,
197
+ fieldAliases: exports.SECURITY_EVENT_FIELD_ALIASES,
198
+ });
199
+ const fields = {};
200
+ const attributes = {};
201
+ const freeTextParts = [];
202
+ for (const token of tokens) {
203
+ if (token.type === TelemetrySearchQuery_1.SearchTokenType.FreeText) {
204
+ const text = token.predicate.value.trim();
205
+ if (text.length > 0) {
206
+ freeTextParts.push(text);
207
+ }
208
+ continue;
209
+ }
210
+ if (token.type === TelemetrySearchQuery_1.SearchTokenType.Attribute) {
211
+ if (token.key.length === 0) {
212
+ continue;
213
+ }
214
+ attributes[token.key] = (0, TelemetrySearchQuery_1.predicateToQueryValue)(token.predicate);
215
+ continue;
216
+ }
217
+ /*
218
+ * A field the parser did not recognise is not a column of this table.
219
+ * Dropping it would silently widen the list; treating it as an attribute
220
+ * is what the user almost certainly meant, since every un-typed source
221
+ * field lands in the attributes map.
222
+ */
223
+ const column = exports.SECURITY_EVENT_FIELD_ALIASES[token.key.toLowerCase()];
224
+ if (!column) {
225
+ attributes[token.key] = (0, TelemetrySearchQuery_1.predicateToQueryValue)(token.predicate);
226
+ continue;
227
+ }
228
+ fields[column] = compileFieldValue(column, token);
229
+ }
230
+ return {
231
+ freeText: freeTextParts.length > 0 ? freeTextParts.join(" ") : null,
232
+ fields: fields,
233
+ attributes: attributes,
234
+ };
235
+ }
236
+ /**
237
+ * Lay the parsed search over a query.
238
+ *
239
+ * Returns a new object: the caller's base query (project + window + the
240
+ * page's own scope) is never mutated. Attribute predicates MERGE into any
241
+ * attributes already on the query rather than replacing the map, so a
242
+ * chip and a typed `@key:value` can coexist.
243
+ */
244
+ function applySecurityEventSearchToQuery(data) {
245
+ const query = Object.assign({}, data.query);
246
+ if (data.filters.freeText) {
247
+ query["message"] = new Search_1.default(data.filters.freeText);
248
+ }
249
+ for (const column of Object.keys(data.filters.fields)) {
250
+ query[column] = data.filters.fields[column];
251
+ }
252
+ const attributeKeys = Object.keys(data.filters.attributes);
253
+ if (attributeKeys.length > 0) {
254
+ const attributes = Object.assign({}, (query["attributes"] || {}));
255
+ for (const key of attributeKeys) {
256
+ attributes[key] = data.filters.attributes[key];
257
+ }
258
+ query["attributes"] = attributes;
259
+ }
260
+ return query;
261
+ }
262
+ /** True when the string holds anything the parser would turn into a filter. */
263
+ function hasSecurityEventSearch(raw) {
264
+ const filters = parseSecurityEventSearch(raw);
265
+ return (filters.freeText !== null ||
266
+ Object.keys(filters.fields).length > 0 ||
267
+ Object.keys(filters.attributes).length > 0);
268
+ }
269
+ /*
270
+ * THE CHIPS.
271
+ *
272
+ * Chips for arbitrary source attributes are keyed `attributes.<key>`, the
273
+ * same grammar the logs, traces and exceptions explorers use, so the shared
274
+ * sidebar and chip row need no special case for them.
275
+ */
276
+ exports.SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX = "attributes.";
277
+ /*
278
+ * A chip the sidebar's "exclude" action created, marked on the KEY rather
279
+ * than the value: `!severityName` / `!attributes.threat.matched`.
280
+ *
281
+ * On the key because a value is data — a hostname, a rule name, a flattened
282
+ * attribute — and any marker put on it could be part of a real value. No
283
+ * column name or attribute key starts with `!`, so the marker is
284
+ * unambiguous, and it survives the `[[key, value], ...]` URL grammar the
285
+ * other explorers already use without a second param. It is the shared facet
286
+ * sidebar's marker (FacetSelection's FACET_EXCLUDE_KEY_PREFIX), which a test
287
+ * holds this one to.
288
+ */
289
+ exports.SECURITY_EVENT_EXCLUDE_FACET_PREFIX = "!";
290
+ function isSecurityEventExcludeFacetKey(facetKey) {
291
+ return facetKey.startsWith(exports.SECURITY_EVENT_EXCLUDE_FACET_PREFIX);
292
+ }
293
+ function toSecurityEventExcludeFacetKey(facetKey) {
294
+ return isSecurityEventExcludeFacetKey(facetKey)
295
+ ? facetKey
296
+ : `${exports.SECURITY_EVENT_EXCLUDE_FACET_PREFIX}${facetKey}`;
297
+ }
298
+ /** The plain facet key an include-or-exclude key stands for. */
299
+ function getSecurityEventBaseFacetKey(facetKey) {
300
+ return isSecurityEventExcludeFacetKey(facetKey)
301
+ ? facetKey.substring(exports.SECURITY_EVENT_EXCLUDE_FACET_PREFIX.length)
302
+ : facetKey;
303
+ }
304
+ function isSecurityEventAttributeFacetKey(facetKey) {
305
+ return getSecurityEventBaseFacetKey(facetKey).startsWith(exports.SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX);
306
+ }
307
+ function getSecurityEventAttributeKey(facetKey) {
308
+ return getSecurityEventBaseFacetKey(facetKey).substring(exports.SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX.length);
309
+ }
310
+ /*
311
+ * Which OneUptime source the event was attributed to — a Telemetry Service
312
+ * standing for the SIEM or connector it arrived from. It is also the column
313
+ * @OwnedThrough narrows on.
314
+ */
315
+ exports.SECURITY_EVENT_SOURCE_FACET_KEY = "primaryEntityId";
316
+ /*
317
+ * The columns the facet sidebar offers, in its order (the Dashboard's
318
+ * SECURITY_EVENT_FACETS gives each its title). A chip names one of them, or
319
+ * a source attribute.
320
+ */
321
+ exports.SECURITY_EVENT_FACET_COLUMNS = [
322
+ exports.SECURITY_EVENT_SOURCE_FACET_KEY,
323
+ "severityName",
324
+ "requestOutcome",
325
+ "className",
326
+ "categoryName",
327
+ "activityName",
328
+ "statusName",
329
+ "vendorName",
330
+ "productName",
331
+ "ruleName",
332
+ "principalUser",
333
+ "principalHost",
334
+ "processName",
335
+ "parentProcessName",
336
+ ];
337
+ /*
338
+ * Whether a chip's key is one the sidebar can make: a facet column or a
339
+ * source attribute with a key, either one included or excluded.
340
+ */
341
+ function isSecurityEventChipKey(facetKey) {
342
+ const baseKey = getSecurityEventBaseFacetKey(facetKey);
343
+ if (isSecurityEventAttributeFacetKey(baseKey)) {
344
+ return getSecurityEventAttributeKey(baseKey).length > 0;
345
+ }
346
+ return exports.SECURITY_EVENT_FACET_COLUMNS.includes(baseKey);
347
+ }
348
+ function compileFacetSelection(values, isExcluded) {
349
+ if (isExcluded) {
350
+ return values.length === 1
351
+ ? new NotEqual_1.default(values[0])
352
+ : new IncludesNone_1.default(values);
353
+ }
354
+ /*
355
+ * A single value compiles to a bare string so ClickHouse gets the plain
356
+ * equality — and with it the column's Set / bloom skip index. More than
357
+ * one becomes an `Includes`, which is an `IN`.
358
+ */
359
+ return values.length === 1 ? values[0] : new Includes_1.default(values);
360
+ }
361
+ /*
362
+ * Compile the sidebar's selections into the list query.
363
+ *
364
+ * Attribute chips land in `attributes[<key>]`. Their values come from the
365
+ * data — an attribute copied off a row, a facet value clicked — so they are
366
+ * compiled as equality, which is both exact and the fast
367
+ * `attributes['k'] = 'v'` map-subscript path.
368
+ *
369
+ * Exclusions are written FIRST so that an include on the same column wins:
370
+ * holding both is a transient state the sidebar cannot reach on purpose,
371
+ * and a list narrowed to a value is a more useful reading of the two chips
372
+ * than one that excludes what it also requires and returns nothing.
373
+ */
374
+ function applySecurityEventFacetFiltersToQuery(data) {
375
+ const query = Object.assign({}, data.query);
376
+ const attributes = Object.assign({}, (query["attributes"] || {}));
377
+ const entries = Array.from(data.filters.entries()).sort((a, b) => {
378
+ const aExcluded = isSecurityEventExcludeFacetKey(a[0]) ? 0 : 1;
379
+ const bExcluded = isSecurityEventExcludeFacetKey(b[0]) ? 0 : 1;
380
+ return aExcluded - bExcluded;
381
+ });
382
+ for (const [facetKey, valueSet] of entries) {
383
+ const values = Array.from(valueSet).filter((value) => {
384
+ return value.length > 0;
385
+ });
386
+ if (values.length === 0) {
387
+ continue;
388
+ }
389
+ const isExcluded = isSecurityEventExcludeFacetKey(facetKey);
390
+ const compiled = compileFacetSelection(values, isExcluded);
391
+ if (isSecurityEventAttributeFacetKey(facetKey)) {
392
+ const attributeKey = getSecurityEventAttributeKey(facetKey);
393
+ if (attributeKey.length === 0) {
394
+ continue;
395
+ }
396
+ attributes[attributeKey] = compiled;
397
+ continue;
398
+ }
399
+ query[getSecurityEventBaseFacetKey(facetKey)] =
400
+ compiled;
401
+ }
402
+ if (Object.keys(attributes).length > 0) {
403
+ query["attributes"] = attributes;
404
+ }
405
+ return query;
406
+ }
407
+ /*
408
+ * The search and the chips over a base query (the project and the window),
409
+ * in the order the Events page lays them: the search first, the chips
410
+ * second - a chip is an explicit click on a value the person can see and
411
+ * take off, so when both name the same column the chip is the one they are
412
+ * steering with.
413
+ */
414
+ function buildSecurityEventSearchQuery(data) {
415
+ return applySecurityEventFacetFiltersToQuery({
416
+ query: applySecurityEventSearchToQuery({
417
+ query: data.base,
418
+ filters: parseSecurityEventSearch(data.search),
419
+ }),
420
+ filters: data.filters,
421
+ });
422
+ }
@@ -0,0 +1,21 @@
1
+ import commonJsModule from "./SecurityEventSearch.js";
2
+ export const EMPTY_SECURITY_EVENT_SEARCH_FILTERS = commonJsModule.EMPTY_SECURITY_EVENT_SEARCH_FILTERS;
3
+ export const SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX = commonJsModule.SECURITY_EVENT_ATTRIBUTE_FACET_PREFIX;
4
+ export const SECURITY_EVENT_CONTAINS_FIELDS = commonJsModule.SECURITY_EVENT_CONTAINS_FIELDS;
5
+ export const SECURITY_EVENT_EXCLUDE_FACET_PREFIX = commonJsModule.SECURITY_EVENT_EXCLUDE_FACET_PREFIX;
6
+ export const SECURITY_EVENT_FACET_COLUMNS = commonJsModule.SECURITY_EVENT_FACET_COLUMNS;
7
+ export const SECURITY_EVENT_FIELD_ALIASES = commonJsModule.SECURITY_EVENT_FIELD_ALIASES;
8
+ export const SECURITY_EVENT_NUMERIC_FIELDS = commonJsModule.SECURITY_EVENT_NUMERIC_FIELDS;
9
+ export const SECURITY_EVENT_SEARCH_FIELD_KEYS = commonJsModule.SECURITY_EVENT_SEARCH_FIELD_KEYS;
10
+ export const SECURITY_EVENT_SOURCE_FACET_KEY = commonJsModule.SECURITY_EVENT_SOURCE_FACET_KEY;
11
+ export const applySecurityEventFacetFiltersToQuery = commonJsModule.applySecurityEventFacetFiltersToQuery;
12
+ export const applySecurityEventSearchToQuery = commonJsModule.applySecurityEventSearchToQuery;
13
+ export const buildSecurityEventSearchQuery = commonJsModule.buildSecurityEventSearchQuery;
14
+ export const getSecurityEventAttributeKey = commonJsModule.getSecurityEventAttributeKey;
15
+ export const getSecurityEventBaseFacetKey = commonJsModule.getSecurityEventBaseFacetKey;
16
+ export const hasSecurityEventSearch = commonJsModule.hasSecurityEventSearch;
17
+ export const isSecurityEventAttributeFacetKey = commonJsModule.isSecurityEventAttributeFacetKey;
18
+ export const isSecurityEventChipKey = commonJsModule.isSecurityEventChipKey;
19
+ export const isSecurityEventExcludeFacetKey = commonJsModule.isSecurityEventExcludeFacetKey;
20
+ export const parseSecurityEventSearch = commonJsModule.parseSecurityEventSearch;
21
+ export const toSecurityEventExcludeFacetKey = commonJsModule.toSecurityEventExcludeFacetKey;
@@ -0,0 +1,12 @@
1
+ import SecurityEvent from "../../Models/AnalyticsModels/SecurityEvent.mjs";
2
+ import Query from "../../Types/BaseDatabase/Query.mjs";
3
+ import ObjectID from "../../Types/ObjectID.mjs";
4
+ import { SecurityHuntFilters } from "../../Types/SecurityEvent/SecurityHunt.mjs";
5
+ export declare function getSecurityHuntFiltersProblem(value: unknown): string | null;
6
+ export declare function buildSecurityHuntQuery(data: {
7
+ projectId: ObjectID;
8
+ searchQuery: string | undefined | null;
9
+ filters: SecurityHuntFilters | undefined | null;
10
+ startTime: Date;
11
+ endTime: Date;
12
+ }): Query<SecurityEvent>;
@@ -0,0 +1,12 @@
1
+ import SecurityEvent from "../../Models/AnalyticsModels/SecurityEvent";
2
+ import Query from "../../Types/BaseDatabase/Query";
3
+ import ObjectID from "../../Types/ObjectID";
4
+ import { SecurityHuntFilters } from "../../Types/SecurityEvent/SecurityHunt";
5
+ export declare function getSecurityHuntFiltersProblem(value: unknown): string | null;
6
+ export declare function buildSecurityHuntQuery(data: {
7
+ projectId: ObjectID;
8
+ searchQuery: string | undefined | null;
9
+ filters: SecurityHuntFilters | undefined | null;
10
+ startTime: Date;
11
+ endTime: Date;
12
+ }): Query<SecurityEvent>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSecurityHuntFiltersProblem = getSecurityHuntFiltersProblem;
7
+ exports.buildSecurityHuntQuery = buildSecurityHuntQuery;
8
+ const InBetween_1 = __importDefault(require("../../Types/BaseDatabase/InBetween"));
9
+ const SecurityHunt_1 = require("../../Types/SecurityEvent/SecurityHunt");
10
+ const SecurityEventSearch_1 = require("./SecurityEventSearch");
11
+ /*
12
+ * A hunt's search, as a read of the SecurityEvent table: its text and its
13
+ * chips over a project and a window, compiled exactly as the Events page
14
+ * compiles them (SecurityEventSearch), so a scheduled run counts what the
15
+ * hunt's page lists for the same window.
16
+ */
17
+ /*
18
+ * What is wrong with a hunt's chips, in the shared words: a key the Events
19
+ * sidebar cannot make, more values than a hunt keeps, or a value too long.
20
+ * Null when they are fine.
21
+ */
22
+ function getSecurityHuntFiltersProblem(value) {
23
+ const filters = (0, SecurityHunt_1.readSecurityHuntFilters)(value);
24
+ let count = 0;
25
+ for (const [key, values] of Object.entries(filters)) {
26
+ if (!(0, SecurityEventSearch_1.isSecurityEventChipKey)(key)) {
27
+ return SecurityHunt_1.SECURITY_HUNT_MESSAGES.unknownFilter.message;
28
+ }
29
+ for (const item of values) {
30
+ if (item.length > SecurityHunt_1.SECURITY_HUNT_FILTER_VALUE_MAX_LENGTH) {
31
+ return SecurityHunt_1.SECURITY_HUNT_MESSAGES.filterValueTooLong.message;
32
+ }
33
+ }
34
+ count += values.length;
35
+ }
36
+ if (count > SecurityHunt_1.SECURITY_HUNT_FILTER_VALUES_MAX) {
37
+ return SecurityHunt_1.SECURITY_HUNT_MESSAGES.tooManyFilterValues.message;
38
+ }
39
+ return null;
40
+ }
41
+ // The read of a hunt's search over one project and one window.
42
+ function buildSecurityHuntQuery(data) {
43
+ return (0, SecurityEventSearch_1.buildSecurityEventSearchQuery)({
44
+ base: {
45
+ projectId: data.projectId,
46
+ time: new InBetween_1.default(data.startTime, data.endTime),
47
+ },
48
+ search: data.searchQuery || "",
49
+ filters: (0, SecurityHunt_1.securityHuntFiltersToMap)(data.filters),
50
+ });
51
+ }
@@ -0,0 +1,3 @@
1
+ import commonJsModule from "./SecurityHuntSearch.js";
2
+ export const buildSecurityHuntQuery = commonJsModule.buildSecurityHuntQuery;
3
+ export const getSecurityHuntFiltersProblem = commonJsModule.getSecurityHuntFiltersProblem;
@@ -26,10 +26,19 @@ export interface TracePerformanceFixOffer {
26
26
  export declare function getTracePerformanceFixOffer(input: TracePerformanceFixOfferInput): TracePerformanceFixOffer;
27
27
  export declare function isDatabaseFinding(finding: PerformanceFinding): boolean;
28
28
  export declare function getFindingOperationName(finding: PerformanceFinding): string;
29
+ export interface TracePerformanceFixRepository {
30
+ id: string;
31
+ name: string;
32
+ }
33
+ export declare const MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES: number;
34
+ export declare const PICK_A_REPOSITORY_FOR_THE_FIX_MESSAGE: string;
35
+ export declare const PICKED_REPOSITORY_NOT_CONNECTED_MESSAGE: string;
29
36
  export interface TracePerformanceFixSuggestion extends TracePerformanceFixOffer {
30
37
  aiRunId: string | null;
38
+ repositories: Array<TracePerformanceFixRepository>;
31
39
  }
32
40
  export declare const NO_TRACE_PERFORMANCE_FIX_SUGGESTION: TracePerformanceFixSuggestion;
41
+ export declare function parseTracePerformanceFixRepositories(value: unknown): Array<TracePerformanceFixRepository>;
33
42
  export declare function parsePerformanceFinding(value: unknown): PerformanceFinding | null;
34
43
  export declare function parseTracePerformanceFixSuggestion(value: unknown): TracePerformanceFixSuggestion;
35
44
  export declare function tracePerformanceFixSuggestionToJSON(suggestion: TracePerformanceFixSuggestion): JSONObject;
@@ -26,10 +26,19 @@ export interface TracePerformanceFixOffer {
26
26
  export declare function getTracePerformanceFixOffer(input: TracePerformanceFixOfferInput): TracePerformanceFixOffer;
27
27
  export declare function isDatabaseFinding(finding: PerformanceFinding): boolean;
28
28
  export declare function getFindingOperationName(finding: PerformanceFinding): string;
29
+ export interface TracePerformanceFixRepository {
30
+ id: string;
31
+ name: string;
32
+ }
33
+ export declare const MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES: number;
34
+ export declare const PICK_A_REPOSITORY_FOR_THE_FIX_MESSAGE: string;
35
+ export declare const PICKED_REPOSITORY_NOT_CONNECTED_MESSAGE: string;
29
36
  export interface TracePerformanceFixSuggestion extends TracePerformanceFixOffer {
30
37
  aiRunId: string | null;
38
+ repositories: Array<TracePerformanceFixRepository>;
31
39
  }
32
40
  export declare const NO_TRACE_PERFORMANCE_FIX_SUGGESTION: TracePerformanceFixSuggestion;
41
+ export declare function parseTracePerformanceFixRepositories(value: unknown): Array<TracePerformanceFixRepository>;
33
42
  export declare function parsePerformanceFinding(value: unknown): PerformanceFinding | null;
34
43
  export declare function parseTracePerformanceFixSuggestion(value: unknown): TracePerformanceFixSuggestion;
35
44
  export declare function tracePerformanceFixSuggestionToJSON(suggestion: TracePerformanceFixSuggestion): JSONObject;
@@ -33,12 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.NO_TRACE_PERFORMANCE_FIX_SUGGESTION = exports.TRACE_NOT_WORTH_FIXING_MESSAGE = exports.WORTH_FIXING_MIN_PERCENT_OF_TRACE = exports.WORTH_FIXING_MIN_MS = void 0;
36
+ exports.NO_TRACE_PERFORMANCE_FIX_SUGGESTION = exports.PICKED_REPOSITORY_NOT_CONNECTED_MESSAGE = exports.PICK_A_REPOSITORY_FOR_THE_FIX_MESSAGE = exports.MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES = exports.TRACE_NOT_WORTH_FIXING_MESSAGE = exports.WORTH_FIXING_MIN_PERCENT_OF_TRACE = exports.WORTH_FIXING_MIN_MS = void 0;
37
37
  exports.isFindingWorthFixing = isFindingWorthFixing;
38
38
  exports.getFindingsWorthFixing = getFindingsWorthFixing;
39
39
  exports.getTracePerformanceFixOffer = getTracePerformanceFixOffer;
40
40
  exports.isDatabaseFinding = isDatabaseFinding;
41
41
  exports.getFindingOperationName = getFindingOperationName;
42
+ exports.parseTracePerformanceFixRepositories = parseTracePerformanceFixRepositories;
42
43
  exports.parsePerformanceFinding = parsePerformanceFinding;
43
44
  exports.parseTracePerformanceFixSuggestion = parseTracePerformanceFixSuggestion;
44
45
  exports.tracePerformanceFixSuggestionToJSON = tracePerformanceFixSuggestionToJSON;
@@ -179,6 +180,25 @@ function getFindingOperationName(finding) {
179
180
  }
180
181
  return finding.normalizedSpanName;
181
182
  }
183
+ /*
184
+ * The most repositories the page is offered to pick from: far more than a
185
+ * project connects, and a bound on what one answer carries.
186
+ */
187
+ exports.MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES = 200;
188
+ /*
189
+ * The server's refusal of a fix the person did not pick a repository for,
190
+ * when several are connected and none was found to hold the trace's code
191
+ * for certain. The trace page asks for the pick first, so people meet this
192
+ * through the API, or on the page after the second repository was
193
+ * connected since it read the list - after "Could not start the fix:",
194
+ * beside the picker the page then shows.
195
+ */
196
+ exports.PICK_A_REPOSITORY_FOR_THE_FIX_MESSAGE = "Several repositories are connected, and none could be matched to this trace's service or code. Pick the one that holds this code.";
197
+ /*
198
+ * The server's refusal of a pick that is not one of the project's connected
199
+ * repositories AI can work in.
200
+ */
201
+ exports.PICKED_REPOSITORY_NOT_CONNECTED_MESSAGE = "That repository is not one of this project's connected repositories OneUptime AI can work in. Pick another, or connect it in Code.";
182
202
  exports.NO_TRACE_PERFORMANCE_FIX_SUGGESTION = {
183
203
  offer: SuggestionOffer_1.default.None,
184
204
  finding: null,
@@ -186,7 +206,48 @@ exports.NO_TRACE_PERFORMANCE_FIX_SUGGESTION = {
186
206
  fixOutcome: null,
187
207
  blocker: null,
188
208
  aiRunId: null,
209
+ repositories: [],
189
210
  };
211
+ function parseRepository(value) {
212
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
213
+ return null;
214
+ }
215
+ const record = value;
216
+ const id = record["id"];
217
+ const name = record["name"];
218
+ if (typeof id !== "string" ||
219
+ !id.trim() ||
220
+ typeof name !== "string" ||
221
+ !name.trim()) {
222
+ return null;
223
+ }
224
+ return { id: id.trim(), name: name.trim() };
225
+ }
226
+ /*
227
+ * The repositories off the wire: whole entries only, each once, at most
228
+ * MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES, in the order the server sent.
229
+ * One repository is no choice (the fix would work in it anyway), so a list
230
+ * of fewer than two reads as none.
231
+ */
232
+ function parseTracePerformanceFixRepositories(value) {
233
+ if (!Array.isArray(value)) {
234
+ return [];
235
+ }
236
+ const seen = new Set();
237
+ const repositories = [];
238
+ for (const entry of value) {
239
+ const repository = parseRepository(entry);
240
+ if (!repository || seen.has(repository.id.toLowerCase())) {
241
+ continue;
242
+ }
243
+ seen.add(repository.id.toLowerCase());
244
+ repositories.push(repository);
245
+ if (repositories.length >= exports.MAX_TRACE_PERFORMANCE_FIX_REPOSITORIES) {
246
+ break;
247
+ }
248
+ }
249
+ return repositories.length > 1 ? repositories : [];
250
+ }
190
251
  function isFiniteNumber(value) {
191
252
  return typeof value === "number" && Number.isFinite(value);
192
253
  }
@@ -320,6 +381,10 @@ function parseTracePerformanceFixSuggestion(value) {
320
381
  fixOutcome,
321
382
  blocker,
322
383
  aiRunId: linksRun ? aiRunId : null,
384
+ // A pick is the fix's own step: only an offer of the fix carries one.
385
+ repositories: offer === SuggestionOffer_1.default.Act
386
+ ? parseTracePerformanceFixRepositories(record["repositories"])
387
+ : [],
323
388
  };
324
389
  }
325
390
  // The route's answer as JSON (the server's side of the parser above).
@@ -335,5 +400,8 @@ function tracePerformanceFixSuggestionToJSON(suggestion) {
335
400
  ? (0, SuggestionBlocker_1.suggestionBlockerToJSON)(suggestion.blocker)
336
401
  : null,
337
402
  aiRunId: suggestion.aiRunId,
403
+ repositories: suggestion.repositories.map((repository) => {
404
+ return { id: repository.id, name: repository.name };
405
+ }),
338
406
  };
339
407
  }