@creator.co/wapi 1.2.3 → 1.2.4
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/.github/workflows/npmpublish.yml +2 -5
- package/README.md +1 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +34 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +64 -0
- package/dist/src/API/Request.d.ts +140 -0
- package/dist/src/API/Request.js +182 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +256 -0
- package/dist/src/API/Response.js +398 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/API/Utils.d.ts +63 -0
- package/dist/src/API/Utils.js +104 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
- package/dist/src/BaseEvent/EventProcessor.js +182 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +74 -0
- package/dist/src/BaseEvent/Process.js +142 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +29 -0
- package/dist/src/BaseEvent/Transaction.js +244 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +131 -0
- package/dist/src/Config/Configuration.js +153 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +101 -0
- package/dist/src/Config/EnvironmentVar.js +213 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +57 -0
- package/dist/src/Crypto/Crypto.js +126 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Crypto/JWT.d.ts +64 -0
- package/dist/src/Crypto/JWT.js +74 -0
- package/dist/src/Crypto/JWT.js.map +1 -0
- package/dist/src/Globals.d.ts +161 -0
- package/dist/src/Globals.js +173 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +180 -0
- package/dist/src/Logger/Logger.js +412 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +107 -0
- package/dist/src/Mailer/Mailer.js +313 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +47 -0
- package/dist/src/Publisher/Publisher.js +141 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +41 -0
- package/dist/src/Server/RouteResolver.js +135 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +104 -0
- package/dist/src/Server/Router.js +45 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
- package/dist/src/Server/lib/ContainerServer.js +143 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +60 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +45 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
- package/dist/src/Server/lib/container/Proxy.js +201 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +18 -0
- package/dist/src/Server/lib/container/Utils.js +84 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +21 -0
- package/dist/src/Validation/Validator.js +48 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/jest.config.ts +1 -8
- package/package.json +3 -3
|
@@ -0,0 +1,313 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
var SES = require("@aws-sdk/client-ses");
|
|
62
|
+
var credential_provider_node_1 = require("@aws-sdk/credential-provider-node");
|
|
63
|
+
var Email = require("email-templates");
|
|
64
|
+
var nodemailer = require("nodemailer");
|
|
65
|
+
/**
|
|
66
|
+
* ${1:Description placeholder}
|
|
67
|
+
*
|
|
68
|
+
* @export
|
|
69
|
+
* @class Mailer
|
|
70
|
+
* @typedef {Mailer}
|
|
71
|
+
*/
|
|
72
|
+
var Mailer = /** @class */ (function () {
|
|
73
|
+
/**
|
|
74
|
+
* Creates an instance of Mailer.
|
|
75
|
+
*
|
|
76
|
+
* @constructor
|
|
77
|
+
* @param {string} defaultFrom
|
|
78
|
+
* @param {string} region
|
|
79
|
+
*/
|
|
80
|
+
function Mailer(defaultFrom, region) {
|
|
81
|
+
/**
|
|
82
|
+
* ${1:Description placeholder}
|
|
83
|
+
*
|
|
84
|
+
* @private
|
|
85
|
+
* @readonly
|
|
86
|
+
* @type {string}
|
|
87
|
+
*/
|
|
88
|
+
this.templateDefaultFile = 'html';
|
|
89
|
+
this.from = defaultFrom;
|
|
90
|
+
this.transporter = nodemailer.createTransport({
|
|
91
|
+
SES: {
|
|
92
|
+
ses: new SES.SESClient({
|
|
93
|
+
credentials: (0, credential_provider_node_1.defaultProvider)(),
|
|
94
|
+
apiVersion: '2010-12-01',
|
|
95
|
+
region: region,
|
|
96
|
+
}),
|
|
97
|
+
aws: SES,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* ${1:Description placeholder}
|
|
103
|
+
*
|
|
104
|
+
* @public
|
|
105
|
+
* @async
|
|
106
|
+
* @param {(string | Array<string>)} to
|
|
107
|
+
* @param {string} htmlMessage
|
|
108
|
+
* @param {string} subject
|
|
109
|
+
* @param {?(string | Array<string>)} [optionalCC]
|
|
110
|
+
* @param {?string} [optionalFrom]
|
|
111
|
+
* @param {?string} [optionalReplyTo]
|
|
112
|
+
* @param {?any[]} [optionalAttachments]
|
|
113
|
+
* @param {?Email.NodeMailerTransportOptions} [optionalTransport]
|
|
114
|
+
* @returns {unknown}
|
|
115
|
+
*/
|
|
116
|
+
Mailer.prototype.sendRawEmail = function (to, htmlMessage, subject, optionalCC, optionalFrom, optionalReplyTo,
|
|
117
|
+
// TODO: improve attachment type -> Attachment
|
|
118
|
+
optionalAttachments, optionalTransport) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var email, resp, e_1;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
switch (_a.label) {
|
|
123
|
+
case 0:
|
|
124
|
+
email = new Email({
|
|
125
|
+
message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject: subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
126
|
+
transport: optionalTransport || this.transporter,
|
|
127
|
+
send: true,
|
|
128
|
+
});
|
|
129
|
+
resp = null;
|
|
130
|
+
_a.label = 1;
|
|
131
|
+
case 1:
|
|
132
|
+
_a.trys.push([1, 3, , 4]);
|
|
133
|
+
return [4 /*yield*/, email.send()];
|
|
134
|
+
case 2:
|
|
135
|
+
resp = _a.sent();
|
|
136
|
+
console.debug('Mailer resp:', resp);
|
|
137
|
+
return [3 /*break*/, 4];
|
|
138
|
+
case 3:
|
|
139
|
+
e_1 = _a.sent();
|
|
140
|
+
console.error('Mailer error:', e_1);
|
|
141
|
+
throw e_1;
|
|
142
|
+
case 4: return [2 /*return*/, resp];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* ${1:Description placeholder}
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
* @async
|
|
152
|
+
* @param {(string | Array<string>)} to
|
|
153
|
+
* @param {(string | Array<string>)} templates
|
|
154
|
+
* @param {object} data
|
|
155
|
+
* @param {?(string | Array<string>)} [optionalCC]
|
|
156
|
+
* @param {?string} [optionalFrom]
|
|
157
|
+
* @param {?string} [optionalReplyTo]
|
|
158
|
+
* @param {?any[]} [optionalAttachments]
|
|
159
|
+
* @param {?Email.NodeMailerTransportOptions} [optionalTransport]
|
|
160
|
+
* @returns {unknown}
|
|
161
|
+
*/
|
|
162
|
+
Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
|
|
163
|
+
// TODO: improve attachment type -> Attachment
|
|
164
|
+
optionalAttachments, optionalTransport) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var email, resp, chosenTemplate, e_2;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
email = new Email({
|
|
171
|
+
message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
172
|
+
transport: optionalTransport || this.transporter,
|
|
173
|
+
send: true,
|
|
174
|
+
});
|
|
175
|
+
resp = null;
|
|
176
|
+
_a.label = 1;
|
|
177
|
+
case 1:
|
|
178
|
+
_a.trys.push([1, 4, , 5]);
|
|
179
|
+
return [4 /*yield*/, this.chooseTemplate(templates, data)];
|
|
180
|
+
case 2:
|
|
181
|
+
chosenTemplate = _a.sent();
|
|
182
|
+
return [4 /*yield*/, email.send({ template: chosenTemplate, locals: data })];
|
|
183
|
+
case 3:
|
|
184
|
+
resp = _a.sent();
|
|
185
|
+
console.debug('Mailer resp:', resp);
|
|
186
|
+
return [3 /*break*/, 5];
|
|
187
|
+
case 4:
|
|
188
|
+
e_2 = _a.sent();
|
|
189
|
+
console.error('Mailer error:', e_2);
|
|
190
|
+
throw e_2;
|
|
191
|
+
case 5: return [2 /*return*/, resp];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* ${1:Description placeholder}
|
|
198
|
+
*
|
|
199
|
+
* @public
|
|
200
|
+
* @param {string} host
|
|
201
|
+
* @param {number} portNumber
|
|
202
|
+
* @param {string} user
|
|
203
|
+
* @param {string} password
|
|
204
|
+
* @returns {Email.NodeMailerTransportOptions}
|
|
205
|
+
*/
|
|
206
|
+
Mailer.prototype.newSMTPTransporter = function (host, portNumber, user, password) {
|
|
207
|
+
var smtpTransporter = nodemailer.createTransport({
|
|
208
|
+
host: host,
|
|
209
|
+
port: portNumber,
|
|
210
|
+
connectionTimeout: 2000,
|
|
211
|
+
auth: {
|
|
212
|
+
user: user,
|
|
213
|
+
pass: password,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return smtpTransporter;
|
|
217
|
+
};
|
|
218
|
+
/* private */
|
|
219
|
+
/**
|
|
220
|
+
* ${1:Description placeholder}
|
|
221
|
+
*
|
|
222
|
+
* @private
|
|
223
|
+
* @async
|
|
224
|
+
* @param {(string | Array<string>)} templates
|
|
225
|
+
* @param {object} data
|
|
226
|
+
* @returns {Promise<string>}
|
|
227
|
+
*/
|
|
228
|
+
Mailer.prototype.chooseTemplate = function (templates, data) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
230
|
+
var templates_1, templates_1_1, template, e_3_1;
|
|
231
|
+
var e_3, _a;
|
|
232
|
+
return __generator(this, function (_b) {
|
|
233
|
+
switch (_b.label) {
|
|
234
|
+
case 0:
|
|
235
|
+
if (!Array.isArray(templates)) return [3 /*break*/, 9];
|
|
236
|
+
_b.label = 1;
|
|
237
|
+
case 1:
|
|
238
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
239
|
+
templates_1 = __values(templates), templates_1_1 = templates_1.next();
|
|
240
|
+
_b.label = 2;
|
|
241
|
+
case 2:
|
|
242
|
+
if (!!templates_1_1.done) return [3 /*break*/, 5];
|
|
243
|
+
template = templates_1_1.value;
|
|
244
|
+
return [4 /*yield*/, this.canRenderTemplate(template, data)];
|
|
245
|
+
case 3:
|
|
246
|
+
if (_b.sent())
|
|
247
|
+
return [2 /*return*/, template];
|
|
248
|
+
_b.label = 4;
|
|
249
|
+
case 4:
|
|
250
|
+
templates_1_1 = templates_1.next();
|
|
251
|
+
return [3 /*break*/, 2];
|
|
252
|
+
case 5: return [3 /*break*/, 8];
|
|
253
|
+
case 6:
|
|
254
|
+
e_3_1 = _b.sent();
|
|
255
|
+
e_3 = { error: e_3_1 };
|
|
256
|
+
return [3 /*break*/, 8];
|
|
257
|
+
case 7:
|
|
258
|
+
try {
|
|
259
|
+
if (templates_1_1 && !templates_1_1.done && (_a = templates_1.return)) _a.call(templates_1);
|
|
260
|
+
}
|
|
261
|
+
finally { if (e_3) throw e_3.error; }
|
|
262
|
+
return [7 /*endfinally*/];
|
|
263
|
+
case 8: return [3 /*break*/, 11];
|
|
264
|
+
case 9:
|
|
265
|
+
if (!templates) return [3 /*break*/, 11];
|
|
266
|
+
return [4 /*yield*/, this.canRenderTemplate(templates, data)];
|
|
267
|
+
case 10:
|
|
268
|
+
if (_b.sent())
|
|
269
|
+
return [2 /*return*/, templates];
|
|
270
|
+
_b.label = 11;
|
|
271
|
+
case 11: throw new Error("Could not render email with template ".concat(templates, " and following data. Please, check logs above! ") +
|
|
272
|
+
JSON.stringify(data, null, 2));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* ${1:Description placeholder}
|
|
279
|
+
*
|
|
280
|
+
* @private
|
|
281
|
+
* @async
|
|
282
|
+
* @param {string} template
|
|
283
|
+
* @param {object} data
|
|
284
|
+
* @returns {Promise<boolean>}
|
|
285
|
+
*/
|
|
286
|
+
Mailer.prototype.canRenderTemplate = function (template, data) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
var validRenderResp, email, e_4;
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
switch (_a.label) {
|
|
291
|
+
case 0:
|
|
292
|
+
validRenderResp = null;
|
|
293
|
+
_a.label = 1;
|
|
294
|
+
case 1:
|
|
295
|
+
_a.trys.push([1, 3, , 4]);
|
|
296
|
+
email = new Email();
|
|
297
|
+
return [4 /*yield*/, email.render("".concat(template, "/").concat(this.templateDefaultFile), data)];
|
|
298
|
+
case 2:
|
|
299
|
+
validRenderResp = _a.sent();
|
|
300
|
+
return [3 /*break*/, 4];
|
|
301
|
+
case 3:
|
|
302
|
+
e_4 = _a.sent();
|
|
303
|
+
console.log("Error while checking renderability of email template ".concat(template), e_4);
|
|
304
|
+
return [3 /*break*/, 4];
|
|
305
|
+
case 4: return [2 /*return*/, validRenderResp != null];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
return Mailer;
|
|
311
|
+
}());
|
|
312
|
+
exports.default = Mailer;
|
|
313
|
+
//# sourceMappingURL=Mailer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAC1C,8EAAmE;AACnE,uCAAwC;AACxC,uCAAwC;AAGxC;;;;;;GAMG;AACH;IA6BE;;;;;;OAMG;IACH,gBAAY,WAAmB,EAAE,MAAc;QA3B/C;;;;;;WAMG;QACc,wBAAmB,GAAW,MAAM,CAAA;QAqBnD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC5C,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,GAAG,CA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;4BAEpF,sBAAO,eAAe,IAAI,IAAI,EAAA;;;;KAC/B;IACH,aAAC;AAAD,CAAC,AA9ND,IA8NC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PublishCommandOutput } from '@aws-sdk/client-sns';
|
|
2
|
+
/**
|
|
3
|
+
* ${1:Description placeholder}
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @typedef {PublisherConfig}
|
|
7
|
+
*/
|
|
8
|
+
export type PublisherConfig = {
|
|
9
|
+
region?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* ${1:Description placeholder}
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @class Publisher
|
|
16
|
+
* @typedef {Publisher}
|
|
17
|
+
*/
|
|
18
|
+
export default class Publisher {
|
|
19
|
+
/**
|
|
20
|
+
* ${1:Description placeholder}
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
private region;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an instance of Publisher.
|
|
28
|
+
*
|
|
29
|
+
* @constructor
|
|
30
|
+
* @param {?PublisherConfig} [config]
|
|
31
|
+
*/
|
|
32
|
+
constructor(config?: PublisherConfig);
|
|
33
|
+
/**
|
|
34
|
+
* ${1:Description placeholder}
|
|
35
|
+
*
|
|
36
|
+
* @async
|
|
37
|
+
* @param {*} messageObject
|
|
38
|
+
* @param {string} topic
|
|
39
|
+
* @param {?object} [additionalProps]
|
|
40
|
+
* @returns {Promise<PublishCommandOutput>}
|
|
41
|
+
*/
|
|
42
|
+
publishOnTopic(messageObject: any, topic: string, additionalProps?: object): Promise<PublishCommandOutput>;
|
|
43
|
+
/**
|
|
44
|
+
* ${1:Description placeholder}
|
|
45
|
+
*/
|
|
46
|
+
_connect(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var client_sns_1 = require("@aws-sdk/client-sns");
|
|
51
|
+
var sha1 = require("sha1");
|
|
52
|
+
//reusable client
|
|
53
|
+
// eslint-disable-next-line no-var
|
|
54
|
+
/**
|
|
55
|
+
* ${1:Description placeholder}
|
|
56
|
+
*
|
|
57
|
+
* @type {(SNSClient | null)}
|
|
58
|
+
*/
|
|
59
|
+
var PUBLISHER_CONN = null;
|
|
60
|
+
// eslint-disable-next-line no-var
|
|
61
|
+
/**
|
|
62
|
+
* ${1:Description placeholder}
|
|
63
|
+
*
|
|
64
|
+
* @type {(string | null)}
|
|
65
|
+
*/
|
|
66
|
+
var PUBLISHER_CONN_HASH = null;
|
|
67
|
+
//
|
|
68
|
+
/**
|
|
69
|
+
* ${1:Description placeholder}
|
|
70
|
+
*
|
|
71
|
+
* @export
|
|
72
|
+
* @class Publisher
|
|
73
|
+
* @typedef {Publisher}
|
|
74
|
+
*/
|
|
75
|
+
var Publisher = /** @class */ (function () {
|
|
76
|
+
/**
|
|
77
|
+
* Creates an instance of Publisher.
|
|
78
|
+
*
|
|
79
|
+
* @constructor
|
|
80
|
+
* @param {?PublisherConfig} [config]
|
|
81
|
+
*/
|
|
82
|
+
function Publisher(config) {
|
|
83
|
+
if (config && config.region) {
|
|
84
|
+
this.region = config.region;
|
|
85
|
+
// console.debug(`Using region: ${this.region}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/* Public */
|
|
89
|
+
/**
|
|
90
|
+
* ${1:Description placeholder}
|
|
91
|
+
*
|
|
92
|
+
* @async
|
|
93
|
+
* @param {*} messageObject
|
|
94
|
+
* @param {string} topic
|
|
95
|
+
* @param {?object} [additionalProps]
|
|
96
|
+
* @returns {Promise<PublishCommandOutput>}
|
|
97
|
+
*/
|
|
98
|
+
Publisher.prototype.publishOnTopic = function (messageObject, topic, additionalProps) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var resp, params, e_1;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
resp = null;
|
|
105
|
+
_a.label = 1;
|
|
106
|
+
case 1:
|
|
107
|
+
_a.trys.push([1, 3, , 4]);
|
|
108
|
+
this._connect();
|
|
109
|
+
params = __assign({ Message: JSON.stringify(messageObject), TopicArn: topic }, (additionalProps ? additionalProps : {}));
|
|
110
|
+
return [4 /*yield*/, PUBLISHER_CONN.send(new client_sns_1.PublishCommand(params))];
|
|
111
|
+
case 2:
|
|
112
|
+
resp = _a.sent();
|
|
113
|
+
return [3 /*break*/, 4];
|
|
114
|
+
case 3:
|
|
115
|
+
e_1 = _a.sent();
|
|
116
|
+
console.error("Error while publishing into topic ".concat(topic, " with error: ").concat(e_1));
|
|
117
|
+
return [3 /*break*/, 4];
|
|
118
|
+
case 4:
|
|
119
|
+
console.debug('Publisher resp', resp);
|
|
120
|
+
return [2 /*return*/, resp];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
/* Private */
|
|
126
|
+
/**
|
|
127
|
+
* ${1:Description placeholder}
|
|
128
|
+
*/
|
|
129
|
+
Publisher.prototype._connect = function () {
|
|
130
|
+
if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
|
|
131
|
+
PUBLISHER_CONN = new client_sns_1.SNSClient({
|
|
132
|
+
apiVersion: '2010-03-31',
|
|
133
|
+
region: this.region,
|
|
134
|
+
});
|
|
135
|
+
PUBLISHER_CONN_HASH = sha1(this.region).toString();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return Publisher;
|
|
139
|
+
}());
|
|
140
|
+
exports.default = Publisher;
|
|
141
|
+
//# sourceMappingURL=Publisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publisher.js","sourceRoot":"","sources":["../../../src/Publisher/Publisher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAK4B;AAC5B,2BAA4B;AAC5B,iBAAiB;AACjB,kCAAkC;AAClC;;;;GAIG;AACH,IAAI,cAAc,GAAqB,IAAI,CAAA;AAC3C,kCAAkC;AAClC;;;;GAIG;AACH,IAAI,mBAAmB,GAAkB,IAAI,CAAA;AAW7C,EAAE;AACF;;;;;;GAMG;AACH;IAQE;;;;;OAKG;IACH,mBAAY,MAAwB;QAClC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE;YAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;YAC3B,iDAAiD;SAClD;IACH,CAAC;IACD,YAAY;IACZ;;;;;;;;OAQG;IACG,kCAAc,GAApB,UACE,aAAkB,EAClB,KAAa,EACb,eAAwB;;;;;;wBAEpB,IAAI,GAAgC,IAAI,CAAA;;;;wBAE1C,IAAI,CAAC,QAAQ,EAAE,CAAA;wBAET,MAAM,cACV,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EACtC,QAAQ,EAAE,KAAK,IACZ,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,CAC5C,CAAA;wBACM,qBAAM,cAAc,CAAC,IAAI,CAAC,IAAI,2BAAc,CAAC,MAAM,CAAC,CAAC,EAAA;;wBAA5D,IAAI,GAAG,SAAqD,CAAA;;;;wBAE5D,OAAO,CAAC,KAAK,CAAC,4CAAqC,KAAK,0BAAgB,GAAC,CAAE,CAAC,CAAA;;;wBAE9E,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAA;wBACrC,sBAAO,IAAI,EAAA;;;;KACZ;IACD,aAAa;IACb;;OAEG;IACH,4BAAQ,GAAR;QACE,IAAI,CAAC,CAAC,cAAc,IAAI,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACzF,cAAc,GAAG,IAAI,sBAAS,CAAC;gBAC7B,UAAU,EAAE,YAAY;gBACxB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAA;YACF,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;SACnD;IACH,CAAC;IACH,gBAAC;AAAD,CAAC,AAhED,IAgEC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Route, RouterConfig } from './Router';
|
|
2
|
+
/**
|
|
3
|
+
* ${1:Description placeholder}
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class RouteResolver
|
|
7
|
+
* @typedef {RouteResolver}
|
|
8
|
+
*/
|
|
9
|
+
export default class RouteResolver {
|
|
10
|
+
readonly config: RouterConfig;
|
|
11
|
+
/**
|
|
12
|
+
* ${1:Description placeholder}
|
|
13
|
+
*
|
|
14
|
+
* @private
|
|
15
|
+
* @type {{ [method: string]: Routes }\}
|
|
16
|
+
*/
|
|
17
|
+
private routes;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an instance of RouteResolver.
|
|
20
|
+
*
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param {RouterConfig} config
|
|
23
|
+
*/
|
|
24
|
+
constructor(config: RouterConfig);
|
|
25
|
+
/**
|
|
26
|
+
* ${1:Description placeholder}
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param {string} method
|
|
30
|
+
* @param {string} path
|
|
31
|
+
* @returns {(Route | undefined)}
|
|
32
|
+
*/
|
|
33
|
+
resolveRoute(method: string, path: string): Route | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Description placeholder
|
|
36
|
+
*
|
|
37
|
+
* @private
|
|
38
|
+
* @param {RouterConfig} config
|
|
39
|
+
*/
|
|
40
|
+
private buildRoutes;
|
|
41
|
+
}
|