sinfactura-types 1.10.320 → 1.10.322

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/account.d.ts CHANGED
@@ -127,12 +127,14 @@ declare global {
127
127
  * rows above and is deliberately NOT an {@link Account}: every money field
128
128
  * differs, and the two are told apart by the `BALANCE-` sort-key prefix.
129
129
  *
130
- * Written by exactly two producers — the operator and storefront
131
- * `GET /account` twins — when a customer statement crosses
132
- * `AUTO_BALANCE_SNAPSHOT_THRESHOLD` un-checkpointed rows, under
133
- * `attribute_not_exists(PK)` so the loser of a concurrent pair no-ops. Read
134
- * back by `getLastBalanceByCustomerId`, which trusts it verbatim — which is
135
- * why a TRUNCATED recompute is never persisted as one.
130
+ * Written by exactly ONE producer — the nightly sweeper
131
+ * (`stacks/lambdas/accountCheckpointSweeper`) — for a customer whose
132
+ * un-checkpointed run crosses `AUTO_BALANCE_SNAPSHOT_THRESHOLD`, under
133
+ * `attribute_not_exists(PK)` so the loser of a concurrent pair no-ops. ⚠️ The
134
+ * two `GET /account` twins used to write it inline and no longer write
135
+ * anything at all: a statement READ has no side effect. Read back by
136
+ * `getLastBalanceByCustomerId`, which trusts it verbatim — which is why a
137
+ * TRUNCATED recompute is never persisted as one.
136
138
  */
137
139
  interface AccountBalanceCheckpoint {
138
140
  /**
@@ -187,6 +189,92 @@ declare global {
187
189
  * It is the reason {@link Account.balance} still exists on the wire after the
188
190
  * stored checkpoint moved to a per-currency map.
189
191
  */
192
+ /**
193
+ * Every way a customer statement can REFUSE, beyond the window vocabulary of
194
+ * {@link AccountDateRangeError}. Published for the same reason that union is:
195
+ * both `GET /account` twins return these as the `error` of a non-2xx, and a
196
+ * closed set the FEs must branch on cannot live under `stacks/`.
197
+ *
198
+ * - `INVALID_CURSOR` — **400.** The `?startKey=` did not decode, or decoded to
199
+ * a cursor for another store or another customer, one whose own key sits
200
+ * outside the statement's key range at either end, or one whose pins do not
201
+ * hold. ⚠️ **There are TWO pins.** `balanceDate` must not be absent,
202
+ * non-numeric or raised past the cursor's own key; `date` must EQUAL the
203
+ * `?date=` of the request spending the cursor, because it is the boundary
204
+ * both statement reads are split on — changing it mid-walk would read the
205
+ * same rows through a different filter and silently skip or repeat every row
206
+ * the move crossed. A client that wants a different window starts a new walk
207
+ * with no cursor. ⚠️ Never
208
+ * "restart from page one" on this: a client cannot tell a silent restart
209
+ * from a legitimate first page, so a paging loop re-reads from the top and
210
+ * appends every row twice. Discard the cursor and ask the user.
211
+ * - `CUSTOMER_LEDGER_TRUNCATED` — **503.** The UNPAGINATED fold-forward sum
212
+ * behind "Saldo anterior" exceeded the read budget, so the opening balance
213
+ * would be WRONG by an unbounded amount rather than merely short. ⚠️ Not
214
+ * retryable by the client: the condition is self-perpetuating until the
215
+ * nightly sweeper checkpoints that customer, because the truncation is
216
+ * exactly what stops a checkpoint being written. It is recorded for the
217
+ * operator under a deduped `ACCOUNT_CUSTOMER_LEDGER_TRUNCATED#{customerId}`
218
+ * ERROR row. Show the operator a "statement unavailable" state; a retry loop
219
+ * only adds load. It can only ever arrive on page ONE — a resumed page
220
+ * computes no sum.
221
+ */
222
+ type AccountStatementError = 'INVALID_CURSOR' | 'CUSTOMER_LEDGER_TRUNCATED';
223
+ /**
224
+ * How a customer statement PAGES.
225
+ *
226
+ * ⚠️ **The statement is two reads, and only the second one pages.** The
227
+ * opening balance is an unpaginated fold-forward sum bounded by the newest
228
+ * balance checkpoint; the movement list is a page of at most
229
+ * `ACCOUNT_STATEMENT_PAGE_MAX` rows, oldest first.
230
+ *
231
+ * - Send `?startKey=` with the `LastEvaluatedKey` of the previous response.
232
+ * Its ABSENCE in a response means the ledger is drained — never "ask again".
233
+ * - The {@link AccountStatementOpeningRow} leads **page one only**. A resumed
234
+ * page carries movement rows alone; adding the opening balance per page is
235
+ * the defect the server-side omission prevents.
236
+ * - The cursor pins the checkpoint the walk started from, so a checkpoint
237
+ * committed between two pages cannot empty page two or move the opening
238
+ * figure. The figure is therefore stable for the whole walk.
239
+ * - It also pins `date`, so **every page of one walk must be requested with
240
+ * the same `?date=`**. A different one is `400 INVALID_CURSOR`, not a
241
+ * re-anchored page: `date` is the boundary both reads are split on.
242
+ * - ⚠️ **A page may be EMPTY and still carry a cursor.** The listing read has
243
+ * a page budget and a wall-clock budget, and it can spend either on rows the
244
+ * `dated` filter discards before it matches anything. An empty page beside a
245
+ * `LastEvaluatedKey` means "keep paging", never "drained" — the cursor's
246
+ * ABSENCE is the only end-of-walk signal.
247
+ * - A cursor is bound to its STORE and its CUSTOMER and cannot be spent
248
+ * against either another. It is **not** bound to the surface: an
249
+ * operator-minted cursor is spendable on the storefront and vice versa,
250
+ * because the projection audience comes from the authorizer on every
251
+ * request and is never carried in the cursor.
252
+ * - `truncated` means what it has always meant: **this response is not the
253
+ * whole ledger.** It is set on EVERY capped page, alongside the cursor, and
254
+ * is absent on the last page of a walk. ⚠️ It is deliberately NOT excused by
255
+ * the cursor's presence: a client that has not yet learned to page would
256
+ * otherwise present one page's rows as the whole ledger, and every consumer
257
+ * of this endpoint does ARITHMETIC over the response — FIFO paid/unpaid
258
+ * allocation, a client-side running balance, footer totals. The flag is what
259
+ * keeps an un-updated client honest until it follows the cursor.
260
+ */
261
+ interface AccountStatementPaging {
262
+ /** Opaque, base64url. Echo it as `?startKey=` for the next page. */
263
+ LastEvaluatedKey?: string;
264
+ /**
265
+ * This response is not the whole ledger. Three causes, and a consumer need not
266
+ * tell them apart: a CAPPED page and a page cut short by the listing read's
267
+ * own PAGE/TIME budget (both resumable — `LastEvaluatedKey` accompanies them,
268
+ * and the budget case may carry no rows at all), and the legacy
269
+ * bare-`customerId` read (un-resumable — no cursor can continue it). Absent
270
+ * once the walk is drained.
271
+ *
272
+ * ⚠️ A truncated fold-forward SUM is neither: it is refused outright with
273
+ * `503 CUSTOMER_LEDGER_TRUNCATED`, because a wrong opening balance is not a
274
+ * short response. See {@link AccountStatementError}.
275
+ */
276
+ truncated?: true;
277
+ }
190
278
  interface AccountStatementOpeningRow {
191
279
  /** `'ACC000001'` for the first, `` `ACC000001-${currency}` `` after that — a display id, not a key. */
192
280
  accountId: string;
package/dist/order.d.ts CHANGED
@@ -102,6 +102,38 @@ declare global {
102
102
  /** userId of the operator who rang it. */
103
103
  recordedBy?: string;
104
104
  }
105
+ /**
106
+ * One line of an ORDER — a cart line plus the ledger stamp only an order has.
107
+ *
108
+ * Separate from {@link CartLine} deliberately: a cart has no `SALE#` ledger
109
+ * row, so a stamp declared there would be a field no cart writer can ever
110
+ * populate and every cart reader would have to explain away. `Order.items`
111
+ * stays assignable from a cart's own lines, because every added field is
112
+ * optional and orders copy cart lines verbatim.
113
+ */
114
+ interface OrderLine extends CartLine {
115
+ /**
116
+ * The stamp THIS line's `SALE#` ledger row is keyed by —
117
+ * `${productId}-${saleTs}`.
118
+ *
119
+ * ⚠️ **Server-owned, always.** The edit request schema is `.strict()` and
120
+ * accepts only `productId`/`quantity`/`price`, so a client cannot supply
121
+ * one; the server carries it forward from the stored line, or allocates a
122
+ * fresh one when it mints a replacement row. A writer that echoed a
123
+ * client value here would let a caller re-point another order's ledger row.
124
+ *
125
+ * ⚠️ **Lines of the SAME product share one value.** The ledger SK carries
126
+ * no line index, so a product spanning several lines owns exactly one row
127
+ * and every one of those lines names it.
128
+ *
129
+ * ⚠️ OPTIONAL PERMANENTLY. Absent means "resolve through the ORDER row's
130
+ * own `saleTs`, then its `createdAt`" — which is every line written before
131
+ * per-line stamping, forward-only, never backfilled. Resolution belongs to
132
+ * ONE helper (`saleLedgerTsForLine`); reading this field directly
133
+ * addresses nothing for the whole legacy population.
134
+ */
135
+ saleTs?: number;
136
+ }
105
137
  interface Order {
106
138
  storeId: string;
107
139
  orderId: string;
@@ -669,7 +701,7 @@ declare global {
669
701
  source?: 'auto' | 'manual';
670
702
  };
671
703
  disabled?: boolean;
672
- items: Partial<CartLine>[];
704
+ items: Partial<OrderLine>[];
673
705
  rating?: number;
674
706
  comment?: string;
675
707
  surveyDate?: number;
package/dist/stock.d.ts CHANGED
@@ -49,7 +49,26 @@ declare global {
49
49
  * movement is UNVALUED, never that it was free.
50
50
  */
51
51
  cost?: number;
52
+ /**
53
+ * The movement has been RETRACTED and must not count toward on-hand.
54
+ *
55
+ * ⚠️ Supersedes the legacy `notEvaluate` spelling, which no writer ever
56
+ * used. This one HAS writers: every order-lifecycle reversal stamps it —
57
+ * a cancelled sale, a disabled order, the replaced half of an edited one
58
+ * and a voided MercadoLibre sale — because the ledger is retract-only and
59
+ * a movement row is never deleted and never overwritten.
60
+ */
52
61
  skip?: boolean;
62
+ /**
63
+ * When the retraction happened, in Unix ms. Present only alongside
64
+ * {@link StockBase.skip}.
65
+ *
66
+ * ⚠️ OPTIONAL PERMANENTLY, and absence does NOT mean "not retracted" —
67
+ * `skip` alone answers that. Rows stamped before this field existed carry
68
+ * none, this platform never backfills, and a reader that treats a missing
69
+ * `retractedAt` as "still live" re-counts every one of them.
70
+ */
71
+ retractedAt?: number;
53
72
  }
54
73
  /**
55
74
  * Attributes persisted on every stock-movement row. `storeId` and `stockId`
@@ -81,7 +100,21 @@ declare global {
81
100
  * `reports?mode=stocks` reports `costlessProducts` beside its totals.
82
101
  */
83
102
  cost?: number;
103
+ /**
104
+ * The movement has been RETRACTED — see {@link StockBase.skip}. The ledger
105
+ * is retract-only: a reversal stamps this in place rather than deleting
106
+ * the row, so the audit trail survives the retraction.
107
+ *
108
+ * ⚠️ A writer stamping this owes {@link StoredStockBase.retractedAt}
109
+ * beside it. Nothing structurally forces the pair, so the writer owes it.
110
+ */
84
111
  skip?: boolean;
112
+ /**
113
+ * When the retraction happened, in Unix ms — see
114
+ * {@link StockBase.retractedAt} for why absence is permanent and is not
115
+ * the same statement as `skip` being absent.
116
+ */
117
+ retractedAt?: number;
85
118
  }
86
119
  /**
87
120
  * Why an operator moved stock by hand, rather than through a purchase, a sale
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.320",
3
+ "version": "1.10.322",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",