npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-afip-ws

v1.3.2

Published

Libreria para usar los Web Services de AFIP con JavaScript y Typescript

Downloads

6

Readme

Integracion con los servicios web de afip


Introducción

Esta es una implementación de los accesos a las apis de afip para NodeJS y TypeScript, en base de un Fork de otro proyecto. La idea es democratizar el acceso a los diversos servicios de AFIP de la manera más sencilla posible En esta versión estan implementados

Errores

En el caso de encontrar un error, crear un issue o pull request en GitHub seguimiento de errores

Documentación

Instalación

Para instalar usando npm

npm install ts-afip-ws

Obtención de los certificados para el ambiente de homologación

Seguir los pasos en la documentación oficial:

Uso

Por el momento hay un solo ejemplo de uso, creando una clase con los diferentes métodos posibles

Ejemplo (AfipClass.ts)

Próximamente agregaré más ejemplos y métodos para el uso del presente repositorio

import Afip from 'ts-afip-ws'

interface ResponseAfip {
    status: 200 | 500,
    data: any
}

export class AfipClass {
    afip: Afip;
    constructor(
        private CUIT: number,
        private cert: string,
        private key: string,
        private production: boolean,
    ) {
        this.afip = new Afip({
            CUIT: this.CUIT,
            res_folder: `${__dirname}/certs/`,
            cert: this.cert,
            key: this.key,
            ta_folder: `${__dirname}/token/`,
            production: this.production
        })
    }
    async getServerStatusDataCUIT(): Promise<ResponseAfip> {
        const status = await this.afip.RegisterScopeFive.getServerStatus();
        if (status.appserver === "OK" && status.authserver === "OK" && status.dbserver === "OK") {
            const response: ResponseAfip = {
                status: 200,
                data: "Servidores online"
            }
            return response;
        } else {
            const response: ResponseAfip = {
                status: 500,
                data: "Servidores fuera de servicio"
            }
            return response;
        }
    }
    async getServerStatusFAct(): Promise<ResponseAfip> {
        const status = await this.afip.ElectronicBilling.getServerStatus();
        if (status.appserver === "OK" && status.authserver === "OK" && status.dbserver === "OK") {
            const response: ResponseAfip = {
                status: 200,
                data: "Servidores online"
            }
            return response;
        } else {
            const response: ResponseAfip = {
                status: 500,
                data: "Servidores fuera de servicio"
            }
            return response;
        }
    }

    async getDataCUIT(cuit_cons: number): Promise<ResponseAfip> {
        const dataCUIT = await this.afip.RegisterScopeFive.getTaxpayerDetails(cuit_cons);
        if (dataCUIT === null) {
            const response: ResponseAfip = {
                status: 500,
                data: null
            }
            return response;
        } else {
            const response: ResponseAfip = {
                status: 200,
                data: dataCUIT
            }
            return response;
        }
    }
    async lastFact(pv: number, tipo: CbteTipos): Promise<ResponseAfip> {
        try {
            const ultFact = await this.afip.ElectronicBilling.getLastVoucher(pv, tipo);
            const response: ResponseAfip = {
                status: 200,
                data: ultFact
            }
            return response;
        } catch (error) {
            const response: ResponseAfip = {
                status: 500,
                data: String(error)
            }
            return response;
        }
    }
    async newFact(data:
        FactMonotribProd
        | FactMonotribServ
        | FactMonotribProdNC
        | FactMonotribServNC
        | FactInscriptoProd
        | FactInscriptoServ
        | FactInscriptoProdNC
        | FactInscriptoServNC): Promise<ResponseAfip> {
        const nfact = await this.lastFact(data.PtoVta, data.CbteTipo);
        if (nfact.status === 200) {
            data.CbteDesde = Number(nfact.data) + 1;
            const dataFact = await this.afip.ElectronicBilling.createVoucher(data);
            data.CAE = dataFact.CAE
            data.CAEFchVto = dataFact.CAEFchVto
            const response: ResponseAfip = {
                status: 200,
                data: data
            }
            return response;
        } else {
            const response: ResponseAfip = {
                status: 500,
                data: "Punto de venta o tipo de factura incorrecta."
            }
            return response;
        }
    }
}