Skip to content

Connect SDK

Types

TypeScript types exported by @alter-ai/connect.

All types are available as named exports.

import AlterConnect, {
type AlterConnectConfig,
type OpenOptions,
type Grant,
type AlterError,
} from "@alter-ai/connect";

The object passed to onSuccess (one entry per provider authorized in the session).

interface Grant {
grant_id: string;
provider: string;
provider_name: string;
account_identifier: string;
timestamp: string;
operation: "creation" | "reauth";
scopes: string[];
status: "active" | "pending" | "error";
metadata?: {
account_display_name?: string;
account_email?: string;
[key: string]: any;
};
}
FieldTypeDescription
grant_idstringThe Alter Vault identifier for this grant. Persist this when the application stores grants in its own database; the headless SDK methods accept it directly for token retrieval.
providerstringProvider technical ID — e.g. "google", "slack", "github". Use this in API calls and database queries.
provider_namestringProvider display name — e.g. "Google", "Slack", "GitHub". Use this when rendering to end users.
account_identifierstringThe identifier for the user account at the provider — typically the user’s email or workspace handle (e.g. "alice@gmail.com", "alice@company.slack.com").
timestampstringISO 8601 timestamp of when the grant was established.
operation"creation" | "reauth"How the grant was established. "creation" is a brand-new grant; "reauth" is a re-authorization of an existing grant (e.g. after an expired refresh token).
scopesstring[]OAuth scopes granted by the user. Example: ["calendar.readonly", "gmail.send"].
status"active" | "pending" | "error"Grant status at the moment the flow completed. "active" is the normal terminal state.
metadataobject?Optional provider-supplied extras. account_display_name and account_email are populated when the provider exposes them. Additional keys may appear depending on the provider; treat unknown keys as advisory.

metadata is optional — older grants and providers that do not expose extras omit it. Always null-check before reading nested keys.

The object passed to onError (and emitted on the error event).

interface AlterError {
code: string;
message: string;
details?: Record<string, any>;
}
FieldTypeDescription
codestringStable, machine-readable error code. See the table below for the codes emitted by the Connect SDK.
messagestringHuman-readable summary safe to surface to end users (no internal identifiers, no PII).
detailsobject?Additional context. For provider errors, contains the provider’s raw error code and description. For popup_blocked, invalid_token, and session_expired, is typically omitted.
CodeCauseResolution
popup_blockedThe browser blocked the popup.Call open() synchronously inside the click handler — see the popup flow notes.
invalid_tokenThe session token is malformed or not recognised.Mint a fresh session on the backend.
session_expiredThe session token expired (10-minute default) or was already used.Mint a fresh session per click.
invalid_optionsopen() was called without a string token or a function onSuccess.Check the call site against the OpenOptions requirements.
sdk_destroyedA method was called after destroy().Call create() again if a new instance is needed.
invalid_responseThe backend reported success but the grant payload was incomplete.Retry; if it persists, capture the trace ID and contact support.
redirect_errorThe mobile redirect flow could not save state to sessionStorage.Usually caused by private-mode tabs with storage disabled. Surface the error and ask the user to use a normal browsing window.
invalid_oauth_urlThe OAuth URL could not be parsed for origin validation.Indicates a misconfigured Alter host; contact support.

For the cross-SDK error catalog (auth, scope, grant, provider) see the Errors reference.

The argument to alterConnect.open().

interface OpenOptions {
token: string;
onSuccess: (grants: Grant[]) => void;
onExit?: () => void;
onError?: (error: AlterError) => void;
onEvent?: (eventName: string, metadata: any) => void;
}
FieldTypeRequiredDescription
tokenstringyesSession token minted on the application backend via app.createConnectSession(). Single-use, short-lived (10-minute default).
onSuccess(grants: Grant[]) => voidyesFires when the user finishes the OAuth flow. Receives an array — one Grant per provider authorized in the session.
onExit() => voidnoFires when the user closes the popup without finishing. Does not fire on the mobile redirect flow.
onError(error: AlterError) => voidnoFires on any failure.
onEvent(eventName: string, metadata: any) => voidnoAnalytics hook. The SDK emits exactly one event today — see Events & callbacks.

See the full open() reference for synchronous error semantics and the mobile redirect flow.

The optional argument to AlterConnect.create().

interface AlterConnectConfig {
debug?: boolean;
baseURL?: string;
}
FieldTypeRequiredDescription
debugbooleannoWhen true, the SDK logs lifecycle events to console.log. Default false.
baseURLstringnoReserved. Not yet supported — passing any value throws at construction. Omit the field. The type member exists so a future self-hosted release can populate it without a breaking API change.

See the create() reference for the reserved-field error and the instance lifecycle methods (close, destroy, isOpen, getVersion).

Exported for typing convenience when the application surfaces a provider list it received elsewhere. The Connect SDK itself does not return Provider objects to the browser.

interface Provider {
id: string;
name: string;
description: string;
category: string;
logo_url: string;
}