@oneuptime/common 14.0.7 → 14.0.8

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 (440) hide show
  1. package/Models/DatabaseModels/Incident.ts +267 -1
  2. package/Models/DatabaseModels/IncidentCustomField.ts +202 -0
  3. package/Models/DatabaseModels/IncidentEpisode.ts +30 -0
  4. package/Models/DatabaseModels/IncidentTemplate.ts +126 -1
  5. package/Models/DatabaseModels/StatusPage.ts +55 -0
  6. package/Models/DatabaseModels/StatusPageSubscriber.ts +128 -0
  7. package/Server/API/IncidentAPI.ts +162 -0
  8. package/Server/API/StatusPageAPI.ts +487 -171
  9. package/Server/API/StatusPageSubscriberAPI.ts +63 -15
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.ts +49 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.ts +108 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.ts +33 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.ts +51 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.ts +33 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.ts +168 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.ts +44 -0
  17. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +14 -0
  18. package/Server/Infrastructure/Semaphore.ts +10 -0
  19. package/Server/Middleware/IdentityRateLimit.ts +108 -3
  20. package/Server/Middleware/SubscriberNotificationPreviewRateLimit.ts +237 -0
  21. package/Server/Middleware/SubscriberNotificationTestSendRateLimit.ts +304 -0
  22. package/Server/Services/DatabaseService.ts +93 -10
  23. package/Server/Services/IncidentCustomFieldService.ts +276 -1
  24. package/Server/Services/IncidentEpisodePublicNoteService.ts +28 -0
  25. package/Server/Services/IncidentEpisodeService.ts +15 -0
  26. package/Server/Services/IncidentEpisodeStateTimelineService.ts +27 -1
  27. package/Server/Services/IncidentPublicNoteService.ts +30 -1
  28. package/Server/Services/IncidentService.ts +1535 -65
  29. package/Server/Services/IncidentStateTimelineService.ts +13 -0
  30. package/Server/Services/IncidentTemplateService.ts +109 -0
  31. package/Server/Services/ScheduledMaintenancePublicNoteService.ts +30 -1
  32. package/Server/Services/ScheduledMaintenanceService.ts +68 -18
  33. package/Server/Services/SmsService.ts +10 -0
  34. package/Server/Services/StatusPageService.ts +65 -8
  35. package/Server/Services/StatusPageSubscriberNotificationTemplateService.ts +299 -37
  36. package/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.ts +129 -0
  37. package/Server/Services/StatusPageSubscriberService.ts +1161 -64
  38. package/Server/Types/Markdown.ts +153 -6
  39. package/Server/Types/Workflow/Components/Email.ts +61 -2
  40. package/Server/Utils/CustomField/CustomFieldRename.ts +378 -0
  41. package/Server/Utils/DataSource/EgressGuard.ts +66 -21
  42. package/Server/Utils/Mail/PinnedSmtpSocket.ts +130 -0
  43. package/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.ts +10 -0
  44. package/Server/Utils/SSRFProtection.ts +76 -16
  45. package/Server/Utils/StatusPage/IncidentStatusPageScope.ts +948 -0
  46. package/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.ts +656 -0
  47. package/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.ts +805 -0
  48. package/Server/Utils/StatusPage/StatusPageExclusion.ts +18 -0
  49. package/Server/Utils/StatusPage/StatusPageReadAccess.ts +125 -0
  50. package/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.ts +151 -0
  51. package/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.ts +70 -0
  52. package/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.ts +421 -0
  53. package/Server/Utils/StatusPage/SubscriberNotificationClaim.ts +107 -0
  54. package/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.ts +1049 -0
  55. package/Server/Utils/StatusPage/SubscriberNotificationFanOut.ts +180 -0
  56. package/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.ts +839 -0
  57. package/Server/Utils/StatusPage/SubscriberNotificationResendAccess.ts +393 -0
  58. package/Server/Utils/StatusPage/SubscriberNotificationRunLimit.ts +246 -0
  59. package/Server/Utils/StatusPage/SubscriberNotificationTiming.ts +133 -0
  60. package/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.ts +215 -0
  61. package/Server/Utils/StatusPageResource.ts +51 -20
  62. package/Server/Utils/VM/VMAPI.ts +1 -0
  63. package/Server/Utils/VM/VMRunner.ts +10 -0
  64. package/Server/Utils/Workflow/OAuth2TokenClient.ts +10 -0
  65. package/Server/Views/Partials/SensitiveUrlToken.ejs +8 -5
  66. package/Tests/App/Accounts/RegisterVerifyEmail.test.tsx +748 -0
  67. package/Tests/App/Accounts/ResendVerificationEmail.test.tsx +1222 -0
  68. package/Tests/App/Accounts/VerificationEmailResendUtils.test.ts +797 -0
  69. package/Tests/App/Accounts/VerifyEmailPending.test.tsx +538 -0
  70. package/Tests/App/Accounts/VerifyEmailResend.test.tsx +779 -0
  71. package/Tests/App/Dashboard/CustomFieldsSettingsIncidentOptions.test.tsx +357 -0
  72. package/Tests/App/Dashboard/EventNotes.test.tsx +776 -0
  73. package/Tests/App/Dashboard/EventNotesPages.test.tsx +119 -0
  74. package/Tests/App/Dashboard/EventNotesUtil.test.ts +116 -17
  75. package/Tests/App/Dashboard/EventOverviewPages.test.tsx +242 -5
  76. package/Tests/App/Dashboard/IncidentChangeStateNotifyDefault.test.tsx +91 -1
  77. package/Tests/App/Dashboard/IncidentCreateDetailsStep.test.tsx +643 -0
  78. package/Tests/App/Dashboard/IncidentCreateFromAlerts.test.tsx +8 -1
  79. package/Tests/App/Dashboard/IncidentCreateStatusPageScope.test.tsx +601 -0
  80. package/Tests/App/Dashboard/IncidentCustomFieldTemplateVariables.test.tsx +386 -0
  81. package/Tests/App/Dashboard/IncidentNoteTemplatePlaceholders.test.tsx +124 -0
  82. package/Tests/App/Dashboard/IncidentNoteTemplateVariablesLoader.test.ts +305 -0
  83. package/Tests/App/Dashboard/IncidentOverviewNotifyDefault.test.tsx +112 -0
  84. package/Tests/App/Dashboard/IncidentSettingsRenotifyOnPublish.test.tsx +674 -0
  85. package/Tests/App/Dashboard/IncidentSettingsStatusPageScope.test.tsx +1051 -0
  86. package/Tests/App/Dashboard/IncidentTemplateCustomFields.test.tsx +384 -0
  87. package/Tests/App/Dashboard/IncidentTemplateStatusPageScopeCard.test.tsx +215 -0
  88. package/Tests/App/Dashboard/PublicNotePagesNotifyDefault.test.tsx +113 -1
  89. package/Tests/App/Dashboard/SubscriberAudienceSummary.test.tsx +512 -0
  90. package/Tests/App/Dashboard/SubscriberNotificationPreviewModal.test.tsx +837 -0
  91. package/Tests/App/Dashboard/SubscriberNotificationStatusLabel.test.tsx +88 -0
  92. package/Tests/App/Dashboard/SubscriberNotificationStatusResend.test.tsx +473 -0
  93. package/Tests/App/Dashboard/SubscriberTemplateLivePreview.test.tsx +196 -0
  94. package/Tests/App/Dashboard/TeamAddedSubscribersUnsubscribedNotice.test.tsx +248 -0
  95. package/Tests/App/SensitiveUrlTokenBootstrap.test.ts +64 -3
  96. package/Tests/App/StatusPage/StatusPageUnsubscribePage.test.tsx +412 -0
  97. package/Tests/Models/IncidentCustomFieldApiSchemaContract.test.ts +217 -0
  98. package/Tests/Models/IncidentCustomFieldCreateSettingsColumns.test.ts +252 -0
  99. package/Tests/Models/StatusPageSubscriberUnsubscribeColumns.test.ts +218 -0
  100. package/Tests/Server/API/ExpiredSessionRouteGuards.test.ts +7 -0
  101. package/Tests/Server/API/IncidentSubscriberAudienceAPI.test.ts +1408 -0
  102. package/Tests/Server/API/StatusPageIncidentScope.test.ts +1868 -0
  103. package/Tests/Server/API/StatusPageIncidentScopePostgres.test.ts +790 -0
  104. package/Tests/Server/API/StatusPageManageSubscriptionRecipient.test.ts +10 -1
  105. package/Tests/Server/API/StatusPageManageSubscriptionTemplateVariables.test.ts +206 -18
  106. package/Tests/Server/API/StatusPagePostmortemVisibility.test.ts +14 -2
  107. package/Tests/Server/API/StatusPageSubscriberCreateResponse.test.ts +217 -0
  108. package/Tests/Server/API/StatusPageSubscriberOwnership.test.ts +103 -2
  109. package/Tests/Server/API/StatusPageUnsubscribeAPI.test.ts +396 -0
  110. package/Tests/Server/Infrastructure/Postgres/AddIncidentStatusPageScopeMigration.test.ts +395 -0
  111. package/Tests/Server/Infrastructure/Postgres/AddIncidentTemplateStatusPageScopeFlagMigration.test.ts +150 -0
  112. package/Tests/Server/Infrastructure/Postgres/AddSubscriberNotificationClaimedAtMigration.test.ts +156 -0
  113. package/Tests/Server/Infrastructure/Postgres/SkipHiddenIncidentCreatedNotificationsMigration.test.ts +410 -0
  114. package/Tests/Server/Middleware/IdentityRateLimit.test.ts +551 -1
  115. package/Tests/Server/Middleware/SubscriberNotificationPreviewRateLimit.test.ts +238 -0
  116. package/Tests/Server/Middleware/SubscriberNotificationTestSendRateLimit.test.ts +245 -0
  117. package/Tests/Server/Services/AddStatusPageSubscriberUnsubscribeTokenMigration.test.ts +152 -0
  118. package/Tests/Server/Services/CrossProjectRelationWriteGuard.test.ts +221 -36
  119. package/Tests/Server/Services/DatabaseServiceCompareAndSetColumns.test.ts +191 -0
  120. package/Tests/Server/Services/IncidentCreatedRenotifyOnPublish.test.ts +681 -0
  121. package/Tests/Server/Services/IncidentCreatedResend.test.ts +775 -0
  122. package/Tests/Server/Services/IncidentCustomFieldRenamePostgres.test.ts +713 -0
  123. package/Tests/Server/Services/IncidentCustomFieldService.test.ts +751 -0
  124. package/Tests/Server/Services/IncidentCustomFieldValueValidation.test.ts +556 -0
  125. package/Tests/Server/Services/IncidentStatusPageScope.test.ts +2971 -0
  126. package/Tests/Server/Services/IncidentStatusPageScopeFeed.test.ts +131 -0
  127. package/Tests/Server/Services/IncidentStatusPageScopePostgres.test.ts +625 -0
  128. package/Tests/Server/Services/IncidentTemplateCustomFieldsCopy.test.ts +311 -0
  129. package/Tests/Server/Services/IncidentTemplateStatusPageScope.test.ts +363 -0
  130. package/Tests/Server/Services/PublicNoteEditFeedEventType.test.ts +213 -0
  131. package/Tests/Server/Services/PublicNoteResendAccess.test.ts +994 -0
  132. package/Tests/Server/Services/ScheduledMaintenanceSubscriberTemplateFormats.test.ts +289 -9
  133. package/Tests/Server/Services/SmsServiceFailIfNotSent.test.ts +67 -0
  134. package/Tests/Server/Services/StatusPageReportIncidentCounts.test.ts +610 -0
  135. package/Tests/Server/Services/StatusPageSubscriberAudienceCounts.test.ts +201 -0
  136. package/Tests/Server/Services/StatusPageSubscriberAudienceCountsPostgres.test.ts +271 -0
  137. package/Tests/Server/Services/StatusPageSubscriberConfirmationTemplateEscaping.test.ts +200 -0
  138. package/Tests/Server/Services/StatusPageSubscriberNotificationLogRedaction.test.ts +54 -0
  139. package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateCompile.test.ts +37 -0
  140. package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateIncidentRecordAccess.test.ts +772 -0
  141. package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateLookup.test.ts +506 -0
  142. package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateLookupPostgres.test.ts +261 -0
  143. package/Tests/Server/Services/StatusPageSubscriberReport.test.ts +21 -5
  144. package/Tests/Server/Services/StatusPageSubscriberUnsubscribe.test.ts +1618 -0
  145. package/Tests/Server/Services/StatusPageSubscriberUnsubscribeLinkSenders.test.ts +373 -0
  146. package/Tests/Server/Services/StatusPageSubscriberUnsubscribePostgres.test.ts +388 -0
  147. package/Tests/Server/Services/SubscriberNotificationInFlightRequeue.test.ts +500 -0
  148. package/Tests/Server/Types/MarkdownEmailLinks.test.ts +320 -0
  149. package/Tests/Server/Types/Workflow/Components/Email.test.ts +491 -1
  150. package/Tests/Server/Types/Workflow/Components/EmailSmtpPinning.test.ts +398 -0
  151. package/Tests/Server/Utils/CustomField/CustomFieldRename.test.ts +586 -0
  152. package/Tests/Server/Utils/DataSource/EgressGuard.test.ts +246 -10
  153. package/Tests/Server/Utils/DataSource/EgressGuardDeploymentConfig.test.ts +226 -0
  154. package/Tests/Server/Utils/DataSource/EgressGuardPinning.test.ts +131 -0
  155. package/Tests/Server/Utils/DataSource/HttpFetch.test.ts +4 -0
  156. package/Tests/Server/Utils/EgressPolicyEnvironment.ts +45 -0
  157. package/Tests/Server/Utils/Mail/PinnedSmtpSocket.test.ts +409 -0
  158. package/Tests/Server/Utils/Monitor/MonitorCriteriaObservationBuilderUnits.test.ts +23 -0
  159. package/Tests/Server/Utils/SSRFProtection.test.ts +4 -0
  160. package/Tests/Server/Utils/SSRFProtectionCloudServiceAddresses.test.ts +4 -0
  161. package/Tests/Server/Utils/SSRFProtectionPrivateNetwork.test.ts +4 -0
  162. package/Tests/Server/Utils/SSRFProtectionResolutionDetail.test.ts +314 -0
  163. package/Tests/Server/Utils/StatusPage/IncidentStatusPageScope.test.ts +1699 -0
  164. package/Tests/Server/Utils/StatusPage/IncidentStatusPageScopeQueriesPostgres.test.ts +508 -0
  165. package/Tests/Server/Utils/StatusPage/IncidentSubscriberAudienceCallerPermission.test.ts +246 -0
  166. package/Tests/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.test.ts +1348 -0
  167. package/Tests/Server/Utils/StatusPage/StatusPageReadAccess.test.ts +221 -0
  168. package/Tests/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.test.ts +132 -0
  169. package/Tests/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.test.ts +155 -0
  170. package/Tests/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.test.ts +708 -0
  171. package/Tests/Server/Utils/StatusPage/SubscriberNotificationClaim.test.ts +255 -0
  172. package/Tests/Server/Utils/StatusPage/SubscriberNotificationClaimPostgres.test.ts +528 -0
  173. package/Tests/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.test.ts +1238 -0
  174. package/Tests/Server/Utils/StatusPage/SubscriberNotificationFanOut.test.ts +472 -0
  175. package/Tests/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.test.ts +1168 -0
  176. package/Tests/Server/Utils/StatusPage/SubscriberNotificationRunLimit.test.ts +275 -0
  177. package/Tests/Server/Utils/StatusPage/SubscriberNotificationTiming.test.ts +131 -0
  178. package/Tests/Server/Utils/StatusPageResource.test.ts +98 -0
  179. package/Tests/Server/Utils/VM/VMRunnerPrivateNetworkWiring.test.ts +17 -0
  180. package/Tests/Server/Utils/VM/VMRunnerSsrf.test.ts +75 -0
  181. package/Tests/Types/CustomField/CustomFieldSavedViews.test.ts +247 -0
  182. package/Tests/Types/CustomField/CustomFieldTemplateValues.test.ts +186 -0
  183. package/Tests/Types/CustomField/CustomFieldTypeCorrespondence.test.ts +48 -0
  184. package/Tests/Types/CustomField/CustomFieldValueFormat.test.ts +215 -0
  185. package/Tests/Types/CustomField/CustomFieldValueValidator.test.ts +343 -0
  186. package/Tests/Types/CustomField/CustomFieldVariableKey.test.ts +364 -0
  187. package/Tests/Types/SafeHtml.test.ts +102 -0
  188. package/Tests/Types/StatusPage/IncidentCreatedRenotify.test.ts +419 -0
  189. package/Tests/Types/StatusPage/IncidentCreatedResend.test.ts +118 -0
  190. package/Tests/Types/StatusPage/IncidentScopeAddedPagesNotification.test.ts +558 -0
  191. package/Tests/Types/StatusPage/IncidentSubscriberAudience.test.ts +284 -0
  192. package/Tests/Types/StatusPage/StatusPageSubscriberUnsubscribe.test.ts +341 -0
  193. package/Tests/Types/StatusPage/SubscriberNotificationPreview.test.ts +196 -0
  194. package/Tests/Types/StatusPage/SubscriberNotificationResend.test.ts +201 -0
  195. package/Tests/Types/StatusPage/SubscriberNotificationTemplateCompiler.test.ts +277 -0
  196. package/Tests/Types/StatusPage/SubscriberNotificationTemplatePreview.test.ts +179 -0
  197. package/Tests/Types/StatusPage/SubscriberNotificationTemplateVariables.test.ts +324 -0
  198. package/Tests/Types/StatusPage/SubscriberUpdateNotification.test.ts +60 -13
  199. package/Tests/UI/Components/CustomFields/CustomFieldFormFields.test.ts +432 -0
  200. package/Tests/UI/Components/CustomFields/CustomFieldModelFormFields.test.tsx +685 -0
  201. package/Tests/UI/Components/CustomFields/CustomFieldsDetailOrder.test.tsx +469 -0
  202. package/Tests/UI/Components/Forms/ModelFormCustomFieldInputs.test.tsx +325 -0
  203. package/Tests/UI/Components/Forms/ModelFormDropdownOptionsRefused.test.tsx +358 -0
  204. package/Tests/UI/Components/ModelTable/CustomFieldColumns.test.tsx +22 -0
  205. package/Tests/UI/Monitor/NetworkPathView.test.tsx +289 -0
  206. package/Tests/Utils/Incident/IncidentNoteTemplateVariables.test.ts +623 -0
  207. package/Tests/Utils/Markdown/MarkdownEscape.test.ts +89 -0
  208. package/Tests/Utils/ProbeNetworkFailureUtil.test.ts +992 -0
  209. package/Tests/Utils/RequestFailedDetails.test.ts +575 -0
  210. package/Types/CustomField/CustomFieldOrder.ts +55 -0
  211. package/Types/CustomField/CustomFieldSavedViews.ts +225 -0
  212. package/Types/CustomField/CustomFieldTemplateMerge.ts +71 -0
  213. package/Types/CustomField/CustomFieldType.ts +14 -0
  214. package/Types/CustomField/CustomFieldValueFormat.ts +161 -0
  215. package/Types/CustomField/CustomFieldValueValidator.ts +488 -0
  216. package/Types/CustomField/CustomFieldVariableKey.ts +211 -0
  217. package/Types/SafeHtml.ts +93 -0
  218. package/Types/StatusPage/IncidentCreatedRenotify.ts +224 -0
  219. package/Types/StatusPage/IncidentCreatedResend.ts +108 -0
  220. package/Types/StatusPage/IncidentScopeAddedPagesNotification.ts +343 -0
  221. package/Types/StatusPage/IncidentSubscriberAudience.ts +332 -0
  222. package/Types/StatusPage/StatusPageSubscriberUnsubscribe.ts +405 -0
  223. package/Types/StatusPage/SubscriberNotificationInterruption.ts +32 -0
  224. package/Types/StatusPage/SubscriberNotificationPreview.ts +322 -0
  225. package/Types/StatusPage/SubscriberNotificationResend.ts +132 -0
  226. package/Types/StatusPage/SubscriberNotificationTemplateCompiler.ts +180 -0
  227. package/Types/StatusPage/SubscriberNotificationTemplatePreview.ts +301 -0
  228. package/Types/StatusPage/SubscriberNotificationTemplateVariables.ts +217 -4
  229. package/Types/StatusPage/SubscriberUpdateNotification.ts +32 -11
  230. package/UI/Components/CustomFields/CustomFieldFormFields.ts +317 -0
  231. package/UI/Components/CustomFields/CustomFieldModelFormFields.tsx +395 -0
  232. package/UI/Components/CustomFields/CustomFieldsDetail.tsx +95 -55
  233. package/UI/Components/Forms/ModelForm.tsx +70 -8
  234. package/UI/Components/Forms/Validation.ts +1 -1
  235. package/UI/Components/ModelFormModal/ModelFormModal.tsx +2 -4
  236. package/UI/Components/ModelTable/AnalyticsModelTable.tsx +2 -6
  237. package/UI/Components/ModelTable/BaseModelTable.tsx +9 -8
  238. package/UI/Components/ModelTable/CustomFieldColumns.tsx +14 -1
  239. package/UI/Components/ModelTable/ModelTable.tsx +6 -7
  240. package/UI/Utils/SensitiveUrlToken.ts +10 -5
  241. package/Utils/API.ts +247 -2
  242. package/Utils/Incident/IncidentNoteTemplateVariables.ts +304 -0
  243. package/Utils/Markdown/MarkdownEscape.ts +65 -0
  244. package/Utils/ProbeNetworkFailureUtil.ts +673 -0
  245. package/build/dist/Models/DatabaseModels/Incident.js +267 -1
  246. package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
  247. package/build/dist/Models/DatabaseModels/IncidentCustomField.js +207 -1
  248. package/build/dist/Models/DatabaseModels/IncidentCustomField.js.map +1 -1
  249. package/build/dist/Models/DatabaseModels/IncidentEpisode.js +31 -0
  250. package/build/dist/Models/DatabaseModels/IncidentEpisode.js.map +1 -1
  251. package/build/dist/Models/DatabaseModels/IncidentTemplate.js +124 -1
  252. package/build/dist/Models/DatabaseModels/IncidentTemplate.js.map +1 -1
  253. package/build/dist/Models/DatabaseModels/StatusPage.js +56 -0
  254. package/build/dist/Models/DatabaseModels/StatusPage.js.map +1 -1
  255. package/build/dist/Models/DatabaseModels/StatusPageSubscriber.js +131 -0
  256. package/build/dist/Models/DatabaseModels/StatusPageSubscriber.js.map +1 -1
  257. package/build/dist/Server/API/IncidentAPI.js +100 -1
  258. package/build/dist/Server/API/IncidentAPI.js.map +1 -1
  259. package/build/dist/Server/API/StatusPageAPI.js +417 -176
  260. package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
  261. package/build/dist/Server/API/StatusPageSubscriberAPI.js +52 -13
  262. package/build/dist/Server/API/StatusPageSubscriberAPI.js.map +1 -1
  263. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.js +41 -0
  264. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.js.map +1 -0
  265. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.js +57 -0
  266. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.js.map +1 -0
  267. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.js +23 -0
  268. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.js.map +1 -0
  269. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.js +40 -0
  270. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.js.map +1 -0
  271. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.js +26 -0
  272. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.js.map +1 -0
  273. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.js +89 -0
  274. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.js.map +1 -0
  275. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.js +29 -0
  276. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.js.map +1 -0
  277. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +14 -0
  278. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  279. package/build/dist/Server/Infrastructure/Semaphore.js +3 -0
  280. package/build/dist/Server/Infrastructure/Semaphore.js.map +1 -1
  281. package/build/dist/Server/Middleware/IdentityRateLimit.js +89 -3
  282. package/build/dist/Server/Middleware/IdentityRateLimit.js.map +1 -1
  283. package/build/dist/Server/Middleware/SubscriberNotificationPreviewRateLimit.js +149 -0
  284. package/build/dist/Server/Middleware/SubscriberNotificationPreviewRateLimit.js.map +1 -0
  285. package/build/dist/Server/Middleware/SubscriberNotificationTestSendRateLimit.js +190 -0
  286. package/build/dist/Server/Middleware/SubscriberNotificationTestSendRateLimit.js.map +1 -0
  287. package/build/dist/Server/Services/DatabaseService.js +56 -7
  288. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  289. package/build/dist/Server/Services/IncidentCustomFieldService.js +204 -8
  290. package/build/dist/Server/Services/IncidentCustomFieldService.js.map +1 -1
  291. package/build/dist/Server/Services/IncidentEpisodePublicNoteService.js +24 -0
  292. package/build/dist/Server/Services/IncidentEpisodePublicNoteService.js.map +1 -1
  293. package/build/dist/Server/Services/IncidentEpisodeService.js +14 -0
  294. package/build/dist/Server/Services/IncidentEpisodeService.js.map +1 -1
  295. package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js +26 -0
  296. package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js.map +1 -1
  297. package/build/dist/Server/Services/IncidentPublicNoteService.js +26 -1
  298. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  299. package/build/dist/Server/Services/IncidentService.js +1052 -0
  300. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  301. package/build/dist/Server/Services/IncidentStateTimelineService.js +12 -0
  302. package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
  303. package/build/dist/Server/Services/IncidentTemplateService.js +83 -0
  304. package/build/dist/Server/Services/IncidentTemplateService.js.map +1 -1
  305. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +26 -1
  306. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  307. package/build/dist/Server/Services/ScheduledMaintenanceService.js +47 -17
  308. package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
  309. package/build/dist/Server/Services/SmsService.js +2 -22
  310. package/build/dist/Server/Services/SmsService.js.map +1 -1
  311. package/build/dist/Server/Services/StatusPageService.js +47 -9
  312. package/build/dist/Server/Services/StatusPageService.js.map +1 -1
  313. package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateService.js +237 -32
  314. package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateService.js.map +1 -1
  315. package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.js +109 -0
  316. package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.js.map +1 -1
  317. package/build/dist/Server/Services/StatusPageSubscriberService.js +925 -99
  318. package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
  319. package/build/dist/Server/Types/Markdown.js +110 -6
  320. package/build/dist/Server/Types/Markdown.js.map +1 -1
  321. package/build/dist/Server/Types/Workflow/Components/Email.js +55 -6
  322. package/build/dist/Server/Types/Workflow/Components/Email.js.map +1 -1
  323. package/build/dist/Server/Utils/CustomField/CustomFieldRename.js +211 -0
  324. package/build/dist/Server/Utils/CustomField/CustomFieldRename.js.map +1 -0
  325. package/build/dist/Server/Utils/DataSource/EgressGuard.js +41 -12
  326. package/build/dist/Server/Utils/DataSource/EgressGuard.js.map +1 -1
  327. package/build/dist/Server/Utils/Mail/PinnedSmtpSocket.js +101 -0
  328. package/build/dist/Server/Utils/Mail/PinnedSmtpSocket.js.map +1 -0
  329. package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js +9 -0
  330. package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js.map +1 -1
  331. package/build/dist/Server/Utils/SSRFProtection.js +48 -6
  332. package/build/dist/Server/Utils/SSRFProtection.js.map +1 -1
  333. package/build/dist/Server/Utils/StatusPage/IncidentStatusPageScope.js +631 -0
  334. package/build/dist/Server/Utils/StatusPage/IncidentStatusPageScope.js.map +1 -0
  335. package/build/dist/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.js +403 -0
  336. package/build/dist/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.js.map +1 -0
  337. package/build/dist/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.js +451 -0
  338. package/build/dist/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.js.map +1 -0
  339. package/build/dist/Server/Utils/StatusPage/StatusPageExclusion.js +13 -0
  340. package/build/dist/Server/Utils/StatusPage/StatusPageExclusion.js.map +1 -0
  341. package/build/dist/Server/Utils/StatusPage/StatusPageReadAccess.js +91 -0
  342. package/build/dist/Server/Utils/StatusPage/StatusPageReadAccess.js.map +1 -0
  343. package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.js +101 -0
  344. package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.js.map +1 -0
  345. package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.js +47 -0
  346. package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.js.map +1 -0
  347. package/build/dist/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.js +273 -0
  348. package/build/dist/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.js.map +1 -0
  349. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationClaim.js +73 -0
  350. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationClaim.js.map +1 -0
  351. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.js +722 -0
  352. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.js.map +1 -0
  353. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationFanOut.js +102 -0
  354. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationFanOut.js.map +1 -0
  355. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.js +527 -0
  356. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.js.map +1 -0
  357. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationResendAccess.js +278 -0
  358. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationResendAccess.js.map +1 -0
  359. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationRunLimit.js +137 -0
  360. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationRunLimit.js.map +1 -0
  361. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationTiming.js +103 -0
  362. package/build/dist/Server/Utils/StatusPage/SubscriberNotificationTiming.js.map +1 -0
  363. package/build/dist/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.js +114 -0
  364. package/build/dist/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.js.map +1 -0
  365. package/build/dist/Server/Utils/StatusPageResource.js +39 -7
  366. package/build/dist/Server/Utils/StatusPageResource.js.map +1 -1
  367. package/build/dist/Server/Utils/VM/VMAPI.js.map +1 -1
  368. package/build/dist/Server/Utils/VM/VMRunner.js +1 -0
  369. package/build/dist/Server/Utils/VM/VMRunner.js.map +1 -1
  370. package/build/dist/Server/Utils/Workflow/OAuth2TokenClient.js +3 -0
  371. package/build/dist/Server/Utils/Workflow/OAuth2TokenClient.js.map +1 -1
  372. package/build/dist/Types/CustomField/CustomFieldOrder.js +36 -0
  373. package/build/dist/Types/CustomField/CustomFieldOrder.js.map +1 -0
  374. package/build/dist/Types/CustomField/CustomFieldSavedViews.js +135 -0
  375. package/build/dist/Types/CustomField/CustomFieldSavedViews.js.map +1 -0
  376. package/build/dist/Types/CustomField/CustomFieldTemplateMerge.js +27 -0
  377. package/build/dist/Types/CustomField/CustomFieldTemplateMerge.js.map +1 -0
  378. package/build/dist/Types/CustomField/CustomFieldType.js +12 -0
  379. package/build/dist/Types/CustomField/CustomFieldType.js.map +1 -1
  380. package/build/dist/Types/CustomField/CustomFieldValueFormat.js +126 -0
  381. package/build/dist/Types/CustomField/CustomFieldValueFormat.js.map +1 -0
  382. package/build/dist/Types/CustomField/CustomFieldValueValidator.js +280 -0
  383. package/build/dist/Types/CustomField/CustomFieldValueValidator.js.map +1 -0
  384. package/build/dist/Types/CustomField/CustomFieldVariableKey.js +150 -0
  385. package/build/dist/Types/CustomField/CustomFieldVariableKey.js.map +1 -0
  386. package/build/dist/Types/SafeHtml.js +84 -0
  387. package/build/dist/Types/SafeHtml.js.map +1 -0
  388. package/build/dist/Types/StatusPage/IncidentCreatedRenotify.js +117 -0
  389. package/build/dist/Types/StatusPage/IncidentCreatedRenotify.js.map +1 -0
  390. package/build/dist/Types/StatusPage/IncidentCreatedResend.js +86 -0
  391. package/build/dist/Types/StatusPage/IncidentCreatedResend.js.map +1 -0
  392. package/build/dist/Types/StatusPage/IncidentScopeAddedPagesNotification.js +246 -0
  393. package/build/dist/Types/StatusPage/IncidentScopeAddedPagesNotification.js.map +1 -0
  394. package/build/dist/Types/StatusPage/IncidentSubscriberAudience.js +183 -0
  395. package/build/dist/Types/StatusPage/IncidentSubscriberAudience.js.map +1 -0
  396. package/build/dist/Types/StatusPage/StatusPageSubscriberUnsubscribe.js +277 -0
  397. package/build/dist/Types/StatusPage/StatusPageSubscriberUnsubscribe.js.map +1 -0
  398. package/build/dist/Types/StatusPage/SubscriberNotificationInterruption.js +27 -0
  399. package/build/dist/Types/StatusPage/SubscriberNotificationInterruption.js.map +1 -0
  400. package/build/dist/Types/StatusPage/SubscriberNotificationPreview.js +190 -0
  401. package/build/dist/Types/StatusPage/SubscriberNotificationPreview.js.map +1 -0
  402. package/build/dist/Types/StatusPage/SubscriberNotificationResend.js +102 -0
  403. package/build/dist/Types/StatusPage/SubscriberNotificationResend.js.map +1 -0
  404. package/build/dist/Types/StatusPage/SubscriberNotificationTemplateCompiler.js +97 -0
  405. package/build/dist/Types/StatusPage/SubscriberNotificationTemplateCompiler.js.map +1 -0
  406. package/build/dist/Types/StatusPage/SubscriberNotificationTemplatePreview.js +175 -0
  407. package/build/dist/Types/StatusPage/SubscriberNotificationTemplatePreview.js.map +1 -0
  408. package/build/dist/Types/StatusPage/SubscriberNotificationTemplateVariables.js +144 -4
  409. package/build/dist/Types/StatusPage/SubscriberNotificationTemplateVariables.js.map +1 -1
  410. package/build/dist/Types/StatusPage/SubscriberUpdateNotification.js +29 -9
  411. package/build/dist/Types/StatusPage/SubscriberUpdateNotification.js.map +1 -1
  412. package/build/dist/UI/Components/CustomFields/CustomFieldFormFields.js +169 -0
  413. package/build/dist/UI/Components/CustomFields/CustomFieldFormFields.js.map +1 -0
  414. package/build/dist/UI/Components/CustomFields/CustomFieldModelFormFields.js +212 -0
  415. package/build/dist/UI/Components/CustomFields/CustomFieldModelFormFields.js.map +1 -0
  416. package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js +64 -49
  417. package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js.map +1 -1
  418. package/build/dist/UI/Components/Forms/ModelForm.js +39 -5
  419. package/build/dist/UI/Components/Forms/ModelForm.js.map +1 -1
  420. package/build/dist/UI/Components/Forms/Validation.js +1 -1
  421. package/build/dist/UI/Components/Forms/Validation.js.map +1 -1
  422. package/build/dist/UI/Components/ModelFormModal/ModelFormModal.js.map +1 -1
  423. package/build/dist/UI/Components/ModelTable/AnalyticsModelTable.js.map +1 -1
  424. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +2 -2
  425. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  426. package/build/dist/UI/Components/ModelTable/CustomFieldColumns.js +13 -1
  427. package/build/dist/UI/Components/ModelTable/CustomFieldColumns.js.map +1 -1
  428. package/build/dist/UI/Components/ModelTable/ModelTable.js +1 -1
  429. package/build/dist/UI/Components/ModelTable/ModelTable.js.map +1 -1
  430. package/build/dist/UI/Utils/SensitiveUrlToken.js +10 -5
  431. package/build/dist/UI/Utils/SensitiveUrlToken.js.map +1 -1
  432. package/build/dist/Utils/API.js +177 -1
  433. package/build/dist/Utils/API.js.map +1 -1
  434. package/build/dist/Utils/Incident/IncidentNoteTemplateVariables.js +155 -0
  435. package/build/dist/Utils/Incident/IncidentNoteTemplateVariables.js.map +1 -0
  436. package/build/dist/Utils/Markdown/MarkdownEscape.js +48 -0
  437. package/build/dist/Utils/Markdown/MarkdownEscape.js.map +1 -1
  438. package/build/dist/Utils/ProbeNetworkFailureUtil.js +460 -0
  439. package/build/dist/Utils/ProbeNetworkFailureUtil.js.map +1 -0
  440. package/package.json +1 -1
@@ -14,6 +14,9 @@ import QueryHelper from "../Types/Database/QueryHelper";
14
14
  import DatabaseService from "./DatabaseService";
15
15
  import IncidentCustomField from "../../Models/DatabaseModels/IncidentCustomField";
16
16
  import CustomFieldMappingService from "./CustomFieldMappingService";
17
+ import IncidentCustomFieldService from "./IncidentCustomFieldService";
18
+ import { mergeTemplateCustomFields } from "../../Types/CustomField/CustomFieldTemplateMerge";
19
+ import { formatCustomFieldValueValidationErrors, validateCustomFieldValues, } from "../../Types/CustomField/CustomFieldValueValidator";
17
20
  import AIRunService from "./AIRunService";
18
21
  import AIRunType from "../../Types/AI/AIRunType";
19
22
  import AIRunStatus from "../../Types/AI/AIRunStatus";
@@ -39,6 +42,14 @@ import { getAffectedResourceRelations } from "../Utils/Database/AffectedResource
39
42
  import SloRecordReferenceValidator from "../Utils/Slo/SloRecordReferenceValidator";
40
43
  import UserNotificationEventType from "../../Types/UserNotification/UserNotificationEventType";
41
44
  import StatusPageSubscriberNotificationStatus from "../../Types/StatusPage/StatusPageSubscriberNotificationStatus";
45
+ import IncidentCreatedRenotify from "../../Types/StatusPage/IncidentCreatedRenotify";
46
+ import IncidentCreatedResend from "../../Types/StatusPage/IncidentCreatedResend";
47
+ import IncidentScopeAddedPagesNotification, { IncidentScopeAddedPagesNotificationAction, } from "../../Types/StatusPage/IncidentScopeAddedPagesNotification";
48
+ import NotAuthorizedException from "../../Types/Exception/NotAuthorizedException";
49
+ import StatusPage from "../../Models/DatabaseModels/StatusPage";
50
+ import StatusPageService from "./StatusPageService";
51
+ import StatusPageReadAccess from "../Utils/StatusPage/StatusPageReadAccess";
52
+ import SubscriberNotificationResendAccess from "../Utils/StatusPage/SubscriberNotificationResendAccess";
42
53
  import DockerHost from "../../Models/DatabaseModels/DockerHost";
43
54
  import PodmanHost from "../../Models/DatabaseModels/PodmanHost";
44
55
  import Host from "../../Models/DatabaseModels/Host";
@@ -57,6 +68,7 @@ import ServiceType from "../../Types/Telemetry/ServiceType";
57
68
  import OneUptimeDate from "../../Types/Date";
58
69
  import TelemetryUtil from "../Utils/Telemetry/Telemetry";
59
70
  import MetricResourceAttributeUtil from "../../Utils/Metrics/MetricResourceAttributeUtil";
71
+ import { escapeMarkdownInline } from "../../Utils/Markdown/MarkdownEscape";
60
72
  import logger from "../Utils/Logger";
61
73
  import ProductAnalytics from "../Utils/ProductAnalytics";
62
74
  import Semaphore from "../Infrastructure/Semaphore";
@@ -325,6 +337,15 @@ export class Service extends DatabaseService {
325
337
  if (updateBy.data.isPrivate === true) {
326
338
  updateBy.data.isVisibleOnStatusPage = false;
327
339
  }
340
+ this.stripServiceOwnedScopeColumns(updateBy);
341
+ /*
342
+ * Before anything below adds values of its own to customFields (the
343
+ * mapped values copied from monitors), so only what the caller wrote is
344
+ * checked.
345
+ */
346
+ await this.validateCustomFieldValuesOnUpdate(updateBy);
347
+ // Before the hooks below add a Pending of their own.
348
+ const isCreatedNotificationResendRequested = this.isCreatedNotificationResendRequested(updateBy);
328
349
  await this.validateProjectScopedReferences(updateBy);
329
350
  const carryForward = {};
330
351
  if (updateBy.data.monitors ||
@@ -401,6 +422,30 @@ export class Service extends DatabaseService {
401
422
  StatusPageSubscriberNotificationStatus.Pending;
402
423
  }
403
424
  }
425
+ await this.queueCreatedNotificationResendToAllStatusPagesIfRequested(updateBy);
426
+ /*
427
+ * Retry or Resend - a user's Pending - over a notification that is
428
+ * being sent would let a second run send it alongside, or be
429
+ * overwritten when the send settles (SubscriberNotificationResendAccess).
430
+ * 'Resend to all pages' above has refused that already, with its own
431
+ * reason; the hooks below queue their own Pending only from a settled
432
+ * state.
433
+ */
434
+ await SubscriberNotificationResendAccess.assertNotQueuedWhileBeingSent({
435
+ modelType: Model,
436
+ service: this,
437
+ updateBy: updateBy,
438
+ statusColumns: [
439
+ "subscriberNotificationStatusOnIncidentCreated",
440
+ "subscriberNotificationStatusOnPostmortemPublished",
441
+ ],
442
+ });
443
+ await this.clearCreatedNotificationRecordOnResend({
444
+ updateBy: updateBy,
445
+ isResendRequested: isCreatedNotificationResendRequested,
446
+ });
447
+ await this.queueCreatedNotificationOnPublishIfRequested(updateBy);
448
+ await this.applyStatusPageScopeToUpdate(updateBy, carryForward);
404
449
  /*
405
450
  * Re-apply mapped custom field values. Covers the Custom Fields modal
406
451
  * saving the whole bag back over a mapped value, and the incident's
@@ -417,6 +462,814 @@ export class Service extends DatabaseService {
417
462
  carryForward: carryForward,
418
463
  };
419
464
  }
465
+ /*
466
+ * The incidents an update will write to, as they are stored, for the hooks
467
+ * below that decide what else joins the update.
468
+ *
469
+ * Read as root: the answer only decides which columns join this update, and
470
+ * the update itself is still checked against the caller's permissions
471
+ * afterwards. Reading with the caller's props would fail the whole edit for
472
+ * a role that may edit incidents but not read these columns. The query
473
+ * already carries the caller's privacy filter (applyIncidentSelfPrivacyFilter),
474
+ * but not their tenant: the update's permission check adds it only after
475
+ * this hook runs. So a non-root caller's read is limited to their own
476
+ * project here, or a request for another project's incident id would be
477
+ * answered with that incident's state (a refusal that depends on it)
478
+ * instead of the usual "nothing updated".
479
+ */
480
+ async findIncidentsForUpdateHook(data) {
481
+ const updateBy = data.updateBy;
482
+ const query = !updateBy.props.isRoot && updateBy.props.tenantId
483
+ ? Object.assign(Object.assign({}, updateBy.query), { projectId: updateBy.props.tenantId }) : updateBy.query;
484
+ return await this.findBy({
485
+ query: query,
486
+ select: data.select,
487
+ limit: LIMIT_MAX,
488
+ skip: 0,
489
+ props: {
490
+ isRoot: true,
491
+ },
492
+ });
493
+ }
494
+ /*
495
+ * CUSTOM FIELD VALUES must fit their fields: a Number field holds a number,
496
+ * a Dropdown one of its options (CustomFieldValueValidator has the rules).
497
+ *
498
+ * Only for writes a user or an API key makes. Root writes - the server's
499
+ * own, such as values copied from monitors or an incident template - are
500
+ * trusted, and the mapped values are added after this runs, so they never
501
+ * reach it. Only the keys a write changes are checked, so a value stored
502
+ * before these checks, or a dropdown option removed since, does not stop
503
+ * someone saving the rest of the card.
504
+ *
505
+ * "Required on create" is not enforced here: incidents created by
506
+ * monitors, the API, Slack, Microsoft Teams or AI cannot fill in a form.
507
+ */
508
+ async getCustomFieldDefinitionsForValidation(projectId) {
509
+ const definitions = await IncidentCustomFieldService.findBy({
510
+ query: {
511
+ projectId: projectId,
512
+ },
513
+ select: {
514
+ name: true,
515
+ customFieldType: true,
516
+ dropdownOptions: true,
517
+ },
518
+ limit: LIMIT_PER_PROJECT,
519
+ skip: 0,
520
+ props: {
521
+ isRoot: true,
522
+ },
523
+ });
524
+ const result = [];
525
+ for (const definition of definitions) {
526
+ if (typeof definition.name !== "string") {
527
+ continue;
528
+ }
529
+ result.push({
530
+ name: definition.name,
531
+ customFieldType: definition.customFieldType,
532
+ dropdownOptions: definition.dropdownOptions,
533
+ });
534
+ }
535
+ return result;
536
+ }
537
+ hasCustomFieldValuesToValidate(customFields) {
538
+ return (customFields !== null &&
539
+ typeof customFields === "object" &&
540
+ !Array.isArray(customFields) &&
541
+ Object.keys(customFields).length > 0);
542
+ }
543
+ throwIfCustomFieldValuesInvalid(errors) {
544
+ if (errors.length > 0) {
545
+ throw new BadDataException(formatCustomFieldValueValidationErrors(errors));
546
+ }
547
+ }
548
+ async validateCustomFieldValuesOnCreate(data) {
549
+ const customFields = data.createBy.data.customFields;
550
+ if (data.createBy.props.isRoot ||
551
+ !data.projectId ||
552
+ !this.hasCustomFieldValuesToValidate(customFields)) {
553
+ return;
554
+ }
555
+ this.throwIfCustomFieldValuesInvalid(validateCustomFieldValues({
556
+ definitions: await this.getCustomFieldDefinitionsForValidation(data.projectId),
557
+ customFields: customFields,
558
+ storedCustomFields: {},
559
+ }));
560
+ }
561
+ /*
562
+ * Checked against each incident the update writes, because what counts as
563
+ * changed depends on what that incident already holds.
564
+ */
565
+ async validateCustomFieldValuesOnUpdate(updateBy) {
566
+ const customFields = updateBy.data.customFields;
567
+ if (updateBy.props.isRoot ||
568
+ !this.hasCustomFieldValuesToValidate(customFields)) {
569
+ return;
570
+ }
571
+ const incidents = await this.findIncidentsForUpdateHook({
572
+ updateBy: updateBy,
573
+ select: {
574
+ _id: true,
575
+ projectId: true,
576
+ customFields: true,
577
+ },
578
+ });
579
+ const definitionsByProject = new Map();
580
+ for (const incident of incidents) {
581
+ if (!incident.projectId) {
582
+ continue;
583
+ }
584
+ const projectKey = incident.projectId.toString();
585
+ if (!definitionsByProject.has(projectKey)) {
586
+ definitionsByProject.set(projectKey, await this.getCustomFieldDefinitionsForValidation(incident.projectId));
587
+ }
588
+ this.throwIfCustomFieldValuesInvalid(validateCustomFieldValues({
589
+ definitions: definitionsByProject.get(projectKey),
590
+ customFields: customFields,
591
+ storedCustomFields: incident.customFields,
592
+ }));
593
+ }
594
+ }
595
+ /*
596
+ * isScopedToStatusPages and statusPagesNotifiedOnCreation are this
597
+ * service's to write. A client value for either is dropped before any hook
598
+ * runs, so what the hooks write is all that is written: the flag is derived
599
+ * from statusPages (applyStatusPageScopeToUpdate), and the record is the
600
+ * notification job's - a client must not be able to seed it and so keep
601
+ * pages from ever hearing about the incident, or clear it and have them
602
+ * told twice. Root (internal) callers keep the record they send.
603
+ */
604
+ stripServiceOwnedScopeColumns(updateBy) {
605
+ const data = updateBy.data;
606
+ delete data["isScopedToStatusPages"];
607
+ if (!updateBy.props.isRoot) {
608
+ delete data["statusPagesNotifiedOnCreation"];
609
+ }
610
+ }
611
+ /*
612
+ * Whether an update itself asks for the 'created' notification to go out
613
+ * again: it sets the status to Pending - the API route of resending it,
614
+ * and the dashboard's Retry - turns notifying on creation on, which
615
+ * onBeforeUpdate maps to Pending, or asks for it to be sent to every
616
+ * status page again (IncidentCreatedResend, the dashboard's Resend). Read
617
+ * before any hook adds a Pending of its own.
618
+ */
619
+ isCreatedNotificationResendRequested(updateBy) {
620
+ return (updateBy.data.subscriberNotificationStatusOnIncidentCreated ===
621
+ StatusPageSubscriberNotificationStatus.Pending ||
622
+ updateBy.data.shouldStatusPageSubscribersBeNotifiedOnIncidentCreated ===
623
+ true ||
624
+ IncidentCreatedResend.isRequested(updateBy.miscDataProps));
625
+ }
626
+ /*
627
+ * 'Resend to all pages' (see IncidentCreatedResend): the 'created'
628
+ * notification goes back to Pending with a message saying so, and
629
+ * clearCreatedNotificationRecordOnResend empties its record of told pages
630
+ * in the same write, so the job sends it to every page the incident
631
+ * reaches now - after a failure too, where a plain Retry would resume.
632
+ *
633
+ * Everything is written into the caller's own update, so it lands with the
634
+ * rest of it or not at all, and the column check that runs after this hook
635
+ * still decides whether the caller may write the status. That check is
636
+ * also made here first, before the incidents are read: the refusals below
637
+ * depend on the notification's state, and a caller who may not send it
638
+ * again is told only that. The incidents are then read with the caller's
639
+ * own permissions (and the privacy filter already on the query), so an
640
+ * incident they cannot see never decides the answer; when they can see
641
+ * none of those the update matches, nothing is queued.
642
+ *
643
+ * Refused - with the reason, rather than silently dropped, because asking
644
+ * for it is the whole point of the request - when any matched incident's
645
+ * notification did not go out (Skipped) or is on its way (Pending,
646
+ * InProgress), and when the same update sets the status to anything but
647
+ * Pending.
648
+ */
649
+ async queueCreatedNotificationResendToAllStatusPagesIfRequested(updateBy) {
650
+ if (!IncidentCreatedResend.isRequested(updateBy.miscDataProps)) {
651
+ return;
652
+ }
653
+ const requestedStatus = updateBy.data.subscriberNotificationStatusOnIncidentCreated;
654
+ if (requestedStatus !== undefined &&
655
+ requestedStatus !== StatusPageSubscriberNotificationStatus.Pending) {
656
+ throw new BadDataException(IncidentCreatedResend.conflictingStatusMessage);
657
+ }
658
+ SubscriberNotificationResendAccess.assertCallerMayUpdateColumns({
659
+ modelType: Model,
660
+ columns: {
661
+ subscriberNotificationStatusOnIncidentCreated: StatusPageSubscriberNotificationStatus.Pending,
662
+ subscriberNotificationStatusMessage: IncidentCreatedResend.queuedMessage,
663
+ statusPagesNotifiedOnCreation: [],
664
+ },
665
+ props: updateBy.props,
666
+ refusal: IncidentCreatedResend.noPermissionMessage,
667
+ });
668
+ const incidents = await this.findBy({
669
+ query: updateBy.query,
670
+ select: {
671
+ _id: true,
672
+ subscriberNotificationStatusOnIncidentCreated: true,
673
+ },
674
+ limit: LIMIT_MAX,
675
+ skip: 0,
676
+ props: updateBy.props,
677
+ });
678
+ for (const incident of incidents) {
679
+ const refusal = IncidentCreatedResend.getRefusalReason(incident.subscriberNotificationStatusOnIncidentCreated);
680
+ if (refusal) {
681
+ throw new BadDataException(refusal);
682
+ }
683
+ }
684
+ if (incidents.length === 0) {
685
+ return;
686
+ }
687
+ updateBy.data.subscriberNotificationStatusOnIncidentCreated =
688
+ StatusPageSubscriberNotificationStatus.Pending;
689
+ if (updateBy.data.subscriberNotificationStatusMessage === undefined) {
690
+ updateBy.data.subscriberNotificationStatusMessage =
691
+ IncidentCreatedResend.queuedMessage;
692
+ }
693
+ }
694
+ /*
695
+ * A resend asked for by the update itself (see
696
+ * isCreatedNotificationResendRequested) goes to every status page, as it
697
+ * always did. The job skips the pages in its record of told pages
698
+ * (Incident.statusPagesNotifiedOnCreation), so without this a resend of a
699
+ * notification that went out would reach nobody: the record is emptied in
700
+ * the same write.
701
+ *
702
+ * It is kept in three cases:
703
+ * - Failed: Retry resumes where the failed send stopped, so the pages it
704
+ * told are not told twice - unless the update asks for it to go to every
705
+ * page again (IncidentCreatedResend), which is what that request is for;
706
+ * - Pending or InProgress: the notification is on its way already, and its
707
+ * record is what keeps a send queued for added pages from reaching the
708
+ * pages told before (IncidentCreatedResend refuses these);
709
+ * - a root caller that writes the record itself.
710
+ *
711
+ * An update matching several incidents empties the record when any of them
712
+ * would otherwise be resent to nobody, because the write applies the same
713
+ * data to all of them.
714
+ */
715
+ async clearCreatedNotificationRecordOnResend(data) {
716
+ const updateBy = data.updateBy;
717
+ if (!data.isResendRequested) {
718
+ return;
719
+ }
720
+ if (updateBy.data["statusPagesNotifiedOnCreation"] !== undefined) {
721
+ return;
722
+ }
723
+ if (IncidentCreatedResend.isRequested(updateBy.miscDataProps)) {
724
+ /*
725
+ * Queued for every page by
726
+ * queueCreatedNotificationResendToAllStatusPagesIfRequested, which
727
+ * left the status alone when the caller can see none of the incidents
728
+ * the update matches: nothing to read to decide.
729
+ */
730
+ if (updateBy.data.subscriberNotificationStatusOnIncidentCreated ===
731
+ StatusPageSubscriberNotificationStatus.Pending) {
732
+ updateBy.data.statusPagesNotifiedOnCreation = [];
733
+ }
734
+ return;
735
+ }
736
+ const incidents = await this.findIncidentsForUpdateHook({
737
+ updateBy: updateBy,
738
+ select: {
739
+ _id: true,
740
+ subscriberNotificationStatusOnIncidentCreated: true,
741
+ },
742
+ });
743
+ const someIncidentWouldReachNobody = incidents.some((incident) => {
744
+ return ![
745
+ StatusPageSubscriberNotificationStatus.Failed,
746
+ StatusPageSubscriberNotificationStatus.Pending,
747
+ StatusPageSubscriberNotificationStatus.InProgress,
748
+ ].includes(incident.subscriberNotificationStatusOnIncidentCreated);
749
+ });
750
+ if (someIncidentWouldReachNobody) {
751
+ updateBy.data.statusPagesNotifiedOnCreation = [];
752
+ }
753
+ }
754
+ /*
755
+ * Publishing a hidden incident can announce it: when the editor turns
756
+ * 'Visible on Status Page' on and ticks "Notify subscribers that this
757
+ * incident was created" (see IncidentCreatedRenotify), the incident's
758
+ * 'created' notification goes back to Pending, and the
759
+ * Incident:SendNotificationToSubscribers job sends it now that the incident
760
+ * is visible - to the pages its record of told pages does not list, so an
761
+ * incident whose notification went out before it was hidden tells only the
762
+ * pages added while it was hidden.
763
+ *
764
+ * It only ever re-queues a notification with someone left to tell, for an
765
+ * incident that is hidden today, not private, and meant to notify on
766
+ * creation, so a stray request cannot email subscribers twice or break a
767
+ * deliberate "don't notify". The status is written into this same update,
768
+ * so it lands together with the visibility change or not at all. The
769
+ * column (and its message) are computed, but their update ACL lists the
770
+ * incident roles, so a non-root edit still passes the column check that
771
+ * runs after this hook.
772
+ *
773
+ * An update that sets the status itself - the API route of resetting it to
774
+ * Pending, or the notify-on-create flag above - is left alone. An update
775
+ * that matches several incidents queues only when every one of them
776
+ * qualifies, because the write applies the same data to all of them.
777
+ */
778
+ async queueCreatedNotificationOnPublishIfRequested(updateBy) {
779
+ if (!IncidentCreatedRenotify.isRequested(updateBy.miscDataProps)) {
780
+ return;
781
+ }
782
+ if (updateBy.data.isVisibleOnStatusPage !== true) {
783
+ return;
784
+ }
785
+ if (updateBy.data.subscriberNotificationStatusOnIncidentCreated !== undefined) {
786
+ return;
787
+ }
788
+ const incidents = await this.findIncidentsForUpdateHook({
789
+ updateBy: updateBy,
790
+ select: {
791
+ _id: true,
792
+ isVisibleOnStatusPage: true,
793
+ isPrivate: true,
794
+ subscriberNotificationStatusOnIncidentCreated: true,
795
+ shouldStatusPageSubscribersBeNotifiedOnIncidentCreated: true,
796
+ statusPagesNotifiedOnCreation: true,
797
+ statusPages: {
798
+ _id: true,
799
+ },
800
+ },
801
+ });
802
+ if (incidents.length === 0) {
803
+ return;
804
+ }
805
+ const everyIncidentQualifies = incidents.every((incident) => {
806
+ return IncidentCreatedRenotify.canRenotifyOnPublish({
807
+ isVisibleOnStatusPage: incident.isVisibleOnStatusPage,
808
+ isPrivate: updateBy.data.isPrivate !== undefined &&
809
+ updateBy.data.isPrivate !== null
810
+ ? updateBy.data.isPrivate
811
+ : incident.isPrivate,
812
+ subscriberNotificationStatusOnIncidentCreated: incident.subscriberNotificationStatusOnIncidentCreated,
813
+ shouldStatusPageSubscribersBeNotifiedOnIncidentCreated: incident.shouldStatusPageSubscribersBeNotifiedOnIncidentCreated,
814
+ // The pages it is limited to once this update is written.
815
+ statusPages: updateBy.data.statusPages !== undefined
816
+ ? updateBy.data.statusPages
817
+ : incident.statusPages,
818
+ statusPagesNotifiedOnCreation: incident.statusPagesNotifiedOnCreation,
819
+ });
820
+ });
821
+ if (!everyIncidentQualifies) {
822
+ logger.debug(`Not re-queueing the incident created notification on publish: ${incidents.length} incident(s) matched and not all of them were hidden, set to notify subscribers and had subscribers left to tell.`);
823
+ return;
824
+ }
825
+ updateBy.data.subscriberNotificationStatusOnIncidentCreated =
826
+ StatusPageSubscriberNotificationStatus.Pending;
827
+ updateBy.data.subscriberNotificationStatusMessage =
828
+ IncidentCreatedRenotify.queuedMessage;
829
+ }
830
+ /*
831
+ * The status pages a new incident is limited to (Incident.statusPages), and
832
+ * the two columns that follow from them.
833
+ *
834
+ * isScopedToStatusPages is derived from the list, whatever the caller sent
835
+ * for it: the column is computed, which exempts it from the column check on
836
+ * create, so a client value would otherwise be stored as is - and a scoped
837
+ * flag with no pages hides the incident from every status page.
838
+ *
839
+ * statusPagesNotifiedOnCreation is the created-notification job's record of
840
+ * the pages it told. A client must not be able to seed it and so keep pages
841
+ * from ever hearing about the incident; only root (internal) callers keep
842
+ * what they send.
843
+ *
844
+ * The pages a non-root caller picks must be pages they can read (see
845
+ * StatusPageReadAccess), except the pages of an incident template they can
846
+ * read: the dashboard fills a template's pages in for everyone who declares
847
+ * from it, which is what the template is for. Pages copied from a template
848
+ * on the server are not the caller's pick. That is checked once the pages
849
+ * are known to be the project's (assertCallerCanPickStatusPagesOnCreate).
850
+ *
851
+ * `isScopedToNothingByTemplate`: declared through the API from a template
852
+ * whose status pages were all deleted. The incident is scoped with no
853
+ * pages - hidden from every status page - rather than unscoped.
854
+ */
855
+ applyStatusPageScopeToCreate(data) {
856
+ const createBy = data.createBy;
857
+ if (!createBy.props.isRoot) {
858
+ delete createBy.data.statusPagesNotifiedOnCreation;
859
+ }
860
+ const statusPageIds = IncidentScopeAddedPagesNotification.normalizeStatusPageIds(createBy.data.statusPages);
861
+ if (createBy.data.statusPages !== undefined &&
862
+ createBy.data.statusPages !== null) {
863
+ createBy.data.statusPages = this.toStatusPageStubs(statusPageIds);
864
+ }
865
+ createBy.data.isScopedToStatusPages =
866
+ statusPageIds.length > 0 || data.isScopedToNothingByTemplate === true;
867
+ }
868
+ /*
869
+ * The pages a non-root caller picks for a new incident must be pages they
870
+ * can read (see applyStatusPageScopeToCreate). Runs after the project check,
871
+ * so another project's page, or one that does not exist, is reported as
872
+ * such rather than as a page the caller cannot read.
873
+ */
874
+ async assertCallerCanPickStatusPagesOnCreate(data) {
875
+ const createBy = data.createBy;
876
+ const statusPageIds = IncidentScopeAddedPagesNotification.normalizeStatusPageIds(createBy.data.statusPages);
877
+ if (createBy.props.isRoot ||
878
+ !data.statusPagesFromCaller ||
879
+ statusPageIds.length === 0) {
880
+ return;
881
+ }
882
+ const readableStatusPageIds = await StatusPageReadAccess.getReadableStatusPageIds({
883
+ statusPageIds: statusPageIds,
884
+ props: createBy.props,
885
+ });
886
+ let unreadableStatusPageIds = statusPageIds.filter((id) => {
887
+ return !readableStatusPageIds.includes(id);
888
+ });
889
+ if (unreadableStatusPageIds.length > 0) {
890
+ const templateStatusPageIds = await this.getStatusPageIdsOfTemplatesReadableByCaller({
891
+ projectId: data.projectId,
892
+ props: createBy.props,
893
+ });
894
+ unreadableStatusPageIds = unreadableStatusPageIds.filter((id) => {
895
+ return !templateStatusPageIds.includes(id);
896
+ });
897
+ }
898
+ if (unreadableStatusPageIds.length > 0) {
899
+ throw new NotAuthorizedException(StatusPageReadAccess.getRefusalMessage("incident"));
900
+ }
901
+ }
902
+ /*
903
+ * The status pages the incident templates the caller can read are limited
904
+ * to. Such a page may be picked for a new incident without reading it:
905
+ * declaring from the template picks it anyway. The templates are read with
906
+ * the caller's permissions (and labels); their pages as root. A caller who
907
+ * cannot read templates at all gets none.
908
+ */
909
+ async getStatusPageIdsOfTemplatesReadableByCaller(data) {
910
+ let templates = [];
911
+ try {
912
+ templates = await IncidentTemplateService.findBy({
913
+ query: {
914
+ projectId: data.projectId,
915
+ },
916
+ select: {
917
+ _id: true,
918
+ },
919
+ limit: LIMIT_MAX,
920
+ skip: 0,
921
+ props: data.props,
922
+ });
923
+ }
924
+ catch (err) {
925
+ // No access to templates (or not on a plan that has them): no pages.
926
+ logger.debug(`Could not read the caller's incident templates while checking the status pages of a new incident: ${err}`);
927
+ return [];
928
+ }
929
+ if (templates.length === 0) {
930
+ return [];
931
+ }
932
+ const templatesWithPages = await IncidentTemplateService.findBy({
933
+ query: {
934
+ _id: QueryHelper.any(templates.map((template) => {
935
+ return template.id.toString();
936
+ })),
937
+ projectId: data.projectId,
938
+ },
939
+ select: {
940
+ _id: true,
941
+ statusPages: {
942
+ _id: true,
943
+ },
944
+ },
945
+ limit: LIMIT_MAX,
946
+ skip: 0,
947
+ props: {
948
+ isRoot: true,
949
+ },
950
+ });
951
+ return IncidentScopeAddedPagesNotification.normalizeStatusPageIds(templatesWithPages.flatMap((template) => {
952
+ return template.statusPages || [];
953
+ }));
954
+ }
955
+ /*
956
+ * The status pages an incident is limited to, on update. Everything that
957
+ * follows from a write to Incident.statusPages happens here, in the
958
+ * caller's own update, so the list, the flag and a re-queued notification
959
+ * land together or not at all:
960
+ *
961
+ * - isScopedToStatusPages is derived from the list the update writes (a
962
+ * value the caller sent for it was dropped by
963
+ * stripServiceOwnedScopeColumns). Nothing else ever sets it, and it is
964
+ * never recomputed when join rows disappear: deleting the only page an
965
+ * incident is scoped to leaves it scoped to nothing, hidden from every
966
+ * page, rather than widened to all of them;
967
+ * - a non-root caller's list is topped up with the pages the incident is
968
+ * scoped to that the caller cannot read. Status pages are label-scoped,
969
+ * so an editor may see only some of an incident's pages, and a list write
970
+ * replaces the whole list (the dashboard sends back what the editor
971
+ * sees). Without this, saving the incident would silently drop every page
972
+ * the editor was not shown;
973
+ * - the pages a non-root caller adds must be pages they can read (see
974
+ * StatusPageReadAccess);
975
+ * - with IncidentScopeAddedPagesNotification requested, the 'created'
976
+ * notification is queued again for the pages the update adds;
977
+ * - what was added and removed is carried forward for the feed item
978
+ * onUpdateSuccess writes, and so is whether the notification was on its
979
+ * way already, which onUpdateSuccess checks again once the pages are
980
+ * written.
981
+ *
982
+ * The flag and the notification columns are computed, but their update
983
+ * access control lists every role that may edit statusPages, so a non-root
984
+ * edit passes the column check that runs after this hook.
985
+ */
986
+ async applyStatusPageScopeToUpdate(updateBy, carryForward) {
987
+ const data = updateBy.data;
988
+ if (data["statusPages"] === undefined) {
989
+ return;
990
+ }
991
+ const incidents = await this.findIncidentsForUpdateHook({
992
+ updateBy: updateBy,
993
+ select: {
994
+ _id: true,
995
+ statusPages: {
996
+ _id: true,
997
+ },
998
+ isVisibleOnStatusPage: true,
999
+ isPrivate: true,
1000
+ subscriberNotificationStatusOnIncidentCreated: true,
1001
+ shouldStatusPageSubscribersBeNotifiedOnIncidentCreated: true,
1002
+ statusPagesNotifiedOnCreation: true,
1003
+ },
1004
+ });
1005
+ const requestedStatusPageIds = IncidentScopeAddedPagesNotification.normalizeStatusPageIds(data["statusPages"]);
1006
+ const hiddenStatusPageIds = updateBy.props.isRoot
1007
+ ? []
1008
+ : await this.getScopedStatusPageIdsHiddenFromCaller({
1009
+ incidents: incidents,
1010
+ props: updateBy.props,
1011
+ });
1012
+ const statusPageIds = [
1013
+ ...requestedStatusPageIds,
1014
+ ...hiddenStatusPageIds.filter((id) => {
1015
+ return !requestedStatusPageIds.includes(id);
1016
+ }),
1017
+ ];
1018
+ if (!updateBy.props.isRoot) {
1019
+ await StatusPageReadAccess.assertCallerCanPickStatusPages({
1020
+ statusPageIds: this.getStatusPageIdsAddedToAny({
1021
+ incidents: incidents,
1022
+ statusPageIds: statusPageIds,
1023
+ }),
1024
+ props: updateBy.props,
1025
+ subject: "incident",
1026
+ });
1027
+ }
1028
+ data["statusPages"] = this.toStatusPageStubs(statusPageIds);
1029
+ data["isScopedToStatusPages"] = statusPageIds.length > 0;
1030
+ const decisions = [];
1031
+ for (const incident of incidents) {
1032
+ const incidentId = incident.id.toString();
1033
+ const change = IncidentScopeAddedPagesNotification.getScopeChange({
1034
+ before: incident.statusPages,
1035
+ after: statusPageIds,
1036
+ });
1037
+ const action = IncidentScopeAddedPagesNotification.getAction({
1038
+ addedStatusPageIds: change.addedStatusPageIds,
1039
+ incident: {
1040
+ subscriberNotificationStatusOnIncidentCreated: incident.subscriberNotificationStatusOnIncidentCreated,
1041
+ shouldStatusPageSubscribersBeNotifiedOnIncidentCreated: incident.shouldStatusPageSubscribersBeNotifiedOnIncidentCreated,
1042
+ isVisibleOnStatusPage: this.getValueAfterUpdate(updateBy.data.isVisibleOnStatusPage, incident.isVisibleOnStatusPage),
1043
+ isPrivate: this.getValueAfterUpdate(updateBy.data.isPrivate, incident.isPrivate),
1044
+ statusPagesNotifiedOnCreation: incident.statusPagesNotifiedOnCreation,
1045
+ },
1046
+ });
1047
+ carryForward[incidentId] = Object.assign(Object.assign({ monitorsRemoved: [], monitorsAdded: [], oldChangeMonitorStatusIdTo: undefined, newMonitorChangeStatusIdTo: undefined }, carryForward[incidentId]), { statusPageScopeChange: Object.assign(Object.assign({}, change), { isScoped: statusPageIds.length > 0, notificationQueued: false,
1048
+ /*
1049
+ * On its way already, and nothing in this update sets the status:
1050
+ * onUpdateSuccess makes sure the send did not finish without the
1051
+ * added pages in the meantime.
1052
+ */
1053
+ notificationAlreadyQueued: action ===
1054
+ IncidentScopeAddedPagesNotificationAction.AlreadyQueued &&
1055
+ updateBy.data.subscriberNotificationStatusOnIncidentCreated ===
1056
+ undefined }) });
1057
+ decisions.push({
1058
+ incidentId: incidentId,
1059
+ action: action,
1060
+ recordToSeed: action === IncidentScopeAddedPagesNotificationAction.Queue
1061
+ ? IncidentScopeAddedPagesNotification.getRecordToSeedOnQueue({
1062
+ statusPagesNotifiedOnCreation: incident.statusPagesNotifiedOnCreation,
1063
+ statusPageIdsBeforeUpdate: incident.statusPages,
1064
+ })
1065
+ : undefined,
1066
+ });
1067
+ }
1068
+ this.queueCreatedNotificationForAddedStatusPagesIfRequested({
1069
+ updateBy: updateBy,
1070
+ decisions: decisions,
1071
+ carryForward: carryForward,
1072
+ });
1073
+ }
1074
+ /*
1075
+ * The pages an update writing `statusPageIds` adds to at least one of the
1076
+ * incidents it matches.
1077
+ */
1078
+ getStatusPageIdsAddedToAny(data) {
1079
+ const added = [];
1080
+ for (const incident of data.incidents) {
1081
+ for (const id of IncidentScopeAddedPagesNotification.getScopeChange({
1082
+ before: incident.statusPages,
1083
+ after: data.statusPageIds,
1084
+ }).addedStatusPageIds) {
1085
+ if (!added.includes(id)) {
1086
+ added.push(id);
1087
+ }
1088
+ }
1089
+ }
1090
+ return added;
1091
+ }
1092
+ /*
1093
+ * Adding status pages to an incident's scope can tell them the incident was
1094
+ * created: with IncidentScopeAddedPagesNotification requested, the 'created'
1095
+ * notification goes back to Pending, and the job sends it to the pages it
1096
+ * has no record of telling (Incident.statusPagesNotifiedOnCreation). See
1097
+ * IncidentScopeAddedPagesNotification.getAction for when it applies.
1098
+ *
1099
+ * A notification that was never sent has no record yet, so the pages the
1100
+ * incident was limited to before are written in as the record in the same
1101
+ * write (getRecordToSeedOnQueue): the job then tells only the added pages.
1102
+ *
1103
+ * An update that sets the status itself - the API route of resetting it to
1104
+ * Pending, the notify-on-create flag, or publishing a hidden incident - is
1105
+ * left alone. An update that matches several incidents queues only when it
1106
+ * may for every one of them, because the write applies the same data to
1107
+ * all. For the same reason it cannot write a record that differs between
1108
+ * them, or overwrite the record of an incident that has one, and is refused
1109
+ * instead.
1110
+ */
1111
+ queueCreatedNotificationForAddedStatusPagesIfRequested(data) {
1112
+ var _a;
1113
+ const updateBy = data.updateBy;
1114
+ if (!IncidentScopeAddedPagesNotification.isRequested(updateBy.miscDataProps)) {
1115
+ return;
1116
+ }
1117
+ if (updateBy.data.subscriberNotificationStatusOnIncidentCreated !== undefined) {
1118
+ return;
1119
+ }
1120
+ const actions = data.decisions.map((decision) => {
1121
+ return decision.action;
1122
+ });
1123
+ if (!actions.includes(IncidentScopeAddedPagesNotificationAction.Queue)) {
1124
+ return;
1125
+ }
1126
+ const everyIncidentMayQueue = actions.every((action) => {
1127
+ return (action === IncidentScopeAddedPagesNotificationAction.Queue ||
1128
+ action === IncidentScopeAddedPagesNotificationAction.AlreadyQueued);
1129
+ });
1130
+ if (!everyIncidentMayQueue) {
1131
+ logger.debug(`Not queueing the incident created notification for added status pages: ${actions.length} incident(s) matched and not all of them gained status pages and may be announced.`);
1132
+ return;
1133
+ }
1134
+ const recordsToSeed = data.decisions
1135
+ .map((decision) => {
1136
+ return decision.recordToSeed;
1137
+ })
1138
+ .filter((record) => {
1139
+ return record !== undefined;
1140
+ });
1141
+ if (recordsToSeed.length > 0) {
1142
+ const recordToSeed = recordsToSeed[0];
1143
+ const everyIncidentTakesTheSameRecord = recordsToSeed.length === data.decisions.length &&
1144
+ recordsToSeed.every((record) => {
1145
+ return ([...record].sort().join(",") === [...recordToSeed].sort().join(","));
1146
+ });
1147
+ if (!everyIncidentTakesTheSameRecord) {
1148
+ throw new BadDataException("These incidents cannot be sent the incident-created notification for their added status pages together: they were limited to different status pages, or not all of them were ever announced. Change them one at a time.");
1149
+ }
1150
+ updateBy.data.statusPagesNotifiedOnCreation = recordToSeed;
1151
+ }
1152
+ updateBy.data.subscriberNotificationStatusOnIncidentCreated =
1153
+ StatusPageSubscriberNotificationStatus.Pending;
1154
+ updateBy.data.subscriberNotificationStatusMessage =
1155
+ IncidentScopeAddedPagesNotification.queuedMessage;
1156
+ for (const decision of data.decisions) {
1157
+ const scopeChange = (_a = data.carryForward[decision.incidentId]) === null || _a === void 0 ? void 0 : _a.statusPageScopeChange;
1158
+ if (scopeChange &&
1159
+ decision.action === IncidentScopeAddedPagesNotificationAction.Queue) {
1160
+ scopeChange.notificationQueued = true;
1161
+ }
1162
+ }
1163
+ }
1164
+ /*
1165
+ * An update that added pages while the 'created' notification was Pending
1166
+ * or being sent left the status alone: the queued send reads the scope when
1167
+ * it goes out, and a running send reads it again once it has finished (see
1168
+ * the Incident:SendNotificationToSubscribers job). One case slips between
1169
+ * the two: the whole send started after this update read the status and
1170
+ * finished before it wrote the pages. Once the pages are written, this
1171
+ * checks for exactly that - the send finished, and an added page is not in
1172
+ * its record - and queues the notification again for the pages it missed.
1173
+ *
1174
+ * Never throws: the update is already written.
1175
+ */
1176
+ async requeueCreatedNotificationIfAddedPagesWereMissed(data) {
1177
+ var _a, _b;
1178
+ if (!((_a = data.change) === null || _a === void 0 ? void 0 : _a.notificationAlreadyQueued) ||
1179
+ data.change.addedStatusPageIds.length === 0) {
1180
+ return;
1181
+ }
1182
+ try {
1183
+ const incident = await this.findOneById({
1184
+ id: data.incidentId,
1185
+ select: {
1186
+ subscriberNotificationStatusOnIncidentCreated: true,
1187
+ statusPagesNotifiedOnCreation: true,
1188
+ },
1189
+ props: {
1190
+ isRoot: true,
1191
+ },
1192
+ });
1193
+ if ((incident === null || incident === void 0 ? void 0 : incident.subscriberNotificationStatusOnIncidentCreated) !==
1194
+ StatusPageSubscriberNotificationStatus.Success) {
1195
+ // Still on its way (it will see the pages), or settled otherwise.
1196
+ return;
1197
+ }
1198
+ const recorded = IncidentScopeAddedPagesNotification.getRecordedStatusPageIds(incident.statusPagesNotifiedOnCreation) || [];
1199
+ const missed = data.change.addedStatusPageIds.some((id) => {
1200
+ return !recorded.includes(id);
1201
+ });
1202
+ if (!missed) {
1203
+ return;
1204
+ }
1205
+ await this.updateOneById({
1206
+ id: data.incidentId,
1207
+ data: {
1208
+ subscriberNotificationStatusOnIncidentCreated: StatusPageSubscriberNotificationStatus.Pending,
1209
+ subscriberNotificationStatusMessage: IncidentScopeAddedPagesNotification.queuedMessage,
1210
+ },
1211
+ props: {
1212
+ isRoot: true,
1213
+ ignoreHooks: true,
1214
+ },
1215
+ });
1216
+ }
1217
+ catch (err) {
1218
+ logger.error(`Failed to check whether the incident created notification reached the status pages added to the incident: ${err}`, {
1219
+ incidentId: (_b = data.incidentId) === null || _b === void 0 ? void 0 : _b.toString(),
1220
+ });
1221
+ }
1222
+ }
1223
+ /*
1224
+ * The pages the matched incidents are scoped to that the caller cannot
1225
+ * read, which a list write from them must keep (see
1226
+ * applyStatusPageScopeToUpdate). A bulk update writes the same list onto
1227
+ * every incident it matches, so it can only keep them when every matched
1228
+ * incident holds the same hidden pages; otherwise it would scope some of
1229
+ * them to pages they were never scoped to, and it is refused.
1230
+ */
1231
+ async getScopedStatusPageIdsHiddenFromCaller(data) {
1232
+ const heldByIncident = data.incidents.map((incident) => {
1233
+ return IncidentScopeAddedPagesNotification.normalizeStatusPageIds(incident.statusPages);
1234
+ });
1235
+ const heldIds = IncidentScopeAddedPagesNotification.normalizeStatusPageIds(heldByIncident.flat());
1236
+ if (heldIds.length === 0) {
1237
+ return [];
1238
+ }
1239
+ const readableIds = await StatusPageReadAccess.getReadableStatusPageIds({
1240
+ statusPageIds: heldIds,
1241
+ props: data.props,
1242
+ });
1243
+ const hiddenByIncident = heldByIncident.map((held) => {
1244
+ return held
1245
+ .filter((id) => {
1246
+ return !readableIds.includes(id);
1247
+ })
1248
+ .sort();
1249
+ });
1250
+ const hiddenIds = hiddenByIncident[0] || [];
1251
+ const everyIncidentHidesTheSame = hiddenByIncident.every((hidden) => {
1252
+ return hidden.join(",") === hiddenIds.join(",");
1253
+ });
1254
+ if (!everyIncidentHidesTheSame) {
1255
+ throw new BadDataException("These incidents are limited to different status pages that you do not have access to, so their status pages cannot be changed together. Change them one at a time.");
1256
+ }
1257
+ return hiddenIds;
1258
+ }
1259
+ toStatusPageStubs(statusPageIds) {
1260
+ return statusPageIds.map((statusPageId) => {
1261
+ const statusPage = new StatusPage();
1262
+ statusPage._id = statusPageId;
1263
+ return statusPage;
1264
+ });
1265
+ }
1266
+ // A column's value once an update is written: the update's, else the stored.
1267
+ getValueAfterUpdate(updatedValue, storedValue) {
1268
+ if (updatedValue !== undefined && updatedValue !== null) {
1269
+ return updatedValue;
1270
+ }
1271
+ return storedValue;
1272
+ }
420
1273
  /*
421
1274
  * An update can repoint an incident at another project's state, severity or
422
1275
  * monitor status just as easily as a create can, and the result is the same:
@@ -533,6 +1386,16 @@ export class Service extends DatabaseService {
533
1386
  modelName: "On-Call Policy",
534
1387
  service: OnCallDutyPolicyService,
535
1388
  },
1389
+ /*
1390
+ * The status pages the incident is limited to. Another project's page
1391
+ * here would put that project's page name into this incident's feed and
1392
+ * scope it to a page it can never show on.
1393
+ */
1394
+ {
1395
+ column: "statusPages",
1396
+ modelName: "Status Page",
1397
+ service: StatusPageService,
1398
+ },
536
1399
  ...getAffectedResourceRelations(this.getModel()),
537
1400
  ];
538
1401
  }
@@ -567,6 +1430,20 @@ export class Service extends DatabaseService {
567
1430
  false;
568
1431
  }
569
1432
  const projectId = createBy.props.tenantId || createBy.data.projectId;
1433
+ /*
1434
+ * The values the caller sent, before a template or a mapping adds any:
1435
+ * those are not the caller's to get wrong.
1436
+ */
1437
+ await this.validateCustomFieldValuesOnCreate({
1438
+ createBy: createBy,
1439
+ projectId: projectId,
1440
+ });
1441
+ /*
1442
+ * Status pages the caller picked, as opposed to ones copied from a
1443
+ * template below (see applyStatusPageScopeToCreate).
1444
+ */
1445
+ const statusPagesFromCaller = createBy.data.statusPages !== undefined &&
1446
+ createBy.data.statusPages !== null;
570
1447
  /*
571
1448
  * Declaring the incident from alerts. The alert ids are checked here,
572
1449
  * before the incident number is taken and before anything is written, so
@@ -626,6 +1503,8 @@ export class Service extends DatabaseService {
626
1503
  }
627
1504
  // Determine the initial incident state
628
1505
  let initialIncidentStateId = undefined;
1506
+ // Declared from a template whose status pages were all deleted.
1507
+ let isScopedToNothingByTemplate = false;
629
1508
  // If currentIncidentStateId is already provided (manual selection), use it
630
1509
  if (createBy.data.currentIncidentStateId) {
631
1510
  initialIncidentStateId = createBy.data.currentIncidentStateId;
@@ -676,6 +1555,9 @@ export class Service extends DatabaseService {
676
1555
  services: { _id: true },
677
1556
  onCallDutyPolicies: { _id: true },
678
1557
  labels: { _id: true },
1558
+ statusPages: { _id: true },
1559
+ isScopedToStatusPages: true,
1560
+ customFields: true,
679
1561
  },
680
1562
  props: {
681
1563
  isRoot: true,
@@ -782,8 +1664,43 @@ export class Service extends DatabaseService {
782
1664
  createBy.data.labels = stubs;
783
1665
  }
784
1666
  }
1667
+ // Applying a template that has status pages scopes the incident.
1668
+ if (createBy.data.statusPages === undefined) {
1669
+ const stubs = stubBy(StatusPage, incidentTemplate.statusPages);
1670
+ if (stubs && stubs.length > 0) {
1671
+ createBy.data.statusPages = stubs;
1672
+ }
1673
+ else if (incidentTemplate.isScopedToStatusPages) {
1674
+ /*
1675
+ * A template limited to status pages that have all been deleted
1676
+ * since. Its incidents stay limited - to nothing - like an
1677
+ * incident whose pages were deleted, rather than reaching every
1678
+ * page that lists their monitors.
1679
+ */
1680
+ isScopedToNothingByTemplate = true;
1681
+ }
1682
+ }
1683
+ /*
1684
+ * The template's custom field values fill in the fields the caller
1685
+ * left out; a value the caller sent always wins. Merged, not
1686
+ * replaced, so the caller's own values are never dropped. They are
1687
+ * the template's, so the value check above (the caller's values
1688
+ * only) does not see them, and the mapping below still has the last
1689
+ * word on a mapped field.
1690
+ */
1691
+ const customFieldsWithTemplate = mergeTemplateCustomFields({
1692
+ templateCustomFields: incidentTemplate.customFields,
1693
+ customFields: createBy.data.customFields,
1694
+ });
1695
+ if (customFieldsWithTemplate) {
1696
+ createBy.data.customFields = customFieldsWithTemplate;
1697
+ }
785
1698
  }
786
1699
  }
1700
+ this.applyStatusPageScopeToCreate({
1701
+ createBy: createBy,
1702
+ isScopedToNothingByTemplate: isScopedToNothingByTemplate,
1703
+ });
787
1704
  // If no custom state is provided or found, fall back to default created state
788
1705
  if (!initialIncidentStateId) {
789
1706
  const incidentState = await IncidentStateService.findOneBy({
@@ -859,6 +1776,12 @@ export class Service extends DatabaseService {
859
1776
  subject: "incident",
860
1777
  serviceLevelObjectives: createBy.data.serviceLevelObjectives,
861
1778
  });
1779
+ // Before the counter increment too, like the checks above.
1780
+ await this.assertCallerCanPickStatusPagesOnCreate({
1781
+ createBy: createBy,
1782
+ projectId: projectId,
1783
+ statusPagesFromCaller: statusPagesFromCaller,
1784
+ });
862
1785
  const incidentCounterResult = await ProjectService.incrementAndGetIncidentCounter(projectId);
863
1786
  createBy.data.currentIncidentStateId = initialIncidentStateId;
864
1787
  createBy.data.incidentNumber = incidentCounterResult.counter;
@@ -964,6 +1887,8 @@ export class Service extends DatabaseService {
964
1887
  * The resources named under "Resources Affected" are read by the feed
965
1888
  * builder itself (LinkedAffectedResources), one relation at a time.
966
1889
  */
1890
+ // The created feed item names the status pages a scoped incident is limited to.
1891
+ isScopedToStatusPages: true,
967
1892
  },
968
1893
  props: {
969
1894
  isRoot: true,
@@ -1492,6 +2417,37 @@ export class Service extends DatabaseService {
1492
2417
  throw error;
1493
2418
  }
1494
2419
  }
2420
+ /*
2421
+ * The status pages a scoped incident is limited to, as a Markdown list for
2422
+ * its created feed item. Read on their own rather than in onCreateSuccess's
2423
+ * select: a find that selects several many-to-many lists returns a row for
2424
+ * every combination of them.
2425
+ */
2426
+ async getScopedStatusPagesMarkdown(incident) {
2427
+ const incidentWithStatusPages = await this.findOneById({
2428
+ id: incident.id,
2429
+ select: {
2430
+ statusPages: {
2431
+ _id: true,
2432
+ name: true,
2433
+ },
2434
+ },
2435
+ props: {
2436
+ isRoot: true,
2437
+ },
2438
+ });
2439
+ const statusPages = (incidentWithStatusPages === null || incidentWithStatusPages === void 0 ? void 0 : incidentWithStatusPages.statusPages) || [];
2440
+ if (statusPages.length === 0) {
2441
+ // Scoped to pages that have all been deleted since: hidden everywhere.
2442
+ return `- None: the status pages it was limited to have been deleted, so it is not shown on any status page.\n`;
2443
+ }
2444
+ let markdown = "";
2445
+ for (const statusPage of statusPages) {
2446
+ // A page name is free text: kept from turning into a link or an image.
2447
+ markdown += `- [${escapeMarkdownInline(statusPage.name || "Untitled status page")}](${(await StatusPageService.getStatusPageLinkInDashboard(incident.projectId, statusPage.id)).toString()})\n`;
2448
+ }
2449
+ return markdown;
2450
+ }
1495
2451
  async createIncidentFeedAsync(incident) {
1496
2452
  var _a, _b, _c, _d, _e, _f, _g;
1497
2453
  try {
@@ -1534,6 +2490,11 @@ ${incident.description || "No description provided."}
1534
2490
  }
1535
2491
  feedInfoInMarkdown += `\n\n`;
1536
2492
  }
2493
+ if (incident.isScopedToStatusPages) {
2494
+ feedInfoInMarkdown += `📣 **Limited to Status Pages**:\n`;
2495
+ feedInfoInMarkdown += await this.getScopedStatusPagesMarkdown(incident);
2496
+ feedInfoInMarkdown += `\n\n`;
2497
+ }
1537
2498
  if (incident.rootCause) {
1538
2499
  feedInfoInMarkdown += `\n
1539
2500
  📄 **Root Cause**:
@@ -2273,6 +3234,19 @@ ${incidentSeverity.name}
2273
3234
  }
2274
3235
  shouldAddIncidentFeed = true;
2275
3236
  }
3237
+ const statusPageScopeMarkdown = await this.getStatusPageScopeFeedMarkdown({
3238
+ projectId: projectId,
3239
+ incidentId: incidentId,
3240
+ change: incidentCarryForward.statusPageScopeChange,
3241
+ });
3242
+ if (statusPageScopeMarkdown) {
3243
+ feedInfoInMarkdown += statusPageScopeMarkdown;
3244
+ shouldAddIncidentFeed = true;
3245
+ }
3246
+ await this.requeueCreatedNotificationIfAddedPagesWereMissed({
3247
+ incidentId: incidentId,
3248
+ change: incidentCarryForward.statusPageScopeChange,
3249
+ });
2276
3250
  if (incidentCarryForward.oldChangeMonitorStatusIdTo &&
2277
3251
  incidentCarryForward.newMonitorChangeStatusIdTo) {
2278
3252
  const oldMonitorStatus = await MonitorStatusService.findOneBy({
@@ -2348,6 +3322,84 @@ ${incidentSeverity.name}
2348
3322
  }
2349
3323
  return onUpdate;
2350
3324
  }
3325
+ /*
3326
+ * The part of an update's feed item that records a change of the status
3327
+ * pages the incident is limited to: the pages added and removed, whether
3328
+ * the incident is now limited at all, and whether the added pages will be
3329
+ * sent the 'created' notification. Empty when the scope did not change.
3330
+ *
3331
+ * Page names are read as root, like the monitor names above. The pages were
3332
+ * validated as this project's when they were written, and the read is
3333
+ * filtered on the project anyway. Never throws: the update is already
3334
+ * written, and a missing line in the feed must not turn it into an error.
3335
+ */
3336
+ async getStatusPageScopeFeedMarkdown(data) {
3337
+ var _a, _b;
3338
+ const change = data.change;
3339
+ if (!change ||
3340
+ (change.addedStatusPageIds.length === 0 &&
3341
+ change.removedStatusPageIds.length === 0)) {
3342
+ return "";
3343
+ }
3344
+ try {
3345
+ const statusPages = await StatusPageService.findBy({
3346
+ query: {
3347
+ _id: QueryHelper.any([
3348
+ ...change.addedStatusPageIds,
3349
+ ...change.removedStatusPageIds,
3350
+ ]),
3351
+ projectId: data.projectId,
3352
+ },
3353
+ select: {
3354
+ _id: true,
3355
+ name: true,
3356
+ },
3357
+ limit: LIMIT_MAX,
3358
+ skip: 0,
3359
+ props: {
3360
+ isRoot: true,
3361
+ },
3362
+ });
3363
+ const statusPageLines = async (ids) => {
3364
+ let lines = "";
3365
+ for (const id of ids) {
3366
+ const statusPage = statusPages.find((page) => {
3367
+ var _a;
3368
+ return ((_a = page.id) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase()) === id;
3369
+ });
3370
+ if (!statusPage) {
3371
+ // Deleted since: its name is gone with it.
3372
+ lines += `- A deleted status page\n`;
3373
+ continue;
3374
+ }
3375
+ // A page name is free text: kept from turning into a link or an image.
3376
+ lines += `- [${escapeMarkdownInline(statusPage.name || "Untitled status page")}](${(await StatusPageService.getStatusPageLinkInDashboard(data.projectId, statusPage.id)).toString()})\n`;
3377
+ }
3378
+ return lines;
3379
+ };
3380
+ let markdown = "";
3381
+ if (change.addedStatusPageIds.length > 0) {
3382
+ markdown += `\n\n**📣 Status Pages Added**:\n${await statusPageLines(change.addedStatusPageIds)}`;
3383
+ }
3384
+ if (change.removedStatusPageIds.length > 0) {
3385
+ markdown += `\n\n**🔕 Status Pages Removed**:\n${await statusPageLines(change.removedStatusPageIds)}`;
3386
+ }
3387
+ markdown += change.isScoped
3388
+ ? `\n\nThis incident is shown on, and notifies the subscribers of, only its selected status pages that list its monitors.\n`
3389
+ : `\n\nThis incident is no longer limited to specific status pages: it is shown on every status page that lists its monitors, except pages that only show incidents limited to them.\n`;
3390
+ if (change.notificationQueued) {
3391
+ markdown += `\nSubscribers of the added status pages will be sent the notification that this incident was created.\n`;
3392
+ }
3393
+ return markdown;
3394
+ }
3395
+ catch (err) {
3396
+ logger.error(`Failed to describe the status page scope change in the incident feed: ${err}`, {
3397
+ projectId: (_a = data.projectId) === null || _a === void 0 ? void 0 : _a.toString(),
3398
+ incidentId: (_b = data.incidentId) === null || _b === void 0 ? void 0 : _b.toString(),
3399
+ });
3400
+ return "";
3401
+ }
3402
+ }
2351
3403
  async doesMonitorHasMoreActiveManualIncidents(monitorId, proojectId) {
2352
3404
  const resolvedState = await IncidentStateService.findOneBy({
2353
3405
  query: {