@avaya/infinity-agent-sdk - v1.0.0
    Preparing search index...

    Main entry point for the Avaya Infinity Agent SDK. AvayaInfinityAgentSdk is a static singleton class with all static methods. Call init once to authenticate and connect, then use the returned User object to manage agent state and interactions. Call destroy to tear everything down cleanly.

    The SDK transitions through the following states:

    UNINITIALIZED → INITIALIZING → INITIALIZED ⇄ FAILED → DESTROYING → UNINITIALIZED
    
    • UNINITIALIZED - initial state; init may be called
    • INITIALIZING - init is in progress; wait for the returned promise to resolve before calling any other SDK methods
    • INITIALIZED - fully operational; destroy may be called
    • FAILED - WebSocket connection lost after all reconnect attempts; retryWebSocketConnection or destroy may be called
    • DESTROYING - destroy is in progress

    Use sdkState to read the current state at any time.

    Subscribe via subscribe to react to state transitions:

    Event When fired
    SdkEventType.SDK_INITIALIZED init() completed successfully
    SdkEventType.INITIALIZATION_FAILED init() threw an error
    SdkEventType.SDK_DESTROYED destroy() completed
    SdkEventType.SESSION_DESTROYED Session was invalidated server-side; SDK self-destructs
    SdkEventType.TOKEN_REFRESH_FAILED OAuth token could not be refreshed; SDK self-destructs
    Index

    Connection

    • Manually triggers a WebSocket reconnection attempt, skipping any pending backoff delay.

      Valid in two situations:

      Returns void

      If the SDK is not initialized (code ASE-1015)

      If a manual retry is not allowed in the current state — e.g. a reconnection attempt is already actively in progress (code ASE-1014)

      // Skip backoff on each individual failed attempt
      AvayaInfinityAgentSdk.subscribe(
      WebSocketConnectionEventType.RECONNECTION_ATTEMPT_FAILED,
      () => {
      retryButton.disabled = false; // let the agent skip the wait
      }
      );

      // Also enable after all retries are exhausted
      AvayaInfinityAgentSdk.subscribe(
      WebSocketConnectionEventType.CONNECTION_FAILED,
      () => {
      retryButton.disabled = false;
      }
      );

      retryButton.addEventListener("click", () => {
      try {
      AvayaInfinityAgentSdk.retryWebSocketConnection();
      } catch (err) {
      console.error("Retry not available:", err);
      }
      });
    • get webSocketConnectionState(): WebSocketConnectionState

      The current WebSocket connection state.

      Reflects real-time connectivity between the SDK and the Avaya platform. Subscribe to WebSocketConnectionEventType events for change notifications rather than polling this property.

      Returns WebSocketConnectionState

      The current WebSocketConnectionState

      If the SDK is not in INITIALIZED or FAILED state (code ASE-1010)

      console.log("WebSocket state:", AvayaInfinityAgentSdk.webSocketConnectionState);
      // → "connected" | "reconnecting" | "failed" | ...

    Events

    • Subscribes to SDK events across all namespaces (sdk, user and all interactions).

      This is a universal event listener that fires for any matching event, whether the event originates from the SDK, the user, or an interaction. Can be called before init - subscribe first to catch lifecycle events such as SdkEventType.SDK_INITIALIZED.

      Type Parameters

      Parameters

      • eventName: T

        The event type to subscribe to

      • handler: AgentSdkEventHandler<T>

        Callback function invoked when the event occurs

      Returns string

      A handler ID that can be used to unsubscribe

      const handlerId = AvayaInfinityAgentSdk.subscribe(
      UserEventType.USER_STATUS_CHANGED,
      (event) => {
      console.log("Status changed:", event.payload.status);
      }
      );
    • Unsubscribes from a previously subscribed SDK event.

      Parameters

      Returns void

    Lifecycle

    • get version(): string

      The current Agent SDK version.

      Returns string

    • Exports the SDK's in-memory log buffer as a JSON Blob.

      The SDK continuously captures recent log entries (respecting the configured AvayaInfinityAgentSdkInitParams.logLevel) into a bounded in-memory ring buffer. This method returns a snapshot of that buffer wrapped in a versioned envelope, suitable for attaching to a support ticket.

      The returned Blob has MIME type application/json. The SDK does NOT trigger a download itself - the host application decides what to do with the Blob (e.g. URL.createObjectURL + anchor click, or merge with another log source). This makes it safe to call from embedded contexts (iframes, CRM connectors) that may block synthetic download clicks.

      This method is synchronous, side-effect-free, and never mutates the buffer - multiple calls return independent snapshots. It is callable across the entire SDK lifecycle, including before init and after destroy; the buffer is reset only on page reload.

      Returns Blob

      A Blob of type application/json containing the log export envelope

      const blob = AvayaInfinityAgentSdk.exportLogs();
      const url = URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.href = url;
      a.download = `avaya-sdk-logs-${new Date().toISOString().replace(/:/g, "-")}.json`;
      a.click();
      URL.revokeObjectURL(url);
      // Consume the export and append SDK entries to an existing log store.
      // exportLogs() is a non-destructive snapshot, so it is safe to call
      // repeatedly (e.g. each time a host log download is requested).
      const blob = AvayaInfinityAgentSdk.exportLogs();
      const exportData = JSON.parse(await blob.text()) as SdkLogExport;
      existingLogs.push(...exportData.entries); // existingLogs: SdkLogEntry[]
    • Sets the capacity (maximum number of entries) of the in-memory log buffer captured for exportLogs, and returns the effective capacity that took effect.

      The requested value is truncated to an integer and clamped to the range [100, 5000]. A non-finite request (NaN) falls back to the default of 2000; ±Infinity clamp to the range bounds. This method never throws for any numeric argument - out-of-range or non-integer inputs are adjusted (and a console warning is logged) rather than rejected. The returned number is the actual capacity after truncation, clamping, and fallback.

      Most-recent retention guarantee: when the new capacity is smaller than the current number of buffered entries, the most-recent entries are retained and the oldest are discarded. If you need older history, call exportLogs before reducing the capacity.

      Like exportLogs, this is callable across the entire SDK lifecycle - including before init and after destroy - because the buffer is decoupled from the SDK lifecycle and reset only on page reload. The buffer can also be sized at startup via AvayaInfinityAgentSdkInitParams.logBufferCapacity.

      Parameters

      • capacity: number

        The desired buffer capacity (entries). Truncated and clamped to [100, 5000].

      Returns number

      The effective capacity after truncation, clamping, and NaN fallback.

      // Increase capture depth during an active incident.
      const effective = AvayaInfinityAgentSdk.setLogBufferCapacity(5000);
      console.log("Log buffer now holds up to", effective, "entries");
    • Sets the active log level for the SDK. Affects all loggers created via LoggerFactory — including those already in use.

      Call this at any point in the SDK lifecycle (before init, after destroy, or while running). Useful for raising verbosity to LogLevel.DEBUG during a live incident and reverting once captured. The initial level can also be set at startup via AvayaInfinityAgentSdkInitParams.logLevel.

      Parameters

      Returns void

      If newLevel is not a valid LogLevel (code ASE-0004)

      AvayaInfinityAgentSdk.setLogLevel(LogLevel.DEBUG);
      
    • Handles the OAuth callback by extracting the authorization code from the current URL and posting it back to the opener window.

      Call this from a script on the page that the IdP redirects to after authentication (popup mode only).

      Returns void

      // In your custom callback page:
      AvayaInfinityAgentSdk.handleOAuthCallback();
    • Initialize the SDK and authenticate the agent.

      Performs authentication, establishes a connection with the server, and returns a User object representing the authenticated agent. The SDK transitions from UNINITIALIZED → INITIALIZING → INITIALIZED.

      Behavior depends on initParams.oAuthMode:

      • redirect (default): On first call, redirects the page to the IdP and returns a never-resolving promise. After the IdP redirects back, init() must be called again to complete authentication and return the User
      • popup: Opens the IdP login in a popup window. The promise resolves with the User after the popup completes authentication. Must be called within a user-gesture handler to avoid browser popup blockers

      On success, fires SdkEventType.SDK_INITIALIZED. On failure, fires SdkEventType.INITIALIZATION_FAILED and resets to UNINITIALIZED.

      Parameters

      Returns Promise<User>

      A promise that resolves to the authenticated User instance

      If initParams contains invalid or missing values (code ASE-0004)

      If the SDK is not in UNINITIALIZED state (code ASE-1010)

      If authentication fails or the WebSocket connection cannot be established

      // Redirect mode - call once on page load; will redirect if not yet authenticated
      const user = await AvayaInfinityAgentSdk.init({
      avayaInfinityHost: "api.avayacloud.com",
      clientId: "your-client-id",
      oAuthRedirectUri: window.location.origin,
      });
      console.log("Signed in as:", user.userFullName);
      // Popup mode - single call inside a click handler
      loginButton.addEventListener("click", async () => {
      const user = await AvayaInfinityAgentSdk.init({
      avayaInfinityHost: "api.avayacloud.com",
      clientId: "your-client-id",
      oAuthRedirectUri: "https://your-app.com/callback.html",
      oAuthMode: "popup",
      });
      console.log("Signed in as:", user.userFullName);
      });
    • Destroy the SDK instance and release all resources.

      Logs the agent out from the Avaya platform, closes the connection with the server, and clears all internal state. The SDK transitions from INITIALIZED (or FAILED) → DESTROYING → UNINITIALIZED.

      After this method resolves, init must be called again to use the SDK. On completion, fires SdkEventType.SDK_DESTROYED.

      Returns Promise<void>

      A promise that resolves when the SDK has been fully torn down

      If the SDK is not in INITIALIZED or FAILED state (code ASE-1010)

      await AvayaInfinityAgentSdk.destroy();
      console.log("SDK destroyed, state:", AvayaInfinityAgentSdk.sdkState);
      // → "UNINITIALIZED"
    • get sdkState(): SdkState

      Returns the current SdkState of the SDK.

      Use this to guard calls to init, destroy, or retryWebSocketConnection that are only valid in specific states.

      Returns SdkState

      The current SDK state

      if (AvayaInfinityAgentSdk.sdkState === SdkState.INITIALIZED) {
      await AvayaInfinityAgentSdk.destroy();
      }