@zerobounce/zero-bounce-sdk 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,7 +37,7 @@ const zeroBounce = new ZeroBounceSDK();
37
37
  Initialize the sdk with your api key:
38
38
 
39
39
  ```javascript
40
- zeroBounce.init("<YOUR_API_KEY>");
40
+ zeroBounce.init("<YOUR_API_KEY>", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
41
41
  ```
42
42
 
43
43
  NOTE: all the methods are asynchronous they have to be used with async / await or .then.catch
@@ -252,29 +252,66 @@ try {
252
252
  console.error(error);
253
253
  }
254
254
  ```
255
- - ##### Email finder - Test a variety of patterns and combinations in real time until it identifies a valid business email.
255
+
256
+ - ####### Email finder - Test a variety of patterns and combinations in real time until it identifies a valid business email.
256
257
 
257
258
  ```javascript
258
259
  // Parameters
259
260
  // ----------
260
261
  // domain: String
261
262
  // The email domain for which to find the email format.
262
- // first_name: String or null (Optional)
263
+ // company_name: String
264
+ // The company name for which to find the email format.
265
+ // first_name: String
263
266
  // The first name of the person whose email format is being searched.
264
267
  // middle_name: String or null (Optional)
265
268
  // The middle name of the person whose email format is being searched.
266
269
  // last_name: String or null (Optional)
267
270
  // The last name of the person whose email format is being searched.
268
271
 
269
- const payload = {
272
+ const domainPayload = {
270
273
  domain: "<DOMAIN>",
271
274
  first_name: "<FIRST_NAME>",
272
275
  middle_name: "<MIDDLE_NAME>",
273
276
  last_name: "<LAST_NAME>"
274
277
  }
275
278
 
279
+ const companyNamePayload = {
280
+ company_name: "<COMPANY_NAME>",
281
+ first_name: "<FIRST_NAME>",
282
+ middle_name: "<MIDDLE_NAME>",
283
+ last_name: "<LAST_NAME>"
284
+ }
285
+
286
+ try {
287
+ const domainResponse = await zeroBounce.findEmailByDomain(domainPayload);
288
+ const companyNameResponse = await zeroBounce.findEmailByCompanyName(companyNamePayload);
289
+ } catch (error) {
290
+ console.error(error);
291
+ }
292
+ ```
293
+
294
+ - ####### Domain Search - Find the domain based on a given domain name or company name
295
+
296
+ ```javascript
297
+ // Parameters
298
+ // ----------
299
+ // domain: String
300
+ // The domain name for which to find the email format.
301
+ // company_name: String
302
+ // The company name for which to find the email format.
303
+
304
+ const domainPayload = {
305
+ domain: "<DOMAIN>"
306
+ }
307
+
308
+ const companyNamePayload = {
309
+ company_name: "<COMPANY_NAME>"
310
+ }
311
+
276
312
  try {
277
- const response = await zeroBounce.guessFormat(payload);
313
+ const domainResponse = await zeroBounce.findEmailFormatByDomain(domainPayload);
314
+ const companyNameResponse = await zeroBounce.findEmailFormatByCompanyName(companyNamePayload);
278
315
  } catch (error) {
279
316
  console.error(error);
280
317
  }
package/documentation.md CHANGED
@@ -31,10 +31,10 @@ const ZeroBounceSDK = require('@zerobounce/zero-bounce-sdk')
31
31
  const zeroBounce = new ZeroBounceSDK();
32
32
  ```
33
33
 
34
- Initialize the sdk with your api key:
34
+ Initialize the sdk with your api key and your preferred api:
35
35
 
36
36
  ```javascript
37
- zeroBounce.init("<YOUR_API_KEY>");
37
+ zeroBounce.init("<YOUR_API_KEY>", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
38
38
  ```
39
39
 
40
40
  NOTE: all the methods are asynchronous they have to be used with async / await or .then.catch
@@ -257,22 +257,58 @@ try {
257
257
  // ----------
258
258
  // domain: String
259
259
  // The email domain for which to find the email format.
260
- // first_name: String or null (Optional)
260
+ // company_name: String
261
+ // The company name for which to find the email format.
262
+ // first_name: String
261
263
  // The first name of the person whose email format is being searched.
262
264
  // middle_name: String or null (Optional)
263
265
  // The middle name of the person whose email format is being searched.
264
266
  // last_name: String or null (Optional)
265
267
  // The last name of the person whose email format is being searched.
266
268
 
267
- const payload = {
269
+ const domainPayload = {
268
270
  domain: "<DOMAIN>",
269
271
  first_name: "<FIRST_NAME>",
270
272
  middle_name: "<MIDDLE_NAME>",
271
273
  last_name: "<LAST_NAME>"
272
274
  }
273
275
 
276
+ const companyNamePayload = {
277
+ company_name: "<COMPANY_NAME>",
278
+ first_name: "<FIRST_NAME>",
279
+ middle_name: "<MIDDLE_NAME>",
280
+ last_name: "<LAST_NAME>"
281
+ }
282
+
283
+ try {
284
+ const domainResponse = await zeroBounce.findEmailByDomain(domainPayload);
285
+ const companyNameResponse = await zeroBounce.findEmailByCompanyName(companyNamePayload);
286
+ } catch (error) {
287
+ console.error(error);
288
+ }
289
+ ```
290
+
291
+ - ####### Domain Search - Find the domain based on a given domain name or company name
292
+
293
+ ```javascript
294
+ // Parameters
295
+ // ----------
296
+ // domain: String
297
+ // The domain name for which to find the email format.
298
+ // company_name: String
299
+ // The company name for which to find the email format.
300
+
301
+ const domainPayload = {
302
+ domain: "<DOMAIN>"
303
+ }
304
+
305
+ const companyNamePayload = {
306
+ company_name: "<COMPANY_NAME>"
307
+ }
308
+
274
309
  try {
275
- const response = await zeroBounce.guessFormat(payload);
310
+ const domainResponse = await zeroBounce.findEmailFormatByDomain(domainPayload);
311
+ const companyNameResponse = await zeroBounce.findEmailFormatByCompanyName(companyNamePayload);
276
312
  } catch (error) {
277
313
  console.error(error);
278
314
  }
@@ -31,10 +31,10 @@ const ZeroBounceSDK = require('zero-bounce-sdk')
31
31
  const zeroBounce = new ZeroBounceSDK();
32
32
  ```
33
33
 
34
- Inicialice el SDK con su clave de API:
34
+ Inicialice el SDK con su clave de API y tu API preferida:
35
35
 
36
36
  ```javascript
37
- zeroBounce.init("<SU_CLAVE_DE_API>");
37
+ zeroBounce.init("<SU_CLAVE_DE_API>", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
38
38
  ```
39
39
 
40
40
  NOTA: todos los métodos son asíncronos y deben usarse con async / await o .then.catch.
@@ -254,6 +254,71 @@ try {
254
254
  }
255
255
  ```
256
256
 
257
+ - ####### Buscador de correos electrónicos: prueba una variedad de patrones y combinaciones en tiempo real hasta que identifique un correo electrónico comercial válido.
258
+
259
+ ```javascript
260
+ // Parameters
261
+ // ----------
262
+ // domain: String
263
+ // El dominio de correo electrónico para el que se debe buscar el formato de correo electrónico.
264
+ // company_name: String
265
+ // El nombre de la empresa para la que se busca el formato de correo electrónico.
266
+ // first_name: String
267
+ // El nombre de la persona cuyo formato de correo electrónico se está buscando.
268
+ // middle_name: String or null (Optional)
269
+ // El segundo nombre de la persona cuyo formato de correo electrónico se está buscando.
270
+ // last_name: String or null (Optional)
271
+ // El apellido de la persona cuyo formato de correo electrónico se está buscando.
272
+
273
+ const domainPayload = {
274
+ domain: "<DOMAIN>",
275
+ first_name: "<FIRST_NAME>",
276
+ middle_name: "<MIDDLE_NAME>",
277
+ last_name: "<LAST_NAME>"
278
+ }
279
+
280
+ const companyNamePayload = {
281
+ company_name: "<COMPANY_NAME>",
282
+ first_name: "<FIRST_NAME>",
283
+ middle_name: "<MIDDLE_NAME>",
284
+ last_name: "<LAST_NAME>"
285
+ }
286
+
287
+ try {
288
+ const domainResponse = await zeroBounce.findEmailByDomain(domainPayload);
289
+ const companyNameResponse = await zeroBounce.findEmailByCompanyName(companyNamePayload);
290
+ } catch (error) {
291
+ console.error(error);
292
+ }
293
+ ```
294
+
295
+ - ####### Búsqueda de dominios: encuentre el dominio basado en un nombre de dominio o nombre de empresa determinados.
296
+
297
+ ```javascript
298
+ // Parameters
299
+ // ----------
300
+ // domain: String
301
+ // El nombre de dominio para el que se busca el formato de correo electrónico.
302
+ // company_name: String
303
+ // El nombre de la empresa para la que se debe buscar el formato de correo electrónico.
304
+
305
+ const domainPayload = {
306
+ domain: "<DOMAIN>"
307
+ }
308
+
309
+ const companyNamePayload = {
310
+ company_name: "<COMPANY_NAME>"
311
+ }
312
+
313
+ try {
314
+ const domainResponse = await zeroBounce.findEmailFormatByDomain(domainPayload);
315
+ const companyNameResponse = await zeroBounce.findEmailFormatByCompanyName(companyNamePayload);
316
+ } catch (error) {
317
+ console.error(error);
318
+ }
319
+ ```
320
+
321
+
257
322
  **Puede utilizar cualquiera de las siguientes direcciones de correo electrónico para probar la API, no se cobran créditos por estas direcciones de correo electrónico de prueba:**
258
323
 
259
324
  - disposable@example.com
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerobounce/zero-bounce-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "This SDK contains methods for interacting easily with ZeroBounce API. More information about ZeroBounce you can find in the official documentation.",
5
5
  "main": "dist/zeroBounceSDK.js",
6
6
  "scripts": {
package/src/utils.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // Constants
2
- export const API_BASE_URL = "https://api.zerobounce.net/v2";
3
2
  export const API_BULK_BASE_URL = "https://bulkapi.zerobounce.net/v2";
4
3
  export const HEADERS = {
5
4
  Accept: "*/*",
@@ -15,9 +14,10 @@ export async function createRequest({
15
14
  batch = false,
16
15
  returnText = false,
17
16
  scoring = false,
17
+ apiBaseURL
18
18
  }) {
19
19
  const url = `${
20
- batch ? API_BULK_BASE_URL : API_BASE_URL
20
+ batch ? API_BULK_BASE_URL : apiBaseURL
21
21
  }${path}?${new URLSearchParams(params)}`;
22
22
 
23
23
  try {
@@ -1,19 +1,28 @@
1
1
  import { createRequest, notInitialized, parameterIsMissing } from "./utils.js";
2
2
 
3
3
  export class ZeroBounceSDK {
4
+ static ApiURL = Object.freeze({
5
+ DEFAULT_API_URL: "https://api.zerobounce.net/v2",
6
+ USA_API_URL: "https://api-us.zerobounce.net/v2",
7
+ EU_API_URL: "https://api-eu.zerobounce.net/v2"
8
+ });
9
+
4
10
  constructor() {
5
11
  this._initialized = false;
6
12
  this._api_key = null;
13
+ this._api_base_url = ZeroBounceSDK.ApiURL.DEFAULT_API_URL;
7
14
  }
8
15
 
9
16
  /**
10
17
  * @param apiKey - your private API key
18
+ * @param apiBaseURL - your preferred API, possible values being ApiURL.DEFAULT_API_URL, ApiURL.USAAPIURL, ApiURL.EUAPIURL
11
19
  * */
12
- init(apiKey) {
20
+ init(apiKey, apiBaseURL = ZeroBounceSDK.ApiURL.DEFAULT_API_URL) {
13
21
  if (!apiKey) {
14
22
  parameterIsMissing("Api key", "Please provide a valid API key.");
15
23
  } else {
16
24
  this._api_key = apiKey;
25
+ this._api_base_url = apiBaseURL;
17
26
  this._initialized = true;
18
27
  }
19
28
  }
@@ -26,7 +35,7 @@ export class ZeroBounceSDK {
26
35
  const params = {
27
36
  api_key: this._api_key,
28
37
  };
29
- return createRequest({ requestType: "GET", params, path: "/getcredits" });
38
+ return createRequest({ requestType: "GET", params, path: "/getcredits", apiBaseURL: this._api_base_url });
30
39
  }
31
40
 
32
41
  /**
@@ -46,7 +55,7 @@ export class ZeroBounceSDK {
46
55
  email: email,
47
56
  ip_address,
48
57
  };
49
- return createRequest({ requestType: "GET", params, path: "/validate" });
58
+ return createRequest({ requestType: "GET", params, path: "/validate", apiBaseURL: this._api_base_url });
50
59
  }
51
60
 
52
61
  /**
@@ -73,7 +82,8 @@ export class ZeroBounceSDK {
73
82
  return createRequest({
74
83
  requestType: "GET",
75
84
  params,
76
- path: "/getapiusage",
85
+ path: "/getapiusage",
86
+ apiBaseURL: this._api_base_url
77
87
  });
78
88
  }
79
89
 
@@ -98,7 +108,8 @@ export class ZeroBounceSDK {
98
108
  requestType: "POST",
99
109
  path: "/validatebatch",
100
110
  body: JSON.stringify(body),
101
- batch: true,
111
+ batch: true,
112
+ apiBaseURL: this._api_base_url
102
113
  });
103
114
  }
104
115
 
@@ -120,7 +131,8 @@ export class ZeroBounceSDK {
120
131
  return createRequest({
121
132
  requestType: "GET",
122
133
  params,
123
- path: "/activity",
134
+ path: "/activity",
135
+ apiBaseURL: this._api_base_url
124
136
  });
125
137
  }
126
138
 
@@ -184,7 +196,8 @@ export class ZeroBounceSDK {
184
196
  requestType: "POST",
185
197
  path: "/sendfile",
186
198
  body,
187
- batch: true,
199
+ batch: true,
200
+ apiBaseURL: this._api_base_url
188
201
  });
189
202
  }
190
203
 
@@ -229,7 +242,8 @@ export class ZeroBounceSDK {
229
242
  requestType: "POST",
230
243
  path: "/scoring/sendfile",
231
244
  body,
232
- batch: true,
245
+ batch: true,
246
+ apiBaseURL: this._api_base_url
233
247
  });
234
248
  }
235
249
 
@@ -251,6 +265,7 @@ export class ZeroBounceSDK {
251
265
  params,
252
266
  path,
253
267
  batch: true,
268
+ apiBaseURL: this._api_base_url
254
269
  });
255
270
  }
256
271
 
@@ -286,7 +301,8 @@ export class ZeroBounceSDK {
286
301
  path,
287
302
  batch: true,
288
303
  returnText: true,
289
- scoring,
304
+ scoring,
305
+ apiBaseURL: this._api_base_url
290
306
  });
291
307
  }
292
308
 
@@ -321,7 +337,8 @@ export class ZeroBounceSDK {
321
337
  params,
322
338
  path,
323
339
  batch: true,
324
- scoring,
340
+ scoring,
341
+ apiBaseURL: this._api_base_url
325
342
  });
326
343
  }
327
344
 
@@ -342,6 +359,144 @@ export class ZeroBounceSDK {
342
359
  // EMAIL FINDER
343
360
 
344
361
  /**
362
+ * @param domain str - domain of the email address
363
+ * @param first_name str - first name
364
+ * @param middle_name str or null - middle name
365
+ * @param last_name str or null - last name
366
+ * */
367
+ findEmailByDomain({
368
+ domain,
369
+ first_name,
370
+ middle_name = null,
371
+ last_name = null
372
+ }) {
373
+ return this._findEmail({
374
+ domain: domain,
375
+ first_name: first_name,
376
+ middle_name: middle_name,
377
+ last_name: last_name
378
+ });
379
+ }
380
+
381
+ /**
382
+ * @param company_name str - company name of the email address
383
+ * @param first_name str - first name
384
+ * @param middle_name str or null - middle name
385
+ * @param last_name str or null - last name
386
+ * */
387
+ findEmailByCompanyName({
388
+ company_name,
389
+ first_name,
390
+ middle_name = null,
391
+ last_name = null
392
+ }) {
393
+ return this._findEmail({
394
+ company_name: company_name,
395
+ first_name: first_name,
396
+ middle_name: middle_name,
397
+ last_name: last_name
398
+ });
399
+ }
400
+
401
+ _findEmail({
402
+ domain = null,
403
+ company_name = null,
404
+ first_name,
405
+ middle_name = null,
406
+ last_name = null
407
+ }) {
408
+ if (!this._initialized) {
409
+ notInitialized();
410
+ return;
411
+ } else if (!domain && !company_name) {
412
+ parameterIsMissing("domain");
413
+ parameterIsMissing("company_name");
414
+ return;
415
+ } else if (!first_name) {
416
+ parameterIsMissing("first_name");
417
+ return;
418
+ }
419
+
420
+ const params = {
421
+ api_key: this._api_key,
422
+ first_name: first_name,
423
+ middle_name: middle_name,
424
+ last_name: last_name,
425
+ };
426
+
427
+ if (domain != null) {
428
+ params["domain"] = domain;
429
+ } else if (company_name != null) {
430
+ params["company_name"] = company_name;
431
+ }
432
+
433
+ return createRequest({
434
+ requestType: "GET",
435
+ params,
436
+ path: "/guessformat",
437
+ apiBaseURL: this._api_base_url
438
+ });
439
+ }
440
+
441
+
442
+ // DOMAIN SEARCH
443
+
444
+ /**
445
+ * @param domain str - domain name
446
+ * */
447
+ findEmailFormatByDomain({
448
+ domain
449
+ }) {
450
+ return this._findEmailFormat({
451
+ domain: domain
452
+ });
453
+ }
454
+
455
+ /**
456
+ * @param company_name str - company name
457
+ * */
458
+ findEmailFormatByCompanyName({
459
+ company_name
460
+ }) {
461
+ return this._findEmailFormat({
462
+ company_name: company_name
463
+ });
464
+ }
465
+
466
+ _findEmailFormat({
467
+ domain = null,
468
+ company_name = null
469
+ }) {
470
+ if (!this._initialized) {
471
+ notInitialized();
472
+ return;
473
+ } else if (!domain && !company_name) {
474
+ parameterIsMissing("domain");
475
+ parameterIsMissing("company_name");
476
+ return;
477
+ }
478
+
479
+ const params = {
480
+ api_key: this._api_key
481
+ };
482
+
483
+ if (domain != null) {
484
+ params["domain"] = domain;
485
+ } else if (company_name != null) {
486
+ params["company_name"] = company_name;
487
+ }
488
+
489
+ return createRequest({
490
+ requestType: "GET",
491
+ params,
492
+ path: "/guessformat",
493
+ apiBaseURL: this._api_base_url
494
+ });
495
+ }
496
+
497
+
498
+ /**
499
+ * @deprecated Use findEmail for Email Finder API, or findEmailFormat for Domain Search API.
345
500
  * @param domain str - domain of the email address
346
501
  * @param first_name str or null - first name
347
502
  * @param middle_name str or null - middle name
@@ -353,6 +508,7 @@ export class ZeroBounceSDK {
353
508
  middle_name = null,
354
509
  last_name = null
355
510
  }) {
511
+ console.warn("guessFormat() is deprecated. Use findEmail for Email Finder API, or findEmailFormat for Domain Search API.");
356
512
  if (!this._initialized) {
357
513
  notInitialized();
358
514
  return;
@@ -372,7 +528,8 @@ export class ZeroBounceSDK {
372
528
  return createRequest({
373
529
  requestType: "GET",
374
530
  params,
375
- path: "/guessformat",
531
+ path: "/guessformat",
532
+ apiBaseURL: this._api_base_url
376
533
  });
377
534
  }
378
535
  }
@@ -31,7 +31,7 @@ describe("ZeroBounceSDK", () => {
31
31
  });
32
32
 
33
33
  it("should return error response with invalid API key", async () => {
34
- zeroBounceSDK.init("invalid-api-key");
34
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
35
35
  try {
36
36
  await zeroBounceSDK.getCredits();
37
37
  } catch (error) {
@@ -49,7 +49,7 @@ describe("ZeroBounceSDK", () => {
49
49
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
50
50
  }));
51
51
 
52
- zeroBounceSDK.init("valid-api-key");
52
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
53
53
  const response = await zeroBounceSDK.getCredits();
54
54
  expect(response).toEqual(expectedResponse);
55
55
  });
@@ -66,7 +66,7 @@ describe("ZeroBounceSDK", () => {
66
66
  });
67
67
 
68
68
  it("should throw an error if stardDate is missing", async () => {
69
- zeroBounceSDK.init("valid-api-key");
69
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
70
70
  await zeroBounceSDK.getApiUsage(null, endDate);
71
71
  expect(console.error).toHaveBeenCalledWith(
72
72
  expect.stringContaining(missingParamMessage)
@@ -74,7 +74,7 @@ describe("ZeroBounceSDK", () => {
74
74
  });
75
75
 
76
76
  it("should throw an error if endDate is missing", async () => {
77
- zeroBounceSDK.init("valid-api-key");
77
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
78
78
  await zeroBounceSDK.getApiUsage(startDate, null);
79
79
  expect(console.error).toHaveBeenCalledWith(
80
80
  expect.stringContaining(missingParamMessage)
@@ -82,7 +82,7 @@ describe("ZeroBounceSDK", () => {
82
82
  });
83
83
 
84
84
  it("should return error response with invalid API key", async () => {
85
- zeroBounceSDK.init("invalid-api-key");
85
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
86
86
  try {
87
87
  await zeroBounceSDK.getApiUsage(startDate, endDate);
88
88
  } catch (error) {
@@ -120,6 +120,7 @@ describe("ZeroBounceSDK", () => {
120
120
  "sub_status_mailbox_quota_exceeded": 0,
121
121
  "sub_status_forcible_disconnect": 0,
122
122
  "sub_status_failed_smtp_connection": 0,
123
+ "sub_status_accept_all": 0,
123
124
  "sub_status_mx_forward": 0,
124
125
  "sub_status_alternate": 0,
125
126
  "sub_status_blocked": 0,
@@ -133,7 +134,7 @@ describe("ZeroBounceSDK", () => {
133
134
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
134
135
  }));
135
136
 
136
- zeroBounceSDK.init("valid-api-key");
137
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
137
138
  const response = await zeroBounceSDK.getApiUsage(startDate, endDate);
138
139
  expect(response).toEqual(expectedResponse);
139
140
  });
@@ -150,7 +151,7 @@ describe("ZeroBounceSDK", () => {
150
151
  });
151
152
 
152
153
  it("should throw an error if email is missing", async () => {
153
- zeroBounceSDK.init("valid-api-key");
154
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
154
155
  await zeroBounceSDK.validateEmail(null);
155
156
  expect(console.error).toHaveBeenCalledWith(
156
157
  expect.stringContaining(missingParamMessage)
@@ -158,7 +159,7 @@ describe("ZeroBounceSDK", () => {
158
159
  });
159
160
 
160
161
  it("should return error response with invalid API key", async () => {
161
- zeroBounceSDK.init("invalid-api-key");
162
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
162
163
  try {
163
164
  await zeroBounceSDK.validateEmail(email, ip_address);
164
165
  } catch (error) {
@@ -194,7 +195,7 @@ describe("ZeroBounceSDK", () => {
194
195
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
195
196
  }));
196
197
 
197
- zeroBounceSDK.init("valid-api-key");
198
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
198
199
  const response = await zeroBounceSDK.validateEmail(email, ip_address);
199
200
  expect(response).toEqual(expectedResponse);
200
201
  });
@@ -213,7 +214,7 @@ describe("ZeroBounceSDK", () => {
213
214
  });
214
215
 
215
216
  it("should throw an error if email list is missing", async () => {
216
- zeroBounceSDK.init("valid-api-key");
217
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
217
218
  await zeroBounceSDK.validateBatch(null);
218
219
  expect(console.error).toHaveBeenCalledWith(
219
220
  expect.stringContaining(missingParamMessage)
@@ -221,7 +222,7 @@ describe("ZeroBounceSDK", () => {
221
222
  });
222
223
 
223
224
  it("should return error response with invalid API key", async () => {
224
- zeroBounceSDK.init("invalid-api-key");
225
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
225
226
  try {
226
227
  await zeroBounceSDK.validateBatch(emailBatch);
227
228
  } catch (error) {
@@ -283,7 +284,7 @@ describe("ZeroBounceSDK", () => {
283
284
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
284
285
  }));
285
286
 
286
- zeroBounceSDK.init("valid-api-key");
287
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
287
288
  const response = await zeroBounceSDK.validateBatch(emailBatch);
288
289
  expect(response).toEqual(expectedResponse);
289
290
  });
@@ -299,7 +300,7 @@ describe("ZeroBounceSDK", () => {
299
300
  });
300
301
 
301
302
  it("should throw an error if email is missing", async () => {
302
- zeroBounceSDK.init("valid-api-key");
303
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
303
304
  await zeroBounceSDK.getEmailActivity(null);
304
305
  expect(console.error).toHaveBeenCalledWith(
305
306
  expect.stringContaining(missingParamMessage)
@@ -307,7 +308,7 @@ describe("ZeroBounceSDK", () => {
307
308
  });
308
309
 
309
310
  it("should return error response with invalid API key", async () => {
310
- zeroBounceSDK.init("invalid-api-key");
311
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
311
312
  try {
312
313
  await zeroBounceSDK.getEmailActivity(email);
313
314
  } catch (error) {
@@ -326,7 +327,7 @@ describe("ZeroBounceSDK", () => {
326
327
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
327
328
  }));
328
329
 
329
- zeroBounceSDK.init("valid-api-key");
330
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
330
331
  const response = await zeroBounceSDK.getEmailActivity(email);
331
332
  expect(response).toEqual(expectedResponse);
332
333
  });
@@ -352,7 +353,7 @@ describe("ZeroBounceSDK", () => {
352
353
  email_address_column: 1,
353
354
  };
354
355
 
355
- zeroBounceSDK.init("valid-api-key");
356
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
356
357
  await zeroBounceSDK.sendFile(payload);
357
358
  expect(console.error).toHaveBeenCalledWith(
358
359
  expect.stringContaining(missingParamMessage)
@@ -364,7 +365,7 @@ describe("ZeroBounceSDK", () => {
364
365
  file: file,
365
366
  };
366
367
 
367
- zeroBounceSDK.init("valid-api-key");
368
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
368
369
  await zeroBounceSDK.sendFile(payload);
369
370
  expect(console.error).toHaveBeenCalledWith(
370
371
  expect.stringContaining(missingParamMessage)
@@ -372,7 +373,7 @@ describe("ZeroBounceSDK", () => {
372
373
  });
373
374
 
374
375
  it("should return error response with invalid API key", async () => {
375
- zeroBounceSDK.init("invalid-api-key");
376
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
376
377
  const response = await zeroBounceSDK.sendFile(payload);
377
378
  expect(response).toEqual({
378
379
  "success": "False",
@@ -395,7 +396,7 @@ describe("ZeroBounceSDK", () => {
395
396
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
396
397
  }));
397
398
 
398
- zeroBounceSDK.init("valid-api-key");
399
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
399
400
  const response = await zeroBounceSDK.sendFile(payload);
400
401
  expect(response).toEqual(expectedResponse);
401
402
  });
@@ -421,7 +422,7 @@ describe("ZeroBounceSDK", () => {
421
422
  email_address_column: 1,
422
423
  };
423
424
 
424
- zeroBounceSDK.init("valid-api-key");
425
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
425
426
  await zeroBounceSDK.sendScoringFile(payload);
426
427
  expect(console.error).toHaveBeenCalledWith(
427
428
  expect.stringContaining(missingParamMessage)
@@ -433,7 +434,7 @@ describe("ZeroBounceSDK", () => {
433
434
  file: file,
434
435
  };
435
436
 
436
- zeroBounceSDK.init("valid-api-key");
437
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
437
438
  await zeroBounceSDK.sendScoringFile(payload);
438
439
  expect(console.error).toHaveBeenCalledWith(
439
440
  expect.stringContaining(missingParamMessage)
@@ -441,7 +442,7 @@ describe("ZeroBounceSDK", () => {
441
442
  });
442
443
 
443
444
  it("should return error response with invalid API key", async () => {
444
- zeroBounceSDK.init("invalid-api-key");
445
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
445
446
  const response = await zeroBounceSDK.sendScoringFile(payload);
446
447
  expect(response).toEqual({
447
448
  "success": "False",
@@ -464,7 +465,7 @@ describe("ZeroBounceSDK", () => {
464
465
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
465
466
  }));
466
467
 
467
- zeroBounceSDK.init("valid-api-key");
468
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
468
469
  const response = await zeroBounceSDK.sendScoringFile(payload);
469
470
  expect(response).toEqual(expectedResponse);
470
471
  });
@@ -480,7 +481,7 @@ describe("ZeroBounceSDK", () => {
480
481
  });
481
482
 
482
483
  it("should throw an error if file id is missing", async () => {
483
- zeroBounceSDK.init("valid-api-key");
484
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
484
485
  await zeroBounceSDK.getFileStatus(null);
485
486
  expect(console.error).toHaveBeenCalledWith(
486
487
  expect.stringContaining(missingParamMessage)
@@ -488,7 +489,7 @@ describe("ZeroBounceSDK", () => {
488
489
  });
489
490
 
490
491
  it("should return error response with invalid API key", async () => {
491
- zeroBounceSDK.init("invalid-api-key");
492
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
492
493
  try {
493
494
  await zeroBounceSDK.getFileStatus(fileId);
494
495
  } catch (error) {
@@ -513,7 +514,7 @@ describe("ZeroBounceSDK", () => {
513
514
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
514
515
  }));
515
516
 
516
- zeroBounceSDK.init("valid-api-key");
517
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
517
518
  const response = await zeroBounceSDK.getFileStatus(fileId);
518
519
  expect(response).toEqual(expectedResponse);
519
520
  });
@@ -529,7 +530,7 @@ describe("ZeroBounceSDK", () => {
529
530
  });
530
531
 
531
532
  it("should throw an error if file id is missing", async () => {
532
- zeroBounceSDK.init("valid-api-key");
533
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
533
534
  await zeroBounceSDK.getScoringFileStatus(null);
534
535
  expect(console.error).toHaveBeenCalledWith(
535
536
  expect.stringContaining(missingParamMessage)
@@ -537,7 +538,7 @@ describe("ZeroBounceSDK", () => {
537
538
  });
538
539
 
539
540
  it("should return error response with invalid API key", async () => {
540
- zeroBounceSDK.init("invalid-api-key");
541
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
541
542
  try {
542
543
  await zeroBounceSDK.getScoringFileStatus(fileId);
543
544
  } catch (error) {
@@ -561,7 +562,7 @@ describe("ZeroBounceSDK", () => {
561
562
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
562
563
  }));
563
564
 
564
- zeroBounceSDK.init("valid-api-key");
565
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
565
566
  const response = await zeroBounceSDK.getScoringFileStatus(fileId);
566
567
  expect(response).toEqual(expectedResponse);
567
568
  });
@@ -577,7 +578,7 @@ describe("ZeroBounceSDK", () => {
577
578
  });
578
579
 
579
580
  it("should throw an error if file id is missing", async () => {
580
- zeroBounceSDK.init("valid-api-key");
581
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
581
582
  await zeroBounceSDK.getFile(null);
582
583
  expect(console.error).toHaveBeenCalledWith(
583
584
  expect.stringContaining(missingParamMessage)
@@ -585,7 +586,7 @@ describe("ZeroBounceSDK", () => {
585
586
  });
586
587
 
587
588
  it("should return error response with invalid API key", async () => {
588
- zeroBounceSDK.init("invalid-api-key");
589
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
589
590
  try {
590
591
  await zeroBounceSDK.getFile(fileId);
591
592
  } catch (error) {
@@ -600,7 +601,7 @@ describe("ZeroBounceSDK", () => {
600
601
  return Promise.resolve(expectedResponse);
601
602
  });
602
603
 
603
- zeroBounceSDK.init("valid-api-key");
604
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
604
605
  const response = await zeroBounceSDK.getFile(fileId);
605
606
  expect(createRequestSpy.mock.calls[0][0]["returnText"]).toEqual(true);
606
607
  expect(response).toEqual(expectedResponse);
@@ -617,7 +618,7 @@ describe("ZeroBounceSDK", () => {
617
618
  });
618
619
 
619
620
  it("should throw an error if file id is missing", async () => {
620
- zeroBounceSDK.init("valid-api-key");
621
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
621
622
  await zeroBounceSDK.getScoringFile(null);
622
623
  expect(console.error).toHaveBeenCalledWith(
623
624
  expect.stringContaining(missingParamMessage)
@@ -625,7 +626,7 @@ describe("ZeroBounceSDK", () => {
625
626
  });
626
627
 
627
628
  it("should return error response with invalid API key", async () => {
628
- zeroBounceSDK.init("invalid-api-key");
629
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
629
630
  try {
630
631
  await zeroBounceSDK.getScoringFile(fileId);
631
632
  } catch (error) {
@@ -640,7 +641,7 @@ describe("ZeroBounceSDK", () => {
640
641
  return Promise.resolve(expectedResponse);
641
642
  });
642
643
 
643
- zeroBounceSDK.init("valid-api-key");
644
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
644
645
  const response = await zeroBounceSDK.getScoringFile(fileId);
645
646
  expect(createRequestSpy.mock.calls[0][0]["returnText"]).toEqual(true);
646
647
  expect(response).toEqual(expectedResponse);
@@ -657,7 +658,7 @@ describe("ZeroBounceSDK", () => {
657
658
  });
658
659
 
659
660
  it("should throw an error if file id is missing", async () => {
660
- zeroBounceSDK.init("valid-api-key");
661
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
661
662
  await zeroBounceSDK.deleteFile(null);
662
663
  expect(console.error).toHaveBeenCalledWith(
663
664
  expect.stringContaining(missingParamMessage)
@@ -665,7 +666,7 @@ describe("ZeroBounceSDK", () => {
665
666
  });
666
667
 
667
668
  it("should return error response with invalid API key", async () => {
668
- zeroBounceSDK.init("invalid-api-key");
669
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
669
670
  try {
670
671
  await zeroBounceSDK.deleteFile(fileId);
671
672
  } catch (error) {
@@ -686,7 +687,7 @@ describe("ZeroBounceSDK", () => {
686
687
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
687
688
  }));
688
689
 
689
- zeroBounceSDK.init("valid-api-key");
690
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
690
691
  const response = await zeroBounceSDK.deleteFile(fileId);
691
692
  expect(response).toEqual(expectedResponse);
692
693
  });
@@ -702,7 +703,7 @@ describe("ZeroBounceSDK", () => {
702
703
  });
703
704
 
704
705
  it("should throw an error if file id is missing", async () => {
705
- zeroBounceSDK.init("valid-api-key");
706
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
706
707
  await zeroBounceSDK.deleteScoringFile(null);
707
708
  expect(console.error).toHaveBeenCalledWith(
708
709
  expect.stringContaining(missingParamMessage)
@@ -710,7 +711,7 @@ describe("ZeroBounceSDK", () => {
710
711
  });
711
712
 
712
713
  it("should return error response with invalid API key", async () => {
713
- zeroBounceSDK.init("invalid-api-key");
714
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
714
715
  try {
715
716
  await zeroBounceSDK.deleteScoringFile(fileId);
716
717
  } catch (error) {
@@ -731,14 +732,14 @@ describe("ZeroBounceSDK", () => {
731
732
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
732
733
  }));
733
734
 
734
- zeroBounceSDK.init("valid-api-key");
735
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
735
736
  const response = await zeroBounceSDK.deleteScoringFile(fileId);
736
737
  expect(response).toEqual(expectedResponse);
737
738
  });
738
739
  });
739
740
 
740
741
  // EMAIL FINDER
741
- describe("guessFormat", () => {
742
+ describe("findEmail", () => {
742
743
  const payload = {
743
744
  domain: "example.com",
744
745
  first_name: "John",
@@ -746,22 +747,22 @@ describe("ZeroBounceSDK", () => {
746
747
  }
747
748
 
748
749
  it("should throw an error if not initialized", async () => {
749
- await zeroBounceSDK.guessFormat(payload);
750
+ await zeroBounceSDK.findEmailByDomain(payload);
750
751
  expect(console.error).toHaveBeenCalledWith(initErrorMessage);
751
752
  });
752
753
 
753
754
  it("should throw an error if domain is missing", async () => {
754
- zeroBounceSDK.init("valid-api-key");
755
- await zeroBounceSDK.guessFormat({domain: null});
755
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
756
+ await zeroBounceSDK.findEmailByDomain({domain: null});
756
757
  expect(console.error).toHaveBeenCalledWith(
757
758
  expect.stringContaining(missingParamMessage)
758
759
  );
759
760
  });
760
761
 
761
762
  it("should return error response with invalid API key", async () => {
762
- zeroBounceSDK.init("invalid-api-key");
763
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
763
764
  try {
764
- await zeroBounceSDK.guessFormat(payload);
765
+ await zeroBounceSDK.findEmailByDomain(payload);
765
766
  } catch (error) {
766
767
  expect(error.message).toEqual('TypeError: Network request failed');
767
768
  }
@@ -770,10 +771,59 @@ describe("ZeroBounceSDK", () => {
770
771
  it("should return the validated format data", async () => {
771
772
  const expectedResponse = {
772
773
  "email": "john.doe@example.com",
774
+ "email_confidence": "high",
773
775
  "domain": "",
776
+ "company_name": "",
777
+ "did_you_mean": "",
778
+ "failure_reason": ""
779
+ }
780
+
781
+ jest.spyOn(global, "fetch").mockImplementationOnce(() => Promise.resolve({
782
+ json: () => Promise.resolve(expectedResponse),
783
+ text: () => Promise.resolve(JSON.stringify(expectedResponse)),
784
+ }));
785
+
786
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
787
+ const response = await zeroBounceSDK.findEmailByDomain(payload);
788
+ expect(response).toEqual(expectedResponse);
789
+ });
790
+ });
791
+
792
+ // DOMAIN SEARCH
793
+ describe("findEmailFormat", () => {
794
+ const payload = {
795
+ domain: "example.com",
796
+ first_name: "John",
797
+ last_name: "Doe",
798
+ }
799
+
800
+ it("should throw an error if not initialized", async () => {
801
+ await zeroBounceSDK.findEmailFormatByDomain(payload);
802
+ expect(console.error).toHaveBeenCalledWith(initErrorMessage);
803
+ });
804
+
805
+ it("should throw an error if domain is missing", async () => {
806
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
807
+ await zeroBounceSDK.findEmailFormatByDomain({domain: null});
808
+ expect(console.error).toHaveBeenCalledWith(
809
+ expect.stringContaining(missingParamMessage)
810
+ );
811
+ });
812
+
813
+ it("should return error response with invalid API key", async () => {
814
+ zeroBounceSDK.init("invalid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
815
+ try {
816
+ await zeroBounceSDK.findEmailFormatByDomain(payload);
817
+ } catch (error) {
818
+ expect(error.message).toEqual('TypeError: Network request failed');
819
+ }
820
+ });
821
+
822
+ it("should return the validated format data", async () => {
823
+ const expectedResponse = {
824
+ "domain": "",
825
+ "company_name": "",
774
826
  "format": "first.last",
775
- "status": "valid",
776
- "sub_status": "",
777
827
  "confidence": "high",
778
828
  "did_you_mean": "",
779
829
  "failure_reason": "",
@@ -785,8 +835,8 @@ describe("ZeroBounceSDK", () => {
785
835
  text: () => Promise.resolve(JSON.stringify(expectedResponse)),
786
836
  }));
787
837
 
788
- zeroBounceSDK.init("valid-api-key");
789
- const response = await zeroBounceSDK.guessFormat(payload);
838
+ zeroBounceSDK.init("valid-api-key", ZeroBounceSDK.ApiURL.DEFAULT_API_URL);
839
+ const response = await zeroBounceSDK.findEmailFormatByDomain(payload);
790
840
  expect(response).toEqual(expectedResponse);
791
841
  });
792
842
  });