Rebasely Beta: data may be purged

examples/storefront Public

TypeScript · 31 lines · 1.2 KiB · at c8458cc

import { WorkerEntrypoint } from "cloudflare:workers";import { createApp } from "./app.ts";import type { Env } from "./env.ts";import { cancelOrder, getOrder, markPaid, recordShipment, type Order, type Settled } from "./orders.ts";// The calls the shop's other Workers make through a service binding (entrypoint OrdersService).// storefront-api stays the only Worker that writes to the database; see// .rebasely/kb/decisions/0006-one-writer-for-the-database.md.export class OrdersService extends WorkerEntrypoint<Env> {  markPaid(orderId: string, paymentIntentId: string): Promise<Settled> {    return markPaid(this.env.DB, this.env.ORDER_EVENTS, orderId, paymentIntentId, Date.now());  }  cancel(orderId: string): Promise<Settled> {    return cancelOrder(this.env.DB, this.env.ORDER_EVENTS, orderId, Date.now());  }  forFulfilment(orderId: string): Promise<Order | null> {    return getOrder(this.env.DB, orderId);  }  recordShipment(orderId: string, shipmentId: string): Promise<Settled> {    return recordShipment(this.env.DB, orderId, shipmentId, Date.now());  }}export default {  fetch(req, env) {    return createApp(env).fetch(req);  },} satisfies ExportedHandler<Env>;