sinfactura-types 1.10.284 → 1.10.285

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.
@@ -18,7 +18,7 @@
18
18
  * Nothing posts to a connection directly.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.isSocketKeepAlive = exports.SOCKET_KEEPALIVE = exports.SOCKET_AUTH_FAIL_REASONS = exports.LIVE_CLIENT_SOCKET_ACTIONS = exports.CLIENT_SOCKET_ACTIONS = exports.DESTRUCTIVE_AGENT_COMMANDS = exports.isAgentCommand = exports.AGENT_COMMANDS = exports.isSocketAction = exports.SOCKET_ACTIONS = void 0;
21
+ exports.isSocketKeepAlive = exports.SOCKET_KEEPALIVE = exports.SOCKET_AUTH_FAIL_REASONS = exports.LIVE_CLIENT_SOCKET_ACTIONS = exports.CLIENT_SOCKET_ACTIONS = exports.DESTRUCTIVE_AGENT_COMMANDS = exports.isAgentCommand = exports.AGENT_COMMANDS = exports.PRODUCT_STOCK_FRAME_FIELDS = exports.isSocketAction = exports.SOCKET_ACTIONS = void 0;
22
22
  /* -------------------------------------------------------------------------- */
23
23
  /* Server → client data frames */
24
24
  /* -------------------------------------------------------------------------- */
@@ -138,6 +138,36 @@ exports.SOCKET_ACTIONS = [
138
138
  */
139
139
  'loyalty',
140
140
  'orders',
141
+ /**
142
+ * A product row changed. Sent in TWO shapes, and a consumer must handle both
143
+ * — see {@link ProductStockFrameData}.
144
+ *
145
+ * 1. **Full row** — the whole `Product`. Sent by the paths that create or
146
+ * re-state a row: `products/_post.ts` (create, edit, disable),
147
+ * `_postStock.ts`, `_postStockAdjust.ts` and
148
+ * `mercadolibre/_matchSuggestions.ts`. A session catalogue INSERTS on this
149
+ * shape. ⚠️ The product CSV import does NOT send it — announcing an import
150
+ * means one frame per row, which does not fit that handler's 29s ceiling
151
+ * until `wsPostStore` grows a batched fan-out; see `products/_import.ts`.
152
+ * 2. **Partial projection** — {@link ProductStockFrameData}, sent by the
153
+ * paths that only move stock: order create (operator and storefront),
154
+ * order edit, void and return, the web cancel, and MercadoLibre inbound
155
+ * stock apply/reverse. A session catalogue PATCHES on this shape and must
156
+ * not treat it as a whole row.
157
+ *
158
+ * ⚠️ The partial shape is a PATCH, and `productId` is the only field
159
+ * guaranteed to identify it. Merging it over a row the client does not hold
160
+ * yet would mint a product with no name or price; the correct handling is to
161
+ * ignore a patch for an unknown id and let the next full read supply it.
162
+ *
163
+ * ⚠️ Audience differs per path and is not derivable from the frame. The
164
+ * order edit, void, return and web-cancel paths reach customer sockets too
165
+ * (`wsPostStoreCustomers`, which suppresses a row by reading
166
+ * `hiddenFromStorefront` off the payload); order create and MercadoLibre
167
+ * stock are operator-only. A customer's copy is
168
+ * `scrubForCustomer`'d, so `cost` is absent there — never rely on its
169
+ * presence to tell the shapes apart.
170
+ */
141
171
  'products',
142
172
  /**
143
173
  * A promotion created, updated or retired. Operator-only —
@@ -353,6 +383,38 @@ exports.SOCKET_ACTIONS = [
353
383
  /** Runtime guard — narrows an untrusted string to a known action. */
354
384
  const isSocketAction = (value) => typeof value === 'string' && exports.SOCKET_ACTIONS.includes(value);
355
385
  exports.isSocketAction = isSocketAction;
386
+ /**
387
+ * The fields a stock-moving write announces, as a RUNTIME tuple.
388
+ *
389
+ * ⚠️ This is the single source of truth, and it is a tuple rather than a
390
+ * hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
391
+ * the api builds its `ProjectionExpression` by joining THIS array
392
+ * (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
393
+ * {@link ProductStockFrameData} derives its keys from it, so the projection
394
+ * that reads the row and the type describing what the FEs receive cannot
395
+ * disagree. Two independently typed lists is exactly the drift this shape
396
+ * exists to prevent — a field added to one and not the other is invisible to
397
+ * `typecheck`, to lint and to any test that compares one against a literal.
398
+ *
399
+ * ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
400
+ * only moves the second — `movementStamp` writes `lastMovementAt`, never
401
+ * `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
402
+ * it stand still across a whole day of sales; order by `lastMovementAt`, or do
403
+ * not order these frames at all.
404
+ *
405
+ * ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
406
+ * no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
407
+ * `size`, `name`, …) breaks every read at once — alias it at the join site.
408
+ */
409
+ exports.PRODUCT_STOCK_FRAME_FIELDS = [
410
+ 'stock',
411
+ 'prices',
412
+ 'cost',
413
+ 'currency',
414
+ 'hiddenFromStorefront',
415
+ 'updatedAt',
416
+ 'lastMovementAt',
417
+ ];
356
418
  /* -------------------------------------------------------------------------- */
357
419
  /* Agent diagnostic commands */
358
420
  /* -------------------------------------------------------------------------- */
package/dist/socket.d.ts CHANGED
@@ -63,6 +63,45 @@ export interface SocketMessage<T = unknown> {
63
63
  action: SocketAction;
64
64
  data: T;
65
65
  }
66
+ /**
67
+ * The fields a stock-moving write announces, as a RUNTIME tuple.
68
+ *
69
+ * ⚠️ This is the single source of truth, and it is a tuple rather than a
70
+ * hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
71
+ * the api builds its `ProjectionExpression` by joining THIS array
72
+ * (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
73
+ * {@link ProductStockFrameData} derives its keys from it, so the projection
74
+ * that reads the row and the type describing what the FEs receive cannot
75
+ * disagree. Two independently typed lists is exactly the drift this shape
76
+ * exists to prevent — a field added to one and not the other is invisible to
77
+ * `typecheck`, to lint and to any test that compares one against a literal.
78
+ *
79
+ * ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
80
+ * only moves the second — `movementStamp` writes `lastMovementAt`, never
81
+ * `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
82
+ * it stand still across a whole day of sales; order by `lastMovementAt`, or do
83
+ * not order these frames at all.
84
+ *
85
+ * ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
86
+ * no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
87
+ * `size`, `name`, …) breaks every read at once — alias it at the join site.
88
+ */
89
+ export declare const PRODUCT_STOCK_FRAME_FIELDS: readonly ["stock", "prices", "cost", "currency", "hiddenFromStorefront", "updatedAt", "lastMovementAt"];
90
+ /**
91
+ * `data` of a **partial** `products` frame — the projection every stock-moving
92
+ * write announces, and the only `products` shape that is not a whole `Product`.
93
+ *
94
+ * ⚠️ `cost` is merchant margin. It is present on the operator copy and removed
95
+ * from the customer copy by `scrubForCustomer`, so it is optional HERE for that
96
+ * reason alone — not because the operator path ever omits it.
97
+ *
98
+ * ⚠️ Every projected field is optional except the two identity keys, because
99
+ * DynamoDB projects only the attributes a row actually carries: a product with
100
+ * no price list has no `prices`, and one that has never moved has no
101
+ * `lastMovementAt`. Absent means "not set on the row", never "unchanged".
102
+ */
103
+ export interface ProductStockFrameData extends Pick<Product, 'storeId' | 'productId'>, Partial<Pick<Product, (typeof PRODUCT_STOCK_FRAME_FIELDS)[number]>> {
104
+ }
66
105
  /**
67
106
  * The `/logs` read mode a `log-delete` frame can refer to.
68
107
  *
package/dist/socket.js CHANGED
@@ -135,6 +135,36 @@ export const SOCKET_ACTIONS = [
135
135
  */
136
136
  'loyalty',
137
137
  'orders',
138
+ /**
139
+ * A product row changed. Sent in TWO shapes, and a consumer must handle both
140
+ * — see {@link ProductStockFrameData}.
141
+ *
142
+ * 1. **Full row** — the whole `Product`. Sent by the paths that create or
143
+ * re-state a row: `products/_post.ts` (create, edit, disable),
144
+ * `_postStock.ts`, `_postStockAdjust.ts` and
145
+ * `mercadolibre/_matchSuggestions.ts`. A session catalogue INSERTS on this
146
+ * shape. ⚠️ The product CSV import does NOT send it — announcing an import
147
+ * means one frame per row, which does not fit that handler's 29s ceiling
148
+ * until `wsPostStore` grows a batched fan-out; see `products/_import.ts`.
149
+ * 2. **Partial projection** — {@link ProductStockFrameData}, sent by the
150
+ * paths that only move stock: order create (operator and storefront),
151
+ * order edit, void and return, the web cancel, and MercadoLibre inbound
152
+ * stock apply/reverse. A session catalogue PATCHES on this shape and must
153
+ * not treat it as a whole row.
154
+ *
155
+ * ⚠️ The partial shape is a PATCH, and `productId` is the only field
156
+ * guaranteed to identify it. Merging it over a row the client does not hold
157
+ * yet would mint a product with no name or price; the correct handling is to
158
+ * ignore a patch for an unknown id and let the next full read supply it.
159
+ *
160
+ * ⚠️ Audience differs per path and is not derivable from the frame. The
161
+ * order edit, void, return and web-cancel paths reach customer sockets too
162
+ * (`wsPostStoreCustomers`, which suppresses a row by reading
163
+ * `hiddenFromStorefront` off the payload); order create and MercadoLibre
164
+ * stock are operator-only. A customer's copy is
165
+ * `scrubForCustomer`'d, so `cost` is absent there — never rely on its
166
+ * presence to tell the shapes apart.
167
+ */
138
168
  'products',
139
169
  /**
140
170
  * A promotion created, updated or retired. Operator-only —
@@ -349,6 +379,38 @@ export const SOCKET_ACTIONS = [
349
379
  ];
350
380
  /** Runtime guard — narrows an untrusted string to a known action. */
351
381
  export const isSocketAction = (value) => typeof value === 'string' && SOCKET_ACTIONS.includes(value);
382
+ /**
383
+ * The fields a stock-moving write announces, as a RUNTIME tuple.
384
+ *
385
+ * ⚠️ This is the single source of truth, and it is a tuple rather than a
386
+ * hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
387
+ * the api builds its `ProjectionExpression` by joining THIS array
388
+ * (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
389
+ * {@link ProductStockFrameData} derives its keys from it, so the projection
390
+ * that reads the row and the type describing what the FEs receive cannot
391
+ * disagree. Two independently typed lists is exactly the drift this shape
392
+ * exists to prevent — a field added to one and not the other is invisible to
393
+ * `typecheck`, to lint and to any test that compares one against a literal.
394
+ *
395
+ * ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
396
+ * only moves the second — `movementStamp` writes `lastMovementAt`, never
397
+ * `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
398
+ * it stand still across a whole day of sales; order by `lastMovementAt`, or do
399
+ * not order these frames at all.
400
+ *
401
+ * ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
402
+ * no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
403
+ * `size`, `name`, …) breaks every read at once — alias it at the join site.
404
+ */
405
+ export const PRODUCT_STOCK_FRAME_FIELDS = [
406
+ 'stock',
407
+ 'prices',
408
+ 'cost',
409
+ 'currency',
410
+ 'hiddenFromStorefront',
411
+ 'updatedAt',
412
+ 'lastMovementAt',
413
+ ];
352
414
  /* -------------------------------------------------------------------------- */
353
415
  /* Agent diagnostic commands */
354
416
  /* -------------------------------------------------------------------------- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinfactura-types",
3
- "version": "1.10.284",
3
+ "version": "1.10.285",
4
4
  "description": "Shared wire and entity contracts for the SINFACTURA platform.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",