@voyantjs/notifications 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +109 -0
- package/README.md +100 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/provider-resolution.d.ts +14 -0
- package/dist/provider-resolution.d.ts.map +1 -0
- package/dist/provider-resolution.js +30 -0
- package/dist/providers/local.d.ts +22 -0
- package/dist/providers/local.d.ts.map +1 -0
- package/dist/providers/local.js +24 -0
- package/dist/providers/resend.d.ts +52 -0
- package/dist/providers/resend.d.ts.map +1 -0
- package/dist/providers/resend.js +50 -0
- package/dist/routes.d.ts +655 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +108 -0
- package/dist/schema.d.ts +1324 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +215 -0
- package/dist/service.d.ts +370 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +781 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +1 -0
- package/dist/tasks/send-due-reminders.d.ts +18 -0
- package/dist/tasks/send-due-reminders.d.ts.map +1 -0
- package/dist/tasks/send-due-reminders.js +6 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/validation.d.ts +275 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +138 -0
- package/package.json +78 -0
package/dist/routes.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { createNotificationService, notificationsService } from "./service.js";
|
|
3
|
+
import { insertNotificationTemplateSchema, notificationDeliveryListQuerySchema, notificationReminderRuleListQuerySchema, notificationReminderRunListQuerySchema, notificationTemplateListQuerySchema, runDueRemindersSchema, sendInvoiceNotificationSchema, sendPaymentSessionNotificationSchema, sendNotificationSchema, insertNotificationReminderRuleSchema, updateNotificationTemplateSchema, updateNotificationReminderRuleSchema, } from "./validation.js";
|
|
4
|
+
export function createNotificationsRoutes(options) {
|
|
5
|
+
return new Hono()
|
|
6
|
+
.get("/templates", async (c) => {
|
|
7
|
+
const query = notificationTemplateListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
8
|
+
return c.json(await notificationsService.listTemplates(c.get("db"), query));
|
|
9
|
+
})
|
|
10
|
+
.post("/templates", async (c) => {
|
|
11
|
+
const row = await notificationsService.createTemplate(c.get("db"), insertNotificationTemplateSchema.parse(await c.req.json()));
|
|
12
|
+
return c.json({ data: row }, 201);
|
|
13
|
+
})
|
|
14
|
+
.get("/templates/:id", async (c) => {
|
|
15
|
+
const row = await notificationsService.getTemplateById(c.get("db"), c.req.param("id"));
|
|
16
|
+
if (!row)
|
|
17
|
+
return c.json({ error: "Notification template not found" }, 404);
|
|
18
|
+
return c.json({ data: row });
|
|
19
|
+
})
|
|
20
|
+
.patch("/templates/:id", async (c) => {
|
|
21
|
+
const row = await notificationsService.updateTemplate(c.get("db"), c.req.param("id"), updateNotificationTemplateSchema.parse(await c.req.json()));
|
|
22
|
+
if (!row)
|
|
23
|
+
return c.json({ error: "Notification template not found" }, 404);
|
|
24
|
+
return c.json({ data: row });
|
|
25
|
+
})
|
|
26
|
+
.get("/deliveries", async (c) => {
|
|
27
|
+
const query = notificationDeliveryListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
28
|
+
return c.json(await notificationsService.listDeliveries(c.get("db"), query));
|
|
29
|
+
})
|
|
30
|
+
.get("/deliveries/:id", async (c) => {
|
|
31
|
+
const row = await notificationsService.getDeliveryById(c.get("db"), c.req.param("id"));
|
|
32
|
+
if (!row)
|
|
33
|
+
return c.json({ error: "Notification delivery not found" }, 404);
|
|
34
|
+
return c.json({ data: row });
|
|
35
|
+
})
|
|
36
|
+
.get("/reminder-rules", async (c) => {
|
|
37
|
+
const query = notificationReminderRuleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
38
|
+
return c.json(await notificationsService.listReminderRules(c.get("db"), query));
|
|
39
|
+
})
|
|
40
|
+
.post("/reminder-rules", async (c) => {
|
|
41
|
+
const row = await notificationsService.createReminderRule(c.get("db"), insertNotificationReminderRuleSchema.parse(await c.req.json()));
|
|
42
|
+
return c.json({ data: row }, 201);
|
|
43
|
+
})
|
|
44
|
+
.get("/reminder-rules/:id", async (c) => {
|
|
45
|
+
const row = await notificationsService.getReminderRuleById(c.get("db"), c.req.param("id"));
|
|
46
|
+
if (!row)
|
|
47
|
+
return c.json({ error: "Notification reminder rule not found" }, 404);
|
|
48
|
+
return c.json({ data: row });
|
|
49
|
+
})
|
|
50
|
+
.patch("/reminder-rules/:id", async (c) => {
|
|
51
|
+
const row = await notificationsService.updateReminderRule(c.get("db"), c.req.param("id"), updateNotificationReminderRuleSchema.parse(await c.req.json()));
|
|
52
|
+
if (!row)
|
|
53
|
+
return c.json({ error: "Notification reminder rule not found" }, 404);
|
|
54
|
+
return c.json({ data: row });
|
|
55
|
+
})
|
|
56
|
+
.get("/reminder-runs", async (c) => {
|
|
57
|
+
const query = notificationReminderRunListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
58
|
+
return c.json(await notificationsService.listReminderRuns(c.get("db"), query));
|
|
59
|
+
})
|
|
60
|
+
.post("/reminders/run-due", async (c) => {
|
|
61
|
+
try {
|
|
62
|
+
const dispatcher = createNotificationService(options?.resolveProviders?.(c.env) ?? options?.providers ?? []);
|
|
63
|
+
const result = await notificationsService.runDueReminders(c.get("db"), dispatcher, runDueRemindersSchema.parse(await c.req.json().catch(() => ({}))));
|
|
64
|
+
return c.json({ data: result });
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const message = error instanceof Error ? error.message : "Reminder sweep failed";
|
|
68
|
+
return c.json({ error: message }, 400);
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
.post("/payment-sessions/:id/send", async (c) => {
|
|
72
|
+
try {
|
|
73
|
+
const dispatcher = createNotificationService(options?.resolveProviders?.(c.env) ?? options?.providers ?? []);
|
|
74
|
+
const row = await notificationsService.sendPaymentSessionNotification(c.get("db"), dispatcher, c.req.param("id"), sendPaymentSessionNotificationSchema.parse(await c.req.json()));
|
|
75
|
+
if (!row)
|
|
76
|
+
return c.json({ error: "Payment session not found" }, 404);
|
|
77
|
+
return c.json({ data: row }, 201);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const message = error instanceof Error ? error.message : "Payment session notification failed";
|
|
81
|
+
return c.json({ error: message }, 400);
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
.post("/invoices/:id/send", async (c) => {
|
|
85
|
+
try {
|
|
86
|
+
const dispatcher = createNotificationService(options?.resolveProviders?.(c.env) ?? options?.providers ?? []);
|
|
87
|
+
const row = await notificationsService.sendInvoiceNotification(c.get("db"), dispatcher, c.req.param("id"), sendInvoiceNotificationSchema.parse(await c.req.json()));
|
|
88
|
+
if (!row)
|
|
89
|
+
return c.json({ error: "Invoice not found" }, 404);
|
|
90
|
+
return c.json({ data: row }, 201);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
const message = error instanceof Error ? error.message : "Invoice notification failed";
|
|
94
|
+
return c.json({ error: message }, 400);
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
.post("/send", async (c) => {
|
|
98
|
+
try {
|
|
99
|
+
const dispatcher = createNotificationService(options?.resolveProviders?.(c.env) ?? options?.providers ?? []);
|
|
100
|
+
const row = await notificationsService.sendNotification(c.get("db"), dispatcher, sendNotificationSchema.parse(await c.req.json()));
|
|
101
|
+
return c.json({ data: row }, 201);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
const message = error instanceof Error ? error.message : "Notification send failed";
|
|
105
|
+
return c.json({ error: message }, 400);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|