diff --git a/apps/server/Dockerfile b/apps/server/Dockerfile index 5a1983693..4a23bb6bd 100644 --- a/apps/server/Dockerfile +++ b/apps/server/Dockerfile @@ -17,6 +17,19 @@ RUN \ --mount=type=bind,target=packages/db/package.json,source=packages/db/package.json \ --mount=type=bind,target=packages/proto/package.json,source=packages/proto/package.json \ --mount=type=bind,target=packages/emails/package.json,source=packages/emails/package.json \ + --mount=type=bind,target=packages/notifications/base/package.json,source=packages/notifications/base/package.json \ + --mount=type=bind,target=packages/notifications/discord/package.json,source=packages/notifications/discord/package.json \ + --mount=type=bind,target=packages/notifications/email/package.json,source=packages/notifications/email/package.json \ + --mount=type=bind,target=packages/notifications/grafana-oncall/package.json,source=packages/notifications/grafana-oncall/package.json \ + --mount=type=bind,target=packages/notifications/google-chat/package.json,source=packages/notifications/google-chat/package.json \ + --mount=type=bind,target=packages/notifications/ntfy/package.json,source=packages/notifications/ntfy/package.json \ + --mount=type=bind,target=packages/notifications/opsgenie/package.json,source=packages/notifications/opsgenie/package.json \ + --mount=type=bind,target=packages/notifications/pagerduty/package.json,source=packages/notifications/pagerduty/package.json \ + --mount=type=bind,target=packages/notifications/slack/package.json,source=packages/notifications/slack/package.json \ + --mount=type=bind,target=packages/notifications/telegram/package.json,source=packages/notifications/telegram/package.json \ + --mount=type=bind,target=packages/notifications/twillio-whatsapp/package.json,source=packages/notifications/twillio-whatsapp/package.json \ + --mount=type=bind,target=packages/notifications/twillio-sms/package.json,source=packages/notifications/twillio-sms/package.json \ + --mount=type=bind,target=packages/notifications/webhook/package.json,source=packages/notifications/webhook/package.json \ --mount=type=bind,target=packages/error/package.json,source=packages/error/package.json \ --mount=type=bind,target=packages/regions/package.json,source=packages/regions/package.json \ --mount=type=bind,target=packages/tinybird/package.json,source=packages/tinybird/package.json \ diff --git a/apps/server/dofigen.lock b/apps/server/dofigen.lock index 82f5d659a..6f5142585 100644 --- a/apps/server/dofigen.lock +++ b/apps/server/dofigen.lock @@ -15,9 +15,9 @@ effective: | path: oven/bun digest: sha256:f20d9cf365ab35529384f1717687c739c92e6f39157a35a95ef06f4049a10e4a label: + org.opencontainers.image.base.name: docker.io/oven/bun:1.3.6 org.opencontainers.image.base.digest: sha256:f20d9cf365ab35529384f1717687c739c92e6f39157a35a95ef06f4049a10e4a org.opencontainers.image.stage: install - org.opencontainers.image.base.name: docker.io/oven/bun:1.3.6 workdir: /app/ run: - bun install --production --frozen-lockfile --verbose @@ -38,6 +38,32 @@ effective: | source: packages/proto/package.json - target: packages/emails/package.json source: packages/emails/package.json + - target: packages/notifications/base/package.json + source: packages/notifications/base/package.json + - target: packages/notifications/discord/package.json + source: packages/notifications/discord/package.json + - target: packages/notifications/email/package.json + source: packages/notifications/email/package.json + - target: packages/notifications/grafana-oncall/package.json + source: packages/notifications/grafana-oncall/package.json + - target: packages/notifications/google-chat/package.json + source: packages/notifications/google-chat/package.json + - target: packages/notifications/ntfy/package.json + source: packages/notifications/ntfy/package.json + - target: packages/notifications/opsgenie/package.json + source: packages/notifications/opsgenie/package.json + - target: packages/notifications/pagerduty/package.json + source: packages/notifications/pagerduty/package.json + - target: packages/notifications/slack/package.json + source: packages/notifications/slack/package.json + - target: packages/notifications/telegram/package.json + source: packages/notifications/telegram/package.json + - target: packages/notifications/twillio-whatsapp/package.json + source: packages/notifications/twillio-whatsapp/package.json + - target: packages/notifications/twillio-sms/package.json + source: packages/notifications/twillio-sms/package.json + - target: packages/notifications/webhook/package.json + source: packages/notifications/webhook/package.json - target: packages/error/package.json source: packages/error/package.json - target: packages/regions/package.json @@ -61,9 +87,9 @@ effective: | path: oven/bun digest: sha256:f20d9cf365ab35529384f1717687c739c92e6f39157a35a95ef06f4049a10e4a label: - org.opencontainers.image.base.name: docker.io/oven/bun:1.3.6 org.opencontainers.image.stage: build org.opencontainers.image.base.digest: sha256:f20d9cf365ab35529384f1717687c739c92e6f39157a35a95ef06f4049a10e4a + org.opencontainers.image.base.name: docker.io/oven/bun:1.3.6 workdir: /app/apps/server env: NODE_ENV: production @@ -81,13 +107,13 @@ effective: | path: debian digest: sha256:b32674fb57780ad57d7b0749242d3f585f462f4ec4a60ae0adacd945f9cb9734 label: + io.dofigen.version: 2.6.0 org.opencontainers.image.vendor: OpenStatus org.opencontainers.image.base.digest: sha256:b32674fb57780ad57d7b0749242d3f585f462f4ec4a60ae0adacd945f9cb9734 org.opencontainers.image.source: https://github.com/openstatusHQ/openstatus + org.opencontainers.image.base.name: docker.io/debian:bullseye-slim org.opencontainers.image.description: REST API server with Hono framework for OpenStatus org.opencontainers.image.authors: OpenStatus Team - org.opencontainers.image.base.name: docker.io/debian:bullseye-slim - io.dofigen.version: 2.6.0 org.opencontainers.image.title: OpenStatus Server user: user: '1000' @@ -125,7 +151,7 @@ images: digest: sha256:f20d9cf365ab35529384f1717687c739c92e6f39157a35a95ef06f4049a10e4a resources: dofigen.yml: - hash: 7e47c3833d499c7394c76a65c785330d2c16fc1b1b29b423fc71a6ec4feccd14 + hash: 534b1d0a16fe15d3ca9a01f090b1303ac7c2e011607e25167357592a6a987129 content: | # Files to exclude from Docker context ignore: @@ -154,6 +180,19 @@ resources: - packages/db/package.json - packages/proto/package.json - packages/emails/package.json + - packages/notifications/base/package.json + - packages/notifications/discord/package.json + - packages/notifications/email/package.json + - packages/notifications/grafana-oncall/package.json + - packages/notifications/google-chat/package.json + - packages/notifications/ntfy/package.json + - packages/notifications/opsgenie/package.json + - packages/notifications/pagerduty/package.json + - packages/notifications/slack/package.json + - packages/notifications/telegram/package.json + - packages/notifications/twillio-whatsapp/package.json + - packages/notifications/twillio-sms/package.json + - packages/notifications/webhook/package.json - packages/error/package.json - packages/regions/package.json - packages/tinybird/package.json diff --git a/apps/server/dofigen.yml b/apps/server/dofigen.yml index d366fc772..febe21276 100644 --- a/apps/server/dofigen.yml +++ b/apps/server/dofigen.yml @@ -25,6 +25,19 @@ builders: - packages/db/package.json - packages/proto/package.json - packages/emails/package.json + - packages/notifications/base/package.json + - packages/notifications/discord/package.json + - packages/notifications/email/package.json + - packages/notifications/grafana-oncall/package.json + - packages/notifications/google-chat/package.json + - packages/notifications/ntfy/package.json + - packages/notifications/opsgenie/package.json + - packages/notifications/pagerduty/package.json + - packages/notifications/slack/package.json + - packages/notifications/telegram/package.json + - packages/notifications/twillio-whatsapp/package.json + - packages/notifications/twillio-sms/package.json + - packages/notifications/webhook/package.json - packages/error/package.json - packages/regions/package.json - packages/tinybird/package.json diff --git a/apps/server/package.json b/apps/server/package.json index 22634c431..2f8b01478 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -24,6 +24,16 @@ "@logtape/otel": "2.0.1", "@logtape/sentry": "2.0.1", "@openstatus/analytics": "workspace:*", + "@openstatus/notification-discord": "workspace:*", + "@openstatus/notification-google-chat": "workspace:*", + "@openstatus/notification-grafana-oncall": "workspace:*", + "@openstatus/notification-ntfy": "workspace:*", + "@openstatus/notification-opsgenie": "workspace:*", + "@openstatus/notification-pagerduty": "workspace:*", + "@openstatus/notification-slack": "workspace:*", + "@openstatus/notification-telegram": "workspace:*", + "@openstatus/notification-twillio-whatsapp": "workspace:*", + "@openstatus/notification-webhook": "workspace:*", "@openstatus/assertions": "workspace:*", "@openstatus/db": "workspace:*", "@openstatus/emails": "workspace:*", diff --git a/apps/server/src/routes/rpc/router.ts b/apps/server/src/routes/rpc/router.ts index 760c8f898..d77712c42 100644 --- a/apps/server/src/routes/rpc/router.ts +++ b/apps/server/src/routes/rpc/router.ts @@ -2,6 +2,7 @@ import { createConnectRouter } from "@connectrpc/connect"; import { HealthService } from "@openstatus/proto/health/v1"; import { MaintenanceService } from "@openstatus/proto/maintenance/v1"; import { MonitorService } from "@openstatus/proto/monitor/v1"; +import { NotificationService } from "@openstatus/proto/notification/v1"; import { StatusPageService } from "@openstatus/proto/status_page/v1"; import { StatusReportService } from "@openstatus/proto/status_report/v1"; @@ -14,6 +15,7 @@ import { import { healthServiceImpl } from "./services/health"; import { maintenanceServiceImpl } from "./services/maintenance"; import { monitorServiceImpl } from "./services/monitor"; +import { notificationServiceImpl } from "./services/notification"; import { statusPageServiceImpl } from "./services/status-page"; import { statusReportServiceImpl } from "./services/status-report"; @@ -37,4 +39,5 @@ export const routes = createConnectRouter({ .service(HealthService, healthServiceImpl) .service(StatusReportService, statusReportServiceImpl) .service(StatusPageService, statusPageServiceImpl) - .service(MaintenanceService, maintenanceServiceImpl); + .service(MaintenanceService, maintenanceServiceImpl) + .service(NotificationService, notificationServiceImpl); diff --git a/apps/server/src/routes/rpc/services/notification/__tests__/notification.test.ts b/apps/server/src/routes/rpc/services/notification/__tests__/notification.test.ts new file mode 100644 index 000000000..0cd061dc0 --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/__tests__/notification.test.ts @@ -0,0 +1,847 @@ +import { afterAll, beforeAll, describe, expect, test } from "bun:test"; +import { db, eq } from "@openstatus/db"; +import { + notification, + notificationsToMonitors, +} from "@openstatus/db/src/schema"; + +import { app } from "@/index"; + +/** + * Helper to make ConnectRPC requests using the Connect protocol (JSON). + * Connect uses POST with JSON body at /rpc// + */ +async function connectRequest( + method: string, + body: Record = {}, + headers: Record = {}, +) { + return app.request( + `/rpc/openstatus.notification.v1.NotificationService/${method}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + ...headers, + }, + body: JSON.stringify(body), + }, + ); +} + +const TEST_PREFIX = "rpc-notification-test"; +let testNotificationId: number; +let testNotificationToDeleteId: number; +let testNotificationToUpdateId: number; + +beforeAll(async () => { + // Clean up any existing test data + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-main`)); + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-to-delete`)); + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-to-update`)); + + // Create test notification (email type) + const notificationRecord = await db + .insert(notification) + .values({ + workspaceId: 1, + name: `${TEST_PREFIX}-main`, + provider: "email", + data: JSON.stringify({ email: "test@example.com" }), + }) + .returning() + .get(); + testNotificationId = notificationRecord.id; + + // Create monitor association + await db.insert(notificationsToMonitors).values({ + notificationId: notificationRecord.id, + monitorId: 1, // Use seeded monitor + }); + + // Create notification to delete + const deleteRecord = await db + .insert(notification) + .values({ + workspaceId: 1, + name: `${TEST_PREFIX}-to-delete`, + provider: "discord", + data: JSON.stringify({ + discord: "https://discord.com/api/webhooks/test", + }), + }) + .returning() + .get(); + testNotificationToDeleteId = deleteRecord.id; + + // Create notification to update + const updateRecord = await db + .insert(notification) + .values({ + workspaceId: 1, + name: `${TEST_PREFIX}-to-update`, + provider: "slack", + data: JSON.stringify({ slack: "https://hooks.slack.com/services/test" }), + }) + .returning() + .get(); + testNotificationToUpdateId = updateRecord.id; + + await db.insert(notificationsToMonitors).values({ + notificationId: updateRecord.id, + monitorId: 1, + }); +}); + +afterAll(async () => { + // Clean up associations + await db + .delete(notificationsToMonitors) + .where(eq(notificationsToMonitors.notificationId, testNotificationId)); + await db + .delete(notificationsToMonitors) + .where( + eq(notificationsToMonitors.notificationId, testNotificationToUpdateId), + ); + + // Clean up notifications + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-main`)); + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-to-delete`)); + await db + .delete(notification) + .where(eq(notification.name, `${TEST_PREFIX}-to-update`)); +}); + +describe("NotificationService.CreateNotification", () => { + test("creates a new email notification", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-created-email`, + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "created@example.com", + }, + }, + monitorIds: ["1"], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notification"); + expect(data.notification.name).toBe(`${TEST_PREFIX}-created-email`); + expect(data.notification.provider).toBe("NOTIFICATION_PROVIDER_EMAIL"); + expect(data.notification.monitorIds).toContain("1"); + + // Clean up + await db + .delete(notificationsToMonitors) + .where( + eq( + notificationsToMonitors.notificationId, + Number(data.notification.id), + ), + ); + await db + .delete(notification) + .where(eq(notification.id, Number(data.notification.id))); + }); + + test("creates a new discord notification", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-created-discord`, + provider: "NOTIFICATION_PROVIDER_DISCORD", + data: { + discord: { + webhookUrl: "https://discord.com/api/webhooks/123/abc", + }, + }, + monitorIds: [], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notification"); + expect(data.notification.name).toBe(`${TEST_PREFIX}-created-discord`); + expect(data.notification.provider).toBe("NOTIFICATION_PROVIDER_DISCORD"); + + // Clean up + await db + .delete(notification) + .where(eq(notification.id, Number(data.notification.id))); + }); + + test("creates a new slack notification", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-created-slack`, + provider: "NOTIFICATION_PROVIDER_SLACK", + data: { + slack: { + webhookUrl: "https://hooks.slack.com/services/T00/B00/XXX", + }, + }, + monitorIds: [], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notification"); + expect(data.notification.provider).toBe("NOTIFICATION_PROVIDER_SLACK"); + + // Clean up + await db + .delete(notification) + .where(eq(notification.id, Number(data.notification.id))); + }); + + test("creates notification with multiple monitors", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-multi-monitor`, + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "multi@example.com", + }, + }, + monitorIds: ["1"], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data.notification.monitorIds).toContain("1"); + + // Clean up + await db + .delete(notificationsToMonitors) + .where( + eq( + notificationsToMonitors.notificationId, + Number(data.notification.id), + ), + ); + await db + .delete(notification) + .where(eq(notification.id, Number(data.notification.id))); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("CreateNotification", { + name: "Unauthorized test", + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "test@example.com", + }, + }, + monitorIds: [], + }); + + expect(res.status).toBe(401); + }); + + test("returns error for invalid monitor ID", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-invalid-monitor`, + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "test@example.com", + }, + }, + monitorIds: ["99999"], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + }); + + test("returns error for unspecified provider", async () => { + const res = await connectRequest( + "CreateNotification", + { + name: `${TEST_PREFIX}-no-provider`, + provider: "NOTIFICATION_PROVIDER_UNSPECIFIED", + data: {}, + monitorIds: [], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); +}); + +describe("NotificationService.GetNotification", () => { + test("returns notification with monitor IDs", async () => { + const res = await connectRequest( + "GetNotification", + { id: String(testNotificationId) }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notification"); + expect(data.notification.id).toBe(String(testNotificationId)); + expect(data.notification.name).toBe(`${TEST_PREFIX}-main`); + expect(data.notification.provider).toBe("NOTIFICATION_PROVIDER_EMAIL"); + expect(data.notification.monitorIds).toContain("1"); + expect(data.notification).toHaveProperty("createdAt"); + expect(data.notification).toHaveProperty("updatedAt"); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("GetNotification", { + id: String(testNotificationId), + }); + + expect(res.status).toBe(401); + }); + + test("returns 404 for non-existent notification", async () => { + const res = await connectRequest( + "GetNotification", + { id: "99999" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + }); + + test("returns 404 for notification in different workspace", async () => { + // Create notification in workspace 2 + const otherRecord = await db + .insert(notification) + .values({ + workspaceId: 2, + name: `${TEST_PREFIX}-other-workspace`, + provider: "email", + data: JSON.stringify({ email: "other@example.com" }), + }) + .returning() + .get(); + + try { + const res = await connectRequest( + "GetNotification", + { id: String(otherRecord.id) }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + } finally { + await db.delete(notification).where(eq(notification.id, otherRecord.id)); + } + }); + + test("returns error when ID is empty string", async () => { + const res = await connectRequest( + "GetNotification", + { id: "" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); +}); + +describe("NotificationService.ListNotifications", () => { + test("returns notifications for authenticated workspace", async () => { + const res = await connectRequest( + "ListNotifications", + {}, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notifications"); + expect(Array.isArray(data.notifications)).toBe(true); + expect(data).toHaveProperty("totalSize"); + }); + + test("returns notifications with correct summary structure", async () => { + const res = await connectRequest( + "ListNotifications", + { limit: 100 }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + const record = data.notifications?.find( + (n: { id: string }) => n.id === String(testNotificationId), + ); + + expect(record).toBeDefined(); + expect(record.name).toBe(`${TEST_PREFIX}-main`); + expect(record.provider).toBe("NOTIFICATION_PROVIDER_EMAIL"); + expect(record).toHaveProperty("monitorCount"); + expect(record).toHaveProperty("createdAt"); + expect(record).toHaveProperty("updatedAt"); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("ListNotifications", {}); + + expect(res.status).toBe(401); + }); + + test("respects limit parameter", async () => { + const res = await connectRequest( + "ListNotifications", + { limit: 1 }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data.notifications?.length || 0).toBeLessThanOrEqual(1); + }); + + test("respects offset parameter", async () => { + // Get total count first + const res1 = await connectRequest( + "ListNotifications", + {}, + { "x-openstatus-key": "1" }, + ); + const data1 = await res1.json(); + const totalSize = data1.totalSize; + + if (totalSize > 1) { + // Get first page + const res2 = await connectRequest( + "ListNotifications", + { limit: 1, offset: 0 }, + { "x-openstatus-key": "1" }, + ); + const data2 = await res2.json(); + + // Get second page + const res3 = await connectRequest( + "ListNotifications", + { limit: 1, offset: 1 }, + { "x-openstatus-key": "1" }, + ); + const data3 = await res3.json(); + + // Should have different notifications + if (data2.notifications?.length > 0 && data3.notifications?.length > 0) { + expect(data2.notifications[0].id).not.toBe(data3.notifications[0].id); + } + } + }); + + test("only returns notifications for authenticated workspace", async () => { + // Create notification in workspace 2 + const otherRecord = await db + .insert(notification) + .values({ + workspaceId: 2, + name: `${TEST_PREFIX}-other-workspace-list`, + provider: "email", + data: JSON.stringify({ email: "other@example.com" }), + }) + .returning() + .get(); + + try { + const res = await connectRequest( + "ListNotifications", + { limit: 100 }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + const recordIds = (data.notifications || []).map( + (n: { id: string }) => n.id, + ); + + expect(recordIds).not.toContain(String(otherRecord.id)); + } finally { + await db.delete(notification).where(eq(notification.id, otherRecord.id)); + } + }); +}); + +describe("NotificationService.UpdateNotification", () => { + test("updates notification name", async () => { + const res = await connectRequest( + "UpdateNotification", + { + id: String(testNotificationToUpdateId), + name: `${TEST_PREFIX}-updated-name`, + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data).toHaveProperty("notification"); + expect(data.notification.name).toBe(`${TEST_PREFIX}-updated-name`); + + // Restore original name + await db + .update(notification) + .set({ name: `${TEST_PREFIX}-to-update` }) + .where(eq(notification.id, testNotificationToUpdateId)); + }); + + test("updates monitor associations", async () => { + const res = await connectRequest( + "UpdateNotification", + { + id: String(testNotificationToUpdateId), + monitorIds: ["1"], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data.notification.monitorIds).toContain("1"); + }); + + test("clears monitor associations with empty array", async () => { + const res = await connectRequest( + "UpdateNotification", + { + id: String(testNotificationToUpdateId), + monitorIds: [], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + const monitorIds = data.notification.monitorIds ?? []; + expect(monitorIds).toHaveLength(0); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("UpdateNotification", { + id: String(testNotificationToUpdateId), + name: "Unauthorized update", + }); + + expect(res.status).toBe(401); + }); + + test("returns 404 for non-existent notification", async () => { + const res = await connectRequest( + "UpdateNotification", + { id: "99999", name: "Non-existent update" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + }); + + test("returns error when ID is empty string", async () => { + const res = await connectRequest( + "UpdateNotification", + { id: "", name: "Empty ID update" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); + + test("returns 404 for notification in different workspace", async () => { + // Create notification in workspace 2 + const otherRecord = await db + .insert(notification) + .values({ + workspaceId: 2, + name: `${TEST_PREFIX}-other-workspace-update`, + provider: "email", + data: JSON.stringify({ email: "other@example.com" }), + }) + .returning() + .get(); + + try { + const res = await connectRequest( + "UpdateNotification", + { id: String(otherRecord.id), name: "Should not update" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + } finally { + await db.delete(notification).where(eq(notification.id, otherRecord.id)); + } + }); + + test("returns error for invalid monitor ID on update", async () => { + const res = await connectRequest( + "UpdateNotification", + { + id: String(testNotificationToUpdateId), + monitorIds: ["99999"], + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + }); +}); + +describe("NotificationService.DeleteNotification", () => { + test("successfully deletes existing notification", async () => { + const res = await connectRequest( + "DeleteNotification", + { id: String(testNotificationToDeleteId) }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + expect(data.success).toBe(true); + + // Verify it's deleted + const deleted = await db + .select() + .from(notification) + .where(eq(notification.id, testNotificationToDeleteId)) + .get(); + expect(deleted).toBeUndefined(); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("DeleteNotification", { id: "1" }); + + expect(res.status).toBe(401); + }); + + test("returns 404 for non-existent notification", async () => { + const res = await connectRequest( + "DeleteNotification", + { id: "99999" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + }); + + test("returns error when ID is empty string", async () => { + const res = await connectRequest( + "DeleteNotification", + { id: "" }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); + + test("returns 404 for notification in different workspace", async () => { + // Create notification in workspace 2 + const otherRecord = await db + .insert(notification) + .values({ + workspaceId: 2, + name: `${TEST_PREFIX}-other-workspace-delete`, + provider: "email", + data: JSON.stringify({ email: "other@example.com" }), + }) + .returning() + .get(); + + try { + const res = await connectRequest( + "DeleteNotification", + { id: String(otherRecord.id) }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(404); + + // Verify it wasn't deleted + const stillExists = await db + .select() + .from(notification) + .where(eq(notification.id, otherRecord.id)) + .get(); + expect(stillExists).toBeDefined(); + } finally { + await db.delete(notification).where(eq(notification.id, otherRecord.id)); + } + }); +}); + +describe("NotificationService.CheckNotificationLimit", () => { + test("returns limit information for authenticated workspace", async () => { + const res = await connectRequest( + "CheckNotificationLimit", + {}, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(200); + + const data = await res.json(); + // Proto3 JSON omits fields with default values (false, 0) + // So we check that the response is valid and contains expected types + // when the values are non-default + const limitReached = data.limitReached ?? false; + const currentCount = data.currentCount ?? 0; + const maxCount = data.maxCount ?? 0; + + expect(typeof limitReached).toBe("boolean"); + expect(typeof currentCount).toBe("number"); + expect(typeof maxCount).toBe("number"); + expect(currentCount).toBeGreaterThanOrEqual(0); + expect(maxCount).toBeGreaterThanOrEqual(0); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("CheckNotificationLimit", {}); + + expect(res.status).toBe(401); + }); +}); + +describe("NotificationService.SendTestNotification", () => { + // Note: These tests verify error handling since we can't actually send + // real notifications in tests without mocking external services + + test("returns error for unsupported email provider", async () => { + const res = await connectRequest( + "SendTestNotification", + { + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "test@example.com", + }, + }, + }, + { "x-openstatus-key": "1" }, + ); + + // Email doesn't support test notifications + expect(res.status).toBe(400); + const data = await res.json(); + expect(data.message).toContain("not supported"); + }); + + test("returns error for unsupported SMS provider", async () => { + const res = await connectRequest( + "SendTestNotification", + { + provider: "NOTIFICATION_PROVIDER_SMS", + data: { + sms: { + phoneNumber: "+1234567890", + }, + }, + }, + { "x-openstatus-key": "1" }, + ); + + // SMS doesn't support test notifications + expect(res.status).toBe(400); + const data = await res.json(); + expect(data.message).toContain("not supported"); + }); + + test("returns error when no data provided", async () => { + const res = await connectRequest( + "SendTestNotification", + { + provider: "NOTIFICATION_PROVIDER_DISCORD", + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); + + test("returns error when data doesn't match provider", async () => { + const res = await connectRequest( + "SendTestNotification", + { + provider: "NOTIFICATION_PROVIDER_DISCORD", + data: { + email: { + email: "test@example.com", + }, + }, + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + const data = await res.json(); + expect(data.message).toContain("Expected discord data"); + }); + + test("returns 401 when no auth key provided", async () => { + const res = await connectRequest("SendTestNotification", { + provider: "NOTIFICATION_PROVIDER_EMAIL", + data: { + email: { + email: "test@example.com", + }, + }, + }); + + expect(res.status).toBe(401); + }); + + test("returns error for unspecified provider", async () => { + const res = await connectRequest( + "SendTestNotification", + { + provider: "NOTIFICATION_PROVIDER_UNSPECIFIED", + data: {}, + }, + { "x-openstatus-key": "1" }, + ); + + expect(res.status).toBe(400); + }); +}); diff --git a/apps/server/src/routes/rpc/services/notification/converters.ts b/apps/server/src/routes/rpc/services/notification/converters.ts new file mode 100644 index 000000000..ad23e2406 --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/converters.ts @@ -0,0 +1,395 @@ +import { create } from "@bufbuild/protobuf"; +import type { NotificationProvider as DBNotificationProvider } from "@openstatus/db/src/schema"; +import type { + Notification, + NotificationData, + NotificationSummary, +} from "@openstatus/proto/notification/v1"; +import { + NotificationDataSchema, + NotificationProvider, + NotificationSchema, + NotificationSummarySchema, + OpsgenieRegion, +} from "@openstatus/proto/notification/v1"; + +type DBNotification = { + id: number; + name: string; + provider: DBNotificationProvider; + data: string | null; + workspaceId: number | null; + createdAt: Date | null; + updatedAt: Date | null; +}; + +/** + * Maps DB provider string to proto NotificationProvider enum. + */ +export function dbProviderToProto( + provider: DBNotificationProvider, +): NotificationProvider { + const mapping: Record = { + discord: NotificationProvider.DISCORD, + email: NotificationProvider.EMAIL, + "google-chat": NotificationProvider.GOOGLE_CHAT, + "grafana-oncall": NotificationProvider.GRAFANA_ONCALL, + ntfy: NotificationProvider.NTFY, + pagerduty: NotificationProvider.PAGERDUTY, + opsgenie: NotificationProvider.OPSGENIE, + slack: NotificationProvider.SLACK, + sms: NotificationProvider.SMS, + telegram: NotificationProvider.TELEGRAM, + webhook: NotificationProvider.WEBHOOK, + whatsapp: NotificationProvider.WHATSAPP, + }; + return mapping[provider] ?? NotificationProvider.UNSPECIFIED; +} + +/** + * Maps NotificationProvider to expected NotificationData case. + */ +export function getExpectedDataCase( + provider: NotificationProvider, +): string | undefined { + const mapping: Record = { + [NotificationProvider.DISCORD]: "discord", + [NotificationProvider.EMAIL]: "email", + [NotificationProvider.GOOGLE_CHAT]: "googleChat", + [NotificationProvider.GRAFANA_ONCALL]: "grafanaOncall", + [NotificationProvider.NTFY]: "ntfy", + [NotificationProvider.PAGERDUTY]: "pagerduty", + [NotificationProvider.OPSGENIE]: "opsgenie", + [NotificationProvider.SLACK]: "slack", + [NotificationProvider.SMS]: "sms", + [NotificationProvider.TELEGRAM]: "telegram", + [NotificationProvider.WEBHOOK]: "webhook", + [NotificationProvider.WHATSAPP]: "whatsapp", + }; + return mapping[provider]; +} + +/** + * Validates that the notification data matches the provider. + * Returns an error message if validation fails, undefined if valid. + */ +export function validateProviderDataConsistency( + provider: NotificationProvider, + data: NotificationData | undefined, +): string | undefined { + if (provider === NotificationProvider.UNSPECIFIED) { + return "Provider must be specified"; + } + + const expectedCase = getExpectedDataCase(provider); + if (!expectedCase) { + return `Unknown provider: ${provider}`; + } + + if (!data || data.data.case === undefined) { + return `Provider ${NotificationProvider[provider]} requires ${expectedCase} data, but no data was provided`; + } + + const actualCase = data.data.case; + if (actualCase !== expectedCase) { + return `Provider ${NotificationProvider[provider]} requires ${expectedCase} data, got ${actualCase}`; + } + + return undefined; +} + +/** + * Maps proto NotificationProvider enum to DB provider string. + */ +export function protoProviderToDb( + provider: NotificationProvider, +): DBNotificationProvider { + const mapping: Record = { + [NotificationProvider.DISCORD]: "discord", + [NotificationProvider.EMAIL]: "email", + [NotificationProvider.GOOGLE_CHAT]: "google-chat", + [NotificationProvider.GRAFANA_ONCALL]: "grafana-oncall", + [NotificationProvider.NTFY]: "ntfy", + [NotificationProvider.PAGERDUTY]: "pagerduty", + [NotificationProvider.OPSGENIE]: "opsgenie", + [NotificationProvider.SLACK]: "slack", + [NotificationProvider.SMS]: "sms", + [NotificationProvider.TELEGRAM]: "telegram", + [NotificationProvider.WEBHOOK]: "webhook", + [NotificationProvider.WHATSAPP]: "whatsapp", + }; + return mapping[provider] ?? "email"; +} + +/** + * Parses DB JSON data string to proto NotificationData. + */ +export function dbDataToProto( + provider: DBNotificationProvider, + dataStr: string | null, +): NotificationData | undefined { + if (!dataStr) { + return undefined; + } + + try { + const data = JSON.parse(dataStr); + const protoData = create(NotificationDataSchema); + + switch (provider) { + case "discord": + if (data.discord) { + protoData.data = { + case: "discord", + value: { + $typeName: "openstatus.notification.v1.DiscordData", + webhookUrl: data.discord, + }, + }; + } + break; + case "email": + if (data.email) { + protoData.data = { + case: "email", + value: { + $typeName: "openstatus.notification.v1.EmailData", + email: data.email, + }, + }; + } + break; + case "google-chat": + if (data["google-chat"]) { + protoData.data = { + case: "googleChat", + value: { + $typeName: "openstatus.notification.v1.GoogleChatData", + webhookUrl: data["google-chat"], + }, + }; + } + break; + case "grafana-oncall": + if (data["grafana-oncall"]) { + protoData.data = { + case: "grafanaOncall", + value: { + $typeName: "openstatus.notification.v1.GrafanaOncallData", + webhookUrl: data["grafana-oncall"].webhookUrl, + }, + }; + } + break; + case "ntfy": + if (data.ntfy) { + protoData.data = { + case: "ntfy", + value: { + $typeName: "openstatus.notification.v1.NtfyData", + topic: data.ntfy.topic || "", + serverUrl: data.ntfy.serverUrl || "https://ntfy.sh", + token: data.ntfy.token, + }, + }; + } + break; + case "pagerduty": + if (data.pagerduty) { + protoData.data = { + case: "pagerduty", + value: { + $typeName: "openstatus.notification.v1.PagerDutyData", + integrationKey: data.pagerduty, + }, + }; + } + break; + case "opsgenie": + if (data.opsgenie) { + protoData.data = { + case: "opsgenie", + value: { + $typeName: "openstatus.notification.v1.OpsgenieData", + apiKey: data.opsgenie.apiKey, + region: + data.opsgenie.region === "eu" + ? OpsgenieRegion.EU + : OpsgenieRegion.US, + }, + }; + } + break; + case "slack": + if (data.slack) { + protoData.data = { + case: "slack", + value: { + $typeName: "openstatus.notification.v1.SlackData", + webhookUrl: data.slack, + }, + }; + } + break; + case "sms": + if (data.sms) { + protoData.data = { + case: "sms", + value: { + $typeName: "openstatus.notification.v1.SmsData", + phoneNumber: data.sms, + }, + }; + } + break; + case "telegram": + if (data.telegram) { + protoData.data = { + case: "telegram", + value: { + $typeName: "openstatus.notification.v1.TelegramData", + chatId: data.telegram.chatId, + }, + }; + } + break; + case "webhook": + if (data.webhook) { + protoData.data = { + case: "webhook", + value: { + $typeName: "openstatus.notification.v1.WebhookData", + endpoint: data.webhook.endpoint, + headers: + data.webhook.headers?.map( + (h: { key: string; value: string }) => ({ + $typeName: "openstatus.notification.v1.WebhookHeader", + key: h.key, + value: h.value, + }), + ) ?? [], + }, + }; + } + break; + case "whatsapp": + if (data.whatsapp) { + protoData.data = { + case: "whatsapp", + value: { + $typeName: "openstatus.notification.v1.WhatsappData", + phoneNumber: data.whatsapp, + }, + }; + } + break; + } + + return protoData; + } catch (error) { + console.error("Failed to parse notification data:", { + provider, + error: error instanceof Error ? error.message : "Unknown error", + }); + return undefined; + } +} + +/** + * Converts proto NotificationData to DB JSON string format. + */ +export function protoDataToDb( + _provider: NotificationProvider, + data: NotificationData | undefined, +): string { + if (!data || data.data.case === undefined) { + return "{}"; + } + + switch (data.data.case) { + case "discord": + return JSON.stringify({ discord: data.data.value.webhookUrl }); + case "email": + return JSON.stringify({ email: data.data.value.email }); + case "googleChat": + return JSON.stringify({ "google-chat": data.data.value.webhookUrl }); + case "grafanaOncall": + return JSON.stringify({ + "grafana-oncall": { webhookUrl: data.data.value.webhookUrl }, + }); + case "ntfy": + return JSON.stringify({ + ntfy: { + topic: data.data.value.topic, + serverUrl: data.data.value.serverUrl, + token: data.data.value.token, + }, + }); + case "pagerduty": + return JSON.stringify({ pagerduty: data.data.value.integrationKey }); + case "opsgenie": + return JSON.stringify({ + opsgenie: { + apiKey: data.data.value.apiKey, + region: data.data.value.region === OpsgenieRegion.EU ? "eu" : "us", + }, + }); + case "slack": + return JSON.stringify({ slack: data.data.value.webhookUrl }); + case "sms": + return JSON.stringify({ sms: data.data.value.phoneNumber }); + case "telegram": + return JSON.stringify({ + telegram: { chatId: data.data.value.chatId }, + }); + case "webhook": + return JSON.stringify({ + webhook: { + endpoint: data.data.value.endpoint, + headers: data.data.value.headers?.map((h) => ({ + key: h.key, + value: h.value, + })), + }, + }); + case "whatsapp": + return JSON.stringify({ whatsapp: data.data.value.phoneNumber }); + default: + return "{}"; + } +} + +/** + * Converts a DB notification to proto Notification format. + */ +export function dbNotificationToProto( + notification: DBNotification, + monitorIds: string[], +): Notification { + return create(NotificationSchema, { + id: String(notification.id), + name: notification.name, + provider: dbProviderToProto(notification.provider), + data: dbDataToProto(notification.provider, notification.data), + monitorIds, + createdAt: notification.createdAt?.toISOString() ?? "", + updatedAt: notification.updatedAt?.toISOString() ?? "", + }); +} + +/** + * Converts a DB notification to proto NotificationSummary format. + */ +export function dbNotificationToProtoSummary( + notification: DBNotification, + monitorCount: number, +): NotificationSummary { + return create(NotificationSummarySchema, { + id: String(notification.id), + name: notification.name, + provider: dbProviderToProto(notification.provider), + monitorCount, + createdAt: notification.createdAt?.toISOString() ?? "", + updatedAt: notification.updatedAt?.toISOString() ?? "", + }); +} diff --git a/apps/server/src/routes/rpc/services/notification/errors.ts b/apps/server/src/routes/rpc/services/notification/errors.ts new file mode 100644 index 000000000..b57b83694 --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/errors.ts @@ -0,0 +1,165 @@ +import { Code, ConnectError } from "@connectrpc/connect"; + +/** + * Error reasons for structured error handling. + */ +export const ErrorReason = { + NOTIFICATION_NOT_FOUND: "NOTIFICATION_NOT_FOUND", + NOTIFICATION_ID_REQUIRED: "NOTIFICATION_ID_REQUIRED", + NOTIFICATION_CREATE_FAILED: "NOTIFICATION_CREATE_FAILED", + NOTIFICATION_UPDATE_FAILED: "NOTIFICATION_UPDATE_FAILED", + NOTIFICATION_LIMIT_REACHED: "NOTIFICATION_LIMIT_REACHED", + PROVIDER_NOT_ALLOWED: "PROVIDER_NOT_ALLOWED", + PROVIDER_NOT_SUPPORTED: "PROVIDER_NOT_SUPPORTED", + INVALID_NOTIFICATION_DATA: "INVALID_NOTIFICATION_DATA", + MONITOR_NOT_FOUND: "MONITOR_NOT_FOUND", + TEST_NOTIFICATION_FAILED: "TEST_NOTIFICATION_FAILED", +} as const; + +export type ErrorReason = (typeof ErrorReason)[keyof typeof ErrorReason]; + +const DOMAIN = "openstatus.dev"; + +/** + * Creates a ConnectError with structured metadata. + */ +function createError( + message: string, + code: Code, + reason: ErrorReason, + metadata?: Record, +): ConnectError { + const headers = new Headers({ + "error-domain": DOMAIN, + "error-reason": reason, + }); + + if (metadata) { + for (const [key, value] of Object.entries(metadata)) { + headers.set(`error-${key}`, value); + } + } + + return new ConnectError(message, code, headers); +} + +/** + * Creates a "notification not found" error. + */ +export function notificationNotFoundError( + notificationId: string, +): ConnectError { + return createError( + "Notification not found", + Code.NotFound, + ErrorReason.NOTIFICATION_NOT_FOUND, + { "notification-id": notificationId }, + ); +} + +/** + * Creates a "notification ID required" error. + */ +export function notificationIdRequiredError(): ConnectError { + return createError( + "Notification ID is required", + Code.InvalidArgument, + ErrorReason.NOTIFICATION_ID_REQUIRED, + ); +} + +/** + * Creates a "failed to create notification" error. + */ +export function notificationCreateFailedError(): ConnectError { + return createError( + "Failed to create notification", + Code.Internal, + ErrorReason.NOTIFICATION_CREATE_FAILED, + ); +} + +/** + * Creates a "failed to update notification" error. + */ +export function notificationUpdateFailedError( + notificationId: string, +): ConnectError { + return createError( + "Failed to update notification", + Code.Internal, + ErrorReason.NOTIFICATION_UPDATE_FAILED, + { "notification-id": notificationId }, + ); +} + +/** + * Creates a "notification limit reached" error. + */ +export function notificationLimitReachedError(): ConnectError { + return createError( + "You have reached your notification channel limit. Upgrade to add more.", + Code.ResourceExhausted, + ErrorReason.NOTIFICATION_LIMIT_REACHED, + ); +} + +/** + * Creates a "provider not allowed" error for limited providers. + */ +export function providerNotAllowedError(provider: string): ConnectError { + return createError( + `The ${provider} provider requires an upgraded plan.`, + Code.PermissionDenied, + ErrorReason.PROVIDER_NOT_ALLOWED, + { provider }, + ); +} + +/** + * Creates a "provider not supported" error. + */ +export function providerNotSupportedError(provider: string): ConnectError { + return createError( + `The provider ${provider} is not supported for test notifications.`, + Code.InvalidArgument, + ErrorReason.PROVIDER_NOT_SUPPORTED, + { provider }, + ); +} + +/** + * Creates an "invalid notification data" error. + */ +export function invalidNotificationDataError(details: string): ConnectError { + return createError( + `Invalid notification data: ${details}`, + Code.InvalidArgument, + ErrorReason.INVALID_NOTIFICATION_DATA, + { details }, + ); +} + +/** + * Creates a "monitor not found" error. + */ +export function monitorNotFoundError(monitorId: string): ConnectError { + return createError( + "Monitor not found or not accessible", + Code.NotFound, + ErrorReason.MONITOR_NOT_FOUND, + { "monitor-id": monitorId }, + ); +} + +/** + * Creates a "test notification failed" error. + */ +export function testNotificationFailedError(message: string): ConnectError { + return createError( + `Test notification failed: ${message}`, + Code.Internal, + ErrorReason.TEST_NOTIFICATION_FAILED, + { message }, + ); +} diff --git a/apps/server/src/routes/rpc/services/notification/index.ts b/apps/server/src/routes/rpc/services/notification/index.ts new file mode 100644 index 000000000..cb14fe4d3 --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/index.ts @@ -0,0 +1,404 @@ +import type { ServiceImpl } from "@connectrpc/connect"; +import { and, count, db, desc, eq, inArray, sql } from "@openstatus/db"; +import { + monitor, + notification, + notificationsToMonitors, +} from "@openstatus/db/src/schema"; +import { + NotificationProvider, + type NotificationService, +} from "@openstatus/proto/notification/v1"; + +import { getRpcContext } from "../../interceptors"; +import { + dbNotificationToProto, + dbNotificationToProtoSummary, + dbProviderToProto, + protoDataToDb, + protoProviderToDb, + validateProviderDataConsistency, +} from "./converters"; +import { + invalidNotificationDataError, + monitorNotFoundError, + notificationCreateFailedError, + notificationIdRequiredError, + notificationNotFoundError, + notificationUpdateFailedError, +} from "./errors"; +import { + checkNotificationLimit, + checkProviderAllowed, + getNotificationLimitInfo, +} from "./limits"; +import { sendTestNotification } from "./test-providers"; + +// Type that works with both db instance and transaction +type DB = typeof db; +type Transaction = Parameters[0]>[0]; + +/** + * Helper to get a notification by ID with workspace scope. + */ +async function getNotificationById(id: number, workspaceId: number) { + return db + .select() + .from(notification) + .where( + and(eq(notification.id, id), eq(notification.workspaceId, workspaceId)), + ) + .get(); +} + +/** + * Helper to get monitor IDs for a notification. + */ +async function getMonitorIdsForNotification( + notificationId: number, +): Promise { + const monitors = await db + .select({ monitorId: notificationsToMonitors.monitorId }) + .from(notificationsToMonitors) + .where(eq(notificationsToMonitors.notificationId, notificationId)) + .all(); + + return monitors.map((m) => String(m.monitorId)); +} + +/** + * Helper to get monitor count for a notification. + */ +async function getMonitorCountForNotification( + notificationId: number, +): Promise { + const result = await db + .select({ count: count() }) + .from(notificationsToMonitors) + .where(eq(notificationsToMonitors.notificationId, notificationId)) + .get(); + + return result?.count ?? 0; +} + +/** + * Validates that all monitor IDs belong to the workspace. + * Throws monitorNotFoundError if any monitor is not found. + */ +async function validateMonitorIds( + monitorIds: string[], + workspaceId: number, + tx: DB | Transaction = db, +): Promise { + if (monitorIds.length === 0) { + return []; + } + + const numericIds = monitorIds.map((id) => Number(id)); + + const validMonitors = await tx + .select({ id: monitor.id }) + .from(monitor) + .where( + and( + inArray(monitor.id, numericIds), + eq(monitor.workspaceId, workspaceId), + ), + ) + .all(); + + const validIds = new Set(validMonitors.map((m) => m.id)); + + for (const id of numericIds) { + if (!validIds.has(id)) { + throw monitorNotFoundError(String(id)); + } + } + + return numericIds; +} + +/** + * Helper to update monitor associations for a notification. + */ +async function updateMonitorAssociations( + notificationId: number, + monitorIds: number[], + tx: DB | Transaction = db, +) { + // Delete existing associations + await tx + .delete(notificationsToMonitors) + .where(eq(notificationsToMonitors.notificationId, notificationId)); + + // Insert new associations + if (monitorIds.length > 0) { + await tx.insert(notificationsToMonitors).values( + monitorIds.map((monitorId) => ({ + notificationId, + monitorId, + })), + ); + } +} + +/** + * Notification service implementation for ConnectRPC. + */ +export const notificationServiceImpl: ServiceImpl = + { + async createNotification(req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + const limits = rpcCtx.workspace.limits; + + // Check notification limit + await checkNotificationLimit(workspaceId, limits); + + // Check if provider is allowed for this plan + checkProviderAllowed(req.provider, limits); + + // Validate provider-data consistency + const validationError = validateProviderDataConsistency( + req.provider, + req.data, + ); + if (validationError) { + throw invalidNotificationDataError(validationError); + } + + // Create notification in a transaction + const newNotification = await db.transaction(async (tx) => { + // Validate monitor IDs + const validMonitorIds = await validateMonitorIds( + req.monitorIds, + workspaceId, + tx, + ); + + // Convert proto data to DB format + const dataStr = protoDataToDb(req.provider, req.data); + + // Create the notification + const record = await tx + .insert(notification) + .values({ + name: req.name, + provider: protoProviderToDb(req.provider), + data: dataStr, + workspaceId, + }) + .returning() + .get(); + + if (!record) { + throw notificationCreateFailedError(); + } + + // Create monitor associations + await updateMonitorAssociations(record.id, validMonitorIds, tx); + + return record; + }); + + return { + notification: dbNotificationToProto(newNotification, req.monitorIds), + }; + }, + + async getNotification(req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + + if (!req.id || req.id.trim() === "") { + throw notificationIdRequiredError(); + } + + const record = await getNotificationById(Number(req.id), workspaceId); + if (!record) { + throw notificationNotFoundError(req.id); + } + + const monitorIds = await getMonitorIdsForNotification(record.id); + + return { + notification: dbNotificationToProto(record, monitorIds), + }; + }, + + async listNotifications(req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + + const limit = Math.min(Math.max(req.limit ?? 50, 1), 100); + const offset = req.offset ?? 0; + + // Get total count + const countResult = await db + .select({ count: sql`count(*)` }) + .from(notification) + .where(eq(notification.workspaceId, workspaceId)) + .get(); + + const totalCount = countResult?.count ?? 0; + + // Get notifications + const records = await db + .select() + .from(notification) + .where(eq(notification.workspaceId, workspaceId)) + .orderBy(desc(notification.createdAt)) + .limit(limit) + .offset(offset) + .all(); + + // Get monitor counts for each notification + const notifications = await Promise.all( + records.map(async (record) => { + const monitorCount = await getMonitorCountForNotification(record.id); + return dbNotificationToProtoSummary(record, monitorCount); + }), + ); + + return { + notifications, + totalSize: totalCount, + }; + }, + + async updateNotification(req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + + if (!req.id || req.id.trim() === "") { + throw notificationIdRequiredError(); + } + + const record = await getNotificationById(Number(req.id), workspaceId); + if (!record) { + throw notificationNotFoundError(req.id); + } + + // Validate provider-data consistency if data is being updated + if (req.data !== undefined) { + const existingProvider = dbProviderToProto(record.provider); + const validationError = validateProviderDataConsistency( + existingProvider, + req.data, + ); + if (validationError) { + throw invalidNotificationDataError(validationError); + } + } + + // Update notification in a transaction + const updatedNotification = await db.transaction(async (tx) => { + // Validate monitor IDs + const validMonitorIds = await validateMonitorIds( + req.monitorIds, + workspaceId, + tx, + ); + + // Build update values + const updateValues: Record = { + updatedAt: new Date(), + }; + + if (req.name !== undefined && req.name !== "") { + updateValues.name = req.name; + } + + if (req.data !== undefined) { + // Use the existing provider since we can't change provider on update + updateValues.data = protoDataToDb( + // Provider can't change, so we'll use the current data's case + req.data.data.case !== undefined + ? (() => { + // Map case to NotificationProvider + const caseToProvider: Record = { + discord: NotificationProvider.DISCORD, + email: NotificationProvider.EMAIL, + googleChat: NotificationProvider.GOOGLE_CHAT, + grafanaOncall: NotificationProvider.GRAFANA_ONCALL, + ntfy: NotificationProvider.NTFY, + pagerduty: NotificationProvider.PAGERDUTY, + opsgenie: NotificationProvider.OPSGENIE, + slack: NotificationProvider.SLACK, + sms: NotificationProvider.SMS, + telegram: NotificationProvider.TELEGRAM, + webhook: NotificationProvider.WEBHOOK, + whatsapp: NotificationProvider.WHATSAPP, + }; + return ( + caseToProvider[req.data.data.case] ?? + NotificationProvider.UNSPECIFIED + ); + })() + : 0, + req.data, + ); + } + + // Update monitor associations + await updateMonitorAssociations(record.id, validMonitorIds, tx); + + // Update the notification + const updated = await tx + .update(notification) + .set(updateValues) + .where(eq(notification.id, record.id)) + .returning() + .get(); + + if (!updated) { + throw notificationUpdateFailedError(req.id); + } + + return updated; + }); + + // Fetch updated monitor IDs + const monitorIds = await getMonitorIdsForNotification( + updatedNotification.id, + ); + + return { + notification: dbNotificationToProto(updatedNotification, monitorIds), + }; + }, + + async deleteNotification(req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + + if (!req.id || req.id.trim() === "") { + throw notificationIdRequiredError(); + } + + const record = await getNotificationById(Number(req.id), workspaceId); + if (!record) { + throw notificationNotFoundError(req.id); + } + + // Delete the notification (cascade will delete associations) + await db.delete(notification).where(eq(notification.id, record.id)); + + return { success: true }; + }, + + async sendTestNotification(req, _ctx) { + const result = await sendTestNotification(req.provider, req.data); + return result; + }, + + async checkNotificationLimit(_req, ctx) { + const rpcCtx = getRpcContext(ctx); + const workspaceId = rpcCtx.workspace.id; + const limits = rpcCtx.workspace.limits; + + const info = await getNotificationLimitInfo(workspaceId, limits); + + return info; + }, + }; diff --git a/apps/server/src/routes/rpc/services/notification/limits.ts b/apps/server/src/routes/rpc/services/notification/limits.ts new file mode 100644 index 000000000..f243a143c --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/limits.ts @@ -0,0 +1,145 @@ +import { count, db, eq } from "@openstatus/db"; +import { notification } from "@openstatus/db/src/schema"; +import type { Limits } from "@openstatus/db/src/schema/plan/schema"; +import { NotificationProvider } from "@openstatus/proto/notification/v1"; +import { + notificationLimitReachedError, + providerNotAllowedError, +} from "./errors"; + +/** + * Providers that require a paid plan. + */ +const LIMITED_PROVIDERS = new Set([ + NotificationProvider.SMS, + NotificationProvider.PAGERDUTY, + NotificationProvider.OPSGENIE, + NotificationProvider.GRAFANA_ONCALL, + NotificationProvider.WHATSAPP, +]); + +/** + * Maps proto provider to the limit key in workspace limits. + */ +function providerToLimitKey( + provider: NotificationProvider, +): keyof Limits | null { + switch (provider) { + case NotificationProvider.SMS: + return "sms"; + case NotificationProvider.PAGERDUTY: + return "pagerduty"; + case NotificationProvider.OPSGENIE: + return "opsgenie"; + case NotificationProvider.GRAFANA_ONCALL: + return "grafana-oncall"; + case NotificationProvider.WHATSAPP: + return "whatsapp"; + default: + return null; + } +} + +/** + * Maps proto provider to display name for error messages. + */ +function providerToDisplayName(provider: NotificationProvider): string { + switch (provider) { + case NotificationProvider.DISCORD: + return "Discord"; + case NotificationProvider.EMAIL: + return "Email"; + case NotificationProvider.GOOGLE_CHAT: + return "Google Chat"; + case NotificationProvider.GRAFANA_ONCALL: + return "Grafana OnCall"; + case NotificationProvider.NTFY: + return "Ntfy"; + case NotificationProvider.PAGERDUTY: + return "PagerDuty"; + case NotificationProvider.OPSGENIE: + return "Opsgenie"; + case NotificationProvider.SLACK: + return "Slack"; + case NotificationProvider.SMS: + return "SMS"; + case NotificationProvider.TELEGRAM: + return "Telegram"; + case NotificationProvider.WEBHOOK: + return "Webhook"; + case NotificationProvider.WHATSAPP: + return "WhatsApp"; + default: + return "Unknown"; + } +} + +/** + * Checks if the workspace has reached its notification limit. + * Throws notificationLimitReachedError if limit is reached. + */ +export async function checkNotificationLimit( + workspaceId: number, + limits: Limits, +): Promise { + const maxCount = limits["notification-channels"]; + + const result = await db + .select({ count: count() }) + .from(notification) + .where(eq(notification.workspaceId, workspaceId)) + .get(); + + const currentCount = result?.count ?? 0; + + if (currentCount >= maxCount) { + throw notificationLimitReachedError(); + } +} + +/** + * Checks if the provider is allowed for the workspace's plan. + * Throws providerNotAllowedError if not allowed. + */ +export function checkProviderAllowed( + provider: NotificationProvider, + limits: Limits, +): void { + if (!LIMITED_PROVIDERS.has(provider)) { + return; // Provider is free for all plans + } + + const limitKey = providerToLimitKey(provider); + if (!limitKey) { + return; // No limit key means it's free + } + + const isAllowed = limits[limitKey]; + if (!isAllowed) { + throw providerNotAllowedError(providerToDisplayName(provider)); + } +} + +/** + * Gets the current notification count and limit for a workspace. + */ +export async function getNotificationLimitInfo( + workspaceId: number, + limits: Limits, +): Promise<{ currentCount: number; maxCount: number; limitReached: boolean }> { + const maxCount = limits["notification-channels"]; + + const result = await db + .select({ count: count() }) + .from(notification) + .where(eq(notification.workspaceId, workspaceId)) + .get(); + + const currentCount = result?.count ?? 0; + + return { + currentCount, + maxCount, + limitReached: currentCount >= maxCount, + }; +} diff --git a/apps/server/src/routes/rpc/services/notification/test-providers.ts b/apps/server/src/routes/rpc/services/notification/test-providers.ts new file mode 100644 index 000000000..90c002284 --- /dev/null +++ b/apps/server/src/routes/rpc/services/notification/test-providers.ts @@ -0,0 +1,168 @@ +import { sendTestDiscordMessage } from "@openstatus/notification-discord"; +import { sendTest as sendGoogleChatTest } from "@openstatus/notification-google-chat"; +import { sendTest as sendGrafanaTest } from "@openstatus/notification-grafana-oncall"; +import { sendTest as sendNtfyTest } from "@openstatus/notification-ntfy"; +import { sendTest as sendOpsgenieTest } from "@openstatus/notification-opsgenie"; +import { sendTest as sendPagerDutyTest } from "@openstatus/notification-pagerduty"; +import { sendTestSlackMessage } from "@openstatus/notification-slack"; +import { sendTest as sendTelegramTest } from "@openstatus/notification-telegram"; +import { sendTest as sendWhatsAppTest } from "@openstatus/notification-twillio-whatsapp"; +import { sendTest as sendWebhookTest } from "@openstatus/notification-webhook"; +import { + type NotificationData, + NotificationProvider, + OpsgenieRegion, +} from "@openstatus/proto/notification/v1"; +import { + invalidNotificationDataError, + providerNotSupportedError, + testNotificationFailedError, +} from "./errors"; + +/** + * Sends a test notification using the specified provider and data. + * Throws an error if the provider is not supported or if sending fails. + */ +export async function sendTestNotification( + provider: NotificationProvider, + data: NotificationData | undefined, +): Promise<{ success: boolean; errorMessage?: string }> { + if (!data || data.data.case === undefined) { + throw invalidNotificationDataError("No provider data specified"); + } + + try { + switch (provider) { + case NotificationProvider.TELEGRAM: { + if (data.data.case !== "telegram") { + throw invalidNotificationDataError( + "Expected telegram data for Telegram provider", + ); + } + await sendTelegramTest({ chatId: data.data.value.chatId }); + return { success: true }; + } + + case NotificationProvider.WHATSAPP: { + if (data.data.case !== "whatsapp") { + throw invalidNotificationDataError( + "Expected whatsapp data for WhatsApp provider", + ); + } + await sendWhatsAppTest({ phoneNumber: data.data.value.phoneNumber }); + return { success: true }; + } + + case NotificationProvider.GOOGLE_CHAT: { + if (data.data.case !== "googleChat") { + throw invalidNotificationDataError( + "Expected google_chat data for Google Chat provider", + ); + } + await sendGoogleChatTest(data.data.value.webhookUrl); + return { success: true }; + } + + case NotificationProvider.GRAFANA_ONCALL: { + if (data.data.case !== "grafanaOncall") { + throw invalidNotificationDataError( + "Expected grafana_oncall data for Grafana OnCall provider", + ); + } + await sendGrafanaTest({ webhookUrl: data.data.value.webhookUrl }); + return { success: true }; + } + + case NotificationProvider.DISCORD: { + if (data.data.case !== "discord") { + throw invalidNotificationDataError( + "Expected discord data for Discord provider", + ); + } + await sendTestDiscordMessage(data.data.value.webhookUrl); + return { success: true }; + } + + case NotificationProvider.SLACK: { + if (data.data.case !== "slack") { + throw invalidNotificationDataError( + "Expected slack data for Slack provider", + ); + } + await sendTestSlackMessage(data.data.value.webhookUrl); + return { success: true }; + } + + case NotificationProvider.NTFY: { + if (data.data.case !== "ntfy") { + throw invalidNotificationDataError( + "Expected ntfy data for Ntfy provider", + ); + } + await sendNtfyTest({ + topic: data.data.value.topic, + serverUrl: data.data.value.serverUrl || undefined, + token: data.data.value.token, + }); + return { success: true }; + } + + case NotificationProvider.PAGERDUTY: { + if (data.data.case !== "pagerduty") { + throw invalidNotificationDataError( + "Expected pagerduty data for PagerDuty provider", + ); + } + await sendPagerDutyTest({ + integrationKey: data.data.value.integrationKey, + }); + return { success: true }; + } + + case NotificationProvider.OPSGENIE: { + if (data.data.case !== "opsgenie") { + throw invalidNotificationDataError( + "Expected opsgenie data for Opsgenie provider", + ); + } + await sendOpsgenieTest({ + apiKey: data.data.value.apiKey, + region: data.data.value.region === OpsgenieRegion.EU ? "eu" : "us", + }); + return { success: true }; + } + + case NotificationProvider.WEBHOOK: { + if (data.data.case !== "webhook") { + throw invalidNotificationDataError( + "Expected webhook data for Webhook provider", + ); + } + await sendWebhookTest({ + url: data.data.value.endpoint, + headers: data.data.value.headers?.map((h) => ({ + key: h.key, + value: h.value, + })), + }); + return { success: true }; + } + + // Providers that don't support test notifications yet + case NotificationProvider.EMAIL: + case NotificationProvider.SMS: + throw providerNotSupportedError(NotificationProvider[provider]); + + default: + throw providerNotSupportedError("Unknown"); + } + } catch (error) { + if (error instanceof Error && "code" in error) { + // Re-throw ConnectErrors as-is + throw error; + } + // Wrap other errors + const message = error instanceof Error ? error.message : "Unknown error"; + throw testNotificationFailedError(message); + } +} diff --git a/packages/proto/api/openstatus/notification/v1/notification.proto b/packages/proto/api/openstatus/notification/v1/notification.proto new file mode 100644 index 000000000..1e8c5a476 --- /dev/null +++ b/packages/proto/api/openstatus/notification/v1/notification.proto @@ -0,0 +1,41 @@ +syntax = "proto3"; + +package openstatus.notification.v1; + +import "openstatus/notification/v1/providers.proto"; + +option go_package = "github.com/openstatushq/openstatus/packages/proto/openstatus/notification/v1;notificationv1"; + +// Notification represents a notification channel with full details. +message Notification { + // Unique identifier for the notification. + string id = 1; + // Display name for the notification channel. + string name = 2; + // Provider type. + NotificationProvider provider = 3; + // Provider-specific configuration. + NotificationData data = 4; + // IDs of monitors associated with this notification. + repeated string monitor_ids = 5; + // Timestamp when the notification was created (RFC 3339). + string created_at = 6; + // Timestamp when the notification was last updated (RFC 3339). + string updated_at = 7; +} + +// NotificationSummary represents a notification channel summary for list responses. +message NotificationSummary { + // Unique identifier for the notification. + string id = 1; + // Display name for the notification channel. + string name = 2; + // Provider type. + NotificationProvider provider = 3; + // Number of monitors associated with this notification. + int32 monitor_count = 4; + // Timestamp when the notification was created (RFC 3339). + string created_at = 5; + // Timestamp when the notification was last updated (RFC 3339). + string updated_at = 6; +} diff --git a/packages/proto/api/openstatus/notification/v1/providers.proto b/packages/proto/api/openstatus/notification/v1/providers.proto new file mode 100644 index 000000000..9a91f4b15 --- /dev/null +++ b/packages/proto/api/openstatus/notification/v1/providers.proto @@ -0,0 +1,165 @@ +syntax = "proto3"; + +package openstatus.notification.v1; + +import "buf/validate/validate.proto"; + +option go_package = "github.com/openstatushq/openstatus/packages/proto/openstatus/notification/v1;notificationv1"; + +// NotificationProvider represents the supported notification channel types. +enum NotificationProvider { + // Unspecified provider. + NOTIFICATION_PROVIDER_UNSPECIFIED = 0; + // Discord webhook. + NOTIFICATION_PROVIDER_DISCORD = 1; + // Email notification. + NOTIFICATION_PROVIDER_EMAIL = 2; + // Google Chat webhook. + NOTIFICATION_PROVIDER_GOOGLE_CHAT = 3; + // Grafana OnCall webhook. + NOTIFICATION_PROVIDER_GRAFANA_ONCALL = 4; + // Ntfy notification service. + NOTIFICATION_PROVIDER_NTFY = 5; + // PagerDuty integration. + NOTIFICATION_PROVIDER_PAGERDUTY = 6; + // Opsgenie integration. + NOTIFICATION_PROVIDER_OPSGENIE = 7; + // Slack webhook. + NOTIFICATION_PROVIDER_SLACK = 8; + // SMS notification. + NOTIFICATION_PROVIDER_SMS = 9; + // Telegram bot. + NOTIFICATION_PROVIDER_TELEGRAM = 10; + // Custom webhook. + NOTIFICATION_PROVIDER_WEBHOOK = 11; + // WhatsApp notification. + NOTIFICATION_PROVIDER_WHATSAPP = 12; +} + +// DiscordData contains configuration for Discord notifications. +message DiscordData { + // Discord webhook URL. + string webhook_url = 1 [(buf.validate.field).string.uri = true]; +} + +// EmailData contains configuration for email notifications. +message EmailData { + // Email address to send notifications to. + string email = 1 [(buf.validate.field).string.email = true]; +} + +// GoogleChatData contains configuration for Google Chat notifications. +message GoogleChatData { + // Google Chat webhook URL. + string webhook_url = 1 [(buf.validate.field).string.uri = true]; +} + +// GrafanaOncallData contains configuration for Grafana OnCall notifications. +message GrafanaOncallData { + // Grafana OnCall webhook URL. + string webhook_url = 1 [(buf.validate.field).string.uri = true]; +} + +// NtfyData contains configuration for Ntfy notifications. +message NtfyData { + // Ntfy topic to publish to. + string topic = 1 [(buf.validate.field).string.min_len = 1]; + // Ntfy server URL (defaults to https://ntfy.sh). + string server_url = 2; + // Optional authentication token. + optional string token = 3; +} + +// PagerDutyData contains configuration for PagerDuty notifications. +message PagerDutyData { + // PagerDuty integration key. + string integration_key = 1 [(buf.validate.field).string.min_len = 1]; +} + +// OpsgenieRegion represents the Opsgenie API region. +enum OpsgenieRegion { + // Unspecified region. + OPSGENIE_REGION_UNSPECIFIED = 0; + // US region. + OPSGENIE_REGION_US = 1; + // EU region. + OPSGENIE_REGION_EU = 2; +} + +// OpsgenieData contains configuration for Opsgenie notifications. +message OpsgenieData { + // Opsgenie API key. + string api_key = 1 [(buf.validate.field).string.min_len = 1]; + // Opsgenie region. + OpsgenieRegion region = 2 [(buf.validate.field).enum.defined_only = true]; +} + +// SlackData contains configuration for Slack notifications. +message SlackData { + // Slack webhook URL. + string webhook_url = 1 [(buf.validate.field).string.uri = true]; +} + +// SmsData contains configuration for SMS notifications. +message SmsData { + // Phone number to send SMS to. + string phone_number = 1 [(buf.validate.field).string.min_len = 1]; +} + +// TelegramData contains configuration for Telegram notifications. +message TelegramData { + // Telegram chat ID. + string chat_id = 1 [(buf.validate.field).string.min_len = 1]; +} + +// WebhookHeader represents a custom header for webhook requests. +message WebhookHeader { + // Header name. + string key = 1 [(buf.validate.field).string.min_len = 1]; + // Header value. + string value = 2; +} + +// WebhookData contains configuration for custom webhook notifications. +message WebhookData { + // Webhook endpoint URL. + string endpoint = 1 [(buf.validate.field).string.uri = true]; + // Optional custom headers. + repeated WebhookHeader headers = 2; +} + +// WhatsappData contains configuration for WhatsApp notifications. +message WhatsappData { + // Phone number to send WhatsApp messages to. + string phone_number = 1 [(buf.validate.field).string.min_len = 1]; +} + +// NotificationData is a union of provider-specific configuration. +message NotificationData { + oneof data { + // Discord configuration. + DiscordData discord = 1; + // Email configuration. + EmailData email = 2; + // Google Chat configuration. + GoogleChatData google_chat = 3; + // Grafana OnCall configuration. + GrafanaOncallData grafana_oncall = 4; + // Ntfy configuration. + NtfyData ntfy = 5; + // PagerDuty configuration. + PagerDutyData pagerduty = 6; + // Opsgenie configuration. + OpsgenieData opsgenie = 7; + // Slack configuration. + SlackData slack = 8; + // SMS configuration. + SmsData sms = 9; + // Telegram configuration. + TelegramData telegram = 10; + // Webhook configuration. + WebhookData webhook = 11; + // WhatsApp configuration. + WhatsappData whatsapp = 12; + } +} diff --git a/packages/proto/api/openstatus/notification/v1/service.proto b/packages/proto/api/openstatus/notification/v1/service.proto new file mode 100644 index 000000000..731cd407a --- /dev/null +++ b/packages/proto/api/openstatus/notification/v1/service.proto @@ -0,0 +1,147 @@ +syntax = "proto3"; + +package openstatus.notification.v1; + +import "buf/validate/validate.proto"; +import "openstatus/notification/v1/notification.proto"; +import "openstatus/notification/v1/providers.proto"; + +option go_package = "github.com/openstatushq/openstatus/packages/proto/openstatus/notification/v1;notificationv1"; + +// NotificationService provides CRUD operations for notification channels. +service NotificationService { + // CreateNotification creates a new notification channel. + rpc CreateNotification(CreateNotificationRequest) returns (CreateNotificationResponse); + + // GetNotification retrieves a notification channel by ID. + rpc GetNotification(GetNotificationRequest) returns (GetNotificationResponse); + + // ListNotifications returns a list of notification channels. + rpc ListNotifications(ListNotificationsRequest) returns (ListNotificationsResponse); + + // UpdateNotification updates an existing notification channel. + rpc UpdateNotification(UpdateNotificationRequest) returns (UpdateNotificationResponse); + + // DeleteNotification removes a notification channel. + rpc DeleteNotification(DeleteNotificationRequest) returns (DeleteNotificationResponse); + + // SendTestNotification sends a test notification to verify configuration. + rpc SendTestNotification(SendTestNotificationRequest) returns (SendTestNotificationResponse); + + // CheckNotificationLimit checks if the workspace has reached its notification limit. + rpc CheckNotificationLimit(CheckNotificationLimitRequest) returns (CheckNotificationLimitResponse); +} + +// CreateNotificationRequest is the request to create a new notification channel. +message CreateNotificationRequest { + // Display name for the notification channel. + string name = 1 [(buf.validate.field).string.min_len = 1]; + // Provider type. + NotificationProvider provider = 2 [(buf.validate.field).enum = { + defined_only: true + not_in: [0] + }]; + // Provider-specific configuration. + NotificationData data = 3 [(buf.validate.field).required = true]; + // IDs of monitors to associate with this notification. + repeated string monitor_ids = 4; +} + +// CreateNotificationResponse is the response after creating a notification channel. +message CreateNotificationResponse { + // The created notification channel. + Notification notification = 1; +} + +// GetNotificationRequest is the request to get a notification channel. +message GetNotificationRequest { + // Notification ID to retrieve (required). + string id = 1 [(buf.validate.field).string.min_len = 1]; +} + +// GetNotificationResponse is the response containing the notification channel. +message GetNotificationResponse { + // The notification channel. + Notification notification = 1; +} + +// ListNotificationsRequest is the request to list notification channels. +message ListNotificationsRequest { + // Maximum number of notifications to return (1-100, defaults to 50). + optional int32 limit = 1 [(buf.validate.field).int32 = { + gte: 1 + lte: 100 + }]; + // Number of notifications to skip for pagination (defaults to 0). + optional int32 offset = 2 [(buf.validate.field).int32.gte = 0]; +} + +// ListNotificationsResponse is the response containing notification channels. +message ListNotificationsResponse { + // Notification channel summaries. + repeated NotificationSummary notifications = 1; + // Total number of notification channels. + int32 total_size = 2; +} + +// UpdateNotificationRequest is the request to update a notification channel. +message UpdateNotificationRequest { + // Notification ID to update (required). + string id = 1 [(buf.validate.field).string.min_len = 1]; + // Updated display name. + optional string name = 2; + // Updated provider-specific configuration. + optional NotificationData data = 3; + // Updated monitor IDs to associate. + repeated string monitor_ids = 4; +} + +// UpdateNotificationResponse is the response after updating a notification channel. +message UpdateNotificationResponse { + // The updated notification channel. + Notification notification = 1; +} + +// DeleteNotificationRequest is the request to delete a notification channel. +message DeleteNotificationRequest { + // Notification ID to delete (required). + string id = 1 [(buf.validate.field).string.min_len = 1]; +} + +// DeleteNotificationResponse is the response after deleting a notification channel. +message DeleteNotificationResponse { + // Whether the deletion was successful. + bool success = 1; +} + +// SendTestNotificationRequest is the request to send a test notification. +message SendTestNotificationRequest { + // Provider type. + NotificationProvider provider = 1 [(buf.validate.field).enum = { + defined_only: true + not_in: [0] + }]; + // Provider-specific configuration. + NotificationData data = 2 [(buf.validate.field).required = true]; +} + +// SendTestNotificationResponse is the response after sending a test notification. +message SendTestNotificationResponse { + // Whether the test was successful. + bool success = 1; + // Optional error message if the test failed. + optional string error_message = 2; +} + +// CheckNotificationLimitRequest is the request to check notification limits. +message CheckNotificationLimitRequest {} + +// CheckNotificationLimitResponse is the response containing limit information. +message CheckNotificationLimitResponse { + // Whether the workspace has reached its notification limit. + bool limit_reached = 1; + // Current number of notification channels. + int32 current_count = 2; + // Maximum allowed notification channels. + int32 max_count = 3; +} diff --git a/packages/proto/gen/ts/openstatus/notification/v1/index.ts b/packages/proto/gen/ts/openstatus/notification/v1/index.ts new file mode 100644 index 000000000..a7baf1db9 --- /dev/null +++ b/packages/proto/gen/ts/openstatus/notification/v1/index.ts @@ -0,0 +1,4 @@ +// Notification service exports +export * from "./providers_pb.js"; +export * from "./notification_pb.js"; +export * from "./service_pb.js"; diff --git a/packages/proto/gen/ts/openstatus/notification/v1/notification_pb.ts b/packages/proto/gen/ts/openstatus/notification/v1/notification_pb.ts new file mode 100644 index 000000000..478269db6 --- /dev/null +++ b/packages/proto/gen/ts/openstatus/notification/v1/notification_pb.ts @@ -0,0 +1,135 @@ +// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.ts" +// @generated from file openstatus/notification/v1/notification.proto (package openstatus.notification.v1, syntax proto3) +/* eslint-disable */ + +import type { GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2"; +import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; +import type { NotificationData, NotificationProvider } from "./providers_pb.ts"; +import { file_openstatus_notification_v1_providers } from "./providers_pb.ts"; +import type { Message } from "@bufbuild/protobuf"; + +/** + * Describes the file openstatus/notification/v1/notification.proto. + */ +export const file_openstatus_notification_v1_notification: GenFile = /*@__PURE__*/ + fileDesc("Ci1vcGVuc3RhdHVzL25vdGlmaWNhdGlvbi92MS9ub3RpZmljYXRpb24ucHJvdG8SGm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxIuUBCgxOb3RpZmljYXRpb24SCgoCaWQYASABKAkSDAoEbmFtZRgCIAEoCRJCCghwcm92aWRlchgDIAEoDjIwLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLk5vdGlmaWNhdGlvblByb3ZpZGVyEjoKBGRhdGEYBCABKAsyLC5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Ob3RpZmljYXRpb25EYXRhEhMKC21vbml0b3JfaWRzGAUgAygJEhIKCmNyZWF0ZWRfYXQYBiABKAkSEgoKdXBkYXRlZF9hdBgHIAEoCSKyAQoTTm90aWZpY2F0aW9uU3VtbWFyeRIKCgJpZBgBIAEoCRIMCgRuYW1lGAIgASgJEkIKCHByb3ZpZGVyGAMgASgOMjAub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuTm90aWZpY2F0aW9uUHJvdmlkZXISFQoNbW9uaXRvcl9jb3VudBgEIAEoBRISCgpjcmVhdGVkX2F0GAUgASgJEhIKCnVwZGF0ZWRfYXQYBiABKAlCXVpbZ2l0aHViLmNvbS9vcGVuc3RhdHVzaHEvb3BlbnN0YXR1cy9wYWNrYWdlcy9wcm90by9vcGVuc3RhdHVzL25vdGlmaWNhdGlvbi92MTtub3RpZmljYXRpb252MWIGcHJvdG8z", [file_openstatus_notification_v1_providers]); + +/** + * Notification represents a notification channel with full details. + * + * @generated from message openstatus.notification.v1.Notification + */ +export type Notification = Message<"openstatus.notification.v1.Notification"> & { + /** + * Unique identifier for the notification. + * + * @generated from field: string id = 1; + */ + id: string; + + /** + * Display name for the notification channel. + * + * @generated from field: string name = 2; + */ + name: string; + + /** + * Provider type. + * + * @generated from field: openstatus.notification.v1.NotificationProvider provider = 3; + */ + provider: NotificationProvider; + + /** + * Provider-specific configuration. + * + * @generated from field: openstatus.notification.v1.NotificationData data = 4; + */ + data?: NotificationData; + + /** + * IDs of monitors associated with this notification. + * + * @generated from field: repeated string monitor_ids = 5; + */ + monitorIds: string[]; + + /** + * Timestamp when the notification was created (RFC 3339). + * + * @generated from field: string created_at = 6; + */ + createdAt: string; + + /** + * Timestamp when the notification was last updated (RFC 3339). + * + * @generated from field: string updated_at = 7; + */ + updatedAt: string; +}; + +/** + * Describes the message openstatus.notification.v1.Notification. + * Use `create(NotificationSchema)` to create a new message. + */ +export const NotificationSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_notification, 0); + +/** + * NotificationSummary represents a notification channel summary for list responses. + * + * @generated from message openstatus.notification.v1.NotificationSummary + */ +export type NotificationSummary = Message<"openstatus.notification.v1.NotificationSummary"> & { + /** + * Unique identifier for the notification. + * + * @generated from field: string id = 1; + */ + id: string; + + /** + * Display name for the notification channel. + * + * @generated from field: string name = 2; + */ + name: string; + + /** + * Provider type. + * + * @generated from field: openstatus.notification.v1.NotificationProvider provider = 3; + */ + provider: NotificationProvider; + + /** + * Number of monitors associated with this notification. + * + * @generated from field: int32 monitor_count = 4; + */ + monitorCount: number; + + /** + * Timestamp when the notification was created (RFC 3339). + * + * @generated from field: string created_at = 5; + */ + createdAt: string; + + /** + * Timestamp when the notification was last updated (RFC 3339). + * + * @generated from field: string updated_at = 6; + */ + updatedAt: string; +}; + +/** + * Describes the message openstatus.notification.v1.NotificationSummary. + * Use `create(NotificationSummarySchema)` to create a new message. + */ +export const NotificationSummarySchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_notification, 1); + diff --git a/packages/proto/gen/ts/openstatus/notification/v1/providers_pb.ts b/packages/proto/gen/ts/openstatus/notification/v1/providers_pb.ts new file mode 100644 index 000000000..f8b5e4c7c --- /dev/null +++ b/packages/proto/gen/ts/openstatus/notification/v1/providers_pb.ts @@ -0,0 +1,576 @@ +// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.ts" +// @generated from file openstatus/notification/v1/providers.proto (package openstatus.notification.v1, syntax proto3) +/* eslint-disable */ + +import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2"; +import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv2"; +import { file_buf_validate_validate } from "../../../buf/validate/validate_pb.ts"; +import type { Message } from "@bufbuild/protobuf"; + +/** + * Describes the file openstatus/notification/v1/providers.proto. + */ +export const file_openstatus_notification_v1_providers: GenFile = /*@__PURE__*/ + fileDesc("CipvcGVuc3RhdHVzL25vdGlmaWNhdGlvbi92MS9wcm92aWRlcnMucHJvdG8SGm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxIiwKC0Rpc2NvcmREYXRhEh0KC3dlYmhvb2tfdXJsGAEgASgJQgi6SAVyA4gBASIjCglFbWFpbERhdGESFgoFZW1haWwYASABKAlCB7pIBHICYAEiLwoOR29vZ2xlQ2hhdERhdGESHQoLd2ViaG9va191cmwYASABKAlCCLpIBXIDiAEBIjIKEUdyYWZhbmFPbmNhbGxEYXRhEh0KC3dlYmhvb2tfdXJsGAEgASgJQgi6SAVyA4gBASJUCghOdGZ5RGF0YRIWCgV0b3BpYxgBIAEoCUIHukgEcgIQARISCgpzZXJ2ZXJfdXJsGAIgASgJEhIKBXRva2VuGAMgASgJSACIAQFCCAoGX3Rva2VuIjEKDVBhZ2VyRHV0eURhdGESIAoPaW50ZWdyYXRpb25fa2V5GAEgASgJQge6SARyAhABIm4KDE9wc2dlbmllRGF0YRIYCgdhcGlfa2V5GAEgASgJQge6SARyAhABEkQKBnJlZ2lvbhgCIAEoDjIqLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLk9wc2dlbmllUmVnaW9uQgi6SAWCAQIQASIqCglTbGFja0RhdGESHQoLd2ViaG9va191cmwYASABKAlCCLpIBXIDiAEBIigKB1Ntc0RhdGESHQoMcGhvbmVfbnVtYmVyGAEgASgJQge6SARyAhABIigKDFRlbGVncmFtRGF0YRIYCgdjaGF0X2lkGAEgASgJQge6SARyAhABIjQKDVdlYmhvb2tIZWFkZXISFAoDa2V5GAEgASgJQge6SARyAhABEg0KBXZhbHVlGAIgASgJImUKC1dlYmhvb2tEYXRhEhoKCGVuZHBvaW50GAEgASgJQgi6SAVyA4gBARI6CgdoZWFkZXJzGAIgAygLMikub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuV2ViaG9va0hlYWRlciItCgxXaGF0c2FwcERhdGESHQoMcGhvbmVfbnVtYmVyGAEgASgJQge6SARyAhABIvIFChBOb3RpZmljYXRpb25EYXRhEjoKB2Rpc2NvcmQYASABKAsyJy5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5EaXNjb3JkRGF0YUgAEjYKBWVtYWlsGAIgASgLMiUub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuRW1haWxEYXRhSAASQQoLZ29vZ2xlX2NoYXQYAyABKAsyKi5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Hb29nbGVDaGF0RGF0YUgAEkcKDmdyYWZhbmFfb25jYWxsGAQgASgLMi0ub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuR3JhZmFuYU9uY2FsbERhdGFIABI0CgRudGZ5GAUgASgLMiQub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuTnRmeURhdGFIABI+CglwYWdlcmR1dHkYBiABKAsyKS5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5QYWdlckR1dHlEYXRhSAASPAoIb3BzZ2VuaWUYByABKAsyKC5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5PcHNnZW5pZURhdGFIABI2CgVzbGFjaxgIIAEoCzIlLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlNsYWNrRGF0YUgAEjIKA3NtcxgJIAEoCzIjLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlNtc0RhdGFIABI8Cgh0ZWxlZ3JhbRgKIAEoCzIoLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlRlbGVncmFtRGF0YUgAEjoKB3dlYmhvb2sYCyABKAsyJy5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5XZWJob29rRGF0YUgAEjwKCHdoYXRzYXBwGAwgASgLMigub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuV2hhdHNhcHBEYXRhSABCBgoEZGF0YSrmAwoUTm90aWZpY2F0aW9uUHJvdmlkZXISJQohTk9USUZJQ0FUSU9OX1BST1ZJREVSX1VOU1BFQ0lGSUVEEAASIQodTk9USUZJQ0FUSU9OX1BST1ZJREVSX0RJU0NPUkQQARIfChtOT1RJRklDQVRJT05fUFJPVklERVJfRU1BSUwQAhIlCiFOT1RJRklDQVRJT05fUFJPVklERVJfR09PR0xFX0NIQVQQAxIoCiROT1RJRklDQVRJT05fUFJPVklERVJfR1JBRkFOQV9PTkNBTEwQBBIeChpOT1RJRklDQVRJT05fUFJPVklERVJfTlRGWRAFEiMKH05PVElGSUNBVElPTl9QUk9WSURFUl9QQUdFUkRVVFkQBhIiCh5OT1RJRklDQVRJT05fUFJPVklERVJfT1BTR0VOSUUQBxIfChtOT1RJRklDQVRJT05fUFJPVklERVJfU0xBQ0sQCBIdChlOT1RJRklDQVRJT05fUFJPVklERVJfU01TEAkSIgoeTk9USUZJQ0FUSU9OX1BST1ZJREVSX1RFTEVHUkFNEAoSIQodTk9USUZJQ0FUSU9OX1BST1ZJREVSX1dFQkhPT0sQCxIiCh5OT1RJRklDQVRJT05fUFJPVklERVJfV0hBVFNBUFAQDCphCg5PcHNnZW5pZVJlZ2lvbhIfChtPUFNHRU5JRV9SRUdJT05fVU5TUEVDSUZJRUQQABIWChJPUFNHRU5JRV9SRUdJT05fVVMQARIWChJPUFNHRU5JRV9SRUdJT05fRVUQAkJdWltnaXRodWIuY29tL29wZW5zdGF0dXNocS9vcGVuc3RhdHVzL3BhY2thZ2VzL3Byb3RvL29wZW5zdGF0dXMvbm90aWZpY2F0aW9uL3YxO25vdGlmaWNhdGlvbnYxYgZwcm90bzM", [file_buf_validate_validate]); + +/** + * DiscordData contains configuration for Discord notifications. + * + * @generated from message openstatus.notification.v1.DiscordData + */ +export type DiscordData = Message<"openstatus.notification.v1.DiscordData"> & { + /** + * Discord webhook URL. + * + * @generated from field: string webhook_url = 1; + */ + webhookUrl: string; +}; + +/** + * Describes the message openstatus.notification.v1.DiscordData. + * Use `create(DiscordDataSchema)` to create a new message. + */ +export const DiscordDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 0); + +/** + * EmailData contains configuration for email notifications. + * + * @generated from message openstatus.notification.v1.EmailData + */ +export type EmailData = Message<"openstatus.notification.v1.EmailData"> & { + /** + * Email address to send notifications to. + * + * @generated from field: string email = 1; + */ + email: string; +}; + +/** + * Describes the message openstatus.notification.v1.EmailData. + * Use `create(EmailDataSchema)` to create a new message. + */ +export const EmailDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 1); + +/** + * GoogleChatData contains configuration for Google Chat notifications. + * + * @generated from message openstatus.notification.v1.GoogleChatData + */ +export type GoogleChatData = Message<"openstatus.notification.v1.GoogleChatData"> & { + /** + * Google Chat webhook URL. + * + * @generated from field: string webhook_url = 1; + */ + webhookUrl: string; +}; + +/** + * Describes the message openstatus.notification.v1.GoogleChatData. + * Use `create(GoogleChatDataSchema)` to create a new message. + */ +export const GoogleChatDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 2); + +/** + * GrafanaOncallData contains configuration for Grafana OnCall notifications. + * + * @generated from message openstatus.notification.v1.GrafanaOncallData + */ +export type GrafanaOncallData = Message<"openstatus.notification.v1.GrafanaOncallData"> & { + /** + * Grafana OnCall webhook URL. + * + * @generated from field: string webhook_url = 1; + */ + webhookUrl: string; +}; + +/** + * Describes the message openstatus.notification.v1.GrafanaOncallData. + * Use `create(GrafanaOncallDataSchema)` to create a new message. + */ +export const GrafanaOncallDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 3); + +/** + * NtfyData contains configuration for Ntfy notifications. + * + * @generated from message openstatus.notification.v1.NtfyData + */ +export type NtfyData = Message<"openstatus.notification.v1.NtfyData"> & { + /** + * Ntfy topic to publish to. + * + * @generated from field: string topic = 1; + */ + topic: string; + + /** + * Ntfy server URL (defaults to https://ntfy.sh). + * + * @generated from field: string server_url = 2; + */ + serverUrl: string; + + /** + * Optional authentication token. + * + * @generated from field: optional string token = 3; + */ + token?: string; +}; + +/** + * Describes the message openstatus.notification.v1.NtfyData. + * Use `create(NtfyDataSchema)` to create a new message. + */ +export const NtfyDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 4); + +/** + * PagerDutyData contains configuration for PagerDuty notifications. + * + * @generated from message openstatus.notification.v1.PagerDutyData + */ +export type PagerDutyData = Message<"openstatus.notification.v1.PagerDutyData"> & { + /** + * PagerDuty integration key. + * + * @generated from field: string integration_key = 1; + */ + integrationKey: string; +}; + +/** + * Describes the message openstatus.notification.v1.PagerDutyData. + * Use `create(PagerDutyDataSchema)` to create a new message. + */ +export const PagerDutyDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 5); + +/** + * OpsgenieData contains configuration for Opsgenie notifications. + * + * @generated from message openstatus.notification.v1.OpsgenieData + */ +export type OpsgenieData = Message<"openstatus.notification.v1.OpsgenieData"> & { + /** + * Opsgenie API key. + * + * @generated from field: string api_key = 1; + */ + apiKey: string; + + /** + * Opsgenie region. + * + * @generated from field: openstatus.notification.v1.OpsgenieRegion region = 2; + */ + region: OpsgenieRegion; +}; + +/** + * Describes the message openstatus.notification.v1.OpsgenieData. + * Use `create(OpsgenieDataSchema)` to create a new message. + */ +export const OpsgenieDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 6); + +/** + * SlackData contains configuration for Slack notifications. + * + * @generated from message openstatus.notification.v1.SlackData + */ +export type SlackData = Message<"openstatus.notification.v1.SlackData"> & { + /** + * Slack webhook URL. + * + * @generated from field: string webhook_url = 1; + */ + webhookUrl: string; +}; + +/** + * Describes the message openstatus.notification.v1.SlackData. + * Use `create(SlackDataSchema)` to create a new message. + */ +export const SlackDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 7); + +/** + * SmsData contains configuration for SMS notifications. + * + * @generated from message openstatus.notification.v1.SmsData + */ +export type SmsData = Message<"openstatus.notification.v1.SmsData"> & { + /** + * Phone number to send SMS to. + * + * @generated from field: string phone_number = 1; + */ + phoneNumber: string; +}; + +/** + * Describes the message openstatus.notification.v1.SmsData. + * Use `create(SmsDataSchema)` to create a new message. + */ +export const SmsDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 8); + +/** + * TelegramData contains configuration for Telegram notifications. + * + * @generated from message openstatus.notification.v1.TelegramData + */ +export type TelegramData = Message<"openstatus.notification.v1.TelegramData"> & { + /** + * Telegram chat ID. + * + * @generated from field: string chat_id = 1; + */ + chatId: string; +}; + +/** + * Describes the message openstatus.notification.v1.TelegramData. + * Use `create(TelegramDataSchema)` to create a new message. + */ +export const TelegramDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 9); + +/** + * WebhookHeader represents a custom header for webhook requests. + * + * @generated from message openstatus.notification.v1.WebhookHeader + */ +export type WebhookHeader = Message<"openstatus.notification.v1.WebhookHeader"> & { + /** + * Header name. + * + * @generated from field: string key = 1; + */ + key: string; + + /** + * Header value. + * + * @generated from field: string value = 2; + */ + value: string; +}; + +/** + * Describes the message openstatus.notification.v1.WebhookHeader. + * Use `create(WebhookHeaderSchema)` to create a new message. + */ +export const WebhookHeaderSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 10); + +/** + * WebhookData contains configuration for custom webhook notifications. + * + * @generated from message openstatus.notification.v1.WebhookData + */ +export type WebhookData = Message<"openstatus.notification.v1.WebhookData"> & { + /** + * Webhook endpoint URL. + * + * @generated from field: string endpoint = 1; + */ + endpoint: string; + + /** + * Optional custom headers. + * + * @generated from field: repeated openstatus.notification.v1.WebhookHeader headers = 2; + */ + headers: WebhookHeader[]; +}; + +/** + * Describes the message openstatus.notification.v1.WebhookData. + * Use `create(WebhookDataSchema)` to create a new message. + */ +export const WebhookDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 11); + +/** + * WhatsappData contains configuration for WhatsApp notifications. + * + * @generated from message openstatus.notification.v1.WhatsappData + */ +export type WhatsappData = Message<"openstatus.notification.v1.WhatsappData"> & { + /** + * Phone number to send WhatsApp messages to. + * + * @generated from field: string phone_number = 1; + */ + phoneNumber: string; +}; + +/** + * Describes the message openstatus.notification.v1.WhatsappData. + * Use `create(WhatsappDataSchema)` to create a new message. + */ +export const WhatsappDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 12); + +/** + * NotificationData is a union of provider-specific configuration. + * + * @generated from message openstatus.notification.v1.NotificationData + */ +export type NotificationData = Message<"openstatus.notification.v1.NotificationData"> & { + /** + * @generated from oneof openstatus.notification.v1.NotificationData.data + */ + data: { + /** + * Discord configuration. + * + * @generated from field: openstatus.notification.v1.DiscordData discord = 1; + */ + value: DiscordData; + case: "discord"; + } | { + /** + * Email configuration. + * + * @generated from field: openstatus.notification.v1.EmailData email = 2; + */ + value: EmailData; + case: "email"; + } | { + /** + * Google Chat configuration. + * + * @generated from field: openstatus.notification.v1.GoogleChatData google_chat = 3; + */ + value: GoogleChatData; + case: "googleChat"; + } | { + /** + * Grafana OnCall configuration. + * + * @generated from field: openstatus.notification.v1.GrafanaOncallData grafana_oncall = 4; + */ + value: GrafanaOncallData; + case: "grafanaOncall"; + } | { + /** + * Ntfy configuration. + * + * @generated from field: openstatus.notification.v1.NtfyData ntfy = 5; + */ + value: NtfyData; + case: "ntfy"; + } | { + /** + * PagerDuty configuration. + * + * @generated from field: openstatus.notification.v1.PagerDutyData pagerduty = 6; + */ + value: PagerDutyData; + case: "pagerduty"; + } | { + /** + * Opsgenie configuration. + * + * @generated from field: openstatus.notification.v1.OpsgenieData opsgenie = 7; + */ + value: OpsgenieData; + case: "opsgenie"; + } | { + /** + * Slack configuration. + * + * @generated from field: openstatus.notification.v1.SlackData slack = 8; + */ + value: SlackData; + case: "slack"; + } | { + /** + * SMS configuration. + * + * @generated from field: openstatus.notification.v1.SmsData sms = 9; + */ + value: SmsData; + case: "sms"; + } | { + /** + * Telegram configuration. + * + * @generated from field: openstatus.notification.v1.TelegramData telegram = 10; + */ + value: TelegramData; + case: "telegram"; + } | { + /** + * Webhook configuration. + * + * @generated from field: openstatus.notification.v1.WebhookData webhook = 11; + */ + value: WebhookData; + case: "webhook"; + } | { + /** + * WhatsApp configuration. + * + * @generated from field: openstatus.notification.v1.WhatsappData whatsapp = 12; + */ + value: WhatsappData; + case: "whatsapp"; + } | { case: undefined; value?: undefined }; +}; + +/** + * Describes the message openstatus.notification.v1.NotificationData. + * Use `create(NotificationDataSchema)` to create a new message. + */ +export const NotificationDataSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_providers, 13); + +/** + * NotificationProvider represents the supported notification channel types. + * + * @generated from enum openstatus.notification.v1.NotificationProvider + */ +export enum NotificationProvider { + /** + * Unspecified provider. + * + * @generated from enum value: NOTIFICATION_PROVIDER_UNSPECIFIED = 0; + */ + UNSPECIFIED = 0, + + /** + * Discord webhook. + * + * @generated from enum value: NOTIFICATION_PROVIDER_DISCORD = 1; + */ + DISCORD = 1, + + /** + * Email notification. + * + * @generated from enum value: NOTIFICATION_PROVIDER_EMAIL = 2; + */ + EMAIL = 2, + + /** + * Google Chat webhook. + * + * @generated from enum value: NOTIFICATION_PROVIDER_GOOGLE_CHAT = 3; + */ + GOOGLE_CHAT = 3, + + /** + * Grafana OnCall webhook. + * + * @generated from enum value: NOTIFICATION_PROVIDER_GRAFANA_ONCALL = 4; + */ + GRAFANA_ONCALL = 4, + + /** + * Ntfy notification service. + * + * @generated from enum value: NOTIFICATION_PROVIDER_NTFY = 5; + */ + NTFY = 5, + + /** + * PagerDuty integration. + * + * @generated from enum value: NOTIFICATION_PROVIDER_PAGERDUTY = 6; + */ + PAGERDUTY = 6, + + /** + * Opsgenie integration. + * + * @generated from enum value: NOTIFICATION_PROVIDER_OPSGENIE = 7; + */ + OPSGENIE = 7, + + /** + * Slack webhook. + * + * @generated from enum value: NOTIFICATION_PROVIDER_SLACK = 8; + */ + SLACK = 8, + + /** + * SMS notification. + * + * @generated from enum value: NOTIFICATION_PROVIDER_SMS = 9; + */ + SMS = 9, + + /** + * Telegram bot. + * + * @generated from enum value: NOTIFICATION_PROVIDER_TELEGRAM = 10; + */ + TELEGRAM = 10, + + /** + * Custom webhook. + * + * @generated from enum value: NOTIFICATION_PROVIDER_WEBHOOK = 11; + */ + WEBHOOK = 11, + + /** + * WhatsApp notification. + * + * @generated from enum value: NOTIFICATION_PROVIDER_WHATSAPP = 12; + */ + WHATSAPP = 12, +} + +/** + * Describes the enum openstatus.notification.v1.NotificationProvider. + */ +export const NotificationProviderSchema: GenEnum = /*@__PURE__*/ + enumDesc(file_openstatus_notification_v1_providers, 0); + +/** + * OpsgenieRegion represents the Opsgenie API region. + * + * @generated from enum openstatus.notification.v1.OpsgenieRegion + */ +export enum OpsgenieRegion { + /** + * Unspecified region. + * + * @generated from enum value: OPSGENIE_REGION_UNSPECIFIED = 0; + */ + UNSPECIFIED = 0, + + /** + * US region. + * + * @generated from enum value: OPSGENIE_REGION_US = 1; + */ + US = 1, + + /** + * EU region. + * + * @generated from enum value: OPSGENIE_REGION_EU = 2; + */ + EU = 2, +} + +/** + * Describes the enum openstatus.notification.v1.OpsgenieRegion. + */ +export const OpsgenieRegionSchema: GenEnum = /*@__PURE__*/ + enumDesc(file_openstatus_notification_v1_providers, 1); + diff --git a/packages/proto/gen/ts/openstatus/notification/v1/service_pb.ts b/packages/proto/gen/ts/openstatus/notification/v1/service_pb.ts new file mode 100644 index 000000000..602cae5af --- /dev/null +++ b/packages/proto/gen/ts/openstatus/notification/v1/service_pb.ts @@ -0,0 +1,470 @@ +// @generated by protoc-gen-es v2.10.2 with parameter "target=ts,import_extension=.ts" +// @generated from file openstatus/notification/v1/service.proto (package openstatus.notification.v1, syntax proto3) +/* eslint-disable */ + +import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2"; +import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2"; +import { file_buf_validate_validate } from "../../../buf/validate/validate_pb.ts"; +import type { Notification, NotificationSummary } from "./notification_pb.ts"; +import { file_openstatus_notification_v1_notification } from "./notification_pb.ts"; +import type { NotificationData, NotificationProvider } from "./providers_pb.ts"; +import { file_openstatus_notification_v1_providers } from "./providers_pb.ts"; +import type { Message } from "@bufbuild/protobuf"; + +/** + * Describes the file openstatus/notification/v1/service.proto. + */ +export const file_openstatus_notification_v1_service: GenFile = /*@__PURE__*/ + fileDesc("CihvcGVuc3RhdHVzL25vdGlmaWNhdGlvbi92MS9zZXJ2aWNlLnByb3RvEhpvcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MSLbAQoZQ3JlYXRlTm90aWZpY2F0aW9uUmVxdWVzdBIVCgRuYW1lGAEgASgJQge6SARyAhABEk4KCHByb3ZpZGVyGAIgASgOMjAub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuTm90aWZpY2F0aW9uUHJvdmlkZXJCCrpIB4IBBBABIAASQgoEZGF0YRgDIAEoCzIsLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLk5vdGlmaWNhdGlvbkRhdGFCBrpIA8gBARITCgttb25pdG9yX2lkcxgEIAMoCSJcChpDcmVhdGVOb3RpZmljYXRpb25SZXNwb25zZRI+Cgxub3RpZmljYXRpb24YASABKAsyKC5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Ob3RpZmljYXRpb24iLQoWR2V0Tm90aWZpY2F0aW9uUmVxdWVzdBITCgJpZBgBIAEoCUIHukgEcgIQASJZChdHZXROb3RpZmljYXRpb25SZXNwb25zZRI+Cgxub3RpZmljYXRpb24YASABKAsyKC5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Ob3RpZmljYXRpb24ibAoYTGlzdE5vdGlmaWNhdGlvbnNSZXF1ZXN0Eh0KBWxpbWl0GAEgASgFQgm6SAYaBBhkKAFIAIgBARIcCgZvZmZzZXQYAiABKAVCB7pIBBoCKABIAYgBAUIICgZfbGltaXRCCQoHX29mZnNldCJ3ChlMaXN0Tm90aWZpY2F0aW9uc1Jlc3BvbnNlEkYKDW5vdGlmaWNhdGlvbnMYASADKAsyLy5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Ob3RpZmljYXRpb25TdW1tYXJ5EhIKCnRvdGFsX3NpemUYAiABKAUiqwEKGVVwZGF0ZU5vdGlmaWNhdGlvblJlcXVlc3QSEwoCaWQYASABKAlCB7pIBHICEAESEQoEbmFtZRgCIAEoCUgAiAEBEj8KBGRhdGEYAyABKAsyLC5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5Ob3RpZmljYXRpb25EYXRhSAGIAQESEwoLbW9uaXRvcl9pZHMYBCADKAlCBwoFX25hbWVCBwoFX2RhdGEiXAoaVXBkYXRlTm90aWZpY2F0aW9uUmVzcG9uc2USPgoMbm90aWZpY2F0aW9uGAEgASgLMigub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuTm90aWZpY2F0aW9uIjAKGURlbGV0ZU5vdGlmaWNhdGlvblJlcXVlc3QSEwoCaWQYASABKAlCB7pIBHICEAEiLQoaRGVsZXRlTm90aWZpY2F0aW9uUmVzcG9uc2USDwoHc3VjY2VzcxgBIAEoCCKxAQobU2VuZFRlc3ROb3RpZmljYXRpb25SZXF1ZXN0Ek4KCHByb3ZpZGVyGAEgASgOMjAub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuTm90aWZpY2F0aW9uUHJvdmlkZXJCCrpIB4IBBBABIAASQgoEZGF0YRgCIAEoCzIsLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLk5vdGlmaWNhdGlvbkRhdGFCBrpIA8gBASJdChxTZW5kVGVzdE5vdGlmaWNhdGlvblJlc3BvbnNlEg8KB3N1Y2Nlc3MYASABKAgSGgoNZXJyb3JfbWVzc2FnZRgCIAEoCUgAiAEBQhAKDl9lcnJvcl9tZXNzYWdlIh8KHUNoZWNrTm90aWZpY2F0aW9uTGltaXRSZXF1ZXN0ImEKHkNoZWNrTm90aWZpY2F0aW9uTGltaXRSZXNwb25zZRIVCg1saW1pdF9yZWFjaGVkGAEgASgIEhUKDWN1cnJlbnRfY291bnQYAiABKAUSEQoJbWF4X2NvdW50GAMgASgFMsQHChNOb3RpZmljYXRpb25TZXJ2aWNlEoMBChJDcmVhdGVOb3RpZmljYXRpb24SNS5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5DcmVhdGVOb3RpZmljYXRpb25SZXF1ZXN0GjYub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuQ3JlYXRlTm90aWZpY2F0aW9uUmVzcG9uc2USegoPR2V0Tm90aWZpY2F0aW9uEjIub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuR2V0Tm90aWZpY2F0aW9uUmVxdWVzdBozLm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLkdldE5vdGlmaWNhdGlvblJlc3BvbnNlEoABChFMaXN0Tm90aWZpY2F0aW9ucxI0Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLkxpc3ROb3RpZmljYXRpb25zUmVxdWVzdBo1Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLkxpc3ROb3RpZmljYXRpb25zUmVzcG9uc2USgwEKElVwZGF0ZU5vdGlmaWNhdGlvbhI1Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlVwZGF0ZU5vdGlmaWNhdGlvblJlcXVlc3QaNi5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5VcGRhdGVOb3RpZmljYXRpb25SZXNwb25zZRKDAQoSRGVsZXRlTm90aWZpY2F0aW9uEjUub3BlbnN0YXR1cy5ub3RpZmljYXRpb24udjEuRGVsZXRlTm90aWZpY2F0aW9uUmVxdWVzdBo2Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLkRlbGV0ZU5vdGlmaWNhdGlvblJlc3BvbnNlEokBChRTZW5kVGVzdE5vdGlmaWNhdGlvbhI3Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlNlbmRUZXN0Tm90aWZpY2F0aW9uUmVxdWVzdBo4Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLlNlbmRUZXN0Tm90aWZpY2F0aW9uUmVzcG9uc2USjwEKFkNoZWNrTm90aWZpY2F0aW9uTGltaXQSOS5vcGVuc3RhdHVzLm5vdGlmaWNhdGlvbi52MS5DaGVja05vdGlmaWNhdGlvbkxpbWl0UmVxdWVzdBo6Lm9wZW5zdGF0dXMubm90aWZpY2F0aW9uLnYxLkNoZWNrTm90aWZpY2F0aW9uTGltaXRSZXNwb25zZUJdWltnaXRodWIuY29tL29wZW5zdGF0dXNocS9vcGVuc3RhdHVzL3BhY2thZ2VzL3Byb3RvL29wZW5zdGF0dXMvbm90aWZpY2F0aW9uL3YxO25vdGlmaWNhdGlvbnYxYgZwcm90bzM", [file_buf_validate_validate, file_openstatus_notification_v1_notification, file_openstatus_notification_v1_providers]); + +/** + * CreateNotificationRequest is the request to create a new notification channel. + * + * @generated from message openstatus.notification.v1.CreateNotificationRequest + */ +export type CreateNotificationRequest = Message<"openstatus.notification.v1.CreateNotificationRequest"> & { + /** + * Display name for the notification channel. + * + * @generated from field: string name = 1; + */ + name: string; + + /** + * Provider type. + * + * @generated from field: openstatus.notification.v1.NotificationProvider provider = 2; + */ + provider: NotificationProvider; + + /** + * Provider-specific configuration. + * + * @generated from field: openstatus.notification.v1.NotificationData data = 3; + */ + data?: NotificationData; + + /** + * IDs of monitors to associate with this notification. + * + * @generated from field: repeated string monitor_ids = 4; + */ + monitorIds: string[]; +}; + +/** + * Describes the message openstatus.notification.v1.CreateNotificationRequest. + * Use `create(CreateNotificationRequestSchema)` to create a new message. + */ +export const CreateNotificationRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 0); + +/** + * CreateNotificationResponse is the response after creating a notification channel. + * + * @generated from message openstatus.notification.v1.CreateNotificationResponse + */ +export type CreateNotificationResponse = Message<"openstatus.notification.v1.CreateNotificationResponse"> & { + /** + * The created notification channel. + * + * @generated from field: openstatus.notification.v1.Notification notification = 1; + */ + notification?: Notification; +}; + +/** + * Describes the message openstatus.notification.v1.CreateNotificationResponse. + * Use `create(CreateNotificationResponseSchema)` to create a new message. + */ +export const CreateNotificationResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 1); + +/** + * GetNotificationRequest is the request to get a notification channel. + * + * @generated from message openstatus.notification.v1.GetNotificationRequest + */ +export type GetNotificationRequest = Message<"openstatus.notification.v1.GetNotificationRequest"> & { + /** + * Notification ID to retrieve (required). + * + * @generated from field: string id = 1; + */ + id: string; +}; + +/** + * Describes the message openstatus.notification.v1.GetNotificationRequest. + * Use `create(GetNotificationRequestSchema)` to create a new message. + */ +export const GetNotificationRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 2); + +/** + * GetNotificationResponse is the response containing the notification channel. + * + * @generated from message openstatus.notification.v1.GetNotificationResponse + */ +export type GetNotificationResponse = Message<"openstatus.notification.v1.GetNotificationResponse"> & { + /** + * The notification channel. + * + * @generated from field: openstatus.notification.v1.Notification notification = 1; + */ + notification?: Notification; +}; + +/** + * Describes the message openstatus.notification.v1.GetNotificationResponse. + * Use `create(GetNotificationResponseSchema)` to create a new message. + */ +export const GetNotificationResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 3); + +/** + * ListNotificationsRequest is the request to list notification channels. + * + * @generated from message openstatus.notification.v1.ListNotificationsRequest + */ +export type ListNotificationsRequest = Message<"openstatus.notification.v1.ListNotificationsRequest"> & { + /** + * Maximum number of notifications to return (1-100, defaults to 50). + * + * @generated from field: optional int32 limit = 1; + */ + limit?: number; + + /** + * Number of notifications to skip for pagination (defaults to 0). + * + * @generated from field: optional int32 offset = 2; + */ + offset?: number; +}; + +/** + * Describes the message openstatus.notification.v1.ListNotificationsRequest. + * Use `create(ListNotificationsRequestSchema)` to create a new message. + */ +export const ListNotificationsRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 4); + +/** + * ListNotificationsResponse is the response containing notification channels. + * + * @generated from message openstatus.notification.v1.ListNotificationsResponse + */ +export type ListNotificationsResponse = Message<"openstatus.notification.v1.ListNotificationsResponse"> & { + /** + * Notification channel summaries. + * + * @generated from field: repeated openstatus.notification.v1.NotificationSummary notifications = 1; + */ + notifications: NotificationSummary[]; + + /** + * Total number of notification channels. + * + * @generated from field: int32 total_size = 2; + */ + totalSize: number; +}; + +/** + * Describes the message openstatus.notification.v1.ListNotificationsResponse. + * Use `create(ListNotificationsResponseSchema)` to create a new message. + */ +export const ListNotificationsResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 5); + +/** + * UpdateNotificationRequest is the request to update a notification channel. + * + * @generated from message openstatus.notification.v1.UpdateNotificationRequest + */ +export type UpdateNotificationRequest = Message<"openstatus.notification.v1.UpdateNotificationRequest"> & { + /** + * Notification ID to update (required). + * + * @generated from field: string id = 1; + */ + id: string; + + /** + * Updated display name. + * + * @generated from field: optional string name = 2; + */ + name?: string; + + /** + * Updated provider-specific configuration. + * + * @generated from field: optional openstatus.notification.v1.NotificationData data = 3; + */ + data?: NotificationData; + + /** + * Updated monitor IDs to associate. + * + * @generated from field: repeated string monitor_ids = 4; + */ + monitorIds: string[]; +}; + +/** + * Describes the message openstatus.notification.v1.UpdateNotificationRequest. + * Use `create(UpdateNotificationRequestSchema)` to create a new message. + */ +export const UpdateNotificationRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 6); + +/** + * UpdateNotificationResponse is the response after updating a notification channel. + * + * @generated from message openstatus.notification.v1.UpdateNotificationResponse + */ +export type UpdateNotificationResponse = Message<"openstatus.notification.v1.UpdateNotificationResponse"> & { + /** + * The updated notification channel. + * + * @generated from field: openstatus.notification.v1.Notification notification = 1; + */ + notification?: Notification; +}; + +/** + * Describes the message openstatus.notification.v1.UpdateNotificationResponse. + * Use `create(UpdateNotificationResponseSchema)` to create a new message. + */ +export const UpdateNotificationResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 7); + +/** + * DeleteNotificationRequest is the request to delete a notification channel. + * + * @generated from message openstatus.notification.v1.DeleteNotificationRequest + */ +export type DeleteNotificationRequest = Message<"openstatus.notification.v1.DeleteNotificationRequest"> & { + /** + * Notification ID to delete (required). + * + * @generated from field: string id = 1; + */ + id: string; +}; + +/** + * Describes the message openstatus.notification.v1.DeleteNotificationRequest. + * Use `create(DeleteNotificationRequestSchema)` to create a new message. + */ +export const DeleteNotificationRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 8); + +/** + * DeleteNotificationResponse is the response after deleting a notification channel. + * + * @generated from message openstatus.notification.v1.DeleteNotificationResponse + */ +export type DeleteNotificationResponse = Message<"openstatus.notification.v1.DeleteNotificationResponse"> & { + /** + * Whether the deletion was successful. + * + * @generated from field: bool success = 1; + */ + success: boolean; +}; + +/** + * Describes the message openstatus.notification.v1.DeleteNotificationResponse. + * Use `create(DeleteNotificationResponseSchema)` to create a new message. + */ +export const DeleteNotificationResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 9); + +/** + * SendTestNotificationRequest is the request to send a test notification. + * + * @generated from message openstatus.notification.v1.SendTestNotificationRequest + */ +export type SendTestNotificationRequest = Message<"openstatus.notification.v1.SendTestNotificationRequest"> & { + /** + * Provider type. + * + * @generated from field: openstatus.notification.v1.NotificationProvider provider = 1; + */ + provider: NotificationProvider; + + /** + * Provider-specific configuration. + * + * @generated from field: openstatus.notification.v1.NotificationData data = 2; + */ + data?: NotificationData; +}; + +/** + * Describes the message openstatus.notification.v1.SendTestNotificationRequest. + * Use `create(SendTestNotificationRequestSchema)` to create a new message. + */ +export const SendTestNotificationRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 10); + +/** + * SendTestNotificationResponse is the response after sending a test notification. + * + * @generated from message openstatus.notification.v1.SendTestNotificationResponse + */ +export type SendTestNotificationResponse = Message<"openstatus.notification.v1.SendTestNotificationResponse"> & { + /** + * Whether the test was successful. + * + * @generated from field: bool success = 1; + */ + success: boolean; + + /** + * Optional error message if the test failed. + * + * @generated from field: optional string error_message = 2; + */ + errorMessage?: string; +}; + +/** + * Describes the message openstatus.notification.v1.SendTestNotificationResponse. + * Use `create(SendTestNotificationResponseSchema)` to create a new message. + */ +export const SendTestNotificationResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 11); + +/** + * CheckNotificationLimitRequest is the request to check notification limits. + * + * @generated from message openstatus.notification.v1.CheckNotificationLimitRequest + */ +export type CheckNotificationLimitRequest = Message<"openstatus.notification.v1.CheckNotificationLimitRequest"> & { +}; + +/** + * Describes the message openstatus.notification.v1.CheckNotificationLimitRequest. + * Use `create(CheckNotificationLimitRequestSchema)` to create a new message. + */ +export const CheckNotificationLimitRequestSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 12); + +/** + * CheckNotificationLimitResponse is the response containing limit information. + * + * @generated from message openstatus.notification.v1.CheckNotificationLimitResponse + */ +export type CheckNotificationLimitResponse = Message<"openstatus.notification.v1.CheckNotificationLimitResponse"> & { + /** + * Whether the workspace has reached its notification limit. + * + * @generated from field: bool limit_reached = 1; + */ + limitReached: boolean; + + /** + * Current number of notification channels. + * + * @generated from field: int32 current_count = 2; + */ + currentCount: number; + + /** + * Maximum allowed notification channels. + * + * @generated from field: int32 max_count = 3; + */ + maxCount: number; +}; + +/** + * Describes the message openstatus.notification.v1.CheckNotificationLimitResponse. + * Use `create(CheckNotificationLimitResponseSchema)` to create a new message. + */ +export const CheckNotificationLimitResponseSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_openstatus_notification_v1_service, 13); + +/** + * NotificationService provides CRUD operations for notification channels. + * + * @generated from service openstatus.notification.v1.NotificationService + */ +export const NotificationService: GenService<{ + /** + * CreateNotification creates a new notification channel. + * + * @generated from rpc openstatus.notification.v1.NotificationService.CreateNotification + */ + createNotification: { + methodKind: "unary"; + input: typeof CreateNotificationRequestSchema; + output: typeof CreateNotificationResponseSchema; + }, + /** + * GetNotification retrieves a notification channel by ID. + * + * @generated from rpc openstatus.notification.v1.NotificationService.GetNotification + */ + getNotification: { + methodKind: "unary"; + input: typeof GetNotificationRequestSchema; + output: typeof GetNotificationResponseSchema; + }, + /** + * ListNotifications returns a list of notification channels. + * + * @generated from rpc openstatus.notification.v1.NotificationService.ListNotifications + */ + listNotifications: { + methodKind: "unary"; + input: typeof ListNotificationsRequestSchema; + output: typeof ListNotificationsResponseSchema; + }, + /** + * UpdateNotification updates an existing notification channel. + * + * @generated from rpc openstatus.notification.v1.NotificationService.UpdateNotification + */ + updateNotification: { + methodKind: "unary"; + input: typeof UpdateNotificationRequestSchema; + output: typeof UpdateNotificationResponseSchema; + }, + /** + * DeleteNotification removes a notification channel. + * + * @generated from rpc openstatus.notification.v1.NotificationService.DeleteNotification + */ + deleteNotification: { + methodKind: "unary"; + input: typeof DeleteNotificationRequestSchema; + output: typeof DeleteNotificationResponseSchema; + }, + /** + * SendTestNotification sends a test notification to verify configuration. + * + * @generated from rpc openstatus.notification.v1.NotificationService.SendTestNotification + */ + sendTestNotification: { + methodKind: "unary"; + input: typeof SendTestNotificationRequestSchema; + output: typeof SendTestNotificationResponseSchema; + }, + /** + * CheckNotificationLimit checks if the workspace has reached its notification limit. + * + * @generated from rpc openstatus.notification.v1.NotificationService.CheckNotificationLimit + */ + checkNotificationLimit: { + methodKind: "unary"; + input: typeof CheckNotificationLimitRequestSchema; + output: typeof CheckNotificationLimitResponseSchema; + }, +}> = /*@__PURE__*/ + serviceDesc(file_openstatus_notification_v1_service, 0); + diff --git a/packages/proto/package.json b/packages/proto/package.json index 9f1813390..f14389167 100644 --- a/packages/proto/package.json +++ b/packages/proto/package.json @@ -28,6 +28,10 @@ "./maintenance/v1": { "import": "./gen/ts/openstatus/maintenance/v1/index.ts", "types": "./gen/ts/openstatus/maintenance/v1/index.ts" + }, + "./notification/v1": { + "import": "./gen/ts/openstatus/notification/v1/index.ts", + "types": "./gen/ts/openstatus/notification/v1/index.ts" } }, "scripts": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f8b4a6de9..0c75eff0b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -494,6 +494,36 @@ importers: '@openstatus/error': specifier: workspace:* version: link:../../packages/error + '@openstatus/notification-discord': + specifier: workspace:* + version: link:../../packages/notifications/discord + '@openstatus/notification-google-chat': + specifier: workspace:* + version: link:../../packages/notifications/google-chat + '@openstatus/notification-grafana-oncall': + specifier: workspace:* + version: link:../../packages/notifications/grafana-oncall + '@openstatus/notification-ntfy': + specifier: workspace:* + version: link:../../packages/notifications/ntfy + '@openstatus/notification-opsgenie': + specifier: workspace:* + version: link:../../packages/notifications/opsgenie + '@openstatus/notification-pagerduty': + specifier: workspace:* + version: link:../../packages/notifications/pagerduty + '@openstatus/notification-slack': + specifier: workspace:* + version: link:../../packages/notifications/slack + '@openstatus/notification-telegram': + specifier: workspace:* + version: link:../../packages/notifications/telegram + '@openstatus/notification-twillio-whatsapp': + specifier: workspace:* + version: link:../../packages/notifications/twillio-whatsapp + '@openstatus/notification-webhook': + specifier: workspace:* + version: link:../../packages/notifications/webhook '@openstatus/proto': specifier: workspace:* version: link:../../packages/proto