@gugananuvem/aws-local-simulator 1.0.12 → 1.0.15

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 (77) hide show
  1. package/README.md +594 -257
  2. package/bin/aws-local-simulator.js +63 -63
  3. package/package.json +21 -10
  4. package/src/config/config-loader.js +114 -114
  5. package/src/config/default-config.js +68 -67
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +146 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +227 -223
  10. package/src/services/apigateway/index.js +73 -68
  11. package/src/services/apigateway/server.js +507 -487
  12. package/src/services/apigateway/simulator.js +1261 -1251
  13. package/src/services/athena/index.js +75 -0
  14. package/src/services/athena/server.js +101 -0
  15. package/src/services/athena/simulador.js +998 -0
  16. package/src/services/athena/simulator.js +346 -0
  17. package/src/services/cloudformation/index.js +106 -0
  18. package/src/services/cloudformation/server.js +417 -0
  19. package/src/services/cloudformation/simulador.js +1045 -0
  20. package/src/services/cloudtrail/index.js +84 -0
  21. package/src/services/cloudtrail/server.js +235 -0
  22. package/src/services/cloudtrail/simulador.js +719 -0
  23. package/src/services/cloudwatch/index.js +84 -0
  24. package/src/services/cloudwatch/server.js +366 -0
  25. package/src/services/cloudwatch/simulador.js +1173 -0
  26. package/src/services/cognito/index.js +79 -65
  27. package/src/services/cognito/server.js +301 -279
  28. package/src/services/cognito/simulator.js +1655 -1115
  29. package/src/services/config/index.js +96 -0
  30. package/src/services/config/server.js +215 -0
  31. package/src/services/config/simulador.js +1260 -0
  32. package/src/services/dynamodb/index.js +74 -70
  33. package/src/services/dynamodb/server.js +125 -121
  34. package/src/services/dynamodb/simulator.js +630 -620
  35. package/src/services/ecs/index.js +65 -65
  36. package/src/services/ecs/server.js +235 -233
  37. package/src/services/ecs/simulator.js +844 -844
  38. package/src/services/eventbridge/index.js +89 -85
  39. package/src/services/eventbridge/server.js +209 -0
  40. package/src/services/eventbridge/simulator.js +684 -0
  41. package/src/services/index.js +45 -19
  42. package/src/services/kms/index.js +75 -0
  43. package/src/services/kms/server.js +67 -0
  44. package/src/services/kms/simulator.js +324 -0
  45. package/src/services/lambda/handler-loader.js +183 -183
  46. package/src/services/lambda/index.js +78 -73
  47. package/src/services/lambda/route-registry.js +274 -274
  48. package/src/services/lambda/server.js +145 -145
  49. package/src/services/lambda/simulator.js +199 -172
  50. package/src/services/parameter-store/index.js +80 -0
  51. package/src/services/parameter-store/server.js +50 -0
  52. package/src/services/parameter-store/simulator.js +201 -0
  53. package/src/services/s3/index.js +73 -69
  54. package/src/services/s3/server.js +329 -238
  55. package/src/services/s3/simulator.js +565 -740
  56. package/src/services/secret-manager/index.js +80 -0
  57. package/src/services/secret-manager/server.js +50 -0
  58. package/src/services/secret-manager/simulator.js +171 -0
  59. package/src/services/sns/index.js +89 -76
  60. package/src/services/sns/server.js +580 -0
  61. package/src/services/sns/simulator.js +1482 -0
  62. package/src/services/sqs/index.js +93 -95
  63. package/src/services/sqs/server.js +349 -345
  64. package/src/services/sqs/simulator.js +441 -441
  65. package/src/services/sts/index.js +37 -37
  66. package/src/services/sts/server.js +144 -142
  67. package/src/services/sts/simulator.js +69 -69
  68. package/src/services/xray/index.js +83 -0
  69. package/src/services/xray/server.js +308 -0
  70. package/src/services/xray/simulador.js +994 -0
  71. package/src/template/aws-config-template.js +87 -87
  72. package/src/template/aws-config-template.mjs +90 -90
  73. package/src/template/config-template.json +203 -203
  74. package/src/utils/aws-config.js +91 -91
  75. package/src/utils/cloudtrail-audit.js +129 -0
  76. package/src/utils/local-store.js +83 -67
  77. package/src/utils/logger.js +59 -59
@@ -1,275 +1,275 @@
1
- /**
2
- * Route Registry - Gerencia o registro e matching de rotas para Lambdas
3
- * Suporta: Path parameters, Wildcards, Middlewares
4
- */
5
-
6
- class RouteRegistry {
7
- constructor() {
8
- this.routes = new Map();
9
- this.middlewares = new Map();
10
- this.globalMiddlewares = [];
11
- }
12
-
13
- /**
14
- * Registra uma rota
15
- * @param {string} path - Caminho da rota (ex: /users/:id, /api/*)
16
- * @param {Function} handler - Função handler da Lambda
17
- * @param {Object} env - Variáveis de ambiente específicas
18
- * @param {Array} middlewares - Middlewares específicos da rota
19
- */
20
- register(path, handler, env = {}, middlewares = []) {
21
- // Normaliza o path
22
- const normalizedPath = this.normalizePath(path);
23
-
24
- // Parse do path para extrair parâmetros
25
- const { pattern, params } = this.parsePath(normalizedPath);
26
-
27
- this.routes.set(normalizedPath, {
28
- path: normalizedPath,
29
- pattern,
30
- params,
31
- handler,
32
- env,
33
- middlewares,
34
- isWildcard: normalizedPath.includes('*'),
35
- hasParams: params.length > 0,
36
- timestamp: Date.now()
37
- });
38
-
39
- // Adiciona versão com barra se não existir
40
- if (!normalizedPath.endsWith('/') && normalizedPath !== '*') {
41
- const slashPath = `${normalizedPath}/`;
42
- if (!this.routes.has(slashPath)) {
43
- this.routes.set(slashPath, {
44
- path: slashPath,
45
- pattern: this.parsePath(slashPath).pattern,
46
- params: this.parsePath(slashPath).params,
47
- handler,
48
- env,
49
- middlewares,
50
- isWildcard: false,
51
- hasParams: this.parsePath(slashPath).params.length > 0,
52
- timestamp: Date.now()
53
- });
54
- }
55
- }
56
-
57
- return this;
58
- }
59
-
60
- /**
61
- * Registra um middleware global
62
- */
63
- use(middleware) {
64
- this.globalMiddlewares.push(middleware);
65
- return this;
66
- }
67
-
68
- /**
69
- * Registra um middleware para uma rota específica
70
- */
71
- useFor(path, middleware) {
72
- const normalizedPath = this.normalizePath(path);
73
- if (!this.middlewares.has(normalizedPath)) {
74
- this.middlewares.set(normalizedPath, []);
75
- }
76
- this.middlewares.get(normalizedPath).push(middleware);
77
- return this;
78
- }
79
-
80
- /**
81
- * Encontra uma rota que corresponde ao path
82
- * @param {string} path - Path da requisição
83
- * @returns {Object|null} - Rota encontrada com parâmetros extraídos
84
- */
85
- find(path) {
86
- const normalizedPath = this.normalizePath(path);
87
-
88
- // Busca exata primeiro
89
- if (this.routes.has(normalizedPath)) {
90
- const route = this.routes.get(normalizedPath);
91
- return {
92
- ...route,
93
- params: {}
94
- };
95
- }
96
-
97
- // Busca por prefixo (para rotas sem parâmetros)
98
- for (const [routePath, route] of this.routes.entries()) {
99
- if (!route.hasParams && !route.isWildcard && normalizedPath.startsWith(routePath)) {
100
- return {
101
- ...route,
102
- params: {}
103
- };
104
- }
105
- }
106
-
107
- // Busca por padrão com parâmetros
108
- for (const [routePath, route] of this.routes.entries()) {
109
- if (route.hasParams && route.pattern) {
110
- const match = route.pattern.exec(normalizedPath);
111
- if (match) {
112
- const params = {};
113
- route.params.forEach((paramName, index) => {
114
- params[paramName] = match[index + 1];
115
- });
116
- return {
117
- ...route,
118
- params
119
- };
120
- }
121
- }
122
- }
123
-
124
- // Busca wildcard
125
- for (const [routePath, route] of this.routes.entries()) {
126
- if (route.isWildcard) {
127
- const wildcardPath = routePath.replace('*', '');
128
- if (normalizedPath.startsWith(wildcardPath)) {
129
- return {
130
- ...route,
131
- params: {
132
- wildcard: normalizedPath.substring(wildcardPath.length)
133
- }
134
- };
135
- }
136
- }
137
- }
138
-
139
- return null;
140
- }
141
-
142
- /**
143
- * Obtém todos os middlewares para uma rota
144
- */
145
- getMiddlewares(route) {
146
- const routeMiddlewares = this.middlewares.get(route.path) || [];
147
- return [...this.globalMiddlewares, ...routeMiddlewares, ...route.middlewares];
148
- }
149
-
150
- /**
151
- * Normaliza o path
152
- */
153
- normalizePath(path) {
154
- // Remove query string
155
- const pathWithoutQuery = path.split('?')[0];
156
-
157
- // Remove trailing slash
158
- let normalized = pathWithoutQuery.replace(/\/+$/, '');
159
-
160
- // Adiciona slash inicial se necessário
161
- if (!normalized.startsWith('/')) {
162
- normalized = `/${normalized}`;
163
- }
164
-
165
- // Se for vazio, usa root
166
- if (normalized === '') {
167
- normalized = '/';
168
- }
169
-
170
- return normalized;
171
- }
172
-
173
- /**
174
- * Parse do path para extrair parâmetros e criar regex pattern
175
- * @param {string} path - Path da rota (ex: /users/:id/posts/:postId)
176
- * @returns {Object} - { pattern, params }
177
- */
178
- parsePath(path) {
179
- const params = [];
180
-
181
- // Substitui :param por regex capture group
182
- const patternString = path.replace(/:[^\s/]+/g, (match) => {
183
- const paramName = match.substring(1);
184
- params.push(paramName);
185
- return '([^/]+)';
186
- });
187
-
188
- // Substitui * por regex wildcard
189
- const finalPatternString = patternString.replace(/\*/g, '(.*)');
190
-
191
- // Cria regex
192
- const pattern = new RegExp(`^${finalPatternString}$`);
193
-
194
- return { pattern, params };
195
- }
196
-
197
- /**
198
- * Remove uma rota
199
- */
200
- unregister(path) {
201
- const normalizedPath = this.normalizePath(path);
202
- this.routes.delete(normalizedPath);
203
- return this;
204
- }
205
-
206
- /**
207
- * Lista todas as rotas
208
- */
209
- list() {
210
- const routes = [];
211
- for (const [path, route] of this.routes.entries()) {
212
- routes.push({
213
- path,
214
- handler: route.handler.name || 'anonymous',
215
- hasParams: route.hasParams,
216
- isWildcard: route.isWildcard,
217
- params: route.params,
218
- env: route.env
219
- });
220
- }
221
- return routes;
222
- }
223
-
224
- /**
225
- * Limpa todas as rotas
226
- */
227
- clear() {
228
- this.routes.clear();
229
- this.middlewares.clear();
230
- this.globalMiddlewares = [];
231
- return this;
232
- }
233
-
234
- /**
235
- * Verifica se uma rota existe
236
- */
237
- has(path) {
238
- const normalizedPath = this.normalizePath(path);
239
- return this.routes.has(normalizedPath) || this.find(path) !== null;
240
- }
241
-
242
- /**
243
- * Obtém todas as rotas em formato de objeto
244
- */
245
- getAll() {
246
- const result = {};
247
- for (const [path, route] of this.routes.entries()) {
248
- result[path] = {
249
- handler: route.handler,
250
- env: route.env,
251
- hasParams: route.hasParams,
252
- params: route.params
253
- };
254
- }
255
- return result;
256
- }
257
-
258
- /**
259
- * Obtém estatísticas das rotas
260
- */
261
- getStats() {
262
- const routes = Array.from(this.routes.values());
263
- return {
264
- total: routes.length,
265
- withParams: routes.filter(r => r.hasParams).length,
266
- wildcards: routes.filter(r => r.isWildcard).length,
267
- routes: routes.map(r => ({
268
- path: r.path,
269
- handler: r.handler.name || 'anonymous'
270
- }))
271
- };
272
- }
273
- }
274
-
1
+ /**
2
+ * Route Registry - Gerencia o registro e matching de rotas para Lambdas
3
+ * Suporta: Path parameters, Wildcards, Middlewares
4
+ */
5
+
6
+ class RouteRegistry {
7
+ constructor() {
8
+ this.routes = new Map();
9
+ this.middlewares = new Map();
10
+ this.globalMiddlewares = [];
11
+ }
12
+
13
+ /**
14
+ * Registra uma rota
15
+ * @param {string} path - Caminho da rota (ex: /users/:id, /api/*)
16
+ * @param {Function} handler - Função handler da Lambda
17
+ * @param {Object} env - Variáveis de ambiente específicas
18
+ * @param {Array} middlewares - Middlewares específicos da rota
19
+ */
20
+ register(path, handler, env = {}, middlewares = []) {
21
+ // Normaliza o path
22
+ const normalizedPath = this.normalizePath(path);
23
+
24
+ // Parse do path para extrair parâmetros
25
+ const { pattern, params } = this.parsePath(normalizedPath);
26
+
27
+ this.routes.set(normalizedPath, {
28
+ path: normalizedPath,
29
+ pattern,
30
+ params,
31
+ handler,
32
+ env,
33
+ middlewares,
34
+ isWildcard: normalizedPath.includes('*'),
35
+ hasParams: params.length > 0,
36
+ timestamp: Date.now()
37
+ });
38
+
39
+ // Adiciona versão com barra se não existir
40
+ if (!normalizedPath.endsWith('/') && normalizedPath !== '*') {
41
+ const slashPath = `${normalizedPath}/`;
42
+ if (!this.routes.has(slashPath)) {
43
+ this.routes.set(slashPath, {
44
+ path: slashPath,
45
+ pattern: this.parsePath(slashPath).pattern,
46
+ params: this.parsePath(slashPath).params,
47
+ handler,
48
+ env,
49
+ middlewares,
50
+ isWildcard: false,
51
+ hasParams: this.parsePath(slashPath).params.length > 0,
52
+ timestamp: Date.now()
53
+ });
54
+ }
55
+ }
56
+
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Registra um middleware global
62
+ */
63
+ use(middleware) {
64
+ this.globalMiddlewares.push(middleware);
65
+ return this;
66
+ }
67
+
68
+ /**
69
+ * Registra um middleware para uma rota específica
70
+ */
71
+ useFor(path, middleware) {
72
+ const normalizedPath = this.normalizePath(path);
73
+ if (!this.middlewares.has(normalizedPath)) {
74
+ this.middlewares.set(normalizedPath, []);
75
+ }
76
+ this.middlewares.get(normalizedPath).push(middleware);
77
+ return this;
78
+ }
79
+
80
+ /**
81
+ * Encontra uma rota que corresponde ao path
82
+ * @param {string} path - Path da requisição
83
+ * @returns {Object|null} - Rota encontrada com parâmetros extraídos
84
+ */
85
+ find(path) {
86
+ const normalizedPath = this.normalizePath(path);
87
+
88
+ // Busca exata primeiro
89
+ if (this.routes.has(normalizedPath)) {
90
+ const route = this.routes.get(normalizedPath);
91
+ return {
92
+ ...route,
93
+ params: {}
94
+ };
95
+ }
96
+
97
+ // Busca por prefixo (para rotas sem parâmetros)
98
+ for (const [routePath, route] of this.routes.entries()) {
99
+ if (!route.hasParams && !route.isWildcard && normalizedPath.startsWith(routePath)) {
100
+ return {
101
+ ...route,
102
+ params: {}
103
+ };
104
+ }
105
+ }
106
+
107
+ // Busca por padrão com parâmetros
108
+ for (const [routePath, route] of this.routes.entries()) {
109
+ if (route.hasParams && route.pattern) {
110
+ const match = route.pattern.exec(normalizedPath);
111
+ if (match) {
112
+ const params = {};
113
+ route.params.forEach((paramName, index) => {
114
+ params[paramName] = match[index + 1];
115
+ });
116
+ return {
117
+ ...route,
118
+ params
119
+ };
120
+ }
121
+ }
122
+ }
123
+
124
+ // Busca wildcard
125
+ for (const [routePath, route] of this.routes.entries()) {
126
+ if (route.isWildcard) {
127
+ const wildcardPath = routePath.replace('*', '');
128
+ if (normalizedPath.startsWith(wildcardPath)) {
129
+ return {
130
+ ...route,
131
+ params: {
132
+ wildcard: normalizedPath.substring(wildcardPath.length)
133
+ }
134
+ };
135
+ }
136
+ }
137
+ }
138
+
139
+ return null;
140
+ }
141
+
142
+ /**
143
+ * Obtém todos os middlewares para uma rota
144
+ */
145
+ getMiddlewares(route) {
146
+ const routeMiddlewares = this.middlewares.get(route.path) || [];
147
+ return [...this.globalMiddlewares, ...routeMiddlewares, ...route.middlewares];
148
+ }
149
+
150
+ /**
151
+ * Normaliza o path
152
+ */
153
+ normalizePath(path) {
154
+ // Remove query string
155
+ const pathWithoutQuery = path.split('?')[0];
156
+
157
+ // Remove trailing slash
158
+ let normalized = pathWithoutQuery.replace(/\/+$/, '');
159
+
160
+ // Adiciona slash inicial se necessário
161
+ if (!normalized.startsWith('/')) {
162
+ normalized = `/${normalized}`;
163
+ }
164
+
165
+ // Se for vazio, usa root
166
+ if (normalized === '') {
167
+ normalized = '/';
168
+ }
169
+
170
+ return normalized;
171
+ }
172
+
173
+ /**
174
+ * Parse do path para extrair parâmetros e criar regex pattern
175
+ * @param {string} path - Path da rota (ex: /users/:id/posts/:postId)
176
+ * @returns {Object} - { pattern, params }
177
+ */
178
+ parsePath(path) {
179
+ const params = [];
180
+
181
+ // Substitui :param por regex capture group
182
+ const patternString = path.replace(/:[^\s/]+/g, (match) => {
183
+ const paramName = match.substring(1);
184
+ params.push(paramName);
185
+ return '([^/]+)';
186
+ });
187
+
188
+ // Substitui * por regex wildcard
189
+ const finalPatternString = patternString.replace(/\*/g, '(.*)');
190
+
191
+ // Cria regex
192
+ const pattern = new RegExp(`^${finalPatternString}$`);
193
+
194
+ return { pattern, params };
195
+ }
196
+
197
+ /**
198
+ * Remove uma rota
199
+ */
200
+ unregister(path) {
201
+ const normalizedPath = this.normalizePath(path);
202
+ this.routes.delete(normalizedPath);
203
+ return this;
204
+ }
205
+
206
+ /**
207
+ * Lista todas as rotas
208
+ */
209
+ list() {
210
+ const routes = [];
211
+ for (const [path, route] of this.routes.entries()) {
212
+ routes.push({
213
+ path,
214
+ handler: route.handler.name || 'anonymous',
215
+ hasParams: route.hasParams,
216
+ isWildcard: route.isWildcard,
217
+ params: route.params,
218
+ env: route.env
219
+ });
220
+ }
221
+ return routes;
222
+ }
223
+
224
+ /**
225
+ * Limpa todas as rotas
226
+ */
227
+ clear() {
228
+ this.routes.clear();
229
+ this.middlewares.clear();
230
+ this.globalMiddlewares = [];
231
+ return this;
232
+ }
233
+
234
+ /**
235
+ * Verifica se uma rota existe
236
+ */
237
+ has(path) {
238
+ const normalizedPath = this.normalizePath(path);
239
+ return this.routes.has(normalizedPath) || this.find(path) !== null;
240
+ }
241
+
242
+ /**
243
+ * Obtém todas as rotas em formato de objeto
244
+ */
245
+ getAll() {
246
+ const result = {};
247
+ for (const [path, route] of this.routes.entries()) {
248
+ result[path] = {
249
+ handler: route.handler,
250
+ env: route.env,
251
+ hasParams: route.hasParams,
252
+ params: route.params
253
+ };
254
+ }
255
+ return result;
256
+ }
257
+
258
+ /**
259
+ * Obtém estatísticas das rotas
260
+ */
261
+ getStats() {
262
+ const routes = Array.from(this.routes.values());
263
+ return {
264
+ total: routes.length,
265
+ withParams: routes.filter(r => r.hasParams).length,
266
+ wildcards: routes.filter(r => r.isWildcard).length,
267
+ routes: routes.map(r => ({
268
+ path: r.path,
269
+ handler: r.handler.name || 'anonymous'
270
+ }))
271
+ };
272
+ }
273
+ }
274
+
275
275
  module.exports = RouteRegistry;