mailgun.js 3.5.9 → 3.7.1

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.
Files changed (75) hide show
  1. package/.eslintrc +27 -11
  2. package/CHANGELOG.md +30 -0
  3. package/commitlint.config.js +1 -2
  4. package/dist/index.d.ts +2 -2
  5. package/dist/lib/client.d.ts +2 -2
  6. package/dist/lib/events.d.ts +9 -25
  7. package/dist/lib/interfaces/APIErrorOptions.d.ts +2 -1
  8. package/dist/lib/interfaces/ApiResponse.d.ts +2 -1
  9. package/dist/lib/interfaces/Events.d.ts +24 -0
  10. package/dist/lib/interfaces/IFormData.d.ts +4 -12
  11. package/dist/lib/interfaces/IpPools.d.ts +12 -0
  12. package/dist/lib/interfaces/Options.d.ts +2 -1
  13. package/dist/lib/interfaces/RequestOptions.d.ts +2 -1
  14. package/dist/lib/interfaces/StatsOptions.d.ts +2 -1
  15. package/dist/lib/interfaces/mailListMembers.d.ts +6 -6
  16. package/dist/lib/ip-pools.d.ts +11 -14
  17. package/dist/lib/ips.d.ts +6 -6
  18. package/dist/lib/messages.d.ts +1 -1
  19. package/dist/lib/request.d.ts +4 -3
  20. package/dist/lib/suppressions.d.ts +1 -1
  21. package/dist/mailgun.node.js +3 -0
  22. package/dist/{mailgun.js.LICENSE.txt → mailgun.node.js.LICENSE.txt} +1 -1
  23. package/dist/mailgun.web.js +3 -0
  24. package/dist/mailgun.web.js.LICENSE.txt +7 -0
  25. package/examples/addresses.js +1 -0
  26. package/examples/list-domains.js +1 -0
  27. package/examples/send-email.js +1 -0
  28. package/index.ts +3 -3
  29. package/lib/client.ts +4 -3
  30. package/lib/events.ts +21 -19
  31. package/lib/interfaces/APIErrorOptions.ts +3 -1
  32. package/lib/interfaces/ApiResponse.ts +3 -1
  33. package/lib/interfaces/Events.ts +25 -0
  34. package/lib/interfaces/IFormData.ts +5 -14
  35. package/lib/interfaces/IpPools.ts +16 -1
  36. package/lib/interfaces/Ips.ts +1 -0
  37. package/lib/interfaces/Options.ts +5 -2
  38. package/lib/interfaces/RequestOptions.ts +4 -2
  39. package/lib/interfaces/StatsOptions.ts +4 -2
  40. package/lib/interfaces/Supressions.ts +1 -1
  41. package/lib/interfaces/lists.ts +1 -0
  42. package/lib/interfaces/mailListMembers.ts +18 -12
  43. package/lib/interfaces/routes.ts +1 -0
  44. package/lib/ip-pools.ts +8 -7
  45. package/lib/ips.ts +3 -3
  46. package/lib/lists.ts +1 -1
  47. package/lib/messages.ts +1 -1
  48. package/lib/parse.ts +4 -3
  49. package/lib/request.ts +18 -8
  50. package/lib/stats.ts +3 -2
  51. package/lib/suppressions.ts +16 -11
  52. package/lib/validate.ts +0 -1
  53. package/package.json +9 -9
  54. package/test/client.test.ts +9 -3
  55. package/test/domains.test.ts +2 -1
  56. package/test/events.test.ts +3 -3
  57. package/test/ips.test.ts +4 -2
  58. package/test/lists.test.ts +7 -8
  59. package/test/mailListMembers.test.ts +49 -44
  60. package/test/messageAttachment.test.ts +5 -5
  61. package/test/messages.test.ts +3 -2
  62. package/test/parse.test.ts +4 -3
  63. package/test/request.test.ts +6 -5
  64. package/test/routes.test.ts +3 -1
  65. package/test/stats.test.ts +3 -2
  66. package/test/suppressions.test.ts +14 -11
  67. package/test/validate.test.ts +3 -2
  68. package/test/webhooks.test.ts +3 -3
  69. package/tsconfig.webpack.json +1 -1
  70. package/webpack/webpack.common.config.js +47 -0
  71. package/webpack/webpack.dev.config.js +18 -0
  72. package/webpack/webpack.release.config.js +37 -0
  73. package/dist/mailgun.js +0 -3
  74. package/webpack.config.js +0 -49
  75. package/webpack.release.config.js +0 -29
@@ -12,18 +12,24 @@ import MessagesClient from '../lib/messages';
12
12
  import RoutesClient from '../lib/routes';
13
13
  import ValidateClient from '../lib/validate';
14
14
  import ParseClient from '../lib/parse';
15
+ import { InputFormData } from '../lib/interfaces/IFormData';
15
16
 
16
17
  describe('Client', function () {
17
18
  let client: any;
18
19
 
19
20
  beforeEach(function () {
20
- client = new Client({ username: 'username', key: 'key', public_key: 'key', timeout: 10000 }, formData);
21
+ client = new Client({
22
+ username: 'username',
23
+ key: 'key',
24
+ public_key: 'key',
25
+ timeout: 10000
26
+ }, formData as InputFormData);
21
27
  });
22
28
 
23
29
  it('raises error when username is not provided', function () {
24
30
  expect(
25
31
  function () {
26
- return new Client({ key: 'key' } as any, formData)
32
+ return new Client({ key: 'key' } as any, formData as InputFormData);
27
33
  }
28
34
  ).to.throw('Parameter "username" is required');
29
35
  });
@@ -31,7 +37,7 @@ describe('Client', function () {
31
37
  it('raises error when key is not provided', function () {
32
38
  expect(
33
39
  function () {
34
- return new Client({ username: 'username' } as any, formData);
40
+ return new Client({ username: 'username' } as any, formData as InputFormData);
35
41
  }
36
42
  ).to.throw('Parameter "key" is required');
37
43
  });
@@ -5,6 +5,7 @@ import { expect } from 'chai';
5
5
  import Request from '../lib/request';
6
6
  import DomainClient from '../lib/domains';
7
7
  import RequestOptions from '../lib/interfaces/RequestOptions';
8
+ import { InputFormData } from '../lib/interfaces/IFormData';
8
9
 
9
10
  // TODO: fix types
10
11
  describe('DomainClient', function () {
@@ -12,7 +13,7 @@ describe('DomainClient', function () {
12
13
  let api: any;
13
14
 
14
15
  beforeEach(function () {
15
- client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
16
+ client = new DomainClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
16
17
  api = nock('https://api.mailgun.net');
17
18
  });
18
19
 
@@ -1,17 +1,17 @@
1
- const formData = require('form-data'); // importing this way to not have type error in line 13
2
-
3
1
  import nock from 'nock';
4
2
 
3
+ import formData from 'form-data';
5
4
  import EventClient from '../lib/events';
6
5
  import MgRequest from '../lib/request';
7
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
+ import { InputFormData } from '../lib/interfaces/IFormData';
8
8
 
9
9
  describe('EventsClient', function () {
10
10
  let client: any;
11
11
  let api: any;
12
12
 
13
13
  beforeEach(function () {
14
- client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
14
+ client = new EventClient(new MgRequest({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
15
15
  api = nock('https://api.mailgun.net');
16
16
  });
17
17
 
package/test/ips.test.ts CHANGED
@@ -1,11 +1,13 @@
1
- const formData = require('form-data');
1
+ // const formData = require('form-data');
2
2
 
3
3
  import nock from 'nock';
4
+ import formData from 'form-data';
4
5
  import Request from '../lib/request';
5
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
6
7
  import IpsClient from '../lib/ips';
7
8
 
8
9
  import { IpData, IpsListResponseBody } from '../lib/interfaces/Ips';
10
+ import { InputFormData } from '../lib/interfaces/IFormData';
9
11
 
10
12
  // TODO: fix types
11
13
  describe('DomainClient', function () {
@@ -13,7 +15,7 @@ describe('DomainClient', function () {
13
15
  let api: any;
14
16
 
15
17
  beforeEach(function () {
16
- client = new IpsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
18
+ client = new IpsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
17
19
  api = nock('https://api.mailgun.net');
18
20
  });
19
21
 
@@ -1,11 +1,12 @@
1
- const formData = require('form-data');
2
-
3
1
  import nock from 'nock';
2
+ import formData from 'form-data';
3
+
4
4
  import Request from '../lib/request';
5
5
  import ListsClient from '../lib/lists';
6
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
7
  import MailListMembers from '../lib/mailListMembers';
8
8
  import { MailingList } from '../lib/interfaces/lists';
9
+ import { InputFormData } from '../lib/interfaces/IFormData';
9
10
 
10
11
  describe('ListsClient', function () {
11
12
  let client: any;
@@ -13,7 +14,7 @@ describe('ListsClient', function () {
13
14
  let defaultList : MailingList;
14
15
 
15
16
  beforeEach(function () {
16
- const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData);
17
+ const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
17
18
  const mailListMembers = new MailListMembers(reqObject);
18
19
  client = new ListsClient(reqObject, mailListMembers);
19
20
  api = nock('https://api.mailgun.net');
@@ -25,7 +26,7 @@ describe('ListsClient', function () {
25
26
  members_count: 1,
26
27
  name: '123',
27
28
  reply_preference: null
28
- } as MailingList
29
+ } as MailingList;
29
30
  });
30
31
 
31
32
  afterEach(function () {
@@ -40,15 +41,14 @@ describe('ListsClient', function () {
40
41
  items: lists
41
42
  });
42
43
 
43
- return client.list().then(function (lists: MailingList[]) {
44
- lists[0].should.eql(defaultList);
44
+ return client.list().then(function (listsRes: MailingList[]) {
45
+ listsRes[0].should.eql(defaultList);
45
46
  });
46
47
  });
47
48
  });
48
49
 
49
50
  describe('get', function () {
50
51
  it('gets a specific mailing list', function () {
51
-
52
52
  api.get('/v3/lists/testing.example.com').reply(200, {
53
53
  list: defaultList
54
54
  });
@@ -61,7 +61,6 @@ describe('ListsClient', function () {
61
61
 
62
62
  describe('create', function () {
63
63
  it('creates the list', function () {
64
-
65
64
  api.post('/v3/lists').reply(200, {
66
65
  list: defaultList
67
66
  });
@@ -1,10 +1,10 @@
1
- const formData = require('form-data');
2
-
3
1
  import nock from 'nock';
2
+ import formData from 'form-data';
4
3
  import Request from '../lib/request';
5
4
  import RequestOptions from '../lib/interfaces/RequestOptions';
6
5
  import MailListMembers from '../lib/mailListMembers';
7
6
  import { DeletedMember, MailListMember, NewMultipleMembersResponse } from '../lib/interfaces/mailListMembers';
7
+ import { InputFormData } from '../lib/interfaces/IFormData';
8
8
 
9
9
  describe('mailListsMembersClient', function () {
10
10
  let client: any;
@@ -12,7 +12,7 @@ describe('mailListsMembersClient', function () {
12
12
  let defaultListMember : MailListMember;
13
13
 
14
14
  beforeEach(function () {
15
- const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData);
15
+ const reqObject = new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData);
16
16
  client = new MailListMembers(reqObject);
17
17
  api = nock('https://api.mailgun.net');
18
18
  defaultListMember = {
@@ -20,7 +20,7 @@ describe('mailListsMembersClient', function () {
20
20
  name: 'test name',
21
21
  subscribed: true,
22
22
  vars: { gender: 'female', age: 0 }
23
- } as MailListMember
23
+ } as MailListMember;
24
24
  });
25
25
 
26
26
  afterEach(function () {
@@ -58,7 +58,7 @@ describe('mailListsMembersClient', function () {
58
58
 
59
59
  describe('createMember', function () {
60
60
  it('adds list member to the mailing list ', function () {
61
- const member:any = {...defaultListMember};
61
+ const member:any = { ...defaultListMember };
62
62
  member.subscribed = true;
63
63
  const mailingListAddress = 'testingMailingListAddress@example.com';
64
64
  api.post(`/v3/lists/${mailingListAddress}/members`).reply(200, {
@@ -67,12 +67,12 @@ describe('mailListsMembersClient', function () {
67
67
 
68
68
  return client.createMember(mailingListAddress, member).then(function (newListMember:any) {
69
69
  newListMember.should.eql(member);
70
- })
70
+ });
71
71
  });
72
72
 
73
73
  it('works with string value in subscribed field', function () {
74
- const member:any = {...defaultListMember};
75
- member.subscribed = "yes";
74
+ const member:any = { ...defaultListMember };
75
+ member.subscribed = 'yes';
76
76
  const mailingListAddress = 'testingMailingListAddress@example.com';
77
77
  api.post(`/v3/lists/${mailingListAddress}/members`).reply(200, {
78
78
  member
@@ -80,13 +80,13 @@ describe('mailListsMembersClient', function () {
80
80
 
81
81
  return client.createMember(mailingListAddress, member).then(function (newListMember:any) {
82
82
  newListMember.should.eql(member);
83
- })
83
+ });
84
84
  });
85
85
  });
86
86
 
87
87
  describe('createMembers', function () {
88
- const mailingListAddress : string = 'testingMailingListAddress@example.com';
89
- let response : NewMultipleMembersResponse;
88
+ const mailingListAddress = 'testingMailingListAddress@example.com';
89
+ let response : NewMultipleMembersResponse;
90
90
 
91
91
  beforeEach(function () {
92
92
  response = {
@@ -106,55 +106,55 @@ describe('mailListsMembersClient', function () {
106
106
 
107
107
  it('adds list of members to the mailing list', function () {
108
108
  const newMembersListPlaceholder = new Array(5).fill(0);
109
- const newMembersList = newMembersListPlaceholder.map((_, index)=>{
110
- return {
111
- address: `test${index}@example.com`,
112
- name: `test name ${index}`,
113
- vars: {gender:"female", age:index},
114
- subscribed: true,
115
- upsert: 'yes'
116
- };
117
- });
109
+ const newMembersList = newMembersListPlaceholder.map((_, index) => ({
110
+ address: `test${index}@example.com`,
111
+ name: `test name ${index}`,
112
+ vars: { gender: 'female', age: index },
113
+ subscribed: true,
114
+ upsert: 'yes'
115
+ }));
118
116
 
119
117
  api.post(`/v3/lists/${mailingListAddress}/members.json`).reply(200, response);
120
118
 
121
119
  return client.createMembers(mailingListAddress, {
122
120
  members: newMembersList,
123
- upsert: "yes"
121
+ upsert: 'yes'
124
122
  }).then(function (result: NewMultipleMembersResponse) {
125
123
  result.should.eql(response);
126
- })
124
+ });
127
125
  });
128
126
 
129
127
  it('works with string value in members field', function () {
130
128
  const newMembersListPlaceholder = new Array(5).fill(0);
131
- const newMembersList = newMembersListPlaceholder.map((_, index)=>{
132
- return {
133
- address: `test${index}@example.com`,
134
- name: `test name ${index}`,
135
- vars: JSON.stringify({gender:"female", age:index}),
136
- subscribed: true,
137
- upsert: 'yes'
138
- };
139
- });
129
+ const newMembersList = newMembersListPlaceholder.map((_, index) => ({
130
+ address: `test${index}@example.com`,
131
+ name: `test name ${index}`,
132
+ vars: JSON.stringify({ gender: 'female', age: index }),
133
+ subscribed: true,
134
+ upsert: 'yes'
135
+
136
+ }));
140
137
  api.post(`/v3/lists/${mailingListAddress}/members.json`).reply(200, response);
141
138
  return client.createMembers(mailingListAddress, {
142
139
  members: newMembersList,
143
- upsert: "yes"
140
+ upsert: 'yes'
144
141
  }).then(function (result: NewMultipleMembersResponse) {
145
142
  result.should.eql(response);
146
- })
143
+ });
147
144
  });
148
-
149
145
  });
150
146
 
151
147
  describe('updateMember', function () {
152
148
  it('updates list member in the mailing list ', function () {
153
149
  const mailingListAddress = 'testingMailingListAddress@example.com';
154
150
  const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
155
- api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, {member: defaultListMember});
151
+ api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, { member: defaultListMember });
156
152
 
157
- return client.updateMember(mailingListAddress, mailingListMemberAddress, defaultListMember).then(function (res: MailListMember) {
153
+ return client.updateMember(
154
+ mailingListAddress,
155
+ mailingListMemberAddress,
156
+ defaultListMember
157
+ ).then(function (res: MailListMember) {
158
158
  res.should.eql(defaultListMember);
159
159
  });
160
160
  });
@@ -162,32 +162,37 @@ describe('mailListsMembersClient', function () {
162
162
  it('works with string value in subscribed field', function () {
163
163
  const mailingListAddress = 'testingMailingListAddress@example.com';
164
164
  const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
165
- const member:any = {...defaultListMember};
166
- member.subscribed = "yes";
167
- api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, {member: defaultListMember});
165
+ const member: any = { ...defaultListMember };
166
+ member.subscribed = 'yes';
167
+ api.put(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, { member: defaultListMember });
168
168
 
169
- return client.updateMember(mailingListAddress, mailingListMemberAddress, member).then(function (res: MailListMember) {
169
+ return client.updateMember(
170
+ mailingListAddress,
171
+ mailingListMemberAddress,
172
+ member
173
+ ).then(function (res: MailListMember) {
170
174
  res.should.eql(defaultListMember);
171
175
  });
172
176
  });
173
177
  });
174
178
 
175
179
  describe('destroyMember', function () {
176
-
177
180
  it('deletes member from the list ', function () {
178
181
  const mailingListAddress = 'testingMailingListAddress@example.com';
179
182
  const mailingListMemberAddress = 'testingMailingListMemberAddress@example.com';
180
183
  const res = {
181
184
  member: defaultListMember,
182
- message: "deleted"
185
+ message: 'deleted'
183
186
  } as DeletedMember;
184
187
 
185
188
  api.delete(`/v3/lists/${mailingListAddress}/members/${mailingListMemberAddress}`).reply(200, res);
186
189
 
187
- return client.destroyMember(mailingListAddress, mailingListMemberAddress).then(function (deletedMemberRes: DeletedMember) {
190
+ return client.destroyMember(
191
+ mailingListAddress,
192
+ mailingListMemberAddress
193
+ ).then(function (deletedMemberRes: DeletedMember) {
188
194
  deletedMemberRes.should.eql(res);
189
195
  });
190
196
  });
191
197
  });
192
-
193
198
  });
@@ -1,12 +1,12 @@
1
- const formData = require('form-data'); // importing this way to not have type error in line 13
2
-
3
1
  import fs from 'fs';
4
2
  import nock from 'nock';
3
+ import { expect } from 'chai';
4
+ import formData from 'form-data';
5
5
 
6
6
  import Request from '../lib/request';
7
7
  import MessagesClient from '../lib/messages';
8
8
  import RequestOptions from '../lib/interfaces/RequestOptions';
9
- import { expect } from 'chai';
9
+ import { InputFormData } from '../lib/interfaces/IFormData';
10
10
 
11
11
  const mailgunLogo = fs.createReadStream(`${__dirname}/img/mailgun.png`);
12
12
 
@@ -15,7 +15,7 @@ describe('MessagesClient', function () {
15
15
  let api: any;
16
16
 
17
17
  beforeEach(function () {
18
- client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
18
+ client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
19
19
  api = nock('https://api.mailgun.net');
20
20
  });
21
21
 
@@ -42,7 +42,7 @@ describe('MessagesClient', function () {
42
42
  filename: 'test-image',
43
43
  data: mailgunLogo
44
44
  }]
45
- })
45
+ });
46
46
 
47
47
  expect(res.message).to.eql('Queued. Thank you.');
48
48
  });
@@ -1,4 +1,4 @@
1
- const formData = require('form-data'); // importing this way to not have type error in line 13
1
+ import formData from 'form-data'; // importing this way to not have type error in line 13
2
2
 
3
3
  import fs from 'fs';
4
4
  import nock from 'nock';
@@ -7,6 +7,7 @@ import { expect } from 'chai';
7
7
  import Request from '../lib/request';
8
8
  import MessagesClient from '../lib/messages';
9
9
  import RequestOptions from '../lib/interfaces/RequestOptions';
10
+ import { InputFormData } from '../lib/interfaces/IFormData';
10
11
 
11
12
  const mailgunLogo = fs.createReadStream(`${__dirname}/img/mailgun.png`);
12
13
 
@@ -15,7 +16,7 @@ describe('MessagesClient', function () {
15
16
  let api: any;
16
17
 
17
18
  beforeEach(function () {
18
- client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
19
+ client = new MessagesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
19
20
  api = nock('https://api.mailgun.net');
20
21
  });
21
22
 
@@ -1,4 +1,4 @@
1
- const formData = require('form-data');
1
+ import formData from 'form-data';
2
2
 
3
3
  import { URLSearchParams } from 'url';
4
4
  import nock from 'nock';
@@ -6,18 +6,19 @@ import Request from '../lib/request';
6
6
  import ParseClient from '../lib/parse';
7
7
 
8
8
  import RequestOptions from '../lib/interfaces/RequestOptions';
9
+ import { InputFormData } from '../lib/interfaces/IFormData';
9
10
 
10
11
  interface Data {
11
12
  parsed: string[],
12
13
  unparseable: string[]
13
- };
14
+ }
14
15
 
15
16
  describe('ParseClient', function () {
16
17
  let client: any;
17
18
  let api: any;
18
19
 
19
20
  beforeEach(function () {
20
- client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
21
+ client = new ParseClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
21
22
  api = nock('https://api.mailgun.net');
22
23
  });
23
24
 
@@ -8,6 +8,7 @@ import Request from '../lib/request';
8
8
  import RequestOptions from '../lib/interfaces/RequestOptions';
9
9
  import APIError from '../lib/error';
10
10
  import APIResponse from '../lib/interfaces/ApiResponse';
11
+ import { InputFormData } from '../lib/interfaces/IFormData';
11
12
 
12
13
  describe('Request', function () {
13
14
  let headers: { [key: string]: string };
@@ -33,7 +34,7 @@ describe('Request', function () {
33
34
  url: 'https://api.mailgun.com',
34
35
  headers: { 'X-CSRF-Token': 'protectme' },
35
36
  timeout: 10000
36
- }, formData);
37
+ }, formData as InputFormData);
37
38
 
38
39
  await req.request('get', '/v2/some/resource1', {
39
40
  headers: { Test: 'Custom Header', 'X-CSRF-Token': 'protectme' },
@@ -46,7 +47,7 @@ describe('Request', function () {
46
47
  .get('/v2/some/resource')
47
48
  .reply(200, { id: 1, message: 'hello' });
48
49
 
49
- const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData);
50
+ const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
50
51
  const res = req.request('get', '/v2/some/resource')
51
52
  .then(function (response: APIResponse) {
52
53
  expect(response.status).to.eql(200);
@@ -61,7 +62,7 @@ describe('Request', function () {
61
62
  .get('/v2/some/resource')
62
63
  .reply(429, 'Too many requests');
63
64
 
64
- const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData);
65
+ const req = new Request({ username: 'api', key: 'key', url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
65
66
  const res = req.request('get', '/v2/some/resource').catch(function (error: APIError) {
66
67
  expect(error.status).to.eql(429);
67
68
  expect(error.details).to.eql('Too many requests');
@@ -80,7 +81,7 @@ describe('Request', function () {
80
81
  .query(search)
81
82
  .reply(200, {});
82
83
 
83
- const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData);
84
+ const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
84
85
  await req.query('get', '/v2/some/resource2', search);
85
86
  });
86
87
  });
@@ -93,7 +94,7 @@ describe('Request', function () {
93
94
  .post('/v2/some/resource')
94
95
  .reply(200, {});
95
96
 
96
- const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData);
97
+ const req = new Request({ url: 'https://api.mailgun.com' } as RequestOptions, formData as InputFormData);
97
98
  const res = req.command('post', '/v2/some/resource', body);
98
99
 
99
100
  return res;
@@ -1,8 +1,10 @@
1
+ /* eslint-disable camelcase */
1
2
  import formData from 'form-data';
2
3
  import nock from 'nock';
3
4
  import Request from '../lib/request';
4
5
  import RoutesClient from '../lib/routes';
5
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
+ import { InputFormData } from '../lib/interfaces/IFormData';
6
8
 
7
9
  interface Data {
8
10
  actions: string[],
@@ -18,7 +20,7 @@ describe('RoutesClient', function () {
18
20
  let api: any;
19
21
 
20
22
  beforeEach(function () {
21
- client = new RoutesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
23
+ client = new RoutesClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
22
24
  api = nock('https://api.mailgun.net');
23
25
  });
24
26
 
@@ -1,17 +1,18 @@
1
- const formData = require('form-data');
1
+ import formData from 'form-data';
2
2
 
3
3
  import nock from 'nock';
4
4
  import Request from '../lib/request';
5
5
  import StatsClient from '../lib/stats';
6
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
7
  import StatsOptions from '../lib/interfaces/StatsOptions';
8
+ import { InputFormData } from '../lib/interfaces/IFormData';
8
9
 
9
10
  describe('StatsClient', function () {
10
11
  let client: any;
11
12
  let api: any;
12
13
 
13
14
  beforeEach(function () {
14
- client = new StatsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
15
+ client = new StatsClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
15
16
  api = nock('https://api.mailgun.net');
16
17
  });
17
18
 
@@ -1,17 +1,20 @@
1
- const should = require('should');
2
- const formData = require('form-data');
3
-
1
+ import chai, { expect } from 'chai';
2
+ import formData from 'form-data';
4
3
  import nock from 'nock';
4
+
5
5
  import Request from '../lib/request';
6
6
  import SuppressionClient from '../lib/suppressions';
7
7
  import RequestOptions from '../lib/interfaces/RequestOptions';
8
+ import { InputFormData } from '../lib/interfaces/IFormData';
9
+
10
+ chai.should();
8
11
 
9
12
  describe('SuppressionsClient', function () {
10
13
  let client: any;
11
14
  let api: any;
12
15
 
13
16
  beforeEach(function () {
14
- client = new SuppressionClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
17
+ client = new SuppressionClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
15
18
  api = nock('https://api.mailgun.net');
16
19
  });
17
20
 
@@ -80,7 +83,7 @@ describe('SuppressionsClient', function () {
80
83
  api.get('/v3/domain.com/unsubscribes').reply(200, response);
81
84
 
82
85
  return client.list('domain.com', 'unsubscribes')
83
- .then(function (unsubscribes: { items: any }) {
86
+ .then(function (unsubscribes: { items: any }) {
84
87
  let u;
85
88
 
86
89
  u = unsubscribes.items[0];
@@ -129,22 +132,22 @@ describe('SuppressionsClient', function () {
129
132
 
130
133
  page = bounces.pages.first;
131
134
  page.url.should.eql('https://api.mailgun.net/v3/mailgun.com/bounces?page=first');
132
- should(page.page).eql('first');
133
- should(page.address).eql(undefined);
135
+ expect(page.page).to.eql('first');
136
+ expect(page.address).to.be.eql(undefined);
134
137
 
135
138
  page = bounces.pages.last;
136
139
  page.url.should.eql('https://api.mailgun.net/v3/mailgun.com/bounces?page=last');
137
- should(page.page).eql('last');
138
- should(page.address).eql(undefined);
140
+ expect(page.page).to.be.eql('last');
141
+ expect(page.address).to.be.eql(undefined);
139
142
 
140
143
  page = bounces.pages.next;
141
144
  page.url.should.eql('https://api.mailgun.net/v3/mailgun.com/bounces?page=next&address=next@mailgun.com');
142
- should(page.page).eql('next');
145
+ expect(page.page).to.be.eql('next');
143
146
  page.address.should.eql('next@mailgun.com');
144
147
 
145
148
  page = bounces.pages.previous;
146
149
  page.url.should.eql('https://api.mailgun.net/v3/mailgun.com/bounces?page=previous&address=previous@mailgun.com');
147
- should(page.page).eql('previous');
150
+ expect(page.page).to.be.eql('previous');
148
151
  page.address.should.eql('previous@mailgun.com');
149
152
  });
150
153
  });
@@ -1,16 +1,17 @@
1
- const formData = require('form-data');
1
+ import formData from 'form-data';
2
2
 
3
3
  import nock from 'nock';
4
4
  import Request from '../lib/request';
5
5
  import ValidateClient from '../lib/validate';
6
6
  import RequestOptions from '../lib/interfaces/RequestOptions';
7
+ import { InputFormData } from '../lib/interfaces/IFormData';
7
8
 
8
9
  describe('ValidateClient', function () {
9
10
  let client: any;
10
11
  let api: any;
11
12
 
12
13
  beforeEach(function () {
13
- client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
14
+ client = new ValidateClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
14
15
  api = nock('https://api.mailgun.net');
15
16
  });
16
17
 
@@ -1,16 +1,16 @@
1
- const formData = require('form-data');
2
-
1
+ import formData from 'form-data';
3
2
  import nock from 'nock';
4
3
  import Request from '../lib/request';
5
4
  import WebhookClient from '../lib/webhooks';
6
5
  import RequestOptions from '../lib/interfaces/RequestOptions';
6
+ import { InputFormData } from '../lib/interfaces/IFormData';
7
7
 
8
8
  describe('WebhookClient', function () {
9
9
  let client: any;
10
10
  let api: any;
11
11
 
12
12
  beforeEach(function () {
13
- client = new WebhookClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData));
13
+ client = new WebhookClient(new Request({ url: 'https://api.mailgun.net' } as RequestOptions, formData as InputFormData));
14
14
  api = nock('https://api.mailgun.net');
15
15
  });
16
16
 
@@ -7,4 +7,4 @@
7
7
  "**/*.test.ts",
8
8
  "node_modules"
9
9
  ]
10
- }
10
+ }