Skip to content

Reference

Types

TypeScript types exported by @alter-ai/connect.

All types are available as named exports.

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

AlterConnect is the default value export. The package does not expose it as a named value export. The seven interfaces above are type-only named exports.

One retained provider grant passed to onSuccess.

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]: unknown;
};
}
FieldTypeDescription
grant_idstringThe Alter Vault identifier for this grant. Server SDK methods accept it as grantId.
providerstringProvider technical ID.
provider_namestringProvider display name. Defaults to provider if the result omits it.
account_identifierstringIdentifier for the provider account. Defaults to an empty string if the result omits it.
timestampstringISO 8601 timestamp. The SDK supplies the current time if the result omits it.
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. Defaults to an empty array.
status"active" | "pending" | "error"Grant status at the moment the flow completed. Defaults to "active".
metadataobject?Optional extras preserved when a success payload supplies them. The current hosted success message omits this field. Treat unknown keys as advisory.

metadata is optional, and the current hosted Connect callback does not supply 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, unknown>;
failedGrants?: ConnectFailedGrant[];
}
FieldTypeDescription
codestringStable, machine-readable error code. See the table below for the codes emitted by the Connect SDK.
messagestringHuman-readable summary. Treat it as display text rather than a control-flow key.
detailsRecord<string, unknown>?Additional context when supplied by the failure payload.
failedGrantsConnectFailedGrant[]?Present on a total usage-limit application failure.
CodeDeliveryCause
invalid_optionsRejected open() promisetoken was not a non-empty string or onSuccess was not a function.
sdk_destroyedRejected open() promise, or thrown by another lifecycle methodopen(), close(), on(), off(), or isOpen() was called after destroy().
popup_blockedonError and error eventThe browser blocked the desktop popup.
redirect_erroronError and error eventThe mobile branch could not save redirect state to sessionStorage.
redirect_state_missingerror eventA full-page redirect came back carrying Alter Connect callback parameters, but no matching flow state exists on this origin. Almost always a return URL on a different origin than the page that called open() — browsers scope the flow’s session storage to one origin, so the callback cannot be completed where it landed.
invalid_oauth_urlonError and error eventThe SDK could not derive a trusted origin from the launch URL. This is a defensive path because supported configuration uses the fixed Alter host.
invalid_responseonError and error eventA success message omitted the grants array, supplied an empty result, or carried malformed grant or failure data.
grant_policy_application_failedonError and error eventEvery resulting grant was rejected because the selected usage limits could not be applied. The error carries failedGrants.

An error posted by the hosted callback keeps its server-supplied code; do not assume the list of those codes is closed. Invalid or expired sessions detected while the hosted page binds or loads are rendered in that page and are not reliable onError callbacks. Use backend session polling when every terminal state must be recovered.

The browser package does not export exception classes. Server SDK classes include ReAuthRequiredError, NoDelegatedGrantError, GrantNotFoundError, CredentialRevokedError, and the headless-flow ConnectFlowError family (ConnectDeniedError, ConnectConfigError, ConnectTimeoutError). See the Errors reference.

One provider result that was not retained because the selected usage limits could not be applied.

interface ConnectFailedGrant {
providerId: string;
reason: string;
message: string;
}

Unknown reason strings are preserved.

The second argument passed to onSuccess.

interface ConnectCompletion {
grants: Grant[];
failedGrants: ConnectFailedGrant[];
}

grants is the same retained-grants result represented by the first callback argument. failedGrants is empty for a full success and populated for a partial completion. A total failure is delivered to onError instead.

The argument to alterConnect.open().

interface OpenOptions {
token: string;
onSuccess: (grants: Grant[], completion: ConnectCompletion) => void;
onExit?: () => void;
onError?: (error: AlterError) => void;
onEvent?: (
eventName: string,
metadata: Record<string, unknown>,
) => void;
}
FieldTypeRequiredDescription
tokenstringyesSession token minted on the application backend via app.createConnectSession(). Short-lived (10-minute default).
onSuccess(grants: Grant[], completion: ConnectCompletion) => voidyesFires when a popup flow retains at least one grant.
onExit() => voidnoFires when the user closes the popup without finishing. Does not fire on the mobile redirect flow or mark the backend session denied.
onError(error: AlterError) => voidnoFires for failures delivered to the browser SDK. Hosted-page-only failures require backend polling.
onEvent(eventName: string, metadata: Record<string, unknown>) => voidnoAnalytics hook. The SDK emits exactly one event today — see Events & callbacks.

See the full open() reference for launch-time rejection semantics and the mobile redirect limitation.

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 and unsupported — passing any value throws at construction. Omit the field.

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 obtained separately. The Connect SDK itself does not return Provider objects.

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

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.