From 55c971cd53df4d16280b1a53caf44ca1fda0bb71 Mon Sep 17 00:00:00 2001 From: slaveeks Date: Fri, 21 Nov 2025 19:45:39 +0300 Subject: [PATCH 1/3] feat(noti): added loop integration --- package.json | 5 +++-- src/models/notify.js | 5 +++++ src/rabbitmq.ts | 9 +++++++++ src/resolvers/project.js | 5 +++++ src/resolvers/projectNotifications.ts | 6 ++++++ src/typeDefs/notifications.ts | 5 +++++ src/typeDefs/notificationsInput.ts | 5 +++++ src/types/notification-channels.d.ts | 7 ++++++- src/utils/personalNotifications.ts | 10 ++++++++++ yarn.lock | 8 ++++---- 10 files changed, 58 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 1600018a..6184df1e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@graphql-tools/schema": "^8.5.1", "@graphql-tools/utils": "^8.9.0", "@hawk.so/nodejs": "^3.1.1", - "@hawk.so/types": "^0.1.33", + "@hawk.so/types": "^0.1.37", "@n1ru4l/json-patch-plus": "^0.2.0", "@types/amqp-connection-manager": "^2.0.4", "@types/bson": "^4.0.5", @@ -87,5 +87,6 @@ "safe-regex": "^2.1.0", "ts-node-dev": "^2.0.0", "uuid": "^8.3.2" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/models/notify.js b/src/models/notify.js index 78c8795e..729d6aef 100644 --- a/src/models/notify.js +++ b/src/models/notify.js @@ -90,6 +90,11 @@ class Notify { endpoint: 'slack', minPeriod: 60, }, + loop: { + isEnabled: true, + endpoint: 'loop', + minPeriod: 60, + }, telegram: { isEnabled: true, endpoint: 'telegram', diff --git a/src/rabbitmq.ts b/src/rabbitmq.ts index 1e614264..cb28ed67 100644 --- a/src/rabbitmq.ts +++ b/src/rabbitmq.ts @@ -27,6 +27,7 @@ export enum Queues { Email = 'sender/email', Telegram = 'notify/telegram', Slack = 'notify/slack', + Loop = 'notify/loop', Limiter = 'cron-tasks/limiter', } @@ -81,6 +82,14 @@ export const WorkerPaths: Record = { queue: Queues.Slack, }, + /** + * Path to loop worker + */ + Loop: { + exchange: Exchanges.Notify, + queue: Queues.Loop, + }, + /** * Path to limiter worker */ diff --git a/src/resolvers/project.js b/src/resolvers/project.js index 786aff11..f0993ef4 100644 --- a/src/resolvers/project.js +++ b/src/resolvers/project.js @@ -90,6 +90,11 @@ module.exports = { endpoint: '', minPeriod: 60, }, + loop: { + isEnabled: false, + endpoint: '', + minPeriod: 60, + }, }, }, true); diff --git a/src/resolvers/projectNotifications.ts b/src/resolvers/projectNotifications.ts index 456bdece..af8e0cec 100644 --- a/src/resolvers/projectNotifications.ts +++ b/src/resolvers/projectNotifications.ts @@ -114,6 +114,12 @@ function validateNotificationsRuleChannels(channels: NotificationsChannelsDBSche } } + if (channels.loop!.isEnabled) { + if (!/^https:\/\/.+\/hooks\/.+$/.test(channels.loop!.endpoint)) { + return 'Invalid loop endpoint passed'; + } + } + if (channels.telegram!.isEnabled) { if (!/^https:\/\/notify\.bot\.codex\.so\/u\/[A-Za-z0-9]+$/.test(channels.telegram!.endpoint)) { return 'Invalid telegram endpoint passed'; diff --git a/src/typeDefs/notifications.ts b/src/typeDefs/notifications.ts index c48fd48d..a923b26b 100644 --- a/src/typeDefs/notifications.ts +++ b/src/typeDefs/notifications.ts @@ -44,6 +44,11 @@ export default gql` """ slack: NotificationsChannelSettings + """ + Loop channel + """ + loop: NotificationsChannelSettings + """ Webpush """ diff --git a/src/typeDefs/notificationsInput.ts b/src/typeDefs/notificationsInput.ts index 71caeccf..fb9aa835 100644 --- a/src/typeDefs/notificationsInput.ts +++ b/src/typeDefs/notificationsInput.ts @@ -40,6 +40,11 @@ export default gql` """ slack: NotificationsChannelSettingsInput + """ + Loop channel + """ + loop: NotificationsChannelSettingsInput + """ Web push """ diff --git a/src/types/notification-channels.d.ts b/src/types/notification-channels.d.ts index e07dd46c..2e751e00 100644 --- a/src/types/notification-channels.d.ts +++ b/src/types/notification-channels.d.ts @@ -17,6 +17,11 @@ export interface NotificationsChannelsDBScheme { */ slack?: NotificationsChannelSettingsDBScheme; + /** + * Alerts through the Loop + */ + loop?: NotificationsChannelSettingsDBScheme; + /** * Alerts through the Telegram */ @@ -43,7 +48,7 @@ export interface NotificationsChannelSettingsDBScheme { isEnabled: boolean; /** - * Endpoint: email, slack webhook, telegram bot webhook, push subscription id, etc + * Endpoint: email, slack/loop webhook, telegram bot webhook, push subscription id, etc */ endpoint: string; diff --git a/src/utils/personalNotifications.ts b/src/utils/personalNotifications.ts index e5a3ce8f..9b3b7339 100644 --- a/src/utils/personalNotifications.ts +++ b/src/utils/personalNotifications.ts @@ -42,4 +42,14 @@ export default async function sendNotification(user: UserDBScheme, task: SenderW }, }); } + + if (user.notifications.channels.loop?.isEnabled) { + await enqueue(WorkerPaths.Loop, { + type: task.type, + payload: { + ...task.payload, + endpoint: user.notifications.channels.loop.endpoint, + }, + }); + } } diff --git a/yarn.lock b/yarn.lock index 44240cfb..239d0887 100644 --- a/yarn.lock +++ b/yarn.lock @@ -458,10 +458,10 @@ dependencies: "@types/mongodb" "^3.5.34" -"@hawk.so/types@^0.1.33": - version "0.1.33" - resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.33.tgz#feb077b699b3e0001552588a372e1efe6cd58f40" - integrity sha512-q3AdVxzQ8Qk8qyYiAcAacxNZXWTG/oLmVpjQlcLm2Eh5OJgpaZvH8hQCeRQ/ml1cqbYW8gUrRbMMCS2QOcwxEw== +"@hawk.so/types@^0.1.37": + version "0.1.37" + resolved "https://registry.yarnpkg.com/@hawk.so/types/-/types-0.1.37.tgz#e68d822957d86aac4fa1fdec7927a046ce0cf8c8" + integrity sha512-34C+TOWA5oJyOL3W+NXlSyY7u0OKkRu2+tIZ4jSJp0c1/5v+qpEPeo07FlOOHqDRRhMG4/2PAgQCronfF2qWPg== dependencies: "@types/mongodb" "^3.5.34" From f0bab0ae379752f95a026948439d06d75e18b718 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 21 Nov 2025 16:50:10 +0000 Subject: [PATCH 2/3] Bump version up to 1.2.24 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6184df1e..b040e7f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.2.23", + "version": "1.2.24", "main": "index.ts", "license": "BUSL-1.1", "scripts": { From 87b692209cc454dbde4e4c9225c9489143b33dd6 Mon Sep 17 00:00:00 2001 From: slaveeks Date: Fri, 21 Nov 2025 19:50:21 +0300 Subject: [PATCH 3/3] clear package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 6184df1e..cff393ad 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,5 @@ "safe-regex": "^2.1.0", "ts-node-dev": "^2.0.0", "uuid": "^8.3.2" - }, - "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" + } }