sinfactura-types 1.10.293 → 1.10.294

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.
@@ -26,12 +26,21 @@ declare global {
26
26
  * its premise; the premise does not survive a grep, and a reader who checks it
27
27
  * and finds it wrong has no way to tell which half to keep.
28
28
  *
29
- * ⚠️ **The api cannot yet REACH `finalized`.** The session entity, its CRUD and
30
- * the `open`/`cancelled` edges ship first; applying the variances is a separate
31
- * change. Every consumer must therefore treat `finalized` as a state it will
32
- * read one day and cannot cause today — the published union is deliberately
33
- * ahead of the write path, exactly as `stocktakeId` was published ahead of this
34
- * entity.
29
+ * ⚠️ **Reaching `finalized` is ONE call, and it can be REFUSED.**
30
+ * `POST /cycle-counts { mode: 'finalize', cycleCountId }` applies the session's
31
+ * variances to stock and moves the row `open → finalized` in a single
32
+ * transaction, so no consumer ever reads a half-applied session; a replay
33
+ * against a session that is already `finalized` answers `200` with the stored
34
+ * row and writes nothing a second time.
35
+ *
36
+ * ⚠️ **The refusal is the part the union cannot show you.** When any line's
37
+ * variance is over the effective tolerance the call answers
38
+ * `403 CYCLE_COUNT_TOLERANCE_EXCEEDED` unless the caller holds ADMIN or
39
+ * MANAGER, and the session stays `open` with nothing written — the variance is
40
+ * still there to be re-counted or escalated. The ladder that decides «over» is
41
+ * stated once, on `CycleCount.tolerancePercent` below. A consumer that offers
42
+ * finalise to every role and renders that 403 as a failure, rather than as
43
+ * «this count needs an admin», is reporting a designed outcome as a fault.
35
44
  */
36
45
  type CycleCountStatus = 'open' | 'finalized' | 'cancelled';
37
46
  /**
@@ -89,6 +98,91 @@ declare global {
89
98
  * not evidence that the zone was counted completely.
90
99
  */
91
100
  zone?: string;
101
+ /**
102
+ * Variance threshold for THIS session's finalise, in PERCENT — set at
103
+ * create/edit time, and the top rung of the resolution ladder.
104
+ *
105
+ * **The ladder, stated once and only here:** this session's own
106
+ * `tolerancePercent` wins; absent, `Store.config.cycleCounts.tolerancePercent`
107
+ * (`./store.ts`); absent as well, the api's built-in default — whose VALUE
108
+ * is stated once, on `Store.config.cycleCounts.tolerancePercent`, and lives
109
+ * in `DEFAULT_CYCLE_COUNT_TOLERANCE_PERCENT`
110
+ * (`stacks/services/cycleCounts.ts`). Every
111
+ * other mention of the threshold points at this docblock instead of
112
+ * repeating the order, because two copies of a resolution order drift and
113
+ * nothing compares them.
114
+ *
115
+ * ⚠️ **Tested PER LINE, and one line is enough.** The threshold is compared
116
+ * against each `items[]` entry's own variance; a session is over it when
117
+ * ANY single line is, never against a session-wide average or a summed
118
+ * ratio. An averaging consumer will show «within tolerance» for a session
119
+ * the api refuses, because one wild line disappears into a hundred exact
120
+ * ones. Strictly `>`: a variance exactly equal to the threshold is WITHIN
121
+ * it.
122
+ *
123
+ * ⚠️ **A percent, not a fraction.** `10` is ten percent. A writer who sends
124
+ * `0.10` meaning «10 %» builds a threshold a hundred times too tight, and
125
+ * every count then needs an ADMIN or MANAGER to finalise — a permission
126
+ * failure that reads as a role bug and is a units bug. Range 0–100.
127
+ *
128
+ * ⚠️ **Absent is not zero tolerance.** Absent means «fall through to the
129
+ * next rung», never «no variance permitted». A consumer that defaults this
130
+ * to `0` before sending it PINS the session at zero and silently removes
131
+ * the store's own setting from the ladder — send the field only when the
132
+ * operator chose a number FOR THIS COUNT, and omit it otherwise.
133
+ *
134
+ * ⚠️ **Measured against `CycleCountItem.systemQuantity`** — the stored
135
+ * snapshot of `Product.stock`, the counter — never against
136
+ * `Σ INCOME − Σ SALE`. The derivation is on `systemQuantity` itself below
137
+ * and is not repeated here; the short of it is that a threshold has to be
138
+ * tested in the same representation the finalise write lands on, or it
139
+ * admits and refuses lines by an on-hand figure the adjustment never
140
+ * touches.
141
+ *
142
+ * ⚠️ **BOTH halves must clear, and the absolute floor is tested FIRST.** A
143
+ * line is over-tolerance only when its delta reaches
144
+ * `CYCLE_COUNT_TOLERANCE_MIN_UNITS` (`stacks/services/cycleCounts.ts`)
145
+ * AND its percentage exceeds the threshold. The floor exists because on a
146
+ * small shelf every miscount is an enormous percentage — one unit of two is
147
+ * 50 % — so a percent-only test flags the noise and buries the counts that
148
+ * matter. ⚠️ **Raising `tolerancePercent` therefore cannot admit a line the
149
+ * floor rejects, and setting it to `0` does not make every slip
150
+ * reviewable** — a consumer that models the threshold as the whole test will
151
+ * predict refusals the api never makes.
152
+ *
153
+ * ⚠️ **The floor SUPPRESSES, it does not TRIGGER — and the two readings
154
+ * disagree on a real case.** «Both must clear» is a CONJUNCTION: a 3-unit
155
+ * miss on a 1000-unit shelf is 0.3 %, clears the floor, and is still WITHIN
156
+ * tolerance because the percentage does not exceed the threshold. A reader
157
+ * who takes «the floor is tested first» to mean «reaching 3 units makes a
158
+ * line reviewable» inverts that row, and inverts it in the direction no
159
+ * gate can see — the api would refuse a finalise every consumer predicts
160
+ * will succeed. Held requires `units >= floor` AND `percent > threshold`;
161
+ * neither alone is sufficient.
162
+ *
163
+ * ⚠️ **A `systemQuantity` of `0` has no percentage at all**, so the floor is
164
+ * the whole test there: finding 2 units where the system believed none is
165
+ * WITHIN tolerance, and finding 3 is over it. This is deliberately not
166
+ * «infinite variance, always ADMIN» — that reading refuses a one-unit slip
167
+ * on an empty shelf, which is the single most common counting noise there
168
+ * is.
169
+ *
170
+ * ⚠️ **This ladder MIRRORS the rule shipped in the app's stocktake domain
171
+ * module** (`src/domain/stocktake.ts` — `STOCKTAKE_TOLERANCE_MIN_UNITS`,
172
+ * `isOverStocktakeTolerance`), deliberately and to the unit. The two were
173
+ * divergent once: the api tested the percentage alone, so the app showed
174
+ * «within tolerance» for sessions the api then refused. Do not «simplify»
175
+ * the floor away on either side without moving the other in the same
176
+ * change. ⚠️ What still differs BY DESIGN is the consequence, not the
177
+ * arithmetic — the app WITHHOLDS a row for acknowledgement, the api
178
+ * REFUSES the finalise with a 403 unless the caller is ADMIN or MANAGER.
179
+ *
180
+ * ⚠️ Not a review state, and it introduces none. Exceeding the threshold
181
+ * changes WHO may finalise; `status` stays `open | finalized | cancelled`
182
+ * either way, and the four-state review model this looks like was proposed
183
+ * and explicitly rejected.
184
+ */
185
+ tolerancePercent?: number;
92
186
  items: CycleCountItem[];
93
187
  /** Unix ms the variances were applied. Present only on a `finalized` session. */
94
188
  finalizedAt?: number;
package/dist/store.d.ts CHANGED
@@ -193,6 +193,46 @@ declare global {
193
193
  /** Cumulative consumption-value share, in percent, up to which a product is `B`. Absent falls back to 95. */
194
194
  bCumulativePercent?: number;
195
195
  }
196
+ /**
197
+ * Store-wide default for how far a cycle count's per-line variance may stray
198
+ * before finalising it stops being routine. Every member is optional and
199
+ * absence falls back to the api's built-in default, so a store that has never
200
+ * configured this still finalises counts — the leaf moves the threshold, it
201
+ * does not switch anything on.
202
+ *
203
+ * ⚠️ Nothing here is a REVIEW STATE. `CycleCountStatus` stays
204
+ * `open | finalized | cancelled`; a four-state `submitted`/`approved`/
205
+ * `rejected` model was proposed and explicitly rejected. A variance over the
206
+ * threshold changes WHO may finalise, never WHAT state the session passes
207
+ * through, so a consumer borrowing the app's «held»/«review» stocktake
208
+ * vocabulary for this is describing a wire state that does not exist.
209
+ */
210
+ interface CycleCountsConfig {
211
+ /**
212
+ * Default variance threshold, in PERCENT, for this store's cycle counts.
213
+ * Absent falls back to the api default (10) —
214
+ * `DEFAULT_CYCLE_COUNT_TOLERANCE_PERCENT` in `stacks/services/cycleCounts.ts`
215
+ * is the one place that number lives.
216
+ *
217
+ * ⚠️ **A percent, not a fraction.** `10` means ten percent. `0.10` means one
218
+ * tenth of one percent — a hundred times tighter than the writer meant,
219
+ * which puts nearly every counted line over the threshold and makes every
220
+ * count need an ADMIN or MANAGER to finalise. Meaningful range 0–100.
221
+ *
222
+ * ⚠️ **The percentage is only HALF the test.** A line must ALSO clear an
223
+ * absolute floor of `CYCLE_COUNT_TOLERANCE_MIN_UNITS` before any threshold
224
+ * applies to it — raising this number alone does not make a small-shelf
225
+ * miscount reviewable, and lowering it does not make a one-unit slip
226
+ * reviewable either. Both halves are stated on
227
+ * `CycleCount.tolerancePercent` (`./cycleCount.ts`).
228
+ *
229
+ * ⚠️ A single session may override this for itself, and absence here is one
230
+ * rung of a ladder rather than a value — both are stated in full on
231
+ * `CycleCount.tolerancePercent` (`./cycleCount.ts`). Deliberately NOT
232
+ * repeated here: two copies of a resolution order drift.
233
+ */
234
+ tolerancePercent?: number;
235
+ }
196
236
  interface Store {
197
237
  /**
198
238
  * Cmd-K palette overrides. Absent means "all built-in verbs, default order".
@@ -361,6 +401,29 @@ declare global {
361
401
  * intended, and it is why the job caps its own fan-out.
362
402
  */
363
403
  abcClassification?: AbcClassificationConfig;
404
+ /**
405
+ * Default variance threshold for cycle-count finalisation.
406
+ *
407
+ * Absent means a finalise runs on the api's default threshold — NOT that
408
+ * counting is off, and NOT zero tolerance. ⚠️ Absent means «fall through to
409
+ * the next rung of the ladder», which is the api default; a reader treating
410
+ * it as `0` makes every line that did not match exactly exceed the
411
+ * threshold, so every count starts requiring an ADMIN or MANAGER. The
412
+ * ladder is stated once, on `CycleCount.tolerancePercent`
413
+ * (`./cycleCount.ts`).
414
+ *
415
+ * ⚠️ Writable at the PRIVILEGED tier, like `abcClassification` above — but
416
+ * by DEFAULT rather than by a new check: `config` is gated by an
417
+ * ALLOW-list (`USER_WRITABLE_CONFIG_LEAVES`, `stacks/lambdas/store/_patch.ts`),
418
+ * so any leaf not on it takes the ADMIN/SUPERVISOR/MANAGER gate and its
419
+ * `STORE_CONFIG_FORBIDDEN` refusal.
420
+ *
421
+ * ⚠️ Tenant-owned, and that is a decision rather than an omission: it is
422
+ * deliberately absent from `StoreConfigAdminOverrideInput`, so there is no
423
+ * cross-tenant MANAGER override of a store's counting threshold. It moves
424
+ * through the tenant's own `PATCH /store` only.
425
+ */
426
+ cycleCounts?: CycleCountsConfig;
364
427
  /**
365
428
  * Ceiling on concurrent refresh-token sessions per user. When a new login
366
429
  * would exceed it the OLDEST family is revoked, so the cap never blocks a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.293",
3
+ "version": "1.10.294",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",