@cccsaurora/clue-ui 1.2.4 → 1.2.5-dev.298

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 (188) hide show
  1. package/ActionForm-D6gYuFRR.js +5970 -0
  2. package/AnnotationDetails-Zx4pjBiN.js +175 -0
  3. package/AnnotationPreview-Dmz7taAU.js +188 -0
  4. package/ClueEnrichContext-CJEJxrgs.js +541 -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.d.ts +10 -2
  79. package/hooks/ClueActionContext.js +6 -6
  80. package/hooks/ClueComponentContext.js +29 -23
  81. package/hooks/ClueConfigProvider.js +14 -12
  82. package/hooks/ClueDatabaseContext.js +19 -13
  83. package/hooks/ClueEnrichContext.js +8 -8
  84. package/hooks/ClueFetcherContext.js +83 -56
  85. package/hooks/ClueGroupContext.js +17 -14
  86. package/hooks/CluePopupContext.js +5 -5
  87. package/hooks/ClueProvider.js +12 -10
  88. package/hooks/selectors.js +7 -7
  89. package/hooks/useActionResult.d.ts +1 -0
  90. package/hooks/useActionResult.js +3 -3
  91. package/hooks/useAnnotations.js +47 -31
  92. package/hooks/useClue.js +6 -4
  93. package/hooks/useClueActions.js +3 -3
  94. package/hooks/useClueConfig.js +6 -4
  95. package/hooks/useClueTypeConfig.js +3 -3
  96. package/hooks/useComparator.js +722 -435
  97. package/hooks/useErrors.js +22 -18
  98. package/hooks/useFetcherResult.d.ts +1 -0
  99. package/hooks/useFetcherResult.js +33 -24
  100. package/hooks/useMyHighlights.js +66 -36
  101. package/hooks/useMyLocalStorage.js +66 -37
  102. package/iconify-CXMreGTg.js +1782 -0
  103. package/icons/Action.js +66 -49
  104. package/icons/Assessment.js +85 -69
  105. package/icons/Context.js +77 -63
  106. package/icons/Opinion.js +76 -60
  107. package/icons/iconMap.js +2 -2
  108. package/identity-CPGTqrE4.js +6 -0
  109. package/index-AMfoEg_6.js +696 -0
  110. package/index-B6C2a_Lg.js +1172 -0
  111. package/index-C12gPw2W.js +17698 -0
  112. package/index-DCKkHTvx.js +15750 -0
  113. package/index-JcKyZeoY.js +465 -0
  114. package/isNil-CIubwp4T.js +6 -0
  115. package/isObject-FTY-5JQX.js +7 -0
  116. package/isObjectLike-OAgjjZye.js +48 -0
  117. package/isSymbol-Xd2FsJyp.js +8 -0
  118. package/last-CUCl67Im.js +7 -0
  119. package/main.js +60 -60
  120. package/maxBy-IKHzFrCS.js +8 -0
  121. package/package.json +1 -1
  122. package/sortBy-DfSj8IoJ.js +96 -0
  123. package/sumBy-D-hb_NY-.js +8 -0
  124. package/text/Frequency.js +42 -23
  125. package/toFinite-Bc55msYj.js +16 -0
  126. package/toNumber-DPxy1FBy.js +39 -0
  127. package/types/RunningActionData.d.ts +1 -0
  128. package/types/WithActionData.d.ts +1 -0
  129. package/useClueTypeConfig-Z1LFp01b.js +3289 -0
  130. package/utils/chain.js +92 -65
  131. package/utils/classificationParser.js +519 -256
  132. package/utils/constants.js +35 -10
  133. package/utils/graph.js +72 -45
  134. package/utils/hashUtil.js +7 -7
  135. package/utils/line.js +131 -81
  136. package/utils/loggerUtil.js +5 -3
  137. package/utils/sessionStorage.js +41 -27
  138. package/utils/time.js +423 -423
  139. package/utils/utils.js +9 -9
  140. package/utils/window.js +21 -10
  141. package/utils-HmNPuoDB.js +199 -0
  142. package/ActionForm-CwsfB99X.js +0 -4458
  143. package/AnnotationDetails-Bw2JdtTL.js +0 -160
  144. package/AnnotationPreview-BO7rVnOP.js +0 -140
  145. package/ClueEnrichContext-KqRuuWNS.js +0 -418
  146. package/FlexOne-BXWFOd1T.js +0 -6
  147. package/_MapCache-BiTi0iqu.js +0 -180
  148. package/_Uint8Array-BQNOM9Rr.js +0 -101
  149. package/_baseAssignValue-CNMLQZco.js +0 -20
  150. package/_baseClone-BnT-6pyM.js +0 -207
  151. package/_baseExtremum-Ca2EHgy2.js +0 -16
  152. package/_baseFlatten-Bfr_Molw.js +0 -72
  153. package/_baseGet-DSZygzyq.js +0 -79
  154. package/_baseIsEqual-VgvaAFZG.js +0 -147
  155. package/_baseIteratee-Dbfsw5z8.js +0 -95
  156. package/_baseSlice-M5RKzt1A.js +0 -10
  157. package/_baseSum-wEbgNeUs.js +0 -10
  158. package/_baseUniq-BJcj69PL.js +0 -79
  159. package/_commonjsHelpers-DaMA6jEr.js +0 -8
  160. package/_createAggregator-k3TuAnxT.js +0 -53
  161. package/_getPrototype-Cr1Mk7BC.js +0 -5
  162. package/_getTag-CK2Sffaq.js +0 -90
  163. package/_isIterateeCall-DkJP7Rbx.js +0 -13
  164. package/_setToArray-C7yMOeww.js +0 -29
  165. package/cloneDeep-CF8TtLHr.js +0 -8
  166. package/countBy-CdYegFSu.js +0 -8
  167. package/debounce-DryYcbJ4.js +0 -56
  168. package/get-CH7kz5Ix.js +0 -8
  169. package/groupBy-br8xmD2R.js +0 -8
  170. package/iconify-BBckr5AQ.js +0 -1263
  171. package/identity-ByMq8VxU.js +0 -6
  172. package/index-BHAe_V9n.js +0 -12768
  173. package/index-BK-zfYhR.js +0 -358
  174. package/index-CA5CUNZO.js +0 -975
  175. package/index-Dj5C04IX.js +0 -568
  176. package/index-p5_wX7q1.js +0 -11729
  177. package/isNil-CjWwlQS3.js +0 -6
  178. package/isObject-B53jY8Qg.js +0 -7
  179. package/isObjectLike-BatpeCIi.js +0 -29
  180. package/isSymbol-C3_SC0Qp.js +0 -8
  181. package/last-7CdUxN0r.js +0 -7
  182. package/maxBy-Bc0dYHcO.js +0 -8
  183. package/sortBy-DY2JBf9n.js +0 -75
  184. package/sumBy-DuMASLPd.js +0 -8
  185. package/toFinite-BMy6GObD.js +0 -14
  186. package/toNumber-YVhnnJv4.js +0 -31
  187. package/useClueTypeConfig-Ct9Ygter.js +0 -2292
  188. package/utils-DmwSUrum.js +0 -129
@@ -0,0 +1,541 @@
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
+ const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
271
+ const options = {
272
+ timeout: defaultTimeout,
273
+ includeRaw: false,
274
+ noCache: false,
275
+ classification: defaultClassification,
276
+ sources: _sources,
277
+ ..._options
278
+ };
279
+ const headers = {};
280
+ const token = getToken == null ? void 0 : getToken();
281
+ if (token) {
282
+ headers.Authorization = `Bearer ${token}`;
283
+ }
284
+ let requestConfig = { baseURL, headers };
285
+ if (onNetworkCall) {
286
+ requestConfig = onNetworkCall(requestConfig);
287
+ }
288
+ const statuses = [];
289
+ for (const selector of bulkRequest) {
290
+ const query = { type: selector.type, value: selector.value, classification: options.classification };
291
+ let statusRecord = await database.status.findOne({
292
+ selector: query
293
+ }).incrementalPatch({
294
+ status: "in-progress"
295
+ });
296
+ if (!statusRecord) {
297
+ statusRecord = await database.status.insert({
298
+ id: v4(),
299
+ ...query,
300
+ status: "in-progress",
301
+ sources: options.sources
302
+ });
303
+ }
304
+ statuses.push(statusRecord.toMutableJSON());
305
+ }
306
+ try {
307
+ const result = await post(bulkRequest, options.sources, options, requestConfig);
308
+ const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
309
+ await _addEntries(entries);
310
+ return result;
311
+ } catch (e) {
312
+ console.error(e);
313
+ return {};
314
+ } finally {
315
+ database.status.bulkUpsert(
316
+ uniqBy(statuses, (_record) => _record.id).map((record) => {
317
+ record.status = "complete";
318
+ return record;
319
+ })
320
+ );
321
+ }
322
+ },
323
+ [
324
+ pickSources,
325
+ sources,
326
+ availableSources,
327
+ defaultTimeout,
328
+ defaultClassification,
329
+ getToken,
330
+ baseURL,
331
+ onNetworkCall,
332
+ database,
333
+ _addEntries
334
+ ]
335
+ );
336
+ const enrichFailedEnrichments = useCallback(async () => {
337
+ if (!(database == null ? void 0 : database.selectors) || database.selectors.closed) {
338
+ return;
339
+ }
340
+ const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
341
+ const byClassification = groupBy(failedEnrichments, "classification");
342
+ const newRequests = [];
343
+ for (const [classification, selectors] of Object.entries(byClassification)) {
344
+ const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
345
+ Object.values(bySelector).forEach((records) => {
346
+ newRequests.push({
347
+ id: v4(),
348
+ type: records[0].type,
349
+ value: records[0].value,
350
+ classification,
351
+ sources: uniq(records.map((_record) => _record.source)).sort(),
352
+ status: "pending"
353
+ });
354
+ });
355
+ }
356
+ await database.status.bulkInsert(newRequests);
357
+ await database.selectors.bulkRemove(failedEnrichments);
358
+ }, [database]);
359
+ const enrichQueued = useMemo(
360
+ () => debounce(
361
+ async () => {
362
+ if (!(database == null ? void 0 : database.status)) {
363
+ return;
364
+ } else if (database.status.closed) {
365
+ console.warn("Status database is closed, will not enrich");
366
+ return;
367
+ }
368
+ const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
369
+ if (selectors.length < 1) {
370
+ return;
371
+ }
372
+ const chunks = chunk(selectors, chunkSize);
373
+ clueDebugLogger(
374
+ `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
375
+ debugLogging
376
+ );
377
+ await Promise.all(
378
+ // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
379
+ // backend, both on the pod level and kubernetes level
380
+ chunks.map(async (reqsChunk) => {
381
+ let _interval = null;
382
+ if (runningRequestCount.current <= maxRequestCount) {
383
+ runningRequestCount.current += 1;
384
+ } else {
385
+ let startOfWait = Date.now();
386
+ await new Promise((res) => {
387
+ _interval = setInterval(() => {
388
+ clueDebugLogger(
389
+ `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
390
+ debugLogging
391
+ );
392
+ if (runningRequestCount.current < maxRequestCount) {
393
+ res();
394
+ }
395
+ }, 400);
396
+ }).finally(() => {
397
+ runningRequestCount.current += 1;
398
+ clearInterval(_interval);
399
+ });
400
+ }
401
+ try {
402
+ const options = {};
403
+ const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
404
+ if (_sources.length > 0) {
405
+ options.sources = _sources;
406
+ }
407
+ await bulkEnrich(
408
+ reqsChunk.map((record) => record.toSelector()),
409
+ options
410
+ );
411
+ await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
412
+ } catch (e) {
413
+ console.error(e);
414
+ } finally {
415
+ runningRequestCount.current -= 1;
416
+ if (_interval) {
417
+ clearInterval(_interval);
418
+ }
419
+ }
420
+ })
421
+ );
422
+ },
423
+ 200,
424
+ { maxWait: 500, leading: false }
425
+ ),
426
+ [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
427
+ );
428
+ useEffect(() => {
429
+ {
430
+ return;
431
+ }
432
+ }, [database, debugLogging]);
433
+ useEffect(() => {
434
+ if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
435
+ return;
436
+ }
437
+ if (database == null ? void 0 : database.status.closed) {
438
+ console.warn("Status collection is closed");
439
+ return;
440
+ }
441
+ const observer = database.status.find({
442
+ selector: {
443
+ status: "pending"
444
+ }
445
+ }).$.subscribe(() => enrichQueued());
446
+ return () => {
447
+ try {
448
+ observer == null ? void 0 : observer.unsubscribe();
449
+ } catch (e) {
450
+ console.warn(e);
451
+ }
452
+ };
453
+ }, [enabled, isReady, database, debugLogging, enrichQueued, (_d = database == null ? void 0 : database.status) == null ? void 0 : _d.closed]);
454
+ const queueEnrich = useCallback(
455
+ async (type, value2, classification) => {
456
+ if (!type) {
457
+ throw new Error("Type cannot be null");
458
+ }
459
+ if (!value2) {
460
+ throw new Error("Value cannot be null");
461
+ }
462
+ const query = { type, value: value2, classification: classification ?? defaultClassification };
463
+ let statusRecord = await database.status.findOne({
464
+ selector: query
465
+ }).exec();
466
+ if (!statusRecord) {
467
+ statusRecord = await database.status.queueInsert({
468
+ id: v4(),
469
+ ...query,
470
+ status: "pending"
471
+ });
472
+ }
473
+ return statusRecord;
474
+ },
475
+ [defaultClassification, database]
476
+ );
477
+ const guessType = useCallback(
478
+ (value2) => {
479
+ var _a2, _b2;
480
+ if (!value2) {
481
+ return null;
482
+ }
483
+ const types = Object.entries(typesDetection);
484
+ const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
485
+ if (regularCheck) {
486
+ return regularCheck;
487
+ }
488
+ const lowercased = value2.toLowerCase();
489
+ const lowercaseCheck = (_b2 = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b2[0];
490
+ if (lowercaseCheck) {
491
+ return lowercaseCheck;
492
+ }
493
+ return null;
494
+ },
495
+ [typesDetection]
496
+ );
497
+ const value = useMemo(
498
+ () => {
499
+ var _a2;
500
+ return {
501
+ bulkEnrich,
502
+ enrich,
503
+ enrichFailedEnrichments,
504
+ sources,
505
+ setSources,
506
+ typesDetection,
507
+ supportedTypes,
508
+ availableSources,
509
+ guessType,
510
+ queueEnrich,
511
+ setCustomIconify,
512
+ setDefaultClassification,
513
+ setReady: setIsReady,
514
+ defaultClassification,
515
+ ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
516
+ };
517
+ },
518
+ [
519
+ bulkEnrich,
520
+ enrich,
521
+ enrichFailedEnrichments,
522
+ sources,
523
+ typesDetection,
524
+ supportedTypes,
525
+ availableSources,
526
+ guessType,
527
+ queueEnrich,
528
+ setDefaultClassification,
529
+ defaultClassification,
530
+ isReady,
531
+ database,
532
+ (_e = clueConfig.config) == null ? void 0 : _e.c12nDef
533
+ ]
534
+ );
535
+ return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
536
+ };
537
+ export {
538
+ ClueEnrichContext as C,
539
+ ClueEnrichProvider as a,
540
+ uniqBy as u
541
+ };
@@ -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
+ };