The ESPRMUser class serves as the central interface for managing user-related operations within the ESP RainMaker SDK. It provides a comprehensive set of methods for:

  • Account Management: Retrieve user information, request and confirm account deletion, update user details, and configure Multi-Factor Authentication (MFA).
  • Group Management: Create, retrieve, share, and transfer groups, as well as manage group sharing requests.
  • Node Management: Fetch user nodes, get node details, manage node mappings, and handle node sharing requests.
  • Notification Management: Create platform endpoints for push notifications and manage endpoints.
  • Event Handling: Subscribe to and manage user-specific events.

By utilizing the ESPRMUser class, developers can seamlessly manage user sessions, interact with backend APIs, and handle complex user-related workflows.

Constructors

Properties

eventCallbacks: EventCallbacks = {}

Event callbacks for user-specific events.

userId: string

User ID of the current user.

Methods

  • Adds tags to the current user.

    This method sends a request to associate the provided tags with the currently logged-in user.

    Parameters

    • tags: string[]

      An array of strings representing the tags to be added.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse containing the result of the operation.

  • Changes the user's password by providing their old password and a new password.

    Parameters

    • oldPassword: string

      The user's current password.

    • newPassword: string

      The new password to set for the user.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success of the password change.

  • Cleans up resources associated with the user.

    This method retrieves the device token map from storage, deletes the endpoint associated with the user's device token, and clears all tokens from storage.

    Returns Promise<void>

    A promise that resolves when the resources are cleaned up.

  • Enables or disables multi-factor authentication (MFA) for the current user.

    Parameters

    • enabled: boolean

      A boolean indicating whether MFA should be enabled (true) or not (false).

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse object containing the result of the operation.

  • Confirms the account deletion request by providing a verification code.

    Parameters

    • verificationCode: string

      The verification code sent to the user for account deletion confirmation.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success of the account deletion confirmation.

  • Confirms the phone number associated with the user by providing a verification code.

    Parameters

    • verificationCode: string

      The verification code sent to the user for confirming the phone number.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success of the phone number confirmation.

  • Confirms the assignment of tags to the user by providing a verification code.

    Parameters

    • verificationCode: string

      The verification code for confirming the tag assignment.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success of the tag assignment confirmation.

  • Creates an ESP device with the given parameters.

    Parameters

    • name: string

      The name of the device.

    • transport: ESPTransport

      The transport type to use.

    • Optionalsecurity: ESPSecurity

      The security type to use (optional).

    • OptionalproofOfPossession: string

      The proof of possession string (optional).

    • OptionalsoftAPPassword: string

      The SoftAP password (optional).

    • Optionalusername: string

      The username (optional).

    Returns Promise<ESPDevice>

    A promise that resolves to an ESPDevice instance.

  • Deletes the custom data value associated with the specified key for the current user. This method sends a request to delete the custom data value for the given key associated with the currently logged-in user.

    Parameters

    • forKey: string

      The key for which the custom data value is to be deleted.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to a success response upon deleting the custom data.

  • Deletes the custom data entry associated with the specified key for the current user. This method sends a request to delete the custom data entry for the specified key associated with the currently logged-in user.

    Parameters

    • name: string

      The key of the custom data entry to be deleted.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success or failure of the operation.

  • Deletes the custom data pemissions associated with the specified key for the current user. This method sends a request to delete the custom data permissions for the given key associated with the currently logged-in user.

    Parameters

    • forKey: string

      The key for which the custom data permissions is to be deleted.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to a success response upon deleting the custom data permissions.

  • Deletes a platform endpoint associated with the specified device token or endpoint.

    Parameters

    • OptionaldeviceToken: string

      The mobile device token used for identifying the platform endpoint.

    • Optionalendpoint: string

      The unique endpoint identifier to delete.

    Returns Promise<ESPAPIResponse>

    A promise resolving to the API response, indicating success or failure.

    ESPAPICallValidationError - Throws an error if both deviceToken and endpoint are missing.

  • Retrieves an automation based on the provided automation ID.

    Parameters

    • automationId: string

      The ID of the automation to be fetched.

    Returns Promise<ESPAutomation>

    A promise that resolves to an ESPAutomation instance containing the automation details.

  • Retrieves user information, optionally including custom data.

    Parameters

    • OptionalwithCustomData: boolean

      Optional flag indicating whether to include custom data in the response. Defaults to false.

    Returns Promise<ESPRMUserInfo>

    A promise that resolves to an ESPRMUserInfo object containing the user information.

  • Logs out the current user, with an option to log out from all sessions.

    Parameters

    • OptionalshouldLogoutFromAllSessions: boolean

      Optional flag indicating whether to log out from all sessions. Defaults to false.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse object containing the result of the logout operation.

  • Removes tags to the current user.

    This method sends a request to remove the provided tags with the currently logged-in user.

    Parameters

    • tags: string[]

      An array of strings representing the tags to be removed.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse containing the result of the operation.

  • Updates the phone number associated with the current user.

    Parameters

    • phoneNumber: string

      The new phone number to be set for the user.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse object containing the result of the operation.

  • Set the timeZone for the user in the user's custom data.

    Parameters

    • timeZoneString: string

      The timeZone string to set.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse indicating the success of the operation.

  • Subscribes a callback function or an array of callback functions to a specified event.

    Parameters

    • event: ESPRMEventType

      The event to subscribe to, represented by ESPRMEventType.

    • callback: Function | Function[]

      The callback function or an array of callback functions to execute when the event is triggered.

    Returns void

    An error if the event type is invalid.

  • Updates the name associated with the current user.

    Parameters

    • newName: string

      The new name to be set for the user.

    Returns Promise<ESPAPIResponse>

    A promise that resolves to an ESPAPIResponse object containing the result of the operation.

  • Clears all tokens from memory and local storage.

    Returns void

  • Extends the session by exchanging the refresh token for a new access token and id token.

    Parameters

    • refreshToken: string

      The refresh token used to extend the session.

    Returns Promise<string>

    A promise that resolves to the new access token.

    Error if session extension fails.

  • Retrieves the current access token. If the access token is expired, it attempts to extend the session using the refresh token.

    Returns Promise<string>

    A promise that resolves to the access token or an empty string if no valid token is available.