Branchwell

Lumen & Gesso / website · lumengesso.com / app / lib / commerce-db.ts

1import 'server-only';
2import { getCloudflareContext } from '@opennextjs/cloudflare';
3import { d1Commerce, sweepAbandonedCheckouts, type CommerceBinding } from './d1-commerce';
4
5function 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
11export function commerceDb() {
12 return d1Commerce(commerceBinding());
13}
14
15export function sweepD1AbandonedCheckouts(cutoff: string) {
16 return sweepAbandonedCheckouts(commerceBinding(), cutoff);
17}