@clxmedia/emailhub-client 2.0.3 → 2.0.5
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/dist/client.d.ts +1 -1
- package/dist/client.js +42 -14
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmailHubConfig, EmailHubEnvironment, EmailHubMessage, EmailHubPriorityLevel, EmailHubSenderProfile } from
|
|
1
|
+
import { EmailHubConfig, EmailHubEnvironment, EmailHubMessage, EmailHubPriorityLevel, EmailHubSenderProfile } from '@clxmedia/types/emailhub';
|
|
2
2
|
export declare class MockEmailHubClient {
|
|
3
3
|
readonly environment: EmailHubEnvironment;
|
|
4
4
|
private extendedLogging;
|
package/dist/client.js
CHANGED
|
@@ -50,7 +50,7 @@ const mockEmailHubSenderProfile = {
|
|
|
50
50
|
spf_status: 'Error',
|
|
51
51
|
created_at: luxon_1.DateTime.local().toISO(),
|
|
52
52
|
updated_at: luxon_1.DateTime.local().toISO(),
|
|
53
|
-
verified_at: undefined
|
|
53
|
+
verified_at: undefined,
|
|
54
54
|
};
|
|
55
55
|
class MockEmailHubClient {
|
|
56
56
|
constructor(extendedLogging = false) {
|
|
@@ -86,7 +86,9 @@ class EmailHubClient {
|
|
|
86
86
|
this.directApiOnly = directApiOnly || false;
|
|
87
87
|
}
|
|
88
88
|
static new(cfg, extendedLogging = false, directApiOnly = false) {
|
|
89
|
-
return
|
|
89
|
+
return cfg.sender.guid && cfg.sender.secret
|
|
90
|
+
? new EmailHubClient(cfg, directApiOnly)
|
|
91
|
+
: new MockEmailHubClient(extendedLogging);
|
|
90
92
|
}
|
|
91
93
|
async loadPubSubClient() {
|
|
92
94
|
if (this.pubsubClient || this.directApiOnly) {
|
|
@@ -111,7 +113,11 @@ class EmailHubClient {
|
|
|
111
113
|
}
|
|
112
114
|
async createSenderProfile(domain) {
|
|
113
115
|
const result = await axios_1.default.post(`${this.server}/sender-profiles`, { domain }, {
|
|
114
|
-
headers: {
|
|
116
|
+
headers: {
|
|
117
|
+
'Content-Type': 'application/json',
|
|
118
|
+
'x-emailhub-sender-guid': this.sender.guid,
|
|
119
|
+
'x-emailhub-sender-secret': this.sender.secret,
|
|
120
|
+
},
|
|
115
121
|
});
|
|
116
122
|
if (result.status === 400) {
|
|
117
123
|
throw Error('Domain already taken or configured.');
|
|
@@ -120,7 +126,11 @@ class EmailHubClient {
|
|
|
120
126
|
}
|
|
121
127
|
async getSenderProfile(domainGuid) {
|
|
122
128
|
const result = await axios_1.default.get(`${this.server}/sender-profiles/${domainGuid}`, {
|
|
123
|
-
headers: {
|
|
129
|
+
headers: {
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
'x-emailhub-sender-guid': this.sender.guid,
|
|
132
|
+
'x-emailhub-sender-secret': this.sender.secret,
|
|
133
|
+
},
|
|
124
134
|
});
|
|
125
135
|
if (result.status >= 400) {
|
|
126
136
|
throw Error('Domain locator invalid or record not found.');
|
|
@@ -129,7 +139,11 @@ class EmailHubClient {
|
|
|
129
139
|
}
|
|
130
140
|
async checkSenderProfile(domainGuid) {
|
|
131
141
|
const result = await axios_1.default.post(`${this.server}/sender-profiles/${domainGuid}`, undefined, {
|
|
132
|
-
headers: {
|
|
142
|
+
headers: {
|
|
143
|
+
'Content-Type': 'application/json',
|
|
144
|
+
'x-emailhub-sender-guid': this.sender.guid,
|
|
145
|
+
'x-emailhub-sender-secret': this.sender.secret,
|
|
146
|
+
},
|
|
133
147
|
});
|
|
134
148
|
if (result.status >= 400) {
|
|
135
149
|
throw Error('Domain locator invalid or record not found.');
|
|
@@ -138,7 +152,11 @@ class EmailHubClient {
|
|
|
138
152
|
}
|
|
139
153
|
async deleteSenderProfile(domainGuid) {
|
|
140
154
|
const result = await axios_1.default.delete(`${this.server}/sender-profiles/${domainGuid}`, {
|
|
141
|
-
headers: {
|
|
155
|
+
headers: {
|
|
156
|
+
'Content-Type': 'application/json',
|
|
157
|
+
'x-emailhub-sender-guid': this.sender.guid,
|
|
158
|
+
'x-emailhub-sender-secret': this.sender.secret,
|
|
159
|
+
},
|
|
142
160
|
});
|
|
143
161
|
return result.status;
|
|
144
162
|
}
|
|
@@ -146,13 +164,22 @@ class EmailHubClient {
|
|
|
146
164
|
await this.loadPubSubClient();
|
|
147
165
|
const xMailGuid = msg && msg.CustomID ? msg.CustomID : uuid.v4();
|
|
148
166
|
msg.CustomID = xMailGuid;
|
|
149
|
-
const topic = options &&
|
|
167
|
+
const topic = options &&
|
|
168
|
+
options.priority &&
|
|
169
|
+
options.priority === emailhub_1.EmailHubPriorityLevel.BULK
|
|
170
|
+
? 'send-new-email-bulk'
|
|
171
|
+
: 'send-new-email';
|
|
150
172
|
if (this.pubsubClient !== null) {
|
|
151
173
|
try {
|
|
152
|
-
await this.pubsubClient
|
|
174
|
+
await this.pubsubClient
|
|
175
|
+
.topic(`projects/xperience-prod/topics/${topic}`)
|
|
153
176
|
.publishMessage({
|
|
154
|
-
json: {
|
|
155
|
-
|
|
177
|
+
json: {
|
|
178
|
+
sender_guid: this.sender.guid,
|
|
179
|
+
sender_secret: this.sender.secret,
|
|
180
|
+
payload: Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64'),
|
|
181
|
+
},
|
|
182
|
+
attributes: { sender_guid: this.sender.guid },
|
|
156
183
|
});
|
|
157
184
|
return xMailGuid;
|
|
158
185
|
}
|
|
@@ -161,11 +188,12 @@ class EmailHubClient {
|
|
|
161
188
|
}
|
|
162
189
|
}
|
|
163
190
|
const result = await axios_1.default.post(`${this.server}/email/send`, msg, {
|
|
164
|
-
headers: {
|
|
191
|
+
headers: {
|
|
192
|
+
'Content-Type': 'application/json',
|
|
193
|
+
'x-emailhub-sender-guid': this.sender.guid,
|
|
194
|
+
'x-emailhub-sender-secret': this.sender.secret,
|
|
195
|
+
},
|
|
165
196
|
});
|
|
166
|
-
if (result.status !== 200) {
|
|
167
|
-
throw Error('Failed to send email.');
|
|
168
|
-
}
|
|
169
197
|
return { guid: xMailGuid, messageId: result.data };
|
|
170
198
|
}
|
|
171
199
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clxmedia/emailhub-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "CLXperience EmailHub Client",
|
|
5
5
|
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"bugs": "https://github.com/adsupnow/xperience-library/emailhub-client",
|
|
43
43
|
"peerDependencies": {},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@clxmedia/types": "1.0.
|
|
45
|
+
"@clxmedia/types": "1.0.186",
|
|
46
46
|
"@google-cloud/pubsub": "4.3.3",
|
|
47
47
|
"uuid": "9.0.1",
|
|
48
48
|
"axios": "1.6.8",
|
|
@@ -72,4 +72,4 @@
|
|
|
72
72
|
"coverageDirectory": "../coverage",
|
|
73
73
|
"testEnvironment": "node"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|