UNPKG

@kilterset/auth0-actions-testing

Version:

Test and develop Auth0 Actions or Okta CIC Actions locally.

77 lines 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.user = void 0; const chance_1 = require("./chance"); const define_1 = require("./define"); const identity_1 = require("./identity"); exports.user = (0, define_1.define)(({ transientParams, params }) => { // If the key is present in the params, use that value. Otherwise, randomly // pick between a value and undefined. const perhapsFallback = (key, value) => params.hasOwnProperty(key) ? params[key] : chance_1.chance.pickone([undefined, value]); const includeFullName = params.given_name || params.family_name || transientParams.includeFullName; const given_name = params.given_name || chance_1.chance.first(); const family_name = params.family_name || chance_1.chance.last(); const potentialName = `${given_name} ${family_name}`; const name = includeFullName ? params.name || potentialName : chance_1.chance.pickone([undefined, potentialName]); let fullNameAttributes; if (includeFullName) { fullNameAttributes = { given_name, family_name, }; } const potentialUsername = [given_name, family_name] .map((part) => part.toLowerCase().replace(/[^a-z]/g, "")) .join("."); const username = perhapsFallback("username", potentialUsername); const email = params.hasOwnProperty("email") ? params.email : chance_1.chance.email(); const email_verified = email ? chance_1.chance.bool() : false; const identities = params.identities || [(0, identity_1.identity)()]; const firstIdentity = identities[0]; let user_id; if (firstIdentity) { user_id = `${firstIdentity.provider}|${firstIdentity.user_id}`; } else { user_id = `auth0|${chance_1.chance.hash({ length: 24 })}`; } // "By default, the local part of the user's email." const nickname = params.nickname || (email ? email.split("@")[0] : chance_1.chance.pickone([undefined, chance_1.chance.word()])); const [earliestDate, middleDate, latestDate] = chance_1.chance .n(chance_1.chance.date, 3) .sort() .map((date) => date.toISOString()); const created_at = earliestDate; const updated_at = latestDate; const last_password_reset = chance_1.chance.pickone([undefined, middleDate]); const phone_number = perhapsFallback("phone_number", chance_1.chance.phone()); const phone_verified = params.hasOwnProperty("phone_verified") ? params.phone_verified : phone_number ? chance_1.chance.bool() : undefined; const picture = perhapsFallback("picture", chance_1.chance.avatar({ protocol: "https", email })); return Object.assign(Object.assign({ user_id, username, name }, fullNameAttributes), { nickname, email, email_verified, phone_number, phone_verified, picture, app_metadata: {}, user_metadata: {}, created_at, updated_at, last_password_reset, identities }); }); //# sourceMappingURL=user.js.map