Skip to content

SDKs & Client Libraries

Sesamy provides official SDKs and client libraries for different use cases and platforms.

Available SDKs

Sesamy SDK (TypeScript)

Lower-level TypeScript SDK for direct API access to all Sesamy services.

Features:

  • Full TypeScript support with comprehensive type definitions
  • Request deduplication and automatic retries for robust HTTP handling
  • Direct access to all API endpoints including complete management APIs
  • Promise-based API with automatic token injection
  • Separate client and management APIs
  • Tree-shaking support for optimal bundle sizes

Learn more →

Sesamy JS (TypeScript)

Full-featured browser JavaScript library for authentication, content access control, analytics, and Sesamy API integration.

Features:

  • Authentication and user session management
  • Content locking and paywall functionality
  • Analytics and event tracking
  • Automatic token refresh
  • Content transformation and access control

Learn more →

Quick Start

Sesamy SDK (TypeScript)

bash
npm install @sesamy/sdk
typescript
import { client, management } from '@sesamy/sdk';

// Client SDK for user operations
const clientSdk = client({
  tokenProvider: async () => 'your-jwt-token',
});

// Get user profile
const profile = await clientSdk.profile.get('user-id');

// Management SDK for admin operations
const mgmtSdk = management({
  tokenProvider: async () => 'your-management-jwt-token',
});

// List all users
const users = await mgmtSdk.users.list();

Sesamy JS (Browser)

bash
npm install @sesamy/sesamy-js
html
<script src="https://cdn.sesamy.com/sesamy-js/latest/sesamy-js.min.js"></script>
<script type="application/json" id="sesamy-js">
  {
    "clientId": "your-client-id"
  }
</script>
<script>
  window.addEventListener('sesamyJsReady', async () => {
    const isAuth = await window.sesamy.auth.isAuthenticated();
    if (isAuth) {
      const profile = await window.sesamy.profile.get();
    }
  });
</script>

Feature Comparison

FeatureSesamy SDKSesamy JS
Authentication
Profile Management
Subscriptions
Entitlements
Checkout
Webhooks⚠️
Management API✅ (Complete)
Content Locking
Analytics
Browser Integration
TypeScript
Async/Await

✅ Full support | ⚠️ Partial support | ❌ Not available

Common Patterns

Initialization

Sesamy SDK (TypeScript)

typescript
import { client, management } from '@sesamy/sdk';

// Client SDK for user-facing operations
const clientSdk = client({
  baseUrl: 'https://api.sesamy.com',
  tokenProvider: async () => process.env.USER_JWT_TOKEN,
});

// Management SDK for admin operations
const mgmtSdk = management({
  baseUrl: 'https://api.sesamy.com',
  tokenProvider: async () => process.env.MANAGEMENT_JWT_TOKEN,
});

Sesamy JS (Browser)

javascript
// Script tag initialization
<script type="application/json" id="sesamy-js">
{
  "clientId": "your-client-id"
}
</script>

// Programmatic initialization
import { init } from '@sesamy/sesamy-js';

const sesamy = await init({
  clientId: 'your-client-id',
});

Error Handling

Sesamy SDK (TypeScript)

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

const sdk = client({
  /* config */
});

try {
  const profile = await sdk.profile.get('user-id');
} catch (error: any) {
  if (error.status === 401) {
    console.error('Authentication required');
  } else if (error.status === 403) {
    console.error('Access denied');
  } else {
    console.error('API error:', error.message);
  }
}

Sesamy JS (Browser)

javascript
// Wait for SDK ready
window.addEventListener('sesamyJsReady', async () => {
  try {
    const profile = await window.sesamy.profile.get();
  } catch (error) {
    if (error.code === 'AUTH_REQUIRED') {
      console.error('Authentication required');
    } else {
      console.error('Error:', error.message);
    }
  }
});

SDK Configuration

Sesamy SDK

Token Provider

The SDK requires a token provider function for authentication:

typescript
const sdk = client({
  tokenProvider: async () => {
    // Implement token retrieval logic
    return await getValidToken();
  },
});

Sesamy JS

Configuration Object

Sesamy JS is configured via a JSON script tag or programmatic initialization:

html
<script type="application/json" id="sesamy-js">
  {
    "clientId": "your-client-id",
    "api": {
      "endpoint": "https://api.sesamy.com"
    },
    "analytics": {
      "enabled": true
    }
  }
</script>

Next Steps

Choose the right SDK for your use case:

  • Sesamy SDK → - For direct API access and server-side applications
  • Sesamy JS → - For browser-based applications with content access control

Or explore the REST APIs directly:

Released under the MIT License.