lesgo 1.0.0 → 2.1.1
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 +5 -4
- package/bin/lesgo-scripts.sh +4 -4
- package/dist/config/app.d.ts +7 -0
- package/dist/config/app.js +9 -0
- package/dist/config/aws.d.ts +5 -0
- package/dist/config/aws.js +4 -0
- package/dist/config/basicAuth.d.ts +7 -0
- package/dist/config/basicAuth.js +8 -0
- package/dist/config/crypto.d.ts +10 -0
- package/dist/config/crypto.js +9 -0
- package/dist/config/dynamodb.d.ts +8 -0
- package/dist/config/dynamodb.js +14 -0
- package/dist/config/elasticache.d.ts +7 -0
- package/dist/config/elasticache.js +6 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.js +11 -0
- package/dist/config/jwt.d.ts +12 -0
- package/dist/config/jwt.js +16 -0
- package/dist/config/rds.d.ts +12 -0
- package/dist/config/rds.js +13 -0
- package/dist/config/s3.d.ts +5 -0
- package/dist/config/s3.js +5 -0
- package/dist/config/secretsManager.d.ts +4 -0
- package/dist/config/secretsManager.js +4 -0
- package/dist/config/sqs.d.ts +9 -0
- package/dist/config/sqs.js +18 -0
- package/dist/exceptions/LesgoException.d.ts +6 -0
- package/{src → dist}/exceptions/LesgoException.js +5 -4
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +1 -0
- package/dist/middlewares/disconnectMiddleware.d.ts +8 -0
- package/dist/middlewares/disconnectMiddleware.js +78 -0
- package/dist/middlewares/httpMiddleware.d.ts +12 -0
- package/dist/middlewares/httpMiddleware.js +74 -0
- package/dist/middlewares/httpResponseMiddleware.d.ts +7 -0
- package/dist/middlewares/httpResponseMiddleware.js +128 -0
- package/dist/middlewares/index.d.ts +7 -0
- package/dist/middlewares/index.js +7 -0
- package/dist/middlewares/invokeCommandMiddleware.d.ts +12 -0
- package/dist/middlewares/invokeCommandMiddleware.js +70 -0
- package/dist/middlewares/sqsMiddleware.d.ts +10 -0
- package/dist/middlewares/sqsMiddleware.js +70 -0
- package/dist/middlewares/verifyBasicAuthMiddleware.d.ts +8 -0
- package/dist/middlewares/verifyBasicAuthMiddleware.js +59 -0
- package/dist/middlewares/verifyJwtMiddleware.d.ts +6 -0
- package/dist/middlewares/verifyJwtMiddleware.js +37 -0
- package/dist/services/DynamoDbService/deleteRecord.d.ts +8 -0
- package/dist/services/DynamoDbService/deleteRecord.js +69 -0
- package/dist/services/DynamoDbService/getClient.d.ts +7 -0
- package/dist/services/DynamoDbService/getClient.js +30 -0
- package/dist/services/DynamoDbService/getTableName.d.ts +2 -0
- package/dist/services/DynamoDbService/getTableName.js +15 -0
- package/dist/services/DynamoDbService/index.d.ts +6 -0
- package/dist/services/DynamoDbService/index.js +6 -0
- package/dist/services/DynamoDbService/putRecord.d.ts +8 -0
- package/dist/services/DynamoDbService/putRecord.js +64 -0
- package/dist/services/DynamoDbService/query.d.ts +7 -0
- package/dist/services/DynamoDbService/query.js +78 -0
- package/dist/services/DynamoDbService/scan.d.ts +7 -0
- package/dist/services/DynamoDbService/scan.js +60 -0
- package/dist/services/DynamoDbService/updateRecord.d.ts +9 -0
- package/dist/services/DynamoDbService/updateRecord.js +89 -0
- package/dist/services/ElastiCacheRedisService/deleteRedisCache.d.ts +3 -0
- package/dist/services/ElastiCacheRedisService/deleteRedisCache.js +62 -0
- package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.d.ts +11 -0
- package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.js +69 -0
- package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.d.ts +12 -0
- package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.js +114 -0
- package/dist/services/ElastiCacheRedisService/getRedisCache.d.ts +3 -0
- package/dist/services/ElastiCacheRedisService/getRedisCache.js +70 -0
- package/dist/services/ElastiCacheRedisService/index.d.ts +5 -0
- package/dist/services/ElastiCacheRedisService/index.js +5 -0
- package/dist/services/ElastiCacheRedisService/setRedisCache.d.ts +6 -0
- package/dist/services/ElastiCacheRedisService/setRedisCache.js +77 -0
- package/dist/services/JWTService/decodeJwt.d.ts +7 -0
- package/dist/services/JWTService/decodeJwt.js +9 -0
- package/dist/services/JWTService/getJwtSecret.d.ts +13 -0
- package/dist/services/JWTService/getJwtSecret.js +54 -0
- package/dist/services/JWTService/index.d.ts +2 -0
- package/dist/services/JWTService/index.js +2 -0
- package/dist/services/JWTService/sign.d.ts +3 -0
- package/dist/services/JWTService/sign.js +31 -0
- package/dist/services/JWTService/verify.d.ts +7 -0
- package/dist/services/JWTService/verify.js +61 -0
- package/dist/services/LoggerService.d.ts +46 -0
- package/{src → dist}/services/LoggerService.js +29 -60
- package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.d.ts +2 -0
- package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.js +60 -0
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.d.ts +8 -0
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.js +87 -0
- package/dist/services/RDSAuroraMySQLProxyService/index.d.ts +3 -0
- package/dist/services/RDSAuroraMySQLProxyService/index.js +3 -0
- package/dist/services/RDSAuroraMySQLProxyService/query.d.ts +4 -0
- package/dist/services/RDSAuroraMySQLProxyService/query.js +63 -0
- package/dist/services/S3Service/getClient.d.ts +4 -0
- package/dist/services/S3Service/getClient.js +28 -0
- package/dist/services/S3Service/getDownloadSignedUrl.d.ts +7 -0
- package/dist/services/S3Service/getDownloadSignedUrl.js +58 -0
- package/dist/services/S3Service/getHeadObject.d.ts +13 -0
- package/dist/services/S3Service/getHeadObject.js +83 -0
- package/dist/services/S3Service/getObject.d.ts +10 -0
- package/dist/services/S3Service/getObject.js +89 -0
- package/dist/services/S3Service/getUploadSignedUrl.d.ts +7 -0
- package/dist/services/S3Service/getUploadSignedUrl.js +61 -0
- package/dist/services/S3Service/index.d.ts +6 -0
- package/dist/services/S3Service/index.js +6 -0
- package/dist/services/S3Service/putObject.d.ts +9 -0
- package/dist/services/S3Service/putObject.js +77 -0
- package/dist/services/SQSService/deleteMessage.d.ts +9 -0
- package/dist/services/SQSService/deleteMessage.js +69 -0
- package/dist/services/SQSService/dispatch.d.ts +9 -0
- package/dist/services/SQSService/dispatch.js +71 -0
- package/dist/services/SQSService/getClient.d.ts +4 -0
- package/dist/services/SQSService/getClient.js +28 -0
- package/dist/services/SQSService/getQueueUrl.d.ts +7 -0
- package/dist/services/SQSService/getQueueUrl.js +25 -0
- package/dist/services/SQSService/index.d.ts +4 -0
- package/dist/services/SQSService/index.js +4 -0
- package/dist/services/SQSService/receiveMessages.d.ts +8 -0
- package/dist/services/SQSService/receiveMessages.js +65 -0
- package/dist/services/SecretsManagerService/getClient.d.ts +7 -0
- package/dist/services/SecretsManagerService/getClient.js +28 -0
- package/dist/services/SecretsManagerService/getSecretValue.d.ts +7 -0
- package/dist/services/SecretsManagerService/getSecretValue.js +65 -0
- package/dist/services/SecretsManagerService/index.d.ts +2 -0
- package/dist/services/SecretsManagerService/index.js +2 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/types/aws.d.ts +8 -0
- package/dist/types/aws.js +1 -0
- package/dist/utils/cache/redis/deleteCache.d.ts +19 -0
- package/dist/utils/cache/redis/deleteCache.js +21 -0
- package/dist/utils/cache/redis/getCache.d.ts +22 -0
- package/dist/utils/cache/redis/getCache.js +24 -0
- package/dist/utils/cache/redis/getClient.d.ts +30 -0
- package/dist/utils/cache/redis/getClient.js +32 -0
- package/dist/utils/cache/redis/index.d.ts +4 -0
- package/dist/utils/cache/redis/index.js +4 -0
- package/dist/utils/cache/redis/setCache.d.ts +25 -0
- package/dist/utils/cache/redis/setCache.js +26 -0
- package/dist/utils/crypto/decrypt.d.ts +33 -0
- package/dist/utils/crypto/decrypt.js +59 -0
- package/dist/utils/crypto/encrypt.d.ts +31 -0
- package/dist/utils/crypto/encrypt.js +41 -0
- package/dist/utils/crypto/hash.d.ts +31 -0
- package/dist/utils/crypto/hash.js +56 -0
- package/dist/utils/crypto/index.d.ts +3 -0
- package/dist/utils/crypto/index.js +3 -0
- package/dist/utils/crypto/validateEncryptionFields.d.ts +19 -0
- package/dist/utils/crypto/validateEncryptionFields.js +71 -0
- package/dist/utils/db/mysql/proxy/disconnect.d.ts +2 -0
- package/dist/utils/db/mysql/proxy/disconnect.js +5 -0
- package/dist/utils/db/mysql/proxy/disconnectDb.d.ts +2 -0
- package/dist/utils/db/mysql/proxy/disconnectDb.js +5 -0
- package/dist/utils/db/mysql/proxy/getClient.d.ts +4 -0
- package/dist/utils/db/mysql/proxy/getClient.js +5 -0
- package/dist/utils/db/mysql/proxy/index.d.ts +3 -0
- package/dist/utils/db/mysql/proxy/index.js +3 -0
- package/dist/utils/db/mysql/proxy/query.d.ts +4 -0
- package/dist/utils/db/mysql/proxy/query.js +45 -0
- package/dist/utils/dynamodb/deleteRecord.d.ts +5 -0
- package/dist/utils/dynamodb/deleteRecord.js +39 -0
- package/dist/utils/dynamodb/getClient.d.ts +3 -0
- package/dist/utils/dynamodb/getClient.js +5 -0
- package/dist/utils/dynamodb/index.d.ts +6 -0
- package/dist/utils/dynamodb/index.js +6 -0
- package/dist/utils/dynamodb/putRecord.d.ts +4 -0
- package/dist/utils/dynamodb/putRecord.js +39 -0
- package/dist/utils/dynamodb/query.d.ts +5 -0
- package/dist/utils/dynamodb/query.js +52 -0
- package/dist/utils/dynamodb/scan.d.ts +4 -0
- package/dist/utils/dynamodb/scan.js +40 -0
- package/dist/utils/dynamodb/updateRecord.d.ts +5 -0
- package/dist/utils/dynamodb/updateRecord.js +53 -0
- package/dist/utils/formatUnixTimestamp.d.ts +8 -0
- package/dist/utils/formatUnixTimestamp.js +17 -0
- package/dist/utils/generateUid.d.ts +13 -0
- package/{src → dist}/utils/generateUid.js +9 -4
- package/dist/utils/getCurrentDatetime.d.ts +2 -0
- package/dist/utils/getCurrentDatetime.js +4 -0
- package/dist/utils/getCurrentTimestamp.d.ts +7 -0
- package/dist/utils/getCurrentTimestamp.js +9 -0
- package/dist/utils/getJwtSubFromAuthHeader.d.ts +9 -0
- package/dist/utils/getJwtSubFromAuthHeader.js +24 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/isDecimal.d.ts +8 -0
- package/dist/utils/isDecimal.js +9 -0
- package/dist/utils/isEmail.d.ts +9 -0
- package/{src → dist}/utils/isEmail.js +9 -4
- package/dist/utils/isEmpty.d.ts +8 -0
- package/dist/utils/isEmpty.js +19 -0
- package/dist/utils/jwt/index.d.ts +2 -0
- package/dist/utils/jwt/index.js +2 -0
- package/dist/utils/jwt/sign.d.ts +3 -0
- package/dist/utils/jwt/sign.js +5 -0
- package/dist/utils/jwt/verify.d.ts +3 -0
- package/dist/utils/jwt/verify.js +12 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.js +38 -0
- package/dist/utils/s3/getClient.d.ts +3 -0
- package/dist/utils/s3/getClient.js +5 -0
- package/dist/utils/s3/getDownloadSignedUrl.d.ts +5 -0
- package/dist/utils/s3/getDownloadSignedUrl.js +39 -0
- package/dist/utils/s3/getHeadObject.d.ts +10 -0
- package/dist/utils/s3/getHeadObject.js +39 -0
- package/dist/utils/s3/getObject.d.ts +13 -0
- package/dist/utils/s3/getObject.js +51 -0
- package/dist/utils/s3/getUploadSignedUrl.d.ts +5 -0
- package/dist/utils/s3/getUploadSignedUrl.js +39 -0
- package/dist/utils/s3/index.d.ts +6 -0
- package/dist/utils/s3/index.js +6 -0
- package/dist/utils/s3/putObject.d.ts +5 -0
- package/dist/utils/s3/putObject.js +39 -0
- package/dist/utils/secretsmanager/getClient.d.ts +3 -0
- package/dist/utils/secretsmanager/getClient.js +5 -0
- package/dist/utils/secretsmanager/getSecretValue.d.ts +4 -0
- package/dist/utils/secretsmanager/getSecretValue.js +68 -0
- package/dist/utils/secretsmanager/index.d.ts +2 -0
- package/dist/utils/secretsmanager/index.js +2 -0
- package/dist/utils/sqs/deleteMessage.d.ts +5 -0
- package/dist/utils/sqs/deleteMessage.js +39 -0
- package/dist/utils/sqs/dispatch.d.ts +5 -0
- package/dist/utils/sqs/dispatch.js +39 -0
- package/dist/utils/sqs/getClient.d.ts +3 -0
- package/dist/utils/sqs/getClient.js +5 -0
- package/dist/utils/sqs/index.d.ts +4 -0
- package/dist/utils/sqs/index.js +4 -0
- package/dist/utils/sqs/receiveMessages.d.ts +5 -0
- package/dist/utils/sqs/receiveMessages.js +39 -0
- package/dist/utils/validateFields.d.ts +22 -0
- package/{src → dist}/utils/validateFields.js +13 -19
- package/package.json +145 -34
- package/src/exceptions/__tests__/LesgoException.spec.js +0 -24
- package/src/exceptions/index.js +0 -4
- package/src/index.js +0 -4
- package/src/middlewares/__mocks__/ValidationErrorException.js +0 -18
- package/src/middlewares/__tests__/basicAuthMiddleware.spec.js +0 -264
- package/src/middlewares/__tests__/clientAuthMiddleware.spec.js +0 -235
- package/src/middlewares/__tests__/errorHttpResponseMiddleware.spec.js +0 -203
- package/src/middlewares/__tests__/gzipHttpResponse.spec.js +0 -185
- package/src/middlewares/__tests__/httpNoOutputMiddleware.spec.js +0 -201
- package/src/middlewares/__tests__/normalizeHttpRequestMiddleware.spec.js +0 -181
- package/src/middlewares/__tests__/normalizeSQSMessageMiddleware.spec.js +0 -120
- package/src/middlewares/__tests__/successHttpResponseMiddleware.spec.js +0 -172
- package/src/middlewares/__tests__/verifyJwtMiddleware.spec.js +0 -297
- package/src/middlewares/basicAuthMiddleware.js +0 -125
- package/src/middlewares/clientAuthMiddleware.js +0 -103
- package/src/middlewares/errorHttpResponseMiddleware.js +0 -101
- package/src/middlewares/gzipHttpResponse.js +0 -98
- package/src/middlewares/httpMiddleware.js +0 -19
- package/src/middlewares/httpNoOutputMiddleware.js +0 -91
- package/src/middlewares/index.js +0 -19
- package/src/middlewares/normalizeHttpRequestMiddleware.js +0 -101
- package/src/middlewares/normalizeSQSMessageMiddleware.js +0 -67
- package/src/middlewares/successHttpResponseMiddleware.js +0 -85
- package/src/middlewares/verifyJwtMiddleware.js +0 -73
- package/src/services/AuroraDbRDSProxyService.js +0 -182
- package/src/services/AuroraDbService.js +0 -111
- package/src/services/DynamoDbService.js +0 -177
- package/src/services/ElastiCacheService.js +0 -17
- package/src/services/ElasticsearchService.js +0 -181
- package/src/services/FirebaseAdminService.js +0 -108
- package/src/services/JwtService.js +0 -52
- package/src/services/S3Service.js +0 -59
- package/src/services/SQSService.js +0 -65
- package/src/services/__tests__/AuroraDbRDSProxyService.spec.js +0 -278
- package/src/services/__tests__/AuroraDbService.spec.js +0 -211
- package/src/services/__tests__/AwsElasticsearchConnection.spec.js +0 -89
- package/src/services/__tests__/DynamoDbService.spec.js +0 -314
- package/src/services/__tests__/ElasticsearchService.spec.js +0 -201
- package/src/services/__tests__/FirebaseAdminService.spec.js +0 -356
- package/src/services/__tests__/JwtService.spec.js +0 -35
- package/src/services/__tests__/LengthAwarePaginator.spec.js +0 -223
- package/src/services/__tests__/LoggerService.spec.js +0 -267
- package/src/services/__tests__/Paginator.spec.js +0 -383
- package/src/services/__tests__/S3Service.spec.js +0 -55
- package/src/services/__tests__/SQSService.spec.js +0 -47
- package/src/services/__tests__/SignedRequest.spec.js +0 -103
- package/src/services/aws/AwsElasticsearchConnection.js +0 -59
- package/src/services/aws/SignedRequest.js +0 -158
- package/src/services/index.js +0 -19
- package/src/services/pagination/LengthAwarePaginator.js +0 -49
- package/src/services/pagination/Paginator.js +0 -260
- package/src/utils/__mocks__/db.js +0 -109
- package/src/utils/__tests__/cache.spec.js +0 -131
- package/src/utils/__tests__/crypto.spec.js +0 -122
- package/src/utils/__tests__/db.spec.js +0 -70
- package/src/utils/__tests__/dynamodb.spec.js +0 -27
- package/src/utils/__tests__/elasticsearch.spec.js +0 -43
- package/src/utils/__tests__/generateUid.spec.js +0 -36
- package/src/utils/__tests__/getJwtSubFromAuthHeader.spec.js +0 -20
- package/src/utils/__tests__/isDecimal.spec.js +0 -12
- package/src/utils/__tests__/isEmail.spec.js +0 -28
- package/src/utils/__tests__/isEmpty.spec.js +0 -31
- package/src/utils/__tests__/logger.spec.js +0 -11
- package/src/utils/__tests__/objectStore.spec.js +0 -67
- package/src/utils/__tests__/prepSQLInsertParams.spec.js +0 -46
- package/src/utils/__tests__/prepSQLUpdateParams.spec.js +0 -36
- package/src/utils/__tests__/queue.spec.js +0 -54
- package/src/utils/__tests__/validateFields.spec.js +0 -374
- package/src/utils/cache.js +0 -215
- package/src/utils/crypto.js +0 -77
- package/src/utils/db.js +0 -17
- package/src/utils/dynamodb.js +0 -6
- package/src/utils/elasticsearch.js +0 -20
- package/src/utils/getJwtSubFromAuthHeader.js +0 -18
- package/src/utils/index.js +0 -26
- package/src/utils/isDecimal.js +0 -2
- package/src/utils/isEmpty.js +0 -6
- package/src/utils/logger.js +0 -25
- package/src/utils/objectStore.js +0 -11
- package/src/utils/prepSQLInsertParams.js +0 -21
- package/src/utils/prepSQLUpdateParams.js +0 -25
- package/src/utils/queue.js +0 -11
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { QueryCommand } from '@aws-sdk/lib-dynamodb';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { validateFields, logger } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getTableName from './getTableName';
|
|
39
|
+
const FILE = 'lesgo.services.DynamoDbService.query';
|
|
40
|
+
const query = (
|
|
41
|
+
tableAlias,
|
|
42
|
+
keyConditionExpression,
|
|
43
|
+
expressionAttributeValues,
|
|
44
|
+
opts,
|
|
45
|
+
clientOpts
|
|
46
|
+
) =>
|
|
47
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const input = validateFields(
|
|
49
|
+
{ tableAlias, keyConditionExpression, expressionAttributeValues },
|
|
50
|
+
[
|
|
51
|
+
{ key: 'tableAlias', type: 'string', required: true },
|
|
52
|
+
{ key: 'keyConditionExpression', type: 'string', required: true },
|
|
53
|
+
{ key: 'expressionAttributeValues', type: 'object', required: true },
|
|
54
|
+
]
|
|
55
|
+
);
|
|
56
|
+
const tableName = getTableName(input.tableAlias);
|
|
57
|
+
const client = getClient(clientOpts);
|
|
58
|
+
const commandInput = Object.assign(
|
|
59
|
+
{
|
|
60
|
+
TableName: tableName,
|
|
61
|
+
KeyConditionExpression: input.keyConditionExpression,
|
|
62
|
+
ExpressionAttributeValues: input.expressionAttributeValues,
|
|
63
|
+
},
|
|
64
|
+
opts
|
|
65
|
+
);
|
|
66
|
+
try {
|
|
67
|
+
const data = yield client.send(new QueryCommand(commandInput));
|
|
68
|
+
logger.debug(`${FILE}::RECEIVED_RESPONSE`, { data, commandInput });
|
|
69
|
+
return data;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw new LesgoException('Failed to query', `${FILE}::ERROR`, 500, {
|
|
72
|
+
error,
|
|
73
|
+
commandInput,
|
|
74
|
+
opts,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
export default query;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ScanCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
export interface ScanOptions extends Partial<Omit<ScanCommandInput, 'TableName'>> {
|
|
4
|
+
TableName?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const scan: (tableAlias: string, opts?: ScanOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/lib-dynamodb").ScanCommandOutput>;
|
|
7
|
+
export default scan;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { validateFields, logger } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getTableName from './getTableName';
|
|
39
|
+
const FILE = 'lesgo.services.DynamoDbService.scan';
|
|
40
|
+
const scan = (tableAlias, opts, clientOpts) =>
|
|
41
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const input = validateFields(Object.assign({ tableAlias }, opts), [
|
|
43
|
+
{ key: 'tableAlias', type: 'string', required: true },
|
|
44
|
+
]);
|
|
45
|
+
const tableName = getTableName(input.tableAlias);
|
|
46
|
+
const client = getClient(clientOpts);
|
|
47
|
+
const commandInput = Object.assign({ TableName: tableName }, opts);
|
|
48
|
+
try {
|
|
49
|
+
const data = yield client.send(new ScanCommand(commandInput));
|
|
50
|
+
logger.debug(`${FILE}::RECEIVED_RESPONSE`, { data, commandInput });
|
|
51
|
+
return data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new LesgoException('Failed to scan', `${FILE}::ERROR`, 500, {
|
|
54
|
+
error,
|
|
55
|
+
commandInput,
|
|
56
|
+
opts,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
export default scan;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NativeAttributeValue, UpdateCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
export type Key = Record<string, NativeAttributeValue>;
|
|
4
|
+
export type UpdateRecordOptions = Omit<UpdateCommandInput, 'TableName' | 'Key'> & {
|
|
5
|
+
TableName?: string;
|
|
6
|
+
Key?: Record<string, NativeAttributeValue> | undefined;
|
|
7
|
+
};
|
|
8
|
+
declare const updateRecord: (key: Record<string, string>, tableAlias: string, updateExpression: string, expressionAttributeValues: Record<string, NativeAttributeValue>, opts?: UpdateRecordOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
|
|
9
|
+
export default updateRecord;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { UpdateCommand } from '@aws-sdk/lib-dynamodb';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger, validateFields } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getTableName from './getTableName';
|
|
39
|
+
const FILE = 'lesgo.services.DynamoDbService.updateRecord';
|
|
40
|
+
const updateRecord = (
|
|
41
|
+
key,
|
|
42
|
+
tableAlias,
|
|
43
|
+
updateExpression,
|
|
44
|
+
expressionAttributeValues,
|
|
45
|
+
opts,
|
|
46
|
+
clientOpts
|
|
47
|
+
) =>
|
|
48
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const input = validateFields(
|
|
50
|
+
Object.assign(
|
|
51
|
+
{ key, tableAlias, updateExpression, expressionAttributeValues },
|
|
52
|
+
opts
|
|
53
|
+
),
|
|
54
|
+
[
|
|
55
|
+
{ key: 'key', type: 'object', required: true },
|
|
56
|
+
{ key: 'tableAlias', type: 'string', required: true },
|
|
57
|
+
{ key: 'updateExpression', type: 'string', required: true },
|
|
58
|
+
{ key: 'expressionAttributeValues', type: 'object', required: true },
|
|
59
|
+
]
|
|
60
|
+
);
|
|
61
|
+
const tableName = getTableName(input.tableAlias);
|
|
62
|
+
const client = getClient(clientOpts);
|
|
63
|
+
const commandInput = Object.assign(
|
|
64
|
+
{
|
|
65
|
+
TableName: tableName,
|
|
66
|
+
Key: input.key,
|
|
67
|
+
UpdateExpression: input.updateExpression,
|
|
68
|
+
ExpressionAttributeValues: input.expressionAttributeValues,
|
|
69
|
+
},
|
|
70
|
+
opts
|
|
71
|
+
);
|
|
72
|
+
try {
|
|
73
|
+
const data = yield client.send(new UpdateCommand(commandInput));
|
|
74
|
+
logger.debug(`${FILE}::RECEIVED_RESPONSE`, { data, commandInput });
|
|
75
|
+
return data;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw new LesgoException(
|
|
78
|
+
'Failed to update record',
|
|
79
|
+
`${FILE}::ERROR`,
|
|
80
|
+
500,
|
|
81
|
+
{
|
|
82
|
+
error,
|
|
83
|
+
commandInput,
|
|
84
|
+
opts,
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
export default updateRecord;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { logger, validateFields } from '../../utils';
|
|
35
|
+
import { LesgoException } from '../../exceptions';
|
|
36
|
+
import getElastiCacheRedisClient from './getElastiCacheRedisClient';
|
|
37
|
+
const FILE = 'lesgo.services.ElastiCacheRedis.deleteRedisCache';
|
|
38
|
+
const deleteRedisCache = (key, clientOpts) =>
|
|
39
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const input = validateFields({ key }, [
|
|
41
|
+
{ key: 'key', type: 'string', required: true },
|
|
42
|
+
]);
|
|
43
|
+
const client = yield getElastiCacheRedisClient(clientOpts);
|
|
44
|
+
let resp;
|
|
45
|
+
try {
|
|
46
|
+
resp = yield client.del(input.key);
|
|
47
|
+
logger.debug(`${FILE}::RECEIVED_RESPONSE`, { resp, input });
|
|
48
|
+
return resp;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw new LesgoException(
|
|
51
|
+
'Failed to delete redis cache',
|
|
52
|
+
`${FILE}::DELETE_ERROR`,
|
|
53
|
+
500,
|
|
54
|
+
{
|
|
55
|
+
err,
|
|
56
|
+
input,
|
|
57
|
+
clientOpts,
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export default deleteRedisCache;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Disconnects the ElastiCache Redis client.
|
|
3
|
+
*
|
|
4
|
+
* It is important to disconnect the ElastiCache Redis client
|
|
5
|
+
* when it is no longer needed to prevent memory leaks and to free up resources,
|
|
6
|
+
* especially for serverless applications on Lambda function.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Promise<void>} A promise that resolves when the disconnection is completed.
|
|
9
|
+
*/
|
|
10
|
+
declare const disconnectElastiCacheRedisClient: () => Promise<void>;
|
|
11
|
+
export default disconnectElastiCacheRedisClient;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { logger } from '../../utils';
|
|
35
|
+
import { singleton } from '../ElastiCacheRedisService/getElastiCacheRedisClient';
|
|
36
|
+
const FILE =
|
|
37
|
+
'lesgo.services.ElastiCacheRedisService.disconnectElastiCacheRedisClient';
|
|
38
|
+
/**
|
|
39
|
+
* Disconnects the ElastiCache Redis client.
|
|
40
|
+
*
|
|
41
|
+
* It is important to disconnect the ElastiCache Redis client
|
|
42
|
+
* when it is no longer needed to prevent memory leaks and to free up resources,
|
|
43
|
+
* especially for serverless applications on Lambda function.
|
|
44
|
+
*
|
|
45
|
+
* @returns {Promise<void>} A promise that resolves when the disconnection is completed.
|
|
46
|
+
*/
|
|
47
|
+
const disconnectElastiCacheRedisClient = () =>
|
|
48
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const singletonConns = Object.keys(singleton);
|
|
50
|
+
if (singletonConns.length === 0) {
|
|
51
|
+
logger.debug(`${FILE}::NO_CONNECTIONS_TO_DISCONNECT`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
logger.debug(`${FILE}::PREPARING_TO_DISCONNECT`, {
|
|
55
|
+
singletonConns,
|
|
56
|
+
});
|
|
57
|
+
singletonConns.forEach(singletonConn =>
|
|
58
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
try {
|
|
60
|
+
yield singleton[singletonConn].quit();
|
|
61
|
+
delete singleton[singletonConn];
|
|
62
|
+
logger.debug(`${FILE}::COMPLETED`, { singletonConn });
|
|
63
|
+
} catch (err) {
|
|
64
|
+
logger.error(`${FILE}::ERROR`, { singletonConn, err });
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
export default disconnectElastiCacheRedisClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cluster } from 'ioredis';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
export interface Singleton {
|
|
4
|
+
[key: string]: Cluster;
|
|
5
|
+
}
|
|
6
|
+
export declare const singleton: Singleton;
|
|
7
|
+
export interface ElastiCacheRedisClientOptions extends ClientOptions {
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
}
|
|
11
|
+
declare const getElastiCacheRedisClient: (clientOpts?: ElastiCacheRedisClientOptions) => Promise<Cluster>;
|
|
12
|
+
export default getElastiCacheRedisClient;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { Cluster } from 'ioredis';
|
|
35
|
+
import { elasticache as elasticacheConfig } from '../../config';
|
|
36
|
+
import { logger, isEmpty, validateFields } from '../../utils';
|
|
37
|
+
import { LesgoException } from '../../exceptions';
|
|
38
|
+
const FILE = 'lesgo.services.ElastiCacheRedisService.getClient';
|
|
39
|
+
export const singleton = {};
|
|
40
|
+
const getElastiCacheRedisClient = clientOpts =>
|
|
41
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const options = validateFields(clientOpts || {}, [
|
|
43
|
+
{ key: 'singletonConn', type: 'string', required: false },
|
|
44
|
+
{ key: 'endpoint', type: 'string', required: false },
|
|
45
|
+
{ key: 'port', type: 'number', required: false },
|
|
46
|
+
]);
|
|
47
|
+
const singletonConn = options.singletonConn || 'default';
|
|
48
|
+
if (!isEmpty(singleton[singletonConn])) {
|
|
49
|
+
logger.debug(`${FILE}::REUSE_ELASTICACHE_REDIS_CONNECTION`);
|
|
50
|
+
return singleton[singletonConn];
|
|
51
|
+
}
|
|
52
|
+
const clusterEndpoint =
|
|
53
|
+
options.endpoint || elasticacheConfig.redis.endpoint;
|
|
54
|
+
const clusterPort = options.port || elasticacheConfig.redis.port || 6379;
|
|
55
|
+
if (!clusterEndpoint) {
|
|
56
|
+
throw new LesgoException(
|
|
57
|
+
'Missing ElastiCache Redis endpoint',
|
|
58
|
+
`${FILE}::MISSING_ENDPOINT`,
|
|
59
|
+
500,
|
|
60
|
+
{ options, elasticacheConfig }
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const redisClient = new Cluster(
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
host: clusterEndpoint,
|
|
67
|
+
port: clusterPort,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
{
|
|
71
|
+
dnsLookup: (address, callback) => callback(null, address),
|
|
72
|
+
redisOptions: {
|
|
73
|
+
tls: {},
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
redisClient.on('error', err => {
|
|
78
|
+
logger.error(`${FILE}::REDIS_CLIENT_NOT_CONNECTED_ERROR`, { err });
|
|
79
|
+
});
|
|
80
|
+
redisClient.on('connect', () => {
|
|
81
|
+
logger.debug(`${FILE}::REDIS_CLIENT_CONNECTED`);
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
yield redisClient.connect();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
// Not ideal to base on error message but ioredis doesn't have a better way to check if it's already connected
|
|
87
|
+
if (error.message === 'Redis is already connecting/connected') {
|
|
88
|
+
logger.debug(`${FILE}::REDIS_ALREADY_CONNECTED`, {
|
|
89
|
+
error,
|
|
90
|
+
errorMessage:
|
|
91
|
+
error === null || error === void 0 ? void 0 : error.message,
|
|
92
|
+
clusterEndpoint,
|
|
93
|
+
clusterPort,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
throw new LesgoException(
|
|
97
|
+
'Failed to connect to ElastiCache Redis',
|
|
98
|
+
`${FILE}::REDIS_CONNECT_ERROR`,
|
|
99
|
+
500,
|
|
100
|
+
{
|
|
101
|
+
error,
|
|
102
|
+
errorMessage:
|
|
103
|
+
error === null || error === void 0 ? void 0 : error.message,
|
|
104
|
+
clusterEndpoint,
|
|
105
|
+
clusterPort,
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
singleton[singletonConn] = redisClient;
|
|
111
|
+
logger.debug(`${FILE}::NEW_ELASTICACHE_REDIS_CONNECTION`);
|
|
112
|
+
return redisClient;
|
|
113
|
+
});
|
|
114
|
+
export default getElastiCacheRedisClient;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { isEmpty, logger, validateFields } from '../../utils';
|
|
35
|
+
import { LesgoException } from '../../exceptions';
|
|
36
|
+
import getElastiCacheRedisClient from './getElastiCacheRedisClient';
|
|
37
|
+
const FILE = 'lesgo.services.ElastiCacheRedis.getRedisCache';
|
|
38
|
+
const getRedisCache = (key, clientOpts) =>
|
|
39
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const input = validateFields({ key }, [
|
|
41
|
+
{ key: 'key', type: 'string', required: true },
|
|
42
|
+
]);
|
|
43
|
+
const client = yield getElastiCacheRedisClient(clientOpts);
|
|
44
|
+
let resp;
|
|
45
|
+
try {
|
|
46
|
+
resp = yield client.get(input.key);
|
|
47
|
+
logger.debug(`${FILE}::RECEIVED_RESPONSE`, { resp, input });
|
|
48
|
+
} catch (err) {
|
|
49
|
+
throw new LesgoException(
|
|
50
|
+
'Failed to get redis cache',
|
|
51
|
+
`${FILE}::GET_ERROR`,
|
|
52
|
+
500,
|
|
53
|
+
{
|
|
54
|
+
err,
|
|
55
|
+
input,
|
|
56
|
+
clientOpts,
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
if (isEmpty(resp) || !resp) return resp;
|
|
62
|
+
const data = JSON.parse(resp);
|
|
63
|
+
logger.debug(`${FILE}::DATA_IS_JSON`, { data });
|
|
64
|
+
return data;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
logger.debug(`${FILE}::DATA_NOT_JSON`, { resp });
|
|
67
|
+
return resp;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
export default getRedisCache;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as deleteRedisCache } from './deleteRedisCache';
|
|
2
|
+
export { default as disconnectElastiCacheRedisClient } from './disconnectElastiCacheRedisClient';
|
|
3
|
+
export { default as getElastiCacheRedisClient } from './getElastiCacheRedisClient';
|
|
4
|
+
export { default as getRedisCache } from './getRedisCache';
|
|
5
|
+
export { default as setRedisCache } from './setRedisCache';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as deleteRedisCache } from './deleteRedisCache';
|
|
2
|
+
export { default as disconnectElastiCacheRedisClient } from './disconnectElastiCacheRedisClient';
|
|
3
|
+
export { default as getElastiCacheRedisClient } from './getElastiCacheRedisClient';
|
|
4
|
+
export { default as getRedisCache } from './getRedisCache';
|
|
5
|
+
export { default as setRedisCache } from './setRedisCache';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClientOptions } from '../../types/aws';
|
|
2
|
+
export interface SetRedisCacheOptions {
|
|
3
|
+
EX?: number;
|
|
4
|
+
}
|
|
5
|
+
declare const setRedisCache: (key: string, value: any, opts?: SetRedisCacheOptions, clientOpts?: ClientOptions) => Promise<"OK">;
|
|
6
|
+
export default setRedisCache;
|