sinfactura-types 1.10.382 → 1.10.384
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/dist/cjs/cycleCount.js +47 -1
- package/dist/cjs/inventory.js +1 -0
- package/dist/cycleCount.d.ts +146 -1
- package/dist/cycleCount.js +46 -0
- package/dist/inventory.d.ts +69 -52
- package/dist/inventory.js +1 -0
- package/dist/lot.d.ts +6 -5
- package/dist/order.d.ts +12 -0
- package/dist/purchaseReceipt.d.ts +8 -0
- package/dist/stock.d.ts +11 -0
- package/dist/store.d.ts +37 -0
- package/dist/user.d.ts +11 -0
- package/package.json +1 -1
package/dist/cjs/cycleCount.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CYCLE_COUNT_ERROR_CODES = exports.isOverCycleCountToleranceRule = exports.cycleCountVariancePercentRule = exports.CYCLE_COUNT_TOLERANCE_MIN_UNITS = exports.CYCLE_COUNT_DEFAULT_TOLERANCE_PERCENT = exports.CYCLE_COUNT_STATUSES = void 0;
|
|
3
|
+
exports.CYCLE_COUNT_ERROR_CODES = exports.isOverCycleCountToleranceRule = exports.cycleCountVariancePercentRule = exports.CYCLE_COUNT_TOLERANCE_MIN_UNITS = exports.CYCLE_COUNT_DEFAULT_TOLERANCE_PERCENT = exports.CYCLE_COUNT_SCOPE_INCOMPLETE_REASONS = exports.CYCLE_COUNT_SCOPE_EXCLUSION_REASONS = exports.CYCLE_COUNT_SCOPE_OUTCOMES = exports.CYCLE_COUNT_SCOPE_TYPES = exports.CYCLE_COUNT_STATUSES = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Every state a count session can hold, as a runtime value so the api's Zod
|
|
6
6
|
* enum, the operator's filter and the union all derive from ONE list.
|
|
7
7
|
*/
|
|
8
8
|
exports.CYCLE_COUNT_STATUSES = ['open', 'finalized', 'cancelled'];
|
|
9
|
+
/** The scopes `POST /cycle-counts { mode: 'preview' | 'start' }` accepts. Anything else is refused 400. */
|
|
10
|
+
exports.CYCLE_COUNT_SCOPE_TYPES = ['category', 'zone'];
|
|
11
|
+
/** Every outcome a scope discovery can end in — see {@link CycleCountScopeDiscovery.outcome}. */
|
|
12
|
+
exports.CYCLE_COUNT_SCOPE_OUTCOMES = [
|
|
13
|
+
'ready',
|
|
14
|
+
'empty',
|
|
15
|
+
'overCap',
|
|
16
|
+
'incomplete',
|
|
17
|
+
];
|
|
18
|
+
/** Why a product matching the scope is NOT a line — see {@link CycleCountScopeExclusion.reason}. */
|
|
19
|
+
exports.CYCLE_COUNT_SCOPE_EXCLUSION_REASONS = [
|
|
20
|
+
'MISSING_STOCK',
|
|
21
|
+
'NON_INTEGER_STOCK',
|
|
22
|
+
'NEGATIVE_STOCK',
|
|
23
|
+
'STOCK_OVER_MAX',
|
|
24
|
+
];
|
|
25
|
+
/** Why a discovery could not prove it saw the whole scope — see {@link CycleCountScopeDiscovery.incompleteReason}. */
|
|
26
|
+
exports.CYCLE_COUNT_SCOPE_INCOMPLETE_REASONS = [
|
|
27
|
+
'READ_BUDGET',
|
|
28
|
+
'TIME_BUDGET',
|
|
29
|
+
'REPEATED_CURSOR',
|
|
30
|
+
'UNPROCESSED_READS',
|
|
31
|
+
];
|
|
9
32
|
/**
|
|
10
33
|
* The tolerance rule itself, as ONE implementation both sides import.
|
|
11
34
|
*
|
|
@@ -127,6 +150,20 @@ exports.isOverCycleCountToleranceRule = isOverCycleCountToleranceRule;
|
|
|
127
150
|
* senders (this one is Spanish, `_postStockAdjust.ts`'s is not), so a consumer
|
|
128
151
|
* must render its own copy off the CODE and never relay the api's prose.
|
|
129
152
|
*
|
|
153
|
+
* Scoped start and the locked baseline:
|
|
154
|
+
*
|
|
155
|
+
* - `CYCLE_COUNT_SCOPE_EMPTY` · 422 — the whole scope was read and yields no line.
|
|
156
|
+
* - `CYCLE_COUNT_SCOPE_OVER_CAP` · 422 — more lines than one session can finalise.
|
|
157
|
+
* - `CYCLE_COUNT_SCOPE_INCOMPLETE` · 422 — the read could not prove it saw everything.
|
|
158
|
+
* - `CYCLE_COUNT_SCOPE_CHANGED` · 409 — `expectedProductIds` no longer matches
|
|
159
|
+
* what the scope yields; `data` is the fresh discovery to show and confirm.
|
|
160
|
+
* - `CYCLE_COUNT_START_KEY_REQUIRED` · 400 — `mode: 'start'` sent without an
|
|
161
|
+
* `Idempotency-Key` header. ⚠️ The header's own refusals
|
|
162
|
+
* (`INVALID_IDEMPOTENCY_KEY`, the fingerprint mismatch, the lock contention)
|
|
163
|
+
* come from the shared idempotency wrapper and are not cycle-count codes.
|
|
164
|
+
* - `CYCLE_COUNT_BASELINE_LOCKED` · 409 — an edit that would change, drop or
|
|
165
|
+
* extend a server-captured baseline.
|
|
166
|
+
*
|
|
130
167
|
* ⚠️ `UNHANDLED_ERROR` is deliberately NOT here, matching
|
|
131
168
|
* {@link PRESUPUESTO_ERROR_CODES}: it is `tryCatch`'s generic envelope for an
|
|
132
169
|
* unexpected THROW and belongs to no endpoint. ⚠️ It answers **400, not 500**, by
|
|
@@ -156,4 +193,13 @@ exports.CYCLE_COUNT_ERROR_CODES = [
|
|
|
156
193
|
'INVALID_CURSOR',
|
|
157
194
|
'PRODUCT_NOT_FOUND',
|
|
158
195
|
'STOCK_ADJUSTMENT_RACED',
|
|
196
|
+
// Scoped start (`mode: 'start'`) — `data` is the `CycleCountScopeDiscovery`
|
|
197
|
+
// on the four scope refusals, and NO session was created by any of them.
|
|
198
|
+
'CYCLE_COUNT_SCOPE_EMPTY',
|
|
199
|
+
'CYCLE_COUNT_SCOPE_OVER_CAP',
|
|
200
|
+
'CYCLE_COUNT_SCOPE_INCOMPLETE',
|
|
201
|
+
'CYCLE_COUNT_SCOPE_CHANGED',
|
|
202
|
+
'CYCLE_COUNT_START_KEY_REQUIRED',
|
|
203
|
+
// `mode: 'edit'` on a `baselineSource: 'server'` session.
|
|
204
|
+
'CYCLE_COUNT_BASELINE_LOCKED',
|
|
159
205
|
];
|
package/dist/cjs/inventory.js
CHANGED
package/dist/cycleCount.d.ts
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* enum, the operator's filter and the union all derive from ONE list.
|
|
4
4
|
*/
|
|
5
5
|
export declare const CYCLE_COUNT_STATUSES: readonly ["open", "finalized", "cancelled"];
|
|
6
|
+
/** The scopes `POST /cycle-counts { mode: 'preview' | 'start' }` accepts. Anything else is refused 400. */
|
|
7
|
+
export declare const CYCLE_COUNT_SCOPE_TYPES: readonly ["category", "zone"];
|
|
8
|
+
/** Every outcome a scope discovery can end in — see {@link CycleCountScopeDiscovery.outcome}. */
|
|
9
|
+
export declare const CYCLE_COUNT_SCOPE_OUTCOMES: readonly ["ready", "empty", "overCap", "incomplete"];
|
|
10
|
+
/** Why a product matching the scope is NOT a line — see {@link CycleCountScopeExclusion.reason}. */
|
|
11
|
+
export declare const CYCLE_COUNT_SCOPE_EXCLUSION_REASONS: readonly ["MISSING_STOCK", "NON_INTEGER_STOCK", "NEGATIVE_STOCK", "STOCK_OVER_MAX"];
|
|
12
|
+
/** Why a discovery could not prove it saw the whole scope — see {@link CycleCountScopeDiscovery.incompleteReason}. */
|
|
13
|
+
export declare const CYCLE_COUNT_SCOPE_INCOMPLETE_REASONS: readonly ["READ_BUDGET", "TIME_BUDGET", "REPEATED_CURSOR", "UNPROCESSED_READS"];
|
|
6
14
|
declare global {
|
|
7
15
|
/**
|
|
8
16
|
* - `open` — being counted; lines may still be added and revised, and nothing
|
|
@@ -43,6 +51,102 @@ declare global {
|
|
|
43
51
|
* «this count needs an admin», is reporting a designed outcome as a fault.
|
|
44
52
|
*/
|
|
45
53
|
type CycleCountStatus = 'open' | 'finalized' | 'cancelled';
|
|
54
|
+
/**
|
|
55
|
+
* What a SCOPED count covers — one category or one shelf zone, never both.
|
|
56
|
+
*
|
|
57
|
+
* - `category` — every product whose `Product.categoryId` equals `categoryId`.
|
|
58
|
+
* - `zone` — every product whose `Product.zone` equals `zone` EXACTLY: the
|
|
59
|
+
* stored string, case- and whitespace-sensitive, as the app's own zone
|
|
60
|
+
* filter compares it. `Product.zone` is free text with no catalogue, so
|
|
61
|
+
* `GET /cycle-counts?mode=zones` lists the zones the server can see; a zone
|
|
62
|
+
* may also be typed, and a zone matching nothing is `empty`, not an error.
|
|
63
|
+
*
|
|
64
|
+
* ⚠️ A shelf zone is NOT a warehouse. Nothing here reads `Warehouse` or
|
|
65
|
+
* `InventoryLevel`.
|
|
66
|
+
*
|
|
67
|
+
* Eligibility, for both: the product exists, is not `disabled` and is not
|
|
68
|
+
* `isService`. An eligible product whose stock cannot be a baseline is
|
|
69
|
+
* EXCLUDED with a reason ({@link CycleCountScopeExclusion}), never defaulted.
|
|
70
|
+
*/
|
|
71
|
+
type CycleCountScope = {
|
|
72
|
+
type: 'category';
|
|
73
|
+
categoryId: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'zone';
|
|
76
|
+
zone: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* - `ready` — the whole scope was seen and it yields 1 to `lineCap` lines.
|
|
80
|
+
* - `empty` — the whole scope was seen and it yields NO line (nothing matches,
|
|
81
|
+
* or everything that matches is excluded). Distinct from `incomplete`.
|
|
82
|
+
* - `overCap` — more lines than one session can finalise. Narrow the scope;
|
|
83
|
+
* the api never picks a subset.
|
|
84
|
+
* - `incomplete` — the read stopped before it could prove it saw everything.
|
|
85
|
+
* ⚠️ Never a partial `ready`: no count can be started from it.
|
|
86
|
+
*/
|
|
87
|
+
type CycleCountScopeOutcome = 'ready' | 'empty' | 'overCap' | 'incomplete';
|
|
88
|
+
/**
|
|
89
|
+
* - `MISSING_STOCK` — the product row carries no numeric `stock`. ⚠️ Not read as `0`.
|
|
90
|
+
* - `NON_INTEGER_STOCK` — a fractional counter; a count line is a whole number.
|
|
91
|
+
* - `NEGATIVE_STOCK` — an oversold counter; a baseline is non-negative.
|
|
92
|
+
* - `STOCK_OVER_MAX` — above the line quantity bound (1 000 000).
|
|
93
|
+
*/
|
|
94
|
+
type CycleCountScopeExclusionReason = 'MISSING_STOCK' | 'NON_INTEGER_STOCK' | 'NEGATIVE_STOCK' | 'STOCK_OVER_MAX';
|
|
95
|
+
/** One product that matches the scope but is not a line, and why. */
|
|
96
|
+
interface CycleCountScopeExclusion {
|
|
97
|
+
productId: string;
|
|
98
|
+
name?: string;
|
|
99
|
+
sku?: string;
|
|
100
|
+
reason: CycleCountScopeExclusionReason;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* - `READ_BUDGET` — more pages than one request may read.
|
|
104
|
+
* - `TIME_BUDGET` — the request ran out of time before the last page.
|
|
105
|
+
* - `REPEATED_CURSOR` — the store handed back a cursor it had already given.
|
|
106
|
+
* - `UNPROCESSED_READS` — some product rows could not be read after retries.
|
|
107
|
+
*/
|
|
108
|
+
type CycleCountScopeIncompleteReason = 'READ_BUDGET' | 'TIME_BUDGET' | 'REPEATED_CURSOR' | 'UNPROCESSED_READS';
|
|
109
|
+
/**
|
|
110
|
+
* What the server found for one scope — the body of `mode: 'preview'`, and the
|
|
111
|
+
* `data` of every scope refusal from `mode: 'start'`.
|
|
112
|
+
*
|
|
113
|
+
* ⚠️ **`items[].systemQuantity` is the SERVER's baseline**: `Product.stock`,
|
|
114
|
+
* the counter finalise adjusts, read strongly consistent from the product row
|
|
115
|
+
* during this request. It is a per-product read, NOT a same-instant snapshot
|
|
116
|
+
* across products: each figure is current at the moment its row was read,
|
|
117
|
+
* between `captureStartedAt` and `capturedAt`. A preview's figures are
|
|
118
|
+
* informational — `mode: 'start'` reads again and stores its own.
|
|
119
|
+
*/
|
|
120
|
+
interface CycleCountScopeDiscovery {
|
|
121
|
+
scope: CycleCountScope;
|
|
122
|
+
outcome: CycleCountScopeOutcome;
|
|
123
|
+
/** Lines in `productId` order, `countedQuantity: 0`. Present on `ready`, and on `overCap` as far as was read. */
|
|
124
|
+
items: CycleCountItem[];
|
|
125
|
+
/** Matching products that are not lines. Never counted against `lineCap`. */
|
|
126
|
+
excluded: CycleCountScopeExclusion[];
|
|
127
|
+
/** `items.length`, or a LOWER bound when `countIsLowerBound`. */
|
|
128
|
+
lineCount: number;
|
|
129
|
+
/** Set on `overCap` when the read stopped at the candidate budget — at least `lineCount`, maybe more. */
|
|
130
|
+
countIsLowerBound?: boolean;
|
|
131
|
+
/** The per-session line cap (49 today), so a consumer states it rather than restating it. */
|
|
132
|
+
lineCap: number;
|
|
133
|
+
/** Set only on `incomplete`. */
|
|
134
|
+
incompleteReason?: CycleCountScopeIncompleteReason;
|
|
135
|
+
/** Unix ms the first product row was read. */
|
|
136
|
+
captureStartedAt: number;
|
|
137
|
+
/** Unix ms the last product row was read. */
|
|
138
|
+
capturedAt: number;
|
|
139
|
+
}
|
|
140
|
+
/** `GET /cycle-counts?mode=zones` — every distinct `Product.zone` on an eligible product, with its product count. */
|
|
141
|
+
interface CycleCountZoneList {
|
|
142
|
+
zones: {
|
|
143
|
+
zone: string;
|
|
144
|
+
productCount: number;
|
|
145
|
+
}[];
|
|
146
|
+
/** `false` when the walk stopped early; `zones` is then what was seen, and a missing zone may still be typed. */
|
|
147
|
+
complete: boolean;
|
|
148
|
+
incompleteReason?: CycleCountScopeIncompleteReason;
|
|
149
|
+
}
|
|
46
150
|
/**
|
|
47
151
|
* A physical count session that the SERVER owns — an id, a stored line set,
|
|
48
152
|
* and a read path. It exists because a stocktake has been a purely
|
|
@@ -124,6 +228,33 @@ declare global {
|
|
|
124
228
|
* not evidence that the zone was counted completely.
|
|
125
229
|
*/
|
|
126
230
|
zone?: string;
|
|
231
|
+
/**
|
|
232
|
+
* The scope a `mode: 'start'` session was opened from. ABSENT on a session
|
|
233
|
+
* opened by a bare `POST` (client-supplied lines), and on every session
|
|
234
|
+
* written before scoped starts existed — nothing backfills it.
|
|
235
|
+
*
|
|
236
|
+
* Unlike `zone` above, this IS a statement of completeness at start: every
|
|
237
|
+
* eligible product the server found in the scope is a line, and every
|
|
238
|
+
* product it found but could not baseline is in `scopeExcluded`.
|
|
239
|
+
*/
|
|
240
|
+
scope?: CycleCountScope;
|
|
241
|
+
/**
|
|
242
|
+
* `'server'` when every line's `systemQuantity` was read by the api at
|
|
243
|
+
* start. ABSENT means the baseline was supplied by the client (the bare
|
|
244
|
+
* `POST`), as every session before this field existed.
|
|
245
|
+
*
|
|
246
|
+
* ⚠️ A `'server'` session's baseline is LOCKED: `mode: 'edit'` refuses
|
|
247
|
+
* `409 CYCLE_COUNT_BASELINE_LOCKED` when a line's `systemQuantity` differs
|
|
248
|
+
* from `baseline`, a line names a product outside it, or a product in it
|
|
249
|
+
* loses every line. Nothing re-reads `Product.stock` into it later.
|
|
250
|
+
*/
|
|
251
|
+
baselineSource?: 'server';
|
|
252
|
+
/** `productId` → the `systemQuantity` captured at start. Only with `baselineSource`. Never rewritten. */
|
|
253
|
+
baseline?: Record<string, number>;
|
|
254
|
+
/** Unix ms the last baseline read completed. Only with `baselineSource`. */
|
|
255
|
+
baselineCapturedAt?: number;
|
|
256
|
+
/** Products the scope matched but could not baseline, as found at start. Only with `scope`. */
|
|
257
|
+
scopeExcluded?: CycleCountScopeExclusion[];
|
|
127
258
|
/**
|
|
128
259
|
* Variance threshold for THIS session's finalise, in PERCENT — set at
|
|
129
260
|
* create/edit time. ⚠️ It can only TIGHTEN the store's threshold, never
|
|
@@ -420,6 +551,20 @@ export declare const isOverCycleCountToleranceRule: (input: {
|
|
|
420
551
|
* senders (this one is Spanish, `_postStockAdjust.ts`'s is not), so a consumer
|
|
421
552
|
* must render its own copy off the CODE and never relay the api's prose.
|
|
422
553
|
*
|
|
554
|
+
* Scoped start and the locked baseline:
|
|
555
|
+
*
|
|
556
|
+
* - `CYCLE_COUNT_SCOPE_EMPTY` · 422 — the whole scope was read and yields no line.
|
|
557
|
+
* - `CYCLE_COUNT_SCOPE_OVER_CAP` · 422 — more lines than one session can finalise.
|
|
558
|
+
* - `CYCLE_COUNT_SCOPE_INCOMPLETE` · 422 — the read could not prove it saw everything.
|
|
559
|
+
* - `CYCLE_COUNT_SCOPE_CHANGED` · 409 — `expectedProductIds` no longer matches
|
|
560
|
+
* what the scope yields; `data` is the fresh discovery to show and confirm.
|
|
561
|
+
* - `CYCLE_COUNT_START_KEY_REQUIRED` · 400 — `mode: 'start'` sent without an
|
|
562
|
+
* `Idempotency-Key` header. ⚠️ The header's own refusals
|
|
563
|
+
* (`INVALID_IDEMPOTENCY_KEY`, the fingerprint mismatch, the lock contention)
|
|
564
|
+
* come from the shared idempotency wrapper and are not cycle-count codes.
|
|
565
|
+
* - `CYCLE_COUNT_BASELINE_LOCKED` · 409 — an edit that would change, drop or
|
|
566
|
+
* extend a server-captured baseline.
|
|
567
|
+
*
|
|
423
568
|
* ⚠️ `UNHANDLED_ERROR` is deliberately NOT here, matching
|
|
424
569
|
* {@link PRESUPUESTO_ERROR_CODES}: it is `tryCatch`'s generic envelope for an
|
|
425
570
|
* unexpected THROW and belongs to no endpoint. ⚠️ It answers **400, not 500**, by
|
|
@@ -430,5 +575,5 @@ export declare const isOverCycleCountToleranceRule: (input: {
|
|
|
430
575
|
* ⚠️ Cross-cutting refusals are NOT repeated here — check `GATING_ERROR_CODES`
|
|
431
576
|
* as well.
|
|
432
577
|
*/
|
|
433
|
-
export declare const CYCLE_COUNT_ERROR_CODES: readonly ["CYCLE_COUNT_NOT_FOUND", "CYCLE_COUNT_NOT_OPEN", "CYCLE_COUNT_ILLEGAL_TRANSITION", "CYCLE_COUNT_VERSION_CONFLICT", "CYCLE_COUNT_CONTENT_CONFLICT", "CYCLE_COUNT_TOLERANCE_EXCEEDED", "CYCLE_COUNT_ID_UNUSABLE", "ROLE_FORBIDDEN", "VALIDATION_FAILED", "INVALID_CURSOR", "PRODUCT_NOT_FOUND", "STOCK_ADJUSTMENT_RACED"];
|
|
578
|
+
export declare const CYCLE_COUNT_ERROR_CODES: readonly ["CYCLE_COUNT_NOT_FOUND", "CYCLE_COUNT_NOT_OPEN", "CYCLE_COUNT_ILLEGAL_TRANSITION", "CYCLE_COUNT_VERSION_CONFLICT", "CYCLE_COUNT_CONTENT_CONFLICT", "CYCLE_COUNT_TOLERANCE_EXCEEDED", "CYCLE_COUNT_ID_UNUSABLE", "ROLE_FORBIDDEN", "VALIDATION_FAILED", "INVALID_CURSOR", "PRODUCT_NOT_FOUND", "STOCK_ADJUSTMENT_RACED", "CYCLE_COUNT_SCOPE_EMPTY", "CYCLE_COUNT_SCOPE_OVER_CAP", "CYCLE_COUNT_SCOPE_INCOMPLETE", "CYCLE_COUNT_SCOPE_CHANGED", "CYCLE_COUNT_START_KEY_REQUIRED", "CYCLE_COUNT_BASELINE_LOCKED"];
|
|
434
579
|
export type CycleCountErrorCode = (typeof CYCLE_COUNT_ERROR_CODES)[number];
|
package/dist/cycleCount.js
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
* enum, the operator's filter and the union all derive from ONE list.
|
|
4
4
|
*/
|
|
5
5
|
export const CYCLE_COUNT_STATUSES = ['open', 'finalized', 'cancelled'];
|
|
6
|
+
/** The scopes `POST /cycle-counts { mode: 'preview' | 'start' }` accepts. Anything else is refused 400. */
|
|
7
|
+
export const CYCLE_COUNT_SCOPE_TYPES = ['category', 'zone'];
|
|
8
|
+
/** Every outcome a scope discovery can end in — see {@link CycleCountScopeDiscovery.outcome}. */
|
|
9
|
+
export const CYCLE_COUNT_SCOPE_OUTCOMES = [
|
|
10
|
+
'ready',
|
|
11
|
+
'empty',
|
|
12
|
+
'overCap',
|
|
13
|
+
'incomplete',
|
|
14
|
+
];
|
|
15
|
+
/** Why a product matching the scope is NOT a line — see {@link CycleCountScopeExclusion.reason}. */
|
|
16
|
+
export const CYCLE_COUNT_SCOPE_EXCLUSION_REASONS = [
|
|
17
|
+
'MISSING_STOCK',
|
|
18
|
+
'NON_INTEGER_STOCK',
|
|
19
|
+
'NEGATIVE_STOCK',
|
|
20
|
+
'STOCK_OVER_MAX',
|
|
21
|
+
];
|
|
22
|
+
/** Why a discovery could not prove it saw the whole scope — see {@link CycleCountScopeDiscovery.incompleteReason}. */
|
|
23
|
+
export const CYCLE_COUNT_SCOPE_INCOMPLETE_REASONS = [
|
|
24
|
+
'READ_BUDGET',
|
|
25
|
+
'TIME_BUDGET',
|
|
26
|
+
'REPEATED_CURSOR',
|
|
27
|
+
'UNPROCESSED_READS',
|
|
28
|
+
];
|
|
6
29
|
/**
|
|
7
30
|
* The tolerance rule itself, as ONE implementation both sides import.
|
|
8
31
|
*
|
|
@@ -122,6 +145,20 @@ export const isOverCycleCountToleranceRule = (input, tolerancePercent) => {
|
|
|
122
145
|
* senders (this one is Spanish, `_postStockAdjust.ts`'s is not), so a consumer
|
|
123
146
|
* must render its own copy off the CODE and never relay the api's prose.
|
|
124
147
|
*
|
|
148
|
+
* Scoped start and the locked baseline:
|
|
149
|
+
*
|
|
150
|
+
* - `CYCLE_COUNT_SCOPE_EMPTY` · 422 — the whole scope was read and yields no line.
|
|
151
|
+
* - `CYCLE_COUNT_SCOPE_OVER_CAP` · 422 — more lines than one session can finalise.
|
|
152
|
+
* - `CYCLE_COUNT_SCOPE_INCOMPLETE` · 422 — the read could not prove it saw everything.
|
|
153
|
+
* - `CYCLE_COUNT_SCOPE_CHANGED` · 409 — `expectedProductIds` no longer matches
|
|
154
|
+
* what the scope yields; `data` is the fresh discovery to show and confirm.
|
|
155
|
+
* - `CYCLE_COUNT_START_KEY_REQUIRED` · 400 — `mode: 'start'` sent without an
|
|
156
|
+
* `Idempotency-Key` header. ⚠️ The header's own refusals
|
|
157
|
+
* (`INVALID_IDEMPOTENCY_KEY`, the fingerprint mismatch, the lock contention)
|
|
158
|
+
* come from the shared idempotency wrapper and are not cycle-count codes.
|
|
159
|
+
* - `CYCLE_COUNT_BASELINE_LOCKED` · 409 — an edit that would change, drop or
|
|
160
|
+
* extend a server-captured baseline.
|
|
161
|
+
*
|
|
125
162
|
* ⚠️ `UNHANDLED_ERROR` is deliberately NOT here, matching
|
|
126
163
|
* {@link PRESUPUESTO_ERROR_CODES}: it is `tryCatch`'s generic envelope for an
|
|
127
164
|
* unexpected THROW and belongs to no endpoint. ⚠️ It answers **400, not 500**, by
|
|
@@ -151,4 +188,13 @@ export const CYCLE_COUNT_ERROR_CODES = [
|
|
|
151
188
|
'INVALID_CURSOR',
|
|
152
189
|
'PRODUCT_NOT_FOUND',
|
|
153
190
|
'STOCK_ADJUSTMENT_RACED',
|
|
191
|
+
// Scoped start (`mode: 'start'`) — `data` is the `CycleCountScopeDiscovery`
|
|
192
|
+
// on the four scope refusals, and NO session was created by any of them.
|
|
193
|
+
'CYCLE_COUNT_SCOPE_EMPTY',
|
|
194
|
+
'CYCLE_COUNT_SCOPE_OVER_CAP',
|
|
195
|
+
'CYCLE_COUNT_SCOPE_INCOMPLETE',
|
|
196
|
+
'CYCLE_COUNT_SCOPE_CHANGED',
|
|
197
|
+
'CYCLE_COUNT_START_KEY_REQUIRED',
|
|
198
|
+
// `mode: 'edit'` on a `baselineSource: 'server'` session.
|
|
199
|
+
'CYCLE_COUNT_BASELINE_LOCKED',
|
|
154
200
|
];
|
package/dist/inventory.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* move `InventoryLevel.reserved`, not `onHand`, so a naive `Σ quantity` over a
|
|
8
8
|
* product's partition double-counts every hold. See `StockMovementType`.
|
|
9
9
|
*/
|
|
10
|
-
export declare const STOCK_MOVEMENT_TYPES: readonly ["receipt", "sale", "transfer_in", "transfer_out", "adjustment", "return", "reservation", "release", "write_off", "lot_consumption"];
|
|
10
|
+
export declare const STOCK_MOVEMENT_TYPES: readonly ["receipt", "sale", "sale_unguarded", "transfer_in", "transfer_out", "adjustment", "return", "reservation", "release", "write_off", "lot_consumption"];
|
|
11
11
|
/**
|
|
12
12
|
* Why an operator moved stock by hand. Runtime value for the same
|
|
13
13
|
* one-list-not-three reason as `STOCK_MOVEMENT_TYPES`.
|
|
@@ -55,18 +55,19 @@ declare global {
|
|
|
55
55
|
* balance, cannot receive a transfer and is not addressable. A consumer that
|
|
56
56
|
* treats the two as interchangeable will attribute stock to a string.
|
|
57
57
|
*
|
|
58
|
-
* ⚠️ **
|
|
59
|
-
* the
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
58
|
+
* ⚠️ **Until a store is cut over, the per-location book does not converge on
|
|
59
|
+
* the store-wide one.** `Product.stock` is the store-wide scalar the order,
|
|
60
|
+
* sale and marketplace paths bump, alongside the store-wide income and sale
|
|
61
|
+
* ledgers those same paths append to. A store's `InventoryLevel` rows start at
|
|
62
|
+
* ZERO and, today, move only for the explicit inventory operations an operator
|
|
63
|
+
* runs — receipts, adjustments, write-offs, transfers, reservations and
|
|
64
|
+
* releases — so `Σ InventoryLevel.onHand` is not `Product.stock` and nothing
|
|
65
|
+
* reconciles the two. The api's ADR-0001 (`docs/DECISIONS.md`) makes the level
|
|
66
|
+
* the stock truth: behind the per-store `Store.stockAuthority` switch, each
|
|
67
|
+
* trading path moves over to updating the level in the same transaction as
|
|
68
|
+
* `Product.stock`, and a one-off seed at cutover puts the gap in the primary
|
|
69
|
+
* depósito. From then on `Product.stock = Σ onHand + units on open transfers`.
|
|
70
|
+
* Before it, the gap is expected and is not drift.
|
|
70
71
|
*
|
|
71
72
|
* ⚠️ A consumer must not present a per-warehouse figure it cannot compute from
|
|
72
73
|
* the level rows themselves, and — more important now, not less — must not
|
|
@@ -320,36 +321,41 @@ declare global {
|
|
|
320
321
|
* — a deploy can follow a merge at any time, and nothing warns you that the
|
|
321
322
|
* first row has landed.
|
|
322
323
|
*
|
|
323
|
-
* ⚠️ **This is a SECOND stock ledger,
|
|
324
|
-
*
|
|
325
|
-
* `
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* a
|
|
324
|
+
* ⚠️ **This is a SECOND stock ledger, beside the store-wide one.** The platform
|
|
325
|
+
* already ships one — the store-wide `INCOME#` / `SALE#` partitions behind
|
|
326
|
+
* `StockIncome` / `StockSale`, where on-hand is `Σ INCOME − Σ SALE`,
|
|
327
|
+
* quantities are unsigned and the sign comes from the partition. This ledger is
|
|
328
|
+
* per-LOCATION, single-partition and signed, and the two do not agree on any of
|
|
329
|
+
* those three things; a report that shows both reconciles them itself.
|
|
330
|
+
*
|
|
331
|
+
* ⚠️ **The level rows are becoming the stock truth (the api's ADR-0001,
|
|
332
|
+
* `docs/DECISIONS.md`), and the writer rule changed with it.** Today, rows here
|
|
333
|
+
* still come only from the explicit inventory operations — operator receipts,
|
|
334
|
+
* adjustments, write-offs, transfers, reservations and releases — and the
|
|
335
|
+
* order, sale and marketplace paths still write only the store-wide pair. As
|
|
336
|
+
* each trading path is moved over, behind the per-store `Store.stockAuthority`
|
|
337
|
+
* switch, it updates the LEVEL in the SAME transaction as `Product.stock`, and
|
|
338
|
+
* its own `SALE#` / `INCOME#` row (stamped with `warehouseId`) is the movement
|
|
339
|
+
* record for that depósito. So the rule to hold on to is now:
|
|
340
|
+
*
|
|
341
|
+
* - a trading path writes the level and the store total in ONE transaction,
|
|
342
|
+
* never in two calls — a level that moved without its total, or the
|
|
343
|
+
* reverse, is the divergence this model exists to remove;
|
|
344
|
+
* - a trading path does NOT also append a row HERE for the same units. Its
|
|
345
|
+
* ledger row already records the movement, and because these rows are
|
|
346
|
+
* immutable a duplicate is only removable by a compensating row somebody
|
|
347
|
+
* has to notice is owed.
|
|
348
|
+
*
|
|
349
|
+
* ⚠️ **Until a store's cutover, its two on-hand figures still differ, and
|
|
350
|
+
* NEITHER is the wrong one.** A store with `stockAuthority` absent or
|
|
351
|
+
* `'store'` has level rows that only the explicit operations moved, so
|
|
352
|
+
* `Σ onHand` is not `Product.stock` and the difference must not be rendered as
|
|
353
|
+
* shrinkage or a variance. After cutover the invariant is
|
|
354
|
+
* `Product.stock = Σ onHand (every depósito) + units on open transfers`. Nothing
|
|
355
|
+
* sizes the pre-cutover gap: `products?mode=stock-reconciliation` compares
|
|
356
|
+
* `Product.stock` against the store-wide ledger and never reads this one, so a
|
|
357
|
+
* per-location screen wired to it is showing store-wide drift under a
|
|
358
|
+
* per-warehouse caption.
|
|
353
359
|
*
|
|
354
360
|
* ⚠️ **Immutable. A row is never updated and never deleted.** A movement that
|
|
355
361
|
* was wrong is corrected by a compensating movement, which is what makes the
|
|
@@ -420,8 +426,9 @@ declare global {
|
|
|
420
426
|
*
|
|
421
427
|
* ⚠️ **The opposite convention to the shipped store-wide ledger**, where
|
|
422
428
|
* quantities are always positive and the partition supplies the sign. The two
|
|
423
|
-
* ledgers
|
|
424
|
-
*
|
|
429
|
+
* ledgers keep running side by side (the store-wide one stays, and gains
|
|
430
|
+
* `warehouseId`), so this is a live read-time hazard rather than a one-off
|
|
431
|
+
* migration one: anything that copies or compares
|
|
425
432
|
* quantities across them without applying the sign inverts every outflow, and
|
|
426
433
|
* the result still totals to a plausible-looking number.
|
|
427
434
|
*
|
|
@@ -561,13 +568,23 @@ declare global {
|
|
|
561
568
|
* loss and correction, and the closest member (`other`) would say less than
|
|
562
569
|
* the type already does.
|
|
563
570
|
*
|
|
571
|
+
* - `sale_unguarded` — the same outflow as `sale`, WITHOUT the availability
|
|
572
|
+
* guard. It exists for a store with `config.stock` off, where a sale is never
|
|
573
|
+
* refused for stock and the depósito level may go negative. `sale` keeps its
|
|
574
|
+
* guarded meaning for strict stores. It is a separate type rather than a
|
|
575
|
+
* per-call override because a "force" flag on a guarded type is
|
|
576
|
+
* indistinguishable, at the call site, from not wanting the guard at all.
|
|
577
|
+
* Nothing writes it yet.
|
|
578
|
+
*
|
|
564
579
|
* ⚠️ **`sale` and `return` are vocabulary this ledger ACCEPTS, not traffic it
|
|
565
|
-
* receives.** The order, sale and marketplace paths
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
580
|
+
* receives from the trading paths.** The order, sale and marketplace paths
|
|
581
|
+
* record their movement on the store-wide income and sale ledgers — once a
|
|
582
|
+
* store is cut over they also move the LEVEL in the same transaction, but they
|
|
583
|
+
* still append nothing here (see `StockMovement`). A row of either type exists
|
|
584
|
+
* here only because an explicit inventory operation booked one, so a
|
|
585
|
+
* per-warehouse sales report built on this ledger reads zero for every
|
|
586
|
+
* location of a store that is selling all day, and the zero is not a bug to
|
|
587
|
+
* chase. Per-depósito sales come from `SALE#` rows' `warehouseId`.
|
|
571
588
|
*
|
|
572
589
|
* ⚠️ **`reservation` and `release` do NOT touch `onHand`.** They move
|
|
573
590
|
* `reserved`, and the units are still physically present the whole time. This
|
|
@@ -583,7 +600,7 @@ declare global {
|
|
|
583
600
|
* REMOVING one is not — rows carrying it are permanent and this platform never
|
|
584
601
|
* backfills.
|
|
585
602
|
*/
|
|
586
|
-
type StockMovementType = 'receipt' | 'sale' | 'transfer_in' | 'transfer_out' | 'adjustment' | 'return' | 'reservation' | 'release' | 'write_off' | 'lot_consumption';
|
|
603
|
+
type StockMovementType = 'receipt' | 'sale' | 'sale_unguarded' | 'transfer_in' | 'transfer_out' | 'adjustment' | 'return' | 'reservation' | 'release' | 'write_off' | 'lot_consumption';
|
|
587
604
|
/**
|
|
588
605
|
* Why an operator adjusted or wrote off stock. Set only on `adjustment` and
|
|
589
606
|
* `write_off` movements; a `sale` or a `receipt` has a reference, not a
|
package/dist/inventory.js
CHANGED
package/dist/lot.d.ts
CHANGED
|
@@ -196,11 +196,12 @@ declare global {
|
|
|
196
196
|
* ⚠️ **Its relationship to `Product.stock` is NONE, and nothing reconciles
|
|
197
197
|
* them.** `Product.stock` is the store-wide scalar the order, sale and
|
|
198
198
|
* marketplace paths move; the `MOV#` ledger this figure is summed from is
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
199
|
+
* written only by explicit inventory operations — trading paths, even once
|
|
200
|
+
* a store's levels become the stock truth, record their movement on the
|
|
201
|
+
* store-wide ledger and never here (see `Warehouse`). Sales never consume
|
|
202
|
+
* a lot, so `Σ remaining` over a product's lots is not `Product.stock`, is
|
|
203
|
+
* not converging on it, and a screen that subtracts one from the other
|
|
204
|
+
* shows an operator a shortfall with no cause. Nothing structurally forces an outflow to carry
|
|
204
205
|
* a `lotId` either, so a lot total exceeding on-hand means un-stamped
|
|
205
206
|
* movements, never data loss.
|
|
206
207
|
*
|
package/dist/order.d.ts
CHANGED
|
@@ -156,6 +156,18 @@ declare global {
|
|
|
156
156
|
* addresses nothing for the whole legacy population.
|
|
157
157
|
*/
|
|
158
158
|
saleTs?: number;
|
|
159
|
+
/**
|
|
160
|
+
* The depósito (`Warehouse.warehouseId`) this line's units leave from.
|
|
161
|
+
*
|
|
162
|
+
* ⚠️ **Resolved ONCE, at creation, and never re-resolved** (the api's
|
|
163
|
+
* ADR-0001). An edit, cancel or return moves stock back into the depósito
|
|
164
|
+
* named here, not into whatever the resolution ladder would pick today.
|
|
165
|
+
*
|
|
166
|
+
* ⚠️ OPTIONAL PERMANENTLY. Nothing writes it yet; absent means a line
|
|
167
|
+
* written before depósito-aware sales, whose stock only the store total
|
|
168
|
+
* ever recorded.
|
|
169
|
+
*/
|
|
170
|
+
warehouseId?: string;
|
|
159
171
|
}
|
|
160
172
|
interface Order {
|
|
161
173
|
storeId: string;
|
|
@@ -66,6 +66,14 @@ declare global {
|
|
|
66
66
|
createdAt: number;
|
|
67
67
|
/** The operator who booked it. */
|
|
68
68
|
userId: string;
|
|
69
|
+
/**
|
|
70
|
+
* The depósito the whole delivery was received into. Every `INCOME#` row
|
|
71
|
+
* the receipt wrote carries the same value.
|
|
72
|
+
*
|
|
73
|
+
* ⚠️ OPTIONAL PERMANENTLY. Nothing writes it yet; absent means a receipt
|
|
74
|
+
* that moved only the store total.
|
|
75
|
+
*/
|
|
76
|
+
warehouseId?: string;
|
|
69
77
|
/** Operator note. ⚠️ Never personal data — this row is not scrubbed and has no TTL. */
|
|
70
78
|
notes?: string;
|
|
71
79
|
items: PurchaseReceiptItem[];
|
package/dist/stock.d.ts
CHANGED
|
@@ -79,6 +79,17 @@ declare global {
|
|
|
79
79
|
*/
|
|
80
80
|
interface StoredStockBase {
|
|
81
81
|
createdAt: number;
|
|
82
|
+
/**
|
|
83
|
+
* The depósito (`Warehouse.warehouseId`) this movement added units to or
|
|
84
|
+
* took them from. On a trading path this row IS the depósito movement:
|
|
85
|
+
* the level moves in the same transaction and no `MOV#` row is written
|
|
86
|
+
* for the same units (the api's ADR-0001).
|
|
87
|
+
*
|
|
88
|
+
* ⚠️ OPTIONAL PERMANENTLY. Nothing writes it yet, and rows written before
|
|
89
|
+
* it never carry one — absent means "store-wide only", never "the
|
|
90
|
+
* primary depósito".
|
|
91
|
+
*/
|
|
92
|
+
warehouseId?: string;
|
|
82
93
|
/**
|
|
83
94
|
* Unit cost this movement is valued at.
|
|
84
95
|
*
|
package/dist/store.d.ts
CHANGED
|
@@ -71,6 +71,18 @@ declare global {
|
|
|
71
71
|
/** Unix ms of soft delete; absent means active. */
|
|
72
72
|
disabledAt?: number;
|
|
73
73
|
}
|
|
74
|
+
/** See `Store.stockAuthority`. */
|
|
75
|
+
type StockAuthority = 'store' | 'depositos';
|
|
76
|
+
/**
|
|
77
|
+
* Per-channel depósito for sales that name none. Each value is a
|
|
78
|
+
* `Warehouse.warehouseId`; see `Store.config.channelWarehouses`.
|
|
79
|
+
*/
|
|
80
|
+
interface StoreChannelWarehouses {
|
|
81
|
+
/** Storefront checkout orders. */
|
|
82
|
+
online?: string;
|
|
83
|
+
/** MercadoLibre orders. */
|
|
84
|
+
mercadolibre?: string;
|
|
85
|
+
}
|
|
74
86
|
interface Ecommerce {
|
|
75
87
|
isActive?: boolean;
|
|
76
88
|
config?: {
|
|
@@ -692,6 +704,15 @@ declare global {
|
|
|
692
704
|
*/
|
|
693
705
|
graceDays: number;
|
|
694
706
|
};
|
|
707
|
+
/**
|
|
708
|
+
* Which depósito each sales channel takes stock from — the third rung of
|
|
709
|
+
* the sale depósito ladder (the api's ADR-0001), after the request and
|
|
710
|
+
* the operator's `User.defaultWarehouseId`, before the primary.
|
|
711
|
+
*
|
|
712
|
+
* Nothing writes or reads it yet. Absent, or a channel absent inside it,
|
|
713
|
+
* means that channel's sales use the primary depósito.
|
|
714
|
+
*/
|
|
715
|
+
channelWarehouses?: StoreChannelWarehouses;
|
|
695
716
|
};
|
|
696
717
|
ecommerce?: Ecommerce;
|
|
697
718
|
photoURL: string;
|
|
@@ -737,6 +758,22 @@ declare global {
|
|
|
737
758
|
ivaTypes: Method[];
|
|
738
759
|
globals?: StoreGlobals;
|
|
739
760
|
maintenance?: MaintenanceInfo;
|
|
761
|
+
/**
|
|
762
|
+
* Which book is the stock truth for this store (the api's ADR-0001).
|
|
763
|
+
*
|
|
764
|
+
* - `'store'` — today's model: trading paths move `Product.stock` and the
|
|
765
|
+
* store-wide ledger only; depósito levels move only for explicit
|
|
766
|
+
* inventory operations.
|
|
767
|
+
* - `'depositos'` — the depósito level is the truth. Every trading path
|
|
768
|
+
* moves the level in the same transaction as `Product.stock`, which
|
|
769
|
+
* stays as the cached store total.
|
|
770
|
+
*
|
|
771
|
+
* ⚠️ Absent means `'store'`. Operator-owned: no request body sets it, and
|
|
772
|
+
* nothing writes or reads it yet — the cutover that flips it also seeds
|
|
773
|
+
* the store's existing gap into its primary depósito. Rollback is
|
|
774
|
+
* flipping it back; the store total is correct either way.
|
|
775
|
+
*/
|
|
776
|
+
stockAuthority?: StockAuthority;
|
|
740
777
|
afipCertAlert?: {
|
|
741
778
|
expiry: number;
|
|
742
779
|
band: 'expired' | '14' | '30' | '60';
|
package/dist/user.d.ts
CHANGED
|
@@ -103,6 +103,17 @@ declare global {
|
|
|
103
103
|
*/
|
|
104
104
|
notificationSound?: boolean;
|
|
105
105
|
permissions?: UserPermissions;
|
|
106
|
+
/**
|
|
107
|
+
* The depósito (`Warehouse.warehouseId`) this operator's sales take stock
|
|
108
|
+
* from when the request names none — the second rung of the sale
|
|
109
|
+
* depósito ladder (the api's ADR-0001), after the request and before the
|
|
110
|
+
* channel setting and the primary.
|
|
111
|
+
*
|
|
112
|
+
* Nothing writes or reads it yet. Absent means "fall through to the next
|
|
113
|
+
* rung", and a value naming a deactivated or deleted depósito falls
|
|
114
|
+
* through the same way rather than refusing the sale.
|
|
115
|
+
*/
|
|
116
|
+
defaultWarehouseId?: string;
|
|
106
117
|
emailVerified?: boolean;
|
|
107
118
|
emailVerifiedAt?: number;
|
|
108
119
|
totp?: UserTotp;
|