@clxmedia/emailhub-client 1.1.3 → 1.1.5

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
@@ -64,12 +64,56 @@ export interface EmailHubSenderProfile {
64
64
  updated_at?: string;
65
65
  verified_at?: string;
66
66
  }
67
+ export declare class MockEmailHubClient {
68
+ readonly environment: EmailHubEnvironment;
69
+ private extendedLogging;
70
+ constructor(extendedLogging?: boolean);
71
+ createSenderProfile(_domain: string): Promise<{
72
+ guid: string;
73
+ id: number;
74
+ domain_name: string;
75
+ domain_id: string;
76
+ mailjet_sender_id: string;
77
+ dkim_txt_name: string;
78
+ dkim_txt_value: string;
79
+ dkim_status: string;
80
+ token_txt_name: string;
81
+ token_txt_value: string;
82
+ spf_txt_value: string;
83
+ spf_status: string;
84
+ created_at: string;
85
+ updated_at?: string;
86
+ verified_at?: string;
87
+ }>;
88
+ checkSenderProfile(domainGuid: string): Promise<{
89
+ guid: string;
90
+ verified_at: string;
91
+ id: number;
92
+ domain_name: string;
93
+ domain_id: string;
94
+ mailjet_sender_id: string;
95
+ dkim_txt_name: string;
96
+ dkim_txt_value: string;
97
+ dkim_status: string;
98
+ token_txt_name: string;
99
+ token_txt_value: string;
100
+ spf_txt_value: string;
101
+ spf_status: string;
102
+ created_at: string;
103
+ updated_at?: string;
104
+ }>;
105
+ deleteSenderProfile(): Promise<void>;
106
+ sendEmail(msg: EmailHubMessage, options?: {
107
+ priority?: EmailHubPriorityLevel;
108
+ }): Promise<string>;
109
+ }
67
110
  export declare class EmailHubClient {
68
111
  readonly environment: EmailHubEnvironment;
69
112
  private sender;
70
113
  private server;
71
114
  private pubsubClient;
72
115
  constructor(cfg: EmailHubConfig);
116
+ static new(cfg: EmailHubConfig, extendedLogging?: boolean): EmailHubClient | MockEmailHubClient;
73
117
  private loadPubSubClient;
74
118
  static validateEmailAddress(email?: string, regex?: RegExp): boolean;
75
119
  createSenderProfile(domain: string): Promise<EmailHubSenderProfile>;
@@ -78,5 +122,6 @@ export declare class EmailHubClient {
78
122
  deleteSenderProfile(domainGuid: string): Promise<HttpStatusCode>;
79
123
  sendEmail(msg: EmailHubMessage, options?: {
80
124
  priority?: EmailHubPriorityLevel;
125
+ writeToLog?: boolean;
81
126
  }): Promise<string>;
82
127
  }
package/dist/client.js CHANGED
@@ -9,8 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.EmailHubClient = exports.EmailHubEnvironment = exports.EmailHubPriorityLevel = void 0;
12
+ exports.EmailHubClient = exports.MockEmailHubClient = exports.EmailHubEnvironment = exports.EmailHubPriorityLevel = void 0;
13
13
  const pubsub_1 = require("@google-cloud/pubsub");
14
+ const luxon_1 = require("luxon");
14
15
  const uuid = require("uuid");
15
16
  const Pako = require("pako");
16
17
  const axios_1 = require("axios");
@@ -26,12 +27,64 @@ var EmailHubEnvironment;
26
27
  })(EmailHubEnvironment = exports.EmailHubEnvironment || (exports.EmailHubEnvironment = {}));
27
28
  const DEFAULT_EMAIL_HUB_URL = 'https://emailhub.clxp.us';
28
29
  const DEFAULT_EMAIL_REGEX = /^([a-z0-9])([a-z\.0-9_%\-\+\*'’!#`&\$/]*)@(.+)\.(.+)$/;
30
+ const mockEmailHubSenderProfile = {
31
+ id: 1,
32
+ guid: 'mock-guid',
33
+ domain_name: 'mock-domain-name',
34
+ domain_id: 'mock-domain-id',
35
+ mailjet_sender_id: 'mock-mailjet-sender-id',
36
+ dkim_txt_name: 'mock-dkim-txt-name',
37
+ dkim_txt_value: 'mock-dkim-txt-value',
38
+ dkim_status: 'OK',
39
+ token_txt_name: 'mock-token-txt-name',
40
+ token_txt_value: 'mock-token-txt-value',
41
+ spf_txt_value: 'mock-spf-txt-value',
42
+ spf_status: 'Error',
43
+ created_at: luxon_1.DateTime.local().toISO(),
44
+ updated_at: luxon_1.DateTime.local().toISO(),
45
+ verified_at: undefined
46
+ };
47
+ class MockEmailHubClient {
48
+ constructor(extendedLogging = false) {
49
+ this.environment = EmailHubEnvironment.localhost;
50
+ this.extendedLogging = extendedLogging;
51
+ }
52
+ createSenderProfile(_domain) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: uuid.v4() });
55
+ });
56
+ }
57
+ checkSenderProfile(domainGuid) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return Object.assign(Object.assign({}, mockEmailHubSenderProfile), { guid: domainGuid, verified_at: luxon_1.DateTime.local().toISO() });
60
+ });
61
+ }
62
+ deleteSenderProfile() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return;
65
+ });
66
+ }
67
+ sendEmail(msg, options) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ if (this.extendedLogging) {
70
+ console.log(`----------------Begin mock email send: Priority: [${(options === null || options === void 0 ? void 0 : options.priority) || 'default'}]-----------------`);
71
+ console.log(JSON.stringify(msg));
72
+ console.log('----------------End mock email send-----------------');
73
+ }
74
+ return uuid.v4();
75
+ });
76
+ }
77
+ }
78
+ exports.MockEmailHubClient = MockEmailHubClient;
29
79
  class EmailHubClient {
30
80
  constructor(cfg) {
31
81
  this.environment = EmailHubEnvironment.emailhub;
32
82
  this.sender = cfg.sender;
33
83
  this.server = cfg.server ? cfg.server : DEFAULT_EMAIL_HUB_URL;
34
84
  }
85
+ static new(cfg, extendedLogging = false) {
86
+ return (cfg.sender.guid && cfg.sender.secret) ? new EmailHubClient(cfg) : new MockEmailHubClient(extendedLogging);
87
+ }
35
88
  loadPubSubClient() {
36
89
  return __awaiter(this, void 0, void 0, function* () {
37
90
  if (this.pubsubClient) {
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { EmailHubClient, EmailHubMessage, EmailHubAttachment, EmailHubConfig, EmailHubInlineAttachment, EmailHubRecipient, EmailHubPriorityLevel, EmailHubSender } from './client';
1
+ export { EmailHubClient, EmailHubMessage, EmailHubAttachment, EmailHubConfig, EmailHubInlineAttachment, EmailHubRecipient, EmailHubPriorityLevel, EmailHubSender, MockEmailHubClient, EmailHubEnvironment, EmailHubSenderProfile } from './client';
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailHubPriorityLevel = exports.EmailHubClient = void 0;
3
+ exports.EmailHubEnvironment = exports.MockEmailHubClient = exports.EmailHubPriorityLevel = exports.EmailHubClient = void 0;
4
4
  var client_1 = require("./client");
5
5
  Object.defineProperty(exports, "EmailHubClient", { enumerable: true, get: function () { return client_1.EmailHubClient; } });
6
6
  Object.defineProperty(exports, "EmailHubPriorityLevel", { enumerable: true, get: function () { return client_1.EmailHubPriorityLevel; } });
7
+ Object.defineProperty(exports, "MockEmailHubClient", { enumerable: true, get: function () { return client_1.MockEmailHubClient; } });
8
+ Object.defineProperty(exports, "EmailHubEnvironment", { enumerable: true, get: function () { return client_1.EmailHubEnvironment; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/emailhub-client",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "CLXperience EmailHub Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",
@@ -37,12 +37,14 @@
37
37
  "dependencies": {
38
38
  "@google-cloud/pubsub": "^3.6.0",
39
39
  "axios": "^1.4.0",
40
+ "luxon": "^3.3.0",
40
41
  "pako": "^2.1.0",
41
42
  "uuid": "^9.0.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@types/axios": "^0.14.0",
45
46
  "@types/jest": "28.1.7",
47
+ "@types/luxon": "^3.3.0",
46
48
  "@types/node": "^20.1.7",
47
49
  "@types/pako": "^2.0.0",
48
50
  "@types/supertest": "2.0.12",