import type { ObjectMap } from "./Utils.js"; export type WellKnownUserObjectAttribute = "Identifier" | "Email" | "Country"; export type UserAttributeValue = string | number | Date | ReadonlyArray; /** * The interface of User Object. * Defines the user attributes which are used for evaluating targeting rules and percentage options. **/ export interface IUser { /** The unique identifier of the user or session (e.g. email address, primary key, session ID, etc.) */ identifier: string; /** Email address of the user. */ email?: string; /** Country of the user. */ country?: string; /** * Custom attributes of the user for advanced targeting rule definitions (e.g. user role, subscription type, etc.) * @remarks * All comparators support `string` values as User Object attribute (in some cases they need to be provided in a specific format though, see below), * but some of them also support other types of values. It depends on the comparator how the values will be handled. The following rules apply: * * **Text-based comparators** (EQUALS, IS ONE OF, etc.) * * accept `string` values, * * all other values are automatically converted to `string` (a warning will be logged but evaluation will continue as normal). * * **SemVer-based comparators** (IS ONE OF, <, >=, etc.) * * accept `string` values containing a properly formatted, valid semver value, * * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). * * **Number-based comparators** (=, <, >=, etc.) * * accept `number` values, * * accept `string` values containing a properly formatted, valid `number` value, * * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). * * **Date time-based comparators** (BEFORE / AFTER) * * accept `Date` values, which are automatically converted to a second-based Unix timestamp, * * accept `number` values representing a second-based Unix timestamp, * * accept `string` values containing a properly formatted, valid `number` value, * * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). * * **String array-based comparators** (ARRAY CONTAINS ANY OF / ARRAY NOT CONTAINS ANY OF) * * accept arrays of `string`, * * accept `string` values containing a valid JSON string which can be deserialized to an array of `string`, * * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped). **/ custom?: Record; } /** * User Object. * Contains user attributes which are used for evaluating targeting rules and percentage options. * @remarks * Please note that the `User` class is not designed to be used as a DTO (data transfer object). * (Since the type of the `custom` property is polymorphic, it's not guaranteed that deserializing * a serialized instance produces an instance with an identical or even valid data content.) **/ export declare class User implements IUser { identifier: string; email?: string | undefined; country?: string | undefined; custom: Record; constructor(identifier: string, email?: string | undefined, country?: string | undefined, custom?: Record); } export declare function getUserIdentifier(user: IUser): string; export declare function getUserAttribute(user: IUser, name: string): UserAttributeValue | null | undefined; export declare function getUserAttributes(user: IUser): ObjectMap;