UNPKG

@embrace-io/react-native

Version:
175 lines (174 loc) 7.16 kB
"use strict"; /** * User API * * This module provides methods to identify users and annotate sessions with user metadata. * User information is attached to sessions and can be used to search for and filter sessions * in the Embrace dashboard. * * @remarks * Consider privacy implications when setting user data. We recommend using anonymized * or hashed identifiers rather than personally identifiable information (PII). * * @see {@link https://embrace.io/docs/react-native/features/identify-users | Identify Users Documentation} */ Object.defineProperty(exports, "__esModule", { value: true }); exports.clearUserEmail = exports.setUserEmail = exports.clearUsername = exports.setUsername = exports.clearUserIdentifier = exports.setUserIdentifier = exports.clearAllUserPersonas = exports.clearUserPersona = exports.addUserPersona = void 0; const promiseHandler_1 = require("../utils/promiseHandler"); const EmbraceManagerModule_1 = require("../EmbraceManagerModule"); /** * Adds a custom persona tag to the current user. * * Personas allow you to categorize users into groups for filtering and analysis. * Multiple personas can be added to a single user. * * @param persona - A string tag to categorize the user (e.g., "premium_user", "beta_tester") * @returns A promise that resolves to `true` if the persona was successfully added, `false` otherwise * * @example * ```typescript * import { addUserPersona } from '@embrace-io/react-native'; * * // Tag user as a high-value customer * await addUserPersona('high_value_cart'); * ``` */ const addUserPersona = (persona) => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.addUserPersona(persona), "addUserPersona", false); exports.addUserPersona = addUserPersona; /** * Removes a specific persona tag from the current user. * * @param persona - The persona tag to remove * @returns A promise that resolves to `true` if the persona was successfully removed, `false` otherwise * * @example * ```typescript * import { clearUserPersona } from '@embrace-io/react-native'; * * await clearUserPersona('high_value_cart'); * ``` */ const clearUserPersona = (persona) => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.clearUserPersona(persona), "clearUserPersona", false); exports.clearUserPersona = clearUserPersona; /** * Removes all persona tags from the current user. * * @returns A promise that resolves to `true` if all personas were successfully cleared, `false` otherwise * * @example * ```typescript * import { clearAllUserPersonas } from '@embrace-io/react-native'; * * await clearAllUserPersonas(); * ``` */ const clearAllUserPersonas = () => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.clearAllUserPersonas(), "clearAllUserPersonas", false); exports.clearAllUserPersonas = clearAllUserPersonas; /** * Sets a unique identifier for the current user. * * This identifier is used to link sessions to a specific user and can be searched * for in the Embrace dashboard. All future sessions will be associated * with this identifier once set. * * @param userIdentifier - A unique identifier for the user (e.g., internal user ID, hashed email) * @returns A promise that resolves to `true` if the identifier was successfully set, `false` otherwise * * @example * ```typescript * import { setUserIdentifier } from '@embrace-io/react-native'; * * await setUserIdentifier('user_12345'); * ``` */ const setUserIdentifier = (userIdentifier) => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.setUserIdentifier(userIdentifier), "setUserIdentifier", false); exports.setUserIdentifier = setUserIdentifier; /** * Clears the current user identifier. * * Call this when a user logs out to stop associating sessions with the previous user. * * @returns A promise that resolves to `true` if the identifier was successfully cleared, `false` otherwise * * @example * ```typescript * import { clearUserIdentifier } from '@embrace-io/react-native'; * * // Call on logout * await clearUserIdentifier(); * ``` */ const clearUserIdentifier = () => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.clearUserIdentifier(), "clearUserIdentifier", false); exports.clearUserIdentifier = clearUserIdentifier; /** * Sets a username for the current user. * * The username is displayed in the Embrace dashboard and can help identify users * when debugging issues. * * Note: Be mindful of PII and privacy regulations when setting usernames. * We strongly recommend using anonymized or pseudonymous usernames where possible in combination with * setUserIdentifier for unique user identification. * * @param username - The username to associate with the current user * @returns A promise that resolves to `true` if the username was successfully set, `false` otherwise * * @example * ```typescript * import { setUsername } from '@embrace-io/react-native'; * * await setUsername('jane_doe'); * ``` */ const setUsername = (username) => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.setUsername(username), "setUsername", false); exports.setUsername = setUsername; /** * Clears the current user's username. * * @returns A promise that resolves to `true` if the username was successfully cleared, `false` otherwise * * @example * ```typescript * import { clearUsername } from '@embrace-io/react-native'; * * await clearUsername(); * ``` */ const clearUsername = () => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.clearUsername(), "clearUsername", false); exports.clearUsername = clearUsername; /** * Sets an email address for the current user. * * The email is displayed in the Embrace dashboard and can help identify users * when debugging issues or providing customer support. * * Note: Be mindful of PII and privacy regulations when setting user email addresses. * We strongly recommend using hashed or anonymized emails where possible in combination with * setUserIdentifier for unique user identification. * * @param userEmail - The email address to associate with the current user * @returns A promise that resolves to `true` if the email was successfully set, `false` otherwise * * @example * ```typescript * import { setUserEmail } from '@embrace-io/react-native'; * * await setUserEmail('jane@example.com'); * ``` */ const setUserEmail = (userEmail) => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.setUserEmail(userEmail), "setUserEmail", false); exports.setUserEmail = setUserEmail; /** * Clears the current user's email address. * * @returns A promise that resolves to `true` if the email was successfully cleared, `false` otherwise * * @example * ```typescript * import { clearUserEmail } from '@embrace-io/react-native'; * * await clearUserEmail(); * ``` */ const clearUserEmail = () => (0, promiseHandler_1.safePromise)(EmbraceManagerModule_1.EmbraceManagerModule.clearUserEmail(), "clearUserEmail", false); exports.clearUserEmail = clearUserEmail;