configcat-common
Version:
ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.
94 lines • 5.85 kB
TypeScript
export declare type WellKnownUserObjectAttribute = "Identifier" | "Email" | "Country";
export declare type UserAttributeValue = string | number | Date | ReadonlyArray<string>;
/**
* 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 {
/** 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 | undefined;
/** Country of the user. */
country?: string | undefined;
/**
* 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: {
[key: string]: UserAttributeValue;
};
constructor(
/** 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 | undefined,
/** Country of the user. */
country?: string | undefined,
/**
* 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?: {
[key: string]: UserAttributeValue;
});
}
export declare function getUserAttribute(user: User, name: string): UserAttributeValue | null | undefined;
export declare function getUserAttributes(user: User): {
[key: string]: UserAttributeValue;
};
//# sourceMappingURL=User.d.ts.map