@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,113 +1,113 @@
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
+ } 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
+
113
113
  module.exports = { loadConfig: ConfigLoader.load.bind(ConfigLoader) };
@@ -1,65 +1,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, // Desabilitado por padrão
13
- eventbridge: false, // Desabilitado por padrão
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
+ },
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,67 +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
- lambda: this.getEnvBool('AWS_LOCAL_SIMULATOR_LAMBDA', true),
17
- sns: this.getEnvBool('AWS_LOCAL_SIMULATOR_SNS', false),
18
- eventbridge: this.getEnvBool('AWS_LOCAL_SIMULATOR_EVENTBRIDGE', false)
19
- };
20
-
21
- // Carrega portas
22
- config.ports = {
23
- dynamodb: this.getEnvInt('AWS_LOCAL_SIMULATOR_DYNAMODB_PORT', 8000),
24
- s3: this.getEnvInt('AWS_LOCAL_SIMULATOR_S3_PORT', 4566),
25
- sqs: this.getEnvInt('AWS_LOCAL_SIMULATOR_SQS_PORT', 9324),
26
- lambda: this.getEnvInt('AWS_LOCAL_SIMULATOR_LAMBDA_PORT', 3001),
27
- sns: this.getEnvInt('AWS_LOCAL_SIMULATOR_SNS_PORT', 9911),
28
- eventbridge: this.getEnvInt('AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT', 4010)
29
- };
30
-
31
- // Carrega diretório de dados
32
- config.dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA || './.aws-local-simulator-data';
33
-
34
- // Carrega nível de log
35
- config.logLevel = process.env.AWS_LOCAL_SIMULATOR_LOG || 'info';
36
-
37
- // Carrega CORS
38
- config.cors = this.getEnvBool('AWS_LOCAL_SIMULATOR_CORS', true);
39
-
40
- // Carrega auto-create
41
- config.autoCreateTables = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_TABLES', true);
42
- config.autoCreateBuckets = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_BUCKETS', true);
43
-
44
- logger.debug('Variáveis de ambiente carregadas:', config);
45
-
46
- return config;
47
- }
48
-
49
- static getEnvBool(key, defaultValue) {
50
- const value = process.env[key];
51
- if (value === undefined) return defaultValue;
52
- return value === 'true' || value === '1' || value === 'yes';
53
- }
54
-
55
- static getEnvInt(key, defaultValue) {
56
- const value = process.env[key];
57
- if (value === undefined) return defaultValue;
58
- const parsed = parseInt(value, 10);
59
- return isNaN(parsed) ? defaultValue : parsed;
60
- }
61
-
62
- static getEnvString(key, defaultValue) {
63
- return process.env[key] || defaultValue;
64
- }
65
- }
66
-
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
+
67
69
  module.exports = EnvLoader;