@companyio/inventory
v0.3.1
Published
Universal inventory package for multi-tenant CompanyIO products
Readme
@companyio/inventory
Universal stock balances, movements, transfers, adjustments, and counts for CompanyIO products.
Inventory is the authoritative source of truth for physical stock quantities and movements.
Sales and Purchasing describe commercial events. Inventory records the stock effect. Accounting owns financial truth. Fuel tank/dip/meter stock stays in @companyio/fuel.
Inventory does not own:
- product/SKU master (
@companyio/catalog) - purchase orders or supplier bills (
@companyio/purchasing) - sales invoices (
@companyio/sales) - journals (
@companyio/accounting) - fuel tanks, dips, litres, pumps (
@companyio/fuel)
productRef stores a @companyio/catalog variant id. locationRef is an opaque location id from the host (warehouse, store, back room — not a Fuel tank).
pnpm exec inventory init --schema apps/api/prisma/schema.prisma
pnpm exec inventory status
pnpm --filter @companyio/api exec prisma migrate deploy --config prisma7.config.tsinventory init copies prisma/migrations/0001_inventory_baseline when the host does not already have it (20260926000700_inventory_baseline). Host migration 20260930120000_inventory_movement_idempotency adds idempotencyKey. Inventory does not connect to PostgreSQL. Tenant columns are main_business_id and branch_id.
Fastify + commerce wiring
const inventory = attachInventory(app, {
store: createPrismaInventoryStore(prisma),
catalog: createCatalogInventoryAdapter(catalog),
prefix: '/api/v1/inventory',
authenticate,
getContext,
});
attachPurchasing(app, {
// ...
inventory: createPurchasingInventoryAdapter(inventory.inventory, {
defaultLocationRef: 'main',
}),
});
attachSales(app, {
// ...
inventory: createSalesInventoryAdapter(inventory.inventory, {
defaultLocationRef: 'main',
}),
});Line or document attributes.locationRef overrides the default location.
API Routes
Mounted at /api/v1/inventory. Full detail: docs/API_ROUTE_INVENTORY.md.
| Method | Route | Auth | Purpose | | -------- | ----------------------- | ------- | --------------- | | GET | /inventory/health | Public | Health | | GET | /inventory/stock | Session | Stock levels | | GET | /inventory/movements | Session | Movements | | POST | /inventory/receipts | Session | Receipt | | POST | /inventory/issues | Session | Issue | | POST/GET | /inventory/transfers… | Session | Transfers | | POST/GET | /inventory/adjustments… | Session | Adjustments | | POST | /inventory/counts… | Session | Counts (+ post) |
Known gaps
- COGS / COGS-return / shortage / gain journals: optional host wiring via
createAccountingInventoryAdapter. Accounts resolve through AccountingresolveInventoryPostingAccounts(seededSTANDARD_CHART_CODES+ optionalOperationalAccountMapping). Verified zero WAC skips journals (skippedZeroCostIds); invalid valuation fails. PassbooksintocreateSalesInventoryAdapter(and FuelinventoryBooks) so costs post once per movement id. locationRefis opaque — hosts own warehouses/stores; vertical tank/dip stock stays in product packages.- No lot/serial tracking yet.
Frontend (/client + /react)
Browser hosts should import from the dedicated entries — never the package root:
import { createInventoryApi } from '@companyio/inventory/client';
import {
InventoryProvider,
InventoryStockPage,
inventoryQueryKeys,
} from '@companyio/inventory/react';InventoryStockPage covers stock on hand, recent movements, receive stock, and physical count.
Product pickers come from @companyio/catalog/react. Host-specific workflows (e.g. ContractFlow
issue-to-project via contractor material-issues) stay in thin product adapters.
Fixed assets are not stock inventory — use @companyio/assets. Fuel tank/dip stock stays in
@companyio/fuel. Purchasing receipts that affect stock go through purchasing → inventory adapters,
not duplicated UI in this package.
Build / test
pnpm --filter @companyio/inventory test
pnpm --filter @companyio/inventory build
pnpm --filter @companyio/inventory typecheckPackage tests cover CLI init, stock movements integration, HTTP routes, client contracts, format
helpers, and browser-boundary guards for /client and /react.
