Updates
This commit is contained in:
+35
-52
@@ -1,55 +1,38 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = validateEmail;
|
||||
const handleNodemailer_1 = __importDefault(require("../../backend/handleNodemailer"));
|
||||
const email_mx_lookup_1 = __importDefault(require("../verification/email-mx-lookup"));
|
||||
const email_regex_test_1 = __importDefault(require("../verification/email-regex-test"));
|
||||
function validateEmail(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ email, welcomeEmailOptions, }) {
|
||||
var _b;
|
||||
if (!email) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email is required.",
|
||||
};
|
||||
}
|
||||
if (!(0, email_regex_test_1.default)(email)) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Invalid email format.",
|
||||
};
|
||||
}
|
||||
const checkEmailMxRecords = yield (0, email_mx_lookup_1.default)(email);
|
||||
if (!checkEmailMxRecords) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email domain does not have valid MX records.",
|
||||
};
|
||||
}
|
||||
if (welcomeEmailOptions) {
|
||||
const welcomeEmail = yield (0, handleNodemailer_1.default)(welcomeEmailOptions);
|
||||
if (!((_b = welcomeEmail === null || welcomeEmail === void 0 ? void 0 : welcomeEmail.accepted) === null || _b === void 0 ? void 0 : _b[0])) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email verification failed.",
|
||||
};
|
||||
}
|
||||
}
|
||||
import handleNodemailer from "../../backend/handleNodemailer";
|
||||
import emailMxLookup from "../verification/email-mx-lookup";
|
||||
import emailRegexCheck from "../verification/email-regex-test";
|
||||
export default async function validateEmail({ email, welcomeEmailOptions, }) {
|
||||
var _a;
|
||||
if (!email) {
|
||||
return {
|
||||
isValid: true,
|
||||
message: "Email is valid.",
|
||||
isValid: false,
|
||||
message: "Email is required.",
|
||||
};
|
||||
});
|
||||
}
|
||||
if (!emailRegexCheck(email)) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Invalid email format.",
|
||||
};
|
||||
}
|
||||
const checkEmailMxRecords = await emailMxLookup(email);
|
||||
if (!checkEmailMxRecords) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email domain does not have valid MX records.",
|
||||
};
|
||||
}
|
||||
if (welcomeEmailOptions) {
|
||||
const welcomeEmail = await handleNodemailer(welcomeEmailOptions);
|
||||
if (!((_a = welcomeEmail === null || welcomeEmail === void 0 ? void 0 : welcomeEmail.accepted) === null || _a === void 0 ? void 0 : _a[0])) {
|
||||
return {
|
||||
isValid: false,
|
||||
message: "Email verification failed.",
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
isValid: true,
|
||||
message: "Email is valid.",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user