mailgun.js 4.0.1 → 4.1.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.
@@ -4,4 +4,4 @@
4
4
 
5
5
  /*! https://mths.be/punycode v1.3.2 by @mathias */
6
6
 
7
- /*! mailgun.js v4.0.0 */
7
+ /*! mailgun.js v4.0.1 */
@@ -16,3 +16,10 @@ export interface UnsubscribeData {
16
16
  tags: any;
17
17
  created_at: string | Date;
18
18
  }
19
+
20
+ export interface WhiteListData {
21
+ type: string;
22
+ value: string;
23
+ reason: string;
24
+ createdAt: string | Date;
25
+ }
@@ -3,7 +3,12 @@ import url from 'url';
3
3
  import urljoin from 'url-join';
4
4
 
5
5
  import Request from './request';
6
- import { BounceData, ComplaintData, UnsubscribeData } from './interfaces/Supressions';
6
+ import {
7
+ BounceData,
8
+ ComplaintData,
9
+ UnsubscribeData,
10
+ WhiteListData
11
+ } from './interfaces/Supressions';
7
12
 
8
13
  const createOptions = {
9
14
  headers: { 'Content-Type': 'application/json' }
@@ -51,7 +56,21 @@ class Unsubscribe {
51
56
  }
52
57
  }
53
58
 
54
- type TModel = typeof Bounce | typeof Complaint | typeof Unsubscribe;
59
+ class WhiteList {
60
+ type: string;
61
+ value: string;
62
+ reason: string;
63
+ createdAt: Date;
64
+
65
+ constructor(data: WhiteListData) {
66
+ this.type = 'whitelists';
67
+ this.value = data.value;
68
+ this.reason = data.reason;
69
+ this.createdAt = new Date(data.createdAt);
70
+ }
71
+ }
72
+
73
+ type TModel = typeof Bounce | typeof Complaint | typeof Unsubscribe | typeof WhiteList;
55
74
 
56
75
  export default class SuppressionClient {
57
76
  request: any;
@@ -59,6 +78,7 @@ export default class SuppressionClient {
59
78
  bounces: typeof Bounce;
60
79
  complaints: typeof Complaint;
61
80
  unsubscribes: typeof Unsubscribe;
81
+ whitelists: typeof WhiteList;
62
82
  };
63
83
 
64
84
  constructor(request: Request) {
@@ -66,7 +86,8 @@ export default class SuppressionClient {
66
86
  this.models = {
67
87
  bounces: Bounce,
68
88
  complaints: Complaint,
69
- unsubscribes: Unsubscribe
89
+ unsubscribes: Unsubscribe,
90
+ whitelists: WhiteList,
70
91
  };
71
92
  }
72
93
 
@@ -106,6 +127,12 @@ export default class SuppressionClient {
106
127
  return new Model(response.body);
107
128
  }
108
129
 
130
+ private createWhiteList(domain: string, data: any) {
131
+ return this.request
132
+ .postWithFD(urljoin('v3', domain, 'whitelists'), data, createOptions)
133
+ .then((response: { body: any }) => response.body);
134
+ }
135
+
109
136
  list(domain: string, type: string, query: any) {
110
137
  const model = (this.models as any)[type];
111
138
 
@@ -125,14 +152,18 @@ export default class SuppressionClient {
125
152
  create(domain: string, type: string, data: any) {
126
153
  // supports adding multiple suppressions by default
127
154
  let postData;
155
+ if (type === 'whitelists') {
156
+ return this.createWhiteList(domain, data);
157
+ }
158
+
128
159
  if (!Array.isArray(data)) {
129
160
  postData = [data];
130
161
  } else {
131
- postData = { ...data };
162
+ postData = [...data];
132
163
  }
133
164
 
134
165
  return this.request
135
- .post(urljoin('v3', domain, type), postData, createOptions)
166
+ .post(urljoin('v3', domain, type), JSON.stringify(postData), createOptions)
136
167
  .then((response: { body: any }) => response.body);
137
168
  }
138
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailgun.js",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "main": "dist/mailgun.node.js",
5
5
  "browser": "dist/mailgun.web.js",
6
6
  "types": "dist/index.d.ts",