@ikonintegration/ikapi 4.0.0-alpha8 → 5.0.0-alpha1

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 (234) 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/dist/index.d.ts +16 -0
  6. package/dist/index.js +27 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/package-lock.json +11886 -0
  9. package/dist/package.json +81 -0
  10. package/dist/src/API/Request.d.ts +125 -0
  11. package/dist/src/API/Request.js +185 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +188 -0
  14. package/dist/src/API/Response.js +270 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/BaseEvent/DynamoTransaction.d.ts +20 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.js +81 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +50 -0
  23. package/dist/src/BaseEvent/Process.js +64 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  26. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  27. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  28. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  29. package/dist/src/BaseEvent/Transaction.js +224 -0
  30. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  31. package/dist/src/Cache/Redis.d.ts +29 -0
  32. package/dist/src/Cache/Redis.js +80 -0
  33. package/dist/src/Cache/Redis.js.map +1 -0
  34. package/dist/src/Cache/types.d.ts +31 -0
  35. package/dist/src/Cache/types.js +2 -0
  36. package/dist/src/Cache/types.js.map +1 -0
  37. package/dist/src/Config/Configuration.d.ts +123 -0
  38. package/dist/src/Config/Configuration.js +109 -0
  39. package/dist/src/Config/Configuration.js.map +1 -0
  40. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  41. package/dist/src/Config/EnvironmentVar.js +138 -0
  42. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  43. package/dist/src/Crypto/Crypto.d.ts +45 -0
  44. package/dist/src/Crypto/Crypto.js +72 -0
  45. package/dist/src/Crypto/Crypto.js.map +1 -0
  46. package/dist/src/Database/Database.d.ts +21 -0
  47. package/dist/src/Database/Database.js +15 -0
  48. package/dist/src/Database/Database.js.map +1 -0
  49. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  50. package/dist/src/Database/DatabaseManager.js +60 -0
  51. package/dist/src/Database/DatabaseManager.js.map +1 -0
  52. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  53. package/dist/src/Database/DatabaseTransaction.js +126 -0
  54. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  55. package/dist/src/Database/index.d.ts +10 -0
  56. package/dist/src/Database/index.js +15 -0
  57. package/dist/src/Database/index.js.map +1 -0
  58. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  61. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  64. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  67. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  73. package/dist/src/Database/types.d.ts +76 -0
  74. package/dist/src/Database/types.js +2 -0
  75. package/dist/src/Database/types.js.map +1 -0
  76. package/dist/src/Globals.d.ts +93 -0
  77. package/dist/src/Globals.js +99 -0
  78. package/dist/src/Globals.js.map +1 -0
  79. package/dist/src/Logger/Logger.d.ts +161 -0
  80. package/dist/src/Logger/Logger.js +297 -0
  81. package/dist/src/Logger/Logger.js.map +1 -0
  82. package/dist/src/Mailer/Mailer.d.ts +78 -0
  83. package/dist/src/Mailer/Mailer.js +182 -0
  84. package/dist/src/Mailer/Mailer.js.map +1 -0
  85. package/dist/src/Publisher/Publisher.d.ts +39 -0
  86. package/dist/src/Publisher/Publisher.js +77 -0
  87. package/dist/src/Publisher/Publisher.js.map +1 -0
  88. package/dist/src/Server/RouteResolver.d.ts +33 -0
  89. package/dist/src/Server/RouteResolver.js +100 -0
  90. package/dist/src/Server/RouteResolver.js.map +1 -0
  91. package/dist/src/Server/Router.d.ts +157 -0
  92. package/dist/src/Server/Router.js +32 -0
  93. package/dist/src/Server/Router.js.map +1 -0
  94. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  95. package/dist/src/Server/lib/ContainerServer.js +66 -0
  96. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  97. package/dist/src/Server/lib/Server.d.ts +45 -0
  98. package/dist/src/Server/lib/Server.js +93 -0
  99. package/dist/src/Server/lib/Server.js.map +1 -0
  100. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  101. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  103. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  106. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  107. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  109. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  110. package/dist/src/Server/lib/container/Proxy.js +143 -0
  111. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  112. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  113. package/dist/src/Server/lib/container/Utils.js +37 -0
  114. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  115. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  116. package/dist/src/Util/AsyncSingleton.js +83 -0
  117. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  118. package/dist/src/Util/Utils.d.ts +61 -0
  119. package/dist/src/Util/Utils.js +147 -0
  120. package/dist/src/Util/Utils.js.map +1 -0
  121. package/dist/src/Validation/Validator.d.ts +17 -0
  122. package/dist/src/Validation/Validator.js +39 -0
  123. package/dist/src/Validation/Validator.js.map +1 -0
  124. package/index.ts +41 -0
  125. package/jest.config.ts +37 -0
  126. package/jest.smoke.config.ts +34 -0
  127. package/package.json +66 -22
  128. package/src/API/Request.ts +214 -0
  129. package/src/API/Response.ts +370 -0
  130. package/src/BaseEvent/DynamoTransaction.ts +125 -0
  131. package/src/BaseEvent/EventProcessor.ts +140 -0
  132. package/src/BaseEvent/Process.ts +78 -0
  133. package/src/BaseEvent/StepTransaction.ts +35 -0
  134. package/src/BaseEvent/Transaction.ts +323 -0
  135. package/src/Cache/Redis.ts +89 -0
  136. package/src/Cache/types.ts +33 -0
  137. package/src/Config/Configuration.ts +199 -0
  138. package/src/Config/EnvironmentVar.ts +147 -0
  139. package/src/Crypto/Crypto.ts +89 -0
  140. package/src/Database/Database.ts +22 -0
  141. package/src/Database/DatabaseManager.ts +67 -0
  142. package/src/Database/DatabaseTransaction.ts +170 -0
  143. package/src/Database/index.ts +27 -0
  144. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  145. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  146. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  147. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  148. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  149. package/src/Database/types.ts +85 -0
  150. package/src/Globals.ts +103 -0
  151. package/src/Logger/Logger.ts +360 -0
  152. package/src/Mailer/Mailer.ts +217 -0
  153. package/src/Publisher/Publisher.ts +96 -0
  154. package/src/Server/RouteResolver.ts +124 -0
  155. package/src/Server/Router.ts +200 -0
  156. package/src/Server/lib/ContainerServer.ts +65 -0
  157. package/src/Server/lib/Server.ts +109 -0
  158. package/src/Server/lib/container/GenericHandler.ts +76 -0
  159. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  160. package/src/Server/lib/container/HealthHandler.ts +11 -0
  161. package/src/Server/lib/container/Proxy.ts +172 -0
  162. package/src/Server/lib/container/Utils.ts +33 -0
  163. package/src/Util/AsyncSingleton.ts +86 -0
  164. package/src/Util/Utils.ts +131 -0
  165. package/src/Validation/Validator.ts +45 -0
  166. package/tests/API/Request.test.ts +273 -0
  167. package/tests/API/Response.test.ts +367 -0
  168. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  169. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  170. package/tests/BaseEvent/Process.test.ts +47 -0
  171. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  172. package/tests/BaseEvent/Transaction.test.ts +402 -0
  173. package/tests/Cache/Redis-client.test.ts +90 -0
  174. package/tests/Cache/Redis-cluster.test.ts +100 -0
  175. package/tests/Config/Config.test.ts +205 -0
  176. package/tests/Config/EnvironmentVar.test.ts +251 -0
  177. package/tests/Crypto/Crypto.test.ts +88 -0
  178. package/tests/Database/DatabaseManager.test.ts +79 -0
  179. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  180. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  181. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  182. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  183. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  184. package/tests/Logger/Logger.test.ts +215 -0
  185. package/tests/Mailer/Mailer.test.ts +59 -0
  186. package/tests/Publisher/Publisher.test.ts +60 -0
  187. package/tests/Server/RouteResolver.test.ts +116 -0
  188. package/tests/Server/Router.test.ts +39 -0
  189. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  190. package/tests/Server/lib/Server.test.ts +12 -0
  191. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  192. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  193. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  194. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  195. package/tests/Server/lib/container/Utils.test.ts +47 -0
  196. package/tests/Test.utils.ts +78 -0
  197. package/tests/Utils/Utils.test.ts +230 -0
  198. package/tests/Validation/Validator.test.ts +82 -0
  199. package/tsconfig.json +26 -0
  200. package/tsconfig.smoke.json +26 -0
  201. package/index.js +0 -88
  202. package/src/API/IKRequest.js +0 -52
  203. package/src/API/IKResponse.js +0 -119
  204. package/src/API/IKUtils.js +0 -51
  205. package/src/BaseEvent/IKProcess.js +0 -77
  206. package/src/BaseEvent/IKTransaction.js +0 -139
  207. package/src/Cache/Prototype/IKCache.js +0 -17
  208. package/src/Cache/Redis/IKRedis.js +0 -148
  209. package/src/Database/DDB/IKDB.js +0 -56
  210. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  211. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  212. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  213. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  214. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  215. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  216. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  217. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  218. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  219. package/src/Database/DDB/IKDBQueryUpdate.js +0 -219
  220. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  221. package/src/Database/PSQL/IKDB.js +0 -41
  222. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  223. package/src/Database/Prototype/IKDB.js +0 -21
  224. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  225. package/src/IKDynamoStream.js +0 -42
  226. package/src/IKEventProcessor.js +0 -42
  227. package/src/IKGlobals.js +0 -24
  228. package/src/IKRouter.js +0 -47
  229. package/src/IKStepTransaction.js +0 -14
  230. package/src/Logger/IKLogger.js +0 -136
  231. package/src/Mailer/IKMailer.js +0 -68
  232. package/src/Publisher/IKPublisher.js +0 -44
  233. package/src/Tracker/IKExecutionTracker.js +0 -79
  234. package/src/Validation/IKValidation.js +0 -77
@@ -0,0 +1,182 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as SES from '@aws-sdk/client-ses';
11
+ import { defaultProvider } from '@aws-sdk/credential-provider-node';
12
+ import Email from 'email-templates';
13
+ import nodemailer from 'nodemailer';
14
+ export default class Mailer {
15
+ /**
16
+ * Constructs a new instance of the EmailSender class.
17
+ * @param {string} defaultFrom - The default "from" email address.
18
+ * @param {string} region - The AWS region to use for sending emails.
19
+ * @returns None
20
+ */
21
+ constructor(defaultFrom, region) {
22
+ /**
23
+ * The default file template for the application.
24
+ * @type {string}
25
+ */
26
+ this.templateDefaultFile = 'html';
27
+ this.from = defaultFrom;
28
+ this.transporter = nodemailer.createTransport({
29
+ SES: {
30
+ ses: new SES.SESClient({
31
+ credentials: defaultProvider(),
32
+ apiVersion: '2010-12-01',
33
+ region,
34
+ }),
35
+ aws: SES,
36
+ },
37
+ });
38
+ }
39
+ /**
40
+ * Sends a raw email with the specified parameters.
41
+ * @param {string | Array<string>} to - The recipient(s) of the email.
42
+ * @param {string} htmlMessage - The HTML content of the email.
43
+ * @param {string} subject - The subject of the email.
44
+ * @param {string | Array<string>} [optionalCC] - The optional CC recipient(s) of the email.
45
+ * @param {string} [optionalFrom] - The optional sender of the email. If not provided, the default sender will be used.
46
+ * @param {string} [optionalReplyTo] - The optional reply-to address for the email.
47
+ * @param {any[]} [optionalAttachments] - The optional attachments to include
48
+ */
49
+ sendRawEmail(to, htmlMessage, subject, optionalCC, optionalFrom, optionalReplyTo,
50
+ // TODO: improve attachment type -> Attachment
51
+ optionalAttachments, optionalTransport) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ //Generate emails
54
+ const email = new Email({
55
+ message: Object.assign(Object.assign(Object.assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
56
+ transport: optionalTransport || this.transporter,
57
+ send: true,
58
+ });
59
+ //
60
+ let resp = null;
61
+ try {
62
+ resp = yield email.send();
63
+ console.debug('Mailer resp:', resp);
64
+ }
65
+ catch (e) {
66
+ console.error('Mailer error:', e);
67
+ throw e;
68
+ }
69
+ return resp;
70
+ });
71
+ }
72
+ /**
73
+ * Sends a templated email to the specified recipients.
74
+ * @param {string | Array<string>} to - The email address(es) of the recipient(s).
75
+ * @param {string | Array<string>} templates - The template(s) to use for the email.
76
+ * @param {object} data - The data to be used in the email template.
77
+ * @param {string | Array<string>} [optionalCC] - The email address(es) to CC.
78
+ * @param {string} [optionalFrom] - The email address to send the email from.
79
+ * @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
80
+ * @param {any[]} [optionalAttachments] - An array
81
+ */
82
+ sendTemplatedEmail(to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
83
+ // TODO: improve attachment type -> Attachment
84
+ optionalAttachments, optionalTransport) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ //Generate emails
87
+ const email = new Email({
88
+ message: Object.assign(Object.assign(Object.assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
89
+ transport: optionalTransport || this.transporter,
90
+ send: true,
91
+ });
92
+ //
93
+ let resp = null;
94
+ try {
95
+ const chosenTemplate = yield this.chooseTemplate(templates, data);
96
+ resp = yield email.send({ template: chosenTemplate, locals: data });
97
+ console.debug('Mailer resp:', resp);
98
+ }
99
+ catch (e) {
100
+ console.error('Mailer error:', e);
101
+ throw e;
102
+ }
103
+ return resp;
104
+ });
105
+ }
106
+ /**
107
+ * Creates a new SMTP transporter for sending emails using NodeMailer.
108
+ * @param {string} host - The SMTP server host.
109
+ * @param {number} portNumber - The port number to connect to the SMTP server.
110
+ * @param {string} user - The username for authentication with the SMTP server.
111
+ * @param {string} password - The password for authentication with the SMTP server.
112
+ * @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
113
+ */
114
+ newSMTPTransporter(host, portNumber, user, password) {
115
+ const smtpTransporter = nodemailer.createTransport({
116
+ host: host,
117
+ port: portNumber,
118
+ connectionTimeout: 2000,
119
+ auth: {
120
+ user: user,
121
+ pass: password,
122
+ },
123
+ });
124
+ return smtpTransporter;
125
+ }
126
+ /**
127
+ * Chooses a template from the given array of templates or a single template string based on whether it can be rendered with the provided data.
128
+ * @param {string | Array<string>} templates - The template(s) to choose from.
129
+ * @param {object} data - The data to be used for rendering the template.
130
+ * @returns {Promise<string>} - The chosen template.
131
+ * @throws {Error} - If no template can be rendered with the provided data.
132
+ */
133
+ chooseTemplate(templates, data) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ if (Array.isArray(templates)) {
136
+ //For each template check if can render it
137
+ for (const template of templates) {
138
+ if (yield this.canRenderTemplate(template, data))
139
+ return template;
140
+ }
141
+ }
142
+ else if (templates) {
143
+ if (yield this.canRenderTemplate(templates, data))
144
+ return templates;
145
+ }
146
+ throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above! ` +
147
+ JSON.stringify(data, null, 2));
148
+ });
149
+ }
150
+ /**
151
+ * Checks if a given email template can be rendered with the provided data.
152
+ * @param {string} template - The name of the email template.
153
+ * @param {object} data - The data to be used for rendering the template.
154
+ * @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
155
+ */
156
+ canRenderTemplate(template, data) {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ const validRenderResp = yield Mailer.renderTemplate(`${template}/${this.templateDefaultFile}`, data);
159
+ return validRenderResp != null;
160
+ });
161
+ }
162
+ /**
163
+ * Renders the given template with the provided data using the Email class.
164
+ * @param {string} template - The name or path of the template to render.
165
+ * @param {object} data - The data object to pass to the template.
166
+ * @returns {Promise<boolean>} - A promise that resolves to true if the template was rendered successfully, false otherwise.
167
+ */
168
+ static renderTemplate(template, data) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ let validRenderResp = null;
171
+ try {
172
+ const email = new Email();
173
+ validRenderResp = yield email.render(`${template}`, data);
174
+ }
175
+ catch (e) {
176
+ console.log(`Error while checking renderability of email template ${template}`, e);
177
+ }
178
+ return validRenderResp;
179
+ });
180
+ }
181
+ }
182
+ //# sourceMapp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M,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC;oBAAE,OAAO,SAAS,CAAA;YACrE,CAAC;YACD,MAAM,IAAI,KAAK,CACb,wCAAwC,SAAS,iDAAiD;gBAChG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACW,iBAAiB,CAAC,QAAgB,EAAE,IAAY;;YAC5D,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,cAAc,CACjD,GAAG,QAAQ,IAAI,IAAI,CAAC,mBAAmB,EAAE,EACzC,IAAI,CACL,CAAA;YACD,OAAO,eAAe,IAAI,IAAI,CAAA;QAChC,CAAC;KAAA;IAED;;;;;OAKG;IACI,MAAM,CAAO,cAAc,CAAC,QAAgB,EAAE,IAAY;;YAC/D,IAAI,eAAe,GAAkB,IAAI,CAAA;YACzC,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;gBACzB,eAAe,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;YAC3D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,wDAAwD,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;YACpF,CAAC;YACD,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF"}
@@ -0,0 +1,39 @@
1
+ import { PublishCommandOutput } from '@aws-sdk/client-sns';
2
+ /**
3
+ * Represents the configuration options for a publisher.
4
+ * @typedef {Object} PublisherConfig
5
+ * @property {string} [region] - The region where the publisher is located.
6
+ */
7
+ export type PublisherConfig = {
8
+ region?: string;
9
+ };
10
+ /**
11
+ * Represents a publisher that can publish messages to an SNS topic.
12
+ */
13
+ export default class Publisher {
14
+ /**
15
+ * The region of the object or entity.
16
+ * @private
17
+ * @type {string}
18
+ */
19
+ private region;
20
+ /**
21
+ * Constructs a new instance of the Publisher class.
22
+ * @param {PublisherConfig} [config] - The configuration object for the Publisher.
23
+ * @returns None
24
+ */
25
+ constructor(config?: PublisherConfig);
26
+ /**
27
+ * Publishes a message on a specified topic.
28
+ * @param {any} messageObject - The message object to be published.
29
+ * @param {string} topic - The ARN of the topic to publish the message to.
30
+ * @param {object} [additionalProps] - Additional properties to include in the publish command.
31
+ * @returns {Promise<PublishCommandOutput>} - A promise that resolves to the response from the publish command.
32
+ */
33
+ publishOnTopic(messageObject: any, topic: string, additionalProps?: object): Promise<PublishCommandOutput | undefined>;
34
+ /**
35
+ * Establishes a connection to the SNS client if it does not already exist or if the region has changed.
36
+ * @returns None
37
+ */
38
+ private connect;
39
+ }
@@ -0,0 +1,77 @@
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 { SNSClient, PublishCommand, } from '@aws-sdk/client-sns';
11
+ import sha1 from 'sha1';
12
+ //reusable client
13
+ /**
14
+ * A variable that holds the connection to the SNS client for publishing messages.
15
+ * @type {SNSClient | null}
16
+ */
17
+ // eslint-disable-next-line no-var
18
+ let PUBLISHER_CONN = null;
19
+ /**
20
+ * The connection hash for the publisher. It is initially set to null.
21
+ * @type {string | null}
22
+ */
23
+ // eslint-disable-next-line no-var
24
+ let PUBLISHER_CONN_HASH = null;
25
+ /**
26
+ * Represents a publisher that can publish messages to an SNS topic.
27
+ */
28
+ export default class Publisher {
29
+ /**
30
+ * Constructs a new instance of the Publisher class.
31
+ * @param {PublisherConfig} [config] - The configuration object for the Publisher.
32
+ * @returns None
33
+ */
34
+ constructor(config) {
35
+ if (config && config.region) {
36
+ this.region = config.region;
37
+ // console.debug(`Using region: ${this.region}`);
38
+ }
39
+ }
40
+ /**
41
+ * Publishes a message on a specified topic.
42
+ * @param {any} messageObject - The message object to be published.
43
+ * @param {string} topic - The ARN of the topic to publish the message to.
44
+ * @param {object} [additionalProps] - Additional properties to include in the publish command.
45
+ * @returns {Promise<PublishCommandOutput>} - A promise that resolves to the response from the publish command.
46
+ */
47
+ publishOnTopic(messageObject, topic, additionalProps) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ let resp = undefined;
50
+ try {
51
+ this.connect();
52
+ //Send to SNS
53
+ const params = Object.assign({ Message: JSON.stringify(messageObject), TopicArn: topic }, (additionalProps ? additionalProps : {}));
54
+ resp = yield PUBLISHER_CONN.send(new PublishCommand(params));
55
+ }
56
+ catch (e) {
57
+ console.error(`Error while publishing into topic ${topic} with error: ${e}`);
58
+ }
59
+ console.debug('Publisher resp', resp);
60
+ return resp;
61
+ });
62
+ }
63
+ /**
64
+ * Establishes a connection to the SNS client if it does not already exist or if the region has changed.
65
+ * @returns None
66
+ */
67
+ connect() {
68
+ if ((!PUBLISHER_CONN && !PUBLISHER_CONN_HASH) || PUBLISHER_CONN_HASH != sha1(this.region)) {
69
+ PUBLISHER_CONN = new SNSClient({
70
+ apiVersion: '2010-03-31',
71
+ region: this.region,
72
+ });
73
+ PUBLISHER_CONN_HASH = sha1(this.region).toString();
74
+ }
75
+ }
76
+ }
77
+ //# sourceMappingURL=Publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Publisher.js","sourceRoot":"","sources":["../../../src/Publisher/Publisher.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,SAAS,EACT,cAAc,GAGf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,iBAAiB;AACjB;;;GAGG;AACH,kCAA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;gBACxB,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAA;YACF,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;QACpD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,33 @@
1
+ import { AnyRoute, RouterConfig } from './Router.js';
2
+ import { HttpMethod } from '../API/Request.js';
3
+ /**
4
+ * A class that resolves routes based on the provided configuration.
5
+ * @class RouteResolver
6
+ */
7
+ export default class RouteResolver {
8
+ /**
9
+ * An object that maps HTTP methods to their corresponding routes.
10
+ * @property {object} routes - The routes object.
11
+ * @property {Routes} routes.method - The routes for the specified HTTP method.
12
+ */
13
+ private routes;
14
+ /**
15
+ * Constructs a new instance of the Router class with the given configuration.
16
+ * @param {RouterConfig} config - The configuration object for the router.
17
+ * @returns None
18
+ */
19
+ constructor(config: RouterConfig);
20
+ /**
21
+ * Resolves a route based on the given HTTP method and path.
22
+ * @param {string} method - The HTTP method of the request.
23
+ * @param {string} path - The path of the request.
24
+ * @returns {Route | undefined} - The resolved route or undefined if no route is found.
25
+ */
26
+ resolveRoute(method: HttpMethod, path: string): AnyRoute | undefined;
27
+ /**
28
+ * Builds the routes for the router based on the given configuration.
29
+ * @param {RouterConfig} config - The router configuration object.
30
+ * @returns None
31
+ */
32
+ private buildRoutes;
33
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Represents a collection of routes that can be added and resolved.
3
+ */
4
+ class Routes {
5
+ /**
6
+ * Initializes a new instance of the class.
7
+ * @constructor
8
+ */
9
+ constructor() {
10
+ this.next = {};
11
+ }
12
+ /**
13
+ * Adds a route to the routing system.
14
+ * @param {Route} route - The route to add.
15
+ * @param {string[]} parts - The parts of the route path.
16
+ * @returns None
17
+ * @throws {Error} If a duplicate route is detected.
18
+ */
19
+ addRoute(route, parts) {
20
+ const first = parts.shift();
21
+ if (first) {
22
+ if (first.startsWith(':')) {
23
+ this.variable = this.variable || new Routes();
24
+ this.variable.addRoute(route, parts);
25
+ }
26
+ else {
27
+ this.next[first] = this.next[first] || new Routes();
28
+ this.next[first].addRoute(route, parts);
29
+ }
30
+ }
31
+ else {
32
+ if (this.current)
33
+ throw new Error(`Duplicate route: ${route.method}: ${route.path}`);
34
+ this.current = route;
35
+ }
36
+ }
37
+ /**
38
+ * Resolves a route based on the given parts.
39
+ * @param {string[]} parts - An array of route parts.
40
+ * @returns {Route} The resolved route.
41
+ */
42
+ resolveRoute(parts) {
43
+ var _a;
44
+ const first = parts.shift();
45
+ if (first) {
46
+ if (first in this.next) {
47
+ return this.next[first].resolveRoute(parts);
48
+ }
49
+ return (_a = this.variable) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
50
+ }
51
+ return this.current;
52
+ }
53
+ }
54
+ /**
55
+ * A class that resolves routes based on the provided configuration.
56
+ * @class RouteResolver
57
+ */
58
+ export default class RouteResolver {
59
+ /**
60
+ * Constructs a new instance of the Router class with the given configuration.
61
+ * @param {RouterConfig} config - The configuration object for the router.
62
+ * @returns None
63
+ */
64
+ constructor(config) {
65
+ this.routes = {};
66
+ this.buildRoutes(config);
67
+ }
68
+ /**
69
+ * Resolves a route based on the given HTTP method and path.
70
+ * @param {string} method - The HTTP method of the request.
71
+ * @param {string} path - The path of the request.
72
+ * @returns {Route | undefined} - The resolved route or undefined if no route is found.
73
+ */
74
+ resolveRoute(method, path) {
75
+ var _a;
76
+ const parts = path.split('/').filter(p => p.length);
77
+ return (_a = this.routes[method]) === null || _a === void 0 ? void 0 : _a.resolveRoute(parts);
78
+ }
79
+ /**
80
+ * Builds the routes for the router based on the given configuration.
81
+ * @param {RouterConfig} config - The router configuration object.
82
+ * @returns None
83
+ */
84
+ buildRoutes(config) {
85
+ const addRoute = (path, route) => {
86
+ const parts = path.split('/').filter(p => p.length);
87
+ this.routes[route.method] = this.routes[route.method] || new Routes();
88
+ this.routes[route.method].addRoute(route, parts);
89
+ };
90
+ for (const route of config.routes) {
91
+ if (Array.isArray(route.path)) {
92
+ for (const path of route.path)
93
+ addRoute(path, route);
94
+ }
95
+ else
96
+ addRoute(route.path, route);
97
+ }
98
+ }
99
+ }
100
+ //# sourceMappingURL=RouteResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouteResolver.js","sourceRoot":"","sources":["../../../src/Server/RouteResolver.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM;IAkBV;;;OAGG;IACH;QACE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ,CAAC,KAAe,EAAE,KAAe;QAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;QAC3B,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,MAAM,EAAE,CAAA;gBAC7C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;YACtC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,EAAE,CAAA;gBACnD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;YACzC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAEpF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACtB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,KAAe;;QACjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA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AQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACnD,CAAC,CAAA;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI;oBAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACtD,CAAC;;gBAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,157 @@
1
+ import { Server as HTTPServer } from 'http';
2
+ import express from 'express';
3
+ import { z } from 'zod';
4
+ import { HttpMethod } from '../API/Request.js';
5
+ import { ResponseErrorType } from '../API/Response.js';
6
+ import Transaction, { TransactionConfig, TransactionExecution, StringMap } from '../BaseEvent/Transaction.js';
7
+ /**
8
+ * Represents a route in an API.
9
+ * @template InputType - The type of the input data for the route.
10
+ * @template OutputType - The type of the output data for the route.
11
+ * @property {string} path - The path of the route.
12
+ * @property {string} method - The HTTP method of the route.
13
+ * @property {TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType>, OutputType | ResponseErrorType>} handler - The handler function for the route.
14
+ * @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[inputSchema] - The input schema for validating the input data.
15
+ * @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[pathSchema] - The path schema for validating the path data.
16
+ * @property {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}[querySchema] - The query schema for validating the query data.
17
+ */
18
+ export interface Route<InputType = never, OutputType = never, PathParamsType = StringMap, QueryParamsType = StringMap> {
19
+ /**
20
+ * Represents a file path as a string.
21
+ * @param {string} path - The file path.
22
+ * @returns None
23
+ */
24
+ path: string | string[];
25
+ /**
26
+ * Represents the method used in an API request.
27
+ * @type {string}
28
+ */
29
+ method: HttpMethod;
30
+ /**
31
+ * Represents a handler for executing a transaction with the given input type and output type.
32
+ * @param {Transaction<InputType, OutputType | ResponseErrorType, PathParamsType, QueryParamsType>} transaction - The transaction to execute.
33
+ * @param {OutputType | ResponseErrorType} - The output type or response error type of the transaction.
34
+ */
35
+ handler: TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType, never, PathParamsType, QueryParamsType>, OutputType | ResponseErrorType>;
36
+ /**
37
+ * An optional input schema for validating the structure of the input data.
38
+ *
39
+ * @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
40
+ */
41
+ inputSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
42
+ /**
43
+ * An optional input schema for validating the structure of the path params.
44
+ *
45
+ * @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
46
+ */
47
+ pathSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
48
+ /**
49
+ * An optional input schema for validating the structure of the query params.
50
+ *
51
+ * @type {?z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>}
52
+ */
53
+ querySchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
54
+ /**
55
+ * An optional openApi object with extra metadata for docs generation.
56
+ */
57
+ openApi?: {
58
+ summary: string;
59
+ description: string;
60
+ tags?: string[];
61
+ outputSchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any> | z.ZodType<any>;
62
+ successCode?: number;
63
+ security?: {
64
+ [key: string]: string[] | never[];
65
+ }[];
66
+ };
67
+ }
68
+ /**
69
+ * Represents a route that can accept any type for its parameters and return values.
70
+ */
71
+ export type AnyRoute = Route<any | never, any | never, any | never, any | never>;
72
+ /**
73
+ * Represents the configuration options for a router.
74
+ * @typedef {TransactionConfig & {
75
+ * routes: Route[]
76
+ * port?: number
77
+ * timeout?: number
78
+ * cors?: {
79
+ * origin?: string | string[]
80
+ * headers?: string[]
81
+ * allowCredentials?: boolean
82
+ * }
83
+ * healthCheckRoute?: string
84
+ * }} RouterConfig
85
+ * @property {Route[]} routes - The routes to be configured in the router.
86
+ * @property {number} [port] - The port number to listen on. If not specified, a default port will be used.
87
+ * @property {number} [timeout] - The timeout duration for requests in milliseconds. If not specified, a default timeout will be
88
+ */
89
+ export type RouterConfig = TransactionConfig & {
90
+ /**
91
+ * An array of route objects representing the available routes in the application.
92
+ * @type {Route[]}
93
+ */
94
+ routes: AnyRoute[];
95
+ /**
96
+ * The port number for the server to listen on.
97
+ * @type {number | undefined}
98
+ */
99
+ port?: number;
100
+ /**
101
+ * Optional timeout value in milliseconds.
102
+ * @type {number | undefined}
103
+ */
104
+ timeout?: number;
105
+ /**
106
+ * Configuration options for Cross-Origin Resource Sharing (CORS).
107
+ * @property {string | string[]} [origin] - The allowed origin(s) for CORS requests.
108
+ * @property {string[]} [headers] - The allowed headers for CORS requests.
109
+ * @property {boolean} [allowCredentials] - Whether to allow credentials (cookies, HTTP authentication, and client-side SSL certificates) to be sent in CORS requests.
110
+ */
111
+ cors?: {
112
+ origin?: string | string[];
113
+ headers?: string[];
114
+ allowCredentials?: boolean;
115
+ };
116
+ /**
117
+ * The route for the health check endpoint.
118
+ * @type {string | undefined}
119
+ */
120
+ healthCheckRoute?: string;
121
+ /**
122
+ * Optional hook function that sets up the container with the provided HTTP server and Express app.
123
+ * @param {HTTPServer} server - The HTTP server instance.
124
+ * @param {express.Express} app - The Express application instance.
125
+ * @returns {Promise<void>} A promise that resolves when the setup is complete.
126
+ */
127
+ containerSetupHook?: (server: HTTPServer, app: express.Express) => Promise<void>;
128
+ };
129
+ /**
130
+ * Represents a router that handles routing logic for a web application.
131
+ */
132
+ export default class Router {
133
+ /**
134
+ * The configuration object for the router.
135
+ */
136
+ private readonly config;
137
+ /**
138
+ * The private readonly server instance.
139
+ */
140
+ private readonly server;
141
+ /**
142
+ * Constructs a new instance of the Router class.
143
+ * @param {RouterConfig} config - The configuration object for the router.
144
+ * @returns None
145
+ */
146
+ constructor(config: RouterConfig);
147
+ /**
148
+ * Retrieves the export function from the server.
149
+ * @returns {CallableFunction} The export function from the server.
150
+ */
151
+ getExport(): CallableFunction;
152
+ /**
153
+ * Checks if the current element is a container.
154
+ * @returns {boolean} - True if the element is a container, false otherwise.
155
+ */
156
+ private isContainer;
157
+ }
@@ -0,0 +1,32 @@
1
+ import ContainerServer from './lib/ContainerServer.js';
2
+ import Server from './lib/Server.js';
3
+ import Utils from '../Util/Utils.js';
4
+ /**
5
+ * Represents a router that handles routing logic for a web application.
6
+ */
7
+ export default class Router {
8
+ /**
9
+ * Constructs a new instance of the Router class.
10
+ * @param {RouterConfig} config - The configuration object for the router.
11
+ * @returns None
12
+ */
13
+ constructor(config) {
14
+ this.config = config;
15
+ this.server = this.isContainer() ? new ContainerServer(config) : new Server(config);
16
+ }
17
+ /**
18
+ * Retrieves the export function from the server.
19
+ * @returns {CallableFunction} The export function from the server.
20
+ */
21
+ getExport() {
22
+ return this.server.getExport();
23
+ }
24
+ /**
25
+ * Checks if the current element is a container.
26
+ * @returns {boolean} - True if the element is a container, false otherwise.
27
+ */
28
+ isContainer() {
29
+ return Utils.isHybridlessContainer();
30
+ }
31
+ }
32
+ //# sourceMappingURL=Router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,MAAM,MAAM,iBAAiB,CAAA;AAQpC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAmJpC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAUzB;;;;OAIG;IACH,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;IACrF,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IAED;;;OAGG;IACK,WAAW;QACjB,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;CACF"}