@cccsaurora/clue-ui 1.5.0-dev.487 → 1.5.2

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