@cccsaurora/clue-ui 1.4.0 → 1.5.0-dev.449
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.
- package/ActionForm-CbLz66Rk.js +6099 -0
- package/AnnotationDetails-CdNvyJl7.js +176 -0
- package/AnnotationPreview-C6a3qRFG.js +188 -0
- package/ClueEnrichContext-0eVIgvZp.js +594 -0
- package/FlexOne-BSYAhhtG.js +9 -0
- package/_MapCache-kuEY_iOH.js +220 -0
- package/_Set-BrSMTlHn.js +6 -0
- package/_Uint8Array-OPpgYQj7.js +123 -0
- package/_arrayIncludes-BNqL-9ZP.js +31 -0
- package/_arrayPush-CBkQqaE_.js +10 -0
- package/_baseAssignValue-CNUVPOBW.js +16 -0
- package/_baseClone-9FaRd1R2.js +287 -0
- package/_baseExtremum-wOGT4Dgw.js +18 -0
- package/_baseFlatten-Co6QHDlG.js +92 -0
- package/_baseGet-Cmp6FztG.js +109 -0
- package/_baseGetTag-Hj-0NTYF.js +44 -0
- package/_baseIsEqual-1CpU47TZ.js +211 -0
- package/_baseIteratee-BN7Vbe5g.js +126 -0
- package/_baseRest-BZ_hQ9PC.js +8 -0
- package/_baseSlice-GAv_YFTT.js +20 -0
- package/_baseSum-D0WC1dN0.js +13 -0
- package/_baseUniq-BnvS3JHL.js +63 -0
- package/_cacheHas-_aF2y2Xv.js +25 -0
- package/_commonjsHelpers-CUmg6egw.js +6 -0
- package/_createAggregator-BUZrP_is.js +63 -0
- package/_defineProperty-DolZLKmv.js +12 -0
- package/_getPrototype-Bb4gm-5m.js +5 -0
- package/_getTag-CML_cXiN.js +105 -0
- package/_isIterateeCall-B1IFEqVv.js +17 -0
- package/_setToArray-CqyqC8ib.js +10 -0
- package/cloneDeep-l3UkXG5M.js +8 -0
- package/components/AnnotationBody.js +49 -35
- package/components/AnnotationDetailPopover.js +39 -30
- package/components/AnnotationDetails.js +7 -7
- package/components/AnnotationEntry.js +35 -35
- package/components/AnnotationPreview.js +5 -5
- package/components/ClassificationChip.js +44 -23
- package/components/CountBadge.js +31 -26
- package/components/EnrichedCard.js +110 -97
- package/components/EnrichedChip.js +130 -105
- package/components/EnrichedTypography.js +133 -107
- package/components/ErrorBoundary.js +28 -24
- package/components/RetryFailedEnrichments.js +10 -9
- package/components/SourcePicker.js +57 -49
- package/components/actions/ActionForm.js +4 -4
- package/components/actions/ExecutePopover.js +75 -59
- package/components/actions/ResultModal.js +4 -4
- package/components/actions/form/schemaAdapter.js +39 -23
- package/components/actions/formats/FileResult.js +86 -59
- package/components/actions/formats/index.js +29 -25
- package/components/display/graph/ExpandMoreButton.js +10 -10
- package/components/display/graph/elements/NodeCard.js +111 -91
- package/components/display/graph/elements/NodeTag.js +15 -13
- package/components/display/graph/index.js +261 -202
- package/components/display/graph/visualizations/Leaf.js +89 -70
- package/components/display/graph/visualizations/cloud/index.js +98 -81
- package/components/display/graph/visualizations/icons/BaseIcon.js +26 -21
- package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
- package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
- package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
- package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
- package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
- package/components/display/graph/visualizations/icons/index.js +14 -13
- package/components/display/graph/visualizations/panels/NodePanel.js +10 -8
- package/components/display/graph/visualizations/tree/BundleLine.js +108 -81
- package/components/display/graph/visualizations/tree/Triangle.js +13 -13
- package/components/display/graph/visualizations/tree/index.js +408 -306
- package/components/display/icons/Iconified.js +27 -12
- package/components/display/json/index.js +4 -4
- package/components/display/markdown/index.js +8678 -5770
- package/components/enrichment/EnrichPopover.js +54 -46
- package/components/fetchers/Fetcher.js +166 -123
- package/components/fetchers/FetcherResultView.js +31 -27
- package/components/fetchers/PreviewModal.js +17 -16
- package/components/fetchers/StatusChip.js +21 -17
- package/components/group/Entry.js +13 -11
- package/components/group/Group.js +13 -10
- package/components/group/GroupControl.js +76 -65
- package/components/stats/QueryStatus.js +45 -32
- package/countBy-Bqcp3VCs.js +14 -0
- package/data/event.js +6 -4
- package/database/globals.js +2 -2
- package/database/index.js +3 -3
- package/database/replication.js +4 -4
- package/get-CdMThM8x.js +8 -0
- package/groupBy-BVV07EGQ.js +14 -0
- package/hooks/ClueActionContext.js +6 -6
- package/hooks/ClueComponentContext.js +29 -23
- package/hooks/ClueConfigProvider.js +14 -12
- package/hooks/ClueDatabaseContext.js +35 -23
- package/hooks/ClueEnrichContext.js +11 -11
- package/hooks/ClueFetcherContext.js +83 -56
- package/hooks/ClueGroupContext.js +17 -14
- package/hooks/CluePopupContext.js +5 -5
- package/hooks/ClueProvider.js +13 -11
- package/hooks/ClueUIPluginContext.js +49 -35
- package/hooks/selectors.js +7 -7
- package/hooks/useActionResult.js +3 -3
- package/hooks/useAnnotations.js +48 -32
- package/hooks/useClue.js +6 -4
- package/hooks/useClueActions.js +3 -3
- package/hooks/useClueConfig.js +6 -4
- package/hooks/useClueTypeConfig.js +49 -24
- package/hooks/useClueUIPlugins.js +8 -7
- package/hooks/useComparator.js +722 -435
- package/hooks/useErrors.js +22 -18
- package/hooks/useFetcherResult.js +33 -24
- package/hooks/useMyHighlights.js +66 -36
- package/hooks/useMyLocalStorage.js +66 -37
- package/iconify-DJxl6dC-.js +1789 -0
- package/icons/Action.js +66 -49
- package/icons/Assessment.js +85 -69
- package/icons/Context.js +77 -63
- package/icons/Opinion.js +76 -60
- package/icons/iconMap.js +2 -2
- package/identity-CPGTqrE4.js +6 -0
- package/index-CDrC9oSE.js +1172 -0
- package/index-CVUD9o3t.js +15768 -0
- package/index-DUEubgWN.js +464 -0
- package/index-DpJxD74E.js +3272 -0
- package/index-IKI1G5v-.js +9314 -0
- package/index-_gpzM2Px.js +702 -0
- package/isArguments-CuYlEuhP.js +27 -0
- package/isArray-RJPfgWqI.js +4 -0
- package/isEmpty-BE656RUK.js +30 -0
- package/isNil-CIubwp4T.js +6 -0
- package/isObject-FTY-5JQX.js +7 -0
- package/isObjectLike-CeENW9FN.js +6 -0
- package/isSymbol-D_H4HPZQ.js +9 -0
- package/last-CUCl67Im.js +7 -0
- package/main.js +62 -62
- package/maxBy-BjjQmX5t.js +8 -0
- package/package.json +1 -1
- package/plugins/ClueUIPlugin.js +163 -96
- package/plugins/file/index.js +15 -15
- package/plugins/graph/index.js +29 -26
- package/plugins/image/index.js +28 -24
- package/plugins/json/index.js +21 -21
- package/plugins/markdown/index.js +18 -18
- package/plugins/registry.js +6 -6
- package/plugins/store.js +4 -4
- package/plugins/test/index.js +17 -17
- package/plugins/utils.js +13 -12
- package/replication-kdsH0l7f.js +11779 -0
- package/sessionStorage-B68y-wnE.js +140 -0
- package/sortBy-B8JVsLQY.js +95 -0
- package/store-9Bv4xoVU.js +2165 -0
- package/sumBy-D-HCzM2i.js +8 -0
- package/text/Frequency.js +42 -23
- package/toFinite-meZTg4Su.js +16 -0
- package/toNumber-B5JaA1vX.js +39 -0
- package/uniq-CahZPAwp.js +7 -0
- package/utils/chain.js +92 -65
- package/utils/classificationParser.js +519 -256
- package/utils/constants.js +37 -11
- package/utils/graph.js +72 -45
- package/utils/hashUtil.js +7 -7
- package/utils/line.js +131 -81
- package/utils/loggerUtil.js +5 -3
- package/utils/sessionStorage.js +7 -7
- package/utils/time.js +447 -427
- package/utils/utils.js +10 -10
- package/utils/window.js +21 -10
- package/utils-CEySTPtg.js +224 -0
- package/ActionForm-DjyNwVzM.js +0 -4403
- package/AnnotationDetails-BvPv3_pR.js +0 -160
- package/AnnotationPreview-C0JN_lr0.js +0 -140
- package/ClueEnrichContext-CNbh-qiy.js +0 -452
- package/FlexOne-BXWFOd1T.js +0 -6
- package/_MapCache-DRK-s2eK.js +0 -179
- package/_Set-DrS_bbSV.js +0 -6
- package/_Uint8Array-D9R2N9Lp.js +0 -98
- package/_arrayIncludes-Dcl_29E6.js +0 -25
- package/_arrayPush-DBJIuK2V.js +0 -8
- package/_baseAssignValue-Bx1cxHj5.js +0 -12
- package/_baseClone-DRhywkxm.js +0 -211
- package/_baseExtremum-DodEaEyF.js +0 -16
- package/_baseFlatten-CD9NgrYE.js +0 -72
- package/_baseGet-bVwDaGrA.js +0 -80
- package/_baseGetTag-CxDaTem-.js +0 -25
- package/_baseIsEqual-C-FKsm1J.js +0 -150
- package/_baseIteratee-D0FhC5bC.js +0 -95
- package/_baseRest-D_eW2E0d.js +0 -8
- package/_baseSlice-M5RKzt1A.js +0 -10
- package/_baseSum-wEbgNeUs.js +0 -10
- package/_baseUniq-D3N8igOm.js +0 -41
- package/_cacheHas-Wgl-hw34.js +0 -22
- package/_commonjsHelpers-C6fGbg64.js +0 -6
- package/_createAggregator-BVj8IAuF.js +0 -53
- package/_defineProperty-BZU4WKA3.js +0 -11
- package/_getPrototype-BGBCg-aX.js +0 -5
- package/_getTag-B7R9qBo7.js +0 -73
- package/_isIterateeCall-Dm0VTAYy.js +0 -13
- package/_setToArray-Ck4YZu0Z.js +0 -9
- package/cloneDeep-fV59zwUf.js +0 -8
- package/countBy-B3rNuG4T.js +0 -8
- package/get-Bil3mzRD.js +0 -8
- package/groupBy-CrJC7sGa.js +0 -8
- package/iconify-Ptb5dTKy.js +0 -1270
- package/identity-ByMq8VxU.js +0 -6
- package/index-BH-gBhtO.js +0 -2282
- package/index-BM9Sve5T.js +0 -571
- package/index-Cj4d5cGz.js +0 -357
- package/index-D3Dwn-8x.js +0 -6464
- package/index-Dh2PP9h8.js +0 -11747
- package/index-DoFpWPHo.js +0 -975
- package/isArguments-BWcXOE6a.js +0 -24
- package/isArray-WzO_os3q.js +0 -4
- package/isEmpty-DKxrY-_M.js +0 -22
- package/isNil-CjWwlQS3.js +0 -6
- package/isObject-B53jY8Qg.js +0 -7
- package/isObjectLike-CYbdrIBr.js +0 -6
- package/isSymbol-DE1Kcy2M.js +0 -9
- package/last-7CdUxN0r.js +0 -7
- package/maxBy-BOWDkL_D.js +0 -8
- package/replication-WkKbPdwG.js +0 -8453
- package/sessionStorage-DFMae61b.js +0 -90
- package/sortBy-BHe812lF.js +0 -74
- package/store-DClHBq7r.js +0 -1169
- package/sumBy-B7f_bP_k.js +0 -8
- package/toFinite-CBrE65MP.js +0 -14
- package/toNumber-CxmWey0f.js +0 -31
- package/uniq-B4UZ671_.js +0 -7
- package/utils-SpTOhPYl.js +0 -147
|
@@ -0,0 +1,594 @@
|
|
|
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
|
+
};
|