@espressif/rainmaker-base-cdf
    Preparing search index...

    Class ESPRMUser

    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.

    Index

    Constructors

    • Initializes the ESPRMUser instance and stores tokens in local storage.

      Parameters

      • tokens: UserTokensData

        Object containing the access token, id token, and refresh token.

      Returns ESPRMUser

    Properties

    eventCallbacks: EventCallbacks

    Event callbacks for user-specific events.

    userId: string

    User ID of the current user.

    Methods

    • Adds a new daylight-based automation trigger for particular nodes.

      Parameters

      Returns Promise<ESPAutomation>

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

    • 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.

    • Adds a weather-based automation trigger for specific nodes.

      Parameters

      Returns Promise<ESPAutomation>

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

    • 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.

    • Creates a new group with the specified parameters.

      Parameters

      • groupInfo: CreateGroupRequest

        The details of the group to be created, including name, node IDs, description, and other optional fields.

      Returns Promise<ESPRMGroup>

      A promise that resolves to an instance of the newly created ESPRMGroup.

    • Creates a platform endpoint for push notifications.

      Parameters

      Returns Promise<string>

      A promise resolving to the platform endpoint.

    • 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 a list of all automations with optional pagination.

      Returns Promise<ESPPaginatedAutomationsResponse>

      A promise that resolves to a paginated response containing automation data.

    • Fetches custom data associated with the current user. This method sends a request to fetch custom data associated with the currently logged-in user.

      Returns Promise<UserCustomDataResponse>

      A promise that resolves with the custom data associated with the user.

    • Retrieves the user's geographical coordinates from the custom data.

      Returns Promise<ESPGeoCoordinates>

      A promise that resolves to an ESPGeoCoordinates object containing the latitude and longitude.

      If the coordinates are not found in the custom data.

    • Retrieves a group by its ID.

      Parameters

      Returns Promise<ESPRMGroup>

      A promise that resolves to an instance of ESPRMGroup.

      ESPAPICallValidationError if the group ID is missing in the request parameters.

    • Retrieves a group by its name.

      Parameters

      Returns Promise<ESPRMGroup>

      A promise that resolves to an instance of ESPRMGroup.

      ESPAPICallValidationError if the group name is missing in the request parameters.

    • Retrieves a list of groups with optional filters and pagination.

      Parameters

      Returns Promise<ESPPaginatedGroupsResponse>

      A promise that resolves to a paginated response containing group data.

    • Parameters

      • Optionalcount: number

      Returns Promise<ESPGroupSharingResponse>

    • Fetches node sharing requests for the user with optional pagination.

      Parameters

      • OptionalpageCount: number

        The number of results to fetch per request. If not provided, the default value is used.

      Returns Promise<ESPNodeSharingResponse>

      A promise that resolves to a paginated response containing node sharing requests.

    • Parameters

      • nodeId: string

      Returns Promise<ESPRMNode>

    • Fetches a list of registered platform endpoints associated with the user.

      Returns Promise<ESPPlatformEndpoint[]>

      A promise that resolves to an array of ESPPlatformEndpoint instances.

    • Parameters

      • Optionalcount: number

      Returns Promise<ESPGroupSharingResponse>

    • Fetches node sharing invitations for the user with optional pagination.

      Parameters

      • OptionalresultCount: number

        The number of results to fetch per request. If not provided, the default value is used.

      Returns Promise<ESPNodeSharingResponse>

      A promise that resolves to a paginated response containing node sharing invitations.

    • 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.

    • Fetches user nodes with optional pagination.

      Parameters

      • OptionalresultCount: number

        An optional parameter to specify the number of results to retrieve. If not provided, all available results will be fetched.

      Returns Promise<ESPPaginatedNodesResponse>

      A promise that resolves to a paginated response containing the user nodes.

    • Retrieves user nodes based on the provided request parameters.

      Parameters

      Returns Promise<ESPPaginatedNodesResponse>

      A promise that resolves to a paginated response containing the user nodes.

    • 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 all callbacks for a specified event or all events.

      Parameters

      • Optionalevent: ESPRMEventType

        (Optional) The event for which to remove callbacks. If omitted, all callbacks for all events are removed.

      Returns void

    • 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.

    • Sends a request to initiate the account deletion process.

      Returns Promise<ESPAPIResponse>

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

    • Searches for ESP BLE devices with the given customer ID.

      Parameters

      • customerId: number

        The customer ID to search for.

      Returns Promise<ESPDevice[]>

      A promise that resolves to an array of ESPDevice instances.

    • Searches for ESP devices with the given prefix.

      Parameters

      • devicePrefix: string

        The prefix of the device name to search for.

      • transport: ESPTransport

      Returns Promise<ESPDevice[]>

      A promise that resolves to an array of ESPDevice instances.

    • Sets custom data associated with the current user. This method sends a request to set custom data for the currently logged-in user.

      Parameters

      • data: UserCustomDataRequest

        The custom data to be set for the user.

      Returns Promise<ESPAPIResponse>

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

    • Stores the user's geographical coordinates in the custom data.

      Parameters

      • geoCoordinates: ESPGeoCoordinates

        An object containing the latitude and longitude to be stored.

      Returns Promise<ESPAPIResponse>

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

    • Sets multiple parameters for the nodes.

      Parameters

      • payload: MultipleNodePayload[]

        The payload containing the parameters to be set for multiple nodes.

      Returns Promise<ESPAPIResponse>

      A promise that resolves to the API response.

    • 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.

    • Shares the specified groups with a user.

      Parameters

      Returns Promise<string>

      A promise that resolves to the request ID from the API.

    • Stop the search for ESP devices.

      Returns Promise<void>

    • 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.

    • Transfers the specified groups to another user.

      Parameters

      Returns Promise<string>

      A promise that resolves to the request ID from the API.

    • Triggers an event and executes all associated callback functions with the provided argument.

      Parameters

      • event: ESPRMEventType

        The event to trigger, represented by ESPRMEventType.

      • arg: any

        The argument to pass to the callback functions.

      Returns void

    • Unsubscribes a specific callback function from a specified event.

      Parameters

      • event: ESPRMEventType

        The event to unsubscribe from, represented by ESPRMEventType.

      • callback: Function

        The callback function to remove.

      Returns void

    • 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.