@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,132 @@
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 cuid from 'cuid';
11
+ import { parseMultiValueQueryStringParameters, parseQueryStringParameters } from './Utils.js';
12
+ import Globals from '../../../Globals.js';
13
+ /**
14
+ * Represents a generic handler event for serverless functions.
15
+ */
16
+ export default class GenericHandlerEvent {
17
+ /**
18
+ * Constructs a new instance of the class.
19
+ * @param {Request} request - The request object.
20
+ * @param {Server['handleServerlessEvent']} serverlessHandler - The serverless handler function.
21
+ * @returns None
22
+ */
23
+ constructor(request, serverlessHandler) {
24
+ this.request = request;
25
+ this.serverlessHandler = serverlessHandler;
26
+ }
27
+ /**
28
+ * Invokes the handler function asynchronously and returns a promise that resolves to a GenericHandlerEventResponse.
29
+ * @returns {Promise<GenericHandlerEventResponse>} A promise that resolves to a GenericHandlerEventResponse.
30
+ */
31
+ invoke() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ // eslint-disable-next-line no-async-promise-executor
34
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ // Build event and context
37
+ const event = this.buildEvent();
38
+ const context = this.buildContext(event, (err, data) => {
39
+ resolve({ err, data });
40
+ });
41
+ // Invoke
42
+ yield this.serverlessHandler(event, context);
43
+ }
44
+ catch (e) {
45
+ reject(e); // forward rejection
46
+ }
47
+ }));
48
+ });
49
+ }
50
+ /**
51
+ * Builds and returns an APIGatewayProxyEvent object based on the current request.
52
+ * @returns {APIGatewayProxyEvent} - The constructed APIGatewayProxyEvent object.
53
+ */
54
+ buildEvent() {
55
+ var _a, _b, _c, _d;
56
+ return {
57
+ body: this.request.body || null, //enforce key
58
+ rawBody: this.request['rawBody'],
59
+ headers: (this.request.headers || {}),
60
+ httpMethod: (_a = this.request.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
61
+ isBase64Encoded: false,
62
+ multiValueHeaders: (this.request.headers || {}),
63
+ multiValueQueryStringParameters: parseMultiValueQueryStringParameters(this.request.url),
64
+ path: this.request.path,
65
+ pathParameters: null,
66
+ queryStringParameters: this.request.url ? parseQueryStringParameters(this.request.url) : {},
67
+ requestContext: {
68
+ accountId: process.env.AWS_ACCOUNT_ID || 'undefined',
69
+ apiId: '',
70
+ authorizer: null,
71
+ domainName: undefined,
72
+ domainPrefix: undefined,
73
+ extendedRequestId: cuid(),
74
+ httpMethod: this.request.method ? this.request.method.toUpperCase() : '',
75
+ identity: {
76
+ accessKey: null,
77
+ accountId: process.env.AWS_ACCOUNT_ID || null,
78
+ caller: null,
79
+ apiKey: null,
80
+ apiKeyId: null,
81
+ clientCert: null,
82
+ cognitoAuthenticationProvider: null,
83
+ cognitoAuthenticationType: null,
84
+ cognitoIdentityId: null,
85
+ cognitoIdentityPoolId: null,
86
+ principalOrgId: null,
87
+ sourceIp: ((_b = this.request.headers) === null || _b === void 0 ? void 0 : _b['x-forwarded-for']) ||
88
+ ((_c = this.request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress) ||
89
+ '',
90
+ user: null,
91
+ userAgent: ((_d = this.request.headers) === null || _d === void 0 ? void 0 : _d['user-agent']) || null,
92
+ userArn: null,
93
+ },
94
+ path: this.request.path,
95
+ protocol: 'HTTP/1.1',
96
+ requestId: `${cuid()}-${cuid()}`,
97
+ requestTime: new Date().toISOString(),
98
+ requestTimeEpoch: Date.now(),
99
+ resourceId: '',
100
+ resourcePath: Globals.Listener_HTTP_ProxyRoute,
101
+ stage: process.env.STAGE || '',
102
+ },
103
+ resource: Globals.Listener_HTTP_ProxyRoute,
104
+ stageVariables: null,
105
+ };
106
+ }
107
+ /**
108
+ * Builds and returns a context object for an AWS Lambda function.
109
+ * @param {APIGatewayProxyEvent} event - The event object passed to the Lambda function.
110
+ * @param {(err?: Error | string, data?: any) => void} callback - The callback function to be called when the Lambda function completes.
111
+ * @returns {Context} - The context object for the Lambda function.
112
+ */
113
+ buildContext(event, callback) {
114
+ return {
115
+ awsRequestId: event.requestContext.requestId,
116
+ callbackWaitsForEmptyEventLoop: true,
117
+ getRemainingTimeInMillis: () => {
118
+ return 0;
119
+ },
120
+ done: (err, data) => callback(err, data),
121
+ fail: err => callback(err),
122
+ succeed: res => callback(undefined, res),
123
+ functionName: 'container-function',
124
+ functionVersion: 'LATEST',
125
+ invokedFunctionArn: 'none',
126
+ memoryLimitInMB: '-1',
127
+ logGroupName: 'undefined',
128
+ logStreamName: 'undefined',
129
+ };
130
+ }
131
+ }
132
+ //# sourceMappingURL=GenericHandlerEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericHandlerEvent.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/GenericHandlerEvent.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAGvB,OAAO,EAAE,oCAAoC,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,OAAO,MAAM,qBAAqB,CAAA;AAezC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAatC;;;;;OAKG;IACH,YAAY,OAAgB,EAAE,iBAAkD;QAC9E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACU,MAAM;;YACjB,qDAAqD;YACrD,OAAO,IAAI,OAAO,CAAC,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC3C,IAAI,CAAC;oBACH,0BAA0B;oBAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;oBAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,GAAoB,EAAE,IAAU,EAAE,EAAE;wBAC5E,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;oBACxB,CAAC,CAAC,CAAA;oBACF,SAAS;oBACT,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;gBAC9C,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,oBAAoB;gBAChC,CAAC;YACH,CAAC,CAAA,CAAC,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AAC,GAAG,EAAE,IAAI,CAAC;YACxC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC1B,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC;YACxC,YAAY,EAAE,oBAAoB;YAClC,eAAe,EAAE,QAAQ;YACzB,kBAAkB,EAAE,MAAM;YAC1B,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,WAAW;YACzB,aAAa,EAAE,WAAW;SAC3B,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { Request, Response } from 'express';
2
+ /**
3
+ * Handles a request and sends a response with the message 'Healthy!'.
4
+ * @param {Request} _request - The request object.
5
+ * @param {Response} res - The response object.
6
+ * @returns None
7
+ */
8
+ declare const _default: (_request: Request, res: Response) => Promise<void>;
9
+ export default _default;
@@ -0,0 +1,19 @@
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
+ /**
11
+ * Handles a request and sends a response with the message 'Healthy!'.
12
+ * @param {Request} _request - The request object.
13
+ * @param {Response} res - The response object.
14
+ * @returns None
15
+ */
16
+ export default (_request, res) => __awaiter(void 0, void 0, void 0, function* () {
17
+ res.send('Healthy!');
18
+ });
19
+ //# sourceMappingURL=HealthHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HealthHandler.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/HealthHandler.ts"],"names":[],"mappings":";;;;;;;;;AAEA;;;;;GAKG;AACH,eAAe,CAAO,QAAiB,EAAE,GAAa,EAAE,EAAE;IACxD,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACtB,CAAC,CAAA,CAAA"}
@@ -0,0 +1,67 @@
1
+ import Server from './../Server.js';
2
+ import { RouterConfig } from '../../Router.js';
3
+ /**
4
+ * Represents a Proxy class that handles routing and server functionality.
5
+ */
6
+ export default class Proxy {
7
+ /**
8
+ * A boolean flag indicating whether the process is currently stopping or not.
9
+ */
10
+ private stopping;
11
+ /**
12
+ * The configuration object for the router.
13
+ */
14
+ private readonly config;
15
+ /**
16
+ * The Express application instance for the server.
17
+ * @readonly
18
+ * @type {express.Express}
19
+ */
20
+ private readonly app;
21
+ /**
22
+ * The handler function for serverless events in the Server class.
23
+ * @param {ServerlessEvent} event - The serverless event object.
24
+ * @returns None
25
+ */
26
+ private readonly serverlessHandler;
27
+ /**
28
+ * Represents a listener for an HTTP server.
29
+ * @private
30
+ * @type {HTTPServer}
31
+ */
32
+ private listener;
33
+ /**
34
+ * Constructs a new instance of the Router class.
35
+ * @param {RouterConfig} config - The configuration object for the router.
36
+ * @param {Server['handleServerlessEvent']} serverlessHandler - The handler function for serverless events.
37
+ * @returns None
38
+ */
39
+ constructor(config: RouterConfig, serverlessHandler: Server['handleServerlessEvent']);
40
+ /**
41
+ * Loads the necessary components and initializes the application.
42
+ * @returns None
43
+ */
44
+ load(): Promise<void>;
45
+ /**
46
+ * Unloads the current module, stopping any active listeners.
47
+ * @param {any} [err] - Optional error object to pass to the stopListeners method.
48
+ * @returns {Promise<void>} - A promise that resolves once the listeners have been stopped.
49
+ */
50
+ unload(err?: any): Promise<void>;
51
+ /**
52
+ * Starts the listeners for the proxy server.
53
+ * @returns {Promise<void>} A promise that resolves when the listeners have started.
54
+ */
55
+ private startListeners;
56
+ /**
57
+ * Stops the listeners and exits the process.
58
+ * @param {any} [err] - Optional error object.
59
+ * @returns {Promise<void>} - A promise that resolves when the listeners are stopped and the process is exited.
60
+ */
61
+ private stopListeners;
62
+ /**
63
+ * Installs the routes for the proxy server.
64
+ * @returns None
65
+ */
66
+ private installRoutes;
67
+ }
@@ -0,0 +1,143 @@
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 fs from 'fs';
11
+ import { createServer } from 'http';
12
+ import cors from 'cors';
13
+ import express from 'express';
14
+ import GenericHandler from './GenericHandler.js';
15
+ import HealthHandler from './HealthHandler.js';
16
+ import Globals from '../../../Globals.js';
17
+ import Utils from '../../../Util/Utils.js';
18
+ /* Get package.json version from IKApi on ESM */
19
+ const { version: appVersion } = JSON.parse(fs.readFileSync('package.json').toString());
20
+ /**
21
+ * Represents a Proxy class that handles routing and server functionality.
22
+ */
23
+ export default class Proxy {
24
+ /**
25
+ * Constructs a new instance of the Router class.
26
+ * @param {RouterConfig} config - The configuration object for the router.
27
+ * @param {Server['handleServerlessEvent']} serverlessHandler - The handler function for serverless events.
28
+ * @returns None
29
+ */
30
+ constructor(config, serverlessHandler) {
31
+ this.stopping = false;
32
+ this.config = config;
33
+ this.serverlessHandler = serverlessHandler;
34
+ this.app = express();
35
+ /* Opinionated Express configs */
36
+ this.app.use(express.json({
37
+ verify(req, res, buf) {
38
+ req['rawBody'] = buf;
39
+ },
40
+ }));
41
+ // apply cors config
42
+ const corsConfig = this.config.cors || Utils.parseObjectNullIfEmpty(process.env.CORS);
43
+ this.app.use(cors(corsConfig
44
+ ? {
45
+ origin: corsConfig.origin,
46
+ allowedHeaders: corsConfig.headers,
47
+ credentials: !!corsConfig.allowCredentials,
48
+ }
49
+ : {}));
50
+ // //This supposedly fix some 502 codes where nodejs socket would hang during
51
+ // //a request and if behind ALB, it would cause 502 codes. Had experiencied this
52
+ // //and 502 codes reduced dramastically, but still some appearances. Maybe this
53
+ // //is just a palliative work-around for the real issue; TODO: need to investigate
54
+ // //in the future.
55
+ // this.listener.listener.keepAliveTimeout = 120e3
56
+ // this.listener.listener.headersTimeout = 120e3
57
+ }
58
+ /**
59
+ * Loads the necessary components and initializes the application.
60
+ * @returns None
61
+ */
62
+ load() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ yield this.startListeners();
65
+ this.installRoutes();
66
+ });
67
+ }
68
+ /**
69
+ * Unloads the current module, stopping any active listeners.
70
+ * @param {any} [err] - Optional error object to pass to the stopListeners method.
71
+ * @returns {Promise<void>} - A promise that resolves once the listeners have been stopped.
72
+ */
73
+ unload(err) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ yield this.stopListeners(err);
76
+ });
77
+ }
78
+ /**
79
+ * Starts the listeners for the proxy server.
80
+ * @returns {Promise<void>} A promise that resolves when the listeners have started.
81
+ */
82
+ startListeners() {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ // eslint-disable-next-line no-async-promise-executor
85
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
86
+ const port = this.config.port || Globals.Listener_HTTP_DefaultPort;
87
+ console.log(`[Proxy] - [STARTING] - v.${appVersion} - :${port}`);
88
+ // Create Server
89
+ this.listener = createServer(this.app);
90
+ // Set defaults
91
+ this.listener.setTimeout(this.config.timeout || Globals.Listener_HTTP_DefaultTimeout);
92
+ // Call hook if available
93
+ if (this.config.containerSetupHook)
94
+ yield this.config.containerSetupHook(this.listener, this.app);
95
+ // Start Server
96
+ this.listener.listen(port, () => {
97
+ console.log(`[Proxy] - [STARTED]`);
98
+ resolve();
99
+ });
100
+ }));
101
+ });
102
+ }
103
+ /**
104
+ * Stops the listeners and exits the process.
105
+ * @param {any} [err] - Optional error object.
106
+ * @returns {Promise<void>} - A promise that resolves when the listeners are stopped and the process is exited.
107
+ */
108
+ stopListeners(err) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ if (this.stopping)
111
+ return;
112
+ this.stopping = true;
113
+ console.debug('[Proxy] - [STOPPING]');
114
+ return new Promise(resolve => {
115
+ this.listener.close(_err => {
116
+ const err2 = err || _err;
117
+ if (err2)
118
+ console.log('[Proxy] - exit output:', err2);
119
+ console.log('[Proxy] - [STOPPED]');
120
+ process.exit(err2 ? 1 : 0);
121
+ resolve(null);
122
+ });
123
+ });
124
+ });
125
+ }
126
+ /**
127
+ * Installs the routes for the proxy server.
128
+ * @returns None
129
+ */
130
+ installRoutes() {
131
+ //Health check route -- This is a bypass route to only check if
132
+ //runtime proxy is working and responding to calls.
133
+ console.log(`[Proxy] - [HEALTH-ROUTE] - ${this.config.healthCheckRoute || Globals.Listener_HTTP_DefaultHealthCheckRoute}`);
134
+ this.app
135
+ .route(this.config.healthCheckRoute || Globals.Listener_HTTP_DefaultHealthCheckRoute)
136
+ .get(HealthHandler);
137
+ //Main route -- We use a wildcard route because is not the job of the runtime and neither
138
+ //the task to deny/constrain routes that invoked this task; all the job is done by the
139
+ //load balancer and we just foward everything we have to the function.
140
+ this.app.route(Globals.Listener_HTTP_ProxyRoute).all(GenericHandler(this.serverlessHandler));
141
+ }
142
+ }
143
+ //# sourceMappingURL=Proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Proxy.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/Proxy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAwB,YAAY,EAAE,MAAM,MAAM,CAAA;AAEzD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,OAAO,MAAM,SAAS,CAAA;AAG7B,OAAO,cAAc,MAAM,qBAAqB,CAAA;AAChD,OAAO,aAAa,MAAM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,IAAI,CAAA;YACpB,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;YACrC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;oBACzB,MAAM,IAAI,GAAG,GAAG,IAAI,IAAI,CAAA;oBACxB,IAAI,IAAI;wBAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAA;oBACrD,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;oBAClC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;oBAC1B,OAAO,CAAC,IAAI,CAAC,CAAA;gBACf,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAED;;;OAGG;IACK,aAAa;QACnB,+DAA+D;QAC/D,mDAAmD;QACnD,OAAO,CAAC,GAAG,CACT,8BACE,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,OAAO,CAAC,qCAC1C,EAAE,CACH,CAAA;QACD,IAAI,CAAC,GAAG;aACL,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,OAAO,CAAC,qCAAqC,CAAC;aACpF,GAAG,CAAC,aAAa,CAAC,CAAA;QACrB,yFAAyF;QACzF,sFAAsF;QACtF,sEAAsE;QACtE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAC9F,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parses the multi-value query string parameters from the given URL.
3
+ * @param {string} url - The URL containing the query string parameters.
4
+ * @returns {Object} - An object representing the parsed query string parameters.
5
+ */
6
+ export declare function parseMultiValueQueryStringParameters(url: string): any;
7
+ /**
8
+ * Parses the query string parameters from a given URL.
9
+ * @param {string} url - The URL to parse the query string parameters from.
10
+ * @returns {object | null} - An object containing the parsed query string parameters, or null if there are no parameters.
11
+ */
12
+ export declare function parseQueryStringParameters(url: any): {
13
+ [k: string]: string;
14
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Parses the multi-value query string parameters from the given URL.
3
+ * @param {string} url - The URL containing the query string parameters.
4
+ * @returns {Object} - An object representing the parsed query string parameters.
5
+ */
6
+ export function parseMultiValueQueryStringParameters(url) {
7
+ // dummy placeholder url for the WHATWG URL constructor
8
+ // https://github.com/nodejs/node/issues/12682
9
+ const { searchParams } = new URL(url, 'http://example');
10
+ //
11
+ if (Array.from(searchParams).length === 0)
12
+ return {};
13
+ const map = new Map();
14
+ // eslint-disable-next-line no-restricted-syntax
15
+ for (const [key, value] of searchParams) {
16
+ const item = map.get(key);
17
+ if (item)
18
+ item.push(value);
19
+ else
20
+ map.set(key, [value]);
21
+ }
22
+ return Object.fromEntries(map);
23
+ }
24
+ /**
25
+ * Parses the query string parameters from a given URL.
26
+ * @param {string} url - The URL to parse the query string parameters from.
27
+ * @returns {object | null} - An object containing the parsed query string parameters, or null if there are no parameters.
28
+ */
29
+ export function parseQueryStringParameters(url) {
30
+ // dummy placeholder url for the WHATWG URL constructor
31
+ // https://github.com/nodejs/node/issues/12682
32
+ const { searchParams } = new URL(url, 'http://example');
33
+ if (Array.from(searchParams).length === 0)
34
+ return {};
35
+ return Object.fromEntries(searchParams);
36
+ }
37
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/Utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,oCAAoC,CAAC,GAAW;IAC9D,uDAAuD;IACvD,8CAA8C;IAC9C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;IACvD,EAAE;IACF,IAAI,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;IACrB,gDAAgD;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,YAAY,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACzB,IAAI,IAAI;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;;YACrB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAG;IAC5C,uDAAuD;IACvD,8CAA8C;IAC9C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;IACvD,IAAI,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACpD,OAAO,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;AACzC,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Represents a class that can be used to create a singleton instance of a class that is created asynchronously.
3
+ */
4
+ export default class AsyncSingleton<T, R> {
5
+ private readonly factory;
6
+ private readonly checker;
7
+ private queue;
8
+ private instantiating;
9
+ private value?;
10
+ /**
11
+ * Creates a new instance of the AsyncSingleton class.
12
+ * @param factory The factory function that creates the instance.
13
+ * @param checker The function that checks if the instance is valid.
14
+ */
15
+ constructor(factory: (r: R) => Promise<T>, checker?: (value: T) => Promise<boolean>);
16
+ /**
17
+ * Gets the instance of the class.
18
+ * @param r The configuration object for creating the instance.
19
+ */
20
+ instance(r: R): Promise<T>;
21
+ /**
22
+ * Gets the current value, may be undefined or invalid.
23
+ */
24
+ getValue(): T | undefined;
25
+ /**
26
+ * Clears the current value and rejects all pending promises.
27
+ */
28
+ clear(): void;
29
+ private initHere;
30
+ private awaitOtherInit;
31
+ }
@@ -0,0 +1,83 @@
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
+ /**
11
+ * Represents a class that can be used to create a singleton instance of a class that is created asynchronously.
12
+ */
13
+ export default class AsyncSingleton {
14
+ /**
15
+ * Creates a new instance of the AsyncSingleton class.
16
+ * @param factory The factory function that creates the instance.
17
+ * @param checker The function that checks if the instance is valid.
18
+ */
19
+ constructor(factory, checker = () => __awaiter(this, void 0, void 0, function* () { return true; })) {
20
+ this.queue = [];
21
+ this.instantiating = false;
22
+ this.factory = factory;
23
+ this.checker = checker;
24
+ }
25
+ /**
26
+ * Gets the instance of the class.
27
+ * @param r The configuration object for creating the instance.
28
+ */
29
+ instance(r) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ if (this.value && (yield this.checker(this.value)))
32
+ return this.value;
33
+ if (this.instantiating) {
34
+ return yield this.awaitOtherInit();
35
+ }
36
+ return yield this.initHere(r);
37
+ });
38
+ }
39
+ /**
40
+ * Gets the current value, may be undefined or invalid.
41
+ */
42
+ getValue() {
43
+ return this.value;
44
+ }
45
+ /**
46
+ * Clears the current value and rejects all pending promises.
47
+ */
48
+ clear() {
49
+ this.value = undefined;
50
+ for (const [, rej] of this.queue) {
51
+ rej();
52
+ }
53
+ this.queue = [];
54
+ }
55
+ initHere(r) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ this.instantiating = true;
59
+ this.value = yield this.factory(r);
60
+ for (const [res] of this.queue) {
61
+ res();
62
+ }
63
+ this.queue = [];
64
+ return this.value;
65
+ }
66
+ finally {
67
+ for (const [, rej] of this.queue) {
68
+ rej();
69
+ }
70
+ this.instantiating = false;
71
+ }
72
+ });
73
+ }
74
+ awaitOtherInit() {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ yield new Promise((res, rej) => {
77
+ this.queue.push([res, rej]);
78
+ });
79
+ return this.value;
80
+ });
81
+ }
82
+ }
83
+ //# sourceMappingURL=AsyncSingleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncSingleton.js","sourceRoot":"","sources":["../../../src/Util/AsyncSingleton.ts"],"names":[],"mappings":";;;;;;;;;AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IASjC;;;;OAIG;IACH,YACE,OAA6B,EAC7B,UAA0C,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAA,GAAA;QAZpD,UAAK,GAAoB,EAAE,CAAA;QAC3B,kBAAa,GAAY,KAAK,CAAA;QAapC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;OAGG;IACU,QAAQ,CAAC,CAAI;;YACxB,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC,KAAK,CAAA;YAErE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACvB,OAAO,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;YACpC,CAAC;YAED,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAC/B,CAAC;KAAA;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACtB,KAAK,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACjC,GAAG,EAAE,CAAA;QACP,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACjB,CAAC;IAEa,QAAQ,CAAC,CAAI;;YACzB,IAAI,CAAC;gBACH,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;gBACzB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;gBAElC,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBAC/B,GAAG,EAAE,CAAA;gBACP,CAAC;gBAED,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;gBAEf,OAAO,IAAI,CAAC,KAAK,CAAA;YACnB,CAAC;oBAAS,CAAC;gBACT,KAAK,MAAM,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBACjC,GAAG,EAAE,CAAA;gBACP,CAAC;gBACD,IAAI,CAAC,aAAa,GAAG,KAAK,CAAA;YAC5B,CAAC;QACH,CAAC;KAAA;IAEa,cAAc;;YAC1B,MAAM,IAAI,OAAO,CAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACnC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;YAC7B,CAAC,CAAC,CAAA;YACF,OAAO,IAAI,CAAC,KAAM,CAAA;QACpB,CAAC;KAAA;CACF"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Utility class containing various static methods for common operations.
3
+ */
4
+ export default class Utils {
5
+ /**
6
+ * Checks if the application is running in a hybridless container.
7
+ * @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
8
+ */
9
+ static isHybridlessContainer(): boolean;
10
+ /**
11
+ * Checks if a given string is valid.
12
+ * @param {string} string - The string to check.
13
+ * @returns {boolean} - True if the string is valid, false otherwise.
14
+ */
15
+ static isValidString(string: string): boolean;
16
+ /**
17
+ * Parses a string into an integer and returns null if the string is not a valid number.
18
+ * @param {string} str - The string to parse into an integer.
19
+ * @returns {number | null} - The parsed integer or null if the string is not a valid number.
20
+ */
21
+ static parseIntNullIfNaN(str?: string): number | null;
22
+ /**
23
+ * Parses a JSON string and returns the resulting object. If the string is empty or
24
+ * cannot be parsed, null is returned.
25
+ * @param {string} string - The JSON string to parse.
26
+ * @returns {any | null} - The parsed object or null if the string is empty or invalid.
27
+ */
28
+ static parseObjectNullIfEmpty(string: string | undefined): any | null;
29
+ /**
30
+ * Checks if a given value is a valid number.
31
+ * @param {string} number - The value to be checked.
32
+ * @returns {boolean} - True if the value is a valid number, false otherwise.
33
+ */
34
+ static isValidNumber(number: string): boolean;
35
+ /**
36
+ * Retrieves the value from an object using a case-insensitive key lookup.
37
+ * @param {any} obj - The object to search for the key.
38
+ * @param {string} key - The key to search for in the object.
39
+ * @returns {any | null} The value associated with the key, or null if the key is not found.
40
+ */
41
+ static caseInsensitiveObjectForKey(obj: any, key: string): any | null;
42
+ /**
43
+ * Cleans out the /tmp directory asynchronously.
44
+ */
45
+ static cleanTemporaryFolder(): Promise<void>;
46
+ /**
47
+ * Marshalls the given item into a DynamoDB format.
48
+ * If the item is an array, it maps over each element and marshalls it recursively.
49
+ * 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.
50
+ * If the item is neither an array nor an object, it converts the item to an attribute.
51
+ * @param {any} item - The item to be marshalled.
52
+ * @returns The marshalled item in DynamoDB format.
53
+ */
54
+ static ddbMarshall<T>(item: T, rec?: boolean): any;
55
+ /**
56
+ * Recursively unmarshalls a DynamoDB item by converting it into a plain JavaScript object.
57
+ * @param {any} item - The DynamoDB item to unmarshall.
58
+ * @returns {any} The unmarshalled JavaScript object.
59
+ */
60
+ static ddbUnmarshall(item: any): any;
61
+ }