@danielrebolledo/cafe-ipdh-lib 1.0.0
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/README.md +78 -0
- package/dist/index.cjs +350 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +386 -0
- package/dist/index.d.ts +386 -0
- package/dist/index.js +319 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comandos JSON para impresora fiscal AEG-R1.
|
|
3
|
+
* Según documentación oficial AEG-R1.
|
|
4
|
+
*/
|
|
5
|
+
type AegPrinterCommand = {
|
|
6
|
+
cmd: "cliF";
|
|
7
|
+
data: {
|
|
8
|
+
rifCI: string;
|
|
9
|
+
razSoc: string[];
|
|
10
|
+
LineAd: string[];
|
|
11
|
+
};
|
|
12
|
+
} | {
|
|
13
|
+
cmd: "proF";
|
|
14
|
+
data: {
|
|
15
|
+
imp: number;
|
|
16
|
+
pre: number;
|
|
17
|
+
cant: number;
|
|
18
|
+
des01: string;
|
|
19
|
+
};
|
|
20
|
+
} | {
|
|
21
|
+
cmd: "subToF";
|
|
22
|
+
data: number;
|
|
23
|
+
valor: number;
|
|
24
|
+
} | {
|
|
25
|
+
cmd: "fpaF";
|
|
26
|
+
data: {
|
|
27
|
+
tipo: number;
|
|
28
|
+
monto: number;
|
|
29
|
+
tasaConv: number;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
cmd: "endFac";
|
|
33
|
+
data: number;
|
|
34
|
+
} | {
|
|
35
|
+
cmd: "encDNF";
|
|
36
|
+
data: [string, string];
|
|
37
|
+
} | {
|
|
38
|
+
cmd: "txtDNF";
|
|
39
|
+
data: [string, string, string, string, string];
|
|
40
|
+
} | {
|
|
41
|
+
cmd: "aperDNF";
|
|
42
|
+
data: string;
|
|
43
|
+
} | {
|
|
44
|
+
cmd: "efeNorJuIzDNF";
|
|
45
|
+
data: string;
|
|
46
|
+
} | {
|
|
47
|
+
cmd: "endDNF";
|
|
48
|
+
data: string;
|
|
49
|
+
} | {
|
|
50
|
+
cmd: "encNC";
|
|
51
|
+
data: [string, string] | [string, string, string];
|
|
52
|
+
} | {
|
|
53
|
+
cmd: "nroFacNC";
|
|
54
|
+
data: number;
|
|
55
|
+
} | {
|
|
56
|
+
cmd: "fechFacNC";
|
|
57
|
+
data: string;
|
|
58
|
+
} | {
|
|
59
|
+
cmd: "conSerNC";
|
|
60
|
+
data: string;
|
|
61
|
+
} | {
|
|
62
|
+
cmd: "rifCiNC";
|
|
63
|
+
data: string;
|
|
64
|
+
} | {
|
|
65
|
+
cmd: "razSocNC";
|
|
66
|
+
data: {
|
|
67
|
+
razSoc: string[];
|
|
68
|
+
LineAd: string[];
|
|
69
|
+
};
|
|
70
|
+
} | {
|
|
71
|
+
cmd: "prodNC";
|
|
72
|
+
data: {
|
|
73
|
+
imp: number;
|
|
74
|
+
pre: number;
|
|
75
|
+
cant: number;
|
|
76
|
+
des01: string;
|
|
77
|
+
};
|
|
78
|
+
} | {
|
|
79
|
+
cmd: "endPoNC";
|
|
80
|
+
data: number;
|
|
81
|
+
} | {
|
|
82
|
+
cmd: "fpaNC";
|
|
83
|
+
data: {
|
|
84
|
+
tipo: number;
|
|
85
|
+
monto: number;
|
|
86
|
+
tasaConv: number;
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
cmd: "endNC";
|
|
90
|
+
data: number;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Cliente para facturación fiscal.
|
|
95
|
+
* Interface mínima requerida para construir comandos de impresora.
|
|
96
|
+
*/
|
|
97
|
+
interface FiscalClient {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
email?: string;
|
|
101
|
+
phone?: string;
|
|
102
|
+
address?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Impuesto de un item (usado para mapeo a códigos de impresora).
|
|
106
|
+
* id puede ser null (ej: GraphQL ItemTax).
|
|
107
|
+
*/
|
|
108
|
+
interface ItemTax {
|
|
109
|
+
id: string | null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Item de orden para facturación fiscal.
|
|
113
|
+
*/
|
|
114
|
+
interface OrderItem {
|
|
115
|
+
id: string;
|
|
116
|
+
name: string;
|
|
117
|
+
sku: string;
|
|
118
|
+
price: number;
|
|
119
|
+
quantity: number;
|
|
120
|
+
total: number;
|
|
121
|
+
taxes?: ItemTax[];
|
|
122
|
+
selectedQuantity?: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Pago completado de una orden.
|
|
126
|
+
*/
|
|
127
|
+
interface OrderPayment {
|
|
128
|
+
amount: number;
|
|
129
|
+
paymentMethod: string;
|
|
130
|
+
cardLast4?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Orden para facturación.
|
|
134
|
+
* Interface mínima para construir comandos de impresora.
|
|
135
|
+
*/
|
|
136
|
+
interface Order {
|
|
137
|
+
items: OrderItem[];
|
|
138
|
+
payments: OrderPayment[];
|
|
139
|
+
total: number;
|
|
140
|
+
client: FiscalClient | null;
|
|
141
|
+
status?: "pending" | "completed" | "canceled" | null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Tipo de documento a imprimir.
|
|
146
|
+
*/
|
|
147
|
+
type DocumentType = "invoice" | "receipt" | "credit_note";
|
|
148
|
+
/**
|
|
149
|
+
* Resultado de envío de comandos a una impresora.
|
|
150
|
+
*/
|
|
151
|
+
interface PrinterCommandResponse$1 {
|
|
152
|
+
cmd: string;
|
|
153
|
+
code: number;
|
|
154
|
+
dataD?: number;
|
|
155
|
+
dataS?: Record<string, unknown>;
|
|
156
|
+
message?: string;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Opciones para construir comandos de factura.
|
|
160
|
+
*/
|
|
161
|
+
interface BuildInvoiceOptions {
|
|
162
|
+
paymentMethodId: "pos_credit" | "pos_debit" | "pos_debit_credit_int" | "cash_int" | "cash_nat";
|
|
163
|
+
storeName?: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Opciones para construir comandos de recibo de pago.
|
|
167
|
+
*/
|
|
168
|
+
interface BuildReceiptOptions {
|
|
169
|
+
orderId: string;
|
|
170
|
+
amountPaid: number;
|
|
171
|
+
paymentMethod: string;
|
|
172
|
+
organizationName?: string;
|
|
173
|
+
paidAt?: Date;
|
|
174
|
+
cardLast4?: string | null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Interface abstracta para un driver de impresora.
|
|
178
|
+
* Cada modelo (AEG-R1, DTP, etc.) implementa esta interface.
|
|
179
|
+
*/
|
|
180
|
+
interface PrinterDriver<TCmd = unknown> {
|
|
181
|
+
readonly model: string;
|
|
182
|
+
/**
|
|
183
|
+
* Construye comandos para imprimir una factura fiscal.
|
|
184
|
+
*/
|
|
185
|
+
buildInvoiceCommands(order: Order, options: BuildInvoiceOptions): TCmd[];
|
|
186
|
+
/**
|
|
187
|
+
* Construye comandos para imprimir un recibo de pago (DNF).
|
|
188
|
+
*/
|
|
189
|
+
buildReceiptCommands(options: BuildReceiptOptions): TCmd[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Driver para impresora fiscal AEG-R1.
|
|
194
|
+
* Construye comandos JSON según documentación oficial.
|
|
195
|
+
*/
|
|
196
|
+
declare const aegPrinter: PrinterDriver<AegPrinterCommand>;
|
|
197
|
+
|
|
198
|
+
type AbrirCfArgs = {
|
|
199
|
+
iTipo?: number;
|
|
200
|
+
sNombreCliente: string;
|
|
201
|
+
sRifCliente: string;
|
|
202
|
+
iFacturaReferencia?: number;
|
|
203
|
+
fechaReferencia?: Date;
|
|
204
|
+
sSerialReferencia?: string;
|
|
205
|
+
bLogo?: boolean;
|
|
206
|
+
sLineaAdicional?: string;
|
|
207
|
+
};
|
|
208
|
+
type ItemCfArgs = {
|
|
209
|
+
iTipo?: number;
|
|
210
|
+
sDescripcion: string;
|
|
211
|
+
sCodigo: string;
|
|
212
|
+
lCantidad: number;
|
|
213
|
+
sUnidad: string;
|
|
214
|
+
lPrecio: number;
|
|
215
|
+
iImpuesto: number;
|
|
216
|
+
iDecPrecio: number;
|
|
217
|
+
iDecCantidad: number;
|
|
218
|
+
};
|
|
219
|
+
type PagoCfArgs = {
|
|
220
|
+
iTipoPago?: number;
|
|
221
|
+
iFormaPago: number;
|
|
222
|
+
sDescripcion: string;
|
|
223
|
+
lMonto: number;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Comandos para impresora fiscal DTP-80i.
|
|
228
|
+
* Cada comando se ejecuta secuencialmente contra un DtpClient.
|
|
229
|
+
*/
|
|
230
|
+
type DtpPrinterCommand = {
|
|
231
|
+
cmd: "F0";
|
|
232
|
+
data: AbrirCfArgs;
|
|
233
|
+
} | {
|
|
234
|
+
cmd: "F1";
|
|
235
|
+
data: ItemCfArgs;
|
|
236
|
+
} | {
|
|
237
|
+
cmd: "F2";
|
|
238
|
+
data: {
|
|
239
|
+
mode?: number;
|
|
240
|
+
foreignCurrencyAmount?: number;
|
|
241
|
+
};
|
|
242
|
+
} | {
|
|
243
|
+
cmd: "F4";
|
|
244
|
+
data: PagoCfArgs;
|
|
245
|
+
} | {
|
|
246
|
+
cmd: "F5";
|
|
247
|
+
data?: {
|
|
248
|
+
additionalLine?: string;
|
|
249
|
+
};
|
|
250
|
+
} | {
|
|
251
|
+
cmd: "F11";
|
|
252
|
+
data: {
|
|
253
|
+
iFormaPago: number;
|
|
254
|
+
sDescripcion: string;
|
|
255
|
+
lMonto: number;
|
|
256
|
+
lTasaCambio: number;
|
|
257
|
+
sSimbolo: string;
|
|
258
|
+
};
|
|
259
|
+
} | {
|
|
260
|
+
cmd: "N0";
|
|
261
|
+
} | {
|
|
262
|
+
cmd: "N1";
|
|
263
|
+
data: {
|
|
264
|
+
line: string;
|
|
265
|
+
size?: number;
|
|
266
|
+
align?: number;
|
|
267
|
+
style?: number;
|
|
268
|
+
};
|
|
269
|
+
} | {
|
|
270
|
+
cmd: "N3";
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Resultado de ejecutar comandos DTP.
|
|
275
|
+
* Incluye documentNumber y totalAmount cuando el último comando es F5 (cerrar factura).
|
|
276
|
+
*/
|
|
277
|
+
interface ExecuteDtpCommandsResult {
|
|
278
|
+
documentNumber?: number;
|
|
279
|
+
totalAmount?: number;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Marcas de impresoras soportadas.
|
|
284
|
+
*/
|
|
285
|
+
type PrinterBrand = "AEG" | "DTP";
|
|
286
|
+
/**
|
|
287
|
+
* Modelos por marca.
|
|
288
|
+
* AEG: R1 (impresora fiscal HTTP)
|
|
289
|
+
* DTP: 80i (impresora fiscal TCP - requiere módulo nativo)
|
|
290
|
+
*/
|
|
291
|
+
type AegModel = "R1";
|
|
292
|
+
type DtpModel = "80i";
|
|
293
|
+
/**
|
|
294
|
+
* Argumentos para AEG-R1.
|
|
295
|
+
* Usa comandos JSON sobre HTTP POST a /cmdoJson.
|
|
296
|
+
*/
|
|
297
|
+
interface SendPrinterCommandsAeg {
|
|
298
|
+
brand: "AEG";
|
|
299
|
+
model: AegModel;
|
|
300
|
+
ip: string;
|
|
301
|
+
commands: AegPrinterCommand[];
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Argumentos para DTP-80i.
|
|
305
|
+
* DTP usa TCP vía módulo nativo - el envío desde esta librería
|
|
306
|
+
* no está soportado. El consumidor debe usar ExpoDtpFiscalPrinter.
|
|
307
|
+
*/
|
|
308
|
+
interface SendPrinterCommandsDtp {
|
|
309
|
+
brand: "DTP";
|
|
310
|
+
model: DtpModel;
|
|
311
|
+
ip: string;
|
|
312
|
+
commands: unknown[];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Argumentos de sendPrinterCommands.
|
|
316
|
+
* Discriminados por brand para validar model.
|
|
317
|
+
*/
|
|
318
|
+
type SendPrinterCommandsArgs = SendPrinterCommandsAeg | SendPrinterCommandsDtp;
|
|
319
|
+
/**
|
|
320
|
+
* Respuesta de un comando de impresora.
|
|
321
|
+
*/
|
|
322
|
+
interface PrinterCommandResponse {
|
|
323
|
+
cmd: string;
|
|
324
|
+
code: number;
|
|
325
|
+
dataD?: number;
|
|
326
|
+
dataS?: Record<string, unknown>;
|
|
327
|
+
message?: string;
|
|
328
|
+
}
|
|
329
|
+
type PrinterResponse = PrinterCommandResponse[];
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Envía comandos a una impresora fiscal.
|
|
333
|
+
*
|
|
334
|
+
* - **AEG-R1**: POST HTTP a {ip}/cmdoJson con body = commands (JSON)
|
|
335
|
+
* - **DTP-80i**: No soportado en esta librería (usa TCP vía módulo nativo).
|
|
336
|
+
* El consumidor debe usar ExpoDtpFiscalPrinter directamente.
|
|
337
|
+
*/
|
|
338
|
+
declare function sendPrinterCommands(args: SendPrinterCommandsArgs, options?: {
|
|
339
|
+
timeout?: number;
|
|
340
|
+
}): Promise<PrinterResponse>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Valores de impuestos (porcentajes) según legislación venezolana.
|
|
344
|
+
*/
|
|
345
|
+
declare enum TaxValues {
|
|
346
|
+
EXENTO_E = 0,
|
|
347
|
+
BI_G = 16,
|
|
348
|
+
IVA_G = 16,
|
|
349
|
+
BI_R = 8,
|
|
350
|
+
IVA_R = 8,
|
|
351
|
+
BI_A = 31,
|
|
352
|
+
IVA_A = 31,
|
|
353
|
+
PERCIBIDO = 0,
|
|
354
|
+
BI_IGTF = 3,
|
|
355
|
+
IVA_IGTF = 3
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Códigos de impuesto para impresora fiscal AEG-R1.
|
|
359
|
+
*/
|
|
360
|
+
declare enum PrinterTaxValues {
|
|
361
|
+
EXENTO_E = 1,
|
|
362
|
+
BI_G = 2,
|
|
363
|
+
IVA_G = 2,
|
|
364
|
+
BI_R = 3,
|
|
365
|
+
IVA_R = 3,
|
|
366
|
+
BI_A = 4,
|
|
367
|
+
IVA_A = 4,
|
|
368
|
+
PERCIBIDO = 5,
|
|
369
|
+
BI_IGTF = 5,
|
|
370
|
+
IVA_IGTF = 5
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* IDs de método de pago para impresora fiscal AEG-R1.
|
|
374
|
+
* Efectivo: 1, Débito: 2, Crédito: 3, Pago Móvil: 5,
|
|
375
|
+
* Débito/Crédito int: 11, Efectivo int: 12
|
|
376
|
+
*/
|
|
377
|
+
declare enum PaymentMethodId {
|
|
378
|
+
CASH = 1,
|
|
379
|
+
POS_DEBIT = 2,
|
|
380
|
+
POS_CREDIT = 3,
|
|
381
|
+
PAGO_MOVIL = 5,
|
|
382
|
+
POS_DEBIT_CREDIT_INT = 11,
|
|
383
|
+
CASH_INT = 12
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export { type AegModel, type AegPrinterCommand, type BuildInvoiceOptions, type BuildReceiptOptions, type DocumentType, type DtpModel, type DtpPrinterCommand, type ExecuteDtpCommandsResult, type FiscalClient, type ItemTax, type Order, type OrderItem, type OrderPayment, PaymentMethodId, type PrinterBrand, type PrinterCommandResponse$1 as PrinterCommandResponse, type PrinterDriver, PrinterTaxValues, type SendPrinterCommandsAeg, type SendPrinterCommandsArgs, type SendPrinterCommandsDtp, TaxValues, aegPrinter, sendPrinterCommands };
|