Nymph.js 1.0.0-beta.113
    Preparing search index...

    A user data model.

    Written by Hunter Perrin for SciActive.

    Hunter Perrin [email protected]

    Hierarchy (View Summary)

    Index

    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.

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

    $originalUsername?: string

    Used to save the current username for domain admin permissions.

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

    $sleepingReference: EntityReference | null

    The reference to use to wake.

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

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

    cdate: number | null

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

    guid: string | null

    The entity's Globally Unique ID.

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

    mdate: number | null

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

    tags: string[]

    Array of the entity's tags.

    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.

    ETYPE: string = 'tilmeld_user'

    The instance of Tilmeld to use for queries.

    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 the user to a (secondary) group.

      Parameters

      Returns Promise<true | (Group & GroupData)[]>

      True if the user is already in the group. The resulting array of groups if the user was not.

    • Add one or more tags.

      Parameters

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

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

      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

    • Delete the object from storage.

      Returns Promise<boolean>

      True on success, false on failure.

    • Returns Promise<boolean>

    • Remove the user from a (secondary) group.

      Parameters

      Returns Promise<true | (Group & GroupData)[]>

      True if the user wasn't in the group. The resulting array of groups if the user was.

    • 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

      • Optionalability: string

        The ability.

      Returns Promise<boolean>

      True or false.

    • Returns (string | null)[] | null

    • Returns any

    • Returns (string | null)[] | null

    • Returns any

    • Returns (string | null)[] | null

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

      • OptionalincludeSData: boolean

        Whether to include the serialized data as well.

      • OptionalreferenceOnlyExisting: boolean

        Whether to only turn existing entities into references.

      Returns any

      The entity's data object.

    • Get the user's group descendants.

      Returns Promise<(Group & GroupData)[]>

    • Build a gatekeeper cache object.

      Returns Promise<{ [k: string]: true }>

    • Returns string | null

    • Returns string[] | null

    • Get a GUID for the entity.

      If the entity has already been saved, this will just return the GUID.

      If the entity has not yet been saved, this will return a new GUID that gets held by the entity. The guid property will remain null, but this method will then always return the same GUID. When the entity is eventually saved into the database, this GUID will be used.

      Returns string

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

    • Grant an ability.

      Parameters

      • ability: string

        The ability.

      Returns void

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

      Parameters

      • ...tags: string[]

        List of tags.

      Returns boolean

      True or false.

    • Returns Promise<boolean>

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

      • Optionalstrict: 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;
        }

      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.

    • Used to set the data.

      This should only be used by Nymph to push the data from storage or the client.

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

      If source is set to "server", the data is coming from the DB or the cache. If not, assume the data is coming from the client and can't be trusted.

      Parameters

      • data: EntityData

        The data object.

      • Optionalsdata: SerializedEntityData

        The serialized data object.

      • Optionalsource: "server"

        If this is set to "server", the data is coming from the DB.

      Returns void

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

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

    • Remove one or more tags.

      Parameters

      • ...tags: string[]

        List of tags.

      Returns void

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

      Parameters

      • Optionaldata: { code: string; password: string }

        The input data from the client.

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

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

    • Revoke an ability.

      Parameters

      • ability: string

        The ability.

      Returns void

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

      Parameters

      • data: { password: string }

        The input data from the client.

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

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

    • Save the object to storage.

      Returns Promise<boolean>

      True on success, false on failure.

    • This should never be accessible on the client.

      Returns Promise<boolean>

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

      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

      Returns void

    • Parameters

      • Optionaldata: { additionalData?: { [k: string]: any } }

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

    • Returns boolean

    • Returns boolean

    • Return a Nymph Entity Reference for this entity.

      If the entity hasn't been saved yet (and has no GUID), it will use the guaranteed GUID from $getGuaranteedGUID, unless existingOnly is true, then it will return the entity.

      Parameters

      • OptionalexistingOnly: boolean

        Whether to only turn existing entities into references.

      Returns User | EntityReference

      A Nymph Entity Reference array.

    • Update the data protection arrays for a user.

      Parameters

      • OptionalgivenUser: User & UserData

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

      Returns void

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

    • Parameters

      • returnObjectIfNotExist: true

      Returns User & UserData

    • Parameters

      • OptionalreturnObjectIfNotExist: false

      Returns User & UserData | null

    • 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
      • Optionalguid: string

        An optional GUID to retrieve.

      Returns Promise<E & EntityDataType<E>>

    • Parameters

      • Optionalusername: string

      Returns Promise<User & UserData>

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

    • Get the users in a domain. This is only accessible to the domain's admins.

      Parameters

      • domain: string
      • Optionaloptions: { limit?: number; offset?: number; reverse?: boolean; sort?: string }

      Returns Promise<(User & UserData)[]>

    • Get a string for full text search for one of an entity's properties.

      The result will be tokenized and stored as the full text search index for use with "search" clauses.

      Return null to not include any tokens in the full text search storage.

      You shouldn't use any other entity data to transform the text, as it won't always be available. This function is meant for things like stripping HTML tags.

      Parameters

      • name: string
      • value: any

      Returns string | null

      By default, returns the value if it is a string.

    • 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;
        }

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

    • Type Parameters

      Parameters

      • event: T
      • callback: T extends "checkUsername"
            ? TilmeldCheckUsernameCallback
            : T extends "beforeRegister"
                ? TilmeldBeforeRegisterCallback
                : T extends "afterRegister"
                    ? TilmeldAfterRegisterCallback
                    : T extends "beforeSave"
                        ? TilmeldBeforeSaveCallback
                        : T extends "afterSave"
                            ? TilmeldAfterSaveCallback
                            : T extends "beforeLogin"
                                ? TilmeldBeforeLoginCallback
                                : T extends "afterLogin"
                                    ? TilmeldAfterLoginCallback
                                    : T extends "beforeLogout"
                                        ? TilmeldBeforeLogoutCallback
                                        : T extends "afterLogout"
                                            ? TilmeldAfterLogoutCallback
                                            : T extends "beforeDelete"
                                                ? TilmeldBeforeDeleteCallback
                                                : (...) extends (...) ? (...) : (...)

      Returns boolean

    • Type Parameters

      Parameters

      • event: T
      • callback: T extends "checkUsername"
            ? TilmeldCheckUsernameCallback
            : T extends "beforeRegister"
                ? TilmeldBeforeRegisterCallback
                : T extends "afterRegister"
                    ? TilmeldAfterRegisterCallback
                    : T extends "beforeSave"
                        ? TilmeldBeforeSaveCallback
                        : T extends "afterSave"
                            ? TilmeldAfterSaveCallback
                            : T extends "beforeLogin"
                                ? TilmeldBeforeLoginCallback
                                : T extends "afterLogin"
                                    ? TilmeldAfterLoginCallback
                                    : T extends "beforeLogout"
                                        ? TilmeldBeforeLogoutCallback
                                        : T extends "afterLogout"
                                            ? TilmeldAfterLogoutCallback
                                            : T extends "beforeDelete"
                                                ? TilmeldBeforeDeleteCallback
                                                : (...) extends (...) ? (...) : (...)

      Returns () => boolean

    • Recover account details.

      Parameters

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

        The input data from the client.

      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.

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

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