@ikonintegration/ikapi 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/package.json +1 -1
  2. package/src/BaseEvent/Launchable/ContainerExec.ts +0 -1
  3. package/src/Mailer/Mailer.ts +42 -52
  4. package/dist/index.d.ts +0 -17
  5. package/dist/index.js +0 -28
  6. package/dist/index.js.map +0 -1
  7. package/dist/package-lock.json +0 -11907
  8. package/dist/package.json +0 -82
  9. package/dist/src/API/Request.d.ts +0 -125
  10. package/dist/src/API/Request.js +0 -185
  11. package/dist/src/API/Request.js.map +0 -1
  12. package/dist/src/API/Response.d.ts +0 -188
  13. package/dist/src/API/Response.js +0 -270
  14. package/dist/src/API/Response.js.map +0 -1
  15. package/dist/src/BaseEvent/DynamoTransaction.d.ts +0 -70
  16. package/dist/src/BaseEvent/DynamoTransaction.js +0 -104
  17. package/dist/src/BaseEvent/DynamoTransaction.js.map +0 -1
  18. package/dist/src/BaseEvent/EventProcessor.d.ts +0 -58
  19. package/dist/src/BaseEvent/EventProcessor.js +0 -101
  20. package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
  21. package/dist/src/BaseEvent/Launchable/ContainerExec.d.ts +0 -42
  22. package/dist/src/BaseEvent/Launchable/ContainerExec.js +0 -104
  23. package/dist/src/BaseEvent/Launchable/ContainerExec.js.map +0 -1
  24. package/dist/src/BaseEvent/Launchable/index.d.ts +0 -34
  25. package/dist/src/BaseEvent/Launchable/index.js +0 -43
  26. package/dist/src/BaseEvent/Launchable/index.js.map +0 -1
  27. package/dist/src/BaseEvent/Launchable/types.d.ts +0 -10
  28. package/dist/src/BaseEvent/Launchable/types.js +0 -2
  29. package/dist/src/BaseEvent/Launchable/types.js.map +0 -1
  30. package/dist/src/BaseEvent/Process.d.ts +0 -50
  31. package/dist/src/BaseEvent/Process.js +0 -64
  32. package/dist/src/BaseEvent/Process.js.map +0 -1
  33. package/dist/src/BaseEvent/StepTransaction.d.ts +0 -23
  34. package/dist/src/BaseEvent/StepTransaction.js +0 -27
  35. package/dist/src/BaseEvent/StepTransaction.js.map +0 -1
  36. package/dist/src/BaseEvent/Transaction.d.ts +0 -149
  37. package/dist/src/BaseEvent/Transaction.js +0 -224
  38. package/dist/src/BaseEvent/Transaction.js.map +0 -1
  39. package/dist/src/Cache/Redis.d.ts +0 -29
  40. package/dist/src/Cache/Redis.js +0 -80
  41. package/dist/src/Cache/Redis.js.map +0 -1
  42. package/dist/src/Cache/types.d.ts +0 -31
  43. package/dist/src/Cache/types.js +0 -2
  44. package/dist/src/Cache/types.js.map +0 -1
  45. package/dist/src/Config/Configuration.d.ts +0 -123
  46. package/dist/src/Config/Configuration.js +0 -109
  47. package/dist/src/Config/Configuration.js.map +0 -1
  48. package/dist/src/Config/EnvironmentVar.d.ts +0 -74
  49. package/dist/src/Config/EnvironmentVar.js +0 -138
  50. package/dist/src/Config/EnvironmentVar.js.map +0 -1
  51. package/dist/src/Crypto/Crypto.d.ts +0 -45
  52. package/dist/src/Crypto/Crypto.js +0 -72
  53. package/dist/src/Crypto/Crypto.js.map +0 -1
  54. package/dist/src/Database/Database.d.ts +0 -21
  55. package/dist/src/Database/Database.js +0 -15
  56. package/dist/src/Database/Database.js.map +0 -1
  57. package/dist/src/Database/DatabaseManager.d.ts +0 -47
  58. package/dist/src/Database/DatabaseManager.js +0 -60
  59. package/dist/src/Database/DatabaseManager.js.map +0 -1
  60. package/dist/src/Database/DatabaseTransaction.d.ts +0 -101
  61. package/dist/src/Database/DatabaseTransaction.js +0 -126
  62. package/dist/src/Database/DatabaseTransaction.js.map +0 -1
  63. package/dist/src/Database/index.d.ts +0 -10
  64. package/dist/src/Database/index.js +0 -15
  65. package/dist/src/Database/index.js.map +0 -1
  66. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +0 -35
  67. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +0 -59
  68. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +0 -1
  69. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +0 -66
  70. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +0 -86
  71. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +0 -1
  72. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +0 -70
  73. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +0 -118
  74. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +0 -1
  75. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +0 -36
  76. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +0 -54
  77. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +0 -1
  78. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +0 -63
  79. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +0 -61
  80. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +0 -1
  81. package/dist/src/Database/types.d.ts +0 -76
  82. package/dist/src/Database/types.js +0 -2
  83. package/dist/src/Database/types.js.map +0 -1
  84. package/dist/src/Globals.d.ts +0 -93
  85. package/dist/src/Globals.js +0 -99
  86. package/dist/src/Globals.js.map +0 -1
  87. package/dist/src/Logger/Logger.d.ts +0 -161
  88. package/dist/src/Logger/Logger.js +0 -299
  89. package/dist/src/Logger/Logger.js.map +0 -1
  90. package/dist/src/Mailer/Mailer.d.ts +0 -78
  91. package/dist/src/Mailer/Mailer.js +0 -182
  92. package/dist/src/Mailer/Mailer.js.map +0 -1
  93. package/dist/src/Publisher/Publisher.d.ts +0 -39
  94. package/dist/src/Publisher/Publisher.js +0 -77
  95. package/dist/src/Publisher/Publisher.js.map +0 -1
  96. package/dist/src/Server/RouteResolver.d.ts +0 -33
  97. package/dist/src/Server/RouteResolver.js +0 -100
  98. package/dist/src/Server/RouteResolver.js.map +0 -1
  99. package/dist/src/Server/Router.d.ts +0 -157
  100. package/dist/src/Server/Router.js +0 -32
  101. package/dist/src/Server/Router.js.map +0 -1
  102. package/dist/src/Server/lib/ContainerServer.d.ts +0 -42
  103. package/dist/src/Server/lib/ContainerServer.js +0 -66
  104. package/dist/src/Server/lib/ContainerServer.js.map +0 -1
  105. package/dist/src/Server/lib/Server.d.ts +0 -45
  106. package/dist/src/Server/lib/Server.js +0 -93
  107. package/dist/src/Server/lib/Server.js.map +0 -1
  108. package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -9
  109. package/dist/src/Server/lib/container/GenericHandler.js +0 -82
  110. package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
  111. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -52
  112. package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -132
  113. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
  114. package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -9
  115. package/dist/src/Server/lib/container/HealthHandler.js +0 -19
  116. package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
  117. package/dist/src/Server/lib/container/Proxy.d.ts +0 -67
  118. package/dist/src/Server/lib/container/Proxy.js +0 -143
  119. package/dist/src/Server/lib/container/Proxy.js.map +0 -1
  120. package/dist/src/Server/lib/container/Utils.d.ts +0 -14
  121. package/dist/src/Server/lib/container/Utils.js +0 -37
  122. package/dist/src/Server/lib/container/Utils.js.map +0 -1
  123. package/dist/src/Util/AsyncSingleton.d.ts +0 -31
  124. package/dist/src/Util/AsyncSingleton.js +0 -83
  125. package/dist/src/Util/AsyncSingleton.js.map +0 -1
  126. package/dist/src/Util/Utils.d.ts +0 -61
  127. package/dist/src/Util/Utils.js +0 -147
  128. package/dist/src/Util/Utils.js.map +0 -1
  129. package/dist/src/Validation/Validator.d.ts +0 -17
  130. package/dist/src/Validation/Validator.js +0 -39
  131. package/dist/src/Validation/Validator.js.map +0 -1
  132. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,270 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import Globals from '../Globals.js';
11
- /**
12
- * CustomError class that extends the built-in Error class.
13
- * @class
14
- * @extends Error
15
- * @param {any} body - The body of the error, which can be an object or a string.
16
- * @constructor
17
- * @property {string} name - The name of the error.
18
- */
19
- class CustomError extends Error {
20
- constructor(body) {
21
- super(body.message || 'Unknown error!');
22
- this.name = body.error || 'UnknownError';
23
- }
24
- }
25
- /**
26
- * Represents a response object with various methods for building and manipulating the response.
27
- * @template BodyType - The type of the response body.
28
- */
29
- export default class Response {
30
- /**
31
- * Constructs a new Response object with the given status code, body, and optional behavior.
32
- * @param {number} statusCode - The HTTP status code of the response.
33
- * @param {BodyType} body - The body of the response.
34
- * @param {Object} [optBehaviour] - Optional behavior configuration for the response.
35
- * @param {boolean} [optBehaviour.shouldStream] - Indicates whether the response should be streamed.
36
- * @param {boolean} [optBehaviour.rawBody] - Indicates whether the response body should be treated as raw data.
37
- * @param {boolean} [optBehaviour.throwOnErrors] - Indicates whether errors should be thrown for non-successful status codes.
38
- * @param {boolean} [optBehaviour
39
- */
40
- constructor(statusCode, body, optBehaviour) {
41
- // response
42
- this.statusCode = statusCode;
43
- this.body = body;
44
- this.headers = {
45
- 'Access-Control-Allow-Origin': '*',
46
- 'Access-Control-Allow-Credentials': true,
47
- 'Content-Type': 'application/json',
48
- };
49
- // behaviour
50
- this.isPipingOut = false; //internal -- flag to indicate streaming out has started and avoid double stream call
51
- // options
52
- this.shouldStream = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.shouldStream); //
53
- this.rawBody = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.rawBody);
54
- this.throwOnErrors = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.throwOnErrors);
55
- this.disableTransactionID = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.disableTransactionID);
56
- }
57
- /**
58
- * Get the status code of the response.
59
- * @returns {number} The status code.
60
- */
61
- getCode() {
62
- return this.statusCode;
63
- }
64
- /**
65
- * Get the body of the object.
66
- * @returns {BodyType} The body of the object.
67
- */
68
- getBody() {
69
- return this.body;
70
- }
71
- /**
72
- * Appends a key-value pair into the body object.
73
- * @param {string} key - The key to append.
74
- * @param {any} value - The value to append.
75
- * @returns None
76
- */
77
- appendIntoBody(key, value) {
78
- this.body[key] = value;
79
- }
80
- /**
81
- * Appends a header to the existing headers object.
82
- * @param {string} key - The key of the header.
83
- * @param {any} value - The value of the header.
84
- * @returns None
85
- */
86
- appendHeader(key, value) {
87
- this.headers[key] = value;
88
- }
89
- /**
90
- * Builds the response for the given context and transaction.
91
- * @param {Context} context - The context object.
92
- * @param {Transaction<any, any, any>} transaction - The transaction object.
93
- * @param {boolean} optDoNotCallContext - Optional flag to indicate whether to call the context or not.
94
- * @returns {Promise<void>} - A promise that resolves when the response is built.
95
- */
96
- build(context, transaction, optDoNotCallContext) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- //Stream support
99
- if (this.isPipingOut)
100
- return;
101
- if (this.shouldStream)
102
- return this.pipe(context);
103
- //append default fields
104
- if (transaction.request.getRequestID() && this.body && !this.disableTransactionID)
105
- this.appendIntoBody('transactionID', transaction.request.getRequestID()); //append transaction ID
106
- //Raw response support
107
- if (this.rawBody)
108
- return this.rawContext(context, transaction);
109
- //build response
110
- const b = Object.assign({ statusCode: this.statusCode, headers: this.headers }, (this.body ? { body: JSON.stringify(this.body) } : {}));
111
- //log response and respond to context
112
- transaction.logger.debug(b);
113
- //Check for transaction response proxy
114
- if (transaction.responseProxy)
115
- yield transaction.responseProxy(this);
116
- //Batch does not succeed directly just on upper transaction (which will should be a batch)
117
- if (!optDoNotCallContext)
118
- context.succeed(b);
119
- });
120
- }
121
- /**
122
- * Private method that pipes the response to the given context.
123
- * @param {Context} context - The context object provided by AWS Lambda.
124
- * @returns None
125
- */
126
- pipe(context) {
127
- //Check if not streaming
128
- this.isPipingOut = true;
129
- //build response
130
- const b = {
131
- statusCode: this.statusCode,
132
- body: this.body,
133
- headers: this.headers,
134
- };
135
- //log response and respond to context
136
- context.succeed(b);
137
- }
138
- /**
139
- * Private method that handles the raw context of a transaction.
140
- * @param {Context} context - The context object.
141
- * @param {Transaction<null, BodyType>} transaction - The transaction object.
142
- * @returns None
143
- */
144
- rawContext(context, transaction) {
145
- //log response and respond to context
146
- transaction.logger.debug(this.body);
147
- if (this.getCode() <= 200 && this.getCode() <= 299)
148
- context.succeed(this.body);
149
- else {
150
- if (!this.throwOnErrors)
151
- context.fail(new CustomError(this.body));
152
- else
153
- throw new CustomError(this.body);
154
- }
155
- }
156
- /**
157
- * Generates a response object for a missing path parameter error.
158
- * @param {string} paramName - The name of the missing path parameter.
159
- * @returns {Response<ResponseErrorType>} - The response object with error details.
160
- */
161
- static MissingParamResponse(paramName) {
162
- console.warn(`Invalid request - Path parameter ${paramName} is missing.`);
163
- return new Response(400, {
164
- err: `Invalid request. Path parameter ${paramName} is missing.`,
165
- errCode: Globals.ErrorCode_MissingParam,
166
- });
167
- }
168
- /**
169
- * Creates a response object for a missing query parameter error.
170
- * @param {string} paramName - The name of the missing query parameter.
171
- * @returns {Response<ResponseErrorType>} - The response object with error details.
172
- */
173
- static MissingQueryResponse(paramName) {
174
- console.warn(`Invalid request - Query parameter ${paramName} is missing.`);
175
- return new Response(400, {
176
- err: `Invalid request. Query parameter ${paramName} is missing.`,
177
- errCode: Globals.ErrorCode_MissingParam,
178
- });
179
- }
180
- /**
181
- * Creates a BadRequestResponse object with the given parameters.
182
- * @param {string} [msg] - The error message.
183
- * @param {string} [errCode] - The error code.
184
- * @param {any} [optBody] - Optional additional body data.
185
- * @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
186
- */
187
- static BadRequestResponse(msg, errCode, optBody) {
188
- console.warn(`Bad request - ${msg}`);
189
- return new Response(400, Object.assign(Object.assign({ err: msg }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
190
- }
191
- /**
192
- * Creates a BadRequestResponse object with rollback option.
193
- * @param {string} msg - The error message.
194
- * @param {string} [errCode] - The error code.
195
- * @param {any} [optBody] - Optional body to include in the response.
196
- * @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
197
- */
198
- static BadRequestResponseWithRollback(msg, errCode, optBody) {
199
- console.warn(`Bad request - ${msg}`);
200
- return new Response(400, Object.assign(Object.assign({ err: msg, rollback: true }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
201
- }
202
- /**
203
- * Creates an unauthorized response with the given error message and error code.
204
- * @param {string} msg - The error message.
205
- * @param {string} [errCode] - The error code (optional).
206
- * @returns {Response<ResponseErrorType>} - The unauthorized response.
207
- */
208
- static UnauthorizedResponse(msg, errCode) {
209
- console.warn(`Denying request - ${msg}`);
210
- return new Response(401, Object.assign({ err: msg }, (errCode ? { errCode: errCode } : {})));
211
- }
212
- /**
213
- * Creates a success response object with the given body.
214
- * @param {BodyType} body - The body of the response.
215
- * @returns {Response<BodyType>} - The success response object.
216
- */
217
- static SuccessResponse(body) {
218
- return new Response(200, (body ? body : {}));
219
- }
220
- /**
221
- * Creates a redirect response with the specified URL.
222
- * @param {string} url - The URL to redirect to.
223
- * @returns {Response<null>} - The redirect response.
224
- */
225
- static RedirectResponse(url) {
226
- const resp = new Response(302, null);
227
- resp.appendHeader('Location', url);
228
- return resp;
229
- }
230
- /**
231
- * Creates a success response with no content.
232
- * @returns {Response<null>} A response object with a status code of 204 and no content.
233
- */
234
- static SuccessNoContentResponse() {
235
- return new Response(204, null);
236
- }
237
- /**
238
- * Creates a success response object with a streaming body and specified content type.
239
- * @param {any} stream - The stream object to be used as the response body.
240
- * @param {string} contentType - The content type of the response.
241
- * @returns {Response} - The success response object.
242
- */
243
- static SuccessStreamResponse(stream, contentType) {
244
- const resp = new Response(200, stream, {
245
- shouldStream: true,
246
- });
247
- resp.appendHeader('Connection', 'keep-alive');
248
- if (contentType)
249
- resp.appendHeader('Content-Type', contentType);
250
- return resp;
251
- }
252
- /**
253
- * Creates a simple HTTP response with the given body and optional status code.
254
- * @param {BodyType} body - The body of the response.
255
- * @param {number} [optionalCode] - The optional status code of the response. Defaults to 200.
256
- * @returns {Response<BodyType>} - The created response object.
257
- */
258
- static SimpleResponse(body, optionalCode) {
259
- const resp = new Response(optionalCode || 200, body);
260
- return resp;
261
- }
262
- static StepFunctionResponse(body, optionalCode) {
263
- const resp = new Response(optionalCode || 200, body, {
264
- rawBody: true,
265
- throwOnErrors: true,
266
- });
267
- return resp;
268
- }
269
- }
270
- //# sourceMappingURL=Response.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,OAAO,MAAM,eAAe,CAAA;AAEnC;;;;;;;GAOG;AACH,MAAM,WAAY,SAAQ,KAAK;IAC7B,YAAY,IAAS;QACnB,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAA;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,cAAc,CAAA;IAC1C,CAAC;CACF;AAaD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IA4C3B;;;;;;;;;OASG;IACH,YACE,UAAkB,EAClB,IAAc,EACd,YAOa;QAEb,WAAW;QACX,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG;YACb,6BAA6B,EAAE,GAAG;YAClC,kCAAkC,EAAE,IAAI;YACxC,cAAc,EAAE,kBAAkB;SACn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OAAO,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CAAC,MAAW,EAAE,WAAmB;QAClE,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE;YACrC,YAAY,EAAE,IAAI;SACnB,CAAC,CAAA;QACF,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QAC7C,IAAI,WAAW;YAAE,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAC1B,IAAc,EACd,YAAqB;QAErB,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAW,IAAc,EAAE,YAAqB;QAChF,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,EAAE;YAC7D,OAAO,EAAE,IAAI;YACb,aAAa,EAAE,IAAI;SACpB,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
@@ -1,70 +0,0 @@
1
- import type { Context, DynamoDBBatchResponse, DynamoDBRecord, DynamoDBStreamEvent } from 'aws-lambda';
2
- import Transaction, { TransactionConfig } from './Transaction.js';
3
- import Response, { ResponseErrorType } from '../API/Response.js';
4
- /**
5
- * Interface representing a DynamoDB record with marshalled data.
6
- * Extends the DynamoDBRecord interface.
7
- * @property {object} Keys - The keys of the record.
8
- * @property {object} OldImage - The old image of the record.
9
- * @property {object} NewImage - The new image of the record.
10
- */
11
- export interface DynamoDBMarshalledRecord extends DynamoDBRecord {
12
- marshalled: {
13
- Keys?: object;
14
- OldImage?: object;
15
- NewImage?: object;
16
- };
17
- }
18
- /**
19
- * Defines a type for executing a transaction on DynamoDB.
20
- * @param {Transaction<null, ResponseInnerType | ResponseErrorType, DynamoDBBatchResponse | null>} transaction - The transaction to execute.
21
- * @param {DynamoDBMarshalledRecord} recordContent - The content of the DynamoDB record.
22
- * @returns A promise that resolves to a response or a DynamoDB batch response.
23
- */
24
- export type DynamoTransactionExecution<ResponseInnerType> = (transaction: Transaction<null, ResponseInnerType | ResponseErrorType, DynamoDBBatchResponse | null>, recordContent: DynamoDBMarshalledRecord) => Promise<Response<ResponseInnerType | ResponseErrorType> | DynamoDBBatchResponse | null>;
25
- /**
26
- * Represents a DynamoDB transaction handler that processes events from a DynamoDB stream.
27
- * @template ResponseInnerType - The inner type of the response.
28
- */
29
- export default class DynamoTransaction<ResponseInnerType> {
30
- /**
31
- * A boolean flag indicating whether failures are allowed.
32
- */
33
- private readonly allowFailure;
34
- /**
35
- * Readonly property that holds the transaction configuration.
36
- */
37
- private readonly config;
38
- /**
39
- * The context object that provides information about the current execution context.
40
- * @type {Context}
41
- */
42
- private readonly context;
43
- /**
44
- * Represents an event from a DynamoDB stream.
45
- * @type {DynamoDBStreamEvent}
46
- */
47
- private readonly event;
48
- /**
49
- * Constructor for a TransactionHandler object.
50
- * @param {DynamoDBStreamEvent} event - The DynamoDB stream event that triggered the transaction.
51
- * @param {Context} context - The AWS Lambda context object.
52
- * @param {TransactionConfig} [config] - Optional configuration for the transaction.
53
- * @param {boolean} [allowFailure] - Flag to indicate whether to allow transaction failure.
54
- * @returns None
55
- */
56
- constructor(event: DynamoDBStreamEvent, context: Context, config?: TransactionConfig, allowFailure?: boolean);
57
- /**
58
- * Processes the event execution and returns a response based on the outcome.
59
- * @param {DynamoTransactionExecution<ResponseInnerType>} execution - The execution object to process.
60
- * @returns {Promise<Response<ResponseErrorType | null> | null | DynamoDBBatchResponse>} A promise that resolves to a response object or null.
61
- * @throws {Error} If the response code is not within the success range and failure is not allowed.
62
- */
63
- processEvent(execution: DynamoTransactionExecution<ResponseInnerType>): Promise<Response<ResponseErrorType | null> | null | DynamoDBBatchResponse>;
64
- /**
65
- * Processes a raw event by executing a transaction on each record in the event.
66
- * @param {DynamoTransactionExecution<ResponseInnerType>} execution - The transaction execution function.
67
- * @returns {Promise<Response<ResponseErrorType | any> | null | DynamoDBBatchResponse>} A promise that resolves to a response object, null, or a DynamoDB batch response.
68
- */
69
- private processRawEvent;
70
- }
@@ -1,104 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import Transaction from './Transaction.js';
11
- import Response from '../API/Response.js';
12
- import Globals from '../Globals.js';
13
- import Utils from '../Util/Utils.js';
14
- /**
15
- * Represents a DynamoDB transaction handler that processes events from a DynamoDB stream.
16
- * @template ResponseInnerType - The inner type of the response.
17
- */
18
- export default class DynamoTransaction {
19
- /**
20
- * Constructor for a TransactionHandler object.
21
- * @param {DynamoDBStreamEvent} event - The DynamoDB stream event that triggered the transaction.
22
- * @param {Context} context - The AWS Lambda context object.
23
- * @param {TransactionConfig} [config] - Optional configuration for the transaction.
24
- * @param {boolean} [allowFailure] - Flag to indicate whether to allow transaction failure.
25
- * @returns None
26
- */
27
- constructor(event, context, config, allowFailure) {
28
- this.event = event;
29
- this.context = context;
30
- this.config = config || {};
31
- this.allowFailure = !!allowFailure;
32
- }
33
- /**
34
- * Processes the event execution and returns a response based on the outcome.
35
- * @param {DynamoTransactionExecution<ResponseInnerType>} execution - The execution object to process.
36
- * @returns {Promise<Response<ResponseErrorType | null> | null | DynamoDBBatchResponse>} A promise that resolves to a response object or null.
37
- * @throws {Error} If the response code is not within the success range and failure is not allowed.
38
- */
39
- processEvent(execution) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const resp = yield this.processRawEvent(execution);
42
- if (!this.allowFailure &&
43
- resp &&
44
- resp instanceof Response &&
45
- !(resp.getCode() >= 200 && resp.getCode() < 300))
46
- throw new Error(JSON.stringify(resp.getBody() || {}));
47
- else if (resp)
48
- return resp;
49
- return null;
50
- });
51
- }
52
- /**
53
- * Processes a raw event by executing a transaction on each record in the event.
54
- * @param {DynamoTransactionExecution<ResponseInnerType>} execution - The transaction execution function.
55
- * @returns {Promise<Response<ResponseErrorType | any> | null | DynamoDBBatchResponse>} A promise that resolves to a response object, null, or a DynamoDB batch response.
56
- */
57
- processRawEvent(execution) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- var _a;
60
- // safe check for empty events?
61
- if (this.event.Records && this.event.Records.length > 0) {
62
- // Regular cleanup of tmp disk to avoid tmp overflow on reused lambdas
63
- if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.skipCleanTmp))
64
- yield Utils.cleanTemporaryFolder();
65
- // init transaction for all records
66
- return yield new Transaction(this.event, this.context, Object.assign(Object.assign({}, this.config), { syncReturn: true })).execute((transaction) => __awaiter(this, void 0, void 0, function* () {
67
- var _a, _b, _c, _d, _e, _f;
68
- // for each available event
69
- const failureIDs = [];
70
- for (const eventRecordIdx in this.event.Records) {
71
- const eventRecord = this.event.Records[eventRecordIdx];
72
- const record = Object.assign(Object.assign({}, eventRecord), { marshalled: Object.assign(Object.assign(Object.assign({}, (((_a = eventRecord.dynamodb) === null || _a === void 0 ? void 0 : _a.Keys)
73
- ? { Keys: Utils.ddbUnmarshall((_b = eventRecord.dynamodb) === null || _b === void 0 ? void 0 : _b.Keys) }
74
- : {})), (((_c = eventRecord.dynamodb) === null || _c === void 0 ? void 0 : _c.OldImage)
75
- ? { OldImage: Utils.ddbUnmarshall((_d = eventRecord.dynamodb) === null || _d === void 0 ? void 0 : _d.OldImage) }
76
- : {})), (((_e = eventRecord.dynamodb) === null || _e === void 0 ? void 0 : _e.NewImage)
77
- ? { NewImage: Utils.ddbUnmarshall((_f = eventRecord.dynamodb) === null || _f === void 0 ? void 0 : _f.NewImage) }
78
- : {})) });
79
- // Call execution with marshalled item
80
- const resp = yield execution(transaction, record);
81
- // check for failure
82
- if (!resp ||
83
- (resp instanceof Response && !((resp === null || resp === void 0 ? void 0 : resp.getCode()) >= 200 && (resp === null || resp === void 0 ? void 0 : resp.getCode()) < 300))) {
84
- // response with failures or fail hard at first
85
- if (this.allowFailure)
86
- failureIDs.push(eventRecord.eventID);
87
- else
88
- return resp;
89
- }
90
- }
91
- // not errored and loop ended - succeeded (might have failures)
92
- if (this.allowFailure)
93
- return {
94
- batchItemFailures: failureIDs.map(id => ({ itemIdentifier: id })),
95
- };
96
- return Response.SuccessResponse(null);
97
- }));
98
- }
99
- else
100
- return Response.BadRequestResponse(Globals.ErrorResponseNoRecords, Globals.ErrorCode_NoRecords);
101
- });
102
- }
103
- }
104
- //# sourceMappingURL=DynamoTransaction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DynamoTransaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/DynamoTransaction.ts"],"names":[],"mappings":";;;;;;;;;AAOA,OAAO,WAAkC,MAAM,kBAAkB,CAAA;AACjE,OAAO,QAA+B,MAAM,oBAAoB,CAAA;AAChE,OAAO,OAAO,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAgCpC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IAuBpC;;;;;;;OAOG;IACH,YACE,KAA0B,EAC1B,OAAgB,EAChB,MAA0B,EAC1B,YAAsB;QAEtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,EAAE,CAA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AAI,CAAC,YAAY;wBACnB,OAAO;4BACL,iBAAiB,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,CAAC;yBAClE,CAAA;oBACH,OAAO,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;gBACvC,CAAC,CAAA,CAAC,CAAA;YACJ,CAAC;;gBACC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,OAAO,CAAC,sBAAsB,EAC9B,OAAO,CAAC,mBAAmB,CAC5B,CAAA;QACL,CAAC;KAAA;CACF"}
@@ -1,58 +0,0 @@
1
- import type { Context, SQSBatchResponse, SQSEvent } from 'aws-lambda';
2
- import Transaction, { TransactionConfig } from './Transaction.js';
3
- import Response, { ResponseErrorType } from '../API/Response.js';
4
- /**
5
- * Type definition for an event processor execution function.
6
- * @param {Transaction<null, ResponseInnerType | ResponseErrorType, SQSBatchResponse>} transaction - The transaction object.
7
- * @param {string | object} recordContent - The content of the record being processed.
8
- * @returns {Promise<Response<ResponseInnerType | ResponseErrorType> | SQSBatchResponse>} - A promise that resolves to the response or batch response.
9
- */
10
- export type EventProcessorExecution<ResponseInnerType> = (transaction: Transaction<null, ResponseInnerType | ResponseErrorType, SQSBatchResponse | null>, recordContent: string | object) => Promise<Response<ResponseInnerType | ResponseErrorType> | SQSBatchResponse | null>;
11
- /**
12
- * EventProcessor class that processes events from an SQS queue.
13
- * @template ResponseInnerType - The type of the inner response object.
14
- */
15
- export default class EventProcessor<ResponseInnerType> {
16
- /**
17
- * A boolean flag indicating whether failures are allowed or not.
18
- * @readonly
19
- */
20
- private readonly allowFailure;
21
- /**
22
- * The configuration object for the API transaction.
23
- */
24
- private readonly config;
25
- /**
26
- * The private readonly context property of the class.
27
- * @type {Context}
28
- */
29
- private readonly context;
30
- /**
31
- * The SQS event object that triggered the Lambda function.
32
- */
33
- private readonly event;
34
- /**
35
- * Constructs a new instance of the class.
36
- * @param {SQSEvent} event - The event object representing the incoming SQS message.
37
- * @param {Context} context - The context object representing the AWS Lambda execution context.
38
- * @param {TransactionConfig} [config] - Optional configuration object for the transaction.
39
- * @param {boolean} [allowFailure] - Optional flag indicating whether to allow failure for the transaction.
40
- * @returns None
41
- */
42
- constructor(event: SQSEvent, context: Context, config?: TransactionConfig, allowFailure?: boolean);
43
- /**
44
- * Processes an event using the provided execution object and returns a response.
45
- * @param {EventProcessorExecution<ResponseInnerType>} execution - The execution object containing the event to process.
46
- * @param {boolean} [doNotDecodeMessage] - Optional flag indicating whether to decode the message.
47
- * @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to the response object, or null if no response is available.
48
- * @throws {Error} - Throws an error if the response code is not within the range of 200 to 299 and failure is not allowed.
49
- */
50
- processEvent(execution: EventProcessorExecution<ResponseInnerType>, doNotDecodeMessage?: boolean): Promise<Response<ResponseErrorType | null> | null | SQSBatchResponse>;
51
- /**
52
- * Processes a raw event by executing the provided execution function and handling any errors or failures.
53
- * @param {EventProcessorExecution<ResponseInnerType>} execution - The execution function to process the event.
54
- * @param {boolean} doNotDecodeMessage - Flag indicating whether to decode the message or not.
55
- * @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to a response object, null, or a SQS batch response.
56
- */
57
- private processRawEvent;
58
- }
@@ -1,101 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import Transaction from './Transaction.js';
11
- import Response from '../API/Response.js';
12
- import Globals from '../Globals.js';
13
- import Utils from '../Util/Utils.js';
14
- /**
15
- * EventProcessor class that processes events from an SQS queue.
16
- * @template ResponseInnerType - The type of the inner response object.
17
- */
18
- export default class EventProcessor {
19
- /**
20
- * Constructs a new instance of the class.
21
- * @param {SQSEvent} event - The event object representing the incoming SQS message.
22
- * @param {Context} context - The context object representing the AWS Lambda execution context.
23
- * @param {TransactionConfig} [config] - Optional configuration object for the transaction.
24
- * @param {boolean} [allowFailure] - Optional flag indicating whether to allow failure for the transaction.
25
- * @returns None
26
- */
27
- constructor(event, context, config, allowFailure) {
28
- this.event = event;
29
- this.context = context;
30
- this.config = config || {};
31
- this.allowFailure = !!allowFailure;
32
- }
33
- /**
34
- * Processes an event using the provided execution object and returns a response.
35
- * @param {EventProcessorExecution<ResponseInnerType>} execution - The execution object containing the event to process.
36
- * @param {boolean} [doNotDecodeMessage] - Optional flag indicating whether to decode the message.
37
- * @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to the response object, or null if no response is available.
38
- * @throws {Error} - Throws an error if the response code is not within the range of 200 to 299 and failure is not allowed.
39
- */
40
- processEvent(execution, doNotDecodeMessage) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const resp = yield this.processRawEvent(execution, !!doNotDecodeMessage);
43
- if (!this.allowFailure &&
44
- resp &&
45
- resp instanceof Response &&
46
- !(resp.getCode() >= 200 && resp.getCode() < 300))
47
- throw new Error(JSON.stringify(resp.getBody() || {}));
48
- else if (resp)
49
- return resp;
50
- return null;
51
- });
52
- }
53
- /**
54
- * Processes a raw event by executing the provided execution function and handling any errors or failures.
55
- * @param {EventProcessorExecution<ResponseInnerType>} execution - The execution function to process the event.
56
- * @param {boolean} doNotDecodeMessage - Flag indicating whether to decode the message or not.
57
- * @returns {Promise<Response<ResponseErrorType> | null | SQSBatchResponse>} - A promise that resolves to a response object, null, or a SQS batch response.
58
- */
59
- processRawEvent(execution, doNotDecodeMessage) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- var _a;
62
- // safe check for empty events?
63
- if (this.event.Records && this.event.Records.length > 0) {
64
- // Regular cleanup of tmp disk to avoid tmp overflow on reused lambdas
65
- if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.skipCleanTmp))
66
- yield Utils.cleanTemporaryFolder();
67
- // init transaction for all records
68
- return yield new Transaction(this.event, this.context, Object.assign(Object.assign({}, this.config), { syncReturn: true })).execute((transaction) => __awaiter(this, void 0, void 0, function* () {
69
- // Map records with decoded message when required
70
- const decodedRecords = this.event.Records.map(eventRecord => doNotDecodeMessage ? eventRecord.body : JSON.parse(eventRecord.body));
71
- // for each available event
72
- const failureIDs = [];
73
- for (const eventRecordIdx in decodedRecords) {
74
- const eventRecord = decodedRecords[eventRecordIdx];
75
- const message = this.event.Records[eventRecordIdx];
76
- // Call execution
77
- const resp = yield execution(transaction, eventRecord);
78
- // check for failure
79
- if (!resp ||
80
- (resp instanceof Response && !((resp === null || resp === void 0 ? void 0 : resp.getCode()) >= 200 && (resp === null || resp === void 0 ? void 0 : resp.getCode()) < 300))) {
81
- // response with failures or fail hard at first
82
- if (this.allowFailure)
83
- failureIDs.push(message.messageId);
84
- else
85
- return resp;
86
- }
87
- }
88
- // not errored and loop ended - succeeded (might have failures)
89
- if (this.allowFailure)
90
- return {
91
- batchItemFailures: failureIDs.map(id => ({ itemIdentifier: id })),
92
- };
93
- return Response.SuccessResponse(null);
94
- }));
95
- }
96
- else
97
- return Response.BadRequestResponse(Globals.ErrorResponseNoRecords, Globals.ErrorCode_NoRecords); // no event to be processed?
98
- });
99
- }
100
- }
101
- //# sourceMappingURL=EventProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EventProcessor.js","sourceRoot":"","sources":["../../../src/BaseEvent/EventProcessor.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,WAAkC,MAAM,kBAAkB,CAAA;AACjE,OAAO,QAA+B,MAAM,oBAAoB,CAAA;AAChE,OAAO,OAAO,MAAM,eAAe,CAAA;AACnC,OAA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