@oneuptime/common 7.0.3718 → 7.0.3815

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 (240) hide show
  1. package/Models/DatabaseModels/Alert.ts +3 -2
  2. package/Models/DatabaseModels/Incident.ts +3 -2
  3. package/Models/DatabaseModels/Index.ts +3 -0
  4. package/Models/DatabaseModels/ProjectUser.ts +335 -0
  5. package/Models/DatabaseModels/ScheduledMaintenance.ts +3 -2
  6. package/Server/API/SlackAPI.ts +127 -91
  7. package/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.ts +17 -0
  8. package/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.ts +17 -0
  9. package/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.ts +17 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.ts +101 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  12. package/Server/Middleware/SlackAuthorization.ts +11 -2
  13. package/Server/Services/AccessTokenService.ts +21 -0
  14. package/Server/Services/AlertFeedService.ts +100 -2
  15. package/Server/Services/AlertInternalNoteService.ts +51 -10
  16. package/Server/Services/AlertOwnerTeamService.ts +52 -4
  17. package/Server/Services/AlertOwnerUserService.ts +54 -4
  18. package/Server/Services/AlertService.ts +295 -54
  19. package/Server/Services/AlertStateService.ts +24 -0
  20. package/Server/Services/AlertStateTimelineService.ts +38 -20
  21. package/Server/Services/IncidentFeedService.ts +101 -2
  22. package/Server/Services/IncidentInternalNoteService.ts +47 -4
  23. package/Server/Services/IncidentOwnerTeamService.ts +57 -4
  24. package/Server/Services/IncidentOwnerUserService.ts +59 -15
  25. package/Server/Services/IncidentPublicNoteService.ts +47 -7
  26. package/Server/Services/IncidentService.ts +279 -193
  27. package/Server/Services/IncidentStateService.ts +25 -0
  28. package/Server/Services/IncidentStateTimelineService.ts +38 -19
  29. package/Server/Services/MonitorStatusTimelineService.ts +7 -17
  30. package/Server/Services/OnCallDutyPolicyEscalationRuleService.ts +2 -0
  31. package/Server/Services/OnCallDutyPolicyExecutionLogService.ts +74 -7
  32. package/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts +63 -4
  33. package/Server/Services/OnCallDutyPolicyService.ts +13 -0
  34. package/Server/Services/ProjectUserService.ts +130 -0
  35. package/Server/Services/ScheduledMaintenanceFeedService.ts +105 -2
  36. package/Server/Services/ScheduledMaintenanceInternalNoteService.ts +61 -15
  37. package/Server/Services/ScheduledMaintenanceOwnerTeamService.ts +59 -18
  38. package/Server/Services/ScheduledMaintenanceOwnerUserService.ts +62 -30
  39. package/Server/Services/ScheduledMaintenancePublicNoteService.ts +59 -15
  40. package/Server/Services/ScheduledMaintenanceService.ts +390 -21
  41. package/Server/Services/ScheduledMaintenanceStateService.ts +122 -34
  42. package/Server/Services/ScheduledMaintenanceStateTimelineService.ts +34 -2
  43. package/Server/Services/StatusPageSubscriberService.ts +3 -0
  44. package/Server/Services/TeamMemberService.ts +20 -0
  45. package/Server/Services/UserNotificationRuleService.ts +74 -0
  46. package/Server/Services/UserOnCallLogService.ts +1 -1
  47. package/Server/Services/UserService.ts +35 -0
  48. package/Server/Services/WorkspaceNotificationRuleService.ts +520 -149
  49. package/Server/Services/WorkspaceUserAuthTokenService.ts +23 -0
  50. package/Server/Utils/Express.ts +1 -1
  51. package/Server/Utils/StartServer.ts +6 -1
  52. package/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.ts +38 -0
  53. package/Server/Utils/Workspace/MicrosoftTeams/Messages/Alert.ts +116 -0
  54. package/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.ts +116 -0
  55. package/Server/Utils/Workspace/MicrosoftTeams/Messages/ScheduledMaintenance.ts +108 -0
  56. package/Server/Utils/Workspace/Slack/Actions/ActionTypes.ts +38 -0
  57. package/Server/Utils/Workspace/Slack/Actions/Alert.ts +697 -0
  58. package/Server/Utils/Workspace/Slack/Actions/Auth.ts +273 -0
  59. package/Server/Utils/Workspace/Slack/Actions/Incident.ts +1123 -0
  60. package/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.ts +956 -0
  61. package/Server/Utils/Workspace/Slack/Messages/Alert.ts +116 -0
  62. package/Server/Utils/Workspace/Slack/Messages/Incident.ts +116 -0
  63. package/Server/Utils/Workspace/Slack/Messages/ScheduledMaintenance.ts +108 -0
  64. package/Server/Utils/Workspace/Slack/Slack.ts +601 -18
  65. package/Server/Utils/Workspace/Slack/app-manifest.json +19 -11
  66. package/Server/Utils/Workspace/Workspace.ts +194 -1
  67. package/Server/Utils/Workspace/WorkspaceBase.ts +159 -19
  68. package/Server/Utils/Workspace/WorkspaceMessages/Alert.ts +69 -0
  69. package/Server/Utils/Workspace/WorkspaceMessages/Incident.ts +68 -0
  70. package/Server/Utils/Workspace/WorkspaceMessages/ScheduledMaintenance.ts +73 -0
  71. package/Types/Date.ts +5 -0
  72. package/Types/Icon/IconProp.ts +1 -0
  73. package/Types/Workspace/NotificationRules/NotificationRuleCondition.ts +2 -1
  74. package/Types/Workspace/NotificationRules/NotificationRuleUtil.ts +251 -121
  75. package/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.ts +6 -0
  76. package/Types/Workspace/WorkspaceMessagePayload.ts +80 -2
  77. package/UI/Components/ComingSoon/ComingSoon.tsx +13 -3
  78. package/UI/Components/Forms/Fields/FormField.tsx +2 -2
  79. package/UI/Components/Icon/Icon.tsx +39 -2
  80. package/UI/Components/ModelTable/BaseModelTable.tsx +16 -0
  81. package/UI/Components/Radio/Radio.tsx +11 -2
  82. package/UI/Components/Table/TableCard.tsx +2 -2
  83. package/build/dist/Models/DatabaseModels/Alert.js.map +1 -1
  84. package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
  85. package/build/dist/Models/DatabaseModels/Index.js +2 -0
  86. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  87. package/build/dist/Models/DatabaseModels/ProjectUser.js +340 -0
  88. package/build/dist/Models/DatabaseModels/ProjectUser.js.map +1 -0
  89. package/build/dist/Models/DatabaseModels/ScheduledMaintenance.js.map +1 -1
  90. package/build/dist/Server/API/SlackAPI.js +93 -79
  91. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  92. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js +12 -0
  93. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js.map +1 -0
  94. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js +12 -0
  95. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js.map +1 -0
  96. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js +12 -0
  97. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js.map +1 -0
  98. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js +42 -0
  99. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js.map +1 -0
  100. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  101. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  102. package/build/dist/Server/Middleware/SlackAuthorization.js +8 -2
  103. package/build/dist/Server/Middleware/SlackAuthorization.js.map +1 -1
  104. package/build/dist/Server/Services/AccessTokenService.js +11 -0
  105. package/build/dist/Server/Services/AccessTokenService.js.map +1 -1
  106. package/build/dist/Server/Services/AlertFeedService.js +62 -2
  107. package/build/dist/Server/Services/AlertFeedService.js.map +1 -1
  108. package/build/dist/Server/Services/AlertInternalNoteService.js +41 -10
  109. package/build/dist/Server/Services/AlertInternalNoteService.js.map +1 -1
  110. package/build/dist/Server/Services/AlertOwnerTeamService.js +42 -4
  111. package/build/dist/Server/Services/AlertOwnerTeamService.js.map +1 -1
  112. package/build/dist/Server/Services/AlertOwnerUserService.js +43 -5
  113. package/build/dist/Server/Services/AlertOwnerUserService.js.map +1 -1
  114. package/build/dist/Server/Services/AlertService.js +233 -51
  115. package/build/dist/Server/Services/AlertService.js.map +1 -1
  116. package/build/dist/Server/Services/AlertStateService.js +13 -0
  117. package/build/dist/Server/Services/AlertStateService.js.map +1 -1
  118. package/build/dist/Server/Services/AlertStateTimelineService.js +32 -18
  119. package/build/dist/Server/Services/AlertStateTimelineService.js.map +1 -1
  120. package/build/dist/Server/Services/IncidentFeedService.js +62 -2
  121. package/build/dist/Server/Services/IncidentFeedService.js.map +1 -1
  122. package/build/dist/Server/Services/IncidentInternalNoteService.js +35 -4
  123. package/build/dist/Server/Services/IncidentInternalNoteService.js.map +1 -1
  124. package/build/dist/Server/Services/IncidentOwnerTeamService.js +42 -4
  125. package/build/dist/Server/Services/IncidentOwnerTeamService.js.map +1 -1
  126. package/build/dist/Server/Services/IncidentOwnerUserService.js +43 -15
  127. package/build/dist/Server/Services/IncidentOwnerUserService.js.map +1 -1
  128. package/build/dist/Server/Services/IncidentPublicNoteService.js +36 -7
  129. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  130. package/build/dist/Server/Services/IncidentService.js +221 -170
  131. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  132. package/build/dist/Server/Services/IncidentStateService.js +14 -0
  133. package/build/dist/Server/Services/IncidentStateService.js.map +1 -1
  134. package/build/dist/Server/Services/IncidentStateTimelineService.js +31 -17
  135. package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
  136. package/build/dist/Server/Services/MonitorStatusTimelineService.js +5 -15
  137. package/build/dist/Server/Services/MonitorStatusTimelineService.js.map +1 -1
  138. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js +1 -0
  139. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js.map +1 -1
  140. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js +62 -7
  141. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js.map +1 -1
  142. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js +51 -5
  143. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js.map +1 -1
  144. package/build/dist/Server/Services/OnCallDutyPolicyService.js +6 -0
  145. package/build/dist/Server/Services/OnCallDutyPolicyService.js.map +1 -1
  146. package/build/dist/Server/Services/ProjectUserService.js +106 -0
  147. package/build/dist/Server/Services/ProjectUserService.js.map +1 -0
  148. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js +62 -2
  149. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js.map +1 -1
  150. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js +38 -8
  151. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js.map +1 -1
  152. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js +28 -4
  153. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js.map +1 -1
  154. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js +30 -16
  155. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js.map +1 -1
  156. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +38 -9
  157. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  158. package/build/dist/Server/Services/ScheduledMaintenanceService.js +279 -14
  159. package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
  160. package/build/dist/Server/Services/ScheduledMaintenanceStateService.js +52 -4
  161. package/build/dist/Server/Services/ScheduledMaintenanceStateService.js.map +1 -1
  162. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js +29 -2
  163. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js.map +1 -1
  164. package/build/dist/Server/Services/StatusPageSubscriberService.js +3 -0
  165. package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
  166. package/build/dist/Server/Services/TeamMemberService.js +17 -0
  167. package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
  168. package/build/dist/Server/Services/UserNotificationRuleService.js +52 -0
  169. package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
  170. package/build/dist/Server/Services/UserOnCallLogService.js +1 -1
  171. package/build/dist/Server/Services/UserOnCallLogService.js.map +1 -1
  172. package/build/dist/Server/Services/UserService.js +23 -0
  173. package/build/dist/Server/Services/UserService.js.map +1 -1
  174. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +316 -84
  175. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
  176. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js +18 -0
  177. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js.map +1 -1
  178. package/build/dist/Server/Utils/StartServer.js +4 -0
  179. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  180. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.js +37 -0
  181. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Actions/ActionTypes.js.map +1 -0
  182. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Alert.js +82 -0
  183. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Alert.js.map +1 -0
  184. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js +82 -0
  185. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js.map +1 -0
  186. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/ScheduledMaintenance.js +74 -0
  187. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/ScheduledMaintenance.js.map +1 -0
  188. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +37 -0
  189. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -0
  190. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js +425 -0
  191. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js.map +1 -0
  192. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js +169 -0
  193. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js.map +1 -0
  194. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +730 -0
  195. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -0
  196. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js +599 -0
  197. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js.map +1 -0
  198. package/build/dist/Server/Utils/Workspace/Slack/Messages/Alert.js +82 -0
  199. package/build/dist/Server/Utils/Workspace/Slack/Messages/Alert.js.map +1 -0
  200. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js +82 -0
  201. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js.map +1 -0
  202. package/build/dist/Server/Utils/Workspace/Slack/Messages/ScheduledMaintenance.js +74 -0
  203. package/build/dist/Server/Utils/Workspace/Slack/Messages/ScheduledMaintenance.js.map +1 -0
  204. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +431 -14
  205. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  206. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +19 -11
  207. package/build/dist/Server/Utils/Workspace/Workspace.js +126 -0
  208. package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
  209. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js +77 -11
  210. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js.map +1 -1
  211. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Alert.js +48 -0
  212. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Alert.js.map +1 -0
  213. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js +47 -0
  214. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js.map +1 -0
  215. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/ScheduledMaintenance.js +47 -0
  216. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/ScheduledMaintenance.js.map +1 -0
  217. package/build/dist/Types/Date.js +4 -0
  218. package/build/dist/Types/Date.js.map +1 -1
  219. package/build/dist/Types/Icon/IconProp.js +1 -0
  220. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  221. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js +2 -1
  222. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js.map +1 -1
  223. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js +214 -120
  224. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js.map +1 -1
  225. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js +2 -0
  226. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js.map +1 -0
  227. package/build/dist/UI/Components/ComingSoon/ComingSoon.js +3 -2
  228. package/build/dist/UI/Components/ComingSoon/ComingSoon.js.map +1 -1
  229. package/build/dist/UI/Components/Forms/Fields/FormField.js +2 -2
  230. package/build/dist/UI/Components/Forms/Fields/FormField.js.map +1 -1
  231. package/build/dist/UI/Components/Icon/Icon.js +19 -2
  232. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  233. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +11 -0
  234. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  235. package/build/dist/UI/Components/Radio/Radio.js +5 -2
  236. package/build/dist/UI/Components/Radio/Radio.js.map +1 -1
  237. package/build/dist/UI/Components/Table/TableCard.js +2 -2
  238. package/build/dist/UI/Components/Table/TableCard.js.map +1 -1
  239. package/package.json +3 -2
  240. package/Server/Utils/Workspace/Slack/app-manifest.example.json +0 -198
@@ -1,7 +1,6 @@
1
1
  import ObjectID from "../../Types/ObjectID";
2
2
  import WorkspaceType from "../../Types/Workspace/WorkspaceType";
3
3
  import DatabaseService from "./DatabaseService";
4
- import Model from "Common/Models/DatabaseModels/WorkspaceNotificationRule";
5
4
  import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
6
5
  import IncidentService from "./IncidentService";
7
6
  import { NotificationRuleConditionCheckOn } from "../../Types/Workspace/NotificationRules/NotificationRuleCondition";
@@ -16,9 +15,14 @@ import WorkspaceUtil from "../Utils/Workspace/Workspace";
16
15
  import WorkspaceUserAuthTokenService from "./WorkspaceUserAuthTokenService";
17
16
  import WorkspaceProjectAuthTokenService from "./WorkspaceProjectAuthTokenService";
18
17
  import logger from "../Utils/Logger";
18
+ import WorkspaceNotificationRule from "Common/Models/DatabaseModels/WorkspaceNotificationRule";
19
+ import UserService from "./UserService";
19
20
  export class Service extends DatabaseService {
20
21
  constructor() {
21
- super(Model);
22
+ super(WorkspaceNotificationRule);
23
+ }
24
+ static getAllWorkspaceTypes() {
25
+ return [WorkspaceType.Slack, WorkspaceType.MicrosoftTeams];
22
26
  }
23
27
  getBotUserIdFromprojectAuthToken(data) {
24
28
  const miscData = data.projectAuthToken.miscData;
@@ -34,7 +38,26 @@ export class Service extends DatabaseService {
34
38
  }
35
39
  throw new BadDataException("Workspace type not supported");
36
40
  }
37
- async createInviteAndPostToChannelsBasedOnRules(data) {
41
+ async getExistingChannelNamesBasedOnEventType(data) {
42
+ logger.debug("getExistingChannelNamesBasedOnEventType called with data:");
43
+ logger.debug(data);
44
+ const notificationRules = await this.getNotificationRules({
45
+ projectId: data.projectId,
46
+ workspaceType: data.workspaceType,
47
+ notificationRuleEventType: data.notificationRuleEventType,
48
+ });
49
+ logger.debug("Notification rules retrieved:");
50
+ logger.debug(notificationRules);
51
+ const existingChannelNames = this.getExistingChannelNamesFromNotificationRules({
52
+ notificationRules: notificationRules.map((rule) => {
53
+ return rule.notificationRule;
54
+ }),
55
+ }) || [];
56
+ logger.debug("Existing channel names:");
57
+ logger.debug(existingChannelNames);
58
+ return existingChannelNames;
59
+ }
60
+ async createChannelsAndInviteUsersToChannelsBasedOnRules(data) {
38
61
  logger.debug("WorkspaceNotificationRuleService.createInviteAndPostToChannelsBasedOnRules");
39
62
  logger.debug(data);
40
63
  const channelsCreated = [];
@@ -69,11 +92,9 @@ export class Service extends DatabaseService {
69
92
  }
70
93
  logger.debug("Creating channels based on rules");
71
94
  const createdWorkspaceChannels = await this.createChannelsBasedOnRules({
72
- projectOrUserAuthTokenForWorkspasce: authToken,
95
+ projectOrUserAuthTokenForWorkspace: authToken,
73
96
  workspaceType: workspaceType,
74
- notificationRules: notificationRules.map((rule) => {
75
- return rule.notificationRule;
76
- }),
97
+ notificationRules: notificationRules,
77
98
  channelNameSiffix: data.channelNameSiffix,
78
99
  notificationEventType: data.notificationRuleEventType,
79
100
  });
@@ -82,14 +103,10 @@ export class Service extends DatabaseService {
82
103
  logger.debug("Inviting users and teams to channels based on rules");
83
104
  await this.inviteUsersAndTeamsToChannelsBasedOnRules({
84
105
  projectId: data.projectId,
85
- projectOrUserAuthTokenForWorkspasce: authToken,
106
+ projectAuth: projectAuth,
86
107
  workspaceType: workspaceType,
87
- notificationRules: notificationRules.map((rule) => {
88
- return rule.notificationRule;
89
- }),
90
- channelNames: createdWorkspaceChannels.map((channel) => {
91
- return channel.name;
92
- }),
108
+ notificationRules: notificationRules,
109
+ notificationChannels: createdWorkspaceChannels,
93
110
  });
94
111
  logger.debug("Getting existing channel names from notification rules");
95
112
  const existingChannelNames = this.getExistingChannelNamesFromNotificationRules({
@@ -108,19 +125,6 @@ export class Service extends DatabaseService {
108
125
  logger.debug("Final list of channel names to post messages to:");
109
126
  logger.debug(existingChannelNames);
110
127
  logger.debug("Posting messages to workspace channels");
111
- await this.postToWorkspaceChannels({
112
- workspaceUserId: this.getBotUserIdFromprojectAuthToken({
113
- projectAuthToken: projectAuth,
114
- workspaceType: workspaceType,
115
- }),
116
- projectOrUserAuthTokenForWorkspasce: authToken,
117
- workspaceType: workspaceType,
118
- workspaceMessagePayload: {
119
- _type: "WorkspaceMessagePayload",
120
- channelNames: existingChannelNames,
121
- messageBlocks: data.messageBlocks,
122
- },
123
- });
124
128
  logger.debug("Channels created:");
125
129
  logger.debug(createdWorkspaceChannels);
126
130
  channelsCreated.push(...createdWorkspaceChannels);
@@ -130,45 +134,248 @@ export class Service extends DatabaseService {
130
134
  channelsCreated: channelsCreated,
131
135
  };
132
136
  }
133
- async postToWorkspaceChannels(data) {
134
- logger.debug("postToWorkspaceChannels called with data:");
135
- logger.debug(data);
136
- await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).sendMessage({
137
- userId: data.workspaceUserId,
138
- workspaceMessagePayload: data.workspaceMessagePayload,
139
- authToken: data.projectOrUserAuthTokenForWorkspasce,
140
- });
141
- logger.debug("Message posted to workspace channels successfully");
137
+ async getNotificationRulesWhereOnCallIsTrue(data) {
138
+ const workspaceTypes = Service.getAllWorkspaceTypes();
139
+ const result = [];
140
+ for (const workspaceType of workspaceTypes) {
141
+ // get matching notification rules
142
+ const notificationRules = await this.getMatchingNotificationRules({
143
+ projectId: data.projectId,
144
+ notificationFor: data.notificationFor,
145
+ workspaceType: workspaceType,
146
+ notificationRuleEventType: data.notificationRuleEventType,
147
+ });
148
+ const filteredNotificationRules = notificationRules.filter((rule) => {
149
+ return rule.notificationRule
150
+ .shouldAutomaticallyInviteOnCallUsersToNewChannel;
151
+ });
152
+ result.push(...filteredNotificationRules);
153
+ }
154
+ return result;
155
+ }
156
+ async getNotificationRulesWhereInviteOwnersIsTrue(data) {
157
+ const workspaceTypes = Service.getAllWorkspaceTypes();
158
+ const result = [];
159
+ for (const workspaceType of workspaceTypes) {
160
+ // get matching notification rules
161
+ const notificationRules = await this.getMatchingNotificationRules({
162
+ projectId: data.projectId,
163
+ notificationFor: data.notificationFor,
164
+ workspaceType: workspaceType,
165
+ notificationRuleEventType: data.notificationRuleEventType,
166
+ });
167
+ const filteredNotificationRules = notificationRules.filter((rule) => {
168
+ return rule.notificationRule
169
+ .shouldInviteOwnersToNewChannel;
170
+ });
171
+ result.push(...filteredNotificationRules);
172
+ }
173
+ return result;
142
174
  }
143
175
  async inviteUsersAndTeamsToChannelsBasedOnRules(data) {
176
+ var _a, _b;
144
177
  logger.debug("inviteUsersAndTeamsToChannelsBasedOnRules called with data:");
145
178
  logger.debug(data);
146
- const inviteUserIds = await this.getUsersIdsToInviteToChannel({
179
+ const inviteUserPayloads = await this.getUsersIdsToInviteToChannel({
147
180
  notificationRules: data.notificationRules,
148
181
  });
149
- logger.debug("User IDs to invite:");
150
- logger.debug(inviteUserIds);
151
- const workspaceUserIds = [];
152
- for (const userId of inviteUserIds) {
153
- const workspaceUserId = await this.getWorkspaceUserIdFromOneUptimeUserId({
154
- projectId: data.projectId,
155
- workspaceType: data.workspaceType,
156
- oneuptimeUserId: userId,
182
+ logger.debug("User IDs to invite by Workspace Notification Rule ID:");
183
+ logger.debug(inviteUserPayloads);
184
+ for (const inviteUserPayload of inviteUserPayloads) {
185
+ const userIds = inviteUserPayload.userIds;
186
+ const workspaceUserIds = [];
187
+ for (const userId of userIds) {
188
+ const workspaceUserId = await this.getWorkspaceUserIdFromOneUptimeUserId({
189
+ projectId: data.projectId,
190
+ workspaceType: data.workspaceType,
191
+ oneuptimeUserId: userId,
192
+ });
193
+ if (workspaceUserId) {
194
+ workspaceUserIds.push(workspaceUserId);
195
+ }
196
+ else {
197
+ try {
198
+ // send a message to channel that user cannot be invited because the account is not connected to workspace.
199
+ const channelIds = ((_b = (_a = data.notificationChannels) === null || _a === void 0 ? void 0 : _a.filter((channel) => {
200
+ return (channel.notificationRuleId ===
201
+ inviteUserPayload.notificationRuleId);
202
+ })) === null || _b === void 0 ? void 0 : _b.map((channel) => {
203
+ return channel.id;
204
+ })) || [];
205
+ logger.debug("Channel IDs to send message to:");
206
+ logger.debug(channelIds);
207
+ await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).sendMessage({
208
+ userId: data.projectAuth.workspaceProjectId,
209
+ authToken: data.projectAuth.authToken,
210
+ workspaceMessagePayload: {
211
+ _type: "WorkspaceMessagePayload",
212
+ channelNames: [],
213
+ channelIds: channelIds,
214
+ workspaceType: data.workspaceType,
215
+ messageBlocks: [
216
+ {
217
+ _type: "WorkspacePayloadMarkdown",
218
+ text: `${await UserService.getUserMarkdownString({
219
+ userId: userId,
220
+ projectId: data.projectId,
221
+ })} cannot be invited to the channel because the account is not connected to ${data.workspaceType}. Please go to User Settings > ${data.workspaceType} on OneUptime Dashboard and connect the account.`,
222
+ },
223
+ ],
224
+ },
225
+ });
226
+ }
227
+ catch (e) {
228
+ logger.error("Error in sending message to channel");
229
+ logger.error(e);
230
+ }
231
+ }
232
+ logger.debug("Workspace User IDs to invite:");
233
+ logger.debug(workspaceUserIds);
234
+ await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).inviteUsersToChannels({
235
+ authToken: data.projectAuth.authToken,
236
+ workspaceChannelInvitationPayload: {
237
+ channelNames: data.notificationChannels
238
+ .filter((channel) => {
239
+ return (channel.notificationRuleId ===
240
+ inviteUserPayload.notificationRuleId);
241
+ })
242
+ .map((channel) => {
243
+ return channel.name;
244
+ }),
245
+ workspaceUserIds: workspaceUserIds,
246
+ },
247
+ });
248
+ }
249
+ }
250
+ logger.debug("Users invited to channels successfully");
251
+ }
252
+ async inviteUsersBasedOnRulesAndWorkspaceChannels(data) {
253
+ // if no rules then return.
254
+ if (data.notificationRules.length === 0) {
255
+ logger.debug("No notification rules found. Returning.");
256
+ return;
257
+ }
258
+ logger.debug("inviteUsersBasedOnRulesAndWorkspaceChannels called with data:");
259
+ logger.debug(data);
260
+ const userIds = data.userIds;
261
+ logger.debug("Users:");
262
+ logger.debug(userIds);
263
+ // get all Workspaces.
264
+ const workspaceTypes = Service.getAllWorkspaceTypes();
265
+ for (const workspaceType of workspaceTypes) {
266
+ // filter rules by workspaceType.
267
+ const notificationRules = data.notificationRules.filter((rule) => {
268
+ return rule.workspaceType === workspaceType;
269
+ });
270
+ logger.debug("Notification rules for workspace type:");
271
+ logger.debug(notificationRules);
272
+ const channelsToInviteToBasedOnRule = data.workspaceChannels.filter((channel) => {
273
+ return notificationRules.find((rule) => {
274
+ var _a;
275
+ return ((_a = rule.id) === null || _a === void 0 ? void 0 : _a.toString()) === channel.notificationRuleId;
276
+ });
277
+ });
278
+ logger.debug("Channels to invite to based on rule:");
279
+ logger.debug(channelsToInviteToBasedOnRule);
280
+ if (channelsToInviteToBasedOnRule.length === 0) {
281
+ logger.debug("No channels to invite to based on rule.");
282
+ continue;
283
+ }
284
+ // get auth token for workspace.
285
+ const projectAuth = await WorkspaceProjectAuthTokenService.findOneBy({
286
+ query: {
287
+ projectId: data.projectId,
288
+ workspaceType: workspaceType,
289
+ },
290
+ select: {
291
+ authToken: true,
292
+ },
293
+ props: {
294
+ isRoot: true,
295
+ },
157
296
  });
158
- if (workspaceUserId) {
159
- workspaceUserIds.push(workspaceUserId);
297
+ if (!projectAuth) {
298
+ logger.debug("No project auth found for workspace type");
299
+ continue;
300
+ }
301
+ // inivte users to channels.
302
+ const workspaceUserIds = [];
303
+ for (const userId of userIds) {
304
+ const workspaceUserId = await this.getWorkspaceUserIdFromOneUptimeUserId({
305
+ projectId: data.projectId,
306
+ workspaceType: workspaceType,
307
+ oneuptimeUserId: userId,
308
+ });
309
+ if (workspaceUserId) {
310
+ workspaceUserIds.push(workspaceUserId);
311
+ }
312
+ else {
313
+ try {
314
+ // send a message to channel that user cannot be invited because the account is not connected to workspace.
315
+ const channelIds = channelsToInviteToBasedOnRule.map((channel) => {
316
+ return channel.id;
317
+ });
318
+ logger.debug("Channel IDs to send message to:");
319
+ logger.debug(channelIds);
320
+ await WorkspaceUtil.getWorkspaceTypeUtil(workspaceType).sendMessage({
321
+ userId: projectAuth.workspaceProjectId,
322
+ authToken: projectAuth.authToken,
323
+ workspaceMessagePayload: {
324
+ _type: "WorkspaceMessagePayload",
325
+ channelNames: [],
326
+ channelIds: channelIds,
327
+ workspaceType: workspaceType,
328
+ messageBlocks: [
329
+ {
330
+ _type: "WorkspacePayloadMarkdown",
331
+ text: `${await UserService.getUserMarkdownString({
332
+ userId: userId,
333
+ projectId: data.projectId,
334
+ })} cannot be invited to the channel because the account is not connected to ${workspaceType}. Please go to User Settings > ${workspaceType} on OneUptime Dashboard and connect the account.`,
335
+ },
336
+ ],
337
+ },
338
+ });
339
+ }
340
+ catch (e) {
341
+ logger.error("Error in sending message to channel");
342
+ logger.error(e);
343
+ }
344
+ }
160
345
  }
346
+ logger.debug("Workspace User IDs to invite:");
347
+ logger.debug(workspaceUserIds);
348
+ const channelNames = channelsToInviteToBasedOnRule.map((channel) => {
349
+ return channel.name;
350
+ });
351
+ logger.debug("Channel names to invite to:");
352
+ logger.debug(channelNames);
353
+ await WorkspaceUtil.getWorkspaceTypeUtil(workspaceType).inviteUsersToChannels({
354
+ authToken: projectAuth.authToken,
355
+ workspaceChannelInvitationPayload: {
356
+ channelNames: channelNames,
357
+ workspaceUserIds: workspaceUserIds,
358
+ },
359
+ });
161
360
  }
162
- logger.debug("Workspace User IDs to invite:");
163
- logger.debug(workspaceUserIds);
164
- await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).inviteUsersToChannels({
165
- authToken: data.projectOrUserAuthTokenForWorkspasce,
166
- workspaceChannelInvitationPayload: {
167
- channelNames: data.channelNames,
168
- workspaceUserIds: workspaceUserIds,
169
- },
361
+ }
362
+ async inviteTeamsBasedOnRulesAndWorkspaceChannels(data) {
363
+ // if no rules then return.
364
+ if (data.notificationRules.length === 0) {
365
+ logger.debug("No notification rules found. Returning.");
366
+ return;
367
+ }
368
+ const usersInTeam = await TeamMemberService.getUsersInTeams(data.teamIds);
369
+ logger.debug("Users in teams:");
370
+ logger.debug(usersInTeam);
371
+ return this.inviteUsersBasedOnRulesAndWorkspaceChannels({
372
+ workspaceChannels: data.workspaceChannels,
373
+ projectId: data.projectId,
374
+ notificationRules: data.notificationRules,
375
+ userIds: usersInTeam.map((user) => {
376
+ return user.id;
377
+ }),
170
378
  });
171
- logger.debug("Users invited to channels successfully");
172
379
  }
173
380
  async getWorkspaceUserIdFromOneUptimeUserId(data) {
174
381
  var _a;
@@ -200,31 +407,34 @@ export class Service extends DatabaseService {
200
407
  logger.debug(data);
201
408
  const createdWorkspaceChannels = [];
202
409
  const createdChannelNames = [];
203
- const newChannelNames = this.getNewChannelNamesFromNotificationRules({
410
+ const notificationChannels = this.getnotificationChannelssFromNotificationRules({
204
411
  notificationRules: data.notificationRules,
205
412
  channelNameSiffix: data.channelNameSiffix,
206
413
  notificationEventType: data.notificationEventType,
207
414
  });
208
415
  logger.debug("New channel names to be created:");
209
- logger.debug(newChannelNames);
210
- if (!newChannelNames || newChannelNames.length === 0) {
416
+ logger.debug(notificationChannels);
417
+ if (!notificationChannels || notificationChannels.length === 0) {
211
418
  logger.debug("No new channel names found. Returning empty array.");
212
419
  return [];
213
420
  }
214
- for (const newChannelName of newChannelNames) {
215
- if (createdChannelNames.includes(newChannelName)) {
216
- logger.debug(`Channel name ${newChannelName} already created. Skipping.`);
421
+ for (const notificationChannel of notificationChannels) {
422
+ if (createdChannelNames.filter((name) => {
423
+ return name === notificationChannel.channelName;
424
+ }).length > 0) {
425
+ logger.debug(`Channel name ${notificationChannel.channelName} already created. Skipping.`);
217
426
  continue;
218
427
  }
219
- logger.debug(`Creating new channel with name: ${newChannelName}`);
428
+ logger.debug(`Creating new channel with name: ${notificationChannel.channelName}`);
220
429
  const channel = await WorkspaceUtil.getWorkspaceTypeUtil(data.workspaceType).createChannel({
221
- authToken: data.projectOrUserAuthTokenForWorkspasce,
222
- channelName: newChannelName,
430
+ authToken: data.projectOrUserAuthTokenForWorkspace,
431
+ channelName: notificationChannel.channelName,
223
432
  });
433
+ const notificationWorkspaceChannel = Object.assign(Object.assign({}, channel), { notificationRuleId: notificationChannel.notificationRuleId });
224
434
  logger.debug("Channel created:");
225
435
  logger.debug(channel);
226
436
  createdChannelNames.push(channel.name);
227
- createdWorkspaceChannels.push(channel);
437
+ createdWorkspaceChannels.push(notificationWorkspaceChannel);
228
438
  }
229
439
  logger.debug("Returning created workspace channels:");
230
440
  logger.debug(createdWorkspaceChannels);
@@ -234,9 +444,10 @@ export class Service extends DatabaseService {
234
444
  var _a;
235
445
  logger.debug("getUsersIdsToInviteToChannel called with data:");
236
446
  logger.debug(data);
237
- const inviteUserIds = [];
238
- for (const notificationRule of data.notificationRules) {
239
- const workspaceRules = notificationRule;
447
+ const result = [];
448
+ for (const workspaceNotificationRule of data.notificationRules) {
449
+ const inviteUserIds = [];
450
+ const workspaceRules = workspaceNotificationRule.notificationRule;
240
451
  if (workspaceRules.shouldCreateNewChannel) {
241
452
  if (workspaceRules.inviteUsersToNewChannel &&
242
453
  workspaceRules.inviteUsersToNewChannel.length > 0) {
@@ -275,10 +486,16 @@ export class Service extends DatabaseService {
275
486
  }
276
487
  }
277
488
  }
489
+ if (inviteUserIds.length > 0) {
490
+ result.push({
491
+ notificationRuleId: workspaceNotificationRule.id.toString(),
492
+ userIds: inviteUserIds,
493
+ });
494
+ }
278
495
  }
279
496
  logger.debug("Final list of user IDs to invite:");
280
- logger.debug(inviteUserIds);
281
- return inviteUserIds;
497
+ logger.debug(result);
498
+ return result;
282
499
  }
283
500
  getExistingChannelNamesFromNotificationRules(data) {
284
501
  logger.debug("getExistingChannelNamesFromNotificationRules called with data:");
@@ -305,27 +522,31 @@ export class Service extends DatabaseService {
305
522
  logger.debug(channelNames);
306
523
  return channelNames;
307
524
  }
308
- getNewChannelNamesFromNotificationRules(data) {
309
- logger.debug("getNewChannelNamesFromNotificationRules called with data:");
525
+ getnotificationChannelssFromNotificationRules(data) {
526
+ logger.debug("getnotificationChannelssFromNotificationRules called with data:");
310
527
  logger.debug(data);
311
- const channelNames = [];
528
+ const channels = [];
312
529
  for (const notificationRule of data.notificationRules) {
313
- const workspaceRules = notificationRule;
530
+ const workspaceRules = notificationRule.notificationRule;
314
531
  logger.debug("Processing notification rule:");
315
532
  logger.debug(workspaceRules);
316
- if (workspaceRules.shouldCreateNewChannel &&
317
- workspaceRules.newChannelTemplateName) {
318
- const newChannelName = workspaceRules.newChannelTemplateName ||
533
+ if (workspaceRules.shouldCreateNewChannel) {
534
+ const notificationChannels = workspaceRules.newChannelTemplateName ||
319
535
  `oneuptime-${data.notificationEventType.toLowerCase()}-`;
320
536
  logger.debug("New channel template name:");
321
- logger.debug(newChannelName);
537
+ logger.debug(notificationChannels);
322
538
  // add suffix and then check if it is already added or not.
323
- const channelName = newChannelName + data.channelNameSiffix;
539
+ const channelName = notificationChannels + data.channelNameSiffix;
324
540
  logger.debug("Final channel name with suffix:");
325
541
  logger.debug(channelName);
326
- if (!channelNames.includes(channelName)) {
542
+ if (channels.filter((name) => {
543
+ return name.channelName === channelName;
544
+ }).length === 0) {
327
545
  // if channel name is not already added then add it.
328
- channelNames.push(channelName);
546
+ channels.push({
547
+ channelName: channelName,
548
+ notificationRuleId: notificationRule.id.toString() || "",
549
+ });
329
550
  logger.debug(`Channel name ${channelName} added to the list.`);
330
551
  }
331
552
  else {
@@ -334,8 +555,8 @@ export class Service extends DatabaseService {
334
555
  }
335
556
  }
336
557
  logger.debug("Final list of new channel names:");
337
- logger.debug(channelNames);
338
- return channelNames;
558
+ logger.debug(channels);
559
+ return channels;
339
560
  }
340
561
  async getNotificationRules(data) {
341
562
  logger.debug("getNotificationRules called with data:");
@@ -348,6 +569,8 @@ export class Service extends DatabaseService {
348
569
  },
349
570
  select: {
350
571
  notificationRule: true,
572
+ workspaceType: true,
573
+ eventType: true,
351
574
  },
352
575
  props: {
353
576
  isRoot: true,
@@ -604,17 +827,26 @@ export class Service extends DatabaseService {
604
827
  workspaceType: data.workspaceType,
605
828
  notificationRuleEventType: data.notificationRuleEventType,
606
829
  });
830
+ logger.debug("Notification rules retrieved:");
831
+ logger.debug(notificationRules);
607
832
  const values = await this.getValuesBasedOnNotificationFor({
608
833
  notificationFor: data.notificationFor,
609
834
  });
835
+ logger.debug("Values based on notification for:");
836
+ logger.debug(values);
610
837
  const matchingNotificationRules = [];
611
838
  for (const notificationRule of notificationRules) {
839
+ logger.debug("Checking if rule matches:");
612
840
  if (WorkspaceNotificationRuleUtil.isRuleMatching({
613
841
  notificationRule: notificationRule.notificationRule,
614
842
  values: values,
615
843
  })) {
844
+ logger.debug("Rule matches. Adding to the list.");
616
845
  matchingNotificationRules.push(notificationRule);
617
846
  }
847
+ else {
848
+ logger.debug("Rule does not match. Skipping.");
849
+ }
618
850
  }
619
851
  return matchingNotificationRules;
620
852
  }