lesgo 0.7.8 → 2.1.0
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 +52 -7
- 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 +36 -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/CHANGELOG.md +0 -9
- 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 -225
- package/src/middlewares/__tests__/clientAuthMiddleware.spec.js +0 -137
- package/src/middlewares/__tests__/errorHttpResponseMiddleware.spec.js +0 -190
- package/src/middlewares/__tests__/gzipHttpResponse.spec.js +0 -185
- package/src/middlewares/__tests__/httpNoOutputMiddleware.spec.js +0 -199
- package/src/middlewares/__tests__/normalizeHttpRequestMiddleware.spec.js +0 -181
- package/src/middlewares/__tests__/normalizeSQSMessageMiddleware.spec.js +0 -120
- package/src/middlewares/__tests__/serverAuthMiddleware.spec.js +0 -170
- package/src/middlewares/__tests__/successHttpResponseMiddleware.spec.js +0 -159
- package/src/middlewares/__tests__/verifyJwtMiddleware.spec.js +0 -222
- package/src/middlewares/basicAuthMiddleware.js +0 -145
- package/src/middlewares/clientAuthMiddleware.js +0 -82
- package/src/middlewares/errorHttpResponseMiddleware.js +0 -99
- package/src/middlewares/gzipHttpResponse.js +0 -98
- package/src/middlewares/httpMiddleware.js +0 -19
- package/src/middlewares/httpNoOutputMiddleware.js +0 -87
- package/src/middlewares/index.js +0 -15
- package/src/middlewares/normalizeHttpRequestMiddleware.js +0 -101
- package/src/middlewares/normalizeSQSMessageMiddleware.js +0 -67
- package/src/middlewares/serverAuthMiddleware.js +0 -29
- package/src/middlewares/successHttpResponseMiddleware.js +0 -83
- package/src/middlewares/verifyJwtMiddleware.js +0 -62
- 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 -252
- 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,71 @@
|
|
|
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 { SendMessageCommand } from '@aws-sdk/client-sqs';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger, validateFields } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getQueueUrl from './getQueueUrl';
|
|
39
|
+
const FILE = 'lesgo.services.SQSService.dispatch';
|
|
40
|
+
const dispatch = (payload, queue, opts, clientOpts) =>
|
|
41
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const queueUrl = getQueueUrl(queue);
|
|
43
|
+
const input = validateFields({ payload }, [
|
|
44
|
+
{ key: 'payload', type: 'object', required: true },
|
|
45
|
+
]);
|
|
46
|
+
const client = getClient(clientOpts);
|
|
47
|
+
const commandInput = Object.assign(
|
|
48
|
+
{ MessageBody: JSON.stringify(input.payload), QueueUrl: queueUrl },
|
|
49
|
+
opts
|
|
50
|
+
);
|
|
51
|
+
try {
|
|
52
|
+
const data = yield client.send(new SendMessageCommand(commandInput));
|
|
53
|
+
logger.debug(`${FILE}::MESSAGE_SENT_TO_QUEUE`, {
|
|
54
|
+
data,
|
|
55
|
+
commandInput,
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new LesgoException(
|
|
60
|
+
'Error occurred sending message to queue',
|
|
61
|
+
`${FILE}::SEND_MESSAGE_ERROR`,
|
|
62
|
+
500,
|
|
63
|
+
{
|
|
64
|
+
error,
|
|
65
|
+
commandInput,
|
|
66
|
+
opts,
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
export default dispatch;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SQSClient } from '@aws-sdk/client-sqs';
|
|
2
|
+
import { logger, isEmpty, validateFields } from '../../utils';
|
|
3
|
+
import { sqs as sqsConfig } from '../../config';
|
|
4
|
+
const FILE = 'lesgo.services.SQSService.getClient';
|
|
5
|
+
const singleton = {};
|
|
6
|
+
const getClient = (clientOpts = {}) => {
|
|
7
|
+
const options = validateFields(clientOpts, [
|
|
8
|
+
{ key: 'region', type: 'string', required: false },
|
|
9
|
+
{ key: 'singletonConn', type: 'string', required: false },
|
|
10
|
+
]);
|
|
11
|
+
const region = options.region || sqsConfig.region;
|
|
12
|
+
const singletonConn = options.singletonConn || 'default';
|
|
13
|
+
if (!isEmpty(singleton[singletonConn])) {
|
|
14
|
+
logger.debug(`${FILE}::REUSE_CLIENT_SINGLETON`, {
|
|
15
|
+
client: singleton[singletonConn],
|
|
16
|
+
region,
|
|
17
|
+
});
|
|
18
|
+
return singleton[singletonConn];
|
|
19
|
+
}
|
|
20
|
+
const client = new SQSClient({ region });
|
|
21
|
+
logger.debug(`${FILE}::NEW_CLIENT`, {
|
|
22
|
+
client,
|
|
23
|
+
region,
|
|
24
|
+
});
|
|
25
|
+
singleton[singletonConn] = client;
|
|
26
|
+
return client;
|
|
27
|
+
};
|
|
28
|
+
export default getClient;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LesgoException } from '../../exceptions';
|
|
2
|
+
import sqsConfig from '../../config/sqs';
|
|
3
|
+
const FILE = 'lesgo.services.SQSService.getQueueUrl';
|
|
4
|
+
export default queue => {
|
|
5
|
+
if (
|
|
6
|
+
typeof queue !== 'string' &&
|
|
7
|
+
'alias' in queue &&
|
|
8
|
+
'name' in queue &&
|
|
9
|
+
'url' in queue
|
|
10
|
+
) {
|
|
11
|
+
return queue.url;
|
|
12
|
+
}
|
|
13
|
+
const configQueue = sqsConfig.queues.find(q => q.alias === queue);
|
|
14
|
+
if (!configQueue) {
|
|
15
|
+
throw new LesgoException(
|
|
16
|
+
`Queue with alias ${queue} not found in config`,
|
|
17
|
+
`${FILE}::QUEUE_NOT_FOUND`,
|
|
18
|
+
404,
|
|
19
|
+
{
|
|
20
|
+
queue,
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return configQueue.url;
|
|
25
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReceiveMessageCommandInput } from '@aws-sdk/client-sqs';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
import { Queue } from './getQueueUrl';
|
|
4
|
+
export interface ReceiveMessagesOptions extends Partial<Omit<ReceiveMessageCommandInput, 'QueueUrl'>> {
|
|
5
|
+
QueueUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const receiveMessages: (queue: string | Queue, opts?: ReceiveMessagesOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-sqs").ReceiveMessageCommandOutput>;
|
|
8
|
+
export default receiveMessages;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { ReceiveMessageCommand } from '@aws-sdk/client-sqs';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getQueueUrl from './getQueueUrl';
|
|
39
|
+
const FILE = 'lesgo.services.SQSService.receiveMessages';
|
|
40
|
+
const receiveMessages = (queue, opts, clientOpts) =>
|
|
41
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const queueUrl = getQueueUrl(queue);
|
|
43
|
+
const client = getClient(clientOpts);
|
|
44
|
+
const commandInput = Object.assign({ QueueUrl: queueUrl }, opts);
|
|
45
|
+
try {
|
|
46
|
+
const data = yield client.send(new ReceiveMessageCommand(commandInput));
|
|
47
|
+
logger.debug(`${FILE}::MESSAGES_RECEIVED_FROM_QUEUE`, {
|
|
48
|
+
data,
|
|
49
|
+
commandInput,
|
|
50
|
+
});
|
|
51
|
+
return data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new LesgoException(
|
|
54
|
+
'Error occurred receiving messages from queue',
|
|
55
|
+
`${FILE}::RECEIVE_MESSAGES_ERROR`,
|
|
56
|
+
500,
|
|
57
|
+
{
|
|
58
|
+
error,
|
|
59
|
+
commandInput,
|
|
60
|
+
opts,
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
export default receiveMessages;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
export interface Singleton {
|
|
4
|
+
[key: string]: SecretsManagerClient;
|
|
5
|
+
}
|
|
6
|
+
declare const getClient: (clientOpts?: ClientOptions) => SecretsManagerClient;
|
|
7
|
+
export default getClient;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import { logger, isEmpty, validateFields } from '../../utils';
|
|
3
|
+
import { secretsmanager as secretsmanagerConfig } from '../../config';
|
|
4
|
+
const FILE = 'lesgo.services.SecretsManager.getClient';
|
|
5
|
+
const singleton = {};
|
|
6
|
+
const getClient = (clientOpts = {}) => {
|
|
7
|
+
const options = validateFields(clientOpts, [
|
|
8
|
+
{ key: 'region', type: 'string', required: false },
|
|
9
|
+
{ key: 'singletonConn', type: 'string', required: false },
|
|
10
|
+
]);
|
|
11
|
+
const region = options.region || secretsmanagerConfig.region;
|
|
12
|
+
const singletonConn = options.singletonConn || 'default';
|
|
13
|
+
if (!isEmpty(singleton[singletonConn])) {
|
|
14
|
+
logger.debug(`${FILE}::REUSE_CLIENT_SINGLETON`, {
|
|
15
|
+
singletonConn,
|
|
16
|
+
region,
|
|
17
|
+
});
|
|
18
|
+
return singleton[singletonConn];
|
|
19
|
+
}
|
|
20
|
+
const client = new SecretsManagerClient({ region });
|
|
21
|
+
logger.debug(`${FILE}::NEW_CLIENT`, {
|
|
22
|
+
singletonConn,
|
|
23
|
+
region,
|
|
24
|
+
});
|
|
25
|
+
singleton[singletonConn] = client;
|
|
26
|
+
return client;
|
|
27
|
+
};
|
|
28
|
+
export default getClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GetSecretValueCommandInput } from '@aws-sdk/client-secrets-manager';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
export type GetSecretValueOptions = Omit<GetSecretValueCommandInput, 'SecretId'> & {
|
|
4
|
+
SecretId?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const getSecretValue: (secretId: string, opts?: GetSecretValueOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-secrets-manager").GetSecretValueCommandOutput>;
|
|
7
|
+
export default getSecretValue;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger, validateFields } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
const FILE = 'lesgo.services.SecretsManager.getSecretValue';
|
|
39
|
+
const getSecretValue = (secretId, opts, clientOpts) =>
|
|
40
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const input = validateFields({ secretId }, [
|
|
42
|
+
{ key: 'secretId', type: 'string', required: true },
|
|
43
|
+
]);
|
|
44
|
+
const client = getClient(clientOpts);
|
|
45
|
+
const command = new GetSecretValueCommand(
|
|
46
|
+
Object.assign({ SecretId: input.secretId }, opts)
|
|
47
|
+
);
|
|
48
|
+
try {
|
|
49
|
+
const resp = yield client.send(command);
|
|
50
|
+
logger.debug(`${FILE}::RESPONSE`, { resp: '<REDACTED>', command });
|
|
51
|
+
return resp;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new LesgoException(
|
|
54
|
+
'Error occurred getting secret value from Secrets Manager',
|
|
55
|
+
`${FILE}::ERROR`,
|
|
56
|
+
500,
|
|
57
|
+
{
|
|
58
|
+
error,
|
|
59
|
+
command,
|
|
60
|
+
opts,
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
export default getSecretValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as LoggerService } from './LoggerService';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as LoggerService } from './LoggerService';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../types/aws';
|
|
2
|
+
/**
|
|
3
|
+
* Deletes the cache value from the Redis cache.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} key - The key of the cache value to delete.
|
|
6
|
+
* @param {ClientOptions} clientOpts - Optional client options for Redis connection.
|
|
7
|
+
* @returns A promise that resolves to the deleted cache value.
|
|
8
|
+
* @throws {LesgoException} If there is an error deleting the cache.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { deleteCache } from 'lesgo/utils/cache/redis';
|
|
13
|
+
*
|
|
14
|
+
* const key = 'myKey';
|
|
15
|
+
*
|
|
16
|
+
* await deleteCache(key);
|
|
17
|
+
*/
|
|
18
|
+
declare const getCache: (key: string, clientOpts?: ClientOptions) => Promise<number>;
|
|
19
|
+
export default getCache;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { deleteRedisCache } from '../../../services/ElastiCacheRedisService';
|
|
2
|
+
/**
|
|
3
|
+
* Deletes the cache value from the Redis cache.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} key - The key of the cache value to delete.
|
|
6
|
+
* @param {ClientOptions} clientOpts - Optional client options for Redis connection.
|
|
7
|
+
* @returns A promise that resolves to the deleted cache value.
|
|
8
|
+
* @throws {LesgoException} If there is an error deleting the cache.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { deleteCache } from 'lesgo/utils/cache/redis';
|
|
13
|
+
*
|
|
14
|
+
* const key = 'myKey';
|
|
15
|
+
*
|
|
16
|
+
* await deleteCache(key);
|
|
17
|
+
*/
|
|
18
|
+
const getCache = (key, clientOpts) => {
|
|
19
|
+
return deleteRedisCache(key, clientOpts);
|
|
20
|
+
};
|
|
21
|
+
export default getCache;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../types/aws';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the value from the cache based on the provided key.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} key - The key used to identify the value in the cache.
|
|
6
|
+
* @param {ClientOptions} clientOpts - Optional client options for the cache client.
|
|
7
|
+
* @returns A promise that resolves when the value is retrieved from the cache.
|
|
8
|
+
*
|
|
9
|
+
* @throws {LesgoException} If there is an error retrieving the cache.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getCache } from 'lesgo/utils/cache/redis';
|
|
14
|
+
*
|
|
15
|
+
* const key = 'myKey';
|
|
16
|
+
*
|
|
17
|
+
* const value = await getCache(key);
|
|
18
|
+
* console.log(value); // Value retrieved from the cache
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const getCache: (key: string, clientOpts?: ClientOptions) => Promise<any>;
|
|
22
|
+
export default getCache;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getRedisCache } from '../../../services/ElastiCacheRedisService';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the value from the cache based on the provided key.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} key - The key used to identify the value in the cache.
|
|
6
|
+
* @param {ClientOptions} clientOpts - Optional client options for the cache client.
|
|
7
|
+
* @returns A promise that resolves when the value is retrieved from the cache.
|
|
8
|
+
*
|
|
9
|
+
* @throws {LesgoException} If there is an error retrieving the cache.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getCache } from 'lesgo/utils/cache/redis';
|
|
14
|
+
*
|
|
15
|
+
* const key = 'myKey';
|
|
16
|
+
*
|
|
17
|
+
* const value = await getCache(key);
|
|
18
|
+
* console.log(value); // Value retrieved from the cache
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const getCache = (key, clientOpts) => {
|
|
22
|
+
return getRedisCache(key, clientOpts);
|
|
23
|
+
};
|
|
24
|
+
export default getCache;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../types/aws';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a Redis client.
|
|
4
|
+
*
|
|
5
|
+
* This function will return a Redis client that is connected to the ElastiCache Redis cluster.
|
|
6
|
+
* A new client will be created if one does not already exist. The client will be reused if it is already connected.
|
|
7
|
+
* This is useful if you need to use the Redis Client functions directly.
|
|
8
|
+
*
|
|
9
|
+
* This function is not intended to be used directly.
|
|
10
|
+
* Use the available `getCache`, `setCache`, and `deleteCache` functions instead.
|
|
11
|
+
*
|
|
12
|
+
* @param {ClientOptions} clientOpts - Optional client options.
|
|
13
|
+
* @returns A promise of with Redis client.
|
|
14
|
+
*
|
|
15
|
+
* @throws {LesgoException} If there is an error creating the client.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { getClient } from 'lesgo/utils/cache/redis';
|
|
20
|
+
*
|
|
21
|
+
* const client = await getClient();
|
|
22
|
+
*
|
|
23
|
+
* const key = 'myKey';
|
|
24
|
+
* const value = 'myValue';
|
|
25
|
+
*
|
|
26
|
+
* await client.set(key, value);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare const getClient: (clientOpts?: ClientOptions) => Promise<import("ioredis/built/cluster").default>;
|
|
30
|
+
export default getClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getElastiCacheRedisClient } from '../../../services/ElastiCacheRedisService';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves a Redis client.
|
|
4
|
+
*
|
|
5
|
+
* This function will return a Redis client that is connected to the ElastiCache Redis cluster.
|
|
6
|
+
* A new client will be created if one does not already exist. The client will be reused if it is already connected.
|
|
7
|
+
* This is useful if you need to use the Redis Client functions directly.
|
|
8
|
+
*
|
|
9
|
+
* This function is not intended to be used directly.
|
|
10
|
+
* Use the available `getCache`, `setCache`, and `deleteCache` functions instead.
|
|
11
|
+
*
|
|
12
|
+
* @param {ClientOptions} clientOpts - Optional client options.
|
|
13
|
+
* @returns A promise of with Redis client.
|
|
14
|
+
*
|
|
15
|
+
* @throws {LesgoException} If there is an error creating the client.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { getClient } from 'lesgo/utils/cache/redis';
|
|
20
|
+
*
|
|
21
|
+
* const client = await getClient();
|
|
22
|
+
*
|
|
23
|
+
* const key = 'myKey';
|
|
24
|
+
* const value = 'myValue';
|
|
25
|
+
*
|
|
26
|
+
* await client.set(key, value);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const getClient = clientOpts => {
|
|
30
|
+
return getElastiCacheRedisClient(clientOpts);
|
|
31
|
+
};
|
|
32
|
+
export default getClient;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../types/aws';
|
|
2
|
+
import { SetRedisCacheOptions } from '../../../services/ElastiCacheRedisService/setRedisCache';
|
|
3
|
+
/**
|
|
4
|
+
* Sets a value in the Redis cache.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} key - The key to set in the cache.
|
|
7
|
+
* @param {any} value - The value to set in the cache.
|
|
8
|
+
* @param {SetRedisCacheOptions} opts - Optional settings for setting the cache.
|
|
9
|
+
* @param {ClientOptions} clientOpts - Optional client options for connecting to Redis.
|
|
10
|
+
* @returns A promise that resolves when the value is successfully set in the cache.
|
|
11
|
+
*
|
|
12
|
+
* @throws {LesgoException} If there is an error setting the cache.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { setCache } from 'lesgo/utils/cache/redis';
|
|
17
|
+
*
|
|
18
|
+
* const key = 'myKey';
|
|
19
|
+
* const value = 'myValue';
|
|
20
|
+
*
|
|
21
|
+
* await setCache(key, value);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare const setCache: (key: string, value: any, opts?: SetRedisCacheOptions, clientOpts?: ClientOptions) => Promise<"OK">;
|
|
25
|
+
export default setCache;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setRedisCache } from '../../../services/ElastiCacheRedisService';
|
|
2
|
+
/**
|
|
3
|
+
* Sets a value in the Redis cache.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} key - The key to set in the cache.
|
|
6
|
+
* @param {any} value - The value to set in the cache.
|
|
7
|
+
* @param {SetRedisCacheOptions} opts - Optional settings for setting the cache.
|
|
8
|
+
* @param {ClientOptions} clientOpts - Optional client options for connecting to Redis.
|
|
9
|
+
* @returns A promise that resolves when the value is successfully set in the cache.
|
|
10
|
+
*
|
|
11
|
+
* @throws {LesgoException} If there is an error setting the cache.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { setCache } from 'lesgo/utils/cache/redis';
|
|
16
|
+
*
|
|
17
|
+
* const key = 'myKey';
|
|
18
|
+
* const value = 'myValue';
|
|
19
|
+
*
|
|
20
|
+
* await setCache(key, value);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const setCache = (key, value, opts, clientOpts) => {
|
|
24
|
+
return setRedisCache(key, value, opts, clientOpts);
|
|
25
|
+
};
|
|
26
|
+
export default setCache;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EncryptionAlgorithm } from './validateEncryptionFields';
|
|
2
|
+
export interface DecryptOptions {
|
|
3
|
+
algorithm?: EncryptionAlgorithm;
|
|
4
|
+
secretKey?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Decrypts the given encrypted text.
|
|
8
|
+
*
|
|
9
|
+
* @param text - The encrypted text to be decrypted.
|
|
10
|
+
* @param opts - Optional decryption options.
|
|
11
|
+
* @returns The decrypted text.
|
|
12
|
+
*
|
|
13
|
+
* @throws {LesgoException} If there is an error decrypting the text.
|
|
14
|
+
* @throws {LesgoException} If the text is not a string.
|
|
15
|
+
* @throws {LesgoException} If the text is not encrypted.
|
|
16
|
+
* @throws {LesgoException} If the algorithm is not valid.
|
|
17
|
+
* @throws {LesgoException} If the secret key is not valid.
|
|
18
|
+
* @throws {LesgoException} If the secret key is not provided.
|
|
19
|
+
* @throws {LesgoException} If the algorithm is not provided.
|
|
20
|
+
* @throws {LesgoException} If the text is not provided.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { decrypt } from 'lesgo/utils/crypto';
|
|
25
|
+
*
|
|
26
|
+
* const encryptedText = 'encryptedText';
|
|
27
|
+
*
|
|
28
|
+
* const decryptedText = decrypt(encryptedText);
|
|
29
|
+
* console.log(decryptedText); // Decrypted text
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare const decrypt: (text: string, opts?: DecryptOptions) => string;
|
|
33
|
+
export default decrypt;
|