@cccsaurora/clue-ui 1.1.3 → 1.2.0-dev.106
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-ByeOzpc4.js +555 -0
- package/AnnotationDetails-DknbKDyl.js +175 -0
- package/AnnotationPreview-CQwKs8se.js +188 -0
- package/ClueEnrichContext-6NJfXpUB.js +536 -0
- package/FlexOne-BSYAhhtG.js +9 -0
- package/_Map-kgDsDYxq.js +64 -0
- package/_MapCache-DabaaWfq.js +161 -0
- package/_Uint8Array-BlVVH1tp.js +129 -0
- package/_baseAssignValue-CNbcU6Nb.js +25 -0
- package/_baseClone-D3a8Pa4T.js +284 -0
- package/_baseExtremum-B1o1zHjR.js +33 -0
- package/_baseFlatten-D4huXoEI.js +92 -0
- package/_baseGet-BSK_nnoz.js +109 -0
- package/_baseIsEqual-B5xLoweL.js +238 -0
- package/_baseIteratee-p6Nj07-n.js +126 -0
- package/_baseSlice-GAv_YFTT.js +20 -0
- package/_baseSum-D0WC1dN0.js +13 -0
- package/_baseUniq-CpupKWcL.js +89 -0
- package/_commonjsHelpers-DWwsNxpa.js +8 -0
- package/_createAggregator-BpVy5xMi.js +63 -0
- package/_getPrototype-D1LAdQKO.js +5 -0
- package/_getTag-D3ToyefI.js +126 -0
- package/cloneDeep-CjP5k9zW.js +8 -0
- package/components/AnnotationBody.js +49 -35
- package/components/AnnotationDetailPopover.js +36 -30
- package/components/AnnotationDetails.js +6 -6
- package/components/AnnotationEntry.js +50 -47
- 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 +64 -50
- package/components/actions/ResultModal.js +5 -5
- package/components/actions/form/schemaAdapter.js +39 -23
- 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 +88 -69
- 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 +407 -305
- package/components/display/icons/Iconified.js +27 -12
- package/components/display/json/index.js +4 -4
- package/components/display/markdown/index.js +8658 -5757
- package/components/enrichment/EnrichPopover.js +55 -47
- package/components/fetchers/Fetcher.js +123 -95
- package/components/fetchers/PreviewModal.js +20 -17
- 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 +77 -66
- package/components/stats/QueryStatus.js +40 -35
- package/countBy-C69WslUA.js +14 -0
- package/data/event.js +6 -4
- package/database/index.js +2 -2
- package/debounce-bV0h5FC5.js +92 -0
- package/get-D3C3lEU3.js +8 -0
- package/groupBy-DC2oOuBN.js +14 -0
- package/hooks/ClueActionContext.js +7 -7
- package/hooks/ClueComponentContext.js +29 -23
- package/hooks/ClueConfigProvider.js +14 -12
- package/hooks/ClueDatabaseContext.js +19 -13
- package/hooks/ClueEnrichContext.js +8 -8
- package/hooks/ClueFetcherContext.js +74 -46
- package/hooks/ClueGroupContext.js +17 -14
- package/hooks/CluePopupContext.js +5 -5
- package/hooks/ClueProvider.js +12 -10
- package/hooks/selectors.js +21 -10
- package/hooks/useActionResult.js +2 -2
- package/hooks/useAnnotations.js +44 -32
- package/hooks/useClue.js +6 -4
- package/hooks/useClueActions.js +3 -3
- package/hooks/useClueConfig.js +6 -4
- package/hooks/useClueTypeConfig.js +3 -3
- package/hooks/useComparator.js +722 -435
- package/hooks/useErrors.js +22 -18
- package/hooks/useMyHighlights.js +66 -36
- package/hooks/useMyLocalStorage.js +66 -37
- package/iconify-CXMreGTg.js +1782 -0
- package/icons/Action.js +66 -49
- package/icons/Assessment.js +84 -68
- package/icons/Context.js +77 -63
- package/icons/Opinion.js +77 -65
- package/icons/iconMap.js +2 -2
- package/identity-CPGTqrE4.js +6 -0
- package/index-BDVjGvMI.js +696 -0
- package/index-BbPn6-Mw.js +15750 -0
- package/index-Bi21Wb23.js +465 -0
- package/index-C3lkTD69.js +1172 -0
- package/index-CC12Ux-9.js +17654 -0
- package/isEmpty-BQkZubqU.js +29 -0
- package/isNil-CIubwp4T.js +6 -0
- package/isObject-FTY-5JQX.js +7 -0
- package/isObjectLike-OAgjjZye.js +48 -0
- package/isSymbol-Xd2FsJyp.js +8 -0
- package/last-CUCl67Im.js +7 -0
- package/main.js +62 -62
- package/package.json +1 -1
- package/sortBy-B-UKp4GT.js +100 -0
- package/sumBy-MYkDPHZL.js +8 -0
- package/text/Frequency.js +42 -23
- package/toFinite-Bc55msYj.js +16 -0
- package/toNumber-DPxy1FBy.js +39 -0
- package/useClueTypeConfig-XvGvIw2S.js +3201 -0
- package/utils/chain.js +91 -64
- package/utils/classificationParser.js +519 -256
- package/utils/constants.js +35 -10
- 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 +41 -27
- package/utils/time.js +423 -423
- package/utils/utils.js +9 -9
- package/utils/window.js +21 -10
- package/utils-7OtvGnmf.js +200 -0
- package/ActionForm-myEAs2UC.js +0 -435
- package/AnnotationDetails-BChWwaXw.js +0 -160
- package/AnnotationPreview-D060vmy2.js +0 -140
- package/ClueEnrichContext-DJNjbXu_.js +0 -418
- package/FlexOne-BXWFOd1T.js +0 -6
- package/_Map-DXNg_Z-q.js +0 -54
- package/_MapCache-Cu25RRDU.js +0 -129
- package/_Uint8Array-DlJCtTvG.js +0 -102
- package/_baseAssignValue-CUmzp727.js +0 -20
- package/_baseClone-BlMmRXeX.js +0 -208
- package/_baseExtremum-P_0akmCi.js +0 -27
- package/_baseFlatten-CN7vDNEQ.js +0 -72
- package/_baseGet-Dgf6_xCm.js +0 -80
- package/_baseIsEqual-Cpjtfb3Q.js +0 -173
- package/_baseIteratee-CP1bocOX.js +0 -95
- package/_baseSlice-M5RKzt1A.js +0 -10
- package/_baseSum-wEbgNeUs.js +0 -10
- package/_baseUniq-tMFmk80M.js +0 -61
- package/_commonjsHelpers-DaMA6jEr.js +0 -8
- package/_createAggregator-B4Cav8ZM.js +0 -53
- package/_getPrototype-CHAFQYL_.js +0 -5
- package/_getTag-BV_UoLYG.js +0 -90
- package/cloneDeep-BPVpFBzJ.js +0 -8
- package/countBy-DOutsa_w.js +0 -8
- package/debounce-DryYcbJ4.js +0 -56
- package/get-Bow1vKwx.js +0 -8
- package/groupBy-BheQYl6f.js +0 -8
- package/iconify-BBckr5AQ.js +0 -1263
- package/identity-ByMq8VxU.js +0 -6
- package/index-BXxfAxFt.js +0 -12734
- package/index-C15OYgRY.js +0 -358
- package/index-E7g8cRyW.js +0 -568
- package/index-p5_wX7q1.js +0 -11729
- package/index-vF6IyBhz.js +0 -975
- package/isEmpty-g47Qir2A.js +0 -21
- package/isNil-CjWwlQS3.js +0 -6
- package/isObject-B53jY8Qg.js +0 -7
- package/isObjectLike-BatpeCIi.js +0 -29
- package/isSymbol-C3_SC0Qp.js +0 -8
- package/last-7CdUxN0r.js +0 -7
- package/sortBy-ITdmD17L.js +0 -79
- package/sumBy-DxJUU2E8.js +0 -8
- package/toFinite-BMy6GObD.js +0 -14
- package/toNumber-YVhnnJv4.js +0 -31
- package/useClueTypeConfig-DyeBcXQX.js +0 -2214
- package/utils-BnmI_6N8.js +0 -130
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { a as addAPIProvider } from "./iconify-CXMreGTg.js";
|
|
3
|
+
import { u as useClueTypeConfig, a as api, p as post } from "./useClueTypeConfig-XvGvIw2S.js";
|
|
4
|
+
import { clueDebugLogger } from "./utils/loggerUtil.js";
|
|
5
|
+
import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
|
|
6
|
+
import { t as toFinite } from "./toFinite-Bc55msYj.js";
|
|
7
|
+
import { d as debounce } from "./debounce-bV0h5FC5.js";
|
|
8
|
+
import { g as groupBy } from "./groupBy-DC2oOuBN.js";
|
|
9
|
+
import { b as baseUniq } from "./_baseUniq-CpupKWcL.js";
|
|
10
|
+
import { b as baseIteratee } from "./_baseIteratee-p6Nj07-n.js";
|
|
11
|
+
import { useContext, useState, useMemo, useCallback, useRef, useEffect } from "react";
|
|
12
|
+
import { c as createContext } from "./index-BDVjGvMI.js";
|
|
13
|
+
import { ClueDatabaseContext } from "./hooks/ClueDatabaseContext.js";
|
|
14
|
+
import useClueConfig from "./hooks/useClueConfig.js";
|
|
15
|
+
function toInteger(value) {
|
|
16
|
+
var result = toFinite(value), remainder = result % 1;
|
|
17
|
+
return result === result ? remainder ? result - remainder : result : 0;
|
|
18
|
+
}
|
|
19
|
+
var nativeCeil = Math.ceil, nativeMax = Math.max;
|
|
20
|
+
function chunk(array, size, guard) {
|
|
21
|
+
if (size === void 0) {
|
|
22
|
+
size = 1;
|
|
23
|
+
} else {
|
|
24
|
+
size = nativeMax(toInteger(size), 0);
|
|
25
|
+
}
|
|
26
|
+
var length = array == null ? 0 : array.length;
|
|
27
|
+
if (!length || size < 1) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
|
|
31
|
+
while (index < length) {
|
|
32
|
+
result[resIndex++] = baseSlice(array, index, index += size);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function uniq(array) {
|
|
37
|
+
return array && array.length ? baseUniq(array) : [];
|
|
38
|
+
}
|
|
39
|
+
function uniqBy(array, iteratee) {
|
|
40
|
+
return array && array.length ? baseUniq(array, baseIteratee(iteratee)) : [];
|
|
41
|
+
}
|
|
42
|
+
let getRandomValues;
|
|
43
|
+
const rnds8 = new Uint8Array(16);
|
|
44
|
+
function rng() {
|
|
45
|
+
if (!getRandomValues) {
|
|
46
|
+
getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
47
|
+
if (!getRandomValues) {
|
|
48
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return getRandomValues(rnds8);
|
|
52
|
+
}
|
|
53
|
+
const byteToHex = [];
|
|
54
|
+
for (let i = 0; i < 256; ++i) {
|
|
55
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
56
|
+
}
|
|
57
|
+
function unsafeStringify(arr, offset = 0) {
|
|
58
|
+
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]];
|
|
59
|
+
}
|
|
60
|
+
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
61
|
+
const native = {
|
|
62
|
+
randomUUID
|
|
63
|
+
};
|
|
64
|
+
function v4(options, buf, offset) {
|
|
65
|
+
if (native.randomUUID && true && !options) {
|
|
66
|
+
return native.randomUUID();
|
|
67
|
+
}
|
|
68
|
+
options = options || {};
|
|
69
|
+
const rnds = options.random || (options.rng || rng)();
|
|
70
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
71
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
72
|
+
return unsafeStringify(rnds);
|
|
73
|
+
}
|
|
74
|
+
const ClueEnrichContext = createContext(null);
|
|
75
|
+
const ClueEnrichProvider = ({
|
|
76
|
+
children,
|
|
77
|
+
classification: _defaultClassification,
|
|
78
|
+
baseURL,
|
|
79
|
+
getToken,
|
|
80
|
+
onNetworkCall,
|
|
81
|
+
pickSources,
|
|
82
|
+
chunkSize = 15,
|
|
83
|
+
maxRequestCount = 4,
|
|
84
|
+
defaultTimeout = 5,
|
|
85
|
+
enabled = true,
|
|
86
|
+
ready = false,
|
|
87
|
+
publicIconify = true,
|
|
88
|
+
skipConfigCall = false,
|
|
89
|
+
customIconify: _customIconify,
|
|
90
|
+
debugLogging = true
|
|
91
|
+
}) => {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
const clueConfig = useClueConfig();
|
|
94
|
+
const database = useContext(ClueDatabaseContext);
|
|
95
|
+
const [configuredDefaultClassification, setConfiguredDefaultClassification] = useState(null);
|
|
96
|
+
const defaultClassification = useMemo(
|
|
97
|
+
() => {
|
|
98
|
+
var _a2, _b2;
|
|
99
|
+
return configuredDefaultClassification ?? _defaultClassification ?? ((_b2 = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b2.RESTRICTED);
|
|
100
|
+
},
|
|
101
|
+
[_defaultClassification, (_b = (_a = clueConfig.config) == null ? void 0 : _a.c12nDef) == null ? void 0 : _b.RESTRICTED, configuredDefaultClassification]
|
|
102
|
+
);
|
|
103
|
+
const setDefaultClassification = useCallback(
|
|
104
|
+
(func) => {
|
|
105
|
+
var _a2;
|
|
106
|
+
return setConfiguredDefaultClassification(func((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef));
|
|
107
|
+
},
|
|
108
|
+
[(_c = clueConfig.config) == null ? void 0 : _c.c12nDef]
|
|
109
|
+
);
|
|
110
|
+
const [isReady, setIsReady] = useState(ready);
|
|
111
|
+
const runningRequestCount = useRef(0);
|
|
112
|
+
const [sources, setSources] = useState([]);
|
|
113
|
+
const { availableSources, typesDetection } = useClueTypeConfig(
|
|
114
|
+
enabled && isReady,
|
|
115
|
+
baseURL,
|
|
116
|
+
debugLogging,
|
|
117
|
+
getToken,
|
|
118
|
+
onNetworkCall
|
|
119
|
+
);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (skipConfigCall || !enabled || !isReady) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const headers = {};
|
|
125
|
+
const token = getToken == null ? void 0 : getToken();
|
|
126
|
+
if (token) {
|
|
127
|
+
headers.Authorization = `Bearer ${token}`;
|
|
128
|
+
}
|
|
129
|
+
let requestConfig = { baseURL, headers };
|
|
130
|
+
if (onNetworkCall) {
|
|
131
|
+
requestConfig = onNetworkCall(requestConfig);
|
|
132
|
+
}
|
|
133
|
+
api.configs.get(requestConfig).then(clueConfig.setConfig);
|
|
134
|
+
}, [baseURL, onNetworkCall, skipConfigCall, isReady]);
|
|
135
|
+
const [customIconify, setCustomIconify] = useState(_customIconify);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (_customIconify) {
|
|
138
|
+
setCustomIconify(_customIconify);
|
|
139
|
+
}
|
|
140
|
+
}, [_customIconify]);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (publicIconify) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
|
|
146
|
+
if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
|
|
147
|
+
iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
|
|
148
|
+
}
|
|
149
|
+
if (iconURL) {
|
|
150
|
+
clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
|
|
151
|
+
addAPIProvider("", {
|
|
152
|
+
resources: [iconURL]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, [baseURL, customIconify, debugLogging, publicIconify]);
|
|
156
|
+
const _addEntries = useCallback(
|
|
157
|
+
async (entries) => {
|
|
158
|
+
const newRecords = [];
|
|
159
|
+
for (const entry of entries) {
|
|
160
|
+
const { latency, source, type, value: value2, items, error } = entry;
|
|
161
|
+
if (error) {
|
|
162
|
+
newRecords.push({
|
|
163
|
+
id: v4(),
|
|
164
|
+
source,
|
|
165
|
+
type,
|
|
166
|
+
value: value2,
|
|
167
|
+
annotations: [],
|
|
168
|
+
classification: defaultClassification,
|
|
169
|
+
latency,
|
|
170
|
+
count: 0,
|
|
171
|
+
error
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
for (const item of items) {
|
|
175
|
+
const { classification, count, link, annotations } = item;
|
|
176
|
+
await database.selectors.find({ selector: { type, value: value2, source, classification } }).incrementalRemove();
|
|
177
|
+
const record = {
|
|
178
|
+
id: v4(),
|
|
179
|
+
source,
|
|
180
|
+
type,
|
|
181
|
+
value: value2,
|
|
182
|
+
annotations,
|
|
183
|
+
classification,
|
|
184
|
+
latency,
|
|
185
|
+
count,
|
|
186
|
+
link,
|
|
187
|
+
error
|
|
188
|
+
};
|
|
189
|
+
if (newRecords.some((_entry) => _entry.id === record.id)) {
|
|
190
|
+
record.id = v4();
|
|
191
|
+
}
|
|
192
|
+
newRecords.push(record);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const result = await database.selectors.bulkInsert(newRecords);
|
|
196
|
+
if (result.error.length > 0) {
|
|
197
|
+
console.warn("Errors on upsert:");
|
|
198
|
+
result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[database, defaultClassification]
|
|
202
|
+
);
|
|
203
|
+
const enrich = useCallback(
|
|
204
|
+
async (type, value2, _options = {}) => {
|
|
205
|
+
var _a2, _b2;
|
|
206
|
+
if (!type || !value2) {
|
|
207
|
+
console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
210
|
+
const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
|
|
211
|
+
const options = {
|
|
212
|
+
timeout: defaultTimeout,
|
|
213
|
+
force: false,
|
|
214
|
+
includeRaw: false,
|
|
215
|
+
noCache: false,
|
|
216
|
+
classification: defaultClassification,
|
|
217
|
+
sources: _sources,
|
|
218
|
+
..._options
|
|
219
|
+
};
|
|
220
|
+
const headers = {};
|
|
221
|
+
const token = getToken == null ? void 0 : getToken();
|
|
222
|
+
if (token) {
|
|
223
|
+
headers.Authorization = `Bearer ${token}`;
|
|
224
|
+
}
|
|
225
|
+
let requestConfig = { baseURL, headers };
|
|
226
|
+
if (onNetworkCall) {
|
|
227
|
+
requestConfig = onNetworkCall(requestConfig);
|
|
228
|
+
}
|
|
229
|
+
const selector = {
|
|
230
|
+
type,
|
|
231
|
+
value: value2,
|
|
232
|
+
classification: options.classification
|
|
233
|
+
};
|
|
234
|
+
let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({ selector: { ...selector } }).exec());
|
|
235
|
+
if (!statusRecord) {
|
|
236
|
+
statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.insert({
|
|
237
|
+
id: v4(),
|
|
238
|
+
type: selector.type,
|
|
239
|
+
value: selector.value,
|
|
240
|
+
classification: selector.classification ?? defaultClassification,
|
|
241
|
+
status: "in-progress"
|
|
242
|
+
}));
|
|
243
|
+
} else {
|
|
244
|
+
await statusRecord.incrementalPatch({ status: "in-progress" });
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const enrichmentResult = await post([selector], options.sources, options, requestConfig);
|
|
248
|
+
const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
|
|
249
|
+
await _addEntries(Object.values(enrichData));
|
|
250
|
+
return enrichData;
|
|
251
|
+
} catch (e) {
|
|
252
|
+
console.error(e);
|
|
253
|
+
return {};
|
|
254
|
+
} finally {
|
|
255
|
+
await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
[
|
|
259
|
+
_addEntries,
|
|
260
|
+
availableSources,
|
|
261
|
+
baseURL,
|
|
262
|
+
database,
|
|
263
|
+
defaultClassification,
|
|
264
|
+
defaultTimeout,
|
|
265
|
+
getToken,
|
|
266
|
+
onNetworkCall,
|
|
267
|
+
pickSources,
|
|
268
|
+
sources
|
|
269
|
+
]
|
|
270
|
+
);
|
|
271
|
+
const bulkEnrich = useCallback(
|
|
272
|
+
async (bulkRequest, _options) => {
|
|
273
|
+
const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
|
|
274
|
+
const options = {
|
|
275
|
+
timeout: defaultTimeout,
|
|
276
|
+
includeRaw: false,
|
|
277
|
+
noCache: false,
|
|
278
|
+
classification: defaultClassification,
|
|
279
|
+
sources: _sources,
|
|
280
|
+
..._options
|
|
281
|
+
};
|
|
282
|
+
const headers = {};
|
|
283
|
+
const token = getToken == null ? void 0 : getToken();
|
|
284
|
+
if (token) {
|
|
285
|
+
headers.Authorization = `Bearer ${token}`;
|
|
286
|
+
}
|
|
287
|
+
let requestConfig = { baseURL, headers };
|
|
288
|
+
if (onNetworkCall) {
|
|
289
|
+
requestConfig = onNetworkCall(requestConfig);
|
|
290
|
+
}
|
|
291
|
+
const statuses = [];
|
|
292
|
+
for (const selector of bulkRequest) {
|
|
293
|
+
const query = { type: selector.type, value: selector.value, classification: options.classification };
|
|
294
|
+
let statusRecord = await database.status.findOne({
|
|
295
|
+
selector: query
|
|
296
|
+
}).incrementalPatch({
|
|
297
|
+
status: "in-progress"
|
|
298
|
+
});
|
|
299
|
+
if (!statusRecord) {
|
|
300
|
+
statusRecord = await database.status.insert({
|
|
301
|
+
id: v4(),
|
|
302
|
+
...query,
|
|
303
|
+
status: "in-progress",
|
|
304
|
+
sources: options.sources
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
statuses.push(statusRecord.toMutableJSON());
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
const result = await post(bulkRequest, options.sources, options, requestConfig);
|
|
311
|
+
const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
|
|
312
|
+
await _addEntries(entries);
|
|
313
|
+
return result;
|
|
314
|
+
} catch (e) {
|
|
315
|
+
console.error(e);
|
|
316
|
+
return {};
|
|
317
|
+
} finally {
|
|
318
|
+
database.status.bulkUpsert(
|
|
319
|
+
uniqBy(statuses, (_record) => _record.id).map((record) => {
|
|
320
|
+
record.status = "complete";
|
|
321
|
+
return record;
|
|
322
|
+
})
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
[
|
|
327
|
+
pickSources,
|
|
328
|
+
sources,
|
|
329
|
+
availableSources,
|
|
330
|
+
defaultTimeout,
|
|
331
|
+
defaultClassification,
|
|
332
|
+
getToken,
|
|
333
|
+
baseURL,
|
|
334
|
+
onNetworkCall,
|
|
335
|
+
database,
|
|
336
|
+
_addEntries
|
|
337
|
+
]
|
|
338
|
+
);
|
|
339
|
+
const enrichFailedEnrichments = useCallback(async () => {
|
|
340
|
+
const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
|
|
341
|
+
const byClassification = groupBy(failedEnrichments, "classification");
|
|
342
|
+
const newRequests = [];
|
|
343
|
+
for (const [classification, selectors] of Object.entries(byClassification)) {
|
|
344
|
+
const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
|
|
345
|
+
Object.values(bySelector).forEach((records) => {
|
|
346
|
+
newRequests.push({
|
|
347
|
+
id: v4(),
|
|
348
|
+
type: records[0].type,
|
|
349
|
+
value: records[0].value,
|
|
350
|
+
classification,
|
|
351
|
+
sources: uniq(records.map((_record) => _record.source)).sort(),
|
|
352
|
+
status: "pending"
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
await database.status.bulkInsert(newRequests);
|
|
357
|
+
await database.selectors.bulkRemove(failedEnrichments);
|
|
358
|
+
}, [database]);
|
|
359
|
+
const enrichQueued = useMemo(
|
|
360
|
+
() => debounce(
|
|
361
|
+
async () => {
|
|
362
|
+
if (!(database == null ? void 0 : database.status)) {
|
|
363
|
+
return;
|
|
364
|
+
} else if (database.status.closed) {
|
|
365
|
+
console.warn("Status database is closed, will not enrich");
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
|
|
369
|
+
if (selectors.length < 1) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const chunks = chunk(selectors, chunkSize);
|
|
373
|
+
clueDebugLogger(
|
|
374
|
+
`Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
|
|
375
|
+
debugLogging
|
|
376
|
+
);
|
|
377
|
+
await Promise.all(
|
|
378
|
+
// For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
|
|
379
|
+
// backend, both on the pod level and kubernetes level
|
|
380
|
+
chunks.map(async (reqsChunk) => {
|
|
381
|
+
let _interval = null;
|
|
382
|
+
if (runningRequestCount.current <= maxRequestCount) {
|
|
383
|
+
runningRequestCount.current += 1;
|
|
384
|
+
} else {
|
|
385
|
+
let startOfWait = Date.now();
|
|
386
|
+
await new Promise((res) => {
|
|
387
|
+
_interval = setInterval(() => {
|
|
388
|
+
clueDebugLogger(
|
|
389
|
+
`Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
|
|
390
|
+
debugLogging
|
|
391
|
+
);
|
|
392
|
+
if (runningRequestCount.current < maxRequestCount) {
|
|
393
|
+
res();
|
|
394
|
+
}
|
|
395
|
+
}, 400);
|
|
396
|
+
}).finally(() => {
|
|
397
|
+
runningRequestCount.current += 1;
|
|
398
|
+
clearInterval(_interval);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
const options = {};
|
|
403
|
+
const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
|
|
404
|
+
if (_sources.length > 0) {
|
|
405
|
+
options.sources = _sources;
|
|
406
|
+
}
|
|
407
|
+
await bulkEnrich(
|
|
408
|
+
reqsChunk.map((record) => record.toSelector()),
|
|
409
|
+
options
|
|
410
|
+
);
|
|
411
|
+
await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
|
|
412
|
+
} catch (e) {
|
|
413
|
+
console.error(e);
|
|
414
|
+
} finally {
|
|
415
|
+
runningRequestCount.current -= 1;
|
|
416
|
+
if (_interval) {
|
|
417
|
+
clearInterval(_interval);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
);
|
|
422
|
+
},
|
|
423
|
+
200,
|
|
424
|
+
{ maxWait: 500, leading: false }
|
|
425
|
+
),
|
|
426
|
+
[bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
|
|
427
|
+
);
|
|
428
|
+
useEffect(() => {
|
|
429
|
+
{
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
}, [database, debugLogging]);
|
|
433
|
+
useEffect(() => {
|
|
434
|
+
if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const observer = database.status.find({
|
|
438
|
+
selector: {
|
|
439
|
+
status: "pending"
|
|
440
|
+
}
|
|
441
|
+
}).$.subscribe(() => enrichQueued());
|
|
442
|
+
return () => {
|
|
443
|
+
try {
|
|
444
|
+
observer == null ? void 0 : observer.unsubscribe();
|
|
445
|
+
} catch (e) {
|
|
446
|
+
console.warn(e);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}, [enabled, isReady, database, debugLogging, enrichQueued]);
|
|
450
|
+
const queueEnrich = useCallback(
|
|
451
|
+
async (type, value2, classification) => {
|
|
452
|
+
if (!type) {
|
|
453
|
+
throw new Error("Type cannot be null");
|
|
454
|
+
}
|
|
455
|
+
if (!value2) {
|
|
456
|
+
throw new Error("Value cannot be null");
|
|
457
|
+
}
|
|
458
|
+
const query = { type, value: value2, classification: classification ?? defaultClassification };
|
|
459
|
+
let statusRecord = await database.status.findOne({
|
|
460
|
+
selector: query
|
|
461
|
+
}).exec();
|
|
462
|
+
if (!statusRecord) {
|
|
463
|
+
statusRecord = await database.status.queueInsert({
|
|
464
|
+
id: v4(),
|
|
465
|
+
...query,
|
|
466
|
+
status: "pending"
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return statusRecord;
|
|
470
|
+
},
|
|
471
|
+
[defaultClassification, database]
|
|
472
|
+
);
|
|
473
|
+
const guessType = useCallback(
|
|
474
|
+
(value2) => {
|
|
475
|
+
var _a2, _b2;
|
|
476
|
+
if (!value2) {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
const types = Object.entries(typesDetection);
|
|
480
|
+
const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
|
|
481
|
+
if (regularCheck) {
|
|
482
|
+
return regularCheck;
|
|
483
|
+
}
|
|
484
|
+
const lowercased = value2.toLowerCase();
|
|
485
|
+
const lowercaseCheck = (_b2 = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b2[0];
|
|
486
|
+
if (lowercaseCheck) {
|
|
487
|
+
return lowercaseCheck;
|
|
488
|
+
}
|
|
489
|
+
return null;
|
|
490
|
+
},
|
|
491
|
+
[typesDetection]
|
|
492
|
+
);
|
|
493
|
+
const value = useMemo(
|
|
494
|
+
() => {
|
|
495
|
+
var _a2;
|
|
496
|
+
return {
|
|
497
|
+
bulkEnrich,
|
|
498
|
+
enrich,
|
|
499
|
+
enrichFailedEnrichments,
|
|
500
|
+
sources,
|
|
501
|
+
setSources,
|
|
502
|
+
typesDetection,
|
|
503
|
+
availableSources,
|
|
504
|
+
guessType,
|
|
505
|
+
queueEnrich,
|
|
506
|
+
setCustomIconify,
|
|
507
|
+
setDefaultClassification,
|
|
508
|
+
setReady: setIsReady,
|
|
509
|
+
defaultClassification,
|
|
510
|
+
ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
|
|
511
|
+
};
|
|
512
|
+
},
|
|
513
|
+
[
|
|
514
|
+
bulkEnrich,
|
|
515
|
+
enrich,
|
|
516
|
+
enrichFailedEnrichments,
|
|
517
|
+
sources,
|
|
518
|
+
typesDetection,
|
|
519
|
+
availableSources,
|
|
520
|
+
guessType,
|
|
521
|
+
queueEnrich,
|
|
522
|
+
setDefaultClassification,
|
|
523
|
+
defaultClassification,
|
|
524
|
+
isReady,
|
|
525
|
+
database,
|
|
526
|
+
(_d = clueConfig.config) == null ? void 0 : _d.c12nDef
|
|
527
|
+
]
|
|
528
|
+
);
|
|
529
|
+
return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
|
|
530
|
+
};
|
|
531
|
+
export {
|
|
532
|
+
ClueEnrichContext as C,
|
|
533
|
+
ClueEnrichProvider as a,
|
|
534
|
+
uniqBy as b,
|
|
535
|
+
uniq as u
|
|
536
|
+
};
|
package/_Map-kgDsDYxq.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { b as baseGetTag, r as root } from "./isObjectLike-OAgjjZye.js";
|
|
2
|
+
import { i as isObject } from "./isObject-FTY-5JQX.js";
|
|
3
|
+
var isArray = Array.isArray;
|
|
4
|
+
var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
|
|
5
|
+
function isFunction(value) {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
var tag = baseGetTag(value);
|
|
10
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
11
|
+
}
|
|
12
|
+
var coreJsData = root["__core-js_shared__"];
|
|
13
|
+
var maskSrcKey = function() {
|
|
14
|
+
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
|
|
15
|
+
return uid ? "Symbol(src)_1." + uid : "";
|
|
16
|
+
}();
|
|
17
|
+
function isMasked(func) {
|
|
18
|
+
return !!maskSrcKey && maskSrcKey in func;
|
|
19
|
+
}
|
|
20
|
+
var funcProto$1 = Function.prototype;
|
|
21
|
+
var funcToString$1 = funcProto$1.toString;
|
|
22
|
+
function toSource(func) {
|
|
23
|
+
if (func != null) {
|
|
24
|
+
try {
|
|
25
|
+
return funcToString$1.call(func);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return func + "";
|
|
30
|
+
} catch (e) {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
36
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
37
|
+
var funcProto = Function.prototype, objectProto = Object.prototype;
|
|
38
|
+
var funcToString = funcProto.toString;
|
|
39
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
40
|
+
var reIsNative = RegExp(
|
|
41
|
+
"^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
42
|
+
);
|
|
43
|
+
function baseIsNative(value) {
|
|
44
|
+
if (!isObject(value) || isMasked(value)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
|
48
|
+
return pattern.test(toSource(value));
|
|
49
|
+
}
|
|
50
|
+
function getValue(object, key) {
|
|
51
|
+
return object == null ? void 0 : object[key];
|
|
52
|
+
}
|
|
53
|
+
function getNative(object, key) {
|
|
54
|
+
var value = getValue(object, key);
|
|
55
|
+
return baseIsNative(value) ? value : void 0;
|
|
56
|
+
}
|
|
57
|
+
var Map = getNative(root, "Map");
|
|
58
|
+
export {
|
|
59
|
+
Map as M,
|
|
60
|
+
isFunction as a,
|
|
61
|
+
getNative as g,
|
|
62
|
+
isArray as i,
|
|
63
|
+
toSource as t
|
|
64
|
+
};
|