Skip to content

Reference

AlterConnect.create()

Construct an AlterConnect instance.

AlterConnect.create(config?) is the entry point. It returns a new, independent instance that can be reused across multiple open() calls.

import AlterConnect from "@alter-ai/connect";
const alterConnect = AlterConnect.create({ debug: true });

Importing the package does not access browser globals. Call create() only in a browser context: construction checks for a redirect result in sessionStorage.

AlterConnect.create(config?: AlterConnectConfig): AlterConnect
NameTypeDefaultDescription
config.debugbooleanfalseWhen true, the SDK logs lifecycle events to console.log under its SDK prefixes. Useful while integrating; leave off in production.
config.baseURLstringReserved. Not yet supported. Passing any value throws at construction time. Omit the field. See the note below.

An AlterConnect instance. See open(), events, and the type reference for AlterConnectConfig.

Calling create() once per application is the usual pattern, but separate calls return separate instances with independent state. Each instance keeps at most one flow open; a second open() call with valid options is a no-op while that instance remains open. Option validation still runs before the open-state check. The SDK does not focus the existing popup. Use isOpen() to check.

const alterConnect = AlterConnect.create();
const token = await fetchSessionToken();
button.disabled = false;
button.addEventListener("click", () => {
void alterConnect.open({ token, onSuccess, onError });
});

These are housekeeping methods returned by create(). The interactive method, open(), has its own page.

Close the popup if one exists, stop the current flow handler, remove callbacks registered by the current open() call, set isOpen() to false, and emit close. Long-lived listeners registered through on() remain in place.

alterConnect.close();

Tear down the instance. This closes an active popup, removes all registered listeners, and marks the instance as destroyed. Subsequent open(), close(), on(), off(), and isOpen() calls fail with code sdk_destroyed; repeated destroy() calls are no-ops. getVersion() remains available.

alterConnect.destroy();

Returns the SDK’s open-state flag. It becomes true when a launch starts and returns to false when close() runs. A manually closed popup resets it automatically only when the supplied onExit callback returns normally. If onExit is omitted or throws, call close() explicitly; another open() call remains a no-op while the flag is still true.

if (alterConnect.isOpen()) {
// ...
}

Returns the runtime version embedded in the bundle. Package 0.11.0 currently returns "0.2.0"; this method does not reflect the package metadata version.

alterConnect.getVersion();

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.