@cccsaurora/clue-ui 1.3.0-dev.403 → 1.3.0

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 (236) hide show
  1. package/ActionForm-CHOSKfvu.js +4403 -0
  2. package/AnnotationDetails-Bqq6Ymmg.js +160 -0
  3. package/AnnotationPreview-CqXmC-j8.js +140 -0
  4. package/ClueEnrichContext-DL6aGe1k.js +432 -0
  5. package/FlexOne-BXWFOd1T.js +6 -0
  6. package/_MapCache-DRK-s2eK.js +179 -0
  7. package/_Set-DrS_bbSV.js +6 -0
  8. package/_Uint8Array-D9R2N9Lp.js +98 -0
  9. package/_arrayIncludes-Dcl_29E6.js +25 -0
  10. package/_arrayPush-DBJIuK2V.js +8 -0
  11. package/_baseAssignValue-Bx1cxHj5.js +12 -0
  12. package/_baseClone-DRhywkxm.js +211 -0
  13. package/_baseExtremum-DodEaEyF.js +16 -0
  14. package/_baseFlatten-CD9NgrYE.js +72 -0
  15. package/_baseGet-bVwDaGrA.js +80 -0
  16. package/_baseGetTag-CxDaTem-.js +25 -0
  17. package/_baseIsEqual-C-FKsm1J.js +150 -0
  18. package/_baseIteratee-D0FhC5bC.js +95 -0
  19. package/_baseRest-D_eW2E0d.js +8 -0
  20. package/_baseSlice-M5RKzt1A.js +10 -0
  21. package/_baseSum-wEbgNeUs.js +10 -0
  22. package/_baseUniq-D3N8igOm.js +41 -0
  23. package/_cacheHas-Wgl-hw34.js +22 -0
  24. package/_commonjsHelpers-C6fGbg64.js +6 -0
  25. package/_createAggregator-BVj8IAuF.js +53 -0
  26. package/_defineProperty-BZU4WKA3.js +11 -0
  27. package/_getPrototype-BGBCg-aX.js +5 -0
  28. package/_getTag-B7R9qBo7.js +73 -0
  29. package/_isIterateeCall-Dm0VTAYy.js +13 -0
  30. package/_setToArray-Ck4YZu0Z.js +9 -0
  31. package/cloneDeep-fV59zwUf.js +8 -0
  32. package/components/AnnotationBody.js +35 -49
  33. package/components/AnnotationDetailPopover.js +30 -36
  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 +23 -44
  38. package/components/CountBadge.js +26 -31
  39. package/components/EnrichedCard.js +97 -110
  40. package/components/EnrichedChip.js +105 -130
  41. package/components/EnrichedTypography.js +107 -133
  42. package/components/ErrorBoundary.js +24 -28
  43. package/components/RetryFailedEnrichments.js +9 -10
  44. package/components/SourcePicker.js +49 -57
  45. package/components/actions/ActionForm.js +4 -4
  46. package/components/actions/ExecutePopover.js +59 -75
  47. package/components/actions/ResultModal.js +4 -4
  48. package/components/actions/form/schemaAdapter.js +23 -39
  49. package/components/actions/formats/FileResult.js +59 -86
  50. package/components/actions/formats/index.js +25 -29
  51. package/components/display/graph/ExpandMoreButton.js +10 -10
  52. package/components/display/graph/elements/NodeCard.js +91 -111
  53. package/components/display/graph/elements/NodeTag.js +13 -15
  54. package/components/display/graph/index.js +204 -262
  55. package/components/display/graph/visualizations/Leaf.js +70 -89
  56. package/components/display/graph/visualizations/cloud/index.js +81 -98
  57. package/components/display/graph/visualizations/icons/BaseIcon.js +21 -26
  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 +13 -14
  64. package/components/display/graph/visualizations/panels/NodePanel.js +8 -10
  65. package/components/display/graph/visualizations/tree/BundleLine.js +81 -108
  66. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  67. package/components/display/graph/visualizations/tree/index.js +306 -408
  68. package/components/display/icons/Iconified.js +12 -27
  69. package/components/display/json/index.js +4 -4
  70. package/components/display/markdown/index.js +5770 -8678
  71. package/components/enrichment/EnrichPopover.js +46 -54
  72. package/components/fetchers/Fetcher.js +123 -166
  73. package/components/fetchers/FetcherResultView.js +27 -31
  74. package/components/fetchers/PreviewModal.js +16 -17
  75. package/components/fetchers/StatusChip.js +17 -21
  76. package/components/group/Entry.js +11 -13
  77. package/components/group/Group.js +10 -13
  78. package/components/group/GroupControl.js +65 -76
  79. package/components/stats/QueryStatus.js +32 -45
  80. package/countBy-B3rNuG4T.js +8 -0
  81. package/data/event.js +4 -6
  82. package/database/globals.js +2 -2
  83. package/database/index.js +3 -3
  84. package/database/replication.js +4 -4
  85. package/en/translation.json +7 -0
  86. package/fr/translation.json +7 -0
  87. package/get-Bil3mzRD.js +8 -0
  88. package/groupBy-CrJC7sGa.js +8 -0
  89. package/hooks/ClueActionContext.js +6 -6
  90. package/hooks/ClueComponentContext.js +23 -29
  91. package/hooks/ClueConfigProvider.js +12 -14
  92. package/hooks/ClueDatabaseContext.js +23 -35
  93. package/hooks/ClueEnrichContext.js +11 -11
  94. package/hooks/ClueFetcherContext.js +56 -83
  95. package/hooks/ClueGroupContext.js +14 -17
  96. package/hooks/CluePopupContext.js +5 -5
  97. package/hooks/ClueProvider.js +11 -13
  98. package/hooks/ClueUIPluginContext.d.ts +5 -0
  99. package/hooks/ClueUIPluginContext.js +35 -47
  100. package/hooks/selectors.js +7 -7
  101. package/hooks/useActionResult.js +3 -3
  102. package/hooks/useAnnotations.js +32 -48
  103. package/hooks/useClue.js +4 -6
  104. package/hooks/useClueActions.js +3 -3
  105. package/hooks/useClueConfig.js +4 -6
  106. package/hooks/useClueTypeConfig.js +24 -49
  107. package/hooks/useClueUIPlugins.d.ts +4 -0
  108. package/hooks/useClueUIPlugins.js +11 -0
  109. package/hooks/useComparator.js +435 -722
  110. package/hooks/useErrors.js +18 -22
  111. package/hooks/useFetcherResult.js +24 -33
  112. package/hooks/useMyHighlights.js +36 -66
  113. package/hooks/useMyLocalStorage.js +37 -66
  114. package/iconify-Ptb5dTKy.js +1270 -0
  115. package/icons/Action.js +49 -66
  116. package/icons/Assessment.js +69 -85
  117. package/icons/Context.js +63 -77
  118. package/icons/Opinion.js +60 -76
  119. package/icons/iconMap.js +2 -2
  120. package/identity-ByMq8VxU.js +6 -0
  121. package/index-BH-gBhtO.js +2282 -0
  122. package/index-BM9Sve5T.js +571 -0
  123. package/index-Cj4d5cGz.js +357 -0
  124. package/index-Dh2PP9h8.js +11747 -0
  125. package/index-DoFpWPHo.js +975 -0
  126. package/index-DzVIklWY.js +6464 -0
  127. package/isArguments-BWcXOE6a.js +24 -0
  128. package/isArray-WzO_os3q.js +4 -0
  129. package/isEmpty-DKxrY-_M.js +22 -0
  130. package/isNil-CjWwlQS3.js +6 -0
  131. package/isObject-B53jY8Qg.js +7 -0
  132. package/isObjectLike-CYbdrIBr.js +6 -0
  133. package/isSymbol-DE1Kcy2M.js +9 -0
  134. package/last-7CdUxN0r.js +7 -0
  135. package/main.js +62 -62
  136. package/maxBy-BOWDkL_D.js +8 -0
  137. package/package.json +3 -2
  138. package/plugins/ClueUIPlugin.d.ts +5 -1
  139. package/plugins/ClueUIPlugin.js +124 -162
  140. package/plugins/file/index.js +15 -15
  141. package/plugins/graph/example/tree.json.d.ts +91 -0
  142. package/plugins/graph/index.d.ts +3 -0
  143. package/plugins/graph/index.js +34 -17
  144. package/plugins/image/index.d.ts +3 -0
  145. package/plugins/image/index.js +34 -18
  146. package/plugins/json/index.d.ts +3 -0
  147. package/plugins/json/index.js +29 -17
  148. package/plugins/markdown/index.d.ts +3 -0
  149. package/plugins/markdown/index.js +28 -17
  150. package/plugins/registry.js +6 -6
  151. package/plugins/store.d.ts +1 -0
  152. package/plugins/store.js +4 -4
  153. package/plugins/test/index.js +17 -17
  154. package/plugins/utils.d.ts +1 -0
  155. package/plugins/utils.js +19 -0
  156. package/replication-WkKbPdwG.js +8453 -0
  157. package/sessionStorage-DFMae61b.js +90 -0
  158. package/sortBy-BHe812lF.js +74 -0
  159. package/store-DClHBq7r.js +1169 -0
  160. package/sumBy-B7f_bP_k.js +8 -0
  161. package/text/Frequency.js +23 -42
  162. package/toFinite-CBrE65MP.js +14 -0
  163. package/toNumber-CxmWey0f.js +31 -0
  164. package/uniq-B4UZ671_.js +7 -0
  165. package/utils/chain.js +65 -92
  166. package/utils/classificationParser.js +256 -519
  167. package/utils/constants.js +11 -37
  168. package/utils/graph.js +45 -72
  169. package/utils/hashUtil.js +7 -7
  170. package/utils/line.js +81 -131
  171. package/utils/loggerUtil.js +3 -5
  172. package/utils/sessionStorage.js +7 -7
  173. package/utils/time.js +427 -447
  174. package/utils/utils.js +10 -10
  175. package/utils/window.js +10 -21
  176. package/utils-SpTOhPYl.js +147 -0
  177. package/ActionForm-CqKcnDWC.js +0 -6099
  178. package/AnnotationDetails-BlPd3T8k.js +0 -176
  179. package/AnnotationPreview-Bl447SKT.js +0 -188
  180. package/ClueEnrichContext-B3YrTCaJ.js +0 -567
  181. package/FlexOne-BSYAhhtG.js +0 -9
  182. package/_MapCache-kuEY_iOH.js +0 -220
  183. package/_Set-BrSMTlHn.js +0 -6
  184. package/_Uint8Array-OPpgYQj7.js +0 -123
  185. package/_arrayIncludes-BNqL-9ZP.js +0 -31
  186. package/_arrayPush-CBkQqaE_.js +0 -10
  187. package/_baseAssignValue-CNUVPOBW.js +0 -16
  188. package/_baseClone-9FaRd1R2.js +0 -287
  189. package/_baseExtremum-wOGT4Dgw.js +0 -18
  190. package/_baseFlatten-Co6QHDlG.js +0 -92
  191. package/_baseGet-Cmp6FztG.js +0 -109
  192. package/_baseGetTag-Hj-0NTYF.js +0 -44
  193. package/_baseIsEqual-1CpU47TZ.js +0 -211
  194. package/_baseIteratee-BN7Vbe5g.js +0 -126
  195. package/_baseRest-BZ_hQ9PC.js +0 -8
  196. package/_baseSlice-GAv_YFTT.js +0 -20
  197. package/_baseSum-D0WC1dN0.js +0 -13
  198. package/_baseUniq-BnvS3JHL.js +0 -63
  199. package/_cacheHas-_aF2y2Xv.js +0 -25
  200. package/_commonjsHelpers-CUmg6egw.js +0 -6
  201. package/_createAggregator-BUZrP_is.js +0 -63
  202. package/_defineProperty-DolZLKmv.js +0 -12
  203. package/_getPrototype-Bb4gm-5m.js +0 -5
  204. package/_getTag-CML_cXiN.js +0 -105
  205. package/_isIterateeCall-B1IFEqVv.js +0 -17
  206. package/_setToArray-CqyqC8ib.js +0 -10
  207. package/cloneDeep-l3UkXG5M.js +0 -8
  208. package/countBy-Bqcp3VCs.js +0 -14
  209. package/get-CdMThM8x.js +0 -8
  210. package/groupBy-BVV07EGQ.js +0 -14
  211. package/iconify-DJxl6dC-.js +0 -1789
  212. package/identity-CPGTqrE4.js +0 -6
  213. package/index-CAvu7vwt.js +0 -1172
  214. package/index-CVUD9o3t.js +0 -15768
  215. package/index-DUEubgWN.js +0 -464
  216. package/index-Dj1N4IQP.js +0 -9314
  217. package/index-DpJxD74E.js +0 -3272
  218. package/index-_gpzM2Px.js +0 -702
  219. package/isArguments-CuYlEuhP.js +0 -27
  220. package/isArray-RJPfgWqI.js +0 -4
  221. package/isEmpty-BE656RUK.js +0 -30
  222. package/isNil-CIubwp4T.js +0 -6
  223. package/isObject-FTY-5JQX.js +0 -7
  224. package/isObjectLike-CeENW9FN.js +0 -6
  225. package/isSymbol-D_H4HPZQ.js +0 -9
  226. package/last-CUCl67Im.js +0 -7
  227. package/maxBy-BjjQmX5t.js +0 -8
  228. package/replication--gLEZw8a.js +0 -11777
  229. package/sessionStorage-B68y-wnE.js +0 -140
  230. package/sortBy-B8JVsLQY.js +0 -95
  231. package/store-DMdRx9g0.js +0 -2156
  232. package/sumBy-D-HCzM2i.js +0 -8
  233. package/toFinite-meZTg4Su.js +0 -16
  234. package/toNumber-B5JaA1vX.js +0 -39
  235. package/uniq-CahZPAwp.js +0 -7
  236. package/utils-CEySTPtg.js +0 -224
@@ -1,567 +0,0 @@
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
- };
@@ -1,9 +0,0 @@
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
- };