@optimiser/common 1.0.304 → 1.0.306

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 (2) hide show
  1. package/dist/lib/utility.js +107 -100
  2. package/package.json +1 -1
@@ -4570,7 +4570,10 @@ function ValidateUserInput(options) {
4570
4570
  delete inputFields[pageField.Name];
4571
4571
  }
4572
4572
  field = schemaFields.find(function (x) { return x.Name == fieldName; });
4573
- if (!field) return [3 /*break*/, 52];
4573
+ if (!field) return [3 /*break*/, 54];
4574
+ if (field.DisableValidateUserInput) {
4575
+ return [2 /*return*/, "continue"];
4576
+ }
4574
4577
  if ((field.UIDataType == 'date' || field.UIDataType == 'datetime') && IsStringValue(fieldData) && fieldData.trim() == '') {
4575
4578
  inputFields[fieldName] = null;
4576
4579
  }
@@ -4602,8 +4605,8 @@ function ValidateUserInput(options) {
4602
4605
  }
4603
4606
  _d.label = 2;
4604
4607
  case 2:
4605
- if (!inputField.includes(fieldName)) return [3 /*break*/, 51];
4606
- if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 51];
4608
+ if (!inputField.includes(fieldName)) return [3 /*break*/, 53];
4609
+ if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 53];
4607
4610
  _a = field.UIDataType;
4608
4611
  switch (_a) {
4609
4612
  case 'int': return [3 /*break*/, 3];
@@ -4614,19 +4617,19 @@ function ValidateUserInput(options) {
4614
4617
  case 'email': return [3 /*break*/, 6];
4615
4618
  case 'checkbox': return [3 /*break*/, 7];
4616
4619
  case 'lookup': return [3 /*break*/, 8];
4617
- case 'multilookup': return [3 /*break*/, 10];
4618
- case 'dropdown': return [3 /*break*/, 18];
4619
- case 'multiselect': return [3 /*break*/, 24];
4620
- case 'url': return [3 /*break*/, 34];
4621
- case 'phone': return [3 /*break*/, 35];
4622
- case "image": return [3 /*break*/, 36];
4623
- case 'file': return [3 /*break*/, 36];
4624
- case 'textarea': return [3 /*break*/, 45];
4625
- case 'text': return [3 /*break*/, 45];
4626
- case 'texteditor': return [3 /*break*/, 45];
4627
- case 'collection': return [3 /*break*/, 46];
4620
+ case 'multilookup': return [3 /*break*/, 11];
4621
+ case 'dropdown': return [3 /*break*/, 20];
4622
+ case 'multiselect': return [3 /*break*/, 26];
4623
+ case 'url': return [3 /*break*/, 36];
4624
+ case 'phone': return [3 /*break*/, 37];
4625
+ case "image": return [3 /*break*/, 38];
4626
+ case 'file': return [3 /*break*/, 38];
4627
+ case 'textarea': return [3 /*break*/, 47];
4628
+ case 'text': return [3 /*break*/, 47];
4629
+ case 'texteditor': return [3 /*break*/, 47];
4630
+ case 'collection': return [3 /*break*/, 48];
4628
4631
  }
4629
- return [3 /*break*/, 51];
4632
+ return [3 /*break*/, 53];
4630
4633
  case 3:
4631
4634
  {
4632
4635
  if (IsStringValue(fieldData)) {
@@ -4645,14 +4648,14 @@ function ValidateUserInput(options) {
4645
4648
  msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
4646
4649
  }
4647
4650
  }
4648
- return [3 /*break*/, 51];
4651
+ return [3 /*break*/, 53];
4649
4652
  case 4:
4650
4653
  {
4651
4654
  if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
4652
4655
  msg = 'Invalid date for ' + field.DisplayName + '!';
4653
4656
  }
4654
4657
  }
4655
- return [3 /*break*/, 51];
4658
+ return [3 /*break*/, 53];
4656
4659
  case 5:
4657
4660
  {
4658
4661
  isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(fieldData);
@@ -4660,7 +4663,7 @@ function ValidateUserInput(options) {
4660
4663
  msg = 'Invalid time for ' + field.DisplayName + '!';
4661
4664
  }
4662
4665
  }
4663
- return [3 /*break*/, 51];
4666
+ return [3 /*break*/, 53];
4664
4667
  case 6:
4665
4668
  {
4666
4669
  filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
@@ -4668,15 +4671,16 @@ function ValidateUserInput(options) {
4668
4671
  msg = fieldData + ' is invalid email for ' + field.DisplayName + '!';
4669
4672
  }
4670
4673
  }
4671
- return [3 /*break*/, 51];
4674
+ return [3 /*break*/, 53];
4672
4675
  case 7:
4673
4676
  {
4674
4677
  if (fieldData !== true && fieldData !== false) {
4675
4678
  msg = 'Invalid user input for ' + field.DisplayName + '!';
4676
4679
  }
4677
4680
  }
4678
- return [3 /*break*/, 51];
4681
+ return [3 /*break*/, 53];
4679
4682
  case 8:
4683
+ if (!!field.IsMultipleLookupObject) return [3 /*break*/, 10];
4680
4684
  searchObj = { _id: fieldData };
4681
4685
  if (field.LookupKey) {
4682
4686
  searchObj = {};
@@ -4692,10 +4696,12 @@ function ValidateUserInput(options) {
4692
4696
  if (result == null) {
4693
4697
  msg = field.DisplayName + ' does not exist!';
4694
4698
  }
4695
- return [3 /*break*/, 51];
4696
- case 10:
4697
- if (!Array.isArray(fieldData)) return [3 /*break*/, 16];
4698
- if (!fieldData.length) return [3 /*break*/, 14];
4699
+ _d.label = 10;
4700
+ case 10: return [3 /*break*/, 53];
4701
+ case 11:
4702
+ if (!Array.isArray(fieldData)) return [3 /*break*/, 18];
4703
+ if (!fieldData.length) return [3 /*break*/, 16];
4704
+ if (!!field.IsMultipleLookupObject) return [3 /*break*/, 15];
4699
4705
  searchObj = { _id: { $in: fieldData } };
4700
4706
  if (field.LookupKey) {
4701
4707
  searchObj = {};
@@ -4706,45 +4712,46 @@ function ValidateUserInput(options) {
4706
4712
  }
4707
4713
  ;
4708
4714
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
4709
- case 11:
4715
+ case 12:
4710
4716
  totalRecord = _d.sent();
4711
- if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 13];
4717
+ if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 14];
4712
4718
  _b = totalRecord;
4713
4719
  return [4 /*yield*/, db.collection('Contact').find(searchObj).count()];
4714
- case 12:
4715
- totalRecord = _b + _d.sent();
4716
- _d.label = 13;
4717
4720
  case 13:
4721
+ totalRecord = _b + _d.sent();
4722
+ _d.label = 14;
4723
+ case 14:
4718
4724
  if (totalRecord !== fieldData.length) {
4719
4725
  msg = field.DisplayName + ' does not exist!';
4720
4726
  }
4721
- return [3 /*break*/, 15];
4722
- case 14:
4723
- if (field.IsRequired) {
4724
- msg = field.DisplayName + ' is required!';
4725
- }
4726
4727
  _d.label = 15;
4727
4728
  case 15: return [3 /*break*/, 17];
4728
4729
  case 16:
4729
- msg = 'Invalid value for ' + field.DisplayName;
4730
+ if (field.IsRequired) {
4731
+ msg = field.DisplayName + ' is required!';
4732
+ }
4730
4733
  _d.label = 17;
4731
- case 17: return [3 /*break*/, 51];
4734
+ case 17: return [3 /*break*/, 19];
4732
4735
  case 18:
4733
- if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 21];
4734
- if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 20];
4736
+ msg = 'Invalid value for ' + field.DisplayName;
4737
+ _d.label = 19;
4738
+ case 19: return [3 /*break*/, 53];
4739
+ case 20:
4740
+ if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 23];
4741
+ if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 22];
4735
4742
  schemaData = null;
4736
4743
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
4737
- case 19:
4744
+ case 21:
4738
4745
  result = _d.sent();
4739
4746
  if (result && result.Data)
4740
4747
  schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
4741
4748
  if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
4742
4749
  msg = field.DisplayName + ' does not exist!';
4743
4750
  }
4744
- _d.label = 20;
4745
- case 20: return [3 /*break*/, 23];
4746
- case 21:
4747
- if (!(field.LookupObject !== undefined)) return [3 /*break*/, 23];
4751
+ _d.label = 22;
4752
+ case 22: return [3 /*break*/, 25];
4753
+ case 23:
4754
+ if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 25];
4748
4755
  searchObj = { _id: fieldData };
4749
4756
  if (field.LookupKey) {
4750
4757
  searchObj = {};
@@ -4755,21 +4762,21 @@ function ValidateUserInput(options) {
4755
4762
  }
4756
4763
  ;
4757
4764
  return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
4758
- case 22:
4765
+ case 24:
4759
4766
  result = _d.sent();
4760
4767
  if (result == null) {
4761
4768
  msg = field.DisplayName + ' does not exist!';
4762
4769
  }
4763
- _d.label = 23;
4764
- case 23: return [3 /*break*/, 51];
4765
- case 24:
4766
- if (!Array.isArray(fieldData)) return [3 /*break*/, 32];
4767
- if (!fieldData.length) return [3 /*break*/, 30];
4768
- if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 27];
4769
- if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 26];
4770
+ _d.label = 25;
4771
+ case 25: return [3 /*break*/, 53];
4772
+ case 26:
4773
+ if (!Array.isArray(fieldData)) return [3 /*break*/, 34];
4774
+ if (!fieldData.length) return [3 /*break*/, 32];
4775
+ if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 29];
4776
+ if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 28];
4770
4777
  schemaData = [];
4771
4778
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
4772
- case 25:
4779
+ case 27:
4773
4780
  result = _d.sent();
4774
4781
  if (result && result.Data) {
4775
4782
  if (action == 'add')
@@ -4780,10 +4787,10 @@ function ValidateUserInput(options) {
4780
4787
  if (schemaData.length != fieldData.length) {
4781
4788
  msg = field.DisplayName + ' does not exist!';
4782
4789
  }
4783
- _d.label = 26;
4784
- case 26: return [3 /*break*/, 29];
4785
- case 27:
4786
- if (!(field.LookupObject !== undefined)) return [3 /*break*/, 29];
4790
+ _d.label = 28;
4791
+ case 28: return [3 /*break*/, 31];
4792
+ case 29:
4793
+ if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 31];
4787
4794
  searchObj = { _id: { $in: fieldData } };
4788
4795
  if (field.LookupKey) {
4789
4796
  searchObj = {};
@@ -4794,32 +4801,32 @@ function ValidateUserInput(options) {
4794
4801
  }
4795
4802
  ;
4796
4803
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
4797
- case 28:
4804
+ case 30:
4798
4805
  totalRecord = _d.sent();
4799
4806
  if (totalRecord !== fieldData.length) {
4800
4807
  msg = field.DisplayName + ' does not exist!';
4801
4808
  }
4802
- _d.label = 29;
4803
- case 29: return [3 /*break*/, 31];
4804
- case 30:
4805
- if (field.IsRequired) {
4806
- msg = field.DisplayName + ' is required!';
4807
- }
4808
4809
  _d.label = 31;
4809
4810
  case 31: return [3 /*break*/, 33];
4810
4811
  case 32:
4811
- msg = 'Invalid value for ' + field.DisplayName;
4812
+ if (field.IsRequired) {
4813
+ msg = field.DisplayName + ' is required!';
4814
+ }
4812
4815
  _d.label = 33;
4813
- case 33: return [3 /*break*/, 51];
4816
+ case 33: return [3 /*break*/, 35];
4814
4817
  case 34:
4818
+ msg = 'Invalid value for ' + field.DisplayName;
4819
+ _d.label = 35;
4820
+ case 35: return [3 /*break*/, 53];
4821
+ case 36:
4815
4822
  {
4816
4823
  regexpression = new RegExp('^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+@,:=#()]*)*(\\?[;&a-z\\d%_@,.:()~+=-]*)?(\\#[-a-z\\d_]*)?$', 'i');
4817
4824
  if (!regexpression.test(fieldData)) {
4818
4825
  msg = 'Invalid URL for ' + field.DisplayName + '!';
4819
4826
  }
4820
4827
  }
4821
- return [3 /*break*/, 51];
4822
- case 35:
4828
+ return [3 /*break*/, 53];
4829
+ case 37:
4823
4830
  {
4824
4831
  if (field.IncludeCountryCode) {
4825
4832
  if (!fieldData.indexOf("+")) {
@@ -4833,11 +4840,11 @@ function ValidateUserInput(options) {
4833
4840
  }
4834
4841
  }
4835
4842
  }
4836
- return [3 /*break*/, 51];
4837
- case 36:
4838
- if (!field.IsMultiple) return [3 /*break*/, 42];
4839
- if (!Array.isArray(fieldData)) return [3 /*break*/, 40];
4840
- if (!fieldData.length) return [3 /*break*/, 38];
4843
+ return [3 /*break*/, 53];
4844
+ case 38:
4845
+ if (!field.IsMultiple) return [3 /*break*/, 44];
4846
+ if (!Array.isArray(fieldData)) return [3 /*break*/, 42];
4847
+ if (!fieldData.length) return [3 /*break*/, 40];
4841
4848
  files = [];
4842
4849
  for (_i = 0, fieldData_1 = fieldData; _i < fieldData_1.length; _i++) {
4843
4850
  obj = fieldData_1[_i];
@@ -4849,37 +4856,37 @@ function ValidateUserInput(options) {
4849
4856
  }
4850
4857
  ;
4851
4858
  return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
4852
- case 37:
4859
+ case 39:
4853
4860
  totalRecord = _d.sent();
4854
4861
  if (totalRecord !== fieldData.length) {
4855
4862
  msg = field.DisplayName + ' does not exist!';
4856
4863
  }
4857
- return [3 /*break*/, 39];
4858
- case 38:
4864
+ return [3 /*break*/, 41];
4865
+ case 40:
4859
4866
  if (field.IsRequired) {
4860
4867
  msg = field.DisplayName + ' is required!';
4861
4868
  }
4862
- _d.label = 39;
4863
- case 39: return [3 /*break*/, 41];
4864
- case 40:
4865
- msg = 'Invalid value for ' + field.DisplayName;
4866
4869
  _d.label = 41;
4867
- case 41: return [3 /*break*/, 44];
4870
+ case 41: return [3 /*break*/, 43];
4868
4871
  case 42:
4872
+ msg = 'Invalid value for ' + field.DisplayName;
4873
+ _d.label = 43;
4874
+ case 43: return [3 /*break*/, 46];
4875
+ case 44:
4869
4876
  searchObj = { _id: fieldData };
4870
4877
  if (action == 'add') {
4871
4878
  searchObj.IsActive = true;
4872
4879
  }
4873
4880
  ;
4874
4881
  return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
4875
- case 43:
4882
+ case 45:
4876
4883
  result = _d.sent();
4877
4884
  if (result == null) {
4878
4885
  msg = field.DisplayName + ' does not exist!';
4879
4886
  }
4880
- _d.label = 44;
4881
- case 44: return [3 /*break*/, 51];
4882
- case 45:
4887
+ _d.label = 46;
4888
+ case 46: return [3 /*break*/, 53];
4889
+ case 47:
4883
4890
  {
4884
4891
  // Maxlength check;
4885
4892
  if (field.MaxLength !== undefined && field.MaxLength !== null && fieldData.length > field.MaxLength) {
@@ -4889,34 +4896,34 @@ function ValidateUserInput(options) {
4889
4896
  msg = 'Invalid value for ' + field.DisplayName;
4890
4897
  }
4891
4898
  }
4892
- return [3 /*break*/, 51];
4893
- case 46:
4894
- if (!fieldData.length) return [3 /*break*/, 50];
4899
+ return [3 /*break*/, 53];
4900
+ case 48:
4901
+ if (!fieldData.length) return [3 /*break*/, 52];
4895
4902
  _c = 0, fieldData_2 = fieldData;
4896
- _d.label = 47;
4897
- case 47:
4898
- if (!(_c < fieldData_2.length)) return [3 /*break*/, 50];
4903
+ _d.label = 49;
4904
+ case 49:
4905
+ if (!(_c < fieldData_2.length)) return [3 /*break*/, 52];
4899
4906
  obj = fieldData_2[_c];
4900
4907
  return [4 /*yield*/, ValidateUserInput({ 'userInput': obj, 'pageData': pageData, 'objectID': documentID, 'db': db, 'collectionField': fieldName })];
4901
- case 48:
4908
+ case 50:
4902
4909
  validateResp = _d.sent();
4903
4910
  if (validateResp && validateResp != "") {
4904
4911
  msg = validateResp;
4905
- return [3 /*break*/, 50];
4912
+ return [3 /*break*/, 52];
4906
4913
  }
4907
- _d.label = 49;
4908
- case 49:
4914
+ _d.label = 51;
4915
+ case 51:
4909
4916
  _c++;
4910
- return [3 /*break*/, 47];
4911
- case 50: return [3 /*break*/, 51];
4912
- case 51: return [3 /*break*/, 53];
4913
- case 52:
4917
+ return [3 /*break*/, 49];
4918
+ case 52: return [3 /*break*/, 53];
4919
+ case 53: return [3 /*break*/, 55];
4920
+ case 54:
4914
4921
  if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
4915
4922
  msg = fieldName + " is not valid schema!";
4916
4923
  return [2 /*return*/, "break"];
4917
4924
  }
4918
- _d.label = 53;
4919
- case 53: return [2 /*return*/];
4925
+ _d.label = 55;
4926
+ case 55: return [2 /*return*/];
4920
4927
  }
4921
4928
  });
4922
4929
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.304",
3
+ "version": "1.0.306",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {