sinfactura-types 1.10.301 → 1.10.303

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.
@@ -143,6 +143,69 @@ exports.SOCKET_ACTIONS = [
143
143
  */
144
144
  'deliveries',
145
145
  'globals',
146
+ /**
147
+ * BE → the store's OPERATOR sockets when a per-location stock balance moves.
148
+ * `data` is ONE whole `InventoryLevel` row — the post-write balance of a
149
+ * single product×warehouse cell, read back consistently by the service that
150
+ * moved it.
151
+ *
152
+ * ⚠️ **Always a FULL row, never a patch — unlike `products`, which sends
153
+ * both shapes.** `InventoryLevel` has no fields beyond the ones on this
154
+ * frame, so a client MAY insert a cell it has never seen; merging a
155
+ * {@link ProductStockFrameData} patch over an unknown product, by contrast,
156
+ * would mint an entity with no name or price.
157
+ *
158
+ * ⚠️ **This frame and a `products` stock frame are two different books and
159
+ * neither implies the other.** Per-location balances move only on the
160
+ * explicit inventory operations; the order and marketplace paths move
161
+ * store-wide `Product.stock` and emit `products`. A client must not reconcile
162
+ * one against the other, and the absence of one says nothing about the other.
163
+ *
164
+ * ⚠️ **ONE FRAME PER CELL, and `data` is never an array.** A movement that
165
+ * touches N locations sends N independent frames — a transfer sends two, the
166
+ * origin and the destination — and each is complete on its own. They may
167
+ * arrive in either order and either may be lost without invalidating the
168
+ * other.
169
+ *
170
+ * ⚠️ **`warehouseId` AND `productId` together are the identity; neither
171
+ * alone places the frame.** A store broadcast carries no audience selector
172
+ * and one product holds a separate balance at every location it has traded
173
+ * at, so a client keyed on `productId` alone overwrites one location's stock
174
+ * with another's — the failure is silent and looks like stock teleporting
175
+ * between depósitos.
176
+ *
177
+ * ⚠️ **`version` is the staleness discriminator and a client MUST use it.**
178
+ * Delivery is best-effort and unordered, so two movements against one cell
179
+ * can arrive newest-first; apply a frame only when its `version` exceeds the
180
+ * one already held for that cell. The counter is per-cell, not per-store.
181
+ * A REPLAYED write — a repeated `movementId`, which commits nothing —
182
+ * broadcasts too: the balances are re-read, so the frame restates a true
183
+ * cell rather than announcing a second movement, and this rule is what makes
184
+ * that duplicate a no-op.
185
+ *
186
+ * ⚠️ Operator-only — `wsPostStore(..., { audience: 'operator' })`, never the
187
+ * `'operator-and-customer'` that `dynamoUpdate`'s automatic broadcast
188
+ * hardcodes. The row carries `avgCost` and `costLayers` — what the store
189
+ * paid, which is merchant margin under another name — and `scrubForCustomer`
190
+ * knows nothing about this entity, so nothing would be stripped from a
191
+ * customer copy. `InventoryLevel` carries no `customerId`, which would make
192
+ * the customer leg a no-op query rather than a leak, but the audience is
193
+ * gated on the ENTITY'S SHAPE rather than on that accident, per
194
+ * `'cycleCounts'` below.
195
+ *
196
+ * ⚠️ The ledger row is NOT on this frame. A `StockMovement` is immutable
197
+ * history carrying the acting `userId` and a free-text `note`, and one call
198
+ * writes up to one per leg; a client that needs it reads
199
+ * `GET /inventory?mode=movements`.
200
+ *
201
+ * The producer is the single write chokepoint of `POST /inventory`
202
+ * (`commitMovement` → `postInventoryLevelFrames`,
203
+ * `stacks/lambdas/inventory/`), covering every write mode: receipt,
204
+ * adjustment, write-off, transfer, reserve and release. The GET modes emit
205
+ * nothing, and `dynamoUpdate` is not involved at all — these rows live on the
206
+ * inventory satellite table, which no generic row writer touches.
207
+ */
208
+ 'inventory',
146
209
  'invoices',
147
210
  'literals',
148
211
  /**
@@ -417,6 +480,34 @@ exports.SOCKET_ACTIONS = [
417
480
  * wrong entity in both places.
418
481
  */
419
482
  'cycleCounts',
483
+ /**
484
+ * BE → the store's OPERATOR sockets on every stock-transfer write: create,
485
+ * dispatch, a per-line arrival, close and cancel. Carries the full
486
+ * `StockTransfer` row, mirroring how `'cycleCounts'` carries the session.
487
+ *
488
+ * ⚠️ Operator-only — `wsPostStore(..., { audience: 'operator' })`, never the
489
+ * `'operator-and-customer'` that `dynamoUpdate`'s automatic broadcast
490
+ * hardcodes. Every write in this domain therefore passes `silent: true` and
491
+ * re-broadcasts through one chokepoint. `StockTransfer` carries no
492
+ * `customerId`, so the customer leg would be a no-op query rather than a
493
+ * leak — state the audience anyway: the safety is a property of today's
494
+ * shape, and a later field would silently turn a no-op into a fan-out. It is
495
+ * gated on the ENTITY'S SHAPE rather than on that accident, because the row
496
+ * carries operator prose (`notes`, which the entity says is never scrubbed
497
+ * and has no TTL) and an internal view of where a store keeps its stock.
498
+ *
499
+ * ⚠️ Declared for the REST surface too, not only the socket:
500
+ * `dynamoUpdate`'s `action` is interpolated into the success message and
501
+ * into the cross-tenant guard's audit label, neither of which `silent`
502
+ * gates — so a writer with no action of its own has to borrow one, and the
503
+ * borrowed name then names the wrong entity in both places.
504
+ *
505
+ * ⚠️ A `received` transfer does NOT mean received equals sent — operators
506
+ * close short arrivals, and the difference is a loss that needs its own
507
+ * adjustment. A client must read the line quantities rather than inferring
508
+ * completeness from the status.
509
+ */
510
+ 'stockTransfers',
420
511
  ];
421
512
  /** Runtime guard — narrows an untrusted string to a known action. */
422
513
  const isSocketAction = (value) => typeof value === 'string' && exports.SOCKET_ACTIONS.includes(value);
@@ -378,7 +378,9 @@ declare global {
378
378
  *
379
379
  * ⚠️ **The consequence, stated so nobody infers a precision this key lacks:
380
380
  * two movements written in the SAME millisecond have NO defined relative
381
- * order.** They sort by UUID, which is arbitrary. For a running-balance replay
381
+ * order.** They sort by the `uniq` component, which is arbitrary — and, since
382
+ * that component is caller-supplied rather than a UUID, arbitrary in whatever
383
+ * way the caller's scheme happens to order. For a running-balance replay
382
384
  * that is a real limitation — within one millisecond, the balance after each
383
385
  * row is not reproducible. Nothing here provides intra-millisecond
384
386
  * monotonicity, and a future caller that needs it is asking for a key-format
@@ -389,8 +391,15 @@ declare global {
389
391
  warehouseId: string;
390
392
  productId: string;
391
393
  /**
392
- * Server-minted UUID — the `uniq` component of the sort key and the row's
393
- * only identity.
394
+ * The `uniq` component of the sort key and the row's only identity.
395
+ *
396
+ * ⚠️ **CALLER-supplied, and NOT necessarily a UUID** — this said "server-minted
397
+ * UUID" and both halves were wrong. `applyMovement` is documented idempotent
398
+ * on *the caller's* `movementId` (`stacks/services/inventoryLevels.ts`), which
399
+ * is what makes a retry credit nothing; and the stock-transfer writer supplies
400
+ * a DERIVED id on purpose, because deriving it from (transfer, line, prior
401
+ * quantity) is exactly the mechanism that stops two operators double-crediting
402
+ * one line. Treat this as an opaque unique string.
394
403
  *
395
404
  * ⚠️ It carries no time information and imposes no order. A row is addressed
396
405
  * by the PAIR (`createdAt`, `movementId`); this field alone cannot rebuild
@@ -783,10 +792,21 @@ declare global {
783
792
  /**
784
793
  * Units actually RECEIVED at the destination so far.
785
794
  *
786
- * ⚠️ A PROJECTION, not the authority. The authority is the set of
787
- * `transfer_in` movements carrying this transfer's id and this line's index;
788
- * this field exists so the transfer renders without a ledger walk. When the
789
- * two disagree, the ledger is right.
795
+ * ⚠️ A PROJECTION maintained by compare-and-set, and the per-line AUTHORITY.
796
+ *
797
+ * ⚠️ This previously said the authority was "the set of `transfer_in`
798
+ * movements carrying this transfer's id and this line's index". That is not
799
+ * implementable and must not be restored: `StockMovement` declares **no
800
+ * line-index attribute**, and its `referenceId` must equal the transfer id
801
+ * exactly, so there is nowhere to put the index. The line survives only
802
+ * inside the derived `movementId` string, recoverable by parse, never by
803
+ * query.
804
+ *
805
+ * So the document is what a reader trusts, and it is safe to: each credit is
806
+ * written under a `ConditionExpression` pinning this field's prior value, so
807
+ * a concurrent second credit of the same line is refused rather than
808
+ * silently doubled. The ledger remains the record of what physically moved;
809
+ * it simply cannot be queried per line.
790
810
  *
791
811
  * ⚠️ Absent means nothing has arrived. A value BELOW `quantity` on a closed
792
812
  * transfer is stock that left and never landed — a real loss that needs its
@@ -796,6 +816,40 @@ declare global {
796
816
  /** The batch these units moved as, on a lot-tracked product. */
797
817
  lotId?: string;
798
818
  }
819
+ /**
820
+ * ONE receipt that actually landed — what a caller must not re-present.
821
+ *
822
+ * Returned by the receive endpoint on success, and — this is the part that
823
+ * matters — carried on the 409 that refuses a LATER line of the same call.
824
+ * Receipts are applied sequentially and the call stops at the first refusal,
825
+ * so the ones already in this array are durable: the ledger holds their
826
+ * `transfer_in` and the document holds their credited `receivedQuantity`.
827
+ *
828
+ * ⚠️ **A client that discards this array re-presents work that is already
829
+ * done**, against a prior quantity that has moved — which the compare-and-set
830
+ * then refuses again, so the transfer appears stuck rather than partly
831
+ * received. Fold every entry into the local row before re-reading.
832
+ *
833
+ * ⚠️ `lineIndex` is the ARRAY INDEX of the line in `StockTransfer.items`,
834
+ * never a `productId` — see {@link TransferItem}.
835
+ */
836
+ interface AppliedTransferReceipt {
837
+ lineIndex: number;
838
+ /** Units credited by THIS receipt — not a running total. */
839
+ quantity: number;
840
+ /** The line's `receivedQuantity` AFTER the credit. */
841
+ receivedQuantity: number;
842
+ /**
843
+ * The derived idempotency key the `transfer_in` was written under.
844
+ *
845
+ * ⚠️ The only place the ledger records which LINE an arrival belongs to —
846
+ * `StockMovement` has no line-index attribute. Recoverable by parse, never
847
+ * by query.
848
+ */
849
+ movementId: string;
850
+ /** True when the ledger half was already there and only the projection moved. */
851
+ replayed: boolean;
852
+ }
799
853
  /**
800
854
  * How a multi-location store chooses which warehouse fills a line.
801
855
  *
package/dist/lot.d.ts CHANGED
@@ -104,6 +104,40 @@ declare global {
104
104
  notes?: string;
105
105
  /** Soft delete. A lot is never hard-deleted: movement rows reference `lotId` permanently. */
106
106
  disabled?: boolean;
107
+ /**
108
+ * The sparse FEFO expiry index's partition value — `LOT#{storeId}`.
109
+ *
110
+ * ⚠️ **OPTIONAL, and the optionality is load-bearing.** Only a lot carrying
111
+ * an `expiryDate` is stamped with this and {@link Lot.expiryRef} — a lot with
112
+ * no expiry (a serialised component batch, traceability-only stock) must be
113
+ * ABSENT from the index rather than present with an invented sentinel. A
114
+ * required field here would force every writer to invent one, and every
115
+ * undated lot would then enter the expiry sweep as if it were about to go
116
+ * bad. Written and cleared together with {@link Lot.expiryRef} — the two
117
+ * always change as a pair; nothing may set one without the other.
118
+ */
119
+ expiryKey?: string;
120
+ /**
121
+ * The sparse FEFO expiry index's sort value —
122
+ * `{expiryDate zero-padded}#{productId}#{lotId}`.
123
+ *
124
+ * ⚠️ **OPTIONAL for the same reason {@link Lot.expiryKey} is, and the two are
125
+ * one unit.** Absent on every lot with no `expiryDate`; present only
126
+ * alongside `expiryKey`. The date is zero-padded so the sort key compares
127
+ * correctly as a STRING — DynamoDB orders an `S` sort key lexicographically,
128
+ * and an unpadded number would put `99999999` before `100000000` the moment
129
+ * the digit count changed. `productId` and `lotId` are appended only to keep
130
+ * the key unique per lot; `storeId` is deliberately NOT in this value — the
131
+ * partition (`expiryKey`) already carries it, the same reasoning
132
+ * `inventoryLevelWarehouseRef` states for its own sort value.
133
+ */
134
+ expiryRef?: string;
135
+ /**
136
+ * Lowercase '#'-joined write-side index over `lotCode`/`notes`. Internal;
137
+ * not part of the read contract — rebuilt by the service on every insert
138
+ * and update, same convention as `Warehouse.search`.
139
+ */
140
+ search?: string;
107
141
  }
108
142
  }
109
143
  export {};
package/dist/socket.d.ts CHANGED
@@ -26,7 +26,7 @@
26
26
  * A client must ignore actions it does not own rather than assume it
27
27
  * receives all of them.
28
28
  */
29
- export declare const SOCKET_ACTIONS: readonly ["account", "appointments", "appointmentWaitlist", "attendance", "automation-rules", "baskets", "cart", "brands", "cash", "categories", "campaigns", "customers", "deliveries", "globals", "invoices", "literals", "loyalty", "orders", "presupuestos", "products", "promotions", "segments", "returns", "rma", "templates", "services", "service-templates", "shifts", "stores", "suppliers", "supplier-invoice", "support", "surveys", "users", "warehouses", "favorites", "webhooks", "account-delete", "baskets-delete", "cart-delete", "log-delete", "notifications", "support-message", "whatsapp-message", "payment_received", "payment_linked", "payment_unlinked", "mercadopago", "mercadopago_dynamic_qr_created", "mercadopago_static_qr_created", "mp_hook_log_appended", "mp_ipn_log_appended", "stripe", "subscription", "caea", "print", "print-order", "print-invoice", "print-product", "print-tag", "print_job_failed", "request_printers", "printers_changed", "agent_status_changed", "print_rules_changed", "printers_active", "agent_command", "maintenance", "currency_auto_updated", "drain_progress", "integration_event_appended", "userActivityRecorded", "mercadolibre_settlement_period", "customDomain", "purchaseOrders", "cycleCounts"];
29
+ export declare const SOCKET_ACTIONS: readonly ["account", "appointments", "appointmentWaitlist", "attendance", "automation-rules", "baskets", "cart", "brands", "cash", "categories", "campaigns", "customers", "deliveries", "globals", "inventory", "invoices", "literals", "loyalty", "orders", "presupuestos", "products", "promotions", "segments", "returns", "rma", "templates", "services", "service-templates", "shifts", "stores", "suppliers", "supplier-invoice", "support", "surveys", "users", "warehouses", "favorites", "webhooks", "account-delete", "baskets-delete", "cart-delete", "log-delete", "notifications", "support-message", "whatsapp-message", "payment_received", "payment_linked", "payment_unlinked", "mercadopago", "mercadopago_dynamic_qr_created", "mercadopago_static_qr_created", "mp_hook_log_appended", "mp_ipn_log_appended", "stripe", "subscription", "caea", "print", "print-order", "print-invoice", "print-product", "print-tag", "print_job_failed", "request_printers", "printers_changed", "agent_status_changed", "print_rules_changed", "printers_active", "agent_command", "maintenance", "currency_auto_updated", "drain_progress", "integration_event_appended", "userActivityRecorded", "mercadolibre_settlement_period", "customDomain", "purchaseOrders", "cycleCounts", "stockTransfers"];
30
30
  /** Union of every server→client data-frame action. */
31
31
  export type SocketAction = (typeof SOCKET_ACTIONS)[number];
32
32
  /**
package/dist/socket.js CHANGED
@@ -140,6 +140,69 @@ export const SOCKET_ACTIONS = [
140
140
  */
141
141
  'deliveries',
142
142
  'globals',
143
+ /**
144
+ * BE → the store's OPERATOR sockets when a per-location stock balance moves.
145
+ * `data` is ONE whole `InventoryLevel` row — the post-write balance of a
146
+ * single product×warehouse cell, read back consistently by the service that
147
+ * moved it.
148
+ *
149
+ * ⚠️ **Always a FULL row, never a patch — unlike `products`, which sends
150
+ * both shapes.** `InventoryLevel` has no fields beyond the ones on this
151
+ * frame, so a client MAY insert a cell it has never seen; merging a
152
+ * {@link ProductStockFrameData} patch over an unknown product, by contrast,
153
+ * would mint an entity with no name or price.
154
+ *
155
+ * ⚠️ **This frame and a `products` stock frame are two different books and
156
+ * neither implies the other.** Per-location balances move only on the
157
+ * explicit inventory operations; the order and marketplace paths move
158
+ * store-wide `Product.stock` and emit `products`. A client must not reconcile
159
+ * one against the other, and the absence of one says nothing about the other.
160
+ *
161
+ * ⚠️ **ONE FRAME PER CELL, and `data` is never an array.** A movement that
162
+ * touches N locations sends N independent frames — a transfer sends two, the
163
+ * origin and the destination — and each is complete on its own. They may
164
+ * arrive in either order and either may be lost without invalidating the
165
+ * other.
166
+ *
167
+ * ⚠️ **`warehouseId` AND `productId` together are the identity; neither
168
+ * alone places the frame.** A store broadcast carries no audience selector
169
+ * and one product holds a separate balance at every location it has traded
170
+ * at, so a client keyed on `productId` alone overwrites one location's stock
171
+ * with another's — the failure is silent and looks like stock teleporting
172
+ * between depósitos.
173
+ *
174
+ * ⚠️ **`version` is the staleness discriminator and a client MUST use it.**
175
+ * Delivery is best-effort and unordered, so two movements against one cell
176
+ * can arrive newest-first; apply a frame only when its `version` exceeds the
177
+ * one already held for that cell. The counter is per-cell, not per-store.
178
+ * A REPLAYED write — a repeated `movementId`, which commits nothing —
179
+ * broadcasts too: the balances are re-read, so the frame restates a true
180
+ * cell rather than announcing a second movement, and this rule is what makes
181
+ * that duplicate a no-op.
182
+ *
183
+ * ⚠️ Operator-only — `wsPostStore(..., { audience: 'operator' })`, never the
184
+ * `'operator-and-customer'` that `dynamoUpdate`'s automatic broadcast
185
+ * hardcodes. The row carries `avgCost` and `costLayers` — what the store
186
+ * paid, which is merchant margin under another name — and `scrubForCustomer`
187
+ * knows nothing about this entity, so nothing would be stripped from a
188
+ * customer copy. `InventoryLevel` carries no `customerId`, which would make
189
+ * the customer leg a no-op query rather than a leak, but the audience is
190
+ * gated on the ENTITY'S SHAPE rather than on that accident, per
191
+ * `'cycleCounts'` below.
192
+ *
193
+ * ⚠️ The ledger row is NOT on this frame. A `StockMovement` is immutable
194
+ * history carrying the acting `userId` and a free-text `note`, and one call
195
+ * writes up to one per leg; a client that needs it reads
196
+ * `GET /inventory?mode=movements`.
197
+ *
198
+ * The producer is the single write chokepoint of `POST /inventory`
199
+ * (`commitMovement` → `postInventoryLevelFrames`,
200
+ * `stacks/lambdas/inventory/`), covering every write mode: receipt,
201
+ * adjustment, write-off, transfer, reserve and release. The GET modes emit
202
+ * nothing, and `dynamoUpdate` is not involved at all — these rows live on the
203
+ * inventory satellite table, which no generic row writer touches.
204
+ */
205
+ 'inventory',
143
206
  'invoices',
144
207
  'literals',
145
208
  /**
@@ -414,6 +477,34 @@ export const SOCKET_ACTIONS = [
414
477
  * wrong entity in both places.
415
478
  */
416
479
  'cycleCounts',
480
+ /**
481
+ * BE → the store's OPERATOR sockets on every stock-transfer write: create,
482
+ * dispatch, a per-line arrival, close and cancel. Carries the full
483
+ * `StockTransfer` row, mirroring how `'cycleCounts'` carries the session.
484
+ *
485
+ * ⚠️ Operator-only — `wsPostStore(..., { audience: 'operator' })`, never the
486
+ * `'operator-and-customer'` that `dynamoUpdate`'s automatic broadcast
487
+ * hardcodes. Every write in this domain therefore passes `silent: true` and
488
+ * re-broadcasts through one chokepoint. `StockTransfer` carries no
489
+ * `customerId`, so the customer leg would be a no-op query rather than a
490
+ * leak — state the audience anyway: the safety is a property of today's
491
+ * shape, and a later field would silently turn a no-op into a fan-out. It is
492
+ * gated on the ENTITY'S SHAPE rather than on that accident, because the row
493
+ * carries operator prose (`notes`, which the entity says is never scrubbed
494
+ * and has no TTL) and an internal view of where a store keeps its stock.
495
+ *
496
+ * ⚠️ Declared for the REST surface too, not only the socket:
497
+ * `dynamoUpdate`'s `action` is interpolated into the success message and
498
+ * into the cross-tenant guard's audit label, neither of which `silent`
499
+ * gates — so a writer with no action of its own has to borrow one, and the
500
+ * borrowed name then names the wrong entity in both places.
501
+ *
502
+ * ⚠️ A `received` transfer does NOT mean received equals sent — operators
503
+ * close short arrivals, and the difference is a loss that needs its own
504
+ * adjustment. A client must read the line quantities rather than inferring
505
+ * completeness from the status.
506
+ */
507
+ 'stockTransfers',
417
508
  ];
418
509
  /** Runtime guard — narrows an untrusted string to a known action. */
419
510
  export const isSocketAction = (value) => typeof value === 'string' && SOCKET_ACTIONS.includes(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.301",
3
+ "version": "1.10.303",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",