Files
andon/server/utils/pushSubscriptionInput.ts
Julien Calixte 5016c5cd47 feat(push): owner-only gate and subscription body validation (T10)
isOwner compares the session email to the configured owner; the body
matches the browser PushSubscription.toJSON() shape, reporter resolved
server-side.
2026-05-28 01:19:19 +02:00

17 lines
574 B
TypeScript

import { type } from 'arktype'
// Validated push-subscription body — the browser's PushSubscription.toJSON()
// shape (T10/F8). Never trusted from the client beyond these constraints; the
// reporter is resolved server-side from the session, not sent here.
const nonEmptyKey = type('string').narrow((s, ctx) => s.length > 0 || ctx.reject('a non-empty key'))
export const PushSubscriptionInput = type({
endpoint: 'string.url',
keys: {
p256dh: nonEmptyKey,
auth: nonEmptyKey,
},
})
export type PushSubscriptionInputData = typeof PushSubscriptionInput.infer