import 'server-only'; import { getCloudflareContext } from '@opennextjs/cloudflare'; import { d1Commerce, sweepAbandonedCheckouts, type CommerceBinding } from './d1-commerce'; function commerceBinding(): CommerceBinding { const { COMMERCE_DB } = getCloudflareContext().env as { COMMERCE_DB?: CommerceBinding }; if (!COMMERCE_DB) throw new Error('The Cloudflare commerce database binding is missing.'); return COMMERCE_DB; } export function commerceDb() { return d1Commerce(commerceBinding()); } export function sweepD1AbandonedCheckouts(cutoff: string) { return sweepAbandonedCheckouts(commerceBinding(), cutoff); }