@oneuptime/common 13.0.3 → 13.0.5

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 (687) hide show
  1. package/Models/DatabaseModels/Index.ts +4 -0
  2. package/Models/DatabaseModels/RumApplication.ts +1 -1
  3. package/Models/DatabaseModels/SecurityEventConnection.ts +457 -0
  4. package/Models/DatabaseModels/SecurityEventConnectionRun.ts +263 -0
  5. package/Models/DatabaseModels/TelemetryIngestionKey.ts +2 -2
  6. package/Server/API/AIInvestigationAPI.ts +484 -24
  7. package/Server/API/GoogleSecOpsConnectionAPI.ts +249 -8
  8. package/Server/API/SecurityEventConnectionAPI.ts +250 -0
  9. package/Server/API/TelemetryAPI.ts +402 -265
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1792700000000-AddSecurityEventConnections.ts +99 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
  12. package/Server/Middleware/TelemetryIngest.ts +101 -6
  13. package/Server/Services/ExceptionAggregationService.ts +7 -16
  14. package/Server/Services/GoogleSecOpsConnectionService.ts +15 -0
  15. package/Server/Services/Index.ts +4 -0
  16. package/Server/Services/InventoryItemService.ts +28 -0
  17. package/Server/Services/LogAggregationService.ts +17 -23
  18. package/Server/Services/MetricAggregationService.ts +4 -14
  19. package/Server/Services/SecurityEventConnectionRunService.ts +10 -0
  20. package/Server/Services/SecurityEventConnectionService.ts +538 -0
  21. package/Server/Services/TraceAggregationService.ts +77 -28
  22. package/Server/Types/AnalyticsDatabase/ModelPermission.ts +9 -0
  23. package/Server/Utils/AI/Chat/ObservabilityAssistant.ts +13 -1
  24. package/Server/Utils/AI/SRE/AIInvestigationEngine.ts +15 -1
  25. package/Server/Utils/AI/SRE/InvestigationEvidence.ts +658 -0
  26. package/Server/Utils/AI/SRE/InvestigationReferences.ts +324 -0
  27. package/Server/Utils/AI/Toolbox/Index.ts +38 -0
  28. package/Server/Utils/AI/Toolbox/TimelineTools.ts +9 -2
  29. package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +80 -0
  30. package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +5 -3
  31. package/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubClient.ts +1108 -0
  32. package/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubConnector.ts +732 -0
  33. package/Server/Utils/SecurityEvent/Connectors/ConnectorPlatformHealth.ts +495 -0
  34. package/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconClient.ts +689 -0
  35. package/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconConnector.ts +767 -0
  36. package/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityClient.ts +571 -0
  37. package/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityConnector.ts +827 -0
  38. package/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrClient.ts +610 -0
  39. package/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrConnector.ts +549 -0
  40. package/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelClient.ts +830 -0
  41. package/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelConnector.ts +684 -0
  42. package/Server/Utils/SecurityEvent/Connectors/Okta/OktaClient.ts +487 -0
  43. package/Server/Utils/SecurityEvent/Connectors/Okta/OktaConnector.ts +778 -0
  44. package/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionPoller.ts +1002 -0
  45. package/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionRunExecutor.ts +556 -0
  46. package/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionTester.ts +275 -0
  47. package/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectorRegistry.ts +53 -0
  48. package/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkClient.ts +709 -0
  49. package/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkConnector.ts +596 -0
  50. package/Server/Utils/SecurityEvent/Connectors/Types.ts +191 -0
  51. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.ts +353 -65
  52. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsConnectionTester.ts +777 -0
  53. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.ts +747 -148
  54. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsRunExecutor.ts +48 -2
  55. package/Server/Utils/SecurityEvent/SecurityEventDedupe.ts +81 -0
  56. package/Server/Utils/SessionReplay/SessionReplayReadService.ts +741 -40
  57. package/Server/Utils/StartServer.ts +10 -0
  58. package/Server/Utils/Telemetry/EntityRegistry.ts +8 -0
  59. package/Server/Utils/Telemetry/KubernetesResourceAttributes.ts +108 -0
  60. package/Server/Utils/Telemetry/ResourceEntityFilter.ts +174 -93
  61. package/Server/Utils/Telemetry/ResourceFacetPlanner.ts +251 -0
  62. package/Server/Utils/Telemetry/ResourceFacetResolver.ts +248 -413
  63. package/Server/Utils/Telemetry/ServiceDependencyDiscovery.ts +668 -0
  64. package/Server/Utils/Telemetry/TraceContextPropagation.ts +348 -0
  65. package/Server/Utils/Telemetry.ts +18 -0
  66. package/Tests/App/Dashboard/AIInvestigationHeaderStatus.test.tsx +413 -0
  67. package/Tests/App/Dashboard/AIRootCauseFeedItem.test.tsx +285 -0
  68. package/Tests/App/Dashboard/AffectedResourcesDisplay.test.tsx +242 -0
  69. package/Tests/App/Dashboard/AlertEpisodeViewFields.test.tsx +601 -15
  70. package/Tests/App/Dashboard/ChangeAlertStateAIHeader.test.tsx +835 -0
  71. package/Tests/App/Dashboard/CloudResourceTelemetryScope.test.ts +41 -0
  72. package/Tests/App/Dashboard/ConnectionTestModal.test.tsx +604 -0
  73. package/Tests/App/Dashboard/ConnectorTestReportView.test.tsx +738 -0
  74. package/Tests/App/Dashboard/DashboardLazyPages.test.tsx +153 -6
  75. package/Tests/App/Dashboard/EntityDetailPanel.test.tsx +165 -0
  76. package/Tests/App/Dashboard/EpisodeChangeState.test.tsx +1069 -0
  77. package/Tests/App/Dashboard/EpisodeMembersCard.test.tsx +772 -0
  78. package/Tests/App/Dashboard/EventOverviewPages.test.tsx +2354 -0
  79. package/Tests/App/Dashboard/EventOverviewSkeleton.test.tsx +210 -0
  80. package/Tests/App/Dashboard/EventStatBar.test.tsx +392 -0
  81. package/Tests/App/Dashboard/EventStatusPanel.test.tsx +247 -0
  82. package/Tests/App/Dashboard/ExceptionAIAssistance.test.tsx +606 -0
  83. package/Tests/App/Dashboard/ExceptionBreadcrumbTimeline.test.tsx +273 -0
  84. package/Tests/App/Dashboard/ExceptionDetailSideMenu.test.tsx +176 -0
  85. package/Tests/App/Dashboard/ExceptionOverviewCards.test.tsx +366 -0
  86. package/Tests/App/Dashboard/ExceptionSignalPages.test.tsx +371 -0
  87. package/Tests/App/Dashboard/ExceptionStackFrameViewer.test.tsx +440 -0
  88. package/Tests/App/Dashboard/ExceptionSummary.test.tsx +381 -0
  89. package/Tests/App/Dashboard/ExceptionTriage.test.tsx +306 -0
  90. package/Tests/App/Dashboard/ExceptionsResourceFacets.test.tsx +604 -0
  91. package/Tests/App/Dashboard/ExceptionsViewerEntityChips.test.tsx +706 -0
  92. package/Tests/App/Dashboard/FeedOrdering.test.ts +32 -0
  93. package/Tests/App/Dashboard/GoogleSecOpsConnectionForm.test.tsx +838 -0
  94. package/Tests/App/Dashboard/GoogleSecOpsConnectionsErrors.test.tsx +18 -0
  95. package/Tests/App/Dashboard/GoogleSecOpsDiagnostics.test.tsx +297 -20
  96. package/Tests/App/Dashboard/IncidentEpisodeViewFields.test.tsx +618 -13
  97. package/Tests/App/Dashboard/InfrastructureExplorer.test.tsx +254 -207
  98. package/Tests/App/Dashboard/InfrastructureGraph.test.tsx +303 -135
  99. package/Tests/App/Dashboard/InvestigationEvidenceList.test.tsx +1251 -0
  100. package/Tests/App/Dashboard/InvestigationFeedRefresh.test.tsx +303 -0
  101. package/Tests/App/Dashboard/InvestigationPanel.test.tsx +876 -8
  102. package/Tests/App/Dashboard/InvestigationPanelStatus.test.tsx +35 -0
  103. package/Tests/App/Dashboard/InvestigationReferenceLink.test.tsx +177 -0
  104. package/Tests/App/Dashboard/InvestigationReportView.test.tsx +1295 -0
  105. package/Tests/App/Dashboard/KubernetesImageReferenceView.test.tsx +114 -0
  106. package/Tests/App/Dashboard/KubernetesLogsTabChips.test.tsx +285 -0
  107. package/Tests/App/Dashboard/LogsEntityChipNames.test.tsx +316 -0
  108. package/Tests/App/Dashboard/LogsResourceFacetChips.test.tsx +361 -0
  109. package/Tests/App/Dashboard/ProfileTableEntityNames.test.tsx +432 -0
  110. package/Tests/App/Dashboard/ProfileViewEntityName.test.tsx +250 -0
  111. package/Tests/App/Dashboard/ResourceArchiveSettings.test.tsx +10 -0
  112. package/Tests/App/Dashboard/ResourceLogsTabsBareLayout.test.tsx +700 -0
  113. package/Tests/App/Dashboard/ResourcePageEntityNameProps.test.tsx +803 -0
  114. package/Tests/App/Dashboard/RumSessionReplaySideMenu.test.tsx +11 -1
  115. package/Tests/App/Dashboard/ScheduledMaintenanceChangeState.test.tsx +1026 -0
  116. package/Tests/App/Dashboard/ScheduledMaintenanceFeedRefresh.test.tsx +436 -0
  117. package/Tests/App/Dashboard/ScheduledMaintenanceOverviewPage.test.tsx +1195 -0
  118. package/Tests/App/Dashboard/SecurityEventConnectionFormModal.test.tsx +1022 -0
  119. package/Tests/App/Dashboard/SecurityEventConnectionsTable.test.tsx +905 -0
  120. package/Tests/App/Dashboard/SecurityEventsSideMenu.test.tsx +247 -0
  121. package/Tests/App/Dashboard/ServiceMapGraph.test.tsx +375 -274
  122. package/Tests/App/Dashboard/SessionReplayAuditTable.test.tsx +410 -0
  123. package/Tests/App/Dashboard/TelemetryResourceRetentionSettings.test.tsx +774 -0
  124. package/Tests/App/Dashboard/TopErrorsPanelResourceNames.test.tsx +316 -0
  125. package/Tests/App/Dashboard/TopologyDataLoading.test.tsx +30 -0
  126. package/Tests/App/Dashboard/TopologyPageNavigation.test.tsx +88 -24
  127. package/Tests/App/Dashboard/TraceExplorer.test.tsx +1590 -0
  128. package/Tests/App/Dashboard/TraceWaterfall.test.tsx +488 -0
  129. package/Tests/App/Dashboard/TracesAnalyticsSeriesLabels.test.tsx +367 -0
  130. package/Tests/App/Dashboard/TracesEntityNames.test.tsx +585 -0
  131. package/Tests/App/Dashboard/TracesResourceFacets.test.tsx +613 -0
  132. package/Tests/App/Dashboard/UseServiceNames.test.tsx +359 -0
  133. package/Tests/Models/DatabaseModels/DomainRoleTierCoverage.test.ts +7 -0
  134. package/Tests/Models/InventoryItemNaming.test.ts +132 -16
  135. package/Tests/Models/SecurityDomainAccessControl.test.ts +61 -17
  136. package/Tests/Server/API/AIInvestigationAPI.test.ts +611 -2
  137. package/Tests/Server/API/AIInvestigationEvidenceAPI.test.ts +1098 -0
  138. package/Tests/Server/API/GoogleSecOpsConnectionAPI.test.ts +409 -0
  139. package/Tests/Server/API/SecurityEventConnectionAPI.test.ts +856 -0
  140. package/Tests/Server/API/SessionReplayAPI.test.ts +528 -1
  141. package/Tests/Server/API/TelemetryFacetsAPI.test.ts +810 -0
  142. package/Tests/Server/Infrastructure/E2EClickHouseFixtureAccess.test.ts +240 -0
  143. package/Tests/Server/Middleware/TelemetryIngestBrowserKey.test.ts +229 -0
  144. package/Tests/Server/Services/InventoryItemDisplayName.test.ts +66 -0
  145. package/Tests/Server/Services/OpenTelemetryResourceRetentionMemo.test.ts +28 -1
  146. package/Tests/Server/Services/SecurityEventConnectionService.test.ts +1233 -0
  147. package/Tests/Server/Services/TelemetryIngestionKeyValidation.test.ts +53 -0
  148. package/Tests/Server/Services/TelemetryResourceFacetCounting.test.ts +218 -0
  149. package/Tests/Server/Services/TelemetryResourceFacetFilters.test.ts +155 -1
  150. package/Tests/Server/Services/TraceAggregationExceptionScope.test.ts +142 -0
  151. package/Tests/Server/Services/TraceAnalyticsResourceDisplayNames.test.ts +85 -24
  152. package/Tests/Server/Types/Database/Permissions/SecurityRoleAccess.test.ts +33 -0
  153. package/Tests/Server/Utils/AI/InvestigationEvidence.test.ts +1395 -0
  154. package/Tests/Server/Utils/AI/InvestigationReferences.test.ts +616 -0
  155. package/Tests/Server/Utils/AI/TimelineTools.test.ts +119 -0
  156. package/Tests/Server/Utils/AI/Toolbox/AIToolbox.test.ts +151 -0
  157. package/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.ts +65 -0
  158. package/Tests/Server/Utils/AnalyticsDatabase/StatementGeneratorExceptionScope.test.ts +224 -0
  159. package/Tests/Server/Utils/LoggerCore.test.ts +597 -0
  160. package/Tests/Server/Utils/Monitor/MonitorCriteriaEvaluatorPerSeriesFanout.test.ts +55 -2
  161. package/Tests/Server/Utils/Monitor/MonitorTemplateUtil.test.ts +1109 -0
  162. package/Tests/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubClient.test.ts +1240 -0
  163. package/Tests/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubConnector.test.ts +1853 -0
  164. package/Tests/Server/Utils/SecurityEvent/Connectors/ConnectorPlatformHealth.test.ts +1129 -0
  165. package/Tests/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconClient.test.ts +1066 -0
  166. package/Tests/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconConnector.test.ts +1568 -0
  167. package/Tests/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityClient.test.ts +930 -0
  168. package/Tests/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityConnector.test.ts +1409 -0
  169. package/Tests/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrClient.test.ts +763 -0
  170. package/Tests/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrConnector.test.ts +1296 -0
  171. package/Tests/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelClient.test.ts +1102 -0
  172. package/Tests/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelConnector.test.ts +1174 -0
  173. package/Tests/Server/Utils/SecurityEvent/Connectors/Okta/OktaClient.test.ts +1032 -0
  174. package/Tests/Server/Utils/SecurityEvent/Connectors/Okta/OktaConnector.test.ts +1558 -0
  175. package/Tests/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionPoller.test.ts +3041 -0
  176. package/Tests/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionRunExecutor.test.ts +1168 -0
  177. package/Tests/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionTester.test.ts +906 -0
  178. package/Tests/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkClient.test.ts +1068 -0
  179. package/Tests/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkConnector.test.ts +1004 -0
  180. package/Tests/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsConnectionTester.test.ts +784 -0
  181. package/Tests/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsRunExecutor.test.ts +113 -1
  182. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsClient.test.ts +5 -1
  183. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsDiagnostics.test.ts +93 -13
  184. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsHttpIntegration.test.ts +23 -1
  185. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPoller.test.ts +25 -3
  186. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPollerFailureTaxonomy.test.ts +22 -8
  187. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPollerHardening.test.ts +82 -16
  188. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsSearchDetections.test.ts +730 -0
  189. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsThreePassPoller.test.ts +1577 -0
  190. package/Tests/Server/Utils/SessionReplay/SessionReplayOriginAllowlist.test.ts +41 -0
  191. package/Tests/Server/Utils/SessionReplay/SessionReplayReadServiceQueries.test.ts +1453 -18
  192. package/Tests/Server/Utils/Telemetry/EntityRegistry.test.ts +711 -0
  193. package/Tests/Server/Utils/Telemetry/KubernetesResourceAttributes.test.ts +162 -0
  194. package/Tests/Server/Utils/Telemetry/ResourceEntityFilter.test.ts +460 -13
  195. package/Tests/Server/Utils/Telemetry/ResourceFacetPlanner.test.ts +678 -0
  196. package/Tests/Server/Utils/Telemetry/ResourceFacetResolver.test.ts +868 -0
  197. package/Tests/Server/Utils/Telemetry/ServiceDependencyDiscovery.test.ts +525 -0
  198. package/Tests/Server/Utils/Telemetry/TraceContextPropagation.test.ts +420 -0
  199. package/Tests/Types/OnCallDutyPolicy/LayerUtilCorePaths.test.ts +1014 -0
  200. package/Tests/Types/OnCallDutyPolicy/LayerUtilExhaustiveRotation.test.ts +9 -6
  201. package/Tests/Types/Rules/RuleCriteriaFieldRegistry.test.ts +276 -0
  202. package/Tests/Types/Rum/SessionReplayApiContracts.test.ts +73 -0
  203. package/Tests/Types/Rum/SessionReplayTransportContracts.test.ts +95 -0
  204. package/Tests/Types/SecurityEvent/Connectors/ConnectorDiagnostics.test.ts +82 -0
  205. package/Tests/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.test.ts +314 -0
  206. package/Tests/Types/Telemetry/ExceptionSpanScope.test.ts +89 -0
  207. package/Tests/Types/Telemetry/LlmConventions.test.ts +495 -0
  208. package/Tests/Types/Telemetry/ResourceEntityFacet.test.ts +96 -0
  209. package/Tests/Types/Telemetry/ResourceFacetCatalog.test.ts +304 -0
  210. package/Tests/UI/Components/ActiveFilterChipsLockedFilters.test.tsx +357 -0
  211. package/Tests/UI/Components/Card.test.tsx +312 -1
  212. package/Tests/UI/Components/CardModelDetailHeaderLayout.test.tsx +253 -0
  213. package/Tests/UI/Components/CardModelDetailRefresher.test.tsx +342 -0
  214. package/Tests/UI/Components/Checkbox.test.tsx +79 -0
  215. package/Tests/UI/Components/CopyTextButton.test.tsx +142 -0
  216. package/Tests/UI/Components/DetailCompactStyle.test.tsx +621 -0
  217. package/Tests/UI/Components/ErrorBoundary.test.tsx +60 -0
  218. package/Tests/UI/Components/FacetSections.test.tsx +581 -0
  219. package/Tests/UI/Components/FacetSidebarControls.test.tsx +812 -0
  220. package/Tests/UI/Components/FacetVisibility.test.ts +429 -0
  221. package/Tests/UI/Components/LockedFilterActions.test.tsx +396 -0
  222. package/Tests/UI/Components/LockedFilterChip.test.tsx +651 -0
  223. package/Tests/UI/Components/LogsEntityNames.test.ts +1769 -0
  224. package/Tests/UI/Components/LogsEntityNamesComponents.test.tsx +696 -0
  225. package/Tests/UI/Components/LogsFacetSidebarHiddenFacets.test.tsx +600 -0
  226. package/Tests/UI/Components/LogsViewerEntityNames.test.tsx +713 -0
  227. package/Tests/UI/Components/MarkdownInlineReferences.test.tsx +2079 -0
  228. package/Tests/UI/Components/MemberRoleAssignment.test.tsx +446 -0
  229. package/Tests/UI/Components/ModelDetailRefetch.test.tsx +397 -0
  230. package/Tests/UI/Components/ModelListRefetch.test.tsx +233 -0
  231. package/Tests/UI/Components/ModelPageModelChange.test.tsx +409 -0
  232. package/Tests/UI/Components/PaginationIntegration.test.tsx +25 -0
  233. package/Tests/UI/Components/ResourceFacetConfigs.test.ts +172 -0
  234. package/Tests/UI/Components/SavedViewsSidebarIntegration.test.tsx +32 -14
  235. package/Tests/UI/Components/TableSortAndMobileColumns.test.tsx +44 -1
  236. package/Tests/UI/Components/TelemetryActiveFilterChipsLockedFilters.test.tsx +304 -0
  237. package/Tests/UI/Components/TelemetryFacetSidebarHiddenFacets.test.tsx +718 -0
  238. package/Tests/UI/Monitor/EvaluationLogList.test.tsx +303 -0
  239. package/Tests/UI/Monitor/MonitorSummarySnapshotRender.test.tsx +55 -1
  240. package/Tests/UI/Rum/FidelityNotices.test.ts +22 -0
  241. package/Tests/UI/Rum/RecordingHealthCard.test.tsx +120 -136
  242. package/Tests/UI/Rum/RecordingHealthDashboard.test.tsx +988 -0
  243. package/Tests/UI/Rum/ReplayCard.test.tsx +32 -0
  244. package/Tests/UI/Rum/ReplayCorrelationPanel.test.tsx +709 -12
  245. package/Tests/UI/Rum/ReplayHeader.test.tsx +50 -1
  246. package/Tests/UI/Rum/ReplayPinControl.test.tsx +67 -10
  247. package/Tests/UI/Rum/ReplayPlayerChrome.test.tsx +41 -12
  248. package/Tests/UI/Rum/ReplayStage.test.tsx +663 -1
  249. package/Tests/UI/Rum/ReplayStageOverlays.test.tsx +173 -0
  250. package/Tests/UI/Rum/ReplayUi.test.tsx +189 -2
  251. package/Tests/UI/Rum/ReplayUserSessionsMenu.test.tsx +91 -0
  252. package/Tests/UI/Rum/SessionReplayEmptyState.test.tsx +1 -1
  253. package/Tests/UI/Rum/SessionReplaySettingsPolicyLoading.test.tsx +585 -0
  254. package/Tests/UI/Rum/SessionReplayTable.test.tsx +844 -51
  255. package/Tests/UI/Rum/SessionReplayUsersTable.test.tsx +29 -1
  256. package/Tests/UI/Telemetry/TelemetryDetailPanel.test.tsx +288 -0
  257. package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +31 -1
  258. package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +6 -0
  259. package/Tests/UI/Utils/Clipboard.test.ts +154 -0
  260. package/Tests/UI/Utils/Navigation.test.ts +24 -0
  261. package/Tests/UI/Utils/Telemetry/TelemetryEntityNames.test.ts +2205 -0
  262. package/Tests/UI/Utils/Telemetry/UseTelemetryEntityNames.test.tsx +844 -0
  263. package/Tests/Utils/AI/InvestigationReport.test.ts +2430 -0
  264. package/Tests/Utils/APIOutgoingRequestTracer.test.ts +137 -0
  265. package/Tests/Utils/Rum/SessionReplayHealth.test.ts +884 -0
  266. package/Tests/Utils/Rum/SessionReplayHealthDiagnosis.test.ts +40 -0
  267. package/Tests/Utils/Rum/SessionReplayRecordingEnded.test.ts +619 -0
  268. package/Tests/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.test.ts +631 -0
  269. package/Tests/Utils/SecurityEvent/Connectors/CrowdStrikeFalconNormalizer.test.ts +479 -0
  270. package/Tests/Utils/SecurityEvent/Connectors/ElasticSecurityNormalizer.test.ts +507 -0
  271. package/Tests/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.test.ts +686 -0
  272. package/Tests/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.test.ts +474 -0
  273. package/Tests/Utils/SecurityEvent/Connectors/OktaNormalizer.test.ts +736 -0
  274. package/Tests/Utils/SecurityEvent/Connectors/SplunkNormalizer.test.ts +407 -0
  275. package/Tests/Utils/SecurityEvent/GoogleSecOpsAlertNormalizer.test.ts +129 -0
  276. package/Tests/Utils/Telemetry/CrossSignalScope.test.ts +57 -1
  277. package/Tests/Utils/Telemetry/EntityRelationship.test.ts +36 -0
  278. package/Tests/Utils/Telemetry/LockedFilterSearch.test.ts +600 -0
  279. package/Tests/Utils/Telemetry/NetworkHost.test.ts +48 -0
  280. package/Tests/Utils/Telemetry/OriginAllowList.test.ts +154 -0
  281. package/Tests/Utils/Traces/CriticalPath.test.ts +25 -0
  282. package/Types/AI/AIChatTypes.ts +8 -0
  283. package/Types/AI/InvestigationEvidence.ts +96 -0
  284. package/Types/Monitor/MonitorEvaluationSummary.ts +5 -0
  285. package/Types/OnCallDutyPolicy/Layer.ts +12 -0
  286. package/Types/Permission.ts +2 -2
  287. package/Types/Rules/RuleCriteriaFieldRegistry.ts +12 -0
  288. package/Types/Rum/SessionReplay.ts +109 -0
  289. package/Types/Rum/SessionReplayApi.ts +31 -0
  290. package/Types/SecurityEvent/Connectors/ConnectorDiagnostics.ts +111 -0
  291. package/Types/SecurityEvent/Connectors/SecurityEventConnectionDiagnostics.ts +87 -0
  292. package/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.ts +492 -0
  293. package/Types/SecurityEvent/Connectors/SecurityEventConnectorProvider.ts +41 -0
  294. package/Types/SecurityEvent/GoogleSecOpsDiagnostics.ts +56 -1
  295. package/Types/SecurityEvent/GoogleSecOpsRegion.ts +34 -0
  296. package/Types/Telemetry/EntityType.ts +14 -0
  297. package/Types/Telemetry/ExceptionSpanScope.ts +83 -0
  298. package/Types/Telemetry/LockedFilterDetail.ts +46 -0
  299. package/Types/Telemetry/ResourceEntityFacet.ts +17 -10
  300. package/Types/Telemetry/ResourceFacetCatalog.ts +171 -0
  301. package/UI/Components/Card/Card.tsx +118 -83
  302. package/UI/Components/Checkbox/Checkbox.tsx +8 -5
  303. package/UI/Components/CopyTextButton/CopyTextButton.tsx +7 -1
  304. package/UI/Components/CustomFields/CustomFieldsDetail.tsx +4 -1
  305. package/UI/Components/Detail/Detail.tsx +137 -22
  306. package/UI/Components/ErrorBoundary.tsx +38 -0
  307. package/UI/Components/LogsViewer/LogsEntityNames.ts +912 -0
  308. package/UI/Components/LogsViewer/LogsViewer.tsx +156 -77
  309. package/UI/Components/LogsViewer/components/ActiveFilterChips.tsx +28 -11
  310. package/UI/Components/LogsViewer/components/FacetSection.tsx +66 -79
  311. package/UI/Components/LogsViewer/components/FacetValueRow.tsx +17 -2
  312. package/UI/Components/LogsViewer/components/LogDetailsPanel.tsx +45 -5
  313. package/UI/Components/LogsViewer/components/LogsAnalyticsView.tsx +100 -19
  314. package/UI/Components/LogsViewer/components/LogsFacetSidebar.tsx +156 -39
  315. package/UI/Components/LogsViewer/components/LogsTable.tsx +30 -8
  316. package/UI/Components/LogsViewer/types.ts +6 -0
  317. package/UI/Components/Markdown.tsx/InlineReferences.tsx +628 -0
  318. package/UI/Components/Markdown.tsx/MarkdownViewer.tsx +385 -312
  319. package/UI/Components/MemberRoleAssignment/MemberRoleAssignment.tsx +50 -22
  320. package/UI/Components/ModelDetail/CardModelDetail.tsx +15 -0
  321. package/UI/Components/ModelDetail/ModelDetail.tsx +64 -19
  322. package/UI/Components/ModelList/ModelList.tsx +33 -8
  323. package/UI/Components/Page/ModelPage.tsx +119 -54
  324. package/UI/Components/Table/Table.tsx +8 -0
  325. package/UI/Components/Table/TableRow.tsx +13 -5
  326. package/UI/Components/TelemetryViewer/FacetVisibility.ts +229 -0
  327. package/UI/Components/TelemetryViewer/ResourceFacetConfigs.ts +46 -0
  328. package/UI/Components/TelemetryViewer/TelemetryViewer.tsx +11 -0
  329. package/UI/Components/TelemetryViewer/components/FacetSearchInput.tsx +79 -0
  330. package/UI/Components/TelemetryViewer/components/FacetSectionHeader.tsx +69 -0
  331. package/UI/Components/TelemetryViewer/components/FacetShowMoreButton.tsx +36 -0
  332. package/UI/Components/TelemetryViewer/components/HiddenFacetsFooter.tsx +88 -0
  333. package/UI/Components/TelemetryViewer/components/LockedFilterActions.tsx +205 -0
  334. package/UI/Components/TelemetryViewer/components/LockedFilterChip.tsx +496 -0
  335. package/UI/Components/TelemetryViewer/components/TelemetryActiveFilterChips.tsx +30 -10
  336. package/UI/Components/TelemetryViewer/components/TelemetryDetailPanel.tsx +203 -10
  337. package/UI/Components/TelemetryViewer/components/TelemetryFacetSection.tsx +60 -73
  338. package/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.tsx +94 -7
  339. package/UI/Components/TelemetryViewer/components/TelemetryFacetValueRow.tsx +17 -2
  340. package/UI/Components/TelemetryViewer/types.ts +19 -0
  341. package/UI/Components/TelemetryViewer/useFacetSearchExemptions.ts +158 -0
  342. package/UI/Components/TelemetryViewer/useFacetSectionSearch.ts +102 -0
  343. package/UI/Utils/Clipboard.ts +68 -2
  344. package/UI/Utils/Navigation.ts +17 -2
  345. package/UI/Utils/Telemetry/TelemetryEntityNames.ts +620 -0
  346. package/UI/Utils/Telemetry/UseTelemetryEntityNames.ts +151 -0
  347. package/Utils/AI/InvestigationReport.ts +1789 -0
  348. package/Utils/API.ts +90 -1
  349. package/Utils/Rum/SessionReplayHealth.ts +11 -0
  350. package/Utils/Rum/SessionReplayRecordingEnded.ts +134 -0
  351. package/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.ts +427 -0
  352. package/Utils/SecurityEvent/Connectors/CrowdStrikeFalconNormalizer.ts +197 -0
  353. package/Utils/SecurityEvent/Connectors/ElasticSecurityNormalizer.ts +464 -0
  354. package/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.ts +567 -0
  355. package/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.ts +299 -0
  356. package/Utils/SecurityEvent/Connectors/OktaNormalizer.ts +467 -0
  357. package/Utils/SecurityEvent/Connectors/SplunkNormalizer.ts +439 -0
  358. package/Utils/SecurityEvent/GoogleSecOpsAlertNormalizer.ts +124 -12
  359. package/Utils/Telemetry/CrossSignalScope.ts +22 -8
  360. package/Utils/Telemetry/EntityRelationship.ts +8 -0
  361. package/Utils/Telemetry/LockedFilterSearch.ts +412 -0
  362. package/Utils/Telemetry/NetworkHost.ts +43 -0
  363. package/Utils/Telemetry/OriginAllowList.ts +139 -4
  364. package/Utils/Traces/CriticalPath.ts +10 -4
  365. package/build/dist/Models/DatabaseModels/Index.js +4 -0
  366. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  367. package/build/dist/Models/DatabaseModels/RumApplication.js +1 -1
  368. package/build/dist/Models/DatabaseModels/RumApplication.js.map +1 -1
  369. package/build/dist/Models/DatabaseModels/SecurityEventConnection.js +490 -0
  370. package/build/dist/Models/DatabaseModels/SecurityEventConnection.js.map +1 -0
  371. package/build/dist/Models/DatabaseModels/SecurityEventConnectionRun.js +287 -0
  372. package/build/dist/Models/DatabaseModels/SecurityEventConnectionRun.js.map +1 -0
  373. package/build/dist/Models/DatabaseModels/TelemetryIngestionKey.js +2 -2
  374. package/build/dist/Models/DatabaseModels/TelemetryIngestionKey.js.map +1 -1
  375. package/build/dist/Server/API/AIInvestigationAPI.js +336 -27
  376. package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
  377. package/build/dist/Server/API/GoogleSecOpsConnectionAPI.js +182 -7
  378. package/build/dist/Server/API/GoogleSecOpsConnectionAPI.js.map +1 -1
  379. package/build/dist/Server/API/SecurityEventConnectionAPI.js +171 -0
  380. package/build/dist/Server/API/SecurityEventConnectionAPI.js.map +1 -0
  381. package/build/dist/Server/API/TelemetryAPI.js +248 -170
  382. package/build/dist/Server/API/TelemetryAPI.js.map +1 -1
  383. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1792700000000-AddSecurityEventConnections.js +40 -0
  384. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1792700000000-AddSecurityEventConnections.js.map +1 -0
  385. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
  386. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  387. package/build/dist/Server/Middleware/TelemetryIngest.js +57 -4
  388. package/build/dist/Server/Middleware/TelemetryIngest.js.map +1 -1
  389. package/build/dist/Server/Services/ExceptionAggregationService.js +7 -16
  390. package/build/dist/Server/Services/ExceptionAggregationService.js.map +1 -1
  391. package/build/dist/Server/Services/GoogleSecOpsConnectionService.js +8 -0
  392. package/build/dist/Server/Services/GoogleSecOpsConnectionService.js.map +1 -1
  393. package/build/dist/Server/Services/Index.js +4 -0
  394. package/build/dist/Server/Services/Index.js.map +1 -1
  395. package/build/dist/Server/Services/InventoryItemService.js +22 -0
  396. package/build/dist/Server/Services/InventoryItemService.js.map +1 -1
  397. package/build/dist/Server/Services/LogAggregationService.js +8 -17
  398. package/build/dist/Server/Services/LogAggregationService.js.map +1 -1
  399. package/build/dist/Server/Services/MetricAggregationService.js +4 -14
  400. package/build/dist/Server/Services/MetricAggregationService.js.map +1 -1
  401. package/build/dist/Server/Services/SecurityEventConnectionRunService.js +9 -0
  402. package/build/dist/Server/Services/SecurityEventConnectionRunService.js.map +1 -0
  403. package/build/dist/Server/Services/SecurityEventConnectionService.js +356 -0
  404. package/build/dist/Server/Services/SecurityEventConnectionService.js.map +1 -0
  405. package/build/dist/Server/Services/TraceAggregationService.js +51 -25
  406. package/build/dist/Server/Services/TraceAggregationService.js.map +1 -1
  407. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js +9 -0
  408. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js.map +1 -1
  409. package/build/dist/Server/Utils/AI/Chat/ObservabilityAssistant.js +3 -0
  410. package/build/dist/Server/Utils/AI/Chat/ObservabilityAssistant.js.map +1 -1
  411. package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js +14 -7
  412. package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js.map +1 -1
  413. package/build/dist/Server/Utils/AI/SRE/InvestigationEvidence.js +468 -0
  414. package/build/dist/Server/Utils/AI/SRE/InvestigationEvidence.js.map +1 -0
  415. package/build/dist/Server/Utils/AI/SRE/InvestigationReferences.js +230 -0
  416. package/build/dist/Server/Utils/AI/SRE/InvestigationReferences.js.map +1 -0
  417. package/build/dist/Server/Utils/AI/Toolbox/Index.js +32 -0
  418. package/build/dist/Server/Utils/AI/Toolbox/Index.js.map +1 -1
  419. package/build/dist/Server/Utils/AI/Toolbox/TimelineTools.js +6 -2
  420. package/build/dist/Server/Utils/AI/Toolbox/TimelineTools.js.map +1 -1
  421. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +59 -0
  422. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
  423. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +5 -3
  424. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -1
  425. package/build/dist/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubClient.js +752 -0
  426. package/build/dist/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubClient.js.map +1 -0
  427. package/build/dist/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubConnector.js +493 -0
  428. package/build/dist/Server/Utils/SecurityEvent/Connectors/AwsSecurityHub/AwsSecurityHubConnector.js.map +1 -0
  429. package/build/dist/Server/Utils/SecurityEvent/Connectors/ConnectorPlatformHealth.js +352 -0
  430. package/build/dist/Server/Utils/SecurityEvent/Connectors/ConnectorPlatformHealth.js.map +1 -0
  431. package/build/dist/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconClient.js +405 -0
  432. package/build/dist/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconClient.js.map +1 -0
  433. package/build/dist/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconConnector.js +466 -0
  434. package/build/dist/Server/Utils/SecurityEvent/Connectors/CrowdStrikeFalcon/CrowdStrikeFalconConnector.js.map +1 -0
  435. package/build/dist/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityClient.js +344 -0
  436. package/build/dist/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityClient.js.map +1 -0
  437. package/build/dist/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityConnector.js +511 -0
  438. package/build/dist/Server/Utils/SecurityEvent/Connectors/ElasticSecurity/ElasticSecurityConnector.js.map +1 -0
  439. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrClient.js +406 -0
  440. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrClient.js.map +1 -0
  441. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrConnector.js +336 -0
  442. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdr/MicrosoftDefenderXdrConnector.js.map +1 -0
  443. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelClient.js +474 -0
  444. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelClient.js.map +1 -0
  445. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelConnector.js +417 -0
  446. package/build/dist/Server/Utils/SecurityEvent/Connectors/MicrosoftSentinel/MicrosoftSentinelConnector.js.map +1 -0
  447. package/build/dist/Server/Utils/SecurityEvent/Connectors/Okta/OktaClient.js +314 -0
  448. package/build/dist/Server/Utils/SecurityEvent/Connectors/Okta/OktaClient.js.map +1 -0
  449. package/build/dist/Server/Utils/SecurityEvent/Connectors/Okta/OktaConnector.js +494 -0
  450. package/build/dist/Server/Utils/SecurityEvent/Connectors/Okta/OktaConnector.js.map +1 -0
  451. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionPoller.js +719 -0
  452. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionPoller.js.map +1 -0
  453. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionRunExecutor.js +404 -0
  454. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionRunExecutor.js.map +1 -0
  455. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionTester.js +209 -0
  456. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectionTester.js.map +1 -0
  457. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectorRegistry.js +40 -0
  458. package/build/dist/Server/Utils/SecurityEvent/Connectors/SecurityEventConnectorRegistry.js.map +1 -0
  459. package/build/dist/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkClient.js +494 -0
  460. package/build/dist/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkClient.js.map +1 -0
  461. package/build/dist/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkConnector.js +379 -0
  462. package/build/dist/Server/Utils/SecurityEvent/Connectors/Splunk/SplunkConnector.js.map +1 -0
  463. package/build/dist/Server/Utils/SecurityEvent/Connectors/Types.js +27 -0
  464. package/build/dist/Server/Utils/SecurityEvent/Connectors/Types.js.map +1 -0
  465. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.js +234 -61
  466. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.js.map +1 -1
  467. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsConnectionTester.js +537 -0
  468. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsConnectionTester.js.map +1 -0
  469. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.js +572 -115
  470. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.js.map +1 -1
  471. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsRunExecutor.js +35 -1
  472. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsRunExecutor.js.map +1 -1
  473. package/build/dist/Server/Utils/SecurityEvent/SecurityEventDedupe.js +52 -0
  474. package/build/dist/Server/Utils/SecurityEvent/SecurityEventDedupe.js.map +1 -0
  475. package/build/dist/Server/Utils/SessionReplay/SessionReplayReadService.js +521 -32
  476. package/build/dist/Server/Utils/SessionReplay/SessionReplayReadService.js.map +1 -1
  477. package/build/dist/Server/Utils/StartServer.js +10 -0
  478. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  479. package/build/dist/Server/Utils/Telemetry/EntityRegistry.js +8 -0
  480. package/build/dist/Server/Utils/Telemetry/EntityRegistry.js.map +1 -1
  481. package/build/dist/Server/Utils/Telemetry/KubernetesResourceAttributes.js +80 -0
  482. package/build/dist/Server/Utils/Telemetry/KubernetesResourceAttributes.js.map +1 -0
  483. package/build/dist/Server/Utils/Telemetry/ResourceEntityFilter.js +122 -67
  484. package/build/dist/Server/Utils/Telemetry/ResourceEntityFilter.js.map +1 -1
  485. package/build/dist/Server/Utils/Telemetry/ResourceFacetPlanner.js +146 -0
  486. package/build/dist/Server/Utils/Telemetry/ResourceFacetPlanner.js.map +1 -0
  487. package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js +174 -248
  488. package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js.map +1 -1
  489. package/build/dist/Server/Utils/Telemetry/ServiceDependencyDiscovery.js +492 -0
  490. package/build/dist/Server/Utils/Telemetry/ServiceDependencyDiscovery.js.map +1 -0
  491. package/build/dist/Server/Utils/Telemetry/TraceContextPropagation.js +259 -0
  492. package/build/dist/Server/Utils/Telemetry/TraceContextPropagation.js.map +1 -0
  493. package/build/dist/Server/Utils/Telemetry.js +11 -5
  494. package/build/dist/Server/Utils/Telemetry.js.map +1 -1
  495. package/build/dist/Types/AI/InvestigationEvidence.js +2 -0
  496. package/build/dist/Types/AI/InvestigationEvidence.js.map +1 -0
  497. package/build/dist/Types/OnCallDutyPolicy/Layer.js +11 -0
  498. package/build/dist/Types/OnCallDutyPolicy/Layer.js.map +1 -1
  499. package/build/dist/Types/Permission.js +2 -2
  500. package/build/dist/Types/Permission.js.map +1 -1
  501. package/build/dist/Types/Rules/RuleCriteriaFieldRegistry.js +9 -0
  502. package/build/dist/Types/Rules/RuleCriteriaFieldRegistry.js.map +1 -1
  503. package/build/dist/Types/Rum/SessionReplay.js +95 -0
  504. package/build/dist/Types/Rum/SessionReplay.js.map +1 -1
  505. package/build/dist/Types/Rum/SessionReplayApi.js.map +1 -1
  506. package/build/dist/Types/SecurityEvent/Connectors/ConnectorDiagnostics.js +18 -0
  507. package/build/dist/Types/SecurityEvent/Connectors/ConnectorDiagnostics.js.map +1 -0
  508. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectionDiagnostics.js +2 -0
  509. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectionDiagnostics.js.map +1 -0
  510. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.js +374 -0
  511. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.js.map +1 -0
  512. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectorProvider.js +35 -0
  513. package/build/dist/Types/SecurityEvent/Connectors/SecurityEventConnectorProvider.js.map +1 -0
  514. package/build/dist/Types/SecurityEvent/GoogleSecOpsRegion.js +35 -0
  515. package/build/dist/Types/SecurityEvent/GoogleSecOpsRegion.js.map +1 -0
  516. package/build/dist/Types/Telemetry/EntityType.js +14 -0
  517. package/build/dist/Types/Telemetry/EntityType.js.map +1 -1
  518. package/build/dist/Types/Telemetry/ExceptionSpanScope.js +59 -0
  519. package/build/dist/Types/Telemetry/ExceptionSpanScope.js.map +1 -0
  520. package/build/dist/Types/Telemetry/LockedFilterDetail.js +16 -0
  521. package/build/dist/Types/Telemetry/LockedFilterDetail.js.map +1 -0
  522. package/build/dist/Types/Telemetry/ResourceEntityFacet.js +16 -10
  523. package/build/dist/Types/Telemetry/ResourceEntityFacet.js.map +1 -1
  524. package/build/dist/Types/Telemetry/ResourceFacetCatalog.js +119 -0
  525. package/build/dist/Types/Telemetry/ResourceFacetCatalog.js.map +1 -0
  526. package/build/dist/UI/Components/Card/Card.js +34 -17
  527. package/build/dist/UI/Components/Card/Card.js.map +1 -1
  528. package/build/dist/UI/Components/Checkbox/Checkbox.js +6 -4
  529. package/build/dist/UI/Components/Checkbox/Checkbox.js.map +1 -1
  530. package/build/dist/UI/Components/CopyTextButton/CopyTextButton.js +5 -1
  531. package/build/dist/UI/Components/CopyTextButton/CopyTextButton.js.map +1 -1
  532. package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js +1 -1
  533. package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js.map +1 -1
  534. package/build/dist/UI/Components/Detail/Detail.js +63 -13
  535. package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
  536. package/build/dist/UI/Components/ErrorBoundary.js +34 -0
  537. package/build/dist/UI/Components/ErrorBoundary.js.map +1 -1
  538. package/build/dist/UI/Components/LogsViewer/LogsEntityNames.js +535 -0
  539. package/build/dist/UI/Components/LogsViewer/LogsEntityNames.js.map +1 -0
  540. package/build/dist/UI/Components/LogsViewer/LogsViewer.js +117 -57
  541. package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
  542. package/build/dist/UI/Components/LogsViewer/components/ActiveFilterChips.js +5 -7
  543. package/build/dist/UI/Components/LogsViewer/components/ActiveFilterChips.js.map +1 -1
  544. package/build/dist/UI/Components/LogsViewer/components/FacetSection.js +31 -44
  545. package/build/dist/UI/Components/LogsViewer/components/FacetSection.js.map +1 -1
  546. package/build/dist/UI/Components/LogsViewer/components/FacetValueRow.js +17 -3
  547. package/build/dist/UI/Components/LogsViewer/components/FacetValueRow.js.map +1 -1
  548. package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js +19 -3
  549. package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js.map +1 -1
  550. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js +64 -18
  551. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js.map +1 -1
  552. package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js +100 -41
  553. package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js.map +1 -1
  554. package/build/dist/UI/Components/LogsViewer/components/LogsTable.js +13 -5
  555. package/build/dist/UI/Components/LogsViewer/components/LogsTable.js.map +1 -1
  556. package/build/dist/UI/Components/LogsViewer/types.js.map +1 -1
  557. package/build/dist/UI/Components/Markdown.tsx/InlineReferences.js +403 -0
  558. package/build/dist/UI/Components/Markdown.tsx/InlineReferences.js.map +1 -0
  559. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js +197 -179
  560. package/build/dist/UI/Components/Markdown.tsx/MarkdownViewer.js.map +1 -1
  561. package/build/dist/UI/Components/MemberRoleAssignment/MemberRoleAssignment.js +30 -21
  562. package/build/dist/UI/Components/MemberRoleAssignment/MemberRoleAssignment.js.map +1 -1
  563. package/build/dist/UI/Components/ModelDetail/CardModelDetail.js +12 -0
  564. package/build/dist/UI/Components/ModelDetail/CardModelDetail.js.map +1 -1
  565. package/build/dist/UI/Components/ModelDetail/ModelDetail.js +46 -12
  566. package/build/dist/UI/Components/ModelDetail/ModelDetail.js.map +1 -1
  567. package/build/dist/UI/Components/ModelList/ModelList.js +26 -7
  568. package/build/dist/UI/Components/ModelList/ModelList.js.map +1 -1
  569. package/build/dist/UI/Components/Page/ModelPage.js +62 -34
  570. package/build/dist/UI/Components/Page/ModelPage.js.map +1 -1
  571. package/build/dist/UI/Components/Table/Table.js +3 -1
  572. package/build/dist/UI/Components/Table/Table.js.map +1 -1
  573. package/build/dist/UI/Components/Table/TableRow.js +8 -1
  574. package/build/dist/UI/Components/Table/TableRow.js.map +1 -1
  575. package/build/dist/UI/Components/TelemetryViewer/FacetVisibility.js +111 -0
  576. package/build/dist/UI/Components/TelemetryViewer/FacetVisibility.js.map +1 -0
  577. package/build/dist/UI/Components/TelemetryViewer/ResourceFacetConfigs.js +22 -0
  578. package/build/dist/UI/Components/TelemetryViewer/ResourceFacetConfigs.js.map +1 -0
  579. package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js +1 -1
  580. package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js.map +1 -1
  581. package/build/dist/UI/Components/TelemetryViewer/components/FacetSearchInput.js +36 -0
  582. package/build/dist/UI/Components/TelemetryViewer/components/FacetSearchInput.js.map +1 -0
  583. package/build/dist/UI/Components/TelemetryViewer/components/FacetSectionHeader.js +21 -0
  584. package/build/dist/UI/Components/TelemetryViewer/components/FacetSectionHeader.js.map +1 -0
  585. package/build/dist/UI/Components/TelemetryViewer/components/FacetShowMoreButton.js +14 -0
  586. package/build/dist/UI/Components/TelemetryViewer/components/FacetShowMoreButton.js.map +1 -0
  587. package/build/dist/UI/Components/TelemetryViewer/components/HiddenFacetsFooter.js +27 -0
  588. package/build/dist/UI/Components/TelemetryViewer/components/HiddenFacetsFooter.js.map +1 -0
  589. package/build/dist/UI/Components/TelemetryViewer/components/LockedFilterActions.js +88 -0
  590. package/build/dist/UI/Components/TelemetryViewer/components/LockedFilterActions.js.map +1 -0
  591. package/build/dist/UI/Components/TelemetryViewer/components/LockedFilterChip.js +228 -0
  592. package/build/dist/UI/Components/TelemetryViewer/components/LockedFilterChip.js.map +1 -0
  593. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryActiveFilterChips.js +6 -6
  594. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryActiveFilterChips.js.map +1 -1
  595. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryDetailPanel.js +111 -12
  596. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryDetailPanel.js.map +1 -1
  597. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSection.js +27 -40
  598. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSection.js.map +1 -1
  599. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js +70 -10
  600. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js.map +1 -1
  601. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetValueRow.js +17 -3
  602. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetValueRow.js.map +1 -1
  603. package/build/dist/UI/Components/TelemetryViewer/types.js +0 -4
  604. package/build/dist/UI/Components/TelemetryViewer/types.js.map +1 -1
  605. package/build/dist/UI/Components/TelemetryViewer/useFacetSearchExemptions.js +70 -0
  606. package/build/dist/UI/Components/TelemetryViewer/useFacetSearchExemptions.js.map +1 -0
  607. package/build/dist/UI/Components/TelemetryViewer/useFacetSectionSearch.js +52 -0
  608. package/build/dist/UI/Components/TelemetryViewer/useFacetSectionSearch.js.map +1 -0
  609. package/build/dist/UI/Utils/Clipboard.js +59 -2
  610. package/build/dist/UI/Utils/Clipboard.js.map +1 -1
  611. package/build/dist/UI/Utils/Navigation.js +11 -2
  612. package/build/dist/UI/Utils/Navigation.js.map +1 -1
  613. package/build/dist/UI/Utils/Telemetry/TelemetryEntityNames.js +471 -0
  614. package/build/dist/UI/Utils/Telemetry/TelemetryEntityNames.js.map +1 -0
  615. package/build/dist/UI/Utils/Telemetry/UseTelemetryEntityNames.js +113 -0
  616. package/build/dist/UI/Utils/Telemetry/UseTelemetryEntityNames.js.map +1 -0
  617. package/build/dist/Utils/AI/InvestigationReport.js +1241 -0
  618. package/build/dist/Utils/AI/InvestigationReport.js.map +1 -0
  619. package/build/dist/Utils/API.js +25 -0
  620. package/build/dist/Utils/API.js.map +1 -1
  621. package/build/dist/Utils/Rum/SessionReplayHealth.js +10 -0
  622. package/build/dist/Utils/Rum/SessionReplayHealth.js.map +1 -1
  623. package/build/dist/Utils/Rum/SessionReplayRecordingEnded.js +54 -0
  624. package/build/dist/Utils/Rum/SessionReplayRecordingEnded.js.map +1 -0
  625. package/build/dist/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.js +311 -0
  626. package/build/dist/Utils/SecurityEvent/Connectors/AwsSecurityHubNormalizer.js.map +1 -0
  627. package/build/dist/Utils/SecurityEvent/Connectors/CrowdStrikeFalconNormalizer.js +150 -0
  628. package/build/dist/Utils/SecurityEvent/Connectors/CrowdStrikeFalconNormalizer.js.map +1 -0
  629. package/build/dist/Utils/SecurityEvent/Connectors/ElasticSecurityNormalizer.js +328 -0
  630. package/build/dist/Utils/SecurityEvent/Connectors/ElasticSecurityNormalizer.js.map +1 -0
  631. package/build/dist/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.js +405 -0
  632. package/build/dist/Utils/SecurityEvent/Connectors/MicrosoftDefenderXdrNormalizer.js.map +1 -0
  633. package/build/dist/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.js +212 -0
  634. package/build/dist/Utils/SecurityEvent/Connectors/MicrosoftSentinelNormalizer.js.map +1 -0
  635. package/build/dist/Utils/SecurityEvent/Connectors/OktaNormalizer.js +351 -0
  636. package/build/dist/Utils/SecurityEvent/Connectors/OktaNormalizer.js.map +1 -0
  637. package/build/dist/Utils/SecurityEvent/Connectors/SplunkNormalizer.js +348 -0
  638. package/build/dist/Utils/SecurityEvent/Connectors/SplunkNormalizer.js.map +1 -0
  639. package/build/dist/Utils/SecurityEvent/GoogleSecOpsAlertNormalizer.js +103 -10
  640. package/build/dist/Utils/SecurityEvent/GoogleSecOpsAlertNormalizer.js.map +1 -1
  641. package/build/dist/Utils/Telemetry/CrossSignalScope.js +16 -5
  642. package/build/dist/Utils/Telemetry/CrossSignalScope.js.map +1 -1
  643. package/build/dist/Utils/Telemetry/EntityRelationship.js +7 -0
  644. package/build/dist/Utils/Telemetry/EntityRelationship.js.map +1 -1
  645. package/build/dist/Utils/Telemetry/LockedFilterSearch.js +277 -0
  646. package/build/dist/Utils/Telemetry/LockedFilterSearch.js.map +1 -0
  647. package/build/dist/Utils/Telemetry/NetworkHost.js +39 -0
  648. package/build/dist/Utils/Telemetry/NetworkHost.js.map +1 -0
  649. package/build/dist/Utils/Telemetry/OriginAllowList.js +105 -4
  650. package/build/dist/Utils/Telemetry/OriginAllowList.js.map +1 -1
  651. package/build/dist/Utils/Traces/CriticalPath.js +9 -4
  652. package/build/dist/Utils/Traces/CriticalPath.js.map +1 -1
  653. package/package.json +1 -1
  654. package/Tests/UI/Rum/RecordingHealthStrip.test.tsx +0 -600
  655. package/UI/Components/GanttChart/Bar/BarLabel.tsx +0 -17
  656. package/UI/Components/GanttChart/Bar/Index.tsx +0 -149
  657. package/UI/Components/GanttChart/ChartContainer.tsx +0 -50
  658. package/UI/Components/GanttChart/Index.tsx +0 -90
  659. package/UI/Components/GanttChart/Row/Index.tsx +0 -22
  660. package/UI/Components/GanttChart/Row/Row.tsx +0 -231
  661. package/UI/Components/GanttChart/Row/RowLabel.tsx +0 -30
  662. package/UI/Components/GanttChart/Rows.tsx +0 -59
  663. package/UI/Components/GanttChart/Timeline/Index.tsx +0 -46
  664. package/UI/Components/GanttChart/Timeline/TimelineInterval.tsx +0 -33
  665. package/UI/Components/GanttChart/Timeline/TimelineIntervalMarks.tsx +0 -43
  666. package/build/dist/UI/Components/GanttChart/Bar/BarLabel.js +0 -8
  667. package/build/dist/UI/Components/GanttChart/Bar/BarLabel.js.map +0 -1
  668. package/build/dist/UI/Components/GanttChart/Bar/Index.js +0 -77
  669. package/build/dist/UI/Components/GanttChart/Bar/Index.js.map +0 -1
  670. package/build/dist/UI/Components/GanttChart/ChartContainer.js +0 -33
  671. package/build/dist/UI/Components/GanttChart/ChartContainer.js.map +0 -1
  672. package/build/dist/UI/Components/GanttChart/Index.js +0 -39
  673. package/build/dist/UI/Components/GanttChart/Index.js.map +0 -1
  674. package/build/dist/UI/Components/GanttChart/Row/Index.js +0 -7
  675. package/build/dist/UI/Components/GanttChart/Row/Index.js.map +0 -1
  676. package/build/dist/UI/Components/GanttChart/Row/Row.js +0 -106
  677. package/build/dist/UI/Components/GanttChart/Row/Row.js.map +0 -1
  678. package/build/dist/UI/Components/GanttChart/Row/RowLabel.js +0 -10
  679. package/build/dist/UI/Components/GanttChart/Row/RowLabel.js.map +0 -1
  680. package/build/dist/UI/Components/GanttChart/Rows.js +0 -19
  681. package/build/dist/UI/Components/GanttChart/Rows.js.map +0 -1
  682. package/build/dist/UI/Components/GanttChart/Timeline/Index.js +0 -16
  683. package/build/dist/UI/Components/GanttChart/Timeline/Index.js.map +0 -1
  684. package/build/dist/UI/Components/GanttChart/Timeline/TimelineInterval.js +0 -13
  685. package/build/dist/UI/Components/GanttChart/Timeline/TimelineInterval.js.map +0 -1
  686. package/build/dist/UI/Components/GanttChart/Timeline/TimelineIntervalMarks.js +0 -13
  687. package/build/dist/UI/Components/GanttChart/Timeline/TimelineIntervalMarks.js.map +0 -1
@@ -0,0 +1,2079 @@
1
+ /*
2
+ * Inline references in MarkdownViewer: the remark transform that turns
3
+ * "[C12]" citation markers and "#6954" incident / alert numbers into custom
4
+ * mdast nodes, the context-driven elements those nodes render as, and the
5
+ * viewer wiring that only opts in when a caller passes `inlineReferences`.
6
+ *
7
+ * react-markdown and the remark packages are ESM and do not run under
8
+ * Common's jest, so:
9
+ *
10
+ * - the transform is exercised directly on hand-built mdast trees;
11
+ * - react-markdown is replaced (below) by a tiny stand-in that records the
12
+ * props MarkdownViewer passes, runs the recorded remark plugins over a
13
+ * test-provided mdast tree, and renders that tree through the recorded
14
+ * `components` map. That is enough to observe the real plugin, the real
15
+ * element components and the real context provider working together
16
+ * through MarkdownViewer, without the real parser.
17
+ */
18
+ import {
19
+ afterEach,
20
+ beforeEach,
21
+ describe,
22
+ expect,
23
+ jest,
24
+ test,
25
+ } from "@jest/globals";
26
+
27
+ jest.mock("react-markdown", () => {
28
+ return {
29
+ __esModule: true,
30
+ default: (props: MockReactMarkdownProps): React.ReactElement => {
31
+ return renderMockMarkdown(props);
32
+ },
33
+ defaultUrlTransform: (url: string): string => {
34
+ return url;
35
+ },
36
+ };
37
+ });
38
+
39
+ import "@testing-library/jest-dom";
40
+ import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
41
+ import React, { ReactElement, useEffect, useState } from "react";
42
+ import remarkGfm from "remark-gfm";
43
+ import getJestMockFunction, { MockFunction } from "../../MockType";
44
+ import {
45
+ CITATION_REFERENCE_NODE_TYPE,
46
+ CITATION_REFERENCE_TAG_NAME,
47
+ EVENT_REFERENCE_NODE_TYPE,
48
+ EVENT_REFERENCE_TAG_NAME,
49
+ InlineReferenceMarkdownNode,
50
+ MARKDOWN_INLINE_REFERENCE_COMPONENTS,
51
+ MarkdownCitationReferenceElement,
52
+ MarkdownEventReference,
53
+ MarkdownEventReferenceElement,
54
+ MarkdownInlineReferenceContext,
55
+ MarkdownInlineReferenceRenderers,
56
+ applyInlineReferences,
57
+ remarkInlineReferences,
58
+ } from "../../../UI/Components/Markdown.tsx/InlineReferences";
59
+ import MarkdownViewer from "../../../UI/Components/Markdown.tsx/MarkdownViewer";
60
+ import LazyMarkdownViewer from "../../../UI/Components/Markdown.tsx/LazyMarkdownViewer";
61
+
62
+ /*
63
+ * ---------------------------------------------------------------------------
64
+ * react-markdown stand-in
65
+ * ---------------------------------------------------------------------------
66
+ */
67
+
68
+ type MockComponentMap = Record<string, React.ElementType>;
69
+
70
+ interface MockReactMarkdownProps {
71
+ children?: string;
72
+ components?: MockComponentMap;
73
+ remarkPlugins?: Array<unknown>;
74
+ }
75
+
76
+ interface MockMarkdownState {
77
+ // When set, rendered instead of `children` (after running the plugins).
78
+ tree: InlineReferenceMarkdownNode | null;
79
+ calls: Array<MockReactMarkdownProps>;
80
+ }
81
+
82
+ const mockMarkdownState: MockMarkdownState = {
83
+ tree: null,
84
+ calls: [],
85
+ };
86
+
87
+ const MOCK_TAG_BY_NODE_TYPE: Record<string, string> = {
88
+ paragraph: "p",
89
+ strong: "strong",
90
+ emphasis: "em",
91
+ delete: "del",
92
+ link: "a",
93
+ image: "img",
94
+ inlineCode: "code",
95
+ blockquote: "blockquote",
96
+ list: "ul",
97
+ listItem: "li",
98
+ heading: "h2",
99
+ };
100
+
101
+ function mockAttributeName(propertyName: string): string {
102
+ // hast `dataCitationId` → DOM `data-citation-id`, as hast-util-to-jsx-runtime does.
103
+ return propertyName.replace(/[A-Z]/g, (letter: string): string => {
104
+ return `-${letter.toLowerCase()}`;
105
+ });
106
+ }
107
+
108
+ function runMockPlugins(
109
+ plugins: Array<unknown>,
110
+ tree: InlineReferenceMarkdownNode,
111
+ ): void {
112
+ for (const plugin of plugins) {
113
+ let transformer: unknown = undefined;
114
+
115
+ if (Array.isArray(plugin)) {
116
+ const [attacher, ...parameters] = plugin as [
117
+ (...args: Array<unknown>) => unknown,
118
+ ...Array<unknown>,
119
+ ];
120
+ transformer = attacher(...parameters);
121
+ } else if (typeof plugin === "function") {
122
+ transformer = (plugin as () => unknown)();
123
+ }
124
+
125
+ if (typeof transformer === "function") {
126
+ (transformer as (node: InlineReferenceMarkdownNode) => void)(tree);
127
+ }
128
+ }
129
+ }
130
+
131
+ function renderMockNode(
132
+ node: InlineReferenceMarkdownNode,
133
+ components: MockComponentMap,
134
+ key: number,
135
+ ): React.ReactNode {
136
+ if (node.type === "text") {
137
+ return node.value || "";
138
+ }
139
+
140
+ if (node.type === "definition") {
141
+ return null;
142
+ }
143
+
144
+ const tagName: string =
145
+ node.data?.hName || MOCK_TAG_BY_NODE_TYPE[node.type] || "span";
146
+ const elementProps: Record<string, unknown> = { key: key };
147
+
148
+ for (const [name, value] of Object.entries(node.data?.hProperties || {})) {
149
+ elementProps[mockAttributeName(name)] = value;
150
+ }
151
+
152
+ if (node.type === "link") {
153
+ elementProps["href"] = node["url"];
154
+ }
155
+
156
+ if (node.type === "image") {
157
+ elementProps["src"] = node["url"];
158
+ elementProps["alt"] = node.alt;
159
+ }
160
+
161
+ const children: Array<React.ReactNode> =
162
+ node.type === "inlineCode"
163
+ ? [node.value || ""]
164
+ : (node.children || []).map(
165
+ (child: InlineReferenceMarkdownNode, index: number) => {
166
+ return renderMockNode(child, components, index);
167
+ },
168
+ );
169
+
170
+ const component: React.ElementType = (components[tagName] ||
171
+ tagName) as React.ElementType;
172
+
173
+ return React.createElement(
174
+ component,
175
+ elementProps,
176
+ ...(children.length > 0 ? children : []),
177
+ );
178
+ }
179
+
180
+ function renderMockMarkdown(props: MockReactMarkdownProps): ReactElement {
181
+ mockMarkdownState.calls.push(props);
182
+
183
+ if (!mockMarkdownState.tree) {
184
+ return React.createElement(
185
+ "div",
186
+ { "data-testid": "react-markdown" },
187
+ props.children,
188
+ );
189
+ }
190
+
191
+ // The real pipeline parses fresh on every render; never mutate the fixture.
192
+ const tree: InlineReferenceMarkdownNode = cloneTree(mockMarkdownState.tree);
193
+ runMockPlugins(props.remarkPlugins || [], tree);
194
+
195
+ return React.createElement(
196
+ "div",
197
+ { "data-testid": "react-markdown" },
198
+ ...(tree.children || []).map(
199
+ (child: InlineReferenceMarkdownNode, index: number) => {
200
+ return renderMockNode(child, props.components || {}, index);
201
+ },
202
+ ),
203
+ );
204
+ }
205
+
206
+ /*
207
+ * ---------------------------------------------------------------------------
208
+ * mdast helpers
209
+ * ---------------------------------------------------------------------------
210
+ */
211
+
212
+ type Node = InlineReferenceMarkdownNode;
213
+
214
+ function cloneTree(tree: Node): Node {
215
+ return JSON.parse(JSON.stringify(tree)) as Node;
216
+ }
217
+
218
+ function text(value: string): Node {
219
+ return { type: "text", value: value };
220
+ }
221
+
222
+ function paragraph(...children: Array<Node>): Node {
223
+ return { type: "paragraph", children: children };
224
+ }
225
+
226
+ function root(...children: Array<Node>): Node {
227
+ return { type: "root", children: children };
228
+ }
229
+
230
+ function citation(citationId: string, value?: string): Node {
231
+ return {
232
+ type: CITATION_REFERENCE_NODE_TYPE,
233
+ data: {
234
+ hName: CITATION_REFERENCE_TAG_NAME,
235
+ hProperties: { dataCitationId: citationId },
236
+ },
237
+ children: [text(value ?? `[${citationId}]`)],
238
+ };
239
+ }
240
+
241
+ function eventRef(
242
+ kind: "incident" | "alert" | "",
243
+ referenceNumber: number,
244
+ value?: string,
245
+ ): Node {
246
+ return {
247
+ type: EVENT_REFERENCE_NODE_TYPE,
248
+ data: {
249
+ hName: EVENT_REFERENCE_TAG_NAME,
250
+ hProperties: {
251
+ dataRefKind: kind,
252
+ dataRefNumber: referenceNumber.toString(),
253
+ },
254
+ },
255
+ children: [text(value ?? `#${referenceNumber}`)],
256
+ };
257
+ }
258
+
259
+ function linkReference(
260
+ identifier: string,
261
+ children: Array<Node>,
262
+ referenceType: "shortcut" | "collapsed" | "full" = "shortcut",
263
+ label?: string,
264
+ ): Node {
265
+ return {
266
+ type: "linkReference",
267
+ identifier: identifier,
268
+ label: label ?? identifier.toUpperCase(),
269
+ referenceType: referenceType,
270
+ children: children,
271
+ };
272
+ }
273
+
274
+ const BOTH: { citations: boolean; eventReferences: boolean } = {
275
+ citations: true,
276
+ eventReferences: true,
277
+ };
278
+
279
+ // Transforms a single paragraph with the given children and returns them.
280
+ function transformParagraph(
281
+ children: Array<Node>,
282
+ options: { citations: boolean; eventReferences: boolean } = BOTH,
283
+ ): Array<Node> {
284
+ const tree: Node = root(paragraph(...children));
285
+ applyInlineReferences(tree, options);
286
+ return tree.children?.[0]?.children || [];
287
+ }
288
+
289
+ function transformText(
290
+ value: string,
291
+ options: { citations: boolean; eventReferences: boolean } = BOTH,
292
+ ): Array<Node> {
293
+ return transformParagraph([text(value)], options);
294
+ }
295
+
296
+ function collectNodes(
297
+ node: Node,
298
+ predicate: (candidate: Node) => boolean,
299
+ ): Array<Node> {
300
+ const found: Array<Node> = predicate(node) ? [node] : [];
301
+ for (const child of node.children || []) {
302
+ found.push(...collectNodes(child, predicate));
303
+ }
304
+ return found;
305
+ }
306
+
307
+ function isCustomReferenceNode(node: Node): boolean {
308
+ return (
309
+ node.type === CITATION_REFERENCE_NODE_TYPE ||
310
+ node.type === EVENT_REFERENCE_NODE_TYPE
311
+ );
312
+ }
313
+
314
+ function countType(tree: Node, type: string): number {
315
+ return collectNodes(tree, (node: Node): boolean => {
316
+ return node.type === type;
317
+ }).length;
318
+ }
319
+
320
+ const CITATION_IDENTIFIER: RegExp = /^c\d{1,3}$/i;
321
+
322
+ function isCitationReferenceNode(node: Node): boolean {
323
+ return (
324
+ (node.type === "linkReference" ||
325
+ node.type === "imageReference" ||
326
+ node.type === "definition") &&
327
+ CITATION_IDENTIFIER.test(node.identifier || "")
328
+ );
329
+ }
330
+
331
+ /*
332
+ * The text a reader would see, with citation references shown the way they
333
+ * read once reverted. The transform must preserve this exactly.
334
+ */
335
+ function visibleText(node: Node): string {
336
+ if (node.type === "text") {
337
+ return node.value || "";
338
+ }
339
+
340
+ if (node.type === "inlineCode" || node.type === "code") {
341
+ return `\`${node.value || ""}\``;
342
+ }
343
+
344
+ if (node.type === "html") {
345
+ return node.value || "";
346
+ }
347
+
348
+ if (node.type === "definition") {
349
+ return "";
350
+ }
351
+
352
+ if (node.type === "break") {
353
+ return "\n";
354
+ }
355
+
356
+ const suffix: string =
357
+ node.referenceType === "collapsed"
358
+ ? "][]"
359
+ : node.referenceType === "full"
360
+ ? `][${node.label || node.identifier || ""}]`
361
+ : "]";
362
+
363
+ if (node.type === "imageReference") {
364
+ return isCitationReferenceNode(node)
365
+ ? `![${node.alt || ""}${suffix}`
366
+ : `<image ${node.alt || ""}>`;
367
+ }
368
+
369
+ const inner: string = (node.children || []).map(visibleText).join("");
370
+
371
+ if (node.type === "linkReference" && isCitationReferenceNode(node)) {
372
+ return `[${inner}${suffix}`;
373
+ }
374
+
375
+ return inner;
376
+ }
377
+
378
+ const customNodeText: (node: Node) => string = (node: Node): string => {
379
+ return (node.children || [])
380
+ .map((child: Node): string => {
381
+ return child.value || "";
382
+ })
383
+ .join("");
384
+ };
385
+
386
+ afterEach(() => {
387
+ cleanup();
388
+ mockMarkdownState.tree = null;
389
+ mockMarkdownState.calls = [];
390
+ });
391
+
392
+ /*
393
+ * ---------------------------------------------------------------------------
394
+ * applyInlineReferences: citations
395
+ * ---------------------------------------------------------------------------
396
+ */
397
+
398
+ describe("applyInlineReferences — citation markers", () => {
399
+ test("splits a single citation into text + citation node + text", () => {
400
+ expect(transformText("Pool ran dry [C12] at 18:01.")).toEqual([
401
+ text("Pool ran dry "),
402
+ citation("C12"),
403
+ text(" at 18:01."),
404
+ ]);
405
+ });
406
+
407
+ test("builds the exact node shape, hName and hProperties", () => {
408
+ const [, node] = transformText("see [C7] now");
409
+
410
+ expect(node).toStrictEqual({
411
+ type: "oneuptimeCitationReference",
412
+ data: {
413
+ hName: "oneuptime-citation-ref",
414
+ hProperties: { dataCitationId: "C7" },
415
+ },
416
+ children: [{ type: "text", value: "[C7]" }],
417
+ });
418
+ });
419
+
420
+ test("splits several citations in one text run in order", () => {
421
+ expect(transformText("A [C1], B [C22] and C [C333].")).toEqual([
422
+ text("A "),
423
+ citation("C1"),
424
+ text(", B "),
425
+ citation("C22"),
426
+ text(" and C "),
427
+ citation("C333"),
428
+ text("."),
429
+ ]);
430
+ });
431
+
432
+ test("adjacent markers [C4][C5] become two back-to-back nodes with no empty text", () => {
433
+ const children: Array<Node> = transformText("dry [C4][C5].");
434
+
435
+ expect(children).toEqual([
436
+ text("dry "),
437
+ citation("C4"),
438
+ citation("C5"),
439
+ text("."),
440
+ ]);
441
+ expect(
442
+ children.some((child: Node): boolean => {
443
+ return child.type === "text" && child.value === "";
444
+ }),
445
+ ).toBe(false);
446
+ });
447
+
448
+ test("a marker that is the whole text run leaves no empty text around it", () => {
449
+ expect(transformText("[C3]")).toEqual([citation("C3")]);
450
+ });
451
+
452
+ test.each([
453
+ ["[C1234]"],
454
+ ["[c12]"],
455
+ ["[C]"],
456
+ ["[ C1 ]"],
457
+ ["C12"],
458
+ ["[CC1]"],
459
+ ["[C1a]"],
460
+ ["[C-1]"],
461
+ ])("leaves the non-citation %p as untouched text", (value: string) => {
462
+ const original: Node = text(`before ${value} after`);
463
+ const children: Array<Node> = transformParagraph([original], {
464
+ citations: true,
465
+ eventReferences: false,
466
+ });
467
+
468
+ expect(children).toHaveLength(1);
469
+ // Untouched nodes are kept by identity (positions and all).
470
+ expect(children[0]).toBe(original);
471
+ });
472
+
473
+ test("splits citations inside strong, emphasis, delete, headings, list items, table cells and blockquotes", () => {
474
+ const tree: Node = root(
475
+ paragraph({ type: "strong", children: [text("[C1]")] }),
476
+ paragraph({ type: "emphasis", children: [text("x [C2]")] }),
477
+ paragraph({ type: "delete", children: [text("[C3] y")] }),
478
+ { type: "heading", depth: 3, children: [text("Why [C4]")] },
479
+ {
480
+ type: "list",
481
+ children: [{ type: "listItem", children: [paragraph(text("- [C5]"))] }],
482
+ },
483
+ {
484
+ type: "table",
485
+ children: [
486
+ {
487
+ type: "tableRow",
488
+ children: [{ type: "tableCell", children: [text("[C6]")] }],
489
+ },
490
+ ],
491
+ },
492
+ { type: "blockquote", children: [paragraph(text("q [C7]"))] },
493
+ );
494
+
495
+ applyInlineReferences(tree, BOTH);
496
+
497
+ const ids: Array<string> = collectNodes(tree, (node: Node): boolean => {
498
+ return node.type === CITATION_REFERENCE_NODE_TYPE;
499
+ }).map((node: Node): string => {
500
+ return node.data?.hProperties?.["dataCitationId"] || "";
501
+ });
502
+
503
+ expect(ids).toEqual(["C1", "C2", "C3", "C4", "C5", "C6", "C7"]);
504
+ });
505
+
506
+ test("the server's evidence list bullet **[C11]** becomes a citation inside strong", () => {
507
+ const tree: Node = root({
508
+ type: "list",
509
+ children: [
510
+ {
511
+ type: "listItem",
512
+ children: [
513
+ paragraph(
514
+ { type: "strong", children: [text("[C11]")] },
515
+ text(" Logs search — 3 row(s)"),
516
+ ),
517
+ ],
518
+ },
519
+ ],
520
+ });
521
+
522
+ applyInlineReferences(tree, BOTH);
523
+
524
+ const strong: Node | undefined =
525
+ tree.children?.[0]?.children?.[0]?.children?.[0]?.children?.[0];
526
+ expect(strong?.children).toEqual([citation("C11")]);
527
+ });
528
+ });
529
+
530
+ /*
531
+ * ---------------------------------------------------------------------------
532
+ * applyInlineReferences: incident / alert numbers
533
+ * ---------------------------------------------------------------------------
534
+ */
535
+
536
+ describe("applyInlineReferences — incident and alert numbers", () => {
537
+ test("splits a bare #number with an empty kind", () => {
538
+ expect(transformText("Same as #6954 last week.")).toEqual([
539
+ text("Same as "),
540
+ eventRef("", 6954),
541
+ text(" last week."),
542
+ ]);
543
+ });
544
+
545
+ test("builds the exact node shape, hName and hProperties", () => {
546
+ const [, node] = transformText("incident #42 again");
547
+
548
+ expect(node).toStrictEqual({
549
+ type: "oneuptimeEventReference",
550
+ data: {
551
+ hName: "oneuptime-event-ref",
552
+ hProperties: { dataRefKind: "incident", dataRefNumber: "42" },
553
+ },
554
+ children: [{ type: "text", value: "#42" }],
555
+ });
556
+ });
557
+
558
+ test("an 'alert' qualifier sets the alert kind, case-insensitively", () => {
559
+ expect(transformText("Alert #12 fired")).toEqual([
560
+ text("Alert "),
561
+ eventRef("alert", 12),
562
+ text(" fired"),
563
+ ]);
564
+ });
565
+
566
+ test("a plural qualifier carries across a comma / and separated list", () => {
567
+ expect(transformText("prior: incidents #1, #2 and #3.")).toEqual([
568
+ text("prior: incidents "),
569
+ eventRef("incident", 1),
570
+ text(", "),
571
+ eventRef("incident", 2),
572
+ text(" and "),
573
+ eventRef("incident", 3),
574
+ text("."),
575
+ ]);
576
+ });
577
+
578
+ test("mixes citations and references in document order", () => {
579
+ expect(
580
+ transformText("Pool dry [C4]; same as incident #1234 and #77 [C5]."),
581
+ ).toEqual([
582
+ text("Pool dry "),
583
+ citation("C4"),
584
+ text("; same as incident "),
585
+ eventRef("incident", 1234),
586
+ text(" and "),
587
+ eventRef("incident", 77),
588
+ text(" "),
589
+ citation("C5"),
590
+ text("."),
591
+ ]);
592
+ });
593
+
594
+ test.each([
595
+ ["abc#12"],
596
+ ["&#123;"],
597
+ ["https://x/#12"],
598
+ ["##12"],
599
+ ["#12abc"],
600
+ ["#1234567890"],
601
+ ["#"],
602
+ ["# 12"],
603
+ ])("does not treat %p as a reference", (value: string) => {
604
+ const original: Node = text(value);
605
+ const children: Array<Node> = transformParagraph([original], {
606
+ citations: false,
607
+ eventReferences: true,
608
+ });
609
+
610
+ expect(children).toEqual([original]);
611
+ });
612
+
613
+ test("a bracketed [#12] (never a link without a definition) keeps its brackets as text", () => {
614
+ expect(transformText("see [#12]")).toEqual([
615
+ text("see ["),
616
+ eventRef("", 12),
617
+ text("]"),
618
+ ]);
619
+ });
620
+
621
+ /*
622
+ * An empty kind means "the subject's kind" to the panel, so a qualifier
623
+ * lost to punctuation would link "alerts: #100" to incident #100.
624
+ */
625
+ test("a qualifier followed by a colon or parenthesis still sets the kind of the whole list", () => {
626
+ expect(transformText("Related alerts: #100, #101")).toEqual([
627
+ text("Related alerts: "),
628
+ eventRef("alert", 100),
629
+ text(", "),
630
+ eventRef("alert", 101),
631
+ ]);
632
+ expect(transformText("a similar incident (#12)")).toEqual([
633
+ text("a similar incident ("),
634
+ eventRef("incident", 12),
635
+ text(")"),
636
+ ]);
637
+ });
638
+
639
+ test.each([
640
+ ["Scheduled maintenance #42 overlapped"],
641
+ ["incident episode #3"],
642
+ ["PRs #45, #46 and #47"],
643
+ ["step #1 of the runbook"],
644
+ ])(
645
+ "leaves a number from another numbering in %p as plain text",
646
+ (value: string) => {
647
+ const original: Node = text(value);
648
+
649
+ expect(transformParagraph([original], BOTH)).toEqual([original]);
650
+ },
651
+ );
652
+
653
+ test("a number from another numbering does not stop a real reference beside it", () => {
654
+ expect(transformText("PR #45 reverted incident #46")).toEqual([
655
+ text("PR #45 reverted incident "),
656
+ eventRef("incident", 46),
657
+ ]);
658
+ });
659
+ });
660
+
661
+ /*
662
+ * ---------------------------------------------------------------------------
663
+ * applyInlineReferences: what is never touched
664
+ * ---------------------------------------------------------------------------
665
+ */
666
+
667
+ describe("applyInlineReferences — opaque content", () => {
668
+ test("never splits text inside a link", () => {
669
+ const link: Node = {
670
+ type: "link",
671
+ url: "https://evil.example/#12",
672
+ children: [text("[C1] incident #12")],
673
+ };
674
+ const snapshot: Node = cloneTree(link);
675
+
676
+ const children: Array<Node> = transformParagraph([
677
+ text("go "),
678
+ link,
679
+ text(" [C2]"),
680
+ ]);
681
+
682
+ expect(children).toEqual([
683
+ text("go "),
684
+ snapshot,
685
+ text(" "),
686
+ citation("C2"),
687
+ ]);
688
+ });
689
+
690
+ test("never splits text inside a non-citation link reference", () => {
691
+ const reference: Node = linkReference("docs", [text("[C1] #12")]);
692
+ const snapshot: Node = cloneTree(reference);
693
+
694
+ expect(transformParagraph([reference])).toEqual([snapshot]);
695
+ });
696
+
697
+ test("never touches inline code, code blocks or html", () => {
698
+ const tree: Node = root(
699
+ paragraph({ type: "inlineCode", value: "[C1] #12" }),
700
+ { type: "code", lang: "text", value: "[C1]\nincident #12" },
701
+ { type: "html", value: "<b>[C1] #12</b>" },
702
+ );
703
+ const snapshot: Node = cloneTree(tree);
704
+
705
+ applyInlineReferences(tree, BOTH);
706
+
707
+ expect(tree).toEqual(snapshot);
708
+ });
709
+
710
+ test("does not split the text of nested link content inside emphasis inside a link", () => {
711
+ const tree: Node = root(
712
+ paragraph({
713
+ type: "link",
714
+ url: "https://example.com",
715
+ children: [{ type: "emphasis", children: [text("[C9] #9")] }],
716
+ }),
717
+ );
718
+ const snapshot: Node = cloneTree(tree);
719
+
720
+ applyInlineReferences(tree, BOTH);
721
+
722
+ expect(tree).toEqual(snapshot);
723
+ });
724
+
725
+ test("leaves the tree untouched when both transforms are off", () => {
726
+ const tree: Node = root(
727
+ { type: "definition", identifier: "c1", url: "https://evil.example" },
728
+ paragraph(text("[C1] #12 "), linkReference("c1", [text("C1")])),
729
+ );
730
+ const snapshot: Node = cloneTree(tree);
731
+
732
+ applyInlineReferences(tree, { citations: false, eventReferences: false });
733
+
734
+ expect(tree).toEqual(snapshot);
735
+ });
736
+
737
+ test("citations off: markers stay text and citation link references are not reverted", () => {
738
+ const reference: Node = linkReference("c1", [text("C1")]);
739
+ const children: Array<Node> = transformParagraph(
740
+ [text("[C2] incident #5 "), reference],
741
+ { citations: false, eventReferences: true },
742
+ );
743
+
744
+ expect(children).toEqual([
745
+ text("[C2] incident "),
746
+ eventRef("incident", 5),
747
+ text(" "),
748
+ reference,
749
+ ]);
750
+ });
751
+
752
+ test("event references off: numbers stay text", () => {
753
+ expect(
754
+ transformText("[C2] incident #5", {
755
+ citations: true,
756
+ eventReferences: false,
757
+ }),
758
+ ).toEqual([citation("C2"), text(" incident #5")]);
759
+ });
760
+
761
+ test("is idempotent — a second pass changes nothing", () => {
762
+ const tree: Node = root(
763
+ paragraph(
764
+ text("dry [C4][C5], incidents #1 and #2 "),
765
+ linkReference("c7", [text("C7")]),
766
+ ),
767
+ );
768
+
769
+ applyInlineReferences(tree, BOTH);
770
+ const once: Node = cloneTree(tree);
771
+ applyInlineReferences(tree, BOTH);
772
+
773
+ expect(tree).toEqual(once);
774
+ });
775
+
776
+ test("tolerates empty, value-less and childless nodes", () => {
777
+ const tree: Node = root(
778
+ paragraph(text(""), { type: "text" }, { type: "break" }),
779
+ { type: "paragraph" },
780
+ { type: "thematicBreak" },
781
+ );
782
+
783
+ expect(() => {
784
+ applyInlineReferences(tree, BOTH);
785
+ }).not.toThrow();
786
+ expect(collectNodes(tree, isCustomReferenceNode)).toHaveLength(0);
787
+ });
788
+
789
+ test("tolerates a missing tree", () => {
790
+ expect(() => {
791
+ applyInlineReferences(undefined as unknown as Node, BOTH);
792
+ applyInlineReferences(null as unknown as Node, BOTH);
793
+ }).not.toThrow();
794
+ });
795
+ });
796
+
797
+ /*
798
+ * ---------------------------------------------------------------------------
799
+ * applyInlineReferences: citation link references and definitions
800
+ * ---------------------------------------------------------------------------
801
+ */
802
+
803
+ describe("applyInlineReferences — a citation can never become a link", () => {
804
+ test("reverts a shortcut [C12] link reference to text and splits it", () => {
805
+ const tree: Node = root(
806
+ paragraph(
807
+ text("See "),
808
+ linkReference("c12", [text("C12")]),
809
+ text(" now"),
810
+ ),
811
+ { type: "definition", identifier: "c12", url: "https://evil.example" },
812
+ );
813
+
814
+ applyInlineReferences(tree, BOTH);
815
+
816
+ expect(tree).toEqual(
817
+ root(paragraph(text("See "), citation("C12"), text(" now"))),
818
+ );
819
+ });
820
+
821
+ test("drops citation definitions anywhere, keeps other definitions", () => {
822
+ const keep: Node = {
823
+ type: "definition",
824
+ identifier: "docs",
825
+ url: "https://docs.example",
826
+ };
827
+ const tree: Node = root(
828
+ { type: "definition", identifier: "C3", url: "https://a.example" },
829
+ keep,
830
+ {
831
+ type: "blockquote",
832
+ children: [
833
+ { type: "definition", identifier: "c999", url: "https://b.example" },
834
+ paragraph(text("quoted")),
835
+ ],
836
+ },
837
+ {
838
+ type: "list",
839
+ children: [
840
+ {
841
+ type: "listItem",
842
+ children: [
843
+ {
844
+ type: "definition",
845
+ identifier: "c1",
846
+ url: "https://c.example",
847
+ },
848
+ ],
849
+ },
850
+ ],
851
+ },
852
+ );
853
+
854
+ applyInlineReferences(tree, BOTH);
855
+
856
+ expect(collectNodes(tree, isCitationReferenceNode)).toHaveLength(0);
857
+ expect(tree.children?.[0]).toBe(keep);
858
+ expect(countType(tree, "definition")).toBe(1);
859
+ });
860
+
861
+ test("does not drop definitions for identifiers that only look similar", () => {
862
+ const tree: Node = root(
863
+ { type: "definition", identifier: "c1234", url: "https://a.example" },
864
+ { type: "definition", identifier: "cc1", url: "https://b.example" },
865
+ { type: "definition", identifier: "c", url: "https://c.example" },
866
+ );
867
+
868
+ applyInlineReferences(tree, BOTH);
869
+
870
+ expect(countType(tree, "definition")).toBe(3);
871
+ });
872
+
873
+ test("reverts a collapsed [C12][] reference", () => {
874
+ expect(
875
+ transformParagraph([linkReference("c12", [text("C12")], "collapsed")]),
876
+ ).toEqual([citation("C12"), text("[]")]);
877
+ });
878
+
879
+ test("reverts a full [evidence][C3] reference", () => {
880
+ expect(
881
+ transformParagraph([
882
+ text("the "),
883
+ linkReference("c3", [text("evidence")], "full", "C3"),
884
+ ]),
885
+ ).toEqual([text("the [evidence]"), citation("C3")]);
886
+ });
887
+
888
+ test("reverts a citation image reference ![C2] to text", () => {
889
+ expect(
890
+ transformParagraph([
891
+ text("look "),
892
+ {
893
+ type: "imageReference",
894
+ identifier: "c2",
895
+ label: "C2",
896
+ referenceType: "shortcut",
897
+ alt: "C2",
898
+ },
899
+ ]),
900
+ ).toEqual([text("look !"), citation("C2")]);
901
+ });
902
+
903
+ test("keeps the formatted children of a reverted reference and still splits inside them", () => {
904
+ expect(
905
+ transformParagraph([
906
+ linkReference(
907
+ "c4",
908
+ [{ type: "emphasis", children: [text("see #88")] }],
909
+ "full",
910
+ "C4",
911
+ ),
912
+ ]),
913
+ ).toEqual([
914
+ text("["),
915
+ { type: "emphasis", children: [text("see "), eventRef("", 88)] },
916
+ text("]"),
917
+ citation("C4"),
918
+ ]);
919
+ });
920
+
921
+ test("reverts citation link references nested in strong inside a list item", () => {
922
+ const tree: Node = root({
923
+ type: "list",
924
+ children: [
925
+ {
926
+ type: "listItem",
927
+ children: [
928
+ paragraph({
929
+ type: "strong",
930
+ children: [linkReference("c11", [text("C11")])],
931
+ }),
932
+ ],
933
+ },
934
+ ],
935
+ });
936
+
937
+ applyInlineReferences(tree, BOTH);
938
+
939
+ expect(countType(tree, "linkReference")).toBe(0);
940
+ expect(
941
+ collectNodes(tree, (node: Node): boolean => {
942
+ return node.type === "strong";
943
+ })[0]?.children,
944
+ ).toEqual([citation("C11")]);
945
+ });
946
+
947
+ test("reverts a citation reference hoisted out of another citation reference", () => {
948
+ /*
949
+ * The parser never nests references, but the transform must not rely on
950
+ * that: the inner reference is examined after the outer one is reverted.
951
+ */
952
+ const tree: Node = root(
953
+ paragraph(
954
+ text("a "),
955
+ linkReference(
956
+ "c18",
957
+ [
958
+ { type: "break" },
959
+ linkReference("c4", [text("C4")], "full", "C4"),
960
+ text(" b"),
961
+ ],
962
+ "full",
963
+ "C18",
964
+ ),
965
+ ),
966
+ );
967
+
968
+ applyInlineReferences(tree, { citations: true, eventReferences: false });
969
+
970
+ expect(countType(tree, "linkReference")).toBe(0);
971
+ // "[C4][C4]" is how a full [C4][C4] reference reads once reverted.
972
+ expect(tree.children?.[0]?.children).toEqual([
973
+ text("a ["),
974
+ { type: "break" },
975
+ citation("C4"),
976
+ citation("C4"),
977
+ text(" b]"),
978
+ citation("C18"),
979
+ ]);
980
+ });
981
+
982
+ test("merges a reverted run into one text node spanning the original positions", () => {
983
+ const start: { line: number; column: number; offset: number } = {
984
+ line: 1,
985
+ column: 1,
986
+ offset: 0,
987
+ };
988
+ const middle: { line: number; column: number; offset: number } = {
989
+ line: 1,
990
+ column: 3,
991
+ offset: 2,
992
+ };
993
+ const end: { line: number; column: number; offset: number } = {
994
+ line: 1,
995
+ column: 9,
996
+ offset: 8,
997
+ };
998
+ const untouchedReference: Node = linkReference("docs", [text("docs")]);
999
+ const tree: Node = root(
1000
+ paragraph(
1001
+ { type: "text", value: "a ", position: { start: start, end: middle } },
1002
+ untouchedReference,
1003
+ { type: "text", value: " b", position: { start: middle, end: end } },
1004
+ ),
1005
+ /*
1006
+ * "[c1]" — lowercase, so the reverted text is not a citation marker and
1007
+ * the merged node survives unsplit.
1008
+ */
1009
+ paragraph(
1010
+ { type: "text", value: "x ", position: { start: start, end: middle } },
1011
+ linkReference("c1", [text("c1")], "shortcut", "c1"),
1012
+ { type: "text", value: " y", position: { start: middle, end: end } },
1013
+ ),
1014
+ paragraph(
1015
+ text("no positions "),
1016
+ linkReference("c2", [text("c2")], "shortcut", "c2"),
1017
+ ),
1018
+ );
1019
+
1020
+ applyInlineReferences(tree, { citations: true, eventReferences: false });
1021
+
1022
+ // No citation reference in the first paragraph: nothing merged, identity kept.
1023
+ expect(tree.children?.[0]?.children).toHaveLength(3);
1024
+ expect(tree.children?.[0]?.children?.[1]).toBe(untouchedReference);
1025
+
1026
+ expect(tree.children?.[1]?.children).toStrictEqual([
1027
+ { type: "text", value: "x [c1] y", position: { start: start, end: end } },
1028
+ ]);
1029
+
1030
+ expect(tree.children?.[2]?.children).toStrictEqual([
1031
+ { type: "text", value: "no positions [c2]" },
1032
+ ]);
1033
+ });
1034
+
1035
+ test("a reverted marker merged with its surrounding text is split back out", () => {
1036
+ expect(
1037
+ transformParagraph(
1038
+ [text("x "), linkReference("c1", [text("C1")]), text(" y")],
1039
+ { citations: true, eventReferences: false },
1040
+ ),
1041
+ ).toEqual([text("x "), citation("C1"), text(" y")]);
1042
+ });
1043
+ });
1044
+
1045
+ /*
1046
+ * ---------------------------------------------------------------------------
1047
+ * applyInlineReferences: invariants over many generated trees
1048
+ * ---------------------------------------------------------------------------
1049
+ */
1050
+
1051
+ describe("applyInlineReferences — generated trees", () => {
1052
+ // Small deterministic PRNG so a failure is reproducible from its seed.
1053
+ const createRandom: (seed: number) => () => number = (
1054
+ seed: number,
1055
+ ): (() => number) => {
1056
+ let state: number = seed >>> 0;
1057
+ return (): number => {
1058
+ state = (state + 0x6d2b79f5) >>> 0;
1059
+ let value: number = state;
1060
+ value = Math.imul(value ^ (value >>> 15), value | 1);
1061
+ value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
1062
+ return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
1063
+ };
1064
+ };
1065
+
1066
+ const FRAGMENTS: Array<string> = [
1067
+ "[C1]",
1068
+ "[C12]",
1069
+ "[C999]",
1070
+ "[C1000]",
1071
+ "[c3]",
1072
+ "[C4][C5]",
1073
+ "#1",
1074
+ "#6954",
1075
+ "#123456789",
1076
+ "#1234567890",
1077
+ "incident ",
1078
+ "incidents ",
1079
+ "alert ",
1080
+ "Alerts ",
1081
+ ", ",
1082
+ " and ",
1083
+ "abc",
1084
+ "abc#12",
1085
+ "&#123;",
1086
+ "/#5",
1087
+ "##7",
1088
+ "#8abc",
1089
+ "[",
1090
+ "]",
1091
+ "C",
1092
+ "#",
1093
+ " ",
1094
+ "\n",
1095
+ "—",
1096
+ "é",
1097
+ "[#12]",
1098
+ "(see [C2])",
1099
+ "javascript:alert(1)",
1100
+ "![x](https://evil.example/p.png)",
1101
+ ];
1102
+
1103
+ type Random = () => number;
1104
+
1105
+ const pick: <T>(random: Random, items: Array<T>) => T = <T,>(
1106
+ random: Random,
1107
+ items: Array<T>,
1108
+ ): T => {
1109
+ return items[Math.floor(random() * items.length)] as T;
1110
+ };
1111
+
1112
+ const randomText: (random: Random) => string = (random: Random): string => {
1113
+ let value: string = "";
1114
+ const count: number = 1 + Math.floor(random() * 6);
1115
+ for (let index: number = 0; index < count; index++) {
1116
+ value += pick(random, FRAGMENTS);
1117
+ }
1118
+ return value;
1119
+ };
1120
+
1121
+ const randomInline: (random: Random, depth: number) => Node = (
1122
+ random: Random,
1123
+ depth: number,
1124
+ ): Node => {
1125
+ const roll: number = random();
1126
+ const nested: () => Array<Node> = (): Array<Node> => {
1127
+ const children: Array<Node> = [];
1128
+ const count: number = 1 + Math.floor(random() * 3);
1129
+ for (let index: number = 0; index < count; index++) {
1130
+ children.push(randomInline(random, depth + 1));
1131
+ }
1132
+ return children;
1133
+ };
1134
+
1135
+ if (depth > 2 || roll < 0.35) {
1136
+ return text(randomText(random));
1137
+ }
1138
+ if (roll < 0.45) {
1139
+ return {
1140
+ type: pick(random, ["strong", "emphasis", "delete"]),
1141
+ children: nested(),
1142
+ };
1143
+ }
1144
+ if (roll < 0.55) {
1145
+ return {
1146
+ type: "link",
1147
+ url: "https://evil.example/#12",
1148
+ children: [text(randomText(random))],
1149
+ };
1150
+ }
1151
+ if (roll < 0.65) {
1152
+ const id: number = 1 + Math.floor(random() * 20);
1153
+ return linkReference(
1154
+ `c${id}`,
1155
+ random() < 0.5 ? [text(`C${id}`)] : nested(),
1156
+ pick(random, ["shortcut", "collapsed", "full"] as Array<
1157
+ "shortcut" | "collapsed" | "full"
1158
+ >),
1159
+ `C${id}`,
1160
+ );
1161
+ }
1162
+ if (roll < 0.72) {
1163
+ return linkReference("docs", [text(randomText(random))]);
1164
+ }
1165
+ if (roll < 0.78) {
1166
+ return {
1167
+ type: "imageReference",
1168
+ identifier: random() < 0.5 ? "c2" : "logo",
1169
+ label: "C2",
1170
+ referenceType: "shortcut",
1171
+ alt: randomText(random),
1172
+ };
1173
+ }
1174
+ if (roll < 0.84) {
1175
+ return { type: "image", url: "https://evil.example/p.png", alt: "x" };
1176
+ }
1177
+ if (roll < 0.9) {
1178
+ return { type: "inlineCode", value: randomText(random) };
1179
+ }
1180
+ if (roll < 0.95) {
1181
+ return { type: "html", value: `<b>${randomText(random)}</b>` };
1182
+ }
1183
+ return { type: "break" };
1184
+ };
1185
+
1186
+ const randomTree: (random: Random) => Node = (random: Random): Node => {
1187
+ const blocks: Array<Node> = [];
1188
+ const count: number = 1 + Math.floor(random() * 5);
1189
+
1190
+ for (let index: number = 0; index < count; index++) {
1191
+ const inlines: Array<Node> = [];
1192
+ const inlineCount: number = 1 + Math.floor(random() * 4);
1193
+ for (let inline: number = 0; inline < inlineCount; inline++) {
1194
+ inlines.push(randomInline(random, 0));
1195
+ }
1196
+
1197
+ const roll: number = random();
1198
+ if (roll < 0.5) {
1199
+ blocks.push(paragraph(...inlines));
1200
+ } else if (roll < 0.6) {
1201
+ blocks.push({ type: "heading", depth: 2, children: inlines });
1202
+ } else if (roll < 0.75) {
1203
+ blocks.push({
1204
+ type: "list",
1205
+ children: [{ type: "listItem", children: [paragraph(...inlines)] }],
1206
+ });
1207
+ } else if (roll < 0.85) {
1208
+ blocks.push({ type: "blockquote", children: [paragraph(...inlines)] });
1209
+ } else if (roll < 0.92) {
1210
+ blocks.push({
1211
+ type: "definition",
1212
+ identifier:
1213
+ random() < 0.7 ? `c${1 + Math.floor(random() * 20)}` : "docs",
1214
+ url: "https://evil.example",
1215
+ });
1216
+ } else {
1217
+ blocks.push({ type: "code", value: randomText(random) });
1218
+ }
1219
+ }
1220
+
1221
+ return root(...blocks);
1222
+ };
1223
+
1224
+ const OPAQUE: Set<string> = new Set<string>([
1225
+ "link",
1226
+ "linkReference",
1227
+ "image",
1228
+ "imageReference",
1229
+ "inlineCode",
1230
+ "code",
1231
+ "html",
1232
+ ]);
1233
+
1234
+ const findCustomNodesInsideOpaque: (
1235
+ node: Node,
1236
+ insideOpaque: boolean,
1237
+ ) => Array<Node> = (node: Node, insideOpaque: boolean): Array<Node> => {
1238
+ const found: Array<Node> =
1239
+ insideOpaque && isCustomReferenceNode(node) ? [node] : [];
1240
+ const childInsideOpaque: boolean = insideOpaque || OPAQUE.has(node.type);
1241
+ for (const child of node.children || []) {
1242
+ found.push(...findCustomNodesInsideOpaque(child, childInsideOpaque));
1243
+ }
1244
+ return found;
1245
+ };
1246
+
1247
+ test("never creates links or images, never leaves a citation link, and preserves the visible text", () => {
1248
+ const random: Random = createRandom(20260914);
1249
+
1250
+ for (let iteration: number = 0; iteration < 400; iteration++) {
1251
+ const tree: Node = randomTree(random);
1252
+ const before: Node = cloneTree(tree);
1253
+
1254
+ applyInlineReferences(tree, BOTH);
1255
+
1256
+ const context: string = `iteration ${iteration}: ${JSON.stringify(before)}`;
1257
+
1258
+ // Never creates link or image nodes.
1259
+ expect({ context, count: countType(tree, "link") }).toEqual({
1260
+ context,
1261
+ count: countType(before, "link"),
1262
+ });
1263
+ expect({ context, count: countType(tree, "image") }).toEqual({
1264
+ context,
1265
+ count: countType(before, "image"),
1266
+ });
1267
+
1268
+ // No citation link reference, image reference or definition survives.
1269
+ expect({
1270
+ context,
1271
+ left: collectNodes(tree, isCitationReferenceNode),
1272
+ }).toEqual({
1273
+ context,
1274
+ left: [],
1275
+ });
1276
+
1277
+ // Other references and definitions are left alone.
1278
+ const nonCitation: (candidate: Node) => boolean = (
1279
+ candidate: Node,
1280
+ ): boolean => {
1281
+ return (
1282
+ ["linkReference", "imageReference", "definition"].includes(
1283
+ candidate.type,
1284
+ ) && !isCitationReferenceNode(candidate)
1285
+ );
1286
+ };
1287
+ expect({
1288
+ context,
1289
+ count: collectNodes(tree, nonCitation).length,
1290
+ }).toEqual({
1291
+ context,
1292
+ count: collectNodes(before, nonCitation).length,
1293
+ });
1294
+
1295
+ // Nothing a reader sees is added, lost or reordered.
1296
+ expect({ context, text: visibleText(tree) }).toEqual({
1297
+ context,
1298
+ text: visibleText(before),
1299
+ });
1300
+
1301
+ // Custom nodes never sit inside links, references or code.
1302
+ expect({
1303
+ context,
1304
+ nested: findCustomNodesInsideOpaque(tree, false),
1305
+ }).toEqual({
1306
+ context,
1307
+ nested: [],
1308
+ });
1309
+
1310
+ // Every custom node carries only a validated token.
1311
+ for (const node of collectNodes(tree, isCustomReferenceNode)) {
1312
+ const value: string = customNodeText(node);
1313
+ expect(node.children).toHaveLength(1);
1314
+
1315
+ if (node.type === CITATION_REFERENCE_NODE_TYPE) {
1316
+ expect(node.data?.hName).toBe(CITATION_REFERENCE_TAG_NAME);
1317
+ expect(value).toMatch(/^\[C\d{1,3}\]$/);
1318
+ expect(node.data?.hProperties).toEqual({
1319
+ dataCitationId: value.slice(1, -1),
1320
+ });
1321
+ } else {
1322
+ expect(node.data?.hName).toBe(EVENT_REFERENCE_TAG_NAME);
1323
+ expect(value).toMatch(/^#\d{1,9}$/);
1324
+ expect(Object.keys(node.data?.hProperties || {}).sort()).toEqual([
1325
+ "dataRefKind",
1326
+ "dataRefNumber",
1327
+ ]);
1328
+ expect(["", "incident", "alert"]).toContain(
1329
+ node.data?.hProperties?.["dataRefKind"],
1330
+ );
1331
+ expect(node.data?.hProperties?.["dataRefNumber"]).toBe(
1332
+ String(parseInt(value.slice(1), 10)),
1333
+ );
1334
+ }
1335
+ }
1336
+ }
1337
+ });
1338
+ });
1339
+
1340
+ /*
1341
+ * ---------------------------------------------------------------------------
1342
+ * remarkInlineReferences
1343
+ * ---------------------------------------------------------------------------
1344
+ */
1345
+
1346
+ describe("remarkInlineReferences", () => {
1347
+ test("returns a transformer that applies both passes by default", () => {
1348
+ const tree: Node = root(paragraph(text("[C1] and #2")));
1349
+
1350
+ remarkInlineReferences()(tree);
1351
+
1352
+ expect(tree.children?.[0]?.children).toEqual([
1353
+ citation("C1"),
1354
+ text(" and "),
1355
+ eventRef("", 2),
1356
+ ]);
1357
+ });
1358
+
1359
+ test("honours disabled passes", () => {
1360
+ const citationsOnly: Node = root(paragraph(text("[C1] and #2")));
1361
+ remarkInlineReferences({ eventReferences: false })(citationsOnly);
1362
+ expect(citationsOnly.children?.[0]?.children).toEqual([
1363
+ citation("C1"),
1364
+ text(" and #2"),
1365
+ ]);
1366
+
1367
+ const referencesOnly: Node = root(paragraph(text("[C1] and #2")));
1368
+ remarkInlineReferences({ citations: false })(referencesOnly);
1369
+ expect(referencesOnly.children?.[0]?.children).toEqual([
1370
+ text("[C1] and "),
1371
+ eventRef("", 2),
1372
+ ]);
1373
+ });
1374
+ });
1375
+
1376
+ /*
1377
+ * ---------------------------------------------------------------------------
1378
+ * Reference elements
1379
+ * ---------------------------------------------------------------------------
1380
+ */
1381
+
1382
+ const Chip: React.FunctionComponent<{ id: string }> = (props: {
1383
+ id: string;
1384
+ }): ReactElement => {
1385
+ return (
1386
+ <button type="button" data-testid="chip">
1387
+ chip:{props.id}
1388
+ </button>
1389
+ );
1390
+ };
1391
+
1392
+ describe("MarkdownCitationReferenceElement", () => {
1393
+ test("renders what renderCitation returns for the citation id", () => {
1394
+ const renderCitation: MockFunction = getJestMockFunction();
1395
+ renderCitation.mockImplementation((citationId: unknown) => {
1396
+ return <Chip id={String(citationId)} />;
1397
+ });
1398
+
1399
+ render(
1400
+ <p>
1401
+ <MarkdownInlineReferenceContext.Provider
1402
+ value={{
1403
+ renderCitation: renderCitation as unknown as (
1404
+ citationId: string,
1405
+ ) => ReactElement | null,
1406
+ }}
1407
+ >
1408
+ before{" "}
1409
+ <MarkdownCitationReferenceElement data-citation-id="C12">
1410
+ [C12]
1411
+ </MarkdownCitationReferenceElement>{" "}
1412
+ after
1413
+ </MarkdownInlineReferenceContext.Provider>
1414
+ </p>,
1415
+ );
1416
+
1417
+ expect(renderCitation).toHaveBeenCalledWith("C12");
1418
+ expect(screen.getByTestId("chip")).toHaveTextContent("chip:C12");
1419
+ expect(screen.queryByText("[C12]")).toBeNull();
1420
+ });
1421
+
1422
+ test("falls back to the plain marker when renderCitation returns null", () => {
1423
+ const { container } = render(
1424
+ <p>
1425
+ <MarkdownInlineReferenceContext.Provider
1426
+ value={{
1427
+ renderCitation: (): ReactElement | null => {
1428
+ return null;
1429
+ },
1430
+ }}
1431
+ >
1432
+ <MarkdownCitationReferenceElement data-citation-id="C5">
1433
+ [C5]
1434
+ </MarkdownCitationReferenceElement>
1435
+ </MarkdownInlineReferenceContext.Provider>
1436
+ </p>,
1437
+ );
1438
+
1439
+ expect(container.innerHTML).toBe("<p>[C5]</p>");
1440
+ });
1441
+
1442
+ test("falls back to plain text without a provider", () => {
1443
+ const { container } = render(
1444
+ <p>
1445
+ <MarkdownCitationReferenceElement data-citation-id="C5">
1446
+ [C5]
1447
+ </MarkdownCitationReferenceElement>
1448
+ </p>,
1449
+ );
1450
+
1451
+ expect(container.innerHTML).toBe("<p>[C5]</p>");
1452
+ });
1453
+
1454
+ test("falls back to plain text when the provider has no renderCitation", () => {
1455
+ const renderEventReference: MockFunction = getJestMockFunction();
1456
+ const { container } = render(
1457
+ <MarkdownInlineReferenceContext.Provider
1458
+ value={{
1459
+ renderEventReference: renderEventReference as unknown as (
1460
+ reference: MarkdownEventReference,
1461
+ ) => ReactElement | null,
1462
+ }}
1463
+ >
1464
+ <MarkdownCitationReferenceElement data-citation-id="C5">
1465
+ [C5]
1466
+ </MarkdownCitationReferenceElement>
1467
+ </MarkdownInlineReferenceContext.Provider>,
1468
+ );
1469
+
1470
+ expect(container.textContent).toBe("[C5]");
1471
+ expect(renderEventReference).not.toHaveBeenCalled();
1472
+ });
1473
+
1474
+ test.each([["javascript:alert(1)"], ["C1234"], ["c12"], [""], ["C1 "]])(
1475
+ "never calls renderCitation for the malformed id %p",
1476
+ (citationId: string) => {
1477
+ const renderCitation: MockFunction = getJestMockFunction();
1478
+ const { container } = render(
1479
+ <MarkdownInlineReferenceContext.Provider
1480
+ value={{
1481
+ renderCitation: renderCitation as unknown as (
1482
+ citationId: string,
1483
+ ) => ReactElement | null,
1484
+ }}
1485
+ >
1486
+ <MarkdownCitationReferenceElement data-citation-id={citationId}>
1487
+ literal
1488
+ </MarkdownCitationReferenceElement>
1489
+ </MarkdownInlineReferenceContext.Provider>,
1490
+ );
1491
+
1492
+ expect(renderCitation).not.toHaveBeenCalled();
1493
+ expect(container.textContent).toBe("literal");
1494
+ },
1495
+ );
1496
+
1497
+ test("renders the marker text when there are no children", () => {
1498
+ const { container } = render(
1499
+ <MarkdownCitationReferenceElement data-citation-id="C8" />,
1500
+ );
1501
+
1502
+ expect(container.textContent).toBe("[C8]");
1503
+ });
1504
+ });
1505
+
1506
+ describe("MarkdownEventReferenceElement", () => {
1507
+ const renderWith: (
1508
+ renderEventReference:
1509
+ | ((reference: MarkdownEventReference) => ReactElement | null)
1510
+ | undefined,
1511
+ element: ReactElement,
1512
+ ) => HTMLElement = (
1513
+ renderEventReference:
1514
+ | ((reference: MarkdownEventReference) => ReactElement | null)
1515
+ | undefined,
1516
+ element: ReactElement,
1517
+ ): HTMLElement => {
1518
+ return render(
1519
+ <MarkdownInlineReferenceContext.Provider
1520
+ value={{ renderEventReference: renderEventReference }}
1521
+ >
1522
+ {element}
1523
+ </MarkdownInlineReferenceContext.Provider>,
1524
+ ).container;
1525
+ };
1526
+
1527
+ test("passes kind, number and the text as written to renderEventReference", () => {
1528
+ const received: Array<MarkdownEventReference> = [];
1529
+
1530
+ renderWith(
1531
+ (reference: MarkdownEventReference): ReactElement => {
1532
+ received.push(reference);
1533
+ return <span data-testid="reference-link">{reference.text}</span>;
1534
+ },
1535
+ <MarkdownEventReferenceElement
1536
+ data-ref-kind="incident"
1537
+ data-ref-number="6954"
1538
+ >
1539
+ #6954
1540
+ </MarkdownEventReferenceElement>,
1541
+ );
1542
+
1543
+ expect(received).toEqual([
1544
+ { kind: "incident", number: 6954, text: "#6954" },
1545
+ ]);
1546
+ expect(screen.getByTestId("reference-link")).toHaveTextContent("#6954");
1547
+ });
1548
+
1549
+ test("an alert kind is passed through", () => {
1550
+ const received: Array<MarkdownEventReference> = [];
1551
+
1552
+ renderWith(
1553
+ (reference: MarkdownEventReference): ReactElement | null => {
1554
+ received.push(reference);
1555
+ return null;
1556
+ },
1557
+ <MarkdownEventReferenceElement data-ref-kind="alert" data-ref-number="7">
1558
+ #7
1559
+ </MarkdownEventReferenceElement>,
1560
+ );
1561
+
1562
+ expect(received).toEqual([{ kind: "alert", number: 7, text: "#7" }]);
1563
+ });
1564
+
1565
+ test.each([[""], ["problem"], ["Incident"], [undefined]])(
1566
+ "an unknown kind %p becomes null",
1567
+ (kind: string | undefined) => {
1568
+ const received: Array<MarkdownEventReference> = [];
1569
+
1570
+ renderWith(
1571
+ (reference: MarkdownEventReference): ReactElement | null => {
1572
+ received.push(reference);
1573
+ return null;
1574
+ },
1575
+ <MarkdownEventReferenceElement
1576
+ data-ref-kind={kind}
1577
+ data-ref-number="12"
1578
+ >
1579
+ #12
1580
+ </MarkdownEventReferenceElement>,
1581
+ );
1582
+
1583
+ expect(received).toEqual([{ kind: null, number: 12, text: "#12" }]);
1584
+ },
1585
+ );
1586
+
1587
+ test("keeps leading zeros in the text but parses the number", () => {
1588
+ const received: Array<MarkdownEventReference> = [];
1589
+
1590
+ renderWith(
1591
+ (reference: MarkdownEventReference): ReactElement | null => {
1592
+ received.push(reference);
1593
+ return null;
1594
+ },
1595
+ <MarkdownEventReferenceElement data-ref-kind="" data-ref-number="7">
1596
+ #007
1597
+ </MarkdownEventReferenceElement>,
1598
+ );
1599
+
1600
+ expect(received).toEqual([{ kind: null, number: 7, text: "#007" }]);
1601
+ });
1602
+
1603
+ test.each([["12a"], [""], ["1234567890"], ["-1"], ["1.5"]])(
1604
+ "never calls renderEventReference for the malformed number %p",
1605
+ (referenceNumber: string) => {
1606
+ const renderEventReference: MockFunction = getJestMockFunction();
1607
+
1608
+ const container: HTMLElement = renderWith(
1609
+ renderEventReference as unknown as (
1610
+ reference: MarkdownEventReference,
1611
+ ) => ReactElement | null,
1612
+ <MarkdownEventReferenceElement
1613
+ data-ref-kind="incident"
1614
+ data-ref-number={referenceNumber}
1615
+ >
1616
+ #literal
1617
+ </MarkdownEventReferenceElement>,
1618
+ );
1619
+
1620
+ expect(renderEventReference).not.toHaveBeenCalled();
1621
+ expect(container.textContent).toBe("#literal");
1622
+ },
1623
+ );
1624
+
1625
+ test("falls back to plain text when the callback returns null, is missing, or there is no provider", () => {
1626
+ const nullCallback: HTMLElement = renderWith(
1627
+ (): ReactElement | null => {
1628
+ return null;
1629
+ },
1630
+ <MarkdownEventReferenceElement
1631
+ data-ref-kind="incident"
1632
+ data-ref-number="1"
1633
+ >
1634
+ #1
1635
+ </MarkdownEventReferenceElement>,
1636
+ );
1637
+ expect(nullCallback.innerHTML).toBe("#1");
1638
+ cleanup();
1639
+
1640
+ const missingCallback: HTMLElement = renderWith(
1641
+ undefined,
1642
+ <MarkdownEventReferenceElement
1643
+ data-ref-kind="incident"
1644
+ data-ref-number="2"
1645
+ >
1646
+ #2
1647
+ </MarkdownEventReferenceElement>,
1648
+ );
1649
+ expect(missingCallback.innerHTML).toBe("#2");
1650
+ cleanup();
1651
+
1652
+ const { container } = render(
1653
+ <MarkdownEventReferenceElement
1654
+ data-ref-kind="incident"
1655
+ data-ref-number="3"
1656
+ >
1657
+ #3
1658
+ </MarkdownEventReferenceElement>,
1659
+ );
1660
+ expect(container.innerHTML).toBe("#3");
1661
+ });
1662
+
1663
+ test("renders #number when there are no children", () => {
1664
+ const received: Array<MarkdownEventReference> = [];
1665
+
1666
+ const container: HTMLElement = renderWith(
1667
+ (reference: MarkdownEventReference): ReactElement | null => {
1668
+ received.push(reference);
1669
+ return null;
1670
+ },
1671
+ <MarkdownEventReferenceElement
1672
+ data-ref-kind="alert"
1673
+ data-ref-number={42}
1674
+ />,
1675
+ );
1676
+
1677
+ expect(received).toEqual([{ kind: "alert", number: 42, text: "#42" }]);
1678
+ expect(container.textContent).toBe("#42");
1679
+ });
1680
+ });
1681
+
1682
+ describe("inline reference components map", () => {
1683
+ test("maps exactly the two custom tag names to the module-scope elements", () => {
1684
+ expect(Object.keys(MARKDOWN_INLINE_REFERENCE_COMPONENTS).sort()).toEqual([
1685
+ "oneuptime-citation-ref",
1686
+ "oneuptime-event-ref",
1687
+ ]);
1688
+ expect(
1689
+ MARKDOWN_INLINE_REFERENCE_COMPONENTS[CITATION_REFERENCE_TAG_NAME],
1690
+ ).toBe(MarkdownCitationReferenceElement);
1691
+ expect(MARKDOWN_INLINE_REFERENCE_COMPONENTS[EVENT_REFERENCE_TAG_NAME]).toBe(
1692
+ MarkdownEventReferenceElement,
1693
+ );
1694
+ });
1695
+ });
1696
+
1697
+ /*
1698
+ * ---------------------------------------------------------------------------
1699
+ * MarkdownViewer wiring
1700
+ * ---------------------------------------------------------------------------
1701
+ */
1702
+
1703
+ const EXISTING_COMPONENT_KEYS: Array<string> = [
1704
+ "a",
1705
+ "blockquote",
1706
+ "code",
1707
+ "h1",
1708
+ "h2",
1709
+ "h3",
1710
+ "h4",
1711
+ "h5",
1712
+ "h6",
1713
+ "hr",
1714
+ "img",
1715
+ "li",
1716
+ "ol",
1717
+ "p",
1718
+ "pre",
1719
+ "strong",
1720
+ "table",
1721
+ "tbody",
1722
+ "td",
1723
+ "th",
1724
+ "thead",
1725
+ "tr",
1726
+ "ul",
1727
+ ];
1728
+
1729
+ function lastMarkdownProps(): MockReactMarkdownProps {
1730
+ const props: MockReactMarkdownProps | undefined =
1731
+ mockMarkdownState.calls[mockMarkdownState.calls.length - 1];
1732
+ if (!props) {
1733
+ throw new Error("react-markdown was not rendered");
1734
+ }
1735
+ return props;
1736
+ }
1737
+
1738
+ const INCIDENT_REPORT_TREE: Node = root(
1739
+ paragraph(
1740
+ { type: "strong", children: [text("Summary")] },
1741
+ text(" — pool ran dry [C4][C5], same as incident #6954 and "),
1742
+ {
1743
+ type: "link",
1744
+ url: "https://evil.example/#12",
1745
+ children: [text("incident #12 [C4]")],
1746
+ },
1747
+ text(". Unknown [C99]."),
1748
+ ),
1749
+ );
1750
+
1751
+ const renderers: () => MarkdownInlineReferenceRenderers =
1752
+ (): MarkdownInlineReferenceRenderers => {
1753
+ return {
1754
+ renderCitation: (citationId: string): ReactElement | null => {
1755
+ if (citationId === "C99") {
1756
+ return null;
1757
+ }
1758
+ return (
1759
+ <button type="button" aria-label={`Citation ${citationId}`}>
1760
+ {citationId}
1761
+ </button>
1762
+ );
1763
+ },
1764
+ renderEventReference: (
1765
+ reference: MarkdownEventReference,
1766
+ ): ReactElement | null => {
1767
+ return (
1768
+ <span
1769
+ data-testid="event-reference"
1770
+ data-kind={reference.kind ?? "none"}
1771
+ data-number={reference.number}
1772
+ >
1773
+ {reference.text}
1774
+ </span>
1775
+ );
1776
+ },
1777
+ };
1778
+ };
1779
+
1780
+ describe("MarkdownViewer inlineReferences wiring", () => {
1781
+ beforeEach(() => {
1782
+ mockMarkdownState.calls = [];
1783
+ });
1784
+
1785
+ test("without inlineReferences: only remark-gfm, the existing components, today's DOM", () => {
1786
+ const { container } = render(
1787
+ <MarkdownViewer text="Same as #6954 [C1]" safeMode={true} />,
1788
+ );
1789
+
1790
+ const props: MockReactMarkdownProps = lastMarkdownProps();
1791
+ expect(props.remarkPlugins).toEqual([remarkGfm]);
1792
+ expect(props.remarkPlugins?.[0]).toBe(remarkGfm);
1793
+ expect(Object.keys(props.components || {}).sort()).toEqual(
1794
+ EXISTING_COMPONENT_KEYS,
1795
+ );
1796
+ expect(container.innerHTML).toBe(
1797
+ '<div class="max-w-none"><div data-testid="react-markdown">Same as #6954 [C1]</div></div>',
1798
+ );
1799
+ });
1800
+
1801
+ test("without inlineReferences a tree never gains reference elements", () => {
1802
+ mockMarkdownState.tree = INCIDENT_REPORT_TREE;
1803
+ const { container } = render(
1804
+ <MarkdownViewer text="ignored" safeMode={true} />,
1805
+ );
1806
+
1807
+ expect(screen.queryAllByRole("button")).toHaveLength(0);
1808
+ expect(screen.queryByTestId("event-reference")).toBeNull();
1809
+ expect(container.textContent).toContain(
1810
+ "pool ran dry [C4][C5], same as incident #6954",
1811
+ );
1812
+ });
1813
+
1814
+ test("with inlineReferences: adds the plugin with both passes and registers the two elements", () => {
1815
+ render(
1816
+ <MarkdownViewer
1817
+ text="x"
1818
+ safeMode={true}
1819
+ inlineReferences={renderers()}
1820
+ />,
1821
+ );
1822
+
1823
+ const props: MockReactMarkdownProps = lastMarkdownProps();
1824
+ expect(props.remarkPlugins).toHaveLength(2);
1825
+ expect(props.remarkPlugins?.[0]).toBe(remarkGfm);
1826
+ expect(props.remarkPlugins?.[1]).toEqual([
1827
+ remarkInlineReferences,
1828
+ { citations: true, eventReferences: true },
1829
+ ]);
1830
+
1831
+ const components: MockComponentMap = props.components || {};
1832
+ expect(Object.keys(components).sort()).toEqual(
1833
+ [
1834
+ ...EXISTING_COMPONENT_KEYS,
1835
+ CITATION_REFERENCE_TAG_NAME,
1836
+ EVENT_REFERENCE_TAG_NAME,
1837
+ ].sort(),
1838
+ );
1839
+ expect(components[CITATION_REFERENCE_TAG_NAME]).toBe(
1840
+ MarkdownCitationReferenceElement,
1841
+ );
1842
+ expect(components[EVENT_REFERENCE_TAG_NAME]).toBe(
1843
+ MarkdownEventReferenceElement,
1844
+ );
1845
+ });
1846
+
1847
+ test("renders citation chips and reference links through the real plugin, elements and context", () => {
1848
+ mockMarkdownState.tree = INCIDENT_REPORT_TREE;
1849
+
1850
+ const { container } = render(
1851
+ <MarkdownViewer
1852
+ text="ignored"
1853
+ safeMode={true}
1854
+ inlineReferences={renderers()}
1855
+ />,
1856
+ );
1857
+
1858
+ expect(
1859
+ screen.getAllByRole("button").map((button: HTMLElement): string => {
1860
+ return button.getAttribute("aria-label") || "";
1861
+ }),
1862
+ ).toEqual(["Citation C4", "Citation C5"]);
1863
+
1864
+ const references: Array<HTMLElement> =
1865
+ screen.getAllByTestId("event-reference");
1866
+ expect(references).toHaveLength(1);
1867
+ expect(references[0]).toHaveAttribute("data-kind", "incident");
1868
+ expect(references[0]).toHaveAttribute("data-number", "6954");
1869
+
1870
+ // A citation the callback declines stays plain text.
1871
+ expect(container.textContent).toContain("Unknown [C99].");
1872
+
1873
+ /*
1874
+ * The model-authored link is still neutralized by the safe `a` renderer,
1875
+ * its text is never split, and nothing interactive nests inside it.
1876
+ */
1877
+ expect(container.querySelector("a")).toBeNull();
1878
+ const neutralized: Element | null = container.querySelector(
1879
+ "span.decoration-dotted",
1880
+ );
1881
+ expect(neutralized).not.toBeNull();
1882
+ expect(neutralized?.textContent).toBe("incident #12 [C4]");
1883
+ expect(neutralized?.querySelector("button, [data-testid]")).toBeNull();
1884
+ });
1885
+
1886
+ test("citations cannot be turned into links with a definition", () => {
1887
+ mockMarkdownState.tree = root(
1888
+ paragraph(text("see "), linkReference("c4", [text("C4")])),
1889
+ { type: "definition", identifier: "c4", url: "https://evil.example" },
1890
+ );
1891
+
1892
+ const { container } = render(
1893
+ <MarkdownViewer
1894
+ text="ignored"
1895
+ safeMode={true}
1896
+ inlineReferences={renderers()}
1897
+ />,
1898
+ );
1899
+
1900
+ expect(container.querySelector("a")).toBeNull();
1901
+ expect(screen.getByRole("button", { name: "Citation C4" })).toBeVisible();
1902
+ });
1903
+
1904
+ test("safeMode neutralization of images still applies with inlineReferences", () => {
1905
+ mockMarkdownState.tree = root(
1906
+ paragraph(text("[C4] "), {
1907
+ type: "image",
1908
+ url: "https://evil.example/p.png",
1909
+ alt: "pixel",
1910
+ }),
1911
+ );
1912
+
1913
+ const { container } = render(
1914
+ <MarkdownViewer
1915
+ text="ignored"
1916
+ safeMode={true}
1917
+ inlineReferences={renderers()}
1918
+ />,
1919
+ );
1920
+
1921
+ expect(container.querySelector("img")).toBeNull();
1922
+ expect(container.textContent).toContain("[image: pixel]");
1923
+ });
1924
+
1925
+ test("new renderer callbacks flow through context without remounting the elements", () => {
1926
+ mockMarkdownState.tree = root(paragraph(text("see [C4]")));
1927
+ let mounts: number = 0;
1928
+
1929
+ const CountingChip: React.FunctionComponent<{ label: string }> = (props: {
1930
+ label: string;
1931
+ }): ReactElement => {
1932
+ const [mountedLabel] = useState<string>(props.label);
1933
+ useEffect(() => {
1934
+ mounts += 1;
1935
+ }, []);
1936
+ return (
1937
+ <button type="button" data-first-label={mountedLabel}>
1938
+ {props.label}
1939
+ </button>
1940
+ );
1941
+ };
1942
+
1943
+ const makeRenderers: (label: string) => MarkdownInlineReferenceRenderers = (
1944
+ label: string,
1945
+ ): MarkdownInlineReferenceRenderers => {
1946
+ return {
1947
+ renderCitation: (citationId: string): ReactElement => {
1948
+ return <CountingChip label={`${label} ${citationId}`} />;
1949
+ },
1950
+ };
1951
+ };
1952
+
1953
+ const { rerender } = render(
1954
+ <MarkdownViewer
1955
+ text="ignored"
1956
+ safeMode={true}
1957
+ inlineReferences={makeRenderers("first")}
1958
+ />,
1959
+ );
1960
+
1961
+ expect(screen.getByRole("button")).toHaveTextContent("first C4");
1962
+
1963
+ rerender(
1964
+ <MarkdownViewer
1965
+ text="ignored"
1966
+ safeMode={true}
1967
+ inlineReferences={makeRenderers("second")}
1968
+ />,
1969
+ );
1970
+
1971
+ const button: HTMLElement = screen.getByRole("button");
1972
+ expect(button).toHaveTextContent("second C4");
1973
+ // Same instance: its first-render state survived the re-render.
1974
+ expect(button).toHaveAttribute("data-first-label", "first C4");
1975
+ expect(mounts).toBe(1);
1976
+ });
1977
+
1978
+ test("the components map keeps its identity across re-renders and changes only with its options", () => {
1979
+ const { rerender } = render(<MarkdownViewer text="one" safeMode={true} />);
1980
+ rerender(<MarkdownViewer text="two" safeMode={true} />);
1981
+
1982
+ const [first, second] = mockMarkdownState.calls;
1983
+ expect(second?.components).toBe(first?.components);
1984
+
1985
+ rerender(<MarkdownViewer text="two" safeMode={false} />);
1986
+ const unsafe: MockComponentMap | undefined = lastMarkdownProps().components;
1987
+ expect(unsafe).not.toBe(first?.components);
1988
+
1989
+ rerender(
1990
+ <MarkdownViewer
1991
+ text="two"
1992
+ safeMode={false}
1993
+ inlineReferences={renderers()}
1994
+ />,
1995
+ );
1996
+ const withReferences: MockComponentMap | undefined =
1997
+ lastMarkdownProps().components;
1998
+ expect(withReferences).not.toBe(unsafe);
1999
+
2000
+ // New callback objects alone do not rebuild the map.
2001
+ rerender(
2002
+ <MarkdownViewer
2003
+ text="three"
2004
+ safeMode={false}
2005
+ inlineReferences={renderers()}
2006
+ />,
2007
+ );
2008
+ expect(lastMarkdownProps().components).toBe(withReferences);
2009
+ });
2010
+
2011
+ test("safeMode still neutralizes links in the memoized map, and unsafe mode still renders them", () => {
2012
+ mockMarkdownState.tree = root(
2013
+ paragraph({
2014
+ type: "link",
2015
+ url: "https://example.com/docs",
2016
+ children: [text("docs")],
2017
+ }),
2018
+ );
2019
+
2020
+ const { container, rerender } = render(
2021
+ <MarkdownViewer text="ignored" safeMode={true} />,
2022
+ );
2023
+ expect(container.querySelector("a")).toBeNull();
2024
+ expect(container.textContent).toBe("docs");
2025
+
2026
+ rerender(<MarkdownViewer text="ignored" safeMode={false} />);
2027
+ expect(container.querySelector("a")).toHaveAttribute(
2028
+ "href",
2029
+ "https://example.com/docs",
2030
+ );
2031
+ });
2032
+
2033
+ test("dropping inlineReferences on a re-render removes the plugin again", () => {
2034
+ mockMarkdownState.tree = root(paragraph(text("see [C4]")));
2035
+
2036
+ const { rerender, container } = render(
2037
+ <MarkdownViewer
2038
+ text="ignored"
2039
+ safeMode={true}
2040
+ inlineReferences={renderers()}
2041
+ />,
2042
+ );
2043
+ expect(screen.getByRole("button")).toBeVisible();
2044
+
2045
+ rerender(<MarkdownViewer text="ignored" safeMode={true} />);
2046
+
2047
+ expect(lastMarkdownProps().remarkPlugins).toEqual([remarkGfm]);
2048
+ expect(screen.queryByRole("button")).toBeNull();
2049
+ expect(container.textContent).toBe("see [C4]");
2050
+ });
2051
+
2052
+ test("LazyMarkdownViewer forwards inlineReferences to the viewer", async () => {
2053
+ mockMarkdownState.tree = root(paragraph(text("alert #9 [C1]")));
2054
+
2055
+ await act(async () => {
2056
+ render(
2057
+ <LazyMarkdownViewer
2058
+ text="ignored"
2059
+ safeMode={true}
2060
+ inlineReferences={renderers()}
2061
+ />,
2062
+ );
2063
+ });
2064
+
2065
+ await waitFor(() => {
2066
+ expect(screen.getByTestId("react-markdown")).toBeInTheDocument();
2067
+ });
2068
+
2069
+ expect(lastMarkdownProps().remarkPlugins?.[1]).toEqual([
2070
+ remarkInlineReferences,
2071
+ { citations: true, eventReferences: true },
2072
+ ]);
2073
+ expect(screen.getByRole("button", { name: "Citation C1" })).toBeVisible();
2074
+ expect(screen.getByTestId("event-reference")).toHaveAttribute(
2075
+ "data-kind",
2076
+ "alert",
2077
+ );
2078
+ });
2079
+ });