@platform-x/hep-notification-client 1.0.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/dist/src/common/service/requestService.js +96 -0
- package/dist/src/common/service/twilioService.js +55 -0
- package/dist/src/common/util/commonUtil.js +44 -0
- package/dist/src/common/util/errorHandler.js +89 -0
- package/dist/src/common/util/logger.js +193 -0
- package/dist/src/common/util/requestTracer.js +17 -0
- package/dist/src/common/util/solrConnector.js +157 -0
- package/dist/src/config/index.js +52 -0
- package/dist/src/index.js +8 -0
- package/dist/src/platform-x/constants/index.js +15 -0
- package/dist/src/platform-x/constants/style.js +103 -0
- package/dist/src/platform-x/dataSource/emailDataSource.js +36 -0
- package/dist/src/platform-x/database/connection.js +51 -0
- package/dist/src/platform-x/database/dao/formBuilder.dao.js +51 -0
- package/dist/src/platform-x/database/index.js +9 -0
- package/dist/src/platform-x/database/models/formBuilder.model.js +35 -0
- package/dist/src/platform-x/util/emailHandler.js +458 -0
- package/dist/src/platform-x/util/emailTemplate.js +82 -0
- package/dist/src/platform-x/util/solr-data-source/SolrHttpDataSource.js +75 -0
- package/package.json +61 -0
- package/templates/orderPlaced.ejs +173 -0
- package/templates/orderPlaced.html +190 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpRequestHandler = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const logger_1 = require("../util/logger");
|
|
18
|
+
const https_1 = __importDefault(require("https"));
|
|
19
|
+
const errorHandler_1 = require("../util/errorHandler");
|
|
20
|
+
const constants_1 = require("../../platform-x/constants");
|
|
21
|
+
class HttpRequestHandler {
|
|
22
|
+
// NOSONAR-NEXT-LINE
|
|
23
|
+
constructor() {
|
|
24
|
+
this.requestTimeout = 1000 * 30;
|
|
25
|
+
} // NOSONAR
|
|
26
|
+
/**
|
|
27
|
+
* post - handler to do post api calls
|
|
28
|
+
* @param requestConfig
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
post(requestConfig) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
logger_1.Logger.info('HttpRequestHandler: Reached post method', 'post');
|
|
34
|
+
const { url, body } = requestConfig;
|
|
35
|
+
const defaultOptions = {
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': constants_1.HTTP_CONTENT_TYPE_JSON,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
let options = requestConfig.options || defaultOptions;
|
|
41
|
+
options.httpsAgent = new https_1.default.Agent({
|
|
42
|
+
rejectUnauthorized: true,
|
|
43
|
+
});
|
|
44
|
+
if (!options.headers) {
|
|
45
|
+
options.headers = {};
|
|
46
|
+
}
|
|
47
|
+
options.timeout = this.requestTimeout;
|
|
48
|
+
return axios_1.default
|
|
49
|
+
.post(url, body, options)
|
|
50
|
+
.then((res) => {
|
|
51
|
+
logger_1.Logger.info('HttpRequestHandler: Successfull Response', 'post');
|
|
52
|
+
return res.data;
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
var _a;
|
|
56
|
+
let apiError = new errorHandler_1.ApiError(err.message, (_a = err.response) === null || _a === void 0 ? void 0 : _a.status);
|
|
57
|
+
logger_1.Logger.error('HttpRequestHandler: Error in post', 'post', err);
|
|
58
|
+
throw apiError;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* get - handler to do get api calls
|
|
64
|
+
* @param requestConfig
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
get(requestConfig) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
logger_1.Logger.info('HttpRequestHandler: Reached get method', 'get');
|
|
70
|
+
const { url } = requestConfig;
|
|
71
|
+
const defaultOptions = {};
|
|
72
|
+
let options = requestConfig.options || defaultOptions;
|
|
73
|
+
options.httpsAgent = new https_1.default.Agent({
|
|
74
|
+
rejectUnauthorized: true,
|
|
75
|
+
});
|
|
76
|
+
if (!options.headers) {
|
|
77
|
+
options.headers = {};
|
|
78
|
+
}
|
|
79
|
+
options.timeout = this.requestTimeout;
|
|
80
|
+
return axios_1.default
|
|
81
|
+
.get(url, options)
|
|
82
|
+
.then((res) => {
|
|
83
|
+
logger_1.Logger.info('HttpRequestHandler: Successfull Response', 'get');
|
|
84
|
+
return res.data;
|
|
85
|
+
})
|
|
86
|
+
.catch((err) => {
|
|
87
|
+
var _a;
|
|
88
|
+
let apiError = new errorHandler_1.ApiError(err.message, (_a = err.response) === null || _a === void 0 ? void 0 : _a.status);
|
|
89
|
+
logger_1.Logger.error('HttpRequestHandler: Error in get', 'get', err);
|
|
90
|
+
throw apiError;
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.HttpRequestHandler = HttpRequestHandler;
|
|
96
|
+
//# sourceMappingURL=requestService.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TwilioService = void 0;
|
|
16
|
+
const twilio_1 = __importDefault(require("twilio"));
|
|
17
|
+
const logger_1 = require("../util/logger");
|
|
18
|
+
class TwilioService {
|
|
19
|
+
/**
|
|
20
|
+
* Constructor to initialize Twilio client and sender number
|
|
21
|
+
* @param accountSid - Twilio Account SID
|
|
22
|
+
* @param authToken - Twilio Auth Token
|
|
23
|
+
* @param senderNumber - Twilio Sender Phone Number
|
|
24
|
+
*/
|
|
25
|
+
constructor(accountSid, authToken, senderNumber) {
|
|
26
|
+
this.client = (0, twilio_1.default)(accountSid, authToken);
|
|
27
|
+
this.senderNumber = senderNumber;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Send an SMS using Twilio
|
|
31
|
+
* @param to - Recipient's phone number
|
|
32
|
+
* @param message - Message content
|
|
33
|
+
* @returns Promise resolving with the Twilio response
|
|
34
|
+
*/
|
|
35
|
+
sendSMS(to, message) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
logger_1.Logger.info('twilioService: Reached sendSMS', 'sendSMS');
|
|
38
|
+
logger_1.Logger.debug('twilioService: check message and recipient number', 'sendSMS', { to, message });
|
|
39
|
+
try {
|
|
40
|
+
const response = yield this.client.messages.create({
|
|
41
|
+
body: message,
|
|
42
|
+
from: this.senderNumber,
|
|
43
|
+
to,
|
|
44
|
+
});
|
|
45
|
+
return response;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger_1.Logger.error('twilioService: error in send SMS by twilio', 'sendSMS', error);
|
|
49
|
+
throw new Error('Failed to send SMS');
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.TwilioService = TwilioService;
|
|
55
|
+
//# sourceMappingURL=twilioService.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validate = exports.validateMessage = exports.validatePhoneNumber = void 0;
|
|
4
|
+
const errorHandler_1 = require("./errorHandler");
|
|
5
|
+
/**
|
|
6
|
+
* Validate a phone number for format and length
|
|
7
|
+
* @param phoneNumber
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
const validatePhoneNumber = (phoneNumber) => {
|
|
11
|
+
// Regular expression for validating international phone numbers
|
|
12
|
+
const phoneRegex = /^\+?[1-9]\d{1,14}$/; // E.164 format
|
|
13
|
+
return phoneRegex === null || phoneRegex === void 0 ? void 0 : phoneRegex.test(phoneNumber);
|
|
14
|
+
};
|
|
15
|
+
exports.validatePhoneNumber = validatePhoneNumber;
|
|
16
|
+
/**
|
|
17
|
+
* Validate a message for length and content
|
|
18
|
+
* @param message
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const validateMessage = (message) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const maxLength = 250; // Standard SMS max length
|
|
24
|
+
return ((_a = message === null || message === void 0 ? void 0 : message.trim()) === null || _a === void 0 ? void 0 : _a.length) > 0 && (message === null || message === void 0 ? void 0 : message.length) <= maxLength;
|
|
25
|
+
};
|
|
26
|
+
exports.validateMessage = validateMessage;
|
|
27
|
+
/**
|
|
28
|
+
* Validate both phone number and message
|
|
29
|
+
* @param phoneNumber
|
|
30
|
+
* @param message
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
const validate = (phoneNumber, message) => {
|
|
34
|
+
const errors = [];
|
|
35
|
+
if (!(0, exports.validatePhoneNumber)(phoneNumber)) {
|
|
36
|
+
(0, errorHandler_1.throwError)('Invalid phone number format. Ensure it follows +915647374757 like this.');
|
|
37
|
+
}
|
|
38
|
+
if (!(0, exports.validateMessage)(message)) {
|
|
39
|
+
(0, errorHandler_1.throwError)('Message must be between 1 and 250 characters.');
|
|
40
|
+
}
|
|
41
|
+
return { valid: true, errors: '' };
|
|
42
|
+
};
|
|
43
|
+
exports.validate = validate;
|
|
44
|
+
//# sourceMappingURL=commonUtil.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwError = exports.errorMapper = exports.CustomError = exports.SolrError = exports.ApiError = exports.CommonErrorTemplate = exports.HTTP_STATUS_MAP = void 0;
|
|
4
|
+
exports.HTTP_STATUS_MAP = new Map([
|
|
5
|
+
[500, 'Internal Server Error']
|
|
6
|
+
]);
|
|
7
|
+
class CommonErrorTemplate extends Error {
|
|
8
|
+
constructor(msg, code) {
|
|
9
|
+
super(msg);
|
|
10
|
+
this.code = code || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
11
|
+
this.type =
|
|
12
|
+
exports.HTTP_STATUS_MAP.get(this.code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
13
|
+
}
|
|
14
|
+
toJSON() {
|
|
15
|
+
return {
|
|
16
|
+
code: this.code,
|
|
17
|
+
type: this.type,
|
|
18
|
+
message: this.message,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.CommonErrorTemplate = CommonErrorTemplate;
|
|
23
|
+
class ApiError extends CommonErrorTemplate {
|
|
24
|
+
constructor(msg, code) {
|
|
25
|
+
super(msg, code);
|
|
26
|
+
this.name = 'ApiError';
|
|
27
|
+
Error.captureStackTrace(this, ApiError);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ApiError = ApiError;
|
|
31
|
+
class SolrError extends CommonErrorTemplate {
|
|
32
|
+
constructor(msg, code) {
|
|
33
|
+
super(msg, code);
|
|
34
|
+
this.name = 'SolrError';
|
|
35
|
+
Error.captureStackTrace(this, SolrError);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SolrError = SolrError;
|
|
39
|
+
class CustomError {
|
|
40
|
+
constructor(errObj, code, type, message, stack) {
|
|
41
|
+
this.code = code;
|
|
42
|
+
this.type = type;
|
|
43
|
+
this.message = message;
|
|
44
|
+
this.stack = stack;
|
|
45
|
+
this.errorObj = errObj;
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
// NOSONAR
|
|
49
|
+
return {
|
|
50
|
+
code: this.code,
|
|
51
|
+
type: this.type,
|
|
52
|
+
message: this.message,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.CustomError = CustomError;
|
|
57
|
+
/**
|
|
58
|
+
* errorMapper - to map error object to custom error
|
|
59
|
+
*/
|
|
60
|
+
const errorMapper = (err, statusCode, type) => {
|
|
61
|
+
let error;
|
|
62
|
+
let customError;
|
|
63
|
+
let code = statusCode || 500 /* HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR */;
|
|
64
|
+
let errorType = type || exports.HTTP_STATUS_MAP.get(code) || "Internal Server Error" /* HTTP_STATUS_TYPE.INTERNAL_SERVER_ERROR */;
|
|
65
|
+
if (typeof err === 'string') {
|
|
66
|
+
error = new Error(err);
|
|
67
|
+
customError = new CustomError(null, code, errorType, error.message, error.stack);
|
|
68
|
+
return customError;
|
|
69
|
+
}
|
|
70
|
+
else if (err.stack &&
|
|
71
|
+
err.message &&
|
|
72
|
+
!(err instanceof CustomError) &&
|
|
73
|
+
!err.toJSON) {
|
|
74
|
+
customError = new CustomError(null, code, errorType, err.message, err.stack);
|
|
75
|
+
return customError;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return err;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.errorMapper = errorMapper;
|
|
82
|
+
/**
|
|
83
|
+
* throwError - to throw custome error
|
|
84
|
+
*/
|
|
85
|
+
const throwError = (err, statusCode, type) => {
|
|
86
|
+
throw (0, exports.errorMapper)(err, statusCode, type);
|
|
87
|
+
};
|
|
88
|
+
exports.throwError = throwError;
|
|
89
|
+
//# sourceMappingURL=errorHandler.js.map
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Logger = exports.LoggerClass = void 0;
|
|
7
|
+
const bunyan_1 = __importDefault(require("bunyan"));
|
|
8
|
+
const index_1 = __importDefault(require("../../config/index"));
|
|
9
|
+
const bunyan_format_1 = __importDefault(require("bunyan-format"));
|
|
10
|
+
const requestTracer_1 = require("./requestTracer");
|
|
11
|
+
class LoggerClass {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.infoLevel = false;
|
|
14
|
+
this.debugLevel = false;
|
|
15
|
+
this.errorLevel = false;
|
|
16
|
+
this.warnLevel = false;
|
|
17
|
+
this.blockedKeywords = ['currentPassword', 'clientSecret', 'newPassword'];
|
|
18
|
+
this.mapLogLevels();
|
|
19
|
+
this.logger = bunyan_1.default.createLogger({
|
|
20
|
+
name: index_1.default.APP_NAME,
|
|
21
|
+
level: 'trace', // by default enabling all levels, controlled through env separately
|
|
22
|
+
stream: (0, bunyan_format_1.default)({
|
|
23
|
+
outputMode: index_1.default.NODE_ENV === 'development' ? 'short' : 'bunyan',
|
|
24
|
+
levelInString: true,
|
|
25
|
+
color: true,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* It's written to handle JSON.circular error
|
|
31
|
+
* @param obj
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
customstringify(obj) {
|
|
35
|
+
let cache = [];
|
|
36
|
+
let str = JSON.stringify(obj, (key, value) => {
|
|
37
|
+
{
|
|
38
|
+
if (typeof value === 'object' && value !== null) {
|
|
39
|
+
if (cache.indexOf(value) !== -1) {
|
|
40
|
+
// Circular reference found, discard key
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Store value in our collection
|
|
44
|
+
cache.push(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
cache = null; // reset the cache
|
|
50
|
+
return str;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* for info log
|
|
54
|
+
* @param message
|
|
55
|
+
* @param payload
|
|
56
|
+
* @param method
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
info(message, method) {
|
|
60
|
+
if (!this.infoLevel) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let loggerParams = {
|
|
64
|
+
message,
|
|
65
|
+
method,
|
|
66
|
+
traceId: (0, requestTracer_1.getTraceId)(),
|
|
67
|
+
};
|
|
68
|
+
this.logger.info(` start ${JSON.stringify(loggerParams)} ==end`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* for warn log
|
|
72
|
+
* @param message
|
|
73
|
+
* @param payload
|
|
74
|
+
* @param method
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
warn(message, method, payload) {
|
|
78
|
+
if (!this.warnLevel) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let loggerParams = {
|
|
82
|
+
message,
|
|
83
|
+
method,
|
|
84
|
+
traceId: (0, requestTracer_1.getTraceId)(),
|
|
85
|
+
statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
|
|
86
|
+
};
|
|
87
|
+
let finalPayload = payload !== undefined ? payload : {};
|
|
88
|
+
this.logger.warn(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* for error log
|
|
92
|
+
* @param message
|
|
93
|
+
* @param payload
|
|
94
|
+
* @param method
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
error(message, method, payload) {
|
|
98
|
+
if (!this.errorLevel) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (payload instanceof Error) {
|
|
102
|
+
payload = {
|
|
103
|
+
message,
|
|
104
|
+
method,
|
|
105
|
+
traceId: (0, requestTracer_1.getTraceId)(),
|
|
106
|
+
stack: payload === null || payload === void 0 ? void 0 : payload.stack,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
let loggerParams = {
|
|
110
|
+
message,
|
|
111
|
+
method,
|
|
112
|
+
traceId: (0, requestTracer_1.getTraceId)(),
|
|
113
|
+
spanId: (0, requestTracer_1.getSpanId)(),
|
|
114
|
+
statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
|
|
115
|
+
};
|
|
116
|
+
let finalPayload = payload !== undefined ? payload : {};
|
|
117
|
+
this.logger.error(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* for debug log
|
|
121
|
+
* @param message
|
|
122
|
+
* @param payload
|
|
123
|
+
* @param method
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
debug(message, method, payload) {
|
|
127
|
+
if (!this.debugLevel) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let loggerParams = {
|
|
131
|
+
message,
|
|
132
|
+
method,
|
|
133
|
+
traceId: (0, requestTracer_1.getTraceId)(),
|
|
134
|
+
statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
|
|
135
|
+
};
|
|
136
|
+
let finalPayload = payload !== undefined ? payload : {};
|
|
137
|
+
this.logger.debug(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* to map log levels and handle from config
|
|
141
|
+
*/
|
|
142
|
+
mapLogLevels() {
|
|
143
|
+
if (index_1.default.LOG_LEVELS.length) {
|
|
144
|
+
index_1.default.LOG_LEVELS.forEach((element) => {
|
|
145
|
+
const logLevel = element.trim();
|
|
146
|
+
if (logLevel === 'info') {
|
|
147
|
+
this.infoLevel = true;
|
|
148
|
+
}
|
|
149
|
+
else if (logLevel === 'debug') {
|
|
150
|
+
this.debugLevel = true;
|
|
151
|
+
}
|
|
152
|
+
else if (logLevel === 'error') {
|
|
153
|
+
this.errorLevel = true;
|
|
154
|
+
}
|
|
155
|
+
else if (logLevel === 'warn') {
|
|
156
|
+
this.warnLevel = true;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* to sanitize logs from unwanted fields to be shown
|
|
163
|
+
* @param request
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
sanitizeLog(request) {
|
|
167
|
+
try {
|
|
168
|
+
if (request) {
|
|
169
|
+
Object.keys(request).forEach((key) => {
|
|
170
|
+
let value = request[key];
|
|
171
|
+
if (request[key] === 'options') {
|
|
172
|
+
delete request.options;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (this.blockedKeywords.find((blockedKey) => key.toLowerCase() === blockedKey.toLowerCase())) {
|
|
176
|
+
request[key] = 'XXXXXXXXXX';
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
request[key] = value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return request;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
this.error('Logger sanitize error', err);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.LoggerClass = LoggerClass;
|
|
192
|
+
exports.Logger = new LoggerClass();
|
|
193
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSpanId = exports.getTraceId = void 0;
|
|
7
|
+
const cls_hooked_1 = __importDefault(require("cls-hooked"));
|
|
8
|
+
const uuid_1 = require("uuid");
|
|
9
|
+
const nsid = `rtracer:${(0, uuid_1.v4)()}`;
|
|
10
|
+
const ns = cls_hooked_1.default.createNamespace(nsid);
|
|
11
|
+
const traceIdKey = 'traceId';
|
|
12
|
+
const spanIdKey = 'spanId';
|
|
13
|
+
const getTraceId = () => ns.get(traceIdKey);
|
|
14
|
+
exports.getTraceId = getTraceId;
|
|
15
|
+
const getSpanId = () => ns.get(spanIdKey);
|
|
16
|
+
exports.getSpanId = getSpanId;
|
|
17
|
+
//# sourceMappingURL=requestTracer.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SolrClient = void 0;
|
|
16
|
+
const logger_1 = require("./logger");
|
|
17
|
+
const index_1 = __importDefault(require("../../config/index"));
|
|
18
|
+
const errorHandler_1 = require("./errorHandler");
|
|
19
|
+
const constants_1 = require("../../platform-x/constants");
|
|
20
|
+
const solr = require('solr-client');
|
|
21
|
+
class SolrClient {
|
|
22
|
+
constructor(core) {
|
|
23
|
+
this.host = index_1.default.SOLR.HOST || '';
|
|
24
|
+
this.port = Number(index_1.default.SOLR.PORT);
|
|
25
|
+
this.path = index_1.default.SOLR.PATH || '/solr';
|
|
26
|
+
this.secure = false;
|
|
27
|
+
this.core = core || process.env.SOLR_CORE || '';
|
|
28
|
+
const options = {
|
|
29
|
+
host: this.host,
|
|
30
|
+
port: this.port,
|
|
31
|
+
core: this.core,
|
|
32
|
+
path: this.path,
|
|
33
|
+
secure: this.secure,
|
|
34
|
+
};
|
|
35
|
+
this.solrNodeClient = solr.createClient(options);
|
|
36
|
+
this.solrQuery = null;
|
|
37
|
+
}
|
|
38
|
+
getQuery() {
|
|
39
|
+
return this.solrQuery;
|
|
40
|
+
}
|
|
41
|
+
createQuery() {
|
|
42
|
+
this.solrQuery = this.solrNodeClient.createQuery();
|
|
43
|
+
return {
|
|
44
|
+
query: this.query.bind(this),
|
|
45
|
+
filterQuery: this.filterQuery.bind(this),
|
|
46
|
+
sort: this.sort.bind(this),
|
|
47
|
+
filterList: this.filterList.bind(this),
|
|
48
|
+
paginate: this.paginate.bind(this),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
executeSearch() {
|
|
52
|
+
logger_1.Logger.info('SOLR ExecuteSearch Reached', 'executeSearch');
|
|
53
|
+
const q = this.solrQuery;
|
|
54
|
+
logger_1.Logger.debug('Before calling search method', 'executeSearch', q);
|
|
55
|
+
//try {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
this.solrNodeClient.search(q, function (err, res) {
|
|
58
|
+
if (err) {
|
|
59
|
+
logger_1.Logger.error(`Error in Solr Search for query:--------------------->`, 'executeSearch', err);
|
|
60
|
+
let solrError = new errorHandler_1.SolrError(err.message || err.name, Number(err.statusCode));
|
|
61
|
+
logger_1.Logger.error('Error in Solr Search for query: ${q}', 'solrSearch', err);
|
|
62
|
+
reject(solrError);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
logger_1.Logger.debug('Before returning search result', 'executeSearch', res);
|
|
66
|
+
resolve(res.response.docs);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
// } catch (err: any) {
|
|
71
|
+
// Logger.info(`SOLR EXECUTION ERRROR------${err}`);
|
|
72
|
+
// throw err;
|
|
73
|
+
// }
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* solrSearch- fn to call solr search
|
|
77
|
+
* @param queryParams
|
|
78
|
+
* @param fields
|
|
79
|
+
* @param fieldType
|
|
80
|
+
* @param sortData
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
solrSearch(queryParams, fields, fieldType, sortData, filterQuery) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
logger_1.Logger.debug('Before calling solrSearch method', 'solrSearch', queryParams);
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
logger_1.Logger.info('Reached Solr Search', 'solrSearch');
|
|
88
|
+
logger_1.Logger.debug('Reached Solr Search', 'solrSearch', { queryParams });
|
|
89
|
+
const defaultRows = constants_1.DEFAULT_SOLR_ROWS;
|
|
90
|
+
let query = this.solrNodeClient.createQuery();
|
|
91
|
+
if (filterQuery) {
|
|
92
|
+
query.matchFilter(filterQuery === null || filterQuery === void 0 ? void 0 : filterQuery.filterKey, filterQuery === null || filterQuery === void 0 ? void 0 : filterQuery.filterValue);
|
|
93
|
+
}
|
|
94
|
+
if (queryParams) {
|
|
95
|
+
query.q(fieldType);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
query.q(`*:*`);
|
|
99
|
+
}
|
|
100
|
+
if (queryParams && queryParams.pagination) {
|
|
101
|
+
query.start(queryParams.pagination.start ? queryParams.pagination.start : 0);
|
|
102
|
+
query.rows(queryParams.pagination.rows
|
|
103
|
+
? queryParams.pagination.rows
|
|
104
|
+
: defaultRows);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
query.start(0);
|
|
108
|
+
query.rows(defaultRows);
|
|
109
|
+
}
|
|
110
|
+
if (fields) {
|
|
111
|
+
let fieldsTemp = Array.isArray(fields) ? fields : Object.keys(fields);
|
|
112
|
+
query.fl(fieldsTemp);
|
|
113
|
+
}
|
|
114
|
+
if (sortData) {
|
|
115
|
+
query.sort(sortData);
|
|
116
|
+
}
|
|
117
|
+
this.solrNodeClient.search(query, function (err, res) {
|
|
118
|
+
if (err) {
|
|
119
|
+
let solrError = new errorHandler_1.SolrError(err.message || err.name, Number(err.statusCode));
|
|
120
|
+
logger_1.Logger.error(`Error in Solr Search for query: ${query}`, 'solrSearch', err);
|
|
121
|
+
reject(solrError);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
logger_1.Logger.debug('Before returning search result', 'solrSearch', res);
|
|
125
|
+
resolve(res.response.docs);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
query(query) {
|
|
132
|
+
let queryString = query || `*:*`;
|
|
133
|
+
this.solrQuery.q(queryString);
|
|
134
|
+
}
|
|
135
|
+
paginate(start, rows) {
|
|
136
|
+
this.solrQuery.start(start || 0);
|
|
137
|
+
this.solrQuery.rows(rows || constants_1.DEFAULT_SOLR_ROWS);
|
|
138
|
+
}
|
|
139
|
+
filterList(fields) {
|
|
140
|
+
if (fields) {
|
|
141
|
+
let fieldsTemp = Array.isArray(fields) ? fields : Object.keys(fields);
|
|
142
|
+
this.solrQuery.fl(fieldsTemp);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
sort(fields) {
|
|
146
|
+
if (fields) {
|
|
147
|
+
this.solrQuery.sort(fields);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
filterQuery(fields) {
|
|
151
|
+
if (fields === null || fields === void 0 ? void 0 : fields.length) {
|
|
152
|
+
this.solrQuery.fq(fields);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.SolrClient = SolrClient;
|
|
157
|
+
//# sourceMappingURL=solrConnector.js.map
|