Skip to content
LogoLogo

Embedded UI SDK

Checked example

This example is included from typechecked source. Complete the integration guide for your deployment and framework.

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.

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

ApiKeyManagerMountOptions

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

ApiKeyManagerProps

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

configFromAttrs

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.

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).

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.

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

initCdn

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

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.

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

MountOptions

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

mountOrgSwitcher

Mount the org-switcher widget into a host element.

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.

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

OrgSwitcher

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

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

OrgSwitcherProps

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

PortalMountOptions

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.

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

readScriptConfig

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

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.

export declare function registerWidgets(): void;

setWidgetDefaults

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

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

unmountOrgSwitcher

Unmount a previously mounted widget and release its React root.

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

unmountWidget

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

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

WIDGET_ELEMENTS

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

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

WidgetContext

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.

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

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.

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.

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