@optimiser/common 1.0.383 → 1.0.385

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.
@@ -1860,7 +1860,7 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1860
1860
  switch (_c.label) {
1861
1861
  case 0:
1862
1862
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1863
- if (!fieldSchema) return [3 /*break*/, 7];
1863
+ if (!fieldSchema) return [3 /*break*/, 9];
1864
1864
  cityfield = void 0;
1865
1865
  if (fieldSchema.LookupObject == "City") {
1866
1866
  cityfield = updateObj[fldName];
@@ -1901,7 +1901,14 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1901
1901
  if (fieldSchema.UIDataType == 'formula')
1902
1902
  delete updateObj[fldName];
1903
1903
  _c.label = 7;
1904
- case 7: return [2 /*return*/];
1904
+ case 7:
1905
+ // QPC-9020 for State and Country Field Server Side Validation
1906
+ return [4 /*yield*/, ValidateStateCountryField({ fieldSchema: fieldSchema, updateObj: updateObj, objectSchema: objectSchema, db: db, cityfield: cityfield })];
1907
+ case 8:
1908
+ // QPC-9020 for State and Country Field Server Side Validation
1909
+ _c.sent();
1910
+ _c.label = 9;
1911
+ case 9: return [2 /*return*/];
1905
1912
  }
1906
1913
  });
1907
1914
  };
@@ -1937,10 +1944,10 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1937
1944
  case 0:
1938
1945
  if (!(fldName == '_id')) return [3 /*break*/, 1];
1939
1946
  delete updateObj[fldName];
1940
- return [3 /*break*/, 5];
1947
+ return [3 /*break*/, 7];
1941
1948
  case 1:
1942
1949
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1943
- if (!fieldSchema) return [3 /*break*/, 5];
1950
+ if (!fieldSchema) return [3 /*break*/, 7];
1944
1951
  cityfield = void 0;
1945
1952
  if (fieldSchema.LookupObject == "City") {
1946
1953
  cityfield = updateObj[fldName];
@@ -1968,7 +1975,14 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1968
1975
  case 4:
1969
1976
  _c.sent();
1970
1977
  _c.label = 5;
1971
- case 5: return [2 /*return*/];
1978
+ case 5:
1979
+ // QPC-9020 for State and Country Field Server Side Validation
1980
+ return [4 /*yield*/, ValidateStateCountryField({ fieldSchema: fieldSchema, updateObj: updateObj, objectSchema: objectSchema, db: db, cityfield: cityfield })];
1981
+ case 6:
1982
+ // QPC-9020 for State and Country Field Server Side Validation
1983
+ _c.sent();
1984
+ _c.label = 7;
1985
+ case 7: return [2 /*return*/];
1972
1986
  }
1973
1987
  });
1974
1988
  };
@@ -4721,6 +4735,19 @@ function IsAnotherObjectField(pageData, fieldName) {
4721
4735
  }
4722
4736
  return false;
4723
4737
  }
4738
+ var CustomSanitizeHtml = function (dirtyHtml) {
4739
+ return (0, sanitize_html_1.default)(dirtyHtml, {
4740
+ allowedTags: sanitize_html_1.default.defaults.allowedTags.concat(['body']), // Preserve <body> tag
4741
+ allowedAttributes: {
4742
+ '*': ['href', 'align', 'alt', 'center', 'bgcolor', 'src', 'title', 'width'],
4743
+ },
4744
+ allowedSchemes: ['http', 'https', 'mailto'], // Allow URLs with these schemes
4745
+ textFilter: function (text) { return text; }, // Keep special characters like & intact
4746
+ parser: {
4747
+ decodeEntities: false, // Prevent converting & to &
4748
+ },
4749
+ });
4750
+ };
4724
4751
  /*
4725
4752
  * Created by: Nirbhay as on 01-09-22
4726
4753
  * This is a common function and used to validate user input format.
@@ -4791,7 +4818,7 @@ function ValidateUserInput(options) {
4791
4818
  if (!field) return [3 /*break*/, 58];
4792
4819
  //sanitizing Html and added IgnoreSanitizeHtml condition so that it can be ignored for certain fields
4793
4820
  if (!field.IgnoreSanitizeHtml && IsStringValue(fieldData)) {
4794
- inputFields[fieldName] = (0, sanitize_html_1.default)(fieldData);
4821
+ inputFields[fieldName] = CustomSanitizeHtml(fieldData);
4795
4822
  fieldData = inputFields[fieldName];
4796
4823
  }
4797
4824
  if (field.DisableValidateUserInput) {
@@ -5669,17 +5696,27 @@ function SyncTotalSlotRemaining(registrationID, db) {
5669
5696
  });
5670
5697
  }
5671
5698
  exports.SyncTotalSlotRemaining = SyncTotalSlotRemaining;
5672
- function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield) {
5699
+ /**
5700
+ *
5701
+ * @param param.fieldSchema fieldSchema contain field related schema information
5702
+ * @param param.updateObj updateObj contains the Updated Object data
5703
+ * @param param.objectSchema objectSchema contains the ObjectSchema of the Object
5704
+ * @param param.db database connection || Db
5705
+ * @param param.cityfield cityfield contain the City Id
5706
+ * @return return the updated State and Country field value based upon the City
5707
+ */
5708
+ function ValidateStateCountryField(_a) {
5709
+ var fieldSchema = _a.fieldSchema, updateObj = _a.updateObj, objectSchema = _a.objectSchema, db = _a.db, cityfield = _a.cityfield;
5673
5710
  return __awaiter(this, void 0, void 0, function () {
5674
5711
  var cityDocument, stateFieldSchema, countryFieldSchema, stateFieldSchema, countryFieldSchema;
5675
- return __generator(this, function (_a) {
5676
- switch (_a.label) {
5712
+ return __generator(this, function (_b) {
5713
+ switch (_b.label) {
5677
5714
  case 0:
5678
5715
  if (!((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.LookupObject) === 'City')) return [3 /*break*/, 3];
5679
5716
  if (!cityfield) return [3 /*break*/, 2];
5680
5717
  return [4 /*yield*/, db.collection('City').findOne({ _id: cityfield })];
5681
5718
  case 1:
5682
- cityDocument = _a.sent();
5719
+ cityDocument = _b.sent();
5683
5720
  if (cityDocument) {
5684
5721
  stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5685
5722
  if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
@@ -5700,7 +5737,7 @@ function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema
5700
5737
  if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5701
5738
  updateObj[fieldSchema.CountryField] = null;
5702
5739
  }
5703
- _a.label = 3;
5740
+ _b.label = 3;
5704
5741
  case 3: return [2 /*return*/];
5705
5742
  }
5706
5743
  });
@@ -1,4 +1,4 @@
1
- import { ObjectId } from "mongodb";
1
+ import { ObjectId, Db } from "mongodb";
2
2
  interface AnyObjectInterface {
3
3
  [key: string]: any;
4
4
  }
@@ -14,4 +14,11 @@ interface GetEncryptedURLOptions {
14
14
  fieldName: string;
15
15
  filterKey: string;
16
16
  }
17
- export { AnyObjectInterface, callBackInterface, GetEncryptedURLOptions };
17
+ interface ValidateStateCountryOptions {
18
+ fieldSchema: AnyObjectInterface;
19
+ updateObj: AnyObjectInterface;
20
+ objectSchema: AnyObjectInterface;
21
+ db: Db;
22
+ cityfield: AnyObjectInterface;
23
+ }
24
+ export { AnyObjectInterface, callBackInterface, GetEncryptedURLOptions, ValidateStateCountryOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.383",
3
+ "version": "1.0.385",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {