@ikonintegration/ikapi 5.0.2 → 5.0.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.
Files changed (132) hide show
  1. package/package.json +1 -1
  2. package/src/BaseEvent/Launchable/ContainerExec.ts +6 -2
  3. package/src/Mailer/Mailer.ts +42 -52
  4. package/dist/index.d.ts +0 -17
  5. package/dist/index.js +0 -28
  6. package/dist/index.js.map +0 -1
  7. package/dist/package-lock.json +0 -11901
  8. package/dist/package.json +0 -82
  9. package/dist/src/API/Request.d.ts +0 -125
  10. package/dist/src/API/Request.js +0 -185
  11. package/dist/src/API/Request.js.map +0 -1
  12. package/dist/src/API/Response.d.ts +0 -188
  13. package/dist/src/API/Response.js +0 -270
  14. package/dist/src/API/Response.js.map +0 -1
  15. package/dist/src/BaseEvent/DynamoTransaction.d.ts +0 -70
  16. package/dist/src/BaseEvent/DynamoTransaction.js +0 -104
  17. package/dist/src/BaseEvent/DynamoTransaction.js.map +0 -1
  18. package/dist/src/BaseEvent/EventProcessor.d.ts +0 -58
  19. package/dist/src/BaseEvent/EventProcessor.js +0 -101
  20. package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
  21. package/dist/src/BaseEvent/Launchable/ContainerExec.d.ts +0 -42
  22. package/dist/src/BaseEvent/Launchable/ContainerExec.js +0 -102
  23. package/dist/src/BaseEvent/Launchable/ContainerExec.js.map +0 -1
  24. package/dist/src/BaseEvent/Launchable/index.d.ts +0 -34
  25. package/dist/src/BaseEvent/Launchable/index.js +0 -43
  26. package/dist/src/BaseEvent/Launchable/index.js.map +0 -1
  27. package/dist/src/BaseEvent/Launchable/types.d.ts +0 -10
  28. package/dist/src/BaseEvent/Launchable/types.js +0 -2
  29. package/dist/src/BaseEvent/Launchable/types.js.map +0 -1
  30. package/dist/src/BaseEvent/Process.d.ts +0 -50
  31. package/dist/src/BaseEvent/Process.js +0 -64
  32. package/dist/src/BaseEvent/Process.js.map +0 -1
  33. package/dist/src/BaseEvent/StepTransaction.d.ts +0 -23
  34. package/dist/src/BaseEvent/StepTransaction.js +0 -27
  35. package/dist/src/BaseEvent/StepTransaction.js.map +0 -1
  36. package/dist/src/BaseEvent/Transaction.d.ts +0 -149
  37. package/dist/src/BaseEvent/Transaction.js +0 -224
  38. package/dist/src/BaseEvent/Transaction.js.map +0 -1
  39. package/dist/src/Cache/Redis.d.ts +0 -29
  40. package/dist/src/Cache/Redis.js +0 -80
  41. package/dist/src/Cache/Redis.js.map +0 -1
  42. package/dist/src/Cache/types.d.ts +0 -31
  43. package/dist/src/Cache/types.js +0 -2
  44. package/dist/src/Cache/types.js.map +0 -1
  45. package/dist/src/Config/Configuration.d.ts +0 -123
  46. package/dist/src/Config/Configuration.js +0 -109
  47. package/dist/src/Config/Configuration.js.map +0 -1
  48. package/dist/src/Config/EnvironmentVar.d.ts +0 -74
  49. package/dist/src/Config/EnvironmentVar.js +0 -138
  50. package/dist/src/Config/EnvironmentVar.js.map +0 -1
  51. package/dist/src/Crypto/Crypto.d.ts +0 -45
  52. package/dist/src/Crypto/Crypto.js +0 -72
  53. package/dist/src/Crypto/Crypto.js.map +0 -1
  54. package/dist/src/Database/Database.d.ts +0 -21
  55. package/dist/src/Database/Database.js +0 -15
  56. package/dist/src/Database/Database.js.map +0 -1
  57. package/dist/src/Database/DatabaseManager.d.ts +0 -47
  58. package/dist/src/Database/DatabaseManager.js +0 -60
  59. package/dist/src/Database/DatabaseManager.js.map +0 -1
  60. package/dist/src/Database/DatabaseTransaction.d.ts +0 -101
  61. package/dist/src/Database/DatabaseTransaction.js +0 -126
  62. package/dist/src/Database/DatabaseTransaction.js.map +0 -1
  63. package/dist/src/Database/index.d.ts +0 -10
  64. package/dist/src/Database/index.js +0 -15
  65. package/dist/src/Database/index.js.map +0 -1
  66. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +0 -35
  67. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +0 -59
  68. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +0 -1
  69. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +0 -66
  70. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +0 -86
  71. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +0 -1
  72. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +0 -70
  73. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +0 -118
  74. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +0 -1
  75. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +0 -36
  76. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +0 -54
  77. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +0 -1
  78. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +0 -63
  79. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +0 -61
  80. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +0 -1
  81. package/dist/src/Database/types.d.ts +0 -76
  82. package/dist/src/Database/types.js +0 -2
  83. package/dist/src/Database/types.js.map +0 -1
  84. package/dist/src/Globals.d.ts +0 -93
  85. package/dist/src/Globals.js +0 -99
  86. package/dist/src/Globals.js.map +0 -1
  87. package/dist/src/Logger/Logger.d.ts +0 -161
  88. package/dist/src/Logger/Logger.js +0 -299
  89. package/dist/src/Logger/Logger.js.map +0 -1
  90. package/dist/src/Mailer/Mailer.d.ts +0 -78
  91. package/dist/src/Mailer/Mailer.js +0 -182
  92. package/dist/src/Mailer/Mailer.js.map +0 -1
  93. package/dist/src/Publisher/Publisher.d.ts +0 -39
  94. package/dist/src/Publisher/Publisher.js +0 -77
  95. package/dist/src/Publisher/Publisher.js.map +0 -1
  96. package/dist/src/Server/RouteResolver.d.ts +0 -33
  97. package/dist/src/Server/RouteResolver.js +0 -100
  98. package/dist/src/Server/RouteResolver.js.map +0 -1
  99. package/dist/src/Server/Router.d.ts +0 -157
  100. package/dist/src/Server/Router.js +0 -32
  101. package/dist/src/Server/Router.js.map +0 -1
  102. package/dist/src/Server/lib/ContainerServer.d.ts +0 -42
  103. package/dist/src/Server/lib/ContainerServer.js +0 -66
  104. package/dist/src/Server/lib/ContainerServer.js.map +0 -1
  105. package/dist/src/Server/lib/Server.d.ts +0 -45
  106. package/dist/src/Server/lib/Server.js +0 -93
  107. package/dist/src/Server/lib/Server.js.map +0 -1
  108. package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -9
  109. package/dist/src/Server/lib/container/GenericHandler.js +0 -82
  110. package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
  111. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -52
  112. package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -132
  113. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
  114. package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -9
  115. package/dist/src/Server/lib/container/HealthHandler.js +0 -19
  116. package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
  117. package/dist/src/Server/lib/container/Proxy.d.ts +0 -67
  118. package/dist/src/Server/lib/container/Proxy.js +0 -143
  119. package/dist/src/Server/lib/container/Proxy.js.map +0 -1
  120. package/dist/src/Server/lib/container/Utils.d.ts +0 -14
  121. package/dist/src/Server/lib/container/Utils.js +0 -37
  122. package/dist/src/Server/lib/container/Utils.js.map +0 -1
  123. package/dist/src/Util/AsyncSingleton.d.ts +0 -31
  124. package/dist/src/Util/AsyncSingleton.js +0 -83
  125. package/dist/src/Util/AsyncSingleton.js.map +0 -1
  126. package/dist/src/Util/Utils.d.ts +0 -61
  127. package/dist/src/Util/Utils.js +0 -147
  128. package/dist/src/Util/Utils.js.map +0 -1
  129. package/dist/src/Validation/Validator.d.ts +0 -17
  130. package/dist/src/Validation/Validator.js +0 -39
  131. package/dist/src/Validation/Validator.js.map +0 -1
  132. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,299 +0,0 @@
1
- import abind from 'abind';
2
- import stringify from 'json-stringify-safe';
3
- import stackTrace from 'stack-trace';
4
- import Utils from '../Util/Utils.js';
5
- /**
6
- * Enumeration of log levels.
7
- * @enum {string}
8
- * @property {string} DEBUG - Debug log level.
9
- * @property {string} INFO - Info log level.
10
- * @property {string} WARN - Warning log level.
11
- * @property {string} ERROR - Error log level.
12
- */
13
- export var LOG_LEVELS;
14
- (function (LOG_LEVELS) {
15
- LOG_LEVELS["DEBUG"] = "DEBUG";
16
- LOG_LEVELS["INFO"] = "INFO";
17
- LOG_LEVELS["WARN"] = "WARN";
18
- LOG_LEVELS["ERROR"] = "ERROR";
19
- })(LOG_LEVELS || (LOG_LEVELS = {}));
20
- /**
21
- * A constant that represents the console object to be used for logging.
22
- * If the console object has a property named 'notGlobalLogger', it is assumed
23
- * to be a custom logger and the 'origin' property is used as the console object.
24
- * Otherwise, the global console object is used.
25
- * @type {Console}
26
- */
27
- const PURE_CONSOLE = console['notGlobalLogger'] ? console['origin'] : console;
28
- /**
29
- * The default log function that is used for logging messages.
30
- * @type {Function}
31
- */
32
- const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE);
33
- /**
34
- * Creates a blacklist array by mapping each string in the given array to its lowercase form.
35
- * The resulting blacklist array is used to filter out sensitive information.
36
- * @type {string[]} blacklist - An array of strings to be converted to lowercase and used as a blacklist.
37
- * @returns {string[]} - An array of lowercase strings representing the blacklist.
38
- */
39
- const blacklist = ['password', 'token', 'accounts', 'rawBody'].map(s => s.toLowerCase());
40
- /* Used to have a clean log */
41
- const defaultSuppress = ['rawBody'].map(s => s.toLowerCase());
42
- /**
43
- * Logger class for logging messages with different log levels.
44
- */
45
- export default class Logger {
46
- /**
47
- * Constructs a Logger object with the given configuration and transaction ID.
48
- * @param {config} config - The configuration object for the logger. Can be undefined.
49
- * @param {string} transactionID - The ID of the transaction associated with the logger.
50
- * @returns None
51
- */
52
- constructor(config, transactionID) {
53
- abind(this);
54
- //
55
- this.origin = PURE_CONSOLE;
56
- this._LOG_LEVEL = (config === null || config === void 0 ? void 0 : config.logLevel)
57
- ? LOG_LEVELS[config === null || config === void 0 ? void 0 : config.logLevel] || LOG_LEVELS.DEBUG
58
- : LOG_LEVELS.DEBUG;
59
- this.config = config || {};
60
- this.transactionID = transactionID;
61
- this.filterBlacklist = this.config.sensitiveFilteringKeywords
62
- ? Array.isArray(this.config.sensitiveFilteringKeywords)
63
- ? this.config.sensitiveFilteringKeywords
64
- : blacklist
65
- : defaultSuppress;
66
- //
67
- this.setupBindings();
68
- //
69
- this.log('Using logger with level: ' + this._LOG_LEVEL.toString());
70
- this.debug('logger config: ', this.config);
71
- }
72
- /**
73
- * Returns a boolean value indicating whether the notGlobalLogger function is executed successfully.
74
- * @returns {boolean} - true if the function is executed successfully, false otherwise.
75
- */
76
- notGlobalLogger() {
77
- return true;
78
- }
79
- /**
80
- * Logs the given arguments with the debug log level.
81
- * @param {...any} args - The arguments to be logged.
82
- * @returns None
83
- */
84
- debug(...args) {
85
- this.processLog(LOG_LEVELS.DEBUG, args);
86
- }
87
- /**
88
- * Logs the given arguments with the INFO log level.
89
- * @param {...any} args - The arguments to be logged.
90
- * @returns None
91
- */
92
- log(...args) {
93
- this.processLog(LOG_LEVELS.INFO, args);
94
- }
95
- /**
96
- * Logs an informational message.
97
- * @param {...any} args - The message(s) to log.
98
- * @returns None
99
- */
100
- info(...args) {
101
- this.processLog(LOG_LEVELS.INFO, args);
102
- }
103
- /**
104
- * Logs a warning message with the provided arguments.
105
- * @param {...any} args - The arguments to be logged as a warning message.
106
- * @returns None
107
- */
108
- warning(...args) {
109
- this.processLog(LOG_LEVELS.WARN, args);
110
- }
111
- /**
112
- * Logs a warning message to the console.
113
- * @param {...any} args - The arguments to be logged.
114
- * @returns None
115
- */
116
- warn(...args) {
117
- this.processLog(LOG_LEVELS.WARN, args);
118
- }
119
- /**
120
- * Logs an error message with the given arguments.
121
- * @param {...any} args - The arguments to log as an error message.
122
- * @returns None
123
- */
124
- error(...args) {
125
- this.processLog(LOG_LEVELS.ERROR, args);
126
- }
127
- /**
128
- * Logs an exception with optional additional arguments.
129
- * @param {any} exception - The exception to log.
130
- * @param {...any} args - Additional arguments to include in the log.
131
- * @returns None
132
- */
133
- exception(exception, ...args) {
134
- this.iexception(exception, args);
135
- }
136
- /**
137
- * Sets up the console bindings for logging purposes.
138
- * @private
139
- * @returns None
140
- */
141
- setupBindings() {
142
- global.console = {
143
- debug: (...args) => this.processLog(LOG_LEVELS.DEBUG, args),
144
- log: (...args) => this.processLog(LOG_LEVELS.INFO, args),
145
- info: (...args) => this.processLog(LOG_LEVELS.INFO, args),
146
- warn: (...args) => this.processLog(LOG_LEVELS.WARN, args),
147
- error: (...args) => this.processLog(LOG_LEVELS.ERROR, args),
148
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
149
- // @ts-ignore
150
- warning: (...args) => this.processLog(LOG_LEVELS.WARN, args),
151
- exception: (exception, ...args) => this.iexception(exception, args),
152
- };
153
- }
154
- /**
155
- * Formats a log message with the specified log level, message, and caller.
156
- * @param {LOG_LEVELS} level - The log level of the message.
157
- * @param {Array<string>} msg - An array of strings representing the message.
158
- * @param {string} caller - The name of the caller function.
159
- * @returns {string} - The formatted log message.
160
- */
161
- formattedLog(level, msg, caller) {
162
- if (Utils.isHybridlessContainer() && this.transactionID) {
163
- return `${this.transactionID}` + ` [${level.toString()}] [${caller}] ${msg.join(' ')}`;
164
- }
165
- else {
166
- return `[${level.toString()}] [${caller}] ${msg.join(' ')}`;
167
- }
168
- }
169
- /**
170
- * Retrieves the name of the caller function at the specified index in the stack trace.
171
- * @param {number} index - The index of the caller function in the stack trace.
172
- * @returns {string} The name of the caller function along with the file path and line number.
173
- */
174
- callerName(index) {
175
- var _a, _b, _c, _d, _e, _f;
176
- const safeIndex = Math.min(index, stackTrace.get().length);
177
- if (stackTrace.get()[safeIndex]) {
178
- let callerName = (_c = (_b = (_a = stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.get()) === null || _a === void 0 ? void 0 : _a[safeIndex]) === null || _b === void 0 ? void 0 : _b.getFileName()) === null || _c === void 0 ? void 0 : _c.split('/');
179
- callerName = (_d = callerName === null || callerName === void 0 ? void 0 : callerName.slice(callerName === null || callerName === void 0 ? void 0 : callerName.indexOf('src'))) === null || _d === void 0 ? void 0 : _d.join('/');
180
- return callerName + ':' + ((_f = (_e = stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.get()) === null || _e === void 0 ? void 0 : _e[safeIndex]) === null || _f === void 0 ? void 0 : _f.getLineNumber());
181
- }
182
- return '';
183
- }
184
- /**
185
- * Processes log messages based on the specified log level.
186
- * @param {LOG_LEVELS} level - The level of the log message.
187
- * @param {any} args - The arguments to be logged.
188
- * @returns None
189
- */
190
- processLog(level, args) {
191
- if (level < this._LOG_LEVEL)
192
- return;
193
- //get args
194
- const msg = [];
195
- for (const arg of args) {
196
- // Deep clone object so we dont modify source
197
- const fMsg = this.formatArgument(arg);
198
- msg.push(fMsg);
199
- }
200
- //push into logs stack
201
- // todo: improve error stack
202
- this.pushLog(level, this.formattedLog(level, msg, this.callerName(3)));
203
- }
204
- formatArgument(arg) {
205
- if (arg instanceof Error) {
206
- return arg.message + '\n' + arg.stack;
207
- }
208
- if (arg && typeof arg === 'object') {
209
- return stringify(this.suppressSensitiveInfo(JSON.parse(stringify(arg))), null, 2);
210
- }
211
- return `${this.suppressSensitiveInfo(arg)}`;
212
- }
213
- /**
214
- * Logs an exception along with additional arguments and the stack trace.
215
- * @param {Error} exception - The exception object to log.
216
- * @param {...any} args - Additional arguments to include in the log.
217
- * @returns None
218
- */
219
- iexception(exception, ...args) {
220
- //format message
221
- const msg = [];
222
- //push exeception
223
- msg.push(exception.toString() + ' -');
224
- //get args
225
- for (const arg of args)
226
- if (arg != exception)
227
- msg.push(arg);
228
- if (exception.stack)
229
- msg.push(exception.stack); //push Exeception stack at the end
230
- //push into logs stack
231
- this.pushLog(LOG_LEVELS.ERROR, this.formattedLog(LOG_LEVELS.ERROR, msg, this.callerName(3)));
232
- }
233
- /**
234
- * Pushes a log message to the console with the specified log level.
235
- * @param {LOG_LEVELS} level - The log level of the message.
236
- * @param {string} fMsg - The formatted log message.
237
- * @returns None
238
- */
239
- pushLog(level, fMsg) {
240
- DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg]);
241
- }
242
- /**
243
- * Suppresses sensitive information in the given value based on the filter blacklist.
244
- * @param {any} value - The value to suppress sensitive information from.
245
- * @returns {string} - The value with sensitive information suppressed.
246
- */
247
- suppressSensitiveInfo(value) {
248
- if (!value || !this.filterBlacklist.length)
249
- return value;
250
- const parent = [value];
251
- const stack = [{ value, parent, key: 0 }];
252
- while (stack.length > 0) {
253
- this.suppressSensitiveInfoItem(stack.pop(), stack.push.bind(stack));
254
- }
255
- return parent[0];
256
- }
257
- suppressSensitiveInfoItem({ value, parent, key }, push) {
258
- if (!value)
259
- return;
260
- if (typeof value === 'string') {
261
- this.suppressSensitiveString({ value, parent, key }, push);
262
- }
263
- else if (Array.isArray(value)) {
264
- value.forEach((v, index) => push({ value: v, parent: value, key: index }));
265
- }
266
- else if (typeof value === 'object') {
267
- this.suppressSensitiveObject(value, push);
268
- }
269
- }
270
- suppressSensitiveString({ value, parent, key }, push) {
271
- var _a;
272
- let modifiedValue = value;
273
- try {
274
- // Try to parse json string
275
- modifiedValue = JSON.parse(value);
276
- push({ value: modifiedValue, parent, key });
277
- }
278
- catch (_b) {
279
- const lower = value.toLowerCase();
280
- if (this.filterBlacklist.some(f => lower == f))
281
- modifiedValue = `**SUPPRESSED_SENSITIVE_DATA** (${((_a = String(modifiedValue)) === null || _a === void 0 ? void 0 : _a.length) || 0} len)`;
282
- }
283
- parent[key] = modifiedValue;
284
- }
285
- suppressSensitiveObject(value, push) {
286
- Object.entries(value).forEach(([k, v]) => {
287
- var _a;
288
- const lower = k.toLowerCase();
289
- const match = v && this.filterBlacklist.some(f => lower == f);
290
- if (match) {
291
- value[k] = `**SUPPRESSED_SENSITIVE_DATA** (${((_a = String(v)) === null || _a === void 0 ? void 0 : _a.length) || 0} len)`;
292
- }
293
- else {
294
- push({ value: v, parent: value, key: k });
295
- }
296
- });
297
- }
298
- }
299
- //# sourceMappingURL=Logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../../src/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,qBAAqB,CAAA;AAC3C,OAAO,UAAU,MAAM,aAAa,CAAA;AAEpC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,6BAAe,CAAA;AACjB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AACD;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC7E;;;GAGG;AACH,MAAM,oBAAoB,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;AAExF,8BAA8B;AAC9B,MAAM,eAAe,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;AAmB7D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IA4BzB;;;;;OAKG;IACH,YAAY,MAAgC,EAAE,aAAqB;QACjE,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,EAAE;QACF,IAAI,CAAC,M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AI,CAAC,OAAO,CAAA;QAC/F,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAA;IAC7B,CAAC;IAEO,uBAAuB,CAAC,KAAa,EAAE,IAAkC;QAC/E,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;;YACvC,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;YAC7B,MAAM,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAA;YAC7D,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,CAAC,CAAC,GAAG,kCAAkC,CAAA,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,MAAM,KAAI,CAAC,OAAO,CAAA;YAC5E,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -1,78 +0,0 @@
1
- import Email from 'email-templates';
2
- export default class Mailer {
3
- /**
4
- * The starting point of a range.
5
- * @type {string}
6
- */
7
- private readonly from;
8
- /**
9
- * The default file template for the application.
10
- * @type {string}
11
- */
12
- private readonly templateDefaultFile;
13
- /**
14
- * The transporter object used for sending emails using the AWS SES service.
15
- * @type {ReturnType<typeof nodemailer.createTransport<SESTransport.SentMessageInfo>>}
16
- */
17
- private readonly transporter;
18
- /**
19
- * Constructs a new instance of the EmailSender class.
20
- * @param {string} defaultFrom - The default "from" email address.
21
- * @param {string} region - The AWS region to use for sending emails.
22
- * @returns None
23
- */
24
- constructor(defaultFrom: string, region: string);
25
- /**
26
- * Sends a raw email with the specified parameters.
27
- * @param {string | Array<string>} to - The recipient(s) of the email.
28
- * @param {string} htmlMessage - The HTML content of the email.
29
- * @param {string} subject - The subject of the email.
30
- * @param {string | Array<string>} [optionalCC] - The optional CC recipient(s) of the email.
31
- * @param {string} [optionalFrom] - The optional sender of the email. If not provided, the default sender will be used.
32
- * @param {string} [optionalReplyTo] - The optional reply-to address for the email.
33
- * @param {any[]} [optionalAttachments] - The optional attachments to include
34
- */
35
- sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<null>;
36
- /**
37
- * Sends a templated email to the specified recipients.
38
- * @param {string | Array<string>} to - The email address(es) of the recipient(s).
39
- * @param {string | Array<string>} templates - The template(s) to use for the email.
40
- * @param {object} data - The data to be used in the email template.
41
- * @param {string | Array<string>} [optionalCC] - The email address(es) to CC.
42
- * @param {string} [optionalFrom] - The email address to send the email from.
43
- * @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
44
- * @param {any[]} [optionalAttachments] - An array
45
- */
46
- sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<null>;
47
- /**
48
- * Creates a new SMTP transporter for sending emails using NodeMailer.
49
- * @param {string} host - The SMTP server host.
50
- * @param {number} portNumber - The port number to connect to the SMTP server.
51
- * @param {string} user - The username for authentication with the SMTP server.
52
- * @param {string} password - The password for authentication with the SMTP server.
53
- * @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
54
- */
55
- newSMTPTransporter(host: string, portNumber: number, user: string, password: string): Email.NodeMailerTransportOptions;
56
- /**
57
- * Chooses a template from the given array of templates or a single template string based on whether it can be rendered with the provided data.
58
- * @param {string | Array<string>} templates - The template(s) to choose from.
59
- * @param {object} data - The data to be used for rendering the template.
60
- * @returns {Promise<string>} - The chosen template.
61
- * @throws {Error} - If no template can be rendered with the provided data.
62
- */
63
- private chooseTemplate;
64
- /**
65
- * Checks if a given email template can be rendered with the provided data.
66
- * @param {string} template - The name of the email template.
67
- * @param {object} data - The data to be used for rendering the template.
68
- * @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
69
- */
70
- private canRenderTemplate;
71
- /**
72
- * Renders the given template with the provided data using the Email class.
73
- * @param {string} template - The name or path of the template to render.
74
- * @param {object} data - The data object to pass to the template.
75
- * @returns {Promise<boolean>} - A promise that resolves to true if the template was rendered successfully, false otherwise.
76
- */
77
- static renderTemplate(template: string, data: object): Promise<any>;
78
- }
@@ -1,182 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import * as SES from '@aws-sdk/client-ses';
11
- import { defaultProvider } from '@aws-sdk/credential-provider-node';
12
- import Email from 'email-templates';
13
- import nodemailer from 'nodemailer';
14
- export default class Mailer {
15
- /**
16
- * Constructs a new instance of the EmailSender class.
17
- * @param {string} defaultFrom - The default "from" email address.
18
- * @param {string} region - The AWS region to use for sending emails.
19
- * @returns None
20
- */
21
- constructor(defaultFrom, region) {
22
- /**
23
- * The default file template for the application.
24
- * @type {string}
25
- */
26
- this.templateDefaultFile = 'html';
27
- this.from = defaultFrom;
28
- this.transporter = nodemailer.createTransport({
29
- SES: {
30
- ses: new SES.SESClient({
31
- credentials: defaultProvider(),
32
- apiVersion: '2010-12-01',
33
- region,
34
- }),
35
- aws: SES,
36
- },
37
- });
38
- }
39
- /**
40
- * Sends a raw email with the specified parameters.
41
- * @param {string | Array<string>} to - The recipient(s) of the email.
42
- * @param {string} htmlMessage - The HTML content of the email.
43
- * @param {string} subject - The subject of the email.
44
- * @param {string | Array<string>} [optionalCC] - The optional CC recipient(s) of the email.
45
- * @param {string} [optionalFrom] - The optional sender of the email. If not provided, the default sender will be used.
46
- * @param {string} [optionalReplyTo] - The optional reply-to address for the email.
47
- * @param {any[]} [optionalAttachments] - The optional attachments to include
48
- */
49
- sendRawEmail(to, htmlMessage, subject, optionalCC, optionalFrom, optionalReplyTo,
50
- // TODO: improve attachment type -> Attachment
51
- optionalAttachments, optionalTransport) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- //Generate emails
54
- const email = new Email({
55
- message: Object.assign(Object.assign(Object.assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
56
- transport: optionalTransport || this.transporter,
57
- send: true,
58
- });
59
- //
60
- let resp = null;
61
- try {
62
- resp = yield email.send();
63
- console.debug('Mailer resp:', resp);
64
- }
65
- catch (e) {
66
- console.error('Mailer error:', e);
67
- throw e;
68
- }
69
- return resp;
70
- });
71
- }
72
- /**
73
- * Sends a templated email to the specified recipients.
74
- * @param {string | Array<string>} to - The email address(es) of the recipient(s).
75
- * @param {string | Array<string>} templates - The template(s) to use for the email.
76
- * @param {object} data - The data to be used in the email template.
77
- * @param {string | Array<string>} [optionalCC] - The email address(es) to CC.
78
- * @param {string} [optionalFrom] - The email address to send the email from.
79
- * @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
80
- * @param {any[]} [optionalAttachments] - An array
81
- */
82
- sendTemplatedEmail(to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
83
- // TODO: improve attachment type -> Attachment
84
- optionalAttachments, optionalTransport) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- //Generate emails
87
- const email = new Email({
88
- message: Object.assign(Object.assign(Object.assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
89
- transport: optionalTransport || this.transporter,
90
- send: true,
91
- });
92
- //
93
- let resp = null;
94
- try {
95
- const chosenTemplate = yield this.chooseTemplate(templates, data);
96
- resp = yield email.send({ template: chosenTemplate, locals: data });
97
- console.debug('Mailer resp:', resp);
98
- }
99
- catch (e) {
100
- console.error('Mailer error:', e);
101
- throw e;
102
- }
103
- return resp;
104
- });
105
- }
106
- /**
107
- * Creates a new SMTP transporter for sending emails using NodeMailer.
108
- * @param {string} host - The SMTP server host.
109
- * @param {number} portNumber - The port number to connect to the SMTP server.
110
- * @param {string} user - The username for authentication with the SMTP server.
111
- * @param {string} password - The password for authentication with the SMTP server.
112
- * @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
113
- */
114
- newSMTPTransporter(host, portNumber, user, password) {
115
- const smtpTransporter = nodemailer.createTransport({
116
- host: host,
117
- port: portNumber,
118
- connectionTimeout: 2000,
119
- auth: {
120
- user: user,
121
- pass: password,
122
- },
123
- });
124
- return smtpTransporter;
125
- }
126
- /**
127
- * Chooses a template from the given array of templates or a single template string based on whether it can be rendered with the provided data.
128
- * @param {string | Array<string>} templates - The template(s) to choose from.
129
- * @param {object} data - The data to be used for rendering the template.
130
- * @returns {Promise<string>} - The chosen template.
131
- * @throws {Error} - If no template can be rendered with the provided data.
132
- */
133
- chooseTemplate(templates, data) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- if (Array.isArray(templates)) {
136
- //For each template check if can render it
137
- for (const template of templates) {
138
- if (yield this.canRenderTemplate(template, data))
139
- return template;
140
- }
141
- }
142
- else if (templates) {
143
- if (yield this.canRenderTemplate(templates, data))
144
- return templates;
145
- }
146
- throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above! ` +
147
- JSON.stringify(data, null, 2));
148
- });
149
- }
150
- /**
151
- * Checks if a given email template can be rendered with the provided data.
152
- * @param {string} template - The name of the email template.
153
- * @param {object} data - The data to be used for rendering the template.
154
- * @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
155
- */
156
- canRenderTemplate(template, data) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- const validRenderResp = yield Mailer.renderTemplate(`${template}/${this.templateDefaultFile}`, data);
159
- return validRenderResp != null;
160
- });
161
- }
162
- /**
163
- * Renders the given template with the provided data using the Email class.
164
- * @param {string} template - The name or path of the template to render.
165
- * @param {object} data - The data object to pass to the template.
166
- * @returns {Promise<boolean>} - A promise that resolves to true if the template was rendered successfully, false otherwise.
167
- */
168
- static renderTemplate(template, data) {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- let validRenderResp = null;
171
- try {
172
- const email = new Email();
173
- validRenderResp = yield email.render(`${template}`, data);
174
- }
175
- catch (e) {
176
- console.log(`Error while checking renderability of email template ${template}`, e);
177
- }
178
- return validRenderResp;
179
- });
180
- }
181
- }
182
- //# sourceMappingURL=Mailer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,MAAM,iBAAiB,CAAA;AACnC,OAAO,UAAU,MAAM,YAAY,CAAA;AAGnC,MAAM,CAAC,OAAO,OAAO,MAAM;IAmBzB;;;;;OAKG;IACH,YAAY,WAAmB,EAAE,MAAc;QAnB/C;;;WAGG;QACc,wBAAmB,GAAW,MAAM,CAAA;QAgBnD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC5C,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,GAAG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;YACzC,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;gBACzB,eAAe,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;YAC3D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,wDAAwD,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;YACpF,CAAC;YACD,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF"}
@@ -1,39 +0,0 @@
1
- import { PublishCommandOutput } from '@aws-sdk/client-sns';
2
- /**
3
- * Represents the configuration options for a publisher.
4
- * @typedef {Object} PublisherConfig
5
- * @property {string} [region] - The region where the publisher is located.
6
- */
7
- export type PublisherConfig = {
8
- region?: string;
9
- };
10
- /**
11
- * Represents a publisher that can publish messages to an SNS topic.
12
- */
13
- export default class Publisher {
14
- /**
15
- * The region of the object or entity.
16
- * @private
17
- * @type {string}
18
- */
19
- private region;
20
- /**
21
- * Constructs a new instance of the Publisher class.
22
- * @param {PublisherConfig} [config] - The configuration object for the Publisher.
23
- * @returns None
24
- */
25
- constructor(config?: PublisherConfig);
26
- /**
27
- * Publishes a message on a specified topic.
28
- * @param {any} messageObject - The message object to be published.
29
- * @param {string} topic - The ARN of the topic to publish the message to.
30
- * @param {object} [additionalProps] - Additional properties to include in the publish command.
31
- * @returns {Promise<PublishCommandOutput>} - A promise that resolves to the response from the publish command.
32
- */
33
- publishOnTopic(messageObject: any, topic: string, additionalProps?: object): Promise<PublishCommandOutput | undefined>;
34
- /**
35
- * Establishes a connection to the SNS client if it does not already exist or if the region has changed.
36
- * @returns None
37
- */
38
- private connect;
39
- }