@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
@@ -0,0 +1,147 @@
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 child_process from 'child_process';
11
+ import { convertToAttr, marshall, unmarshall } from '@aws-sdk/util-dynamodb';
12
+ /**
13
+ * Utility class containing various static methods for common operations.
14
+ */
15
+ export default class Utils {
16
+ /**
17
+ * Checks if the application is running in a hybridless container.
18
+ * @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
19
+ */
20
+ static isHybridlessContainer() {
21
+ return process.env.HYBRIDLESS_RUNTIME == 'true';
22
+ }
23
+ /**
24
+ * Checks if a given string is valid.
25
+ * @param {string} string - The string to check.
26
+ * @returns {boolean} - True if the string is valid, false otherwise.
27
+ */
28
+ static isValidString(string) {
29
+ return (string === null || string === void 0 ? void 0 : string.length) > 0 && !Array.isArray(string);
30
+ }
31
+ /**
32
+ * Parses a string into an integer and returns null if the string is not a valid number.
33
+ * @param {string} str - The string to parse into an integer.
34
+ * @returns {number | null} - The parsed integer or null if the string is not a valid number.
35
+ */
36
+ static parseIntNullIfNaN(str) {
37
+ const n = parseInt(str || '');
38
+ return isNaN(n) ? null : n;
39
+ }
40
+ /**
41
+ * Parses a JSON string and returns the resulting object. If the string is empty or
42
+ * cannot be parsed, null is returned.
43
+ * @param {string} string - The JSON string to parse.
44
+ * @returns {any | null} - The parsed object or null if the string is empty or invalid.
45
+ */
46
+ static parseObjectNullIfEmpty(string) {
47
+ let o = null;
48
+ try {
49
+ o = string ? JSON.parse(string) : null;
50
+ if (o && Object.keys(o).length <= 0)
51
+ o = null;
52
+ }
53
+ catch (e) {
54
+ /* empty */
55
+ }
56
+ return o;
57
+ }
58
+ /**
59
+ * Checks if a given value is a valid number.
60
+ * @param {string} number - The value to be checked.
61
+ * @returns {boolean} - True if the value is a valid number, false otherwise.
62
+ */
63
+ static isValidNumber(number) {
64
+ let validNumb = NaN;
65
+ try {
66
+ validNumb = parseInt(number + '');
67
+ }
68
+ catch (e) {
69
+ console.error('Error while validating number', e);
70
+ }
71
+ return !isNaN(validNumb) && !Array.isArray(number);
72
+ }
73
+ /**
74
+ * Retrieves the value from an object using a case-insensitive key lookup.
75
+ * @param {any} obj - The object to search for the key.
76
+ * @param {string} key - The key to search for in the object.
77
+ * @returns {any | null} The value associated with the key, or null if the key is not found.
78
+ */
79
+ static caseInsensitiveObjectForKey(obj, key) {
80
+ if (!obj)
81
+ return null;
82
+ const insensitiveKey = Object.keys(obj).find(k => k.toLowerCase() === key.toLowerCase());
83
+ if (insensitiveKey && insensitiveKey != '')
84
+ return obj[insensitiveKey];
85
+ return null;
86
+ }
87
+ /**
88
+ * Cleans out the /tmp directory asynchronously.
89
+ */
90
+ static cleanTemporaryFolder() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ return new Promise(resolve => {
93
+ try {
94
+ child_process.execSync('rm -rf /tmp/*');
95
+ console.log('Cleaned tmp folder');
96
+ }
97
+ catch (err) {
98
+ console.error('Error while cleaning tmp folder', err);
99
+ }
100
+ finally {
101
+ resolve();
102
+ }
103
+ });
104
+ });
105
+ }
106
+ /**
107
+ * Marshalls the given item into a DynamoDB format.
108
+ * If the item is an array, it maps over each element and marshalls it recursively.
109
+ * If the item is an object, it marshalls the object using the marshall function with options to remove undefined values and convert class instances to maps.
110
+ * If the item is neither an array nor an object, it converts the item to an attribute.
111
+ * @param {any} item - The item to be marshalled.
112
+ * @returns The marshalled item in DynamoDB format.
113
+ */
114
+ static ddbMarshall(item, rec) {
115
+ if (Array.isArray(item))
116
+ return { L: item.map(_i => this.ddbMarshall(_i, true)) };
117
+ else if (typeof item === 'object' && isNaN(parseInt(item))) {
118
+ const marshalled = marshall(item, {
119
+ removeUndefinedValues: true,
120
+ convertClassInstanceToMap: true,
121
+ });
122
+ if (rec)
123
+ return { M: marshalled };
124
+ else
125
+ return marshalled;
126
+ }
127
+ else
128
+ return convertToAttr(item, { removeUndefinedValues: true, convertClassInstanceToMap: true });
129
+ }
130
+ /**
131
+ * Recursively unmarshalls a DynamoDB item by converting it into a plain JavaScript object.
132
+ * @param {any} item - The DynamoDB item to unmarshall.
133
+ * @returns {any} The unmarshalled JavaScript object.
134
+ */
135
+ static ddbUnmarshall(item) {
136
+ if (!item && item !== false)
137
+ return null;
138
+ if (Array.isArray(item)) {
139
+ return item.map(_item => this.ddbUnmarshall(_item));
140
+ }
141
+ else if (typeof item === 'object') {
142
+ return unmarshall(item);
143
+ }
144
+ return item;
145
+ }
146
+ }
147
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/Util/Utils.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ import Response, { ResponseErrorType } from '../API/Response.js';
3
+ /**
4
+ * Validates the given data against the provided schema.
5
+ * @param {any} data - The data to be validated.
6
+ * @param {z.ZodObject<any>} schema - The schema to validate against.
7
+ * @returns {boolean | Response<ResponseErrorType>} - Returns true if the data is valid, otherwise returns a response object with an error message.
8
+ */
9
+ export default class Validator {
10
+ /**
11
+ * Validates the given data against the provided schema.
12
+ * @param {any} data - The data to be validated.
13
+ * @param {z.ZodObject<any> | z.ZodUnion<any>} schema - The schema to validate against.
14
+ * @returns {boolean | Response<ResponseErrorType>} - Returns either true if the data is valid or a Response object with an error message if validation fails.
15
+ */
16
+ static validateSchema(data: any, schema: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>): boolean | Response<ResponseErrorType>;
17
+ }
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ import Response from '../API/Response.js';
3
+ import Globals from '../Globals.js';
4
+ /**
5
+ * Validates the given data against the provided schema.
6
+ * @param {any} data - The data to be validated.
7
+ * @param {z.ZodObject<any>} schema - The schema to validate against.
8
+ * @returns {boolean | Response<ResponseErrorType>} - Returns true if the data is valid, otherwise returns a response object with an error message.
9
+ */
10
+ export default class Validator {
11
+ /**
12
+ * Validates the given data against the provided schema.
13
+ * @param {any} data - The data to be validated.
14
+ * @param {z.ZodObject<any> | z.ZodUnion<any>} schema - The schema to validate against.
15
+ * @returns {boolean | Response<ResponseErrorType>} - Returns either true if the data is valid or a Response object with an error message if validation fails.
16
+ */
17
+ static validateSchema(data, schema) {
18
+ let error, validatedInput;
19
+ // Validate body against known zod schema
20
+ try {
21
+ schema.parse(data);
22
+ validatedInput = true;
23
+ }
24
+ catch (err) {
25
+ if (err instanceof z.ZodError)
26
+ error = JSON.parse(err.message);
27
+ else
28
+ error = 'Unknown validation error!'; //unhandled case, hard to test
29
+ }
30
+ // Error validation
31
+ if (!validatedInput || error) {
32
+ return Response.BadRequestResponse(Globals.ErrorResponseValidationFail, Globals.ErrorCode_InvalidInput, { validationFailure: error });
33
+ }
34
+ else {
35
+ return true;
36
+ }
37
+ }
38
+ }
39
+ //# sourceMappingURL=Validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validation/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,QAA+B,MAAM,oBAAoB,CAAA;AAChE,OAAO,OAAO,MAAM,eAAe,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAC1B,IAAS,EACT,MAAwE;QAExE,IAAI,KAAK,EAAE,cAAc,CAAA;QAEzB,yCAAyC;QACzC,IAAI,CAAC;YACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAClB,cAAc,GAAG,IAAI,CAAA;QACvB,CAAC;QAAC,OAAO,GAAqB,EAAE,CAAC;YAC/B,IAAI,GAAG,YAAY,CAAC,CAAC,QAAQ;gBAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;;gBACzD,KAAK,GAAG,2BAA2B,CAAA,CAAC,8BAA8B;QACzE,CAAC;QAED,mBAAmB;QACnB,IAAI,CAAC,cAAc,IAAI,KAAK,EAAE,CAAC;YAC7B,OAAO,QAAQ,CAAC,kBAAkB,CAChC,OAAO,CAAC,2BAA2B,EACnC,OAAO,CAAC,sBAAsB,EAC9B,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAA;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ {"root":["../index.ts","../src/globals.ts","../src/api/request.ts","../src/api/response.ts","../src/baseevent/dynamotransaction.ts","../src/baseevent/eventprocessor.ts","../src/baseevent/process.ts","../src/baseevent/steptransaction.ts","../src/baseevent/transaction.ts","../src/cache/redis.ts","../src/cache/types.ts","../src/config/configuration.ts","../src/config/environmentvar.ts","../src/crypto/crypto.ts","../src/database/database.ts","../src/database/databasemanager.ts","../src/database/databasetransaction.ts","../src/database/index.ts","../src/database/types.ts","../src/database/integrations/dynamo/dynamodatabase.ts","../src/database/integrations/kysely/kyselydatabase.ts","../src/database/integrations/kysely/kyselytransaction.ts","../src/database/integrations/pgsql/postgresdatabase.ts","../src/database/integrations/pgsql/postgrestransaction.ts","../src/logger/logger.ts","../src/mailer/mailer.ts","../src/publisher/publisher.ts","../src/server/routeresolver.ts","../src/server/router.ts","../src/server/lib/containerserver.ts","../src/server/lib/server.ts","../src/server/lib/container/generichandler.ts","../src/server/lib/container/generichandlerevent.ts","../src/server/lib/container/healthhandler.ts","../src/server/lib/container/proxy.ts","../src/server/lib/container/utils.ts","../src/util/asyncsingleton.ts","../src/util/utils.ts","../src/validation/validator.ts","../package-lock.json","../package.json"],"version":"5.6.2"}
package/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { HttpMethod } from './src/API/Request.js'
2
+ import Response, { ResponseErrorType } from './src/API/Response.js'
3
+ import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js'
4
+ import EventProcessor from './src/BaseEvent/EventProcessor.js'
5
+ import Process from './src/BaseEvent/Process.js'
6
+ import StepTransaction from './src/BaseEvent/StepTransaction.js'
7
+ import Transaction, { TransactionConfig } from './src/BaseEvent/Transaction.js'
8
+ import Redis from './src/Cache/Redis.js'
9
+ import Configuration from './src/Config/Configuration.js'
10
+ import Crypto from './src/Crypto/Crypto.js'
11
+ import * as Database from './src/Database/index.js'
12
+ import Mailer from './src/Mailer/Mailer.js'
13
+ import Router, { Route } from './src/Server/Router.js'
14
+ import AsyncSingleton from './src/Util/AsyncSingleton.js'
15
+ import Utils from './src/Util/Utils.js'
16
+
17
+ export {
18
+ // Base Events
19
+ Transaction,
20
+ Process,
21
+ EventProcessor,
22
+ DynamoTransaction,
23
+ StepTransaction,
24
+ // Http
25
+ Router,
26
+ Route,
27
+ HttpMethod,
28
+ // Modules
29
+ Mailer,
30
+ Crypto,
31
+ Configuration,
32
+ Redis,
33
+ Database,
34
+ // API
35
+ Response,
36
+ ResponseErrorType,
37
+ // Helpers
38
+ Utils,
39
+ AsyncSingleton,
40
+ TransactionConfig,
41
+ }
package/jest.config.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { Config } from '@jest/types'
2
+ /* eslint-env node */
3
+ const config: Config.InitialOptions = {
4
+ preset: 'ts-jest/presets/default-esm',
5
+ testEnvironment: 'node',
6
+ modulePathIgnorePatterns: ['smoke-tests'],
7
+ reporters: [
8
+ 'default',
9
+ [
10
+ 'jest-junit',
11
+ {
12
+ outputDirectory: 'coverage',
13
+ outputName: 'jest-junit.xml',
14
+ ancestorSeparator: ' › ',
15
+ uniqueOutputName: 'false',
16
+ suiteNameTemplate: '{filepath}',
17
+ classNameTemplate: '{classname}',
18
+ titleTemplate: '{title}',
19
+ },
20
+ ],
21
+ ],
22
+ coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
23
+ collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
24
+ coverageThreshold: {
25
+ global: {
26
+ branches: 80,
27
+ functions: 80,
28
+ lines: 80,
29
+ statements: 80,
30
+ },
31
+ },
32
+ // .js imports support
33
+ moduleNameMapper: {
34
+ '^(\\.\\.?\\/.+)\\.jsx?$': '$1',
35
+ },
36
+ }
37
+ export default config
@@ -0,0 +1,34 @@
1
+ import type { Config } from '@jest/types'
2
+ /* eslint-env node */
3
+ const config: Config.InitialOptions = {
4
+ testEnvironment: 'node',
5
+ // ECMA suppport https://jestjs.io/docs/ecmascript-modules
6
+ transform: {},
7
+ //
8
+ reporters: [
9
+ 'default',
10
+ [
11
+ 'jest-junit',
12
+ {
13
+ outputDirectory: 'coverage',
14
+ outputName: 'jest-junit.xml',
15
+ ancestorSeparator: ' › ',
16
+ uniqueOutputName: 'false',
17
+ suiteNameTemplate: '{filepath}',
18
+ classNameTemplate: '{classname}',
19
+ titleTemplate: '{title}',
20
+ },
21
+ ],
22
+ ],
23
+ coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
24
+ collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
25
+ coverageThreshold: {
26
+ global: {
27
+ branches: 70,
28
+ functions: 70,
29
+ lines: 70,
30
+ statements: 70,
31
+ },
32
+ },
33
+ }
34
+ export default config
package/package.json CHANGED
@@ -1,37 +1,81 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "",
5
- "main": "index.js",
6
- "module": "main.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1",
10
- "pre-publish": "npm i -production && curl -sf https://gobinaries.com/tj/node-prune | sh && node-prune"
9
+ "build": "tsc --build",
10
+ "clean": "tsc --build --clean",
11
+ "lint-fix": "eslint . --fix",
12
+ "lint": "eslint .",
13
+ "docs": "npx typedoc --tsconfig tsconfig.json index.ts src/**/* --includeVersion --entryPointStrategy expand",
14
+ "test": "npm run test-ts && npm run test-js",
15
+ "test-ts": "jest --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
16
+ "test-js": "rm -rf ./smoke-tests; tsc -p tsconfig.smoke.json && cd smoke-tests && npm i && NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --config=./jest.smoke.config.js --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
17
+ "test-dev": "jest --coverage --runInBand && cat coverage/coverage.txt"
11
18
  },
12
19
  "author": "",
13
20
  "license": "ISC",
14
21
  "dependencies": {
15
- "@aws-sdk/client-dynamodb": "^3.363.0",
16
- "@aws-sdk/client-ses": "^3.363.0",
17
- "@aws-sdk/client-sns": "^3.363.0",
18
- "@aws-sdk/credential-provider-node": "^3.363.0",
19
- "@aws-sdk/node-http-handler": "^3.360.0",
20
- "@aws-sdk/util-dynamodb": "^3.365.0",
21
- "@aws-sdk/util-endpoints": "^3.357.0",
22
- "@ikonintegration/mod-resources-tracker-client": "0.0.19",
22
+ "@aws-sdk/client-dynamodb": "^3.650.0",
23
+ "@aws-sdk/client-kms": "^3.650.0",
24
+ "@aws-sdk/client-secrets-manager": "^3.650.0",
25
+ "@aws-sdk/client-ses": "^3.650.0",
26
+ "@aws-sdk/client-sns": "^3.650.0",
27
+ "@aws-sdk/client-ssm": "^3.650.0",
28
+ "@aws-sdk/credential-provider-node": "^3.650.0",
29
+ "@aws-sdk/util-dynamodb": "^3.650.0",
30
+ "@smithy/node-http-handler": "^3.2.0",
31
+ "@types/email-templates": "^10.0.1",
32
+ "@types/nodemailer": "^6.4.10",
33
+ "@types/object-hash": "^3.0.4",
23
34
  "abind": "^1.0.5",
24
- "bluebird": "^3.7.2",
25
- "email-templates": "^11.0.5",
26
- "is-email": "^1.0.2",
27
- "is-uuid": "^1.0.2",
35
+ "cors": "^2.8.5",
36
+ "cuid": "^3.0.0",
37
+ "dotenv": "^16.4.1",
38
+ "email-templates": "^12.0.1",
39
+ "express": "^4.21.0",
28
40
  "json-stringify-safe": "^5.0.1",
29
- "ksuid": "^3.0.0",
30
- "nodemailer": "^6.9.3",
31
- "path-to-regexp": "^6.3.0",
32
- "pg": "^8.11.1",
41
+ "kysely": "^0.27.2",
42
+ "node-cache": "^5.1.2",
43
+ "object-hash": "^3.0.0",
44
+ "parse-duration": "^1.1.0",
45
+ "path-to-regexp": "^8.1.0",
46
+ "pg": "^8.11.3",
47
+ "redis": "^4.7.0",
33
48
  "sha1": "^1.1.1",
34
49
  "stack-trace": "0.0.10",
35
- "superstruct": "1.0.3"
50
+ "zod": "^3.23.4"
51
+ },
52
+ "devDependencies": {
53
+ "@jest/globals": "^29.7.0",
54
+ "@types/aws-lambda": "^8.10.145",
55
+ "@types/chai": "^4.3.19",
56
+ "@types/cors": "^2.8.15",
57
+ "@types/express": "^4.17.19",
58
+ "@types/jest": "^29.5.13",
59
+ "@types/node": "^20.12.7",
60
+ "@types/path-to-regexp": "^1.7.0",
61
+ "@types/pg": "^8.11.9",
62
+ "@types/supertest": "^6.0.2",
63
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
64
+ "@typescript-eslint/parser": "^7.7.1",
65
+ "aws-lambda": "^1.0.7",
66
+ "aws-sdk-client-mock": "^4.0.0",
67
+ "chai": "^4.4.1",
68
+ "eslint": "^8.48.0",
69
+ "eslint-config-prettier": "^9.0.0",
70
+ "eslint-plugin-import": "^2.30.0",
71
+ "eslint-plugin-prettier": "^5.0.0",
72
+ "eslint-plugin-require-extensions": "^0.1.3",
73
+ "jest": "^29.7.0",
74
+ "jest-junit": "^16.0.0",
75
+ "prettier": "^3.2.5",
76
+ "supertest": "^7.0.0",
77
+ "ts-jest": "^29.2.5",
78
+ "ts-node": "^10.9.1",
79
+ "typescript": "^5.6.2"
36
80
  }
37
81
  }
@@ -0,0 +1,214 @@
1
+ import type { Context, APIGatewayEvent } from 'aws-lambda'
2
+
3
+ import Logger from '../Logger/Logger.js'
4
+ import Utils from '../Util/Utils.js'
5
+
6
+ /**
7
+ * Represents a request object with generic types for input, query parameters, and path parameters.
8
+ * @class Request
9
+ * @template InputType - The type of the input data for the request.
10
+ * @template PathParamsType - The type of the path parameters for the request.
11
+ * @template QueryParamsType - The type of the query parameters for the request.
12
+ */
13
+ export default class Request<InputType, PathParamsType, QueryParamsType> {
14
+ /**
15
+ * Represents an API Gateway event for a request.
16
+ * @type {APIGatewayEvent}
17
+ */
18
+ private requestEvent: APIGatewayEvent
19
+ /**
20
+ * The context object for the current instance.
21
+ */
22
+ private context: Context
23
+
24
+ /**
25
+ * Constructs a new instance of the class.
26
+ * @param {APIGatewayEvent} requestEvent - The API Gateway event object.
27
+ * @param {Context} context - The context object.
28
+ * @param {Logger} logger - The logger object.
29
+ * @returns None
30
+ */
31
+ constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
32
+ this.requestEvent = requestEvent
33
+ this.context = context
34
+ logger.debug('Request info:', requestEvent)
35
+ logger.debug('Request context:', context)
36
+ }
37
+
38
+ /**
39
+ * Checks if the specified query parameter exists and has a valid value.
40
+ * @param {keyof QueryParamsType} paramName - The name of the query parameter to check.
41
+ * @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
42
+ */
43
+ public containsQueryParam(paramName: keyof QueryParamsType): boolean {
44
+ const val = this.getQueryParam(paramName)
45
+ return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
46
+ }
47
+
48
+ /**
49
+ * Retrieves the value of a query parameter from the URL.
50
+ * @param {keyof QueryParamsType} paramName - The name of the query parameter to retrieve.
51
+ * @returns {string | null} The value of the query parameter, or null if it does not exist.
52
+ */
53
+ public getQueryParam(paramName: keyof QueryParamsType): string {
54
+ return Utils.caseInsensitiveObjectForKey(
55
+ this.requestEvent.queryStringParameters,
56
+ String(paramName)
57
+ )
58
+ }
59
+
60
+ /**
61
+ * Retrieves the value of the specified header from the request event headers.
62
+ * @param {string} headerName - The name of the header to retrieve.
63
+ * @returns {string | null} - The value of the header, or null if the header is not found.
64
+ */
65
+ public getHeader(headerName: string): string | null {
66
+ return Utils.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName)
67
+ }
68
+
69
+ /**
70
+ * Retrieves the value of a context parameter from the request context object.
71
+ * @param {string} cxtParam - The name of the context parameter to retrieve.
72
+ * @returns The value of the context parameter, or null if it does not exist.
73
+ */
74
+ public getContextParam(cxtParam: string): any | null {
75
+ return Utils.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam)
76
+ }
77
+
78
+ /**
79
+ * Checks if the given parameter name exists in the PathParamsType object.
80
+ * @param {keyof PathParamsType} paramName - The name of the parameter to check.
81
+ * @returns {boolean} - True if the parameter exists, false otherwise.
82
+ */
83
+ public containsPathParam(paramName: keyof PathParamsType): boolean {
84
+ const val = this.getPathParam(paramName)
85
+ return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
86
+ }
87
+
88
+ /**
89
+ * Retrieves the value of a specific path parameter from the URL.
90
+ * @param {keyof PathParamsType} paramName - The name of the path parameter to retrieve.
91
+ * @returns {string} The value of the path parameter, or null if it does not exist.
92
+ */
93
+ public getPathParam(paramName: keyof PathParamsType): string {
94
+ return Utils.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, String(paramName))
95
+ }
96
+
97
+ /**
98
+ * Retrieves the body of the request event and parses it if it is a string.
99
+ * @returns {InputType} The parsed body of the request event.
100
+ */
101
+ public getBody(raw?: boolean): InputType {
102
+ const body: any = this.requestEvent.body
103
+
104
+ if (raw) return Utils.isHybridlessContainer() ? this.requestEvent['rawBody'] : body
105
+
106
+ if (typeof body === 'string' || body instanceof String) {
107
+ try {
108
+ return JSON.parse(body as string)
109
+ } catch (e) {
110
+ console.error('Error while getting request body!', e)
111
+ }
112
+ }
113
+
114
+ return body
115
+ }
116
+
117
+ /**
118
+ * Retrieves the path from the request event.
119
+ * @returns {string} The path of the request event.
120
+ */
121
+ public getPath(): string {
122
+ return this.requestEvent.path
123
+ }
124
+
125
+ /**
126
+ * Retrieves the HTTP method of the current request.
127
+ * @returns {string} The HTTP method of the request.
128
+ */
129
+ public getMethod(): HttpMethod {
130
+ if (this.requestEvent.httpMethod) {
131
+ const httpMethod = this.requestEvent.httpMethod.toUpperCase()
132
+ if (httpMethod in HttpMethod) {
133
+ return HttpMethod[httpMethod]
134
+ }
135
+ }
136
+
137
+ throw new Error(`Invalid HTTP method: ${this.requestEvent.httpMethod}`)
138
+ }
139
+
140
+ /**
141
+ * Retrieves the path parameters from the request event.
142
+ * @returns {PathParamsType | null} - The path parameters object, or null if not found.
143
+ */
144
+ public getPathParams(): PathParamsType {
145
+ // type conversion guaranteed by validation
146
+ return this.requestEvent.pathParameters as PathParamsType
147
+ }
148
+
149
+ /**
150
+ * Retrieves the query parameters from the request event.
151
+ * @returns {QueryParamsType | null} - The query parameters object, or null if not found.
152
+ */
153
+ public getQueryParams(): QueryParamsType {
154
+ // type conversion guaranteed by validation
155
+ return this.requestEvent.queryStringParameters as QueryParamsType
156
+ }
157
+
158
+ /**
159
+ * Retrieves the value of the 'Authorization' header from the request.
160
+ * @returns The value of the 'Authorization' header, or null if it is not present.
161
+ */
162
+ public getAuthorizationHeader(): string | null {
163
+ return this.getHeader('Authorization')
164
+ }
165
+
166
+ /**
167
+ * Retrieves the request ID associated with the current execution context.
168
+ * @returns {string} The request ID.
169
+ */
170
+ public getRequestID(): string {
171
+ if (this.context.awsRequestId) return this.context.awsRequestId
172
+ return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown'
173
+ }
174
+
175
+ /**
176
+ * Retrieves the origin IP address of the request.
177
+ * @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
178
+ */
179
+ public getOriginIP(): string {
180
+ const origin = this.getContextParam('identity')?.sourceIp
181
+ const hOrigin = this.getHeader('X-Forwarded-For')
182
+ return origin ? origin : hOrigin ? hOrigin : 'unknown'
183
+ }
184
+
185
+ /**
186
+ * Sets the fixed path parameters in the request event object.
187
+ * @param {any[]} keys - An array of keys representing the path parameter names.
188
+ * @param {any[]} result - An array of values representing the path parameter values.
189
+ * @returns None
190
+ */
191
+ public setFixedPathParams(keys: any[], result: any[]): void {
192
+ if (!this.requestEvent.pathParameters) this.requestEvent.pathParameters = {}
193
+ keys.forEach((key, index) => {
194
+ if (this.requestEvent?.pathParameters) {
195
+ this.requestEvent.pathParameters[key.name] = result[index + 1]
196
+ }
197
+ })
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Enum representing the HTTP methods.
203
+ */
204
+ export enum HttpMethod {
205
+ GET = 'GET',
206
+ HEAD = 'HEAD',
207
+ POST = 'POST',
208
+ PUT = 'PUT',
209
+ DELETE = 'DELETE',
210
+ CONNECT = 'CONNECT',
211
+ OPTIONS = 'OPTIONS',
212
+ TRACE = 'TRACE',
213
+ PATCH = 'PATCH',
214
+ }