UNPKG

facturapi

Version:

Librería oficial de Facturapi. Crea CFDIs timbrados y enviados al SAT, XML y PDF

3 lines (2 loc) 28.6 kB
"use strict";var ge=Object.create;var Y=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var Ne=(t,e,n,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let u of Se(e))!Re.call(t,u)&&u!==n&&Y(t,u,{get:()=>e[u],enumerable:!(l=Ie(e,u))||l.enumerable});return t};var $=(t,e,n)=>(n=t!=null?ge(be(t)):{},Ne(e||!t||!t.__esModule?Y(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class De{constructor(e){this.client=e}create(e,n=null){return this.client.post("/customers",{body:e,params:n})}list(e){return e||(e={}),this.client.get("/customers",{params:e})}retrieve(e){return e?this.client.get("/customers/"+e):Promise.reject(new Error("id is required"))}update(e,n,l=null){return this.client.put("/customers/"+e,{body:n,params:l})}del(e){return this.client.delete("/customers/"+e)}validateTaxInfo(e){return this.client.get("/customers/"+e+"/tax-info-validation")}sendEditLinkByEmail(e,n){return this.client.post("/customers/"+e+"/email-edit-link",{body:n})}}class we{constructor(e){this.client=e}create(e){return this.client.post("/products",{body:e})}list(e){return this.client.get("/products",{params:e})}retrieve(e){return e?this.client.get("/products/"+e):Promise.reject(new Error("id is required"))}update(e,n){return this.client.put("/products/"+e,{body:n})}del(e){return this.client.delete("/products/"+e)}}class Ce{constructor(e){this.client=e}create(e,n){return this.client.post("/invoices",{body:e,params:n})}list(e){return e||(e={}),this.client.get("/invoices",{params:e})}retrieve(e){return e?this.client.get("/invoices/"+e):Promise.reject(new Error("id is required"))}cancel(e,n){return this.client.delete("/invoices/"+e,{params:n})}sendByEmail(e,n){return this.client.post("/invoices/"+e+"/email",{body:n})}async downloadPdf(e){return this.client.get("/invoices/"+e+"/pdf")}async downloadXml(e){return this.client.get("/invoices/"+e+"/xml")}downloadZip(e){return this.client.get("/invoices/"+e+"/zip")}downloadCancellationReceiptXml(e){return this.client.get("/invoices/"+e+"/cancellation_receipt/xml")}downloadCancellationReceiptPdf(e){return this.client.get("/invoices/"+e+"/cancellation_receipt/pdf")}updateDraft(e,n){return this.client.put("/invoices/"+e,{body:n})}stampDraft(e,n){return this.client.post("/invoices/"+e+"/stamp",{params:n})}updateStatus(e){return this.client.put("/invoices/"+e+"/status")}copyToDraft(e){return this.client.post("/invoices/"+e+"/copy")}previewPdf(e){return this.client.post("/invoices/preview/pdf",{body:e})}}var Te=function(){return typeof globalThis<"u"?globalThis:typeof self<"u"?self:window}(),{FormData:W,Blob:$e,File:ve}=Te;const Pe="https://www.facturapi.io/v2",me="https://www.facturapi.io/v1",te="v2",T=typeof process<"u"&&!!process?.versions?.node,re=typeof navigator<"u"&&navigator?.product==="ReactNative";function Le(t){return new Promise((e,n)=>{const l=[];t.on("data",u=>l.push(u)),t.on("end",()=>e(Buffer.concat(l))),t.on("error",n)})}const B=async(t,e,n)=>{if(T){const l=t instanceof Buffer?t:await Le(t);return new ve([l],e,{type:n})}return t};class Be{constructor(e){this.client=e}create(e){return this.client.post("/organizations",{body:e})}list(e){return e||(e={}),this.client.get("/organizations",{params:e})}retrieve(e){return e?this.client.get("/organizations/"+e):Promise.reject(new Error("id is required"))}updateLegal(e,n){return e?this.client.put("/organizations/"+e+"/legal",{body:n}):Promise.reject(new Error("id is required"))}updateCustomization(e,n){return this.client.put("/organizations/"+e+"/customization",{body:n})}updateReceiptSettings(e,n){return this.client.put("/organizations/"+e+"/receipts",{body:n})}updateDomain(e,n){return this.client.put("/organizations/"+e+"/domain",{body:n})}checkDomainIsAvailable(e){return this.client.put("/organizations/domain-check",{body:e})}async uploadLogo(e,n){const l=await B(n,"file","application/octet-stream"),u=new W;return u.append("file",l,"file"),this.client.put("/organizations/"+e+"/logo",{formData:u})}async uploadCertificate(e,n,l,u){let a=new W;const[c,d]=await Promise.all([B(n,"cer.cer","application/octet-stream"),B(l,"key.key","application/octet-stream")]);return a.append("cer",c,"cer.cer"),a.append("key",d,"key.key"),a.append("password",u),this.client.put("/organizations/"+e+"/certificate",{formData:a})}deleteCertificate(e){return this.client.delete("/organizations/"+e+"/certificate")}del(e){return e?this.client.delete("/organizations/"+e):Promise.reject(new Error("id is required"))}getTestApiKey(e){return this.client.get("/organizations/"+e+"/apikeys/test")}renewTestApiKey(e){return this.client.put("/organizations/"+e+"/apikeys/test")}async listLiveApiKeys(e){return this.client.get("/organizations/"+e+"/apikeys/live")}renewLiveApiKey(e){return this.client.put("/organizations/"+e+"/apikeys/live")}async deleteLiveApiKey(e,n){return this.client.delete("/organizations/"+e+"/apikeys/live/"+n)}listSeriesGroup(e){return this.client.get("/organizations/"+e+"/series-group")}createSeriesGroup(e,n){return this.client.post("/organizations/"+e+"/series-group",{body:n})}updateSeriesGroup(e,n,l){return this.client.put(`/organizations/${e}/series-group/${n}`,{body:l})}deleteSeriesGroup(e,n){return this.client.delete(`/organizations/${e}/series-group/${n}`)}me(){return this.client.get("/organizations/me")}updateSelfInvoiceSettings(e,n){return this.client.put("/organizations/"+e+"/self-invoice",{body:n})}}class Me{constructor(e){this.client=e}searchProducts(e){return this.client.get("/catalogs/products",{params:e})}searchUnits(e){return this.client.get("/catalogs/units",{params:e})}}class Ue{constructor(e){this.client=e}create(e){return this.client.post("/receipts",{body:e})}list(e){return e||(e={}),this.client.get("/receipts",{params:e})}retrieve(e){return e?this.client.get("/receipts/"+e):Promise.reject(new Error("id is required"))}invoice(e,n){return this.client.post("/receipts/"+e+"/invoice",{body:n})}createGlobalInvoice(e){return this.client.post("/receipts/global-invoice",{body:e})}cancel(e){return this.client.delete("/receipts/"+e)}sendByEmail(e,n){return this.client.post("/receipts/"+e+"/email",{body:n})}downloadPdf(e){return this.client.get("/receipts/"+e+"/pdf")}}class Ge{constructor(e){this.client=e}create(e){return this.client.post("/retentions",{body:e})}list(e){return e||(e={}),this.client.get("/retentions",{params:e})}retrieve(e){return e?this.client.get("/retentions/"+e):Promise.reject(new Error("id is required"))}cancel(e,n){return this.client.delete("/retentions/"+e,{params:n})}sendByEmail(e,n){return this.client.post("/retentions/"+e+"/email",{body:n})}downloadPdf(e){return this.client.get("/retentions/"+e+"/pdf")}downloadXml(e){return this.client.get("/retentions/"+e+"/xml")}downloadZip(e){return this.client.get("/retentions/"+e+"/zip")}}class Ve{constructor(e){this.client=e}create(e){return this.client.post("/webhooks",{body:e})}list(e){return e||(e={}),this.client.get("/webhooks",{params:e})}retrieve(e){return e?this.client.get("/webhooks/"+e):Promise.reject(new Error("id is required"))}update(e,n){return this.client.put("/webhooks/"+e,{body:n})}del(e){return this.client.delete("/webhooks/"+e)}async validateSignature(e){const{secret:n,signature:l,payload:u}=e;let a;if(typeof u=="string")a=u;else if(Buffer.isBuffer(u))a=u.toString("utf8");else if(typeof u=="object")a=JSON.stringify(u);else throw new Error("Invalid payload type");if(re)return this.client.post("/webhooks/validate-signature",{body:{secret:n,signature:l,payload:a}});if(T){const c=await import("crypto"),h=c.createHmac("sha256",n).update(a).digest(),A=Buffer.from(l,"hex");if(h.length!==A.length)throw new Error("Invalid signature");if(!c.timingSafeEqual(h,A))throw new Error("Invalid signature");return JSON.parse(a)}else{const c=new TextEncoder,d=c.encode(a),h=c.encode(n),A=await crypto.subtle.sign("HMAC",await crypto.subtle.importKey("raw",h,{name:"HMAC",hash:"SHA-256"},!1,["sign"]),d),S=Array.from(new Uint8Array(A)).map(b=>b.toString(16).padStart(2,"0")).join("").toLowerCase();if(l!==S)throw new Error("Invalid signature")}return JSON.parse(a)}}class Fe{constructor(e){this.client=e}validateTaxId(e){return this.client.get("/tools/tax_id_validation",{params:{tax_id:e}})}}var M=(t=>(t.EFECTIVO="01",t.CHEQUE_NOMINATIVO="02",t.TRANSFERENCIA_ELECTRONICA_DE_FONDOS="03",t.TARJETA_DE_CREDITO="04",t.MONEDERO_ELECTRONICO="05",t.DINERO_ELECTRONICO="06",t.VALES_DE_DESPENSA="08",t.DACION_EN_PAGO="12",t.PAGO_POR_SUBROGACION="13",t.PAGO_POR_CONSIGNACION="14",t.CONDONACION="15",t.COMPENSACION="17",t.NOVACION="23",t.CONFUSION="24",t.REMISIÓN_DE_DEUDA="25",t.PRESCRIPCION_O_CADUCIDAD="26",t.A_SATISFACCION_DEL_ACREEDOR="27",t.TARJETA_DE_DEBITO="28",t.TARJETA_DE_SERVICIOS="29",t.APLICACION_DE_ANTICIPOS="30",t.INTERMEDIARIO_DE_PAGOS="31",t.POR_DEFINIR="99",t))(M||{});const je=[{value:"01",label:"Efectivo"},{value:"02",label:"Cheque nominativo"},{value:"03",label:"Transferencia electrónica de fondos"},{value:"04",label:"Tarjeta de crédito"},{value:"05",label:"Monedero electrónico"},{value:"06",label:"Dinero electrónico"},{value:"08",label:"Vales de despensa"},{value:"12",label:"Dación en pago"},{value:"13",label:"Pago por subrogación"},{value:"14",label:"Pago por consignación"},{value:"15",label:"Condonación"},{value:"17",label:"Compensación"},{value:"23",label:"Novación"},{value:"24",label:"Confusión"},{value:"25",label:"Remisión de deuda"},{value:"26",label:"Prescripción o caducidad"},{value:"27",label:"A satisfacción del acreedor"},{value:"28",label:"Tarjeta de débito"},{value:"29",label:"Tarjeta de servicios"},{value:"30",label:"Aplicación de anticipos"},{value:"31",label:"Intermediario de pagos"},{value:"99",label:"Por definir"}];var U=(t=>(t.IVA="IVA",t.IEPS="IEPS",t.ISR="ISR",t))(U||{}),G=(t=>(t.RATE="Tasa",t.QUOTA="Cuota",t))(G||{}),V=(t=>(t.SUM_BEFORE_TAXES="sum_before_taxes",t.UNIT="unit",t.BREAK_DOWN="break_down",t.SUBTRACT_BEFORE_BREAKDOWN="subtract_before_break_down",t))(V||{}),F=(t=>(t.PAGO_EN_UNA_EXHIBICION="PUE",t.PAGO_EN_PARCIALIDADES_DIFERIDO="PPD",t))(F||{}),j=(t=>(t.ADQUISICION_MERCANCIAS="G01",t.DEVOLUCIONES_DESCUENTOS_BONIFICACIONES="G02",t.GASTOS_EN_GENERAL="G03",t.CONSTRUCCIONES="I01",t.MOBILIARIO_Y_EQUIPO_DE_OFICINA="I02",t.EQUIPO_DE_TRANSPORTE="I03",t.EQUIPO_DE_COMPUTO="I04",t.DADOS_TROQUELES_HERRAMENTAL="I05",t.COMUNICACIONES_TELEFONICAS="I06",t.COMUNICACIONES_SATELITALES="I07",t.OTRA_MAQUINARIA="I08",t.HONORARIOS_MEDICOS="D01",t.GASTOS_MEDICOS_POR_INCAPACIDAD="D02",t.GASTOS_FUNERALES="D03",t.DONATIVOS="D04",t.INTERESES_POR_CREDITOS_HIPOTECARIOS="D05",t.APORTACIONES_VOLUNTARIAS_SAR="D06",t.PRIMA_SEGUROS_GASTOS_MEDICOS="D07",t.GASTOS_TRANSPORTACION_ESCOLAR="D08",t.CUENTAS_AHORRO_PENSIONES="D09",t.SERVICIOS_EDUCATIVOS="D10",t.SIN_EFECTOS_FISCALES="S01",t.PAGOS="CP01",t.NOMINA="CN01",t.POR_DEFINIR="P01",t))(j||{}),k=(t=>(t.INGRESO="I",t.EGRESO="E",t.TRASLADO="T",t.NOMINA="N",t.PAGO="P",t))(k||{}),z=(t=>(t.NOTA_DE_CREDITO="01",t.NOTA_DE_DEBITO="02",t.DELOVUCION_DE_MERCANCIA="03",t.SUSTITUCION_DE_CFDI_PREVIOS="04",t.TRASLADOS_DE_MERCANCIA_FACTURADOS_PREVIAMENTE="05",t.FACTURA_POR_TRASLADOS_PREVIOS="06",t.APLICACION_DE_ANTICIPO="07",t))(z||{}),H=(t=>(t.GENERAL_LEY_DE_PERSONAS_MORALES="601",t.PERSONAS_MORALES_CON_FINES_NO_LUCRATIVOS="603",t.SUELDOS_Y_SALARIOS="605",t.ARRENDAMIENTO="606",t.REGIMEN_DE_ENAJENACION_O_ADQUISICION_DE_BIENES="607",t.DEMAS_INGRESOS="608",t.RESIDENTES_EN_EL_EXTRANJERO_SIN_ESTABLECIMIENTO_PERMANENTE_EN_MÉXICO="610",t.RESIDENTES_EN_EL_EXTRANJERO="610",t.INGRESOS_POR_DIVIDENDOS_SOCIOS_Y_ACCIONISTAS="611",t.PERSONAS_FISICAS_CON_ACTIVIDADES_EMPRESARIALES_Y_PROFESIONALES="612",t.INGRESOS_POR_INTERESES="614",t.REGIMEN_DE_LOS_INGRESOS_POR_OBTENCION_DE_PREMIOS="615",t.SIN_OBLIGACIONES_FISCALES="616",t.SOCIEDADES_COOPERATIVAS_DE_PRODUCCION="620",t.REGIMEN_DE_INCORPORACION_FISCAL="621",t.ACTIVIDADES_AGRICOLAS_GANADERAS_SILVICOLAS_Y_PESQUERAS="622",t.OPCIONAL_PARA_GRUPOS_DE_SOCIEDADES="623",t.COORDINADOS="624",t.ACTIVIDADES_EMPRESARIALES_CON_INGRESOS_A_TRAVÉS_DE_PLATAFORMAS_TECNOLÓGICAS="625",t.RÉGIMEN_SIMPLIFICADO_DE_CONFIANZA="626",t))(H||{}),q=(t=>(t.DRAFT="draft",t.PENDING="pending",t.VALID="valid",t.CANCELED="canceled",t.FAILED="failed",t))(q||{}),ie=(t=>(t.DAY="day",t.WEEK="week",t.FORTNIGHT="fortnight",t.MONTH="month",t.TWO_MONTHS="two_months",t))(ie||{}),ne=(t=>(t.OPEN="open",t.CANCELED="canceled",t.INVOICED_TO_CUSTOMER="invoiced_to_customer",t.INVOICED_GLOBALLY="invoiced_globally",t))(ne||{}),se=(t=>(t.ISSUING="issuing",t.RECEIVING="receiving",t))(se||{}),oe=(t=>(t.NONE="none",t.ACCEPTED="accepted",t.PENDING="pending",t.REJECTED="rejected",t.EXPIRED="expired",t))(oe||{}),ae=(t=>(t.DAY="day",t.WEEK="week",t.FORTNIGHT="fortnight",t.MONTH="month",t.TWO_MONTHS="two_months",t))(ae||{}),ce=(t=>(t.CUSTOM="custom",t.PAGO="pago",t.NOMINA="nomina",t))(ce||{}),x=(t=>(t.ERRORES_CON_RELACION="01",t.ERRORES_SIN_RELACION="02",t.NO_SE_CONCRETO="03",t.FACTURA_GLOBAL="04",t))(x||{}),D=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ke(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var w={exports:{}},Z;function ze(){return Z||(Z=1,function(t,e){var n=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof D<"u"&&D,l=function(){function a(){this.fetch=!1,this.DOMException=n.DOMException}return a.prototype=n,new a}();(function(a){(function(c){var d=typeof a<"u"&&a||typeof self<"u"&&self||typeof D<"u"&&D||{},h={searchParams:"URLSearchParams"in d,iterable:"Symbol"in d&&"iterator"in Symbol,blob:"FileReader"in d&&"Blob"in d&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in d,arrayBuffer:"ArrayBuffer"in d};function A(r){return r&&DataView.prototype.isPrototypeOf(r)}if(h.arrayBuffer)var S=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],b=ArrayBuffer.isView||function(r){return r&&S.indexOf(Object.prototype.toString.call(r))>-1};function y(r){if(typeof r!="string"&&(r=String(r)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(r)||r==="")throw new TypeError('Invalid character in header field name: "'+r+'"');return r.toLowerCase()}function R(r){return typeof r!="string"&&(r=String(r)),r}function v(r){var i={next:function(){var s=r.shift();return{done:s===void 0,value:s}}};return h.iterable&&(i[Symbol.iterator]=function(){return i}),i}function E(r){this.map={},r instanceof E?r.forEach(function(i,s){this.append(s,i)},this):Array.isArray(r)?r.forEach(function(i){if(i.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+i.length);this.append(i[0],i[1])},this):r&&Object.getOwnPropertyNames(r).forEach(function(i){this.append(i,r[i])},this)}E.prototype.append=function(r,i){r=y(r),i=R(i);var s=this.map[r];this.map[r]=s?s+", "+i:i},E.prototype.delete=function(r){delete this.map[y(r)]},E.prototype.get=function(r){return r=y(r),this.has(r)?this.map[r]:null},E.prototype.has=function(r){return this.map.hasOwnProperty(y(r))},E.prototype.set=function(r,i){this.map[y(r)]=R(i)},E.prototype.forEach=function(r,i){for(var s in this.map)this.map.hasOwnProperty(s)&&r.call(i,this.map[s],s,this)},E.prototype.keys=function(){var r=[];return this.forEach(function(i,s){r.push(s)}),v(r)},E.prototype.values=function(){var r=[];return this.forEach(function(i){r.push(i)}),v(r)},E.prototype.entries=function(){var r=[];return this.forEach(function(i,s){r.push([s,i])}),v(r)},h.iterable&&(E.prototype[Symbol.iterator]=E.prototype.entries);function P(r){if(!r._noBody){if(r.bodyUsed)return Promise.reject(new TypeError("Already read"));r.bodyUsed=!0}}function J(r){return new Promise(function(i,s){r.onload=function(){i(r.result)},r.onerror=function(){s(r.error)}})}function de(r){var i=new FileReader,s=J(i);return i.readAsArrayBuffer(r),s}function he(r){var i=new FileReader,s=J(i),f=/charset=([A-Za-z0-9_-]+)/.exec(r.type),p=f?f[1]:"utf-8";return i.readAsText(r,p),s}function pe(r){for(var i=new Uint8Array(r),s=new Array(i.length),f=0;f<i.length;f++)s[f]=String.fromCharCode(i[f]);return s.join("")}function X(r){if(r.slice)return r.slice(0);var i=new Uint8Array(r.byteLength);return i.set(new Uint8Array(r)),i.buffer}function K(){return this.bodyUsed=!1,this._initBody=function(r){this.bodyUsed=this.bodyUsed,this._bodyInit=r,r?typeof r=="string"?this._bodyText=r:h.blob&&Blob.prototype.isPrototypeOf(r)?this._bodyBlob=r:h.formData&&FormData.prototype.isPrototypeOf(r)?this._bodyFormData=r:h.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)?this._bodyText=r.toString():h.arrayBuffer&&h.blob&&A(r)?(this._bodyArrayBuffer=X(r.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):h.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(r)||b(r))?this._bodyArrayBuffer=X(r):this._bodyText=r=Object.prototype.toString.call(r):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof r=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):h.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},h.blob&&(this.blob=function(){var r=P(this);if(r)return r;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var r=P(this);return r||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(h.blob)return this.blob().then(de);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var r=P(this);if(r)return r;if(this._bodyBlob)return he(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(pe(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},h.formData&&(this.formData=function(){return this.text().then(Oe)}),this.json=function(){return this.text().then(JSON.parse)},this}var Ee=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function _e(r){var i=r.toUpperCase();return Ee.indexOf(i)>-1?i:r}function g(r,i){if(!(this instanceof g))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');i=i||{};var s=i.body;if(r instanceof g){if(r.bodyUsed)throw new TypeError("Already read");this.url=r.url,this.credentials=r.credentials,i.headers||(this.headers=new E(r.headers)),this.method=r.method,this.mode=r.mode,this.signal=r.signal,!s&&r._bodyInit!=null&&(s=r._bodyInit,r.bodyUsed=!0)}else this.url=String(r);if(this.credentials=i.credentials||this.credentials||"same-origin",(i.headers||!this.headers)&&(this.headers=new E(i.headers)),this.method=_e(i.method||this.method||"GET"),this.mode=i.mode||this.mode||null,this.signal=i.signal||this.signal||function(){if("AbortController"in d){var o=new AbortController;return o.signal}}(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&s)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(s),(this.method==="GET"||this.method==="HEAD")&&(i.cache==="no-store"||i.cache==="no-cache")){var f=/([?&])_=[^&]*/;if(f.test(this.url))this.url=this.url.replace(f,"$1_="+new Date().getTime());else{var p=/\?/;this.url+=(p.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}g.prototype.clone=function(){return new g(this,{body:this._bodyInit})};function Oe(r){var i=new FormData;return r.trim().split("&").forEach(function(s){if(s){var f=s.split("="),p=f.shift().replace(/\+/g," "),o=f.join("=").replace(/\+/g," ");i.append(decodeURIComponent(p),decodeURIComponent(o))}}),i}function Ae(r){var i=new E,s=r.replace(/\r?\n[\t ]+/g," ");return s.split("\r").map(function(f){return f.indexOf(` `)===0?f.substr(1,f.length):f}).forEach(function(f){var p=f.split(":"),o=p.shift().trim();if(o){var N=p.join(":").trim();try{i.append(o,N)}catch(L){console.warn("Response "+L.message)}}}),i}K.call(g.prototype);function O(r,i){if(!(this instanceof O))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(i||(i={}),this.type="default",this.status=i.status===void 0?200:i.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=i.statusText===void 0?"":""+i.statusText,this.headers=new E(i.headers),this.url=i.url||"",this._initBody(r)}K.call(O.prototype),O.prototype.clone=function(){return new O(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new E(this.headers),url:this.url})},O.error=function(){var r=new O(null,{status:200,statusText:""});return r.ok=!1,r.status=0,r.type="error",r};var ye=[301,302,303,307,308];O.redirect=function(r,i){if(ye.indexOf(i)===-1)throw new RangeError("Invalid status code");return new O(null,{status:i,headers:{location:r}})},c.DOMException=d.DOMException;try{new c.DOMException}catch{c.DOMException=function(i,s){this.message=i,this.name=s;var f=Error(i);this.stack=f.stack},c.DOMException.prototype=Object.create(Error.prototype),c.DOMException.prototype.constructor=c.DOMException}function m(r,i){return new Promise(function(s,f){var p=new g(r,i);if(p.signal&&p.signal.aborted)return f(new c.DOMException("Aborted","AbortError"));var o=new XMLHttpRequest;function N(){o.abort()}o.onload=function(){var _={statusText:o.statusText,headers:Ae(o.getAllResponseHeaders()||"")};p.url.indexOf("file://")===0&&(o.status<200||o.status>599)?_.status=200:_.status=o.status,_.url="responseURL"in o?o.responseURL:_.headers.get("X-Request-URL");var I="response"in o?o.response:o.responseText;setTimeout(function(){s(new O(I,_))},0)},o.onerror=function(){setTimeout(function(){f(new TypeError("Network request failed"))},0)},o.ontimeout=function(){setTimeout(function(){f(new TypeError("Network request timed out"))},0)},o.onabort=function(){setTimeout(function(){f(new c.DOMException("Aborted","AbortError"))},0)};function L(_){try{return _===""&&d.location.href?d.location.href:_}catch{return _}}if(o.open(p.method,L(p.url),!0),p.credentials==="include"?o.withCredentials=!0:p.credentials==="omit"&&(o.withCredentials=!1),"responseType"in o&&(h.blob?o.responseType="blob":h.arrayBuffer&&(o.responseType="arraybuffer")),i&&typeof i.headers=="object"&&!(i.headers instanceof E||d.Headers&&i.headers instanceof d.Headers)){var Q=[];Object.getOwnPropertyNames(i.headers).forEach(function(_){Q.push(y(_)),o.setRequestHeader(_,R(i.headers[_]))}),p.headers.forEach(function(_,I){Q.indexOf(I)===-1&&o.setRequestHeader(I,_)})}else p.headers.forEach(function(_,I){o.setRequestHeader(I,_)});p.signal&&(p.signal.addEventListener("abort",N),o.onreadystatechange=function(){o.readyState===4&&p.signal.removeEventListener("abort",N)}),o.send(typeof p._bodyInit>"u"?null:p._bodyInit)})}return m.polyfill=!0,d.fetch||(d.fetch=m,d.Headers=E,d.Request=g,d.Response=O),c.Headers=E,c.Request=g,c.Response=O,c.fetch=m,c})({})})(l),l.fetch.ponyfill=!0,delete l.fetch.polyfill;var u=n.fetch?n:l;e=u.fetch,e.default=u.fetch,e.fetch=u.fetch,e.Headers=u.Headers,e.Request=u.Request,e.Response=u.Response,t.exports=e}(w,w.exports)),w.exports}var He=ze();const qe=ke(He);let C;T?C=t=>Buffer.from(t).toString("base64"):re?C=t=>globalThis.Buffer.from(t).toString("base64"):C=globalThis.btoa;const xe=async t=>{if(!t.ok){const n=await t.json();throw new Error(n.message||t.statusText)}const e=t.headers.get("content-type");if(e){if(e.includes("image/")||e.includes("application/pdf")||e.includes("application/xml")||e.includes("application/zip"))if(T){const n=t.body?.getReader();if(!n)return t.body;try{const{Readable:l}=await import("stream");return new l({read(){n.read().then(({done:u,value:a})=>{u?this.push(null):this.push(Buffer.from(a))})}})}catch{throw new Error('Node.js streams are not available in this environment. Please install the "stream" package.')}}else return t.blob();else if(e.includes("application/json"))return t.json()}return t.text()};function Je(t){return C(t)}const Xe=(t,e=te)=>{let n=e==="v1"?me:Pe;const l={Authorization:`Basic ${Je(t+":")}`};return{get baseURL(){return n},set baseURL(a){n=a},async request(a,c){const{params:d,body:h,formData:A,...S}=c||{},b=d?"?"+new URLSearchParams(d).toString():"",y={...S,headers:{...l,...A?{}:{"Content-Type":"application/json"}},body:A||(h?JSON.stringify(h):void 0)},R=await qe(n+a+b,y);return xe(R)},get(a,c){return this.request(a,{method:"GET",...c})},post(a,c){return this.request(a,{method:"POST",...c})},put(a,c){return this.request(a,{method:"PUT",...c})},delete(a,c){return this.request(a,{method:"DELETE",...c})}}};class Ke{constructor(e){this.client=e}searchAirTransportCodes(e){return this.client.get("/catalogs/cartaporte/3.1/air-transport-codes",{params:e})}searchTransportConfigs(e){return this.client.get("/catalogs/cartaporte/3.1/transport-configs",{params:e})}searchRightsOfPassage(e){return this.client.get("/catalogs/cartaporte/3.1/rights-of-passage",{params:e})}searchCustomsDocuments(e){return this.client.get("/catalogs/cartaporte/3.1/customs-documents",{params:e})}searchPackagingTypes(e){return this.client.get("/catalogs/cartaporte/3.1/packaging-types",{params:e})}searchTrailerTypes(e){return this.client.get("/catalogs/cartaporte/3.1/trailer-types",{params:e})}searchHazardousMaterials(e){return this.client.get("/catalogs/cartaporte/3.1/hazardous-materials",{params:e})}searchNavalAuthorizations(e){return this.client.get("/catalogs/cartaporte/3.1/naval-authorizations",{params:e})}searchPortStations(e){return this.client.get("/catalogs/cartaporte/3.1/port-stations",{params:e})}searchMarineContainers(e){return this.client.get("/catalogs/cartaporte/3.1/marine-containers",{params:e})}}var le=(t=>(t.RECEIPT_SELF_INVOICE_COMPLETE="receipt.self_invoice_complete",t.INVOICE_CANCELLATION_STATUS_UPDATED="invoice.cancellation_status_updated",t.RECEIPT_STATUS_UPDATED="receipt.status_updated",t.GLOBAL_INVOICE="invoice.global_invoice_created",t.INVOICES_STATUS_UPDATED="invoice.status_updated",t.INVOICES_CREATED_FROM_DASHBOARD="invoice.created_from_dashboard",t.CUSTOMER_EDIT_LINK_COMPLETED="customer.edit_link_completed",t))(le||{}),ue=(t=>(t.RECEIPT="receipt",t.INVOICE="invoice",t.CUSTOMER="customer",t))(ue||{}),fe=(t=>(t.ENABLED="enabled",t.DISABLED="disabled",t))(fe||{});const ee=["v1","v2"];class Qe{get BASE_URL(){return this._wrapper.baseURL}set BASE_URL(e){this._wrapper.baseURL=e}static get TaxType(){return U}static get TaxFactor(){return G}static get IepsMode(){return V}static get PaymentForm(){return M}static get PaymentMethod(){return F}static get InvoiceType(){return k}static get InvoiceUse(){return j}static get InvoiceRelation(){return z}static get TaxSystem(){return H}static get InvoiceStatus(){return q}static get CancellationMotive(){return x}constructor(e,n={}){if(n.apiVersion){if(!ee.includes(n.apiVersion))throw new Error("Invalid API version. Valid values are: "+ee.join(", "));this.apiVersion=n.apiVersion}else this.apiVersion=te;this._wrapper=Xe(e,this.apiVersion),this.customers=new De(this._wrapper),this.products=new we(this._wrapper),this.invoices=new Ce(this._wrapper),this.organizations=new Be(this._wrapper),this.catalogs=new Me(this._wrapper),this.cartaPorteCatalogs=new Ke(this._wrapper),this.receipts=new Ue(this._wrapper),this.retentions=new Ge(this._wrapper),this.tools=new Fe(this._wrapper),this.webhooks=new Ve(this._wrapper)}}exports.ApiEventDataType=ue;exports.ApiEventType=le;exports.CancellationMotive=x;exports.CancellationStatus=oe;exports.GlobalInvoicePeriodicity=ie;exports.IepsMode=V;exports.InvoiceComplementType=ce;exports.InvoiceRelation=z;exports.InvoiceStatus=q;exports.InvoiceType=k;exports.InvoiceUse=j;exports.InvoicingPeriod=ae;exports.IssuingType=se;exports.PaymentForm=M;exports.PaymentFormList=je;exports.PaymentMethod=F;exports.ReceiptStatus=ne;exports.TaxFactor=G;exports.TaxSystem=H;exports.TaxType=U;exports.WebhookEndpointStatus=fe;exports.default=Qe;