fix(core): update
This commit is contained in:
parent
ff5ab4def0
commit
ee25cfc78f
10478
assets/domains.json
Normal file
10478
assets/domains.json
Normal file
File diff suppressed because it is too large
Load Diff
21
license
Normal file
21
license
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Lossless GmbH
|
||||
Copyright (c) Romain SIMON
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CON
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -2318,7 +2318,7 @@
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://verdaccio.lossless.one/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
},
|
||||
@ -3484,7 +3484,7 @@
|
||||
},
|
||||
"isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://verdaccio.lossless.one/isexe/-/isexe-2.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=",
|
||||
"dev": true
|
||||
},
|
||||
|
@ -24,7 +24,8 @@
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdns": "^4.0.3",
|
||||
"@pushrocks/smartfile": "^7.0.12",
|
||||
"@pushrocks/smartmustache": "^2.0.9"
|
||||
"@pushrocks/smartmustache": "^2.0.9",
|
||||
"@pushrocks/smartrequest": "^1.1.47"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
17
test/test.ts
17
test/test.ts
@ -10,6 +10,23 @@ tap.test('should create an instance of EmailAddressValidator', async () => {
|
||||
|
||||
tap.test('should validate an email', async () => {
|
||||
const result = await emailAddressValidatorInstance.validate('sandbox@bleu.de');
|
||||
expect(result.freemail).to.be.false;
|
||||
expect(result.disposable).to.be.false;
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('should recognize an email as freemail', async () => {
|
||||
const result = await emailAddressValidatorInstance.validate('sandbox@gmail.com');
|
||||
expect(result.freemail).to.be.true;
|
||||
expect(result.disposable).to.be.false;
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('should recognize an email as disposable', async () => {
|
||||
const result = await emailAddressValidatorInstance.validate('sandbox@gmx.de');
|
||||
expect(result.freemail).to.be.false;
|
||||
expect(result.disposable).to.be.true;
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('should create a SmartMail', async () => {
|
||||
|
@ -1,19 +1,58 @@
|
||||
import * as plugins from './smartmail.plugins';
|
||||
import * as paths from './smartmail.paths';
|
||||
|
||||
export interface IEmailValidationResult {
|
||||
valid: boolean;
|
||||
disposable: boolean;
|
||||
freemail: boolean;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export class EmailAddressValidator {
|
||||
public domainMap: { [key: string]: 'disposable' | 'freemail'};
|
||||
|
||||
public smartdns = new plugins.smartdns.Smartdns({});
|
||||
|
||||
public async validate(emailArg: string): Promise<IEmailValidationResult> {
|
||||
await this.fetchDomains();
|
||||
const emailArray = emailArg.split('@');
|
||||
const result = await this.smartdns.getRecord(emailArray[1], 'MX');
|
||||
// console.log(emailArray);
|
||||
// console.log(this.domainMap[emailArray[1]]);
|
||||
return {
|
||||
valid: !!result,
|
||||
reason: 'todo'
|
||||
reason: 'todo',
|
||||
disposable: this.domainMap[emailArray[1]] === 'disposable',
|
||||
freemail: this.domainMap[emailArray[1]] === 'freemail'
|
||||
};
|
||||
}
|
||||
|
||||
public async fetchDomains() {
|
||||
if (!this.domainMap) {
|
||||
const localFileString = plugins.smartfile.fs.toStringSync(
|
||||
plugins.path.join(paths.assetDir, 'domains.json')
|
||||
);
|
||||
const localFileObject = JSON.parse(localFileString);
|
||||
|
||||
|
||||
let onlineFileObject: any;
|
||||
try {
|
||||
onlineFileObject = (
|
||||
await plugins.smartrequest.getJson(
|
||||
'https://raw.githubusercontent.com/romainsimon/emailvalid/master/domains.json'
|
||||
)
|
||||
).body;
|
||||
this.domainMap = onlineFileObject;
|
||||
console.log(
|
||||
'smartmail EmailAddressValidator: Using online email list for email validation'
|
||||
);
|
||||
} catch (e) {
|
||||
this.domainMap = localFileObject;
|
||||
console.log(e);
|
||||
console.log(
|
||||
'smartmail EmailAddressValidator: Using local email list for email validation'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
4
ts/smartmail.paths.ts
Normal file
4
ts/smartmail.paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './smartmail.plugins';
|
||||
|
||||
export const packageDir = plugins.path.join(__dirname, '../');
|
||||
export const assetDir = plugins.path.join(packageDir, './assets');
|
@ -1,5 +1,14 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
};
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartdns from '@pushrocks/smartdns';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartmustache from '@pushrocks/smartmustache';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
|
||||
export { smartdns, smartfile, smartmustache };
|
||||
export { smartdns, smartfile, smartmustache, smartrequest };
|
||||
|
Loading…
Reference in New Issue
Block a user