Fork anchor, strip all push notification code (APNs, FCM, WebPush), rename from anchor to mailship, add new database schema for subscriptions + events tables, and add HTTP API for email notification registration and NIP-9a relay push callbacks. - POST /subscription/email — register for email digests - DELETE /subscription/:key — unsubscribe - POST /notify/:id — NIP-9a relay push callback - GET /confirm?token=... — confirm email - GET /unsubscribe?token=... — unsubscribe Co-authored-by: mplorentz
35 lines
No EOL
937 B
TypeScript
35 lines
No EOL
937 B
TypeScript
import { CronExpressionParser } from 'cron-parser'
|
|
import { tryCatch, int, HOUR } from '@welshman/lib'
|
|
|
|
export type Subscription = {
|
|
id: string
|
|
key: string
|
|
pubkey: string
|
|
email: string
|
|
frequency: string
|
|
created_at: number
|
|
confirmed_at?: number
|
|
unsubscribed_at?: number
|
|
last_digest_at?: number
|
|
}
|
|
|
|
export const getSubscriptionError = (sub: Subscription) => {
|
|
if (!sub.email?.includes('@')) {
|
|
return 'Please provide a valid email address'
|
|
}
|
|
|
|
if (!['daily', 'weekly'].includes(sub.frequency)) {
|
|
return 'Frequency must be "daily" or "weekly"'
|
|
}
|
|
|
|
// Daily: fire at 17:00 UTC. Weekly: fire Monday at 17:00 UTC.
|
|
// Validation: just ensure frequency is valid, cron is generated internally.
|
|
}
|
|
|
|
export const getCronExpression = (frequency: string, hour = 17, minute = 0) => {
|
|
if (frequency === 'daily') {
|
|
return `0 ${minute} ${hour} * * *`
|
|
}
|
|
// Weekly on Monday
|
|
return `0 ${minute} ${hour} * * 1`
|
|
} |