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

@turnstile-portal/api-client

v0.2.11

Published

Type-safe API client for Turnstile API

Downloads

105

Readme

@turnstile-portal/api-client

Type-safe API client for Turnstile API, generated from OpenAPI specification.

Installation

npm install @turnstile-portal/api-client
# or
pnpm add @turnstile-portal/api-client
# or
yarn add @turnstile-portal/api-client

Usage

Basic Usage

import { TurnstileApiClient } from '@turnstile-portal/api-client';

const client = new TurnstileApiClient({
  baseUrl: 'https://api.turnstile.xyz',
});
// or use predefined base URLs / helpers:
// const client = createSandboxClient();
// const client = new TurnstileApiClient({ baseUrl: SANDBOX_BASE_URL });

// Check service health
const health = await client.getHealth();

// Get a single token by address
const token = await client.getTokenByAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48');

// Get paginated tokens
const response = await client.getTokens({ limit: 100, cursor: 0 });
console.log(response.data); // Array of tokens
console.log(response.pagination); // Pagination info

Auto-pagination

// Fetch all tokens (automatically handles pagination)
const allTokens = await client.getAllTokens();

// Fetch all bridged tokens
const bridgedTokens = await client.getAllBridgedTokens();

// Manual pagination with async iterator
for await (const token of client.getAllPages(
  (params) => client.getTokens(params),
  100 // limit per page
)) {
  console.log(token);
}

Token Status Filters

// Get proposed tokens
const proposed = await client.getProposedTokens({ limit: 50 });

// Get rejected tokens
const rejected = await client.getRejectedTokens({ limit: 50 });

// Get accepted tokens (not yet fully bridged)
const accepted = await client.getAcceptedTokens({ limit: 50 });

// Get fully bridged tokens
const bridged = await client.getBridgedTokens({ limit: 50 });

Contract Operations

// Get a contract instance by address
const contract = await client.getContract('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef');

// Get a contract instance with artifact data included
const contractWithArtifact = await client.getContract(
  '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
  true // includeArtifact
);

// Get a contract artifact by contract class ID or artifact hash
const artifact = await client.getArtifact('0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890');

// Get all contract instance addresses for a specific contract class
const instances = await client.getContractInstancesByClassId(
  '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
  { match: 'any' },
);
console.log(instances); // Array of contract addresses

Custom Headers and Fetch

const client = new TurnstileApiClient({
  baseUrl: 'https://api.turnstile.xyz',
  headers: {
    'X-API-Key': 'your-api-key',
  },
  // Use custom fetch implementation (e.g., for Node.js < 18)
  fetch: customFetch,
});

API Reference

TurnstileApiClient

Constructor

new TurnstileApiClient(config: ClientConfig)

ClientConfig:

  • baseUrl: string - Base URL of the API
  • headers?: Record<string, string> - Optional custom headers
  • fetch?: typeof fetch - Optional custom fetch implementation

Methods

Health & Status:

  • getHealth() - Check service health
  • getReady() - Check service readiness (including database)

Token Operations:

  • getTokens(params?) - Get paginated list of all tokens
  • getTokenByAddress(address) - Get token by L1 or L2 address
  • getProposedTokens(params?) - Get proposed tokens
  • getRejectedTokens(params?) - Get rejected tokens
  • getAcceptedTokens(params?) - Get accepted tokens
  • getBridgedTokens(params?) - Get fully bridged tokens
  • getAllTokens(limit?) - Get all tokens (auto-paginated)
  • getAllBridgedTokens(limit?) - Get all bridged tokens (auto-paginated)

Contract Operations:

  • getContract(address, includeArtifact?) - Get contract instance by address
  • getArtifact(identifier) - Get contract artifact by contract class ID or artifact hash
  • getContractInstancesByClassId(contractClassId, query?) - Get contract instance addresses with optional match scope (current, original, any)

Utilities:

  • getAllPages(fetcher, limit?) - Async iterator for pagination

Types

The client exports all necessary types:

import type {
  Token,
  TokensResponse,
  ContractInstance,
  ContractArtifact,
  ContractInstancesResponse,
  HealthResponse,
  ReadyResponse,
  ErrorResponse,
  PaginationParams,
  ClientConfig,
} from '@turnstile-portal/api-client';

Development

# Install dependencies
pnpm install

# Generate types from OpenAPI schema
pnpm generate

# Build the package
pnpm build

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Check code quality
pnpm check

License

MIT