@clxmedia/emailhub-client 1.0.5 → 1.0.6
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 +6 -2
- package/dist/client.js +4 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PubSub } from "@google-cloud/pubsub";
|
|
2
1
|
export declare enum EmailHubPriorityLevel {
|
|
3
2
|
NORMAL = "normal",
|
|
4
3
|
BULK = "bulk"
|
|
@@ -37,15 +36,20 @@ export interface EmailHubSender {
|
|
|
37
36
|
export interface EmailHubConfig {
|
|
38
37
|
sender: EmailHubSender;
|
|
39
38
|
server?: string;
|
|
39
|
+
credential?: CredentialBody;
|
|
40
|
+
}
|
|
41
|
+
export interface CredentialBody {
|
|
42
|
+
client_email?: string;
|
|
43
|
+
private_key?: string;
|
|
40
44
|
}
|
|
41
45
|
export declare class EmailHubClient {
|
|
42
46
|
private sender;
|
|
43
47
|
private server;
|
|
48
|
+
private credential;
|
|
44
49
|
constructor(cfg: EmailHubConfig);
|
|
45
50
|
static compressMessage(msg: EmailHubMessage): string;
|
|
46
51
|
sendEmail(msg: EmailHubMessage, options?: {
|
|
47
52
|
priority?: EmailHubPriorityLevel;
|
|
48
53
|
xMailGuid?: string;
|
|
49
|
-
cloudPubSub?: PubSub;
|
|
50
54
|
}): Promise<string>;
|
|
51
55
|
}
|
package/dist/client.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EmailHubClient = exports.EmailHubPriorityLevel = void 0;
|
|
13
|
+
const pubsub_1 = require("@google-cloud/pubsub");
|
|
13
14
|
const uuid = require("uuid");
|
|
14
15
|
const Pako = require("pako");
|
|
15
16
|
const axios_1 = require("axios");
|
|
@@ -23,17 +24,18 @@ class EmailHubClient {
|
|
|
23
24
|
constructor(cfg) {
|
|
24
25
|
this.sender = cfg.sender;
|
|
25
26
|
this.server = cfg.server ? cfg.server : DEFAULT_EMAIL_HUB_URL;
|
|
27
|
+
this.credential = cfg.credential ? cfg.credential : null;
|
|
26
28
|
}
|
|
27
29
|
static compressMessage(msg) {
|
|
28
30
|
return Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64');
|
|
29
31
|
}
|
|
30
32
|
sendEmail(msg, options) {
|
|
31
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const cloudPubSub = options.cloudPubSub ? options.cloudPubSub : null;
|
|
33
34
|
const xMailGuid = options && options.xMailGuid ? options.xMailGuid : uuid.v4();
|
|
34
35
|
msg.CustomID = xMailGuid;
|
|
35
36
|
const topic = options && options.priority && options.priority === EmailHubPriorityLevel.BULK ? 'send-new-email-bulk' : 'send-new-email';
|
|
36
|
-
if (
|
|
37
|
+
if (this.credential !== null) {
|
|
38
|
+
const cloudPubSub = new pubsub_1.PubSub({ credentials: this.credential });
|
|
37
39
|
yield cloudPubSub.topic(`projects/xperience-prod/topics/${topic}`)
|
|
38
40
|
.publishMessage({
|
|
39
41
|
json: { sender_guid: this.sender.guid, sender_secret: this.sender.secret, payload: EmailHubClient.compressMessage(msg) },
|