mailgun.js 5.0.0 → 5.0.3

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.
@@ -6,6 +6,7 @@ import Request from '../lib/request';
6
6
  import SuppressionClient from '../lib/suppressions';
7
7
  import RequestOptions from '../lib/interfaces/RequestOptions';
8
8
  import { InputFormData } from '../lib/interfaces/IFormData';
9
+ import { WhiteListData } from '../lib/interfaces/Supressions';
9
10
 
10
11
  chai.should();
11
12
 
@@ -123,6 +124,38 @@ describe('SuppressionsClient', function () {
123
124
  });
124
125
  });
125
126
 
127
+ it('fetches WhiteLists', function () {
128
+ response.items = [{
129
+ type: 'whitelists',
130
+ value: 'brad@example.com',
131
+ reason: 'first reason',
132
+ createdAt: '2021-11-30T10:38:56.000Z'
133
+ }, {
134
+ type: 'whitelists',
135
+ value: 'roman@example.com',
136
+ reason: 'second reason',
137
+ createdAt: '2021-11-30T10:38:56.000Z'
138
+ }];
139
+
140
+ api.get('/v3/domain.com/whitelists').reply(200, response);
141
+
142
+ return client.list('domain.com', 'whitelists')
143
+ .then(function (complaints: { items: WhiteListData[] }) {
144
+ let c;
145
+ c = complaints.items[0];
146
+ c.type.should.eql('whitelists');
147
+ c.value.should.eql('brad@example.com');
148
+ c.reason.should.eql('first reason');
149
+ c.createdAt.should.eql(new Date('2021-11-30T10:38:56.000Z'));
150
+
151
+ c = complaints.items[1];
152
+ c.type.should.eql('whitelists');
153
+ c.value.should.eql('roman@example.com');
154
+ c.reason.should.eql('second reason');
155
+ c.createdAt.should.eql(new Date('2021-11-30T10:38:56.000Z'));
156
+ });
157
+ });
158
+
126
159
  it('parses page links', function () {
127
160
  api.get('/v3/domain.com/bounces').reply(200, response);
128
161
 
@@ -186,21 +219,72 @@ describe('SuppressionsClient', function () {
186
219
  });
187
220
  });
188
221
  });
189
-
190
222
  describe('create', function () {
191
- it('creates suppression', function () {
192
- api.post('/v3/domain.com/bounces').reply(200, {
193
- message: 'Bounced address has been inserted',
194
- address: 'myaddress'
223
+ describe('create bounce', function () {
224
+ it('creates suppression', function () {
225
+ api.post('/v3/domain.com/bounces').reply(200, {
226
+ message: '1 addresses have been added to the bounces table'
227
+ });
228
+
229
+ return client.create('domain.com', 'bounces', {
230
+ address: 'myaddress',
231
+ code: 550
232
+ }).then(function (data: { message: string }) {
233
+ data.message.should.eql('1 addresses have been added to the bounces table');
234
+ });
195
235
  });
236
+ });
196
237
 
197
- return client.create('domain.com', 'bounces', {
198
- address: 'myaddress',
199
- code: 550
200
- }).then(function (data: { address: string }) {
201
- data.address.should.eql('myaddress');
238
+ describe('create multiple bounces', function () {
239
+ it('creates bounces', async function () {
240
+ const message = '2 addresses have been added to the bounces table';
241
+ api.post('/v3/domain.com/bounces').reply(200, {
242
+ message
243
+ });
244
+ return client.create('domain.com', 'bounces',
245
+ [{ address: 'myaddress' }, { address: 'myaddress1' }])
246
+ .then(function (data: { message: string }) {
247
+ data.message.should.eql(message);
248
+ });
249
+ });
250
+ });
251
+ describe('create whitelists', function () {
252
+ it('creates whitelist', async function () {
253
+ const message = '1 addresses have been added to the whitelists table';
254
+ api.post('/v3/domain.com/whitelists').reply(200, {
255
+ message
256
+ });
257
+ return client.create('domain.com', 'whitelists',
258
+ { address: 'myaddress' })
259
+ .then(function (data: { message: string }) {
260
+ data.message.should.eql(message);
261
+ });
202
262
  });
203
263
  });
264
+
265
+ describe('create multiple whitelists', function () {
266
+ it('throws in case multiple whitelists provided', async function () {
267
+ try {
268
+ await client.create('domain.com', 'whitelists',
269
+ [{ address: 'myaddress' }, { address: 'myaddress1' }]);
270
+ } catch (error: any) {
271
+ error.message.should.eql('Data property should be an object');
272
+ error.details.should.eql("Whitelist's creation process does not support multiple creations. Data property should be an object");
273
+ error.status.should.eql(400);
274
+ }
275
+ });
276
+ });
277
+
278
+ it('throws in case type is unknown', async function () {
279
+ try {
280
+ await client.create('domain.com', 'wrong type',
281
+ { address: 'myaddress' });
282
+ } catch (error: any) {
283
+ error.message.should.eql('Unknown type value');
284
+ error.details.should.eql('Type may be only one of [bounces, complaints, unsubscribes, whitelists]');
285
+ error.status.should.eql(400);
286
+ }
287
+ });
204
288
  });
205
289
 
206
290
  describe('destroy', function () {
package/tsconfig.json CHANGED
@@ -10,8 +10,8 @@
10
10
 
11
11
  "allowSyntheticDefaultImports": true,
12
12
  "incremental": true,
13
- "skipLibCheck": true
14
- // "strict": true,
13
+ "skipLibCheck": true,
14
+ "strict": true
15
15
  },
16
16
  "typedocOptions": {
17
17
  "out": "docs",
@@ -16,7 +16,6 @@ const commonConfig = {
16
16
  path: path.join(SRC_DIR, outputDir),
17
17
  filename: 'mailgun.js',
18
18
  library: 'mailgun',
19
- libraryTarget: 'umd',
20
19
  globalObject: 'this',
21
20
  },
22
21
  module: {
@@ -4,7 +4,12 @@ const commonConfig = require('./webpack.common.config');
4
4
  const nodeConf = merge(commonConfig, {
5
5
  target: 'node',
6
6
  output: {
7
- filename: 'mailgun.node.js'
7
+ filename: 'mailgun.node.js',
8
+ library: {
9
+ name: 'mailgun',
10
+ type: 'umd',
11
+ export: 'default',
12
+ }
8
13
  },
9
14
  watchOptions: {
10
15
  aggregateTimeout: 300,
@@ -16,7 +21,10 @@ const nodeConf = merge(commonConfig, {
16
21
  const webConf = merge(commonConfig, {
17
22
  target: 'web',
18
23
  output: {
19
- filename: 'mailgun.web.js'
24
+ filename: 'mailgun.web.js',
25
+ library: {
26
+ type: 'amd'
27
+ }
20
28
  },
21
29
  watchOptions: {
22
30
  aggregateTimeout: 300,
@@ -24,14 +24,22 @@ const productionConfig = merge(baseConfig, {
24
24
  const nodeConf = merge(productionConfig, {
25
25
  target: 'node',
26
26
  output: {
27
- filename: 'mailgun.node.js'
27
+ filename: 'mailgun.node.js',
28
+ library: {
29
+ name: 'mailgun',
30
+ type: 'umd',
31
+ export: 'default',
32
+ }
28
33
  }
29
34
  });
30
35
 
31
36
  const webConf = merge(productionConfig, {
32
37
  target: 'web',
33
38
  output: {
34
- filename: 'mailgun.web.js'
39
+ filename: 'mailgun.web.js',
40
+ library: {
41
+ type: 'amd'
42
+ }
35
43
  }
36
44
  });
37
45
  module.exports = [nodeConf, webConf];