@clxmedia/emailhub-client 2.0.1 → 2.0.3

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
@@ -47,8 +47,9 @@ export declare class EmailHubClient {
47
47
  private sender;
48
48
  private server;
49
49
  private pubsubClient;
50
- constructor(cfg: EmailHubConfig);
51
- static new(cfg: EmailHubConfig, extendedLogging?: boolean): EmailHubClient | MockEmailHubClient;
50
+ private directApiOnly;
51
+ constructor(cfg: EmailHubConfig, directApiOnly?: boolean);
52
+ static new(cfg: EmailHubConfig, extendedLogging?: boolean, directApiOnly?: boolean): EmailHubClient | MockEmailHubClient;
52
53
  private loadPubSubClient;
53
54
  static validateEmailAddress(email?: string, regex?: RegExp): boolean;
54
55
  createSenderProfile(domain: string): Promise<EmailHubSenderProfile>;
@@ -58,5 +59,8 @@ export declare class EmailHubClient {
58
59
  sendEmail(msg: EmailHubMessage, options?: {
59
60
  priority?: EmailHubPriorityLevel;
60
61
  writeToLog?: boolean;
61
- }): Promise<string>;
62
+ }): Promise<{
63
+ guid: string;
64
+ messageId?: string;
65
+ }>;
62
66
  }
package/dist/client.js CHANGED
@@ -78,16 +78,18 @@ class MockEmailHubClient {
78
78
  }
79
79
  exports.MockEmailHubClient = MockEmailHubClient;
80
80
  class EmailHubClient {
81
- constructor(cfg) {
81
+ constructor(cfg, directApiOnly = false) {
82
82
  this.environment = emailhub_1.EmailHubEnvironment.emailhub;
83
+ this.directApiOnly = false;
83
84
  this.sender = cfg.sender;
84
85
  this.server = cfg.server ? cfg.server : DEFAULT_EMAIL_HUB_URL;
86
+ this.directApiOnly = directApiOnly || false;
85
87
  }
86
- static new(cfg, extendedLogging = false) {
87
- return (cfg.sender.guid && cfg.sender.secret) ? new EmailHubClient(cfg) : new MockEmailHubClient(extendedLogging);
88
+ static new(cfg, extendedLogging = false, directApiOnly = false) {
89
+ return (cfg.sender.guid && cfg.sender.secret) ? new EmailHubClient(cfg, directApiOnly) : new MockEmailHubClient(extendedLogging);
88
90
  }
89
91
  async loadPubSubClient() {
90
- if (this.pubsubClient) {
92
+ if (this.pubsubClient || this.directApiOnly) {
91
93
  return;
92
94
  }
93
95
  try {
@@ -158,10 +160,13 @@ class EmailHubClient {
158
160
  console.log('Failed to send email via PubSub queue. Falling back to Direct API connection.');
159
161
  }
160
162
  }
161
- await axios_1.default.post(`${this.server}/email/send`, msg, {
163
+ const result = await axios_1.default.post(`${this.server}/email/send`, msg, {
162
164
  headers: { 'Content-Type': 'application/json', 'x-emailhub-sender-guid': this.sender.guid, 'x-emailhub-sender-secret': this.sender.secret }
163
165
  });
164
- return xMailGuid;
166
+ if (result.status !== 200) {
167
+ throw Error('Failed to send email.');
168
+ }
169
+ return { guid: xMailGuid, messageId: result.data };
165
170
  }
166
171
  }
167
172
  exports.EmailHubClient = EmailHubClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/emailhub-client",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "CLXperience EmailHub Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",
@@ -37,11 +37,12 @@
37
37
  },
38
38
  "repository": {
39
39
  "type": "git",
40
- "url": "https://github.com/adsupnow/xperience-clients/emailhub"
40
+ "url": "https://github.com/adsupnow/xperience-library/emailhub-client"
41
41
  },
42
- "bugs": "https://github.com/adsupnow/xperience-clients/emailhub",
42
+ "bugs": "https://github.com/adsupnow/xperience-library/emailhub-client",
43
43
  "peerDependencies": {},
44
44
  "dependencies": {
45
+ "@clxmedia/types": "1.0.16",
45
46
  "@google-cloud/pubsub": "4.3.3",
46
47
  "uuid": "9.0.1",
47
48
  "axios": "1.6.8",
@@ -50,7 +51,6 @@
50
51
  },
51
52
  "devDependencies": {
52
53
  "typescript": "^5.2.2",
53
- "@clxmedia/types": "1.0.15",
54
54
  "@types/node": "^20",
55
55
  "@types/jsonwebtoken": "9.0.6",
56
56
  "jest": "29.7.0",