"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidEmailAddress = exports.validateOrganizationEmailDomains = exports.isValidEmailDomain = exports.getEmailDomain = void 0;
const getEmailDomain = (email) => {
    if (/\s/.test(email)) {
        throw new Error(`Invalid email, contains whitespace: ${email}`);
    }
    const domains = email.split('@');
    if (domains.length !== 2 || !domains[1]) {
        throw new Error(`Invalid email: ${email}`);
    }
    return domains[1].toLowerCase();
};
exports.getEmailDomain = getEmailDomain;
const EMAIL_PROVIDER_LIST = [
    'gmail.com',
    'yahoo.com',
    'hotmail.com',
    'aol.com',
    'hotmail.co.uk',
    'hotmail.fr',
    'msn.com',
    'yahoo.fr',
    'wanadoo.fr',
    'orange.fr',
    'comcast.net',
    'yahoo.co.uk',
    'yahoo.com.br',
    'yahoo.co.in',
    'live.com',
    'rediffmail.com',
    'free.fr',
    'gmx.de',
    'web.de',
    'yandex.ru',
    'outlook.com',
    'uol.com.br',
    'bol.com.br',
    'mail.ru',
    'cox.net',
    'hotmail.it',
    'sbcglobal.net',
    'sfr.fr',
    'live.fr',
    'verizon.net',
    'live.co.uk',
    'googlemail.com',
    'yahoo.es',
    'ig.com.br',
    'live.nl',
    'bigpond.com',
    'terra.com.br',
    'yahoo.it',
    'yahoo.de',
    'rocketmail.com',
    'yahoo.in',
    'hotmail.es',
    'hotmail.de',
    'shaw.ca',
    'yahoo.co.jp',
    'sky.com',
    'blueyonder.co.uk',
    'icloud.com',
];
const isEmailProviderDomain = (domain) => EMAIL_PROVIDER_LIST.includes(domain);
const VALID_EMAIL_DOMAIN_REGEX = /^[a-zA-Z0-9][\w.-]+\.\w{2,4}/g;
const isValidEmailDomain = (value) => value.match(VALID_EMAIL_DOMAIN_REGEX);
exports.isValidEmailDomain = isValidEmailDomain;
const validateOrganizationEmailDomains = (domains) => {
    const invalidDomains = domains.filter((domain) => isEmailProviderDomain(domain));
    if (!invalidDomains.length) {
        return undefined;
    }
    const readableDomainList = new Intl.ListFormat('en-US', {
        style: 'long',
        type: 'conjunction',
    }).format(invalidDomains);
    return `${readableDomainList} ${invalidDomains.length === 1 ? 'is' : 'are'} not allowed as organization email(s)`;
};
exports.validateOrganizationEmailDomains = validateOrganizationEmailDomains;
const isValidEmailAddress = (email) => /^[\w.+'-]+@[\w-]+\.[A-Za-z]{2,}(?:\.[A-Za-z]{2,})*$/.test(email);
exports.isValidEmailAddress = isValidEmailAddress;
//# sourceMappingURL=email.js.map