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,59 @@
|
|
|
1
|
+
import { createDecipheriv } from 'crypto';
|
|
2
|
+
import cryptoConfig from '../../config/crypto';
|
|
3
|
+
import {
|
|
4
|
+
validateEncryptionAlgorithm,
|
|
5
|
+
validateSecretKey,
|
|
6
|
+
} from './validateEncryptionFields';
|
|
7
|
+
import logger from '../logger';
|
|
8
|
+
import validateFields from '../validateFields';
|
|
9
|
+
const FILE = 'lesgo.utils.crypto.decrypt';
|
|
10
|
+
/**
|
|
11
|
+
* Decrypts the given encrypted text.
|
|
12
|
+
*
|
|
13
|
+
* @param text - The encrypted text to be decrypted.
|
|
14
|
+
* @param opts - Optional decryption options.
|
|
15
|
+
* @returns The decrypted text.
|
|
16
|
+
*
|
|
17
|
+
* @throws {LesgoException} If there is an error decrypting the text.
|
|
18
|
+
* @throws {LesgoException} If the text is not a string.
|
|
19
|
+
* @throws {LesgoException} If the text is not encrypted.
|
|
20
|
+
* @throws {LesgoException} If the algorithm is not valid.
|
|
21
|
+
* @throws {LesgoException} If the secret key is not valid.
|
|
22
|
+
* @throws {LesgoException} If the secret key is not provided.
|
|
23
|
+
* @throws {LesgoException} If the algorithm is not provided.
|
|
24
|
+
* @throws {LesgoException} If the text is not provided.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { decrypt } from 'lesgo/utils/crypto';
|
|
29
|
+
*
|
|
30
|
+
* const encryptedText = 'encryptedText';
|
|
31
|
+
*
|
|
32
|
+
* const decryptedText = decrypt(encryptedText);
|
|
33
|
+
* console.log(decryptedText); // Decrypted text
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const decrypt = (text, opts) => {
|
|
37
|
+
logger.debug(`${FILE}::DECRYPT`, { text });
|
|
38
|
+
const input = validateFields({ text }, [
|
|
39
|
+
{ key: 'text', type: 'string', required: true },
|
|
40
|
+
]);
|
|
41
|
+
const validAlgorithm =
|
|
42
|
+
(opts === null || opts === void 0 ? void 0 : opts.algorithm) ||
|
|
43
|
+
cryptoConfig.encryption.algorithm;
|
|
44
|
+
const validSecretKey =
|
|
45
|
+
(opts === null || opts === void 0 ? void 0 : opts.secretKey) ||
|
|
46
|
+
cryptoConfig.encryption.secretKey;
|
|
47
|
+
validateEncryptionAlgorithm(validAlgorithm);
|
|
48
|
+
validateSecretKey(validSecretKey, validAlgorithm);
|
|
49
|
+
const textParts = input.text.split(':');
|
|
50
|
+
const iv = Buffer.from(textParts.shift() || '', 'hex');
|
|
51
|
+
const encryptedText = Buffer.from(textParts.join(':'), 'hex');
|
|
52
|
+
const decipher = createDecipheriv(validAlgorithm, validSecretKey, iv);
|
|
53
|
+
let decrypted = decipher.update(encryptedText);
|
|
54
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
55
|
+
const decryptedText = decrypted.toString();
|
|
56
|
+
logger.debug(`${FILE}::DECRYPTED_TEXT`, { decryptedText });
|
|
57
|
+
return decryptedText;
|
|
58
|
+
};
|
|
59
|
+
export default decrypt;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EncryptionAlgorithm } from './validateEncryptionFields';
|
|
2
|
+
export interface EncryptOptions {
|
|
3
|
+
algorithm?: EncryptionAlgorithm;
|
|
4
|
+
secretKey?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts the given text using the specified options.
|
|
8
|
+
*
|
|
9
|
+
* @param text - The text to be encrypted.
|
|
10
|
+
* @param opts - Optional encryption options.
|
|
11
|
+
* @returns The encrypted text.
|
|
12
|
+
*
|
|
13
|
+
* @throws {LesgoException} If there is an error encrypting the text.
|
|
14
|
+
* @throws {LesgoException} If the text is not a string.
|
|
15
|
+
* @throws {LesgoException} If the algorithm is not valid.
|
|
16
|
+
* @throws {LesgoException} If the secret key is not valid.
|
|
17
|
+
* @throws {LesgoException} If the secret key is not provided.
|
|
18
|
+
* @throws {LesgoException} If the algorithm is not provided.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { encrypt } from 'lesgo/utils/crypto';
|
|
23
|
+
*
|
|
24
|
+
* const text = 'myText';
|
|
25
|
+
*
|
|
26
|
+
* const encryptedText = encrypt(text);
|
|
27
|
+
* console.log(encryptedText); // Encrypted text
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const encrypt: (text: string, opts?: EncryptOptions) => string;
|
|
31
|
+
export default encrypt;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { randomBytes, createCipheriv } from 'crypto';
|
|
2
|
+
import validateEncryptionFields from './validateEncryptionFields';
|
|
3
|
+
import logger from '../logger';
|
|
4
|
+
const FILE = 'lesgo.utils.crypto.encrypt';
|
|
5
|
+
/**
|
|
6
|
+
* Encrypts the given text using the specified options.
|
|
7
|
+
*
|
|
8
|
+
* @param text - The text to be encrypted.
|
|
9
|
+
* @param opts - Optional encryption options.
|
|
10
|
+
* @returns The encrypted text.
|
|
11
|
+
*
|
|
12
|
+
* @throws {LesgoException} If there is an error encrypting the text.
|
|
13
|
+
* @throws {LesgoException} If the text is not a string.
|
|
14
|
+
* @throws {LesgoException} If the algorithm is not valid.
|
|
15
|
+
* @throws {LesgoException} If the secret key is not valid.
|
|
16
|
+
* @throws {LesgoException} If the secret key is not provided.
|
|
17
|
+
* @throws {LesgoException} If the algorithm is not provided.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { encrypt } from 'lesgo/utils/crypto';
|
|
22
|
+
*
|
|
23
|
+
* const text = 'myText';
|
|
24
|
+
*
|
|
25
|
+
* const encryptedText = encrypt(text);
|
|
26
|
+
* console.log(encryptedText); // Encrypted text
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const encrypt = (text, opts) => {
|
|
30
|
+
logger.debug(`${FILE}::ENCRYPT`, { text });
|
|
31
|
+
const { validText, validAlgorithm, validIvLength, validSecretKey } =
|
|
32
|
+
validateEncryptionFields(text, opts);
|
|
33
|
+
const iv = randomBytes(validIvLength);
|
|
34
|
+
const cipher = createCipheriv(validAlgorithm, validSecretKey, iv);
|
|
35
|
+
let encrypted = cipher.update(validText);
|
|
36
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
37
|
+
const encryptedText = `${iv.toString('hex')}:${encrypted.toString('hex')}`;
|
|
38
|
+
logger.debug(`${FILE}::ENCRYPTED_TEXT`, { encryptedText });
|
|
39
|
+
return encryptedText;
|
|
40
|
+
};
|
|
41
|
+
export default encrypt;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type HashAlgorithm = 'md5' | 'sha256' | 'sha512';
|
|
2
|
+
export interface HashOptions {
|
|
3
|
+
algorithm?: HashAlgorithm;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the hash value of the given data using the specified algorithm.
|
|
7
|
+
*
|
|
8
|
+
* @param data - The data to be hashed.
|
|
9
|
+
* @param opts - Optional configuration for the hash algorithm.
|
|
10
|
+
* @returns The hashed value as a string.
|
|
11
|
+
*
|
|
12
|
+
* @throws {LesgoException} if an invalid hash algorithm is supplied.
|
|
13
|
+
* @throws {LesgoException} if the data is not a string.
|
|
14
|
+
* @throws {LesgoException} if the data is not provided.
|
|
15
|
+
* @throws {LesgoException} if the algorithm is not provided.
|
|
16
|
+
* @throws {LesgoException} if the algorithm is not valid.
|
|
17
|
+
* @throws {LesgoException} if the algorithm is not a string.
|
|
18
|
+
* @throws {LesgoException} if the algorithm is not a valid hash algorithm.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { hash } from 'lesgo/utils/crypto';
|
|
23
|
+
*
|
|
24
|
+
* const data = 'myData';
|
|
25
|
+
*
|
|
26
|
+
* const hashedValue = hash(data);
|
|
27
|
+
* console.log(hashedValue); // Hashed value
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const hash: (data: string, opts?: HashOptions) => string;
|
|
31
|
+
export default hash;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { crypto as cryptoConfig } from '../../config';
|
|
3
|
+
import validateFields from '../validateFields';
|
|
4
|
+
import { LesgoException } from '../../exceptions';
|
|
5
|
+
const FILE = 'lesgo.utils.crypto.hash';
|
|
6
|
+
const isHashAlgorithm = algorithm => {
|
|
7
|
+
return ['md5', 'sha256', 'sha512'].includes(algorithm);
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the hash value of the given data using the specified algorithm.
|
|
11
|
+
*
|
|
12
|
+
* @param data - The data to be hashed.
|
|
13
|
+
* @param opts - Optional configuration for the hash algorithm.
|
|
14
|
+
* @returns The hashed value as a string.
|
|
15
|
+
*
|
|
16
|
+
* @throws {LesgoException} if an invalid hash algorithm is supplied.
|
|
17
|
+
* @throws {LesgoException} if the data is not a string.
|
|
18
|
+
* @throws {LesgoException} if the data is not provided.
|
|
19
|
+
* @throws {LesgoException} if the algorithm is not provided.
|
|
20
|
+
* @throws {LesgoException} if the algorithm is not valid.
|
|
21
|
+
* @throws {LesgoException} if the algorithm is not a string.
|
|
22
|
+
* @throws {LesgoException} if the algorithm is not a valid hash algorithm.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { hash } from 'lesgo/utils/crypto';
|
|
27
|
+
*
|
|
28
|
+
* const data = 'myData';
|
|
29
|
+
*
|
|
30
|
+
* const hashedValue = hash(data);
|
|
31
|
+
* console.log(hashedValue); // Hashed value
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const hash = (data, opts) => {
|
|
35
|
+
const input = validateFields({ data }, [
|
|
36
|
+
{ key: 'data', type: 'string', required: true },
|
|
37
|
+
]);
|
|
38
|
+
const algorithmSupplied =
|
|
39
|
+
(opts === null || opts === void 0 ? void 0 : opts.algorithm) ||
|
|
40
|
+
cryptoConfig.hash.algorithm;
|
|
41
|
+
if (!isHashAlgorithm(algorithmSupplied)) {
|
|
42
|
+
throw new LesgoException(
|
|
43
|
+
'Invalid hash algorithm supplied',
|
|
44
|
+
`${FILE}::ERROR_INVALID_HASH_ALGORITHM`,
|
|
45
|
+
500,
|
|
46
|
+
{
|
|
47
|
+
algorithmSupplied,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const hashedValue = createHash(algorithmSupplied)
|
|
52
|
+
.update(input.data)
|
|
53
|
+
.digest('hex');
|
|
54
|
+
return hashedValue;
|
|
55
|
+
};
|
|
56
|
+
export default hash;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare enum EncryptionAlgorithm {
|
|
2
|
+
AES128 = "aes-128-cbc",
|
|
3
|
+
AES192 = "aes-192-cbc",
|
|
4
|
+
AES256 = "aes-256-cbc",
|
|
5
|
+
AES512 = "aes-512-cbc"
|
|
6
|
+
}
|
|
7
|
+
interface ValidateEncryptionFieldsOptions {
|
|
8
|
+
algorithm?: EncryptionAlgorithm;
|
|
9
|
+
secretKey?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const validateEncryptionAlgorithm: (algorithm: EncryptionAlgorithm) => void;
|
|
12
|
+
export declare const validateSecretKey: (secretKey?: string, algorithm?: EncryptionAlgorithm) => void;
|
|
13
|
+
declare const validateEncryptionFields: (text: string, opts?: ValidateEncryptionFieldsOptions) => {
|
|
14
|
+
validText: any;
|
|
15
|
+
validAlgorithm: EncryptionAlgorithm;
|
|
16
|
+
validSecretKey: string;
|
|
17
|
+
validIvLength: number;
|
|
18
|
+
};
|
|
19
|
+
export default validateEncryptionFields;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { LesgoException } from '../../exceptions';
|
|
2
|
+
import cryptoConfig from '../../config/crypto';
|
|
3
|
+
import validateFields from '../validateFields';
|
|
4
|
+
export var EncryptionAlgorithm;
|
|
5
|
+
(function (EncryptionAlgorithm) {
|
|
6
|
+
EncryptionAlgorithm['AES128'] = 'aes-128-cbc';
|
|
7
|
+
EncryptionAlgorithm['AES192'] = 'aes-192-cbc';
|
|
8
|
+
EncryptionAlgorithm['AES256'] = 'aes-256-cbc';
|
|
9
|
+
EncryptionAlgorithm['AES512'] = 'aes-512-cbc';
|
|
10
|
+
})(EncryptionAlgorithm || (EncryptionAlgorithm = {}));
|
|
11
|
+
const FILE = 'lesgo.utils.crypto.validateEncryptionFields';
|
|
12
|
+
export const validateEncryptionAlgorithm = algorithm => {
|
|
13
|
+
const input = validateFields({ algorithm }, [
|
|
14
|
+
{ key: 'algorithm', type: 'string', required: true },
|
|
15
|
+
]);
|
|
16
|
+
if (!Object.values(EncryptionAlgorithm).includes(input.algorithm)) {
|
|
17
|
+
throw new LesgoException(
|
|
18
|
+
'Invalid encryption algorithm supplied',
|
|
19
|
+
`${FILE}::ERROR_INVALID_ENCRYPTION_ALGORITHM`,
|
|
20
|
+
500,
|
|
21
|
+
{
|
|
22
|
+
algorithm,
|
|
23
|
+
allowedAlgorithms: Object.values(EncryptionAlgorithm),
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const validateSecretKey = (secretKey, algorithm) => {
|
|
29
|
+
const keyLengths = {
|
|
30
|
+
'aes-128-cbc': 16,
|
|
31
|
+
'aes-192-cbc': 24,
|
|
32
|
+
'aes-256-cbc': 32,
|
|
33
|
+
'aes-512-cbc': 64,
|
|
34
|
+
};
|
|
35
|
+
const input = validateFields({ secretKey, algorithm }, [
|
|
36
|
+
{ key: 'algorithm', type: 'string', required: true },
|
|
37
|
+
{ key: 'secretKey', type: 'string', required: true },
|
|
38
|
+
]);
|
|
39
|
+
const keyLength = keyLengths[input.algorithm];
|
|
40
|
+
if (!keyLength) {
|
|
41
|
+
throw new LesgoException(
|
|
42
|
+
`Invalid secret key length for ${input.algorithm}`,
|
|
43
|
+
`${FILE}::ERROR_INVALID_SECRET_KEY_LENGTH`,
|
|
44
|
+
500,
|
|
45
|
+
{
|
|
46
|
+
secretKey,
|
|
47
|
+
keyLength,
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const validateEncryptionFields = (text, opts) => {
|
|
53
|
+
const input = validateFields({ text }, [
|
|
54
|
+
{ key: 'text', type: 'string', required: true },
|
|
55
|
+
]);
|
|
56
|
+
const algorithmSupplied =
|
|
57
|
+
(opts === null || opts === void 0 ? void 0 : opts.algorithm) ||
|
|
58
|
+
cryptoConfig.encryption.algorithm;
|
|
59
|
+
const secretKeySupplied =
|
|
60
|
+
(opts === null || opts === void 0 ? void 0 : opts.secretKey) ||
|
|
61
|
+
cryptoConfig.encryption.secretKey;
|
|
62
|
+
validateEncryptionAlgorithm(algorithmSupplied);
|
|
63
|
+
validateSecretKey(secretKeySupplied, algorithmSupplied);
|
|
64
|
+
return {
|
|
65
|
+
validText: input.text,
|
|
66
|
+
validAlgorithm: algorithmSupplied,
|
|
67
|
+
validSecretKey: secretKeySupplied,
|
|
68
|
+
validIvLength: 16,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export default validateEncryptionFields;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ConnectionOptions } from 'mysql2/promise';
|
|
2
|
+
import { RDSAuroraMySQLProxyClientOptions } from '../../../../types/aws';
|
|
3
|
+
declare const getClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<import("mysql2/promise").Connection>;
|
|
4
|
+
export default getClient;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ConnectionOptions } from 'mysql2/promise';
|
|
2
|
+
import { RDSAuroraMySQLProxyClientOptions } from '../../../../types/aws';
|
|
3
|
+
declare const query: (sql: string, preparedValues?: any[], connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<import("mysql2/promise").QueryResult>;
|
|
4
|
+
export default query;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 queryService from '../../../../services/RDSAuroraMySQLProxyService/query';
|
|
35
|
+
const query = (sql, preparedValues, connOptions, clientOpts) =>
|
|
36
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const [res] = yield queryService(
|
|
38
|
+
sql,
|
|
39
|
+
preparedValues,
|
|
40
|
+
connOptions,
|
|
41
|
+
clientOpts
|
|
42
|
+
);
|
|
43
|
+
return res;
|
|
44
|
+
});
|
|
45
|
+
export default query;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ClientOptions } from '../../types/aws';
|
|
2
|
+
import { Key } from '../../services/DynamoDbService/deleteRecord';
|
|
3
|
+
import { DeleteCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
4
|
+
declare const deleteRecord: (key: Key, tableAlias: string, opts?: DeleteCommandInput, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
|
|
5
|
+
export default deleteRecord;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 deleteRecordService from '../../services/DynamoDbService/deleteRecord';
|
|
35
|
+
const deleteRecord = (key, tableAlias, opts, clientOpts) =>
|
|
36
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
return deleteRecordService(key, tableAlias, opts, clientOpts);
|
|
38
|
+
});
|
|
39
|
+
export default deleteRecord;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as deleteRecord } from './deleteRecord';
|
|
2
|
+
export { default as getClient } from './getClient';
|
|
3
|
+
export { default as putRecord } from './putRecord';
|
|
4
|
+
export { default as query } from './query';
|
|
5
|
+
export { default as scan } from './scan';
|
|
6
|
+
export { default as updateRecord } from './updateRecord';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as deleteRecord } from './deleteRecord';
|
|
2
|
+
export { default as getClient } from './getClient';
|
|
3
|
+
export { default as putRecord } from './putRecord';
|
|
4
|
+
export { default as query } from './query';
|
|
5
|
+
export { default as scan } from './scan';
|
|
6
|
+
export { default as updateRecord } from './updateRecord';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ClientOptions } from '../../types/aws';
|
|
2
|
+
import { Item, PutRecordOptions } from '../../services/DynamoDbService/putRecord';
|
|
3
|
+
declare const putRecord: (item: Item, tableAlias: string, opts?: PutRecordOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput>;
|
|
4
|
+
export default putRecord;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 putRecordService from '../../services/DynamoDbService/putRecord';
|
|
35
|
+
const putRecord = (item, tableAlias, opts, clientOpts) =>
|
|
36
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
return putRecordService(item, tableAlias, opts, clientOpts);
|
|
38
|
+
});
|
|
39
|
+
export default putRecord;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ClientOptions } from '../../types/aws';
|
|
2
|
+
import { QueryOptions } from '../../services/DynamoDbService/query';
|
|
3
|
+
import { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
|
|
4
|
+
export declare const query: (tableAlias: string, keyConditionExpression: string, expressionAttributeValues: Record<string, NativeAttributeValue>, opts?: QueryOptions, clientOpts?: ClientOptions) => Promise<Record<string, any>[]>;
|
|
5
|
+
export default query;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 queryService from '../../services/DynamoDbService/query';
|
|
35
|
+
export const query = (
|
|
36
|
+
tableAlias,
|
|
37
|
+
keyConditionExpression,
|
|
38
|
+
expressionAttributeValues,
|
|
39
|
+
opts,
|
|
40
|
+
clientOpts
|
|
41
|
+
) =>
|
|
42
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const data = yield queryService(
|
|
44
|
+
tableAlias,
|
|
45
|
+
keyConditionExpression,
|
|
46
|
+
expressionAttributeValues,
|
|
47
|
+
opts,
|
|
48
|
+
clientOpts
|
|
49
|
+
);
|
|
50
|
+
return (data === null || data === void 0 ? void 0 : data.Items) || [];
|
|
51
|
+
});
|
|
52
|
+
export default query;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 scanService from '../../services/DynamoDbService/scan';
|
|
35
|
+
export const scan = (tableAlias, opts, clientOpts) =>
|
|
36
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const data = yield scanService(tableAlias, opts, clientOpts);
|
|
38
|
+
return (data === null || data === void 0 ? void 0 : data.Items) || [];
|
|
39
|
+
});
|
|
40
|
+
export default scan;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ClientOptions } from '../../types/aws';
|
|
2
|
+
import { Key, UpdateRecordOptions } from '../../services/DynamoDbService/updateRecord';
|
|
3
|
+
import { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
|
|
4
|
+
export declare const updateRecord: (key: Key, tableAlias: string, updateExpression: string, expressionAttributeValues: Record<string, NativeAttributeValue>, opts?: UpdateRecordOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
|
|
5
|
+
export default updateRecord;
|