import { Helpers } from './helpers'; import { LogInstance } from 'larvitutils'; import { UserBase } from './userBase'; import { Users, UsersOptions } from './users'; export { Users } from './users'; export { UserBase } from './userBase'; export type UserLibOptions = { db: any; log?: LogInstance; }; export type HistoricFieldData = { fieldData: string; timestamp: string; }; export declare class UserLib { helpers: Helpers; private dataWriter; private log; private lUtils; private options; constructor(options: UserLibOptions); runDbMigrations(scriptPath?: string): Promise; /** * Add a single user field to database * * @param {string} userUuid - * @param {string} fieldName - * @param {string} fieldValue - * @returns {Promise} - */ addUserDataField(userUuid: string, fieldName: string, fieldValue: string | string[]): Promise; /** * Add user fields * * @param {string} userUuid - * @param {object} fields - field name as key, field values as array to that key - ex: {'role': ['admin','user']} * @returns {Promise} - */ addUserDataFields(userUuid: string, fields: Record): Promise; /** * Checks a password for validity * @param {string} password - plain text password * @param {string} hash - hash to check password against * @param {Promise} - True if password matches */ checkPassword(password: string, hash: string): Promise; /** * Creates a new user (and adds to it to db) * * @param {string} username - * @param {string} password (plain text) or false for no password (user will not be able to login at all) * @param {object} userFields - key, value pairs, where value can be an array of values * @param {string} uuid - if not supplied a random will be generated * @returns {Promise} - The newly created user */ create(username: string, password: string | boolean, userFields?: Record, uuid?: string): Promise; /** * Checks if a unsername is available * * @param {string} username - * @returns {Promise} - */ usernameAvailable(username: string): Promise; /** * Create a user object from a field * IMPORTANT! Only fetches first matching user! * * @param {string} fieldName - * @param {string} fieldValue - * @returns {Promise} - "user" being a new user object or boolean false on failed search */ fromField(fieldName: string, fieldValue: string): Promise; /** * Create a user object from fields * IMPORTANT! Only fetches first matching user that matches all fields! * * @param {object} fields - {'fieldName': 'fieldValue', 'fieldName2': 'fieldValue2'} * @returns {Promise} - "user" being a new user object or boolean false on failed search */ fromFields(fields: Record): Promise; /** * Create a user object from username and password * * @param {string} username - * @param {string} password - * @returns {Promise} - "user" being a new user object or boolean false on failed login */ fromUserAndPass(username: string, password: string): Promise; /** * Create a user object from username * * @param {string} username - * @returns {Promise} - "user" being a new user object */ fromUsername(username: string): Promise; /** * Verify that a user exists in the database * * @param {string} userUuid - User UUID to check * @returns {Promise} - True if user exists, false if not */ userExists(userUuid: string): Promise; /** * Instanciate user object from user id * * @param {number} userUuid - * @param {boolean} includeInactive - If true, will also load inactive users * @returns {Promise} userObj will be false if no user is found */ fromUuid(userUuid: string, includeInactive?: boolean): Promise; /** * Get historic field data from user id * * @param {number} userUuid - * @param {date} [start] - Date object - Will show all historic changes if omitted. Will show all historic changes from start until now if used without end * @param {date} [end] - Date object - Must be used together with start * @returns {Promise} Historic field changes, will be false if no user is found */ getHistoricFieldDataFromUuid(userUuid: string, start?: Date, end?: Date): Promise | false>; /** * Remove historic field data * * @param {string} timestamp - Timestamp - Removes history up until this point in time. If omitted, all historic field data will be removed. * @returns {Promise} - */ rmHistoricFieldData(timestamp?: string): Promise; /** * Get field data for a user * * @param {string} userUuid - * @param {string} fieldName - * @returns {Promise} data is always an array of data (or empty array) */ getFieldData(userUuid: string, fieldName: string): Promise; /** * Hashes a new password * * @param {string} password - * @returns {Promise} Hashed password */ hashPassword(password: string): Promise; /** * Replace all fields * IMPORTANT!!! Will clear all data not given in the fields parameter * * @param {string} userUuid - * @param {object} fields - field name as key, field values as array to that key - ex: {'role': ['admin','user']} * @returns {Promise} - */ replaceUserFields(userUuid: string, fields: Record): Promise; /** * Remove a user * * @param {string} userUuid - * @returns {Promise} - */ rmUser(userUuid: string): Promise; /** * Remove a user field * * @param {string} userUuid - * @param {string} fieldName - * @returns {Promise} - */ rmUserField(userUuid: string, fieldName: string): Promise; /** * Set password for a user * * @param {string} userUuid - * @param {string} newPassword (plain text) or false for no valid password (user will not be able to login at all) * @returns {Promise} - */ setPassword(userUuid: string, newPassword: string | boolean): Promise; /** * Set the username for a user * * @param {string} userUuid - * @param {string} newUsername - * @returns {Promise} - */ setUsername(userUuid: string, newUsername: string): Promise; /** * Set inactive for a user * * @param {string} userUuid - * @param {string} newInactive - * @returns {Promise} - */ setInactive(userUuid: string, newInactive: boolean): Promise; getUsers(options?: Omit): ReturnType; } //# sourceMappingURL=index.d.ts.map