|
| 1 | +import { Events } from "@openstatus/analytics"; |
| 2 | +import { notifyMaintenance } from "@openstatus/services/maintenance"; |
| 3 | +import { notifyStatusReport } from "@openstatus/services/status-report"; |
| 4 | +import { z } from "zod"; |
| 5 | + |
| 6 | +import { toServiceCtx, toTRPCError } from "../service-adapter"; |
| 7 | +import { createTRPCRouter, protectedProcedure } from "../trpc"; |
| 8 | + |
| 9 | +// Subscriber dispatch fans out across every channel (email + webhook), so it |
| 10 | +// must run on the lambda runtime: the email channel (Resend + react-email |
| 11 | +// render) can't run on Edge and would silently drop emails while webhooks |
| 12 | +// still go out. Kept off the statusReport/maintenance routers, which are |
| 13 | +// Edge-served — see the `lambdas` list in the dashboard tRPC client. |
| 14 | +export const subscriberNotificationRouter = createTRPCRouter({ |
| 15 | + statusReport: protectedProcedure |
| 16 | + .meta({ track: Events.NotifyReport }) |
| 17 | + .input(z.object({ id: z.number() })) |
| 18 | + .mutation(async ({ ctx, input }) => { |
| 19 | + try { |
| 20 | + await notifyStatusReport({ |
| 21 | + ctx: toServiceCtx(ctx), |
| 22 | + input: { statusReportUpdateId: input.id }, |
| 23 | + }); |
| 24 | + return { success: true }; |
| 25 | + } catch (err) { |
| 26 | + toTRPCError(err); |
| 27 | + } |
| 28 | + }), |
| 29 | + |
| 30 | + maintenance: protectedProcedure |
| 31 | + .meta({ track: Events.NotifyMaintenance }) |
| 32 | + .input(z.object({ id: z.number() })) |
| 33 | + .mutation(async ({ ctx, input }) => { |
| 34 | + try { |
| 35 | + await notifyMaintenance({ |
| 36 | + ctx: toServiceCtx(ctx), |
| 37 | + input: { maintenanceId: input.id }, |
| 38 | + }); |
| 39 | + return { success: true }; |
| 40 | + } catch (err) { |
| 41 | + toTRPCError(err); |
| 42 | + } |
| 43 | + }), |
| 44 | +}); |
0 commit comments