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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nxgate/sdk

v1.0.0

Published

SDK oficial da NXGATE para integração PIX - Node.js/TypeScript

Readme

@nxgate/sdk

SDK oficial da NXGATE para integração PIX em Node.js/TypeScript.

Recursos

  • TypeScript-first com suporte completo a JavaScript
  • Zero dependências - usa fetch e crypto nativos do Node.js 18+
  • Gerenciamento automático de tokens - cache com renovação antes da expiração
  • Assinatura HMAC automática - quando hmacSecret é fornecido
  • Parser de webhooks com type guards tipados
  • Erros tipados - NXGateError com código, título, descrição e status HTTP
  • Retry automático em erros 503 com backoff exponencial
  • Dual build - CJS + ESM

Instalação

npm install @nxgate/sdk

Requisitos

  • Node.js 18 ou superior

Uso

Configuração

import { NXGate } from '@nxgate/sdk'

const nx = new NXGate({
  clientId: 'nxgate_xxx',
  clientSecret: 'seu_secret',
  hmacSecret: 'seu_hmac_secret', // opcional
})

Gerar Cobrança PIX (Cash-in)

const cobranca = await nx.pixGenerate({
  valor: 100.00,
  nome_pagador: 'João da Silva',
  documento_pagador: '12345678901',
  descricao: 'Pagamento do pedido #123',
  webhook: 'https://meusite.com/webhook',
})

console.log(cobranca.paymentCode)       // Código PIX copia e cola
console.log(cobranca.paymentCodeBase64) // QR Code em base64
console.log(cobranca.idTransaction)     // ID da transação

Saque PIX (Cash-out)

const saque = await nx.pixWithdraw({
  valor: 50.00,
  chave_pix: '[email protected]',
  tipo_chave: 'EMAIL',
  webhook: 'https://meusite.com/webhook',
})

console.log(saque.internalreference) // Referência interna

Consultar Saldo

const saldo = await nx.getBalance()

console.log(saldo.balance)   // Saldo total
console.log(saldo.blocked)   // Saldo bloqueado
console.log(saldo.available) // Saldo disponível

Consultar Transação

const tx = await nx.getTransaction({
  type: 'cash-in',
  txid: 'px_xxx',
})

console.log(tx.status)     // Status da transação
console.log(tx.amount)     // Valor
console.log(tx.paidAt)     // Data do pagamento
console.log(tx.endToEnd)   // Identificador end-to-end

Webhook

import { NXGateWebhook } from '@nxgate/sdk'

// No handler do seu webhook (Express, Fastify, etc.)
app.post('/webhook', (req, res) => {
  const event = NXGateWebhook.parse(req.body)

  if (NXGateWebhook.isCashIn(event)) {
    // Evento de pagamento recebido (cash-in)
    if (NXGateWebhook.isPaid(event)) {
      console.log('Pagamento confirmado:', event.data.amount)
      console.log('Pagador:', event.data.debtor_name)
      console.log('End-to-end:', event.data.end_to_end)
    }

    if (NXGateWebhook.isRefunded(event)) {
      console.log('Pagamento estornado:', event.data.tx_id)
    }
  }

  if (NXGateWebhook.isCashOut(event)) {
    // Evento de saque (cash-out)
    if (NXGateWebhook.isCashOutSuccess(event)) {
      console.log('Saque realizado:', event.amount)
    }

    if (NXGateWebhook.isCashOutError(event)) {
      console.log('Erro no saque:', event.error)
    }
  }

  res.sendStatus(200)
})

Tipos de Chave PIX

| Tipo | Descrição | |----------|------------------------------| | CPF | CPF do destinatário | | CNPJ | CNPJ do destinatário | | EMAIL | E-mail do destinatário | | PHONE | Telefone do destinatário | | RANDOM | Chave aleatória |

Split de Pagamentos

const cobranca = await nx.pixGenerate({
  valor: 100.00,
  nome_pagador: 'João da Silva',
  documento_pagador: '12345678901',
  split_users: [
    { username: 'loja1', percentage: 70 },
    { username: 'loja2', percentage: 30 },
  ],
})

Tratamento de Erros

import { NXGate, NXGateError } from '@nxgate/sdk'

try {
  await nx.pixGenerate({ ... })
} catch (err) {
  if (err instanceof NXGateError) {
    console.error('Código:', err.code)
    console.error('Título:', err.title)
    console.error('Descrição:', err.description)
    console.error('Status HTTP:', err.status)
  }
}

Assinatura HMAC

Quando hmacSecret é fornecido na configuração, todas as requisições incluem automaticamente os headers de assinatura HMAC-SHA256:

  • X-Client-ID - Identificador do cliente
  • X-HMAC-Signature - Assinatura HMAC-SHA256 em base64
  • X-HMAC-Timestamp - Timestamp ISO 8601
  • X-HMAC-Nonce - Identificador único por requisição

A assinatura é gerada sobre o payload: METHOD\nPATH\nTIMESTAMP\nNONCE\nBODY

Configuração Avançada

const nx = new NXGate({
  clientId: 'nxgate_xxx',
  clientSecret: 'secret',
  hmacSecret: 'hmac_secret',       // opcional
  baseUrl: 'https://api.nxgate.com.br', // padrão
  timeout: 30000,                  // 30s, padrão
  maxRetries: 2,                   // tentativas em 503, padrão
})

Eventos de Webhook

Cash-in (Pagamento)

| Tipo | Descrição | |-------------------------------------|------------------------| | QR_CODE_COPY_AND_PASTE_PAID | Pagamento confirmado | | QR_CODE_COPY_AND_PASTE_REFUNDED | Pagamento estornado |

Cash-out (Saque)

| Tipo | Descrição | |--------------------------|-------------------| | PIX_CASHOUT_SUCCESS | Saque realizado | | PIX_CASHOUT_ERROR | Erro no saque | | PIX_CASHOUT_REFUNDED | Saque estornado |

Licença

MIT