API reference

Orders, products, customers and invoices

Statuses, attention rules, views and totals of the commerce and billing modules.

Everything in utils/ is a pure function: it takes data and returns data, with no Vue and no global state. Pass the current date as now so results are deterministic. Each file has its unit tests in tests/unit/.

orderStepIndex()

The fulfilment step of an order.

utils/orders.ts
orderStepIndex(order: Pick<Order, 'status'>): number

orderStepDate()

When an order reached a step.

utils/orders.ts
orderStepDate(order: Pick<Order, 'events'>, step: OrderStep): string | undefined

orderDispatchDue()

The date an order must be dispatched.

utils/orders.ts
orderDispatchDue(order: Order): string

isOrderLate()

Whether an order missed its dispatch or delivery window.

utils/orders.ts
isOrderLate(order: Order, now: Date): boolean

matchesOrderView()

Whether an order belongs to a view.

utils/orders.ts
matchesOrderView(order: Pick<Order, 'status' | 'paymentStatus'>, view: OrderView): boolean

orderViewCounts()

The count of every order view.

utils/orders.ts
orderViewCounts(orders: Pick<Order, 'status' | 'paymentStatus'>[]): Record<OrderView, number>

orderAttention()

Orders that need attention now.

utils/orders.ts
orderAttention(orders: Order[], now: Date): { late: number; unpaid: number; }
Returnslateunpaid

productStock()

Total stock across variants.

utils/products.ts
productStock(product: Pick<Product, 'variants'>): number

productStockState()

in, low or out of stock.

utils/products.ts
productStockState(product: StockFields): ProductStockState

productSales()

Units sold in the period.

utils/products.ts
productSales(product: Pick<Product, 'dailySales'>): number

productRevenue()

Revenue in the period.

utils/products.ts
productRevenue(product: Pick<Product, 'dailySales' | 'price'>): number

productSalesTrend()

Change of sales against the previous half.

utils/products.ts
productSalesTrend(product: Pick<Product, 'dailySales'>): number

productDaysLeft()

Days until the stock runs out at the current pace.

utils/products.ts
productDaysLeft(product: Pick<Product, 'variants' | 'dailySales'>): number | undefined

productMargin()

Margin from price and cost.

utils/products.ts
productMargin(product: Pick<Product, 'price' | 'cost'>): number

productDiscount()

Discount from the compare-at price.

utils/products.ts
productDiscount(product: Pick<Product, 'price' | 'compareAtPrice'>): number

matchesProductView()

Whether a product belongs to a view.

utils/products.ts
matchesProductView(product: Pick<Product, 'status' | 'variants' | 'lowStockThreshold'>, view: ProductView): boolean

productViewCounts()

The count of every product view.

utils/products.ts
productViewCounts(products: Pick<Product, 'status' | 'variants' | 'lowStockThreshold'>[]): Record<ProductView, number>

productAttention()

Products out of stock or running out soon.

utils/products.ts
productAttention(products: Product[]): { out: number; runningLow: number; }
ReturnsoutrunningLow

customerSegment()

VIP, regular, new or at risk, derived from activity.

utils/customers.ts
customerSegment(customer: ActivityFields, now: Date): CustomerSegment

customerDaysSinceOrder()

Days since the last order.

utils/customers.ts
customerDaysSinceOrder(customer: Pick<Customer, 'lastOrder'>, now: Date): number

customerAverageOrder()

Average order value.

utils/customers.ts
customerAverageOrder(customer: Pick<Customer, 'spent' | 'orders'>): number

customerSpendTrend()

Spend trend over 12 months.

utils/customers.ts
customerSpendTrend(customer: Pick<Customer, 'monthlySpend'>): number

customerOrderInterval()

Average days between orders.

utils/customers.ts
customerOrderInterval(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders'>): number | undefined

customerNextOrderIn()

Days until the expected next order.

utils/customers.ts
customerNextOrderIn(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders' | 'status'>, now: Date): number | undefined

matchesCustomerView()

Whether a customer belongs to a view.

utils/customers.ts
matchesCustomerView(customer: ActivityFields, view: CustomerView, now: Date): boolean

customerViewCounts()

The count of every customer view.

utils/customers.ts
customerViewCounts(customers: ActivityFields[], now: Date): Record<CustomerView, number>

customerAttention()

Customers to win back.

utils/customers.ts
customerAttention(customers: Customer[], now: Date): { atRisk: number; value: number; }
ReturnsatRiskvalue

invoiceTotals()

Subtotal, discount, tax and total.

utils/invoices.ts
invoiceTotals(invoice: Pick<Invoice, 'lines' | 'taxRate' | 'discountRate'>): InvoiceTotals
Returnssubtotaldiscounttaxtotal

invoicePaid()

The amount paid so far.

utils/invoices.ts
invoicePaid(invoice: Pick<Invoice, 'payments'>): number

invoiceBalance()

The amount still due.

utils/invoices.ts
invoiceBalance(invoice: Invoice): number

invoiceDaysToDue()

Days to the due date (negative when overdue).

utils/invoices.ts
invoiceDaysToDue(invoice: Pick<Invoice, 'due'>, now: Date): number

invoiceStatus()

Draft, pending, partial, overdue or paid.

utils/invoices.ts
invoiceStatus(invoice: Invoice, now: Date): InvoiceStatus

invoiceAgingBucket()

The aging bucket of an unpaid invoice.

utils/invoices.ts
invoiceAgingBucket(invoice: Invoice, now: Date): InvoiceAgingBucket | undefined

invoiceAging()

Outstanding amounts by aging bucket.

utils/invoices.ts
invoiceAging(invoices: Invoice[], now: Date): { buckets: Record<InvoiceAgingBucket, number>; count: number; total: number; }
Returnsbucketscounttotal

invoicePaidSince()

Amount collected since a date.

utils/invoices.ts
invoicePaidSince(invoices: Invoice[], since: Date): number

averageCollectionDays()

Average days to get paid.

utils/invoices.ts
averageCollectionDays(invoices: Invoice[]): number | undefined

matchesInvoiceView()

Whether an invoice belongs to a view.

utils/invoices.ts
matchesInvoiceView(invoice: Invoice, view: InvoiceView, now: Date): boolean

invoiceViewCounts()

The count of every invoice view.

utils/invoices.ts
invoiceViewCounts(invoices: Invoice[], now: Date): Record<InvoiceView, number>
© 2026 melsami UI.
Developer documentation for melsami UI.