Notifications API
Base path: /api/notifications
File: ayts-api/src/routes/notifications.ts
Auth required: Yes
POST /api/notifications/subscribe
Register a device for push notifications (Web Push / VAPID).
{
"subscription": {
"endpoint": "https://fcm.googleapis.com/...",
"keys": {
"p256dh": "...",
"auth": "..."
}
}
}
The subscription object comes from the browser's Push API:
const registration = await navigator.serviceWorker.ready;
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: NEXT_PUBLIC_VAPID_PUBLIC_KEY,
});
Response 200:
{ "success": true, "subscriptionId": "uuid" }
DELETE /api/notifications/unsubscribe
Remove a push subscription.
{ "endpoint": "https://fcm.googleapis.com/..." }
POST /api/notifications/send (Admin / Internal)
Send a push notification to a user. Used internally by order event handlers.
{
"userId": "uuid",
"title": "Order Update",
"body": "Your order AYTS-20260506-1234 is being prepared.",
"data": { "orderId": "uuid", "url": "/orders/uuid" }
}
Notification Events
These are triggered automatically by order status changes:
| Event | Recipient | Message |
|---|---|---|
| Order confirmed | Customer | "Your order has been confirmed!" |
| Order preparing | Customer | "Your order is being prepared" |
| Order ready | Customer | "Your order is ready for pickup" |
| Out for delivery | Customer | "Your rider is on the way!" |
| Order delivered | Customer | "Order delivered — please leave a review" |
| New order | Vendor | "You have a new order: AYTS-..." |
| New order | Rider | "New delivery available" |
Email Notifications
Order events should also trigger emails via ayts-api/src/lib/email.ts:
Email notifications are implemented (email.ts exists) but are not yet wired to order status change events. This means customers do not receive confirmation or status update emails.
To wire: in orders-simple.ts after each status update, call:
await sendEmail({
to: customer.email,
subject: 'Order Confirmed — AYTS',
template: 'order-confirmed',
data: { orderNumber, total, items },
});
SMS Notifications
ayts-api/src/lib/sms.ts — Semaphore API.
Requires SEMAPHORE_API_KEY set via wrangler secret put.