@oneuptime/common 9.4.11 → 9.4.13

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 (286) hide show
  1. package/Models/DatabaseModels/Incident.ts +77 -0
  2. package/Models/DatabaseModels/IncidentEpisode.ts +1223 -0
  3. package/Models/DatabaseModels/IncidentEpisodeFeed.ts +533 -0
  4. package/Models/DatabaseModels/IncidentEpisodeInternalNote.ts +456 -0
  5. package/Models/DatabaseModels/IncidentEpisodeMember.ts +587 -0
  6. package/Models/DatabaseModels/IncidentEpisodeOwnerTeam.ts +421 -0
  7. package/Models/DatabaseModels/IncidentEpisodeOwnerUser.ts +419 -0
  8. package/Models/DatabaseModels/IncidentEpisodeStateTimeline.ts +524 -0
  9. package/Models/DatabaseModels/IncidentGroupingRule.ts +1430 -0
  10. package/Models/DatabaseModels/Index.ts +18 -0
  11. package/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.ts +70 -0
  12. package/Models/DatabaseModels/OnCallDutyPolicyExecutionLogTimeline.ts +59 -0
  13. package/Models/DatabaseModels/Project.ts +29 -0
  14. package/Models/DatabaseModels/UserOnCallLog.ts +48 -0
  15. package/Models/DatabaseModels/UserOnCallLogTimeline.ts +49 -0
  16. package/Models/DatabaseModels/WorkspaceNotificationLog.ts +57 -0
  17. package/Server/API/BillingAPI.ts +78 -1
  18. package/Server/API/IncidentEpisodeAPI.ts +150 -0
  19. package/Server/API/SlackAPI.ts +23 -0
  20. package/Server/API/UserOnCallLogTimelineAPI.ts +24 -4
  21. package/Server/BillingConfig.ts +3 -0
  22. package/Server/EnvironmentConfig.ts +1 -0
  23. package/Server/Infrastructure/Postgres/SchemaMigrations/1769599843642-MigrationName.ts +29 -0
  24. package/Server/Infrastructure/Postgres/SchemaMigrations/1769626069479-MigrationName.ts +729 -0
  25. package/Server/Infrastructure/Postgres/SchemaMigrations/1769629928240-MigrationName.ts +261 -0
  26. package/Server/Infrastructure/Postgres/SchemaMigrations/1769676117342-RenameEvaluateOverTimeInCriteriaFilter.ts +28 -0
  27. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  28. package/Server/Services/AIBillingService.ts +10 -0
  29. package/Server/Services/BillingService.ts +349 -1
  30. package/Server/Services/CallService.ts +1 -0
  31. package/Server/Services/IncidentEpisodeFeedService.ts +94 -0
  32. package/Server/Services/IncidentEpisodeInternalNoteService.ts +71 -0
  33. package/Server/Services/IncidentEpisodeMemberService.ts +321 -0
  34. package/Server/Services/IncidentEpisodeOwnerTeamService.ts +10 -0
  35. package/Server/Services/IncidentEpisodeOwnerUserService.ts +10 -0
  36. package/Server/Services/IncidentEpisodeService.ts +1045 -0
  37. package/Server/Services/IncidentEpisodeStateTimelineService.ts +566 -0
  38. package/Server/Services/IncidentGroupingEngineService.ts +1047 -0
  39. package/Server/Services/IncidentGroupingRuleService.ts +14 -0
  40. package/Server/Services/IncidentService.ts +11 -0
  41. package/Server/Services/Index.ts +18 -0
  42. package/Server/Services/MailService.ts +1 -0
  43. package/Server/Services/MonitorService.ts +9 -0
  44. package/Server/Services/NotificationService.ts +10 -0
  45. package/Server/Services/OnCallDutyPolicyEscalationRuleService.ts +18 -0
  46. package/Server/Services/OnCallDutyPolicyExecutionLogService.ts +64 -2
  47. package/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts +26 -1
  48. package/Server/Services/OnCallDutyPolicyService.ts +15 -0
  49. package/Server/Services/ProjectService.ts +33 -2
  50. package/Server/Services/SmsService.ts +1 -0
  51. package/Server/Services/UserNotificationRuleService.ts +48 -2
  52. package/Server/Services/UserNotificationSettingService.ts +23 -0
  53. package/Server/Services/UserOnCallLogService.ts +41 -4
  54. package/Server/Services/UserService.ts +45 -1
  55. package/Server/Services/WhatsAppService.ts +1 -0
  56. package/Server/Services/WorkspaceNotificationLogService.ts +16 -0
  57. package/Server/Services/WorkspaceNotificationRuleService.ts +116 -0
  58. package/Server/Types/Database/Permissions/TenantPermission.ts +20 -0
  59. package/Server/Utils/AI/IncidentEpisodeAIContextBuilder.ts +490 -0
  60. package/Server/Utils/Monitor/Criteria/APIRequestCriteria.ts +1 -1
  61. package/Server/Utils/Monitor/Criteria/CompareCriteria.ts +1 -1
  62. package/Server/Utils/Monitor/Criteria/IncomingRequestCriteria.ts +1 -1
  63. package/Server/Utils/Monitor/Criteria/SSLMonitorCriteria.ts +1 -1
  64. package/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.ts +2 -2
  65. package/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.ts +182 -0
  66. package/Server/Utils/Monitor/MonitorCriteriaEvaluator.ts +13 -0
  67. package/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.ts +1 -1
  68. package/Server/Utils/Monitor/MonitorTemplateUtil.ts +37 -0
  69. package/Server/Utils/PushNotificationUtil.ts +31 -0
  70. package/Server/Utils/WhatsAppTemplateUtil.ts +14 -0
  71. package/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.ts +18 -0
  72. package/Server/Utils/Workspace/MicrosoftTeams/Actions/IncidentEpisode.ts +702 -0
  73. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +20 -0
  74. package/Server/Utils/Workspace/Slack/Actions/ActionTypes.ts +11 -0
  75. package/Server/Utils/Workspace/Slack/Actions/IncidentEpisode.ts +918 -0
  76. package/Server/Utils/Workspace/Slack/Messages/IncidentEpisode.ts +120 -0
  77. package/Server/Utils/Workspace/WorkspaceMessages/IncidentEpisode.ts +74 -0
  78. package/Types/Email/EmailTemplateType.ts +7 -0
  79. package/Types/Monitor/CriteriaFilter.ts +24 -4
  80. package/Types/Monitor/MonitorCriteriaInstance.ts +67 -0
  81. package/Types/Monitor/MonitorStep.ts +37 -0
  82. package/Types/Monitor/MonitorStepSnmpMonitor.ts +102 -0
  83. package/Types/Monitor/MonitorType.ts +15 -2
  84. package/Types/Monitor/SnmpMonitor/SnmpAuthProtocol.ts +8 -0
  85. package/Types/Monitor/SnmpMonitor/SnmpDataType.ts +21 -0
  86. package/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.ts +16 -0
  87. package/Types/Monitor/SnmpMonitor/SnmpOid.ts +60 -0
  88. package/Types/Monitor/SnmpMonitor/SnmpPrivProtocol.ts +7 -0
  89. package/Types/Monitor/SnmpMonitor/SnmpSecurityLevel.ts +7 -0
  90. package/Types/Monitor/SnmpMonitor/SnmpV3Auth.ts +12 -0
  91. package/Types/Monitor/SnmpMonitor/SnmpVersion.ts +7 -0
  92. package/Types/NotificationSetting/NotificationSettingEventType.ts +7 -0
  93. package/Types/Permission.ts +311 -0
  94. package/Types/Probe/ProbeMonitorResponse.ts +2 -0
  95. package/Types/UserNotification/UserNotificationEventType.ts +1 -0
  96. package/Types/WhatsApp/WhatsAppTemplates.ts +24 -0
  97. package/Types/Workspace/NotificationRules/EventType.ts +1 -0
  98. package/Types/Workspace/NotificationRules/NotificationRuleCondition.ts +38 -1
  99. package/Utils/Monitor/MonitorMetricType.ts +2 -1
  100. package/build/dist/Models/DatabaseModels/Incident.js +78 -0
  101. package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
  102. package/build/dist/Models/DatabaseModels/IncidentEpisode.js +1250 -0
  103. package/build/dist/Models/DatabaseModels/IncidentEpisode.js.map +1 -0
  104. package/build/dist/Models/DatabaseModels/IncidentEpisodeFeed.js +555 -0
  105. package/build/dist/Models/DatabaseModels/IncidentEpisodeFeed.js.map +1 -0
  106. package/build/dist/Models/DatabaseModels/IncidentEpisodeInternalNote.js +467 -0
  107. package/build/dist/Models/DatabaseModels/IncidentEpisodeInternalNote.js.map +1 -0
  108. package/build/dist/Models/DatabaseModels/IncidentEpisodeMember.js +607 -0
  109. package/build/dist/Models/DatabaseModels/IncidentEpisodeMember.js.map +1 -0
  110. package/build/dist/Models/DatabaseModels/IncidentEpisodeOwnerTeam.js +437 -0
  111. package/build/dist/Models/DatabaseModels/IncidentEpisodeOwnerTeam.js.map +1 -0
  112. package/build/dist/Models/DatabaseModels/IncidentEpisodeOwnerUser.js +436 -0
  113. package/build/dist/Models/DatabaseModels/IncidentEpisodeOwnerUser.js.map +1 -0
  114. package/build/dist/Models/DatabaseModels/IncidentEpisodeStateTimeline.js +546 -0
  115. package/build/dist/Models/DatabaseModels/IncidentEpisodeStateTimeline.js.map +1 -0
  116. package/build/dist/Models/DatabaseModels/IncidentGroupingRule.js +1437 -0
  117. package/build/dist/Models/DatabaseModels/IncidentGroupingRule.js.map +1 -0
  118. package/build/dist/Models/DatabaseModels/Index.js +16 -0
  119. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  120. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.js +69 -0
  121. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.js.map +1 -1
  122. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyExecutionLogTimeline.js +58 -0
  123. package/build/dist/Models/DatabaseModels/OnCallDutyPolicyExecutionLogTimeline.js.map +1 -1
  124. package/build/dist/Models/DatabaseModels/Project.js +30 -0
  125. package/build/dist/Models/DatabaseModels/Project.js.map +1 -1
  126. package/build/dist/Models/DatabaseModels/UserOnCallLog.js +47 -0
  127. package/build/dist/Models/DatabaseModels/UserOnCallLog.js.map +1 -1
  128. package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js +48 -0
  129. package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js.map +1 -1
  130. package/build/dist/Models/DatabaseModels/WorkspaceNotificationLog.js +58 -0
  131. package/build/dist/Models/DatabaseModels/WorkspaceNotificationLog.js.map +1 -1
  132. package/build/dist/Server/API/BillingAPI.js +44 -1
  133. package/build/dist/Server/API/BillingAPI.js.map +1 -1
  134. package/build/dist/Server/API/IncidentEpisodeAPI.js +97 -0
  135. package/build/dist/Server/API/IncidentEpisodeAPI.js.map +1 -0
  136. package/build/dist/Server/API/SlackAPI.js +18 -0
  137. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  138. package/build/dist/Server/API/UserOnCallLogTimelineAPI.js +30 -10
  139. package/build/dist/Server/API/UserOnCallLogTimelineAPI.js.map +1 -1
  140. package/build/dist/Server/BillingConfig.js +2 -0
  141. package/build/dist/Server/BillingConfig.js.map +1 -1
  142. package/build/dist/Server/EnvironmentConfig.js +1 -0
  143. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  144. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769599843642-MigrationName.js +16 -0
  145. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769599843642-MigrationName.js.map +1 -0
  146. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769626069479-MigrationName.js +256 -0
  147. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769626069479-MigrationName.js.map +1 -0
  148. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769629928240-MigrationName.js +96 -0
  149. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769629928240-MigrationName.js.map +1 -0
  150. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769676117342-RenameEvaluateOverTimeInCriteriaFilter.js +25 -0
  151. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1769676117342-RenameEvaluateOverTimeInCriteriaFilter.js.map +1 -0
  152. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  153. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  154. package/build/dist/Server/Services/AIBillingService.js +10 -1
  155. package/build/dist/Server/Services/AIBillingService.js.map +1 -1
  156. package/build/dist/Server/Services/BillingService.js +224 -5
  157. package/build/dist/Server/Services/BillingService.js.map +1 -1
  158. package/build/dist/Server/Services/CallService.js.map +1 -1
  159. package/build/dist/Server/Services/IncidentEpisodeFeedService.js +83 -0
  160. package/build/dist/Server/Services/IncidentEpisodeFeedService.js.map +1 -0
  161. package/build/dist/Server/Services/IncidentEpisodeInternalNoteService.js +70 -0
  162. package/build/dist/Server/Services/IncidentEpisodeInternalNoteService.js.map +1 -0
  163. package/build/dist/Server/Services/IncidentEpisodeMemberService.js +298 -0
  164. package/build/dist/Server/Services/IncidentEpisodeMemberService.js.map +1 -0
  165. package/build/dist/Server/Services/IncidentEpisodeOwnerTeamService.js +9 -0
  166. package/build/dist/Server/Services/IncidentEpisodeOwnerTeamService.js.map +1 -0
  167. package/build/dist/Server/Services/IncidentEpisodeOwnerUserService.js +9 -0
  168. package/build/dist/Server/Services/IncidentEpisodeOwnerUserService.js.map +1 -0
  169. package/build/dist/Server/Services/IncidentEpisodeService.js +933 -0
  170. package/build/dist/Server/Services/IncidentEpisodeService.js.map +1 -0
  171. package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js +498 -0
  172. package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js.map +1 -0
  173. package/build/dist/Server/Services/IncidentGroupingEngineService.js +799 -0
  174. package/build/dist/Server/Services/IncidentGroupingEngineService.js.map +1 -0
  175. package/build/dist/Server/Services/IncidentGroupingRuleService.js +13 -0
  176. package/build/dist/Server/Services/IncidentGroupingRuleService.js.map +1 -0
  177. package/build/dist/Server/Services/IncidentService.js +10 -0
  178. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  179. package/build/dist/Server/Services/Index.js +16 -0
  180. package/build/dist/Server/Services/Index.js.map +1 -1
  181. package/build/dist/Server/Services/MailService.js.map +1 -1
  182. package/build/dist/Server/Services/MonitorService.js +9 -1
  183. package/build/dist/Server/Services/MonitorService.js.map +1 -1
  184. package/build/dist/Server/Services/NotificationService.js +10 -1
  185. package/build/dist/Server/Services/NotificationService.js.map +1 -1
  186. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js +10 -0
  187. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js.map +1 -1
  188. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js +48 -2
  189. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js.map +1 -1
  190. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js +20 -1
  191. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js.map +1 -1
  192. package/build/dist/Server/Services/OnCallDutyPolicyService.js +8 -0
  193. package/build/dist/Server/Services/OnCallDutyPolicyService.js.map +1 -1
  194. package/build/dist/Server/Services/ProjectService.js +16 -3
  195. package/build/dist/Server/Services/ProjectService.js.map +1 -1
  196. package/build/dist/Server/Services/SmsService.js.map +1 -1
  197. package/build/dist/Server/Services/UserNotificationRuleService.js +39 -2
  198. package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
  199. package/build/dist/Server/Services/UserNotificationSettingService.js +9 -0
  200. package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
  201. package/build/dist/Server/Services/UserOnCallLogService.js +35 -3
  202. package/build/dist/Server/Services/UserOnCallLogService.js.map +1 -1
  203. package/build/dist/Server/Services/UserService.js +40 -0
  204. package/build/dist/Server/Services/UserService.js.map +1 -1
  205. package/build/dist/Server/Services/WhatsAppService.js.map +1 -1
  206. package/build/dist/Server/Services/WorkspaceNotificationLogService.js +12 -0
  207. package/build/dist/Server/Services/WorkspaceNotificationLogService.js.map +1 -1
  208. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +95 -1
  209. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
  210. package/build/dist/Server/Types/Database/Permissions/TenantPermission.js +17 -0
  211. package/build/dist/Server/Types/Database/Permissions/TenantPermission.js.map +1 -1
  212. package/build/dist/Server/Utils/AI/IncidentEpisodeAIContextBuilder.js +402 -0
  213. package/build/dist/Server/Utils/AI/IncidentEpisodeAIContextBuilder.js.map +1 -0
  214. package/build/dist/Server/Utils/Monitor/Criteria/APIRequestCriteria.js +1 -1
  215. package/build/dist/Server/Utils/Monitor/Criteria/CompareCriteria.js +1 -1
  216. package/build/dist/Server/Utils/Monitor/Criteria/IncomingRequestCriteria.js +1 -1
  217. package/build/dist/Server/Utils/Monitor/Criteria/SSLMonitorCriteria.js +1 -1
  218. package/build/dist/Server/Utils/Monitor/Criteria/ServerMonitorCriteria.js +2 -2
  219. package/build/dist/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.js +135 -0
  220. package/build/dist/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.js.map +1 -0
  221. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js +10 -0
  222. package/build/dist/Server/Utils/Monitor/MonitorCriteriaEvaluator.js.map +1 -1
  223. package/build/dist/Server/Utils/Monitor/MonitorCriteriaExpectationBuilder.js +1 -1
  224. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js +26 -0
  225. package/build/dist/Server/Utils/Monitor/MonitorTemplateUtil.js.map +1 -1
  226. package/build/dist/Server/Utils/PushNotificationUtil.js +20 -0
  227. package/build/dist/Server/Utils/PushNotificationUtil.js.map +1 -1
  228. package/build/dist/Server/Utils/WhatsAppTemplateUtil.js +8 -0
  229. package/build/dist/Server/Utils/WhatsAppTemplateUtil.js.map +1 -1
  230. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.js +17 -0
  231. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.js.map +1 -1
  232. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/IncidentEpisode.js +547 -0
  233. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/IncidentEpisode.js.map +1 -0
  234. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +15 -0
  235. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  236. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +10 -0
  237. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -1
  238. package/build/dist/Server/Utils/Workspace/Slack/Actions/IncidentEpisode.js +651 -0
  239. package/build/dist/Server/Utils/Workspace/Slack/Actions/IncidentEpisode.js.map +1 -0
  240. package/build/dist/Server/Utils/Workspace/Slack/Messages/IncidentEpisode.js +100 -0
  241. package/build/dist/Server/Utils/Workspace/Slack/Messages/IncidentEpisode.js.map +1 -0
  242. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/IncidentEpisode.js +70 -0
  243. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/IncidentEpisode.js.map +1 -0
  244. package/build/dist/Types/Email/EmailTemplateType.js +6 -0
  245. package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
  246. package/build/dist/Types/Monitor/CriteriaFilter.js +16 -3
  247. package/build/dist/Types/Monitor/CriteriaFilter.js.map +1 -1
  248. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js +62 -0
  249. package/build/dist/Types/Monitor/MonitorCriteriaInstance.js.map +1 -1
  250. package/build/dist/Types/Monitor/MonitorStep.js +26 -0
  251. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  252. package/build/dist/Types/Monitor/MonitorStepSnmpMonitor.js +77 -0
  253. package/build/dist/Types/Monitor/MonitorStepSnmpMonitor.js.map +1 -0
  254. package/build/dist/Types/Monitor/MonitorType.js +13 -2
  255. package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
  256. package/build/dist/Types/Monitor/SnmpMonitor/SnmpAuthProtocol.js +9 -0
  257. package/build/dist/Types/Monitor/SnmpMonitor/SnmpAuthProtocol.js.map +1 -0
  258. package/build/dist/Types/Monitor/SnmpMonitor/SnmpDataType.js +22 -0
  259. package/build/dist/Types/Monitor/SnmpMonitor/SnmpDataType.js.map +1 -0
  260. package/build/dist/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.js +2 -0
  261. package/build/dist/Types/Monitor/SnmpMonitor/SnmpMonitorResponse.js.map +1 -0
  262. package/build/dist/Types/Monitor/SnmpMonitor/SnmpOid.js +55 -0
  263. package/build/dist/Types/Monitor/SnmpMonitor/SnmpOid.js.map +1 -0
  264. package/build/dist/Types/Monitor/SnmpMonitor/SnmpPrivProtocol.js +8 -0
  265. package/build/dist/Types/Monitor/SnmpMonitor/SnmpPrivProtocol.js.map +1 -0
  266. package/build/dist/Types/Monitor/SnmpMonitor/SnmpSecurityLevel.js +8 -0
  267. package/build/dist/Types/Monitor/SnmpMonitor/SnmpSecurityLevel.js.map +1 -0
  268. package/build/dist/Types/Monitor/SnmpMonitor/SnmpV3Auth.js +2 -0
  269. package/build/dist/Types/Monitor/SnmpMonitor/SnmpV3Auth.js.map +1 -0
  270. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVersion.js +8 -0
  271. package/build/dist/Types/Monitor/SnmpMonitor/SnmpVersion.js.map +1 -0
  272. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js +5 -0
  273. package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js.map +1 -1
  274. package/build/dist/Types/Permission.js +264 -0
  275. package/build/dist/Types/Permission.js.map +1 -1
  276. package/build/dist/Types/UserNotification/UserNotificationEventType.js +1 -0
  277. package/build/dist/Types/UserNotification/UserNotificationEventType.js.map +1 -1
  278. package/build/dist/Types/WhatsApp/WhatsAppTemplates.js +15 -0
  279. package/build/dist/Types/WhatsApp/WhatsAppTemplates.js.map +1 -1
  280. package/build/dist/Types/Workspace/NotificationRules/EventType.js +1 -0
  281. package/build/dist/Types/Workspace/NotificationRules/EventType.js.map +1 -1
  282. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js +33 -1
  283. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js.map +1 -1
  284. package/build/dist/Utils/Monitor/MonitorMetricType.js +2 -1
  285. package/build/dist/Utils/Monitor/MonitorMetricType.js.map +1 -1
  286. package/package.json +1 -1
@@ -1,8 +1,16 @@
1
- import { BillingPrivateKey, IsBillingEnabled } from "../EnvironmentConfig";
1
+ import {
2
+ BillingPrivateKey,
3
+ BillingWebhookSecret,
4
+ IsBillingEnabled,
5
+ DashboardClientUrl,
6
+ } from "../EnvironmentConfig";
7
+ import Project from "../../Models/DatabaseModels/Project";
2
8
  import ServerMeteredPlan from "../Types/Billing/MeteredPlan/ServerMeteredPlan";
3
9
  import Errors from "../Utils/Errors";
4
10
  import logger from "../Utils/Logger";
5
11
  import BaseService from "./BaseService";
12
+ import MailService from "./MailService";
13
+ import ProjectService from "./ProjectService";
6
14
  import SubscriptionPlan from "../../Types/Billing/SubscriptionPlan";
7
15
  import SubscriptionStatus, {
8
16
  SubscriptionStatusUtil,
@@ -10,6 +18,7 @@ import SubscriptionStatus, {
10
18
  import OneUptimeDate from "../../Types/Date";
11
19
  import Dictionary from "../../Types/Dictionary";
12
20
  import Email from "../../Types/Email";
21
+ import EmailTemplateType from "../../Types/Email/EmailTemplateType";
13
22
  import APIException from "../../Types/Exception/ApiException";
14
23
  import BadDataException from "../../Types/Exception/BadDataException";
15
24
  import ProductType from "../../Types/MeteredPlan/ProductType";
@@ -86,8 +95,16 @@ export class BillingService extends BaseService {
86
95
  businessDetails: string,
87
96
  countryCode?: string | null,
88
97
  financeAccountingEmail?: string | null,
98
+ sendInvoicesByEmail?: boolean | null,
89
99
  ): Promise<void> {
100
+ logger.debug(
101
+ `[Invoice Email] updateCustomerBusinessDetails called - customerId: ${id}, sendInvoicesByEmail: ${sendInvoicesByEmail}`,
102
+ );
103
+
90
104
  if (!this.isBillingEnabled()) {
105
+ logger.debug(
106
+ `[Invoice Email] Billing not enabled, skipping updateCustomerBusinessDetails for customer ${id}`,
107
+ );
91
108
  throw new BadDataException(Errors.BillingService.BILLING_NOT_ENABLED);
92
109
  }
93
110
  /*
@@ -133,6 +150,14 @@ export class BillingService extends BaseService {
133
150
  // Remove if cleared
134
151
  metadata["finance_accounting_email"] = "";
135
152
  }
153
+ if (sendInvoicesByEmail !== undefined && sendInvoicesByEmail !== null) {
154
+ metadata["send_invoices_by_email"] = sendInvoicesByEmail
155
+ ? "true"
156
+ : "false";
157
+ logger.debug(
158
+ `[Invoice Email] Setting send_invoices_by_email metadata to "${metadata["send_invoices_by_email"]}" for customer ${id}`,
159
+ );
160
+ }
136
161
 
137
162
  const updateParams: Stripe.CustomerUpdateParams = {
138
163
  metadata,
@@ -169,7 +194,11 @@ export class BillingService extends BaseService {
169
194
  } as any;
170
195
  }
171
196
 
197
+ logger.debug(
198
+ `[Invoice Email] Updating Stripe customer ${id} with metadata: ${JSON.stringify(metadata)}`,
199
+ );
172
200
  await this.stripe.customers.update(id, updateParams);
201
+ logger.debug(`[Invoice Email] Successfully updated Stripe customer ${id}`);
173
202
  }
174
203
 
175
204
  @CaptureSpan()
@@ -924,12 +953,169 @@ export class BillingService extends BaseService {
924
953
  return billingInvoices;
925
954
  }
926
955
 
956
+ @CaptureSpan()
957
+ public async sendInvoiceByEmail(
958
+ invoiceId: string,
959
+ recipientEmail?: Email,
960
+ projectId?: ObjectID,
961
+ ): Promise<void> {
962
+ logger.debug(
963
+ `[Invoice Email] sendInvoiceByEmail called for invoice: ${invoiceId}, recipientEmail: ${recipientEmail?.toString()}`,
964
+ );
965
+
966
+ if (!this.isBillingEnabled()) {
967
+ logger.debug(
968
+ `[Invoice Email] Billing not enabled, skipping send for invoice: ${invoiceId}`,
969
+ );
970
+ throw new BadDataException(Errors.BillingService.BILLING_NOT_ENABLED);
971
+ }
972
+
973
+ try {
974
+ // Fetch invoice details from Stripe
975
+ logger.debug(
976
+ `[Invoice Email] Fetching invoice ${invoiceId} details from Stripe`,
977
+ );
978
+ const stripeInvoice: Stripe.Invoice =
979
+ await this.stripe.invoices.retrieve(invoiceId);
980
+
981
+ if (!stripeInvoice) {
982
+ logger.error(
983
+ `[Invoice Email] Invoice ${invoiceId} not found in Stripe`,
984
+ );
985
+ return;
986
+ }
987
+
988
+ // Determine recipient email
989
+ let toEmail: Email | undefined = recipientEmail;
990
+ if (!toEmail && stripeInvoice.customer_email) {
991
+ toEmail = new Email(stripeInvoice.customer_email);
992
+ }
993
+
994
+ if (!toEmail) {
995
+ logger.error(
996
+ `[Invoice Email] No recipient email found for invoice ${invoiceId}`,
997
+ );
998
+ return;
999
+ }
1000
+
1001
+ // Format invoice data for email
1002
+ const invoiceNumber: string = stripeInvoice.number || invoiceId;
1003
+ const invoiceDate: string = stripeInvoice.created
1004
+ ? OneUptimeDate.getDateAsFormattedString(
1005
+ new Date(stripeInvoice.created * 1000),
1006
+ )
1007
+ : OneUptimeDate.getDateAsFormattedString(
1008
+ OneUptimeDate.getCurrentDate(),
1009
+ );
1010
+ const amount: string = `${(stripeInvoice.amount_due / 100).toFixed(2)} ${stripeInvoice.currency?.toUpperCase() || "USD"}`;
1011
+ const invoicePdfUrl: string | undefined =
1012
+ stripeInvoice.invoice_pdf || undefined;
1013
+ const description: string | undefined =
1014
+ stripeInvoice.description || undefined;
1015
+
1016
+ // Build dashboard link
1017
+ let dashboardLink: string | undefined = undefined;
1018
+ if (projectId && DashboardClientUrl) {
1019
+ dashboardLink = `${DashboardClientUrl.toString()}/dashboard/${projectId.toString()}/settings/billing`;
1020
+ }
1021
+
1022
+ logger.debug(
1023
+ `[Invoice Email] Sending invoice email to ${toEmail.toString()} - Invoice #${invoiceNumber}, Amount: ${amount}`,
1024
+ );
1025
+
1026
+ // Send email via OneUptime MailService
1027
+ await MailService.sendMail(
1028
+ {
1029
+ toEmail: toEmail,
1030
+ templateType: EmailTemplateType.Invoice,
1031
+ vars: {
1032
+ invoiceNumber: invoiceNumber,
1033
+ invoiceDate: invoiceDate,
1034
+ amount: amount,
1035
+ description: description || "",
1036
+ invoicePdfUrl: invoicePdfUrl || "",
1037
+ dashboardLink: dashboardLink || "",
1038
+ },
1039
+ subject: `Invoice #${invoiceNumber} from OneUptime`,
1040
+ },
1041
+ {
1042
+ projectId: projectId,
1043
+ },
1044
+ );
1045
+
1046
+ logger.debug(
1047
+ `[Invoice Email] Successfully sent invoice ${invoiceId} email to ${toEmail.toString()}`,
1048
+ );
1049
+ } catch (err) {
1050
+ logger.error(
1051
+ `[Invoice Email] Failed to send invoice ${invoiceId} by email: ${err}`,
1052
+ );
1053
+ // Don't throw - sending email is not critical
1054
+ }
1055
+ }
1056
+
1057
+ @CaptureSpan()
1058
+ public async shouldSendInvoicesByEmail(customerId: string): Promise<boolean> {
1059
+ logger.debug(
1060
+ `[Invoice Email] shouldSendInvoicesByEmail called for customer: ${customerId}`,
1061
+ );
1062
+
1063
+ if (!this.isBillingEnabled()) {
1064
+ logger.debug(
1065
+ `[Invoice Email] Billing not enabled, returning false for customer: ${customerId}`,
1066
+ );
1067
+ return false;
1068
+ }
1069
+
1070
+ try {
1071
+ logger.debug(
1072
+ `[Invoice Email] Retrieving customer ${customerId} from Stripe to check preference`,
1073
+ );
1074
+ const customer: Stripe.Response<
1075
+ Stripe.Customer | Stripe.DeletedCustomer
1076
+ > = await this.stripe.customers.retrieve(customerId);
1077
+
1078
+ if (!customer || customer.deleted) {
1079
+ logger.debug(
1080
+ `[Invoice Email] Customer ${customerId} not found or deleted, returning false`,
1081
+ );
1082
+ return false;
1083
+ }
1084
+
1085
+ const metadata: Stripe.Metadata = (customer as Stripe.Customer).metadata;
1086
+ const sendInvoicesByEmail: boolean =
1087
+ metadata?.["send_invoices_by_email"] === "true";
1088
+ logger.debug(
1089
+ `[Invoice Email] Customer ${customerId} metadata.send_invoices_by_email = "${metadata?.["send_invoices_by_email"]}", result: ${sendInvoicesByEmail}`,
1090
+ );
1091
+ return sendInvoicesByEmail;
1092
+ } catch (err) {
1093
+ logger.error(
1094
+ `[Invoice Email] Failed to check invoice email preference for customer ${customerId}: ${err}`,
1095
+ );
1096
+ return false;
1097
+ }
1098
+ }
1099
+
927
1100
  @CaptureSpan()
928
1101
  public async generateInvoiceAndChargeCustomer(
929
1102
  customerId: string,
930
1103
  itemText: string,
931
1104
  amountInUsd: number,
1105
+ options?: {
1106
+ sendInvoiceByEmail?: boolean | undefined;
1107
+ recipientEmail?: Email | undefined;
1108
+ projectId?: ObjectID | undefined;
1109
+ },
932
1110
  ): Promise<void> {
1111
+ const sendInvoiceByEmail: boolean = options?.sendInvoiceByEmail || false;
1112
+ const recipientEmail: Email | undefined = options?.recipientEmail;
1113
+ const projectId: ObjectID | undefined = options?.projectId;
1114
+
1115
+ logger.debug(
1116
+ `[Invoice Email] generateInvoiceAndChargeCustomer called - customer: ${customerId}, amount: $${amountInUsd}, sendInvoiceByEmail: ${sendInvoiceByEmail}, recipientEmail: ${recipientEmail?.toString()}, projectId: ${projectId?.toString()}`,
1117
+ );
1118
+
933
1119
  const invoice: Stripe.Invoice = await this.stripe.invoices.create({
934
1120
  customer: customerId,
935
1121
  auto_advance: true, // do not automatically charge.
@@ -937,9 +1123,16 @@ export class BillingService extends BaseService {
937
1123
  });
938
1124
 
939
1125
  if (!invoice || !invoice.id) {
1126
+ logger.error(
1127
+ `[Invoice Email] Failed to create invoice for customer ${customerId}`,
1128
+ );
940
1129
  throw new APIException(Errors.BillingService.INVOICE_NOT_GENERATED);
941
1130
  }
942
1131
 
1132
+ logger.debug(
1133
+ `[Invoice Email] Created invoice ${invoice.id} for customer ${customerId}`,
1134
+ );
1135
+
943
1136
  await this.stripe.invoiceItems.create({
944
1137
  invoice: invoice.id,
945
1138
  amount: amountInUsd * 100,
@@ -947,11 +1140,32 @@ export class BillingService extends BaseService {
947
1140
  customer: customerId,
948
1141
  });
949
1142
 
1143
+ logger.debug(
1144
+ `[Invoice Email] Added invoice item to invoice ${invoice.id}: ${itemText}, $${amountInUsd}`,
1145
+ );
1146
+
950
1147
  await this.stripe.invoices.finalizeInvoice(invoice.id!);
1148
+ logger.debug(`[Invoice Email] Finalized invoice ${invoice.id}`);
951
1149
 
952
1150
  try {
953
1151
  await this.payInvoice(customerId, invoice.id!);
1152
+ logger.debug(`[Invoice Email] Paid invoice ${invoice.id}`);
1153
+
1154
+ // Send invoice by email if requested
1155
+ if (sendInvoiceByEmail) {
1156
+ logger.debug(
1157
+ `[Invoice Email] sendInvoiceByEmail is true, sending invoice ${invoice.id} by email`,
1158
+ );
1159
+ await this.sendInvoiceByEmail(invoice.id!, recipientEmail, projectId);
1160
+ } else {
1161
+ logger.debug(
1162
+ `[Invoice Email] sendInvoiceByEmail is false, skipping email for invoice ${invoice.id}`,
1163
+ );
1164
+ }
954
1165
  } catch (err) {
1166
+ logger.error(
1167
+ `[Invoice Email] Failed to pay invoice ${invoice.id}, voiding: ${err}`,
1168
+ );
955
1169
  // mark invoice as failed and do not collect payment.
956
1170
  await this.voidInvoice(invoice.id!);
957
1171
  throw err;
@@ -1035,6 +1249,140 @@ export class BillingService extends BaseService {
1035
1249
  "Plan with productType " + productType + " not found",
1036
1250
  );
1037
1251
  }
1252
+
1253
+ @CaptureSpan()
1254
+ public verifyWebhookSignature(
1255
+ payload: string | Buffer,
1256
+ signature: string,
1257
+ ): Stripe.Event {
1258
+ logger.debug(`[Invoice Email] verifyWebhookSignature called`);
1259
+
1260
+ if (!BillingWebhookSecret) {
1261
+ logger.error(`[Invoice Email] Billing webhook secret is not configured`);
1262
+ throw new BadDataException("Billing webhook secret is not configured");
1263
+ }
1264
+
1265
+ logger.debug(
1266
+ `[Invoice Email] Verifying webhook signature with secret (length: ${BillingWebhookSecret.length})`,
1267
+ );
1268
+ const event: Stripe.Event = this.stripe.webhooks.constructEvent(
1269
+ payload,
1270
+ signature,
1271
+ BillingWebhookSecret,
1272
+ );
1273
+ logger.debug(
1274
+ `[Invoice Email] Webhook signature verified, event type: ${event.type}, event id: ${event.id}`,
1275
+ );
1276
+ return event;
1277
+ }
1278
+
1279
+ @CaptureSpan()
1280
+ public async handleWebhookEvent(event: Stripe.Event): Promise<void> {
1281
+ logger.debug(
1282
+ `[Invoice Email] handleWebhookEvent called - event type: ${event.type}, event id: ${event.id}`,
1283
+ );
1284
+
1285
+ if (!this.isBillingEnabled()) {
1286
+ logger.debug(
1287
+ `[Invoice Email] Billing not enabled, ignoring webhook event ${event.id}`,
1288
+ );
1289
+ return;
1290
+ }
1291
+
1292
+ // Handle invoice.finalized event to send invoice by email if customer has opted in
1293
+ if (event.type === "invoice.finalized") {
1294
+ logger.debug(
1295
+ `[Invoice Email] Processing invoice.finalized event ${event.id}`,
1296
+ );
1297
+ const invoice: Stripe.Invoice = event.data.object as Stripe.Invoice;
1298
+
1299
+ logger.debug(
1300
+ `[Invoice Email] Invoice details - id: ${invoice.id}, number: ${invoice.number}, customer: ${invoice.customer}, status: ${invoice.status}`,
1301
+ );
1302
+
1303
+ if (!invoice.customer) {
1304
+ logger.debug(
1305
+ `[Invoice Email] No customer on invoice ${invoice.id}, skipping`,
1306
+ );
1307
+ return;
1308
+ }
1309
+
1310
+ const customerId: string =
1311
+ typeof invoice.customer === "string"
1312
+ ? invoice.customer
1313
+ : invoice.customer.id;
1314
+
1315
+ logger.debug(
1316
+ `[Invoice Email] Extracted customer ID: ${customerId} from invoice ${invoice.id}`,
1317
+ );
1318
+
1319
+ try {
1320
+ logger.debug(
1321
+ `[Invoice Email] Checking if customer ${customerId} has invoice emails enabled`,
1322
+ );
1323
+ const shouldSend: boolean =
1324
+ await this.shouldSendInvoicesByEmail(customerId);
1325
+
1326
+ if (shouldSend && invoice.id) {
1327
+ logger.debug(
1328
+ `[Invoice Email] Customer ${customerId} has invoice emails enabled, looking up project`,
1329
+ );
1330
+
1331
+ // Find the project by Stripe customer ID
1332
+ const project: Project | null = await ProjectService.findOneBy({
1333
+ query: {
1334
+ paymentProviderCustomerId: customerId,
1335
+ },
1336
+ select: {
1337
+ _id: true,
1338
+ financeAccountingEmail: true,
1339
+ },
1340
+ props: {
1341
+ isRoot: true,
1342
+ },
1343
+ });
1344
+
1345
+ let recipientEmail: Email | undefined = undefined;
1346
+ let projectId: ObjectID | undefined = undefined;
1347
+
1348
+ if (project) {
1349
+ projectId = project.id || undefined;
1350
+ if (project.financeAccountingEmail) {
1351
+ recipientEmail = new Email(project.financeAccountingEmail);
1352
+ }
1353
+ logger.debug(
1354
+ `[Invoice Email] Found project ${projectId?.toString()}, financeAccountingEmail: ${recipientEmail?.toString()}`,
1355
+ );
1356
+ } else {
1357
+ logger.debug(
1358
+ `[Invoice Email] No project found for customer ${customerId}, will use Stripe customer email`,
1359
+ );
1360
+ }
1361
+
1362
+ logger.debug(
1363
+ `[Invoice Email] Sending invoice ${invoice.id} by email`,
1364
+ );
1365
+ await this.sendInvoiceByEmail(invoice.id, recipientEmail, projectId);
1366
+ logger.debug(
1367
+ `[Invoice Email] Successfully processed invoice.finalized - sent invoice ${invoice.id} by email`,
1368
+ );
1369
+ } else {
1370
+ logger.debug(
1371
+ `[Invoice Email] Customer ${customerId} has invoice emails disabled (shouldSend: ${shouldSend}), skipping email for invoice ${invoice.id}`,
1372
+ );
1373
+ }
1374
+ } catch (err) {
1375
+ logger.error(
1376
+ `[Invoice Email] Failed to send invoice by email for invoice ${invoice.id}: ${err}`,
1377
+ );
1378
+ // Don't throw - webhook should still return success
1379
+ }
1380
+ } else {
1381
+ logger.debug(
1382
+ `[Invoice Email] Ignoring event type ${event.type}, not invoice.finalized`,
1383
+ );
1384
+ }
1385
+ }
1038
1386
  }
1039
1387
 
1040
1388
  export default new BillingService();
@@ -29,6 +29,7 @@ export class CallService extends BaseService {
29
29
  incidentId?: ObjectID | undefined;
30
30
  alertId?: ObjectID | undefined;
31
31
  alertEpisodeId?: ObjectID | undefined;
32
+ incidentEpisodeId?: ObjectID | undefined;
32
33
  scheduledMaintenanceId?: ObjectID | undefined;
33
34
  statusPageId?: ObjectID | undefined;
34
35
  statusPageAnnouncementId?: ObjectID | undefined;
@@ -0,0 +1,94 @@
1
+ import { Blue500 } from "../../Types/BrandColors";
2
+ import Color from "../../Types/Color";
3
+ import OneUptimeDate from "../../Types/Date";
4
+ import BadDataException from "../../Types/Exception/BadDataException";
5
+ import ObjectID from "../../Types/ObjectID";
6
+ import { IsBillingEnabled } from "../EnvironmentConfig";
7
+ import logger from "../Utils/Logger";
8
+ import DatabaseService from "./DatabaseService";
9
+ import Model, {
10
+ IncidentEpisodeFeedEventType,
11
+ } from "../../Models/DatabaseModels/IncidentEpisodeFeed";
12
+ import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
13
+
14
+ export class Service extends DatabaseService<Model> {
15
+ public constructor() {
16
+ super(Model);
17
+
18
+ if (IsBillingEnabled) {
19
+ this.hardDeleteItemsOlderThanInDays("createdAt", 3 * 365); // 3 years
20
+ }
21
+ }
22
+
23
+ @CaptureSpan()
24
+ public async createIncidentEpisodeFeedItem(data: {
25
+ incidentEpisodeId: ObjectID;
26
+ feedInfoInMarkdown: string;
27
+ incidentEpisodeFeedEventType: IncidentEpisodeFeedEventType;
28
+ projectId: ObjectID;
29
+ moreInformationInMarkdown?: string | undefined;
30
+ displayColor?: Color | undefined;
31
+ userId?: ObjectID | undefined;
32
+ postedAt?: Date | undefined;
33
+ }): Promise<void> {
34
+ try {
35
+ if (!data.incidentEpisodeId) {
36
+ throw new BadDataException("Incident Episode ID is required");
37
+ }
38
+
39
+ if (!data.feedInfoInMarkdown) {
40
+ throw new BadDataException("Log in markdown is required");
41
+ }
42
+
43
+ if (!data.incidentEpisodeFeedEventType) {
44
+ throw new BadDataException("Incident episode log event is required");
45
+ }
46
+
47
+ if (!data.projectId) {
48
+ throw new BadDataException("Project ID is required");
49
+ }
50
+
51
+ const incidentEpisodeFeed: Model = new Model();
52
+
53
+ if (!data.displayColor) {
54
+ data.displayColor = Blue500;
55
+ }
56
+
57
+ if (data.userId) {
58
+ incidentEpisodeFeed.userId = data.userId;
59
+ }
60
+
61
+ incidentEpisodeFeed.displayColor = data.displayColor;
62
+
63
+ incidentEpisodeFeed.incidentEpisodeId = data.incidentEpisodeId;
64
+ incidentEpisodeFeed.feedInfoInMarkdown = data.feedInfoInMarkdown;
65
+ incidentEpisodeFeed.incidentEpisodeFeedEventType =
66
+ data.incidentEpisodeFeedEventType;
67
+ incidentEpisodeFeed.projectId = data.projectId;
68
+
69
+ if (!data.postedAt) {
70
+ incidentEpisodeFeed.postedAt = OneUptimeDate.getCurrentDate();
71
+ } else {
72
+ incidentEpisodeFeed.postedAt = data.postedAt;
73
+ }
74
+
75
+ if (data.moreInformationInMarkdown) {
76
+ incidentEpisodeFeed.moreInformationInMarkdown =
77
+ data.moreInformationInMarkdown;
78
+ }
79
+
80
+ await this.create({
81
+ data: incidentEpisodeFeed,
82
+ props: {
83
+ isRoot: true,
84
+ },
85
+ });
86
+ } catch (error) {
87
+ logger.error("IncidentEpisodeFeedService.createIncidentEpisodeFeedItem");
88
+ logger.error(error);
89
+ // we dont want to throw the error here, as this is a non-critical operation
90
+ }
91
+ }
92
+ }
93
+
94
+ export default new Service();
@@ -0,0 +1,71 @@
1
+ import ObjectID from "../../Types/ObjectID";
2
+ import DatabaseService from "./DatabaseService";
3
+ import Model from "../../Models/DatabaseModels/IncidentEpisodeInternalNote";
4
+ import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
5
+ import File from "../../Models/DatabaseModels/File";
6
+
7
+ export class Service extends DatabaseService<Model> {
8
+ public constructor() {
9
+ super(Model);
10
+ }
11
+
12
+ @CaptureSpan()
13
+ public async addNote(data: {
14
+ userId: ObjectID;
15
+ incidentEpisodeId: ObjectID;
16
+ projectId: ObjectID;
17
+ note: string;
18
+ attachmentFileIds?: Array<ObjectID>;
19
+ postedFromSlackMessageId?: string;
20
+ }): Promise<Model> {
21
+ const internalNote: Model = new Model();
22
+ internalNote.createdByUserId = data.userId;
23
+ internalNote.incidentEpisodeId = data.incidentEpisodeId;
24
+ internalNote.projectId = data.projectId;
25
+ internalNote.note = data.note;
26
+
27
+ if (data.postedFromSlackMessageId) {
28
+ internalNote.postedFromSlackMessageId = data.postedFromSlackMessageId;
29
+ }
30
+
31
+ if (data.attachmentFileIds && data.attachmentFileIds.length > 0) {
32
+ internalNote.attachments = data.attachmentFileIds.map(
33
+ (fileId: ObjectID) => {
34
+ const file: File = new File();
35
+ file.id = fileId;
36
+ return file;
37
+ },
38
+ );
39
+ }
40
+
41
+ return this.create({
42
+ data: internalNote,
43
+ props: {
44
+ isRoot: true,
45
+ },
46
+ });
47
+ }
48
+
49
+ @CaptureSpan()
50
+ public async hasNoteFromSlackMessage(data: {
51
+ incidentEpisodeId: ObjectID;
52
+ postedFromSlackMessageId: string;
53
+ }): Promise<boolean> {
54
+ const existingNote: Model | null = await this.findOneBy({
55
+ query: {
56
+ incidentEpisodeId: data.incidentEpisodeId,
57
+ postedFromSlackMessageId: data.postedFromSlackMessageId,
58
+ },
59
+ select: {
60
+ _id: true,
61
+ },
62
+ props: {
63
+ isRoot: true,
64
+ },
65
+ });
66
+
67
+ return existingNote !== null;
68
+ }
69
+ }
70
+
71
+ export default new Service();