Operar

Contingencia OFFLINE

Si el SIAT no responde, el SDK firma local (codigoEmision=2) y te devuelve OFFLINE para reenviar por paquete.

index.ts
1// El SDK detecta el fallback OFFLINE automáticamente
2const factura = await supay.invoices.emit({
3 pointOfSaleId: POS_ID, customer, items,
4}, { idempotencyKey: "venta-000148" });
5 
6if (factura.status === "OFFLINE") {
7 // 1. Registra el evento significativo
8 const evento = await supay.contingency.registerEvent({
9 pointOfSaleId: POS_ID,
10 codigoEvento: 1, // corte de internet, etc.
11 fechaInicio: new Date().toISOString(),
12 });
13 
14 // 2. Cuando vuelve la red, envía por paquete
15 const lote = await supay.packages.send({
16 pointOfSaleId: POS_ID,
17 invoiceIds: [factura.id],
18 contingencyEventId: factura.contingencyEventId ?? evento.id,
19 });
20 
21 // 3. Valida el resultado del paquete
22 await supay.packages.validate({ batchId: lote.batchId });
23}

Reglas

Una repetición idempotente nunca re-emite una factura ya terminada. Al volver la red, el evento significativo se completa con fecha de fin y código de recepción del SIAT. Siempre usa `idempotencyKey` en el `emit` inicial.