@clxmedia/emailhub-client 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ RELEASE 1.0.0
2
+
3
+ Initial release
@@ -0,0 +1,31 @@
1
+ # Contributing
2
+
3
+ 1. [Fork it](https://help.github.com/articles/fork-a-repo/)
4
+ 2. Install dependencies (`npm install`)
5
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
6
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
7
+ 5. Test your changes (`npm test`)
8
+ 6. Push to the branch (`git push origin my-new-feature`)
9
+ 7. [Create new Pull Request](https://help.github.com/articles/creating-a-pull-request/)
10
+
11
+ ## Testing
12
+
13
+ We use [Jest](https://github.com/facebook/jest) to write tests. Run our test suite with this command:
14
+
15
+ ```
16
+ npm test
17
+ ```
18
+
19
+ ## Code Style
20
+
21
+ We use [Prettier](https://prettier.io/) and tslint to maintain code style and best practices.
22
+ Please make sure your PR adheres to the guides by running:
23
+
24
+ ```
25
+ npm run format
26
+ ```
27
+
28
+ and
29
+ ```
30
+ npm run lint
31
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 John Biundo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ <h1 align="center"></h1>
2
+
3
+ <h3 align="center">CLXperience EmailHub Client</h3>
4
+
5
+ ## Usage
6
+
7
+ Client connector for internal Conxversion Logix Xperience services.
8
+
9
+ ## Change Log
10
+
11
+ See [Changelog](CHANGELOG.md) for more information.
12
+
13
+ ## Author
14
+
15
+ **Brandon Thompson**
16
+
17
+ ## License
18
+
19
+ Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,48 @@
1
+ export declare enum EmailHubPriorityLevel {
2
+ NORMAL = "normal",
3
+ BULK = "bulk"
4
+ }
5
+ export interface EmailHubAttachment {
6
+ ContentType: string;
7
+ Filename: string;
8
+ Base64Content: string;
9
+ }
10
+ export interface EmailHubInlineAttachment extends EmailHubAttachment {
11
+ ContentID: string;
12
+ }
13
+ export interface EmailHubRecipient {
14
+ Email: string;
15
+ Name: string;
16
+ }
17
+ export interface EmailHubMessage {
18
+ From: {
19
+ Email: string;
20
+ Name: string;
21
+ };
22
+ To: EmailHubRecipient[];
23
+ Cc?: EmailHubRecipient[];
24
+ Bcc?: EmailHubRecipient[];
25
+ Subject: string;
26
+ TextPart?: string;
27
+ HTMLPart?: string;
28
+ CustomID?: string;
29
+ Attachments?: EmailHubAttachment[];
30
+ InlinedAttachments?: EmailHubInlineAttachment[];
31
+ }
32
+ export interface EmailHubSender {
33
+ guid: string;
34
+ secret: string;
35
+ }
36
+ export interface EmailHubConfig {
37
+ sender: EmailHubSender;
38
+ }
39
+ export declare class EmailHubClient {
40
+ private cloudPubSub;
41
+ private sender;
42
+ constructor(cfg: EmailHubConfig);
43
+ static compressMessage(msg: EmailHubMessage): string;
44
+ sendEmail(msg: EmailHubMessage, options?: {
45
+ priority?: EmailHubPriorityLevel;
46
+ xMailGuid?: string;
47
+ }): Promise<string>;
48
+ }
package/dist/client.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EmailHubClient = exports.EmailHubPriorityLevel = void 0;
13
+ const pubsub_1 = require("@google-cloud/pubsub");
14
+ const uuid = require("uuid");
15
+ const Pako = require("pako");
16
+ var EmailHubPriorityLevel;
17
+ (function (EmailHubPriorityLevel) {
18
+ EmailHubPriorityLevel["NORMAL"] = "normal";
19
+ EmailHubPriorityLevel["BULK"] = "bulk";
20
+ })(EmailHubPriorityLevel = exports.EmailHubPriorityLevel || (exports.EmailHubPriorityLevel = {}));
21
+ class EmailHubClient {
22
+ constructor(cfg) {
23
+ this.cloudPubSub = new pubsub_1.PubSub();
24
+ this.sender = cfg.sender;
25
+ }
26
+ static compressMessage(msg) {
27
+ return Buffer.from(Pako.deflate(Buffer.from(JSON.stringify(msg)).toString('base64'))).toString('base64');
28
+ }
29
+ sendEmail(msg, options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const xMailGuid = options && options.xMailGuid ? options.xMailGuid : uuid.v4();
32
+ msg.CustomID = xMailGuid;
33
+ const topic = options && options.priority && options.priority === EmailHubPriorityLevel.BULK ? 'send-new-email-bulk' : 'send-new-email';
34
+ yield this.cloudPubSub.topic(`projects/xperience-prod/topics/${topic}`)
35
+ .publishMessage({
36
+ json: { sender_guid: this.sender.guid, sender_secret: this.sender.secret, payload: EmailHubClient.compressMessage(msg) },
37
+ attributes: { sender_guid: this.sender.guid }
38
+ });
39
+ return xMailGuid;
40
+ });
41
+ }
42
+ }
43
+ exports.EmailHubClient = EmailHubClient;
@@ -0,0 +1 @@
1
+ export { EmailHubClient, EmailHubMessage, EmailHubAttachment, EmailHubConfig, EmailHubInlineAttachment, EmailHubRecipient, EmailHubPriorityLevel, EmailHubSender } from './client';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailHubPriorityLevel = exports.EmailHubClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "EmailHubClient", { enumerable: true, get: function () { return client_1.EmailHubClient; } });
6
+ Object.defineProperty(exports, "EmailHubPriorityLevel", { enumerable: true, get: function () { return client_1.EmailHubPriorityLevel; } });
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@clxmedia/emailhub-client",
3
+ "version": "1.0.0",
4
+ "description": "CLXperience EmailHub Client",
5
+ "author": "Brandon Thompson <brandont@clxmedia.com>",
6
+ "license": "MIT",
7
+ "readmeFilename": "README.md",
8
+ "main": "dist/client.js",
9
+ "typings": "dist/client.d.ts",
10
+ "files": [
11
+ "dist/**/*",
12
+ "*.md"
13
+ ],
14
+ "scripts": {
15
+ "start:dev": "tsc -w",
16
+ "build": "tsc",
17
+ "prepare": "npm run build",
18
+ "format": "prettier --write \"src/**/*.ts\"",
19
+ "lint": "tslint -p tsconfig.json -c tslint.json",
20
+ "test": "jest",
21
+ "test:watch": "jest --watch",
22
+ "test:cov": "jest --coverage",
23
+ "test:e2e": "jest --config ./test/jest-e2e.json"
24
+ },
25
+ "keywords": [
26
+ "nestjs"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/adsupnow/xperience-clients/emailhub"
34
+ },
35
+ "bugs": "https://github.com/adsupnow/xperience-clients/emailhub",
36
+ "peerDependencies": {},
37
+ "dependencies": {
38
+ "@google-cloud/pubsub": "^3.6.0",
39
+ "pako": "^2.1.0",
40
+ "uuid": "^9.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/jest": "28.1.7",
44
+ "@types/node": "^20.1.7",
45
+ "@types/supertest": "2.0.12",
46
+ "jest": "28.1.3",
47
+ "prettier": "2.7.1",
48
+ "supertest": "6.2.4",
49
+ "ts-jest": "28.0.8",
50
+ "ts-node": "10.9.1",
51
+ "tsc-watch": "5.0.3",
52
+ "tsconfig-paths": "4.1.0",
53
+ "tslint": "6.1.3",
54
+ "typescript": "4.7.4"
55
+ },
56
+ "jest": {
57
+ "moduleFileExtensions": [
58
+ "js",
59
+ "json",
60
+ "ts"
61
+ ],
62
+ "rootDir": "src",
63
+ "testRegex": ".spec.ts$",
64
+ "transform": {
65
+ "^.+\\.(t|j)s$": "ts-jest"
66
+ },
67
+ "coverageDirectory": "../coverage",
68
+ "testEnvironment": "node"
69
+ }
70
+ }