arca-sdk 1.0.4 → 1.1.1

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/dist/index.cjs CHANGED
@@ -507,8 +507,17 @@ var WsaaService = class {
507
507
  // src/types/wsfe.ts
508
508
  var InvoiceType = /* @__PURE__ */ ((InvoiceType2) => {
509
509
  InvoiceType2[InvoiceType2["FACTURA_A"] = 1] = "FACTURA_A";
510
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_A"] = 2] = "NOTA_DEBITO_A";
511
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_A"] = 3] = "NOTA_CREDITO_A";
512
+ InvoiceType2[InvoiceType2["RECIBO_A"] = 4] = "RECIBO_A";
510
513
  InvoiceType2[InvoiceType2["FACTURA_B"] = 6] = "FACTURA_B";
514
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_B"] = 7] = "NOTA_DEBITO_B";
515
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_B"] = 8] = "NOTA_CREDITO_B";
516
+ InvoiceType2[InvoiceType2["RECIBO_B"] = 9] = "RECIBO_B";
511
517
  InvoiceType2[InvoiceType2["FACTURA_C"] = 11] = "FACTURA_C";
518
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_C"] = 12] = "NOTA_DEBITO_C";
519
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_C"] = 13] = "NOTA_CREDITO_C";
520
+ InvoiceType2[InvoiceType2["RECIBO_C"] = 15] = "RECIBO_C";
512
521
  InvoiceType2[InvoiceType2["TICKET_A"] = 81] = "TICKET_A";
513
522
  InvoiceType2[InvoiceType2["TICKET_B"] = 82] = "TICKET_B";
514
523
  InvoiceType2[InvoiceType2["TICKET_C"] = 83] = "TICKET_C";
@@ -715,7 +724,8 @@ var WsfeService = class _WsfeService {
715
724
  buyer: {
716
725
  docType: 99 /* FINAL_CONSUMER */,
717
726
  docNumber: "0"
718
- }
727
+ },
728
+ optionals: params.optionals
719
729
  });
720
730
  }
721
731
  /**
@@ -732,62 +742,99 @@ var WsfeService = class _WsfeService {
732
742
  buyer: {
733
743
  docType: 99 /* FINAL_CONSUMER */,
734
744
  docNumber: "0"
735
- }
745
+ },
746
+ optionals: params.optionals
736
747
  });
737
748
  return { ...cae, items: params.items };
738
749
  }
739
750
  /**
740
- * Emite una Factura C (consumidor final, sin discriminación de IVA).
751
+ * Emite una Factura A (Responsable Inscripto a Responsable Inscripto, con IVA discriminado).
752
+ * REQUIERE `vatRate` en todos los items.
741
753
  */
742
- async issueInvoiceC(params) {
743
- const total = round(calculateTotal(params.items));
744
- return this.issueDocument({
745
- type: 11 /* FACTURA_C */,
746
- concept: params.concept || 1 /* PRODUCTS */,
747
- total,
748
- date: params.date,
749
- buyer: {
750
- docType: 99 /* FINAL_CONSUMER */,
751
- docNumber: "0"
752
- },
753
- items: params.items
754
- });
754
+ async issueInvoiceA(params) {
755
+ return this.issueInvoiceWithVAT(1 /* FACTURA_A */, params);
755
756
  }
756
757
  /**
757
758
  * Emite una Factura B (con IVA discriminado).
758
759
  * REQUIERE `vatRate` en todos los items.
759
760
  */
760
761
  async issueInvoiceB(params) {
761
- this.validateItemsWithVAT(params.items);
762
- const includesVAT = params.includesVAT || false;
763
- const vatData = this.calculateVATByRate(params.items, includesVAT);
764
- return this.issueDocument({
765
- type: 6 /* FACTURA_B */,
766
- concept: params.concept || 1 /* PRODUCTS */,
767
- items: params.items,
768
- buyer: params.buyer,
769
- date: params.date,
770
- vatData,
771
- includesVAT
772
- });
762
+ return this.issueInvoiceWithVAT(6 /* FACTURA_B */, params);
773
763
  }
774
764
  /**
775
- * Emite una Factura A (Responsable Inscripto a Responsable Inscripto, con IVA discriminado).
776
- * REQUIERE `vatRate` en todos los items.
765
+ * Emite una Factura C (consumidor final, sin discriminación de IVA).
777
766
  */
778
- async issueInvoiceA(params) {
779
- this.validateItemsWithVAT(params.items);
780
- const includesVAT = params.includesVAT || false;
781
- const vatData = this.calculateVATByRate(params.items, includesVAT);
782
- return this.issueDocument({
783
- type: 1 /* FACTURA_A */,
784
- concept: params.concept || 1 /* PRODUCTS */,
785
- items: params.items,
786
- buyer: params.buyer,
787
- date: params.date,
788
- vatData,
789
- includesVAT
790
- });
767
+ async issueInvoiceC(params) {
768
+ return this.issueInvoiceWithoutVAT(11 /* FACTURA_C */, params);
769
+ }
770
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
771
+ // Recibos
772
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
773
+ /**
774
+ * Emite un Recibo A (con IVA discriminado).
775
+ */
776
+ async issueReceiptA(params) {
777
+ return this.issueInvoiceWithVAT(4 /* RECIBO_A */, params);
778
+ }
779
+ /**
780
+ * Emite un Recibo B (con IVA discriminado).
781
+ */
782
+ async issueReceiptB(params) {
783
+ return this.issueInvoiceWithVAT(9 /* RECIBO_B */, params);
784
+ }
785
+ /**
786
+ * Emite un Recibo C (sin discriminación de IVA).
787
+ */
788
+ async issueReceiptC(params) {
789
+ return this.issueInvoiceWithoutVAT(15 /* RECIBO_C */, params);
790
+ }
791
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
792
+ // Notas de Crédito
793
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
794
+ /**
795
+ * Emite una Nota de Crédito A.
796
+ * REQUIERE especificar la Factura A original en `associatedInvoices`.
797
+ */
798
+ async issueCreditNoteA(params) {
799
+ return this.issueInvoiceWithVAT(3 /* NOTA_CREDITO_A */, params);
800
+ }
801
+ /**
802
+ * Emite una Nota de Crédito B.
803
+ * REQUIERE especificar la Factura B original en `associatedInvoices`.
804
+ */
805
+ async issueCreditNoteB(params) {
806
+ return this.issueInvoiceWithVAT(8 /* NOTA_CREDITO_B */, params);
807
+ }
808
+ /**
809
+ * Emite una Nota de Crédito C.
810
+ * REQUIERE especificar la Factura C original en `associatedInvoices`.
811
+ */
812
+ async issueCreditNoteC(params) {
813
+ return this.issueInvoiceWithoutVAT(13 /* NOTA_CREDITO_C */, params);
814
+ }
815
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
816
+ // Notas de Débito
817
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
818
+ /**
819
+ * Emite una Nota de Débito A.
820
+ * REQUIERE especificar la Factura A original en `associatedInvoices`.
821
+ */
822
+ async issueDebitNoteA(params) {
823
+ return this.issueInvoiceWithVAT(2 /* NOTA_DEBITO_A */, params);
824
+ }
825
+ /**
826
+ * Emite una Nota de Débito B.
827
+ * REQUIERE especificar la Factura B original en `associatedInvoices`.
828
+ */
829
+ async issueDebitNoteB(params) {
830
+ return this.issueInvoiceWithVAT(7 /* NOTA_DEBITO_B */, params);
831
+ }
832
+ /**
833
+ * Emite una Nota de Débito C.
834
+ * REQUIERE especificar la Factura C original en `associatedInvoices`.
835
+ */
836
+ async issueDebitNoteC(params) {
837
+ return this.issueInvoiceWithoutVAT(12 /* NOTA_DEBITO_C */, params);
791
838
  }
792
839
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
793
840
  // Consultas
@@ -848,6 +895,11 @@ var WsfeService = class _WsfeService {
848
895
  );
849
896
  }
850
897
  const det = data.ResultGet;
898
+ let optionals;
899
+ if (det.Opcionales && det.Opcionales.Opcional) {
900
+ const optList = Array.isArray(det.Opcionales.Opcional) ? det.Opcionales.Opcional : [det.Opcionales.Opcional];
901
+ optionals = optList.map((o) => ({ id: String(o.Id), value: String(o.Valor) }));
902
+ }
851
903
  return {
852
904
  invoiceType: Number(det.CbteTipo),
853
905
  pointOfSale: Number(det.PtoVta),
@@ -861,7 +913,8 @@ var WsfeService = class _WsfeService {
861
913
  vat: Number(det.ImpIVA),
862
914
  cae: String(det.CodAutorizacion),
863
915
  caeExpiry: String(det.FchVto),
864
- result: det.Resultado
916
+ result: det.Resultado,
917
+ optionals
865
918
  };
866
919
  }
867
920
  /**
@@ -918,6 +971,65 @@ var WsfeService = class _WsfeService {
918
971
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
919
972
  // Métodos internos
920
973
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
974
+ /**
975
+ * Helper para emitir comprobantes tipo A/B que requieren IVA
976
+ */
977
+ async issueInvoiceWithVAT(type, params) {
978
+ this.validateItemsWithVAT(params.items);
979
+ this.validateAssociatedInvoices(type, params.associatedInvoices);
980
+ const includesVAT = params.includesVAT || false;
981
+ const vatData = this.calculateVATByRate(params.items, includesVAT);
982
+ return this.issueDocument({
983
+ type,
984
+ concept: params.concept || 1 /* PRODUCTS */,
985
+ items: params.items,
986
+ buyer: params.buyer,
987
+ associatedInvoices: params.associatedInvoices,
988
+ date: params.date,
989
+ vatData,
990
+ includesVAT,
991
+ optionals: params.optionals
992
+ });
993
+ }
994
+ /**
995
+ * Helper para emitir comprobantes tipo C que no discriminan IVA
996
+ */
997
+ async issueInvoiceWithoutVAT(type, params) {
998
+ this.validateAssociatedInvoices(type, params.associatedInvoices);
999
+ const total = round(calculateTotal(params.items));
1000
+ return this.issueDocument({
1001
+ type,
1002
+ concept: params.concept || 1 /* PRODUCTS */,
1003
+ total,
1004
+ date: params.date,
1005
+ buyer: params.buyer || {
1006
+ docType: 99 /* FINAL_CONSUMER */,
1007
+ docNumber: "0"
1008
+ },
1009
+ items: params.items,
1010
+ associatedInvoices: params.associatedInvoices,
1011
+ optionals: params.optionals
1012
+ });
1013
+ }
1014
+ /**
1015
+ * Validación obligatoria para NC/ND
1016
+ */
1017
+ validateAssociatedInvoices(type, associatedInvoices) {
1018
+ const needsAssociation = [
1019
+ 3 /* NOTA_CREDITO_A */,
1020
+ 2 /* NOTA_DEBITO_A */,
1021
+ 8 /* NOTA_CREDITO_B */,
1022
+ 7 /* NOTA_DEBITO_B */,
1023
+ 13 /* NOTA_CREDITO_C */,
1024
+ 12 /* NOTA_DEBITO_C */
1025
+ ].includes(type);
1026
+ if (needsAssociation && (!associatedInvoices || associatedInvoices.length === 0)) {
1027
+ throw new ArcaValidationError(
1028
+ "Las Notas de Cr\xE9dito y D\xE9bito requieren al menos un comprobante asociado.",
1029
+ { hint: "Debes enviar el arreglo `associatedInvoices` con la factura original a la cual haces referencia" }
1030
+ );
1031
+ }
1032
+ }
921
1033
  /**
922
1034
  * Método genérico interno para emitir cualquier tipo de comprobante.
923
1035
  */
@@ -942,10 +1054,12 @@ var WsfeService = class _WsfeService {
942
1054
  concept: request.concept,
943
1055
  date: request.date || /* @__PURE__ */ new Date(),
944
1056
  buyer: request.buyer,
1057
+ associatedInvoices: request.associatedInvoices,
945
1058
  net,
946
1059
  vat,
947
1060
  total,
948
- vatData: request.vatData
1061
+ vatData: request.vatData,
1062
+ optionals: request.optionals
949
1063
  });
950
1064
  const endpoint = getWsfeEndpoint(this.config.environment);
951
1065
  const response = await callArcaApi(endpoint, {
@@ -1087,6 +1201,21 @@ var WsfeService = class _WsfeService {
1087
1201
  });
1088
1202
  vatXml += "\n </ar:Iva>";
1089
1203
  }
1204
+ let asocXml = "";
1205
+ if (params.associatedInvoices && params.associatedInvoices.length > 0) {
1206
+ asocXml = "<ar:CbtesAsoc>";
1207
+ params.associatedInvoices.forEach((asoc) => {
1208
+ asocXml += `
1209
+ <ar:CbteAsoc>
1210
+ <ar:Tipo>${asoc.type}</ar:Tipo>
1211
+ <ar:PtoVta>${asoc.pointOfSale}</ar:PtoVta>
1212
+ <ar:Nro>${asoc.invoiceNumber}</ar:Nro>
1213
+ ${asoc.cuit ? `<ar:Cuit>${asoc.cuit}</ar:Cuit>` : ""}
1214
+ ${asoc.date ? `<ar:CbteFch>${asoc.date.toISOString().split("T")[0].replace(/-/g, "")}</ar:CbteFch>` : ""}
1215
+ </ar:CbteAsoc>`;
1216
+ });
1217
+ asocXml += "\n </ar:CbtesAsoc>";
1218
+ }
1090
1219
  return `<?xml version="1.0" encoding="UTF-8"?>
1091
1220
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
1092
1221
  xmlns:ar="http://ar.gov.afip.dif.FEV1/">
@@ -1120,6 +1249,7 @@ var WsfeService = class _WsfeService {
1120
1249
  <ar:ImpTrib>0.00</ar:ImpTrib>
1121
1250
  <ar:MonId>PES</ar:MonId>
1122
1251
  <ar:MonCotiz>1</ar:MonCotiz>
1252
+ ${asocXml}
1123
1253
  ${vatXml}
1124
1254
  </ar:FECAEDetRequest>
1125
1255
  </ar:FeDetReq>