@cccsaurora/clue-ui 0.15.0-dev.30 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/package.json +141 -37
  2. package/ActionForm-DgfJwTzt.js +0 -436
  3. package/AnnotationPreview-BvNpZOP0.js +0 -188
  4. package/ClueEnrichContext-DXwLVp0M.js +0 -518
  5. package/FlexOne-BSYAhhtG.js +0 -9
  6. package/_Map-kgDsDYxq.js +0 -64
  7. package/_MapCache-DabaaWfq.js +0 -161
  8. package/_Uint8Array-BlVVH1tp.js +0 -129
  9. package/_baseAssignValue-CNbcU6Nb.js +0 -25
  10. package/_baseClone-D3a8Pa4T.js +0 -284
  11. package/_baseExtremum-B1o1zHjR.js +0 -33
  12. package/_baseFlatten-D4huXoEI.js +0 -92
  13. package/_baseGet-BSK_nnoz.js +0 -109
  14. package/_baseIsEqual-B5xLoweL.js +0 -238
  15. package/_baseIteratee-p6Nj07-n.js +0 -126
  16. package/_baseSlice-GAv_YFTT.js +0 -20
  17. package/_baseSum-D0WC1dN0.js +0 -13
  18. package/_baseUniq-CpupKWcL.js +0 -89
  19. package/_commonjsHelpers-CUmg6egw.js +0 -6
  20. package/_createAggregator-BpVy5xMi.js +0 -63
  21. package/_getPrototype-D1LAdQKO.js +0 -5
  22. package/_getTag-D3ToyefI.js +0 -126
  23. package/api/lookup/enrich.d.ts +0 -10
  24. package/api/lookup/index.d.ts +0 -5
  25. package/api/lookup/types.d.ts +0 -5
  26. package/api/lookup/types_detection.d.ts +0 -5
  27. package/cloneDeep-CjP5k9zW.js +0 -8
  28. package/components/AnnotationBody.d.ts +0 -6
  29. package/components/AnnotationBody.js +0 -56
  30. package/components/AnnotationDetailPopover.d.ts +0 -14
  31. package/components/AnnotationDetailPopover.js +0 -61
  32. package/components/AnnotationDetails.d.ts +0 -8
  33. package/components/AnnotationDetails.js +0 -172
  34. package/components/AnnotationEntry.d.ts +0 -6
  35. package/components/AnnotationEntry.js +0 -59
  36. package/components/AnnotationPreview.d.ts +0 -14
  37. package/components/AnnotationPreview.js +0 -11
  38. package/components/ClassificationChip.d.ts +0 -11
  39. package/components/ClassificationChip.js +0 -52
  40. package/components/CountBadge.d.ts +0 -8
  41. package/components/CountBadge.js +0 -34
  42. package/components/EnrichedCard.d.ts +0 -14
  43. package/components/EnrichedCard.js +0 -162
  44. package/components/EnrichedChip.d.ts +0 -9
  45. package/components/EnrichedChip.js +0 -176
  46. package/components/EnrichedTypography.d.ts +0 -16
  47. package/components/EnrichedTypography.js +0 -178
  48. package/components/ErrorBoundary.d.ts +0 -15
  49. package/components/ErrorBoundary.js +0 -36
  50. package/components/RetryFailedEnrichments.d.ts +0 -2
  51. package/components/RetryFailedEnrichments.js +0 -13
  52. package/components/SourcePicker.d.ts +0 -2
  53. package/components/SourcePicker.js +0 -98
  54. package/components/actions/ActionForm.d.ts +0 -6
  55. package/components/actions/ActionForm.js +0 -16
  56. package/components/actions/ExecutePopover.d.ts +0 -10
  57. package/components/actions/ExecutePopover.js +0 -93
  58. package/components/actions/ResultModal.d.ts +0 -9
  59. package/components/actions/ResultModal.js +0 -46
  60. package/components/actions/form/schemaAdapter.d.ts +0 -3
  61. package/components/actions/form/schemaAdapter.js +0 -47
  62. package/components/display/graph/ExpandMoreButton.d.ts +0 -7
  63. package/components/display/graph/ExpandMoreButton.js +0 -18
  64. package/components/display/graph/elements/NodeCard.d.ts +0 -10
  65. package/components/display/graph/elements/NodeCard.js +0 -146
  66. package/components/display/graph/elements/NodeTag.d.ts +0 -9
  67. package/components/display/graph/elements/NodeTag.js +0 -17
  68. package/components/display/graph/index.d.ts +0 -9
  69. package/components/display/graph/index.js +0 -438
  70. package/components/display/graph/visualizations/Leaf.d.ts +0 -25
  71. package/components/display/graph/visualizations/Leaf.js +0 -125
  72. package/components/display/graph/visualizations/cloud/index.d.ts +0 -24
  73. package/components/display/graph/visualizations/cloud/index.js +0 -141
  74. package/components/display/graph/visualizations/icons/BaseIcon.d.ts +0 -12
  75. package/components/display/graph/visualizations/icons/BaseIcon.js +0 -37
  76. package/components/display/graph/visualizations/icons/BugIcon.d.ts +0 -5
  77. package/components/display/graph/visualizations/icons/BugIcon.js +0 -18
  78. package/components/display/graph/visualizations/icons/HostIcon.d.ts +0 -5
  79. package/components/display/graph/visualizations/icons/HostIcon.js +0 -24
  80. package/components/display/graph/visualizations/icons/NetworkIcon.d.ts +0 -5
  81. package/components/display/graph/visualizations/icons/NetworkIcon.js +0 -24
  82. package/components/display/graph/visualizations/icons/ProcessIcon.d.ts +0 -5
  83. package/components/display/graph/visualizations/icons/ProcessIcon.js +0 -18
  84. package/components/display/graph/visualizations/icons/TargetIcon.d.ts +0 -5
  85. package/components/display/graph/visualizations/icons/TargetIcon.js +0 -19
  86. package/components/display/graph/visualizations/icons/index.d.ts +0 -2
  87. package/components/display/graph/visualizations/icons/index.js +0 -16
  88. package/components/display/graph/visualizations/panels/NodePanel.d.ts +0 -8
  89. package/components/display/graph/visualizations/panels/NodePanel.js +0 -12
  90. package/components/display/graph/visualizations/tree/BundleLine.d.ts +0 -29
  91. package/components/display/graph/visualizations/tree/BundleLine.js +0 -121
  92. package/components/display/graph/visualizations/tree/Triangle.d.ts +0 -9
  93. package/components/display/graph/visualizations/tree/Triangle.js +0 -26
  94. package/components/display/graph/visualizations/tree/index.d.ts +0 -36
  95. package/components/display/graph/visualizations/tree/index.js +0 -485
  96. package/components/display/graph/visualizations/tree/types.d.ts +0 -11
  97. package/components/display/graph/visualizations/tree/types.js +0 -1
  98. package/components/display/icons/Iconified.d.ts +0 -9
  99. package/components/display/icons/Iconified.js +0 -29
  100. package/components/display/json/index.d.ts +0 -14
  101. package/components/display/json/index.js +0 -12
  102. package/components/display/markdown/DynamicTabs.d.ts +0 -8
  103. package/components/display/markdown/DynamicTabs.js +0 -26
  104. package/components/display/markdown/index.d.ts +0 -9
  105. package/components/display/markdown/index.js +0 -13389
  106. package/components/display/markdown/markdownPlugins/tabs.d.ts +0 -3
  107. package/components/display/markdown/markdownPlugins/tabs.js +0 -4
  108. package/components/enrichment/EnrichPopover.d.ts +0 -10
  109. package/components/enrichment/EnrichPopover.js +0 -88
  110. package/components/fetchers/Fetcher.d.ts +0 -17
  111. package/components/fetchers/Fetcher.js +0 -188
  112. package/components/fetchers/PreviewModal.d.ts +0 -8
  113. package/components/fetchers/PreviewModal.js +0 -22
  114. package/components/fetchers/StatusChip.d.ts +0 -8
  115. package/components/fetchers/StatusChip.js +0 -30
  116. package/components/group/Entry.d.ts +0 -8
  117. package/components/group/Entry.js +0 -15
  118. package/components/group/Group.d.ts +0 -12
  119. package/components/group/Group.js +0 -15
  120. package/components/group/GroupControl.d.ts +0 -4
  121. package/components/group/GroupControl.js +0 -103
  122. package/components/stats/QueryStatus.d.ts +0 -4
  123. package/components/stats/QueryStatus.js +0 -61
  124. package/countBy-C69WslUA.js +0 -14
  125. package/data/event.d.ts +0 -12
  126. package/data/event.js +0 -8
  127. package/database/index.d.ts +0 -4
  128. package/database/index.js +0 -4
  129. package/database/selector.schema.json.d.ts +0 -119
  130. package/database/status.schema.json.d.ts +0 -38
  131. package/database/types.d.ts +0 -64
  132. package/debounce-bV0h5FC5.js +0 -92
  133. package/en/translation.json +0 -135
  134. package/fr/translation.json +0 -135
  135. package/get-D3C3lEU3.js +0 -8
  136. package/groupBy-DC2oOuBN.js +0 -14
  137. package/hooks/ClueActionContext.d.ts +0 -86
  138. package/hooks/ClueActionContext.js +0 -18
  139. package/hooks/ClueComponentContext.d.ts +0 -10
  140. package/hooks/ClueComponentContext.js +0 -40
  141. package/hooks/ClueConfigProvider.d.ts +0 -12
  142. package/hooks/ClueConfigProvider.js +0 -23
  143. package/hooks/ClueDatabaseContext.d.ts +0 -10
  144. package/hooks/ClueDatabaseContext.js +0 -23
  145. package/hooks/ClueEnrichContext.d.ts +0 -6
  146. package/hooks/ClueEnrichContext.js +0 -15
  147. package/hooks/ClueEnrichContextType.d.ts +0 -113
  148. package/hooks/ClueEnrichProps.d.ts +0 -81
  149. package/hooks/ClueFetcherContext.d.ts +0 -35
  150. package/hooks/ClueFetcherContext.js +0 -88
  151. package/hooks/ClueGroupContext.d.ts +0 -14
  152. package/hooks/ClueGroupContext.js +0 -23
  153. package/hooks/CluePopupContext.d.ts +0 -24
  154. package/hooks/CluePopupContext.js +0 -12
  155. package/hooks/ClueProvider.d.ts +0 -9
  156. package/hooks/ClueProvider.js +0 -14
  157. package/hooks/selectors.d.ts +0 -10
  158. package/hooks/selectors.js +0 -24
  159. package/hooks/useAnnotations.d.ts +0 -24
  160. package/hooks/useAnnotations.js +0 -69
  161. package/hooks/useClue.d.ts +0 -4
  162. package/hooks/useClue.js +0 -8
  163. package/hooks/useClueActions.d.ts +0 -4
  164. package/hooks/useClueActions.js +0 -5
  165. package/hooks/useClueConfig.d.ts +0 -1
  166. package/hooks/useClueConfig.js +0 -8
  167. package/hooks/useClueTypeConfig.d.ts +0 -17
  168. package/hooks/useClueTypeConfig.js +0 -7
  169. package/hooks/useComparator.d.ts +0 -16
  170. package/hooks/useComparator.js +0 -1060
  171. package/hooks/useErrors.d.ts +0 -17
  172. package/hooks/useErrors.js +0 -35
  173. package/hooks/useMyHighlights.d.ts +0 -11
  174. package/hooks/useMyHighlights.js +0 -74
  175. package/hooks/useMyLocalStorage.d.ts +0 -16
  176. package/hooks/useMyLocalStorage.js +0 -80
  177. package/iconify-CXMreGTg.js +0 -1782
  178. package/icons/Action.d.ts +0 -9
  179. package/icons/Action.js +0 -90
  180. package/icons/Assessment.d.ts +0 -11
  181. package/icons/Assessment.js +0 -123
  182. package/icons/Context.d.ts +0 -12
  183. package/icons/Context.js +0 -83
  184. package/icons/Opinion.d.ts +0 -11
  185. package/icons/Opinion.js +0 -125
  186. package/icons/iconMap.d.ts +0 -7
  187. package/icons/iconMap.js +0 -10
  188. package/identity-CPGTqrE4.js +0 -6
  189. package/index-BDVjGvMI.js +0 -696
  190. package/index-BDrtH5ec.js +0 -465
  191. package/index-C9lySIVX.js +0 -1172
  192. package/index-DJYqRcxJ.js +0 -15750
  193. package/index-Dn2NHyXg.js +0 -17654
  194. package/index.css +0 -21
  195. package/isEmpty-BQkZubqU.js +0 -29
  196. package/isNil-CIubwp4T.js +0 -6
  197. package/isObject-FTY-5JQX.js +0 -7
  198. package/isObjectLike-OAgjjZye.js +0 -48
  199. package/isSymbol-Xd2FsJyp.js +0 -8
  200. package/isUndefined-CE8h73dH.js +0 -10
  201. package/last-CUCl67Im.js +0 -7
  202. package/main.d.ts +0 -42
  203. package/main.js +0 -70
  204. package/public/manifest.json +0 -16
  205. package/public/robots.txt +0 -3
  206. package/public/svg/dark/clue-h.svg +0 -52
  207. package/public/svg/dark/clue-icon1-simple.svg +0 -33
  208. package/public/svg/dark/clue-icon1.svg +0 -44
  209. package/public/svg/dark/clue-icon2-simple.svg +0 -26
  210. package/public/svg/dark/clue-icon2.svg +0 -37
  211. package/public/svg/dark/clue-name.svg +0 -14
  212. package/public/svg/dark/clue-v.svg +0 -52
  213. package/public/svg/light/clue-h.svg +0 -60
  214. package/public/svg/light/clue-icon1-simple.svg +0 -37
  215. package/public/svg/light/clue-icon1.svg +0 -48
  216. package/public/svg/light/clue-icon2-simple.svg +0 -30
  217. package/public/svg/light/clue-icon2.svg +0 -41
  218. package/public/svg/light/clue-name.svg +0 -14
  219. package/public/svg/light/clue-v.svg +0 -60
  220. package/sortBy-B-UKp4GT.js +0 -100
  221. package/sumBy-MYkDPHZL.js +0 -8
  222. package/tabs-xGuUGsJd.js +0 -254
  223. package/text/Frequency.d.ts +0 -9
  224. package/text/Frequency.js +0 -49
  225. package/toFinite-CArjry_l.js +0 -16
  226. package/toNumber-DPxy1FBy.js +0 -39
  227. package/types/EnrichmentProps.d.ts +0 -73
  228. package/types/RunningActionData.d.ts +0 -15
  229. package/types/WithActionData.d.ts +0 -9
  230. package/types/action.d.ts +0 -25
  231. package/types/config.d.ts +0 -16
  232. package/types/fetcher.d.ts +0 -60
  233. package/types/graph.d.ts +0 -101
  234. package/types/lookup.d.ts +0 -62
  235. package/types/network.d.ts +0 -9
  236. package/useClueTypeConfig-D9ZSxa4F.js +0 -3096
  237. package/utils/chain.d.ts +0 -14
  238. package/utils/chain.js +0 -106
  239. package/utils/classificationParser.d.ts +0 -195
  240. package/utils/classificationParser.js +0 -553
  241. package/utils/constants.d.ts +0 -26
  242. package/utils/constants.js +0 -36
  243. package/utils/graph.d.ts +0 -13
  244. package/utils/graph.js +0 -79
  245. package/utils/hashUtil.d.ts +0 -6
  246. package/utils/hashUtil.js +0 -11
  247. package/utils/line.d.ts +0 -28
  248. package/utils/line.js +0 -136
  249. package/utils/loggerUtil.d.ts +0 -6
  250. package/utils/loggerUtil.js +0 -8
  251. package/utils/sessionStorage.d.ts +0 -9
  252. package/utils/sessionStorage.js +0 -51
  253. package/utils/utils.d.ts +0 -13
  254. package/utils/utils.js +0 -11
  255. package/utils/window.d.ts +0 -3
  256. package/utils/window.js +0 -24
  257. package/utils-CxIhC2xH.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-CxIhC2xH.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 "./isUndefined-CE8h73dH.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,518 +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-D9ZSxa4F.js";
4
- import { clueDebugLogger } from "./utils/loggerUtil.js";
5
- import { useContext, useMemo, useState, useRef, useEffect, useCallback } from "react";
6
- import { c as createContext } from "./index-BDVjGvMI.js";
7
- import { ClueDatabaseContext } from "./hooks/ClueDatabaseContext.js";
8
- import useClueConfig from "./hooks/useClueConfig.js";
9
- import { g as groupBy } from "./groupBy-DC2oOuBN.js";
10
- import { b as baseUniq } from "./_baseUniq-CpupKWcL.js";
11
- import { d as debounce } from "./debounce-bV0h5FC5.js";
12
- import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
13
- import { t as toFinite } from "./toFinite-CArjry_l.js";
14
- function toInteger(value) {
15
- var result = toFinite(value), remainder = result % 1;
16
- return result === result ? remainder ? result - remainder : result : 0;
17
- }
18
- var nativeCeil = Math.ceil, nativeMax = Math.max;
19
- function chunk(array, size, guard) {
20
- if (size === void 0) {
21
- size = 1;
22
- } else {
23
- size = nativeMax(toInteger(size), 0);
24
- }
25
- var length = array == null ? 0 : array.length;
26
- if (!length || size < 1) {
27
- return [];
28
- }
29
- var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
30
- while (index < length) {
31
- result[resIndex++] = baseSlice(array, index, index += size);
32
- }
33
- return result;
34
- }
35
- function uniq(array) {
36
- return array && array.length ? baseUniq(array) : [];
37
- }
38
- let getRandomValues;
39
- const rnds8 = new Uint8Array(16);
40
- function rng() {
41
- if (!getRandomValues) {
42
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
43
- if (!getRandomValues) {
44
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
45
- }
46
- }
47
- return getRandomValues(rnds8);
48
- }
49
- const byteToHex = [];
50
- for (let i = 0; i < 256; ++i) {
51
- byteToHex.push((i + 256).toString(16).slice(1));
52
- }
53
- function unsafeStringify(arr, offset = 0) {
54
- 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]];
55
- }
56
- const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
57
- const native = {
58
- randomUUID
59
- };
60
- function v4(options, buf, offset) {
61
- if (native.randomUUID && true && !options) {
62
- return native.randomUUID();
63
- }
64
- options = options || {};
65
- const rnds = options.random || (options.rng || rng)();
66
- rnds[6] = rnds[6] & 15 | 64;
67
- rnds[8] = rnds[8] & 63 | 128;
68
- return unsafeStringify(rnds);
69
- }
70
- const ClueEnrichContext = createContext(null);
71
- const ClueEnrichProvider = ({
72
- children,
73
- classification: _defaultClassification,
74
- baseURL,
75
- getToken,
76
- onNetworkCall,
77
- pickSources,
78
- chunkSize = 15,
79
- maxRequestCount = 4,
80
- defaultTimeout = 5,
81
- enabled = true,
82
- ready = false,
83
- publicIconify = true,
84
- skipConfigCall = false,
85
- customIconify: _customIconify,
86
- debugLogging = true
87
- }) => {
88
- var _a;
89
- const clueConfig = useClueConfig();
90
- const database = useContext(ClueDatabaseContext);
91
- const defaultClassification = useMemo(() => {
92
- var _a2, _b;
93
- return (_b = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b.UNRESTRICTED;
94
- }, [clueConfig.config]);
95
- const [isReady, setIsReady] = useState(ready);
96
- const runningRequestCount = useRef(0);
97
- const [sources, setSources] = useState([]);
98
- const { availableSources, typesDetection } = useClueTypeConfig(
99
- enabled && isReady,
100
- baseURL,
101
- debugLogging,
102
- getToken,
103
- onNetworkCall
104
- );
105
- useEffect(() => {
106
- if (skipConfigCall || !enabled || !isReady) {
107
- return;
108
- }
109
- const headers = {};
110
- const token = getToken == null ? void 0 : getToken();
111
- if (token) {
112
- headers.Authorization = `Bearer ${token}`;
113
- }
114
- let requestConfig = { baseURL, headers };
115
- if (onNetworkCall) {
116
- requestConfig = onNetworkCall(requestConfig);
117
- }
118
- api.configs.get(requestConfig).then(clueConfig.setConfig);
119
- }, [baseURL, onNetworkCall, skipConfigCall, isReady]);
120
- const [customIconify, setCustomIconify] = useState(_customIconify);
121
- useEffect(() => {
122
- if (_customIconify) {
123
- setCustomIconify(_customIconify);
124
- }
125
- }, [_customIconify]);
126
- useEffect(() => {
127
- if (publicIconify) {
128
- return;
129
- }
130
- let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
131
- if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
132
- iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
133
- }
134
- if (iconURL) {
135
- clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
136
- addAPIProvider("", {
137
- resources: [iconURL]
138
- });
139
- }
140
- }, [baseURL, customIconify, debugLogging, publicIconify]);
141
- const _addEntries = useCallback(
142
- async (entries) => {
143
- const newRecords = [];
144
- for (const entry of entries) {
145
- const { latency, source, type, value: value2, items, error } = entry;
146
- if (error) {
147
- newRecords.push({
148
- id: v4(),
149
- source,
150
- type,
151
- value: value2,
152
- annotations: [],
153
- classification: defaultClassification,
154
- latency,
155
- count: 0,
156
- error
157
- });
158
- }
159
- for (const item of items) {
160
- const { classification, count, link, annotations } = item;
161
- await database.selectors.find({ selector: { type, value: value2, source, classification } }).incrementalRemove();
162
- const record = {
163
- id: v4(),
164
- source,
165
- type,
166
- value: value2,
167
- annotations,
168
- classification,
169
- latency,
170
- count,
171
- link,
172
- error
173
- };
174
- if (newRecords.some((_entry) => _entry.id === record.id)) {
175
- record.id = v4();
176
- }
177
- newRecords.push(record);
178
- }
179
- }
180
- const result = await database.selectors.bulkInsert(newRecords);
181
- if (result.error.length > 0) {
182
- console.warn("Errors on upsert:");
183
- result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
184
- }
185
- },
186
- [database, defaultClassification]
187
- );
188
- const enrich = useCallback(
189
- async (type, value2, _options = {}) => {
190
- var _a2, _b;
191
- if (!type || !value2) {
192
- console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
193
- return {};
194
- }
195
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
196
- const options = {
197
- timeout: defaultTimeout,
198
- force: false,
199
- includeRaw: false,
200
- noCache: false,
201
- classification: defaultClassification,
202
- sources: _sources,
203
- ..._options
204
- };
205
- const headers = {};
206
- const token = getToken == null ? void 0 : getToken();
207
- if (token) {
208
- headers.Authorization = `Bearer ${token}`;
209
- }
210
- let requestConfig = { baseURL, headers };
211
- if (onNetworkCall) {
212
- requestConfig = onNetworkCall(requestConfig);
213
- }
214
- const selector = {
215
- type,
216
- value: value2,
217
- classification: options.classification
218
- };
219
- let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({ selector: { ...selector } }).exec());
220
- if (!statusRecord) {
221
- statusRecord = await ((_b = database.status) == null ? void 0 : _b.insert({
222
- id: v4(),
223
- type: selector.type,
224
- value: selector.value,
225
- classification: selector.classification ?? defaultClassification,
226
- status: "in-progress"
227
- }));
228
- } else {
229
- await statusRecord.incrementalPatch({ status: "in-progress" });
230
- }
231
- try {
232
- const enrichmentResult = await post([selector], options.sources, options, requestConfig);
233
- const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
234
- await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
235
- await _addEntries(Object.values(enrichData));
236
- return enrichData;
237
- } catch (e) {
238
- console.error(e);
239
- return {};
240
- }
241
- },
242
- [
243
- _addEntries,
244
- availableSources,
245
- baseURL,
246
- database,
247
- defaultClassification,
248
- defaultTimeout,
249
- getToken,
250
- onNetworkCall,
251
- pickSources,
252
- sources
253
- ]
254
- );
255
- const bulkEnrich = useCallback(
256
- async (bulkRequest, _options) => {
257
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
258
- const options = {
259
- timeout: defaultTimeout,
260
- includeRaw: false,
261
- noCache: false,
262
- classification: defaultClassification,
263
- sources: _sources,
264
- ..._options
265
- };
266
- const headers = {};
267
- const token = getToken == null ? void 0 : getToken();
268
- if (token) {
269
- headers.Authorization = `Bearer ${token}`;
270
- }
271
- let requestConfig = { baseURL, headers };
272
- if (onNetworkCall) {
273
- requestConfig = onNetworkCall(requestConfig);
274
- }
275
- const statuses = [];
276
- for (const selector of bulkRequest) {
277
- const query = { type: selector.type, value: selector.value, classification: options.classification };
278
- let statusRecord = await database.status.findOne({
279
- selector: query
280
- }).incrementalPatch({
281
- status: "in-progress"
282
- });
283
- if (!statusRecord) {
284
- statusRecord = await database.status.insert({
285
- id: v4(),
286
- ...query,
287
- status: "in-progress",
288
- sources: options.sources
289
- });
290
- }
291
- statuses.push(statusRecord.toMutableJSON());
292
- }
293
- try {
294
- const result = await post(bulkRequest, options.sources, options, requestConfig);
295
- const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
296
- await _addEntries(entries);
297
- return result;
298
- } catch (e) {
299
- console.error(e);
300
- return {};
301
- } finally {
302
- const records = await Promise.all(statuses);
303
- database.status.bulkUpsert(
304
- records.map((record) => {
305
- record.status = "complete";
306
- return record;
307
- })
308
- );
309
- }
310
- },
311
- [
312
- pickSources,
313
- sources,
314
- availableSources,
315
- defaultTimeout,
316
- defaultClassification,
317
- getToken,
318
- baseURL,
319
- onNetworkCall,
320
- database,
321
- _addEntries
322
- ]
323
- );
324
- const enrichFailedEnrichments = useCallback(async () => {
325
- const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
326
- const byClassification = groupBy(failedEnrichments, "classification");
327
- const newRequests = [];
328
- for (const [classification, selectors] of Object.entries(byClassification)) {
329
- const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
330
- Object.values(bySelector).forEach((records) => {
331
- newRequests.push({
332
- id: v4(),
333
- type: records[0].type,
334
- value: records[0].value,
335
- classification,
336
- sources: uniq(records.map((_record) => _record.source)).sort(),
337
- status: "pending"
338
- });
339
- });
340
- }
341
- await database.status.bulkInsert(newRequests);
342
- await database.selectors.bulkRemove(failedEnrichments);
343
- }, [database]);
344
- const enrichQueued = useMemo(
345
- () => debounce(
346
- async () => {
347
- if (!(database == null ? void 0 : database.status)) {
348
- return;
349
- } else if (database.status.closed) {
350
- console.warn("Status database is closed, will not enrich");
351
- return;
352
- }
353
- const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
354
- if (selectors.length < 1) {
355
- return;
356
- }
357
- const chunks = chunk(selectors, chunkSize);
358
- clueDebugLogger(
359
- `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
360
- debugLogging
361
- );
362
- await Promise.all(
363
- // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
364
- // backend, both on the pod level and kubernetes level
365
- chunks.map(async (reqsChunk) => {
366
- let _interval = null;
367
- if (runningRequestCount.current <= maxRequestCount) {
368
- runningRequestCount.current += 1;
369
- } else {
370
- let startOfWait = Date.now();
371
- await new Promise((res) => {
372
- _interval = setInterval(() => {
373
- clueDebugLogger(
374
- `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
375
- debugLogging
376
- );
377
- if (runningRequestCount.current < maxRequestCount) {
378
- res();
379
- }
380
- }, 400);
381
- }).finally(() => {
382
- runningRequestCount.current += 1;
383
- clearInterval(_interval);
384
- });
385
- }
386
- try {
387
- const options = {};
388
- const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
389
- if (_sources.length > 0) {
390
- options.sources = _sources;
391
- }
392
- await bulkEnrich(
393
- reqsChunk.map((record) => record.toSelector()),
394
- options
395
- );
396
- await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
397
- } catch (e) {
398
- console.error(e);
399
- } finally {
400
- runningRequestCount.current -= 1;
401
- if (_interval) {
402
- clearInterval(_interval);
403
- }
404
- }
405
- })
406
- );
407
- },
408
- 200,
409
- { maxWait: 500, leading: false }
410
- ),
411
- [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
412
- );
413
- useEffect(() => {
414
- {
415
- return;
416
- }
417
- }, [database, debugLogging]);
418
- useEffect(() => {
419
- if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
420
- return;
421
- }
422
- const observer = database.status.find({
423
- selector: {
424
- status: "pending"
425
- }
426
- }).$.subscribe(() => enrichQueued());
427
- return () => {
428
- try {
429
- observer == null ? void 0 : observer.unsubscribe();
430
- } catch (e) {
431
- console.warn(e);
432
- }
433
- };
434
- }, [enabled, isReady, database, debugLogging, enrichQueued]);
435
- const queueEnrich = useCallback(
436
- async (type, value2, classification) => {
437
- if (!type) {
438
- throw new Error("Type cannot be null");
439
- }
440
- if (!value2) {
441
- throw new Error("Value cannot be null");
442
- }
443
- const query = { type, value: value2, classification: classification ?? defaultClassification };
444
- let statusRecord = await database.status.findOne({
445
- selector: query
446
- }).exec();
447
- if (!statusRecord) {
448
- statusRecord = await database.status.queueInsert({
449
- id: v4(),
450
- ...query,
451
- status: "pending"
452
- });
453
- }
454
- return statusRecord;
455
- },
456
- [defaultClassification, database]
457
- );
458
- const guessType = useCallback(
459
- (value2) => {
460
- var _a2, _b;
461
- if (!value2) {
462
- return null;
463
- }
464
- const types = Object.entries(typesDetection);
465
- const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
466
- if (regularCheck) {
467
- return regularCheck;
468
- }
469
- const lowercased = value2.toLowerCase();
470
- const lowercaseCheck = (_b = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b[0];
471
- if (lowercaseCheck) {
472
- return lowercaseCheck;
473
- }
474
- return null;
475
- },
476
- [typesDetection]
477
- );
478
- const value = useMemo(
479
- () => {
480
- var _a2;
481
- return {
482
- bulkEnrich,
483
- enrich,
484
- enrichFailedEnrichments,
485
- sources,
486
- setSources,
487
- typesDetection,
488
- availableSources,
489
- guessType,
490
- queueEnrich,
491
- setCustomIconify,
492
- setReady: setIsReady,
493
- defaultClassification,
494
- ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
495
- };
496
- },
497
- [
498
- bulkEnrich,
499
- enrich,
500
- enrichFailedEnrichments,
501
- sources,
502
- typesDetection,
503
- availableSources,
504
- guessType,
505
- queueEnrich,
506
- defaultClassification,
507
- isReady,
508
- database,
509
- (_a = clueConfig.config) == null ? void 0 : _a.c12nDef
510
- ]
511
- );
512
- return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
513
- };
514
- export {
515
- ClueEnrichContext as C,
516
- ClueEnrichProvider as a,
517
- uniq as u
518
- };