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.
Signature
Section titled “Signature”AlterConnect.create(config?: AlterConnectConfig): AlterConnectParameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
config.debug | boolean | false | When true, the SDK logs lifecycle events to console.log under its SDK prefixes. Useful while integrating; leave off in production. |
config.baseURL | string | — | Reserved. Not yet supported. Passing any value throws at construction time. Omit the field. See the note below. |
Returns
Section titled “Returns”An AlterConnect instance. See open(), events, and the type reference for AlterConnectConfig.
Reusing the instance
Section titled “Reusing the instance”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 });});Instance lifecycle methods
Section titled “Instance lifecycle methods”These are housekeeping methods returned by create(). The interactive method, open(), has its own page.
close()
Section titled “close()”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();destroy()
Section titled “destroy()”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();isOpen()
Section titled “isOpen()”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()) { // ...}getVersion()
Section titled “getVersion()”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();