Skip to content

Commit a18212c

Browse files
authored
Merge pull request #592 from codex-team/feat/loop
feat(noti): added loop integration
2 parents 5907e7a + 03bd573 commit a18212c

File tree

10 files changed

+57
-7
lines changed

10 files changed

+57
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.2.23",
3+
"version": "1.2.24",
44
"main": "index.ts",
55
"license": "BUSL-1.1",
66
"scripts": {
@@ -39,7 +39,7 @@
3939
"@graphql-tools/schema": "^8.5.1",
4040
"@graphql-tools/utils": "^8.9.0",
4141
"@hawk.so/nodejs": "^3.1.1",
42-
"@hawk.so/types": "^0.1.33",
42+
"@hawk.so/types": "^0.1.37",
4343
"@n1ru4l/json-patch-plus": "^0.2.0",
4444
"@types/amqp-connection-manager": "^2.0.4",
4545
"@types/bson": "^4.0.5",

src/models/notify.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class Notify {
9090
endpoint: 'slack',
9191
minPeriod: 60,
9292
},
93+
loop: {
94+
isEnabled: true,
95+
endpoint: 'loop',
96+
minPeriod: 60,
97+
},
9398
telegram: {
9499
isEnabled: true,
95100
endpoint: 'telegram',

src/rabbitmq.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum Queues {
2727
Email = 'sender/email',
2828
Telegram = 'notify/telegram',
2929
Slack = 'notify/slack',
30+
Loop = 'notify/loop',
3031
Limiter = 'cron-tasks/limiter',
3132
}
3233

@@ -81,6 +82,14 @@ export const WorkerPaths: Record<string, WorkerPath> = {
8182
queue: Queues.Slack,
8283
},
8384

85+
/**
86+
* Path to loop worker
87+
*/
88+
Loop: {
89+
exchange: Exchanges.Notify,
90+
queue: Queues.Loop,
91+
},
92+
8493
/**
8594
* Path to limiter worker
8695
*/

src/resolvers/project.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ module.exports = {
9090
endpoint: '',
9191
minPeriod: 60,
9292
},
93+
loop: {
94+
isEnabled: false,
95+
endpoint: '',
96+
minPeriod: 60,
97+
},
9398
},
9499
}, true);
95100

src/resolvers/projectNotifications.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ function validateNotificationsRuleChannels(channels: NotificationsChannelsDBSche
114114
}
115115
}
116116

117+
if (channels.loop!.isEnabled) {
118+
if (!/^https:\/\/.+\/hooks\/.+$/.test(channels.loop!.endpoint)) {
119+
return 'Invalid loop endpoint passed';
120+
}
121+
}
122+
117123
if (channels.telegram!.isEnabled) {
118124
if (!/^https:\/\/notify\.bot\.codex\.so\/u\/[A-Za-z0-9]+$/.test(channels.telegram!.endpoint)) {
119125
return 'Invalid telegram endpoint passed';

src/typeDefs/notifications.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export default gql`
4444
"""
4545
slack: NotificationsChannelSettings
4646
47+
"""
48+
Loop channel
49+
"""
50+
loop: NotificationsChannelSettings
51+
4752
"""
4853
Webpush
4954
"""

src/typeDefs/notificationsInput.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export default gql`
4040
"""
4141
slack: NotificationsChannelSettingsInput
4242
43+
"""
44+
Loop channel
45+
"""
46+
loop: NotificationsChannelSettingsInput
47+
4348
"""
4449
Web push
4550
"""

src/types/notification-channels.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export interface NotificationsChannelsDBScheme {
1717
*/
1818
slack?: NotificationsChannelSettingsDBScheme;
1919

20+
/**
21+
* Alerts through the Loop
22+
*/
23+
loop?: NotificationsChannelSettingsDBScheme;
24+
2025
/**
2126
* Alerts through the Telegram
2227
*/
@@ -43,7 +48,7 @@ export interface NotificationsChannelSettingsDBScheme {
4348
isEnabled: boolean;
4449

4550
/**
46-
* Endpoint: email, slack webhook, telegram bot webhook, push subscription id, etc
51+
* Endpoint: email, slack/loop webhook, telegram bot webhook, push subscription id, etc
4752
*/
4853
endpoint: string;
4954

src/utils/personalNotifications.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ export default async function sendNotification(user: UserDBScheme, task: SenderW
4242
},
4343
});
4444
}
45+
46+
if (user.notifications.channels.loop?.isEnabled) {
47+
await enqueue(WorkerPaths.Loop, {
48+
type: task.type,
49+
payload: {
50+
...task.payload,
51+
endpoint: user.notifications.channels.loop.endpoint,
52+
},
53+
});
54+
}
4555
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@
458458
dependencies:
459459
"@types/mongodb" "^3.5.34"
460460

461-
"@hawk.so/types@^0.1.33":
462-
version "0.1.33"
463-
resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.33.tgz#feb077b699b3e0001552588a372e1efe6cd58f40"
464-
integrity sha512-q3AdVxzQ8Qk8qyYiAcAacxNZXWTG/oLmVpjQlcLm2Eh5OJgpaZvH8hQCeRQ/ml1cqbYW8gUrRbMMCS2QOcwxEw==
461+
"@hawk.so/types@^0.1.37":
462+
version "0.1.37"
463+
resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.37.tgz#e68d822957d86aac4fa1fdec7927a046ce0cf8c8"
464+
integrity sha512-34C+TOWA5oJyOL3W+NXlSyY7u0OKkRu2+tIZ4jSJp0c1/5v+qpEPeo07FlOOHqDRRhMG4/2PAgQCronfF2qWPg==
465465
dependencies:
466466
"@types/mongodb" "^3.5.34"
467467

0 commit comments

Comments
 (0)