@gugananuvem/aws-local-simulator 1.0.8 → 1.0.10
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.
- package/README.md +2 -1
- package/bin/aws-local-simulator.js +62 -1
- package/package.json +10 -7
- package/src/config/config-loader.js +113 -0
- package/src/config/default-config.js +65 -0
- package/src/config/env-loader.js +69 -0
- package/src/index.js +131 -1
- package/src/index.mjs +124 -0
- package/src/server.js +222 -0
- package/src/services/apigateway/index.js +67 -0
- package/src/services/apigateway/server.js +435 -0
- package/src/services/apigateway/simulator.js +1252 -0
- package/src/services/cognito/index.js +66 -0
- package/src/services/cognito/server.js +229 -0
- package/src/services/cognito/simulator.js +848 -0
- package/src/services/dynamodb/index.js +71 -0
- package/src/services/dynamodb/server.js +122 -0
- package/src/services/dynamodb/simulator.js +614 -0
- package/src/services/ecs/index.js +66 -0
- package/src/services/ecs/server.js +234 -0
- package/src/services/ecs/simulator.js +845 -0
- package/src/services/eventbridge/index.js +85 -0
- package/src/services/index.js +19 -0
- package/src/services/lambda/handler-loader.js +173 -0
- package/src/services/lambda/index.js +73 -0
- package/src/services/lambda/route-registry.js +275 -0
- package/src/services/lambda/server.js +153 -0
- package/src/services/lambda/simulator.js +285 -0
- package/src/services/s3/index.js +70 -0
- package/src/services/s3/server.js +239 -0
- package/src/services/s3/simulator.js +740 -0
- package/src/services/sns/index.js +76 -0
- package/src/services/sqs/index.js +96 -0
- package/src/services/sqs/server.js +274 -0
- package/src/services/sqs/simulator.js +660 -0
- package/src/template/aws-config-template.js +88 -0
- package/src/template/aws-config-template.mjs +91 -0
- package/src/template/config-template.json +203 -0
- package/src/utils/aws-config.js +92 -0
- package/src/utils/local-store.js +68 -0
- package/src/utils/logger.js +60 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS SDK v3 Configuration for Local Development
|
|
3
|
+
* Gerado pelo AWS Local Simulator
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
|
|
7
|
+
const { DynamoDBDocumentClient } = require('@aws-sdk/lib-dynamodb');
|
|
8
|
+
const { S3Client } = require('@aws-sdk/client-s3');
|
|
9
|
+
const { SQSClient } = require('@aws-sdk/client-sqs');
|
|
10
|
+
const { SNSClient } = require('@aws-sdk/client-sns');
|
|
11
|
+
const { EventBridgeClient } = require('@aws-sdk/client-eventbridge');
|
|
12
|
+
|
|
13
|
+
// Configurações de ambiente
|
|
14
|
+
const isLocal = process.env.IS_LOCAL === 'true' || process.env.NODE_ENV === 'development';
|
|
15
|
+
|
|
16
|
+
// Endpoints locais (configuráveis via variáveis de ambiente)
|
|
17
|
+
const endpoints = {
|
|
18
|
+
dynamodb: process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
|
|
19
|
+
s3: process.env.S3_ENDPOINT || 'http://localhost:4566',
|
|
20
|
+
sqs: process.env.SQS_ENDPOINT || 'http://localhost:9324',
|
|
21
|
+
sns: process.env.SNS_ENDPOINT || 'http://localhost:9911',
|
|
22
|
+
eventbridge: process.env.EVENTBRIDGE_ENDPOINT || 'http://localhost:4010'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Credenciais locais
|
|
26
|
+
const localCredentials = {
|
|
27
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
|
|
28
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const baseConfig = {
|
|
32
|
+
region: process.env.AWS_REGION || 'us-east-1',
|
|
33
|
+
credentials: isLocal ? localCredentials : undefined
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// DynamoDB Client
|
|
37
|
+
const dynamoDBClient = new DynamoDBClient({
|
|
38
|
+
...baseConfig,
|
|
39
|
+
endpoint: isLocal ? endpoints.dynamodb : undefined
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const dynamoDB = DynamoDBDocumentClient.from(dynamoDBClient);
|
|
43
|
+
|
|
44
|
+
// S3 Client
|
|
45
|
+
const s3 = new S3Client({
|
|
46
|
+
...baseConfig,
|
|
47
|
+
endpoint: isLocal ? endpoints.s3 : undefined,
|
|
48
|
+
forcePathStyle: isLocal
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// SQS Client
|
|
52
|
+
const sqs = new SQSClient({
|
|
53
|
+
...baseConfig,
|
|
54
|
+
endpoint: isLocal ? endpoints.sqs : undefined
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// SNS Client
|
|
58
|
+
const sns = new SNSClient({
|
|
59
|
+
...baseConfig,
|
|
60
|
+
endpoint: isLocal ? endpoints.sns : undefined
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// EventBridge Client
|
|
64
|
+
const eventbridge = new EventBridgeClient({
|
|
65
|
+
...baseConfig,
|
|
66
|
+
endpoint: isLocal ? endpoints.eventbridge : undefined
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
// Clients
|
|
71
|
+
dynamoDB,
|
|
72
|
+
dynamoDBClient,
|
|
73
|
+
s3,
|
|
74
|
+
sqs,
|
|
75
|
+
sns,
|
|
76
|
+
eventbridge,
|
|
77
|
+
|
|
78
|
+
// Utilitários
|
|
79
|
+
isLocal,
|
|
80
|
+
endpoints,
|
|
81
|
+
|
|
82
|
+
// Configuração
|
|
83
|
+
config: {
|
|
84
|
+
region: baseConfig.region,
|
|
85
|
+
isLocal,
|
|
86
|
+
endpoints
|
|
87
|
+
}
|
|
88
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS SDK v3 Configuration for Local Development (ES Module)
|
|
3
|
+
* Gerado pelo AWS Local Simulator
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
7
|
+
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
8
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
9
|
+
import { SQSClient } from '@aws-sdk/client-sqs';
|
|
10
|
+
import { SNSClient } from '@aws-sdk/client-sns';
|
|
11
|
+
import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
|
|
12
|
+
|
|
13
|
+
// Configurações de ambiente
|
|
14
|
+
const isLocal = process.env.IS_LOCAL === 'true' || process.env.NODE_ENV === 'development';
|
|
15
|
+
|
|
16
|
+
// Endpoints locais
|
|
17
|
+
const endpoints = {
|
|
18
|
+
dynamodb: process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
|
|
19
|
+
s3: process.env.S3_ENDPOINT || 'http://localhost:4566',
|
|
20
|
+
sqs: process.env.SQS_ENDPOINT || 'http://localhost:9324',
|
|
21
|
+
sns: process.env.SNS_ENDPOINT || 'http://localhost:9911',
|
|
22
|
+
eventbridge: process.env.EVENTBRIDGE_ENDPOINT || 'http://localhost:4010'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Credenciais locais
|
|
26
|
+
const localCredentials = {
|
|
27
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
|
|
28
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const baseConfig = {
|
|
32
|
+
region: process.env.AWS_REGION || 'us-east-1',
|
|
33
|
+
credentials: isLocal ? localCredentials : undefined
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// DynamoDB Client
|
|
37
|
+
const dynamoDBClient = new DynamoDBClient({
|
|
38
|
+
...baseConfig,
|
|
39
|
+
endpoint: isLocal ? endpoints.dynamodb : undefined
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const dynamoDB = DynamoDBDocumentClient.from(dynamoDBClient);
|
|
43
|
+
|
|
44
|
+
// S3 Client
|
|
45
|
+
const s3 = new S3Client({
|
|
46
|
+
...baseConfig,
|
|
47
|
+
endpoint: isLocal ? endpoints.s3 : undefined,
|
|
48
|
+
forcePathStyle: isLocal
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// SQS Client
|
|
52
|
+
const sqs = new SQSClient({
|
|
53
|
+
...baseConfig,
|
|
54
|
+
endpoint: isLocal ? endpoints.sqs : undefined
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// SNS Client
|
|
58
|
+
const sns = new SNSClient({
|
|
59
|
+
...baseConfig,
|
|
60
|
+
endpoint: isLocal ? endpoints.sns : undefined
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// EventBridge Client
|
|
64
|
+
const eventbridge = new EventBridgeClient({
|
|
65
|
+
...baseConfig,
|
|
66
|
+
endpoint: isLocal ? endpoints.eventbridge : undefined
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
dynamoDB,
|
|
71
|
+
dynamoDBClient,
|
|
72
|
+
s3,
|
|
73
|
+
sqs,
|
|
74
|
+
sns,
|
|
75
|
+
eventbridge,
|
|
76
|
+
isLocal,
|
|
77
|
+
endpoints,
|
|
78
|
+
baseConfig as config
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default {
|
|
82
|
+
dynamoDB,
|
|
83
|
+
dynamoDBClient,
|
|
84
|
+
s3,
|
|
85
|
+
sqs,
|
|
86
|
+
sns,
|
|
87
|
+
eventbridge,
|
|
88
|
+
isLocal,
|
|
89
|
+
endpoints,
|
|
90
|
+
config: baseConfig
|
|
91
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
{
|
|
2
|
+
"services": {
|
|
3
|
+
"dynamodb": true,
|
|
4
|
+
"s3": true,
|
|
5
|
+
"sqs": true,
|
|
6
|
+
"lambda": true,
|
|
7
|
+
"sns": false,
|
|
8
|
+
"eventbridge": false,
|
|
9
|
+
"apigateway": true,
|
|
10
|
+
"ecs": false
|
|
11
|
+
},
|
|
12
|
+
"ports": {
|
|
13
|
+
"dynamodb": 8000,
|
|
14
|
+
"s3": 4566,
|
|
15
|
+
"sqs": 9324,
|
|
16
|
+
"lambda": 3001,
|
|
17
|
+
"sns": 9911,
|
|
18
|
+
"eventbridge": 4010
|
|
19
|
+
},
|
|
20
|
+
"lambdas": [
|
|
21
|
+
{
|
|
22
|
+
"path": "/api/users",
|
|
23
|
+
"handler": "./src/handlers/users.js",
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"env": {
|
|
26
|
+
"TABLE_NAME": "users-table",
|
|
27
|
+
"BUCKET_NAME": "user-files"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"path": "/api/products",
|
|
32
|
+
"handler": "./src/handlers/products.mjs",
|
|
33
|
+
"type": "module",
|
|
34
|
+
"env": {
|
|
35
|
+
"TABLE_NAME": "products-table"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"dynamodb": {
|
|
40
|
+
"tables": [
|
|
41
|
+
{
|
|
42
|
+
"TableName": "users-table",
|
|
43
|
+
"KeySchema": [{ "AttributeName": "userId", "KeyType": "HASH" }],
|
|
44
|
+
"AttributeDefinitions": [{ "AttributeName": "userId", "AttributeType": "S" }],
|
|
45
|
+
"ProvisionedThroughput": {
|
|
46
|
+
"ReadCapacityUnits": 5,
|
|
47
|
+
"WriteCapacityUnits": 5
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"s3": {
|
|
53
|
+
"buckets": ["users-files", "public-assets"]
|
|
54
|
+
},
|
|
55
|
+
"sqs": {
|
|
56
|
+
"queues": [
|
|
57
|
+
{
|
|
58
|
+
"name": "notifications-queue",
|
|
59
|
+
"lambdaPath": "/api/notifications",
|
|
60
|
+
"batchSize": 10
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"apigateway": {
|
|
65
|
+
"defaultCors": {
|
|
66
|
+
"allowOrigins": ["http://localhost:3000"],
|
|
67
|
+
"allowMethods": ["GET", "POST", "PUT", "DELETE"],
|
|
68
|
+
"allowHeaders": ["Content-Type", "Authorization"],
|
|
69
|
+
"maxAge": 300
|
|
70
|
+
},
|
|
71
|
+
"defaultThrottling": {
|
|
72
|
+
"burstLimit": 50,
|
|
73
|
+
"rateLimit": 10
|
|
74
|
+
},
|
|
75
|
+
"enableAccessLogging": true
|
|
76
|
+
},
|
|
77
|
+
"restApis": [
|
|
78
|
+
{
|
|
79
|
+
"name": "MyAPI",
|
|
80
|
+
"description": "My REST API",
|
|
81
|
+
"resources": [
|
|
82
|
+
{
|
|
83
|
+
"path": "/users",
|
|
84
|
+
"methods": [
|
|
85
|
+
{
|
|
86
|
+
"httpMethod": "GET",
|
|
87
|
+
"authorizationType": "NONE",
|
|
88
|
+
"integration": {
|
|
89
|
+
"type": "HTTP",
|
|
90
|
+
"uri": "http://localhost:3001/users",
|
|
91
|
+
"httpMethod": "GET"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"httpMethod": "POST",
|
|
96
|
+
"authorizationType": "NONE",
|
|
97
|
+
"integration": {
|
|
98
|
+
"type": "AWS",
|
|
99
|
+
"uri": "arn:aws:lambda:local:function:createUser"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"path": "/users/{userId}",
|
|
106
|
+
"methods": [
|
|
107
|
+
{
|
|
108
|
+
"httpMethod": "GET",
|
|
109
|
+
"authorizationType": "NONE",
|
|
110
|
+
"integration": {
|
|
111
|
+
"type": "HTTP",
|
|
112
|
+
"uri": "http://localhost:3001/users/{userId}",
|
|
113
|
+
"httpMethod": "GET"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"stages": [
|
|
120
|
+
{
|
|
121
|
+
"stageName": "dev",
|
|
122
|
+
"variables": {
|
|
123
|
+
"ENVIRONMENT": "development"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"stageName": "prod",
|
|
128
|
+
"variables": {
|
|
129
|
+
"ENVIRONMENT": "production"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"apiKeys": [
|
|
136
|
+
{
|
|
137
|
+
"name": "MyAPIKey",
|
|
138
|
+
"description": "Key for MyAPI",
|
|
139
|
+
"enabled": true
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"usagePlans": [
|
|
143
|
+
{
|
|
144
|
+
"name": "BasicPlan",
|
|
145
|
+
"description": "Basic usage plan",
|
|
146
|
+
"throttle": {
|
|
147
|
+
"burstLimit": 100,
|
|
148
|
+
"rateLimit": 10
|
|
149
|
+
},
|
|
150
|
+
"quota": {
|
|
151
|
+
"limit": 10000,
|
|
152
|
+
"period": "DAY"
|
|
153
|
+
},
|
|
154
|
+
"apiStages": [
|
|
155
|
+
{
|
|
156
|
+
"apiId": "api_123",
|
|
157
|
+
"stage": "dev"
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"ecs": {
|
|
163
|
+
"clusters": ["production", "staging", "development"],
|
|
164
|
+
"defaultTaskCpu": 512,
|
|
165
|
+
"defaultTaskMemory": 1024,
|
|
166
|
+
"containerRuntime": "simulate"
|
|
167
|
+
},
|
|
168
|
+
"taskDefinitions": [
|
|
169
|
+
{
|
|
170
|
+
"family": "my-app",
|
|
171
|
+
"containerDefinitions": [
|
|
172
|
+
{
|
|
173
|
+
"name": "web",
|
|
174
|
+
"image": "nginx:alpine",
|
|
175
|
+
"cpu": 256,
|
|
176
|
+
"memory": 512,
|
|
177
|
+
"essential": true,
|
|
178
|
+
"portMappings": [
|
|
179
|
+
{
|
|
180
|
+
"containerPort": 80,
|
|
181
|
+
"hostPort": 0,
|
|
182
|
+
"protocol": "tcp"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
"environment": [{ "name": "ENVIRONMENT", "value": "local" }]
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"networkMode": "awsvpc",
|
|
189
|
+
"cpu": "512",
|
|
190
|
+
"memory": "1024"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"services-ecs": [
|
|
194
|
+
{
|
|
195
|
+
"name": "my-web-service",
|
|
196
|
+
"cluster": "development",
|
|
197
|
+
"taskDefinition": "my-app",
|
|
198
|
+
"desiredCount": 2,
|
|
199
|
+
"schedulingStrategy": "REPLICA"
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/utils/aws-config.js
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cria configuração para AWS SDK baseada no ambiente
|
|
5
|
+
*/
|
|
6
|
+
function createAWSConfig(options = {}) {
|
|
7
|
+
const isLocal = process.env.NODE_ENV === 'development' || process.env.IS_LOCAL === 'true';
|
|
8
|
+
|
|
9
|
+
const config = {
|
|
10
|
+
region: options.region || process.env.AWS_REGION || 'us-east-1',
|
|
11
|
+
credentials: options.credentials || {
|
|
12
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'local',
|
|
13
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'local'
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
if (isLocal || options.forceLocal) {
|
|
18
|
+
config.endpoints = {
|
|
19
|
+
dynamoDB: options.dynamoDBEndpoint || process.env.DYNAMODB_ENDPOINT || 'http://localhost:8000',
|
|
20
|
+
s3: options.s3Endpoint || process.env.S3_ENDPOINT || 'http://localhost:4566',
|
|
21
|
+
sqs: options.sqsEndpoint || process.env.SQS_ENDPOINT || 'http://localhost:9324',
|
|
22
|
+
lambda: options.lambdaEndpoint || process.env.LAMBDA_ENDPOINT || 'http://localhost:3001'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Cria cliente DynamoDB configurado
|
|
31
|
+
*/
|
|
32
|
+
function createDynamoDBClient(options = {}) {
|
|
33
|
+
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
|
|
34
|
+
const config = createAWSConfig(options);
|
|
35
|
+
|
|
36
|
+
const clientConfig = {
|
|
37
|
+
region: config.region,
|
|
38
|
+
credentials: config.credentials
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (config.endpoints?.dynamoDB) {
|
|
42
|
+
clientConfig.endpoint = config.endpoints.dynamoDB;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return new DynamoDBClient(clientConfig);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cria cliente S3 configurado
|
|
50
|
+
*/
|
|
51
|
+
function createS3Client(options = {}) {
|
|
52
|
+
const { S3Client } = require('@aws-sdk/client-s3');
|
|
53
|
+
const config = createAWSConfig(options);
|
|
54
|
+
|
|
55
|
+
const clientConfig = {
|
|
56
|
+
region: config.region,
|
|
57
|
+
credentials: config.credentials
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (config.endpoints?.s3) {
|
|
61
|
+
clientConfig.endpoint = config.endpoints.s3;
|
|
62
|
+
clientConfig.forcePathStyle = true; // Necessário para S3 local
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return new S3Client(clientConfig);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Cria cliente SQS configurado
|
|
70
|
+
*/
|
|
71
|
+
function createSQSClient(options = {}) {
|
|
72
|
+
const { SQSClient } = require('@aws-sdk/client-sqs');
|
|
73
|
+
const config = createAWSConfig(options);
|
|
74
|
+
|
|
75
|
+
const clientConfig = {
|
|
76
|
+
region: config.region,
|
|
77
|
+
credentials: config.credentials
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (config.endpoints?.sqs) {
|
|
81
|
+
clientConfig.endpoint = config.endpoints.sqs;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new SQSClient(clientConfig);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = {
|
|
88
|
+
createAWSConfig,
|
|
89
|
+
createDynamoDBClient,
|
|
90
|
+
createS3Client,
|
|
91
|
+
createSQSClient
|
|
92
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Store - Persistência em arquivos JSON
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const mkdirp = require('mkdirp');
|
|
8
|
+
|
|
9
|
+
class LocalStore {
|
|
10
|
+
constructor(dataDir) {
|
|
11
|
+
this.dataDir = dataDir;
|
|
12
|
+
this.ensureDir();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ensureDir() {
|
|
16
|
+
if (!fs.existsSync(this.dataDir)) {
|
|
17
|
+
mkdirp.sync(this.dataDir);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getFilePath(entity) {
|
|
22
|
+
return path.join(this.dataDir, `${entity}.json`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
read(entity) {
|
|
26
|
+
const filePath = this.getFilePath(entity);
|
|
27
|
+
if (!fs.existsSync(filePath)) return [];
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
31
|
+
return JSON.parse(content);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`Erro ao ler ${entity}:`, error);
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
write(entity, data) {
|
|
39
|
+
const filePath = this.getFilePath(entity);
|
|
40
|
+
try {
|
|
41
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error(`Erro ao escrever ${entity}:`, error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
delete(entity) {
|
|
49
|
+
const filePath = this.getFilePath(entity);
|
|
50
|
+
if (fs.existsSync(filePath)) {
|
|
51
|
+
fs.unlinkSync(filePath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exists(entity) {
|
|
56
|
+
const filePath = this.getFilePath(entity);
|
|
57
|
+
return fs.existsSync(filePath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
list() {
|
|
61
|
+
if (!fs.existsSync(this.dataDir)) return [];
|
|
62
|
+
return fs.readdirSync(this.dataDir)
|
|
63
|
+
.filter(f => f.endsWith('.json'))
|
|
64
|
+
.map(f => f.replace('.json', ''));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = LocalStore;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger configurável
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let currentLogLevel = 'info';
|
|
6
|
+
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
silent: 0,
|
|
9
|
+
error: 1,
|
|
10
|
+
warn: 2,
|
|
11
|
+
info: 3,
|
|
12
|
+
debug: 4,
|
|
13
|
+
verboso: 5
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class Logger {
|
|
17
|
+
static setLevel(level) {
|
|
18
|
+
if (LOG_LEVELS[level] !== undefined) {
|
|
19
|
+
currentLogLevel = level;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static error(...args) {
|
|
24
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.error) {
|
|
25
|
+
console.error('\x1b[31m%s\x1b[0m', '❌', ...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static warn(...args) {
|
|
30
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.warn) {
|
|
31
|
+
console.warn('\x1b[33m%s\x1b[0m', '⚠️', ...args);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static info(...args) {
|
|
36
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
37
|
+
console.log('\x1b[36m%s\x1b[0m', 'ℹ️', ...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static debug(...args) {
|
|
42
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.debug) {
|
|
43
|
+
console.debug('\x1b[90m%s\x1b[0m', '🔍', ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static verboso(...args) {
|
|
48
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.verboso) {
|
|
49
|
+
console.log('\x1b[35m%s\x1b[0m', '📝', ...args);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static success(...args) {
|
|
54
|
+
if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
|
|
55
|
+
console.log('\x1b[32m%s\x1b[0m', '✅', ...args);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = Logger;
|