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

@heymantle/core-api-client

v0.3.0

Published

TypeScript SDK for the Mantle Core API

Readme

@heymantle/core-api-client

A TypeScript SDK for the Mantle Core API. Built with a resource-based architecture similar to the Stripe SDK.

Installation

npm install @heymantle/core-api-client

Quick Start

import { MantleCoreClient } from '@heymantle/core-api-client';

const client = new MantleCoreClient({
  apiKey: 'your-api-key',
});

Authentication

The client supports two authentication methods:

// API Key (for server-side use)
const client = new MantleCoreClient({
  apiKey: 'your-api-key',
});

// OAuth Access Token
const client = new MantleCoreClient({
  accessToken: 'your-oauth-token',
});

Resources

For full documentation on all available resources and their parameters, see the Mantle Core API Reference.

Customers

// List customers
const { customers, hasNextPage, total } = await client.customers.list({
  take: 25,
  search: 'acme',
  sort: 'createdAt',
  sortDirection: 'desc',
});

// Cursor-based pagination
if (hasNextPage) {
  const nextPage = await client.customers.list({ take: 25, cursor });
}

// Get a customer
const { customer } = await client.customers.retrieve('cust_123');

// Update a customer
const { customer } = await client.customers.update('cust_123', {
  name: 'Acme Corporation',
  tags: ['enterprise', 'vip'],
});

// Delete a customer
await client.customers.del('cust_123');

Configuration Options

import { MantleCoreClient } from '@heymantle/core-api-client';

const client = new MantleCoreClient({
  // Required: one of apiKey or accessToken
  apiKey: 'your-api-key',

  // Optional: custom base URL (defaults to https://api.heymantle.com/v1)
  baseURL: 'https://api.heymantle.com/v1',

  // Optional: request timeout in ms (defaults to 30000)
  timeout: 30000,

  // Optional: override the fetch implementation
  fetchFn: customFetch,
});

// Update authentication at runtime
client.updateAuth({ accessToken: 'new-token' });

Custom fetch — JWT sessions with @heymantle/app-bridge-react

If you're building a Mantle app and want API calls to be authenticated via JWT session rather than an API key, you can pass the authenticatedFetch function from @heymantle/app-bridge-react as the fetchFn override:

import { MantleCoreClient } from '@heymantle/core-api-client';
import { useAuthenticatedFetch } from '@heymantle/app-bridge-react';

function useClient() {
  const authenticatedFetch = useAuthenticatedFetch();

  return new MantleCoreClient({
    fetchFn: authenticatedFetch,
  });
}

This ensures every request made by the SDK is routed through the app bridge's authenticated fetch, automatically attaching the session token.

Middleware

The client supports Koa-style middleware for intercepting requests and responses. Middleware can be used for logging, authentication refresh, retry logic, and more.

Creating Custom Middleware

import { MantleCoreClient, type Middleware } from '@heymantle/core-api-client';

const loggingMiddleware: Middleware = async (ctx, next) => {
  const start = Date.now();
  console.log(`[Request] ${ctx.request.method} ${ctx.request.url}`);

  await next();

  const duration = Date.now() - start;
  console.log(`[Response] ${ctx.response?.status} (${duration}ms)`);
};

const client = new MantleCoreClient({ apiKey: 'your-api-key' });
client.use(loggingMiddleware, { name: 'logging', priority: 10 });

Auth Refresh Middleware

Automatically refresh expired access tokens:

import { MantleCoreClient, createAuthRefreshMiddleware } from '@heymantle/core-api-client';

const client = new MantleCoreClient({ accessToken: 'initial-token' });

client.use(
  createAuthRefreshMiddleware({
    refreshToken: async () => {
      const response = await fetch('/api/refresh', { method: 'POST' });
      const data = await response.json();
      return data.accessToken;
    },
    onRefreshSuccess: (newToken) => {
      localStorage.setItem('accessToken', newToken);
    },
    onRefreshFailed: (error) => {
      window.location.href = '/login';
    },
  }),
  { name: 'auth-refresh' }
);

Rate Limit Middleware

The API enforces rate limits: 1,000 requests/minute and 5,000 requests/5 minutes. Use the built-in middleware:

import { createRateLimitMiddleware } from '@heymantle/core-api-client';

// Auto-retry on 429 responses
client.use(createRateLimitMiddleware({ enableRetry: true }));

// Preemptive throttling to avoid hitting limits
client.use(createRateLimitMiddleware({ enableThrottle: true }));

Error Handling

import {
  MantleAPIError,
  MantleAuthenticationError,
  MantlePermissionError,
  MantleNotFoundError,
  MantleValidationError,
  MantleRateLimitError,
} from '@heymantle/core-api-client';

try {
  await client.customers.retrieve('invalid_id');
} catch (error) {
  if (error instanceof MantleAuthenticationError) {
    console.log('Please re-authenticate');
  } else if (error instanceof MantlePermissionError) {
    console.log('Access denied');
  } else if (error instanceof MantleNotFoundError) {
    console.log('Resource not found');
  } else if (error instanceof MantleValidationError) {
    console.log('Validation failed:', error.details);
  } else if (error instanceof MantleRateLimitError) {
    console.log(`Rate limited. Retry after: ${error.retryAfter}s`);
  } else if (error instanceof MantleAPIError) {
    console.log(`Error ${error.statusCode}: ${error.message}`);
  }
}

License

MIT