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

keyparty-sdk

v0.1.8

Published

Node.js TypeScript SDK for KeyParty credit management with webhooks, child key management, and transaction history (Phase 1 endpoints verified working)

Readme

KeyParty SDK

TypeScript SDK for KeyParty credit management with server-authoritative timestamps and comprehensive audit trails.

Installation

npm install keyparty-sdk

Quick Start

import { KeyPartyClient } from 'keyparty-sdk';

const client = new KeyPartyClient(process.env.KEYPARTY_SERVICE_KEY);

// Get balance
const balance = await client.getCredits('user_123');

// Manage credits
await client.addCredits('user_123', 100, 'Signup bonus');
await client.deductCredits('user_123', 10, 'API usage');

Features

  • Single API call per operation with automatic retries
  • Full TypeScript support with zero dependencies
  • Secure permission model (service keys vs child keys)
  • Recurring subscriptions with automated renewals
  • Webhook management for event notifications
  • Child key lifecycle management and monitoring
  • Transaction history with pagination and filtering

Security Model

Key Types

Service Key (sk_*) - Full administrative access for SaaS owners

  • Manage credits (add, deduct, set, view)
  • Create and manage child keys, webhooks, subscriptions
  • View all transaction history

Child Key (ck_pk_*) - Limited user access

  • View own balance and transaction history
  • Deduct own credits only
  • Cannot add credits or create keys

Permission Matrix

| Operation | Service Key | Child Key | |-----------|-------------|-----------| | View Credits | Yes | Yes (own only) | | Deduct Credits | Yes | Yes (own only) | | Add/Set Credits | Yes | No | | Manage Keys/Webhooks | Yes | No |

Error Handling

import {
  ForbiddenError,
  InsufficientCreditsError,
  AuthenticationError
} from 'keyparty-sdk';

try {
  await client.deductCredits('user_123', 100, 'API usage');
} catch (error) {
  if (error instanceof InsufficientCreditsError) {
    console.error('Not enough credits');
  } else if (error instanceof ForbiddenError) {
    console.error('Permission denied');
  }
}

Available Errors: ForbiddenError, AuthenticationError, ValidationError, UserNotFoundError, InsufficientCreditsError, RateLimitError, NetworkError (auto-retry)

API Reference

Core Operations

// Credits
await client.getCredits(userId);
await client.addCredits(userId, amount, reason?);
await client.deductCredits(userId, amount, reason?);
await client.setCredits(userId, amount, reason?);
await client.batchOperation(operation, userId, amount);

// Child Keys
await client.createChildKey(userId, credits, options?);
await client.listChildKeys(options?);
await client.revokeChildKey(childKeyId);
await client.getChildKeyStatus(childKeyId);
await client.getChildKeyMetadata(childKeyId);
await client.updateChildKeyMetadata(childKeyId, metadata);

// Subscriptions
await client.startSubscription(userId, amount, validityDays);
await client.stopSubscription(userId, subscriptionId);
await client.getSubscriptionStatus(userId);

// Multi-tenant subscriptions
await client.startExternalUserSubscription(externalUserId, amount, validityDays);
await client.stopExternalUserSubscription(externalUserId, subscriptionId);
await client.getExternalUserSubscriptionStatus(externalUserId);

// Webhooks
await client.createWebhook(config);
await client.listWebhooks(status?);
await client.getWebhook(webhookId);
await client.updateWebhook(webhookId, updates);
await client.rotateWebhookSecret(webhookId);
await client.deleteWebhook(webhookId);

// Transaction History
await client.getTransactionHistory(userId, options?);
await client.getTransactionById(transactionId);

Transaction History Options

const history = await client.getTransactionHistory('user_123', {
  limit: 50,              // Results per page (default: 50)
  offset: 0,              // Skip results (default: 0)
  type: 'deduct',         // Filter: 'deduct' | 'increase' | 'set'
  startDate: new Date(),  // Date range start
  endDate: new Date()     // Date range end
});

Webhook Events

  • service_key.rotated / service_key.created
  • child_key.created / child_key.revoked
  • credits.low_threshold / credits.exhausted

Constructor Options

const client = new KeyPartyClient(serviceKey, {
  baseUrl: 'https://your-api.com',  // Custom endpoint
  timeout: 10000,                    // Request timeout (ms)
  retryAttempts: 3,                  // Retry attempts
  retryDelay: 1000                   // Retry delay (ms)
});

Configuration

Required:

KEYPARTY_SERVICE_KEY=sk_test_your_service_key

Optional:

KEYPARTY_BASE_URL=https://your-deployment.convex.site
KEYPARTY_TIMEOUT=10000
KEYPARTY_RETRY_ATTEMPTS=3

Testing

npm test                                          # Run all tests
KEYPARTY_SERVICE_KEY=sk_test npm test            # Include integration tests
npm run test:watch                                # Watch mode

Requirements

  • Node.js v22.0.0 or higher
  • TypeScript 5.0+ (for TypeScript projects)

Version History

  • v0.1.7 - Phase 1 complete: Fixed endpoint mismatches, verified integration tests
  • v0.1.6 - Added child key management and transaction history
  • v0.1.5 - Added webhook management
  • v0.1.4 - Added recurring subscriptions
  • v0.1.3 - Security fix: Restricted child key permissions
  • v0.1.0 - Initial release

License

MIT

Support

https://github.com/areweai/keyparty-sdk/issues