sinfactura-types 1.10.300 → 1.10.301
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/webhook.js +19 -1
- package/dist/store.d.ts +1 -0
- package/dist/webhook.d.ts +192 -1
- package/dist/webhook.js +18 -0
- package/package.json +1 -1
package/dist/cjs/webhook.js
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
// BREAKING change to every subscriber that exhaustively switches on it, even
|
|
44
44
|
// though it adds rather than removes.
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.PRINT_JOB_SETTLED_OUTCOMES = exports.WEBHOOK_EVENT_TYPES = void 0;
|
|
46
|
+
exports.ORDER_CREATED_SOURCES = exports.PRINT_JOB_SETTLED_OUTCOMES = exports.WEBHOOK_EVENT_TYPES = void 0;
|
|
47
47
|
/**
|
|
48
48
|
* Every event an integrator can subscribe to — print-state transitions and
|
|
49
49
|
* business events alike.
|
|
@@ -69,6 +69,24 @@ exports.WEBHOOK_EVENT_TYPES = [
|
|
|
69
69
|
'payment.received',
|
|
70
70
|
'product.stock_low',
|
|
71
71
|
'product.stock_out',
|
|
72
|
+
'order.created',
|
|
73
|
+
'invoice.generated',
|
|
72
74
|
];
|
|
73
75
|
/** Terminal outcomes for a print job. Closed union — a job printed, or it failed. */
|
|
74
76
|
exports.PRINT_JOB_SETTLED_OUTCOMES = ['printed', 'failed'];
|
|
77
|
+
/**
|
|
78
|
+
* Where an `order.created` event was minted.
|
|
79
|
+
*
|
|
80
|
+
* ⚠️ A CLOSED union, and rule 1 above applies to it with full force: a fifth
|
|
81
|
+
* order-minting path cannot be added here without breaking every subscriber
|
|
82
|
+
* that switches exhaustively — it mints `order.created.v2` instead. The four
|
|
83
|
+
* members are the complete set of paths that write an ORDER row today, each
|
|
84
|
+
* verified at its own post-commit fan-out, not a sample.
|
|
85
|
+
*
|
|
86
|
+
* `service_delivery` is the repair-shop handover: a `ready` → `delivered`
|
|
87
|
+
* transition mints an ordinary sale out of the counter lines the operator
|
|
88
|
+
* named. It is a real order, indistinguishable downstream from a till sale,
|
|
89
|
+
* and it is the one path whose existence an integrator would otherwise never
|
|
90
|
+
* learn about.
|
|
91
|
+
*/
|
|
92
|
+
exports.ORDER_CREATED_SOURCES = ['pos', 'storefront', 'service_delivery', 'mercadolibre'];
|
package/dist/store.d.ts
CHANGED
package/dist/webhook.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* immediately subscribable — and a store that subscribes to an event with no
|
|
11
11
|
* emit site gets silence it cannot distinguish from "nothing happened".
|
|
12
12
|
*/
|
|
13
|
-
export declare const WEBHOOK_EVENT_TYPES: readonly ["print.queued", "print.received", "print.printed", "print.failed", "print.agent.connected", "print.agent.disconnected", "print.printer.online", "print.printer.offline", "print.job.settled", "payment.received", "product.stock_low", "product.stock_out"];
|
|
13
|
+
export declare const WEBHOOK_EVENT_TYPES: readonly ["print.queued", "print.received", "print.printed", "print.failed", "print.agent.connected", "print.agent.disconnected", "print.printer.online", "print.printer.offline", "print.job.settled", "payment.received", "product.stock_low", "product.stock_out", "order.created", "invoice.generated"];
|
|
14
14
|
export type WebhookEventType = (typeof WEBHOOK_EVENT_TYPES)[number];
|
|
15
15
|
/** Terminal outcomes for a print job. Closed union — a job printed, or it failed. */
|
|
16
16
|
export declare const PRINT_JOB_SETTLED_OUTCOMES: readonly ["printed", "failed"];
|
|
@@ -188,3 +188,194 @@ export interface ProductStockOutPayload {
|
|
|
188
188
|
/** Server-stamped Unix milliseconds. */
|
|
189
189
|
crossedAt: number;
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Where an `order.created` event was minted.
|
|
193
|
+
*
|
|
194
|
+
* ⚠️ A CLOSED union, and rule 1 above applies to it with full force: a fifth
|
|
195
|
+
* order-minting path cannot be added here without breaking every subscriber
|
|
196
|
+
* that switches exhaustively — it mints `order.created.v2` instead. The four
|
|
197
|
+
* members are the complete set of paths that write an ORDER row today, each
|
|
198
|
+
* verified at its own post-commit fan-out, not a sample.
|
|
199
|
+
*
|
|
200
|
+
* `service_delivery` is the repair-shop handover: a `ready` → `delivered`
|
|
201
|
+
* transition mints an ordinary sale out of the counter lines the operator
|
|
202
|
+
* named. It is a real order, indistinguishable downstream from a till sale,
|
|
203
|
+
* and it is the one path whose existence an integrator would otherwise never
|
|
204
|
+
* learn about.
|
|
205
|
+
*/
|
|
206
|
+
export declare const ORDER_CREATED_SOURCES: readonly ["pos", "storefront", "service_delivery", "mercadolibre"];
|
|
207
|
+
export type OrderCreatedSource = (typeof ORDER_CREATED_SOURCES)[number];
|
|
208
|
+
/**
|
|
209
|
+
* Payload for `order.created` — an ORDER row is durable, emitted from the
|
|
210
|
+
* post-commit fan-out of each of the four paths that mint one.
|
|
211
|
+
*
|
|
212
|
+
* ── WHY THERE IS NO `total` AND NO `currency` ────────────────────────────
|
|
213
|
+
*
|
|
214
|
+
* Both were considered and both are deliberately ABSENT, and this is the
|
|
215
|
+
* decision most likely to be "fixed" by someone who finds the figure sitting
|
|
216
|
+
* in scope at a seam. It is not an availability problem — a total is reachable
|
|
217
|
+
* at all four. It is a DENOMINATION problem:
|
|
218
|
+
*
|
|
219
|
+
* - `Order.currency` is a catalogId (lowercase, e.g. `'ars'`, an FK to
|
|
220
|
+
* `PlatformCurrency`), while {@link PaymentReceivedWebhookPayload}'s
|
|
221
|
+
* `currency` is ISO 4217 (`'ARS'`). The MercadoLibre leg holds ML's own
|
|
222
|
+
* `currency_id` instead, a third vocabulary again. One field name spelling
|
|
223
|
+
* three things across two sibling events is worse for a reconciler than no
|
|
224
|
+
* field at all.
|
|
225
|
+
* - A money figure with no trustworthy denomination beside it is a number an
|
|
226
|
+
* integrator would reconcile against and be wrong about — and a
|
|
227
|
+
* present-but-wrong amount is strictly worse than an absent one, because
|
|
228
|
+
* nothing about it looks broken.
|
|
229
|
+
*
|
|
230
|
+
* So money lives on `payment.received`, where the denomination is ISO and
|
|
231
|
+
* provider-authoritative, and this event says only that an order exists. An
|
|
232
|
+
* integrator that needs the figures reads `GET /orders` under its own token,
|
|
233
|
+
* where the capability gate already lives.
|
|
234
|
+
*
|
|
235
|
+
* ⚠️ Rule 1 makes this reversible in the safe direction only: adding `total`
|
|
236
|
+
* and `currency` LATER, as optionals with a stated vocabulary, is additive.
|
|
237
|
+
* Shipping them now and discovering the mismatch would not be.
|
|
238
|
+
*
|
|
239
|
+
* ⚠️ **The MercadoLibre leg is AT-MOST-ONCE.** It rides the `orders_v2` SQS
|
|
240
|
+
* consumer's `outcome: 'created'` branch, so a record that commits the order
|
|
241
|
+
* and then dies before the fan-out is redelivered as `outcome: 'updated'` and
|
|
242
|
+
* emits nothing. The store users' new-order notification carries exactly the
|
|
243
|
+
* same exposure on exactly the same branch. The other three legs are
|
|
244
|
+
* exactly-once: each sits past a committed transaction inside the request that
|
|
245
|
+
* made it.
|
|
246
|
+
*
|
|
247
|
+
* ⚠️ **No order EDIT emits.** This fires on the write that creates the row and
|
|
248
|
+
* never again — not on a line change, a discount, a tender, a fulfilment move
|
|
249
|
+
* or a cancellation.
|
|
250
|
+
*/
|
|
251
|
+
export interface OrderCreatedPayload {
|
|
252
|
+
orderId: string;
|
|
253
|
+
source: OrderCreatedSource;
|
|
254
|
+
/**
|
|
255
|
+
* Server-stamped Unix milliseconds, taken at the post-commit emit.
|
|
256
|
+
*
|
|
257
|
+
* ⚠️ **NOT `Order.createdAt`.** It is within milliseconds of it (the emit
|
|
258
|
+
* sits on the commit's own tail, in the same invocation), but it is the
|
|
259
|
+
* moment the api ANNOUNCED the order, not the stamp the row carries. Same
|
|
260
|
+
* convention, and same reason, as `crossedAt` on the stock payloads: it is
|
|
261
|
+
* uniformly in scope at every seam, so it can be REQUIRED and can never be
|
|
262
|
+
* subtly wrong at one of them.
|
|
263
|
+
*
|
|
264
|
+
* ⚠️ A subscriber that falls back to RECEIPT time gets this wrong under
|
|
265
|
+
* delivery retry, and retry is live (5 attempts with backoff).
|
|
266
|
+
*/
|
|
267
|
+
occurredAt: number;
|
|
268
|
+
/**
|
|
269
|
+
* The order's customer.
|
|
270
|
+
*
|
|
271
|
+
* Present on the three synchronous legs without exception — a POS walk-in
|
|
272
|
+
* has no NAMED customer but is minted against the store's system customer
|
|
273
|
+
* row, so `Order.customerId` is never empty. Absent only on the
|
|
274
|
+
* MercadoLibre leg when the post-write order re-read came back empty: that
|
|
275
|
+
* is the same read that gates the operator broadcast beside it, and when it
|
|
276
|
+
* vanishes the api genuinely does not know the buyer at that instant.
|
|
277
|
+
*/
|
|
278
|
+
customerId?: string;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Payload for `invoice.generated` — ARCA authorised a fiscal voucher and its
|
|
282
|
+
* `INVOICE#{storeId}` row is durable.
|
|
283
|
+
*
|
|
284
|
+
* ── WHAT COUNTS AS "GENERATED" ───────────────────────────────────────────
|
|
285
|
+
*
|
|
286
|
+
* Exactly the statuses `isFiscalStatusDeliverable` admits: `authorized_cae`,
|
|
287
|
+
* `authorized_caea` and `caea_reported`. A `pending_cae` row (written when
|
|
288
|
+
* ARCA was unreachable) and a `rejected` one are NOT events here — the first
|
|
289
|
+
* fires later, from the outage drain, once a real CAE lands; the second never
|
|
290
|
+
* fires at all.
|
|
291
|
+
*
|
|
292
|
+
* ⚠️ **Never gate an emit on `cae !== ''`.** `authorized_caea` carries a
|
|
293
|
+
* `caea` and an empty `cae`, so that test silently drops every CAEA voucher —
|
|
294
|
+
* which is precisely the contingency path a store is on when ARCA is down and
|
|
295
|
+
* an integrator most needs to hear from us.
|
|
296
|
+
*
|
|
297
|
+
* ── CREDIT AND DEBIT NOTES ARE THIS EVENT ────────────────────────────────
|
|
298
|
+
*
|
|
299
|
+
* An NC/ND reaches the same authorisation chokepoint as a Factura, is archived
|
|
300
|
+
* the same way, is broadcast the same way, and the outage drain settles it the
|
|
301
|
+
* same way. It is discriminated by `invoiceType` (the ARCA CbteTipo), which is
|
|
302
|
+
* a NUMBER rather than a union precisely so a new voucher type is not a
|
|
303
|
+
* union-widening breaking change under rule 1. Excluding notes would leave an
|
|
304
|
+
* integrator reconciling fiscal documents short by every reversal — a silence
|
|
305
|
+
* it could not distinguish from "no note was issued".
|
|
306
|
+
*
|
|
307
|
+
* ⚠️ **There is no `pdfUrl`, and one cannot be added by populating a field.**
|
|
308
|
+
* No stable or presigned invoice-PDF URL exists anywhere in this system: the
|
|
309
|
+
* PDF is rendered on demand and returned as a base64 data URI through the
|
|
310
|
+
* authenticated `GET /invoices` route, the S3 cold archive holds JSON, and the
|
|
311
|
+
* email path attaches bytes. A URL would be a new design decision about
|
|
312
|
+
* lifetime and authentication, not a field to fill in.
|
|
313
|
+
*
|
|
314
|
+
* ⚠️ **No receptor identity, ever.** `razonSocial`, `cuit`, `cuitType`,
|
|
315
|
+
* `address` and `location` all sit on the row this payload is built beside and
|
|
316
|
+
* are all personal data under Ley 25.326 leaving our network to a
|
|
317
|
+
* tenant-registered URL. `cae`, `caea`, `invoiceNumber` and `pointOfSale` are
|
|
318
|
+
* fiscal codes, not personal data, and are safe. This is why the payload is
|
|
319
|
+
* ENUMERATED: a spread of the invoice row ships the receptor's identity.
|
|
320
|
+
*
|
|
321
|
+
* ⚠️ **No `total` and no `currency`**, for the same denomination reason as
|
|
322
|
+
* {@link OrderCreatedPayload}, plus one specific to this row: on the WSFEX
|
|
323
|
+
* export path `Invoice.total` is the ARS peso base while the voucher itself is
|
|
324
|
+
* denominated in a foreign currency, so the stored figure is not the amount the
|
|
325
|
+
* voucher declares.
|
|
326
|
+
*/
|
|
327
|
+
export interface InvoiceGeneratedPayload {
|
|
328
|
+
invoiceId: string;
|
|
329
|
+
orderId: string;
|
|
330
|
+
customerId: string;
|
|
331
|
+
/**
|
|
332
|
+
* ARCA CbteTipo — 1/6 Factura A/B, 3/8 NC, 2/7 ND, 19 Factura E (export), …
|
|
333
|
+
*
|
|
334
|
+
* A `number`, deliberately: the ARCA codeset grows, and under rule 1 a
|
|
335
|
+
* widened union would break every exhaustive subscriber while a wider number
|
|
336
|
+
* range does not.
|
|
337
|
+
*/
|
|
338
|
+
invoiceType: number;
|
|
339
|
+
pointOfSale: number;
|
|
340
|
+
invoiceNumber: number;
|
|
341
|
+
/**
|
|
342
|
+
* The deliverable subset of `FiscalStatus`, never the full union.
|
|
343
|
+
*
|
|
344
|
+
* ⚠️ Widening this to a fourth member is a BREAKING change under rule 1 and
|
|
345
|
+
* mints a new event string.
|
|
346
|
+
*
|
|
347
|
+
* ⚠️ `caea_reported` is admitted by the gate but emitted by NO seam today —
|
|
348
|
+
* it is the post-Inform status of a voucher that was already announced as
|
|
349
|
+
* `authorized_caea`, and re-announcing the same voucher on its Inform would
|
|
350
|
+
* be a duplicate, not a new fiscal document. It is in the union because the
|
|
351
|
+
* gate (`isFiscalStatusDeliverable`) admits it and narrowing the union later
|
|
352
|
+
* would be the breaking direction; a subscriber should treat it as reserved.
|
|
353
|
+
*/
|
|
354
|
+
fiscalStatus: 'authorized_cae' | 'authorized_caea' | 'caea_reported';
|
|
355
|
+
/** ARCA CAE. Present iff `fiscalStatus === 'authorized_cae'`. */
|
|
356
|
+
cae?: string;
|
|
357
|
+
/** ARCA CAEA. Present iff `fiscalStatus` is `authorized_caea` or `caea_reported`. */
|
|
358
|
+
caea?: string;
|
|
359
|
+
/**
|
|
360
|
+
* Expiry as ARCA returned it, `YYYYMMDD`.
|
|
361
|
+
*
|
|
362
|
+
* ⚠️ It does NOT mean the same thing on both branches. Under
|
|
363
|
+
* `authorized_cae` it is the CAE's own `FchVto`. Under `authorized_caea` it
|
|
364
|
+
* is the CAEA PERIOD's `validTo` — a CAEA has no per-voucher expiry, so the
|
|
365
|
+
* field carries the fortnight's end and is shared by every voucher stamped
|
|
366
|
+
* in that period. Read it together with `fiscalStatus`, never alone.
|
|
367
|
+
*
|
|
368
|
+
* Optional because the value is omitted when empty rather than sent blank.
|
|
369
|
+
*/
|
|
370
|
+
caeExpiration?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Server-stamped Unix milliseconds at the post-commit emit — the moment
|
|
373
|
+
* authorisation became durable here, NOT the voucher's `dated` (its fiscal
|
|
374
|
+
* date) and NOT `Invoice.createdAt`. Same convention and same reason as
|
|
375
|
+
* {@link OrderCreatedPayload.occurredAt}.
|
|
376
|
+
*
|
|
377
|
+
* ⚠️ On the ARCA-outage drain this is the DRAIN's clock, hours or days after
|
|
378
|
+
* the sale — which is the honest answer to "when was this authorised".
|
|
379
|
+
*/
|
|
380
|
+
occurredAt: number;
|
|
381
|
+
}
|
package/dist/webhook.js
CHANGED
|
@@ -66,6 +66,24 @@ export const WEBHOOK_EVENT_TYPES = [
|
|
|
66
66
|
'payment.received',
|
|
67
67
|
'product.stock_low',
|
|
68
68
|
'product.stock_out',
|
|
69
|
+
'order.created',
|
|
70
|
+
'invoice.generated',
|
|
69
71
|
];
|
|
70
72
|
/** Terminal outcomes for a print job. Closed union — a job printed, or it failed. */
|
|
71
73
|
export const PRINT_JOB_SETTLED_OUTCOMES = ['printed', 'failed'];
|
|
74
|
+
/**
|
|
75
|
+
* Where an `order.created` event was minted.
|
|
76
|
+
*
|
|
77
|
+
* ⚠️ A CLOSED union, and rule 1 above applies to it with full force: a fifth
|
|
78
|
+
* order-minting path cannot be added here without breaking every subscriber
|
|
79
|
+
* that switches exhaustively — it mints `order.created.v2` instead. The four
|
|
80
|
+
* members are the complete set of paths that write an ORDER row today, each
|
|
81
|
+
* verified at its own post-commit fan-out, not a sample.
|
|
82
|
+
*
|
|
83
|
+
* `service_delivery` is the repair-shop handover: a `ready` → `delivered`
|
|
84
|
+
* transition mints an ordinary sale out of the counter lines the operator
|
|
85
|
+
* named. It is a real order, indistinguishable downstream from a till sale,
|
|
86
|
+
* and it is the one path whose existence an integrator would otherwise never
|
|
87
|
+
* learn about.
|
|
88
|
+
*/
|
|
89
|
+
export const ORDER_CREATED_SOURCES = ['pos', 'storefront', 'service_delivery', 'mercadolibre'];
|