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.js CHANGED
@@ -461,8 +461,17 @@ var WsaaService = class {
461
461
  // src/types/wsfe.ts
462
462
  var InvoiceType = /* @__PURE__ */ ((InvoiceType2) => {
463
463
  InvoiceType2[InvoiceType2["FACTURA_A"] = 1] = "FACTURA_A";
464
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_A"] = 2] = "NOTA_DEBITO_A";
465
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_A"] = 3] = "NOTA_CREDITO_A";
466
+ InvoiceType2[InvoiceType2["RECIBO_A"] = 4] = "RECIBO_A";
464
467
  InvoiceType2[InvoiceType2["FACTURA_B"] = 6] = "FACTURA_B";
468
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_B"] = 7] = "NOTA_DEBITO_B";
469
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_B"] = 8] = "NOTA_CREDITO_B";
470
+ InvoiceType2[InvoiceType2["RECIBO_B"] = 9] = "RECIBO_B";
465
471
  InvoiceType2[InvoiceType2["FACTURA_C"] = 11] = "FACTURA_C";
472
+ InvoiceType2[InvoiceType2["NOTA_DEBITO_C"] = 12] = "NOTA_DEBITO_C";
473
+ InvoiceType2[InvoiceType2["NOTA_CREDITO_C"] = 13] = "NOTA_CREDITO_C";
474
+ InvoiceType2[InvoiceType2["RECIBO_C"] = 15] = "RECIBO_C";
466
475
  InvoiceType2[InvoiceType2["TICKET_A"] = 81] = "TICKET_A";
467
476
  InvoiceType2[InvoiceType2["TICKET_B"] = 82] = "TICKET_B";
468
477
  InvoiceType2[InvoiceType2["TICKET_C"] = 83] = "TICKET_C";
@@ -669,7 +678,8 @@ var WsfeService = class _WsfeService {
669
678
  buyer: {
670
679
  docType: 99 /* FINAL_CONSUMER */,
671
680
  docNumber: "0"
672
- }
681
+ },
682
+ optionals: params.optionals
673
683
  });
674
684
  }
675
685
  /**
@@ -686,62 +696,99 @@ var WsfeService = class _WsfeService {
686
696
  buyer: {
687
697
  docType: 99 /* FINAL_CONSUMER */,
688
698
  docNumber: "0"
689
- }
699
+ },
700
+ optionals: params.optionals
690
701
  });
691
702
  return { ...cae, items: params.items };
692
703
  }
693
704
  /**
694
- * Emite una Factura C (consumidor final, sin discriminación de IVA).
705
+ * Emite una Factura A (Responsable Inscripto a Responsable Inscripto, con IVA discriminado).
706
+ * REQUIERE `vatRate` en todos los items.
695
707
  */
696
- async issueInvoiceC(params) {
697
- const total = round(calculateTotal(params.items));
698
- return this.issueDocument({
699
- type: 11 /* FACTURA_C */,
700
- concept: params.concept || 1 /* PRODUCTS */,
701
- total,
702
- date: params.date,
703
- buyer: {
704
- docType: 99 /* FINAL_CONSUMER */,
705
- docNumber: "0"
706
- },
707
- items: params.items
708
- });
708
+ async issueInvoiceA(params) {
709
+ return this.issueInvoiceWithVAT(1 /* FACTURA_A */, params);
709
710
  }
710
711
  /**
711
712
  * Emite una Factura B (con IVA discriminado).
712
713
  * REQUIERE `vatRate` en todos los items.
713
714
  */
714
715
  async issueInvoiceB(params) {
715
- this.validateItemsWithVAT(params.items);
716
- const includesVAT = params.includesVAT || false;
717
- const vatData = this.calculateVATByRate(params.items, includesVAT);
718
- return this.issueDocument({
719
- type: 6 /* FACTURA_B */,
720
- concept: params.concept || 1 /* PRODUCTS */,
721
- items: params.items,
722
- buyer: params.buyer,
723
- date: params.date,
724
- vatData,
725
- includesVAT
726
- });
716
+ return this.issueInvoiceWithVAT(6 /* FACTURA_B */, params);
727
717
  }
728
718
  /**
729
- * Emite una Factura A (Responsable Inscripto a Responsable Inscripto, con IVA discriminado).
730
- * REQUIERE `vatRate` en todos los items.
719
+ * Emite una Factura C (consumidor final, sin discriminación de IVA).
731
720
  */
732
- async issueInvoiceA(params) {
733
- this.validateItemsWithVAT(params.items);
734
- const includesVAT = params.includesVAT || false;
735
- const vatData = this.calculateVATByRate(params.items, includesVAT);
736
- return this.issueDocument({
737
- type: 1 /* FACTURA_A */,
738
- concept: params.concept || 1 /* PRODUCTS */,
739
- items: params.items,
740
- buyer: params.buyer,
741
- date: params.date,
742
- vatData,
743
- includesVAT
744
- });
721
+ async issueInvoiceC(params) {
722
+ return this.issueInvoiceWithoutVAT(11 /* FACTURA_C */, params);
723
+ }
724
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
725
+ // Recibos
726
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
727
+ /**
728
+ * Emite un Recibo A (con IVA discriminado).
729
+ */
730
+ async issueReceiptA(params) {
731
+ return this.issueInvoiceWithVAT(4 /* RECIBO_A */, params);
732
+ }
733
+ /**
734
+ * Emite un Recibo B (con IVA discriminado).
735
+ */
736
+ async issueReceiptB(params) {
737
+ return this.issueInvoiceWithVAT(9 /* RECIBO_B */, params);
738
+ }
739
+ /**
740
+ * Emite un Recibo C (sin discriminación de IVA).
741
+ */
742
+ async issueReceiptC(params) {
743
+ return this.issueInvoiceWithoutVAT(15 /* RECIBO_C */, params);
744
+ }
745
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
746
+ // Notas de Crédito
747
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
748
+ /**
749
+ * Emite una Nota de Crédito A.
750
+ * REQUIERE especificar la Factura A original en `associatedInvoices`.
751
+ */
752
+ async issueCreditNoteA(params) {
753
+ return this.issueInvoiceWithVAT(3 /* NOTA_CREDITO_A */, params);
754
+ }
755
+ /**
756
+ * Emite una Nota de Crédito B.
757
+ * REQUIERE especificar la Factura B original en `associatedInvoices`.
758
+ */
759
+ async issueCreditNoteB(params) {
760
+ return this.issueInvoiceWithVAT(8 /* NOTA_CREDITO_B */, params);
761
+ }
762
+ /**
763
+ * Emite una Nota de Crédito C.
764
+ * REQUIERE especificar la Factura C original en `associatedInvoices`.
765
+ */
766
+ async issueCreditNoteC(params) {
767
+ return this.issueInvoiceWithoutVAT(13 /* NOTA_CREDITO_C */, params);
768
+ }
769
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
770
+ // Notas de Débito
771
+ // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
772
+ /**
773
+ * Emite una Nota de Débito A.
774
+ * REQUIERE especificar la Factura A original en `associatedInvoices`.
775
+ */
776
+ async issueDebitNoteA(params) {
777
+ return this.issueInvoiceWithVAT(2 /* NOTA_DEBITO_A */, params);
778
+ }
779
+ /**
780
+ * Emite una Nota de Débito B.
781
+ * REQUIERE especificar la Factura B original en `associatedInvoices`.
782
+ */
783
+ async issueDebitNoteB(params) {
784
+ return this.issueInvoiceWithVAT(7 /* NOTA_DEBITO_B */, params);
785
+ }
786
+ /**
787
+ * Emite una Nota de Débito C.
788
+ * REQUIERE especificar la Factura C original en `associatedInvoices`.
789
+ */
790
+ async issueDebitNoteC(params) {
791
+ return this.issueInvoiceWithoutVAT(12 /* NOTA_DEBITO_C */, params);
745
792
  }
746
793
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
747
794
  // Consultas
@@ -802,6 +849,11 @@ var WsfeService = class _WsfeService {
802
849
  );
803
850
  }
804
851
  const det = data.ResultGet;
852
+ let optionals;
853
+ if (det.Opcionales && det.Opcionales.Opcional) {
854
+ const optList = Array.isArray(det.Opcionales.Opcional) ? det.Opcionales.Opcional : [det.Opcionales.Opcional];
855
+ optionals = optList.map((o) => ({ id: String(o.Id), value: String(o.Valor) }));
856
+ }
805
857
  return {
806
858
  invoiceType: Number(det.CbteTipo),
807
859
  pointOfSale: Number(det.PtoVta),
@@ -815,7 +867,8 @@ var WsfeService = class _WsfeService {
815
867
  vat: Number(det.ImpIVA),
816
868
  cae: String(det.CodAutorizacion),
817
869
  caeExpiry: String(det.FchVto),
818
- result: det.Resultado
870
+ result: det.Resultado,
871
+ optionals
819
872
  };
820
873
  }
821
874
  /**
@@ -872,6 +925,65 @@ var WsfeService = class _WsfeService {
872
925
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
873
926
  // Métodos internos
874
927
  // ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
928
+ /**
929
+ * Helper para emitir comprobantes tipo A/B que requieren IVA
930
+ */
931
+ async issueInvoiceWithVAT(type, params) {
932
+ this.validateItemsWithVAT(params.items);
933
+ this.validateAssociatedInvoices(type, params.associatedInvoices);
934
+ const includesVAT = params.includesVAT || false;
935
+ const vatData = this.calculateVATByRate(params.items, includesVAT);
936
+ return this.issueDocument({
937
+ type,
938
+ concept: params.concept || 1 /* PRODUCTS */,
939
+ items: params.items,
940
+ buyer: params.buyer,
941
+ associatedInvoices: params.associatedInvoices,
942
+ date: params.date,
943
+ vatData,
944
+ includesVAT,
945
+ optionals: params.optionals
946
+ });
947
+ }
948
+ /**
949
+ * Helper para emitir comprobantes tipo C que no discriminan IVA
950
+ */
951
+ async issueInvoiceWithoutVAT(type, params) {
952
+ this.validateAssociatedInvoices(type, params.associatedInvoices);
953
+ const total = round(calculateTotal(params.items));
954
+ return this.issueDocument({
955
+ type,
956
+ concept: params.concept || 1 /* PRODUCTS */,
957
+ total,
958
+ date: params.date,
959
+ buyer: params.buyer || {
960
+ docType: 99 /* FINAL_CONSUMER */,
961
+ docNumber: "0"
962
+ },
963
+ items: params.items,
964
+ associatedInvoices: params.associatedInvoices,
965
+ optionals: params.optionals
966
+ });
967
+ }
968
+ /**
969
+ * Validación obligatoria para NC/ND
970
+ */
971
+ validateAssociatedInvoices(type, associatedInvoices) {
972
+ const needsAssociation = [
973
+ 3 /* NOTA_CREDITO_A */,
974
+ 2 /* NOTA_DEBITO_A */,
975
+ 8 /* NOTA_CREDITO_B */,
976
+ 7 /* NOTA_DEBITO_B */,
977
+ 13 /* NOTA_CREDITO_C */,
978
+ 12 /* NOTA_DEBITO_C */
979
+ ].includes(type);
980
+ if (needsAssociation && (!associatedInvoices || associatedInvoices.length === 0)) {
981
+ throw new ArcaValidationError(
982
+ "Las Notas de Cr\xE9dito y D\xE9bito requieren al menos un comprobante asociado.",
983
+ { hint: "Debes enviar el arreglo `associatedInvoices` con la factura original a la cual haces referencia" }
984
+ );
985
+ }
986
+ }
875
987
  /**
876
988
  * Método genérico interno para emitir cualquier tipo de comprobante.
877
989
  */
@@ -896,10 +1008,12 @@ var WsfeService = class _WsfeService {
896
1008
  concept: request.concept,
897
1009
  date: request.date || /* @__PURE__ */ new Date(),
898
1010
  buyer: request.buyer,
1011
+ associatedInvoices: request.associatedInvoices,
899
1012
  net,
900
1013
  vat,
901
1014
  total,
902
- vatData: request.vatData
1015
+ vatData: request.vatData,
1016
+ optionals: request.optionals
903
1017
  });
904
1018
  const endpoint = getWsfeEndpoint(this.config.environment);
905
1019
  const response = await callArcaApi(endpoint, {
@@ -1041,6 +1155,21 @@ var WsfeService = class _WsfeService {
1041
1155
  });
1042
1156
  vatXml += "\n </ar:Iva>";
1043
1157
  }
1158
+ let asocXml = "";
1159
+ if (params.associatedInvoices && params.associatedInvoices.length > 0) {
1160
+ asocXml = "<ar:CbtesAsoc>";
1161
+ params.associatedInvoices.forEach((asoc) => {
1162
+ asocXml += `
1163
+ <ar:CbteAsoc>
1164
+ <ar:Tipo>${asoc.type}</ar:Tipo>
1165
+ <ar:PtoVta>${asoc.pointOfSale}</ar:PtoVta>
1166
+ <ar:Nro>${asoc.invoiceNumber}</ar:Nro>
1167
+ ${asoc.cuit ? `<ar:Cuit>${asoc.cuit}</ar:Cuit>` : ""}
1168
+ ${asoc.date ? `<ar:CbteFch>${asoc.date.toISOString().split("T")[0].replace(/-/g, "")}</ar:CbteFch>` : ""}
1169
+ </ar:CbteAsoc>`;
1170
+ });
1171
+ asocXml += "\n </ar:CbtesAsoc>";
1172
+ }
1044
1173
  return `<?xml version="1.0" encoding="UTF-8"?>
1045
1174
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
1046
1175
  xmlns:ar="http://ar.gov.afip.dif.FEV1/">
@@ -1074,6 +1203,7 @@ var WsfeService = class _WsfeService {
1074
1203
  <ar:ImpTrib>0.00</ar:ImpTrib>
1075
1204
  <ar:MonId>PES</ar:MonId>
1076
1205
  <ar:MonCotiz>1</ar:MonCotiz>
1206
+ ${asocXml}
1077
1207
  ${vatXml}
1078
1208
  </ar:FECAEDetRequest>
1079
1209
  </ar:FeDetReq>