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

@panoptic-it-solutions/quickbooks-client

v0.1.4

Published

QuickBooks Online API client with OAuth 2.0, rate limiting, and typed entities

Readme

@panoptic-it-solutions/quickbooks-client

QuickBooks Online API client with OAuth 2.0, rate limiting, and typed entities.

Installation

npm install @panoptic-it-solutions/quickbooks-client

Quick Start

import { QuickBooksClient, generateAuthUrl, exchangeCodeForTokens, generateState } from '@panoptic-it-solutions/quickbooks-client';
import type { TokenStore, QuickBooksTokens } from '@panoptic-it-solutions/quickbooks-client';

// 1. Implement TokenStore for your storage backend
const tokenStore: TokenStore = {
  async getTokens() {
    // Return stored tokens or null
    return db.getQuickBooksTokens();
  },
  async storeTokens(tokens) {
    // Store tokens
    await db.saveQuickBooksTokens(tokens);
  },
  async clearTokens() {
    // Clear tokens
    await db.deleteQuickBooksTokens();
  }
};

// 2. Create the client
const client = new QuickBooksClient({
  clientId: process.env.QB_CLIENT_ID,
  clientSecret: process.env.QB_CLIENT_SECRET,
  redirectUri: process.env.QB_REDIRECT_URI,
  environment: 'production', // or 'sandbox'
  tokenStore,
});

// 3. Use the client
const invoices = await client.getInvoices();
const customers = await client.getCustomers('Active = true');

OAuth Flow

Generate Authorization URL

import { generateAuthUrl, generateState } from '@panoptic/quickbooks-client';

const state = generateState(); // Store this for CSRF validation
const authUrl = generateAuthUrl({
  clientId: process.env.QB_CLIENT_ID,
  clientSecret: process.env.QB_CLIENT_SECRET,
  redirectUri: process.env.QB_REDIRECT_URI,
}, state);

// Redirect user to authUrl

Handle OAuth Callback

import { exchangeCodeForTokens } from '@panoptic/quickbooks-client';

// In your callback handler:
const tokens = await exchangeCodeForTokens(
  {
    clientId: process.env.QB_CLIENT_ID,
    clientSecret: process.env.QB_CLIENT_SECRET,
    redirectUri: process.env.QB_REDIRECT_URI,
  },
  code,    // from URL params
  realmId  // from URL params
);

// Store tokens using your TokenStore
await tokenStore.storeTokens(tokens);

API Methods

Invoices

const invoices = await client.getInvoices();
const invoice = await client.getInvoice('123');
const newInvoice = await client.createInvoice({
  CustomerRef: { value: '1' },
  Line: [{ Amount: 100, DetailType: 'SalesItemLineDetail' }]
});

Customers

const customers = await client.getCustomers();
const customer = await client.getCustomer('123');
const newCustomer = await client.createCustomer({
  DisplayName: 'Acme Corp'
});

Payments

const payments = await client.getPayments();
const payment = await client.createPayment({
  CustomerRef: { value: '1' },
  TotalAmt: 100
});

Bills & Vendors

const bills = await client.getBills();
const vendors = await client.getVendors();

Raw Query

const results = await client.query<Invoice>(
  "SELECT * FROM Invoice WHERE Balance > '0'"
);

Features

  • No external OAuth dependencies - Pure fetch-based OAuth 2.0 implementation
  • Automatic token refresh - Tokens are refreshed automatically when expired
  • Rate limiting - Built-in 500 req/min rate limiter with exponential backoff
  • Typed entities - Full TypeScript support for Invoice, Customer, Payment, etc.
  • Pluggable token storage - Implement TokenStore interface for any backend

TokenStore Interface

interface TokenStore {
  getTokens(): Promise<QuickBooksTokens | null>;
  storeTokens(tokens: QuickBooksTokens): Promise<void>;
  clearTokens(): Promise<void>;
}

interface QuickBooksTokens {
  access_token: string;
  refresh_token: string;
  realm_id: string;
  expires_at: number;
}

Error Handling

import { QuickBooksError, QB_ERROR_CODES } from '@panoptic-it-solutions/quickbooks-client';

try {
  await client.getInvoices();
} catch (error) {
  if (error instanceof QuickBooksError) {
    switch (error.code) {
      case QB_ERROR_CODES.TOKEN_EXPIRED:
        // Handle expired token
        break;
      case QB_ERROR_CODES.RATE_LIMIT:
        // Handle rate limiting
        break;
      case QB_ERROR_CODES.UNAUTHORIZED:
        // Handle auth error
        break;
    }
  }
}

Configuration

| Option | Required | Default | Description | |--------|----------|---------|-------------| | clientId | Yes | - | OAuth client ID from Intuit | | clientSecret | Yes | - | OAuth client secret | | redirectUri | Yes | - | OAuth callback URL | | environment | No | production | sandbox or production | | tokenStore | Yes | - | Token storage implementation | | onLog | No | - | Logging callback |

License

MIT