@stackflow-lab/tef-elgin 1.0.3

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.
@@ -0,0 +1,232 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import koffi from 'koffi';
3
+
4
+ declare function loadElginDll(dllPath?: string): {
5
+ GetProdutoTef: koffi.KoffiFunction;
6
+ GetClientTCP: koffi.KoffiFunction;
7
+ SetClientTCP: koffi.KoffiFunction;
8
+ ConfigurarDadosPDV: koffi.KoffiFunction;
9
+ IniciarOperacaoTEF: koffi.KoffiFunction;
10
+ RecuperarOperacaoTEF: koffi.KoffiFunction;
11
+ RealizarPagamentoTEF: koffi.KoffiFunction;
12
+ RealizarPixTEF: koffi.KoffiFunction;
13
+ RealizarAdmTEF: koffi.KoffiFunction;
14
+ ConfirmarOperacaoTEF: koffi.KoffiFunction;
15
+ FinalizarOperacaoTEF: koffi.KoffiFunction;
16
+ unload: () => void;
17
+ };
18
+ type ElginDll = ReturnType<typeof loadElginDll>;
19
+
20
+ /**
21
+ * Payment operations API — provides dedicated methods for each payment type
22
+ */
23
+ declare class PaymentApi {
24
+ private client;
25
+ constructor(client: Client);
26
+ /**
27
+ * PIX payment
28
+ * @param amount - Amount in format "10.00" or "1000" (cents)
29
+ */
30
+ pix(amount: string): Promise<void>;
31
+ /**
32
+ * Credit card payment
33
+ * @param amount - Amount in format "10.00" or "1000" (cents)
34
+ */
35
+ credit(amount: string): Promise<void>;
36
+ /**
37
+ * Debit card payment
38
+ * @param amount - Amount in format "10.00" or "1000" (cents)
39
+ */
40
+ debit(amount: string): Promise<void>;
41
+ /**
42
+ * Voucher card payment
43
+ * @param amount - Amount in format "10.00" or "1000" (cents)
44
+ */
45
+ voucher(amount: string): Promise<void>;
46
+ /**
47
+ * Fleet card payment
48
+ * @param amount - Amount in format "10.00" or "1000" (cents)
49
+ */
50
+ fleet(amount: string): Promise<void>;
51
+ /**
52
+ * Private label card payment
53
+ * @param amount - Amount in format "10.00" or "1000" (cents)
54
+ */
55
+ privateLabel(amount: string): Promise<void>;
56
+ /**
57
+ * Ask user which card type to use
58
+ * @param amount - Amount in format "10.00" or "1000" (cents)
59
+ */
60
+ ask(amount: string): Promise<void>;
61
+ }
62
+
63
+ /**
64
+ * Administrative operations API
65
+ */
66
+ declare class AdminApi {
67
+ private client;
68
+ constructor(client: Client);
69
+ /**
70
+ * Ask user which administrative operation to perform
71
+ */
72
+ ask(): Promise<void>;
73
+ /**
74
+ * Cancel a previous transaction
75
+ */
76
+ cancel(): Promise<void>;
77
+ /**
78
+ * Check for pending transactions
79
+ */
80
+ pending(): Promise<void>;
81
+ /**
82
+ * Reprint last receipt
83
+ */
84
+ reprint(): Promise<void>;
85
+ }
86
+
87
+ interface PdvConfig {
88
+ pinpadText: string;
89
+ version: string;
90
+ storeName: string;
91
+ storeCode: string;
92
+ terminalId: string;
93
+ }
94
+ /** Raw JSON returned by the DLL — field names are dictated by Elgin's protocol */
95
+ interface TefResponse {
96
+ codigo?: number;
97
+ mensagem?: string;
98
+ tef?: {
99
+ retorno?: string;
100
+ sequencial?: string;
101
+ automacao_coleta_retorno?: string;
102
+ automacao_coleta_sequencial?: string;
103
+ automacao_coleta_tipo?: string;
104
+ automacao_coleta_opcao?: string;
105
+ automacao_coleta_mascara?: string;
106
+ mensagemResultado?: string;
107
+ comprovanteDiferenciadoLoja?: string;
108
+ comprovanteDiferenciadoPortador?: string;
109
+ [key: string]: unknown;
110
+ };
111
+ }
112
+ /** Card type for payment transactions */
113
+ type CardType = 'ask' | 'credit' | 'debit' | 'voucher' | 'fleet' | 'private-label';
114
+ /** Administrative operation */
115
+ type AdminOp = 'ask' | 'cancel' | 'pending' | 'reprint';
116
+ interface CollectTextEvent {
117
+ message: string;
118
+ type: string;
119
+ mask?: string;
120
+ }
121
+ interface CollectOptionsEvent {
122
+ message: string;
123
+ options: string[];
124
+ }
125
+ interface ApprovedEvent {
126
+ sequenceId: string;
127
+ needsConfirmation: boolean;
128
+ acquirerDocument?: string;
129
+ authorizationCode?: string;
130
+ transactionDateTime?: string;
131
+ paymentMethod?: string;
132
+ merchantId?: string;
133
+ terminalId?: string;
134
+ message?: string;
135
+ cardBrand?: string;
136
+ merchantName?: string;
137
+ provider?: string;
138
+ nsu?: string;
139
+ maskedPan?: string;
140
+ result?: string;
141
+ service?: string;
142
+ cardType?: string;
143
+ transaction?: string;
144
+ uniqueId?: string;
145
+ totalAmount?: string;
146
+ }
147
+ interface PrintEvent {
148
+ store: string;
149
+ customer: string;
150
+ }
151
+ interface QrCodeEvent {
152
+ data: string;
153
+ }
154
+ interface TefClientEvents {
155
+ /** Status/display message from the device */
156
+ display: [message: string];
157
+ /** Informational message — no user input needed, client continues automatically */
158
+ waiting: [message: string];
159
+ /** Requests free-text input from the user */
160
+ 'collect:text': [data: CollectTextEvent];
161
+ /** Requests option selection from the user */
162
+ 'collect:options': [data: CollectOptionsEvent];
163
+ /** PIX QR Code available for display */
164
+ qrcode: [data: QrCodeEvent];
165
+ /** Receipt ready for printing */
166
+ print: [data: PrintEvent];
167
+ /** Transaction approved */
168
+ approved: [data: ApprovedEvent];
169
+ /** Transaction declined by the network/bank */
170
+ declined: [code: string, message: string];
171
+ /** Confirmation recorded */
172
+ confirmed: [];
173
+ /** Session finished */
174
+ finished: [];
175
+ /** Technical error (connection, DLL, etc.) */
176
+ error: [code: string, message: string];
177
+ }
178
+
179
+ declare class Client extends EventEmitter<TefClientEvents> {
180
+ private worker;
181
+ private mockDll;
182
+ private operationType;
183
+ private cardType;
184
+ private adminOp;
185
+ private collectResolver;
186
+ private _debugEnabled;
187
+ private workerPromiseResolve;
188
+ private workerPromiseReject;
189
+ /** Payment operations - use methods like payment.pix(), payment.credit(), etc. */
190
+ readonly payment: PaymentApi;
191
+ /** Administrative operations - use methods like admin.cancel(), admin.pending(), etc. */
192
+ readonly admin: AdminApi;
193
+ constructor(dllPathOrInstance?: string | ElginDll);
194
+ /**
195
+ * Creates a new Client instance
196
+ * @param dllPath - Optional path to the DLL (defaults to C:\Elgin\TEF\E1_Tef01.dll)
197
+ */
198
+ static instance(dllPath?: string): Client;
199
+ /**
200
+ * Enables debug logging to see all DLL calls, responses, and events
201
+ */
202
+ enableDebug(): void;
203
+ /**
204
+ * Disables debug logging
205
+ */
206
+ disableDebug(): void;
207
+ private _log;
208
+ private _sendToWorker;
209
+ configure(ip: string, port: number, pdv: PdvConfig): Promise<void>;
210
+ /** @internal */
211
+ _executePayment(card: CardType, amount: string): Promise<void>;
212
+ /** @internal */
213
+ _executePix(amount: string): Promise<void>;
214
+ /** @internal */
215
+ _executeAdmin(op: AdminOp): Promise<void>;
216
+ /** Sends the user's answer to the pending collect request */
217
+ respond(info: string): void;
218
+ /** Cancels the pending collect request */
219
+ cancel(): void;
220
+ unload(): void;
221
+ private _run;
222
+ private _collectLoop;
223
+ private _callTransaction;
224
+ private _confirm;
225
+ private _finalize;
226
+ private _waitCollect;
227
+ private _parse;
228
+ private _nextSeq;
229
+ private _extractQrCode;
230
+ }
231
+
232
+ export { AdminApi, type ApprovedEvent, Client, type CollectOptionsEvent, type CollectTextEvent, PaymentApi, type PdvConfig, type PrintEvent, type QrCodeEvent, type TefClientEvents, type TefResponse };
@@ -0,0 +1,232 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import koffi from 'koffi';
3
+
4
+ declare function loadElginDll(dllPath?: string): {
5
+ GetProdutoTef: koffi.KoffiFunction;
6
+ GetClientTCP: koffi.KoffiFunction;
7
+ SetClientTCP: koffi.KoffiFunction;
8
+ ConfigurarDadosPDV: koffi.KoffiFunction;
9
+ IniciarOperacaoTEF: koffi.KoffiFunction;
10
+ RecuperarOperacaoTEF: koffi.KoffiFunction;
11
+ RealizarPagamentoTEF: koffi.KoffiFunction;
12
+ RealizarPixTEF: koffi.KoffiFunction;
13
+ RealizarAdmTEF: koffi.KoffiFunction;
14
+ ConfirmarOperacaoTEF: koffi.KoffiFunction;
15
+ FinalizarOperacaoTEF: koffi.KoffiFunction;
16
+ unload: () => void;
17
+ };
18
+ type ElginDll = ReturnType<typeof loadElginDll>;
19
+
20
+ /**
21
+ * Payment operations API — provides dedicated methods for each payment type
22
+ */
23
+ declare class PaymentApi {
24
+ private client;
25
+ constructor(client: Client);
26
+ /**
27
+ * PIX payment
28
+ * @param amount - Amount in format "10.00" or "1000" (cents)
29
+ */
30
+ pix(amount: string): Promise<void>;
31
+ /**
32
+ * Credit card payment
33
+ * @param amount - Amount in format "10.00" or "1000" (cents)
34
+ */
35
+ credit(amount: string): Promise<void>;
36
+ /**
37
+ * Debit card payment
38
+ * @param amount - Amount in format "10.00" or "1000" (cents)
39
+ */
40
+ debit(amount: string): Promise<void>;
41
+ /**
42
+ * Voucher card payment
43
+ * @param amount - Amount in format "10.00" or "1000" (cents)
44
+ */
45
+ voucher(amount: string): Promise<void>;
46
+ /**
47
+ * Fleet card payment
48
+ * @param amount - Amount in format "10.00" or "1000" (cents)
49
+ */
50
+ fleet(amount: string): Promise<void>;
51
+ /**
52
+ * Private label card payment
53
+ * @param amount - Amount in format "10.00" or "1000" (cents)
54
+ */
55
+ privateLabel(amount: string): Promise<void>;
56
+ /**
57
+ * Ask user which card type to use
58
+ * @param amount - Amount in format "10.00" or "1000" (cents)
59
+ */
60
+ ask(amount: string): Promise<void>;
61
+ }
62
+
63
+ /**
64
+ * Administrative operations API
65
+ */
66
+ declare class AdminApi {
67
+ private client;
68
+ constructor(client: Client);
69
+ /**
70
+ * Ask user which administrative operation to perform
71
+ */
72
+ ask(): Promise<void>;
73
+ /**
74
+ * Cancel a previous transaction
75
+ */
76
+ cancel(): Promise<void>;
77
+ /**
78
+ * Check for pending transactions
79
+ */
80
+ pending(): Promise<void>;
81
+ /**
82
+ * Reprint last receipt
83
+ */
84
+ reprint(): Promise<void>;
85
+ }
86
+
87
+ interface PdvConfig {
88
+ pinpadText: string;
89
+ version: string;
90
+ storeName: string;
91
+ storeCode: string;
92
+ terminalId: string;
93
+ }
94
+ /** Raw JSON returned by the DLL — field names are dictated by Elgin's protocol */
95
+ interface TefResponse {
96
+ codigo?: number;
97
+ mensagem?: string;
98
+ tef?: {
99
+ retorno?: string;
100
+ sequencial?: string;
101
+ automacao_coleta_retorno?: string;
102
+ automacao_coleta_sequencial?: string;
103
+ automacao_coleta_tipo?: string;
104
+ automacao_coleta_opcao?: string;
105
+ automacao_coleta_mascara?: string;
106
+ mensagemResultado?: string;
107
+ comprovanteDiferenciadoLoja?: string;
108
+ comprovanteDiferenciadoPortador?: string;
109
+ [key: string]: unknown;
110
+ };
111
+ }
112
+ /** Card type for payment transactions */
113
+ type CardType = 'ask' | 'credit' | 'debit' | 'voucher' | 'fleet' | 'private-label';
114
+ /** Administrative operation */
115
+ type AdminOp = 'ask' | 'cancel' | 'pending' | 'reprint';
116
+ interface CollectTextEvent {
117
+ message: string;
118
+ type: string;
119
+ mask?: string;
120
+ }
121
+ interface CollectOptionsEvent {
122
+ message: string;
123
+ options: string[];
124
+ }
125
+ interface ApprovedEvent {
126
+ sequenceId: string;
127
+ needsConfirmation: boolean;
128
+ acquirerDocument?: string;
129
+ authorizationCode?: string;
130
+ transactionDateTime?: string;
131
+ paymentMethod?: string;
132
+ merchantId?: string;
133
+ terminalId?: string;
134
+ message?: string;
135
+ cardBrand?: string;
136
+ merchantName?: string;
137
+ provider?: string;
138
+ nsu?: string;
139
+ maskedPan?: string;
140
+ result?: string;
141
+ service?: string;
142
+ cardType?: string;
143
+ transaction?: string;
144
+ uniqueId?: string;
145
+ totalAmount?: string;
146
+ }
147
+ interface PrintEvent {
148
+ store: string;
149
+ customer: string;
150
+ }
151
+ interface QrCodeEvent {
152
+ data: string;
153
+ }
154
+ interface TefClientEvents {
155
+ /** Status/display message from the device */
156
+ display: [message: string];
157
+ /** Informational message — no user input needed, client continues automatically */
158
+ waiting: [message: string];
159
+ /** Requests free-text input from the user */
160
+ 'collect:text': [data: CollectTextEvent];
161
+ /** Requests option selection from the user */
162
+ 'collect:options': [data: CollectOptionsEvent];
163
+ /** PIX QR Code available for display */
164
+ qrcode: [data: QrCodeEvent];
165
+ /** Receipt ready for printing */
166
+ print: [data: PrintEvent];
167
+ /** Transaction approved */
168
+ approved: [data: ApprovedEvent];
169
+ /** Transaction declined by the network/bank */
170
+ declined: [code: string, message: string];
171
+ /** Confirmation recorded */
172
+ confirmed: [];
173
+ /** Session finished */
174
+ finished: [];
175
+ /** Technical error (connection, DLL, etc.) */
176
+ error: [code: string, message: string];
177
+ }
178
+
179
+ declare class Client extends EventEmitter<TefClientEvents> {
180
+ private worker;
181
+ private mockDll;
182
+ private operationType;
183
+ private cardType;
184
+ private adminOp;
185
+ private collectResolver;
186
+ private _debugEnabled;
187
+ private workerPromiseResolve;
188
+ private workerPromiseReject;
189
+ /** Payment operations - use methods like payment.pix(), payment.credit(), etc. */
190
+ readonly payment: PaymentApi;
191
+ /** Administrative operations - use methods like admin.cancel(), admin.pending(), etc. */
192
+ readonly admin: AdminApi;
193
+ constructor(dllPathOrInstance?: string | ElginDll);
194
+ /**
195
+ * Creates a new Client instance
196
+ * @param dllPath - Optional path to the DLL (defaults to C:\Elgin\TEF\E1_Tef01.dll)
197
+ */
198
+ static instance(dllPath?: string): Client;
199
+ /**
200
+ * Enables debug logging to see all DLL calls, responses, and events
201
+ */
202
+ enableDebug(): void;
203
+ /**
204
+ * Disables debug logging
205
+ */
206
+ disableDebug(): void;
207
+ private _log;
208
+ private _sendToWorker;
209
+ configure(ip: string, port: number, pdv: PdvConfig): Promise<void>;
210
+ /** @internal */
211
+ _executePayment(card: CardType, amount: string): Promise<void>;
212
+ /** @internal */
213
+ _executePix(amount: string): Promise<void>;
214
+ /** @internal */
215
+ _executeAdmin(op: AdminOp): Promise<void>;
216
+ /** Sends the user's answer to the pending collect request */
217
+ respond(info: string): void;
218
+ /** Cancels the pending collect request */
219
+ cancel(): void;
220
+ unload(): void;
221
+ private _run;
222
+ private _collectLoop;
223
+ private _callTransaction;
224
+ private _confirm;
225
+ private _finalize;
226
+ private _waitCollect;
227
+ private _parse;
228
+ private _nextSeq;
229
+ private _extractQrCode;
230
+ }
231
+
232
+ export { AdminApi, type ApprovedEvent, Client, type CollectOptionsEvent, type CollectTextEvent, PaymentApi, type PdvConfig, type PrintEvent, type QrCodeEvent, type TefClientEvents, type TefResponse };