@cccsaurora/clue-ui 1.3.0 → 1.4.0-dev.426

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 (224) hide show
  1. package/ActionForm-CqKcnDWC.js +6099 -0
  2. package/AnnotationDetails-BlPd3T8k.js +176 -0
  3. package/AnnotationPreview-Bl447SKT.js +188 -0
  4. package/ClueEnrichContext-B3YrTCaJ.js +567 -0
  5. package/FlexOne-BSYAhhtG.js +9 -0
  6. package/_MapCache-kuEY_iOH.js +220 -0
  7. package/_Set-BrSMTlHn.js +6 -0
  8. package/_Uint8Array-OPpgYQj7.js +123 -0
  9. package/_arrayIncludes-BNqL-9ZP.js +31 -0
  10. package/_arrayPush-CBkQqaE_.js +10 -0
  11. package/_baseAssignValue-CNUVPOBW.js +16 -0
  12. package/_baseClone-9FaRd1R2.js +287 -0
  13. package/_baseExtremum-wOGT4Dgw.js +18 -0
  14. package/_baseFlatten-Co6QHDlG.js +92 -0
  15. package/_baseGet-Cmp6FztG.js +109 -0
  16. package/_baseGetTag-Hj-0NTYF.js +44 -0
  17. package/_baseIsEqual-1CpU47TZ.js +211 -0
  18. package/_baseIteratee-BN7Vbe5g.js +126 -0
  19. package/_baseRest-BZ_hQ9PC.js +8 -0
  20. package/_baseSlice-GAv_YFTT.js +20 -0
  21. package/_baseSum-D0WC1dN0.js +13 -0
  22. package/_baseUniq-BnvS3JHL.js +63 -0
  23. package/_cacheHas-_aF2y2Xv.js +25 -0
  24. package/_commonjsHelpers-CUmg6egw.js +6 -0
  25. package/_createAggregator-BUZrP_is.js +63 -0
  26. package/_defineProperty-DolZLKmv.js +12 -0
  27. package/_getPrototype-Bb4gm-5m.js +5 -0
  28. package/_getTag-CML_cXiN.js +105 -0
  29. package/_isIterateeCall-B1IFEqVv.js +17 -0
  30. package/_setToArray-CqyqC8ib.js +10 -0
  31. package/cloneDeep-l3UkXG5M.js +8 -0
  32. package/components/AnnotationBody.js +49 -35
  33. package/components/AnnotationDetailPopover.js +36 -30
  34. package/components/AnnotationDetails.js +7 -7
  35. package/components/AnnotationEntry.js +35 -35
  36. package/components/AnnotationPreview.js +5 -5
  37. package/components/ClassificationChip.js +44 -23
  38. package/components/CountBadge.js +31 -26
  39. package/components/EnrichedCard.js +110 -97
  40. package/components/EnrichedChip.js +130 -105
  41. package/components/EnrichedTypography.js +133 -107
  42. package/components/ErrorBoundary.js +28 -24
  43. package/components/RetryFailedEnrichments.js +10 -9
  44. package/components/SourcePicker.js +57 -49
  45. package/components/actions/ActionForm.js +4 -4
  46. package/components/actions/ExecutePopover.js +75 -59
  47. package/components/actions/ResultModal.js +4 -4
  48. package/components/actions/form/schemaAdapter.js +39 -23
  49. package/components/actions/formats/FileResult.js +86 -59
  50. package/components/actions/formats/index.js +29 -25
  51. package/components/display/graph/ExpandMoreButton.js +10 -10
  52. package/components/display/graph/elements/NodeCard.js +111 -91
  53. package/components/display/graph/elements/NodeTag.js +15 -13
  54. package/components/display/graph/index.js +261 -202
  55. package/components/display/graph/visualizations/Leaf.js +89 -70
  56. package/components/display/graph/visualizations/cloud/index.js +98 -81
  57. package/components/display/graph/visualizations/icons/BaseIcon.js +26 -21
  58. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  59. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  60. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  61. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  62. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  63. package/components/display/graph/visualizations/icons/index.js +14 -13
  64. package/components/display/graph/visualizations/panels/NodePanel.js +10 -8
  65. package/components/display/graph/visualizations/tree/BundleLine.js +108 -81
  66. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  67. package/components/display/graph/visualizations/tree/index.js +408 -306
  68. package/components/display/icons/Iconified.js +27 -12
  69. package/components/display/json/index.js +4 -4
  70. package/components/display/markdown/index.js +8678 -5770
  71. package/components/enrichment/EnrichPopover.js +54 -46
  72. package/components/fetchers/Fetcher.js +166 -123
  73. package/components/fetchers/FetcherResultView.js +31 -27
  74. package/components/fetchers/PreviewModal.js +17 -16
  75. package/components/fetchers/StatusChip.js +21 -17
  76. package/components/group/Entry.js +13 -11
  77. package/components/group/Group.js +13 -10
  78. package/components/group/GroupControl.js +76 -65
  79. package/components/stats/QueryStatus.js +45 -32
  80. package/countBy-Bqcp3VCs.js +14 -0
  81. package/data/event.js +6 -4
  82. package/database/globals.js +2 -2
  83. package/database/index.js +3 -3
  84. package/database/replication.js +4 -4
  85. package/get-CdMThM8x.js +8 -0
  86. package/groupBy-BVV07EGQ.js +14 -0
  87. package/hooks/ClueActionContext.js +6 -6
  88. package/hooks/ClueComponentContext.js +29 -23
  89. package/hooks/ClueConfigProvider.js +14 -12
  90. package/hooks/ClueDatabaseContext.js +35 -23
  91. package/hooks/ClueEnrichContext.js +11 -11
  92. package/hooks/ClueFetcherContext.js +83 -56
  93. package/hooks/ClueGroupContext.js +17 -14
  94. package/hooks/CluePopupContext.js +5 -5
  95. package/hooks/ClueProvider.js +13 -11
  96. package/hooks/ClueUIPluginContext.js +49 -35
  97. package/hooks/selectors.js +7 -7
  98. package/hooks/useActionResult.js +3 -3
  99. package/hooks/useAnnotations.js +48 -32
  100. package/hooks/useClue.js +6 -4
  101. package/hooks/useClueActions.js +3 -3
  102. package/hooks/useClueConfig.js +6 -4
  103. package/hooks/useClueTypeConfig.js +49 -24
  104. package/hooks/useClueUIPlugins.js +8 -7
  105. package/hooks/useComparator.js +722 -435
  106. package/hooks/useErrors.js +22 -18
  107. package/hooks/useFetcherResult.js +33 -24
  108. package/hooks/useMyHighlights.js +66 -36
  109. package/hooks/useMyLocalStorage.js +66 -37
  110. package/iconify-DJxl6dC-.js +1789 -0
  111. package/icons/Action.js +66 -49
  112. package/icons/Assessment.js +85 -69
  113. package/icons/Context.js +77 -63
  114. package/icons/Opinion.js +76 -60
  115. package/icons/iconMap.js +2 -2
  116. package/identity-CPGTqrE4.js +6 -0
  117. package/index-CAvu7vwt.js +1172 -0
  118. package/index-CVUD9o3t.js +15768 -0
  119. package/index-DUEubgWN.js +464 -0
  120. package/index-Dj1N4IQP.js +9314 -0
  121. package/index-DpJxD74E.js +3272 -0
  122. package/index-_gpzM2Px.js +702 -0
  123. package/isArguments-CuYlEuhP.js +27 -0
  124. package/isArray-RJPfgWqI.js +4 -0
  125. package/isEmpty-BE656RUK.js +30 -0
  126. package/isNil-CIubwp4T.js +6 -0
  127. package/isObject-FTY-5JQX.js +7 -0
  128. package/isObjectLike-CeENW9FN.js +6 -0
  129. package/isSymbol-D_H4HPZQ.js +9 -0
  130. package/last-CUCl67Im.js +7 -0
  131. package/main.js +62 -62
  132. package/maxBy-BjjQmX5t.js +8 -0
  133. package/package.json +1 -1
  134. package/plugins/ClueUIPlugin.js +163 -96
  135. package/plugins/file/index.js +15 -15
  136. package/plugins/graph/index.js +29 -26
  137. package/plugins/image/index.js +28 -24
  138. package/plugins/json/index.js +21 -21
  139. package/plugins/markdown/index.js +18 -18
  140. package/plugins/registry.js +6 -6
  141. package/plugins/store.js +4 -4
  142. package/plugins/test/index.js +17 -17
  143. package/plugins/utils.js +13 -12
  144. package/replication--gLEZw8a.js +11777 -0
  145. package/sessionStorage-B68y-wnE.js +140 -0
  146. package/sortBy-B8JVsLQY.js +95 -0
  147. package/store-B9sjQbcS.js +2163 -0
  148. package/sumBy-D-HCzM2i.js +8 -0
  149. package/text/Frequency.js +42 -23
  150. package/toFinite-meZTg4Su.js +16 -0
  151. package/toNumber-B5JaA1vX.js +39 -0
  152. package/uniq-CahZPAwp.js +7 -0
  153. package/utils/chain.js +92 -65
  154. package/utils/classificationParser.js +519 -256
  155. package/utils/constants.js +37 -11
  156. package/utils/graph.js +72 -45
  157. package/utils/hashUtil.js +7 -7
  158. package/utils/line.js +131 -81
  159. package/utils/loggerUtil.js +5 -3
  160. package/utils/sessionStorage.js +7 -7
  161. package/utils/time.js +447 -427
  162. package/utils/utils.js +10 -10
  163. package/utils/window.js +21 -10
  164. package/utils-CEySTPtg.js +224 -0
  165. package/ActionForm-CHOSKfvu.js +0 -4403
  166. package/AnnotationDetails-Bqq6Ymmg.js +0 -160
  167. package/AnnotationPreview-CqXmC-j8.js +0 -140
  168. package/ClueEnrichContext-DL6aGe1k.js +0 -432
  169. package/FlexOne-BXWFOd1T.js +0 -6
  170. package/_MapCache-DRK-s2eK.js +0 -179
  171. package/_Set-DrS_bbSV.js +0 -6
  172. package/_Uint8Array-D9R2N9Lp.js +0 -98
  173. package/_arrayIncludes-Dcl_29E6.js +0 -25
  174. package/_arrayPush-DBJIuK2V.js +0 -8
  175. package/_baseAssignValue-Bx1cxHj5.js +0 -12
  176. package/_baseClone-DRhywkxm.js +0 -211
  177. package/_baseExtremum-DodEaEyF.js +0 -16
  178. package/_baseFlatten-CD9NgrYE.js +0 -72
  179. package/_baseGet-bVwDaGrA.js +0 -80
  180. package/_baseGetTag-CxDaTem-.js +0 -25
  181. package/_baseIsEqual-C-FKsm1J.js +0 -150
  182. package/_baseIteratee-D0FhC5bC.js +0 -95
  183. package/_baseRest-D_eW2E0d.js +0 -8
  184. package/_baseSlice-M5RKzt1A.js +0 -10
  185. package/_baseSum-wEbgNeUs.js +0 -10
  186. package/_baseUniq-D3N8igOm.js +0 -41
  187. package/_cacheHas-Wgl-hw34.js +0 -22
  188. package/_commonjsHelpers-C6fGbg64.js +0 -6
  189. package/_createAggregator-BVj8IAuF.js +0 -53
  190. package/_defineProperty-BZU4WKA3.js +0 -11
  191. package/_getPrototype-BGBCg-aX.js +0 -5
  192. package/_getTag-B7R9qBo7.js +0 -73
  193. package/_isIterateeCall-Dm0VTAYy.js +0 -13
  194. package/_setToArray-Ck4YZu0Z.js +0 -9
  195. package/cloneDeep-fV59zwUf.js +0 -8
  196. package/countBy-B3rNuG4T.js +0 -8
  197. package/get-Bil3mzRD.js +0 -8
  198. package/groupBy-CrJC7sGa.js +0 -8
  199. package/iconify-Ptb5dTKy.js +0 -1270
  200. package/identity-ByMq8VxU.js +0 -6
  201. package/index-BH-gBhtO.js +0 -2282
  202. package/index-BM9Sve5T.js +0 -571
  203. package/index-Cj4d5cGz.js +0 -357
  204. package/index-Dh2PP9h8.js +0 -11747
  205. package/index-DoFpWPHo.js +0 -975
  206. package/index-DzVIklWY.js +0 -6464
  207. package/isArguments-BWcXOE6a.js +0 -24
  208. package/isArray-WzO_os3q.js +0 -4
  209. package/isEmpty-DKxrY-_M.js +0 -22
  210. package/isNil-CjWwlQS3.js +0 -6
  211. package/isObject-B53jY8Qg.js +0 -7
  212. package/isObjectLike-CYbdrIBr.js +0 -6
  213. package/isSymbol-DE1Kcy2M.js +0 -9
  214. package/last-7CdUxN0r.js +0 -7
  215. package/maxBy-BOWDkL_D.js +0 -8
  216. package/replication-WkKbPdwG.js +0 -8453
  217. package/sessionStorage-DFMae61b.js +0 -90
  218. package/sortBy-BHe812lF.js +0 -74
  219. package/store-DClHBq7r.js +0 -1169
  220. package/sumBy-B7f_bP_k.js +0 -8
  221. package/toFinite-CBrE65MP.js +0 -14
  222. package/toNumber-CxmWey0f.js +0 -31
  223. package/uniq-B4UZ671_.js +0 -7
  224. package/utils-SpTOhPYl.js +0 -147
@@ -0,0 +1,567 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { a as addAPIProvider } from "./iconify-DJxl6dC-.js";
3
+ import { a as api, p as post } from "./index-DpJxD74E.js";
4
+ import { REPLICATORS } from "./database/globals.js";
5
+ import { clueDebugLogger } from "./utils/loggerUtil.js";
6
+ import { c as computeStatusId } from "./utils-CEySTPtg.js";
7
+ import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
8
+ import { t as toFinite } from "./toFinite-meZTg4Su.js";
9
+ import { d as debounce } from "./sessionStorage-B68y-wnE.js";
10
+ import { g as groupBy } from "./groupBy-BVV07EGQ.js";
11
+ import { u as uniq } from "./uniq-CahZPAwp.js";
12
+ import { b as baseIteratee } from "./_baseIteratee-BN7Vbe5g.js";
13
+ import { b as baseUniq } from "./_baseUniq-BnvS3JHL.js";
14
+ import { useContext, useState, useMemo, useCallback, useRef, useEffect } from "react";
15
+ import { c as createContext } from "./index-_gpzM2Px.js";
16
+ import { ClueDatabaseContext } from "./hooks/ClueDatabaseContext.js";
17
+ import useClueConfig from "./hooks/useClueConfig.js";
18
+ import useClueTypeConfig from "./hooks/useClueTypeConfig.js";
19
+ import { i as isEmpty } from "./isEmpty-BE656RUK.js";
20
+ function toInteger(value) {
21
+ var result = toFinite(value), remainder = result % 1;
22
+ return result === result ? remainder ? result - remainder : result : 0;
23
+ }
24
+ var nativeCeil = Math.ceil, nativeMax = Math.max;
25
+ function chunk(array, size, guard) {
26
+ if (size === void 0) {
27
+ size = 1;
28
+ } else {
29
+ size = nativeMax(toInteger(size), 0);
30
+ }
31
+ var length = array == null ? 0 : array.length;
32
+ if (!length || size < 1) {
33
+ return [];
34
+ }
35
+ var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
36
+ while (index < length) {
37
+ result[resIndex++] = baseSlice(array, index, index += size);
38
+ }
39
+ return result;
40
+ }
41
+ function uniqBy(array, iteratee) {
42
+ return array && array.length ? baseUniq(array, baseIteratee(iteratee)) : [];
43
+ }
44
+ let getRandomValues;
45
+ const rnds8 = new Uint8Array(16);
46
+ function rng() {
47
+ if (!getRandomValues) {
48
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
49
+ if (!getRandomValues) {
50
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
51
+ }
52
+ }
53
+ return getRandomValues(rnds8);
54
+ }
55
+ const byteToHex = [];
56
+ for (let i = 0; i < 256; ++i) {
57
+ byteToHex.push((i + 256).toString(16).slice(1));
58
+ }
59
+ function unsafeStringify(arr, offset = 0) {
60
+ 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]];
61
+ }
62
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
63
+ const native = {
64
+ randomUUID
65
+ };
66
+ function v4(options, buf, offset) {
67
+ if (native.randomUUID && true && !options) {
68
+ return native.randomUUID();
69
+ }
70
+ options = options || {};
71
+ const rnds = options.random || (options.rng || rng)();
72
+ rnds[6] = rnds[6] & 15 | 64;
73
+ rnds[8] = rnds[8] & 63 | 128;
74
+ return unsafeStringify(rnds);
75
+ }
76
+ const ClueEnrichContext = createContext(null);
77
+ const ClueEnrichProvider = ({
78
+ children,
79
+ classification: _defaultClassification,
80
+ baseURL,
81
+ getToken,
82
+ onNetworkCall,
83
+ pickSources,
84
+ chunkSize = 15,
85
+ maxRequestCount = 4,
86
+ defaultTimeout = 5,
87
+ enabled = true,
88
+ ready = false,
89
+ publicIconify = true,
90
+ skipConfigCall = false,
91
+ customIconify: _customIconify,
92
+ debugLogging = true
93
+ }) => {
94
+ var _a, _b, _c, _d, _e;
95
+ const clueConfig = useClueConfig();
96
+ const database = useContext(ClueDatabaseContext);
97
+ const [configuredDefaultClassification, setConfiguredDefaultClassification] = useState(null);
98
+ const defaultClassification = useMemo(
99
+ () => {
100
+ var _a2, _b2;
101
+ return configuredDefaultClassification ?? _defaultClassification ?? ((_b2 = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b2.RESTRICTED);
102
+ },
103
+ [_defaultClassification, (_b = (_a = clueConfig.config) == null ? void 0 : _a.c12nDef) == null ? void 0 : _b.RESTRICTED, configuredDefaultClassification]
104
+ );
105
+ const setDefaultClassification = useCallback(
106
+ (func) => {
107
+ var _a2;
108
+ return setConfiguredDefaultClassification(func((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef));
109
+ },
110
+ [(_c = clueConfig.config) == null ? void 0 : _c.c12nDef]
111
+ );
112
+ const [isReady, setIsReady] = useState(ready);
113
+ const runningRequestCount = useRef(0);
114
+ const [sources, setSources] = useState([]);
115
+ const { availableSources, typesDetection, supportedTypes } = useClueTypeConfig(
116
+ enabled && isReady,
117
+ baseURL,
118
+ debugLogging,
119
+ getToken,
120
+ onNetworkCall
121
+ );
122
+ useEffect(() => {
123
+ if (skipConfigCall || !enabled || !isReady) {
124
+ return;
125
+ }
126
+ const headers = {};
127
+ const token = getToken == null ? void 0 : getToken();
128
+ if (token) {
129
+ headers.Authorization = `Bearer ${token}`;
130
+ }
131
+ let requestConfig = { baseURL, headers };
132
+ if (onNetworkCall) {
133
+ requestConfig = onNetworkCall(requestConfig);
134
+ }
135
+ api.configs.get(requestConfig).then(clueConfig.setConfig);
136
+ }, [baseURL, onNetworkCall, skipConfigCall, isReady]);
137
+ useEffect(() => {
138
+ if (isReady) {
139
+ Object.values(REPLICATORS).forEach((replicator) => {
140
+ replicator.reSync();
141
+ replicator.start();
142
+ });
143
+ }
144
+ return () => {
145
+ Object.values(REPLICATORS).forEach((replicator) => {
146
+ replicator.pause();
147
+ });
148
+ };
149
+ }, [isReady]);
150
+ const [customIconify, setCustomIconify] = useState(_customIconify);
151
+ useEffect(() => {
152
+ if (_customIconify) {
153
+ setCustomIconify(_customIconify);
154
+ }
155
+ }, [_customIconify]);
156
+ useEffect(() => {
157
+ if (publicIconify) {
158
+ return;
159
+ }
160
+ let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
161
+ if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
162
+ iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
163
+ }
164
+ if (iconURL) {
165
+ clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
166
+ addAPIProvider("", {
167
+ resources: [iconURL]
168
+ });
169
+ }
170
+ }, [baseURL, customIconify, debugLogging, publicIconify]);
171
+ const _addEntries = useCallback(
172
+ async (entries) => {
173
+ const newRecords = [];
174
+ for (const entry of entries) {
175
+ const { latency, source, type, value: value2, items, error } = entry;
176
+ await database.selectors.find({ selector: { type, value: value2, source } }).incrementalRemove();
177
+ if (error) {
178
+ newRecords.push({
179
+ id: v4(),
180
+ source,
181
+ type,
182
+ value: value2,
183
+ annotations: [],
184
+ classification: defaultClassification,
185
+ latency,
186
+ count: 0,
187
+ error
188
+ });
189
+ }
190
+ for (const item of items) {
191
+ const { classification, count, link, annotations } = item;
192
+ const record = {
193
+ id: v4(),
194
+ source,
195
+ type,
196
+ value: value2,
197
+ annotations,
198
+ classification,
199
+ latency,
200
+ count,
201
+ link,
202
+ error
203
+ };
204
+ if (newRecords.some((_entry) => _entry.id === record.id)) {
205
+ record.id = v4();
206
+ }
207
+ newRecords.push(record);
208
+ }
209
+ }
210
+ const result = await database.selectors.bulkInsert(newRecords);
211
+ if (result.error.length > 0) {
212
+ console.warn("Errors on upsert:");
213
+ result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
214
+ }
215
+ },
216
+ [database, defaultClassification]
217
+ );
218
+ const enrich = useCallback(
219
+ async (type, value2, _options = {}) => {
220
+ var _a2;
221
+ if (!type || !value2) {
222
+ console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
223
+ return {};
224
+ }
225
+ const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
226
+ const options = {
227
+ timeout: defaultTimeout,
228
+ force: false,
229
+ includeRaw: false,
230
+ noCache: false,
231
+ classification: defaultClassification,
232
+ sources: _sources,
233
+ ..._options
234
+ };
235
+ const headers = {};
236
+ const token = getToken == null ? void 0 : getToken();
237
+ if (token) {
238
+ headers.Authorization = `Bearer ${token}`;
239
+ }
240
+ let requestConfig = { baseURL, headers };
241
+ if (onNetworkCall) {
242
+ requestConfig = onNetworkCall(requestConfig);
243
+ }
244
+ const selector = {
245
+ type,
246
+ value: value2,
247
+ classification: options.classification
248
+ };
249
+ let statusRecord = await database.status.findOne({ selector: { ...selector } }).exec();
250
+ if (!statusRecord) {
251
+ statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.insert({
252
+ id: await computeStatusId(selector.type, selector.value, selector.classification ?? defaultClassification),
253
+ type: selector.type,
254
+ value: selector.value,
255
+ classification: selector.classification ?? defaultClassification,
256
+ status: "in-progress"
257
+ }));
258
+ } else {
259
+ await statusRecord.incrementalPatch({ status: "in-progress" });
260
+ }
261
+ try {
262
+ const enrichmentResult = await post([selector], options.sources, options, requestConfig);
263
+ const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
264
+ await _addEntries(Object.values(enrichData));
265
+ return enrichData;
266
+ } catch (e) {
267
+ console.error(e);
268
+ return {};
269
+ } finally {
270
+ await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
271
+ }
272
+ },
273
+ [
274
+ _addEntries,
275
+ availableSources,
276
+ baseURL,
277
+ database,
278
+ defaultClassification,
279
+ defaultTimeout,
280
+ getToken,
281
+ onNetworkCall,
282
+ pickSources,
283
+ sources
284
+ ]
285
+ );
286
+ const bulkEnrich = useCallback(
287
+ async (bulkRequest, _options) => {
288
+ var _a2, _b2;
289
+ const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
290
+ const options = {
291
+ timeout: defaultTimeout,
292
+ includeRaw: false,
293
+ noCache: false,
294
+ classification: defaultClassification,
295
+ sources: _sources,
296
+ ..._options
297
+ };
298
+ const headers = {};
299
+ const token = getToken == null ? void 0 : getToken();
300
+ if (token) {
301
+ headers.Authorization = `Bearer ${token}`;
302
+ }
303
+ let requestConfig = { baseURL, headers };
304
+ if (onNetworkCall) {
305
+ requestConfig = onNetworkCall(requestConfig);
306
+ }
307
+ const statuses = [];
308
+ for (const selector of bulkRequest) {
309
+ const query = { type: selector.type, value: selector.value, classification: options.classification };
310
+ let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({
311
+ selector: query
312
+ }).incrementalPatch({
313
+ status: "in-progress"
314
+ }));
315
+ if (!statusRecord) {
316
+ statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.insert({
317
+ id: await computeStatusId(query.type, query.value, query.classification),
318
+ ...query,
319
+ status: "in-progress",
320
+ sources: options.sources
321
+ }));
322
+ }
323
+ if (statusRecord) {
324
+ statuses.push(statusRecord.toMutableJSON());
325
+ }
326
+ }
327
+ try {
328
+ const result = await post(bulkRequest, options.sources, options, requestConfig);
329
+ const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
330
+ await _addEntries(entries);
331
+ return result;
332
+ } catch (e) {
333
+ console.error(e);
334
+ return {};
335
+ } finally {
336
+ database.status.bulkUpsert(
337
+ uniqBy(statuses, (_record) => _record.id).map((record) => {
338
+ record.status = "complete";
339
+ return record;
340
+ })
341
+ );
342
+ }
343
+ },
344
+ [
345
+ pickSources,
346
+ sources,
347
+ availableSources,
348
+ defaultTimeout,
349
+ defaultClassification,
350
+ getToken,
351
+ baseURL,
352
+ onNetworkCall,
353
+ database,
354
+ _addEntries
355
+ ]
356
+ );
357
+ const enrichFailedEnrichments = useCallback(async () => {
358
+ if (!(database == null ? void 0 : database.selectors) || database.selectors.closed) {
359
+ return;
360
+ }
361
+ const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
362
+ const byClassification = groupBy(failedEnrichments, "classification");
363
+ const newRequests = [];
364
+ for (const [classification, selectors] of Object.entries(byClassification)) {
365
+ const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
366
+ for (const records of Object.values(bySelector)) {
367
+ newRequests.push({
368
+ id: await computeStatusId(records[0].type, records[0].value, classification),
369
+ type: records[0].type,
370
+ value: records[0].value,
371
+ classification,
372
+ sources: uniq(records.map((_record) => _record.source)).sort(),
373
+ status: "pending"
374
+ });
375
+ }
376
+ }
377
+ await database.status.bulkInsert(newRequests);
378
+ await database.selectors.bulkRemove(failedEnrichments);
379
+ }, [database]);
380
+ const enrichQueued = useMemo(
381
+ () => debounce(
382
+ async () => {
383
+ if (!(database == null ? void 0 : database.status)) {
384
+ return;
385
+ } else if (database.status.closed) {
386
+ console.warn("Status database is closed, will not enrich");
387
+ return;
388
+ }
389
+ const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
390
+ if (selectors.length < 1) {
391
+ return;
392
+ }
393
+ const chunks = chunk(selectors, chunkSize);
394
+ clueDebugLogger(
395
+ `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
396
+ debugLogging
397
+ );
398
+ await Promise.all(
399
+ // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
400
+ // backend, both on the pod level and kubernetes level
401
+ chunks.map(async (reqsChunk) => {
402
+ let _interval = null;
403
+ if (runningRequestCount.current <= maxRequestCount) {
404
+ runningRequestCount.current += 1;
405
+ } else {
406
+ let startOfWait = Date.now();
407
+ await new Promise((res) => {
408
+ _interval = setInterval(() => {
409
+ clueDebugLogger(
410
+ `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
411
+ debugLogging
412
+ );
413
+ if (runningRequestCount.current < maxRequestCount) {
414
+ res();
415
+ }
416
+ }, 400);
417
+ }).finally(() => {
418
+ runningRequestCount.current += 1;
419
+ clearInterval(_interval);
420
+ });
421
+ }
422
+ try {
423
+ const options = {};
424
+ const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
425
+ if (_sources.length > 0) {
426
+ options.sources = _sources;
427
+ }
428
+ await bulkEnrich(
429
+ reqsChunk.map((record) => record.toSelector()),
430
+ options
431
+ );
432
+ await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
433
+ } catch (e) {
434
+ console.error(e);
435
+ } finally {
436
+ runningRequestCount.current -= 1;
437
+ if (_interval) {
438
+ clearInterval(_interval);
439
+ }
440
+ }
441
+ })
442
+ );
443
+ },
444
+ 200,
445
+ { maxWait: 500, leading: false }
446
+ ),
447
+ [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
448
+ );
449
+ useEffect(() => {
450
+ {
451
+ return;
452
+ }
453
+ }, [database, debugLogging]);
454
+ useEffect(() => {
455
+ if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
456
+ return;
457
+ }
458
+ if (database == null ? void 0 : database.status.closed) {
459
+ console.warn("Status collection is closed");
460
+ return;
461
+ }
462
+ const observer = database.status.find({
463
+ selector: {
464
+ status: "pending"
465
+ }
466
+ }).$.subscribe(() => enrichQueued());
467
+ return () => {
468
+ try {
469
+ observer == null ? void 0 : observer.unsubscribe();
470
+ } catch (e) {
471
+ console.warn(e);
472
+ }
473
+ };
474
+ }, [enabled, isReady, database, debugLogging, enrichQueued, (_d = database == null ? void 0 : database.status) == null ? void 0 : _d.closed]);
475
+ const queueEnrich = useCallback(
476
+ async (type, value2, classification) => {
477
+ var _a2, _b2;
478
+ if (!type) {
479
+ throw new Error("Type cannot be null");
480
+ }
481
+ if (!value2) {
482
+ throw new Error("Value cannot be null");
483
+ }
484
+ if (!database.status || database.status.closed) {
485
+ console.warn("status collection is closed");
486
+ return;
487
+ }
488
+ const query = { type, value: value2, classification: classification ?? defaultClassification };
489
+ let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({
490
+ selector: query
491
+ }).exec());
492
+ if (!statusRecord) {
493
+ statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.queueInsert({
494
+ id: await computeStatusId(query.type, query.value, query.classification),
495
+ ...query,
496
+ status: "pending"
497
+ }));
498
+ }
499
+ return statusRecord;
500
+ },
501
+ [defaultClassification, database]
502
+ );
503
+ const guessType = useCallback(
504
+ (value2) => {
505
+ var _a2, _b2;
506
+ if (!value2) {
507
+ return null;
508
+ }
509
+ const types = Object.entries(typesDetection);
510
+ const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
511
+ if (regularCheck) {
512
+ return regularCheck;
513
+ }
514
+ const lowercased = value2.toLowerCase();
515
+ const lowercaseCheck = (_b2 = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b2[0];
516
+ if (lowercaseCheck) {
517
+ return lowercaseCheck;
518
+ }
519
+ return null;
520
+ },
521
+ [typesDetection]
522
+ );
523
+ const value = useMemo(
524
+ () => {
525
+ var _a2, _b2;
526
+ return {
527
+ bulkEnrich,
528
+ enrich,
529
+ enrichFailedEnrichments,
530
+ sources,
531
+ setSources,
532
+ typesDetection,
533
+ supportedTypes,
534
+ availableSources,
535
+ guessType,
536
+ queueEnrich,
537
+ setCustomIconify,
538
+ setDefaultClassification,
539
+ setReady: setIsReady,
540
+ defaultClassification,
541
+ ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) && (isEmpty(REPLICATORS) || ((_b2 = database.selectors) == null ? void 0 : _b2.synced))
542
+ };
543
+ },
544
+ [
545
+ bulkEnrich,
546
+ enrich,
547
+ enrichFailedEnrichments,
548
+ sources,
549
+ typesDetection,
550
+ supportedTypes,
551
+ availableSources,
552
+ guessType,
553
+ queueEnrich,
554
+ setDefaultClassification,
555
+ defaultClassification,
556
+ isReady,
557
+ database,
558
+ (_e = clueConfig.config) == null ? void 0 : _e.c12nDef
559
+ ]
560
+ );
561
+ return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
562
+ };
563
+ export {
564
+ ClueEnrichContext as C,
565
+ ClueEnrichProvider as a,
566
+ uniqBy as u
567
+ };
@@ -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
+ };