apf-node-common 1.0.107 → 1.0.110
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/ApplicationContextService.js +103 -103
- package/CoreUtils.js +59 -59
- package/Logger/index.js +93 -93
- package/Logger/loggerTransports.js +137 -137
- package/SSMConfig.js +44 -44
- package/ScheduleCalculationService.js +0 -0
- package/auditlog/AuditLogger.js +58 -58
- package/auditlog/AuditLoggerRepository.js +38 -38
- package/auditlog/AuditLoggerService.js +37 -37
- package/config/SSMParameters.js +16 -16
- package/constants/CommonMessages.js +14 -14
- package/constants/Frequency.js +8 -8
- package/constants/TimeZone.js +11 -11
- package/constants/UserType.js +9 -9
- package/exception/CustomException.js +36 -36
- package/exception/SendResponse.js +139 -139
- package/index.js +187 -187
- package/package.json +29 -29
- package/test/AWSUtilityIntegrationTest.js +94 -94
- package/test/FrequencyValidatorTest.js +0 -0
- package/test/LambdaCommunicationServiceTest.js +83 -83
- package/test/ScheduleCalculationServiceTest.js +0 -0
- package/utils/HashIds.js +139 -139
- package/utils/NumberFormatter.js +253 -253
- package/utils/aws/AESEncryptionUsingKMS.js +106 -106
- package/utils/aws/AWSAPIKeyGenerator.js +307 -307
- package/utils/aws/AWSS3Utils.js +128 -128
- package/utils/aws/AWSSMSUtils.js +63 -63
- package/utils/aws/AWSSNSBasedEmailDispatcher.js +37 -37
- package/utils/aws/AWSSNSBasedSMSDispatcher.js +37 -37
- package/utils/aws/AWSSNSUtils.js +38 -38
- package/utils/aws/LambdaCommunicationService.js +232 -232
- package/utils/enumHelper.js +7 -7
- package/utils/thirdparty/URLShorteningService.js +25 -25
- package/validation/CoreValidations.js +45 -45
- package/validation/FrequencyValidator.js +0 -0
- package/validation/SchemaValidation.js +106 -106
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
const LambdaCommunicationService = require('../utils/aws/LambdaCommunicationService');
|
|
2
|
-
const assert = require('chai');
|
|
3
|
-
var expect = require('chai').expect;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe('LambdaCommunicationServiceTestCase',async function() {
|
|
7
|
-
|
|
8
|
-
it('return 200 Status code', async function() {
|
|
9
|
-
//Arrange
|
|
10
|
-
this.enableTimeouts(false)
|
|
11
|
-
|
|
12
|
-
let path = "/countries";
|
|
13
|
-
let jsonData = {};
|
|
14
|
-
|
|
15
|
-
let communicationRequest = {
|
|
16
|
-
moduleName: "Fraud",
|
|
17
|
-
method: "GET",
|
|
18
|
-
path: path,
|
|
19
|
-
userType: "1",
|
|
20
|
-
// parentId: "67",
|
|
21
|
-
jsonData:jsonData
|
|
22
|
-
}
|
|
23
|
-
//Act
|
|
24
|
-
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
25
|
-
var resultJson = JSON.parse(resultString);
|
|
26
|
-
|
|
27
|
-
//Assert
|
|
28
|
-
expect(resultJson.statusCode).to.equal(200);
|
|
29
|
-
expect(resultJson.body).to.not.equal(null);
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('return 200 status with successful login',async function() {
|
|
34
|
-
//Arrange
|
|
35
|
-
this.enableTimeouts(false)
|
|
36
|
-
|
|
37
|
-
let path = "/users/sessions";
|
|
38
|
-
let jsonData = {
|
|
39
|
-
userName: "SanalMerchant",
|
|
40
|
-
password: "SanalMerchant"
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
let communicationRequest = {
|
|
44
|
-
moduleName: "Infrastructure",
|
|
45
|
-
method: "POST",
|
|
46
|
-
path: path,
|
|
47
|
-
userType: "1",
|
|
48
|
-
parentId: "67",
|
|
49
|
-
jsonData:jsonData
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//Act
|
|
53
|
-
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
54
|
-
var resultJson = JSON.parse(resultString);
|
|
55
|
-
//Assert
|
|
56
|
-
expect(resultJson.statusCode).to.equal(200);
|
|
57
|
-
expect(resultJson.body).to.not.equal(null);
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('return the Merchant Data', async function() {
|
|
62
|
-
//Arrange
|
|
63
|
-
this.enableTimeouts(false)
|
|
64
|
-
|
|
65
|
-
let path = "/merchants/n7de378M/customers";
|
|
66
|
-
let communicationRequest = {
|
|
67
|
-
moduleName: "Domain",
|
|
68
|
-
method: "Get",
|
|
69
|
-
path: path,
|
|
70
|
-
userType: "1",
|
|
71
|
-
parentId: "67"
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//Act
|
|
75
|
-
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
76
|
-
var resultJson = JSON.parse(resultString);
|
|
77
|
-
console.log(resultJson.statusCode);
|
|
78
|
-
|
|
79
|
-
//Assert
|
|
80
|
-
expect(resultJson.statusCode).to.equal(200);
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
|
|
1
|
+
const LambdaCommunicationService = require('../utils/aws/LambdaCommunicationService');
|
|
2
|
+
const assert = require('chai');
|
|
3
|
+
var expect = require('chai').expect;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('LambdaCommunicationServiceTestCase',async function() {
|
|
7
|
+
|
|
8
|
+
it('return 200 Status code', async function() {
|
|
9
|
+
//Arrange
|
|
10
|
+
this.enableTimeouts(false)
|
|
11
|
+
|
|
12
|
+
let path = "/countries";
|
|
13
|
+
let jsonData = {};
|
|
14
|
+
|
|
15
|
+
let communicationRequest = {
|
|
16
|
+
moduleName: "Fraud",
|
|
17
|
+
method: "GET",
|
|
18
|
+
path: path,
|
|
19
|
+
userType: "1",
|
|
20
|
+
// parentId: "67",
|
|
21
|
+
jsonData:jsonData
|
|
22
|
+
}
|
|
23
|
+
//Act
|
|
24
|
+
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
25
|
+
var resultJson = JSON.parse(resultString);
|
|
26
|
+
|
|
27
|
+
//Assert
|
|
28
|
+
expect(resultJson.statusCode).to.equal(200);
|
|
29
|
+
expect(resultJson.body).to.not.equal(null);
|
|
30
|
+
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('return 200 status with successful login',async function() {
|
|
34
|
+
//Arrange
|
|
35
|
+
this.enableTimeouts(false)
|
|
36
|
+
|
|
37
|
+
let path = "/users/sessions";
|
|
38
|
+
let jsonData = {
|
|
39
|
+
userName: "SanalMerchant",
|
|
40
|
+
password: "SanalMerchant"
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let communicationRequest = {
|
|
44
|
+
moduleName: "Infrastructure",
|
|
45
|
+
method: "POST",
|
|
46
|
+
path: path,
|
|
47
|
+
userType: "1",
|
|
48
|
+
parentId: "67",
|
|
49
|
+
jsonData:jsonData
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//Act
|
|
53
|
+
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
54
|
+
var resultJson = JSON.parse(resultString);
|
|
55
|
+
//Assert
|
|
56
|
+
expect(resultJson.statusCode).to.equal(200);
|
|
57
|
+
expect(resultJson.body).to.not.equal(null);
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('return the Merchant Data', async function() {
|
|
62
|
+
//Arrange
|
|
63
|
+
this.enableTimeouts(false)
|
|
64
|
+
|
|
65
|
+
let path = "/merchants/n7de378M/customers";
|
|
66
|
+
let communicationRequest = {
|
|
67
|
+
moduleName: "Domain",
|
|
68
|
+
method: "Get",
|
|
69
|
+
path: path,
|
|
70
|
+
userType: "1",
|
|
71
|
+
parentId: "67"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//Act
|
|
75
|
+
const resultString = await LambdaCommunicationService.invokeLambdaAPI(communicationRequest);
|
|
76
|
+
var resultJson = JSON.parse(resultString);
|
|
77
|
+
console.log(resultJson.statusCode);
|
|
78
|
+
|
|
79
|
+
//Assert
|
|
80
|
+
expect(resultJson.statusCode).to.equal(200);
|
|
81
|
+
|
|
82
|
+
})
|
|
83
|
+
|
|
84
84
|
})
|
|
File without changes
|
package/utils/HashIds.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
const AWS = require('aws-sdk');
|
|
2
|
-
|
|
3
|
-
const awsEnv = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
4
|
-
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
5
|
-
AWS.config.update({ region: awsRegion });
|
|
6
|
-
const camelcaseKeys = require('camelcase-keys');
|
|
7
|
-
const CoreUtils = require('../CoreUtils');
|
|
8
|
-
const httpContext = require('express-http-context');
|
|
9
|
-
const TimeZoneConvertor = require('./TimeZoneConverter')
|
|
10
|
-
const moment = require('moment');
|
|
11
|
-
const log = require('../Logger').getLogger();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let hashids;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
|
|
19
|
-
hashResponse(hashConfig, response, properties,dateproperties) {
|
|
20
|
-
if (properties === undefined || response === undefined) {
|
|
21
|
-
log.error('No properties to unhash');
|
|
22
|
-
}
|
|
23
|
-
hashids = hashConfig;
|
|
24
|
-
|
|
25
|
-
response = hash(response, properties,dateproperties);
|
|
26
|
-
return response;
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
unHashRequest(hashConfig, request, properties) {
|
|
31
|
-
hashids = hashConfig;
|
|
32
|
-
if (properties === undefined || request === undefined) {
|
|
33
|
-
log.error('No properties to unhash');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
request = unHash(request, properties);
|
|
37
|
-
return request;
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function unHash(request, properties) {
|
|
44
|
-
if (typeof request !== 'object' || request === null) {
|
|
45
|
-
return request
|
|
46
|
-
}
|
|
47
|
-
if (Array.isArray(request)) {
|
|
48
|
-
return deepUnHashedArray(request, properties);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return deepUnHashedObject(request, properties);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function deepUnHashedObject(request, properties) {
|
|
55
|
-
const result = {}
|
|
56
|
-
|
|
57
|
-
Object.keys(request).forEach((key) => {
|
|
58
|
-
let requestKey = request[key]
|
|
59
|
-
let timeZone = httpContext.get("TimeZone");
|
|
60
|
-
if (properties.includes(key) && (typeof requestKey === "string")) {
|
|
61
|
-
const hashedValue = requestKey;
|
|
62
|
-
|
|
63
|
-
result[key] = parseInt(hashids.decode(hashedValue));
|
|
64
|
-
|
|
65
|
-
} else if (CoreUtils.isInputDateTime(requestKey)) {
|
|
66
|
-
result[key] = CoreUtils.getUTCDate(requestKey, timeZone);
|
|
67
|
-
} else if (CoreUtils.isInputDate(requestKey)) {
|
|
68
|
-
let dateProperty = `${requestKey} 00:00:00`
|
|
69
|
-
result[key] = CoreUtils.getUTCDate(dateProperty, timeZone);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const value = requestKey;
|
|
73
|
-
result[key] = unHash(requestKey, properties);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}, {})
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function deepUnHashedArray(collection, properties) {
|
|
81
|
-
return collection.map((value) => {
|
|
82
|
-
return unHash(value, properties)
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function hash(response, properties,dateproperties) {
|
|
87
|
-
if (typeof response !== 'object' || response === null) {
|
|
88
|
-
return response;
|
|
89
|
-
}
|
|
90
|
-
if (Array.isArray(response)) {
|
|
91
|
-
return deepHashedArray(response, properties,dateproperties);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return deepHashedObject(response, properties,dateproperties);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function deepHashedObject(response, properties,dateproperties) {
|
|
98
|
-
const result = {}
|
|
99
|
-
Object.keys(response).forEach((key) => {
|
|
100
|
-
if (properties.includes(key)) {
|
|
101
|
-
const unHashedValue = response[key];
|
|
102
|
-
if (unHashedValue !== null && unHashedValue !== "" && unHashedValue != 0 && (typeof(unHashedValue) === 'number')) {
|
|
103
|
-
result[key] = hashids.encode(unHashedValue);
|
|
104
|
-
} else {
|
|
105
|
-
result[key] = unHashedValue;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
} else {
|
|
109
|
-
const value = response[key];
|
|
110
|
-
if (value instanceof Date && value != null) {
|
|
111
|
-
let timezone = 0;
|
|
112
|
-
if (httpContext.get("TimeZone")) {
|
|
113
|
-
timezone = parseInt(httpContext.get("TimeZone"))
|
|
114
|
-
}
|
|
115
|
-
let toMerchantTimeZone = TimeZoneConvertor.timeZoneConvert(timezone, moment(value).utc(true));
|
|
116
|
-
|
|
117
|
-
if (!toMerchantTimeZone) {
|
|
118
|
-
toMerchantTimeZone = moment(value).utc(true).format('MM-DD-YYYY HH:mm:ss')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if(dateproperties!= undefined && Array.isArray(dateproperties) && dateproperties.includes(key)){
|
|
122
|
-
toMerchantTimeZone = toMerchantTimeZone.substring(0,10);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
result[key] = toMerchantTimeZone;
|
|
126
|
-
} else
|
|
127
|
-
// if (value != null) {
|
|
128
|
-
result[key] = hash(response[key], properties);
|
|
129
|
-
// }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
}, {})
|
|
133
|
-
return camelcaseKeys(result);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function deepHashedArray(collection, properties,dateproperties) {
|
|
137
|
-
return collection.map((value) => {
|
|
138
|
-
return hash(value, properties,dateproperties)
|
|
139
|
-
})
|
|
1
|
+
const AWS = require('aws-sdk');
|
|
2
|
+
|
|
3
|
+
const awsEnv = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
4
|
+
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
5
|
+
AWS.config.update({ region: awsRegion });
|
|
6
|
+
const camelcaseKeys = require('camelcase-keys');
|
|
7
|
+
const CoreUtils = require('../CoreUtils');
|
|
8
|
+
const httpContext = require('express-http-context');
|
|
9
|
+
const TimeZoneConvertor = require('./TimeZoneConverter')
|
|
10
|
+
const moment = require('moment');
|
|
11
|
+
const log = require('../Logger').getLogger();
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
let hashids;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
|
|
19
|
+
hashResponse(hashConfig, response, properties,dateproperties) {
|
|
20
|
+
if (properties === undefined || response === undefined) {
|
|
21
|
+
log.error('No properties to unhash');
|
|
22
|
+
}
|
|
23
|
+
hashids = hashConfig;
|
|
24
|
+
|
|
25
|
+
response = hash(response, properties,dateproperties);
|
|
26
|
+
return response;
|
|
27
|
+
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
unHashRequest(hashConfig, request, properties) {
|
|
31
|
+
hashids = hashConfig;
|
|
32
|
+
if (properties === undefined || request === undefined) {
|
|
33
|
+
log.error('No properties to unhash');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
request = unHash(request, properties);
|
|
37
|
+
return request;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function unHash(request, properties) {
|
|
44
|
+
if (typeof request !== 'object' || request === null) {
|
|
45
|
+
return request
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(request)) {
|
|
48
|
+
return deepUnHashedArray(request, properties);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return deepUnHashedObject(request, properties);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function deepUnHashedObject(request, properties) {
|
|
55
|
+
const result = {}
|
|
56
|
+
|
|
57
|
+
Object.keys(request).forEach((key) => {
|
|
58
|
+
let requestKey = request[key]
|
|
59
|
+
let timeZone = httpContext.get("TimeZone");
|
|
60
|
+
if (properties.includes(key) && (typeof requestKey === "string")) {
|
|
61
|
+
const hashedValue = requestKey;
|
|
62
|
+
|
|
63
|
+
result[key] = parseInt(hashids.decode(hashedValue));
|
|
64
|
+
|
|
65
|
+
} else if (CoreUtils.isInputDateTime(requestKey)) {
|
|
66
|
+
result[key] = CoreUtils.getUTCDate(requestKey, timeZone);
|
|
67
|
+
} else if (CoreUtils.isInputDate(requestKey)) {
|
|
68
|
+
let dateProperty = `${requestKey} 00:00:00`
|
|
69
|
+
result[key] = CoreUtils.getUTCDate(dateProperty, timeZone);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const value = requestKey;
|
|
73
|
+
result[key] = unHash(requestKey, properties);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}, {})
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function deepUnHashedArray(collection, properties) {
|
|
81
|
+
return collection.map((value) => {
|
|
82
|
+
return unHash(value, properties)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function hash(response, properties,dateproperties) {
|
|
87
|
+
if (typeof response !== 'object' || response === null) {
|
|
88
|
+
return response;
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(response)) {
|
|
91
|
+
return deepHashedArray(response, properties,dateproperties);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return deepHashedObject(response, properties,dateproperties);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function deepHashedObject(response, properties,dateproperties) {
|
|
98
|
+
const result = {}
|
|
99
|
+
Object.keys(response).forEach((key) => {
|
|
100
|
+
if (properties.includes(key)) {
|
|
101
|
+
const unHashedValue = response[key];
|
|
102
|
+
if (unHashedValue !== null && unHashedValue !== "" && unHashedValue != 0 && (typeof(unHashedValue) === 'number')) {
|
|
103
|
+
result[key] = hashids.encode(unHashedValue);
|
|
104
|
+
} else {
|
|
105
|
+
result[key] = unHashedValue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
} else {
|
|
109
|
+
const value = response[key];
|
|
110
|
+
if (value instanceof Date && value != null) {
|
|
111
|
+
let timezone = 0;
|
|
112
|
+
if (httpContext.get("TimeZone")) {
|
|
113
|
+
timezone = parseInt(httpContext.get("TimeZone"))
|
|
114
|
+
}
|
|
115
|
+
let toMerchantTimeZone = TimeZoneConvertor.timeZoneConvert(timezone, moment(value).utc(true));
|
|
116
|
+
|
|
117
|
+
if (!toMerchantTimeZone) {
|
|
118
|
+
toMerchantTimeZone = moment(value).utc(true).format('MM-DD-YYYY HH:mm:ss')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if(dateproperties!= undefined && Array.isArray(dateproperties) && dateproperties.includes(key)){
|
|
122
|
+
toMerchantTimeZone = toMerchantTimeZone.substring(0,10);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
result[key] = toMerchantTimeZone;
|
|
126
|
+
} else
|
|
127
|
+
// if (value != null) {
|
|
128
|
+
result[key] = hash(response[key], properties,dateproperties);
|
|
129
|
+
// }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}, {})
|
|
133
|
+
return camelcaseKeys(result);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function deepHashedArray(collection, properties,dateproperties) {
|
|
137
|
+
return collection.map((value) => {
|
|
138
|
+
return hash(value, properties,dateproperties)
|
|
139
|
+
})
|
|
140
140
|
}
|