@flink-app/email-plugin 0.2.0-beta.15 → 0.2.0-beta.18

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.
@@ -0,0 +1,17 @@
1
+ import { emailFlowmailer as email } from "./schemas/emailFlowmailer";
2
+ import { client } from "./schemas/client";
3
+ export interface flowmailerClientOptions {
4
+ client_id: string;
5
+ client_secrect: string;
6
+ account_id: string;
7
+ }
8
+ export declare class flowMailerClient implements client {
9
+ accessToken: string;
10
+ client_id: string;
11
+ client_secrect: string;
12
+ account_id: string;
13
+ constructor(options: flowmailerClientOptions);
14
+ getToken(): Promise<void>;
15
+ sendEmail(email: email, to: string): Promise<boolean>;
16
+ send(email: email): Promise<boolean>;
17
+ }
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.flowMailerClient = void 0;
54
+ var axios_1 = __importDefault(require("axios"));
55
+ var querystring_1 = __importDefault(require("querystring"));
56
+ var flowMailerClient = /** @class */ (function () {
57
+ function flowMailerClient(options) {
58
+ this.accessToken = "";
59
+ this.client_id = options.client_id;
60
+ this.client_secrect = options.client_secrect;
61
+ this.account_id = options.account_id;
62
+ }
63
+ flowMailerClient.prototype.getToken = function () {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var resp, ex_1;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ _a.trys.push([0, 2, , 3]);
70
+ return [4 /*yield*/, axios_1.default.post("https://login.flowmailer.net/oauth/token", querystring_1.default.stringify({
71
+ client_id: this.client_id,
72
+ client_secret: this.client_secrect,
73
+ grant_type: "client_credentials",
74
+ scope: "api",
75
+ }), {
76
+ headers: {
77
+ "Content-Type": "application/x-www-form-urlencoded",
78
+ },
79
+ })];
80
+ case 1:
81
+ resp = _a.sent();
82
+ if (resp.status == 200) {
83
+ this.accessToken = resp.data.access_token;
84
+ }
85
+ return [3 /*break*/, 3];
86
+ case 2:
87
+ ex_1 = _a.sent();
88
+ return [3 /*break*/, 3];
89
+ case 3: return [2 /*return*/];
90
+ }
91
+ });
92
+ });
93
+ };
94
+ flowMailerClient.prototype.sendEmail = function (email, to) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var data, resp, ex_2;
97
+ var _a, _b;
98
+ return __generator(this, function (_c) {
99
+ switch (_c.label) {
100
+ case 0:
101
+ data = {
102
+ messageType: "EMAIL",
103
+ senderAddress: email.from,
104
+ recipientAddress: to,
105
+ subject: email.subject,
106
+ text: email.text,
107
+ html: email.html,
108
+ };
109
+ if (email.attachments) {
110
+ data = __assign(__assign({}, data), { attachments: email.attachments.map(function (a) { return (__assign(__assign({}, a), { disposition: "attachment" })); }) });
111
+ }
112
+ _c.label = 1;
113
+ case 1:
114
+ _c.trys.push([1, 3, , 4]);
115
+ return [4 /*yield*/, axios_1.default.post("https://api.flowmailer.net/".concat(this.account_id, "/messages/submit"), data, {
116
+ headers: {
117
+ Accept: "application/vnd.flowmailer.v1.12+json",
118
+ "Content-Type": "application/vnd.flowmailer.v1.12+json;charset=UTF-8",
119
+ Authorization: "Bearer ".concat(this.accessToken),
120
+ },
121
+ })];
122
+ case 2:
123
+ resp = _c.sent();
124
+ if (resp.status == 201)
125
+ return [2 /*return*/, true];
126
+ return [3 /*break*/, 4];
127
+ case 3:
128
+ ex_2 = _c.sent();
129
+ if (((_b = (_a = ex_2 === null || ex_2 === void 0 ? void 0 : ex_2.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) != "invalid_token") {
130
+ }
131
+ return [3 /*break*/, 4];
132
+ case 4: return [2 /*return*/, false];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ flowMailerClient.prototype.send = function (email) {
138
+ return __awaiter(this, void 0, void 0, function () {
139
+ var failure, _a, _b, _c, _i, i, success;
140
+ return __generator(this, function (_d) {
141
+ switch (_d.label) {
142
+ case 0:
143
+ failure = false;
144
+ _a = email.to;
145
+ _b = [];
146
+ for (_c in _a)
147
+ _b.push(_c);
148
+ _i = 0;
149
+ _d.label = 1;
150
+ case 1:
151
+ if (!(_i < _b.length)) return [3 /*break*/, 8];
152
+ _c = _b[_i];
153
+ if (!(_c in _a)) return [3 /*break*/, 7];
154
+ i = _c;
155
+ if (!this.client_secrect) {
156
+ this.getToken();
157
+ }
158
+ return [4 /*yield*/, this.sendEmail(email, email.to[i])];
159
+ case 2:
160
+ success = _d.sent();
161
+ if (!!success) return [3 /*break*/, 4];
162
+ return [4 /*yield*/, this.getToken()];
163
+ case 3:
164
+ _d.sent();
165
+ return [3 /*break*/, 5];
166
+ case 4: return [3 /*break*/, 7];
167
+ case 5: return [4 /*yield*/, this.sendEmail(email, email.to[i])];
168
+ case 6:
169
+ success = _d.sent();
170
+ if (!success)
171
+ failure = true;
172
+ _d.label = 7;
173
+ case 7:
174
+ _i++;
175
+ return [3 /*break*/, 1];
176
+ case 8: return [2 /*return*/, !failure];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ return flowMailerClient;
182
+ }());
183
+ exports.flowMailerClient = flowMailerClient;
@@ -0,0 +1,30 @@
1
+ export type emailFlowmailer = {
2
+ /**
3
+ * From address used to send the email
4
+ */
5
+ from: string;
6
+ /**
7
+ * Email addresses to send to
8
+ */
9
+ to: string[];
10
+ /**
11
+ * Reply email
12
+ */
13
+ replyTo?: string;
14
+ /**
15
+ * Email addresses to add as BCC
16
+ */
17
+ bcc?: string[];
18
+ /**
19
+ * Subject of email
20
+ */
21
+ subject: string;
22
+ text?: string;
23
+ html?: string;
24
+ attachments?: fowmailerAttachment[];
25
+ };
26
+ export type fowmailerAttachment = {
27
+ content: string;
28
+ contentType: string;
29
+ filename: string;
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/email-plugin",
3
- "version": "0.2.0-beta.15",
3
+ "version": "0.2.0-beta.18",
4
4
  "description": "Flink plugin that makes it possible to send email",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -19,10 +19,10 @@
19
19
  "nodemailer": "^6.6.2"
20
20
  },
21
21
  "devDependencies": {
22
- "@flink-app/flink": "^0.2.0-beta.15",
22
+ "@flink-app/flink": "^0.2.0-beta.18",
23
23
  "@types/node": "^15.6.2",
24
24
  "ts-node": "^9.1.1",
25
25
  "typescript": "^4.2.4"
26
26
  },
27
- "gitHead": "798ef9a11c291c0b16ed937436dd46986942546c"
27
+ "gitHead": "aaeadba35673b13654a54bf752fef3ecc4c94b52"
28
28
  }
@@ -1,6 +0,0 @@
1
- export interface sendgridClientOptions {
2
- /**
3
- * API-key to use when sending email
4
- */
5
- apiKey: string;
6
- }
@@ -1,9 +0,0 @@
1
- export interface smtpClientOptions {
2
- host: string;
3
- port: number;
4
- secure: boolean;
5
- auth?: {
6
- user: string;
7
- pass: string;
8
- };
9
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });