@cccsaurora/clue-ui 1.2.7-patch.320 → 1.2.8-dev.326

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 (183) hide show
  1. package/ActionForm-CPNudc44.js +5973 -0
  2. package/AnnotationDetails-CeWJZ845.js +175 -0
  3. package/AnnotationPreview-BzWMQSXa.js +188 -0
  4. package/ClueEnrichContext-CpzPSHQm.js +549 -0
  5. package/FlexOne-BSYAhhtG.js +9 -0
  6. package/_MapCache-WmuDdwuH.js +222 -0
  7. package/_Uint8Array-B7JqpgFX.js +128 -0
  8. package/_baseAssignValue-CGTuELqU.js +25 -0
  9. package/_baseClone-CkNrTyhm.js +283 -0
  10. package/_baseExtremum-kob8QXyt.js +18 -0
  11. package/_baseFlatten-jIR_sN_-.js +92 -0
  12. package/_baseGet-Bx3A4Qfp.js +108 -0
  13. package/_baseIsEqual-C5OTWzTk.js +208 -0
  14. package/_baseIteratee-avi7MX2o.js +126 -0
  15. package/_baseSlice-GAv_YFTT.js +20 -0
  16. package/_baseSum-D0WC1dN0.js +13 -0
  17. package/_baseUniq-BI9GIHMF.js +115 -0
  18. package/_commonjsHelpers-DWwsNxpa.js +8 -0
  19. package/_createAggregator-QD8MzKwe.js +63 -0
  20. package/_getPrototype-CU0j_POw.js +5 -0
  21. package/_getTag-Ckxxfr88.js +126 -0
  22. package/_isIterateeCall-Ds3sw2SF.js +17 -0
  23. package/_setToArray-CaPKQhcz.js +33 -0
  24. package/cloneDeep-DJrLSw8W.js +8 -0
  25. package/components/AnnotationBody.js +49 -35
  26. package/components/AnnotationDetailPopover.js +36 -30
  27. package/components/AnnotationDetails.js +7 -7
  28. package/components/AnnotationEntry.js +35 -35
  29. package/components/AnnotationPreview.js +5 -5
  30. package/components/ClassificationChip.js +44 -23
  31. package/components/CountBadge.js +31 -26
  32. package/components/EnrichedCard.js +110 -97
  33. package/components/EnrichedChip.js +130 -105
  34. package/components/EnrichedTypography.js +133 -107
  35. package/components/ErrorBoundary.js +28 -24
  36. package/components/RetryFailedEnrichments.js +10 -9
  37. package/components/SourcePicker.js +57 -49
  38. package/components/actions/ActionForm.js +4 -4
  39. package/components/actions/ExecutePopover.js +75 -59
  40. package/components/actions/ResultModal.js +4 -4
  41. package/components/actions/form/schemaAdapter.js +39 -23
  42. package/components/actions/formats/FileResult.js +86 -59
  43. package/components/actions/formats/index.js +21 -10
  44. package/components/display/graph/ExpandMoreButton.js +10 -10
  45. package/components/display/graph/elements/NodeCard.js +111 -91
  46. package/components/display/graph/elements/NodeTag.js +15 -13
  47. package/components/display/graph/index.js +261 -202
  48. package/components/display/graph/visualizations/Leaf.js +88 -69
  49. package/components/display/graph/visualizations/cloud/index.js +98 -81
  50. package/components/display/graph/visualizations/icons/BaseIcon.js +26 -21
  51. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  52. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  53. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  54. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  55. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  56. package/components/display/graph/visualizations/icons/index.js +14 -13
  57. package/components/display/graph/visualizations/panels/NodePanel.js +10 -8
  58. package/components/display/graph/visualizations/tree/BundleLine.js +108 -81
  59. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  60. package/components/display/graph/visualizations/tree/index.js +408 -306
  61. package/components/display/icons/Iconified.js +27 -12
  62. package/components/display/json/index.js +4 -4
  63. package/components/display/markdown/index.js +8678 -5770
  64. package/components/enrichment/EnrichPopover.js +54 -46
  65. package/components/fetchers/Fetcher.js +158 -119
  66. package/components/fetchers/PreviewModal.js +20 -17
  67. package/components/fetchers/StatusChip.js +21 -17
  68. package/components/group/Entry.js +13 -11
  69. package/components/group/Group.js +13 -10
  70. package/components/group/GroupControl.js +76 -65
  71. package/components/stats/QueryStatus.js +43 -33
  72. package/countBy-c6S3dvSW.js +14 -0
  73. package/data/event.js +6 -4
  74. package/database/index.js +2 -2
  75. package/debounce-bV0h5FC5.js +92 -0
  76. package/get-DSsNkRQs.js +8 -0
  77. package/groupBy-xqz-n0Vd.js +14 -0
  78. package/hooks/ClueActionContext.js +6 -6
  79. package/hooks/ClueComponentContext.js +29 -23
  80. package/hooks/ClueConfigProvider.js +14 -12
  81. package/hooks/ClueDatabaseContext.js +19 -13
  82. package/hooks/ClueEnrichContext.js +8 -8
  83. package/hooks/ClueFetcherContext.js +83 -56
  84. package/hooks/ClueGroupContext.js +17 -14
  85. package/hooks/CluePopupContext.js +5 -5
  86. package/hooks/ClueProvider.js +12 -10
  87. package/hooks/selectors.js +7 -7
  88. package/hooks/useActionResult.js +3 -3
  89. package/hooks/useAnnotations.js +47 -31
  90. package/hooks/useClue.js +6 -4
  91. package/hooks/useClueActions.js +3 -3
  92. package/hooks/useClueConfig.js +6 -4
  93. package/hooks/useClueTypeConfig.js +3 -3
  94. package/hooks/useComparator.js +722 -435
  95. package/hooks/useErrors.js +22 -18
  96. package/hooks/useFetcherResult.js +33 -24
  97. package/hooks/useMyHighlights.js +66 -36
  98. package/hooks/useMyLocalStorage.js +66 -37
  99. package/iconify-CXMreGTg.js +1782 -0
  100. package/icons/Action.js +66 -49
  101. package/icons/Assessment.js +85 -69
  102. package/icons/Context.js +77 -63
  103. package/icons/Opinion.js +76 -60
  104. package/icons/iconMap.js +2 -2
  105. package/identity-CPGTqrE4.js +6 -0
  106. package/index-AMfoEg_6.js +696 -0
  107. package/index-B6C2a_Lg.js +1172 -0
  108. package/index-C12gPw2W.js +17698 -0
  109. package/index-DCKkHTvx.js +15750 -0
  110. package/index-JcKyZeoY.js +465 -0
  111. package/isNil-CIubwp4T.js +6 -0
  112. package/isObject-FTY-5JQX.js +7 -0
  113. package/isObjectLike-OAgjjZye.js +48 -0
  114. package/isSymbol-Xd2FsJyp.js +8 -0
  115. package/last-CUCl67Im.js +7 -0
  116. package/main.js +60 -60
  117. package/maxBy-IKHzFrCS.js +8 -0
  118. package/package.json +1 -1
  119. package/sortBy-DfSj8IoJ.js +96 -0
  120. package/sumBy-D-hb_NY-.js +8 -0
  121. package/text/Frequency.js +42 -23
  122. package/toFinite-Bc55msYj.js +16 -0
  123. package/toNumber-DPxy1FBy.js +39 -0
  124. package/useClueTypeConfig-Z1LFp01b.js +3289 -0
  125. package/utils/chain.js +92 -65
  126. package/utils/classificationParser.js +519 -256
  127. package/utils/constants.js +35 -10
  128. package/utils/graph.js +72 -45
  129. package/utils/hashUtil.js +7 -7
  130. package/utils/line.js +131 -81
  131. package/utils/loggerUtil.js +5 -3
  132. package/utils/sessionStorage.js +41 -27
  133. package/utils/time.js +423 -423
  134. package/utils/utils.js +9 -9
  135. package/utils/window.js +21 -10
  136. package/utils-HmNPuoDB.js +199 -0
  137. package/ActionForm-1iQtvort.js +0 -4470
  138. package/AnnotationDetails-CcXHDi0B.js +0 -160
  139. package/AnnotationPreview-BLEnPDVF.js +0 -140
  140. package/ClueEnrichContext-B8X0Nw9n.js +0 -424
  141. package/FlexOne-BXWFOd1T.js +0 -6
  142. package/_MapCache-BiTi0iqu.js +0 -180
  143. package/_Uint8Array-BQNOM9Rr.js +0 -101
  144. package/_baseAssignValue-CNMLQZco.js +0 -20
  145. package/_baseClone-BnT-6pyM.js +0 -207
  146. package/_baseExtremum-Ca2EHgy2.js +0 -16
  147. package/_baseFlatten-Bfr_Molw.js +0 -72
  148. package/_baseGet-DSZygzyq.js +0 -79
  149. package/_baseIsEqual-VgvaAFZG.js +0 -147
  150. package/_baseIteratee-Dbfsw5z8.js +0 -95
  151. package/_baseSlice-M5RKzt1A.js +0 -10
  152. package/_baseSum-wEbgNeUs.js +0 -10
  153. package/_baseUniq-BJcj69PL.js +0 -79
  154. package/_commonjsHelpers-DaMA6jEr.js +0 -8
  155. package/_createAggregator-k3TuAnxT.js +0 -53
  156. package/_getPrototype-Cr1Mk7BC.js +0 -5
  157. package/_getTag-CK2Sffaq.js +0 -90
  158. package/_isIterateeCall-DkJP7Rbx.js +0 -13
  159. package/_setToArray-C7yMOeww.js +0 -29
  160. package/cloneDeep-CF8TtLHr.js +0 -8
  161. package/countBy-CdYegFSu.js +0 -8
  162. package/debounce-DryYcbJ4.js +0 -56
  163. package/get-CH7kz5Ix.js +0 -8
  164. package/groupBy-br8xmD2R.js +0 -8
  165. package/iconify-BBckr5AQ.js +0 -1263
  166. package/identity-ByMq8VxU.js +0 -6
  167. package/index-BHAe_V9n.js +0 -12768
  168. package/index-BK-zfYhR.js +0 -358
  169. package/index-CA5CUNZO.js +0 -975
  170. package/index-Dj5C04IX.js +0 -568
  171. package/index-p5_wX7q1.js +0 -11729
  172. package/isNil-CjWwlQS3.js +0 -6
  173. package/isObject-B53jY8Qg.js +0 -7
  174. package/isObjectLike-BatpeCIi.js +0 -29
  175. package/isSymbol-C3_SC0Qp.js +0 -8
  176. package/last-7CdUxN0r.js +0 -7
  177. package/maxBy-Bc0dYHcO.js +0 -8
  178. package/sortBy-DY2JBf9n.js +0 -75
  179. package/sumBy-DuMASLPd.js +0 -8
  180. package/toFinite-BMy6GObD.js +0 -14
  181. package/toNumber-YVhnnJv4.js +0 -31
  182. package/useClueTypeConfig-Ct9Ygter.js +0 -2292
  183. package/utils-DmwSUrum.js +0 -129
@@ -0,0 +1,549 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { a as addAPIProvider } from "./iconify-CXMreGTg.js";
3
+ import { b as useClueTypeConfig, a as api, p as post, u as uniq } from "./useClueTypeConfig-Z1LFp01b.js";
4
+ import { clueDebugLogger } from "./utils/loggerUtil.js";
5
+ import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
6
+ import { t as toFinite } from "./toFinite-Bc55msYj.js";
7
+ import { d as debounce } from "./debounce-bV0h5FC5.js";
8
+ import { g as groupBy } from "./groupBy-xqz-n0Vd.js";
9
+ import { b as baseIteratee } from "./_baseIteratee-avi7MX2o.js";
10
+ import { b as baseUniq } from "./_baseUniq-BI9GIHMF.js";
11
+ import { useContext, useState, useMemo, useCallback, useRef, useEffect } from "react";
12
+ import { c as createContext } from "./index-AMfoEg_6.js";
13
+ import { ClueDatabaseContext } from "./hooks/ClueDatabaseContext.js";
14
+ import useClueConfig from "./hooks/useClueConfig.js";
15
+ function toInteger(value) {
16
+ var result = toFinite(value), remainder = result % 1;
17
+ return result === result ? remainder ? result - remainder : result : 0;
18
+ }
19
+ var nativeCeil = Math.ceil, nativeMax = Math.max;
20
+ function chunk(array, size, guard) {
21
+ if (size === void 0) {
22
+ size = 1;
23
+ } else {
24
+ size = nativeMax(toInteger(size), 0);
25
+ }
26
+ var length = array == null ? 0 : array.length;
27
+ if (!length || size < 1) {
28
+ return [];
29
+ }
30
+ var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
31
+ while (index < length) {
32
+ result[resIndex++] = baseSlice(array, index, index += size);
33
+ }
34
+ return result;
35
+ }
36
+ function uniqBy(array, iteratee) {
37
+ return array && array.length ? baseUniq(array, baseIteratee(iteratee)) : [];
38
+ }
39
+ let getRandomValues;
40
+ const rnds8 = new Uint8Array(16);
41
+ function rng() {
42
+ if (!getRandomValues) {
43
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
44
+ if (!getRandomValues) {
45
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
46
+ }
47
+ }
48
+ return getRandomValues(rnds8);
49
+ }
50
+ const byteToHex = [];
51
+ for (let i = 0; i < 256; ++i) {
52
+ byteToHex.push((i + 256).toString(16).slice(1));
53
+ }
54
+ function unsafeStringify(arr, offset = 0) {
55
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
56
+ }
57
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
58
+ const native = {
59
+ randomUUID
60
+ };
61
+ function v4(options, buf, offset) {
62
+ if (native.randomUUID && true && !options) {
63
+ return native.randomUUID();
64
+ }
65
+ options = options || {};
66
+ const rnds = options.random || (options.rng || rng)();
67
+ rnds[6] = rnds[6] & 15 | 64;
68
+ rnds[8] = rnds[8] & 63 | 128;
69
+ return unsafeStringify(rnds);
70
+ }
71
+ const ClueEnrichContext = createContext(null);
72
+ const ClueEnrichProvider = ({
73
+ children,
74
+ classification: _defaultClassification,
75
+ baseURL,
76
+ getToken,
77
+ onNetworkCall,
78
+ pickSources,
79
+ chunkSize = 15,
80
+ maxRequestCount = 4,
81
+ defaultTimeout = 5,
82
+ enabled = true,
83
+ ready = false,
84
+ publicIconify = true,
85
+ skipConfigCall = false,
86
+ customIconify: _customIconify,
87
+ debugLogging = true
88
+ }) => {
89
+ var _a, _b, _c, _d, _e;
90
+ const clueConfig = useClueConfig();
91
+ const database = useContext(ClueDatabaseContext);
92
+ const [configuredDefaultClassification, setConfiguredDefaultClassification] = useState(null);
93
+ const defaultClassification = useMemo(
94
+ () => {
95
+ var _a2, _b2;
96
+ return configuredDefaultClassification ?? _defaultClassification ?? ((_b2 = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b2.RESTRICTED);
97
+ },
98
+ [_defaultClassification, (_b = (_a = clueConfig.config) == null ? void 0 : _a.c12nDef) == null ? void 0 : _b.RESTRICTED, configuredDefaultClassification]
99
+ );
100
+ const setDefaultClassification = useCallback(
101
+ (func) => {
102
+ var _a2;
103
+ return setConfiguredDefaultClassification(func((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef));
104
+ },
105
+ [(_c = clueConfig.config) == null ? void 0 : _c.c12nDef]
106
+ );
107
+ const [isReady, setIsReady] = useState(ready);
108
+ const runningRequestCount = useRef(0);
109
+ const [sources, setSources] = useState([]);
110
+ const { availableSources, typesDetection, supportedTypes } = useClueTypeConfig(
111
+ enabled && isReady,
112
+ baseURL,
113
+ debugLogging,
114
+ getToken,
115
+ onNetworkCall
116
+ );
117
+ useEffect(() => {
118
+ if (skipConfigCall || !enabled || !isReady) {
119
+ return;
120
+ }
121
+ const headers = {};
122
+ const token = getToken == null ? void 0 : getToken();
123
+ if (token) {
124
+ headers.Authorization = `Bearer ${token}`;
125
+ }
126
+ let requestConfig = { baseURL, headers };
127
+ if (onNetworkCall) {
128
+ requestConfig = onNetworkCall(requestConfig);
129
+ }
130
+ api.configs.get(requestConfig).then(clueConfig.setConfig);
131
+ }, [baseURL, onNetworkCall, skipConfigCall, isReady]);
132
+ const [customIconify, setCustomIconify] = useState(_customIconify);
133
+ useEffect(() => {
134
+ if (_customIconify) {
135
+ setCustomIconify(_customIconify);
136
+ }
137
+ }, [_customIconify]);
138
+ useEffect(() => {
139
+ if (publicIconify) {
140
+ return;
141
+ }
142
+ let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
143
+ if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
144
+ iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
145
+ }
146
+ if (iconURL) {
147
+ clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
148
+ addAPIProvider("", {
149
+ resources: [iconURL]
150
+ });
151
+ }
152
+ }, [baseURL, customIconify, debugLogging, publicIconify]);
153
+ const _addEntries = useCallback(
154
+ async (entries) => {
155
+ const newRecords = [];
156
+ for (const entry of entries) {
157
+ const { latency, source, type, value: value2, items, error } = entry;
158
+ if (error) {
159
+ newRecords.push({
160
+ id: v4(),
161
+ source,
162
+ type,
163
+ value: value2,
164
+ annotations: [],
165
+ classification: defaultClassification,
166
+ latency,
167
+ count: 0,
168
+ error
169
+ });
170
+ }
171
+ for (const item of items) {
172
+ const { classification, count, link, annotations } = item;
173
+ await database.selectors.find({ selector: { type, value: value2, source, classification } }).incrementalRemove();
174
+ const record = {
175
+ id: v4(),
176
+ source,
177
+ type,
178
+ value: value2,
179
+ annotations,
180
+ classification,
181
+ latency,
182
+ count,
183
+ link,
184
+ error
185
+ };
186
+ if (newRecords.some((_entry) => _entry.id === record.id)) {
187
+ record.id = v4();
188
+ }
189
+ newRecords.push(record);
190
+ }
191
+ }
192
+ const result = await database.selectors.bulkInsert(newRecords);
193
+ if (result.error.length > 0) {
194
+ console.warn("Errors on upsert:");
195
+ result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
196
+ }
197
+ },
198
+ [database, defaultClassification]
199
+ );
200
+ const enrich = useCallback(
201
+ async (type, value2, _options = {}) => {
202
+ var _a2, _b2;
203
+ if (!type || !value2) {
204
+ console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
205
+ return {};
206
+ }
207
+ const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
208
+ const options = {
209
+ timeout: defaultTimeout,
210
+ force: false,
211
+ includeRaw: false,
212
+ noCache: false,
213
+ classification: defaultClassification,
214
+ sources: _sources,
215
+ ..._options
216
+ };
217
+ const headers = {};
218
+ const token = getToken == null ? void 0 : getToken();
219
+ if (token) {
220
+ headers.Authorization = `Bearer ${token}`;
221
+ }
222
+ let requestConfig = { baseURL, headers };
223
+ if (onNetworkCall) {
224
+ requestConfig = onNetworkCall(requestConfig);
225
+ }
226
+ const selector = {
227
+ type,
228
+ value: value2,
229
+ classification: options.classification
230
+ };
231
+ let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({ selector: { ...selector } }).exec());
232
+ if (!statusRecord) {
233
+ statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.insert({
234
+ id: v4(),
235
+ type: selector.type,
236
+ value: selector.value,
237
+ classification: selector.classification ?? defaultClassification,
238
+ status: "in-progress"
239
+ }));
240
+ } else {
241
+ await statusRecord.incrementalPatch({ status: "in-progress" });
242
+ }
243
+ try {
244
+ const enrichmentResult = await post([selector], options.sources, options, requestConfig);
245
+ const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
246
+ await _addEntries(Object.values(enrichData));
247
+ return enrichData;
248
+ } catch (e) {
249
+ console.error(e);
250
+ return {};
251
+ } finally {
252
+ await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
253
+ }
254
+ },
255
+ [
256
+ _addEntries,
257
+ availableSources,
258
+ baseURL,
259
+ database,
260
+ defaultClassification,
261
+ defaultTimeout,
262
+ getToken,
263
+ onNetworkCall,
264
+ pickSources,
265
+ sources
266
+ ]
267
+ );
268
+ const bulkEnrich = useCallback(
269
+ async (bulkRequest, _options) => {
270
+ var _a2, _b2;
271
+ const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
272
+ const options = {
273
+ timeout: defaultTimeout,
274
+ includeRaw: false,
275
+ noCache: false,
276
+ classification: defaultClassification,
277
+ sources: _sources,
278
+ ..._options
279
+ };
280
+ const headers = {};
281
+ const token = getToken == null ? void 0 : getToken();
282
+ if (token) {
283
+ headers.Authorization = `Bearer ${token}`;
284
+ }
285
+ let requestConfig = { baseURL, headers };
286
+ if (onNetworkCall) {
287
+ requestConfig = onNetworkCall(requestConfig);
288
+ }
289
+ const statuses = [];
290
+ for (const selector of bulkRequest) {
291
+ const query = { type: selector.type, value: selector.value, classification: options.classification };
292
+ let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({
293
+ selector: query
294
+ }).incrementalPatch({
295
+ status: "in-progress"
296
+ }));
297
+ if (!statusRecord) {
298
+ statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.insert({
299
+ id: v4(),
300
+ ...query,
301
+ status: "in-progress",
302
+ sources: options.sources
303
+ }));
304
+ }
305
+ if (statusRecord) {
306
+ statuses.push(statusRecord.toMutableJSON());
307
+ }
308
+ }
309
+ try {
310
+ const result = await post(bulkRequest, options.sources, options, requestConfig);
311
+ const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
312
+ await _addEntries(entries);
313
+ return result;
314
+ } catch (e) {
315
+ console.error(e);
316
+ return {};
317
+ } finally {
318
+ database.status.bulkUpsert(
319
+ uniqBy(statuses, (_record) => _record.id).map((record) => {
320
+ record.status = "complete";
321
+ return record;
322
+ })
323
+ );
324
+ }
325
+ },
326
+ [
327
+ pickSources,
328
+ sources,
329
+ availableSources,
330
+ defaultTimeout,
331
+ defaultClassification,
332
+ getToken,
333
+ baseURL,
334
+ onNetworkCall,
335
+ database,
336
+ _addEntries
337
+ ]
338
+ );
339
+ const enrichFailedEnrichments = useCallback(async () => {
340
+ if (!(database == null ? void 0 : database.selectors) || database.selectors.closed) {
341
+ return;
342
+ }
343
+ const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
344
+ const byClassification = groupBy(failedEnrichments, "classification");
345
+ const newRequests = [];
346
+ for (const [classification, selectors] of Object.entries(byClassification)) {
347
+ const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
348
+ Object.values(bySelector).forEach((records) => {
349
+ newRequests.push({
350
+ id: v4(),
351
+ type: records[0].type,
352
+ value: records[0].value,
353
+ classification,
354
+ sources: uniq(records.map((_record) => _record.source)).sort(),
355
+ status: "pending"
356
+ });
357
+ });
358
+ }
359
+ await database.status.bulkInsert(newRequests);
360
+ await database.selectors.bulkRemove(failedEnrichments);
361
+ }, [database]);
362
+ const enrichQueued = useMemo(
363
+ () => debounce(
364
+ async () => {
365
+ if (!(database == null ? void 0 : database.status)) {
366
+ return;
367
+ } else if (database.status.closed) {
368
+ console.warn("Status database is closed, will not enrich");
369
+ return;
370
+ }
371
+ const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
372
+ if (selectors.length < 1) {
373
+ return;
374
+ }
375
+ const chunks = chunk(selectors, chunkSize);
376
+ clueDebugLogger(
377
+ `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
378
+ debugLogging
379
+ );
380
+ await Promise.all(
381
+ // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
382
+ // backend, both on the pod level and kubernetes level
383
+ chunks.map(async (reqsChunk) => {
384
+ let _interval = null;
385
+ if (runningRequestCount.current <= maxRequestCount) {
386
+ runningRequestCount.current += 1;
387
+ } else {
388
+ let startOfWait = Date.now();
389
+ await new Promise((res) => {
390
+ _interval = setInterval(() => {
391
+ clueDebugLogger(
392
+ `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
393
+ debugLogging
394
+ );
395
+ if (runningRequestCount.current < maxRequestCount) {
396
+ res();
397
+ }
398
+ }, 400);
399
+ }).finally(() => {
400
+ runningRequestCount.current += 1;
401
+ clearInterval(_interval);
402
+ });
403
+ }
404
+ try {
405
+ const options = {};
406
+ const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
407
+ if (_sources.length > 0) {
408
+ options.sources = _sources;
409
+ }
410
+ await bulkEnrich(
411
+ reqsChunk.map((record) => record.toSelector()),
412
+ options
413
+ );
414
+ await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
415
+ } catch (e) {
416
+ console.error(e);
417
+ } finally {
418
+ runningRequestCount.current -= 1;
419
+ if (_interval) {
420
+ clearInterval(_interval);
421
+ }
422
+ }
423
+ })
424
+ );
425
+ },
426
+ 200,
427
+ { maxWait: 500, leading: false }
428
+ ),
429
+ [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
430
+ );
431
+ useEffect(() => {
432
+ {
433
+ return;
434
+ }
435
+ }, [database, debugLogging]);
436
+ useEffect(() => {
437
+ if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
438
+ return;
439
+ }
440
+ if (database == null ? void 0 : database.status.closed) {
441
+ console.warn("Status collection is closed");
442
+ return;
443
+ }
444
+ const observer = database.status.find({
445
+ selector: {
446
+ status: "pending"
447
+ }
448
+ }).$.subscribe(() => enrichQueued());
449
+ return () => {
450
+ try {
451
+ observer == null ? void 0 : observer.unsubscribe();
452
+ } catch (e) {
453
+ console.warn(e);
454
+ }
455
+ };
456
+ }, [enabled, isReady, database, debugLogging, enrichQueued, (_d = database == null ? void 0 : database.status) == null ? void 0 : _d.closed]);
457
+ const queueEnrich = useCallback(
458
+ async (type, value2, classification) => {
459
+ var _a2, _b2;
460
+ if (!type) {
461
+ throw new Error("Type cannot be null");
462
+ }
463
+ if (!value2) {
464
+ throw new Error("Value cannot be null");
465
+ }
466
+ if (!database.status || database.status.closed) {
467
+ console.warn("status collection is closed");
468
+ return;
469
+ }
470
+ const query = { type, value: value2, classification: classification ?? defaultClassification };
471
+ let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({
472
+ selector: query
473
+ }).exec());
474
+ if (!statusRecord) {
475
+ statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.queueInsert({
476
+ id: v4(),
477
+ ...query,
478
+ status: "pending"
479
+ }));
480
+ }
481
+ return statusRecord;
482
+ },
483
+ [defaultClassification, database]
484
+ );
485
+ const guessType = useCallback(
486
+ (value2) => {
487
+ var _a2, _b2;
488
+ if (!value2) {
489
+ return null;
490
+ }
491
+ const types = Object.entries(typesDetection);
492
+ const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
493
+ if (regularCheck) {
494
+ return regularCheck;
495
+ }
496
+ const lowercased = value2.toLowerCase();
497
+ const lowercaseCheck = (_b2 = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b2[0];
498
+ if (lowercaseCheck) {
499
+ return lowercaseCheck;
500
+ }
501
+ return null;
502
+ },
503
+ [typesDetection]
504
+ );
505
+ const value = useMemo(
506
+ () => {
507
+ var _a2;
508
+ return {
509
+ bulkEnrich,
510
+ enrich,
511
+ enrichFailedEnrichments,
512
+ sources,
513
+ setSources,
514
+ typesDetection,
515
+ supportedTypes,
516
+ availableSources,
517
+ guessType,
518
+ queueEnrich,
519
+ setCustomIconify,
520
+ setDefaultClassification,
521
+ setReady: setIsReady,
522
+ defaultClassification,
523
+ ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
524
+ };
525
+ },
526
+ [
527
+ bulkEnrich,
528
+ enrich,
529
+ enrichFailedEnrichments,
530
+ sources,
531
+ typesDetection,
532
+ supportedTypes,
533
+ availableSources,
534
+ guessType,
535
+ queueEnrich,
536
+ setDefaultClassification,
537
+ defaultClassification,
538
+ isReady,
539
+ database,
540
+ (_e = clueConfig.config) == null ? void 0 : _e.c12nDef
541
+ ]
542
+ );
543
+ return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
544
+ };
545
+ export {
546
+ ClueEnrichContext as C,
547
+ ClueEnrichProvider as a,
548
+ uniqBy as u
549
+ };
@@ -0,0 +1,9 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { memo } from "react";
3
+ const FlexOne = ({ children = null }) => {
4
+ return /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children });
5
+ };
6
+ const FlexOne$1 = memo(FlexOne);
7
+ export {
8
+ FlexOne$1 as F
9
+ };