@gugananuvem/aws-local-simulator 1.0.33 → 1.0.34

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 (79) hide show
  1. package/README.md +834 -834
  2. package/aws-config +153 -153
  3. package/bin/aws-local-simulator.js +63 -63
  4. package/package.json +3 -2
  5. package/src/config/config-loader.js +114 -114
  6. package/src/config/default-config.js +79 -79
  7. package/src/config/env-loader.js +68 -68
  8. package/src/index.js +146 -146
  9. package/src/index.mjs +123 -123
  10. package/src/server.js +463 -463
  11. package/src/services/apigateway/index.js +75 -75
  12. package/src/services/apigateway/server.js +607 -607
  13. package/src/services/apigateway/simulator.js +1405 -1405
  14. package/src/services/athena/index.js +75 -75
  15. package/src/services/athena/server.js +101 -101
  16. package/src/services/athena/simulador.js +998 -998
  17. package/src/services/athena/simulator.js +346 -346
  18. package/src/services/cloudformation/index.js +106 -106
  19. package/src/services/cloudformation/server.js +417 -417
  20. package/src/services/cloudformation/simulador.js +1020 -1020
  21. package/src/services/cloudtrail/index.js +84 -84
  22. package/src/services/cloudtrail/server.js +235 -235
  23. package/src/services/cloudtrail/simulador.js +719 -719
  24. package/src/services/cloudwatch/index.js +84 -84
  25. package/src/services/cloudwatch/server.js +366 -366
  26. package/src/services/cloudwatch/simulador.js +1173 -1173
  27. package/src/services/cognito/index.js +79 -79
  28. package/src/services/cognito/server.js +297 -297
  29. package/src/services/cognito/simulator.js +1992 -1761
  30. package/src/services/config/index.js +96 -96
  31. package/src/services/config/server.js +215 -215
  32. package/src/services/config/simulador.js +1260 -1260
  33. package/src/services/dynamodb/index.js +74 -74
  34. package/src/services/dynamodb/server.js +139 -139
  35. package/src/services/dynamodb/simulator.js +1005 -994
  36. package/src/services/dynamodb/sqlite-store.js +722 -0
  37. package/src/services/ecs/index.js +65 -65
  38. package/src/services/ecs/server.js +235 -235
  39. package/src/services/ecs/simulator.js +844 -844
  40. package/src/services/eventbridge/index.js +89 -89
  41. package/src/services/eventbridge/server.js +209 -209
  42. package/src/services/eventbridge/simulator.js +684 -684
  43. package/src/services/index.js +45 -45
  44. package/src/services/kms/index.js +75 -75
  45. package/src/services/kms/server.js +81 -81
  46. package/src/services/kms/simulator.js +344 -344
  47. package/src/services/lambda/handler-loader.js +183 -183
  48. package/src/services/lambda/index.js +81 -81
  49. package/src/services/lambda/route-registry.js +274 -274
  50. package/src/services/lambda/server.js +191 -191
  51. package/src/services/lambda/simulator.js +364 -364
  52. package/src/services/parameter-store/index.js +80 -80
  53. package/src/services/parameter-store/server.js +50 -50
  54. package/src/services/parameter-store/simulator.js +201 -201
  55. package/src/services/s3/index.js +73 -73
  56. package/src/services/s3/server.js +350 -350
  57. package/src/services/s3/simulator.js +568 -568
  58. package/src/services/secret-manager/index.js +80 -80
  59. package/src/services/secret-manager/server.js +51 -51
  60. package/src/services/secret-manager/simulator.js +182 -182
  61. package/src/services/sns/index.js +89 -89
  62. package/src/services/sns/server.js +607 -607
  63. package/src/services/sns/simulator.js +1482 -1482
  64. package/src/services/sqs/index.js +98 -98
  65. package/src/services/sqs/server.js +360 -360
  66. package/src/services/sqs/simulator.js +509 -509
  67. package/src/services/sts/index.js +37 -37
  68. package/src/services/sts/server.js +144 -144
  69. package/src/services/sts/simulator.js +69 -69
  70. package/src/services/xray/index.js +83 -83
  71. package/src/services/xray/server.js +308 -308
  72. package/src/services/xray/simulador.js +994 -994
  73. package/src/template/aws-config-template.js +87 -87
  74. package/src/template/aws-config-template.mjs +90 -90
  75. package/src/template/config-template.json +203 -203
  76. package/src/utils/aws-config.js +91 -91
  77. package/src/utils/cloudtrail-audit.js +129 -129
  78. package/src/utils/local-store.js +83 -83
  79. package/src/utils/logger.js +59 -59
@@ -1,115 +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
- 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
-
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
+
115
115
  module.exports = { loadConfig: ConfigLoader.load.bind(ConfigLoader) };
@@ -1,79 +1,79 @@
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: true,
13
- eventbridge: true,
14
- ecs: false,
15
- cognito: true,
16
- apigateway: true,
17
- sts: true,
18
- "secret-manager": true,
19
- "parameter-store": true,
20
- kms: true,
21
- kinesis: true,
22
- },
23
-
24
- // Portas padrão
25
- ports: {
26
- dynamodb: 8000,
27
- s3: 4566,
28
- sqs: 9324,
29
- lambda: 3001,
30
- sns: 9911,
31
- eventbridge: 4010,
32
- ecs: 8080,
33
- cognito: 9229,
34
- apigateway: 4567,
35
- sts: 9326,
36
- athena: 4599,
37
- secretManager: 4001,
38
- parameterStore: 4002,
39
- kms: 4000,
40
- kinesis: 4568,
41
- },
42
- apigateway: {
43
- defaultCors: {
44
- allowOrigins: ["*"],
45
- allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
46
- allowHeaders: ["*"],
47
- maxAge: 300,
48
- },
49
- defaultThrottling: {
50
- burstLimit: 100,
51
- rateLimit: 10,
52
- },
53
- enableAccessLogging: true,
54
- autoDeploy: true,
55
- },
56
- // Configurações de persistência
57
- dataDir: "./.aws-local-simulator-data",
58
-
59
- // Configurações de logging
60
- logLevel: "info", // silent, info, debug, verboso
61
-
62
- // Configurações das Lambdas
63
- lambdas: [], // Será preenchido pelo usuário
64
-
65
- // Configurações de CORS
66
- cors: true,
67
-
68
- // Auto-criação de tabelas DynamoDB
69
- autoCreateTables: true,
70
-
71
- // Auto-criação de buckets S3
72
- autoCreateBuckets: true,
73
-
74
- // Configurações adicionais
75
- additional: {},
76
-
77
- // Porta do servidor de administração (Management API)
78
- adminPort: 9999,
79
- };
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: true,
13
+ eventbridge: true,
14
+ ecs: false,
15
+ cognito: true,
16
+ apigateway: true,
17
+ sts: true,
18
+ "secret-manager": true,
19
+ "parameter-store": true,
20
+ kms: true,
21
+ kinesis: true,
22
+ },
23
+
24
+ // Portas padrão
25
+ ports: {
26
+ dynamodb: 8000,
27
+ s3: 4566,
28
+ sqs: 9324,
29
+ lambda: 3001,
30
+ sns: 9911,
31
+ eventbridge: 4010,
32
+ ecs: 8080,
33
+ cognito: 9229,
34
+ apigateway: 4567,
35
+ sts: 9326,
36
+ athena: 4599,
37
+ secretManager: 4001,
38
+ parameterStore: 4002,
39
+ kms: 4000,
40
+ kinesis: 4568,
41
+ },
42
+ apigateway: {
43
+ defaultCors: {
44
+ allowOrigins: ["*"],
45
+ allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
46
+ allowHeaders: ["*"],
47
+ maxAge: 300,
48
+ },
49
+ defaultThrottling: {
50
+ burstLimit: 100,
51
+ rateLimit: 10,
52
+ },
53
+ enableAccessLogging: true,
54
+ autoDeploy: true,
55
+ },
56
+ // Configurações de persistência
57
+ dataDir: "./.aws-local-simulator-data",
58
+
59
+ // Configurações de logging
60
+ logLevel: "info", // silent, info, debug, verboso
61
+
62
+ // Configurações das Lambdas
63
+ lambdas: [], // Será preenchido pelo usuário
64
+
65
+ // Configurações de CORS
66
+ cors: true,
67
+
68
+ // Auto-criação de tabelas DynamoDB
69
+ autoCreateTables: true,
70
+
71
+ // Auto-criação de buckets S3
72
+ autoCreateBuckets: true,
73
+
74
+ // Configurações adicionais
75
+ additional: {},
76
+
77
+ // Porta do servidor de administração (Management API)
78
+ adminPort: 9999,
79
+ };
@@ -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;