@mikkelscheike/email-provider-links
Version:
TypeScript library for email provider detection with 93 providers (207 domains), concurrent DNS resolution, optimized performance, 94.65% test coverage, and enterprise security for login and password reset flows
71 lines • 2.43 kB
JavaScript
;
/**
* Provider Data Schema
*
* This represents the compressed format for provider data
* designed to reduce file size and improve parsing performance.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TXT_PATTERN_COMPRESSION = void 0;
exports.compressTxtPattern = compressTxtPattern;
exports.decompressTxtPattern = decompressTxtPattern;
exports.validateProvider = validateProvider;
/**
* Common TXT pattern prefixes that can be compressed
*/
exports.TXT_PATTERN_COMPRESSION = {
'v=spf1 include:': 'spf:',
'v=spf1 ': 'spf1:',
'google-site-verification=': 'gsv:',
'MS=ms': 'ms',
'zoho-verification=': 'zv:',
'mailgun-verification=': 'mv:'
};
/**
* Compress TXT patterns by removing common prefixes
*/
function compressTxtPattern(pattern) {
for (const [prefix, compressed] of Object.entries(exports.TXT_PATTERN_COMPRESSION)) {
if (pattern.startsWith(prefix)) {
return compressed + pattern.substring(prefix.length);
}
}
return pattern;
}
/**
* Decompress TXT patterns by restoring prefixes
*/
function decompressTxtPattern(compressed) {
for (const [prefix, compressedPrefix] of Object.entries(exports.TXT_PATTERN_COMPRESSION)) {
if (compressed.startsWith(compressedPrefix)) {
return prefix + compressed.substring(compressedPrefix.length);
}
}
return compressed;
}
/**
* Validation schema for providers
*/
function validateProvider(provider) {
const errors = [];
if (!provider.id || typeof provider.id !== 'string') {
errors.push('Provider ID is required and must be a string');
}
if (!provider.companyProvider || typeof provider.companyProvider !== 'string') {
errors.push('Company provider is required and must be a string');
}
if (provider.loginUrl !== null && (typeof provider.loginUrl !== 'string' || !provider.loginUrl.startsWith('https://'))) {
errors.push('Login URL must be null or a string starting with HTTPS');
}
if (provider.domains && !Array.isArray(provider.domains)) {
errors.push('Domains must be an array');
}
if (provider.mx && !Array.isArray(provider.mx)) {
errors.push('MX patterns must be an array');
}
if (provider.txt && !Array.isArray(provider.txt)) {
errors.push('TXT patterns must be an array');
}
return errors;
}
//# sourceMappingURL=schema.js.map