UNPKG

idea-toolbox

Version:
46 lines (45 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Auth0User = void 0; const resource_model_1 = require("./resource.model"); const utils_1 = require("./utils"); /** * A user stored in a Auth0 User Pool. */ class Auth0User extends resource_model_1.Resource { constructor() { super(...arguments); /** * Whether the user is part of the administrators group. */ this.isAdmin = () => this.groups.includes('admins'); /** * Whether the user is part of the robots group. */ this.isRobot = () => this.groups.includes('robots'); } load(x) { this.userId = this.clean(x.userId || x.sub, String); this.email = this.clean(x.email, String); this.emailVerified = this.clean(x.emailVerified || x.email_verified, Boolean); this.name = this.clean(x.name, String); this.nickname = this.clean(x.nickname, String); this.picture = this.clean(x.picture, String); this.updatedAt = this.clean(x.updatedAt || x.updated_at, utils_1.toISOString); this.groups = this.cleanArray(x.groups, String); this.attributes = x.attributes ?? {}; this.preferences = x.preferences ?? {}; } /** * Check whether the user's attributes are valid. */ validate() { const e = []; if (this.iE(this.email, 'email')) e.push('email'); if (this.iE(this.name)) e.push('name'); return e; } } exports.Auth0User = Auth0User;