lesgo 1.0.0 → 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 +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
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create the utility that sends signed request
|
|
3
|
-
*
|
|
4
|
-
* @ref
|
|
5
|
-
* https://github.com/guardian/aws-signed-request
|
|
6
|
-
* https://github.com/TheDeveloper/http-aws-es
|
|
7
|
-
* https://github.com/elastic/elasticsearch-js
|
|
8
|
-
*
|
|
9
|
-
* @param {aws-sdk} AWS sdk
|
|
10
|
-
* @param {Object} config Configuration containing
|
|
11
|
-
* * endpoint: AWS endpoint
|
|
12
|
-
* * region: AWS region
|
|
13
|
-
* * service: AWS service
|
|
14
|
-
* * rawResponse: Will return rawResponse from httprequest
|
|
15
|
-
* * awsCreds: Aws crendential to use. default to AWS default
|
|
16
|
-
* * region: AWS region
|
|
17
|
-
* @return {Object} Utility with method `send`
|
|
18
|
-
*/
|
|
19
|
-
let AWS;
|
|
20
|
-
let awsEndpoint;
|
|
21
|
-
let awsCreds;
|
|
22
|
-
let service;
|
|
23
|
-
let region;
|
|
24
|
-
|
|
25
|
-
const initialize = (aws, config) => {
|
|
26
|
-
AWS = aws;
|
|
27
|
-
awsEndpoint = new AWS.Endpoint(config.endpoint);
|
|
28
|
-
awsCreds = config.awsCreds || new AWS.EnvironmentCredentials('AWS');
|
|
29
|
-
service = config.service;
|
|
30
|
-
region = config.region;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const handleSuccess = (httpResp, asPlainText, callback) => {
|
|
34
|
-
let respBody = '';
|
|
35
|
-
httpResp.on('data', chunk => {
|
|
36
|
-
respBody += chunk;
|
|
37
|
-
});
|
|
38
|
-
httpResp.on('end', () => {
|
|
39
|
-
if (httpResp.statusCode >= 200 && httpResp.statusCode < 400) {
|
|
40
|
-
if (asPlainText) {
|
|
41
|
-
process.nextTick(() => {
|
|
42
|
-
callback(null, respBody);
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
try {
|
|
46
|
-
const parsedRespBody = JSON.parse(respBody);
|
|
47
|
-
process.nextTick(() => {
|
|
48
|
-
callback(null, parsedRespBody);
|
|
49
|
-
});
|
|
50
|
-
} catch (ex) {
|
|
51
|
-
const error = new Error('Invalid JSON response');
|
|
52
|
-
error.responseText = respBody;
|
|
53
|
-
process.nextTick(() => {
|
|
54
|
-
callback(error);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
let errorMessage;
|
|
60
|
-
try {
|
|
61
|
-
const errorResponse = JSON.parse(respBody);
|
|
62
|
-
errorMessage = errorResponse.Message;
|
|
63
|
-
} catch (ex) {
|
|
64
|
-
errorMessage = respBody;
|
|
65
|
-
}
|
|
66
|
-
process.nextTick(() => {
|
|
67
|
-
const error = new Error(errorMessage);
|
|
68
|
-
error.responseText = respBody;
|
|
69
|
-
callback(error);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const handleFail = (err, callback) => {
|
|
76
|
-
const error = typeof err === 'string' ? new Error(err) : err;
|
|
77
|
-
process.nextTick(() => {
|
|
78
|
-
callback(error);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const sendRequest = (params, callback) => {
|
|
83
|
-
const req = new AWS.HttpRequest(awsEndpoint);
|
|
84
|
-
const rawResponse = params.rawResponse || false;
|
|
85
|
-
|
|
86
|
-
req.method = params.method.toUpperCase();
|
|
87
|
-
req.path = params.path;
|
|
88
|
-
req.region = region;
|
|
89
|
-
req.headers = params.headers || {};
|
|
90
|
-
req.headers['presigned-expires'] = false;
|
|
91
|
-
req.headers.Host = awsEndpoint.host;
|
|
92
|
-
|
|
93
|
-
if (params.message) {
|
|
94
|
-
req.body =
|
|
95
|
-
typeof params.message === 'string'
|
|
96
|
-
? params.message
|
|
97
|
-
: JSON.stringify(params.message);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const signer = new AWS.Signers.V4(req, service);
|
|
101
|
-
signer.addAuthorization(awsCreds, new Date());
|
|
102
|
-
|
|
103
|
-
const send = new AWS.NodeHttpClient();
|
|
104
|
-
send.handleRequest(
|
|
105
|
-
req,
|
|
106
|
-
AWS.config.httpOptions,
|
|
107
|
-
/* istanbul ignore next */
|
|
108
|
-
httpResp => {
|
|
109
|
-
// eslint-disable-next-line no-unused-expressions
|
|
110
|
-
rawResponse
|
|
111
|
-
? callback(null, httpResp)
|
|
112
|
-
: handleSuccess(httpResp, params.json === false, callback);
|
|
113
|
-
},
|
|
114
|
-
/* istanbul ignore next */
|
|
115
|
-
err => {
|
|
116
|
-
// eslint-disable-next-line no-unused-expressions
|
|
117
|
-
rawResponse ? callback(err) : handleFail(err, callback);
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const signedRequest = (aws, config) => {
|
|
123
|
-
initialize(aws, config);
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
/**
|
|
127
|
-
* Send a request
|
|
128
|
-
* @param {Object} params Object containing
|
|
129
|
-
* * method: HTTP method (e.g GET, POST)
|
|
130
|
-
* * path: Request path (e.g. '/_cat/indices')
|
|
131
|
-
* * message: Request body (String or JSON)
|
|
132
|
-
* * json: Boolean, whether the response from the server should be parsed as JSON
|
|
133
|
-
* @return {[type]} [description]
|
|
134
|
-
*/
|
|
135
|
-
send(params, callback) {
|
|
136
|
-
if (!params) {
|
|
137
|
-
process.nextTick(() => {
|
|
138
|
-
callback(new TypeError('Missing or invalid parameters'));
|
|
139
|
-
});
|
|
140
|
-
} else if (!params.method) {
|
|
141
|
-
process.nextTick(() => {
|
|
142
|
-
callback(new TypeError('Missing method'));
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
try {
|
|
146
|
-
sendRequest(params, callback);
|
|
147
|
-
} catch (ex) /* istanbul ignore next */ {
|
|
148
|
-
process.nextTick(() => {
|
|
149
|
-
callback(ex);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export { initialize, handleSuccess, handleFail, sendRequest, signedRequest };
|
|
158
|
-
export default signedRequest;
|
package/src/services/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import AuroraDbService from './AuroraDbService';
|
|
2
|
-
import DynamoDbService from './DynamoDbService';
|
|
3
|
-
import ElastiCacheService from './ElastiCacheService';
|
|
4
|
-
import ElasticsearchService from './ElasticsearchService';
|
|
5
|
-
import JwtService from './JwtService';
|
|
6
|
-
import LoggerService from './LoggerService';
|
|
7
|
-
import S3Service from './S3Service';
|
|
8
|
-
import SQSService from './SQSService';
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
AuroraDbService,
|
|
12
|
-
DynamoDbService,
|
|
13
|
-
ElastiCacheService,
|
|
14
|
-
ElasticsearchService,
|
|
15
|
-
JwtService,
|
|
16
|
-
LoggerService,
|
|
17
|
-
S3Service,
|
|
18
|
-
SQSService,
|
|
19
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import Paginator from './Paginator';
|
|
2
|
-
import LesgoException from '../../exceptions/LesgoException';
|
|
3
|
-
import validateFields from '../../utils/validateFields';
|
|
4
|
-
|
|
5
|
-
const FILE = 'Services/pagination/LengthAwarePaginator';
|
|
6
|
-
|
|
7
|
-
export default class LengthAwarePaginator extends Paginator {
|
|
8
|
-
/**
|
|
9
|
-
* Constructor
|
|
10
|
-
*
|
|
11
|
-
* @param db
|
|
12
|
-
* @param sql
|
|
13
|
-
* @param sqlParams
|
|
14
|
-
* @param options
|
|
15
|
-
* @param connection
|
|
16
|
-
*/
|
|
17
|
-
constructor(db, sql, sqlParams, options, connection = {}) {
|
|
18
|
-
const validFields = [{ key: 'total', type: 'number', required: true }];
|
|
19
|
-
|
|
20
|
-
let validated = {};
|
|
21
|
-
try {
|
|
22
|
-
validated = validateFields(options, validFields);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new LesgoException(
|
|
25
|
-
error.message,
|
|
26
|
-
`${FILE}::FIELD_VALIDATION_EXCEPTION`,
|
|
27
|
-
500,
|
|
28
|
-
{
|
|
29
|
-
...options,
|
|
30
|
-
error,
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { total } = validated;
|
|
36
|
-
|
|
37
|
-
super(db, sql, sqlParams, options, connection);
|
|
38
|
-
this.totalProp = total;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Total items in all pages.
|
|
43
|
-
*
|
|
44
|
-
* @returns {null|number}
|
|
45
|
-
*/
|
|
46
|
-
async total() {
|
|
47
|
-
return this.totalProp;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import LesgoException from '../../exceptions/LesgoException';
|
|
2
|
-
import validateFields from '../../utils/validateFields';
|
|
3
|
-
|
|
4
|
-
const FILE = 'Services/pagination/Paginator';
|
|
5
|
-
|
|
6
|
-
export default class Paginator {
|
|
7
|
-
/**
|
|
8
|
-
* Constructor
|
|
9
|
-
*
|
|
10
|
-
* @param db
|
|
11
|
-
* @param sql
|
|
12
|
-
* @param sqlParams
|
|
13
|
-
* @param options
|
|
14
|
-
*/
|
|
15
|
-
constructor(db, sql, sqlParams, options = {}, connection = {}) {
|
|
16
|
-
const validFields = [
|
|
17
|
-
{ key: 'db', type: 'object', required: true },
|
|
18
|
-
{ key: 'sql', type: 'string', required: true },
|
|
19
|
-
{ key: 'sqlParams', type: 'object', required: true },
|
|
20
|
-
{ key: 'perPage', type: 'number', required: false },
|
|
21
|
-
{ key: 'currentPage', type: 'number', required: false },
|
|
22
|
-
{ key: 'connection', type: 'object', required: false },
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
let validated = {};
|
|
26
|
-
try {
|
|
27
|
-
validated = validateFields(
|
|
28
|
-
{
|
|
29
|
-
db,
|
|
30
|
-
sql,
|
|
31
|
-
sqlParams,
|
|
32
|
-
...options,
|
|
33
|
-
connection,
|
|
34
|
-
},
|
|
35
|
-
validFields
|
|
36
|
-
);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new LesgoException(
|
|
39
|
-
error.message,
|
|
40
|
-
`${FILE}::FIELD_VALIDATION_EXCEPTION`,
|
|
41
|
-
500,
|
|
42
|
-
{
|
|
43
|
-
...options,
|
|
44
|
-
error,
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const { perPage, currentPage } = validated;
|
|
50
|
-
|
|
51
|
-
this.dbProp = db;
|
|
52
|
-
this.sqlProp = sql;
|
|
53
|
-
this.sqlParamsProp = sqlParams;
|
|
54
|
-
this.perPageProp = perPage || 10;
|
|
55
|
-
this.currentPageProp = currentPage || 1;
|
|
56
|
-
|
|
57
|
-
this.hasNext = false;
|
|
58
|
-
|
|
59
|
-
this.response = [];
|
|
60
|
-
this.totalProp = false;
|
|
61
|
-
|
|
62
|
-
this.connection = connection;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Count all items in the current page.
|
|
67
|
-
*
|
|
68
|
-
* @returns {number}
|
|
69
|
-
*/
|
|
70
|
-
async count() {
|
|
71
|
-
return this.response.length || (await this.executeQuery()).length;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Previous page
|
|
76
|
-
*
|
|
77
|
-
* @returns {boolean|number}
|
|
78
|
-
*/
|
|
79
|
-
previousPage() {
|
|
80
|
-
if (this.currentPage() > 1) {
|
|
81
|
-
return this.currentPage() - 1;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The current page.
|
|
89
|
-
*
|
|
90
|
-
* @returns {*|number}
|
|
91
|
-
*/
|
|
92
|
-
currentPage() {
|
|
93
|
-
return this.currentPageProp;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Next page
|
|
98
|
-
*
|
|
99
|
-
* @returns {Promise<boolean|*>}
|
|
100
|
-
*/
|
|
101
|
-
async nextPage() {
|
|
102
|
-
if (this.response.length <= 0) {
|
|
103
|
-
await this.executeQuery();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (this.hasNext) {
|
|
107
|
-
return this.currentPage() + 1;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* First item in the current page.
|
|
115
|
-
*
|
|
116
|
-
* @returns {*}
|
|
117
|
-
*/
|
|
118
|
-
async firstItem() {
|
|
119
|
-
if (this.response.length <= 0) {
|
|
120
|
-
await this.executeQuery();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return this.response[0];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Last item in the current page.
|
|
128
|
-
*/
|
|
129
|
-
async lastItem() {
|
|
130
|
-
if (this.response.length <= 0) {
|
|
131
|
-
await this.executeQuery();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return this.response[this.response.length - 1];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Number of items per page.
|
|
139
|
-
*
|
|
140
|
-
* @returns {*}
|
|
141
|
-
*/
|
|
142
|
-
perPage() {
|
|
143
|
-
return this.perPageProp;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Get the last page.
|
|
148
|
-
*
|
|
149
|
-
* @returns {Promise<number>}
|
|
150
|
-
*/
|
|
151
|
-
async lastPage() {
|
|
152
|
-
return this.calculateTotalNumberOfPages();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Total items in all pages.
|
|
157
|
-
*
|
|
158
|
-
* @returns {null|number}
|
|
159
|
-
*/
|
|
160
|
-
async total() {
|
|
161
|
-
return this.totalProp || this.countTotalItems();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* All items in the current page.
|
|
166
|
-
*
|
|
167
|
-
* @returns {[]}
|
|
168
|
-
*/
|
|
169
|
-
async items() {
|
|
170
|
-
if (this.response.length <= 0) {
|
|
171
|
-
await this.executeQuery();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return this.response;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Convert to object.
|
|
179
|
-
*
|
|
180
|
-
* @returns {Promise<{per_page: *, count: *, items: *, current_page: (*|number)}>}
|
|
181
|
-
*/
|
|
182
|
-
async toObject() {
|
|
183
|
-
if (this.response.length <= 0) {
|
|
184
|
-
await this.executeQuery();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
count: await this.count(),
|
|
189
|
-
previous_page: this.previousPage(),
|
|
190
|
-
current_page: this.currentPage(),
|
|
191
|
-
next_page: await this.nextPage(),
|
|
192
|
-
last_page: await this.lastPage(),
|
|
193
|
-
per_page: this.perPage(),
|
|
194
|
-
total: await this.total(),
|
|
195
|
-
items: await this.items(),
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// They act as protected methods.
|
|
200
|
-
|
|
201
|
-
getLimitAndOffsetByPageAndContentPerPage() {
|
|
202
|
-
const offset = this.currentPage() * this.perPage() - this.perPage();
|
|
203
|
-
const limit = this.perPage();
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
offset,
|
|
207
|
-
limit,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
generatePaginationSqlSnippet() {
|
|
212
|
-
const values = this.getLimitAndOffsetByPageAndContentPerPage();
|
|
213
|
-
const limitWithExtraData = values.limit + 1;
|
|
214
|
-
return this.sqlProp.concat(
|
|
215
|
-
` LIMIT ${limitWithExtraData} OFFSET ${values.offset}`
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async executeQuery() {
|
|
220
|
-
const total = this.totalProp;
|
|
221
|
-
if (
|
|
222
|
-
(typeof total === 'number' && total > 0) ||
|
|
223
|
-
(typeof total !== 'number' && !total)
|
|
224
|
-
) {
|
|
225
|
-
this.response = await this.dbProp.select(
|
|
226
|
-
this.generatePaginationSqlSnippet(),
|
|
227
|
-
this.sqlParamsProp,
|
|
228
|
-
this.connection
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
this.hasNext = this.response.length > this.perPage();
|
|
233
|
-
if (this.hasNext) {
|
|
234
|
-
this.response.pop();
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return this.response;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Count total items with basic implementation.
|
|
242
|
-
*
|
|
243
|
-
* @returns {Promise<number>}
|
|
244
|
-
*/
|
|
245
|
-
async countTotalItems() {
|
|
246
|
-
const resp = await this.dbProp.select(
|
|
247
|
-
this.sqlProp,
|
|
248
|
-
this.sqlParamsProp,
|
|
249
|
-
this.connection
|
|
250
|
-
);
|
|
251
|
-
this.totalProp = Object.keys(resp).length;
|
|
252
|
-
|
|
253
|
-
return this.totalProp;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async calculateTotalNumberOfPages() {
|
|
257
|
-
const total = await this.total();
|
|
258
|
-
return Math.ceil(total / this.perPage());
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
export const mockData = {
|
|
2
|
-
index_0: 'data_0',
|
|
3
|
-
index_1: 'data_1',
|
|
4
|
-
index_2: 'data_2',
|
|
5
|
-
index_3: 'data_3',
|
|
6
|
-
index_4: 'data_4',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const mockDataFirstItem = {
|
|
10
|
-
index_0: 'data_0_first_item',
|
|
11
|
-
index_1: 'data_1_first_item',
|
|
12
|
-
index_2: 'data_2_first_item',
|
|
13
|
-
index_3: 'data_3_first_item',
|
|
14
|
-
index_4: 'data_4_first_item',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const mockDataLastItem = {
|
|
18
|
-
index_0: 'data_0_last_item',
|
|
19
|
-
index_1: 'data_1_last_item',
|
|
20
|
-
index_2: 'data_2_last_item',
|
|
21
|
-
index_3: 'data_3_last_item',
|
|
22
|
-
index_4: 'data_4_last_item',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default {
|
|
26
|
-
// eslint-disable-next-line no-unused-vars
|
|
27
|
-
select: jest.fn().mockImplementation((sql, sqlParams) => {
|
|
28
|
-
if (sql.startsWith('SELECT * FROM tests LIMIT 6 OFFSET 10')) {
|
|
29
|
-
return Promise.resolve([
|
|
30
|
-
{ ...mockDataFirstItem },
|
|
31
|
-
{ ...mockData },
|
|
32
|
-
{ ...mockData },
|
|
33
|
-
{ ...mockData },
|
|
34
|
-
{ ...mockDataLastItem },
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
sql.startsWith('SELECT * FROM tests LIMIT 6') ||
|
|
40
|
-
sql.startsWith('SELECT * FROM total_tests LIMIT 6')
|
|
41
|
-
) {
|
|
42
|
-
return Promise.resolve([
|
|
43
|
-
{ ...mockDataFirstItem },
|
|
44
|
-
{ ...mockData },
|
|
45
|
-
{ ...mockData },
|
|
46
|
-
{ ...mockData },
|
|
47
|
-
{ ...mockDataLastItem },
|
|
48
|
-
{ ...mockData },
|
|
49
|
-
]);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (sql.startsWith('SELECT * FROM total_tests')) {
|
|
53
|
-
return Promise.resolve([
|
|
54
|
-
{ ...mockDataFirstItem },
|
|
55
|
-
{ ...mockData },
|
|
56
|
-
{ ...mockData },
|
|
57
|
-
{ ...mockData },
|
|
58
|
-
{ ...mockData },
|
|
59
|
-
{ ...mockData },
|
|
60
|
-
{ ...mockData },
|
|
61
|
-
{ ...mockData },
|
|
62
|
-
{ ...mockData },
|
|
63
|
-
{ ...mockData },
|
|
64
|
-
{ ...mockData },
|
|
65
|
-
{ ...mockData },
|
|
66
|
-
{ ...mockData },
|
|
67
|
-
{ ...mockData },
|
|
68
|
-
{ ...mockData },
|
|
69
|
-
{ ...mockData },
|
|
70
|
-
{ ...mockData },
|
|
71
|
-
{ ...mockData },
|
|
72
|
-
{ ...mockData },
|
|
73
|
-
{ ...mockData },
|
|
74
|
-
{ ...mockData },
|
|
75
|
-
{ ...mockData },
|
|
76
|
-
{ ...mockData },
|
|
77
|
-
{ ...mockData },
|
|
78
|
-
{ ...mockData },
|
|
79
|
-
{ ...mockData },
|
|
80
|
-
{ ...mockData },
|
|
81
|
-
{ ...mockData },
|
|
82
|
-
{ ...mockData },
|
|
83
|
-
{ ...mockDataLastItem },
|
|
84
|
-
]);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (sql.startsWith('SELECT * FROM tests')) {
|
|
88
|
-
return Promise.resolve([
|
|
89
|
-
{ ...mockData },
|
|
90
|
-
{ ...mockData },
|
|
91
|
-
{ ...mockData },
|
|
92
|
-
{ ...mockData },
|
|
93
|
-
{ ...mockData },
|
|
94
|
-
{ ...mockData },
|
|
95
|
-
{ ...mockData },
|
|
96
|
-
{ ...mockData },
|
|
97
|
-
{ ...mockData },
|
|
98
|
-
{ ...mockData },
|
|
99
|
-
]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return Promise.resolve({
|
|
103
|
-
mocked: {
|
|
104
|
-
sql,
|
|
105
|
-
sqlParams,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}),
|
|
109
|
-
};
|