---
title: Permissions client SDK
description: >-
  Public portable Permissions client functions and types, generated from the SDK
  source.
canonical_url: 'https://saaslayer.com/docs/reference/permissions/'
last_updated: '2026-11-21T21:40:59-08:00'
---
# Permissions client SDK

## Checked example

This example is included from source and typechecked against the SDK. Supply your
own deployment configuration and session; this page does not run a live request.

```ts
import { createPermissionsClient } from '@saaslayer/permissions'

// Read these from your application's trusted configuration and signed-in session.
export async function listMyOrganizations(apiBase: string, sessionToken: string) {
  const permissions = createPermissionsClient({
    apiBase,
    token: sessionToken,
    authMode: 'bearer',
  })
  return permissions.listMyOrganizations()
}
```

Reference for **@saaslayer/permissions 0.3.0**. Generated from this version's public exports and TypeScript declarations. Signatures describe the API; the integration guides explain behavior and setup.

## ApiError

```ts
export interface ApiError {
    status: number;
    type: string;
    code?: string;
    message: string;
    details?: Record<string, unknown>;
}
```

## ApiKey

```ts
export interface ApiKey {
    id?: string;
    keyId?: string;
    name?: string;
    principalType?: string;
    userId?: string;
    scope?: Scope | null;
    permissions?: ApiKeyPermissions;
    status?: string;
    expiresAt?: string | null;
    apiKey?: string;
    [key: string]: unknown;
}
```

## ApiKeyPermissions

```ts
export interface ApiKeyPermissions {
    allows: PermissionAllow[];
    denies?: PermissionAllow[];
}
```

## ApiResponse

```ts
export interface ApiResponse<T = unknown> {
    data: T;
    raw: unknown;
    meta?: {
        nextCursor?: string;
    };
}
```

## AuthMode

How the token is sent. 'auto' (default): a 3-dot-segment JWT/session token → bearer, else x-api-key.

```ts
export type AuthMode = 'apikey' | 'bearer' | 'auto';
```

## CatalogScope

A choosable scope in the registered catalog (drives the key-manager picker).

```ts
export interface CatalogScope {
    id: string;
    service: string;
    resourceType: string;
    action: string;
    scope: string;
    grant: 'auto' | 'approval';
    owner?: string;
    description?: string;
}
```

## CreateApiKeyInput

```ts
export interface CreateApiKeyInput {
    userId?: string;
    principal?: {
        type: string;
        id: string;
    };
    name: string;
    scope?: Scope | null;
    permissions: ApiKeyPermissions;
    expiresAt?: string;
}
```

## createPermissionsClient

Create a headless Permissions client. No React, no DOM — safe in browsers, workers, and Node 18+.

```ts
export declare function createPermissionsClient(options: PermissionsClientOptions): PermissionsClient;
```

## DEFAULT_MAINTENANCE_MAX_WAIT_MS

```ts
export declare const DEFAULT_MAINTENANCE_MAX_WAIT_MS: 30000;
```

## isMaintenanceError

A Permissions API admin maintenance answer (503 `maintenance`): retryable, never a deny or a permission error.

```ts
export declare function isMaintenanceError(err: unknown): err is ApiError;
```

## MaintenanceRetryOptions

Waiting out the Permissions API's admin maintenance gate (503, error code `maintenance`, Retry-After).

```ts
export interface MaintenanceRetryOptions {
    baseDelayMs?: number;
    maxWaitMs?: number;
    sleep?: (ms: number) => Promise<void>;
}
```

## MyOrganizations

The authenticated caller's own orgs + projects — the two-level switcher surface (M0.9).

```ts
export interface MyOrganizations {
    organizations: OrgRef[];
    projects: OrgRef[];
}
```

## Org

```ts
export interface Org {
    id: string;
    name?: string;
    [key: string]: unknown;
}
```

## OrgRef

A caller-scoped org/project reference (from GET /me/organizations).

```ts
export interface OrgRef {
    id: string;
    name?: string;
    personal?: boolean;
    createdAt?: string;
}
```

## PermissionAllow

```ts
export interface PermissionAllow {
    action: string;
    resource?: string;
    service?: string;
    when?: unknown;
}
```

## PermissionsClient

```ts
export interface PermissionsClient {
    request(method: string, path: string, body?: unknown): Promise<ApiResponse>;
    list(resource: string, params?: Record<string, string>): Promise<ApiResponse>;
    get(resource: string, id: string): Promise<ApiResponse>;
    listOrgs(params?: Record<string, string>): Promise<Org[]>;
    listMyOrganizations(): Promise<MyOrganizations>;
    listCatalogScopes(): Promise<CatalogScope[]>;
    listApiKeys(userId: string): Promise<ApiKey[]>;
    listWorkspaceApiKeys(workspaceId: string): Promise<ApiKey[]>;
    createApiKey(input: CreateApiKeyInput): Promise<ApiKey>;
    editApiKeyScopes(keyId: string, delta: ScopeDelta): Promise<ApiKey>;
    rotateApiKey(keyId: string): Promise<ApiKey>;
    revokeApiKey(keyId: string): Promise<void>;
}
```

## PermissionsClientOptions

```ts
export interface PermissionsClientOptions {
    apiBase: string;
    token: string;
    authMode?: AuthMode;
    fetch?: typeof fetch;
    maintenanceRetry?: MaintenanceRetryOptions;
}
```

## Scope

An API key's scope: one workspace, or an org and the workspaces in it the key covers ('\*' = all).

```ts
export interface Scope {
    type: 'WORKSPACE' | 'ORG';
    id: string;
    workspaces?: string[] | '*';
}
```

## ScopeDelta

Add/remove scopes on an issued key (D11 agent-evolve).

```ts
export interface ScopeDelta {
    add?: PermissionAllow[];
    remove?: PermissionAllow[];
}
```
