---
title: Embedded UI SDK
description: 'Public embedded UI SDK functions and types, generated from the SDK source.'
canonical_url: 'https://saaslayer.com/docs/reference/embedded-ui/'
last_updated: '2026-11-23T16:12:49-08:00'
---
# Embedded UI SDK

## Checked example

This example is included from typechecked source. Complete the
[integration guide](https://saaslayer.com/docs/getting-started/agents) for your deployment and framework.

```ts
import { configureWidgets, registerWidgets } from '@saaslayer/embed'

// Run in the browser before mounting SaaSLayer custom elements.
export function prepareWidgets(apiBase: string, permissionsApiBase: string) {
  configureWidgets({ apiBase, permissionsApiBase })
  registerWidgets()
}
```

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

## ApiKeyManager

Self-serve + admin API-key widget over the headless SDK.

```ts
export declare function ApiKeyManager(props: ApiKeyManagerProps): React.JSX.Element;
```

## ApiKeyManagerMountOptions

```ts
export interface ApiKeyManagerMountOptions extends ApiKeyManagerProps {
    colorScheme?: 'light' | 'dark' | 'auto';
}
```

## ApiKeyManagerProps

```ts
export interface ApiKeyManagerProps {
    apiBase: string;
    token: string;
    authMode?: AuthMode;
    variant?: 'self' | 'admin';
    userId?: string;
    workspaceId?: string;
}
```

## configFromAttrs

```ts
export declare function configFromAttrs(el: HTMLElement): SaaSLayerConfig;
```

## configureWidgets

Configure every \<sl-\*> element on the page that does not name an option itself. Element attributes still win.

```ts
export declare function configureWidgets(options: WidgetOptions): void;
```

## defineWidget

Define a single custom element wrapping a React widget. Idempotent: a tag already registered is skipped
(guards the double-registration error).

```ts
export declare function defineWidget(tag: string, def: WidgetDef): void;
```

## getWidgetContext

The facade for the deployment at `apiBase`, sharing the Session its `&#60;sl-*&#62;` elements use. `appApiBase` is the
host's own API base. Resolves once the deployment's login descriptor is read; rejects when either base is not an
https URL or the descriptor cannot be read.

```ts
export declare function getWidgetContext(options: { apiBase: string; appApiBase: string; }): Promise<WidgetContext>;
```

## initCdn

Apply a loader script's default config + register the \<sl-\*> suite.

```ts
export declare function initCdn(script: { getAttribute(name: string): string | null; } | null): void;
```

## mountApiKeyManager

Mount the API key manager widget (self-serve or admin inventory) into a host element.

```ts
export declare function mountApiKeyManager(el: Element, opts: ApiKeyManagerMountOptions): void;
```

## MountOptions

```ts
export interface MountOptions extends OrgSwitcherProps {
    colorScheme?: 'light' | 'dark' | 'auto';
}
```

## mountOrgSwitcher

Mount the org-switcher widget into a host element.

```ts
export declare function mountOrgSwitcher(el: Element, opts: MountOptions): void;
```

## mountPortal

Mount the Portal into a host element. The session never enters the iframe URL or browser storage: it is posted to
the exact Portal origin on a random per-mount channel once the Portal says it is ready. `unmountWidget(el)` removes it.

```ts
export declare function mountPortal(el: Element, opts: PortalMountOptions): void;
```

## OrgSwitcher

Headless-friendly org switcher. Renders a labelled select of the caller's orgs.

```ts
export declare function OrgSwitcher(props: OrgSwitcherProps): React.JSX.Element;
```

## OrgSwitcherProps

```ts
export interface OrgSwitcherProps {
    apiBase: string;
    token: string;
    authMode?: AuthMode;
    orgId?: string;
    onChange?: (orgId: string) => void;
    label?: string;
    placeholder?: string;
}
```

## PortalMountOptions

```ts
export interface PortalMountOptions {
    portalUrl: string;
    getToken: (signal: AbortSignal) => Promise<PortalSession>;
    colorScheme?: 'light' | 'dark' | 'auto';
    theme?: PortalTheme;
}
```

## PortalSession

An org-scoped Permissions session (`sess_…`) for the Portal, as the host acquired it.

```ts
export interface PortalSession {
    token: string;
    expiresAt: string;
    sessionId: string;
}
```

## readScriptConfig

Read default widget config from a loader \<script>'s data-\* attributes (only present keys).

```ts
export declare function readScriptConfig(script: { getAttribute(name: string): string | null; } | null): WidgetDefaults;
```

## registerWidgets

Register the full \<sl-\*> widget suite. Safe to call multiple times. On a callback page inside a sign-in popup the
provider's answer is first relayed to the window that opened it; nothing on such a page completes the sign-in.

```ts
export declare function registerWidgets(): void;
```

## setWidgetDefaults

Set fallback config for \<sl-\*> elements that omit an attribute. Element attributes still win.

```ts
export declare function setWidgetDefaults(defaults: WidgetDefaults): void;
```

## unmountOrgSwitcher

Unmount a previously mounted widget and release its React root.

```ts
export declare function unmountOrgSwitcher(el: Element): void;
```

## unmountWidget

Unmount any previously mounted SaaSLayer widget or Portal and release what it holds.

```ts
export declare function unmountWidget(el: Element): void;
```

## WIDGET_ELEMENTS

The suite: tag → widget (+ optional event/prop wiring).

```ts
export declare const WIDGET_ELEMENTS: Record<string, WidgetDef>;
```

## WidgetContext

```ts
export interface WidgetContext {
    getState(): WidgetState;
    subscribe(listener: (state: WidgetState) => void): () => void;
    switchOrg(orgId: string): Promise<void>;
    refreshOrganizations(): Promise<void>;
    fetchApp(path: string, init?: RequestInit): Promise<Response>;
    getProfile(): WidgetProfile | null;
    checkPermissions(checks: PermissionCheck[]): Promise<BatchPermissionResult[]>;
    signOut(): Promise<void>;
}
```

## WidgetContextError

A refusal or failure of the facade. `status` is the HTTP status when a server answered with one.

```ts
export interface WidgetContextError {
  "code": WidgetContextErrorCode;
  "status"?: number | undefined;
  "name": string;
  "message": string;
  "stack"?: string | undefined;
  "cause"?: unknown;
}
export declare const WidgetContextError: {
  new (code: WidgetContextErrorCode, message: string, status?: number): WidgetContextError;
};
```

## WidgetContextErrorCode

```ts
export type WidgetContextErrorCode = 'discovery_failed' | 'not_signed_in' | 'destination_refused' | 'init_refused' | 'context_changed' | 'org_switch_failed' | 'organizations_unavailable' | 'permissions_unavailable';
```

## WidgetOptions

What `configureWidgets` (or the loader script) sets for every element that does not name the option itself.

```ts
export interface WidgetOptions {
    apiBase?: string;
    permissionsApiBase?: string;
    socialMode?: SocialMode;
    redirectUri?: string;
    brandName?: string;
    privacyPolicyUrl?: string;
    termsUrl?: string;
    phoneCountries?: string[];
    storage?: StoragePolicy;
    dom?: WidgetDom;
}
```

## WidgetState

What the host may know: who is signed in, the org their token acts in and the project they picked there. Never a token.

```ts
export interface WidgetState {
    signedIn: boolean;
    suid?: string;
    orgId?: string;
    projectId?: string;
}
```
