Skip to Content
SDKsTypeScript

TypeScript SDK

Fully typed, built on fetch: it works in Node.js 18 and later, Deno, Bun, edge runtimes and browsers.

npm install @licenseman/sdk

npm  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicensesApi or CustomersApi, and one method per endpoint, named after it: Create a license is createLicense. Each method takes a single object with the endpoint’s path and query parameters, and its body under the name of its schema, and returns the response, typed.

The API Reference shows the TypeScript call for every endpoint: it’s the place to look for what a method takes and returns.

Authentication

Pass a Configuration to each class you create:

import { Configuration, LicensesApi } from "@licenseman/sdk"; // With an API key, from your backend: const licenses = new LicensesApi( new Configuration({ apiKey: process.env.LICENSEMANAGER_API_KEY }), ); // With a token scoped to a customer, license or machine: const scoped = new LicensesApi(new Configuration({ accessToken: token }));

Never ship an API key in your application or a web page. In a browser, use a scoped token.

Examples

Create a license after a sale, and email its key to the customer:

const license = await licenses.createLicense({ productId: "x7Kp2QaZ", createLicense: { email: "jane@example.com", sendKey: true }, });

Validate a key from your application, which needs no credentials:

const { license: token } = await new LicensesApi().validateKey({ productId: "x7Kp2QaZ", validateKey: { key: "7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", fingerprint: "4c:32:75:8f:9a:1e", version: "1.4.2", }, });

List the licenses of a product, one page at a time:

const { data, pagination } = await licenses.listLicenses({ productId: "x7Kp2QaZ", page: 2, pageSize: 50, sort: "-createdAt", });

Errors

A failed request throws a ResponseError, holding the response. Its body has the error’s stable code:

import { ResponseError } from "@licenseman/sdk"; try { await licenses.getLicense({ id: "l3Nv8KwB" }); } catch (error) { if (error instanceof ResponseError) { const { error: details } = await error.response.json(); console.error(error.response.status, details.code, details.message); } }