@clxmedia/emailhub-client 1.0.6 → 1.0.7
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 +2 -2
- package/dist/client.js +20 -4
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -36,7 +36,6 @@ export interface EmailHubSender {
|
|
|
36
36
|
export interface EmailHubConfig {
|
|
37
37
|
sender: EmailHubSender;
|
|
38
38
|
server?: string;
|
|
39
|
-
credential?: CredentialBody;
|
|
40
39
|
}
|
|
41
40
|
export interface CredentialBody {
|
|
42
41
|
client_email?: string;
|
|
@@ -45,9 +44,10 @@ export interface CredentialBody {
|
|
|
45
44
|
export declare class EmailHubClient {
|
|
46
45
|
private sender;
|
|
47
46
|
private server;
|
|
48
|
-
private
|
|
47
|
+
private pubsubClient;
|
|
49
48
|
constructor(cfg: EmailHubConfig);
|
|
50
49
|
static compressMessage(msg: EmailHubMessage): string;
|
|
50
|
+
loadPubSubClient(): Promise<void>;
|
|
51
51
|
sendEmail(msg: EmailHubMessage, options?: {
|
|
52
52
|
priority?: EmailHubPriorityLevel;
|
|
53
53
|
xMailGuid?: string;
|
package/dist/client.js
CHANGED
|
@@ -24,19 +24,35 @@ class EmailHubClient {
|
|
|
24
24
|
constructor(cfg) {
|
|
25
25
|
this.sender = cfg.sender;
|
|
26
26
|
this.server = cfg.server ? cfg.server : DEFAULT_EMAIL_HUB_URL;
|
|
27
|
-
this.credential = cfg.credential ? cfg.credential : null;
|
|
28
27
|
}
|
|
29
28
|
static compressMessage(msg) {
|
|
30
29
|
return Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64');
|
|
31
30
|
}
|
|
31
|
+
loadPubSubClient() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (this.pubsubClient) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
this.pubsubClient = new pubsub_1.PubSub();
|
|
38
|
+
yield this.pubsubClient.auth.getCredentials();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
this.pubsubClient = null;
|
|
43
|
+
console.log('Could not load default GCP credentials. Sending email directly via API.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
32
48
|
sendEmail(msg, options) {
|
|
33
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
yield this.loadPubSubClient();
|
|
34
51
|
const xMailGuid = options && options.xMailGuid ? options.xMailGuid : uuid.v4();
|
|
35
52
|
msg.CustomID = xMailGuid;
|
|
36
53
|
const topic = options && options.priority && options.priority === EmailHubPriorityLevel.BULK ? 'send-new-email-bulk' : 'send-new-email';
|
|
37
|
-
if (this.
|
|
38
|
-
|
|
39
|
-
yield cloudPubSub.topic(`projects/xperience-prod/topics/${topic}`)
|
|
54
|
+
if (this.pubsubClient !== null) {
|
|
55
|
+
yield this.pubsubClient.topic(`projects/xperience-prod/topics/${topic}`)
|
|
40
56
|
.publishMessage({
|
|
41
57
|
json: { sender_guid: this.sender.guid, sender_secret: this.sender.secret, payload: EmailHubClient.compressMessage(msg) },
|
|
42
58
|
attributes: { sender_guid: this.sender.guid }
|