@ikonintegration/ikapi 4.0.1 → 5.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.
Files changed (236) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +81 -0
  3. package/.github/workflows/npmpublish.yml +8 -19
  4. package/.github/workflows/prs.yml +12 -0
  5. package/README.md +89 -99
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +27 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/package-lock.json +11881 -0
  10. package/dist/package.json +81 -0
  11. package/dist/src/API/Request.d.ts +125 -0
  12. package/dist/src/API/Request.js +185 -0
  13. package/dist/src/API/Request.js.map +1 -0
  14. package/dist/src/API/Response.d.ts +188 -0
  15. package/dist/src/API/Response.js +270 -0
  16. package/dist/src/API/Response.js.map +1 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
  19. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  20. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  21. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  22. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  23. package/dist/src/BaseEvent/Process.d.ts +50 -0
  24. package/dist/src/BaseEvent/Process.js +64 -0
  25. package/dist/src/BaseEvent/Process.js.map +1 -0
  26. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  27. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  28. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  29. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  30. package/dist/src/BaseEvent/Transaction.js +224 -0
  31. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  32. package/dist/src/Cache/Redis.d.ts +29 -0
  33. package/dist/src/Cache/Redis.js +80 -0
  34. package/dist/src/Cache/Redis.js.map +1 -0
  35. package/dist/src/Cache/types.d.ts +31 -0
  36. package/dist/src/Cache/types.js +2 -0
  37. package/dist/src/Cache/types.js.map +1 -0
  38. package/dist/src/Config/Configuration.d.ts +123 -0
  39. package/dist/src/Config/Configuration.js +109 -0
  40. package/dist/src/Config/Configuration.js.map +1 -0
  41. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  42. package/dist/src/Config/EnvironmentVar.js +138 -0
  43. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  44. package/dist/src/Crypto/Crypto.d.ts +45 -0
  45. package/dist/src/Crypto/Crypto.js +72 -0
  46. package/dist/src/Crypto/Crypto.js.map +1 -0
  47. package/dist/src/Database/Database.d.ts +21 -0
  48. package/dist/src/Database/Database.js +15 -0
  49. package/dist/src/Database/Database.js.map +1 -0
  50. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  51. package/dist/src/Database/DatabaseManager.js +60 -0
  52. package/dist/src/Database/DatabaseManager.js.map +1 -0
  53. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  54. package/dist/src/Database/DatabaseTransaction.js +126 -0
  55. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  56. package/dist/src/Database/index.d.ts +10 -0
  57. package/dist/src/Database/index.js +15 -0
  58. package/dist/src/Database/index.js.map +1 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  61. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  64. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  67. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  73. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  74. package/dist/src/Database/types.d.ts +76 -0
  75. package/dist/src/Database/types.js +2 -0
  76. package/dist/src/Database/types.js.map +1 -0
  77. package/dist/src/Globals.d.ts +93 -0
  78. package/dist/src/Globals.js +99 -0
  79. package/dist/src/Globals.js.map +1 -0
  80. package/dist/src/Logger/Logger.d.ts +161 -0
  81. package/dist/src/Logger/Logger.js +299 -0
  82. package/dist/src/Logger/Logger.js.map +1 -0
  83. package/dist/src/Mailer/Mailer.d.ts +78 -0
  84. package/dist/src/Mailer/Mailer.js +182 -0
  85. package/dist/src/Mailer/Mailer.js.map +1 -0
  86. package/dist/src/Publisher/Publisher.d.ts +39 -0
  87. package/dist/src/Publisher/Publisher.js +77 -0
  88. package/dist/src/Publisher/Publisher.js.map +1 -0
  89. package/dist/src/Server/RouteResolver.d.ts +33 -0
  90. package/dist/src/Server/RouteResolver.js +100 -0
  91. package/dist/src/Server/RouteResolver.js.map +1 -0
  92. package/dist/src/Server/Router.d.ts +157 -0
  93. package/dist/src/Server/Router.js +32 -0
  94. package/dist/src/Server/Router.js.map +1 -0
  95. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  96. package/dist/src/Server/lib/ContainerServer.js +66 -0
  97. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  98. package/dist/src/Server/lib/Server.d.ts +45 -0
  99. package/dist/src/Server/lib/Server.js +93 -0
  100. package/dist/src/Server/lib/Server.js.map +1 -0
  101. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  103. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  106. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  107. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  109. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  110. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  111. package/dist/src/Server/lib/container/Proxy.js +143 -0
  112. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  113. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  114. package/dist/src/Server/lib/container/Utils.js +37 -0
  115. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  116. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  117. package/dist/src/Util/AsyncSingleton.js +83 -0
  118. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  119. package/dist/src/Util/Utils.d.ts +61 -0
  120. package/dist/src/Util/Utils.js +147 -0
  121. package/dist/src/Util/Utils.js.map +1 -0
  122. package/dist/src/Validation/Validator.d.ts +17 -0
  123. package/dist/src/Validation/Validator.js +39 -0
  124. package/dist/src/Validation/Validator.js.map +1 -0
  125. package/dist/tsconfig.tsbuildinfo +1 -0
  126. package/index.ts +41 -0
  127. package/jest.config.ts +37 -0
  128. package/jest.smoke.config.ts +34 -0
  129. package/package.json +66 -22
  130. package/src/API/Request.ts +214 -0
  131. package/src/API/Response.ts +370 -0
  132. package/src/BaseEvent/DynamoTransaction.ts +175 -0
  133. package/src/BaseEvent/EventProcessor.ts +140 -0
  134. package/src/BaseEvent/Process.ts +78 -0
  135. package/src/BaseEvent/StepTransaction.ts +35 -0
  136. package/src/BaseEvent/Transaction.ts +323 -0
  137. package/src/Cache/Redis.ts +89 -0
  138. package/src/Cache/types.ts +33 -0
  139. package/src/Config/Configuration.ts +199 -0
  140. package/src/Config/EnvironmentVar.ts +142 -0
  141. package/src/Crypto/Crypto.ts +89 -0
  142. package/src/Database/Database.ts +22 -0
  143. package/src/Database/DatabaseManager.ts +67 -0
  144. package/src/Database/DatabaseTransaction.ts +170 -0
  145. package/src/Database/index.ts +27 -0
  146. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  147. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  148. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  149. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  150. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  151. package/src/Database/types.ts +85 -0
  152. package/src/Globals.ts +103 -0
  153. package/src/Logger/Logger.ts +363 -0
  154. package/src/Mailer/Mailer.ts +217 -0
  155. package/src/Publisher/Publisher.ts +96 -0
  156. package/src/Server/RouteResolver.ts +124 -0
  157. package/src/Server/Router.ts +200 -0
  158. package/src/Server/lib/ContainerServer.ts +65 -0
  159. package/src/Server/lib/Server.ts +109 -0
  160. package/src/Server/lib/container/GenericHandler.ts +76 -0
  161. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  162. package/src/Server/lib/container/HealthHandler.ts +11 -0
  163. package/src/Server/lib/container/Proxy.ts +172 -0
  164. package/src/Server/lib/container/Utils.ts +33 -0
  165. package/src/Util/AsyncSingleton.ts +86 -0
  166. package/src/Util/Utils.ts +131 -0
  167. package/src/Validation/Validator.ts +45 -0
  168. package/tests/API/Request.test.ts +273 -0
  169. package/tests/API/Response.test.ts +367 -0
  170. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  171. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  172. package/tests/BaseEvent/Process.test.ts +47 -0
  173. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  174. package/tests/BaseEvent/Transaction.test.ts +402 -0
  175. package/tests/Cache/Redis-client.test.ts +90 -0
  176. package/tests/Cache/Redis-cluster.test.ts +100 -0
  177. package/tests/Config/Config.test.ts +205 -0
  178. package/tests/Config/EnvironmentVar.test.ts +251 -0
  179. package/tests/Crypto/Crypto.test.ts +88 -0
  180. package/tests/Database/DatabaseManager.test.ts +79 -0
  181. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  182. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  183. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  184. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  185. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  186. package/tests/Logger/Logger.test.ts +215 -0
  187. package/tests/Mailer/Mailer.test.ts +59 -0
  188. package/tests/Publisher/Publisher.test.ts +60 -0
  189. package/tests/Server/RouteResolver.test.ts +116 -0
  190. package/tests/Server/Router.test.ts +39 -0
  191. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  192. package/tests/Server/lib/Server.test.ts +12 -0
  193. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  194. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  195. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  196. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  197. package/tests/Server/lib/container/Utils.test.ts +47 -0
  198. package/tests/Test.utils.ts +78 -0
  199. package/tests/Utils/Utils.test.ts +229 -0
  200. package/tests/Validation/Validator.test.ts +82 -0
  201. package/tsconfig.json +26 -0
  202. package/tsconfig.smoke.json +26 -0
  203. package/index.js +0 -88
  204. package/src/API/IKRequest.js +0 -52
  205. package/src/API/IKResponse.js +0 -119
  206. package/src/API/IKUtils.js +0 -51
  207. package/src/BaseEvent/IKProcess.js +0 -77
  208. package/src/BaseEvent/IKTransaction.js +0 -139
  209. package/src/Cache/Prototype/IKCache.js +0 -17
  210. package/src/Cache/Redis/IKRedis.js +0 -148
  211. package/src/Database/DDB/IKDB.js +0 -56
  212. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  213. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  214. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  215. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  216. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  217. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  218. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  219. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  220. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  221. package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
  222. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  223. package/src/Database/PSQL/IKDB.js +0 -41
  224. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  225. package/src/Database/Prototype/IKDB.js +0 -21
  226. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  227. package/src/IKDynamoStream.js +0 -42
  228. package/src/IKEventProcessor.js +0 -42
  229. package/src/IKGlobals.js +0 -24
  230. package/src/IKRouter.js +0 -47
  231. package/src/IKStepTransaction.js +0 -14
  232. package/src/Logger/IKLogger.js +0 -136
  233. package/src/Mailer/IKMailer.js +0 -69
  234. package/src/Publisher/IKPublisher.js +0 -44
  235. package/src/Tracker/IKExecutionTracker.js +0 -79
  236. package/src/Validation/IKValidation.js +0 -76
@@ -1,136 +0,0 @@
1
- import abind from 'abind';
2
- import stackTrace from 'stack-trace';
3
- import stringify from 'json-stringify-safe';
4
- //
5
- import Utils from "./../API/IKUtils.js";
6
- //
7
- export const LOG_LEVELS = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
8
- const LOG_STRINGS = ['DEBUG', 'INFO', 'WARN', 'ERROR'];
9
- const PURE_CONSOLE = (console.flushLogs ? console.origin : console);
10
- const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE);
11
- //
12
- const blacklist = ['password','phonenumber'/*,'code'*/,'resetCode','recaptchaToken','token','mfa','REFRESH_TOKEN','SECRET_HASH','SecretHash','AccessToken','UserCode','paymentMethodNonce'];
13
- //
14
- export default class IKLogger {
15
- constructor(_config, _LOG_LEVEL, transactionID) {
16
- abind(this);
17
- //
18
- if (!_LOG_LEVEL && !(_config || {}).level) _LOG_LEVEL = LOG_LEVELS.DEBUG;
19
- else {
20
- _LOG_LEVEL = LOG_STRINGS.indexOf((_config || {}).level || _LOG_LEVEL);
21
- if (_LOG_LEVEL == -1) _LOG_LEVEL = LOG_LEVELS.DEBUG;
22
- }
23
- //
24
- this.origin = PURE_CONSOLE;
25
- this._LOG_LEVEL = _LOG_LEVEL;
26
- this._config = _config || {};
27
- this._transactionID = transactionID;
28
- this._filterBlacklist = this._config.sensitiveFilteringKeywords || blacklist;
29
- //
30
- this._setupBindings();
31
- //
32
- this.log("Using logger with level: " + LOG_STRINGS[this._LOG_LEVEL]);
33
- this.debug("logger config: ", this._config);
34
- }
35
-
36
- //Public
37
- debug(...args) { this._processLog(false, LOG_LEVELS.DEBUG, args); }
38
- log(...args) { this._processLog(false, LOG_LEVELS.INFO, args); }
39
- info(...args) { this._processLog(false, LOG_LEVELS.INFO, args); }
40
- warning(...args) { this._processLog(false, LOG_LEVELS.WARN, args); }
41
- warn(...args) { this._processLog(false, LOG_LEVELS.WARN, args); }
42
- error(...args) { this._processLog(false, LOG_LEVELS.ERROR, args); }
43
- exception(exception, ...args) { this._exception(false, exception, args); }
44
- _exception(isRaw ,exception, ...args) {
45
- //format message
46
- let msg = [];
47
- //push exeception
48
- msg.push(exception + " -");
49
- //get args
50
- for (let arg of args) if (arg != exception) msg.push(arg);
51
- msg.push(exception.stack); //push exeception stack at the end
52
- //push into logs stack
53
- this._pushLog(LOG_LEVELS.ERROR, this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3), isRaw));
54
- }
55
- //
56
- cleanUp() { }
57
- async flushLogs() {}
58
-
59
-
60
- //initialization
61
- _setupBindings() {
62
- global.console = {
63
- debug: (...args) => this._processLog(true, LOG_LEVELS.DEBUG, args),
64
- log: (...args) => this._processLog(true, LOG_LEVELS.INFO, args),
65
- info: (...args) => this._processLog(true, LOG_LEVELS.INFO, args),
66
- warning: (...args) => this._processLog(true, LOG_LEVELS.WARN, args),
67
- warn: (...args) => this._processLog(true, LOG_LEVELS.WARN, args),
68
- error: (...args) => this._processLog(true, LOG_LEVELS.ERROR, args),
69
- exception: (exception, ...args) => this._exception(true, exception, args),
70
- };
71
- }
72
-
73
-
74
- /* Formatters */
75
- _timestamp() {
76
- let d = new Date();
77
- return [Utils.toDoubleDigit(d.getMonth()+1), Utils.toDoubleDigit(d.getDate()), d.getFullYear()].join('/') +' ' +
78
- [Utils.toDoubleDigit(d.getHours()), Utils.toDoubleDigit(d.getMinutes()), Utils.toDoubleDigit(d.getSeconds())].join(':');
79
- }
80
- _formattedLog(level, msg, caller, isRaw) {
81
- if (Utils.isOffline()) {
82
- return ` [${this._timestamp()} - ${LOG_STRINGS[level]}] [${caller}] ${msg.join(" ")}`;
83
- } else if (Utils.isHybridlessContainer() && this._transactionID) {
84
- return (isRaw ? '' : ` ${this._transactionID}`) + ` [${LOG_STRINGS[level]}] [${caller}] ${(msg.map(this._supressSensitiveInfo).join(" "))}`;
85
- } else {
86
- return ` [${LOG_STRINGS[level]}] [${caller}] ${msg.join(" ")}`;
87
- }
88
- }
89
- _callerName(index) {
90
- let safeIndex = Math.min(index, stackTrace.get().length);
91
- if (stackTrace.get()[safeIndex]) {
92
- let callerName = (stackTrace.get()[safeIndex] ? stackTrace.get()[safeIndex].getTypeName() : null);
93
- if (!callerName) {
94
- callerName = stackTrace.get()[safeIndex].getFileName().split("/");
95
- callerName = callerName.slice(callerName.indexOf("src")).join("/");
96
- } return callerName + ":" + stackTrace.get()[safeIndex].getLineNumber();
97
- } return '';
98
- }
99
- /* Helpers (core functionality) */
100
- _processLog(isRaw, level, args) {
101
- if (level < this._LOG_LEVEL) return;
102
- //get args
103
- let msg = [];
104
- for (let arg of args) msg.push(((typeof arg === 'object' && !(arg instanceof Error)) ? stringify(arg, null, 2) : arg));
105
- //push into logs stack
106
- // todo: improve error stack
107
- this._pushLog(level, this._formattedLog(level, msg, this._callerName(3), isRaw));
108
- }
109
- _pushLog(level, fMsg) {
110
- // push into logs stack
111
- // this._logs.push(fMsg);
112
- DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg]);
113
- }
114
- /* Sensitive information handling */
115
- _supressSensitiveInfo(value) {
116
- //realy false
117
- if (this._config.enableSensitiveFiltering !== undefined && (!this._config.enableSensitiveFiltering || this._config.enableSensitiveFiltering == 'false')) return value;
118
- if (typeof value == "string") {
119
- //content based replacement
120
- blacklist.forEach((f) => {
121
- const match = blacklist.find((f) => value.toLowerCase().includes(f.toLowerCase()));
122
- if (match) value = '**SUPRESSED_SENSITIVE_DATA**';
123
- });
124
- return value;
125
- } else if (typeof value == 'object') {
126
- //key based replacement
127
- Object.keys(value).forEach(function (elt, i, array) {
128
- const match = blacklist.find((f) => elt.toLowerCase().includes(f.toLowerCase()));
129
- if (match) value[elt] = '**SUPRESSED_SENSITIVE_DATA**';
130
- else value[elt] = value[elt];
131
- });
132
- return value;
133
- } else if (Array.isArray(value)) return value.map(v=>this._supressSensitiveInfo(v));
134
- return value;
135
- }
136
- }
@@ -1,69 +0,0 @@
1
- import nodemailer from "nodemailer";
2
- import Email from 'email-templates';
3
- import AWSSES from "@aws-sdk/client-ses";
4
- //
5
- import { defaultProvider } from '@aws-sdk/credential-provider-node';
6
- import Utils from "./../API/IKUtils.js";
7
- //
8
- export default class IKMailer {
9
- constructor(_defaultFrom, region) {
10
- this.from = _defaultFrom;
11
- this.templateDefaultFile = 'html';
12
- //setup local stuff
13
- let configObj = {region: region};
14
- if (Utils.isOffline()) configObj = {region: region, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY};
15
- //
16
- this.transporter = nodemailer.createTransport({
17
- SES: {
18
- ses: new AWSSES.SESClient({ apiVersion: "2010-12-01", ...configObj, defaultProvider }),
19
- aws: AWSSES
20
- }
21
- });
22
- }
23
-
24
- //to and cc can be an array, just one address or a comma separated string containing multiple addresses
25
- async sendTemplatedEmail(_to, _templates, _data, _optionalCC, _optionalAttachments, _optionalHeaders, _optionalFrom) {
26
- //Generate emails
27
- const email = new Email({
28
- message: {
29
- ...(_optionalHeaders ? {headers: _optionalHeaders} : {}),
30
- from: _optionalFrom ? _optionalFrom : this.from,
31
- to: _to,
32
- ...(_optionalAttachments ? {attachments: _optionalAttachments} : {}),
33
- ...(_optionalCC ? {cc: _optionalCC} : {})
34
- },
35
- transport: this.transporter,
36
- send: true,
37
- });
38
- //
39
- let resp = null;
40
- try {
41
- const choosenTemplate = await this._chooseTemplate(_templates, _data);
42
- resp = await email.send({template: choosenTemplate, locals: _data});
43
- // console.debug('Mailer resp:', resp);
44
- } catch (e) { console.error('Mailer error:', e); }
45
- return resp;
46
- }
47
-
48
-
49
- /* private */
50
- async _chooseTemplate(templates, data) {
51
- if (Array.isArray(templates)) {
52
- //For each template check if can render it
53
- for (let template of templates) {
54
- if (await this._canRenderTemplate(template, data)) return template;
55
- }
56
- } else if (templates) {
57
- if (await this._canRenderTemplate(templates, data)) return templates;
58
- } throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above!`, data);
59
- }
60
- async _canRenderTemplate(template, data) {
61
- let validRenderResp = null;
62
- try {
63
- const email = new Email();
64
- validRenderResp = await email.render(`${template}/${this.templateDefaultFile}`, data);
65
- } catch (e) {
66
- console.log(`Error while checking renderability of email template ${template}`, e);
67
- } return (validRenderResp != null);
68
- }
69
- }
@@ -1,44 +0,0 @@
1
- import { SNSClient, PublishCommand } from "@aws-sdk/client-sns";
2
- import sha1 from 'sha1';
3
- //
4
- import Utils from "./../API/IKUtils.js";
5
- //reusable client
6
- var PUBLISHER_CONN = null;
7
- var PUBLISHER_CONN_HASH = null;
8
- //
9
- export default class IKPublisher {
10
- constructor(config) {
11
- if (config && config.region) {
12
- this.region = config.region;
13
- // console.debug(`Using region: ${this.region}`);
14
- }
15
- }
16
- /* Public */
17
- async publishOnTopic(messageObject, topic, additionalProps) {
18
- let resp = null;
19
- try {
20
- this._connect();
21
- //Send to SNS
22
- const params = {
23
- Message: JSON.stringify(messageObject),
24
- TopicArn: topic,
25
- ...(additionalProps ? additionalProps : {}),
26
- };
27
- resp = await PUBLISHER_CONN.send(new PublishCommand(params));
28
- } catch (e) {
29
- console.error(`Error while publishing into topic ${topic} with error: ${e}`);
30
- }
31
- console.debug('Publisher resp', resp);
32
- return resp;
33
- }
34
- /* Private */
35
- _connect() {
36
- if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
37
- //Configure when sending!
38
- let configObj = { region: this.region };
39
- if (Utils.isOffline()) configObj = { ...configObj, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY };
40
- PUBLISHER_CONN = (new SNSClient({ apiVersion: '2010-03-31', ...configObj }));
41
- PUBLISHER_CONN_HASH = sha1(this.region);
42
- }
43
- }
44
- }
@@ -1,79 +0,0 @@
1
- import RTClient from '@ikonintegration/mod-resources-tracker-client';
2
- //
3
- import Utils from "../API/IKUtils.js";
4
- //
5
- import fs from 'fs';
6
- //
7
- export default class IKExecutionTracker {
8
- constructor(config, context, db) {
9
- this.context = context;
10
- this.db = db;
11
- this.config = config;
12
- this.startedOn = Date.now();
13
- this.drainedExecution = false;
14
- if (config) this.client = this._getClient(config);
15
- this.claimers = {};
16
- }
17
- /* Public */
18
- appendClaimer(value, key) { this.claimers[value] = key; }
19
- appendEvent(event) { this.client.appendEvent(event); }
20
- //
21
- resetExecutionTrace() {
22
- this.startedOn = Date.now();
23
- this.drainedExecution = false;
24
- }
25
- async quickDrain() {
26
- try {
27
- //Check for client but claimers
28
- if (!this.client) return; //disabled
29
- //drain stats (drain will filter for events with claimers only)
30
- await this.client.drain(this.claimers);
31
- } catch (e) { console.error(`Error while draining tracker events: ${e}`); }
32
- }
33
- async trackExecAndDrain() {
34
- try {
35
- //Check
36
- if (this.drainedExecution) return;
37
- this.drainedExecution = true;
38
- //Check for client and claimers
39
- if (!this.client) return; //disabled
40
- //detect execution and log (ECS or lambda)
41
- this._detectExecutionAndLog();
42
- //detect DB and log (DDB only for now)
43
- this._collectDDBStats();
44
- //drain stats (drain will filter for events with claimers only)
45
- await this.client.drain(this.claimers);
46
- } catch (e) { console.error(`Error while tracking execution: ${e}`); }
47
- }
48
- /* private tracker */
49
- _detectExecutionAndLog() {
50
- //Is running on container?
51
- if (Utils.isHybridlessContainer()) {
52
- //ECS, get metadata info and log if applicable and succeeded on it
53
- const context = this._getECSMetadataObject();
54
- // console.debug('Context', context);
55
- if (context && context.ContainerInstanceARN) {
56
- const extraDetails = { startTime: this.startedOn, endTime: Date.now(), taskConfig: { cpu: process.env.CPU, memory: process.env.MEMORY, taskName: context.TaskDefinitionFamily } };
57
- const event = RTClient.newECSExecutionEvent(context.TaskARN, context.ContainerInstanceARN, extraDetails);
58
- this.appendEvent(event);
59
- }
60
- } else {
61
- const event = RTClient.newLambdaInvocationEvent(this.context ? this.context.awsRequestId : null);
62
- this.appendEvent(event); //lambda logging
63
- }
64
- }
65
- _collectDDBStats() {
66
- const stats = this.db ? this.db.getTrackerStats() : null;
67
- if (stats) this.client.appendEvent(RTClient.newDynamoEvent(stats.tableName, stats.readUnits, stats.writeUnits));
68
- }
69
- /* Private */
70
- _getClient(config) {
71
- return new RTClient({ busName: config.busName, region: config.region, source: config.appName });
72
- }
73
- /* ECS helper */
74
- _getECSMetadataObject() {
75
- try { return JSON.parse(fs.readFileSync(process.env.ECS_CONTAINER_METADATA_FILE)); }
76
- catch (e) { console.error('Unable to retrieve metadata object: ' + e); }
77
- return null;
78
- }
79
- }
@@ -1,76 +0,0 @@
1
- import IKGlobals from './../IKGlobals.js';
2
- import Utils from './../API/IKUtils.js';
3
- import IKResponse, { IKBadRequestResponse } from './../API/IKResponse.js';
4
- //https://www.npmjs.com/package/superstruct
5
- import * as struct from 'superstruct';
6
- //validation libs
7
- import isUuid from 'is-uuid';
8
- import isEmail from 'is-email';
9
- //
10
- export default class IKValidation {
11
- constructor(config) {
12
- this.customStruct = {};
13
- this._buildInternalTypes((config && config.additionalTypes ? config.additionalTypes : {}));
14
- }
15
- _buildInternalTypes(additionalTypes) {
16
- for (const key in IKValidation.internalTypes()) {
17
- this.customStruct[key] = struct.define(key, IKValidation.internalTypes()[key]);
18
- }
19
- for (const key in additionalTypes) {
20
- this.customStruct[key] = struct.define(key, additionalTypes[key]);
21
- }
22
- }
23
- async validate(spec, obj, request) {
24
- let assertion = null;
25
- let err = null;
26
- try {
27
- let parsedRawObj = obj;
28
- if (typeof spec == 'function') spec = spec(this)
29
- assertion = struct.assert(parsedRawObj, spec);
30
- } catch (e) {
31
- console.debug(e);
32
- const { path, value, type } = e;
33
- const key = (path ? path[0] : undefined);
34
- let errorMessage = e;
35
- //Check for value required error
36
- if (value === undefined) errorMessage = `Required value '${key}' is missing.`
37
- else if (type === undefined) errorMessage = `Unknown key '${key}'.`
38
- else errorMessage = `Invalid value '${value}' for key '${key}'.`
39
- //Generate error
40
- err = IKBadRequestResponse(IKGlobals.ErrorResponseValidationFail + errorMessage, IKGlobals.ErrorCode_InvalidInput);
41
- }
42
- //Catch error as response
43
- if (err) return err;
44
- //run normal code out of this try/catch scope
45
- return await request(obj);
46
- }
47
- }
48
- //
49
- IKValidation.internalTypes = function() {
50
- return {
51
- email: value => { return (isEmail(value) && value.length < 256); },
52
- fullAddress: value => {
53
- if (!value) return false;
54
- return true;
55
- },
56
- 'date-yyyymmdd': value => {
57
- if (!value) return false;
58
- //TODO CHECK DATE FORMAT
59
- let d = new Date(value);
60
- return (d instanceof Date && !isNaN(d));
61
- },
62
- 'arrayIDs': value => {
63
- if (!value || !Array.isArray(value)) return false;
64
- for (let id of value) if (id.length < 10) return false;
65
- return true;
66
- },
67
- //TODO: this should be moved out to the project requiring this
68
- ACEArray: value => {
69
- if (!value || !value.length) return false;
70
- for (let val of value) {
71
- if (!val.accessType || !val.roleID) return false;
72
- }
73
- return true;
74
- },
75
- }
76
- }