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

passportx-sdk

v1.0.3

Published

Official JavaScript SDK for PassportX - Achievement badges on Stacks blockchain

Readme

passportx-sdk

Official JavaScript/TypeScript SDK for PassportX - Achievement badges on the Stacks blockchain.

npm version License: MIT TypeScript

Features

  • 🎯 Type-safe: Full TypeScript support with comprehensive type definitions
  • 🚀 Easy to use: Simple, intuitive API
  • 📦 Lightweight: Minimal dependencies
  • 🔒 Secure: Built-in error handling and validation
  • 🌐 Universal: Works in Node.js and browsers
  • Modern: Uses async/await and promises

Installation

npm install passportx-sdk
yarn add passportx-sdk
pnpm add passportx-sdk

Quick Start

import { PassportX } from 'passportx-sdk';

// Initialize the SDK
const client = new PassportX({
  apiUrl: 'https://api.passportx.app',
  network: 'mainnet',
});

// Get user badges
const badges = await client.getUserBadges(
  'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
);

console.log(`User has ${badges.length} badges`);
badges.forEach((badge) => {
  console.log(`${badge.template.icon} ${badge.template.name}`);
});

Usage Examples

Initialize the Client

import { PassportX } from 'passportx-sdk';

// With default configuration (mainnet)
const client = new PassportX();

// With custom configuration
const client = new PassportX({
  apiUrl: 'https://api.passportx.app',
  network: 'testnet',
  timeout: 15000,
});

// With API key for authenticated requests
const client = new PassportX({
  apiKey: 'your-api-key-here',
});

Get User Badges

// Get all badges for a user
const badges = await client.getUserBadges(
  'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM'
);

// With filtering and pagination
const badges = await client.getUserBadges(
  'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM',
  {
    category: 'achievement',
    level: 3,
    limit: 10,
    offset: 0,
  }
);

// Process badges
badges.forEach((badge) => {
  console.log(`Badge: ${badge.template.name}`);
  console.log(`Level: ${badge.metadata.level}`);
  console.log(`Category: ${badge.metadata.category}`);
  console.log(`Issued: ${badge.issuedAt}`);
});

Get Badge Information

// Get a specific badge
const badge = await client.getBadge('badge_id_123');

console.log(`Name: ${badge.template.name}`);
console.log(`Description: ${badge.template.description}`);
console.log(`Owner: ${badge.owner}`);
console.log(`Issuer: ${badge.issuer}`);

// Get just the metadata
const metadata = await client.getBadgeMetadata('badge_id_123');
console.log(`Level ${metadata.level} ${metadata.category} badge`);

// Verify a badge exists
const isValid = await client.verifyBadge('badge_id_123');
if (isValid) {
  console.log('Badge is valid');
}

Work with Communities

// Get community information
const community = await client.getCommunity('passportx-community');

console.log(`Name: ${community.name}`);
console.log(`Members: ${community.memberCount}`);
console.log(`Description: ${community.description}`);

// Get all badge templates in a community
const templates = await client.getCommunityBadges('community_id');

templates.forEach((template) => {
  console.log(`${template.icon} ${template.name} (Level ${template.level})`);
  console.log(`Requirements: ${template.requirements}`);
});

// Get community members
const members = await client.getCommunityMembers('community_id', { limit: 20 });

console.log(`Total members: ${members.pagination.total}`);
members.data.forEach((member) => {
  console.log(`${member.name}: ${member.badgeCount} badges`);
});

// Get community leaderboard
const leaderboard = await client.getCommunityLeaderboard('community_id', 10);

leaderboard.forEach((user, index) => {
  console.log(`#${index + 1}: ${user.name} - ${user.badgeCount} badges`);
});

// Get community analytics
const analytics = await client.getCommunityAnalytics('community_id');

console.log(`Total members: ${analytics.totalMembers}`);
console.log(`Total badges issued: ${analytics.totalIssuedBadges}`);
console.log(`Badge templates: ${analytics.totalBadgeTemplates}`);

List Communities

// Get all public communities
const communities = await client.listCommunities({ limit: 10 });

communities.data.forEach((community) => {
  console.log(`${community.name} - ${community.memberCount} members`);
});

// Search communities
const results = await client.listCommunities({
  search: 'developer',
  tags: ['tech', 'programming'],
  limit: 20,
});

// Check if there are more results
if (results.pagination.hasMore) {
  const nextPage = await client.listCommunities({
    search: 'developer',
    offset: results.pagination.offset + results.pagination.limit,
  });
}

Error Handling

import { PassportX, PassportXError } from 'passportx-sdk';

const client = new PassportX();

try {
  const badge = await client.getBadge('invalid_id');
} catch (error) {
  if (error instanceof PassportXError) {
    console.error(`Error: ${error.message}`);
    console.error(`Code: ${error.code}`);
    console.error(`Status: ${error.statusCode}`);
  } else {
    console.error('Unexpected error:', error);
  }
}

API Reference

PassportX Client

Constructor

new PassportX(config?: PassportXConfig)

Parameters:

  • config (optional): Configuration object
    • apiUrl: Base URL for the API (default: 'https://api.passportx.app')
    • network: Stacks network ('mainnet' | 'testnet' | 'devnet')
    • apiKey: Optional API key for authenticated requests
    • timeout: Request timeout in milliseconds (default: 10000)

Methods

getUserBadges
getUserBadges(address: string, options?: BadgeQueryOptions): Promise<BadgeWithTemplate[]>

Get all badges for a specific user address.

getBadge
getBadge(badgeId: string): Promise<BadgeWithTemplate>

Get detailed information about a specific badge.

getBadgeMetadata
getBadgeMetadata(badgeId: string): Promise<BadgeMetadata>

Get metadata for a specific badge.

getCommunity
getCommunity(idOrSlug: string): Promise<Community>

Get information about a community by ID or slug.

getCommunityBadges
getCommunityBadges(communityId: string): Promise<BadgeTemplate[]>

Get all badge templates for a community.

getCommunityMembers
getCommunityMembers(communityId: string, options?: QueryOptions): Promise<PaginatedResponse<any>>

Get community members with pagination.

listCommunities
listCommunities(options?: QueryOptions): Promise<PaginatedResponse<Community>>

List all public communities.

getCommunityAnalytics
getCommunityAnalytics(communityId: string): Promise<any>

Get analytics data for a community.

getCommunityLeaderboard
getCommunityLeaderboard(communityId: string, limit?: number): Promise<any[]>

Get the top badge earners in a community.

verifyBadge
verifyBadge(badgeId: string): Promise<boolean>

Verify if a badge exists and is valid.

TypeScript Support

The SDK is written in TypeScript and includes comprehensive type definitions. All types are exported for your convenience:

import {
  PassportX,
  Badge,
  BadgeTemplate,
  Community,
  BadgeCategory,
  PassportXError,
  // ... and more
} from 'passportx-sdk';

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT © PassportX Team

Links

Support

If you have questions or need help, please: