@gugananuvem/aws-local-simulator 1.0.9 → 1.0.11

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 (41) hide show
  1. package/README.md +204 -192
  2. package/bin/aws-local-simulator.js +62 -62
  3. package/package.json +2 -2
  4. package/src/config/config-loader.js +112 -112
  5. package/src/config/default-config.js +65 -65
  6. package/src/config/env-loader.js +68 -66
  7. package/src/index.js +130 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +221 -219
  10. package/src/services/apigateway/index.js +66 -66
  11. package/src/services/apigateway/server.js +434 -434
  12. package/src/services/apigateway/simulator.js +1251 -1251
  13. package/src/services/cognito/index.js +65 -65
  14. package/src/services/cognito/server.js +228 -228
  15. package/src/services/cognito/simulator.js +847 -847
  16. package/src/services/dynamodb/index.js +70 -70
  17. package/src/services/dynamodb/server.js +121 -121
  18. package/src/services/dynamodb/simulator.js +620 -614
  19. package/src/services/ecs/index.js +66 -0
  20. package/src/services/ecs/server.js +234 -0
  21. package/src/services/ecs/simulator.js +845 -0
  22. package/src/services/eventbridge/index.js +84 -84
  23. package/src/services/index.js +18 -18
  24. package/src/services/lambda/handler-loader.js +172 -172
  25. package/src/services/lambda/index.js +72 -72
  26. package/src/services/lambda/route-registry.js +274 -274
  27. package/src/services/lambda/server.js +152 -152
  28. package/src/services/lambda/simulator.js +284 -277
  29. package/src/services/s3/index.js +69 -69
  30. package/src/services/s3/server.js +238 -238
  31. package/src/services/s3/simulator.js +740 -740
  32. package/src/services/sns/index.js +75 -75
  33. package/src/services/sqs/index.js +95 -95
  34. package/src/services/sqs/server.js +273 -273
  35. package/src/services/sqs/simulator.js +659 -659
  36. package/src/template/aws-config-template.js +87 -87
  37. package/src/template/aws-config-template.mjs +90 -90
  38. package/src/template/config-template.json +203 -165
  39. package/src/utils/aws-config.js +91 -91
  40. package/src/utils/local-store.js +67 -67
  41. package/src/utils/logger.js +59 -59
@@ -1,153 +1,153 @@
1
- /**
2
- * Lambda Server - Servidor HTTP para Lambda (API Gateway style)
3
- */
4
-
5
- const express = require('express');
6
- const cors = require('cors');
7
- const LambdaSimulator = require('./simulator');
8
- const logger = require('../../utils/logger');
9
-
10
- class LambdaServer {
11
- constructor(port, config) {
12
- this.port = port;
13
- this.config = config;
14
- this.app = express();
15
- this.simulator = null;
16
- this.server = null;
17
- this.setupMiddlewares();
18
- }
19
-
20
- setupMiddlewares() {
21
- this.app.use(express.json({ limit: '10mb' }));
22
- this.app.use(express.urlencoded({ extended: true }));
23
- this.app.use(cors());
24
-
25
- // Logging de requisições
26
- if (logger.currentLogLevel === 'verboso') {
27
- this.app.use((req, res, next) => {
28
- const start = Date.now();
29
- res.on('finish', () => {
30
- const duration = Date.now() - start;
31
- logger.verboso(`Lambda: ${req.method} ${req.path} - ${duration}ms`);
32
- });
33
- next();
34
- });
35
- }
36
- }
37
-
38
- async initialize() {
39
- this.simulator = new LambdaSimulator(this.config);
40
- await this.simulator.initialize();
41
- this.setupRoutes();
42
- }
43
-
44
- setupRoutes() {
45
- // Health check
46
- this.app.get('/health', (req, res) => {
47
- res.json({
48
- status: 'healthy',
49
- version: require('../../../package.json').version,
50
- lambdas: this.simulator.getLambdasCount(),
51
- routes: this.simulator.listRoutes()
52
- });
53
- });
54
-
55
- // Rota catch-all para todas as Lambdas
56
- this.app.all('*', async (req, res) => {
57
- const result = await this.simulator.handleRequest(req, res);
58
-
59
- if (result && result.error) {
60
- res.status(result.status).json(result.error);
61
- }
62
- });
63
-
64
- // Admin endpoints
65
- this.setupAdminRoutes();
66
- }
67
-
68
- setupAdminRoutes() {
69
- // Listar todas as Lambdas
70
- this.app.get('/__admin/lambdas', (req, res) => {
71
- res.json(this.simulator.listLambdas());
72
- });
73
-
74
- // Detalhes de uma Lambda
75
- this.app.get('/__admin/lambdas/:path', (req, res) => {
76
- const lambda = this.simulator.getLambda(req.params.path);
77
- if (lambda) {
78
- res.json(lambda);
79
- } else {
80
- res.status(404).json({ error: 'Lambda not found' });
81
- }
82
- });
83
-
84
- // Recarregar Lambdas
85
- this.app.post('/__admin/reload', async (req, res) => {
86
- await this.simulator.reloadLambdas();
87
- res.json({
88
- message: 'Lambdas recarregadas',
89
- count: this.simulator.getLambdasCount()
90
- });
91
- });
92
-
93
- // Injetar variável de ambiente
94
- this.app.post('/__admin/env', (req, res) => {
95
- const { key, value } = req.body;
96
- if (key && value !== undefined) {
97
- this.simulator.setEnvironmentVariable(key, value);
98
- res.json({ message: `Environment variable ${key} set` });
99
- } else {
100
- res.status(400).json({ error: 'Missing key or value' });
101
- }
102
- });
103
-
104
- // Listar variáveis de ambiente
105
- this.app.get('/__admin/env', (req, res) => {
106
- res.json(this.simulator.getEnvironmentVariables());
107
- });
108
-
109
- // Estatísticas
110
- this.app.get('/__admin/stats', (req, res) => {
111
- res.json(this.simulator.getStats());
112
- });
113
- }
114
-
115
- start() {
116
- return new Promise((resolve) => {
117
- this.server = this.app.listen(this.port, () => {
118
- logger.info(`🚀 Lambda API rodando em http://localhost:${this.port}`);
119
- this.printRoutes();
120
- resolve();
121
- });
122
- });
123
- }
124
-
125
- printRoutes() {
126
- logger.info('\n📚 Lambdas registradas:');
127
- const lambdas = this.simulator.listLambdas();
128
- for (const lambda of lambdas) {
129
- logger.info(` ${lambda.path.padEnd(30)} -> ${lambda.handlerName || 'anonymous'}`);
130
- }
131
- }
132
-
133
- stop() {
134
- return new Promise((resolve) => {
135
- if (this.server) {
136
- this.server.close(() => resolve());
137
- } else {
138
- resolve();
139
- }
140
- });
141
- }
142
-
143
- getStatus() {
144
- return {
145
- running: !!this.server,
146
- port: this.port,
147
- endpoint: `http://localhost:${this.port}`,
148
- lambdasCount: this.simulator?.getLambdasCount() || 0
149
- };
150
- }
151
- }
152
-
1
+ /**
2
+ * Lambda Server - Servidor HTTP para Lambda (API Gateway style)
3
+ */
4
+
5
+ const express = require('express');
6
+ const cors = require('cors');
7
+ const LambdaSimulator = require('./simulator');
8
+ const logger = require('../../utils/logger');
9
+
10
+ class LambdaServer {
11
+ constructor(port, config) {
12
+ this.port = port;
13
+ this.config = config;
14
+ this.app = express();
15
+ this.simulator = null;
16
+ this.server = null;
17
+ this.setupMiddlewares();
18
+ }
19
+
20
+ setupMiddlewares() {
21
+ this.app.use(express.json({ limit: '10mb' }));
22
+ this.app.use(express.urlencoded({ extended: true }));
23
+ this.app.use(cors());
24
+
25
+ // Logging de requisições
26
+ if (logger.currentLogLevel === 'verboso') {
27
+ this.app.use((req, res, next) => {
28
+ const start = Date.now();
29
+ res.on('finish', () => {
30
+ const duration = Date.now() - start;
31
+ logger.verboso(`Lambda: ${req.method} ${req.path} - ${duration}ms`);
32
+ });
33
+ next();
34
+ });
35
+ }
36
+ }
37
+
38
+ async initialize() {
39
+ this.simulator = new LambdaSimulator(this.config);
40
+ await this.simulator.initialize();
41
+ this.setupRoutes();
42
+ }
43
+
44
+ setupRoutes() {
45
+ // Health check
46
+ this.app.get('/health', (req, res) => {
47
+ res.json({
48
+ status: 'healthy',
49
+ version: require('../../../package.json').version,
50
+ lambdas: this.simulator.getLambdasCount(),
51
+ routes: this.simulator.listRoutes()
52
+ });
53
+ });
54
+
55
+ // Rota catch-all para todas as Lambdas
56
+ this.app.all('*', async (req, res) => {
57
+ const result = await this.simulator.handleRequest(req, res);
58
+
59
+ if (result && result.error) {
60
+ res.status(result.status).json(result.error);
61
+ }
62
+ });
63
+
64
+ // Admin endpoints
65
+ this.setupAdminRoutes();
66
+ }
67
+
68
+ setupAdminRoutes() {
69
+ // Listar todas as Lambdas
70
+ this.app.get('/__admin/lambdas', (req, res) => {
71
+ res.json(this.simulator.listLambdas());
72
+ });
73
+
74
+ // Detalhes de uma Lambda
75
+ this.app.get('/__admin/lambdas/:path', (req, res) => {
76
+ const lambda = this.simulator.getLambda(req.params.path);
77
+ if (lambda) {
78
+ res.json(lambda);
79
+ } else {
80
+ res.status(404).json({ error: 'Lambda not found' });
81
+ }
82
+ });
83
+
84
+ // Recarregar Lambdas
85
+ this.app.post('/__admin/reload', async (req, res) => {
86
+ await this.simulator.reloadLambdas();
87
+ res.json({
88
+ message: 'Lambdas recarregadas',
89
+ count: this.simulator.getLambdasCount()
90
+ });
91
+ });
92
+
93
+ // Injetar variável de ambiente
94
+ this.app.post('/__admin/env', (req, res) => {
95
+ const { key, value } = req.body;
96
+ if (key && value !== undefined) {
97
+ this.simulator.setEnvironmentVariable(key, value);
98
+ res.json({ message: `Environment variable ${key} set` });
99
+ } else {
100
+ res.status(400).json({ error: 'Missing key or value' });
101
+ }
102
+ });
103
+
104
+ // Listar variáveis de ambiente
105
+ this.app.get('/__admin/env', (req, res) => {
106
+ res.json(this.simulator.getEnvironmentVariables());
107
+ });
108
+
109
+ // Estatísticas
110
+ this.app.get('/__admin/stats', (req, res) => {
111
+ res.json(this.simulator.getStats());
112
+ });
113
+ }
114
+
115
+ start() {
116
+ return new Promise((resolve) => {
117
+ this.server = this.app.listen(this.port, () => {
118
+ logger.info(`🚀 Lambda API rodando em http://localhost:${this.port}`);
119
+ this.printRoutes();
120
+ resolve();
121
+ });
122
+ });
123
+ }
124
+
125
+ printRoutes() {
126
+ logger.info('\n📚 Lambdas registradas:');
127
+ const lambdas = this.simulator.listLambdas();
128
+ for (const lambda of lambdas) {
129
+ logger.info(` ${lambda.path.padEnd(30)} -> ${lambda.handlerName || 'anonymous'}`);
130
+ }
131
+ }
132
+
133
+ stop() {
134
+ return new Promise((resolve) => {
135
+ if (this.server) {
136
+ this.server.close(() => resolve());
137
+ } else {
138
+ resolve();
139
+ }
140
+ });
141
+ }
142
+
143
+ getStatus() {
144
+ return {
145
+ running: !!this.server,
146
+ port: this.port,
147
+ endpoint: `http://localhost:${this.port}`,
148
+ lambdasCount: this.simulator?.getLambdasCount() || 0
149
+ };
150
+ }
151
+ }
152
+
153
153
  module.exports = LambdaServer;