@clxmedia/emailhub-client 1.1.7 → 2.0.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.
- package/README.md +1 -1
- package/dist/client.d.ts +3 -4
- package/dist/client.js +101 -104
- package/package.json +24 -26
- package/CHANGELOG.md +0 -3
- package/CONTRIBUTING.md +0 -31
package/README.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { EmailHubConfig, EmailHubEnvironment, EmailHubMessage, EmailHubPriorityLevel, EmailHubSenderProfile } from "@clxmedia/types/emailhub";
|
|
2
|
-
import { HttpStatusCode } from "axios";
|
|
3
2
|
export declare class MockEmailHubClient {
|
|
4
3
|
readonly environment: EmailHubEnvironment;
|
|
5
4
|
private extendedLogging;
|
|
6
5
|
constructor(extendedLogging?: boolean);
|
|
7
6
|
createSenderProfile(_domain: string): Promise<{
|
|
8
|
-
guid:
|
|
7
|
+
guid: any;
|
|
9
8
|
id: number;
|
|
10
9
|
domain_name: string;
|
|
11
10
|
domain_id: string;
|
|
@@ -23,7 +22,7 @@ export declare class MockEmailHubClient {
|
|
|
23
22
|
}>;
|
|
24
23
|
checkSenderProfile(domainGuid: string): Promise<{
|
|
25
24
|
guid: string;
|
|
26
|
-
verified_at:
|
|
25
|
+
verified_at: any;
|
|
27
26
|
id: number;
|
|
28
27
|
domain_name: string;
|
|
29
28
|
domain_id: string;
|
|
@@ -55,7 +54,7 @@ export declare class EmailHubClient {
|
|
|
55
54
|
createSenderProfile(domain: string): Promise<EmailHubSenderProfile>;
|
|
56
55
|
getSenderProfile(domainGuid: string): Promise<EmailHubSenderProfile>;
|
|
57
56
|
checkSenderProfile(domainGuid: string): Promise<EmailHubSenderProfile>;
|
|
58
|
-
deleteSenderProfile(domainGuid: string): Promise<
|
|
57
|
+
deleteSenderProfile(domainGuid: string): Promise<number>;
|
|
59
58
|
sendEmail(msg: EmailHubMessage, options?: {
|
|
60
59
|
priority?: EmailHubPriorityLevel;
|
|
61
60
|
writeToLog?: boolean;
|
package/dist/client.js
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
27
|
};
|
|
11
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
29
|
exports.EmailHubClient = exports.MockEmailHubClient = void 0;
|
|
13
30
|
const pubsub_1 = require("@google-cloud/pubsub");
|
|
14
31
|
const emailhub_1 = require("@clxmedia/types/emailhub");
|
|
15
32
|
const luxon_1 = require("luxon");
|
|
16
|
-
const uuid = require("uuid");
|
|
17
|
-
const Pako = require("pako");
|
|
18
|
-
const axios_1 = require("axios");
|
|
33
|
+
const uuid = __importStar(require("uuid"));
|
|
34
|
+
const Pako = __importStar(require("pako"));
|
|
35
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
36
|
const DEFAULT_EMAIL_HUB_URL = 'https://emailhub.clxp.us';
|
|
20
37
|
const DEFAULT_EMAIL_REGEX = /^([a-z0-9])([a-z\.0-9_%\-\+\*'’!#`&\$/]*)@(.+)\.(.+)$/;
|
|
21
38
|
const mockEmailHubSenderProfile = {
|
|
@@ -40,31 +57,23 @@ class MockEmailHubClient {
|
|
|
40
57
|
this.environment = emailhub_1.EmailHubEnvironment.localhost;
|
|
41
58
|
this.extendedLogging = extendedLogging;
|
|
42
59
|
}
|
|
43
|
-
createSenderProfile(_domain) {
|
|
44
|
-
return
|
|
45
|
-
return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: uuid.v4() });
|
|
46
|
-
});
|
|
60
|
+
async createSenderProfile(_domain) {
|
|
61
|
+
return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: uuid.v4() });
|
|
47
62
|
}
|
|
48
|
-
checkSenderProfile(domainGuid) {
|
|
49
|
-
return
|
|
50
|
-
return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: domainGuid, verified_at: luxon_1.DateTime.local().toISO() });
|
|
51
|
-
});
|
|
63
|
+
async checkSenderProfile(domainGuid) {
|
|
64
|
+
return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: domainGuid, verified_at: luxon_1.DateTime.local().toISO() });
|
|
52
65
|
}
|
|
53
|
-
deleteSenderProfile() {
|
|
54
|
-
return
|
|
55
|
-
return;
|
|
56
|
-
});
|
|
66
|
+
async deleteSenderProfile() {
|
|
67
|
+
return;
|
|
57
68
|
}
|
|
58
|
-
sendEmail(msg, options) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return xMailGuid;
|
|
67
|
-
});
|
|
69
|
+
async sendEmail(msg, options) {
|
|
70
|
+
if (this.extendedLogging) {
|
|
71
|
+
console.log(`----------------Begin mock email send: Priority: [${(options === null || options === void 0 ? void 0 : options.priority) || 'default'}]-----------------`);
|
|
72
|
+
console.log(JSON.stringify(msg));
|
|
73
|
+
console.log('----------------End mock email send-----------------');
|
|
74
|
+
}
|
|
75
|
+
const xMailGuid = msg && msg.CustomID ? msg.CustomID : uuid.v4();
|
|
76
|
+
return xMailGuid;
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
exports.MockEmailHubClient = MockEmailHubClient;
|
|
@@ -77,22 +86,20 @@ class EmailHubClient {
|
|
|
77
86
|
static new(cfg, extendedLogging = false) {
|
|
78
87
|
return (cfg.sender.guid && cfg.sender.secret) ? new EmailHubClient(cfg) : new MockEmailHubClient(extendedLogging);
|
|
79
88
|
}
|
|
80
|
-
loadPubSubClient() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
});
|
|
89
|
+
async loadPubSubClient() {
|
|
90
|
+
if (this.pubsubClient) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
this.pubsubClient = new pubsub_1.PubSub();
|
|
95
|
+
await this.pubsubClient.auth.getCredentials();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
this.pubsubClient = null;
|
|
100
|
+
console.log('Could not load default GCP credentials. Sending email directly via API.');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
96
103
|
}
|
|
97
104
|
static validateEmailAddress(email, regex = DEFAULT_EMAIL_REGEX) {
|
|
98
105
|
if (!email) {
|
|
@@ -100,71 +107,61 @@ class EmailHubClient {
|
|
|
100
107
|
}
|
|
101
108
|
return regex.test(email.toLocaleLowerCase());
|
|
102
109
|
}
|
|
103
|
-
createSenderProfile(domain) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
107
|
-
});
|
|
108
|
-
if (result.status === 400) {
|
|
109
|
-
throw Error('Domain already taken or configured.');
|
|
110
|
-
}
|
|
111
|
-
return result.data;
|
|
110
|
+
async createSenderProfile(domain) {
|
|
111
|
+
const result = await axios_1.default.post(`${this.server}/sender-profiles`, { domain }, {
|
|
112
|
+
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
112
113
|
});
|
|
114
|
+
if (result.status === 400) {
|
|
115
|
+
throw Error('Domain already taken or configured.');
|
|
116
|
+
}
|
|
117
|
+
return result.data;
|
|
113
118
|
}
|
|
114
|
-
getSenderProfile(domainGuid) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
118
|
-
});
|
|
119
|
-
if (result.status >= 400) {
|
|
120
|
-
throw Error('Domain locator invalid or record not found.');
|
|
121
|
-
}
|
|
122
|
-
return result.data;
|
|
119
|
+
async getSenderProfile(domainGuid) {
|
|
120
|
+
const result = await axios_1.default.get(`${this.server}/sender-profiles/${domainGuid}`, {
|
|
121
|
+
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
123
122
|
});
|
|
123
|
+
if (result.status >= 400) {
|
|
124
|
+
throw Error('Domain locator invalid or record not found.');
|
|
125
|
+
}
|
|
126
|
+
return result.data;
|
|
124
127
|
}
|
|
125
|
-
checkSenderProfile(domainGuid) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
129
|
-
});
|
|
130
|
-
if (result.status >= 400) {
|
|
131
|
-
throw Error('Domain locator invalid or record not found.');
|
|
132
|
-
}
|
|
133
|
-
return result.data;
|
|
128
|
+
async checkSenderProfile(domainGuid) {
|
|
129
|
+
const result = await axios_1.default.post(`${this.server}/sender-profiles/${domainGuid}`, undefined, {
|
|
130
|
+
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
134
131
|
});
|
|
132
|
+
if (result.status >= 400) {
|
|
133
|
+
throw Error('Domain locator invalid or record not found.');
|
|
134
|
+
}
|
|
135
|
+
return result.data;
|
|
135
136
|
}
|
|
136
|
-
deleteSenderProfile(domainGuid) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
140
|
-
});
|
|
141
|
-
return result.status;
|
|
137
|
+
async deleteSenderProfile(domainGuid) {
|
|
138
|
+
const result = await axios_1.default.delete(`${this.server}/sender-profiles/${domainGuid}`, {
|
|
139
|
+
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
142
140
|
});
|
|
141
|
+
return result.status;
|
|
143
142
|
}
|
|
144
|
-
sendEmail(msg, options) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return xMailGuid;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
console.log('Failed to send email via PubSub queue. Falling back to Direct API connection.');
|
|
161
|
-
}
|
|
143
|
+
async sendEmail(msg, options) {
|
|
144
|
+
await this.loadPubSubClient();
|
|
145
|
+
const xMailGuid = msg && msg.CustomID ? msg.CustomID : uuid.v4();
|
|
146
|
+
msg.CustomID = xMailGuid;
|
|
147
|
+
const topic = options && options.priority && options.priority === emailhub_1.EmailHubPriorityLevel.BULK ? 'send-new-email-bulk' : 'send-new-email';
|
|
148
|
+
if (this.pubsubClient !== null) {
|
|
149
|
+
try {
|
|
150
|
+
await this.pubsubClient.topic(`projects/xperience-prod/topics/${topic}`)
|
|
151
|
+
.publishMessage({
|
|
152
|
+
json: { sender_guid: this.sender.guid, sender_secret: this.sender.secret, payload: Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64') },
|
|
153
|
+
attributes: { sender_guid: this.sender.guid }
|
|
154
|
+
});
|
|
155
|
+
return xMailGuid;
|
|
162
156
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
157
|
+
catch (e) {
|
|
158
|
+
console.log('Failed to send email via PubSub queue. Falling back to Direct API connection.');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
await axios_1.default.post(`${this.server}/email/send`, msg, {
|
|
162
|
+
headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
|
|
167
163
|
});
|
|
164
|
+
return xMailGuid;
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
exports.EmailHubClient = EmailHubClient;
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clxmedia/emailhub-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "CLXperience EmailHub Client",
|
|
5
5
|
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"readmeFilename": "README.md",
|
|
8
|
-
"main": "dist/
|
|
9
|
-
"
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/**/*",
|
|
12
12
|
"*.md"
|
|
13
13
|
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./client": "./dist/client.js"
|
|
20
|
+
},
|
|
14
21
|
"scripts": {
|
|
15
22
|
"start:dev": "tsc -w",
|
|
16
|
-
"build": "tsc",
|
|
23
|
+
"build": "rm -Rf dist && tsc",
|
|
17
24
|
"prepare": "npm run build",
|
|
18
25
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
19
26
|
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
@@ -35,30 +42,21 @@
|
|
|
35
42
|
"bugs": "https://github.com/adsupnow/xperience-clients/emailhub",
|
|
36
43
|
"peerDependencies": {},
|
|
37
44
|
"dependencies": {
|
|
38
|
-
"@google-cloud/pubsub": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"pako": "
|
|
42
|
-
"
|
|
45
|
+
"@google-cloud/pubsub": "4.3.3",
|
|
46
|
+
"uuid": "9.0.1",
|
|
47
|
+
"axios": "1.6.8",
|
|
48
|
+
"pako": "2.1.0",
|
|
49
|
+
"luxon": "3.4.4"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"@types
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"prettier": "2.7.1",
|
|
54
|
-
"supertest": "6.2.4",
|
|
55
|
-
"ts-jest": "28.0.8",
|
|
56
|
-
"ts-node": "10.9.1",
|
|
57
|
-
"tsc-watch": "5.0.3",
|
|
58
|
-
"tsconfig-paths": "4.1.0",
|
|
59
|
-
"tslint": "6.1.3",
|
|
60
|
-
"typescript": "4.7.4",
|
|
61
|
-
"@clxmedia/types": "1.0.3"
|
|
52
|
+
"typescript": "^5.2.2",
|
|
53
|
+
"@clxmedia/types": "1.0.15",
|
|
54
|
+
"@types/node": "^20",
|
|
55
|
+
"@types/jsonwebtoken": "9.0.6",
|
|
56
|
+
"jest": "29.7.0",
|
|
57
|
+
"ts-jest": "29.1.2",
|
|
58
|
+
"nock": "13.5.4",
|
|
59
|
+
"tslint": "6.1.3"
|
|
62
60
|
},
|
|
63
61
|
"jest": {
|
|
64
62
|
"moduleFileExtensions": [
|
package/CHANGELOG.md
DELETED
package/CONTRIBUTING.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
1. [Fork it](https://help.github.com/articles/fork-a-repo/)
|
|
4
|
-
2. Install dependencies (`npm install`)
|
|
5
|
-
3. Create your feature branch (`git checkout -b my-new-feature`)
|
|
6
|
-
4. Commit your changes (`git commit -am 'Added some feature'`)
|
|
7
|
-
5. Test your changes (`npm test`)
|
|
8
|
-
6. Push to the branch (`git push origin my-new-feature`)
|
|
9
|
-
7. [Create new Pull Request](https://help.github.com/articles/creating-a-pull-request/)
|
|
10
|
-
|
|
11
|
-
## Testing
|
|
12
|
-
|
|
13
|
-
We use [Jest](https://github.com/facebook/jest) to write tests. Run our test suite with this command:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
npm test
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Code Style
|
|
20
|
-
|
|
21
|
-
We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices.
|
|
22
|
-
Please make sure your PR adheres to the guides by running:
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
npm run format
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
and
|
|
29
|
-
```
|
|
30
|
-
npm run lint
|
|
31
|
-
```
|