@acontplus/ng-common 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.
@@ -0,0 +1,455 @@
1
+ import { Observable } from 'rxjs';
2
+ import { HttpResponse } from '@angular/common/http';
3
+ import * as i0 from '@angular/core';
4
+ import { InjectionToken, OnInit } from '@angular/core';
5
+ import { FormGroup } from '@angular/forms';
6
+
7
+ interface WhatsAppTextRequest {
8
+ to: string;
9
+ message: string;
10
+ previewUrl?: boolean;
11
+ }
12
+ interface WhatsAppTextTemplateRequest {
13
+ to: string;
14
+ templateName: string;
15
+ languageCode?: string;
16
+ bodyParams?: string[];
17
+ }
18
+ interface WhatsAppDocumentRequest {
19
+ to: string;
20
+ documentUrl: string;
21
+ caption?: string;
22
+ filename?: string;
23
+ }
24
+ interface WhatsAppDocumentTemplateRequest {
25
+ to: string;
26
+ templateName: string;
27
+ languageCode?: string;
28
+ filename?: string;
29
+ bodyParams?: string[];
30
+ file: File;
31
+ }
32
+ interface WhatsAppResponse {
33
+ success: boolean;
34
+ messageId?: string;
35
+ phoneNumber?: string;
36
+ error?: {
37
+ code: number;
38
+ message: string;
39
+ };
40
+ }
41
+ interface WhatsAppStatusResponse {
42
+ enabled: boolean;
43
+ provider: string;
44
+ }
45
+ interface DocumentDeliveryParams {
46
+ phone: string;
47
+ file: File;
48
+ customerName: string;
49
+ establishmentName: string;
50
+ documentSeries: string;
51
+ documentType: string;
52
+ }
53
+ type WhatsAppTextMessage = WhatsAppTextRequest;
54
+ type WhatsAppTemplateMessage = WhatsAppTextTemplateRequest;
55
+ type WhatsAppDocumentMessage = WhatsAppDocumentRequest;
56
+ type WhatsAppDocumentTemplateMessage = WhatsAppDocumentTemplateRequest;
57
+ type WhatsAppMessageResponse = WhatsAppResponse;
58
+ type WhatsAppProviderStatus = WhatsAppStatusResponse;
59
+
60
+ /**
61
+ * Puerto para proveedores de WhatsApp
62
+ * Define la interfaz que deben implementar todos los adaptadores (Meta, Green, etc.)
63
+ */
64
+ interface WhatsAppMessagingPort {
65
+ sendText(request: WhatsAppTextRequest): Observable<WhatsAppResponse>;
66
+ sendTextTemplate(request: WhatsAppTextTemplateRequest): Observable<WhatsAppResponse>;
67
+ sendDocument(request: WhatsAppDocumentRequest): Observable<WhatsAppResponse>;
68
+ sendDocumentTemplate(request: WhatsAppDocumentTemplateRequest): Observable<WhatsAppResponse>;
69
+ getStatus(): Observable<WhatsAppStatusResponse>;
70
+ }
71
+
72
+ interface PrintParams {
73
+ id: number;
74
+ documentoId: number;
75
+ tipo: 1 | 2 | 3 | 4 | 5 | 6;
76
+ codDoc: string;
77
+ codEstab?: string;
78
+ }
79
+ interface PrintConfig {
80
+ codDoc: string;
81
+ getUrlPrintServer: boolean;
82
+ id: number;
83
+ codEstab?: string;
84
+ }
85
+ interface ApiResponse<T = any> {
86
+ code: string;
87
+ message: string;
88
+ payload?: T;
89
+ }
90
+ /**
91
+ * Puerto para impresión de documentos
92
+ * Solo se encarga de impresión, no de generación de reportes
93
+ */
94
+ interface PrinterPort {
95
+ askToPrint(params: PrintParams): void;
96
+ getPrintConfig(params: PrintParams): Observable<ApiResponse>;
97
+ print(urlPrinter: string, params: PrintParams): Observable<ApiResponse>;
98
+ createPrintOrder(id: number): void;
99
+ createPrintCommanda(id: number): void;
100
+ createPrintOrderWithCommanda(id: number): void;
101
+ createInvoicePrint(id: number, documentoId: number): void;
102
+ createNotaEntregaPrint(id: number, documentoId: number): void;
103
+ }
104
+
105
+ interface ReportGenerationOptions<T = any> {
106
+ data: T;
107
+ format?: 'pdf' | 'excel' | 'word';
108
+ useV1Api?: boolean;
109
+ forceDownload?: boolean;
110
+ returnBlob?: boolean;
111
+ }
112
+ /**
113
+ * Puerto para generación de reportes
114
+ * Solo se encarga de generar reportes, no de impresión
115
+ */
116
+ interface ReportPort {
117
+ generate<T>(options: ReportGenerationOptions<T>): Observable<HttpResponse<Blob>> | void;
118
+ saveFile(response: any, format?: string, forceDownload?: boolean): void;
119
+ getFileName(response: any): string;
120
+ }
121
+
122
+ declare const API_PATHS: {
123
+ readonly WHATSAPP: "/api/common/whatsapp-cloud";
124
+ readonly REPORTS: "/api/reports";
125
+ readonly CONFIG: "/api/config";
126
+ };
127
+ declare const DOCUMENT_TYPES: {
128
+ readonly NORMAL: "NORMAL";
129
+ readonly FACTURA: "FACTURA";
130
+ readonly NOTA_ENTREGA: "NOTA_ENTREGA";
131
+ };
132
+
133
+ declare const REPORT_PORT: InjectionToken<ReportPort>;
134
+
135
+ declare const WHATSAPP_MESSAGING_PORT: InjectionToken<WhatsAppMessagingPort>;
136
+
137
+ declare const PRINTER_PORT: InjectionToken<PrinterPort>;
138
+
139
+ declare class ReportFacade {
140
+ private readonly reportPort;
141
+ generate<T>(options: ReportGenerationOptions<T>): Observable<any> | void;
142
+ generatePDF<T>(data: T, forceDownload?: boolean): void;
143
+ generateExcel<T>(data: T, forceDownload?: boolean): void;
144
+ generateWord<T>(data: T, forceDownload?: boolean): void;
145
+ generateBlob<T>(data: T, format?: 'pdf' | 'excel' | 'word'): Observable<any>;
146
+ static ɵfac: i0.ɵɵFactoryDeclaration<ReportFacade, never>;
147
+ static ɵprov: i0.ɵɵInjectableDeclaration<ReportFacade>;
148
+ }
149
+
150
+ declare class WhatsAppMessagingFacade {
151
+ private readonly messagingPort;
152
+ private readonly messageBuilder;
153
+ sendSimpleText(to: string, message: string, previewUrl?: boolean): Observable<WhatsAppResponse>;
154
+ sendTemplateText(to: string, templateName: string, params?: string[], languageCode?: string): Observable<WhatsAppResponse>;
155
+ sendDocument(to: string, documentUrl: string, caption?: string, filename?: string): Observable<WhatsAppResponse>;
156
+ deliverDocument(params: DocumentDeliveryParams): Observable<WhatsAppResponse>;
157
+ sendDocumentWithTemplate(params: {
158
+ phone: string;
159
+ file: File;
160
+ templateName: string;
161
+ bodyParams?: string[];
162
+ languageCode?: string;
163
+ filename?: string;
164
+ }): Observable<WhatsAppResponse>;
165
+ sendDocumentWithMessages(params: {
166
+ phone: string;
167
+ file: File;
168
+ messages: {
169
+ main: string;
170
+ promo: string;
171
+ };
172
+ }): Observable<WhatsAppResponse>;
173
+ getProviderStatus(): Observable<any>;
174
+ isValidPhone(phone: string): boolean;
175
+ toDisplayFormat(phone: string): string;
176
+ static ɵfac: i0.ɵɵFactoryDeclaration<WhatsAppMessagingFacade, never>;
177
+ static ɵprov: i0.ɵɵInjectableDeclaration<WhatsAppMessagingFacade>;
178
+ }
179
+
180
+ declare class PrinterFacade {
181
+ private readonly printerPort;
182
+ askToPrint(params: PrintParams): void;
183
+ printOrder(id: number): void;
184
+ printCommanda(id: number): void;
185
+ printOrderWithCommanda(id: number): void;
186
+ printInvoice(id: number, documentoId: number): void;
187
+ printNotaEntrega(id: number, documentoId: number): void;
188
+ autoPrint(data: {
189
+ printerAutomatic: boolean;
190
+ orderId: number;
191
+ idDocumento: number;
192
+ }, codDoc: string): void;
193
+ static ɵfac: i0.ɵɵFactoryDeclaration<PrinterFacade, never>;
194
+ static ɵprov: i0.ɵɵInjectableDeclaration<PrinterFacade>;
195
+ }
196
+
197
+ declare class MetaWhatsAppAdapter implements WhatsAppMessagingPort {
198
+ private readonly http;
199
+ sendText(request: WhatsAppTextRequest): Observable<WhatsAppResponse>;
200
+ sendTextTemplate(request: WhatsAppTextTemplateRequest): Observable<WhatsAppResponse>;
201
+ sendDocument(request: WhatsAppDocumentRequest): Observable<WhatsAppResponse>;
202
+ sendDocumentTemplate(request: WhatsAppDocumentTemplateRequest): Observable<WhatsAppResponse>;
203
+ getStatus(): Observable<WhatsAppStatusResponse>;
204
+ static ɵfac: i0.ɵɵFactoryDeclaration<MetaWhatsAppAdapter, never>;
205
+ static ɵprov: i0.ɵɵInjectableDeclaration<MetaWhatsAppAdapter>;
206
+ }
207
+
208
+ /**
209
+ * Adaptador para Green API (legacy)
210
+ * Implementa la interfaz WhatsApp usando Green API
211
+ */
212
+ declare class GreenWhatsAppAdapter implements WhatsAppMessagingPort {
213
+ private readonly http;
214
+ sendText(request: WhatsAppTextRequest): Observable<WhatsAppResponse>;
215
+ sendTextTemplate(request: WhatsAppTextTemplateRequest): Observable<WhatsAppResponse>;
216
+ sendDocument(request: WhatsAppDocumentRequest): Observable<WhatsAppResponse>;
217
+ sendDocumentTemplate(request: WhatsAppDocumentTemplateRequest): Observable<WhatsAppResponse>;
218
+ getStatus(): Observable<WhatsAppStatusResponse>;
219
+ static ɵfac: i0.ɵɵFactoryDeclaration<GreenWhatsAppAdapter, never>;
220
+ static ɵprov: i0.ɵɵInjectableDeclaration<GreenWhatsAppAdapter>;
221
+ }
222
+
223
+ declare class ReportAdapter implements ReportPort {
224
+ private readonly http;
225
+ generate<T>(options: ReportGenerationOptions<T>): Observable<HttpResponse<Blob>> | void;
226
+ getFileName(response: any): string;
227
+ saveFile(response: any, format?: string, forceDownload?: boolean): void;
228
+ static ɵfac: i0.ɵɵFactoryDeclaration<ReportAdapter, never>;
229
+ static ɵprov: i0.ɵɵInjectableDeclaration<ReportAdapter>;
230
+ }
231
+
232
+ declare class PrinterAdapter implements PrinterPort {
233
+ private readonly http;
234
+ askToPrint(obj: PrintParams): void;
235
+ getPrintConfig(obj: PrintParams): Observable<ApiResponse>;
236
+ print(urlPrinter: string, paramsToPrint: PrintParams): Observable<ApiResponse>;
237
+ createPrintOrder(id: number): void;
238
+ createPrintCommanda(id: number): void;
239
+ createPrintOrderWithCommanda(id: number): void;
240
+ createInvoicePrint(id: number, documentoId: number): void;
241
+ createNotaEntregaPrint(id: number, documentoId: number): void;
242
+ static ɵfac: i0.ɵɵFactoryDeclaration<PrinterAdapter, never>;
243
+ static ɵprov: i0.ɵɵInjectableDeclaration<PrinterAdapter>;
244
+ }
245
+
246
+ interface ReportDocumentData {
247
+ codDoc: string;
248
+ codEstab?: string;
249
+ id?: number;
250
+ serie?: string;
251
+ }
252
+ interface ReportParams {
253
+ hasService?: boolean;
254
+ reportParams: string;
255
+ dataParams: string;
256
+ }
257
+ declare class ReportParamsBuilder {
258
+ private readonly reportConfigs;
259
+ /**
260
+ * Construye los parámetros de reporte según el tipo de documento
261
+ */
262
+ buildParams(docData: ReportDocumentData, format?: 'pdf' | 'excel' | 'word'): ReportParams;
263
+ /**
264
+ * Determina si debe usar la API v1 según el tipo de documento
265
+ */
266
+ shouldUseV1Api(codDoc: string): boolean;
267
+ /**
268
+ * Obtiene la configuración para un tipo de documento
269
+ */
270
+ private getReportConfig;
271
+ /**
272
+ * Construye los parámetros del reporte
273
+ */
274
+ private buildReportParams;
275
+ /**
276
+ * Construye los parámetros de datos
277
+ */
278
+ private buildDataParams;
279
+ /**
280
+ * Método de conveniencia para generar reporte directamente
281
+ */
282
+ generateReportFor(docData: ReportDocumentData, format?: 'pdf' | 'excel' | 'word', returnBlob?: boolean): {
283
+ data: ReportParams;
284
+ format: "pdf" | "excel" | "word";
285
+ useV1Api: boolean;
286
+ returnBlob: boolean;
287
+ };
288
+ /**
289
+ * Obtiene la lista de tipos de documento soportados
290
+ */
291
+ getSupportedDocumentTypes(): string[];
292
+ /**
293
+ * Verifica si un tipo de documento está soportado
294
+ */
295
+ isDocumentTypeSupported(codDoc: string): boolean;
296
+ static ɵfac: i0.ɵɵFactoryDeclaration<ReportParamsBuilder, never>;
297
+ static ɵprov: i0.ɵɵInjectableDeclaration<ReportParamsBuilder>;
298
+ }
299
+
300
+ interface DocumentDeliveryData {
301
+ comprador: string;
302
+ establecimiento: string;
303
+ serie: string;
304
+ tipo: string;
305
+ }
306
+ interface WhatsAppMessages {
307
+ main: string;
308
+ promo: string;
309
+ }
310
+ declare class WhatsAppMessageBuilder {
311
+ buildDocumentDeliveryMessages(data: DocumentDeliveryData): WhatsAppMessages;
312
+ buildWelcomeMessage(customerName: string, establishmentName: string): string;
313
+ buildOrderConfirmationMessage(orderNumber: string, customerName: string): string;
314
+ buildPaymentReminderMessage(customerName: string, amount: number, dueDate: string): string;
315
+ private buildMainMessage;
316
+ private buildPromoMessage;
317
+ private getDocumentTypeDisplay;
318
+ static ɵfac: i0.ɵɵFactoryDeclaration<WhatsAppMessageBuilder, never>;
319
+ static ɵprov: i0.ɵɵInjectableDeclaration<WhatsAppMessageBuilder>;
320
+ }
321
+
322
+ /**
323
+ * Utilidades para manejo de archivos y respuestas HTTP
324
+ */
325
+ declare class FileMapperUtil {
326
+ /**
327
+ * Extrae el nombre de archivo desde el header Content-Disposition
328
+ */
329
+ static extractFileName(response: any): string;
330
+ /**
331
+ * Crea un objeto File desde una respuesta HTTP
332
+ */
333
+ static fromResponse(response: any): File;
334
+ /**
335
+ * Descarga un archivo usando la API nativa del navegador
336
+ */
337
+ static downloadFile(blob: Blob, fileName: string): void;
338
+ /**
339
+ * Abre un archivo en una nueva ventana (para PDFs)
340
+ */
341
+ static openFile(blob: Blob, fileName: string): void;
342
+ /**
343
+ * Detecta si es un navegador legacy que requiere descarga forzada
344
+ */
345
+ static isLegacyBrowser(): boolean;
346
+ private static generateDefaultFileName;
347
+ }
348
+
349
+ interface PhoneValidationResult {
350
+ isValid: boolean;
351
+ cleanPhone: string;
352
+ errorMessage?: string;
353
+ }
354
+ /**
355
+ * Utilidades para formateo y validación de números telefónicos
356
+ */
357
+ declare class PhoneFormatterUtil {
358
+ /**
359
+ * Limpia el teléfono removiendo todos los caracteres no numéricos
360
+ */
361
+ static cleanPhone(phone: string): string;
362
+ /**
363
+ * Valida si un teléfono ecuatoriano es válido
364
+ */
365
+ static validateEcuadorianPhone(phone: string): PhoneValidationResult;
366
+ /**
367
+ * Convierte número local ecuatoriano a formato internacional
368
+ */
369
+ static toInternationalFormat(phone: string): string;
370
+ /**
371
+ * Formatea teléfono para la API de WhatsApp Business (con @c.us)
372
+ */
373
+ static formatForWhatsAppApi(phone: string): string;
374
+ /**
375
+ * Formatea teléfono para WhatsApp Web (sin @c.us)
376
+ */
377
+ static formatForWhatsAppWeb(phone: string): string;
378
+ /**
379
+ * Formatea teléfono para mostrar al usuario (con espacios y +)
380
+ */
381
+ static formatForDisplay(phone: string): string;
382
+ /**
383
+ * Validación general para teléfonos internacionales
384
+ */
385
+ static isValidInternationalPhone(phone: string): boolean;
386
+ /**
387
+ * Genera el hint apropiado según el estado del teléfono
388
+ */
389
+ static getPhoneHint(phone: string): string;
390
+ /**
391
+ * Obtiene el placeholder para el campo de teléfono
392
+ */
393
+ static getPhonePlaceholder(): string;
394
+ }
395
+
396
+ interface DocumentData {
397
+ idDocumentoElectronico?: number;
398
+ documentoId?: number;
399
+ codDoc: string;
400
+ docType?: string;
401
+ codEstab?: string;
402
+ id?: number;
403
+ serie?: string;
404
+ }
405
+ interface WhatsAppSendConfig {
406
+ documentData?: DocumentData;
407
+ phoneNumbers?: string[];
408
+ defaultMessage?: string;
409
+ establishmentPhone?: string;
410
+ establishmentName?: string;
411
+ customerName?: string;
412
+ }
413
+ declare class WhatsAppSender implements OnInit {
414
+ config?: WhatsAppSendConfig;
415
+ private readonly fb;
416
+ private readonly whatsappFacade;
417
+ private readonly reportFacade;
418
+ private readonly snackBar;
419
+ private readonly reportBuilder;
420
+ whatsappForm: FormGroup;
421
+ isLoading: i0.WritableSignal<boolean>;
422
+ messageLength: number;
423
+ phoneNumbers: i0.WritableSignal<string[]>;
424
+ showWhatsAppWebLink: i0.WritableSignal<boolean>;
425
+ whatsAppWebUrl: i0.WritableSignal<string>;
426
+ establishmentPhone: string;
427
+ establishmentName: string;
428
+ customerName: string;
429
+ ngOnInit(): void;
430
+ private loadConfigData;
431
+ private initializeForm;
432
+ private ecuadorianPhoneValidator;
433
+ private setupMessageLengthCounter;
434
+ sendWhatsApp(): void;
435
+ private validatePhoneNumber;
436
+ private sendSimpleMessage;
437
+ private sendWithDocument;
438
+ private generateReport;
439
+ private processReportFile;
440
+ private sendMediaWithMessages;
441
+ private prepareWhatsAppWebLink;
442
+ openWhatsAppWeb(): void;
443
+ hideWhatsAppWebLink(): void;
444
+ private showSuccess;
445
+ private showError;
446
+ clearForm(): void;
447
+ get formattedPhoneDisplay(): string;
448
+ get phonePlaceholder(): string;
449
+ get phoneHint(): string;
450
+ static ɵfac: i0.ɵɵFactoryDeclaration<WhatsAppSender, never>;
451
+ static ɵcmp: i0.ɵɵComponentDeclaration<WhatsAppSender, "acp-whatsapp-sender", never, { "config": { "alias": "config"; "required": false; }; }, {}, never, never, true, never>;
452
+ }
453
+
454
+ export { API_PATHS, DOCUMENT_TYPES, FileMapperUtil, GreenWhatsAppAdapter, MetaWhatsAppAdapter, PRINTER_PORT, PhoneFormatterUtil, PrinterAdapter, PrinterFacade, REPORT_PORT, ReportAdapter, ReportFacade, ReportParamsBuilder, WHATSAPP_MESSAGING_PORT, WhatsAppMessageBuilder, WhatsAppMessagingFacade, WhatsAppSender };
455
+ export type { ApiResponse, DocumentData, DocumentDeliveryData, DocumentDeliveryParams, PhoneValidationResult, PrintConfig, PrintParams, PrinterPort, ReportDocumentData, ReportGenerationOptions, ReportParams, ReportPort, WhatsAppDocumentMessage, WhatsAppDocumentRequest, WhatsAppDocumentTemplateMessage, WhatsAppDocumentTemplateRequest, WhatsAppMessageResponse, WhatsAppMessages, WhatsAppMessagingPort, WhatsAppProviderStatus, WhatsAppResponse, WhatsAppSendConfig, WhatsAppStatusResponse, WhatsAppTemplateMessage, WhatsAppTextMessage, WhatsAppTextRequest, WhatsAppTextTemplateRequest };