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.
- package/CHANGELOG.md +7 -0
- package/dist/lib/interfaces/Supressions.d.ts +6 -0
- package/dist/lib/suppressions.d.ts +12 -3
- package/dist/mailgun.node.js +2 -2
- package/dist/mailgun.node.js.LICENSE.txt +1 -1
- package/dist/mailgun.web.js +2 -2
- package/dist/mailgun.web.js.LICENSE.txt +1 -1
- package/lib/interfaces/Supressions.ts +7 -0
- package/lib/suppressions.ts +36 -5
- package/package.json +1 -1
package/lib/suppressions.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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 =
|
|
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
|
|