@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,113 +1,115 @@
1
- /**
2
- * Carrega configurações do usuário
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const defaultConfig = require('./default-config');
8
- const EnvLoader = require('./env-loader');
9
- const logger = require('../utils/logger');
10
-
11
- class ConfigLoader {
12
- static async load(configPath) {
13
- logger.info('📝 Carregando configurações...');
14
-
15
- // 1. Carrega configurações padrão
16
- let config = { ...defaultConfig };
17
-
18
- // 2. Sobrescreve com variáveis de ambiente
19
- const envConfig = EnvLoader.load();
20
- config = this.mergeDeep(config, envConfig);
21
-
22
- // 3. Sobrescreve com arquivo de configuração do usuário se existir
23
- if (configPath) {
24
- const userConfig = await this.loadUserConfig(configPath);
25
- config = this.mergeDeep(config, userConfig);
26
- } else {
27
- // Tenta encontrar arquivo de configuração padrão
28
- const possiblePaths = [
29
- path.join(process.cwd(), 'aws-local-simulator.json'),
30
- path.join(process.cwd(), 'aws-local-simulator.config.json'),
31
- path.join(process.cwd(), '.aws-local-simulator.json')
32
- ];
33
-
34
- for (const possiblePath of possiblePaths) {
35
- if (fs.existsSync(possiblePath)) {
36
- const userConfig = await this.loadUserConfig(possiblePath);
37
- config = this.mergeDeep(config, userConfig);
38
- logger.info(`✅ Configuração carregada de: ${possiblePath}`);
39
- break;
40
- }
41
- }
42
- }
43
-
44
- // 4. Valida configurações
45
- this.validate(config);
46
-
47
- logger.info(`✅ Configurações carregadas (logLevel: ${config.logLevel})`);
48
-
49
- return config;
50
- }
51
-
52
- static async loadUserConfig(filePath) {
53
- try {
54
- const fullPath = path.resolve(process.cwd(), filePath);
55
-
56
- if (!fs.existsSync(fullPath)) {
57
- logger.warn(`Arquivo de configuração não encontrado: ${fullPath}`);
58
- return {};
59
- }
60
-
61
- const content = fs.readFileSync(fullPath, 'utf8');
62
- const config = JSON.parse(content);
63
-
64
- return config;
65
- } catch (error) {
66
- logger.error(`Erro ao carregar configuração de ${filePath}:`, error);
67
- throw error;
68
- }
69
- }
70
-
71
- static validate(config) {
72
- // Valida serviços
73
- const enabledServices = Object.entries(config.services)
74
- .filter(([_, enabled]) => enabled)
75
- .map(([name]) => name);
76
-
77
- if (enabledServices.length === 0) {
78
- logger.warn('⚠️ Nenhum serviço está habilitado!');
79
- } else {
80
- logger.info(`📦 Serviços habilitados: ${enabledServices.join(', ')}`);
81
- }
82
-
83
- // Valida diretório de dados
84
- if (!config.dataDir) {
85
- throw new Error('dataDir não configurado');
86
- }
87
-
88
- // Valida portas
89
- for (const [service, port] of Object.entries(config.ports)) {
90
- if (config.services[service] && (port < 1 || port > 65535)) {
91
- throw new Error(`Porta inválida para ${service}: ${port}`);
92
- }
93
- }
94
- }
95
-
96
- static mergeDeep(target, source) {
97
- const output = { ...target };
98
-
99
- for (const key in source) {
100
- if (source.hasOwnProperty(key)) {
101
- if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
102
- output[key] = this.mergeDeep(target[key] || {}, source[key]);
103
- } else {
104
- output[key] = source[key];
105
- }
106
- }
107
- }
108
-
109
- return output;
110
- }
111
- }
112
-
1
+ /**
2
+ * Carrega configurações do usuário
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const defaultConfig = require('./default-config');
8
+ const EnvLoader = require('./env-loader');
9
+ const logger = require('../utils/logger');
10
+
11
+ class ConfigLoader {
12
+ static async load(configPath) {
13
+ logger.info('📝 Carregando configurações...');
14
+
15
+ // 1. Carrega configurações padrão
16
+ let config = { ...defaultConfig };
17
+
18
+ // 2. Sobrescreve com variáveis de ambiente
19
+ const envConfig = EnvLoader.load();
20
+ config = this.mergeDeep(config, envConfig);
21
+
22
+ // 3. Sobrescreve com arquivo de configuração do usuário se existir
23
+ if (configPath) {
24
+ const userConfig = await this.loadUserConfig(configPath);
25
+ config = this.mergeDeep(config, userConfig);
26
+ config._configPath = path.resolve(process.cwd(), configPath);
27
+ } else {
28
+ // Tenta encontrar arquivo de configuração padrão
29
+ const possiblePaths = [
30
+ path.join(process.cwd(), 'aws-local-simulator.json'),
31
+ path.join(process.cwd(), 'aws-local-simulator.config.json'),
32
+ path.join(process.cwd(), '.aws-local-simulator.json')
33
+ ];
34
+
35
+ for (const possiblePath of possiblePaths) {
36
+ if (fs.existsSync(possiblePath)) {
37
+ const userConfig = await this.loadUserConfig(possiblePath);
38
+ config = this.mergeDeep(config, userConfig);
39
+ config._configPath = possiblePath;
40
+ logger.info(`✅ Configuração carregada de: ${possiblePath}`);
41
+ break;
42
+ }
43
+ }
44
+ }
45
+
46
+ // 4. Valida configurações
47
+ this.validate(config);
48
+
49
+ logger.info(`✅ Configurações carregadas (logLevel: ${config.logLevel})`);
50
+
51
+ return config;
52
+ }
53
+
54
+ static async loadUserConfig(filePath) {
55
+ try {
56
+ const fullPath = path.resolve(process.cwd(), filePath);
57
+
58
+ if (!fs.existsSync(fullPath)) {
59
+ logger.warn(`Arquivo de configuração não encontrado: ${fullPath}`);
60
+ return {};
61
+ }
62
+
63
+ const content = fs.readFileSync(fullPath, 'utf8');
64
+ const config = JSON.parse(content);
65
+
66
+ return config;
67
+ } catch (error) {
68
+ logger.error(`Erro ao carregar configuração de ${filePath}:`, error);
69
+ throw error;
70
+ }
71
+ }
72
+
73
+ static validate(config) {
74
+ // Valida serviços
75
+ const enabledServices = Object.entries(config.services)
76
+ .filter(([_, enabled]) => enabled)
77
+ .map(([name]) => name);
78
+
79
+ if (enabledServices.length === 0) {
80
+ logger.warn('⚠️ Nenhum serviço está habilitado!');
81
+ } else {
82
+ logger.info(`📦 Serviços habilitados: ${enabledServices.join(', ')}`);
83
+ }
84
+
85
+ // Valida diretório de dados
86
+ if (!config.dataDir) {
87
+ throw new Error('dataDir não configurado');
88
+ }
89
+
90
+ // Valida portas
91
+ for (const [service, port] of Object.entries(config.ports)) {
92
+ if (config.services[service] && (port < 1 || port > 65535)) {
93
+ throw new Error(`Porta inválida para ${service}: ${port}`);
94
+ }
95
+ }
96
+ }
97
+
98
+ static mergeDeep(target, source) {
99
+ const output = { ...target };
100
+
101
+ for (const key in source) {
102
+ if (source.hasOwnProperty(key)) {
103
+ if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
104
+ output[key] = this.mergeDeep(target[key] || {}, source[key]);
105
+ } else {
106
+ output[key] = source[key];
107
+ }
108
+ }
109
+ }
110
+
111
+ return output;
112
+ }
113
+ }
114
+
113
115
  module.exports = { loadConfig: ConfigLoader.load.bind(ConfigLoader) };
@@ -1,65 +1,67 @@
1
- /**
2
- * Configurações padrão do simulador
3
- */
4
-
5
- module.exports = {
6
- // Serviços habilitados por padrão
7
- services: {
8
- dynamodb: true,
9
- s3: true,
10
- sqs: true,
11
- lambda: true,
12
- sns: false,
13
- eventbridge: false,
14
- ecs: false,
15
- cognito: false,
16
- apigateway: false,
17
- },
18
-
19
- // Portas padrão
20
- ports: {
21
- dynamodb: 8000,
22
- s3: 4566,
23
- sqs: 9324,
24
- lambda: 3001,
25
- sns: 9911,
26
- eventbridge: 4010,
27
- ecs: 8080,
28
- cognito: 9229,
29
- apigateway: 4567,
30
- },
31
- apigateway: {
32
- defaultCors: {
33
- allowOrigins: ["*"],
34
- allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
35
- allowHeaders: ["*"],
36
- maxAge: 300,
37
- },
38
- defaultThrottling: {
39
- burstLimit: 100,
40
- rateLimit: 10,
41
- },
42
- enableAccessLogging: true,
43
- autoDeploy: true,
44
- },
45
- // Configurações de persistência
46
- dataDir: "./.aws-local-simulator-data",
47
-
48
- // Configurações de logging
49
- logLevel: "info", // silent, info, debug, verboso
50
-
51
- // Configurações das Lambdas
52
- lambdas: [], // Será preenchido pelo usuário
53
-
54
- // Configurações de CORS
55
- cors: true,
56
-
57
- // Auto-criação de tabelas DynamoDB
58
- autoCreateTables: true,
59
-
60
- // Auto-criação de buckets S3
61
- autoCreateBuckets: true,
62
-
63
- // Configurações adicionais
64
- additional: {},
65
- };
1
+ /**
2
+ * Configurações padrão do simulador
3
+ */
4
+
5
+ module.exports = {
6
+ // Serviços habilitados por padrão
7
+ services: {
8
+ dynamodb: true,
9
+ s3: true,
10
+ sqs: true,
11
+ lambda: true,
12
+ sns: false,
13
+ eventbridge: false,
14
+ ecs: false,
15
+ cognito: false,
16
+ apigateway: false,
17
+ sts: true,
18
+ },
19
+
20
+ // Portas padrão
21
+ ports: {
22
+ dynamodb: 8000,
23
+ s3: 4566,
24
+ sqs: 9324,
25
+ lambda: 3001,
26
+ sns: 9911,
27
+ eventbridge: 4010,
28
+ ecs: 8080,
29
+ cognito: 9229,
30
+ apigateway: 4567,
31
+ sts: 9326,
32
+ },
33
+ apigateway: {
34
+ defaultCors: {
35
+ allowOrigins: ["*"],
36
+ allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
37
+ allowHeaders: ["*"],
38
+ maxAge: 300,
39
+ },
40
+ defaultThrottling: {
41
+ burstLimit: 100,
42
+ rateLimit: 10,
43
+ },
44
+ enableAccessLogging: true,
45
+ autoDeploy: true,
46
+ },
47
+ // Configurações de persistência
48
+ dataDir: "./.aws-local-simulator-data",
49
+
50
+ // Configurações de logging
51
+ logLevel: "info", // silent, info, debug, verboso
52
+
53
+ // Configurações das Lambdas
54
+ lambdas: [], // Será preenchido pelo usuário
55
+
56
+ // Configurações de CORS
57
+ cors: true,
58
+
59
+ // Auto-criação de tabelas DynamoDB
60
+ autoCreateTables: true,
61
+
62
+ // Auto-criação de buckets S3
63
+ autoCreateBuckets: true,
64
+
65
+ // Configurações adicionais
66
+ additional: {},
67
+ };
@@ -1,69 +1,69 @@
1
- /**
2
- * Carrega configurações de variáveis de ambiente
3
- */
4
-
5
- const logger = require('../utils/logger');
6
-
7
- class EnvLoader {
8
- static load() {
9
- const config = {};
10
-
11
- // Carrega configuração de serviços
12
- config.services = {
13
- dynamodb: this.getEnvBool('AWS_LOCAL_SIMULATOR_DYNAMODB', true),
14
- s3: this.getEnvBool('AWS_LOCAL_SIMULATOR_S3', true),
15
- sqs: this.getEnvBool('AWS_LOCAL_SIMULATOR_SQS', true),
16
- sns: this.getEnvBool('AWS_LOCAL_SIMULATOR_SNS', false),
17
- lambda: this.getEnvBool('AWS_LOCAL_SIMULATOR_LAMBDA', true),
18
- apigateway: this.getEnvBool('AWS_LOCAL_SIMULATOR_APIGATEWAY', false),
19
- eventbridge: this.getEnvBool('AWS_LOCAL_SIMULATOR_EVENTBRIDGE', false)
20
- };
21
-
22
- // Carrega portas
23
- config.ports = {
24
- dynamodb: this.getEnvInt('AWS_LOCAL_SIMULATOR_DYNAMODB_PORT', 8000),
25
- s3: this.getEnvInt('AWS_LOCAL_SIMULATOR_S3_PORT', 4566),
26
- sqs: this.getEnvInt('AWS_LOCAL_SIMULATOR_SQS_PORT', 9324),
27
- lambda: this.getEnvInt('AWS_LOCAL_SIMULATOR_LAMBDA_PORT', 3001),
28
- sns: this.getEnvInt('AWS_LOCAL_SIMULATOR_SNS_PORT', 9911),
29
- apigateway: this.getEnvInt('AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT', 4567),
30
- eventbridge: this.getEnvInt('AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT', 4010)
31
- };
32
-
33
- // Carrega diretório de dados
34
- config.dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA || './.aws-local-simulator-data';
35
-
36
- // Carrega nível de log
37
- config.logLevel = process.env.AWS_LOCAL_SIMULATOR_LOG || 'info';
38
-
39
- // Carrega CORS
40
- config.cors = this.getEnvBool('AWS_LOCAL_SIMULATOR_CORS', true);
41
-
42
- // Carrega auto-create
43
- config.autoCreateTables = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_TABLES', true);
44
- config.autoCreateBuckets = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_BUCKETS', true);
45
-
46
- logger.debug('Variáveis de ambiente carregadas:', config);
47
-
48
- return config;
49
- }
50
-
51
- static getEnvBool(key, defaultValue) {
52
- const value = process.env[key];
53
- if (value === undefined) return defaultValue;
54
- return value === 'true' || value === '1' || value === 'yes';
55
- }
56
-
57
- static getEnvInt(key, defaultValue) {
58
- const value = process.env[key];
59
- if (value === undefined) return defaultValue;
60
- const parsed = parseInt(value, 10);
61
- return isNaN(parsed) ? defaultValue : parsed;
62
- }
63
-
64
- static getEnvString(key, defaultValue) {
65
- return process.env[key] || defaultValue;
66
- }
67
- }
68
-
1
+ /**
2
+ * Carrega configurações de variáveis de ambiente
3
+ */
4
+
5
+ const logger = require('../utils/logger');
6
+
7
+ class EnvLoader {
8
+ static load() {
9
+ const config = {};
10
+
11
+ // Carrega configuração de serviços
12
+ config.services = {
13
+ dynamodb: this.getEnvBool('AWS_LOCAL_SIMULATOR_DYNAMODB', true),
14
+ s3: this.getEnvBool('AWS_LOCAL_SIMULATOR_S3', true),
15
+ sqs: this.getEnvBool('AWS_LOCAL_SIMULATOR_SQS', true),
16
+ sns: this.getEnvBool('AWS_LOCAL_SIMULATOR_SNS', false),
17
+ lambda: this.getEnvBool('AWS_LOCAL_SIMULATOR_LAMBDA', true),
18
+ apigateway: this.getEnvBool('AWS_LOCAL_SIMULATOR_APIGATEWAY', false),
19
+ eventbridge: this.getEnvBool('AWS_LOCAL_SIMULATOR_EVENTBRIDGE', false)
20
+ };
21
+
22
+ // Carrega portas
23
+ config.ports = {
24
+ dynamodb: this.getEnvInt('AWS_LOCAL_SIMULATOR_DYNAMODB_PORT', 8000),
25
+ s3: this.getEnvInt('AWS_LOCAL_SIMULATOR_S3_PORT', 4566),
26
+ sqs: this.getEnvInt('AWS_LOCAL_SIMULATOR_SQS_PORT', 9324),
27
+ lambda: this.getEnvInt('AWS_LOCAL_SIMULATOR_LAMBDA_PORT', 3001),
28
+ sns: this.getEnvInt('AWS_LOCAL_SIMULATOR_SNS_PORT', 9911),
29
+ apigateway: this.getEnvInt('AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT', 4567),
30
+ eventbridge: this.getEnvInt('AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT', 4010)
31
+ };
32
+
33
+ // Carrega diretório de dados
34
+ config.dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA || './.aws-local-simulator-data';
35
+
36
+ // Carrega nível de log
37
+ config.logLevel = process.env.AWS_LOCAL_SIMULATOR_LOG || 'info';
38
+
39
+ // Carrega CORS
40
+ config.cors = this.getEnvBool('AWS_LOCAL_SIMULATOR_CORS', true);
41
+
42
+ // Carrega auto-create
43
+ config.autoCreateTables = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_TABLES', true);
44
+ config.autoCreateBuckets = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_BUCKETS', true);
45
+
46
+ logger.debug('Variáveis de ambiente carregadas:', config);
47
+
48
+ return config;
49
+ }
50
+
51
+ static getEnvBool(key, defaultValue) {
52
+ const value = process.env[key];
53
+ if (value === undefined) return defaultValue;
54
+ return value === 'true' || value === '1' || value === 'yes';
55
+ }
56
+
57
+ static getEnvInt(key, defaultValue) {
58
+ const value = process.env[key];
59
+ if (value === undefined) return defaultValue;
60
+ const parsed = parseInt(value, 10);
61
+ return isNaN(parsed) ? defaultValue : parsed;
62
+ }
63
+
64
+ static getEnvString(key, defaultValue) {
65
+ return process.env[key] || defaultValue;
66
+ }
67
+ }
68
+
69
69
  module.exports = EnvLoader;