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 🙏

© 2025 – Pkg Stats / Ryan Hefner

serasa-xapi

v1.0.0

Published

Uma biblioteca TypeScript para consumir as APIs do Serasa Experian, com foco inicial em score de crédito e dados para CNPJ e CPF.

Downloads

6

Readme

Serasa Experian API Library

Uma biblioteca TypeScript para consumir as APIs do Serasa Experian, com foco inicial em score de crédito e dados para CNPJ e CPF.

Instalação

npm install serasa-experian-api-library
# ou
yarn add serasa-experian-api-library

Uso

Autenticação

Para usar a biblioteca, você precisará do seu CLIENT_ID e CLIENT_SECRET fornecidos pela Serasa Experian. É recomendado armazená-los em variáveis de ambiente (.env).

import SerasaExperianAPI from 'serasa-experian-api-library';

// Carrega as variáveis de ambiente (se estiver usando dotenv)
// require('dotenv').config();

const clientId = process.env.SERASA_CLIENT_ID || 'YOUR_CLIENT_ID';
const clientSecret = process.env.SERASA_CLIENT_SECRET || 'YOUR_CLIENT_SECRET';

const serasaApi = new SerasaExperianAPI({
  clientId,
  clientSecret,
  environment: 'homologation', // ou 'production'
});

Exemplos de Uso

Consultar Score de Fraude para Pessoa Física (CPF)

import SerasaExperianAPI from 'serasa-experian-api-library';

// ... (configuração da instância da API)

async function consultarScoreFraudePF() {
  try {
    const data = {
      person: {
        document: '00000000000', // Substitua pelo CPF real
      },
      score: ['FRAUD_SCORE_PF'],
    };
    const response = await serasaApi.getConsumerFraudScore(data);
    console.log('Resposta Score de Fraude PF:', response);
  } catch (error) {
    console.error('Erro ao consultar Score de Fraude PF:', error);
  }
}

consultarScoreFraudePF();

Consultar Score de Fraude para Pessoa Jurídica (CNPJ)

import SerasaExperianAPI from 'serasa-experian-api-library';

// ... (configuração da instância da API)

async function consultarScoreFraudePJ() {
  try {
    const data = {
      company: {
        document: '00000000000000', // Substitua pelo CNPJ real
      },
      score: ['FRAUD_SCORE_PJ'],
    };
    const response = await serasaApi.getBusinessFraudScore(data);
    console.log('Resposta Score de Fraude PJ:', response);
  } catch (error) {
    console.error('Erro ao consultar Score de Fraude PJ:', error);
  }
}

consultarScoreFraudePJ();

Consultar Dados Avulsos para Pessoa Física (CPF)

import SerasaExperianAPI from 'serasa-experian-api-library';

// ... (configuração da instância da API)

async function consultarDadosAvulsosPF() {
  try {
    const cpf = '00000000000'; // Substitua pelo CPF real
    const data = {
      reportName: 'RELATORIO_DADOS_AVULSOS_PF',
      optionalFeatures: 'SCORE_POSITIVO,RENDA_ESTIMADA_PF', // Exemplo de features opcionais
      // reportParameters: [{ name: 'VAR_1', value: 'VALUE_1' }], // Se necessário
    };
    const response = await serasaApi.getDadosAvulsosPF(data, cpf);
    console.log('Resposta Dados Avulsos PF:', response);
  } catch (error) {
    console.error('Erro ao consultar Dados Avulsos PF:', error);
  }
}

consultarDadosAvulsosPF();

Consultar Dados Avulsos para Pessoa Jurídica (CNPJ)

import SerasaExperianAPI from 'serasa-experian-api-library';

// ... (configuração da instância da API)

async function consultarDadosAvulsosPJ() {
  try {
    const cnpj = '00000000000000'; // Substitua pelo CNPJ real
    const data = {
      reportName: 'RELATORIO_DADOS_AVULSOS_PJ',
      optionalFeatures: 'SCORE_POSITIVO,FATURAMENTO_ESTIMADO_POSITIVO', // Exemplo de features opcionais
      // reportParameters: [{ name: 'VAR_1', value: 'VALUE_1' }], // Se necessário
    };
    const response = await serasaApi.getDadosAvulsosPJ(data, cnpj);
    console.log('Resposta Dados Avulsos PJ:', response);
  } catch (error) {
    console.error('Erro ao consultar Dados Avulsos PJ:', error);
  }
}

consultarDadosAvulsosPJ();

Contribuição

Sinta-se à vontade para contribuir com melhorias, correções de bugs ou a adição de novas APIs. Crie um pull request com suas alterações.

Licença

Este projeto está licenciado sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.