1 | const verifiers = {
|
2 | datavalidation: require('./verifiers/datavalidation'),
|
3 | neverbounce: require('./verifiers/neverbounce'),
|
4 | mailgun: require('./verifiers/mailgun')
|
5 | };
|
6 |
|
7 | function detectVerifier (env = {}, fallback = null) {
|
8 | if (env.DATAVALIDATION_API_KEY) {
|
9 | return 'datavalidation';
|
10 | }
|
11 |
|
12 | if (env.NEVERBOUNCE_API_KEY) {
|
13 | return 'neverbounce';
|
14 | }
|
15 |
|
16 | if (env.MAILGUN_API_KEY) {
|
17 | return 'mailgun';
|
18 | }
|
19 |
|
20 | return fallback;
|
21 | }
|
22 |
|
23 | function createVerifier (verifier, options = {}) {
|
24 | if (!verifier) {
|
25 | throw new Error('verifier is required');
|
26 | }
|
27 |
|
28 | if (!verifiers[verifier]) {
|
29 | throw new Error(`Unsupported verifier: ${verifier}`);
|
30 | }
|
31 |
|
32 | const config = {
|
33 | ...verifiers[verifier].DEFAULTS,
|
34 | ...options
|
35 | };
|
36 |
|
37 | if (!config.apiKey) {
|
38 | throw new Error('options.apiKey is required');
|
39 | }
|
40 |
|
41 | return verifiers[verifier](config);
|
42 | }
|
43 |
|
44 | module.exports = { verifiers, createVerifier, detectVerifier };
|