UNPKG

envio-comprobantes-sri

Version:

Envia comprobantes electronicos al SRI (Ecuador). Recibe un objeto JSON. Lo convierte a XML, lo firma, lo envía al servicio web del SRI y devuelve la respuesta.

47 lines (46 loc) 2.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AutorizacionXMLEnviado_SRI = void 0; const axios_1 = __importDefault(require("axios")); const TablasSRI_1 = require("./Structures/Utils/TablasSRI"); const urls_1 = __importDefault(require("./urls")); const parseWebServiceResponse_1 = __importDefault(require("./Utils/parseWebServiceResponse")); async function AutorizacionXMLEnviado_SRI(clave_acceso, signal, ambiente) { const xml_envelope = ` <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ec="http://ec.gob.sri.ws.autorizacion"> <soapenv:Header /> <soapenv:Body> <ec:autorizacionComprobante> <claveAccesoComprobante>${clave_acceso}</claveAccesoComprobante> </ec:autorizacionComprobante> </soapenv:Body> </soapenv:Envelope>`.replace(/\n/g, "").replace(/\t/g, "").replace(/ /g, ""); const endpoint = ambiente === TablasSRI_1.TablaAmbiente.PRODUCCION ? urls_1.default.AUTORIZACION_PRODUCCION : urls_1.default.AUTORIZACION_PRUEBAS; const response = await axios_1.default.post(endpoint, xml_envelope, { headers: { "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br" }, method: "POST", signal }); if (response.headers.get("Content-Type").indexOf("text/xml") < 0) { throw new Error("The https request response with a non-xml value"); } const xml = (0, parseWebServiceResponse_1.default)(response.data, "Autorizar_XML", xml_envelope); return { estado: xml.getTextValue("estado") // String crudo del SRI: ISO 8601 con offset de Ecuador (ej. "2026-03-11T23:53:55-05:00"). // Se propaga sin conversion — no usar new Date() sobre este valor. , fechaAutorizacion: xml.getTextValue("fechaAutorizacion"), ambiente: xml.getTextValue("ambiente"), xml_received: response.data, xml_sent: xml_envelope }; } exports.AutorizacionXMLEnviado_SRI = AutorizacionXMLEnviado_SRI;