Skip to main content

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:

EventRecipientMessage
Order confirmedCustomer"Your order has been confirmed!"
Order preparingCustomer"Your order is being prepared"
Order readyCustomer"Your order is ready for pickup"
Out for deliveryCustomer"Your rider is on the way!"
Order deliveredCustomer"Order delivered — please leave a review"
New orderVendor"You have a new order: AYTS-..."
New orderRider"New delivery available"

Email Notifications

Order events should also trigger emails via ayts-api/src/lib/email.ts:

Not wired yet

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.

Not configured

Requires SEMAPHORE_API_KEY set via wrangler secret put.