Lumen & Gesso / website · lumengesso.com / app / lib / commerce-db.ts
| 1 | import 'server-only'; |
| 2 | import { getCloudflareContext } from '@opennextjs/cloudflare'; |
| 3 | import { d1Commerce, sweepAbandonedCheckouts, type CommerceBinding } from './d1-commerce'; |
| 4 | |
| 5 | function commerceBinding(): CommerceBinding { |
| 6 | const { COMMERCE_DB } = getCloudflareContext().env as { COMMERCE_DB?: CommerceBinding }; |
| 7 | if (!COMMERCE_DB) throw new Error('The Cloudflare commerce database binding is missing.'); |
| 8 | return COMMERCE_DB; |
| 9 | } |
| 10 | |
| 11 | export function commerceDb() { |
| 12 | return d1Commerce(commerceBinding()); |
| 13 | } |
| 14 | |
| 15 | export function sweepD1AbandonedCheckouts(cutoff: string) { |
| 16 | return sweepAbandonedCheckouts(commerceBinding(), cutoff); |
| 17 | } |