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