apf-node-common 1.0.109 → 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,233 +1,233 @@
|
|
|
1
|
-
const AWS = require('aws-sdk');
|
|
2
|
-
const uuidv1 = require('uuid
|
|
3
|
-
const jwt = require('jsonwebtoken');
|
|
4
|
-
const ms = require('ms');
|
|
5
|
-
|
|
6
|
-
const SSMConfig = require("../../SSMConfig");
|
|
7
|
-
const ssmParam = require('../../config/SSMParameters')['ssm']
|
|
8
|
-
|
|
9
|
-
const environment = (process.env.NODE_ENVIRONMENT || 'dev');
|
|
10
|
-
const region = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
11
|
-
AWS.config.region = region;
|
|
12
|
-
const lambdaClient = new AWS.Lambda();
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
/**
|
|
16
|
-
* This api is used for lambda inter communication.
|
|
17
|
-
* @param {string} moduleName
|
|
18
|
-
* @param {string} method
|
|
19
|
-
* @param {string} path
|
|
20
|
-
* @param {object} jsonData
|
|
21
|
-
* @param {string} userType
|
|
22
|
-
* @param {string} rawToken
|
|
23
|
-
*/
|
|
24
|
-
async invokeAPI(communicationRequest) {
|
|
25
|
-
console.log("LambdaCommunicationService : invokeAPI : Start : " );
|
|
26
|
-
|
|
27
|
-
validate(communicationRequest);
|
|
28
|
-
if (!communicationRequest.rawToken) {
|
|
29
|
-
console.log('raw token is required.');
|
|
30
|
-
throw new Error('raw token is required.');
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
let invokePayLoad = await generatePayload(communicationRequest.method, communicationRequest.path, communicationRequest.jsonData, communicationRequest.userType, communicationRequest.rawToken);
|
|
34
|
-
let params = {
|
|
35
|
-
FunctionName: environment.concat('-', communicationRequest.moduleName, '-', 'API'),
|
|
36
|
-
InvocationType: 'RequestResponse',
|
|
37
|
-
Payload: invokePayLoad
|
|
38
|
-
}
|
|
39
|
-
let response = await lambdaClient.invoke(params).promise();
|
|
40
|
-
console.log("LambdaCommunicationService : invokeAPI : End : " );
|
|
41
|
-
|
|
42
|
-
return response.Payload;
|
|
43
|
-
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.log("error occured while invoking api ", error);
|
|
46
|
-
console.log("LambdaCommunicationService : invokeAPI : Error : " + JSON.stringify(error.name));
|
|
47
|
-
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
},async invokeLambdaAPI(communicationRequest) {
|
|
51
|
-
console.log("LambdaCommunicationService : invokeLambdaAPI : Start : " );
|
|
52
|
-
validate(communicationRequest);
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
let invokePayLoad = await generatePayload(communicationRequest.method, communicationRequest.path, communicationRequest.jsonData, communicationRequest.userType, '', communicationRequest.id, communicationRequest.parentId, communicationRequest.resellerId,communicationRequest.merchantId);
|
|
56
|
-
let params = {
|
|
57
|
-
FunctionName: environment.concat('-', communicationRequest.moduleName, '-', 'API'),
|
|
58
|
-
InvocationType: 'RequestResponse',
|
|
59
|
-
Payload: invokePayLoad
|
|
60
|
-
}
|
|
61
|
-
let response = await lambdaClient.invoke(params).promise();
|
|
62
|
-
console.log("LambdaCommunicationService : invokeLambdaAPI : End : " );
|
|
63
|
-
|
|
64
|
-
return response.Payload;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.log("error occured while invoking api ", error);
|
|
67
|
-
console.log("LambdaCommunicationService : invokeLambdaAPI : Error : " + JSON.stringify(error.name));
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
},async generateJWTToken(userType, id, parentId, resellerId,merchantId){
|
|
72
|
-
return await generateJWTToken(userType, id, parentId, resellerId,merchantId);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function validate(communicationRequest) {
|
|
77
|
-
if (!communicationRequest) {
|
|
78
|
-
console.log('communication request is required.');
|
|
79
|
-
throw new Error('communication request is required.');
|
|
80
|
-
}
|
|
81
|
-
else if (!communicationRequest.moduleName) {
|
|
82
|
-
console.log('module name is required.');
|
|
83
|
-
throw new Error('module name is required.');
|
|
84
|
-
}
|
|
85
|
-
else if (!communicationRequest.method) {
|
|
86
|
-
console.log('method is required.');
|
|
87
|
-
throw new Error('method is required.');
|
|
88
|
-
}
|
|
89
|
-
else if (!communicationRequest.path) {
|
|
90
|
-
console.log('path is required.');
|
|
91
|
-
throw new Error('path is required.');
|
|
92
|
-
}
|
|
93
|
-
else if (!communicationRequest.userType) {
|
|
94
|
-
console.log('user type is required.');
|
|
95
|
-
throw new Error('user type is required.');
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/*function getUserTypeString(userType) {
|
|
100
|
-
switch (userType) {
|
|
101
|
-
case 0:
|
|
102
|
-
return "Reseller"
|
|
103
|
-
case 1:
|
|
104
|
-
return "Merchant"
|
|
105
|
-
case 2:
|
|
106
|
-
return "Global"
|
|
107
|
-
}
|
|
108
|
-
}*/
|
|
109
|
-
|
|
110
|
-
async function generatePayload(method, path, jsonData, userType, rawToken, id, parentId, resellerId = '0',merchantId) {
|
|
111
|
-
console.log("inside generatePayload start")
|
|
112
|
-
|
|
113
|
-
if (!rawToken || rawToken === ''){
|
|
114
|
-
rawToken = await generateJWTToken(userType, id, parentId, resellerId,merchantId);
|
|
115
|
-
}
|
|
116
|
-
let queryStringParameters;
|
|
117
|
-
|
|
118
|
-
let queryString = path.indexOf('?', 0) > 0 ? path.substring(path.indexOf('?', 0)) : '';
|
|
119
|
-
|
|
120
|
-
if (queryString || queryString !== ''){
|
|
121
|
-
queryStringParameters = parseQueryString(queryString);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let apiEvent = {
|
|
125
|
-
"httpMethod": method,
|
|
126
|
-
"path": path.indexOf("?", 0) > 0 ? path.substring(0, path.indexOf("?", 0)) : path,
|
|
127
|
-
"pathParameters": { "proxy": path },
|
|
128
|
-
"body": (jsonData!= undefined&&jsonData!="") ? JSON.stringify(jsonData):"",
|
|
129
|
-
"requestContext": {
|
|
130
|
-
"requestId": uuidv1().toString(),
|
|
131
|
-
"identity": {
|
|
132
|
-
"caller": "",
|
|
133
|
-
"userAgent": "HPG-LambdaCommunicator"
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
"headers": {
|
|
137
|
-
"via": "",
|
|
138
|
-
"X-Forwarded-For": "",
|
|
139
|
-
"Accept": "application/json",
|
|
140
|
-
"Content-Type": "application/json",
|
|
141
|
-
"User-Agent": "HPG-LambdaCommunicator",
|
|
142
|
-
"Authorization": "Bearer ".concat(rawToken),
|
|
143
|
-
"Accept-Encoding": "gzip, deflate, br",
|
|
144
|
-
|
|
145
|
-
},
|
|
146
|
-
"stageVariables": {"env":`${environment}`},
|
|
147
|
-
"queryStringParameters": queryStringParameters
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* let apiEvent = {
|
|
151
|
-
HttpMethod: method,
|
|
152
|
-
Path: path.indexOf('?', 0) > 0 ? path.substring(0, path.indexOf('?', 0)) : path,
|
|
153
|
-
PathParameters: { "proxy": path },
|
|
154
|
-
Body: jsonData!= undefined ? JSON.stringify(jsonData):'',
|
|
155
|
-
RequestContext: {
|
|
156
|
-
RequestId: uuidv1().toString(),
|
|
157
|
-
Identity: {
|
|
158
|
-
Caller: "",
|
|
159
|
-
UserAgent: "HPG-LambdaCommunicator"
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
Headers: {
|
|
163
|
-
"Via": "",
|
|
164
|
-
"X-Forwarded-For": "",
|
|
165
|
-
"Accept": "application/json",
|
|
166
|
-
"Content-Type": "application/json",
|
|
167
|
-
"User-Agent": "HPG-LambdaCommunicator",
|
|
168
|
-
"Authorization": "Bearer ".concat(rawToken),
|
|
169
|
-
'Accept-Encoding': 'gzip, deflate, br',
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
StageVariables: {},
|
|
173
|
-
QueryStringParameters: queryStringParameters
|
|
174
|
-
}*/
|
|
175
|
-
console.log("inside generatePayload end")
|
|
176
|
-
|
|
177
|
-
return JSON.stringify(apiEvent);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function parseQueryString(query) {
|
|
181
|
-
let queryDict = new Object();
|
|
182
|
-
let queryArray = query.replace(/^\?*/, '').split('&');
|
|
183
|
-
|
|
184
|
-
queryArray.forEach(element => {
|
|
185
|
-
//let parts = element.replace(/^\=*/, '');
|
|
186
|
-
let parts = element.split('=');
|
|
187
|
-
console.log(parts)
|
|
188
|
-
if (parts.length == 2)
|
|
189
|
-
queryDict[parts[0].trim()] = decodeURI(parts[1]).trim();
|
|
190
|
-
else
|
|
191
|
-
queryDict[parts[0].trim()] = "";
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
return queryDict;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function generateJWTToken(userType, id, parentId, resellerId,merchantId) {
|
|
198
|
-
console.log("inside generateJWTToken start")
|
|
199
|
-
const ssmConfig = await SSMConfig.ssmConfig(ssmParam);
|
|
200
|
-
console.log(parentId)
|
|
201
|
-
|
|
202
|
-
let payload = {
|
|
203
|
-
Id: id,
|
|
204
|
-
sub: "System",
|
|
205
|
-
Admin: "1",
|
|
206
|
-
UserType: userType,
|
|
207
|
-
jit: "0",
|
|
208
|
-
Role: "0",
|
|
209
|
-
ParentId: (parentId === undefined || parentId === "0")? "0":parentId.toString(),
|
|
210
|
-
ResellerId: resellerId,
|
|
211
|
-
MerchantId: (merchantId === undefined || merchantId === "0")? "0":merchantId.toString(),
|
|
212
|
-
Service: "Service"
|
|
213
|
-
};
|
|
214
|
-
let secretSigningKey = ssmConfig.SigningKey;
|
|
215
|
-
let tokenIssuer = ssmConfig.Issuer;
|
|
216
|
-
let signOptions = {
|
|
217
|
-
issuer: tokenIssuer,
|
|
218
|
-
audience: "HPGServer",
|
|
219
|
-
expiresIn: "2h",
|
|
220
|
-
notBefore: ms('0s')
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
let token = jwt.sign(payload, secretSigningKey, signOptions);
|
|
224
|
-
console.log(token);
|
|
225
|
-
console.log("inside generateJWTToken end");
|
|
226
|
-
|
|
227
|
-
return token;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// var obj = new LambdaCommunicationService();
|
|
1
|
+
const AWS = require('aws-sdk');
|
|
2
|
+
const {v1 : uuidv1} = require('uuid');
|
|
3
|
+
const jwt = require('jsonwebtoken');
|
|
4
|
+
const ms = require('ms');
|
|
5
|
+
|
|
6
|
+
const SSMConfig = require("../../SSMConfig");
|
|
7
|
+
const ssmParam = require('../../config/SSMParameters')['ssm']
|
|
8
|
+
|
|
9
|
+
const environment = (process.env.NODE_ENVIRONMENT || 'dev');
|
|
10
|
+
const region = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
11
|
+
AWS.config.region = region;
|
|
12
|
+
const lambdaClient = new AWS.Lambda();
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
/**
|
|
16
|
+
* This api is used for lambda inter communication.
|
|
17
|
+
* @param {string} moduleName
|
|
18
|
+
* @param {string} method
|
|
19
|
+
* @param {string} path
|
|
20
|
+
* @param {object} jsonData
|
|
21
|
+
* @param {string} userType
|
|
22
|
+
* @param {string} rawToken
|
|
23
|
+
*/
|
|
24
|
+
async invokeAPI(communicationRequest) {
|
|
25
|
+
console.log("LambdaCommunicationService : invokeAPI : Start : " );
|
|
26
|
+
|
|
27
|
+
validate(communicationRequest);
|
|
28
|
+
if (!communicationRequest.rawToken) {
|
|
29
|
+
console.log('raw token is required.');
|
|
30
|
+
throw new Error('raw token is required.');
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
let invokePayLoad = await generatePayload(communicationRequest.method, communicationRequest.path, communicationRequest.jsonData, communicationRequest.userType, communicationRequest.rawToken);
|
|
34
|
+
let params = {
|
|
35
|
+
FunctionName: environment.concat('-', communicationRequest.moduleName, '-', 'API'),
|
|
36
|
+
InvocationType: 'RequestResponse',
|
|
37
|
+
Payload: invokePayLoad
|
|
38
|
+
}
|
|
39
|
+
let response = await lambdaClient.invoke(params).promise();
|
|
40
|
+
console.log("LambdaCommunicationService : invokeAPI : End : " );
|
|
41
|
+
|
|
42
|
+
return response.Payload;
|
|
43
|
+
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.log("error occured while invoking api ", error);
|
|
46
|
+
console.log("LambdaCommunicationService : invokeAPI : Error : " + JSON.stringify(error.name));
|
|
47
|
+
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
},async invokeLambdaAPI(communicationRequest) {
|
|
51
|
+
console.log("LambdaCommunicationService : invokeLambdaAPI : Start : " );
|
|
52
|
+
validate(communicationRequest);
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
let invokePayLoad = await generatePayload(communicationRequest.method, communicationRequest.path, communicationRequest.jsonData, communicationRequest.userType, '', communicationRequest.id, communicationRequest.parentId, communicationRequest.resellerId,communicationRequest.merchantId);
|
|
56
|
+
let params = {
|
|
57
|
+
FunctionName: environment.concat('-', communicationRequest.moduleName, '-', 'API'),
|
|
58
|
+
InvocationType: 'RequestResponse',
|
|
59
|
+
Payload: invokePayLoad
|
|
60
|
+
}
|
|
61
|
+
let response = await lambdaClient.invoke(params).promise();
|
|
62
|
+
console.log("LambdaCommunicationService : invokeLambdaAPI : End : " );
|
|
63
|
+
|
|
64
|
+
return response.Payload;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.log("error occured while invoking api ", error);
|
|
67
|
+
console.log("LambdaCommunicationService : invokeLambdaAPI : Error : " + JSON.stringify(error.name));
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
},async generateJWTToken(userType, id, parentId, resellerId,merchantId){
|
|
72
|
+
return await generateJWTToken(userType, id, parentId, resellerId,merchantId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function validate(communicationRequest) {
|
|
77
|
+
if (!communicationRequest) {
|
|
78
|
+
console.log('communication request is required.');
|
|
79
|
+
throw new Error('communication request is required.');
|
|
80
|
+
}
|
|
81
|
+
else if (!communicationRequest.moduleName) {
|
|
82
|
+
console.log('module name is required.');
|
|
83
|
+
throw new Error('module name is required.');
|
|
84
|
+
}
|
|
85
|
+
else if (!communicationRequest.method) {
|
|
86
|
+
console.log('method is required.');
|
|
87
|
+
throw new Error('method is required.');
|
|
88
|
+
}
|
|
89
|
+
else if (!communicationRequest.path) {
|
|
90
|
+
console.log('path is required.');
|
|
91
|
+
throw new Error('path is required.');
|
|
92
|
+
}
|
|
93
|
+
else if (!communicationRequest.userType) {
|
|
94
|
+
console.log('user type is required.');
|
|
95
|
+
throw new Error('user type is required.');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*function getUserTypeString(userType) {
|
|
100
|
+
switch (userType) {
|
|
101
|
+
case 0:
|
|
102
|
+
return "Reseller"
|
|
103
|
+
case 1:
|
|
104
|
+
return "Merchant"
|
|
105
|
+
case 2:
|
|
106
|
+
return "Global"
|
|
107
|
+
}
|
|
108
|
+
}*/
|
|
109
|
+
|
|
110
|
+
async function generatePayload(method, path, jsonData, userType, rawToken, id, parentId, resellerId = '0',merchantId) {
|
|
111
|
+
console.log("inside generatePayload start")
|
|
112
|
+
|
|
113
|
+
if (!rawToken || rawToken === ''){
|
|
114
|
+
rawToken = await generateJWTToken(userType, id, parentId, resellerId,merchantId);
|
|
115
|
+
}
|
|
116
|
+
let queryStringParameters;
|
|
117
|
+
|
|
118
|
+
let queryString = path.indexOf('?', 0) > 0 ? path.substring(path.indexOf('?', 0)) : '';
|
|
119
|
+
|
|
120
|
+
if (queryString || queryString !== ''){
|
|
121
|
+
queryStringParameters = parseQueryString(queryString);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let apiEvent = {
|
|
125
|
+
"httpMethod": method,
|
|
126
|
+
"path": path.indexOf("?", 0) > 0 ? path.substring(0, path.indexOf("?", 0)) : path,
|
|
127
|
+
"pathParameters": { "proxy": path },
|
|
128
|
+
"body": (jsonData!= undefined&&jsonData!="") ? JSON.stringify(jsonData):"",
|
|
129
|
+
"requestContext": {
|
|
130
|
+
"requestId": uuidv1().toString(),
|
|
131
|
+
"identity": {
|
|
132
|
+
"caller": "",
|
|
133
|
+
"userAgent": "HPG-LambdaCommunicator"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"headers": {
|
|
137
|
+
"via": "",
|
|
138
|
+
"X-Forwarded-For": "",
|
|
139
|
+
"Accept": "application/json",
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
"User-Agent": "HPG-LambdaCommunicator",
|
|
142
|
+
"Authorization": "Bearer ".concat(rawToken),
|
|
143
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
144
|
+
|
|
145
|
+
},
|
|
146
|
+
"stageVariables": {"env":`${environment}`},
|
|
147
|
+
"queryStringParameters": queryStringParameters
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* let apiEvent = {
|
|
151
|
+
HttpMethod: method,
|
|
152
|
+
Path: path.indexOf('?', 0) > 0 ? path.substring(0, path.indexOf('?', 0)) : path,
|
|
153
|
+
PathParameters: { "proxy": path },
|
|
154
|
+
Body: jsonData!= undefined ? JSON.stringify(jsonData):'',
|
|
155
|
+
RequestContext: {
|
|
156
|
+
RequestId: uuidv1().toString(),
|
|
157
|
+
Identity: {
|
|
158
|
+
Caller: "",
|
|
159
|
+
UserAgent: "HPG-LambdaCommunicator"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
Headers: {
|
|
163
|
+
"Via": "",
|
|
164
|
+
"X-Forwarded-For": "",
|
|
165
|
+
"Accept": "application/json",
|
|
166
|
+
"Content-Type": "application/json",
|
|
167
|
+
"User-Agent": "HPG-LambdaCommunicator",
|
|
168
|
+
"Authorization": "Bearer ".concat(rawToken),
|
|
169
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
170
|
+
|
|
171
|
+
},
|
|
172
|
+
StageVariables: {},
|
|
173
|
+
QueryStringParameters: queryStringParameters
|
|
174
|
+
}*/
|
|
175
|
+
console.log("inside generatePayload end")
|
|
176
|
+
|
|
177
|
+
return JSON.stringify(apiEvent);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function parseQueryString(query) {
|
|
181
|
+
let queryDict = new Object();
|
|
182
|
+
let queryArray = query.replace(/^\?*/, '').split('&');
|
|
183
|
+
|
|
184
|
+
queryArray.forEach(element => {
|
|
185
|
+
//let parts = element.replace(/^\=*/, '');
|
|
186
|
+
let parts = element.split('=');
|
|
187
|
+
console.log(parts)
|
|
188
|
+
if (parts.length == 2)
|
|
189
|
+
queryDict[parts[0].trim()] = decodeURI(parts[1]).trim();
|
|
190
|
+
else
|
|
191
|
+
queryDict[parts[0].trim()] = "";
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return queryDict;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function generateJWTToken(userType, id, parentId, resellerId,merchantId) {
|
|
198
|
+
console.log("inside generateJWTToken start")
|
|
199
|
+
const ssmConfig = await SSMConfig.ssmConfig(ssmParam);
|
|
200
|
+
console.log(parentId)
|
|
201
|
+
|
|
202
|
+
let payload = {
|
|
203
|
+
Id: id,
|
|
204
|
+
sub: "System",
|
|
205
|
+
Admin: "1",
|
|
206
|
+
UserType: userType,
|
|
207
|
+
jit: "0",
|
|
208
|
+
Role: "0",
|
|
209
|
+
ParentId: (parentId === undefined || parentId === "0")? "0":parentId.toString(),
|
|
210
|
+
ResellerId: resellerId,
|
|
211
|
+
MerchantId: (merchantId === undefined || merchantId === "0")? "0":merchantId.toString(),
|
|
212
|
+
Service: "Service"
|
|
213
|
+
};
|
|
214
|
+
let secretSigningKey = ssmConfig.SigningKey;
|
|
215
|
+
let tokenIssuer = ssmConfig.Issuer;
|
|
216
|
+
let signOptions = {
|
|
217
|
+
issuer: tokenIssuer,
|
|
218
|
+
audience: "HPGServer",
|
|
219
|
+
expiresIn: "2h",
|
|
220
|
+
notBefore: ms('0s')
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
let token = jwt.sign(payload, secretSigningKey, signOptions);
|
|
224
|
+
console.log(token);
|
|
225
|
+
console.log("inside generateJWTToken end");
|
|
226
|
+
|
|
227
|
+
return token;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
// var obj = new LambdaCommunicationService();
|
|
233
233
|
// obj.invokeAPI("Infrastructure", "POST", "users/sessions", { userName: "SKIndiaMerchant", password: "Admin@1234" }, userType = 1)
|
package/utils/enumHelper.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
// returns key/enum based on enum value
|
|
3
|
-
getEnumByValue: function (obj, val) {
|
|
4
|
-
return Object.keys(obj).filter(function (k) {
|
|
5
|
-
return obj[k] === val;
|
|
6
|
-
}).pop() || null;
|
|
7
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
// returns key/enum based on enum value
|
|
3
|
+
getEnumByValue: function (obj, val) {
|
|
4
|
+
return Object.keys(obj).filter(function (k) {
|
|
5
|
+
return obj[k] === val;
|
|
6
|
+
}).pop() || null;
|
|
7
|
+
}
|
|
8
8
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
const httpClient = require( "axios" );
|
|
2
|
-
module.exports = {
|
|
3
|
-
|
|
4
|
-
async shortenURL(longURL,apiUrl,accessToken ){
|
|
5
|
-
let shortURL = "";
|
|
6
|
-
var reqHeaders = {
|
|
7
|
-
'Content-Type': 'application/json'
|
|
8
|
-
}
|
|
9
|
-
try{
|
|
10
|
-
let url = encodeURIComponent( longURL )
|
|
11
|
-
let requestBody = {
|
|
12
|
-
};
|
|
13
|
-
let postURL = apiUrl+"?access_token="+accessToken+`&longUrl=${url}`;
|
|
14
|
-
let response = await httpClient.post( postURL ,requestBody,{ "headers": reqHeaders });
|
|
15
|
-
if( response && response.status === 200 ){
|
|
16
|
-
shortURL = response.data.data.url;
|
|
17
|
-
}
|
|
18
|
-
}catch(error){
|
|
19
|
-
console.log(`error occured while shortening url - ${longURL}`);
|
|
20
|
-
console.log(error);
|
|
21
|
-
}
|
|
22
|
-
return shortURL;
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
1
|
+
const httpClient = require( "axios" );
|
|
2
|
+
module.exports = {
|
|
3
|
+
|
|
4
|
+
async shortenURL(longURL,apiUrl,accessToken ){
|
|
5
|
+
let shortURL = "";
|
|
6
|
+
var reqHeaders = {
|
|
7
|
+
'Content-Type': 'application/json'
|
|
8
|
+
}
|
|
9
|
+
try{
|
|
10
|
+
let url = encodeURIComponent( longURL )
|
|
11
|
+
let requestBody = {
|
|
12
|
+
};
|
|
13
|
+
let postURL = apiUrl+"?access_token="+accessToken+`&longUrl=${url}`;
|
|
14
|
+
let response = await httpClient.post( postURL ,requestBody,{ "headers": reqHeaders });
|
|
15
|
+
if( response && response.status === 200 ){
|
|
16
|
+
shortURL = response.data.data.url;
|
|
17
|
+
}
|
|
18
|
+
}catch(error){
|
|
19
|
+
console.log(`error occured while shortening url - ${longURL}`);
|
|
20
|
+
console.log(error);
|
|
21
|
+
}
|
|
22
|
+
return shortURL;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
26
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
let Validator = require("fastest-validator");
|
|
3
|
-
let v = new Validator({
|
|
4
|
-
messages: {
|
|
5
|
-
// Register our new error message text
|
|
6
|
-
errorMessage: "The '{field}' field must be an even number! Actual: {actual}"
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
validateRequest = (schema,dto)=> {
|
|
11
|
-
const log = require('../index').Logger;
|
|
12
|
-
var check = v.compile(schema);
|
|
13
|
-
let validationResponse = check(dto)
|
|
14
|
-
log.info('dto validated ' + JSON.stringify(validationResponse));
|
|
15
|
-
if (validationResponse.length>0 ) {
|
|
16
|
-
log.error('data validation failed33333');
|
|
17
|
-
let response=createErrorResponse(validationResponse);
|
|
18
|
-
log.error('data validation failed111' + response);
|
|
19
|
-
return response
|
|
20
|
-
} else {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function createErrorResponse (validationResponse) {
|
|
26
|
-
var errors = [];
|
|
27
|
-
var error;
|
|
28
|
-
const log = require('../index').Logger;
|
|
29
|
-
validationResponse.forEach(function (errorRow) {
|
|
30
|
-
error = {
|
|
31
|
-
"message": errorRow.message,
|
|
32
|
-
"field": errorRow.field,
|
|
33
|
-
"description": ""
|
|
34
|
-
}
|
|
35
|
-
errors.push(error);
|
|
36
|
-
});
|
|
37
|
-
log.info('errors::: ' + JSON.stringify(errors));
|
|
38
|
-
return errors;
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
module.exports = {
|
|
43
|
-
generateErrorResponse : createErrorResponse,
|
|
44
|
-
validateRequest : validateRequest
|
|
45
|
-
};
|
|
1
|
+
|
|
2
|
+
let Validator = require("fastest-validator");
|
|
3
|
+
let v = new Validator({
|
|
4
|
+
messages: {
|
|
5
|
+
// Register our new error message text
|
|
6
|
+
errorMessage: "The '{field}' field must be an even number! Actual: {actual}"
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
validateRequest = (schema,dto)=> {
|
|
11
|
+
const log = require('../index').Logger;
|
|
12
|
+
var check = v.compile(schema);
|
|
13
|
+
let validationResponse = check(dto)
|
|
14
|
+
log.info('dto validated ' + JSON.stringify(validationResponse));
|
|
15
|
+
if (validationResponse.length>0 ) {
|
|
16
|
+
log.error('data validation failed33333');
|
|
17
|
+
let response=createErrorResponse(validationResponse);
|
|
18
|
+
log.error('data validation failed111' + response);
|
|
19
|
+
return response
|
|
20
|
+
} else {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createErrorResponse (validationResponse) {
|
|
26
|
+
var errors = [];
|
|
27
|
+
var error;
|
|
28
|
+
const log = require('../index').Logger;
|
|
29
|
+
validationResponse.forEach(function (errorRow) {
|
|
30
|
+
error = {
|
|
31
|
+
"message": errorRow.message,
|
|
32
|
+
"field": errorRow.field,
|
|
33
|
+
"description": ""
|
|
34
|
+
}
|
|
35
|
+
errors.push(error);
|
|
36
|
+
});
|
|
37
|
+
log.info('errors::: ' + JSON.stringify(errors));
|
|
38
|
+
return errors;
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
generateErrorResponse : createErrorResponse,
|
|
44
|
+
validateRequest : validateRequest
|
|
45
|
+
};
|
|
46
46
|
//exports.generateErrorResponse=createErrorResponse
|
|
File without changes
|