sinfactura-types 1.10.321 → 1.10.323

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/auth.d.ts CHANGED
@@ -33,6 +33,17 @@ declare global {
33
33
  /** Remember this device — same semantics as `Login.trustDevice`. */
34
34
  trustDevice?: boolean;
35
35
  }
36
+ /**
37
+ * Registration request body.
38
+ *
39
+ * ⚠️ ONE type serves TWO endpoints whose schemas differ: tenant self-registration
40
+ * (`POST /auth`, mode `register`) and the storefront CUSTOMER registration. It
41
+ * mirrors neither exactly — the tenant schema also takes `name` and `waitlist` and
42
+ * makes `fullName` optional and `phone` required; the customer schema has no
43
+ * `name`, requires `fullName` and takes an address. Both front ends reach it
44
+ * through a cast, so tightening it towards either schema breaks the other's
45
+ * compile. `acquisition` is tenant-only; the customer registration ignores it.
46
+ */
36
47
  interface Register {
37
48
  email: string;
38
49
  password: string;
@@ -40,6 +51,8 @@ declare global {
40
51
  fullName: string;
41
52
  phone?: string;
42
53
  acknowledgedSharedCuit?: boolean;
54
+ /** First-touch acquisition captured by the registration client; the api server-stamps `capturedAt`. */
55
+ acquisition?: StoreAcquisitionInput;
43
56
  }
44
57
  interface Recover {
45
58
  email: string;
package/dist/store.d.ts CHANGED
@@ -234,6 +234,21 @@ declare global {
234
234
  */
235
235
  tolerancePercent?: number;
236
236
  }
237
+ /** First-touch acquisition metadata captured when this tenant self-registers. */
238
+ interface StoreAcquisition {
239
+ source: string;
240
+ medium: string;
241
+ campaign: string;
242
+ content?: string;
243
+ /** Unix ms, stamped by the api from the registration timestamp. */
244
+ capturedAt: number;
245
+ }
246
+ /**
247
+ * The REQUEST leaf: everything a registration client may send, i.e.
248
+ * `StoreAcquisition` minus the server-owned stamp. The api refuses a body
249
+ * carrying `capturedAt`, and refuses any key this type does not name.
250
+ */
251
+ type StoreAcquisitionInput = Omit<StoreAcquisition, 'capturedAt'>;
237
252
  interface Store {
238
253
  /**
239
254
  * Cmd-K palette overrides. Absent means "all built-in verbs, default order".
@@ -305,6 +320,8 @@ declare global {
305
320
  /** Payment CBU contact leaf (22 digits), shown to customers. */
306
321
  cbu?: string;
307
322
  acknowledgedSharedCuit?: boolean;
323
+ /** First-touch acquisition; absent for non-campaign/legacy registrations and never client-updated after creation. */
324
+ acquisition?: StoreAcquisition;
308
325
  /**
309
326
  * Response-time join, not a persisted Store attribute — and TWO different
310
327
  * shapes depending on the endpoint: `GET /tenants` (SUPERVISOR) attaches the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.321",
3
+ "version": "1.10.323",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",