@happyvertical/smrt-inventory 0.57.17 → 0.57.18
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.
- package/AGENTS.md +19 -1
- package/README.md +32 -2
- package/dist/collections/LotCollection.d.ts +22 -0
- package/dist/collections/LotCollection.d.ts.map +1 -0
- package/dist/collections/LotCorrectionCollection.d.ts +12 -0
- package/dist/collections/LotCorrectionCollection.d.ts.map +1 -0
- package/dist/collections/LotDocumentCollection.d.ts +12 -0
- package/dist/collections/LotDocumentCollection.d.ts.map +1 -0
- package/dist/collections/LotStockLevelCollection.d.ts +21 -0
- package/dist/collections/LotStockLevelCollection.d.ts.map +1 -0
- package/dist/collections/LotUsageCollection.d.ts +18 -0
- package/dist/collections/LotUsageCollection.d.ts.map +1 -0
- package/dist/collections/index.d.ts +5 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1168 -31
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +2921 -288
- package/dist/models/Lot.d.ts +96 -0
- package/dist/models/Lot.d.ts.map +1 -0
- package/dist/models/LotCorrection.d.ts +55 -0
- package/dist/models/LotCorrection.d.ts.map +1 -0
- package/dist/models/LotDocument.d.ts +45 -0
- package/dist/models/LotDocument.d.ts.map +1 -0
- package/dist/models/LotStockLevel.d.ts +43 -0
- package/dist/models/LotStockLevel.d.ts.map +1 -0
- package/dist/models/LotUsage.d.ts +64 -0
- package/dist/models/LotUsage.d.ts.map +1 -0
- package/dist/models/StockMovement.d.ts +7 -0
- package/dist/models/StockMovement.d.ts.map +1 -1
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/services/LotService.d.ts +258 -0
- package/dist/services/LotService.d.ts.map +1 -0
- package/dist/services/StockService.d.ts +25 -2
- package/dist/services/StockService.d.ts.map +1 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/lot-errors.d.ts +44 -0
- package/dist/services/lot-errors.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +1333 -76
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -24,6 +24,15 @@
|
|
|
24
24
|
* `console.warn`. Tests and consumers that observe that warning should
|
|
25
25
|
* upgrade their adapter.
|
|
26
26
|
*
|
|
27
|
+
* **Lots**: pass `lotId` in the options of any mutation and the same deltas
|
|
28
|
+
* are applied to {@link LotStockLevel} rows keyed by
|
|
29
|
+
* `(lotId, locationId, state)`, with the same non-negative rule, and the
|
|
30
|
+
* lot is stamped on every movement written. SKU-level balances behave
|
|
31
|
+
* exactly as without a lot. Create lots with {@link LotService}; compose
|
|
32
|
+
* both through a shared transaction (`stock.withTransaction`, then
|
|
33
|
+
* `createLotService({ db: tx.db })`) to receive a lot and its stock
|
|
34
|
+
* atomically.
|
|
35
|
+
*
|
|
27
36
|
* Callers should never reach into the level or movement collections
|
|
28
37
|
* directly to mutate balances — doing so silently desyncs the audit
|
|
29
38
|
* ledger and breaks cycle counts.
|
|
@@ -40,7 +49,7 @@
|
|
|
40
49
|
* @packageDocumentation
|
|
41
50
|
*/
|
|
42
51
|
import { type DatabaseConfig } from '@happyvertical/smrt-core';
|
|
43
|
-
import { InventoryLocationCollection, StockLevelCollection, StockMovementCollection } from '../collections/index.js';
|
|
52
|
+
import { InventoryLocationCollection, LotCollection, LotStockLevelCollection, StockLevelCollection, StockMovementCollection } from '../collections/index.js';
|
|
44
53
|
import type { StockLevel } from '../models/StockLevel.js';
|
|
45
54
|
import type { StockMovementReason, StockState } from '../types.js';
|
|
46
55
|
/**
|
|
@@ -56,8 +65,12 @@ export declare class InsufficientStockError extends Error {
|
|
|
56
65
|
readonly state: StockState;
|
|
57
66
|
readonly requested: number;
|
|
58
67
|
readonly available: number;
|
|
68
|
+
/** Set when the shortfall is in a lot's balance rather than the SKU's. */
|
|
69
|
+
readonly lotId?: string | undefined;
|
|
59
70
|
name: string;
|
|
60
|
-
constructor(skuId: string, locationId: string, state: StockState, requested: number, available: number
|
|
71
|
+
constructor(skuId: string, locationId: string, state: StockState, requested: number, available: number,
|
|
72
|
+
/** Set when the shortfall is in a lot's balance rather than the SKU's. */
|
|
73
|
+
lotId?: string | undefined);
|
|
61
74
|
}
|
|
62
75
|
/**
|
|
63
76
|
* Options shared by every {@link StockService} method that wants to leave
|
|
@@ -65,6 +78,11 @@ export declare class InsufficientStockError extends Error {
|
|
|
65
78
|
* pattern in {@link StockMovement.sourceType} / {@link StockMovement.sourceId}.
|
|
66
79
|
*/
|
|
67
80
|
export interface StockMutationOptions {
|
|
81
|
+
/**
|
|
82
|
+
* Track this mutation against a {@link Lot}. The lot must exist and, when
|
|
83
|
+
* it names a SKU, that SKU must match (else {@link LotMismatchError}).
|
|
84
|
+
*/
|
|
85
|
+
lotId?: string | null;
|
|
68
86
|
/** Cross-package tag, e.g. `'Contract'`, `'Fulfillment'`, `'CycleCount'`. */
|
|
69
87
|
sourceType?: string;
|
|
70
88
|
/** Cross-package id of the row that caused this mutation. */
|
|
@@ -131,6 +149,10 @@ export declare class StockService {
|
|
|
131
149
|
readonly levels: StockLevelCollection;
|
|
132
150
|
readonly movements: StockMovementCollection;
|
|
133
151
|
readonly locations: InventoryLocationCollection;
|
|
152
|
+
/** Per-lot balances, mutated only by this service. */
|
|
153
|
+
readonly lotLevels: LotStockLevelCollection;
|
|
154
|
+
/** Lookup of lots for validation; created through {@link LotService}. */
|
|
155
|
+
readonly lots: LotCollection;
|
|
134
156
|
/**
|
|
135
157
|
* Marks a service instance handed to a {@link withTransaction}
|
|
136
158
|
* callback. Public mutation methods on a tx-bound instance skip
|
|
@@ -171,6 +193,7 @@ export declare class StockService {
|
|
|
171
193
|
* callback), reuse it; otherwise open a fresh one.
|
|
172
194
|
*/
|
|
173
195
|
private runAtomically;
|
|
196
|
+
private txCollections;
|
|
174
197
|
/**
|
|
175
198
|
* Add `qty` to available stock at the given location. Used for
|
|
176
199
|
* purchase-order receipts, customer returns going back into available
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StockService.d.ts","sourceRoot":"","sources":["../../src/services/StockService.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"StockService.d.ts","sourceRoot":"","sources":["../../src/services/StockService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAGH,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,2BAA2B,EAC3B,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKnE;;;;;;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;IACjC,0EAA0E;aAC1D,KAAK,CAAC,EAAE,MAAM;IATvB,IAAI,SAA4B;gBAGvB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM;IACjC,0EAA0E;IAC1D,KAAK,CAAC,EAAE,MAAM,YAAA;CAOjC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,w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AK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;;OAIG;IACG,OAAO,CACX,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC;IAgChB;;;;;;;;;;;OAWG;IACG,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC;IAkEhB;;;;OAIG;IACG,gBAAgB,CACpB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,eAAe,GAAE,MAAM,GAAG,IAAW,GACpC,OAAO,CAAC,UAAU,CAAC;IA4BtB;;;;;;;;;;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;CAoCjB;AAyTD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAEvB"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
export { type ContractCreatedLine, type ContractCreatedPayload, type FulfillmentShippedLine, type FulfillmentShippedPayload, type InstalledInventoryDispatchHandlers, type InstallInventoryDispatchHandlersOptions, installInventoryDispatchHandlers, } from './dispatch-handlers.js';
|
|
7
|
+
export { type AttachDocumentInput, createLotService, type LotChangeOptions, LotService, type LotServiceOptions, type ReceiveLotInput, type RecordUsageInput, type TraceNode, type TraceOptions, } from './LotService.js';
|
|
8
|
+
export { DuplicateLotError, LotCorrectionError, LotInUseError, LotMismatchError, LotNotFoundError, } from './lot-errors.js';
|
|
7
9
|
export { createStockService, InsufficientStockError, type StockMutationOptions, StockService, type StockServiceOptions, } from './StockService.js';
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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"}
|
|
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,KAAK,mBAAmB,EACxB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors thrown by {@link LotService} and by {@link StockService} when a
|
|
3
|
+
* mutation names a lot. Kept in their own module so both services can
|
|
4
|
+
* import them without a cycle.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/** The lot id does not exist (or belongs to another tenant). */
|
|
9
|
+
export declare class LotNotFoundError extends Error {
|
|
10
|
+
readonly lotId: string;
|
|
11
|
+
name: string;
|
|
12
|
+
constructor(lotId: string);
|
|
13
|
+
}
|
|
14
|
+
/** A stock mutation named a lot that belongs to a different SKU. */
|
|
15
|
+
export declare class LotMismatchError extends Error {
|
|
16
|
+
readonly lotId: string;
|
|
17
|
+
readonly lotSkuId: string;
|
|
18
|
+
readonly skuId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
constructor(lotId: string, lotSkuId: string, skuId: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A unique lot or serial with this number already exists. Carries the
|
|
24
|
+
* existing lot's id so the caller can link to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DuplicateLotError extends Error {
|
|
27
|
+
readonly lotNumber: string;
|
|
28
|
+
readonly existingLotId: string | null;
|
|
29
|
+
name: string;
|
|
30
|
+
constructor(lotNumber: string, existingLotId: string | null);
|
|
31
|
+
}
|
|
32
|
+
/** An exclusive lot is already in use by a different consumer. */
|
|
33
|
+
export declare class LotInUseError extends Error {
|
|
34
|
+
readonly lotId: string;
|
|
35
|
+
readonly consumerType: string;
|
|
36
|
+
readonly consumerId: string;
|
|
37
|
+
name: string;
|
|
38
|
+
constructor(lotId: string, consumerType: string, consumerId: string);
|
|
39
|
+
}
|
|
40
|
+
/** A correction was refused: missing or oversized reason, or nothing changes. */
|
|
41
|
+
export declare class LotCorrectionError extends Error {
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=lot-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lot-errors.d.ts","sourceRoot":"","sources":["../../src/services/lot-errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gEAAgE;AAChE,qBAAa,gBAAiB,SAAQ,KAAK;aAGb,KAAK,EAAE,MAAM;IAFhC,IAAI,SAAsB;gBAEP,KAAK,EAAE,MAAM;CAG1C;AAED,oEAAoE;AACpE,qBAAa,gBAAiB,SAAQ,KAAK;aAIvB,KAAK,EAAE,MAAM;aACb,QAAQ,EAAE,MAAM;aAChB,KAAK,EAAE,MAAM;IALtB,IAAI,SAAsB;gBAGjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM;CAIhC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;aAIxB,SAAS,EAAE,MAAM;aACjB,aAAa,EAAE,MAAM,GAAG,IAAI;IAJrC,IAAI,SAAuB;gBAGlB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,IAAI;CAI/C;AAED,kEAAkE;AAClE,qBAAa,aAAc,SAAQ,KAAK;aAIpB,KAAK,EAAE,MAAM;aACb,YAAY,EAAE,MAAM;aACpB,UAAU,EAAE,MAAM;IAL3B,IAAI,SAAmB;gBAGd,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM;CAIrC;AAED,iFAAiF;AACjF,qBAAa,kBAAmB,SAAQ,KAAK;IAClC,IAAI,SAAwB;CACtC"}
|