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

@ocx-inc/credits

v0.0.0

Published

API client for Credits Management

Readme

@ocx-inc/credits

TypeScript client for the Credits Management API with separate client and server implementations.

Installation

pnpm add @ocx-inc/credits

Package Exports

This package uses package.json exports to provide separate entry points:

  • @ocx-inc/credits/client - Client-side API (frontend/browser)
  • @ocx-inc/credits/server - Server-side API (backend/admin)

Each entry point exports only the relevant code, enabling better tree-shaking and clearer separation of concerns.

Usage

Server-Side (Backend/Admin)

Use ServerClient for backend operations with API key authentication. This client has full access to all operations including creating transactions and managing users.

import { ServerClient } from '@ocx-inc/credits/server';

const serverClient = new ServerClient({
  baseUrl: 'https://your-api-url.com',
  apiKey: 'your-api-key',
});

// Create a user (idempotent)
await serverClient.createUser('app-id', 'user-id');

// Grant credits
await serverClient.createTransaction('app-id', 'user-id', {
  delta: 100,
  reason: 'grant',
});

// Consume credits
await serverClient.createTransaction('app-id', 'user-id', {
  delta: -10,
  reason: 'consume',
});

// List all users (admin only)
const users = await serverClient.listUsers('app-id');

// Get any user's balance
const balance = await serverClient.getBalance('app-id', 'user-id');

Client-Side (Frontend/End-User)

Use UserClient for frontend operations with JWT authentication. This client can only access the authenticated user's own data (read-only).

import { UserClient } from '@ocx-inc/credits/client';

const client = new UserClient({
  baseUrl: 'https://your-api-url.com',
  applicationId: 'app-id',
  bearerToken: userJwtToken, // From your auth provider (Clerk, Auth0, etc.)
});

// Get own balance
const balance = await client.getBalance('user-id');
console.log(`Balance: ${balance.balance} credits`);

// List own transaction history
const transactions = await client.listTransactions('user-id');

// Get own user info
const user = await client.getUser('user-id');

API Reference

ServerClient

Server-side client for backend/admin operations. Requires API key authentication.

Constructor Options:

  • baseUrl (string): The base URL of the API
  • apiKey (string): API key for authentication
  • fetch (function, optional): Custom fetch implementation

Methods:

User Management

  • createUser(applicationId, userId): Create or update a user (idempotent)
  • getUser(applicationId, userId): Get user information
  • listUsers(applicationId, cursor?): List all users in the application

Credits Management

  • getBalance(applicationId, userId): Get user's credit balance
  • createTransaction(applicationId, userId, transaction): Create a credit transaction (grant/consume/refund)
  • listTransactions(applicationId, userId, cursor?): List user's transaction history

UserClient

Client-side client for end-user operations. Requires JWT bearer token authentication.

Constructor Options:

  • baseUrl (string): The base URL of the API
  • applicationId (string): The application ID
  • bearerToken (string): JWT token from your auth provider
  • fetch (function, optional): Custom fetch implementation

Methods:

  • getUser(userId): Get authenticated user's information
  • getBalance(userId): Get authenticated user's credit balance
  • listTransactions(userId, cursor?): List authenticated user's transaction history

Note: Client-side users cannot create transactions. All credit modifications must be done through the server using ServerClient.

Type Definitions

Types are automatically exported from each entry point:

// Import from the client module
import type {
  UserClient,
  UserClientOptions,
  GetBalanceResponse,
  ListTransactionsResponse,
  CreditTransactionReason
} from '@ocx-inc/credits/client';

// Import from the server module
import type {
  ServerClient,
  ServerClientOptions,
  CreateTransactionRequest,
  CreateTransactionResponse,
  CreditTransactionReason
} from '@ocx-inc/credits/server';

Available Types:

export type CreditTransactionReason = "grant" | "consume" | "refund";

export type CreateTransactionRequest = {
  delta: number;
  reason: CreditTransactionReason;
};

export type GetBalanceResponse = {
  balance: number;
};

export type ListTransactionsResponse = {
  transactions: Array<{
    delta: number;
    reason: CreditTransactionReason;
    createdAt: Date;
  }>;
  nextCursor?: string;
};

Security

  • Server Client: Full access with API key authentication. Keep your API key secret and only use it server-side.
  • Client Client: Read-only access with JWT authentication. Safe to use in frontend applications.
  • The API validates JWT tokens and ensures users can only access their own data.