Skip to content
Platform documentation
Node.js SDK
SDKs

Node.js SDK

Authoritative access checks and checkout from your backend.

Use the workspace package

The current @bagseven/sdk package is private to this monorepo. Add it as a workspace dependency to your application and build it before use. A public npm release is not assumed.

bash
corepack pnpm --filter @bagseven/sdk build

# In a consuming workspace package.json:
# "@bagseven/sdk": "workspace:*"

Initialize a server client

typescript
import { BagsevenClient } from "@bagseven/sdk/node";

const bagseven = new BagsevenClient({
  apiKey: process.env.BAGSEVEN_SECRET_KEY!,
  baseUrl: "http://127.0.0.1:4001",
});

Use your deployed entitlement API origin in production. The gateway on port 4000 serves policy routes; the public entitlement API in these examples is the daemon on port 4001.

Check before delivering work

typescript
const access = await bagseven.checkEntitlement("ocr", {
  holder: "customer-123",
});

if (!access.enabled) {
  throw new Error("An active OCR entitlement is required");
}

const usage = await bagseven.consumeEntitlement({
  feature: "ocr",
  holder: "customer-123",
  amount: "1",
  idempotencyKey: "document-job-123",
});

Use the exact holder from checkout. A server must enforce the consume result even if the browser already showed an enabled feature.

Issue a customer token

typescript
const { token } = await bagseven.identify({
  holder: "customer-123",
  email: "customer@example.com",
  expiresIn: 900,
});

// Return this short-lived customer token to that customer’s UI.
// Keep BAGSEVEN_SECRET_KEY on your backend.

Authenticate your own customer before choosing the holder. Do not let an arbitrary browser-supplied holder determine which customer token your backend issues.

Identify the authenticated billing customer

typescript
const { token } = await bagseven.identify({
  holder: authenticatedUser.id,
  email: authenticatedUser.verifiedEmail,
});

Use the merchant secret key only on your backend. The email is your authenticated assertion about that customer, not an address accepted blindly from the browser. Opaque holder IDs need an explicit contact for live checkout. A valid email-shaped holder is a backward-compatible contact default at token issuance.

Bagseven documentationemail and wallet · Avalanche · Registry