/** * This function will be executed automatically after either shipment status or payment status is updated. */ import { PoolClient } from '@evershop/postgres-query-builder'; import { OrderRow } from '../../../types/db/index.js'; export declare function resolveOrderStatus(paymentStatus: string, shipmentStatus: string): string; /** * Whether an order status is terminal — no further lifecycle progression. A * terminal status has an empty `next` transition list (`closed`, `canceled` in * the defaults). Used to gate fulfillment actions declaratively: a shipment * cannot be created for a terminal order (a fully-refunded order is `closed`; a * canceled order is `canceled`). Reuses the status-flow config, so extensions * that register their own terminal statuses are covered automatically. */ export declare function isTerminalOrderStatus(status: string | null | undefined): boolean; /** * Clamp a projected order status against where the order already is, so the * lifecycle only ever holds or moves forward — it never reverts and never * leaves a terminal state. This is the single place order-status "memory" * lives; `resolveOrderStatus` is a pure projection of (payment, shipment) and * knows nothing about the order's current status. * * Rules, in order: * 1. No current status yet (brand-new order) → accept the candidate. * 2. Current status is terminal (`closed`/`canceled` — empty `next`) → keep * it. A refunded order stays `closed` however its shipments move; a * canceled order stays `canceled`. * 3. Candidate sorts *before* the current status in the flow → keep current * (no revert). * 4. Otherwise → adopt the candidate (forward progress). * * Because rules 2 and 3 return the *current* status, `changeOrderStatus` * becomes a no-op instead of an error. Before this, both cases THREW — from the * bootstrap `changePaymentStatus`/`changeShipmentStatus` hooks ("Order is * already closed") and from `changeOrderStatus` itself ("Can not revert") — and * the throw rolled back the enclosing transaction. That coupled a harmless * projection result (the order status simply can't move) to a hard failure of * the action the merchant actually took (cancel a shipment, record a refund). * The clamp decouples them: the action commits, the order status just holds. * A misconfigured `psoMapping` can no longer roll back a valid operation. * * @param flow Topo-sorted order-status names, from `getOrderStatusFlow()`. */ export declare function clampOrderStatus(candidate: string, current: string | null | undefined, flow: string[]): string; export declare function changeOrderStatus(orderId: number, status: string, conn?: PoolClient): Promise; export declare function hookBeforeUpdateOrderStatus(callback: (this: { order: OrderRow; status: string; }, ...args: [ orderId: number, status: string, connection: PoolClient, ...args: any[] ]) => void | Promise, priority?: number): void; export declare function hookAfterUpdateOrderStatus(callback: (this: { order: OrderRow; status: string; }, ...args: [ orderId: number, status: string, connection: PoolClient, ...args: any[] ]) => void | Promise, priority?: number): void; export declare function hookBeforeAddOrderStatusChangeEvents(callback: (this: { order: OrderRow; status: string; }, ...args: [ orderId: number, before: string, after: string, connection: PoolClient ]) => void | Promise, priority?: number): void; export declare function hookAfterAddOrderStatusChangeEvents(callback: (this: { order: OrderRow; status: string; }, ...args: [ orderId: number, before: string, after: string, connection: PoolClient ]) => void | Promise, priority?: number): void;