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.
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
export interface ApiError {
status: number;
type: string;
code?: string;
message: string;
details?: Record<string, unknown>;
}ApiKey
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
export interface ApiKeyPermissions {
allows: PermissionAllow[];
denies?: PermissionAllow[];
}ApiResponse
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.
export type AuthMode = 'apikey' | 'bearer' | 'auto';CatalogScope
A choosable scope in the registered catalog (drives the key-manager picker).
export interface CatalogScope {
id: string;
service: string;
resourceType: string;
action: string;
scope: string;
grant: 'auto' | 'approval';
owner?: string;
description?: string;
}CreateApiKeyInput
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+.
export declare function createPermissionsClient(options: PermissionsClientOptions): PermissionsClient;DEFAULT_MAINTENANCE_MAX_WAIT_MS
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.
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).
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).
export interface MyOrganizations {
organizations: OrgRef[];
projects: OrgRef[];
}Org
export interface Org {
id: string;
name?: string;
[key: string]: unknown;
}OrgRef
A caller-scoped org/project reference (from GET /me/organizations).
export interface OrgRef {
id: string;
name?: string;
personal?: boolean;
createdAt?: string;
}PermissionAllow
export interface PermissionAllow {
action: string;
resource?: string;
service?: string;
when?: unknown;
}PermissionsClient
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
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).
export interface Scope {
type: 'WORKSPACE' | 'ORG';
id: string;
workspaces?: string[] | '*';
}ScopeDelta
Add/remove scopes on an issued key (D11 agent-evolve).
export interface ScopeDelta {
add?: PermissionAllow[];
remove?: PermissionAllow[];
}