{"_id":"@cooperadoras-digitales/facturajs","_rev":"2-ed8dd4ccb9eb9af3869537e6869a04d7","name":"@cooperadoras-digitales/facturajs","dist-tags":{"latest":"0.2.0-coop2"},"versions":{"0.2.0":{"name":"@cooperadoras-digitales/facturajs","description":"Comunicación con los web services de AFIP utilizando nodejs.","author":{"name":"Emilio Astarita"},"licence":"MIT","version":"0.2.0","engines":{"node":">=12.0.0"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"prettier":"prettier --write \"src/**/*.{md,json,ts}\"","build":"tsc","clean":"rm -rf dist/*","prepare":"npm run clean ; npm run build"},"dependencies":{"debug":"^4.3.1","moment":"^2.29.1","node-forge":"1.3.1","ntpclient":"^1.0.2","soap":"1.0.0","source-map-support":"^0.5.19","uniqid":"^5.2.0","xml2js":"0.6.2","xlsx":"0.18.5","lodash":"^4.17.21","purify-ts":"^1.1.0"},"devDependencies":{"@types/node-forge":"^0.9.6","@types/uniqid":"^5.2.0","@types/xml2js":"^0.4.7","@types/lodash":"^4.14.178","@types/request":"^2.48.8","prettier":"^2.2.1","typescript":"^4.1.3"},"license":"MIT","_id":"@cooperadoras-digitales/facturajs@0.2.0","gitHead":"4254450aa13f30cf087308135a0059884af84f35","_nodeVersion":"18.18.0","_npmVersion":"9.8.1","dist":{"integrity":"sha512-e5hatdVjLdaqD/enKobzDUvU24ZG8qhB76kTCFTnjYy8XpREWFgqXfEwEhiVCjqWSnNIGZ+kCypgdmVCQg+M3g==","shasum":"7309ea6984fcfd5e68bc8de052ef22e8ebec71e8","tarball":"https://registry.npmjs.org/@cooperadoras-digitales/facturajs/-/facturajs-0.2.0.tgz","fileCount":33,"unpackedSize":47551,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFfhhdzCrADTs1UI7ZxSOMZ/PY38u49OtcI9l8G0AZ/oAiBxFD9IYXkZnvCb3i3/zxbFFwbRC7aclEE2ibZSC/vCmA=="}]},"_npmUser":{"name":"jparedes","email":"jparedes@gmail.com"},"directories":{},"maintainers":[{"name":"jparedes","email":"jparedes@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/facturajs_0.2.0_1695301544161_0.5735273678835713"},"_hasShrinkwrap":false},"0.2.0-coop1":{"name":"@cooperadoras-digitales/facturajs","description":"Comunicación con los web services de AFIP utilizando nodejs.","author":{"name":"Emilio Astarita"},"licence":"MIT","version":"0.2.0-coop1","engines":{"node":">=12.0.0"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"prettier":"prettier --write \"src/**/*.{md,json,ts}\"","build":"tsc","clean":"rm -rf dist/*","prepare":"npm run clean ; npm run build"},"dependencies":{"debug":"^4.3.1","moment":"^2.29.1","node-forge":"1.3.1","ntpclient":"^1.0.2","soap":"1.0.0","source-map-support":"^0.5.19","uniqid":"^5.2.0","xml2js":"0.6.2","xlsx":"0.18.5","lodash":"^4.17.21","purify-ts":"^1.1.0"},"devDependencies":{"@types/node-forge":"^0.9.6","@types/uniqid":"^5.2.0","@types/xml2js":"^0.4.7","@types/lodash":"^4.14.178","@types/request":"^2.48.8","prettier":"^2.2.1","typescript":"^4.1.3"},"license":"MIT","licenseText":"MIT License\n\nCopyright (c) 2018 Emilio Astarita\nCopyright (c) 2021 Andrés Q\nCopyright (c) 2023 Cooperadoras-Digitales\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@cooperadoras-digitales/facturajs@0.2.0-coop1","dist":{"shasum":"a76824da89e728e44ad1a448b5628dcd089185be","integrity":"sha512-/ePiX+vpYrPACnohWwPIy+7vqZVJp+en1LXQnGnYwSsoHjGy8HmlOtOORhBoliU0zY+2Cuh6kChnN/WHdpUxLg==","tarball":"https://registry.npmjs.org/@cooperadoras-digitales/facturajs/-/facturajs-0.2.0-coop1.tgz","fileCount":36,"unpackedSize":47557,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCOX3BqfnP+M31XmiM3rdVzS/foP7ejDEBpfffGDMHSUwIhAJeBt97HJ+y9qGiX1VmLzo76kfCEZs8wZemoYcKDYXla"}]},"_npmUser":{"name":"jparedes","email":"jparedes@gmail.com"},"directories":{},"maintainers":[{"name":"jparedes","email":"jparedes@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/facturajs_0.2.0-coop1_1695303680650_0.5407987242418326"},"_hasShrinkwrap":false},"0.2.0-coop2":{"name":"@cooperadoras-digitales/facturajs","description":"Comunicación con los web services de AFIP utilizando nodejs.","author":{"name":"Emilio Astarita"},"licence":"MIT","version":"0.2.0-coop2","engines":{"node":">=12.0.0"},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"prettier":"prettier --write \"src/**/*.{md,json,ts}\"","build":"tsc","clean":"rm -rf dist/*","prepare":"npm run clean ; npm run build"},"dependencies":{"debug":"^4.3.1","moment":"^2.29.1","node-forge":"1.3.1","ntpclient":"^1.0.2","soap":"1.0.0","source-map-support":"^0.5.19","uniqid":"^5.2.0","xml2js":"0.6.2","xlsx":"0.18.5","lodash":"^4.17.21","purify-ts":"^1.1.0"},"devDependencies":{"@types/node-forge":"^0.9.6","@types/uniqid":"^5.2.0","@types/xml2js":"^0.4.7","@types/lodash":"^4.14.178","@types/request":"^2.48.8","prettier":"^2.2.1","typescript":"^4.1.3"},"license":"MIT","licenseText":"MIT License\n\nCopyright (c) 2018 Emilio Astarita\nCopyright (c) 2021 Andrés Q\nCopyright (c) 2023 Cooperadoras-Digitales\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@cooperadoras-digitales/facturajs@0.2.0-coop2","dist":{"shasum":"e0b9db63e155cbb374100e4c27664446a836d5c0","integrity":"sha512-x8fu2vUysVmrqW0GixYcb2dEiuCsT0z9AgzI/h9htNN8XK11wOss8gIM4u2HWDZPn4fxegQ3DBRNaBeAaV42XQ==","tarball":"https://registry.npmjs.org/@cooperadoras-digitales/facturajs/-/facturajs-0.2.0-coop2.tgz","fileCount":36,"unpackedSize":47557,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVR/fGTzBFyH8B8N5Smcrbhrn1ND72r1oZ3Qd2Wza0GAIhAJhE1GrvQUmajGf0Tn0Pn1t2zqtm3yAVpVvjiBKMMSWm"}]},"_npmUser":{"name":"jparedes","email":"jparedes@gmail.com"},"directories":{},"maintainers":[{"name":"jparedes","email":"jparedes@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/facturajs_0.2.0-coop2_1695304252628_0.8536844070136098"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-21T13:05:44.031Z","0.2.0":"2023-09-21T13:05:44.375Z","modified":"2023-09-21T13:50:53.041Z","0.2.0-coop1":"2023-09-21T13:41:20.853Z","0.2.0-coop2":"2023-09-21T13:50:52.827Z"},"maintainers":[{"name":"jparedes","email":"jparedes@gmail.com"}],"description":"Comunicación con los web services de AFIP utilizando nodejs.","author":{"name":"Emilio Astarita"},"license":"MIT","readme":"![facturajs](facturajs.jpg?raw=true&1 \"FacturaJS\")\n\n# facturajs\n\nAfip Web Services desde nodejs.\n\n````bash\n~$ yarn add facturajs\n# OR\n~$ npm i facturajs\n````\n\n## WebServices de la AFIP con node  \n\nEl objetivo de esta lib es facilitar la comunicación con la AFIP utilizando node.js. En mi caso particular, necesitaba *generar facturas electrónicas como monotributista* de manera automática. \n\nNo tiene muchas pretenciones, pero el código puede ser ilustrativo para armar otras integraciones más complejas.    \n\n### Obtener certificados en la AFIP\n  \nLos servicios de AFIP están disponibles mediante SOAP y su página principal es [AFIP WS](http://www.afip.gob.ar/ws).\n\nLos servicios poseen dos entornos conocidos como homologación (para testing), y producción.\n\nPara utilizar ambos entornos hay que obtener certificados digitales de la AFIP.\n\nDe nuestro lado lo primero es generar certificados relacionados a nuestro CUIT:\n\n```bash\n# Crear clave privada\n~ $ openssl genrsa -out private/private_key.key 2048 \n# Crear certificado\n~ $ openssl req -new -key private/private_key.key -subj \"/C=AR/O=TU_EMPRESA/CN=TU_SISTEMA/serialNumber=CUIT TU_CUIT\" -out private/afip.csr\n\n```\n(*) Dónde dice `CUIT TU_CUIT` es importante el espacio y conservar la palabra \"CUIT\". \n\n### Adherirse a homologación (testing)\n\nEn este [pdf (WSASS como adherirse)](https://www.afip.gob.ar/ws/WSASS/WSASS_como_adherirse.pdf) pueden ver el proceso de adhesión al servicio de homologación. Básicamente das de alta el servicio y le cargas el CSR generado en el paso anterior, la página web te va a entregar otro cert que lo tenes que copiar y lo guardas en un archivo de texto: `private/cert.pem`. El último paso, en esa misma página, sería autorizar tu cert al servicio que quieras usar. En mi caso quería el de facturas digitales llamado: `wsfe`. \n\n### Ejemplo de uso  \n\n\n#### Crear una factura electrónica\n\nEn este ejemplo pueden [ver como crear una factura electrónica con el último número de comprobante válido](src/examples/create-bill.ts).\n\nPara poder ver más en detalle que está sucediendo se puede configurar el `LOG_LEVEL` y namespace de `DEBUG`:\n\n```bash\n~$ LOG_LEVEL=3 DEBUG=facturajs node dist/examples/create-bill-monotributo.js\n# Salida:\n# Last bill number:  43\n# Next bill number to create:  44\n# Created bill {\n#     \"FeCabResp\": {\n#         \"Cuit\": \"XXXXXXXXXX\",\n#         \"PtoVta\": 2,\n#         \"CbteTipo\": 11,\n#         \"FchProceso\": \"20180423081028\",\n#         \"CantReg\": 1,\n#         \"Resultado\": \"A\",\n#         \"Reproceso\": \"N\"\n#     },\n#     \"FeDetResp\": {\n#         \"FECAEDetResponse\": [\n#             {\n#                 \"Concepto\": 1,\n#                 \"DocTipo\": 99,\n#                 \"DocNro\": \"0\",\n#                 \"CbteDesde\": \"44\",\n#                 \"CbteHasta\": \"44\",\n#                 \"CbteFch\": \"20180423\",\n#                 \"Resultado\": \"A\",\n#                 \"CAE\": \"68174646182386\",\n#                 \"CAEFchVto\": \"20180503\"\n#             }\n#         ]\n#     }\n# }\n```\n\n#### Ejecutar cualquier método del WebService\n\nDe manera general cualquier método del WebService se puede llamar con `execRemote(servicio, método, parámetros)`, por ejemplo:\n\n````typescript\nconst afip = new AfipServices(config);\nafip.execRemote('wsfev1', 'FECAESolicitar', {\n    Auth: {Cuit: 27000000000},\n    params: {\n        CbteTipo: 11,\n        PtoVta: 2\n    }    \n}).then(res => console.log(res))\n````\n \n \n \n#### Config\n\nEl constructor `AfipServices` acepta un objeto que cumpla con la interfaz de `IConfigService`. La descripción de sus propiedades:\n\n* `homo` Un booleano que determina el uso del entorno de homologación.\n* `cacheTokensPath` Path a un file dónde se cachearan los tokens obtenidos para no solicitarlos cada vez.\n* `tokensExpireInHours` La cantidad de horas en la que expirará el archivo de tokens cacheados.\n* `privateKeyContents` El contenido de la private key (no hace falta path en este caso)\n* `privateKeyPath` Path a la private key (al igual que antes podemos omitir el contenido)\n* `certContents` El contenido del certificado (no hace falta path en este caso)\n* `certPath` Path al certificado (al igual que antes podemos omitir el contenido)\n\n\n#### Nota acerca de métodos de cifrado openssl\n\nEn algunos sistemas operativos con una versión de la configuración de openssl mas nueva\nse reportó un error porque openssl rechaza los métodos de cifrado de AFIP.\nAlgunos usuarios reportaron que en un sistema Debian la solución fue editar `/etc/ssl/openssl.cnf`.\nY comentar la siguiente línea:\n```\n# CipherString = DEFAULT@SECLEVEL=2\n```\n\n\n#### Proyectos relacionados\n\n- [SOAP de la AFIP a REST](https://github.com/sarriaroman/AFIP-API) enciende un server expressjs y sirve de wrapper alrededor del SOAP para poder consumir los servicios con una interfaz REST. A partir de ese repo se armó esta lib.\n\n\n#### Colaboradores\n\n* mbenedettini \n","readmeFilename":"README.md"}