← Case study

POSTGRESQL REFERENCE · WORKING SOURCE

src/contracts.ts

This file ships in the runnable source archive. Synthetic fixtures and demonstration policies are identified in the README.

Download the complete project ↓
export type Role = "customer" | "operator";
export interface Actor {
  id: string;
  email: string;
  name: string;
  orgId: string;
  orgName: string;
  role: Role;
  csrfToken?: string;
}
export interface PalletDeclaration {
  lengthMm: number;
  widthMm: number;
  heightMm: number;
  weightKg: number;
  condition: "ambient";
  goods: "packaged_dry";
}
export interface QuoteRequest {
  warehouseId: string;
  zoneId: string;
  quantity: number;
  startAt: string;
  endAt: string;
  pallet: PalletDeclaration;
}
export interface ReceiveRequest {
  pallets: Array<
    {
      label: string;
      externalId?: string;
      lengthMm?: number;
      widthMm?: number;
      heightMm?: number;
      weightKg?: number;
      condition?: string;
      goods?: string;
    }
  >;
  approveVariance?: boolean;
  reason?: string;
  expectedEndAt?: string;
}
export interface ReleaseRequest {
  palletIds: string[];
  reason: string;
  releaseRequestId?: string;
}
export interface ApiErrorBody {
  error: { code: string; message: string; details?: unknown; retryable?: boolean };
}
export interface InvoiceSummary {
  palletDays: number;
  storageCents: number;
  receivingCents: number;
  releaseCents: number;
  adjustmentCents: number;
  totalCents: number;
}
export interface QuoteResponse {
  id: string;
  warehouseId: string;
  zoneId: string;
  quantity: number;
  startAt: string;
  endAt: string;
  expiresAt: string;
  rateVersion: string;
  currency: string;
  lines: Array<{ kind: string; quantity: number; unitCents: number; totalCents: number }>;
  totalCents: number;
  terms: string;
  pallet: PalletDeclaration;
  status: string;
  availability: { available: number; requested: number; assumption: string };
}
export interface HoldResponse {
  id: string;
  quoteId: string;
  expiresAt: string;
  positionIds: string[];
  status: string;
}
export interface ReservationResponse {
  id: string;
  quoteId: string;
  warehouseId: string;
  zoneId: string;
  customerName: string;
  customerOrgId: string;
  status: "confirmed" | "cancelled" | "expired" | "completed";
  receivingStatus: "open" | "closed_released" | "closed_retained";
  startAt: string;
  endAt: string;
  quantity: number;
  unreceived: number;
  inCustody: number;
  released: number;
  rateVersion: string;
  estimateCents: number;
  declaration: PalletDeclaration;
}
export interface PalletResponse {
  id: string;
  label: string;
  externalId: string | null;
  externalScheme: string | null;
  reservationId: string;
  ownerOrgId: string;
  positionId: string | null;
  positionLabel: string | null;
  receivedAt: string;
  releasedAt: string | null;
  customerName: string;
  declaration: PalletDeclaration;
}
export interface ReceiveResponse {
  reservation: ReservationResponse;
  pallets: PalletResponse[];
  movementIds: string[];
  variance: { early: boolean; late: boolean; excess: number };
}
export interface ReleaseResponse {
  reservation: ReservationResponse;
  released: PalletResponse[];
  movementIds: string[];
}
export interface InvoiceLine {
  id: string;
  kind: "storage" | "receiving" | "release" | "adjustment";
  palletId: string | null;
  palletLabel: string | null;
  serviceDate: string | null;
  quantity: number;
  unitCents: number;
  totalCents: number;
  movementIds: string[];
  rateVersion: string;
  rateCardId: string;
  provisional: boolean;
}
export interface MovementResponse {
  id: string;
  kind: string;
  palletId: string | null;
  occurredAt: string;
  recordedAt: string;
  actorName: string;
  ownerOrgId: string;
  fromPositionId: string | null;
  toPositionId: string | null;
  reason: string;
  adjustmentOf: string | null;
  data: unknown;
}
export interface InvoiceResponse {
  reservationId: string;
  customerName: string;
  currency: string;
  rateVersion: string;
  rateCardId: string;
  terms: string;
  quoteEstimateCents: number;
  currentEstimateCents: number;
  asOf: string;
  summary: InvoiceSummary;
  lines: InvoiceLine[];
  events: MovementResponse[];
}
// SQL rows are mapped to public DTOs at the boundary, never returned wholesale.
// deno-lint-ignore no-explicit-any
export type Row = Record<string, any>;