sinfactura-types 1.10.293 → 1.10.295
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/ai.d.ts +214 -0
- package/dist/ai.js +4 -1
- package/dist/cjs/ai.js +4 -1
- package/dist/cycleCount.d.ts +100 -6
- package/dist/store.d.ts +63 -0
- package/package.json +1 -1
package/dist/ai.d.ts
CHANGED
|
@@ -62,5 +62,219 @@ declare global {
|
|
|
62
62
|
model: string;
|
|
63
63
|
cached: boolean;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* One line item read off the document.
|
|
67
|
+
*
|
|
68
|
+
* ⚠️ `quantity` and `unitPrice` are optional and their ABSENCE is the
|
|
69
|
+
* uncertainty signal — see `SupplierDocExtractSuggestion`. Absent means the
|
|
70
|
+
* extractor could not read that number on that line; it is never emitted as
|
|
71
|
+
* `0`, because `0` is a value an operator would accept without checking.
|
|
72
|
+
*/
|
|
73
|
+
interface SupplierDocExtractItem {
|
|
74
|
+
/**
|
|
75
|
+
* The line's description as printed.
|
|
76
|
+
*
|
|
77
|
+
* ⚠️ May carry personal data — never log it, never put it in an error
|
|
78
|
+
* `message`, never attach it to a Sentry tag.
|
|
79
|
+
*/
|
|
80
|
+
description: string;
|
|
81
|
+
/** Units as printed. Absent when illegible — never `0` as a stand-in. */
|
|
82
|
+
quantity?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Per-unit price as printed, in the document's OWN currency — the
|
|
85
|
+
* extractor never converts, and never divides a line total by a quantity
|
|
86
|
+
* to synthesize one. Absent when illegible.
|
|
87
|
+
*/
|
|
88
|
+
unitPrice?: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* One per-alícuota IVA bucket read off the document's tax summary.
|
|
92
|
+
*
|
|
93
|
+
* `id` is the ARCA IVA codeset id — the SAME numbering `InvoiceAlicuota.id`
|
|
94
|
+
* uses, NOT a percentage: 3 = 0 % · 4 = 10,5 % · 5 = 21 % · 6 = 27 % ·
|
|
95
|
+
* 8 = 5 % · 9 = 2,5 %. A rate the extractor cannot map onto one of those six
|
|
96
|
+
* is dropped server-side rather than guessed, so `id` on the wire is always
|
|
97
|
+
* one of them.
|
|
98
|
+
*
|
|
99
|
+
* ⚠️ Deliberately NOT `InvoiceAlicuota`, though the codeset is shared and
|
|
100
|
+
* single-sourced there. `InvoiceAlicuota` is the AUTHORITATIVE breakdown of a
|
|
101
|
+
* voucher THIS store issued and requires both amounts; this is a partial
|
|
102
|
+
* reading of a voucher somebody else issued. Reusing it would force a bucket
|
|
103
|
+
* where only one of the two amounts was legible to be dropped whole — losing
|
|
104
|
+
* "there IS a 21 % line here" — and would tie a compras guess to a ventas
|
|
105
|
+
* shape that the CAE path may reshape for reasons of its own.
|
|
106
|
+
*
|
|
107
|
+
* ⚠️ MAPPING GAP the app must handle: `SupplierInvoice` carries only the
|
|
108
|
+
* 10,5 / 21 / 27 rate slots (`neto10`/`iva10`, `neto21`/`iva21`,
|
|
109
|
+
* `neto27`/`iva27`). Ids 3, 8 and 9 have NO slot on that row, so a bucket
|
|
110
|
+
* carrying one cannot be pre-filled anywhere — surface it to the operator
|
|
111
|
+
* instead of discarding it, or the booked total silently stops matching the
|
|
112
|
+
* voucher.
|
|
113
|
+
*/
|
|
114
|
+
interface SupplierDocExtractIvaBucket {
|
|
115
|
+
/** ARCA IVA codeset id — 3, 4, 5, 6, 8 or 9. */
|
|
116
|
+
id: number;
|
|
117
|
+
/** Neto gravado at this rate, as printed. Absent when illegible. */
|
|
118
|
+
baseImp?: number;
|
|
119
|
+
/**
|
|
120
|
+
* IVA liquidado at this rate, as printed. Absent when illegible; `0` is a
|
|
121
|
+
* real, declarable value at the 0 % rate and is not a placeholder.
|
|
122
|
+
*/
|
|
123
|
+
importe?: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The extracted candidate. Nothing here is persisted by the call that
|
|
127
|
+
* produced it — see the section header.
|
|
128
|
+
*
|
|
129
|
+
* ⚠️ THERE IS NO CONFIDENCE SCORE, per field or per row, and that is a
|
|
130
|
+
* decision rather than an omission. A model's self-reported confidence is
|
|
131
|
+
* uncalibrated — it is generated text, not a measured probability — and
|
|
132
|
+
* publishing one invites exactly the client the suggestion-only posture
|
|
133
|
+
* exists to prevent: one that auto-accepts everything above a threshold and
|
|
134
|
+
* shows the operator only what scored low. The uncertainty signal is ABSENCE
|
|
135
|
+
* instead: every extracted NUMBER is optional, and an absent number means
|
|
136
|
+
* "not legible", never "zero". An app deciding what to highlight for review
|
|
137
|
+
* should highlight every absent field — and treat the whole suggestion as
|
|
138
|
+
* unreviewed until the operator confirms it, because a confidently-read
|
|
139
|
+
* wrong number looks exactly like a confidently-read right one.
|
|
140
|
+
*
|
|
141
|
+
* Both arrays are ALWAYS PRESENT and MAY BE EMPTY — an empty `items` means no
|
|
142
|
+
* line table was readable, and the app still renders the section. ⚠️ This is
|
|
143
|
+
* the opposite convention from `ProductEnrichSuggestion.attributes`
|
|
144
|
+
* (absent-or-non-empty) on purpose: that one feeds optional form slots, these
|
|
145
|
+
* feed two sections the supplier-invoice form always shows.
|
|
146
|
+
*/
|
|
147
|
+
interface SupplierDocExtractSuggestion {
|
|
148
|
+
items: SupplierDocExtractItem[];
|
|
149
|
+
ivaBreakdown: SupplierDocExtractIvaBucket[];
|
|
150
|
+
/**
|
|
151
|
+
* Conceptos NO GRAVADOS total, as printed. Document-level rather than an
|
|
152
|
+
* `ivaBreakdown` row on purpose — ARCA's Ids 1 (No Gravado) and 2 (Exento)
|
|
153
|
+
* are Códigos de Operación, not alícuotas, and are rejected inside an IVA
|
|
154
|
+
* array; `InvoiceAlicuota` documents the same rule. Pre-fills
|
|
155
|
+
* `SupplierInvoice.noGravado`. Absent when the document prints no such
|
|
156
|
+
* line, or prints one that is not legible.
|
|
157
|
+
*/
|
|
158
|
+
noGravado?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Operaciones EXENTAS total, as printed — same rationale as `noGravado`.
|
|
161
|
+
* Pre-fills `SupplierInvoice.exento`.
|
|
162
|
+
*/
|
|
163
|
+
exento?: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Request body of the supplier-invoice document-extraction endpoint.
|
|
167
|
+
*
|
|
168
|
+
* ⚠️ There is deliberately no `filename` here, unlike
|
|
169
|
+
* `SupportFileAttachmentUpload`. The server pins a fixed, neutral document
|
|
170
|
+
* name on the model request; a caller-supplied filename would put tenant text
|
|
171
|
+
* into the one field the model transport itself flags as readable as
|
|
172
|
+
* instructions.
|
|
173
|
+
*/
|
|
174
|
+
interface SupplierDocExtractRequest {
|
|
175
|
+
/**
|
|
176
|
+
* Declared document format — only `'pdf'` is accepted today, and widening
|
|
177
|
+
* it later is additive. ⚠️ The declaration is VERIFIED against the decoded
|
|
178
|
+
* bytes' magic number: a body declaring `'pdf'` whose bytes are not a PDF
|
|
179
|
+
* is refused `UNSUPPORTED_MEDIA_TYPE` and never reaches the model on
|
|
180
|
+
* trust.
|
|
181
|
+
*/
|
|
182
|
+
format: 'pdf';
|
|
183
|
+
/**
|
|
184
|
+
* The document itself, as BARE base64 (no `data:` URI prefix) — the same
|
|
185
|
+
* transport as `SupportFileAttachmentUpload.data`, which is this API's
|
|
186
|
+
* shipped file-ingress shape; there is no presigned-upload route to use
|
|
187
|
+
* instead.
|
|
188
|
+
*
|
|
189
|
+
* Decoded maximum 4 MiB. ⚠️ That ingress cap sits STRICTLY BELOW the model
|
|
190
|
+
* transport's own per-document byte cap, so size is only ever refused
|
|
191
|
+
* here, as `CONTENT_TOO_LARGE` — the larger downstream limit is
|
|
192
|
+
* unreachable from this endpoint and no code reports it.
|
|
193
|
+
*
|
|
194
|
+
* ⚠️ Never logged and never echoed back.
|
|
195
|
+
*/
|
|
196
|
+
data: string;
|
|
197
|
+
/**
|
|
198
|
+
* Page count of the document, COUNTED BY THE CALLER.
|
|
199
|
+
*
|
|
200
|
+
* ⚠️ Send it whenever you can. The page cap is only enforceable pre-flight
|
|
201
|
+
* when it is DECLARED — omit it and the check does not run at all: the
|
|
202
|
+
* document is sent, the call is made, the tenant's ceiling is charged for
|
|
203
|
+
* it, and the model provider enforces its own page limit opaquely, so the
|
|
204
|
+
* caller gets a generic upstream failure instead of
|
|
205
|
+
* `DOCUMENT_TOO_MANY_PAGES`. A caller that can cheaply count pages (the
|
|
206
|
+
* app already parses the PDF to preview it) should ALWAYS send this:
|
|
207
|
+
* omitting it buys nothing and gives up the one free refusal.
|
|
208
|
+
*
|
|
209
|
+
* A declared count above the cap is refused before any model call, so
|
|
210
|
+
* nothing is spent.
|
|
211
|
+
*/
|
|
212
|
+
pageCount?: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* `data` payload of the success envelope — the body is
|
|
216
|
+
* `{ message, data: SupplierDocExtractResponse }`, the same envelope
|
|
217
|
+
* `ProductEnrichResponse` rides in.
|
|
218
|
+
*
|
|
219
|
+
* There is no `cached` flag, unlike `ProductEnrichResponse`: every call
|
|
220
|
+
* extracts afresh.
|
|
221
|
+
*/
|
|
222
|
+
interface SupplierDocExtractResponse {
|
|
223
|
+
suggestion: SupplierDocExtractSuggestion;
|
|
224
|
+
/** The model that actually produced the extraction. */
|
|
225
|
+
model: string;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The `error` codes this endpoint answers. Bare SCREAMING_SNAKE, no prefix.
|
|
229
|
+
*
|
|
230
|
+
* Three refusal FAMILIES, deliberately not collapsed, because they differ in
|
|
231
|
+
* who paid and what the operator should do next:
|
|
232
|
+
*
|
|
233
|
+
* · INGRESS — `INVALID_BASE64`, `UNSUPPORTED_MEDIA_TYPE`,
|
|
234
|
+
* `CONTENT_TOO_LARGE`, `DOCUMENT_TOO_MANY_PAGES`. The document NEVER
|
|
235
|
+
* REACHED THE MODEL: no call was made, nothing was metered, nothing was
|
|
236
|
+
* billed. The operator fixes the file and retries at once, for free.
|
|
237
|
+
* · BUDGET — `COST_CEILING_EXCEEDED`. A spend ceiling, not a problem with the
|
|
238
|
+
* document. The same file can succeed later, unchanged.
|
|
239
|
+
* · MODEL — `DOC_EXTRACT_BLOCKED`, `DOC_EXTRACT_GENERATION_FAILED`. The
|
|
240
|
+
* document DID reach the model and the call WAS metered. Retrying spends
|
|
241
|
+
* again and rarely helps on the same file.
|
|
242
|
+
*
|
|
243
|
+
* Collapsing an ingress refusal into a model failure is the mistake this
|
|
244
|
+
* split exists to prevent: it tells an operator a call was paid for when
|
|
245
|
+
* none was made, and it hides the one class of failure they can fix.
|
|
246
|
+
*
|
|
247
|
+
* Per member:
|
|
248
|
+
* - `INVALID_BASE64` · 400 — `data` is not well-formed base64.
|
|
249
|
+
* - `UNSUPPORTED_MEDIA_TYPE` · 415 — the decoded bytes are not a PDF,
|
|
250
|
+
* whatever `format` declared.
|
|
251
|
+
* - `CONTENT_TOO_LARGE` · 413 — decoded size over the 4 MiB ingress cap.
|
|
252
|
+
* - `DOCUMENT_TOO_MANY_PAGES` · 413 — the DECLARED `pageCount` exceeds the
|
|
253
|
+
* model's page limit. ⚠️ Reachable ONLY when the caller declared one — see
|
|
254
|
+
* `SupplierDocExtractRequest.pageCount`.
|
|
255
|
+
* - `COST_CEILING_EXCEEDED` · 403 OR 503, and the app must switch on which.
|
|
256
|
+
* 403 is the TENANT's own ceiling and carries `upsell: true` plus
|
|
257
|
+
* `feature: 'aiFeatures'`; 503 is the platform-wide ceiling, carries
|
|
258
|
+
* neither, and is an operator hard-stop that no tenant action clears.
|
|
259
|
+
* ⚠️ The code lands in BOTH `error` and `message`, matching the shipped
|
|
260
|
+
* ceiling mapper — `message` is NOT prose on this member and must not be
|
|
261
|
+
* shown to a user verbatim.
|
|
262
|
+
* - `AI_DOC_EXTRACT_DISABLED` · 503 — the platform kill-switch for this
|
|
263
|
+
* feature is off. Distinct from a ceiling: nothing was spent and no budget
|
|
264
|
+
* is exhausted.
|
|
265
|
+
* - `AI_OPT_OUT` · 403 — this store switched AI off. Fail-closed, so a store
|
|
266
|
+
* read that THREW answers this too; the same code the enrichment endpoint
|
|
267
|
+
* uses, not a second spelling of it.
|
|
268
|
+
* - `DOC_EXTRACT_BLOCKED` · 422 — the model's guardrail refused the document.
|
|
269
|
+
* - `DOC_EXTRACT_GENERATION_FAILED` · 502 — the model answered but not in a
|
|
270
|
+
* shape that parses. Named for symmetry with `ENRICH_GENERATION_FAILED`,
|
|
271
|
+
* which is the same failure on the sibling endpoint.
|
|
272
|
+
*
|
|
273
|
+
* ⚠️ Cross-cutting refusals are NOT listed here and are still reachable —
|
|
274
|
+
* `PLAN_UPGRADE_REQUIRED` above all, since the endpoint is `aiFeatures`-
|
|
275
|
+
* entitled. Check `GatingErrorCode` IN ADDITION to this union, never instead
|
|
276
|
+
* of it.
|
|
277
|
+
*/
|
|
278
|
+
type SupplierDocExtractErrorCode = 'INVALID_BASE64' | 'UNSUPPORTED_MEDIA_TYPE' | 'CONTENT_TOO_LARGE' | 'DOCUMENT_TOO_MANY_PAGES' | 'COST_CEILING_EXCEEDED' | 'AI_DOC_EXTRACT_DISABLED' | 'AI_OPT_OUT' | 'DOC_EXTRACT_BLOCKED' | 'DOC_EXTRACT_GENERATION_FAILED';
|
|
65
279
|
}
|
|
66
280
|
export {};
|
package/dist/ai.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
// AI platform-spend
|
|
1
|
+
// AI contracts — the MANAGER platform-spend report, plus the tenant-facing
|
|
2
|
+
// AI suggestion endpoints (product enrichment, supplier-invoice document
|
|
3
|
+
// extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
|
|
4
|
+
// section below restates what its own call does not persist.
|
|
2
5
|
export {};
|
package/dist/cjs/ai.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// AI platform-spend
|
|
2
|
+
// AI contracts — the MANAGER platform-spend report, plus the tenant-facing
|
|
3
|
+
// AI suggestion endpoints (product enrichment, supplier-invoice document
|
|
4
|
+
// extraction). Every suggestion endpoint here is SUGGESTION-ONLY: each
|
|
5
|
+
// section below restates what its own call does not persist.
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/cycleCount.d.ts
CHANGED
|
@@ -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
|
-
* ⚠️ **
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|