For the complete documentation index, see llms.txt. This page is also available as Markdown.

Node.js / TypeScript

@selfxyz/enterprise-sdk is the official Node/TS client for Self Enterprise. It wraps session creation, retrieval, and webhook signature verification with typed payloads.

Install

npm install @selfxyz/enterprise-sdk

Node 20+. ESM-only.

Initialize

import { SelfClient } from '@selfxyz/enterprise-sdk';

const self = new SelfClient({
  apiKey: process.env.SELF_API_KEY!,        // sk_test_... or sk_live_...
});

The API key is the only option you need to pass. Whether the client talks to test or live is determined by the key prefix (sk_test_ or sk_live_).

Sessions

Create

Get the flowId by publishing a configuration in the dashboard, it's shown on the product's Test and Live tabs. See Configure a product.

const session = await self.sessions.create({
  flowId: '9c0b4f1c-1d6c-4f1b-a8c4-9f0fa0a8d9e2',
  externalUuid: 'a1b2c3d4-5678-4e9a-b012-3456789abcde',  // a UUID, your stable id for the user
  // optional:
  expiresInSeconds: 3600,
  metadata: { campaign: 'winter-2026' },
  successUrl: 'https://app.example.com/verified',
  failureUrl: 'https://app.example.com/failed',
});

session.verificationUrl;  // give to the user
session.id;               // store on your side
session.expiresAt;        // ISO-8601

Returns Session (alias of CreateSessionResponse).

The most important fields:

Field
Notes

id

Persistent session ID. Use this when calling sessions.get(...) or matching against webhook events.

verificationUrl

The URL to hand to the user. They open it in their Self app.

expiresAt

ISO-8601 timestamp. After this the session cannot be completed.

flowVersionId

Immutable pin to the flow version this session ran against. Publishing a new flow version doesn't disturb in-flight sessions.

Get

Returns SessionDetail (exported from the SDK, an alias of SessionDetailResponse):

Types

The SDK re-exports the canonical Zod schemas and inferred types from @self/schemas:

You can also import the schemas themselves for runtime validation:

Webhook verification

See Verify webhooks.

Error handling

Bad arguments (for example a flowId or externalUuid that isn't a UUID) throw SelfValidationError before any request is sent. The SDK doesn't retry, handle transient 429 and 5xx responses yourself (back off and retry). See Error handling for the full code catalog.

Last updated