sinfactura-types 1.10.284 → 1.10.286
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/cjs/socket.js +85 -1
- package/dist/socket.d.ts +76 -0
- package/dist/socket.js +84 -0
- package/package.json +1 -1
package/dist/cjs/socket.js
CHANGED
|
@@ -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
|
/* -------------------------------------------------------------------------- */
|
|
@@ -111,6 +111,28 @@ exports.SOCKET_ACTIONS = [
|
|
|
111
111
|
* silently turn a no-op into a fan-out.
|
|
112
112
|
*/
|
|
113
113
|
'campaigns',
|
|
114
|
+
/**
|
|
115
|
+
* A customer row created or updated. `data` is the LIST-VISIBLE projection
|
|
116
|
+
* of the row (`projectCustomerOperatorBroadcast`), never the raw CUSTOMER
|
|
117
|
+
* row — `scrubForCustomer` knows nothing about this entity, so that
|
|
118
|
+
* allow-list IS the scrub. ⚠️ **MOST paths send to the shopper's socket too.** Every
|
|
119
|
+
* `dynamoUpdate`-driven write echoes with `'operator-and-customer'`
|
|
120
|
+
* (hardcoded), and so do the money paths where a shopper watches their own
|
|
121
|
+
* balance move; `'operator'` alone is the newer minority — the `lastBuy`
|
|
122
|
+
* stamp, the CSV import, the MercadoLibre buyer, the avatar write. Do not
|
|
123
|
+
* read this frame as operator-only: the projection is the same either way,
|
|
124
|
+
* and a client that receives one it cannot place is expected to DROP it
|
|
125
|
+
* rather than treat arrival as membership.
|
|
126
|
+
*
|
|
127
|
+
* ⚠️ **TWO shapes, discriminated by the PRESENCE of `customerId`.** The
|
|
128
|
+
* per-row frame carries it. The bulk-import frame is `CustomersRefetchData`
|
|
129
|
+
* — `{ refetch: true }`, no id and no customer data at all, meaning "drop
|
|
130
|
+
* the cached customer list and refetch it". The CSV import sends per-row
|
|
131
|
+
* frames up to a small created-row cap and exactly ONE refetch frame above
|
|
132
|
+
* it, because one SQS send per created row is unaffordable at import scale.
|
|
133
|
+
* See `CustomersRefetchData` for why a consumer that does not know the
|
|
134
|
+
* second shape degrades quietly rather than wrongly.
|
|
135
|
+
*/
|
|
114
136
|
'customers',
|
|
115
137
|
/**
|
|
116
138
|
* A delivery created, or an event appended to its timeline. Operator-only —
|
|
@@ -138,6 +160,36 @@ exports.SOCKET_ACTIONS = [
|
|
|
138
160
|
*/
|
|
139
161
|
'loyalty',
|
|
140
162
|
'orders',
|
|
163
|
+
/**
|
|
164
|
+
* A product row changed. Sent in TWO shapes, and a consumer must handle both
|
|
165
|
+
* — see {@link ProductStockFrameData}.
|
|
166
|
+
*
|
|
167
|
+
* 1. **Full row** — the whole `Product`. Sent by the paths that create or
|
|
168
|
+
* re-state a row: `products/_post.ts` (create, edit, disable),
|
|
169
|
+
* `_postStock.ts`, `_postStockAdjust.ts` and
|
|
170
|
+
* `mercadolibre/_matchSuggestions.ts`. A session catalogue INSERTS on this
|
|
171
|
+
* shape. ⚠️ The product CSV import does NOT send it — announcing an import
|
|
172
|
+
* means one frame per row, which does not fit that handler's 29s ceiling
|
|
173
|
+
* until `wsPostStore` grows a batched fan-out; see `products/_import.ts`.
|
|
174
|
+
* 2. **Partial projection** — {@link ProductStockFrameData}, sent by the
|
|
175
|
+
* paths that only move stock: order create (operator and storefront),
|
|
176
|
+
* order edit, void and return, the web cancel, and MercadoLibre inbound
|
|
177
|
+
* stock apply/reverse. A session catalogue PATCHES on this shape and must
|
|
178
|
+
* not treat it as a whole row.
|
|
179
|
+
*
|
|
180
|
+
* ⚠️ The partial shape is a PATCH, and `productId` is the only field
|
|
181
|
+
* guaranteed to identify it. Merging it over a row the client does not hold
|
|
182
|
+
* yet would mint a product with no name or price; the correct handling is to
|
|
183
|
+
* ignore a patch for an unknown id and let the next full read supply it.
|
|
184
|
+
*
|
|
185
|
+
* ⚠️ Audience differs per path and is not derivable from the frame. The
|
|
186
|
+
* order edit, void, return and web-cancel paths reach customer sockets too
|
|
187
|
+
* (`wsPostStoreCustomers`, which suppresses a row by reading
|
|
188
|
+
* `hiddenFromStorefront` off the payload); order create and MercadoLibre
|
|
189
|
+
* stock are operator-only. A customer's copy is
|
|
190
|
+
* `scrubForCustomer`'d, so `cost` is absent there — never rely on its
|
|
191
|
+
* presence to tell the shapes apart.
|
|
192
|
+
*/
|
|
141
193
|
'products',
|
|
142
194
|
/**
|
|
143
195
|
* A promotion created, updated or retired. Operator-only —
|
|
@@ -353,6 +405,38 @@ exports.SOCKET_ACTIONS = [
|
|
|
353
405
|
/** Runtime guard — narrows an untrusted string to a known action. */
|
|
354
406
|
const isSocketAction = (value) => typeof value === 'string' && exports.SOCKET_ACTIONS.includes(value);
|
|
355
407
|
exports.isSocketAction = isSocketAction;
|
|
408
|
+
/**
|
|
409
|
+
* The fields a stock-moving write announces, as a RUNTIME tuple.
|
|
410
|
+
*
|
|
411
|
+
* ⚠️ This is the single source of truth, and it is a tuple rather than a
|
|
412
|
+
* hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
|
|
413
|
+
* the api builds its `ProjectionExpression` by joining THIS array
|
|
414
|
+
* (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
|
|
415
|
+
* {@link ProductStockFrameData} derives its keys from it, so the projection
|
|
416
|
+
* that reads the row and the type describing what the FEs receive cannot
|
|
417
|
+
* disagree. Two independently typed lists is exactly the drift this shape
|
|
418
|
+
* exists to prevent — a field added to one and not the other is invisible to
|
|
419
|
+
* `typecheck`, to lint and to any test that compares one against a literal.
|
|
420
|
+
*
|
|
421
|
+
* ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
|
|
422
|
+
* only moves the second — `movementStamp` writes `lastMovementAt`, never
|
|
423
|
+
* `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
|
|
424
|
+
* it stand still across a whole day of sales; order by `lastMovementAt`, or do
|
|
425
|
+
* not order these frames at all.
|
|
426
|
+
*
|
|
427
|
+
* ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
|
|
428
|
+
* no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
|
|
429
|
+
* `size`, `name`, …) breaks every read at once — alias it at the join site.
|
|
430
|
+
*/
|
|
431
|
+
exports.PRODUCT_STOCK_FRAME_FIELDS = [
|
|
432
|
+
'stock',
|
|
433
|
+
'prices',
|
|
434
|
+
'cost',
|
|
435
|
+
'currency',
|
|
436
|
+
'hiddenFromStorefront',
|
|
437
|
+
'updatedAt',
|
|
438
|
+
'lastMovementAt',
|
|
439
|
+
];
|
|
356
440
|
/* -------------------------------------------------------------------------- */
|
|
357
441
|
/* Agent diagnostic commands */
|
|
358
442
|
/* -------------------------------------------------------------------------- */
|
package/dist/socket.d.ts
CHANGED
|
@@ -49,6 +49,43 @@ export interface CustomDomainSocketPayload {
|
|
|
49
49
|
error?: string;
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* `data` of the BULK-IMPORT `customers` frame: "drop your cached customer list
|
|
54
|
+
* and refetch it". Audience `'operator'` — a customer holds no operator
|
|
55
|
+
* customer list, and the frame names no customer to address.
|
|
56
|
+
*
|
|
57
|
+
* The CSV import can create ~10,000 customers in one request, and a projected
|
|
58
|
+
* frame per created row is an SQS send per created row on a handler already
|
|
59
|
+
* near the 29s Lambda ceiling. So the import sends per-row frames only up to a
|
|
60
|
+
* small created-row cap and exactly one of these above it. ⚠️ The cap lives
|
|
61
|
+
* with the producer and is deliberately NOT restated here: it is a cost
|
|
62
|
+
* threshold that will be tuned, and a number on the wire contract would be
|
|
63
|
+
* read as one a consumer may rely on.
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ **Carries no `customerId` and no customer fields whatsoever**, and that
|
|
66
|
+
* emptiness is what makes it safe to fan out to every operator socket on the
|
|
67
|
+
* store no matter what the import contained — there is nothing on it to scope,
|
|
68
|
+
* scrub or disclose. Keep it that way: adding even a list of created ids turns
|
|
69
|
+
* a refetch signal back into a payload with an audience decision behind it.
|
|
70
|
+
*
|
|
71
|
+
* ⚠️ **Discriminate on the ABSENCE of `customerId`**, the same split
|
|
72
|
+
* `LogDeleteAllData` makes against `LogDeleteOneData`. `refetch` is the
|
|
73
|
+
* positive spelling of that one discriminator, never a second axis.
|
|
74
|
+
*
|
|
75
|
+
* ⚠️ **A consumer that does not yet know this shape degrades to the old
|
|
76
|
+
* behaviour SILENTLY.** `app` drops a `customers` frame carrying no
|
|
77
|
+
* `customerId` — it has no row to place — so until it handles this one, an
|
|
78
|
+
* over-cap import leaves the cached list stale exactly as it was before this
|
|
79
|
+
* frame existed. That fallback is intended: stale, never wrong. It is also the
|
|
80
|
+
* first thing to check when an over-cap import "sends nothing".
|
|
81
|
+
*/
|
|
82
|
+
export interface CustomersRefetchData {
|
|
83
|
+
/**
|
|
84
|
+
* Literal `true`, so the shape cannot be spelled `{ refetch: false }` —
|
|
85
|
+
* "no refetch needed" is a frame that was never sent, not a field value.
|
|
86
|
+
*/
|
|
87
|
+
refetch: true;
|
|
88
|
+
}
|
|
52
89
|
/** Runtime guard — narrows an untrusted string to a known action. */
|
|
53
90
|
export declare const isSocketAction: (value: unknown) => value is SocketAction;
|
|
54
91
|
/**
|
|
@@ -63,6 +100,45 @@ export interface SocketMessage<T = unknown> {
|
|
|
63
100
|
action: SocketAction;
|
|
64
101
|
data: T;
|
|
65
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* The fields a stock-moving write announces, as a RUNTIME tuple.
|
|
105
|
+
*
|
|
106
|
+
* ⚠️ This is the single source of truth, and it is a tuple rather than a
|
|
107
|
+
* hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
|
|
108
|
+
* the api builds its `ProjectionExpression` by joining THIS array
|
|
109
|
+
* (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
|
|
110
|
+
* {@link ProductStockFrameData} derives its keys from it, so the projection
|
|
111
|
+
* that reads the row and the type describing what the FEs receive cannot
|
|
112
|
+
* disagree. Two independently typed lists is exactly the drift this shape
|
|
113
|
+
* exists to prevent — a field added to one and not the other is invisible to
|
|
114
|
+
* `typecheck`, to lint and to any test that compares one against a literal.
|
|
115
|
+
*
|
|
116
|
+
* ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
|
|
117
|
+
* only moves the second — `movementStamp` writes `lastMovementAt`, never
|
|
118
|
+
* `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
|
|
119
|
+
* it stand still across a whole day of sales; order by `lastMovementAt`, or do
|
|
120
|
+
* not order these frames at all.
|
|
121
|
+
*
|
|
122
|
+
* ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
|
|
123
|
+
* no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
|
|
124
|
+
* `size`, `name`, …) breaks every read at once — alias it at the join site.
|
|
125
|
+
*/
|
|
126
|
+
export declare const PRODUCT_STOCK_FRAME_FIELDS: readonly ["stock", "prices", "cost", "currency", "hiddenFromStorefront", "updatedAt", "lastMovementAt"];
|
|
127
|
+
/**
|
|
128
|
+
* `data` of a **partial** `products` frame — the projection every stock-moving
|
|
129
|
+
* write announces, and the only `products` shape that is not a whole `Product`.
|
|
130
|
+
*
|
|
131
|
+
* ⚠️ `cost` is merchant margin. It is present on the operator copy and removed
|
|
132
|
+
* from the customer copy by `scrubForCustomer`, so it is optional HERE for that
|
|
133
|
+
* reason alone — not because the operator path ever omits it.
|
|
134
|
+
*
|
|
135
|
+
* ⚠️ Every projected field is optional except the two identity keys, because
|
|
136
|
+
* DynamoDB projects only the attributes a row actually carries: a product with
|
|
137
|
+
* no price list has no `prices`, and one that has never moved has no
|
|
138
|
+
* `lastMovementAt`. Absent means "not set on the row", never "unchanged".
|
|
139
|
+
*/
|
|
140
|
+
export interface ProductStockFrameData extends Pick<Product, 'storeId' | 'productId'>, Partial<Pick<Product, (typeof PRODUCT_STOCK_FRAME_FIELDS)[number]>> {
|
|
141
|
+
}
|
|
66
142
|
/**
|
|
67
143
|
* The `/logs` read mode a `log-delete` frame can refer to.
|
|
68
144
|
*
|
package/dist/socket.js
CHANGED
|
@@ -108,6 +108,28 @@ export const SOCKET_ACTIONS = [
|
|
|
108
108
|
* silently turn a no-op into a fan-out.
|
|
109
109
|
*/
|
|
110
110
|
'campaigns',
|
|
111
|
+
/**
|
|
112
|
+
* A customer row created or updated. `data` is the LIST-VISIBLE projection
|
|
113
|
+
* of the row (`projectCustomerOperatorBroadcast`), never the raw CUSTOMER
|
|
114
|
+
* row — `scrubForCustomer` knows nothing about this entity, so that
|
|
115
|
+
* allow-list IS the scrub. ⚠️ **MOST paths send to the shopper's socket too.** Every
|
|
116
|
+
* `dynamoUpdate`-driven write echoes with `'operator-and-customer'`
|
|
117
|
+
* (hardcoded), and so do the money paths where a shopper watches their own
|
|
118
|
+
* balance move; `'operator'` alone is the newer minority — the `lastBuy`
|
|
119
|
+
* stamp, the CSV import, the MercadoLibre buyer, the avatar write. Do not
|
|
120
|
+
* read this frame as operator-only: the projection is the same either way,
|
|
121
|
+
* and a client that receives one it cannot place is expected to DROP it
|
|
122
|
+
* rather than treat arrival as membership.
|
|
123
|
+
*
|
|
124
|
+
* ⚠️ **TWO shapes, discriminated by the PRESENCE of `customerId`.** The
|
|
125
|
+
* per-row frame carries it. The bulk-import frame is `CustomersRefetchData`
|
|
126
|
+
* — `{ refetch: true }`, no id and no customer data at all, meaning "drop
|
|
127
|
+
* the cached customer list and refetch it". The CSV import sends per-row
|
|
128
|
+
* frames up to a small created-row cap and exactly ONE refetch frame above
|
|
129
|
+
* it, because one SQS send per created row is unaffordable at import scale.
|
|
130
|
+
* See `CustomersRefetchData` for why a consumer that does not know the
|
|
131
|
+
* second shape degrades quietly rather than wrongly.
|
|
132
|
+
*/
|
|
111
133
|
'customers',
|
|
112
134
|
/**
|
|
113
135
|
* A delivery created, or an event appended to its timeline. Operator-only —
|
|
@@ -135,6 +157,36 @@ export const SOCKET_ACTIONS = [
|
|
|
135
157
|
*/
|
|
136
158
|
'loyalty',
|
|
137
159
|
'orders',
|
|
160
|
+
/**
|
|
161
|
+
* A product row changed. Sent in TWO shapes, and a consumer must handle both
|
|
162
|
+
* — see {@link ProductStockFrameData}.
|
|
163
|
+
*
|
|
164
|
+
* 1. **Full row** — the whole `Product`. Sent by the paths that create or
|
|
165
|
+
* re-state a row: `products/_post.ts` (create, edit, disable),
|
|
166
|
+
* `_postStock.ts`, `_postStockAdjust.ts` and
|
|
167
|
+
* `mercadolibre/_matchSuggestions.ts`. A session catalogue INSERTS on this
|
|
168
|
+
* shape. ⚠️ The product CSV import does NOT send it — announcing an import
|
|
169
|
+
* means one frame per row, which does not fit that handler's 29s ceiling
|
|
170
|
+
* until `wsPostStore` grows a batched fan-out; see `products/_import.ts`.
|
|
171
|
+
* 2. **Partial projection** — {@link ProductStockFrameData}, sent by the
|
|
172
|
+
* paths that only move stock: order create (operator and storefront),
|
|
173
|
+
* order edit, void and return, the web cancel, and MercadoLibre inbound
|
|
174
|
+
* stock apply/reverse. A session catalogue PATCHES on this shape and must
|
|
175
|
+
* not treat it as a whole row.
|
|
176
|
+
*
|
|
177
|
+
* ⚠️ The partial shape is a PATCH, and `productId` is the only field
|
|
178
|
+
* guaranteed to identify it. Merging it over a row the client does not hold
|
|
179
|
+
* yet would mint a product with no name or price; the correct handling is to
|
|
180
|
+
* ignore a patch for an unknown id and let the next full read supply it.
|
|
181
|
+
*
|
|
182
|
+
* ⚠️ Audience differs per path and is not derivable from the frame. The
|
|
183
|
+
* order edit, void, return and web-cancel paths reach customer sockets too
|
|
184
|
+
* (`wsPostStoreCustomers`, which suppresses a row by reading
|
|
185
|
+
* `hiddenFromStorefront` off the payload); order create and MercadoLibre
|
|
186
|
+
* stock are operator-only. A customer's copy is
|
|
187
|
+
* `scrubForCustomer`'d, so `cost` is absent there — never rely on its
|
|
188
|
+
* presence to tell the shapes apart.
|
|
189
|
+
*/
|
|
138
190
|
'products',
|
|
139
191
|
/**
|
|
140
192
|
* A promotion created, updated or retired. Operator-only —
|
|
@@ -349,6 +401,38 @@ export const SOCKET_ACTIONS = [
|
|
|
349
401
|
];
|
|
350
402
|
/** Runtime guard — narrows an untrusted string to a known action. */
|
|
351
403
|
export const isSocketAction = (value) => typeof value === 'string' && SOCKET_ACTIONS.includes(value);
|
|
404
|
+
/**
|
|
405
|
+
* The fields a stock-moving write announces, as a RUNTIME tuple.
|
|
406
|
+
*
|
|
407
|
+
* ⚠️ This is the single source of truth, and it is a tuple rather than a
|
|
408
|
+
* hand-kept list in two places for the reason `RESPONSE_STRIPPED_KEYS` is one:
|
|
409
|
+
* the api builds its `ProjectionExpression` by joining THIS array
|
|
410
|
+
* (`PRODUCT_STOCK_PROJECTION` in `@helpers/broadcastProductRows`) and
|
|
411
|
+
* {@link ProductStockFrameData} derives its keys from it, so the projection
|
|
412
|
+
* that reads the row and the type describing what the FEs receive cannot
|
|
413
|
+
* disagree. Two independently typed lists is exactly the drift this shape
|
|
414
|
+
* exists to prevent — a field added to one and not the other is invisible to
|
|
415
|
+
* `typecheck`, to lint and to any test that compares one against a literal.
|
|
416
|
+
*
|
|
417
|
+
* ⚠️ `updatedAt` and `lastMovementAt` are BOTH carried because a stock write
|
|
418
|
+
* only moves the second — `movementStamp` writes `lastMovementAt`, never
|
|
419
|
+
* `updatedAt`. A consumer ordering `products` frames by `updatedAt` will watch
|
|
420
|
+
* it stand still across a whole day of sales; order by `lastMovementAt`, or do
|
|
421
|
+
* not order these frames at all.
|
|
422
|
+
*
|
|
423
|
+
* ⚠️ Neither name is a DynamoDB reserved word, so the joined projection needs
|
|
424
|
+
* no `ExpressionAttributeNames` alias. Adding one that IS reserved (`status`,
|
|
425
|
+
* `size`, `name`, …) breaks every read at once — alias it at the join site.
|
|
426
|
+
*/
|
|
427
|
+
export const PRODUCT_STOCK_FRAME_FIELDS = [
|
|
428
|
+
'stock',
|
|
429
|
+
'prices',
|
|
430
|
+
'cost',
|
|
431
|
+
'currency',
|
|
432
|
+
'hiddenFromStorefront',
|
|
433
|
+
'updatedAt',
|
|
434
|
+
'lastMovementAt',
|
|
435
|
+
];
|
|
352
436
|
/* -------------------------------------------------------------------------- */
|
|
353
437
|
/* Agent diagnostic commands */
|
|
354
438
|
/* -------------------------------------------------------------------------- */
|