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

@sesamy/sdk

v1.23.0

Published

Pure TypeScript SDK for Sesamy API Proxy

Downloads

608

Readme

@sesamy/sdk

A pure TypeScript SDK for the Sesamy API Proxy, designed for tree-shaking with separate client and management exports.

Installation

npm install @sesamy/sdk
# or
pnpm add @sesamy/sdk

Usage

The SDK is auth-agnostic and accepts a tokenProvider function that returns a complete Authorization header value (e.g., "Bearer token" or "Basic credentials"). This allows integration with any authentication library or method, supporting both Bearer token and Basic authentication schemes.

Importing Types

import { client, management } from '@sesamy/sdk';
import type { User, Profile, Subscription, Entitlement } from '@sesamy/types';

Client SDK (End-user operations)

import { client } from '@sesamy/sdk';

// Example with auth0-spa-js
import { Auth0Client } from '@auth0/auth0-spa-js';
const auth0Client = new Auth0Client({
  domain: 'your-domain.auth0.com',
  client_id: 'your-client-id',
});

const sdkClient = client({
  baseUrl: 'https://api-proxy.example.com',
  tokenProvider: async () => {
    const token = await auth0Client.getTokenSilently();
    return `Bearer ${token}`; // Return the full Authorization header
  },
  vendorId: 'your-vendor-id', // Optional, for multi-tenancy
});

// Use client methods
const profile: Profile = await sdkClient.getProfile('user-id');
const updatedProfile: Profile = await sdkClient.updateProfile('user-id', { name: 'New Name' });

// Generate checkout link
const checkoutUrl = sdkClient.checkouts.generateLink(
  { apiUrl: 'https://api-proxy.example.com' },
  {
    items: [{ sku: 'premium-monthly' }],
    email: '[email protected]',
    language: 'en',
    redirectUrl: 'https://example.com/success',
  }
);

// Generate other links
const accountUrl = sdkClient.links.generateAccountLink(
  { baseUrl: 'https://app.example.com', clientId: 'your-client-id' },
  { language: 'en' }
);

const changePaymentUrl = sdkClient.links.generateChangePaymentLink(
  { baseUrl: 'https://app.example.com', clientId: 'your-client-id' },
  { contractId: 'contract-123', language: 'en' }
);

Management SDK (Admin operations)

import { management } from '@sesamy/sdk';

// Example with server-side auth (e.g., auth0-next or next-auth)
const sdkManagement = management({
  baseUrl: 'https://api-proxy.example.com',
  tokenProvider: async () => {
    // Your token retrieval logic here
    // e.g., from session, auth0-next, next-auth, etc.
    const token = await getTokenFromSession();
    return `Bearer ${token}`; // Return the full Authorization header
  },
  vendorId: 'your-vendor-id',
});

// Use management methods
const users: User[] = await sdkManagement.getUsers({ limit: 10 });
const newUser: User = await sdkManagement.createUser({ email: '[email protected]' });
await sdkManagement.setPassword('user-id', 'new-password');

Tree Shaking

Import only what you need to reduce bundle size:

// Only client
import { client } from '@sesamy/sdk';

// Only management
import { management } from '@sesamy/sdk';

// Only specific parts
import client from '@sesamy/sdk/client';
import management from '@sesamy/sdk/management';

API Reference

Types

The SDK re-exports TypeScript type definitions from the shared @sesamy/types package:

import type {
  User,
  Profile,
  Address,
  Subscription,
  Entitlement,
  EntitlementType,
  Product,
  Contract,
  Checkout,
  Bill,
  Transaction,
  Fulfillment,
  Vendor,
  Amendment,
  Tally,
  PaymentIssue,
  UserMetadata,
} from '@sesamy/types';

// SDK-specific types
import type { SDKConfig, ClientSDK, ManagementSDK } from '@sesamy/sdk';

Client Methods

  • getProfile(userId: string): Promise<Profile> - Get user profile
  • updateProfile(userId: string, data: Partial<Profile>): Promise<Profile> - Update user profile

Checkout Methods

  • checkouts.generateLink(config, params): string - Generate a checkout link URL
  • checkouts.create(data): Promise<Checkout> - Create a checkout session
  • checkouts.get(id): Promise<Checkout> - Get checkout session by ID
  • checkouts.update(id, data): Promise<Checkout> - Update a checkout session

Link Generation Methods

  • links.generateCheckoutLink(config, params): string - Generate a checkout link URL
  • links.generateAccountLink(config, params): string - Generate an account management link
  • links.generateChangePaymentLink(config, params): string - Generate a change payment method link
  • links.generateChangePlanLink(config, params): string - Generate a change subscription plan link
  • links.generateConsumeLink(config, params): string - Generate a content consumption link

Management Methods

  • getUsers(query?: any): Promise<User[]> - List users with optional filtering
  • createUser(data: Partial<User>): Promise<User> - Create a new user
  • getUser(userId: string): Promise<User> - Get a user by ID
  • updateUser(userId: string, data: Partial<User>): Promise<User> - Update a user
  • deleteUser(userId: string): Promise<void> - Delete a user
  • setPassword(userId: string, password: string): Promise<void> - Set user password
  • changeLoginIdentifier(userId: string, email: string): Promise<void> - Change user login email
  • setUserMetadata(userId: string, key: string, value: string): Promise<void> - Set user metadata
  • deleteUserMetadata(userId: string, key: string): Promise<void> - Delete user metadata

Configuration

  • baseUrl (required): Base URL for the API proxy
  • tokenProvider (required): Async function that returns the full Authorization header value (e.g., "Bearer token", "Basic credentials")
  • vendorId (optional): Vendor ID for multi-tenant setups

Error Handling

The SDK throws errors for API failures. Handle token expiration by refreshing tokens in your tokenProvider:

const sdk = client({
  baseUrl: 'https://api-proxy.example.com',
  tokenProvider: async () => {
    try {
      const token = await auth0Client.getTokenSilently();
      return `Bearer ${token}`; // Return the full Authorization header
    } catch (error) {
      // Handle token refresh failure
      throw new Error('Authentication failed');
    }
  },
});

Development

Using pnpm filters

From the monorepo root, you can use the sdk filter to run commands specifically for this package:

# Build the SDK
pnpm sdk build

# Production build (includes type definitions)
pnpm sdk build:prod

# Type checking
pnpm sdk type-check

# Development server
pnpm sdk dev

Direct commands

You can also run commands directly in the package directory:

cd packages/sdk
pnpm build
pnpm build:prod
pnpm type-check

License

MIT