oro-sdk 3.12.0 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,53 @@ export declare function filterTriggeredAnsweredWithKind(workflowData: WorkflowDa
11
11
  */
12
12
  export declare function getWorkflowDataByCategory(workflowData: WorkflowData, category: MetadataCategory): Promise<PopulatedWorkflowData>;
13
13
  export declare function getImagesFromIndexDb(answer: SelectedAnswerData): Promise<WorkflowUploadedImage[]>;
14
- export declare function isTriggered(triggers: string[], answers: string[]): boolean;
14
+ /**
15
+ * Determine if a question is triggered by some answers
16
+ *
17
+ * We use the following logical combinations of rules:
18
+ *
19
+ * #### Single string
20
+ *
21
+ * ```
22
+ * // Required: rule1
23
+ * rules: rule1
24
+ * ```
25
+ *
26
+ * #### Array of strings (AND is applied between statements):
27
+ *
28
+ * ```
29
+ * // Required: rule1 AND rule2
30
+ * rules: [ rule1, rule2 ]
31
+ * ```
32
+ *
33
+ * #### Array of arrays of strings (OR is applied between inner arrays. AND is applied between inner arrays statements)
34
+ *
35
+ * ```
36
+ * // Required: rule1 OR rule2
37
+ * rules: [
38
+ * [ rule1 ],
39
+ * [ rule2 ]
40
+ * ]
41
+ *
42
+ * // Required: rule1 OR (rule2 AND rule3)
43
+ * rules: [
44
+ * [ rule1 ],
45
+ * [ rule2, rule3 ]
46
+ * ]
47
+ *
48
+ * // THIS IS FORBIDDEN
49
+ * rules: [
50
+ * rule1, // <-- THIS IS FORBIDDEN. Instead use [ rule1 ]
51
+ * [ rule2, rule3 ]
52
+ * ]
53
+ * ```
54
+ *
55
+ * @param triggers the triggering rules
56
+ * @param answers the answers to check againts triggering rules
57
+ * @returns `true` if triggers are verified against ansers. Otherwise, returns `false`.
58
+ * @throws an Error if triggers typing is wrong
59
+ */
60
+ export declare function isTriggered(triggers: string[][] | string[] | string, answers: string[]): boolean;
15
61
  export declare function flattenSelectedAnswers(answers: SelectedAnswersData): string[];
16
62
  /**
17
63
  * This function helps you to get a valid workflow selectedAnswers structure
@@ -982,6 +982,53 @@ function _getImagesFromIndexDb() {
982
982
  function populateWorkflowField(_x6, _x7) {
983
983
  return _populateWorkflowField.apply(this, arguments);
984
984
  }
985
+ /**
986
+ * Determine if a question is triggered by some answers
987
+ *
988
+ * We use the following logical combinations of rules:
989
+ *
990
+ * #### Single string
991
+ *
992
+ * ```
993
+ * // Required: rule1
994
+ * rules: rule1
995
+ * ```
996
+ *
997
+ * #### Array of strings (AND is applied between statements):
998
+ *
999
+ * ```
1000
+ * // Required: rule1 AND rule2
1001
+ * rules: [ rule1, rule2 ]
1002
+ * ```
1003
+ *
1004
+ * #### Array of arrays of strings (OR is applied between inner arrays. AND is applied between inner arrays statements)
1005
+ *
1006
+ * ```
1007
+ * // Required: rule1 OR rule2
1008
+ * rules: [
1009
+ * [ rule1 ],
1010
+ * [ rule2 ]
1011
+ * ]
1012
+ *
1013
+ * // Required: rule1 OR (rule2 AND rule3)
1014
+ * rules: [
1015
+ * [ rule1 ],
1016
+ * [ rule2, rule3 ]
1017
+ * ]
1018
+ *
1019
+ * // THIS IS FORBIDDEN
1020
+ * rules: [
1021
+ * rule1, // <-- THIS IS FORBIDDEN. Instead use [ rule1 ]
1022
+ * [ rule2, rule3 ]
1023
+ * ]
1024
+ * ```
1025
+ *
1026
+ * @param triggers the triggering rules
1027
+ * @param answers the answers to check againts triggering rules
1028
+ * @returns `true` if triggers are verified against ansers. Otherwise, returns `false`.
1029
+ * @throws an Error if triggers typing is wrong
1030
+ */
1031
+
985
1032
 
986
1033
  function _populateWorkflowField() {
987
1034
  _populateWorkflowField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(question, answerValue) {
@@ -1060,21 +1107,34 @@ function _populateWorkflowField() {
1060
1107
  }
1061
1108
 
1062
1109
  function isTriggered(triggers, answers) {
1063
- for (var _iterator = _createForOfIteratorHelperLoose(triggers), _step; !(_step = _iterator()).done;) {
1064
- var trigger = _step.value;
1110
+ // is triggers contained in answers
1111
+ if (typeof triggers === 'string') {
1112
+ return answers.includes(triggers);
1113
+ }
1065
1114
 
1066
- if (!answers.includes(trigger)) {
1067
- return false;
1115
+ if (Array.isArray(triggers)) {
1116
+ // rule combination kind: rule1 OR (rule2 AND rule3)
1117
+ if (Array.isArray(triggers[0])) {
1118
+ return triggers.some(function (subSetTriggers) {
1119
+ return subSetTriggers.every(function (trigger) {
1120
+ return answers.includes(trigger);
1121
+ });
1122
+ });
1123
+ } else {
1124
+ // rule combination kind: rule1 AND rule2
1125
+ return triggers.every(function (trigger) {
1126
+ return answers.includes(trigger);
1127
+ });
1068
1128
  }
1069
1129
  }
1070
1130
 
1071
- return true;
1131
+ throw Error('[isTriggered] triggers is not typed well');
1072
1132
  }
1073
1133
  function flattenSelectedAnswers(answers) {
1074
1134
  var linearAnswers = [];
1075
1135
 
1076
- for (var _iterator2 = _createForOfIteratorHelperLoose(answers), _step2; !(_step2 = _iterator2()).done;) {
1077
- var answer = _step2.value;
1136
+ for (var _iterator = _createForOfIteratorHelperLoose(answers), _step; !(_step = _iterator()).done;) {
1137
+ var answer = _step.value;
1078
1138
  linearAnswers.push.apply(linearAnswers, Object.values(answer));
1079
1139
  }
1080
1140