@experteam-mx/ngx-services 20.9.9 → 20.10.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.
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, makeEnvironmentProviders, NgModule, inject, Injectable } from '@angular/core';
3
3
  import { provideHttpClient, HttpClient, HttpHeaders, HttpResponse, HttpParams } from '@angular/common/http';
4
- import { map, mergeMap, forkJoin, tap, BehaviorSubject, merge, firstValueFrom, Observable, of } from 'rxjs';
4
+ import { map, mergeMap, forkJoin, tap, BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs';
5
5
  import { map as map$1, tap as tap$1, finalize, shareReplay } from 'rxjs/operators';
6
6
  import { CookieService } from 'ngx-cookie-service';
7
7
  import Pusher from 'pusher-js';
@@ -2948,6 +2948,26 @@ class ApiCustomsService {
2948
2948
  params
2949
2949
  }).pipe(map(({ data }) => data));
2950
2950
  }
2951
+ /**
2952
+ * Retrieves the documents for a specific country.
2953
+ *
2954
+ * @param {DocumentsByCountryIn} body - The body of the request.
2955
+ * @return {Observable<DocumentsByCountryOut>} An Observable that emits the documents.
2956
+ */
2957
+ postDocumentsByCountry(body) {
2958
+ return this.http.post(`${this.url}/documents/by-country`, body)
2959
+ .pipe(map(({ data }) => data));
2960
+ }
2961
+ /**
2962
+ * Prints a document for a specific country and code.
2963
+ *
2964
+ * @param {DocumentsPrintIn} body - The body of the request.
2965
+ * @return {Observable<DocumentsPrintOut>} An Observable that emits the printed document.
2966
+ */
2967
+ postDocumentsPrint(body) {
2968
+ return this.http.post(`${this.url}/documents/print`, body)
2969
+ .pipe(map(({ data }) => data));
2970
+ }
2951
2971
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiCustomsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2952
2972
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiCustomsService, providedIn: 'root' });
2953
2973
  }
@@ -2979,6 +2999,36 @@ class ApiDiscountsService {
2979
2999
  return this.http.get(`${this.url}/discounts`, { params })
2980
3000
  .pipe(map(({ data }) => data));
2981
3001
  }
3002
+ /**
3003
+ * Retrieves a list of active discounts.
3004
+ *
3005
+ * @param {QueryParams} [params] - Optional query parameters to filter active discounts.
3006
+ * @return {Observable<DiscountsOut>} An Observable that emits the active discounts data.
3007
+ */
3008
+ getDiscountsActives(params) {
3009
+ return this.http.get(`${this.url}/discounts/actives`, { params })
3010
+ .pipe(map(({ data }) => data));
3011
+ }
3012
+ /**
3013
+ * Searches for a customer by identification, phone, or email (Version 2).
3014
+ *
3015
+ * @param {OperationsSearchCustomerV2In} body - The search criteria for the customer.
3016
+ * @return {Observable<OperationsSearchCustomerV2Out>} An Observable that emits the search result.
3017
+ */
3018
+ postOperationsSearchCustomerV2(body) {
3019
+ return this.http.post(`${this.url}/operations/search-customer/V2`, body)
3020
+ .pipe(map(({ data }) => data));
3021
+ }
3022
+ /**
3023
+ * Creates a registered customer (Version 2).
3024
+ *
3025
+ * @param {RegisteredCustomerIn} body - The registered customer data to create.
3026
+ * @return {Observable<RegisteredCustomerOut>} An Observable that emits the created registered customer.
3027
+ */
3028
+ postRegisteredCustomersV2(body) {
3029
+ return this.http.post(`${this.url}/registered-customers/V2`, body)
3030
+ .pipe(map(({ data }) => data));
3031
+ }
2982
3032
  /**
2983
3033
  * Sends a request to create or update discounts on the server.
2984
3034
  *
@@ -3216,6 +3266,27 @@ class ApiDropoffsService {
3216
3266
  postShipmentsEReceipt(body) {
3217
3267
  return this.http.post(`${this.url}/shipments/ereceipt`, body).pipe(map(({ data }) => data));
3218
3268
  }
3269
+ /**
3270
+ * Retrieves the check-in print payload for the given operation.
3271
+ *
3272
+ * @param {number} operationId - The unique identifier of the check-in operation to print.
3273
+ * @param {QueryParams} params - The query parameters used to customize the print request.
3274
+ * @return {Observable<CheckInPrintOut>} An observable that emits the check-in print data.
3275
+ */
3276
+ getCheckInPrint(operationId, params) {
3277
+ return this.http.get(`${this.url}/check-in/print/${operationId}`, { params })
3278
+ .pipe(map(({ data }) => data));
3279
+ }
3280
+ /**
3281
+ * Retrieves the printable ticket payload for the given dropoff operation.
3282
+ *
3283
+ * @param {number} operationId - The unique identifier of the operation.
3284
+ * @return {Observable<OperationTicketsOut>} An observable that emits the operation ticket data.
3285
+ */
3286
+ getOperationTickets(operationId) {
3287
+ return this.http.get(`${this.url}/operations/${operationId}/tickets`)
3288
+ .pipe(map(({ data }) => data));
3289
+ }
3219
3290
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiDropoffsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3220
3291
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiDropoffsService, providedIn: 'root' });
3221
3292
  }
@@ -3904,8 +3975,8 @@ class ApiInvoicesService {
3904
3975
  * @param documentId - Numeric identifier of the document to print.
3905
3976
  * @returns An Observable that emits the ticket data for the given document.
3906
3977
  */
3907
- getOperationPrintTicket(documentId) {
3908
- return this.http.get(`${this.url}/operation/print/ticket/${documentId}`)
3978
+ getOperationPrintTicket(documentId, params) {
3979
+ return this.http.get(`${this.url}/operation/print/ticket/${documentId}`, { params })
3909
3980
  .pipe(map(({ data }) => data));
3910
3981
  }
3911
3982
  /**
@@ -3937,7 +4008,7 @@ class ApiInvoicesService {
3937
4008
  * @param {number} id - The unique identifier of the collection for which the receipt needs to be retrieved.
3938
4009
  * @return {Observable<PrintCollectionReceiptOut>} An observable containing the collection receipt data.
3939
4010
  */
3940
- getPrintCollectionReceipt(id) {
4011
+ getOperationPrintCollectionReceipt(id) {
3941
4012
  return this.http.get(`${this.url}/operation/print/collection-receipt/${id}`)
3942
4013
  .pipe(map(({ data }) => data));
3943
4014
  }
@@ -5328,6 +5399,26 @@ class ApiShipmentsService {
5328
5399
  return this.http.get(`${this.url}/shipments/${id}/documents`)
5329
5400
  .pipe(map(({ data }) => data));
5330
5401
  }
5402
+ /**
5403
+ * Retrieves the label for a specific shipment
5404
+ * @param {number} shipmentId - The unique identifier of the shipment to retrieve the label for
5405
+ * @returns {Observable<ShipmentLabelOut>} Observable containing the label for the shipment
5406
+ */
5407
+ getShipmentLabel(shipmentId, format = 'pdf') {
5408
+ return this.http.get(`${this.url}/shipments/${shipmentId}/label/${format}`)
5409
+ .pipe(map(({ data }) => data));
5410
+ }
5411
+ /**
5412
+ * Generates a commercial invoice label for the specified shipment.
5413
+ *
5414
+ * @param {number} shipmentId - The unique identifier of the shipment.
5415
+ * @param {CommercialInvoiceLabelIn} body - Payload containing the invoice label date.
5416
+ * @returns {Observable<CommercialInvoiceLabelOut>} Observable emitting the generated commercial invoice label for the shipment.
5417
+ */
5418
+ postCommercialInvoiceLabel(shipmentId, body) {
5419
+ return this.http.post(`${this.url}/commercial-invoice-labels/${shipmentId}`, body)
5420
+ .pipe(map(({ data }) => data));
5421
+ }
5331
5422
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiShipmentsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
5332
5423
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.27", ngImport: i0, type: ApiShipmentsService, providedIn: 'root' });
5333
5424
  }
@@ -5624,11 +5715,11 @@ var PrintersType;
5624
5715
  })(PrintersType || (PrintersType = {}));
5625
5716
 
5626
5717
  class PrintersService {
5627
- environments = inject(ENVIRONMENT_TOKEN);
5628
5718
  http = inject(HttpClient);
5629
5719
  availablePrinters$ = new BehaviorSubject([]);
5630
- printMode = PrintMode.DISPLAY;
5631
5720
  printers = [];
5721
+ printMode = PrintMode.DISPLAY;
5722
+ printServiceUrl = '';
5632
5723
  /**
5633
5724
  * Retrieves the print URL from the environments configuration or defaults to 'http://localhost:9100'
5634
5725
  * if not specified.
@@ -5636,7 +5727,15 @@ class PrintersService {
5636
5727
  * @return {string} The URL to be used for printing.
5637
5728
  */
5638
5729
  get url() {
5639
- return this.environments.printUrl ?? 'http://localhost:9100';
5730
+ return this.printServiceUrl || 'http://localhost:9100';
5731
+ }
5732
+ /**
5733
+ * Indicates whether any configured printers are available for use.
5734
+ *
5735
+ * @return {boolean} Returns true if at least one printer is configured; otherwise, false.
5736
+ */
5737
+ get usingPrinters() {
5738
+ return this.printers.some((printer) => printer.configured);
5640
5739
  }
5641
5740
  /**
5642
5741
  * Prints or displays a document based on the current print mode.
@@ -5646,9 +5745,9 @@ class PrintersService {
5646
5745
  * @param {Printable} document - The document to be printed or displayed.
5647
5746
  * @return {Promise<void>} A promise that resolves when the printing or displaying process is complete, or rejects if an error occurs.
5648
5747
  */
5649
- print(document) {
5748
+ print(document, printMode = this.printMode) {
5650
5749
  return new Promise((resolve, reject) => {
5651
- switch (this.printMode) {
5750
+ switch (printMode) {
5652
5751
  case PrintMode.PRINT:
5653
5752
  this.sendToPrinter(document).then(() => resolve()).catch(reject);
5654
5753
  break;
@@ -5656,13 +5755,11 @@ class PrintersService {
5656
5755
  this.sendToBrowser(document).then(resolve).catch(reject);
5657
5756
  break;
5658
5757
  case PrintMode.BOTH:
5659
- merge([
5758
+ Promise.all([
5660
5759
  this.sendToBrowser(document),
5661
5760
  this.sendToPrinter(document)
5662
- ]).subscribe({
5663
- next: () => resolve(),
5664
- error: reject,
5665
- });
5761
+ ]).then(() => resolve())
5762
+ .catch(reject);
5666
5763
  break;
5667
5764
  }
5668
5765
  });
@@ -5675,8 +5772,9 @@ class PrintersService {
5675
5772
  * @param {PrintMode} config.printMode - The mode of printing, defining whether to use print, digital, or both.
5676
5773
  * @return {void} This method does not return any value.
5677
5774
  */
5678
- setUp({ country, printMode }) {
5775
+ setUp({ country, printMode, printServiceUrl }) {
5679
5776
  this.printMode = printMode;
5777
+ this.printServiceUrl = printServiceUrl || '';
5680
5778
  if (this.printMode === PrintMode.BOTH || this.printMode === PrintMode.PRINT) {
5681
5779
  this.checkPrinters(country);
5682
5780
  }
@@ -5691,10 +5789,9 @@ class PrintersService {
5691
5789
  setDown() {
5692
5790
  this.printers = [];
5693
5791
  this.availablePrinters$.next(this.printers);
5694
- this.availablePrinters$.complete();
5695
5792
  }
5696
5793
  sendToPrinter({ type, content, format }) {
5697
- const printer = this.printers.find(({ name }) => name === type);
5794
+ const printer = this.printers.find((printer) => printer.type === type && printer.configured);
5698
5795
  if (!printer) {
5699
5796
  throw new Error(`Printer ${type} not found.`);
5700
5797
  }
@@ -5708,7 +5805,7 @@ class PrintersService {
5708
5805
  return new Promise((resolve, reject) => {
5709
5806
  try {
5710
5807
  if (format === PrintableFormat.ZPL2) {
5711
- return;
5808
+ return resolve();
5712
5809
  }
5713
5810
  downloadBase64Pdf(content);
5714
5811
  resolve();
@@ -5719,22 +5816,26 @@ class PrintersService {
5719
5816
  });
5720
5817
  }
5721
5818
  checkPrinters(country) {
5819
+ this.printers = [];
5722
5820
  if (country.label_printer_name) {
5723
5821
  this.printers.push({
5724
- name: PrintersType.LABEL,
5725
5822
  configured: false,
5823
+ name: country.label_printer_name,
5824
+ type: PrintersType.LABEL,
5726
5825
  });
5727
5826
  }
5728
5827
  if (country.receipt_printer_name) {
5729
5828
  this.printers.push({
5730
- name: PrintersType.RECEIPT,
5731
5829
  configured: false,
5830
+ name: country.receipt_printer_name,
5831
+ type: PrintersType.RECEIPT,
5732
5832
  });
5733
5833
  }
5734
5834
  if (country.others_printer_name) {
5735
5835
  this.printers.push({
5736
- name: PrintersType.OTHERS,
5737
5836
  configured: false,
5837
+ name: country.others_printer_name,
5838
+ type: PrintersType.OTHERS,
5738
5839
  });
5739
5840
  }
5740
5841
  this.http.get(`${this.url}/available`)