@clxmedia/emailhub-client 1.0.7 → 1.0.8

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 CHANGED
@@ -22,6 +22,7 @@ export interface EmailHubMessage {
22
22
  To: EmailHubRecipient[];
23
23
  Cc?: EmailHubRecipient[];
24
24
  Bcc?: EmailHubRecipient[];
25
+ ReplyTo?: EmailHubRecipient | undefined;
25
26
  Subject: string;
26
27
  TextPart?: string;
27
28
  HTMLPart?: string;
@@ -46,10 +47,8 @@ export declare class EmailHubClient {
46
47
  private server;
47
48
  private pubsubClient;
48
49
  constructor(cfg: EmailHubConfig);
49
- static compressMessage(msg: EmailHubMessage): string;
50
- loadPubSubClient(): Promise<void>;
50
+ private loadPubSubClient;
51
51
  sendEmail(msg: EmailHubMessage, options?: {
52
52
  priority?: EmailHubPriorityLevel;
53
- xMailGuid?: string;
54
53
  }): Promise<string>;
55
54
  }
package/dist/client.js CHANGED
@@ -25,9 +25,6 @@ class EmailHubClient {
25
25
  this.sender = cfg.sender;
26
26
  this.server = cfg.server ? cfg.server : DEFAULT_EMAIL_HUB_URL;
27
27
  }
28
- static compressMessage(msg) {
29
- return Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64');
30
- }
31
28
  loadPubSubClient() {
32
29
  return __awaiter(this, void 0, void 0, function* () {
33
30
  if (this.pubsubClient) {
@@ -48,16 +45,21 @@ class EmailHubClient {
48
45
  sendEmail(msg, options) {
49
46
  return __awaiter(this, void 0, void 0, function* () {
50
47
  yield this.loadPubSubClient();
51
- const xMailGuid = options && options.xMailGuid ? options.xMailGuid : uuid.v4();
48
+ const xMailGuid = msg && msg.CustomID ? msg.CustomID : uuid.v4();
52
49
  msg.CustomID = xMailGuid;
53
50
  const topic = options && options.priority && options.priority === EmailHubPriorityLevel.BULK ? 'send-new-email-bulk' : 'send-new-email';
54
51
  if (this.pubsubClient !== null) {
55
- yield this.pubsubClient.topic(`projects/xperience-prod/topics/${topic}`)
56
- .publishMessage({
57
- json: { sender_guid: this.sender.guid, sender_secret: this.sender.secret, payload: EmailHubClient.compressMessage(msg) },
58
- attributes: { sender_guid: this.sender.guid }
59
- });
60
- return xMailGuid;
52
+ try {
53
+ yield this.pubsubClient.topic(`projects/xperience-prod/topics/${topic}`)
54
+ .publishMessage({
55
+ 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') },
56
+ attributes: { sender_guid: this.sender.guid }
57
+ });
58
+ return xMailGuid;
59
+ }
60
+ catch (e) {
61
+ console.log('Failed to send email via PubSub queue. Falling back to Direct API connection.');
62
+ }
61
63
  }
62
64
  yield axios_1.default.post(`${this.server}/email/send`, msg, {
63
65
  headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/emailhub-client",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "CLXperience EmailHub Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",