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

@carbonapi/typescript-sdk

v6.2.0

Published

TypeScript SDK for CarbonAPI

Readme

CarbonAPI TypeScript SDK

A TypeScript SDK for interacting with the CarbonAPI, featuring full type safety and automatic type generation from OpenAPI specifications.

Requirements

  • An API key from the CarbonAPI Portal (https://portal.carbonapi.io)
  • A webhook signing secret from your project page.

Installation

npm install @carbonapi/typescript-sdk
# or
yarn add @carbonapi/typescript-sdk
# or
pnpm add @carbonapi/typescript-sdk

Usage

Basic Usage

import { CarbonAPIClient } from "@carbonapi/typescript-sdk";

// Initialize the client with your API key
const client = new CarbonAPIClient({
  apiKey: "your-api-key-here",
  // Optional: Override the default base URL
  // baseURL: 'https://custom-api-url.com',
});

// Create a batch of transactions
const transactionBatchResponse = await client.createTransactionBatch({
  transactions: [
    {
      id: "123",
      date: "2025-05-13T03:52:52Z",
      tax: 10,
      total: 100,
      subtotal: 90,
      description: "Purchase of new laptop",
      supplierName: "Mighty Ape",
      sourceAccount: "Office Expenses",
      currency: "NZD",
    },
  ],
  countryCode: "NZL",
  factorClass: "commodity",
});

// Get transaction batch status
const batchId = transactionBatchResponse.batchIds[0];
const transactionBatchStatus = await client.getTransactionBatch(batchId);

console.log("Transaction Batch Status:", transactionBatchStatus.status);
console.log("Transactions:", transactionBatchStatus.transactions);

Webhook Handling

The SDK includes built-in webhook verification. Here's how to handle webhooks:

import { CarbonAPIClient } from "@carbonapi/typescript-sdk";
import express from "express";

const app = express();

// Remember to use RAW body type, otherwise this won't work as expected!
app.use(express.raw({ type: "application/json" }));

// Initialize the client with your API key and webhook secret
const client = new CarbonAPIClient({
  apiKey: "your-api-key-here",
  webhookSecret: "your-webhook-secret-here",
});

// Example webhook handler using Express
app.post("/webhook", async (req, res) => {
  try {
    // Verify and parse the webhook payload
    const event = await client.verifyWebhookRequest(req);

    // Handle different webhook event types
    switch (event.type) {
      case "transaction.batch.completed":
        console.log("Batch completed:", event.data);
        break;
    }

    res.status(200).json({ received: true });
  } catch (error) {
    console.error("Webhook verification failed:", error);
    res.status(400).json({ error: "Webhook verification failed" });
  }
});

API Reference

CarbonAPIClient

The main client class for interacting with the CarbonAPI.

Constructor

new CarbonAPIClient(config: CarbonAPIConfig)
Configuration Options
  • apiKey (required): Your CarbonAPI API key
  • baseURL (optional): Custom base URL for the API (default: 'https://api.aws-au.carbonapi.io/')
  • webhookSecret (optional): Your webhook signing secret for verifying webhook payloads

Methods

  • getClient(): Returns the underlying typed openapi-fetch client
  • createTransactionBatch(batch: CreateBatchRequestDTO): Create a batch of transactions
  • getTransactionBatch(batchId: string): Get the status and transactions for a batch
  • verifyWebhook(payload: string, headers: Record<string, string>): Verify and parse a webhook payload
  • verifyWebhookRequest(request: Request): Verify and parse a webhook payload from a raw request

Transaction Data Structure

When creating a transaction batch, each transaction should have the following structure:

interface TransactionDTO {
  id: string; // Unique transaction identifier
  date: string; // ISO 8601 date format
  subtotal: number; // Transaction subtotal
  tax: number; // Tax amount
  total: number; // Total amount
  description: string; // Transaction description
  supplierName: string; // Supplier/vendor name
  sourceAccount: string; // Source account name
  currency: string; // Currency code (e.g., "NZD")
}

Webhook Events

The SDK supports webhook events with the following structure:

interface WebhookEvent {
  id: string;
  type: string;
  data: unknown;
  timestamp: number;
}

The event type and data structure will depend on the specific webhook event being received.

Development

  1. Clone the repository
  2. Install dependencies:
    pnpm install
  3. Build the SDK:
    pnpm run build
  4. Run tests:
    pnpm test

License

MIT