@cccsaurora/clue-ui 1.0.1-dev.70 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/ActionForm-BtTv0s4P.js +340 -0
  2. package/AnnotationDetails-D5tBIeEw.js +160 -0
  3. package/AnnotationPreview-CZr_CcZC.js +140 -0
  4. package/ClueEnrichContext-DH9lqjwH.js +401 -0
  5. package/FlexOne-BXWFOd1T.js +6 -0
  6. package/_Map-DXNg_Z-q.js +54 -0
  7. package/_MapCache-Cu25RRDU.js +129 -0
  8. package/_Uint8Array-DlJCtTvG.js +102 -0
  9. package/_baseAssignValue-CUmzp727.js +20 -0
  10. package/_baseClone-BlMmRXeX.js +208 -0
  11. package/_baseExtremum-P_0akmCi.js +27 -0
  12. package/_baseFlatten-CN7vDNEQ.js +72 -0
  13. package/_baseGet-Dgf6_xCm.js +80 -0
  14. package/_baseIsEqual-Cpjtfb3Q.js +173 -0
  15. package/_baseIteratee-CP1bocOX.js +95 -0
  16. package/_baseSlice-M5RKzt1A.js +10 -0
  17. package/_baseSum-wEbgNeUs.js +10 -0
  18. package/_baseUniq-tMFmk80M.js +61 -0
  19. package/_commonjsHelpers-C6fGbg64.js +6 -0
  20. package/_createAggregator-B4Cav8ZM.js +53 -0
  21. package/_getPrototype-CHAFQYL_.js +5 -0
  22. package/_getTag-BV_UoLYG.js +90 -0
  23. package/cloneDeep-BPVpFBzJ.js +8 -0
  24. package/components/AnnotationBody.js +34 -49
  25. package/components/AnnotationDetailPopover.js +30 -36
  26. package/components/AnnotationDetails.js +6 -6
  27. package/components/AnnotationEntry.js +47 -50
  28. package/components/AnnotationPreview.js +5 -5
  29. package/components/ClassificationChip.js +23 -44
  30. package/components/CountBadge.js +26 -31
  31. package/components/EnrichedCard.js +92 -104
  32. package/components/EnrichedChip.js +109 -134
  33. package/components/EnrichedTypography.js +110 -136
  34. package/components/ErrorBoundary.js +24 -28
  35. package/components/RetryFailedEnrichments.js +9 -10
  36. package/components/SourcePicker.js +49 -57
  37. package/components/actions/ActionForm.js +4 -4
  38. package/components/actions/ExecutePopover.js +50 -64
  39. package/components/actions/ResultModal.js +34 -37
  40. package/components/actions/form/schemaAdapter.js +20 -39
  41. package/components/display/graph/ExpandMoreButton.js +10 -10
  42. package/components/display/graph/elements/NodeCard.js +76 -92
  43. package/components/display/graph/elements/NodeTag.js +13 -15
  44. package/components/display/graph/index.js +200 -258
  45. package/components/display/graph/visualizations/Leaf.js +69 -88
  46. package/components/display/graph/visualizations/cloud/index.js +81 -98
  47. package/components/display/graph/visualizations/icons/BaseIcon.js +21 -26
  48. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  49. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  50. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  51. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  52. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  53. package/components/display/graph/visualizations/icons/index.js +13 -14
  54. package/components/display/graph/visualizations/panels/NodePanel.js +8 -10
  55. package/components/display/graph/visualizations/tree/BundleLine.js +81 -108
  56. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  57. package/components/display/graph/visualizations/tree/index.js +305 -407
  58. package/components/display/icons/Iconified.js +12 -27
  59. package/components/display/json/index.js +4 -4
  60. package/components/display/markdown/DynamicTabs.js +17 -22
  61. package/components/display/markdown/index.js +5674 -8531
  62. package/components/display/markdown/markdownPlugins/tabs.js +1 -1
  63. package/components/enrichment/EnrichPopover.js +47 -55
  64. package/components/fetchers/Fetcher.js +95 -123
  65. package/components/fetchers/PreviewModal.js +17 -20
  66. package/components/fetchers/StatusChip.js +18 -22
  67. package/components/group/Entry.js +11 -13
  68. package/components/group/Group.js +10 -13
  69. package/components/group/GroupControl.js +65 -76
  70. package/components/stats/QueryStatus.js +28 -37
  71. package/countBy-DOutsa_w.js +8 -0
  72. package/data/event.js +4 -6
  73. package/database/index.js +2 -2
  74. package/debounce-DryYcbJ4.js +56 -0
  75. package/get-Bow1vKwx.js +8 -0
  76. package/groupBy-BheQYl6f.js +8 -0
  77. package/hooks/ClueActionContext.js +6 -6
  78. package/hooks/ClueComponentContext.js +23 -29
  79. package/hooks/ClueConfigProvider.js +12 -14
  80. package/hooks/ClueDatabaseContext.js +13 -19
  81. package/hooks/ClueEnrichContext.js +8 -8
  82. package/hooks/ClueFetcherContext.js +46 -74
  83. package/hooks/ClueGroupContext.js +14 -17
  84. package/hooks/CluePopupContext.js +5 -5
  85. package/hooks/ClueProvider.js +10 -12
  86. package/hooks/selectors.js +11 -22
  87. package/hooks/useAnnotations.js +29 -45
  88. package/hooks/useClue.js +4 -6
  89. package/hooks/useClueActions.js +3 -3
  90. package/hooks/useClueConfig.js +5 -5
  91. package/hooks/useClueTypeConfig.js +3 -3
  92. package/hooks/useComparator.js +435 -722
  93. package/hooks/useErrors.js +18 -22
  94. package/hooks/useMyHighlights.js +36 -66
  95. package/hooks/useMyLocalStorage.js +43 -63
  96. package/iconify-BBckr5AQ.js +1263 -0
  97. package/icons/Action.js +49 -66
  98. package/icons/Assessment.js +68 -84
  99. package/icons/Context.js +61 -75
  100. package/icons/Opinion.js +65 -77
  101. package/icons/iconMap.js +2 -2
  102. package/identity-ByMq8VxU.js +6 -0
  103. package/index-BUcHmehh.js +975 -0
  104. package/index-Bo-v5IAc.js +12754 -0
  105. package/index-CnaCBNrd.js +358 -0
  106. package/index-E7g8cRyW.js +568 -0
  107. package/index-p5_wX7q1.js +11729 -0
  108. package/isEmpty-g47Qir2A.js +21 -0
  109. package/isNil-CjWwlQS3.js +6 -0
  110. package/isObject-B53jY8Qg.js +7 -0
  111. package/isObjectLike-BatpeCIi.js +29 -0
  112. package/isSymbol-C3_SC0Qp.js +8 -0
  113. package/last-7CdUxN0r.js +7 -0
  114. package/main.js +58 -58
  115. package/package.json +1 -1
  116. package/sortBy-ITdmD17L.js +79 -0
  117. package/sumBy-DxJUU2E8.js +8 -0
  118. package/tabs-CgADNA57.js +195 -0
  119. package/text/Frequency.js +23 -42
  120. package/toFinite-BMy6GObD.js +14 -0
  121. package/toNumber-YVhnnJv4.js +31 -0
  122. package/useClueTypeConfig-CneP98N_.js +2260 -0
  123. package/utils/chain.js +64 -91
  124. package/utils/classificationParser.d.ts +8 -8
  125. package/utils/classificationParser.js +257 -520
  126. package/utils/constants.js +10 -35
  127. package/utils/graph.js +45 -72
  128. package/utils/hashUtil.js +7 -7
  129. package/utils/line.js +81 -131
  130. package/utils/loggerUtil.js +3 -5
  131. package/utils/sessionStorage.js +29 -41
  132. package/utils/utils.js +9 -9
  133. package/utils/window.js +10 -21
  134. package/utils-CD0rFIFU.js +2704 -0
  135. package/ActionForm-D4ryHO0M.js +0 -436
  136. package/AnnotationDetails-YAPoqw3R.js +0 -175
  137. package/AnnotationPreview-DiQDjt9s.js +0 -188
  138. package/ClueEnrichContext-DIn6g8tw.js +0 -522
  139. package/FlexOne-BSYAhhtG.js +0 -9
  140. package/_Map-kgDsDYxq.js +0 -64
  141. package/_MapCache-DabaaWfq.js +0 -161
  142. package/_Uint8Array-BlVVH1tp.js +0 -129
  143. package/_baseAssignValue-CNbcU6Nb.js +0 -25
  144. package/_baseClone-D3a8Pa4T.js +0 -284
  145. package/_baseExtremum-B1o1zHjR.js +0 -33
  146. package/_baseFlatten-D4huXoEI.js +0 -92
  147. package/_baseGet-BSK_nnoz.js +0 -109
  148. package/_baseIsEqual-B5xLoweL.js +0 -238
  149. package/_baseIteratee-p6Nj07-n.js +0 -126
  150. package/_baseSlice-GAv_YFTT.js +0 -20
  151. package/_baseSum-D0WC1dN0.js +0 -13
  152. package/_baseUniq-CpupKWcL.js +0 -89
  153. package/_commonjsHelpers-CUmg6egw.js +0 -6
  154. package/_createAggregator-BpVy5xMi.js +0 -63
  155. package/_getPrototype-D1LAdQKO.js +0 -5
  156. package/_getTag-D3ToyefI.js +0 -126
  157. package/cloneDeep-CjP5k9zW.js +0 -8
  158. package/countBy-C69WslUA.js +0 -14
  159. package/debounce-bV0h5FC5.js +0 -92
  160. package/get-D3C3lEU3.js +0 -8
  161. package/groupBy-DC2oOuBN.js +0 -14
  162. package/iconify-CXMreGTg.js +0 -1782
  163. package/identity-CPGTqrE4.js +0 -6
  164. package/index-BDVjGvMI.js +0 -696
  165. package/index-BHPT3qoB.js +0 -1172
  166. package/index-BMxyILVD.js +0 -465
  167. package/index-BbPn6-Mw.js +0 -15750
  168. package/index-Dz1kF2MU.js +0 -17654
  169. package/isEmpty-BQkZubqU.js +0 -29
  170. package/isNil-CIubwp4T.js +0 -6
  171. package/isObject-FTY-5JQX.js +0 -7
  172. package/isObjectLike-OAgjjZye.js +0 -48
  173. package/isSymbol-Xd2FsJyp.js +0 -8
  174. package/last-CUCl67Im.js +0 -7
  175. package/sortBy-B-UKp4GT.js +0 -100
  176. package/sumBy-MYkDPHZL.js +0 -8
  177. package/tabs-xGuUGsJd.js +0 -254
  178. package/toFinite-Bc55msYj.js +0 -16
  179. package/toNumber-DPxy1FBy.js +0 -39
  180. package/useClueTypeConfig-CH-nGq6a.js +0 -3184
  181. package/utils-Dr4wbKBZ.js +0 -4182
@@ -1,188 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { I as Icon } from "./iconify-CXMreGTg.js";
3
- import { useTheme, Popper, Fade, Paper, Stack, Typography, Divider } from "@mui/material";
4
- import AnnotationDetailPopover from "./components/AnnotationDetailPopover.js";
5
- import useAnnotations from "./hooks/useAnnotations.js";
6
- import { t as twitterShort } from "./utils-Dr4wbKBZ.js";
7
- import { useState, useRef, useCallback, useEffect, useMemo } from "react";
8
- import { c as createContext, u as useContextSelector } from "./index-BDVjGvMI.js";
9
- import { SHOW_EVENT_ID, HIDE_EVENT_ID } from "./data/event.js";
10
- import { safeDispatchEvent, safeAddEventListener } from "./utils/window.js";
11
- import { i as isNull } from "./AnnotationDetails-YAPoqw3R.js";
12
- const CluePopupContext = createContext(null);
13
- const CluePopupProvider = ({ children }) => {
14
- const [popupType, setPopupType] = useState(null);
15
- const [detailsAnchorEl, setDetailsAnchorEl] = useState(null);
16
- const [detailsData, setDetailsData] = useState(null);
17
- const [detailsContent, setDetailsContent] = useState(null);
18
- const [popoverProps, setPopoverProps] = useState({});
19
- const externalOnClose = useRef(null);
20
- const showInfo = useCallback((type, anchorEl, value, options) => {
21
- safeDispatchEvent(
22
- new CustomEvent(SHOW_EVENT_ID, {
23
- detail: {
24
- type,
25
- anchorEl,
26
- value,
27
- options
28
- }
29
- })
30
- );
31
- }, []);
32
- const closeInfo = useCallback(
33
- (type, value) => {
34
- safeDispatchEvent(
35
- new CustomEvent(HIDE_EVENT_ID, {
36
- detail: {
37
- type,
38
- value
39
- }
40
- })
41
- );
42
- },
43
- // eslint-disable-next-line react-hooks/exhaustive-deps
44
- []
45
- );
46
- const handleShowPopup = useCallback((event) => {
47
- const { detail } = event;
48
- setPopupType(detail.type);
49
- setDetailsData(detail.value);
50
- if (detail.options) {
51
- if (detail.options.content) {
52
- setDetailsContent(detail.options.content);
53
- }
54
- if (detail.options.onClose) {
55
- externalOnClose.current = detail.options.onClose;
56
- }
57
- if (detail.options.popoverProps) {
58
- setPopoverProps(detail.options.popoverProps);
59
- }
60
- }
61
- setDetailsAnchorEl(detail.anchorEl);
62
- }, []);
63
- const handleHidePopup = useCallback(
64
- (event) => {
65
- const { detail } = event;
66
- if (detailsData && (detail.type !== popupType || detailsData.type !== detail.value.type || detailsData.value !== detail.value.value)) {
67
- return;
68
- }
69
- setPopupType(null);
70
- setDetailsAnchorEl(null);
71
- setDetailsData(null);
72
- setDetailsContent(null);
73
- setPopoverProps({});
74
- externalOnClose.current = null;
75
- },
76
- [detailsData, popupType]
77
- );
78
- useEffect(() => {
79
- const cleanupShow = safeAddEventListener(SHOW_EVENT_ID, handleShowPopup);
80
- const cleanupHide = safeAddEventListener(HIDE_EVENT_ID, handleHidePopup);
81
- return () => {
82
- cleanupShow();
83
- cleanupHide();
84
- };
85
- }, [handleShowPopup, handleHidePopup]);
86
- const context = useMemo(
87
- () => ({
88
- showInfo,
89
- closeInfo,
90
- __detailsContent: detailsContent
91
- }),
92
- [closeInfo, detailsContent, showInfo]
93
- );
94
- return /* @__PURE__ */ jsxs(CluePopupContext.Provider, { value: context, children: [
95
- children,
96
- /* @__PURE__ */ jsx(
97
- AnnotationDetailPopover,
98
- {
99
- ...popoverProps,
100
- anchorEl: detailsAnchorEl,
101
- open: !!detailsAnchorEl && popupType === "details",
102
- enrichRequest: detailsData,
103
- onClose: () => {
104
- if (externalOnClose.current) {
105
- externalOnClose.current();
106
- } else {
107
- closeInfo("details", detailsData);
108
- }
109
- }
110
- }
111
- ),
112
- /* @__PURE__ */ jsx(
113
- AnnotationPreview,
114
- {
115
- ...popoverProps,
116
- anchorEl: detailsAnchorEl,
117
- open: !!detailsAnchorEl && !isNull(popupType) && popupType !== "details",
118
- annotationType: popupType,
119
- enrichRequest: detailsData
120
- }
121
- )
122
- ] });
123
- };
124
- const AnnotationPreview = ({ annotationType, anchorEl, enrichRequest, open, ...otherProps }) => {
125
- const theme = useTheme();
126
- const _detailsContent = useContextSelector(CluePopupContext, (state) => state.__detailsContent);
127
- const [annotations] = useAnnotations(enrichRequest == null ? void 0 : enrichRequest.type, enrichRequest == null ? void 0 : enrichRequest.value, enrichRequest == null ? void 0 : enrichRequest.classification);
128
- const filteredAnnotations = useMemo(
129
- () => annotationType === "actionResults" ? [] : annotations.filter((annotation) => annotation.type === annotationType),
130
- [annotationType, annotations]
131
- );
132
- const getZIndex = useCallback((_anchorEl) => {
133
- try {
134
- const zIndex = parseInt(window.getComputedStyle(_anchorEl, null).getPropertyValue("z-index"));
135
- if (isNaN(zIndex)) {
136
- return getZIndex(_anchorEl.parentElement);
137
- }
138
- return (zIndex + 2).toString();
139
- } catch {
140
- return "2";
141
- }
142
- }, []);
143
- if (!filteredAnnotations.length && !_detailsContent) {
144
- return null;
145
- }
146
- return /* @__PURE__ */ jsx(
147
- Popper,
148
- {
149
- ...otherProps,
150
- open,
151
- anchorEl,
152
- placement: "bottom-start",
153
- sx: [{ zIndex: getZIndex(anchorEl) }, ...Array.isArray(otherProps.sx) ? otherProps.sx : [otherProps.sx]],
154
- children: /* @__PURE__ */ jsx(Fade, { in: !!anchorEl, children: /* @__PURE__ */ jsx(Paper, { sx: { overflowY: "auto", maxWidth: "500px", boxShadow: theme.shadows[2] }, children: /* @__PURE__ */ jsx(Stack, { direction: "column", sx: { p: 1 }, spacing: 1, divider: /* @__PURE__ */ jsx(Divider, { orientation: "horizontal" }), children: _detailsContent ?? filteredAnnotations.map((annotation) => /* @__PURE__ */ jsxs(
155
- Stack,
156
- {
157
- direction: "column",
158
- spacing: 1,
159
- children: [
160
- /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, alignItems: "center", children: [
161
- annotation.analytic_icon && /* @__PURE__ */ jsx(
162
- Icon,
163
- {
164
- icon: annotation.analytic_icon,
165
- style: { filter: "drop-shadow(0px 0px 1px rgb(0 0 0 / 0.4))" }
166
- }
167
- ),
168
- /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { textTransform: "capitalize" }, children: annotation.analytic ?? annotation.author }),
169
- /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "text.secondary", children: [
170
- "(",
171
- twitterShort(annotation.timestamp),
172
- ")"
173
- ] })
174
- ] }),
175
- /* @__PURE__ */ jsx(Typography, { variant: "body2", children: annotation.summary }),
176
- /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: annotation.value })
177
- ]
178
- },
179
- annotation.analytic + annotation.author + annotation.value + annotation.link + annotation.summary + annotation.timestamp
180
- )) }) }) })
181
- }
182
- );
183
- };
184
- export {
185
- AnnotationPreview as A,
186
- CluePopupContext as C,
187
- CluePopupProvider as a
188
- };
@@ -1,522 +0,0 @@
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-CH-nGq6a.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, useMemo, useState, useRef, useEffect, useCallback } 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;
93
- const clueConfig = useClueConfig();
94
- const database = useContext(ClueDatabaseContext);
95
- const defaultClassification = useMemo(() => {
96
- var _a2, _b;
97
- return (_b = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b.UNRESTRICTED;
98
- }, [clueConfig.config]);
99
- const [isReady, setIsReady] = useState(ready);
100
- const runningRequestCount = useRef(0);
101
- const [sources, setSources] = useState([]);
102
- const { availableSources, typesDetection } = useClueTypeConfig(
103
- enabled && isReady,
104
- baseURL,
105
- debugLogging,
106
- getToken,
107
- onNetworkCall
108
- );
109
- useEffect(() => {
110
- if (skipConfigCall || !enabled || !isReady) {
111
- return;
112
- }
113
- const headers = {};
114
- const token = getToken == null ? void 0 : getToken();
115
- if (token) {
116
- headers.Authorization = `Bearer ${token}`;
117
- }
118
- let requestConfig = { baseURL, headers };
119
- if (onNetworkCall) {
120
- requestConfig = onNetworkCall(requestConfig);
121
- }
122
- api.configs.get(requestConfig).then(clueConfig.setConfig);
123
- }, [baseURL, onNetworkCall, skipConfigCall, isReady]);
124
- const [customIconify, setCustomIconify] = useState(_customIconify);
125
- useEffect(() => {
126
- if (_customIconify) {
127
- setCustomIconify(_customIconify);
128
- }
129
- }, [_customIconify]);
130
- useEffect(() => {
131
- if (publicIconify) {
132
- return;
133
- }
134
- let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
135
- if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
136
- iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
137
- }
138
- if (iconURL) {
139
- clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
140
- addAPIProvider("", {
141
- resources: [iconURL]
142
- });
143
- }
144
- }, [baseURL, customIconify, debugLogging, publicIconify]);
145
- const _addEntries = useCallback(
146
- async (entries) => {
147
- const newRecords = [];
148
- for (const entry of entries) {
149
- const { latency, source, type, value: value2, items, error } = entry;
150
- if (error) {
151
- newRecords.push({
152
- id: v4(),
153
- source,
154
- type,
155
- value: value2,
156
- annotations: [],
157
- classification: defaultClassification,
158
- latency,
159
- count: 0,
160
- error
161
- });
162
- }
163
- for (const item of items) {
164
- const { classification, count, link, annotations } = item;
165
- await database.selectors.find({ selector: { type, value: value2, source, classification } }).incrementalRemove();
166
- const record = {
167
- id: v4(),
168
- source,
169
- type,
170
- value: value2,
171
- annotations,
172
- classification,
173
- latency,
174
- count,
175
- link,
176
- error
177
- };
178
- if (newRecords.some((_entry) => _entry.id === record.id)) {
179
- record.id = v4();
180
- }
181
- newRecords.push(record);
182
- }
183
- }
184
- const result = await database.selectors.bulkInsert(newRecords);
185
- if (result.error.length > 0) {
186
- console.warn("Errors on upsert:");
187
- result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
188
- }
189
- },
190
- [database, defaultClassification]
191
- );
192
- const enrich = useCallback(
193
- async (type, value2, _options = {}) => {
194
- var _a2, _b;
195
- if (!type || !value2) {
196
- console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
197
- return {};
198
- }
199
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
200
- const options = {
201
- timeout: defaultTimeout,
202
- force: false,
203
- includeRaw: false,
204
- noCache: false,
205
- classification: defaultClassification,
206
- sources: _sources,
207
- ..._options
208
- };
209
- const headers = {};
210
- const token = getToken == null ? void 0 : getToken();
211
- if (token) {
212
- headers.Authorization = `Bearer ${token}`;
213
- }
214
- let requestConfig = { baseURL, headers };
215
- if (onNetworkCall) {
216
- requestConfig = onNetworkCall(requestConfig);
217
- }
218
- const selector = {
219
- type,
220
- value: value2,
221
- classification: options.classification
222
- };
223
- let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({ selector: { ...selector } }).exec());
224
- if (!statusRecord) {
225
- statusRecord = await ((_b = database.status) == null ? void 0 : _b.insert({
226
- id: v4(),
227
- type: selector.type,
228
- value: selector.value,
229
- classification: selector.classification ?? defaultClassification,
230
- status: "in-progress"
231
- }));
232
- } else {
233
- await statusRecord.incrementalPatch({ status: "in-progress" });
234
- }
235
- try {
236
- const enrichmentResult = await post([selector], options.sources, options, requestConfig);
237
- const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
238
- await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
239
- await _addEntries(Object.values(enrichData));
240
- return enrichData;
241
- } catch (e) {
242
- console.error(e);
243
- return {};
244
- }
245
- },
246
- [
247
- _addEntries,
248
- availableSources,
249
- baseURL,
250
- database,
251
- defaultClassification,
252
- defaultTimeout,
253
- getToken,
254
- onNetworkCall,
255
- pickSources,
256
- sources
257
- ]
258
- );
259
- const bulkEnrich = useCallback(
260
- async (bulkRequest, _options) => {
261
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
262
- const options = {
263
- timeout: defaultTimeout,
264
- includeRaw: false,
265
- noCache: false,
266
- classification: defaultClassification,
267
- sources: _sources,
268
- ..._options
269
- };
270
- const headers = {};
271
- const token = getToken == null ? void 0 : getToken();
272
- if (token) {
273
- headers.Authorization = `Bearer ${token}`;
274
- }
275
- let requestConfig = { baseURL, headers };
276
- if (onNetworkCall) {
277
- requestConfig = onNetworkCall(requestConfig);
278
- }
279
- const statuses = [];
280
- for (const selector of bulkRequest) {
281
- const query = { type: selector.type, value: selector.value, classification: options.classification };
282
- let statusRecord = await database.status.findOne({
283
- selector: query
284
- }).incrementalPatch({
285
- status: "in-progress"
286
- });
287
- if (!statusRecord) {
288
- statusRecord = await database.status.insert({
289
- id: v4(),
290
- ...query,
291
- status: "in-progress",
292
- sources: options.sources
293
- });
294
- }
295
- statuses.push(statusRecord.toMutableJSON());
296
- }
297
- try {
298
- const result = await post(bulkRequest, options.sources, options, requestConfig);
299
- const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
300
- await _addEntries(entries);
301
- return result;
302
- } catch (e) {
303
- console.error(e);
304
- return {};
305
- } finally {
306
- database.status.bulkUpsert(
307
- uniqBy(statuses, (_record) => _record.id).map((record) => {
308
- record.status = "complete";
309
- return record;
310
- })
311
- );
312
- }
313
- },
314
- [
315
- pickSources,
316
- sources,
317
- availableSources,
318
- defaultTimeout,
319
- defaultClassification,
320
- getToken,
321
- baseURL,
322
- onNetworkCall,
323
- database,
324
- _addEntries
325
- ]
326
- );
327
- const enrichFailedEnrichments = useCallback(async () => {
328
- const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
329
- const byClassification = groupBy(failedEnrichments, "classification");
330
- const newRequests = [];
331
- for (const [classification, selectors] of Object.entries(byClassification)) {
332
- const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
333
- Object.values(bySelector).forEach((records) => {
334
- newRequests.push({
335
- id: v4(),
336
- type: records[0].type,
337
- value: records[0].value,
338
- classification,
339
- sources: uniq(records.map((_record) => _record.source)).sort(),
340
- status: "pending"
341
- });
342
- });
343
- }
344
- await database.status.bulkInsert(newRequests);
345
- await database.selectors.bulkRemove(failedEnrichments);
346
- }, [database]);
347
- const enrichQueued = useMemo(
348
- () => debounce(
349
- async () => {
350
- if (!(database == null ? void 0 : database.status)) {
351
- return;
352
- } else if (database.status.closed) {
353
- console.warn("Status database is closed, will not enrich");
354
- return;
355
- }
356
- const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
357
- if (selectors.length < 1) {
358
- return;
359
- }
360
- const chunks = chunk(selectors, chunkSize);
361
- clueDebugLogger(
362
- `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
363
- debugLogging
364
- );
365
- await Promise.all(
366
- // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
367
- // backend, both on the pod level and kubernetes level
368
- chunks.map(async (reqsChunk) => {
369
- let _interval = null;
370
- if (runningRequestCount.current <= maxRequestCount) {
371
- runningRequestCount.current += 1;
372
- } else {
373
- let startOfWait = Date.now();
374
- await new Promise((res) => {
375
- _interval = setInterval(() => {
376
- clueDebugLogger(
377
- `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
378
- debugLogging
379
- );
380
- if (runningRequestCount.current < maxRequestCount) {
381
- res();
382
- }
383
- }, 400);
384
- }).finally(() => {
385
- runningRequestCount.current += 1;
386
- clearInterval(_interval);
387
- });
388
- }
389
- try {
390
- const options = {};
391
- const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
392
- if (_sources.length > 0) {
393
- options.sources = _sources;
394
- }
395
- await bulkEnrich(
396
- reqsChunk.map((record) => record.toSelector()),
397
- options
398
- );
399
- await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
400
- } catch (e) {
401
- console.error(e);
402
- } finally {
403
- runningRequestCount.current -= 1;
404
- if (_interval) {
405
- clearInterval(_interval);
406
- }
407
- }
408
- })
409
- );
410
- },
411
- 200,
412
- { maxWait: 500, leading: false }
413
- ),
414
- [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
415
- );
416
- useEffect(() => {
417
- {
418
- return;
419
- }
420
- }, [database, debugLogging]);
421
- useEffect(() => {
422
- if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
423
- return;
424
- }
425
- const observer = database.status.find({
426
- selector: {
427
- status: "pending"
428
- }
429
- }).$.subscribe(() => enrichQueued());
430
- return () => {
431
- try {
432
- observer == null ? void 0 : observer.unsubscribe();
433
- } catch (e) {
434
- console.warn(e);
435
- }
436
- };
437
- }, [enabled, isReady, database, debugLogging, enrichQueued]);
438
- const queueEnrich = useCallback(
439
- async (type, value2, classification) => {
440
- if (!type) {
441
- throw new Error("Type cannot be null");
442
- }
443
- if (!value2) {
444
- throw new Error("Value cannot be null");
445
- }
446
- const query = { type, value: value2, classification: classification ?? defaultClassification };
447
- let statusRecord = await database.status.findOne({
448
- selector: query
449
- }).exec();
450
- if (!statusRecord) {
451
- statusRecord = await database.status.queueInsert({
452
- id: v4(),
453
- ...query,
454
- status: "pending"
455
- });
456
- }
457
- return statusRecord;
458
- },
459
- [defaultClassification, database]
460
- );
461
- const guessType = useCallback(
462
- (value2) => {
463
- var _a2, _b;
464
- if (!value2) {
465
- return null;
466
- }
467
- const types = Object.entries(typesDetection);
468
- const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
469
- if (regularCheck) {
470
- return regularCheck;
471
- }
472
- const lowercased = value2.toLowerCase();
473
- const lowercaseCheck = (_b = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b[0];
474
- if (lowercaseCheck) {
475
- return lowercaseCheck;
476
- }
477
- return null;
478
- },
479
- [typesDetection]
480
- );
481
- const value = useMemo(
482
- () => {
483
- var _a2;
484
- return {
485
- bulkEnrich,
486
- enrich,
487
- enrichFailedEnrichments,
488
- sources,
489
- setSources,
490
- typesDetection,
491
- availableSources,
492
- guessType,
493
- queueEnrich,
494
- setCustomIconify,
495
- setReady: setIsReady,
496
- defaultClassification,
497
- ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
498
- };
499
- },
500
- [
501
- bulkEnrich,
502
- enrich,
503
- enrichFailedEnrichments,
504
- sources,
505
- typesDetection,
506
- availableSources,
507
- guessType,
508
- queueEnrich,
509
- defaultClassification,
510
- isReady,
511
- database,
512
- (_a = clueConfig.config) == null ? void 0 : _a.c12nDef
513
- ]
514
- );
515
- return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
516
- };
517
- export {
518
- ClueEnrichContext as C,
519
- ClueEnrichProvider as a,
520
- uniqBy as b,
521
- uniq as u
522
- };