@gugananuvem/aws-local-simulator 1.0.10 → 1.0.12

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 (44) hide show
  1. package/README.md +257 -193
  2. package/bin/aws-local-simulator.js +62 -62
  3. package/package.json +2 -2
  4. package/src/config/config-loader.js +114 -112
  5. package/src/config/default-config.js +67 -65
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +130 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +223 -222
  10. package/src/services/apigateway/index.js +68 -66
  11. package/src/services/apigateway/server.js +487 -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 +279 -228
  15. package/src/services/cognito/simulator.js +1114 -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 +65 -65
  20. package/src/services/ecs/server.js +233 -233
  21. package/src/services/ecs/simulator.js +844 -844
  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 +183 -172
  25. package/src/services/lambda/index.js +73 -72
  26. package/src/services/lambda/route-registry.js +274 -274
  27. package/src/services/lambda/server.js +145 -152
  28. package/src/services/lambda/simulator.js +172 -285
  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 +345 -273
  35. package/src/services/sqs/simulator.js +441 -660
  36. package/src/services/sts/index.js +37 -0
  37. package/src/services/sts/server.js +142 -0
  38. package/src/services/sts/simulator.js +69 -0
  39. package/src/template/aws-config-template.js +87 -87
  40. package/src/template/aws-config-template.mjs +90 -90
  41. package/src/template/config-template.json +203 -203
  42. package/src/utils/aws-config.js +91 -91
  43. package/src/utils/local-store.js +67 -67
  44. package/src/utils/logger.js +59 -59
@@ -1,66 +1,66 @@
1
- /**
2
- * Cognito Service - Simulador de Amazon Cognito
3
- * Suporta: User Pools, Identity Pools, Authentication, User Management
4
- */
5
-
6
- const CognitoServer = require('./server');
7
- const CognitoSimulator = require('./simulator');
8
-
9
- class CognitoService {
10
- constructor(config) {
11
- this.config = config;
12
- this.name = 'cognito';
13
- this.port = config.ports.cognito || 9229;
14
- this.server = null;
15
- this.simulator = null;
16
- this.isRunning = false;
17
- }
18
-
19
- async initialize() {
20
- const logger = require('../../utils/logger');
21
- logger.debug(`Inicializando Cognito Service na porta ${this.port}...`);
22
-
23
- this.simulator = new CognitoSimulator(this.config);
24
- await this.simulator.initialize();
25
-
26
- this.server = new CognitoServer(this.port, this.config);
27
- this.server.simulator = this.simulator;
28
-
29
- await this.server.initialize();
30
-
31
- logger.debug('Cognito Service inicializado');
32
- }
33
-
34
- async start() {
35
- if (this.isRunning) return;
36
- await this.server.start();
37
- this.isRunning = true;
38
- }
39
-
40
- async stop() {
41
- if (!this.isRunning) return;
42
- await this.server.stop();
43
- this.isRunning = false;
44
- }
45
-
46
- async reset() {
47
- await this.simulator.reset();
48
- }
49
-
50
- getStatus() {
51
- return {
52
- running: this.isRunning,
53
- port: this.port,
54
- endpoint: `http://localhost:${this.port}`,
55
- userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
56
- usersCount: this.simulator?.getTotalUsersCount() || 0,
57
- identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0
58
- };
59
- }
60
-
61
- getSimulator() {
62
- return this.simulator;
63
- }
64
- }
65
-
1
+ /**
2
+ * Cognito Service - Simulador de Amazon Cognito
3
+ * Suporta: User Pools, Identity Pools, Authentication, User Management
4
+ */
5
+
6
+ const CognitoServer = require('./server');
7
+ const CognitoSimulator = require('./simulator');
8
+
9
+ class CognitoService {
10
+ constructor(config) {
11
+ this.config = config;
12
+ this.name = 'cognito';
13
+ this.port = config.ports.cognito || 9229;
14
+ this.server = null;
15
+ this.simulator = null;
16
+ this.isRunning = false;
17
+ }
18
+
19
+ async initialize() {
20
+ const logger = require('../../utils/logger');
21
+ logger.debug(`Inicializando Cognito Service na porta ${this.port}...`);
22
+
23
+ this.simulator = new CognitoSimulator(this.config);
24
+ await this.simulator.initialize();
25
+
26
+ this.server = new CognitoServer(this.port, this.config);
27
+ this.server.simulator = this.simulator;
28
+
29
+ await this.server.initialize();
30
+
31
+ logger.debug('Cognito Service inicializado');
32
+ }
33
+
34
+ async start() {
35
+ if (this.isRunning) return;
36
+ await this.server.start();
37
+ this.isRunning = true;
38
+ }
39
+
40
+ async stop() {
41
+ if (!this.isRunning) return;
42
+ await this.server.stop();
43
+ this.isRunning = false;
44
+ }
45
+
46
+ async reset() {
47
+ await this.simulator.reset();
48
+ }
49
+
50
+ getStatus() {
51
+ return {
52
+ running: this.isRunning,
53
+ port: this.port,
54
+ endpoint: `http://localhost:${this.port}`,
55
+ userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
56
+ usersCount: this.simulator?.getTotalUsersCount() || 0,
57
+ identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0
58
+ };
59
+ }
60
+
61
+ getSimulator() {
62
+ return this.simulator;
63
+ }
64
+ }
65
+
66
66
  module.exports = CognitoService;
@@ -1,229 +1,280 @@
1
- /**
2
- * Cognito Server - Servidor HTTP para Cognito API
3
- */
4
-
5
- const express = require('express');
6
- const logger = require('../../utils/logger');
7
-
8
- class CognitoServer {
9
- constructor(port, config) {
10
- this.port = port;
11
- this.config = config;
12
- this.app = express();
13
- this.simulator = null;
14
- this.server = null;
15
- this.setupMiddlewares();
16
- }
17
-
18
- setupMiddlewares() {
19
- this.app.use(express.json());
20
-
21
- if (logger.currentLogLevel === 'verboso') {
22
- this.app.use((req, res, next) => {
23
- const start = Date.now();
24
- res.on('finish', () => {
25
- const duration = Date.now() - start;
26
- logger.verboso(`Cognito: ${req.method} ${req.path} - ${duration}ms`);
27
- });
28
- next();
29
- });
30
- }
31
- }
32
-
33
- async initialize() {
34
- this.setupRoutes();
35
- logger.debug('Cognito Server inicializado');
36
- }
37
-
38
- setupRoutes() {
39
- // Health check
40
- this.app.get('/health', (req, res) => {
41
- res.json({
42
- status: 'healthy',
43
- service: 'cognito-simulator',
44
- version: '1.0.0'
45
- });
46
- });
47
-
48
- // User Pool operations
49
- this.app.post('/', async (req, res) => {
50
- const target = req.headers['x-amz-target'];
51
- if (!target) {
52
- return res.status(400).json({ error: 'Missing X-Amz-Target header' });
53
- }
54
-
55
- try {
56
- const result = await this.handleRequest(target, req.body);
57
- res.json(result);
58
- } catch (error) {
59
- logger.error('Cognito Error:', error);
60
- res.status(400).json({
61
- __type: error.code || 'InternalServerError',
62
- message: error.message
63
- });
64
- }
65
- });
66
-
67
- // Admin endpoints
68
- this.setupAdminRoutes();
69
- }
70
-
71
- async handleRequest(target, params) {
72
- const action = target.split('.')[2] || target.split('.')[1];
73
-
74
- logger.verboso(`Cognito Action: ${action}`);
75
-
76
- switch(action) {
77
- // User Pool Management
78
- case 'CreateUserPool':
79
- return this.simulator.createUserPool(params);
80
- case 'ListUserPools':
81
- return this.simulator.listUserPools(params);
82
- case 'DescribeUserPool':
83
- return this.simulator.describeUserPool(params);
84
- case 'DeleteUserPool':
85
- return this.simulator.deleteUserPool(params);
86
-
87
- // User Pool Client Management
88
- case 'CreateUserPoolClient':
89
- return this.simulator.createUserPoolClient(params);
90
-
91
- // User Operations
92
- case 'SignUp':
93
- return this.simulator.signUp(params);
94
- case 'ConfirmSignUp':
95
- return this.simulator.confirmSignUp(params);
96
- case 'InitiateAuth':
97
- return this.simulator.initiateAuth(params);
98
- case 'GetToken':
99
- return this.simulator.getToken(params);
100
-
101
- // Admin Operations
102
- case 'AdminGetUser':
103
- return this.simulator.adminGetUser(params);
104
- case 'AdminCreateUser':
105
- return this.simulator.adminCreateUser(params);
106
- case 'AdminSetUserPassword':
107
- return this.simulator.adminSetUserPassword(params);
108
- case 'AdminDeleteUser':
109
- return this.simulator.adminDeleteUser(params);
110
-
111
- // Identity Pool Operations
112
- case 'CreateIdentityPool':
113
- return this.simulator.createIdentityPool(params);
114
- case 'GetId':
115
- return this.simulator.getId(params);
116
- case 'GetCredentialsForIdentity':
117
- return this.simulator.getCredentialsForIdentity(params);
118
-
119
- default:
120
- throw new Error(`Unsupported action: ${action}`);
121
- }
122
- }
123
-
124
- setupAdminRoutes() {
125
- this.app.get('/__admin/userpools', (req, res) => {
126
- res.json({
127
- userPools: this.simulator.getUserPoolsCount(),
128
- users: this.simulator.getTotalUsersCount(),
129
- identityPools: this.simulator.getIdentityPoolsCount(),
130
- activeSessions: this.simulator.getActiveSessionsCount()
131
- });
132
- });
133
-
134
- this.app.get('/__admin/userpools/:poolId/users', (req, res) => {
135
- const pool = this.simulator.userPools.get(req.params.poolId);
136
- if (!pool) {
137
- return res.status(404).json({ error: 'User pool not found' });
138
- }
139
-
140
- const users = [];
141
- for (const userId of pool.Users) {
142
- const user = this.simulator.users.get(userId);
143
- if (user) {
144
- users.push({
145
- username: user.Username,
146
- userId: user.UserId,
147
- status: user.UserStatus,
148
- attributes: user.Attributes,
149
- created: user.CreatedDate
150
- });
151
- }
152
- }
153
-
154
- res.json(users);
155
- });
156
-
157
- this.app.get('/__admin/validate-token', (req, res) => {
158
- const authHeader = req.headers.authorization;
159
- if (!authHeader) {
160
- return res.status(401).json({ error: 'No token provided' });
161
- }
162
-
163
- const token = authHeader.replace('Bearer ', '');
164
- const decoded = this.simulator.verifyAccessToken(token);
165
-
166
- if (!decoded) {
167
- return res.status(401).json({ error: 'Invalid token' });
168
- }
169
-
170
- res.json({ valid: true, payload: decoded });
171
- });
172
-
173
- this.app.post('/__admin/generate-token', (req, res) => {
174
- const { username, userPoolId, clientId } = req.body;
175
-
176
- const userPool = this.simulator.userPools.get(userPoolId);
177
- if (!userPool) {
178
- return res.status(404).json({ error: 'User pool not found' });
179
- }
180
-
181
- const user = this.simulator.findUserByUsername(username, null, userPoolId);
182
- if (!user) {
183
- return res.status(404).json({ error: 'User not found' });
184
- }
185
-
186
- const accessToken = this.simulator.generateAccessToken(user, userPool, clientId);
187
- const idToken = this.simulator.generateIdToken(user, userPool, clientId);
188
-
189
- res.json({
190
- accessToken,
191
- idToken,
192
- expiresIn: 3600
193
- });
194
- });
195
- }
196
-
197
- start() {
198
- return new Promise((resolve) => {
199
- this.server = this.app.listen(this.port, () => {
200
- logger.info(`🔐 Cognito rodando em http://localhost:${this.port}`);
201
- resolve();
202
- });
203
- });
204
- }
205
-
206
- stop() {
207
- return new Promise((resolve) => {
208
- if (this.server) {
209
- this.server.close(() => resolve());
210
- } else {
211
- resolve();
212
- }
213
- });
214
- }
215
-
216
- getStatus() {
217
- return {
218
- running: !!this.server,
219
- port: this.port,
220
- endpoint: `http://localhost:${this.port}`,
221
- userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
222
- usersCount: this.simulator?.getTotalUsersCount() || 0,
223
- identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0,
224
- activeSessions: this.simulator?.getActiveSessionsCount() || 0
225
- };
226
- }
227
- }
228
-
1
+ /**
2
+ * Cognito Server - Servidor HTTP para Cognito API
3
+ */
4
+
5
+ const express = require('express');
6
+ const logger = require('../../utils/logger');
7
+
8
+ class CognitoServer {
9
+ constructor(port, config) {
10
+ this.port = port;
11
+ this.config = config;
12
+ this.app = express();
13
+ this.simulator = null;
14
+ this.server = null;
15
+ this.setupMiddlewares();
16
+ }
17
+
18
+ setupMiddlewares() {
19
+ this.app.use(express.raw({ type: '*/*', limit: '10mb' }));
20
+ this.app.use((req, res, next) => {
21
+ if (req.body && Buffer.isBuffer(req.body)) {
22
+ try {
23
+ req.body = JSON.parse(req.body.toString('utf8'));
24
+ } catch (e) {
25
+ req.body = {};
26
+ }
27
+ } else if (!req.body) {
28
+ req.body = {};
29
+ }
30
+ next();
31
+ });
32
+
33
+ if (logger.currentLogLevel === 'verboso') {
34
+ this.app.use((req, res, next) => {
35
+ const start = Date.now();
36
+ res.on('finish', () => {
37
+ const duration = Date.now() - start;
38
+ logger.verboso(`Cognito: ${req.method} ${req.path} - ${duration}ms`);
39
+ });
40
+ next();
41
+ });
42
+ }
43
+ }
44
+
45
+ async initialize() {
46
+ this.setupRoutes();
47
+ logger.debug('Cognito Server inicializado');
48
+ }
49
+
50
+ setupRoutes() {
51
+ // Health check
52
+ this.app.get('/health', (req, res) => {
53
+ res.json({
54
+ status: 'healthy',
55
+ service: 'cognito-simulator',
56
+ version: '1.0.0'
57
+ });
58
+ });
59
+
60
+ // User Pool operations
61
+ this.app.post('/', async (req, res) => {
62
+ const target = req.headers['x-amz-target'];
63
+ logger.info(`Cognito incoming: target=${target} body=${JSON.stringify(req.body)}`);
64
+ if (!target) {
65
+ return res.status(400).json({ error: 'Missing X-Amz-Target header' });
66
+ }
67
+
68
+ try {
69
+ const result = await this.handleRequest(target, req.body || {});
70
+ res.json(result);
71
+ } catch (error) {
72
+ logger.error('Cognito Error:', error);
73
+ res.status(400).json({
74
+ __type: error.code || 'InternalServerError',
75
+ message: error.message
76
+ });
77
+ }
78
+ });
79
+
80
+ // Admin endpoints
81
+ this.setupAdminRoutes();
82
+ }
83
+
84
+ async handleRequest(target, params) {
85
+ const action = target.split('.')[2] || target.split('.')[1];
86
+
87
+ logger.verboso(`Cognito Action: ${action}`);
88
+
89
+ switch(action) {
90
+ // User Pool Management
91
+ case 'CreateUserPool':
92
+ return this.simulator.createUserPool(params);
93
+ case 'ListUserPools':
94
+ return this.simulator.listUserPools(params);
95
+ case 'DescribeUserPool':
96
+ return this.simulator.describeUserPool(params);
97
+ case 'DeleteUserPool':
98
+ return this.simulator.deleteUserPool(params);
99
+
100
+ case 'ListUsers':
101
+ return this.simulator.listUsers(params);
102
+ // User Pool Client Management
103
+ case 'CreateUserPoolClient':
104
+ return this.simulator.createUserPoolClient(params);
105
+ case 'ListUserPoolClients':
106
+ return this.simulator.listUserPoolClients(params);
107
+ case 'DescribeUserPoolClient':
108
+ return this.simulator.describeUserPoolClient(params);
109
+ case 'DeleteUserPoolClient':
110
+ return this.simulator.deleteUserPoolClient(params);
111
+
112
+ // User Operations
113
+ case 'SignUp':
114
+ return this.simulator.signUp(params);
115
+ case 'ConfirmSignUp':
116
+ return this.simulator.confirmSignUp(params);
117
+ case 'ForgotPassword':
118
+ return this.simulator.forgotPassword(params);
119
+ case 'ConfirmForgotPassword':
120
+ return this.simulator.confirmForgotPassword(params);
121
+ case 'ChangePassword':
122
+ return this.simulator.changePassword(params);
123
+ case 'InitiateAuth':
124
+ return this.simulator.initiateAuth(params);
125
+ case 'RespondToAuthChallenge':
126
+ return this.simulator.respondToAuthChallenge(params);
127
+ case 'GetToken':
128
+ return this.simulator.getToken(params);
129
+ case 'GlobalSignOut':
130
+ return this.simulator.globalSignOut(params);
131
+ case 'RevokeToken':
132
+ return this.simulator.revokeToken(params);
133
+ case 'GetUser':
134
+ return this.simulator.getUser(params);
135
+ case 'UpdateUserAttributes':
136
+ return this.simulator.updateUserAttributes(params);
137
+ case 'DeleteUser':
138
+ return this.simulator.deleteUser(params);
139
+
140
+ // Admin Operations
141
+ case 'AdminGetUser':
142
+ return this.simulator.adminGetUser(params);
143
+ case 'AdminCreateUser':
144
+ return this.simulator.adminCreateUser(params);
145
+ case 'AdminSetUserPassword':
146
+ return this.simulator.adminSetUserPassword(params);
147
+ case 'AdminDeleteUser':
148
+ return this.simulator.adminDeleteUser(params);
149
+ case 'AdminDisableUser':
150
+ return this.simulator.adminDisableUser(params);
151
+ case 'AdminEnableUser':
152
+ return this.simulator.adminEnableUser(params);
153
+ case 'AdminResetUserPassword':
154
+ return this.simulator.adminResetUserPassword(params);
155
+ case 'AdminInitiateAuth':
156
+ return this.simulator.initiateAuth(params);
157
+ case 'AdminListGroupsForUser':
158
+ return this.simulator.adminListGroupsForUser(params);
159
+ case 'AdminUserGlobalSignOut':
160
+ return this.simulator.adminUserGlobalSignOut(params);
161
+
162
+ // Identity Pool Operations
163
+ case 'CreateIdentityPool':
164
+ return this.simulator.createIdentityPool(params);
165
+ case 'GetId':
166
+ return this.simulator.getId(params);
167
+ case 'GetCredentialsForIdentity':
168
+ return this.simulator.getCredentialsForIdentity(params);
169
+
170
+ default:
171
+ throw new Error(`Unsupported action: ${action}`);
172
+ }
173
+ }
174
+
175
+ setupAdminRoutes() {
176
+ this.app.get('/__admin/userpools', (req, res) => {
177
+ res.json({
178
+ userPools: this.simulator.getUserPoolsCount(),
179
+ users: this.simulator.getTotalUsersCount(),
180
+ identityPools: this.simulator.getIdentityPoolsCount(),
181
+ activeSessions: this.simulator.getActiveSessionsCount()
182
+ });
183
+ });
184
+
185
+ this.app.get('/__admin/userpools/:poolId/users', (req, res) => {
186
+ const pool = this.simulator.userPools.get(req.params.poolId);
187
+ if (!pool) {
188
+ return res.status(404).json({ error: 'User pool not found' });
189
+ }
190
+
191
+ const users = [];
192
+ for (const userId of pool.Users) {
193
+ const user = this.simulator.users.get(userId);
194
+ if (user) {
195
+ users.push({
196
+ username: user.Username,
197
+ userId: user.UserId,
198
+ status: user.UserStatus,
199
+ attributes: user.Attributes,
200
+ created: user.CreatedDate
201
+ });
202
+ }
203
+ }
204
+
205
+ res.json(users);
206
+ });
207
+
208
+ this.app.get('/__admin/validate-token', (req, res) => {
209
+ const authHeader = req.headers.authorization;
210
+ if (!authHeader) {
211
+ return res.status(401).json({ error: 'No token provided' });
212
+ }
213
+
214
+ const token = authHeader.replace('Bearer ', '');
215
+ const decoded = this.simulator.verifyAccessToken(token);
216
+
217
+ if (!decoded) {
218
+ return res.status(401).json({ error: 'Invalid token' });
219
+ }
220
+
221
+ res.json({ valid: true, payload: decoded });
222
+ });
223
+
224
+ this.app.post('/__admin/generate-token', (req, res) => {
225
+ const { username, userPoolId, clientId } = req.body;
226
+
227
+ const userPool = this.simulator.userPools.get(userPoolId);
228
+ if (!userPool) {
229
+ return res.status(404).json({ error: 'User pool not found' });
230
+ }
231
+
232
+ const user = this.simulator.findUserByUsername(username, null, userPoolId);
233
+ if (!user) {
234
+ return res.status(404).json({ error: 'User not found' });
235
+ }
236
+
237
+ const accessToken = this.simulator.generateAccessToken(user, userPool, clientId);
238
+ const idToken = this.simulator.generateIdToken(user, userPool, clientId);
239
+
240
+ res.json({
241
+ accessToken,
242
+ idToken,
243
+ expiresIn: 3600
244
+ });
245
+ });
246
+ }
247
+
248
+ start() {
249
+ return new Promise((resolve) => {
250
+ this.server = this.app.listen(this.port, () => {
251
+ logger.info(`🔐 Cognito rodando em http://localhost:${this.port}`);
252
+ resolve();
253
+ });
254
+ });
255
+ }
256
+
257
+ stop() {
258
+ return new Promise((resolve) => {
259
+ if (this.server) {
260
+ this.server.close(() => resolve());
261
+ } else {
262
+ resolve();
263
+ }
264
+ });
265
+ }
266
+
267
+ getStatus() {
268
+ return {
269
+ running: !!this.server,
270
+ port: this.port,
271
+ endpoint: `http://localhost:${this.port}`,
272
+ userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
273
+ usersCount: this.simulator?.getTotalUsersCount() || 0,
274
+ identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0,
275
+ activeSessions: this.simulator?.getActiveSessionsCount() || 0
276
+ };
277
+ }
278
+ }
279
+
229
280
  module.exports = CognitoServer;