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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@usegrant/sdk

v2.1.0

Published

TypeSafe TypeScript SDK for accessing the UseGrant REST API

Downloads

92

Readme

UseGrant SDK

TypeSafe TypeScript SDK for accessing the UseGrant REST API.

Tests

Installation

SDK can be installed using npm, bun or pnpm package managers:

npm install @usegrant/sdk
# or
bun install @usegrant/sdk
# or
pnpm install @usegrant/sdk

Authentication

To use the SDK, you need to have an API key. You can create one in the UseGrant Settings Page page. If you face any 401 or 403 errors when you are sending a token, it can be one of the following reasons:

  • The token is invalid, check if you have copied the token correctly. Also make sure the token is in format uga_<token>.
  • The token has expired, you can create a new token and replace the existing token.

Runtime

The SDK uses the Fetch API under the hood, which is supported widely in all modern browsers and Node.js(18+).

Usage

The following example shows how to create a provider using the SDK.

import UseGrant from '@usegrant/sdk';

// Initialize the SDK
const usegrant = new UseGrant('YOUR_API_KEY');

// Create a provider
const provider = await usegrant.createProvider({
  name: 'My Provider',
  description: 'My Provider Description',
});

Available methods:

  • createProvider
  • listProviders
  • getProvider
  • deleteProvider
  • createClient
  • listClients
  • getClient
  • deleteClient
  • addDomain
  • listDomains
  • getDomain
  • verifyDomain
  • deleteDomain
  • createToken
  • listTenants
  • createTenant
  • getTenant
  • deleteTenant
  • listTenantProviders
  • createTenantProvider
  • getTenantProvider
  • deleteTenantProvider
  • listTenantProviderPolicies
  • createTenantProviderPolicy
  • getTenantProviderPolicy
  • deleteTenantProviderPolicy
  • validateToken

Refer to the API Reference for more information about the available methods and their parameters.

TypeScript Support

The SDK is written in TypeScript and provides full type safety out of the box. All methods and their parameters are fully typed:

Configuration

Retry Options

The SDK uses the ky library under the hood, which supports retry options. You can pass a retry option to the constructor to customize the retry behavior.

const usegrant = new UseGrant('YOUR_API_KEY', {
  retry: {
    limit: 3,
    backoffLimit: 1000,
  },
});

Abort Signal

The SDK supports abort signal to cancel the request. You can pass a signal option to the constructor to customize the abort behavior.

const usegrant = new UseGrant('YOUR_API_KEY', {
  signal: AbortSignal.timeout(1000),
});

Refer to the ky retry options for more information about the available options.

Error Handling

The SDK throws a custom error UseGrantError when you face any errors from the API. You can catch the error and handle it accordingly.

import { UseGrant, UseGrantError } from '@usegrant/sdk';

const usegrant = new UseGrant('YOUR_API_KEY');

try {
  const provider = await usegrant.createProvider({
    name: 'My Provider',
    description: 'My Provider Description',
  });
} catch {
  // handle the error
}

Error Handling

The SDK throws a custom error UseGrantError when you face any errors from the API or ZodError when you face any errors from the schema validation. You can catch the error and handle it accordingly.

import { UseGrant, UseGrantError } from '@usegrant/sdk';
import { z } from 'zod';

const usegrant = new UseGrant('YOUR_API_KEY');

try {
  const provider = await usegrant.createProvider({
    name: 'My Provider',
    description: 'My Provider Description',
  });
} catch (error) {
  if (error instanceof z.ZodError) {
    // handle the validation error
  }

  if (error instanceof UseGrantError) {
    // handle the api error
  }

  // handle the unknown error
}

Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run changeset npx @changeset/cli to generate the changelog and commit the generated changelog file along with the changes
  5. Commit your changes (git commit -m 'Add some amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Please make sure to update tests as appropriate and follow the existing coding style.

For reference to changeset, please refer to the Changeset Documentation.