@oneuptime/common 12.0.28 → 12.0.30

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 (367) hide show
  1. package/Models/DatabaseModels/DashboardDomain.ts +43 -0
  2. package/Models/DatabaseModels/Index.ts +11 -0
  3. package/Models/DatabaseModels/MonitorTemplate.ts +15 -3
  4. package/Models/DatabaseModels/OnCallDutyPolicySchedule.ts +43 -0
  5. package/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.ts +662 -0
  6. package/Models/DatabaseModels/ProjectOnCallCalendarFeed.ts +584 -0
  7. package/Models/DatabaseModels/StatusPageDomain.ts +43 -0
  8. package/Models/DatabaseModels/UserOnCallCalendarFeed.ts +546 -0
  9. package/Models/DatabaseModels/UserOnCallShiftReminder.ts +231 -0
  10. package/Models/DatabaseModels/UserOnCallShiftReminderLog.ts +331 -0
  11. package/Server/API/DashboardDomainAPI.ts +74 -0
  12. package/Server/API/MicrosoftTeamsAPI.ts +81 -180
  13. package/Server/API/OnCallCalendarAPI.ts +2194 -0
  14. package/Server/API/StatusPageDomainAPI.ts +74 -0
  15. package/Server/EnvironmentConfig.ts +138 -0
  16. package/Server/Infrastructure/OnCallCalendarFeedCache.ts +1050 -0
  17. package/Server/Infrastructure/Postgres/SchemaMigrations/1790200000000-AllowNullMonitorNameOnMonitorTemplate.ts +43 -0
  18. package/Server/Infrastructure/Postgres/SchemaMigrations/1790300000000-AddCertificateReissueRequestedAtToDomains.ts +40 -0
  19. package/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.ts +253 -0
  20. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
  21. package/Server/Middleware/OnCallCalendarFeedRateLimit.ts +487 -0
  22. package/Server/Middleware/ProjectAuthorization.ts +6 -1
  23. package/Server/Services/DashboardDomainService.ts +131 -0
  24. package/Server/Services/Index.ts +12 -0
  25. package/Server/Services/LogPipelineProcessorService.ts +88 -0
  26. package/Server/Services/MonitorTemplateService.ts +70 -11
  27. package/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts +32 -0
  28. package/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.ts +260 -0
  29. package/Server/Services/OnCallDutyPolicyScheduleLayerService.ts +70 -3
  30. package/Server/Services/OnCallDutyPolicyScheduleLayerUserService.ts +138 -3
  31. package/Server/Services/OnCallDutyPolicyScheduleService.ts +1465 -134
  32. package/Server/Services/OnCallDutyPolicyUserOverrideService.ts +167 -31
  33. package/Server/Services/ProjectOnCallCalendarFeedService.ts +192 -0
  34. package/Server/Services/StatusPageDomainService.ts +163 -3
  35. package/Server/Services/StatusPagePrivateUserSessionService.ts +197 -56
  36. package/Server/Services/TeamMemberService.ts +489 -1
  37. package/Server/Services/TeamService.ts +50 -0
  38. package/Server/Services/UserNotificationSettingService.ts +44 -1
  39. package/Server/Services/UserOnCallCalendarFeedService.ts +159 -0
  40. package/Server/Services/UserOnCallShiftReminderLogService.ts +151 -0
  41. package/Server/Services/UserOnCallShiftReminderService.ts +112 -0
  42. package/Server/Types/Domain.ts +17 -0
  43. package/Server/Utils/APIKey/AccessPermission.ts +24 -0
  44. package/Server/Utils/Greenlock/Greenlock.ts +156 -58
  45. package/Server/Utils/LogPipelineProcessorValidation.ts +112 -0
  46. package/Server/Utils/OnCall/CalendarFeedToken.ts +241 -0
  47. package/Server/Utils/OnCall/OnCallCalendarFeedRenderer.ts +1488 -0
  48. package/Server/Utils/OnCall/OnCallCalendarFeedUrls.ts +230 -0
  49. package/Server/Utils/OnCall/OnCallShiftChangeListeners.ts +227 -0
  50. package/Server/Utils/OnCall/OnCallShiftMaterializer.ts +1127 -0
  51. package/Server/Utils/OnCall/OnCallShiftReminderListener.ts +174 -0
  52. package/Server/Utils/OnCall/OnCallShiftReminderRunner.ts +2584 -0
  53. package/Server/Utils/Response.ts +134 -0
  54. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.ts +1094 -45
  55. package/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.ts +153 -17
  56. package/Server/Utils/StartServer.ts +10 -0
  57. package/Server/Utils/Telemetry/AppMetrics.ts +51 -0
  58. package/Server/Utils/Workspace/MicrosoftTeams/Actions/Alert.ts +23 -11
  59. package/Server/Utils/Workspace/MicrosoftTeams/Actions/Auth.ts +0 -170
  60. package/Server/Utils/Workspace/MicrosoftTeams/Actions/Authorization.ts +158 -0
  61. package/Server/Utils/Workspace/MicrosoftTeams/Actions/Incident.ts +23 -11
  62. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +35 -13
  63. package/Tests/App/Dashboard/MonitorTemplateColumnAndFacet.test.tsx +505 -0
  64. package/Tests/App/Dashboard/OnCallCalendarFeedLinks.test.tsx +229 -0
  65. package/Tests/App/Dashboard/OnCallCalendarFeedPlanGate.test.tsx +489 -0
  66. package/Tests/App/Dashboard/OnCallCalendarFeedSideMenus.test.tsx +149 -0
  67. package/Tests/App/Dashboard/OnCallCalendarFeedUtil.test.ts +855 -0
  68. package/Tests/App/Dashboard/OnCallPersonalCalendarFeed.test.tsx +1209 -0
  69. package/Tests/App/Dashboard/OnCallSharedCalendarFeedCard.test.tsx +1019 -0
  70. package/Tests/App/Dashboard/OnCallShiftRemindersAndUpcomingShifts.test.tsx +655 -0
  71. package/Tests/App/Dashboard/UserSettingsSetupChecklistModel.test.ts +73 -0
  72. package/Tests/App/StatusPage/StatusPageLoginCodeBootstrap.test.ts +106 -0
  73. package/Tests/App/StatusPage/StatusPageLoginCodeUtil.test.ts +84 -0
  74. package/Tests/App/StatusPage/StatusPageRedirectSafety.test.ts +119 -0
  75. package/Tests/Models/MonitorTemplateMonitorNameColumn.test.ts +258 -0
  76. package/Tests/Models/OnCallCalendarFeedModels.test.ts +642 -0
  77. package/Tests/Models/OnCallDutyPolicyScheduleCalendarFeed.test.ts +288 -0
  78. package/Tests/Models/OnCallDutyPolicyScheduleShiftConfigVersion.test.ts +88 -0
  79. package/Tests/Models/UserOnCallShiftReminderModels.test.ts +368 -0
  80. package/Tests/Server/API/CustomDomainReissueSslAPI.test.ts +469 -0
  81. package/Tests/Server/API/Helpers.ts +8 -0
  82. package/Tests/Server/API/MicrosoftTeamsBotMessagesEndpoint.test.ts +729 -0
  83. package/Tests/Server/API/MicrosoftTeamsBotTestEndpoint.test.ts +26 -0
  84. package/Tests/Server/API/MicrosoftTeamsLegacyWebhookRemoval.test.ts +402 -0
  85. package/Tests/Server/API/OnCallCalendarAPI.test.ts +4461 -0
  86. package/Tests/Server/EnvironmentConfigOnCallCalendarFeed.test.ts +357 -0
  87. package/Tests/Server/Infrastructure/OnCallCalendarFeedCache.test.ts +1589 -0
  88. package/Tests/Server/Infrastructure/Postgres/AddOnCallCalendarFeedsMigration.test.ts +369 -0
  89. package/Tests/Server/Middleware/OnCallCalendarFeedRateLimit.test.ts +1365 -0
  90. package/Tests/Server/Middleware/ProjectAuthorizationApiKeyMiddleware.test.ts +4 -0
  91. package/Tests/Server/Services/AddCertificateReissueRequestedAtToDomainsMigration.test.ts +287 -0
  92. package/Tests/Server/Services/CustomDomainCertificateReissue.test.ts +477 -0
  93. package/Tests/Server/Services/FeedRetentionConsistency.test.ts +70 -0
  94. package/Tests/Server/Services/LogPipelineProcessorSaveValidation.test.ts +249 -0
  95. package/Tests/Server/Services/MonitorTemplateServiceBulkSync.test.ts +549 -0
  96. package/Tests/Server/Services/MonitorTemplateServiceNetworkDeviceSync.test.ts +16 -3
  97. package/Tests/Server/Services/NetworkDeviceAutoImportRuleEngineService.test.ts +57 -0
  98. package/Tests/Server/Services/OnCallCalendarFeedServices.test.ts +1103 -0
  99. package/Tests/Server/Services/OnCallDutyPolicyScheduleResolver.test.ts +1037 -0
  100. package/Tests/Server/Services/OnCallShiftConfigPropagation.test.ts +1270 -0
  101. package/Tests/Server/Services/SecurityEventLastErrorColumnWidth.test.ts +151 -15
  102. package/Tests/Server/Services/StatusPagePrivateUserSessionService.test.ts +587 -0
  103. package/Tests/Server/Services/TeamDeleteMemberCleanup.test.ts +156 -0
  104. package/Tests/Server/Services/TeamMemberOnCallCleanup.test.ts +755 -0
  105. package/Tests/Server/Services/UserNotificationSettingShiftReminderDefaults.test.ts +267 -0
  106. package/Tests/Server/Services/UserOnCallShiftReminderServices.test.ts +583 -0
  107. package/Tests/Server/Types/Database/Permissions/ApiKeyFileAccess.test.ts +286 -0
  108. package/Tests/Server/Types/Database/Permissions/MonitorTemplateColumnAccess.test.ts +328 -0
  109. package/Tests/Server/Types/Database/Permissions/OnCallCalendarFeedPermissions.test.ts +254 -0
  110. package/Tests/Server/Types/Database/QueryHelperFindWithSameTextAndIsNull.test.ts +83 -0
  111. package/Tests/Server/Utils/AI/SRE/ConfidenceSignal.test.ts +377 -0
  112. package/Tests/Server/Utils/APIKey/AccessPermission.test.ts +16 -1
  113. package/Tests/Server/Utils/Greenlock/CertificateRenewalSchedule.test.ts +250 -0
  114. package/Tests/Server/Utils/LogPipelineProcessorValidation.test.ts +198 -0
  115. package/Tests/Server/Utils/OnCall/CalendarFeedToken.test.ts +467 -0
  116. package/Tests/Server/Utils/OnCall/OnCallCalendarFeedRenderer.test.ts +2142 -0
  117. package/Tests/Server/Utils/OnCall/OnCallCalendarFeedUrls.test.ts +278 -0
  118. package/Tests/Server/Utils/OnCall/OnCallResolverTestHarness.ts +440 -0
  119. package/Tests/Server/Utils/OnCall/OnCallShiftChangeListeners.test.ts +314 -0
  120. package/Tests/Server/Utils/OnCall/OnCallShiftMaterializer.test.ts +1502 -0
  121. package/Tests/Server/Utils/OnCall/OnCallShiftReminderListener.test.ts +491 -0
  122. package/Tests/Server/Utils/OnCall/OnCallShiftReminderRunner.test.ts +3088 -0
  123. package/Tests/Server/Utils/OnCall/OnCallShiftReminderTestHarness.ts +910 -0
  124. package/Tests/Server/Utils/ResponseSendCalendarResponse.test.ts +561 -0
  125. package/Tests/Server/Utils/SecurityEvent/ConnectorErrorMessage.test.ts +48 -9
  126. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsAuth.test.ts +726 -0
  127. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsClient.test.ts +74 -11
  128. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsErrorHandling.test.ts +1107 -0
  129. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPoller.test.ts +20 -3
  130. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPollerFailureTaxonomy.test.ts +51 -11
  131. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsPollerHardening.test.ts +1246 -0
  132. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsRequestContract.test.ts +961 -0
  133. package/Tests/Server/Utils/SecurityEvent/GoogleSecOpsResponseParsing.test.ts +653 -0
  134. package/Tests/Server/Utils/StartServerEncryptionSecretWarning.test.ts +64 -0
  135. package/Tests/Server/Utils/Telemetry/AppMetrics.test.ts +29 -0
  136. package/Tests/Server/Utils/Workspace/MicrosoftTeamsActionAuthorization.test.ts +880 -0
  137. package/Tests/Types/API/HTTPResponse.test.ts +175 -0
  138. package/Tests/Types/API/Route.test.ts +36 -4
  139. package/Tests/Types/Calendar/ICalendar.test.ts +488 -0
  140. package/Tests/Types/Database/DatabaseProperty.test.ts +171 -0
  141. package/Tests/Types/DateLocalShortDateTimeString.test.ts +518 -0
  142. package/Tests/Types/DateLocalTimeString.test.ts +259 -0
  143. package/Tests/Types/DateUserPrefers12HourFormat.test.ts +316 -0
  144. package/Tests/Types/NotificationSetting/NotificationSettingEventType.test.ts +53 -0
  145. package/Tests/Types/OnCallDutyPolicy/CalendarFeedTestFixtures.ts +310 -0
  146. package/Tests/Types/OnCallDutyPolicy/CalendarFeedWindow.test.ts +205 -0
  147. package/Tests/Types/OnCallDutyPolicy/LayerUtilLayerMetaAndIterationCap.test.ts +458 -0
  148. package/Tests/Types/OnCallDutyPolicy/MaterializedShift.test.ts +197 -0
  149. package/Tests/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.test.ts +1986 -0
  150. package/Tests/Types/OnCallDutyPolicy/ScheduleShiftUtilGroupKey.test.ts +678 -0
  151. package/Tests/Types/OnCallDutyPolicy/ShiftSeamUtil.test.ts +417 -0
  152. package/Tests/UI/Components/LogsHistogram.test.tsx +41 -2
  153. package/Tests/UI/Components/LogsViewerEmptyStateTimeRange.test.tsx +212 -0
  154. package/Tests/UI/Components/TelemetryChartClockFormat.test.tsx +359 -0
  155. package/Tests/UI/Components/TimeRangePickerClockFormat.test.tsx +422 -0
  156. package/Tests/UI/Components/TimeRangePickerDropdown.test.tsx +146 -8
  157. package/Tests/UI/MicrosoftTeams/MicrosoftTeamsMessagingEndpointGuidance.test.tsx +520 -0
  158. package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +10 -0
  159. package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +2 -0
  160. package/Tests/UI/Utils/Navigation.test.ts +82 -0
  161. package/Tests/Utils/Array.test.ts +100 -0
  162. package/Tests/Utils/CertificateReissue.test.ts +225 -0
  163. package/Tests/Utils/Grok/Grok.test.ts +492 -0
  164. package/Tests/Utils/Monitor/NetworkDeviceMonitorTemplateUtil.test.ts +181 -13
  165. package/Types/API/Route.ts +20 -5
  166. package/Types/Calendar/ICalendar.ts +442 -0
  167. package/Types/Date.ts +143 -13
  168. package/Types/Email/EmailTemplateType.ts +2 -0
  169. package/Types/NotificationSetting/NotificationSettingEventType.ts +4 -0
  170. package/Types/OnCallDutyPolicy/CalendarFeedWindow.ts +140 -0
  171. package/Types/OnCallDutyPolicy/Layer.ts +190 -35
  172. package/Types/OnCallDutyPolicy/MaterializedShift.ts +274 -0
  173. package/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.ts +1415 -0
  174. package/Types/OnCallDutyPolicy/ScheduleShiftUtil.ts +159 -4
  175. package/Types/OnCallDutyPolicy/ShiftSeamUtil.ts +106 -0
  176. package/Types/Rum/SessionReplay.ts +62 -1
  177. package/UI/Components/Date/TimeRangePickerDropdown.tsx +9 -5
  178. package/UI/Components/LogsViewer/LogsViewer.tsx +12 -7
  179. package/UI/Components/LogsViewer/components/HistogramTooltip.tsx +18 -17
  180. package/UI/Components/LogsViewer/components/LogsAnalyticsView.tsx +21 -28
  181. package/UI/Components/LogsViewer/components/LogsHistogram.tsx +2 -4
  182. package/UI/Components/TelemetryViewer/components/TelemetryHistogram.tsx +2 -4
  183. package/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.tsx +17 -16
  184. package/UI/Utils/Navigation.ts +42 -0
  185. package/Utils/Array.ts +37 -0
  186. package/Utils/CertificateReissue.ts +128 -0
  187. package/Utils/Grok/Grok.ts +461 -0
  188. package/Utils/Grok/GrokPatterns.ts +118 -0
  189. package/Utils/Monitor/NetworkDeviceMonitorTemplateUtil.ts +58 -6
  190. package/build/dist/Models/DatabaseModels/DashboardDomain.js +44 -0
  191. package/build/dist/Models/DatabaseModels/DashboardDomain.js.map +1 -1
  192. package/build/dist/Models/DatabaseModels/Index.js +11 -0
  193. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  194. package/build/dist/Models/DatabaseModels/MonitorTemplate.js +17 -4
  195. package/build/dist/Models/DatabaseModels/MonitorTemplate.js.map +1 -1
  196. package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js +44 -0
  197. package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js.map +1 -1
  198. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.js +699 -0
  199. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleCalendarFeed.js.map +1 -0
  200. package/build/dist/Models/DatabaseModels/ProjectOnCallCalendarFeed.js +620 -0
  201. package/build/dist/Models/DatabaseModels/ProjectOnCallCalendarFeed.js.map +1 -0
  202. package/build/dist/Models/DatabaseModels/StatusPageDomain.js +44 -0
  203. package/build/dist/Models/DatabaseModels/StatusPageDomain.js.map +1 -1
  204. package/build/dist/Models/DatabaseModels/UserOnCallCalendarFeed.js +585 -0
  205. package/build/dist/Models/DatabaseModels/UserOnCallCalendarFeed.js.map +1 -0
  206. package/build/dist/Models/DatabaseModels/UserOnCallShiftReminder.js +247 -0
  207. package/build/dist/Models/DatabaseModels/UserOnCallShiftReminder.js.map +1 -0
  208. package/build/dist/Models/DatabaseModels/UserOnCallShiftReminderLog.js +355 -0
  209. package/build/dist/Models/DatabaseModels/UserOnCallShiftReminderLog.js.map +1 -0
  210. package/build/dist/Server/API/DashboardDomainAPI.js +43 -1
  211. package/build/dist/Server/API/DashboardDomainAPI.js.map +1 -1
  212. package/build/dist/Server/API/MicrosoftTeamsAPI.js +74 -118
  213. package/build/dist/Server/API/MicrosoftTeamsAPI.js.map +1 -1
  214. package/build/dist/Server/API/OnCallCalendarAPI.js +1371 -0
  215. package/build/dist/Server/API/OnCallCalendarAPI.js.map +1 -0
  216. package/build/dist/Server/API/StatusPageDomainAPI.js +43 -1
  217. package/build/dist/Server/API/StatusPageDomainAPI.js.map +1 -1
  218. package/build/dist/Server/EnvironmentConfig.js +102 -0
  219. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  220. package/build/dist/Server/Infrastructure/OnCallCalendarFeedCache.js +663 -0
  221. package/build/dist/Server/Infrastructure/OnCallCalendarFeedCache.js.map +1 -0
  222. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790200000000-AllowNullMonitorNameOnMonitorTemplate.js +34 -0
  223. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790200000000-AllowNullMonitorNameOnMonitorTemplate.js.map +1 -0
  224. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790300000000-AddCertificateReissueRequestedAtToDomains.js +28 -0
  225. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790300000000-AddCertificateReissueRequestedAtToDomains.js.map +1 -0
  226. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.js +103 -0
  227. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1790400000000-AddOnCallCalendarFeeds.js.map +1 -0
  228. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
  229. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  230. package/build/dist/Server/Middleware/OnCallCalendarFeedRateLimit.js +342 -0
  231. package/build/dist/Server/Middleware/OnCallCalendarFeedRateLimit.js.map +1 -0
  232. package/build/dist/Server/Middleware/ProjectAuthorization.js +6 -1
  233. package/build/dist/Server/Middleware/ProjectAuthorization.js.map +1 -1
  234. package/build/dist/Server/Services/DashboardDomainService.js +104 -0
  235. package/build/dist/Server/Services/DashboardDomainService.js.map +1 -1
  236. package/build/dist/Server/Services/Index.js +12 -0
  237. package/build/dist/Server/Services/Index.js.map +1 -1
  238. package/build/dist/Server/Services/LogPipelineProcessorService.js +65 -0
  239. package/build/dist/Server/Services/LogPipelineProcessorService.js.map +1 -1
  240. package/build/dist/Server/Services/MonitorTemplateService.js +57 -11
  241. package/build/dist/Server/Services/MonitorTemplateService.js.map +1 -1
  242. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js +20 -0
  243. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js.map +1 -1
  244. package/build/dist/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.js +219 -0
  245. package/build/dist/Server/Services/OnCallDutyPolicyScheduleCalendarFeedService.js.map +1 -0
  246. package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerService.js +47 -3
  247. package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerService.js.map +1 -1
  248. package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js +112 -3
  249. package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js.map +1 -1
  250. package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +955 -9
  251. package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
  252. package/build/dist/Server/Services/OnCallDutyPolicyUserOverrideService.js +93 -6
  253. package/build/dist/Server/Services/OnCallDutyPolicyUserOverrideService.js.map +1 -1
  254. package/build/dist/Server/Services/ProjectOnCallCalendarFeedService.js +157 -0
  255. package/build/dist/Server/Services/ProjectOnCallCalendarFeedService.js.map +1 -0
  256. package/build/dist/Server/Services/StatusPageDomainService.js +132 -3
  257. package/build/dist/Server/Services/StatusPageDomainService.js.map +1 -1
  258. package/build/dist/Server/Services/StatusPagePrivateUserSessionService.js +112 -32
  259. package/build/dist/Server/Services/StatusPagePrivateUserSessionService.js.map +1 -1
  260. package/build/dist/Server/Services/TeamMemberService.js +396 -1
  261. package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
  262. package/build/dist/Server/Services/TeamService.js +43 -0
  263. package/build/dist/Server/Services/TeamService.js.map +1 -1
  264. package/build/dist/Server/Services/UserNotificationSettingService.js +26 -1
  265. package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
  266. package/build/dist/Server/Services/UserOnCallCalendarFeedService.js +140 -0
  267. package/build/dist/Server/Services/UserOnCallCalendarFeedService.js.map +1 -0
  268. package/build/dist/Server/Services/UserOnCallShiftReminderLogService.js +116 -0
  269. package/build/dist/Server/Services/UserOnCallShiftReminderLogService.js.map +1 -0
  270. package/build/dist/Server/Services/UserOnCallShiftReminderService.js +92 -0
  271. package/build/dist/Server/Services/UserOnCallShiftReminderService.js.map +1 -0
  272. package/build/dist/Server/Types/Domain.js +16 -0
  273. package/build/dist/Server/Types/Domain.js.map +1 -1
  274. package/build/dist/Server/Utils/APIKey/AccessPermission.js +24 -0
  275. package/build/dist/Server/Utils/APIKey/AccessPermission.js.map +1 -1
  276. package/build/dist/Server/Utils/Greenlock/Greenlock.js +110 -35
  277. package/build/dist/Server/Utils/Greenlock/Greenlock.js.map +1 -1
  278. package/build/dist/Server/Utils/LogPipelineProcessorValidation.js +77 -0
  279. package/build/dist/Server/Utils/LogPipelineProcessorValidation.js.map +1 -0
  280. package/build/dist/Server/Utils/OnCall/CalendarFeedToken.js +161 -0
  281. package/build/dist/Server/Utils/OnCall/CalendarFeedToken.js.map +1 -0
  282. package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedRenderer.js +983 -0
  283. package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedRenderer.js.map +1 -0
  284. package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedUrls.js +155 -0
  285. package/build/dist/Server/Utils/OnCall/OnCallCalendarFeedUrls.js.map +1 -0
  286. package/build/dist/Server/Utils/OnCall/OnCallShiftChangeListeners.js +145 -0
  287. package/build/dist/Server/Utils/OnCall/OnCallShiftChangeListeners.js.map +1 -0
  288. package/build/dist/Server/Utils/OnCall/OnCallShiftMaterializer.js +752 -0
  289. package/build/dist/Server/Utils/OnCall/OnCallShiftMaterializer.js.map +1 -0
  290. package/build/dist/Server/Utils/OnCall/OnCallShiftReminderListener.js +92 -0
  291. package/build/dist/Server/Utils/OnCall/OnCallShiftReminderListener.js.map +1 -0
  292. package/build/dist/Server/Utils/OnCall/OnCallShiftReminderRunner.js +1786 -0
  293. package/build/dist/Server/Utils/OnCall/OnCallShiftReminderRunner.js.map +1 -0
  294. package/build/dist/Server/Utils/Response.js +97 -0
  295. package/build/dist/Server/Utils/Response.js.map +1 -1
  296. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.js +777 -36
  297. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsClient.js.map +1 -1
  298. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.js +108 -17
  299. package/build/dist/Server/Utils/SecurityEvent/GoogleSecOps/GoogleSecOpsPoller.js.map +1 -1
  300. package/build/dist/Server/Utils/StartServer.js +9 -1
  301. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  302. package/build/dist/Server/Utils/Telemetry/AppMetrics.js +41 -0
  303. package/build/dist/Server/Utils/Telemetry/AppMetrics.js.map +1 -1
  304. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Alert.js +17 -6
  305. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Alert.js.map +1 -1
  306. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Auth.js +0 -159
  307. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Auth.js.map +1 -1
  308. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Authorization.js +128 -0
  309. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Authorization.js.map +1 -0
  310. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Incident.js +17 -6
  311. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/Incident.js.map +1 -1
  312. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +25 -13
  313. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  314. package/build/dist/Types/API/Route.js +16 -5
  315. package/build/dist/Types/API/Route.js.map +1 -1
  316. package/build/dist/Types/Calendar/ICalendar.js +290 -0
  317. package/build/dist/Types/Calendar/ICalendar.js.map +1 -0
  318. package/build/dist/Types/Date.js +115 -13
  319. package/build/dist/Types/Date.js.map +1 -1
  320. package/build/dist/Types/Email/EmailTemplateType.js +2 -0
  321. package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
  322. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js +3 -0
  323. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js.map +1 -1
  324. package/build/dist/Types/OnCallDutyPolicy/CalendarFeedWindow.js +97 -0
  325. package/build/dist/Types/OnCallDutyPolicy/CalendarFeedWindow.js.map +1 -0
  326. package/build/dist/Types/OnCallDutyPolicy/Layer.js +113 -19
  327. package/build/dist/Types/OnCallDutyPolicy/Layer.js.map +1 -1
  328. package/build/dist/Types/OnCallDutyPolicy/MaterializedShift.js +134 -0
  329. package/build/dist/Types/OnCallDutyPolicy/MaterializedShift.js.map +1 -0
  330. package/build/dist/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.js +800 -0
  331. package/build/dist/Types/OnCallDutyPolicy/OnCallCalendarFeedUtil.js.map +1 -0
  332. package/build/dist/Types/OnCallDutyPolicy/ScheduleShiftUtil.js +97 -3
  333. package/build/dist/Types/OnCallDutyPolicy/ScheduleShiftUtil.js.map +1 -1
  334. package/build/dist/Types/OnCallDutyPolicy/ShiftSeamUtil.js +77 -0
  335. package/build/dist/Types/OnCallDutyPolicy/ShiftSeamUtil.js.map +1 -0
  336. package/build/dist/Types/Rum/SessionReplay.js +38 -0
  337. package/build/dist/Types/Rum/SessionReplay.js.map +1 -1
  338. package/build/dist/UI/Components/Date/TimeRangePickerDropdown.js +9 -5
  339. package/build/dist/UI/Components/Date/TimeRangePickerDropdown.js.map +1 -1
  340. package/build/dist/UI/Components/LogsViewer/LogsViewer.js +12 -7
  341. package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
  342. package/build/dist/UI/Components/LogsViewer/components/HistogramTooltip.js +15 -14
  343. package/build/dist/UI/Components/LogsViewer/components/HistogramTooltip.js.map +1 -1
  344. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js +17 -22
  345. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js.map +1 -1
  346. package/build/dist/UI/Components/LogsViewer/components/LogsHistogram.js +2 -4
  347. package/build/dist/UI/Components/LogsViewer/components/LogsHistogram.js.map +1 -1
  348. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js +2 -4
  349. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js.map +1 -1
  350. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js +15 -14
  351. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js.map +1 -1
  352. package/build/dist/UI/Utils/Navigation.js +30 -0
  353. package/build/dist/UI/Utils/Navigation.js.map +1 -1
  354. package/build/dist/Utils/Array.js +25 -0
  355. package/build/dist/Utils/Array.js.map +1 -1
  356. package/build/dist/Utils/CertificateReissue.js +97 -0
  357. package/build/dist/Utils/CertificateReissue.js.map +1 -0
  358. package/build/dist/Utils/Grok/Grok.js +324 -0
  359. package/build/dist/Utils/Grok/Grok.js.map +1 -0
  360. package/build/dist/Utils/Grok/GrokPatterns.js +112 -0
  361. package/build/dist/Utils/Grok/GrokPatterns.js.map +1 -0
  362. package/build/dist/Utils/Monitor/NetworkDeviceMonitorTemplateUtil.js +63 -3
  363. package/build/dist/Utils/Monitor/NetworkDeviceMonitorTemplateUtil.js.map +1 -1
  364. package/package.json +1 -1
  365. package/UI/Utils/JsonWebToken.ts +0 -14
  366. package/build/dist/UI/Utils/JsonWebToken.js +0 -10
  367. package/build/dist/UI/Utils/JsonWebToken.js.map +0 -1
@@ -16,11 +16,64 @@ import ServerException from "../../../Types/Exception/ServerException";
16
16
  import Text from "../../../Types/Text";
17
17
  import AcmeCertificate from "../../../Models/DatabaseModels/AcmeCertificate";
18
18
  import AcmeChallenge from "../../../Models/DatabaseModels/AcmeChallenge";
19
+ import ArrayUtil from "../../../Utils/Array";
19
20
  import acme from "acme-client";
20
21
  import { Challenge } from "acme-client/types/rfc8555";
21
22
  import CaptureSpan from "../Telemetry/CaptureSpan";
22
23
 
23
24
  export default class GreenlockUtil {
25
+ /*
26
+ * How early a certificate is renewed, as a range rather than a single value.
27
+ *
28
+ * Let's Encrypt issues for 90 days, so every domain ordered on the same day
29
+ * expires on the same day. Renewing them all at one fixed lead time keeps
30
+ * that batch together for every cycle that follows, and a single bad day -
31
+ * an upstream outage, a rate limit, a run that does not finish - then expires
32
+ * the whole batch at once instead of one domain.
33
+ *
34
+ * Spreading the lead time across a range pulls the batch apart: domains that
35
+ * expire on the same day come due days apart, and having been renewed days
36
+ * apart they expire days apart next cycle too. The offset is derived from the
37
+ * domain name so it is stable - a domain must not drift in and out of
38
+ * eligibility between two runs, which would leave it renewed by neither.
39
+ */
40
+ public static readonly RENEW_LEAD_TIME_MAX_IN_DAYS: number = 40;
41
+ public static readonly RENEW_LEAD_TIME_MIN_IN_DAYS: number = 25;
42
+
43
+ /*
44
+ * A run renews at most this many domains, at most this many at a time.
45
+ *
46
+ * Both bound how much of a backlog is dispatched at once. Let's Encrypt
47
+ * allows 300 new orders per account per three hours, and the reactive
48
+ * provisioning sweep spends from the same allowance, so a run that tried to
49
+ * clear a large backlog in one pass would spend the account's budget and get
50
+ * the renewals behind it refused. At the schedule this job runs on the cap
51
+ * still clears far more per day than one sequential daily pass ever did,
52
+ * while leaving room under the limit.
53
+ */
54
+ public static readonly RENEW_MAX_PER_RUN: number = 10;
55
+ public static readonly RENEW_CONCURRENCY: number = 5;
56
+
57
+ /*
58
+ * Stable per-domain lead time, somewhere in the range above. Same domain,
59
+ * same answer, on every run and every replica.
60
+ */
61
+ public static getRenewalLeadTimeInDays(domain: string): number {
62
+ const spanInDays: number =
63
+ GreenlockUtil.RENEW_LEAD_TIME_MAX_IN_DAYS -
64
+ GreenlockUtil.RENEW_LEAD_TIME_MIN_IN_DAYS;
65
+
66
+ let hash: number = 0;
67
+
68
+ for (let i: number = 0; i < domain.length; i++) {
69
+ hash = (hash * 31 + domain.charCodeAt(i)) % 1000003;
70
+ }
71
+
72
+ return (
73
+ GreenlockUtil.RENEW_LEAD_TIME_MIN_IN_DAYS + (hash % (spanInDays + 1))
74
+ );
75
+ }
76
+
24
77
  @CaptureSpan()
25
78
  public static async renewAllCertsWhichAreExpiringSoon(data: {
26
79
  validateCname: (domain: string) => Promise<boolean>;
@@ -29,15 +82,17 @@ export default class GreenlockUtil {
29
82
  try {
30
83
  logger.debug("Renewing all certificates");
31
84
 
32
- // get all certificates which are expiring soon
33
-
85
+ /*
86
+ * Read the widest window any domain's lead time can make it due in, then
87
+ * keep only the domains whose own lead time has actually been reached.
88
+ */
34
89
  const certificates: AcmeCertificate[] =
35
90
  await AcmeCertificateService.findBy({
36
91
  query: {
37
92
  expiresAt: QueryHelper.lessThanEqualTo(
38
93
  OneUptimeDate.addRemoveDays(
39
94
  OneUptimeDate.getCurrentDate(),
40
- 40, // 40 days before expiry
95
+ GreenlockUtil.RENEW_LEAD_TIME_MAX_IN_DAYS,
41
96
  ),
42
97
  ),
43
98
  },
@@ -45,6 +100,7 @@ export default class GreenlockUtil {
45
100
  skip: 0,
46
101
  select: {
47
102
  domain: true,
103
+ expiresAt: true,
48
104
  },
49
105
  sort: {
50
106
  expiresAt: SortOrder.Ascending,
@@ -54,76 +110,118 @@ export default class GreenlockUtil {
54
110
  },
55
111
  });
56
112
 
113
+ const now: Date = OneUptimeDate.getCurrentDate();
114
+
115
+ const dueCertificates: AcmeCertificate[] = certificates.filter(
116
+ (certificate: AcmeCertificate) => {
117
+ if (!certificate.domain || !certificate.expiresAt) {
118
+ return false;
119
+ }
120
+
121
+ const renewAt: Date = OneUptimeDate.addRemoveDays(
122
+ certificate.expiresAt,
123
+ -GreenlockUtil.getRenewalLeadTimeInDays(certificate.domain),
124
+ );
125
+
126
+ return !OneUptimeDate.isAfter(renewAt, now);
127
+ },
128
+ );
129
+
130
+ /*
131
+ * Still sorted by expiry, so a run that cannot take the whole backlog
132
+ * spends itself on the domains closest to expiring and leaves the rest -
133
+ * which by construction still have weeks of lead time - to the next run.
134
+ */
135
+ const batch: AcmeCertificate[] = dueCertificates.slice(
136
+ 0,
137
+ GreenlockUtil.RENEW_MAX_PER_RUN,
138
+ );
139
+
57
140
  logger.debug(
58
- `Found ${certificates.length} certificates which are expiring soon`,
59
- { certificateCount: certificates.length },
141
+ `Found ${dueCertificates.length} certificates due for renewal, renewing ${batch.length} in this run`,
142
+ {
143
+ dueCount: dueCertificates.length,
144
+ batchCount: batch.length,
145
+ },
146
+ );
147
+
148
+ await ArrayUtil.forEachWithConcurrency(
149
+ batch,
150
+ GreenlockUtil.RENEW_CONCURRENCY,
151
+ async (certificate: AcmeCertificate): Promise<void> => {
152
+ await GreenlockUtil.renewCertForDomain({
153
+ domain: certificate.domain as string,
154
+ validateCname: data.validateCname,
155
+ notifyDomainRemoved: data.notifyDomainRemoved,
156
+ });
157
+ },
60
158
  );
159
+ } catch (e) {
160
+ logger.error("Error renewing all certificates");
161
+ logger.error(e);
61
162
 
62
- // order certificate for each domain
163
+ throw e;
164
+ }
165
+ }
63
166
 
64
- for (const certificate of certificates) {
65
- if (!certificate.domain) {
66
- continue;
67
- }
167
+ /*
168
+ * Renew one domain. Never throws: one domain that cannot be renewed - a CNAME
169
+ * that no longer points here, a challenge the CA would not accept - must not
170
+ * take down the rest of the run with it.
171
+ */
172
+ private static async renewCertForDomain(data: {
173
+ domain: string;
174
+ validateCname: (domain: string) => Promise<boolean>;
175
+ notifyDomainRemoved: (domain: string) => Promise<void>;
176
+ }): Promise<void> {
177
+ const { domain } = data;
178
+
179
+ const certLogAttributes: LogAttributes = {
180
+ domain: domain,
181
+ };
68
182
 
69
- const certLogAttributes: LogAttributes = {
70
- domain: certificate.domain,
71
- };
183
+ logger.debug(
184
+ `Renewing certificate for domain: ${domain}`,
185
+ certLogAttributes,
186
+ );
72
187
 
188
+ try {
189
+ //validate cname
190
+ const isValidCname: boolean = await data.validateCname(domain);
191
+
192
+ if (!isValidCname) {
73
193
  logger.debug(
74
- `Renewing certificate for domain: ${certificate.domain}`,
194
+ `CNAME is not valid for domain: ${domain}`,
75
195
  certLogAttributes,
76
196
  );
77
197
 
78
- try {
79
- //validate cname
80
- const isValidCname: boolean = await data.validateCname(
81
- certificate.domain,
82
- );
83
-
84
- if (!isValidCname) {
85
- logger.debug(
86
- `CNAME is not valid for domain: ${certificate.domain}`,
87
- certLogAttributes,
88
- );
89
-
90
- // if cname is not valid then remove the domain
91
- await GreenlockUtil.removeDomain(certificate.domain);
92
- await data.notifyDomainRemoved(certificate.domain);
198
+ // if cname is not valid then remove the domain
199
+ await GreenlockUtil.removeDomain(domain);
200
+ await data.notifyDomainRemoved(domain);
93
201
 
94
- logger.error(
95
- `Cname is not valid for domain: ${certificate.domain}`,
96
- certLogAttributes,
97
- );
98
- } else {
99
- logger.debug(
100
- `CNAME is valid for domain: ${certificate.domain}`,
101
- certLogAttributes,
102
- );
202
+ logger.error(
203
+ `Cname is not valid for domain: ${domain}`,
204
+ certLogAttributes,
205
+ );
206
+ } else {
207
+ logger.debug(`CNAME is valid for domain: ${domain}`, certLogAttributes);
103
208
 
104
- await GreenlockUtil.orderCert({
105
- domain: certificate.domain,
106
- validateCname: data.validateCname,
107
- });
209
+ await GreenlockUtil.orderCert({
210
+ domain: domain,
211
+ validateCname: data.validateCname,
212
+ });
108
213
 
109
- logger.debug(
110
- `Certificate renewed for domain: ${certificate.domain}`,
111
- certLogAttributes,
112
- );
113
- }
114
- } catch (e) {
115
- logger.error(
116
- `Error renewing certificate for domain: ${certificate.domain}`,
117
- certLogAttributes,
118
- );
119
- logger.error(e, certLogAttributes);
120
- }
214
+ logger.debug(
215
+ `Certificate renewed for domain: ${domain}`,
216
+ certLogAttributes,
217
+ );
121
218
  }
122
219
  } catch (e) {
123
- logger.error("Error renewing all certificates");
124
- logger.error(e);
125
-
126
- throw e;
220
+ logger.error(
221
+ `Error renewing certificate for domain: ${domain}`,
222
+ certLogAttributes,
223
+ );
224
+ logger.error(e, certLogAttributes);
127
225
  }
128
226
  }
129
227
 
@@ -0,0 +1,112 @@
1
+ import BadDataException from "../../Types/Exception/BadDataException";
2
+ import { JSONObject } from "../../Types/JSON";
3
+ import LogPipelineProcessorType, {
4
+ GrokParserConfig,
5
+ } from "../../Types/Log/LogPipelineProcessorType";
6
+ import { compileGrokPattern } from "../../Utils/Grok/Grok";
7
+
8
+ /*
9
+ * Save-time validation for log pipeline processors.
10
+ *
11
+ * A processor that cannot do anything is worse than a rejected one: it
12
+ * sits in the pipeline list looking configured while every log flows
13
+ * past it untouched, and nothing surfaces the fact. That is exactly how
14
+ * GrokParser behaved before it was implemented
15
+ * (OneUptime/oneuptime#2515).
16
+ *
17
+ * The grok pattern is the one field where a typo is both easy and
18
+ * invisible - `%{IPV4:client ip}` or a stray bracket compiles to
19
+ * nothing. Compiling it here is cheap, happens once per human edit, and
20
+ * puts the error in front of the only person who can fix it. The ingest
21
+ * path stays defensive anyway: rows saved before this validation
22
+ * existed still fail closed to "leave the log alone".
23
+ */
24
+
25
+ /*
26
+ * Prefixes become the leading part of an attribute key, so hold them to
27
+ * what an attribute key can sensibly be.
28
+ */
29
+ const TARGET_PREFIX_REGEX: RegExp = /^[A-Za-z_][A-Za-z0-9_.@:-]*$/;
30
+
31
+ export interface LogPipelineProcessorCandidate {
32
+ processorType: string | undefined | null;
33
+ configuration: JSONObject | string | undefined | null;
34
+ }
35
+
36
+ /*
37
+ * `configuration` is a jsonb column, but the dashboard's JSON form field
38
+ * has historically persisted it as a JSON string literal - so both
39
+ * shapes reach here (see LogPipelineService.normalizeProcessorConfig).
40
+ */
41
+ function readConfiguration(
42
+ configuration: JSONObject | string | undefined | null,
43
+ ): JSONObject | null {
44
+ if (configuration && typeof configuration === "object") {
45
+ return configuration as JSONObject;
46
+ }
47
+
48
+ if (typeof configuration === "string") {
49
+ try {
50
+ const parsed: unknown = JSON.parse(configuration);
51
+
52
+ if (parsed && typeof parsed === "object") {
53
+ return parsed as JSONObject;
54
+ }
55
+ } catch {
56
+ throw new BadDataException("Processor configuration is not valid JSON.");
57
+ }
58
+ }
59
+
60
+ return null;
61
+ }
62
+
63
+ export function validateLogPipelineProcessor(
64
+ candidate: LogPipelineProcessorCandidate,
65
+ ): void {
66
+ if (candidate.processorType !== LogPipelineProcessorType.GrokParser) {
67
+ return;
68
+ }
69
+
70
+ const configuration: JSONObject | null = readConfiguration(
71
+ candidate.configuration,
72
+ );
73
+
74
+ if (!configuration) {
75
+ throw new BadDataException(
76
+ "A Grok Parser processor needs a configuration with a grok pattern.",
77
+ );
78
+ }
79
+
80
+ const config: GrokParserConfig = configuration as unknown as GrokParserConfig;
81
+ const pattern: string =
82
+ typeof config.pattern === "string" ? config.pattern.trim() : "";
83
+
84
+ if (!pattern) {
85
+ throw new BadDataException(
86
+ "A Grok Parser processor needs a grok pattern, for example: %{IPV4:client_ip} %{WORD:verb}",
87
+ );
88
+ }
89
+
90
+ // Throws BadDataException with a message written for the person editing.
91
+ compileGrokPattern(pattern);
92
+
93
+ if (config.targetPrefix !== undefined && config.targetPrefix !== null) {
94
+ if (typeof config.targetPrefix !== "string") {
95
+ throw new BadDataException("Target prefix must be text.");
96
+ }
97
+
98
+ const targetPrefix: string = config.targetPrefix.trim();
99
+
100
+ if (targetPrefix && !TARGET_PREFIX_REGEX.test(targetPrefix)) {
101
+ throw new BadDataException(
102
+ `"${config.targetPrefix}" is not a valid target prefix. Use letters, digits, and . _ - : @ (starting with a letter or underscore).`,
103
+ );
104
+ }
105
+ }
106
+
107
+ if (config.source !== undefined && config.source !== null) {
108
+ if (typeof config.source !== "string") {
109
+ throw new BadDataException("Source field must be text.");
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,241 @@
1
+ import crypto from "crypto";
2
+ import OneUptimeDate from "../../../Types/Date";
3
+ import { PREVIOUS_TOKEN_GRACE_DAYS } from "../../../Types/OnCallDutyPolicy/CalendarFeedWindow";
4
+
5
+ /*
6
+ * The capability token that addresses an on-call calendar feed.
7
+ *
8
+ * A calendar client keeps the feed URL forever and re-fetches it unattended,
9
+ * so the token has to be both unguessable and cheap to look up: 256 bits from
10
+ * the CSPRNG, carried in the URL as base64url (43 characters, no padding), and
11
+ * stored ONLY as its unkeyed SHA-256 hex digest. The digest is what the public
12
+ * route queries by, which keeps the plaintext out of the indexed column; a
13
+ * database dump therefore yields hashes, not working feed URLs.
14
+ *
15
+ * Unkeyed on purpose: a keyed hash (HMAC over EncryptionSecret, the backup-code
16
+ * recipe) would tie every feed to the instance secret, and rotating that secret
17
+ * would silently break every subscribed calendar in the world with no way to
18
+ * tell the user. The token already carries 256 bits of entropy, so a rainbow
19
+ * table buys nothing and the key adds no strength worth that failure mode.
20
+ *
21
+ * The hint is the last four characters - enough for the settings page to say
22
+ * "link ending in …k3Qx" so a user can tell two links apart, far too little to
23
+ * recover anything.
24
+ */
25
+
26
+ // crypto.randomBytes(32) -> 32 bytes -> ceil(32 * 8 / 6) = 43 base64url chars.
27
+ const TOKEN_BYTE_LENGTH: number = 32;
28
+
29
+ export const CALENDAR_FEED_TOKEN_LENGTH: number = 43;
30
+
31
+ export const CALENDAR_FEED_TOKEN_HINT_LENGTH: number = 4;
32
+
33
+ /*
34
+ * Shape guard for the public route. Anything that does not match is answered
35
+ * 404 before any database work, so a scanner probing the path costs one regex.
36
+ */
37
+ export const CALENDAR_FEED_TOKEN_REGEX: RegExp = /^[A-Za-z0-9_-]{43}$/;
38
+
39
+ export interface MintedCalendarFeedToken {
40
+ /** The plaintext token. Goes into the URL and, encrypted, into `token`. */
41
+ token: string;
42
+ /** Unkeyed SHA-256 hex digest of the token. The indexed lookup column. */
43
+ tokenHash: string;
44
+ /** Last four characters of the token, for display only. */
45
+ tokenHint: string;
46
+ }
47
+
48
+ /*
49
+ * Everything a feed row's token columns hold after a rotation: the new
50
+ * token set, when it was minted, and the rotated-out hash with the instant
51
+ * it stops being honoured. `previousTokenHash` is null when there was no
52
+ * token before (a first mint), so a fresh feed never carries a grace entry.
53
+ */
54
+ export interface CalendarFeedRotation extends MintedCalendarFeedToken {
55
+ rotatedAt: Date;
56
+ previousTokenHash: string | null;
57
+ previousTokenExpiresAt: Date | null;
58
+ }
59
+
60
+ /*
61
+ * The token columns every feed model carries (UserOnCallCalendarFeed,
62
+ * OnCallDutyPolicyScheduleCalendarFeed, ProjectOnCallCalendarFeed). Typed
63
+ * structurally so the three services share one rule without a common base.
64
+ */
65
+ export interface CalendarFeedTokenColumns {
66
+ token?: string | undefined;
67
+ tokenHash?: string | undefined;
68
+ tokenHint?: string | undefined;
69
+ rotatedAt?: Date | undefined;
70
+ previousTokenHash?: string | undefined;
71
+ previousTokenExpiresAt?: Date | undefined;
72
+ }
73
+
74
+ export interface CalendarFeedRotationUpdateData {
75
+ token: string;
76
+ tokenHash: string;
77
+ tokenHint: string;
78
+ rotatedAt: Date;
79
+ previousTokenHash: string;
80
+ previousTokenExpiresAt: Date;
81
+ }
82
+
83
+ export default class CalendarFeedToken {
84
+ /**
85
+ * A fresh 43-character base64url token from 32 CSPRNG bytes.
86
+ */
87
+ public static mint(): string {
88
+ return crypto.randomBytes(TOKEN_BYTE_LENGTH).toString("base64url");
89
+ }
90
+
91
+ /**
92
+ * Unkeyed SHA-256 of the token, lowercase hex (64 characters). This is the
93
+ * value stored in `tokenHash` / `previousTokenHash` and the value the public
94
+ * route looks up by. Deterministic: the same token always hashes the same.
95
+ */
96
+ public static hash(token: string): string {
97
+ return crypto.createHash("sha256").update(token, "utf8").digest("hex");
98
+ }
99
+
100
+ /**
101
+ * The display hint - the last four characters of the token. Never enough to
102
+ * reconstruct the token; enough to tell "…k3Qx" from "…Q9zA" in the UI.
103
+ */
104
+ public static hint(token: string): string {
105
+ return token.slice(-CALENDAR_FEED_TOKEN_HINT_LENGTH);
106
+ }
107
+
108
+ /**
109
+ * True when the string has exactly the shape a minted token has. Used as
110
+ * the shape guard on the public route so a malformed path never reaches the
111
+ * database.
112
+ */
113
+ public static isValidShape(token: unknown): token is string {
114
+ return typeof token === "string" && CALENDAR_FEED_TOKEN_REGEX.test(token);
115
+ }
116
+
117
+ /**
118
+ * Everything a feed row needs when a token is minted or rotated.
119
+ */
120
+ public static mintSet(): MintedCalendarFeedToken {
121
+ const token: string = CalendarFeedToken.mint();
122
+
123
+ return {
124
+ token: token,
125
+ tokenHash: CalendarFeedToken.hash(token),
126
+ tokenHint: CalendarFeedToken.hint(token),
127
+ };
128
+ }
129
+
130
+ /**
131
+ * The token columns a feed row should hold after minting or rotating.
132
+ *
133
+ * The hash the row held before (if any) moves to `previousTokenHash` and
134
+ * keeps serving an EMPTY calendar until `previousTokenExpiresAt`
135
+ * (PREVIOUS_TOKEN_GRACE_DAYS from now), so a still-subscribed client clears
136
+ * its copy instead of showing "could not fetch" until the user notices.
137
+ */
138
+ public static buildRotation(data: {
139
+ currentTokenHash: string | null | undefined;
140
+ now?: Date | undefined;
141
+ }): CalendarFeedRotation {
142
+ const now: Date = data.now || OneUptimeDate.getCurrentDate();
143
+ const minted: MintedCalendarFeedToken = CalendarFeedToken.mintSet();
144
+
145
+ const previousTokenHash: string | null = data.currentTokenHash || null;
146
+
147
+ return {
148
+ ...minted,
149
+ rotatedAt: now,
150
+ previousTokenHash: previousTokenHash,
151
+ previousTokenExpiresAt: previousTokenHash
152
+ ? OneUptimeDate.addRemoveDays(now, PREVIOUS_TOKEN_GRACE_DAYS)
153
+ : null,
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Populate the token columns of a row about to be INSERTED.
159
+ *
160
+ * With `trustSuppliedToken`, a well-formed plaintext token already on the
161
+ * row (the calendar API mints one up front so it can build the URL in the
162
+ * same response) is kept and the hash and hint are DERIVED from it. Without
163
+ * it - every non-root create - whatever the request carried is discarded
164
+ * and a fresh token is minted. Either way a malformed token or a
165
+ * caller-chosen hash is replaced: there is no path to a row whose hash
166
+ * disagrees with its token, and no path for a request body to choose the
167
+ * secret. A brand-new row never carries a grace-period hash.
168
+ */
169
+ public static applyTokenColumnsOnCreate(
170
+ data: CalendarFeedTokenColumns,
171
+ options: { trustSuppliedToken: boolean },
172
+ ): MintedCalendarFeedToken {
173
+ let minted: MintedCalendarFeedToken;
174
+
175
+ if (
176
+ options.trustSuppliedToken &&
177
+ CalendarFeedToken.isValidShape(data.token)
178
+ ) {
179
+ minted = {
180
+ token: data.token,
181
+ tokenHash: CalendarFeedToken.hash(data.token),
182
+ tokenHint: CalendarFeedToken.hint(data.token),
183
+ };
184
+ } else {
185
+ minted = CalendarFeedToken.mintSet();
186
+ }
187
+
188
+ data.token = minted.token;
189
+ data.tokenHash = minted.tokenHash;
190
+ data.tokenHint = minted.tokenHint;
191
+ data.rotatedAt = OneUptimeDate.getCurrentDate();
192
+ data.previousTokenHash = undefined;
193
+ data.previousTokenExpiresAt = undefined;
194
+
195
+ return minted;
196
+ }
197
+
198
+ /**
199
+ * The partial row a rotation writes. `previousTokenHash` /
200
+ * `previousTokenExpiresAt` are null on a first mint, which the update path
201
+ * has to be able to write; the model types them as optional strings/dates,
202
+ * hence the cast at this one boundary.
203
+ */
204
+ public static toRotationUpdateData(
205
+ rotation: CalendarFeedRotation,
206
+ ): CalendarFeedRotationUpdateData {
207
+ return {
208
+ token: rotation.token,
209
+ tokenHash: rotation.tokenHash,
210
+ tokenHint: rotation.tokenHint,
211
+ rotatedAt: rotation.rotatedAt,
212
+ previousTokenHash: rotation.previousTokenHash as unknown as string,
213
+ previousTokenExpiresAt:
214
+ rotation.previousTokenExpiresAt as unknown as Date,
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Constant-time comparison of two hashes, for callers that compare a
220
+ * freshly computed digest against a stored one in memory rather than in a
221
+ * WHERE clause. Length mismatch is answered false without leaking timing on
222
+ * the content.
223
+ */
224
+ public static isHashEqual(a: string, b: string): boolean {
225
+ /*
226
+ * Plain Uint8Arrays rather than Buffers: the two are interchangeable at
227
+ * runtime, but the App build's @types/node rejects Buffer where an
228
+ * ArrayBufferView is expected (the same mismatch PasswordHash and
229
+ * TwoFactorBackupCode trip over), and TextEncoder is global on every
230
+ * supported Node.
231
+ */
232
+ const bytesA: Uint8Array = new TextEncoder().encode(a);
233
+ const bytesB: Uint8Array = new TextEncoder().encode(b);
234
+
235
+ if (bytesA.length !== bytesB.length) {
236
+ return false;
237
+ }
238
+
239
+ return crypto.timingSafeEqual(bytesA, bytesB);
240
+ }
241
+ }