sense-js-sdk
    Preparing search index...

    Class SenseApiClient

    A client for interacting with the Sense API.

    Index

    Constructors

    Properties

    Event emitter for client events.

    SenseApiClientEventTypes for the possible events and their payloads.

    Accessors

    • get isAuthenticated(): boolean

      Returns whether the client currently has an active session.

      Returns boolean

      True if the client has an active session, false otherwise.

    Methods

    • Completes a multi-factor authentication (MFA) login flow with the Sense API.

      Parameters

      • mfaToken: string

        The MFA token received from the initial login attempt.

      • oneTimePassword: string

        The one-time password (OTP) code for MFA verification.

      • clientDate: Date

        The current date/time on the client device for time synchronization.

      Returns Promise<void>

      SenseApiError If the MFA authentication fails.

    • Retrieves all devices detected by a specific Sense monitor.

      Parameters

      • monitorId: number

        The ID of the Sense monitor to get devices for.

      Returns Promise<Device[]>

      A promise that resolves to an array of Device objects representing the detected devices.

      SenseApiError If the API request fails.

      UnauthenticatedError If there is no valid session.

    • Retrieves historical trend data for a Sense monitor.

      Parameters

      • monitorId: number

        The ID of the Sense monitor to get trends for.

      • timezone: string

        The timezone to use for date calculations, in IANA format (e.g. 'America/New_York'). This should correspond to the timezone of the monitor, as found in the Monitor object returned by getMonitorOverview.

      • scale: TrendScale

        The time scale for which to retrieve trends (e.g. DAY, WEEK, MONTH, YEAR, CYCLE).

      • OptionalstartDate: Date

        Optional start date to retrieve trends from. If not provided, trends will start from the current date.

      Returns Promise<Trends>

      A promise that resolves to a Trends object containing the trend data.

      SenseApiError If the API request fails.

      UnauthenticatedError If there is no valid session.

    • Authenticates a user with the Sense API using email and password credentials.

      Parameters

      • emailAddress: string

        The email address of the user attempting to authenticate.

      • password: string

        The password of the user attempting to authenticate.

      Returns Promise<undefined | string>

      A promise that resolves to an MFA token if multi-factor authentication is required, or undefined if authentication is successful without MFA.

      This method will:

      • Clear any existing session
      • Attempt to authenticate with the provided credentials
      • Handle MFA requirements if needed
      • Create a new session if authentication is successful

      If this method returns a value, it indicates that multi-factor authentication is required. In this case, the returned MFA token should be used to complete the authentication process using the completeMfaLogin method.

      SenseApiError If authentication fails for reasons other than MFA being required.

    • Starts real-time updates for a monitor.

      Parameters

      • monitorId: number

        The ID of the monitor to start real-time updates for.

      Returns Promise<void>

      UnauthenticatedError If there is no valid session.