apf-node-common 1.0.109 → 1.0.111

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.
Files changed (37) hide show
  1. package/ApplicationContextService.js +103 -103
  2. package/CoreUtils.js +59 -59
  3. package/Logger/index.js +93 -93
  4. package/Logger/loggerTransports.js +137 -137
  5. package/SSMConfig.js +44 -44
  6. package/ScheduleCalculationService.js +0 -0
  7. package/auditlog/AuditLogger.js +58 -58
  8. package/auditlog/AuditLoggerRepository.js +38 -38
  9. package/auditlog/AuditLoggerService.js +37 -37
  10. package/config/SSMParameters.js +16 -16
  11. package/constants/CommonMessages.js +14 -14
  12. package/constants/Frequency.js +8 -8
  13. package/constants/TimeZone.js +11 -11
  14. package/constants/UserType.js +9 -9
  15. package/exception/CustomException.js +36 -36
  16. package/exception/SendResponse.js +139 -139
  17. package/index.js +187 -187
  18. package/package.json +29 -29
  19. package/test/AWSUtilityIntegrationTest.js +94 -94
  20. package/test/FrequencyValidatorTest.js +0 -0
  21. package/test/LambdaCommunicationServiceTest.js +83 -83
  22. package/test/ScheduleCalculationServiceTest.js +0 -0
  23. package/utils/HashIds.js +139 -139
  24. package/utils/NumberFormatter.js +253 -253
  25. package/utils/aws/AESEncryptionUsingKMS.js +106 -106
  26. package/utils/aws/AWSAPIKeyGenerator.js +307 -307
  27. package/utils/aws/AWSS3Utils.js +128 -128
  28. package/utils/aws/AWSSMSUtils.js +63 -63
  29. package/utils/aws/AWSSNSBasedEmailDispatcher.js +37 -37
  30. package/utils/aws/AWSSNSBasedSMSDispatcher.js +37 -37
  31. package/utils/aws/AWSSNSUtils.js +35 -38
  32. package/utils/aws/LambdaCommunicationService.js +232 -232
  33. package/utils/enumHelper.js +7 -7
  34. package/utils/thirdparty/URLShorteningService.js +25 -25
  35. package/validation/CoreValidations.js +45 -45
  36. package/validation/FrequencyValidator.js +0 -0
  37. 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,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
- })
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
  }