Keyring
ReferencePackages

@keyring/react

The embeddable Manage API keys component, browser-only, embed-token-only.

Generated from packages/react/src/index.ts and the declarations it exports, by packages/docs/tools/generate-reference.mjs. Every signature below is printed from the source; the prose is the source's own doc comment.
npm install @keyring/react

Functions

KeyringKeys

export function KeyringKeys(props: KeyringKeysProps): JSX.Element;

useEmbedSession

export function useEmbedSession(getToken: () => Promise<string>, baseUrl: string): SessionState & {
    readonly reconnect: () => void;
    readonly reportAuthError: (error: unknown) => boolean;
};

Classes

EmbedClient

export class EmbedClient {
    constructor(private readonly baseUrl: string, private readonly token: string);
    async session(): Promise<EmbedSession>;
    async listKeys(options: {
        includeRevoked?: boolean;
    } = {}): Promise<ApiKey[]>;
    async createKey(input: {
        name?: string;
        scopes?: readonly string[];
    }): Promise<MintedApiKey>;
    async rotateKey(keyId: string, options: {
        overlapHours?: number;
    } = {}): Promise<{
        minted: MintedApiKey;
        previous: ApiKey;
    }>;
    async revokeKey(keyId: string, reason?: string): Promise<ApiKey>;
}

KeyringApiError

export class KeyringApiError extends Error {
    constructor(readonly status: number, readonly code: string | undefined, message: string);
}

KeyringAuthError

export class KeyringAuthError extends Error {
    constructor(message: string, readonly cause_?: unknown);
}

Interfaces

ApiKey

export interface ApiKey {
  readonly id: string;
  readonly projectId: string;
  readonly tenantId: string;
  readonly env: Environment;
  readonly displayPrefix: string;
  readonly name: string | null;
  readonly scopes: readonly string[];
  readonly expiresAt: string | null;
  readonly revokedAt: string | null;
  readonly revokedReason: string | null;
  readonly quarantinedAt: string | null;
  readonly quarantineReason: string | null;
  readonly rotatedFrom: string | null;
  readonly createdAt: string;
  readonly lastUsedAt: string | null;
}

EmbedSession

export interface EmbedSession {
  readonly project: {
    readonly id: string;
    readonly name: string;
    readonly slug: string;
  };
  readonly env: Environment;
  readonly testMode: boolean;
  readonly tenant: {
    readonly id: string;
    readonly externalId: string;
    readonly name: string | null;
  };
  readonly scopes: readonly string[];
  readonly expiresAt: string;
  readonly expiresInMs: number;
  readonly receivedAtMs: number;
}

KeyringKeysProps

export interface KeyringKeysProps {
  readonly getToken: () => Promise<string>;
  readonly baseUrl: string;
  readonly className?: string;
}

MintedApiKey

export interface MintedApiKey extends ApiKey {
  readonly key: string;
  readonly keyShownOnce: true;
}

Types

Environment

export type Environment = 'live' | 'test';

SessionState

export type SessionState =
  | { readonly status: 'loading' }
  | {
      readonly status: 'ready';
      readonly client: EmbedClient;
      readonly session: EmbedSession;
    }
  | { readonly status: 'reauth'; readonly message: string };

Constants

REFRESH_MARGIN_MS

const REFRESH_MARGIN_MS: 60000;

On this page