Add notification preferences and alternate dues payment options

Notification preferences (migration 048):
- Per-member opt-out of muteable categories (bookings, classes, forms,
  admin alerts); billing is always-on. Opt-out model, default on.
- Dispatcher reads prefs and marks muted outbox rows 'skipped' instead
  of sending; pure isMuted logic, fail-open on a prefs lookup error.
- notification_preferences table (default-deny RLS); /me toggles and
  self-view via validated service-client actions.

Alternate dues payment methods (migration 049):
- Admin sets external pay-here URLs per platform (PayPal/Zeffy/Venmo)
  in /settings; members see active ones on /me and pay off-platform;
  the treasurer reconciles manually (platform pre-tagged). https-only.
- dues_payment_methods table (SELECT space member, write admin/board).

/me visual pass:
- Restore the chip/preset profile editor (skills/interests/willing-to/
  affiliations); promote ChipInput and presets to shared modules.
- Gate the Stripe pay-dues button on whether the space has Stripe
  configured; show external links or a contact-admin note otherwise.
This commit is contained in:
Moheeb Zara
2026-05-19 20:26:32 -07:00
parent addedfdb0f
commit ab8c22ae1d
29 changed files with 1281 additions and 124 deletions
+24 -4
View File
@@ -10,9 +10,11 @@ import {
import { SIGNUP_STATUS_LABEL, SESSION_STATUS_LABEL } from '@/lib/classes-logic'
import { RESERVATION_STATUS_LABEL } from '@/lib/equipment-logic'
import { presenceStatus } from '@/lib/presence-logic'
import { DuesCard } from '@/components/billing/dues-card'
import { DuesCard, type DuesMethod } from '@/components/billing/dues-card'
import { ProfileForm, type ProfileInitial } from './profile-form'
import { CancelAction } from './cancel-action'
import { NotificationPrefs } from './notification-prefs'
import type { PrefMap } from '@/lib/notifications-prefs-logic'
import { cancelMySignup, cancelReservation } from '@/lib/actions'
const STATUS_VARIANT: Record<CertStatus, 'default' | 'outline'> = {
@@ -54,15 +56,17 @@ export type MyVisit = { id: string; checked_in_at: string; checked_out_at: strin
export type MyNotif = { id: string; type: string; subject: string; status: string; createdAt: string; sentAt: string | null }
export type MyPayment = { id: string; amount: number; currency: string; platform: string; description: string | null; status: string; date: string }
export type HeldPermission = { code: string; label: string }
export type Billing = { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean } | null
export type Billing = { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean; configured: boolean } | null
type Props = {
profile: ProfileInitial
grants: Grant[]
held: HeldPermission[]
billing: Billing
duesMethods: DuesMethod[]
payments: MyPayment[]
notifs: MyNotif[]
notifPrefs: PrefMap
classSignups: ClassSignup[]
reservations: Reservation[]
myCards: MyCard[]
@@ -76,8 +80,10 @@ export function MePortalClient({
grants,
held,
billing,
duesMethods,
payments,
notifs,
notifPrefs,
classSignups,
reservations,
myCards,
@@ -135,7 +141,7 @@ export function MePortalClient({
<TabsContent value="membership" className="space-y-8">
<section>
<h2 className={sectionH}>Dues</h2>
<DuesCard billing={billing} />
<DuesCard billing={billing} methods={duesMethods} />
</section>
<section>
@@ -210,6 +216,14 @@ export function MePortalClient({
</TabsContent>
<TabsContent value="activity" className="space-y-8">
<section>
<h2 className={sectionH}>Email preferences</h2>
<NotificationPrefs initial={notifPrefs} />
<p className="font-sans text-xs text-muted-foreground mt-3">
Billing emails (dues receipts, payment alerts) are always sent.
</p>
</section>
<section>
<h2 className={sectionH}>Notifications</h2>
{notifs.length === 0 ? (
@@ -228,7 +242,13 @@ export function MePortalClient({
</p>
</div>
<Badge variant={n.status === 'sent' ? 'default' : 'outline'}>
{n.status === 'sent' ? 'Sent' : n.status === 'failed' ? 'Failed' : 'Queued'}
{n.status === 'sent'
? 'Sent'
: n.status === 'failed'
? 'Failed'
: n.status === 'skipped'
? 'Muted'
: 'Queued'}
</Badge>
</li>
))}
+52
View File
@@ -0,0 +1,52 @@
'use client'
import { useState, useTransition } from 'react'
import { toast } from 'sonner'
import { Switch } from '@/components/ui/switch'
import {
CATEGORY_META,
type PrefMap,
type NotificationCategory,
} from '@/lib/notifications-prefs-logic'
import { setMyNotificationPreference } from '@/lib/actions'
// Per-category email opt-out toggles. Optimistic: the switch flips immediately
// and reverts if the server action fails. Billing is never shown (always on).
export function NotificationPrefs({ initial }: { initial: PrefMap }) {
const [prefs, setPrefs] = useState<PrefMap>(initial)
const [pending, startTransition] = useTransition()
function toggle(category: NotificationCategory, next: boolean) {
const prev = prefs[category] ?? true
setPrefs(p => ({ ...p, [category]: next }))
startTransition(async () => {
const res = await setMyNotificationPreference({ category, enabled: next })
if ('error' in res) {
setPrefs(p => ({ ...p, [category]: prev }))
toast.error(res.error)
}
})
}
return (
<ul className="divide-y rounded-lg border border-border">
{CATEGORY_META.map(meta => {
const enabled = prefs[meta.category] ?? true
return (
<li key={meta.category} className="p-4 flex items-center justify-between gap-4">
<div className="min-w-0">
<span className="font-sans text-sm text-foreground">{meta.label}</span>
<p className="font-sans text-xs text-muted-foreground mt-0.5">{meta.description}</p>
</div>
<Switch
checked={enabled}
disabled={pending}
onCheckedChange={next => toggle(meta.category, next)}
aria-label={`Email me about ${meta.label}`}
/>
</li>
)
})}
</ul>
)
}
+14 -2
View File
@@ -3,7 +3,9 @@ import { createClient } from '@/lib/supabase/server'
import { createAdminClient } from '@/lib/supabase/admin'
import { PageHeader, PageTitle } from '@/components/ui/page-title'
import { PERMISSIONS, PERMISSION_CODES } from '@/lib/permissions-catalog'
import { getMyClassSignups, getMyReservations, getMyCards, getMyVisits, getMyBilling, getMyNotifications, getMyPayments } from '@/lib/actions'
import { getMyClassSignups, getMyReservations, getMyCards, getMyVisits, getMyBilling, getMyNotifications, getMyNotificationPreferences, getMyPayments, listActiveDuesPaymentMethods } from '@/lib/actions'
import type { PrefMap } from '@/lib/notifications-prefs-logic'
import type { DuesMethod } from '@/components/billing/dues-card'
import {
MePortalClient,
type Grant,
@@ -107,12 +109,20 @@ export default async function MePage() {
const billingRes = await getMyBilling()
const billing = ('data' in billingRes ? billingRes.data : null) as
| { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean }
| { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean; configured: boolean }
| null
const duesMethodsRes = await listActiveDuesPaymentMethods()
const duesMethods: DuesMethod[] = 'data' in duesMethodsRes
? duesMethodsRes.data.map(m => ({ platform: m.platform, url: m.url, instructions: m.instructions }))
: []
const notifsRes = await getMyNotifications()
const notifs: MyNotif[] = 'data' in notifsRes ? (notifsRes.data as MyNotif[]) : []
const notifPrefsRes = await getMyNotificationPreferences()
const notifPrefs: PrefMap = 'data' in notifPrefsRes ? notifPrefsRes.data : {}
const paymentsRes = await getMyPayments()
const payments: MyPayment[] = 'data' in paymentsRes ? (paymentsRes.data as MyPayment[]) : []
@@ -127,8 +137,10 @@ export default async function MePage() {
grants={grants}
held={held}
billing={billing}
duesMethods={duesMethods}
payments={payments}
notifs={notifs}
notifPrefs={notifPrefs}
classSignups={classSignups}
reservations={reservations}
myCards={myCards}
+90 -78
View File
@@ -7,6 +7,8 @@ import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import { ChipInput } from '@/components/chip-input'
import { WILLING_TO_SUGGESTIONS } from '@/lib/profile-presets'
import { updateMyProfile, discloseAffiliations, requestEmailChange } from '@/lib/actions'
export type ProfileInitial = {
@@ -21,11 +23,11 @@ export type ProfileInitial = {
affiliations: string[]
}
const toList = (s: string): string[] =>
s.split(',').map(x => x.trim()).filter(Boolean)
const sameList = (a: string[], b: string[]) =>
a.length === b.length && a.every((x, i) => x === b[i])
const fieldLabel = 'font-mono text-[10px] tracking-widest text-muted-foreground uppercase'
export function ProfileForm({ initial }: { initial: ProfileInitial }) {
const router = useRouter()
const [busy, setBusy] = useState(false)
@@ -35,10 +37,10 @@ export function ProfileForm({ initial }: { initial: ProfileInitial }) {
const [handle, setHandle] = useState(initial.handle)
const [phone, setPhone] = useState(initial.phone)
const [bio, setBio] = useState(initial.bio)
const [skills, setSkills] = useState(initial.skills.join(', '))
const [interests, setInterests] = useState(initial.interests.join(', '))
const [willingTo, setWillingTo] = useState(initial.willing_to.join(', '))
const [affiliations, setAffiliations] = useState(initial.affiliations.join(', '))
const [skills, setSkills] = useState<string[]>(initial.skills)
const [interests, setInterests] = useState<string[]>(initial.interests)
const [willingTo, setWillingTo] = useState<string[]>(initial.willing_to)
const [affiliations, setAffiliations] = useState<string[]>(initial.affiliations)
async function save() {
if (!displayName.trim()) return toast.error('Display name is required.')
@@ -49,9 +51,9 @@ export function ProfileForm({ initial }: { initial: ProfileInitial }) {
handle: handle.trim() || null,
phone: phone.trim() || null,
bio: bio.trim() || null,
skills: toList(skills),
interests: toList(interests),
willing_to: toList(willingTo),
skills,
interests,
willing_to: willingTo,
})
if ('error' in res && res.error) {
setBusy(false)
@@ -60,9 +62,8 @@ export function ProfileForm({ initial }: { initial: ProfileInitial }) {
// Only re-disclose affiliations when they actually changed, so the
// conflict-of-interest disclosure timestamp is not reset on every save.
const nextAffiliations = toList(affiliations)
if (!sameList(nextAffiliations, initial.affiliations)) {
const aff = await discloseAffiliations({ affiliations: nextAffiliations })
if (!sameList(affiliations, initial.affiliations)) {
const aff = await discloseAffiliations({ affiliations })
if ('error' in aff && aff.error) {
setBusy(false)
return toast.error(aff.error)
@@ -88,83 +89,94 @@ export function ProfileForm({ initial }: { initial: ProfileInitial }) {
}
return (
<div className="space-y-4">
<div className="bg-card rounded border border-border p-4 space-y-4">
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-name">Display name</Label>
<Input id="pf-name" value={displayName} onChange={e => setDisplayName(e.target.value)} maxLength={100} />
<div className="space-y-4">
<div className="bg-card rounded-lg border border-border p-5 space-y-5">
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-name">Display name</Label>
<Input id="pf-name" value={displayName} onChange={e => setDisplayName(e.target.value)} maxLength={100} />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-handle">Handle</Label>
<Input id="pf-handle" value={handle} onChange={e => setHandle(e.target.value)} maxLength={50} placeholder="optional" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-phone">Phone</Label>
<Input id="pf-phone" value={phone} onChange={e => setPhone(e.target.value)} maxLength={20} placeholder="optional" />
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-handle">Handle</Label>
<Input id="pf-handle" value={handle} onChange={e => setHandle(e.target.value)} maxLength={50} placeholder="optional" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-phone">Phone</Label>
<Input id="pf-phone" value={phone} onChange={e => setPhone(e.target.value)} maxLength={20} placeholder="optional" />
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-bio">Bio</Label>
<Textarea id="pf-bio" value={bio} onChange={e => setBio(e.target.value)} maxLength={2000} rows={3} placeholder="optional" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-bio">Bio</Label>
<Textarea id="pf-bio" value={bio} onChange={e => setBio(e.target.value)} maxLength={2000} rows={3} placeholder="optional" />
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-skills">Skills</Label>
<Input id="pf-skills" value={skills} onChange={e => setSkills(e.target.value)} placeholder="comma, separated" />
<span className={fieldLabel}>Skills</span>
<ChipInput values={skills} onChange={setSkills} placeholder="add a skill and press enter" maxLength={60} maxItems={40} />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-interests">Interests</Label>
<Input id="pf-interests" value={interests} onChange={e => setInterests(e.target.value)} placeholder="comma, separated" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-willing">Willing to</Label>
<Input id="pf-willing" value={willingTo} onChange={e => setWillingTo(e.target.value)} placeholder="comma, separated" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-aff">Affiliations (conflict-of-interest)</Label>
<Input id="pf-aff" value={affiliations} onChange={e => setAffiliations(e.target.value)} placeholder="comma, separated" />
</div>
</div>
<div className="flex justify-end">
<Button size="sm" disabled={busy} onClick={save}>
{busy ? 'Saving…' : 'Save profile'}
</Button>
</div>
</div>
<div className="bg-card rounded border border-border p-4 space-y-3">
<div>
<p className="font-sans text-sm font-medium text-foreground">Login email</p>
<p className="font-mono text-[10px] text-muted-foreground mt-0.5">
{initial.email || 'not set'}
</p>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-email">New email</Label>
<Input
id="pf-email"
type="email"
value={newEmail}
onChange={e => setNewEmail(e.target.value)}
maxLength={254}
placeholder="[email protected]"
<span className={fieldLabel}>Interests</span>
<ChipInput values={interests} onChange={setInterests} placeholder="add an interest and press enter" maxLength={60} maxItems={40} />
</div>
<div className="space-y-1.5">
<span className={fieldLabel}>Willing to do</span>
<ChipInput
values={willingTo}
onChange={setWillingTo}
placeholder="add a role and press enter"
maxLength={60}
maxItems={20}
suggestions={WILLING_TO_SUGGESTIONS}
/>
<p className="font-sans text-xs text-muted-foreground">
Used by the board-only recruitment view when looking for members willing to take on a role.
</p>
</div>
<div className="space-y-1.5">
<span className={fieldLabel}>Affiliations (conflict-of-interest)</span>
<ChipInput values={affiliations} onChange={setAffiliations} placeholder="add an affiliation and press enter" maxLength={200} maxItems={50} />
</div>
<div className="flex justify-end">
<Button size="sm" disabled={busy} onClick={save}>
{busy ? 'Saving…' : 'Save profile'}
</Button>
</div>
</div>
<div className="flex items-center justify-between gap-3 flex-wrap">
<p className="font-sans text-xs text-muted-foreground">
You must confirm via links sent to both your current and new address.
</p>
<Button size="sm" variant="outline" disabled={emailBusy} onClick={changeEmail}>
{emailBusy ? 'Sending…' : 'Change email'}
</Button>
<div className="bg-card rounded-lg border border-border p-5 space-y-3">
<div>
<p className="font-sans text-sm font-medium text-foreground">Login email</p>
<p className="font-mono text-[10px] text-muted-foreground mt-0.5">
{initial.email || 'not set'}
</p>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-email">New email</Label>
<Input
id="pf-email"
type="email"
value={newEmail}
onChange={e => setNewEmail(e.target.value)}
maxLength={254}
placeholder="[email protected]"
/>
</div>
</div>
<div className="flex items-center justify-between gap-3 flex-wrap">
<p className="font-sans text-xs text-muted-foreground">
You must confirm via links sent to both your current and new address.
</p>
<Button size="sm" variant="outline" disabled={emailBusy} onClick={changeEmail}>
{emailBusy ? 'Sending…' : 'Change email'}
</Button>
</div>
</div>
</div>
</div>
)
}
+1 -1
View File
@@ -3,7 +3,7 @@
import { useState, useTransition } from 'react'
import { useRouter } from 'next/navigation'
import { discloseAffiliations } from '@/lib/actions'
import { ChipInput } from './chip-input'
import { ChipInput } from '@/components/chip-input'
export function AffiliationsForm({ initial }: { initial: { affiliations: string[] } }) {
const router = useRouter()
-100
View File
@@ -1,100 +0,0 @@
'use client'
import { useState, type KeyboardEvent } from 'react'
type Props = {
values: string[]
onChange: (next: string[]) => void
placeholder?: string
maxLength?: number
maxItems?: number
suggestions?: string[]
}
/**
* Minimal chip / token input. Press Enter or comma to commit the current
* value. Backspace on an empty input removes the last chip. Optional
* suggestion list shows un-used suggestions as click-to-add chips below.
*/
export function ChipInput({
values,
onChange,
placeholder,
maxLength = 80,
maxItems = 50,
suggestions,
}: Props) {
const [draft, setDraft] = useState('')
function commit(raw: string) {
const v = raw.trim()
if (!v) return
if (values.includes(v)) return
if (values.length >= maxItems) return
onChange([...values, v.slice(0, maxLength)])
setDraft('')
}
function remove(idx: number) {
onChange(values.filter((_, i) => i !== idx))
}
function handleKeyDown(e: KeyboardEvent<HTMLInputElement>) {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault()
commit(draft)
} else if (e.key === 'Backspace' && draft === '' && values.length > 0) {
e.preventDefault()
onChange(values.slice(0, -1))
}
}
const remainingSuggestions = (suggestions ?? []).filter(s => !values.includes(s))
return (
<div>
<div className="flex flex-wrap items-center gap-1.5 bg-background border border-border rounded px-2 py-1.5 focus-within:border-primary">
{values.map((v, i) => (
<span
key={`${v}-${i}`}
className="inline-flex items-center gap-1 bg-muted rounded px-2 py-0.5 font-mono text-xs"
>
{v}
<button
type="button"
onClick={() => remove(i)}
className="text-muted-foreground hover:text-foreground"
aria-label={`Remove ${v}`}
>
×
</button>
</span>
))}
<input
type="text"
value={draft}
onChange={e => setDraft(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={() => commit(draft)}
placeholder={values.length === 0 ? placeholder : ''}
maxLength={maxLength}
className="flex-1 min-w-[120px] bg-transparent text-foreground font-sans text-sm py-1 px-1 focus:outline-none"
/>
</div>
{remainingSuggestions.length > 0 && (
<div className="flex flex-wrap gap-1.5 mt-2">
{remainingSuggestions.map(s => (
<button
key={s}
type="button"
onClick={() => commit(s)}
className="font-mono text-[10px] tracking-widest border border-border text-muted-foreground hover:text-foreground hover:border-primary rounded px-2 py-0.5"
>
+ {s}
</button>
))}
</div>
)}
</div>
)
}
+2 -11
View File
@@ -3,7 +3,8 @@
import { useState, useTransition } from 'react'
import { useRouter } from 'next/navigation'
import { updateMyProfile } from '@/lib/actions'
import { ChipInput } from './chip-input'
import { ChipInput } from '@/components/chip-input'
import { WILLING_TO_SUGGESTIONS } from '@/lib/profile-presets'
type Props = {
initial: {
@@ -16,16 +17,6 @@ type Props = {
}
}
const WILLING_TO_SUGGESTIONS = [
'board_candidate',
'treasurer_candidate',
'host_volunteer',
'area_lead_candidate',
'event_organizer',
'safety_committee',
'docs_steward',
]
export function ProfileForm({ initial }: Props) {
const router = useRouter()
const [displayName, setDisplayName] = useState(initial.display_name)
+2
View File
@@ -1,6 +1,7 @@
import { createClient } from '@/lib/supabase/server'
import SettingsClient from './settings-client'
import { StripeBillingPanel } from '@/components/settings/stripe-billing-panel'
import { DuesPaymentMethodsPanel } from '@/components/settings/dues-payment-methods-panel'
import { redirect } from 'next/navigation'
export default async function SettingsPage() {
@@ -34,6 +35,7 @@ export default async function SettingsPage() {
currentRole={member.role}
/>
<StripeBillingPanel spaceId={member.space_id} />
<DuesPaymentMethodsPanel />
</>
)
}
+46 -2
View File
@@ -17,6 +17,11 @@ import { timingSafeEqual } from 'node:crypto'
import { createAdminClient } from '@/lib/supabase/admin'
import { sendEmail } from '@/lib/email/send'
import { isTerminalAttempt, MAX_NOTIFICATION_ATTEMPTS } from '@/lib/notifications-logic'
import {
isMuted,
type PrefMap,
type NotificationCategory,
} from '@/lib/notifications-prefs-logic'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
@@ -51,7 +56,7 @@ export async function POST(req: NextRequest) {
const admin = createAdminClient()
const { data: candidates, error } = await admin
.from('notifications')
.select('id, space_id, recipient, subject, body_html, body_text, attempts')
.select('id, space_id, member_id, type, recipient, subject, body_html, body_text, attempts')
.eq('status', 'pending')
.eq('channel', 'email')
.lt('attempts', MAX_NOTIFICATION_ATTEMPTS)
@@ -87,11 +92,50 @@ export async function POST(req: NextRequest) {
}
}
// Per-member notification preferences for the rows we're about to drain.
// member_id is a space_members PK (globally unique), so keying by it alone is
// unambiguous across spaces. A row whose type maps to a category the member
// muted is marked 'skipped' (a terminal status) so it leaves the pending pool
// instead of being re-scanned every minute. Billing types and unmapped types
// are never muteable (see notifications-prefs-logic). member_id null (e.g. a
// future broadcast) has no member to have a preference, so it always sends.
const memberIds = Array.from(
new Set((rows ?? []).map(r => r.member_id as string | null).filter((m): m is string => !!m)),
)
const prefsByMember = new Map<string, PrefMap>()
if (memberIds.length > 0) {
const { data: prefRows, error: prefErr } = await admin
.from('notification_preferences')
.select('member_id, category, enabled')
.in('member_id', memberIds)
// Fail open: if the prefs lookup errors, send everything rather than risk
// silently dropping a wanted (e.g. dues-failure) email on a transient blip.
if (prefErr) console.error('[cron/notifications] prefs lookup failed:', prefErr.message)
for (const p of prefRows ?? []) {
const mid = p.member_id as string
if (!prefsByMember.has(mid)) prefsByMember.set(mid, {})
prefsByMember.get(mid)![p.category as NotificationCategory] = p.enabled as boolean
}
}
let sent = 0
let failed = 0
let retried = 0
let skipped = 0
for (const row of rows ?? []) {
const memberId = row.member_id as string | null
if (memberId && isMuted(prefsByMember.get(memberId) ?? {}, row.type as string)) {
// No send, no Resend call, no rate-limit spacing: muted rows are cheap.
await admin
.from('notifications')
.update({ status: 'skipped', last_error: null })
.eq('id', row.id)
.eq('status', 'pending')
skipped++
continue
}
const res = await sendEmail({
to: row.recipient as string,
subject: row.subject as string,
@@ -135,5 +179,5 @@ export async function POST(req: NextRequest) {
if (SPACING_MS) await sleep(SPACING_MS)
}
return NextResponse.json({ scanned: rows?.length ?? 0, sent, failed, retried })
return NextResponse.json({ scanned: rows?.length ?? 0, sent, failed, retried, skipped })
}