@optimiser/common 1.0.226 → 1.0.230

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.
@@ -185,4 +185,5 @@ declare function GetUserProfile(msp_d: AnyObjectInterface, db: Db, mdb: Db, next
185
185
  */
186
186
  declare function ErrorHandlerForServices(Error: OPT_ERROR, ServiceOrigin: string, EmailConfig: any, Module?: string, db?: Db): Promise<any>;
187
187
  declare function CheckCaptcha(token: string, captcha: string, redisClient: Redis): Promise<unknown>;
188
- export { CheckForWhiteListedDomain, ReturnJsonResponse, ConvertFileByteSize, GetObjectByKeyValueFromList, IsEqualArrays, IsEqualValue, CheckUserProfileField, GetPageFieldData, GetPageObjectSchema, GetFieldDetail, UpdateRecentViewObject, SyncChildObjectData, SyncParentObjectData, DeleteFieldInOtherCollection, SyncFieldInSameCollection, SyncFieldInSameCollectionByObjectID, SyncFieldInSameCollectionByObjectIDWithPromise, SyncFieldInOtherCollection, SyncUserInOtherCollection, BuildLookupDataField, CheckDataBeforeAdd, CheckDataBeforeUpdate, BuildGridFieldProjection, BuildFieldProjection, BuildLookupFieldProjection, FilterConditions, GirdHeaderFilters, AddLog, CheckFilterFieldsProjection, VerifyEmailPassword, GetMyTeamUsers, ExtractChildUsersTree, GetMaxKeyValueListSchema, VerifyAWSEmailConfig, GenerateId, SyncUserDetailsWithMasterDB, SignoutUserFromAllDevices, SignoutUsersWithPromise, SignoutMultipleUsersFromAllDevices, UserLicenseConsumeCalculate, sendMailWithUserAccount, GetEmailClientConfigs, GetCompanyEncryptionKey, ExecuteDynamicDMLQuery, ExecuteDynamicDQLQuery, GetUserProfilePermissions, MakeUserPasswordInvalid, ConvertJsonToXLXS, SendResetPasswordMail, SendMailToSupport, MailTemplateStructure, SendMailToCustomer, parseMSPCookie, GetIPDetailsFromReq, isEmptyObj, SyncListSchemaFieldInOtherCollection, UpdateTagCountAfterDelete, SyncTagCountAfterUpdate, ReactivateFieldInOtherCollection, SyncUserLicenceConsumedCount, BroadCastEventToAllCompanyUsers, CheckDataPermission, SyncCompanyLicenceInMasterCompanyAfterAdd, NextServiceDateForDashboard, CheckDateNotInPast, GetWeekDayByDayAndOccurance, GetInterValFromOccurance, GetWeekDayInfoInMonth, GetDayIndex, GetUserProfile, ErrorHandlerForServices, CheckCaptcha };
188
+ declare function ValidateSanitizeUserInput(inputFields: AnyObjectInterface, pageData: AnyObjectInterface): Promise<AnyObjectInterface[] | undefined>;
189
+ export { CheckForWhiteListedDomain, ReturnJsonResponse, ConvertFileByteSize, GetObjectByKeyValueFromList, IsEqualArrays, IsEqualValue, CheckUserProfileField, GetPageFieldData, GetPageObjectSchema, GetFieldDetail, UpdateRecentViewObject, SyncChildObjectData, SyncParentObjectData, DeleteFieldInOtherCollection, SyncFieldInSameCollection, SyncFieldInSameCollectionByObjectID, SyncFieldInSameCollectionByObjectIDWithPromise, SyncFieldInOtherCollection, SyncUserInOtherCollection, BuildLookupDataField, CheckDataBeforeAdd, CheckDataBeforeUpdate, BuildGridFieldProjection, BuildFieldProjection, BuildLookupFieldProjection, FilterConditions, GirdHeaderFilters, AddLog, CheckFilterFieldsProjection, VerifyEmailPassword, GetMyTeamUsers, ExtractChildUsersTree, GetMaxKeyValueListSchema, VerifyAWSEmailConfig, GenerateId, SyncUserDetailsWithMasterDB, SignoutUserFromAllDevices, SignoutUsersWithPromise, SignoutMultipleUsersFromAllDevices, UserLicenseConsumeCalculate, sendMailWithUserAccount, GetEmailClientConfigs, GetCompanyEncryptionKey, ExecuteDynamicDMLQuery, ExecuteDynamicDQLQuery, GetUserProfilePermissions, MakeUserPasswordInvalid, ConvertJsonToXLXS, SendResetPasswordMail, SendMailToSupport, MailTemplateStructure, SendMailToCustomer, parseMSPCookie, GetIPDetailsFromReq, isEmptyObj, SyncListSchemaFieldInOtherCollection, UpdateTagCountAfterDelete, SyncTagCountAfterUpdate, ReactivateFieldInOtherCollection, SyncUserLicenceConsumedCount, BroadCastEventToAllCompanyUsers, CheckDataPermission, SyncCompanyLicenceInMasterCompanyAfterAdd, NextServiceDateForDashboard, CheckDateNotInPast, GetWeekDayByDayAndOccurance, GetInterValFromOccurance, GetWeekDayInfoInMonth, GetDayIndex, GetUserProfile, ErrorHandlerForServices, CheckCaptcha, ValidateSanitizeUserInput };
@@ -80,7 +80,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
80
80
  return (mod && mod.__esModule) ? mod : { "default": mod };
81
81
  };
82
82
  Object.defineProperty(exports, "__esModule", { value: true });
83
- exports.CheckCaptcha = exports.ErrorHandlerForServices = exports.GetUserProfile = exports.GetDayIndex = exports.GetWeekDayInfoInMonth = exports.GetInterValFromOccurance = exports.GetWeekDayByDayAndOccurance = exports.CheckDateNotInPast = exports.NextServiceDateForDashboard = exports.SyncCompanyLicenceInMasterCompanyAfterAdd = exports.CheckDataPermission = exports.BroadCastEventToAllCompanyUsers = exports.SyncUserLicenceConsumedCount = exports.ReactivateFieldInOtherCollection = exports.SyncTagCountAfterUpdate = exports.UpdateTagCountAfterDelete = exports.SyncListSchemaFieldInOtherCollection = exports.isEmptyObj = exports.GetIPDetailsFromReq = exports.parseMSPCookie = exports.SendMailToCustomer = exports.MailTemplateStructure = exports.SendMailToSupport = exports.SendResetPasswordMail = exports.ConvertJsonToXLXS = exports.MakeUserPasswordInvalid = exports.GetUserProfilePermissions = exports.ExecuteDynamicDQLQuery = exports.ExecuteDynamicDMLQuery = exports.GetCompanyEncryptionKey = exports.GetEmailClientConfigs = exports.sendMailWithUserAccount = exports.UserLicenseConsumeCalculate = exports.SignoutMultipleUsersFromAllDevices = exports.SignoutUsersWithPromise = exports.SignoutUserFromAllDevices = exports.SyncUserDetailsWithMasterDB = exports.GenerateId = exports.VerifyAWSEmailConfig = exports.GetMaxKeyValueListSchema = exports.ExtractChildUsersTree = exports.GetMyTeamUsers = exports.VerifyEmailPassword = exports.CheckFilterFieldsProjection = exports.AddLog = exports.GirdHeaderFilters = exports.FilterConditions = exports.BuildLookupFieldProjection = exports.BuildFieldProjection = exports.BuildGridFieldProjection = exports.CheckDataBeforeUpdate = exports.CheckDataBeforeAdd = exports.BuildLookupDataField = exports.SyncUserInOtherCollection = exports.SyncFieldInOtherCollection = exports.SyncFieldInSameCollectionByObjectIDWithPromise = exports.SyncFieldInSameCollectionByObjectID = exports.SyncFieldInSameCollection = exports.DeleteFieldInOtherCollection = exports.SyncParentObjectData = exports.SyncChildObjectData = exports.UpdateRecentViewObject = exports.GetFieldDetail = exports.GetPageObjectSchema = exports.GetPageFieldData = exports.CheckUserProfileField = exports.IsEqualValue = exports.IsEqualArrays = exports.GetObjectByKeyValueFromList = exports.ConvertFileByteSize = exports.ReturnJsonResponse = exports.CheckForWhiteListedDomain = void 0;
83
+ exports.ValidateSanitizeUserInput = exports.CheckCaptcha = exports.ErrorHandlerForServices = exports.GetUserProfile = exports.GetDayIndex = exports.GetWeekDayInfoInMonth = exports.GetInterValFromOccurance = exports.GetWeekDayByDayAndOccurance = exports.CheckDateNotInPast = exports.NextServiceDateForDashboard = exports.SyncCompanyLicenceInMasterCompanyAfterAdd = exports.CheckDataPermission = exports.BroadCastEventToAllCompanyUsers = exports.SyncUserLicenceConsumedCount = exports.ReactivateFieldInOtherCollection = exports.SyncTagCountAfterUpdate = exports.UpdateTagCountAfterDelete = exports.SyncListSchemaFieldInOtherCollection = exports.isEmptyObj = exports.GetIPDetailsFromReq = exports.parseMSPCookie = exports.SendMailToCustomer = exports.MailTemplateStructure = exports.SendMailToSupport = exports.SendResetPasswordMail = exports.ConvertJsonToXLXS = exports.MakeUserPasswordInvalid = exports.GetUserProfilePermissions = exports.ExecuteDynamicDQLQuery = exports.ExecuteDynamicDMLQuery = exports.GetCompanyEncryptionKey = exports.GetEmailClientConfigs = exports.sendMailWithUserAccount = exports.UserLicenseConsumeCalculate = exports.SignoutMultipleUsersFromAllDevices = exports.SignoutUsersWithPromise = exports.SignoutUserFromAllDevices = exports.SyncUserDetailsWithMasterDB = exports.GenerateId = exports.VerifyAWSEmailConfig = exports.GetMaxKeyValueListSchema = exports.ExtractChildUsersTree = exports.GetMyTeamUsers = exports.VerifyEmailPassword = exports.CheckFilterFieldsProjection = exports.AddLog = exports.GirdHeaderFilters = exports.FilterConditions = exports.BuildLookupFieldProjection = exports.BuildFieldProjection = exports.BuildGridFieldProjection = exports.CheckDataBeforeUpdate = exports.CheckDataBeforeAdd = exports.BuildLookupDataField = exports.SyncUserInOtherCollection = exports.SyncFieldInOtherCollection = exports.SyncFieldInSameCollectionByObjectIDWithPromise = exports.SyncFieldInSameCollectionByObjectID = exports.SyncFieldInSameCollection = exports.DeleteFieldInOtherCollection = exports.SyncParentObjectData = exports.SyncChildObjectData = exports.UpdateRecentViewObject = exports.GetFieldDetail = exports.GetPageObjectSchema = exports.GetPageFieldData = exports.CheckUserProfileField = exports.IsEqualValue = exports.IsEqualArrays = exports.GetObjectByKeyValueFromList = exports.ConvertFileByteSize = exports.ReturnJsonResponse = exports.CheckForWhiteListedDomain = void 0;
84
84
  var moment_1 = __importDefault(require("moment"));
85
85
  var nodemailer_1 = __importDefault(require("nodemailer"));
86
86
  var mongodb_1 = require("mongodb");
@@ -88,14 +88,15 @@ var bson_1 = require("bson");
88
88
  var Excel = __importStar(require("exceljs"));
89
89
  var path_1 = __importDefault(require("path"));
90
90
  var fs_1 = __importDefault(require("fs"));
91
- var axios_1 = __importDefault(require("axios"));
91
+ var geoip = __importStar(require("geoip-lite"));
92
92
  var crypto_1 = __importDefault(require("crypto"));
93
93
  var constants_1 = __importDefault(require("../constants"));
94
94
  var mail_1 = require("../utility/mail");
95
95
  var errorHandlerForServices_1 = __importDefault(require("../utility/errorHandlerForServices"));
96
96
  var cryptoService = __importStar(require("../utility/crypto"));
97
- var https_1 = __importDefault(require("https"));
97
+ var countrycode_1 = require("./countrycode");
98
98
  require("moment-timezone");
99
+ var sanitize = require('mongo-sanitize');
99
100
  function GetObjectByKeyValueFromList(list, key, val) {
100
101
  if (list && list.length > 0) {
101
102
  for (var i = 0; i < list.length; i++) {
@@ -2972,40 +2973,39 @@ function ConvertFileByteSize(bytes) {
2972
2973
  exports.ConvertFileByteSize = ConvertFileByteSize;
2973
2974
  function GetIPDetailsFromReq(req) {
2974
2975
  return __awaiter(this, void 0, void 0, function () {
2975
- var ip, domainName, ipDetails;
2976
+ var ip, ipDetails;
2976
2977
  return __generator(this, function (_a) {
2977
- switch (_a.label) {
2978
- case 0:
2979
- if (req.headers['x-original-forwarded-for']) {
2980
- console.log("In req.headers['x-original-forwarded-for']"); /* Temp for brijesh */
2981
- ip = req.headers['x-original-forwarded-for'];
2982
- }
2983
- else if (req.headers['x-forwarded-for']) {
2984
- console.log("In req.headers['x-forwarded-for']"); /* Temp for brijesh */
2985
- ip = req.headers['x-forwarded-for'].split(",")[0];
2986
- }
2987
- else if (req.connection && req.connection.remoteAddress) {
2988
- ip = req.connection.remoteAddress;
2989
- }
2990
- else {
2991
- ip = req.ip;
2992
- }
2993
- domainName = req.headers.host ? req.headers.host : req.headers.origin;
2994
- return [4 /*yield*/, axios_1.default.post("https://" + domainName + "/user/noauth/getlocationfromip", { ip: ip }, {
2995
- httpsAgent: new https_1.default.Agent({
2996
- rejectUnauthorized: false
2997
- })
2998
- })];
2999
- case 1:
3000
- ipDetails = (_a.sent()).data;
3001
- ipDetails = ipDetails.data;
3002
- /* if (ipDetails) {
3003
- ipDetails.countryName = countryCode(ipDetails.country)
3004
- ipDetails.ip = ip
3005
- } */
3006
- console.log('>>IP DE ', ipDetails);
3007
- return [2 /*return*/, ipDetails];
2978
+ if (req.headers['x-original-forwarded-for']) {
2979
+ //console.log("In req.headers['x-original-forwarded-for']");
2980
+ ip = req.headers['x-original-forwarded-for'];
2981
+ }
2982
+ else if (req.headers['x-forwarded-for']) {
2983
+ //console.log("In req.headers['x-forwarded-for']");
2984
+ ip = req.headers['x-forwarded-for'].split(",")[0];
2985
+ }
2986
+ else if (req.connection && req.connection.remoteAddress) {
2987
+ ip = req.connection.remoteAddress;
2988
+ }
2989
+ else {
2990
+ ip = req.ip;
2991
+ }
2992
+ ipDetails = geoip.lookup(ip);
2993
+ if (ipDetails) {
2994
+ ipDetails.countryName = countrycode_1.getCountryFromCode(ipDetails.country);
2995
+ ipDetails.ip = ip;
2996
+ // }
2997
+ //return connection.ReturnJsonResponse(req, res, { Status: 200, Message: 'success', Data: ipDetails, Type: 'POST', LogData: false });
3008
2998
  }
2999
+ else {
3000
+ ipDetails = '';
3001
+ }
3002
+ //ipDetails = ipDetails.data;
3003
+ /* if (ipDetails) {
3004
+ ipDetails.countryName = countryCode(ipDetails.country)
3005
+ ipDetails.ip = ip
3006
+ } */
3007
+ console.log('>>IP DE ', ipDetails);
3008
+ return [2 /*return*/, ipDetails];
3009
3009
  });
3010
3010
  });
3011
3011
  }
@@ -3806,6 +3806,14 @@ function ErrorHandlerForServices(Error, ServiceOrigin, EmailConfig, Module, db)
3806
3806
  });
3807
3807
  }
3808
3808
  exports.ErrorHandlerForServices = ErrorHandlerForServices;
3809
+ /*
3810
+ * Created by: Brijesh and edited by Shazaib as on 15-11-21
3811
+ * Desc: This function is used for verifying captcha
3812
+ * @param1: token (from user form)
3813
+ * @param2: captcha code (from user form)
3814
+ * @param3: redisClient , object of the redis client.
3815
+ * return value: message string
3816
+ */
3809
3817
  function CheckCaptcha(token, captcha, redisClient) {
3810
3818
  return new Promise(function (resolve, reject) {
3811
3819
  redisClient.hgetall(token, function (err, data) {
@@ -3829,3 +3837,94 @@ function CheckCaptcha(token, captcha, redisClient) {
3829
3837
  });
3830
3838
  }
3831
3839
  exports.CheckCaptcha = CheckCaptcha;
3840
+ /*
3841
+ * this function isused tp capitalized first latter of a string.
3842
+ * @param1: string ex: 'lazy boy'
3843
+ * return value: Lazy boy else false if value is not a string
3844
+ */
3845
+ function CapitalizeFirstLetter(str) {
3846
+ if (typeof str !== 'string' || !str) {
3847
+ return false;
3848
+ }
3849
+ return str.charAt(0).toUpperCase() + str.slice(1);
3850
+ }
3851
+ function EmailValidation(elmValue) {
3852
+ var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
3853
+ if (filter.test(elmValue)) {
3854
+ return true;
3855
+ }
3856
+ return false;
3857
+ }
3858
+ /*
3859
+ * Created by: Mohan as on 09-11-21
3860
+ * This is a common function and used to validate and sanitise user input.
3861
+ * @param1: inputFields (from user form)
3862
+ * {
3863
+ OwnerID: { '$oid': '6123438f6693ea0012919e9a' },
3864
+ Salutation: '1',
3865
+ FirstName: 'Santa',
3866
+ LastName: 'Singh',
3867
+ VIPStatus: null,
3868
+ OperaProfileId: null
3869
+ }
3870
+
3871
+ * @param2: pageData objectdata from ObjectSchema collection
3872
+ * Desc: This fuinction maps all fields from user form with objectdata from ObjectSchema collection.
3873
+ * return value: array.
3874
+ * example: [{"msg":'Invalid email'}, {all validated and sanitized fields with key:value}]
3875
+ */
3876
+ function ValidateSanitizeUserInput(inputFields, pageData) {
3877
+ return __awaiter(this, void 0, void 0, function () {
3878
+ var objElement, inputItem, key, val, sanitizeInput, msg, _i, _a, item, elm, elmValue;
3879
+ return __generator(this, function (_b) {
3880
+ try {
3881
+ objElement = {};
3882
+ inputItem = {};
3883
+ for (key in inputFields) {
3884
+ if (inputFields.hasOwnProperty(key)) {
3885
+ val = inputFields[key];
3886
+ //if (val !== null && (typeof val === 'object' || mongodb.ObjectID.isValid(val))) {
3887
+ if (val !== null && (typeof val === 'object' || mongodb_1.ObjectID.isValid(val))) {
3888
+ inputItem[key] = val;
3889
+ }
3890
+ else {
3891
+ inputItem[key] = (typeof val === 'string') ? sanitize(val.toString().trim()) : sanitize(val); // sanitize input values
3892
+ }
3893
+ objElement[key] = inputItem[key];
3894
+ }
3895
+ }
3896
+ sanitizeInput = [];
3897
+ msg = '';
3898
+ for (_i = 0, _a = pageData.Fields; _i < _a.length; _i++) {
3899
+ item = _a[_i];
3900
+ elm = item.Name.toString();
3901
+ elmValue = inputItem[elm];
3902
+ if (item.IsRequired == true && item.IsRequired !== undefined) {
3903
+ // check for required input fileds
3904
+ if (elmValue && item.UIDataType == 'email' && elmValue != '' && elmValue != null && elmValue !== undefined) {
3905
+ if (!EmailValidation(elmValue.toString())) {
3906
+ msg = 'Invalid email format!';
3907
+ }
3908
+ }
3909
+ else {
3910
+ // other required field
3911
+ if (elmValue == '' || elmValue == 'null' || elmValue === null) {
3912
+ msg = CapitalizeFirstLetter(item.DisplayName) + ' is required!';
3913
+ }
3914
+ }
3915
+ }
3916
+ // }
3917
+ }
3918
+ sanitizeInput.push({ "msg": msg });
3919
+ sanitizeInput.push(objElement);
3920
+ //console.log("=============>",sanitizeInput);
3921
+ return [2 /*return*/, sanitizeInput];
3922
+ }
3923
+ catch (err) {
3924
+ console.log("Error in validateSanitizeUserInput() in utility.js: ", err);
3925
+ }
3926
+ return [2 /*return*/];
3927
+ });
3928
+ });
3929
+ }
3930
+ exports.ValidateSanitizeUserInput = ValidateSanitizeUserInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.226",
3
+ "version": "1.0.230",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -30,6 +30,7 @@
30
30
  "libphonenumber-js": "^1.9.23",
31
31
  "moment": "^2.25.3",
32
32
  "moment-timezone": "^0.5.27",
33
+ "mongo-sanitize": "^1.1.0",
33
34
  "mongodb": "^3.6.2",
34
35
  "nodemailer": "^6.4.11",
35
36
  "promise.allsettled": "^1.0.2",