@happyvertical/smrt-inventory 0.51.32 → 0.51.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StockService.d.ts","sourceRoot":"","sources":["../../src/services/StockService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGH,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAInE;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;aAI7B,KAAK,EAAE,MAAM;aACb,UAAU,EAAE,MAAM;aAClB,KAAK,EAAE,UAAU;aACjB,SAAS,EAAE,MAAM;aACjB,SAAS,EAAE,MAAM;IAP1B,IAAI,SAA4B;gBAGvB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM;CAOpC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,EAAE,EAAE,cAAc,CAAC;CACpB;AAsBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,YAAY;IAErB;;;;;;;OAOG;aACa,EAAE,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AAI,CAAC;IAmDhB;;;;;;;;;;OAUG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,oBAAoB,GAAG;QAAE,KAAK,CAAC,EAAE,UAAU,CAAA;KAAO,GAC1D,OAAO,CAAC,IAAI,CAAC;CA+BjB;AAiMD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAEvB"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Opt-in DispatchBus subscribers that bridge upstream packages to the
3
+ * {@link StockService}.
4
+ *
5
+ * **Off by default.** The package never auto-subscribes — consumer apps
6
+ * call {@link installInventoryDispatchHandlers} from their `smrt.ts`
7
+ * wiring once they have decided they want automatic stock motion when
8
+ * contracts are created and fulfilments ship.
9
+ *
10
+ * The production-order leg (`production_order:posted` → consume
11
+ * materials + produce SKUs) is deliberately *not* installed here; that
12
+ * subscriber lives in `@happyvertical/smrt-manufacturing` (see issue
13
+ * #1250) and depends on the BOM model that ships alongside it.
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import type { DatabaseConfig, DispatchBus } from '@happyvertical/smrt-core';
18
+ import { type StockService } from './StockService.js';
19
+ /**
20
+ * Shape of a single reserved line in a `contract:created` payload. The
21
+ * producer (typically `@happyvertical/smrt-commerce`) packs one entry
22
+ * per line that needs stock motion; everything else (taxes, fees,
23
+ * non-physical items) should be filtered upstream.
24
+ */
25
+ export interface ContractCreatedLine {
26
+ skuId: string;
27
+ locationId: string;
28
+ qty: number;
29
+ }
30
+ /**
31
+ * Shape of the `contract:created` payload this handler expects. Carries
32
+ * the contract id (used for source attribution on the audit row) and
33
+ * the list of line items to reserve.
34
+ */
35
+ export interface ContractCreatedPayload {
36
+ contractId: string;
37
+ lines: ContractCreatedLine[];
38
+ }
39
+ /**
40
+ * Shape of a single shipped line in a `fulfillment:shipped` payload.
41
+ */
42
+ export interface FulfillmentShippedLine {
43
+ skuId: string;
44
+ locationId: string;
45
+ qty: number;
46
+ }
47
+ /**
48
+ * Shape of the `fulfillment:shipped` payload this handler expects.
49
+ * Producers emit one per shipped fulfilment; the handler fulfils each
50
+ * line against the level created by the matching `contract:created`
51
+ * reservation.
52
+ */
53
+ export interface FulfillmentShippedPayload {
54
+ fulfillmentId: string;
55
+ lines: FulfillmentShippedLine[];
56
+ }
57
+ /**
58
+ * Options accepted by {@link installInventoryDispatchHandlers}.
59
+ *
60
+ * Provide either a pre-built {@link StockService} (when sharing one
61
+ * across multiple subsystems) or a `db` for the helper to construct one
62
+ * on first use.
63
+ */
64
+ export type InstallInventoryDispatchHandlersOptions = {
65
+ /**
66
+ * Bus to subscribe on. Typically the app-wide `DispatchBus` created in
67
+ * the application's `smrt.ts`.
68
+ */
69
+ dispatchBus: DispatchBus;
70
+ /**
71
+ * When `true` (default), install the `contract:created` handler.
72
+ * Producers should publish a {@link ContractCreatedPayload}.
73
+ */
74
+ installContractReserved?: boolean;
75
+ /**
76
+ * When `true` (default), install the `fulfillment:shipped` handler.
77
+ * Producers should publish a {@link FulfillmentShippedPayload}.
78
+ */
79
+ installFulfillmentShipped?: boolean;
80
+ } & ({
81
+ stockService: StockService;
82
+ db?: DatabaseConfig;
83
+ } | {
84
+ db: DatabaseConfig;
85
+ stockService?: undefined;
86
+ });
87
+ /**
88
+ * Result handle returned by {@link installInventoryDispatchHandlers}.
89
+ * Call `dispose()` to detach the subscribers (mainly useful in tests
90
+ * and on graceful shutdown).
91
+ */
92
+ export interface InstalledInventoryDispatchHandlers {
93
+ /** Resolved StockService — useful for follow-up writes in the same scope. */
94
+ stockService: StockService;
95
+ /** Detach every installed subscriber. Idempotent. */
96
+ dispose(): void;
97
+ }
98
+ /**
99
+ * Subscribe a {@link StockService}-driven handler to the relevant signals
100
+ * on the given {@link DispatchBus}. Returns a disposer for tests and
101
+ * shutdown hooks.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * import { createDispatchBus } from '@happyvertical/smrt-core';
106
+ * import { installInventoryDispatchHandlers } from '@happyvertical/smrt-inventory';
107
+ *
108
+ * const bus = await createDispatchBus({ db });
109
+ * const handlers = await installInventoryDispatchHandlers({
110
+ * dispatchBus: bus,
111
+ * db,
112
+ * });
113
+ * ```
114
+ */
115
+ export declare function installInventoryDispatchHandlers(options: InstallInventoryDispatchHandlersOptions): Promise<InstalledInventoryDispatchHandlers>;
116
+ //# sourceMappingURL=dispatch-handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-handlers.d.ts","sourceRoot":"","sources":["../../src/services/dispatch-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EAGZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI1E;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,mBAAmB,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,sBAAsB,EAAE,CAAC;CACjC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC;IACzB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,GAAG,CACA;IAAE,YAAY,EAAE,YAAY,CAAC;IAAC,EAAE,CAAC,EAAE,cAAc,CAAA;CAAE,GACnD;IAAE,EAAE,EAAE,cAAc,CAAC;IAAC,YAAY,CAAC,EAAE,SAAS,CAAA;CAAE,CACnD,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,kCAAkC;IACjD,6EAA6E;IAC7E,YAAY,EAAE,YAAY,CAAC;IAC3B,qDAAqD;IACrD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,uCAAuC,GAC/C,OAAO,CAAC,kCAAkC,CAAC,CA6C7C"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Service exports for `@happyvertical/smrt-inventory`.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { type ContractCreatedLine, type ContractCreatedPayload, type FulfillmentShippedLine, type FulfillmentShippedPayload, type InstalledInventoryDispatchHandlers, type InstallInventoryDispatchHandlersOptions, installInventoryDispatchHandlers, } from './dispatch-handlers.js';
7
+ export { createStockService, InsufficientStockError, type StockMutationOptions, StockService, type StockServiceOptions, } from './StockService.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,kCAAkC,EACvC,KAAK,uCAAuC,EAC5C,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC"}
@@ -3,12 +3,12 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-inventory",
6
- "packageVersion": "0.51.32",
6
+ "packageVersion": "0.51.33",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "e300807bcb31a8fa471db8b302a901cabb13b8c343c077078c669f9e6b2625d8",
11
- "packageJson": "7982c5e5f8c5b9fef84a1ff3b953dde201343e0d79bed98ad4b529e71ca2c1c1",
10
+ "manifest": "78ad406940e0da8c9c516d9370561baff35f342c429c1ffa9f4ac06d412bbaf9",
11
+ "packageJson": "29e834e5876c142b8de3ebf51888ed4bc379c17a4f00c1efe06c50a0a8417cfc",
12
12
  "agents": "a771bf16d21cabbe43a77d5cb87ca7dedbf2e68d1928cf804cf4fefaad7a765f"
13
13
  },
14
14
  "exports": [
@@ -23,7 +23,7 @@
23
23
  "@happyvertical/sql": "catalog:",
24
24
  "@happyvertical/smrt-vitest": "workspace:*",
25
25
  "@types/node": "24.13.6",
26
- "typescript": "5.9.3",
26
+ "typescript": "6.0.3",
27
27
  "vite": "8.1.4",
28
28
  "vitest": "4.1.10"
29
29
  },
package/dist/types.d.ts CHANGED
@@ -1,55 +1,51 @@
1
- /**
2
- * Shared types for @happyvertical/smrt-inventory.
3
- *
4
- * These are deliberately industry-neutral: the same vocabulary serves
5
- * apparel, furniture, automotive, CPG, electronics, and any other domain
6
- * that tracks countable units across locations.
7
- *
8
- * @packageDocumentation
9
- */
10
-
11
- /**
12
- * Open-ended classifier for an InventoryLocation. The framework does not
13
- * special-case any value — pass whatever taxonomy your application needs.
14
- *
15
- * The strings listed here are conventions, not an exhaustive enum:
16
- * - `warehouse` — fulfillment warehouse
17
- * - `factory` — manufacturing site
18
- * - `retail` — storefront / point-of-sale
19
- * - `in_transit` — virtual location for stock that has left A but not yet
20
- * arrived at B; balances `transfer()` semantics
21
- * - `virtual` — any other non-physical bucket (returns staging, scrap,
22
- * consignment pool)
23
- */
24
- export declare type InventoryLocationKind = string;
25
-
26
- /**
27
- * Why a StockMovement was written.
28
- *
29
- * Each {@link StockService} method writes one movement with a `reasonCode`
30
- * drawn from this list. Free-form `string` is also accepted so consumers
31
- * can introduce vocabulary specific to their business (e.g. `'shrink'`,
32
- * `'sample'`, `'consignment_out'`) without forking the package.
33
- */
34
- export declare type StockMovementReason = 'receipt' | 'reservation' | 'release' | 'fulfillment' | 'transfer_out' | 'transfer_in' | 'adjustment' | 'production_consume' | 'production_produce' | (string & {});
35
-
36
- /**
37
- * Logical state of a quantity of stock at a `(skuId, locationId)` pair.
38
- *
39
- * StockLevel rows are tuples of `(skuId, locationId, state)`, so a single
40
- * SKU at a single location can simultaneously have non-zero quantities in
41
- * several states (e.g. 50 available, 10 allocated, 3 damaged).
42
- *
43
- * - `available` — on hand and free to allocate.
44
- * - `allocated` — reserved against a contract, order, or production plan;
45
- * physically still on site but no longer free to sell.
46
- * - `wip` — work-in-progress: consumed materials inside an active
47
- * production order, not yet emitted as finished goods.
48
- * - `qc_hold` — held pending quality control; not available to allocate
49
- * or ship until released.
50
- * - `damaged` — damaged or otherwise unsellable; kept on the books for
51
- * shrinkage accounting until written off.
52
- */
53
- export declare type StockState = 'available' | 'allocated' | 'wip' | 'qc_hold' | 'damaged';
54
-
55
- export { }
1
+ /**
2
+ * Shared types for @happyvertical/smrt-inventory.
3
+ *
4
+ * These are deliberately industry-neutral: the same vocabulary serves
5
+ * apparel, furniture, automotive, CPG, electronics, and any other domain
6
+ * that tracks countable units across locations.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ /**
11
+ * Logical state of a quantity of stock at a `(skuId, locationId)` pair.
12
+ *
13
+ * StockLevel rows are tuples of `(skuId, locationId, state)`, so a single
14
+ * SKU at a single location can simultaneously have non-zero quantities in
15
+ * several states (e.g. 50 available, 10 allocated, 3 damaged).
16
+ *
17
+ * - `available` — on hand and free to allocate.
18
+ * - `allocated` — reserved against a contract, order, or production plan;
19
+ * physically still on site but no longer free to sell.
20
+ * - `wip` — work-in-progress: consumed materials inside an active
21
+ * production order, not yet emitted as finished goods.
22
+ * - `qc_hold` — held pending quality control; not available to allocate
23
+ * or ship until released.
24
+ * - `damaged` — damaged or otherwise unsellable; kept on the books for
25
+ * shrinkage accounting until written off.
26
+ */
27
+ export type StockState = 'available' | 'allocated' | 'wip' | 'qc_hold' | 'damaged';
28
+ /**
29
+ * Open-ended classifier for an InventoryLocation. The framework does not
30
+ * special-case any value — pass whatever taxonomy your application needs.
31
+ *
32
+ * The strings listed here are conventions, not an exhaustive enum:
33
+ * - `warehouse` — fulfillment warehouse
34
+ * - `factory` — manufacturing site
35
+ * - `retail` — storefront / point-of-sale
36
+ * - `in_transit` — virtual location for stock that has left A but not yet
37
+ * arrived at B; balances `transfer()` semantics
38
+ * - `virtual` — any other non-physical bucket (returns staging, scrap,
39
+ * consignment pool)
40
+ */
41
+ export type InventoryLocationKind = string;
42
+ /**
43
+ * Why a StockMovement was written.
44
+ *
45
+ * Each {@link StockService} method writes one movement with a `reasonCode`
46
+ * drawn from this list. Free-form `string` is also accepted so consumers
47
+ * can introduce vocabulary specific to their business (e.g. `'shrink'`,
48
+ * `'sample'`, `'consignment_out'`) without forking the package.
49
+ */
50
+ export type StockMovementReason = 'receipt' | 'reservation' | 'release' | 'fulfillment' | 'transfer_out' | 'transfer_in' | 'adjustment' | 'production_consume' | 'production_produce' | (string & {});
51
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,GAClB,WAAW,GACX,WAAW,GACX,KAAK,GACL,SAAS,GACT,SAAS,CAAC;AAEd;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAC3B,SAAS,GACT,aAAa,GACb,SAAS,GACT,aAAa,GACb,cAAc,GACd,aAAa,GACb,YAAY,GACZ,oBAAoB,GACpB,oBAAoB,GACpB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-inventory",
3
- "version": "0.51.32",
3
+ "version": "0.51.33",
4
4
  "description": "Multi-location stock tracking for the SMRT framework — Sku, InventoryLocation, StockLevel, StockMovement, and a stock-mutation service",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,14 +20,14 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@happyvertical/logger": "^0.94.1",
23
- "@happyvertical/smrt-core": "0.51.32",
24
- "@happyvertical/smrt-tenancy": "0.51.32",
23
+ "@happyvertical/smrt-core": "0.51.33",
24
+ "@happyvertical/smrt-tenancy": "0.51.33",
25
25
  "@happyvertical/sql": "^0.94.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@happyvertical/smrt-vitest": "0.51.32",
28
+ "@happyvertical/smrt-vitest": "0.51.33",
29
29
  "@types/node": "24.13.6",
30
- "typescript": "5.9.3",
30
+ "typescript": "6.0.3",
31
31
  "vite": "8.1.4",
32
32
  "vitest": "4.1.10"
33
33
  },