import "server-only"; import type { CartMutation, CartSnapshot, OrderSnapshot } from "@salixcommerce/core"; export type CommerceFailureCode = | "CART_CLOSED" | "COMMERCE_UNAVAILABLE" | "EMPTY_CART" | "IDEMPOTENCY_CONFLICT" | "ILLEGAL_ORDER_TRANSITION" | "INSUFFICIENT_INVENTORY" | "INVALID_REQUEST" | "ORDER_NOT_FOUND" | "PAYMENT_ALREADY_PENDING" | "PROVIDER_FAILURE" | "VARIANT_UNAVAILABLE"; export interface CommerceFailure { readonly code: CommerceFailureCode; readonly message: string; readonly status: 400 | 404 | 409 | 500 | 503; } export type CommerceResult = { readonly data: T; readonly ok: true } | { readonly error: CommerceFailure; readonly ok: false }; export interface CommerceRepository { cancelOrder( input: Readonly<{ capabilityHash: string; idempotencyKey: string; reason: string; reference: string; requestHash: string; }>, ): Promise>; createOrder( input: Readonly<{ capabilityHash: string; contactEmail: string; idempotencyKey: string; requestHash: string; }>, ): Promise>; loadCart(capabilityHash: string): Promise; loadOrder(capabilityHash: string, reference: string): Promise; mutateCart( input: Readonly<{ capabilityHash: string; command: CartMutation; requestHash: string; }>, ): Promise>; } export function commerceFailure( code: CommerceFailureCode, message: string, status: CommerceFailure["status"], ): CommerceFailure { return Object.freeze({ code, message, status }); }