A user data model.

Written by Hunter Perrin for SciActive.

Author

Hunter Perrin [email protected]

Copyright

SciActive Inc

See

http://nymph.io/

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

$allowlistData?: string[] = ...

If this is defined, then it lists the only properties that will be accepted from incoming JSON. Any other properties will be ignored.

If you use an allowlist, you don't need to use protectedData, since you can simply leave those entries out of allowlistData.

$allowlistTags?: string[] = []

If this is defined, then it lists the only tags that will be accepted from incoming JSON. Any other tags will be ignored.

$clientEnabledMethods: string[] = ...

The names of methods allowed to be called by the frontend with serverCall.

$data: UserData

The data proxy object.

$dataHandler: Object

The data proxy handler.

$dataStore: UserData

The actual data store.

$descendantGroups?: (Group & GroupData)[]

The user's group descendants.

$gatekeeperCache?: {
    [k: string]: true;
}

Gatekeeper ability cache.

Gatekeeper will cache the user's abilities that it calculates, so it can check faster if that user has been checked before.

Type declaration

  • [k: string]: true
$isASleepingReference: boolean

Whether this instance is a sleeping reference.

$nymph: Nymph

The instance of Nymph to use for queries.

$originalEmail?: string

Used to save the current email address to send verification if it changes from the frontend.

If you are changing a user's email address and want to bypass email verification, don't set this.

$privateData: string[] = ...

Properties that will not be serialized into JSON with toJSON(). This can be considered a denylist, because these properties will not be set with incoming JSON.

Clients CAN still determine what is in these properties, unless they are also listed in searchRestrictedData.

$protectedData: string[]

Properties that can only be modified by server side code. They will still be visible on the frontend, unlike $privateData, but any changes to them that come from the frontend will be ignored.

In addition to what's listed here, all of the access control properties will be included when Tilmeld is being used. These are:

  • acUser
  • acGroup
  • acOther
  • acRead
  • acWrite
  • acFull
  • user
  • group

You should modify these through client enabled methods or the $save method instead, for safety.

$protectedTags: string[]

Tags that can only be added/removed by server side code. They will still be visible on the frontend, but any changes to them that come from the frontend will be ignored.

The actual sdata store.

$skipAcWhenSaving: boolean = false

This is explicitly used only during the registration proccess.

$sleepingReference: null | EntityReference

The reference to use to wake.

$wakePromise: null | Promise<Entity<UserData>>

A promise that resolved when the entity's data is wake.

cdate: null | number

The creation date of the entity as a Unix timestamp in milliseconds.

guid: null | string

The entity's Globally Unique ID.

This is a 12 byte number represented as a lower case HEX string (24 characters).

mdate: null | number

The modified date of the entity as a Unix timestamp in milliseconds.

tags: string[]

Array of the entity's tags.

DEFAULT_ALLOWLIST_DATA: string[] = []
DEFAULT_CLIENT_ENABLED_METHODS: string[] = ...
DEFAULT_PRIVATE_DATA: string[] = ...
ETYPE: string = 'tilmeld_user'

The instance of Tilmeld to use for queries.

afterLoginCallbacks: TilmeldAfterLoginCallback[] = []
afterLogoutCallbacks: TilmeldAfterLogoutCallback[] = []
afterRegisterCallbacks: TilmeldAfterRegisterCallback[] = []
beforeLoginCallbacks: TilmeldBeforeLoginCallback[] = []
beforeLogoutCallbacks: TilmeldBeforeLogoutCallback[] = []
beforeRegisterCallbacks: TilmeldBeforeRegisterCallback[] = []
checkUsernameCallbacks: TilmeldCheckUsernameCallback[] = []
class: string = 'User'

The lookup name for this entity.

This is used for reference arrays (and sleeping references) and client requests.

clientEnabledStaticMethods: string[] = ...

The names of static methods allowed to be called by the frontend with serverCallStatic.

nymph: Nymph

The instance of Nymph to use for queries.

pubSubEnabled: boolean

Whether this entity should publish changes to PubSub servers.

restEnabled: boolean

Whether this entity should be accessible on the frontend through the REST server.

If this is false, any request from the client that attempts to use this entity will fail.

searchRestrictedData: string[] = ...

Properties that will not be searchable from the frontend. If the frontend includes any of these properties in any of their clauses, they will be filtered out before the search is executed.

Methods

  • Add one or more tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns void

  • Search the array for this object and return the corresponding index.

    If strict is false, is() is used to compare. If strict is true, equals() is used.

    Parameters

    • array: any[]

      The array to search.

    • Optional strict: boolean

      Whether to use stronger comparison.

    Returns number

    The index if the object is in the array, -1 if it isn't.

  • Check if this is a sleeping reference.

    Returns boolean

  • A frontend accessible method to change the user's password.

    Parameters

    • data: {
          currentPassword: string;
          newPassword: string;
          revokeCurrentTokens?: boolean;
      }

      The input data from the client.

      • currentPassword: string
      • newPassword: string
      • Optional revokeCurrentTokens?: boolean

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Check if this is a sleeping reference and throw an error if so.

    Returns void

  • Check that an email is unique.

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Check the given password against the user's.

    Parameters

    • password: string

      The password in question.

    Returns boolean

    True if the passwords match, otherwise false.

  • Check that a phone number is unique.

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Check the given code against the user's TOTP secret.

    Parameters

    • code: string

      The code in question.

    Returns boolean

    True if the code is valid, otherwise false.

  • Check that a username is valid.

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Replace any referenced entities in the data with sleeping references.

    Calling this function ensures that the next time a referenced entity is accessed, it will be retrieved from the DB (unless it is in Nymph's cache).

    Returns void

  • Perform a more strict comparison of this object to another.

    Parameters

    • object: any

      The object to compare.

    Returns boolean

    True or false.

  • Check to see if a user has an ability.

    This function will check both user and group abilities, if the user is marked to inherit the abilities of its group.

    If ability is undefined, it will check to see if the user is currently logged in.

    If the user has the "system/admin" ability, this function will return true.

    Parameters

    • Optional ability: string

      The ability.

    Returns Promise<boolean>

    True or false.

  • Returns null | (null | string)[]

  • Returns null | string

  • Returns null | (null | string)[]

  • Returns null | string

  • Returns null | (null | string)[]

  • Get the client enabled methods.

    Returns string[]

    The names of methods allowed to be called by the frontend with serverCall.

  • Used to retrieve the data object.

    This should only be used by Nymph to save the data into storage.

    Parameters

    • Optional includeSData: boolean

      Whether to include the serialized data as well.

    Returns any

    The entity's data object.

  • Build a gatekeeper cache object.

    Returns Promise<{
        [k: string]: T;
    }>

  • A frontend accessible method to generate a new TOTP secret.

    Returns Promise<{
        qrcode: string;
        secret: string;
        uri: string;
    }>

    An object with 'uri', 'qrcode', and 'secret'.

  • Used to retrieve the serialized data object.

    This should only be used by Nymph to save the data object into storage.

    This method is used by Nymph to avoid unserializing data that hasn't been requested yet.

    It should always be called after getData().

    Returns SerializedEntityData

    The entity's serialized data object.

  • Get the entity's tags.

    Using this instead of accessing the tags prop directly will wake sleeping references.

    Returns string[]

    The entity's tags.

  • Get an array of strings that must be unique across the current etype.

    When you try to save another entity with any of the same unique strings, Nymph will throw an error.

    The default implementation of this method returns an empty array, meaning there are no uniqueness constraints applied to its etype.

    Returns Promise<string[]>

    Resolves to an array of entity's unique constraint strings.

  • Get an object that holds the same data as the entity.

    This provides an object that can be validated.

    Returns any

    A pure object representation of the entity.

  • Check that the entity has all of the given tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns boolean

    True or false.

  • Check whether this object is in an array.

    If strict is false, is() is used to compare. If strict is true, equals() is used.

    Parameters

    • array: any[]

      The array to search.

    • Optional strict: boolean

      Whether to use stronger comparison.

    Returns boolean

    True if the object is in the array, false if it isn't.

  • Check whether the user is in a (primary or secondary) group.

    Parameters

    Returns Promise<boolean>

    True or false.

  • Perform a less strict comparison of this object to another.

    Parameters

    • object: any

      The object to compare.

    Returns boolean

    True or false.

  • Check whether the user is a descendant of a group.

    Parameters

    Returns Promise<boolean>

    True or false.

  • Accept JSON data from the client.

    This function uses the security protection lists:

    • $protectedTags
    • $protectedData
    • $allowlistTags
    • $allowlistData

    Parameters

    • input: EntityJson

      The input data. Please note, this will be modified (destroyed).

    • allowConflict: boolean = false

      Allow to accept data that is older than the current data.

    Returns void

  • Accept JSON patch from the client.

    This function uses the security protection lists:

    • $protectedTags
    • $protectedData
    • $allowlistTags
    • $allowlistData

    Parameters

    • patch: EntityPatch

      The patch data. Please note, this will be modified (destroyed).

    • allowConflict: boolean = false

      Allow to accept data that is older than the current data.

    Returns void

  • Parameters

    • data: {
          additionalData?: {
              [k: string]: any;
          };
          code?: string;
          password: string;
          username: string;
      }
      • Optional additionalData?: {
            [k: string]: any;
        }
        • [k: string]: any
      • Optional code?: string
      • password: string
      • username: string

    Returns Promise<{
        message: string;
        needTOTP: boolean;
        result: boolean;
    } | {
        message: any;
        needTOTP?: undefined;
        result: boolean;
    }>

  • Log a user out of the system.

    Returns Promise<{
        message: any;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Change the user's password.

    Parameters

    • password: string

      The new password.

    Returns string

    The resulting password or hash which is stored in the entity.

  • Refresh the object from storage. (Bypasses Nymph's cache.)

    If the object has been deleted from storage, the database cannot be reached, or a database error occurs, refresh() will return 0.

    Returns Promise<boolean | 0>

    False if the data has not been saved, 0 if it can't be refreshed, true on success.

  • Parameters

    • data: {
          additionalData?: {
              [k: string]: any;
          };
          password: string;
      }
      • Optional additionalData?: {
            [k: string]: any;
        }
        • [k: string]: any
      • password: string

    Returns Promise<{
        loggedin: boolean;
        message: string;
        result: boolean;
    }>

  • A frontend accessible method to remove the TOTP secret from the user's account.

    Parameters

    • Optional data: {
          code: string;
          password: string;
      }

      The input data from the client.

      • code: string
      • password: string

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Remove one or more tags.

    Parameters

    • Rest ...tags: string[]

      List of tags.

    Returns void

  • A frontend accessible method to revoke all currently issued tokens.

    Parameters

    • data: {
          password: string;
      }

      The input data from the client.

      • password: string

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • A frontend accessible method to save a TOTP secret into the user's account.

    Parameters

    • data: {
          code: string;
          password: string;
          secret: string;
      }

      The input data from the client.

      • code: string
      • password: string
      • secret: string

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Send the user email verification/change/cancellation links.

    Returns Promise<boolean>

    True on success, false on failure.

  • Parameters

    • Optional data: {
          additionalData?: {
              [k: string]: any;
          };
      }
      • Optional additionalData?: {
            [k: string]: any;
        }
        • [k: string]: any

    Returns Promise<{
        message: any;
        result: boolean;
    }>

  • Return a Nymph Entity Reference for this entity.

    If the entity hasn't been saved yet (and has no GUID), it will be returned instead.

    Returns User | EntityReference

    A Nymph Entity Reference array as an unsaved entity.

  • Update the data protection arrays for a user.

    Parameters

    • Optional givenUser: User & UserData

      User to update protection for. If undefined, will use the currently logged in user.

    Returns void

  • Set whether to use "skipAc" when accessing entity references.

    Parameters

    • skipAc: boolean

      True or false, whether to use it.

    Returns void

  • Alter the options for a query for this entity.

    Type Parameters

    Parameters

    • options: T

      The current options.

    Returns T

    The altered options.

  • Create or retrieve a new entity instance.

    Note that this will always return an entity, even if the GUID is not found.

    Type Parameters

    Parameters

    • this: (new () => E)
        • new (): E
        • Returns E

    • Optional guid: string

      An optional GUID to retrieve.

    Returns Promise<E & EntityDataType<E>>

  • Create a new sleeping reference instance.

    Sleeping references won't retrieve their data from the database until they are readied with $wake() or a parent's $wakeAll().

    Type Parameters

    Parameters

    • this: (new () => E)
        • new (): E
        • Returns E

    • reference: EntityReference

      The Nymph Entity Reference to use to wake.

    Returns E & EntityDataType<E>

    The new instance.

  • Returns {
        allowRegistration: boolean;
        allowUsernameChange: boolean;
        emailUsernames: boolean;
        pwRecovery: boolean;
        regFields: string[];
        unverifiedAccess: boolean;
        userFields: string[];
        verifyEmail: boolean;
    }

    • allowRegistration: boolean
    • allowUsernameChange: boolean
    • emailUsernames: boolean
    • pwRecovery: boolean
    • regFields: string[]
    • unverifiedAccess: boolean
    • userFields: string[]
    • verifyEmail: boolean
  • Get an array of strings that must be unique across the current etype.

    When you try to save another entity with any of the same unique strings, Nymph will throw an error.

    The default implementation of this static method instantiates the entity, assigns all of the given data, then calls $getUniques and returns its output. This can have a performance impact if a lot of extra processing happens during any of these steps. You can override this method to calculate the unique strings faster, but you must return the same strings that would be returned by $getUniques.

    Parameters

    • __namedParameters: {
          cdate?: number;
          data: EntityData;
          guid?: string;
          mdate?: number;
          sdata?: SerializedEntityData;
          tags: string[];
      }

    Returns Promise<string[]>

    Resolves to an array of entity's unique constraint strings.

  • Parameters

    • data: {
          additionalData?: {
              [k: string]: any;
          };
          code?: string;
          password: string;
          username: string;
      }
      • Optional additionalData?: {
            [k: string]: any;
        }
        • [k: string]: any
      • Optional code?: string
      • password: string
      • username: string

    Returns Promise<{
        message: string;
        result: boolean;
        user?: User & UserData;
    }>

  • Recover account details.

    Parameters

    • data: {
          password: string;
          secret: string;
          username: string;
      }

      The input data from the client.

      • password: string
      • secret: string
      • username: string

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

  • Send an account recovery link.

    Parameters

    • data: {
          account: string;
          recoveryType: "password" | "username";
      }

      The input data from the client.

      • account: string
      • recoveryType: "password" | "username"

    Returns Promise<{
        message: string;
        result: boolean;
    }>

    An object with a boolean 'result' entry and a 'message' entry.

Generated using TypeDoc