@qrvey/utils 1.15.0-1 → 1.15.0-10

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 (49) hide show
  1. package/dist/cjs/filters/adapters/index.d.ts +1 -0
  2. package/dist/cjs/filters/adapters/index.js +1 -0
  3. package/dist/cjs/filters/adapters/transformFilters.d.ts +61 -0
  4. package/dist/cjs/filters/adapters/transformFilters.js +432 -0
  5. package/dist/cjs/filters/helpers/common/getDateProperties.d.ts +6 -0
  6. package/dist/cjs/filters/helpers/common/getDateProperties.js +2 -1
  7. package/dist/cjs/filters/helpers/settings/getFilterSettings.js +1 -1
  8. package/dist/cjs/filters/interfaces/common/IFSScopeID.d.ts +4 -0
  9. package/dist/cjs/general/array/howManyByParam.d.ts +8 -0
  10. package/dist/cjs/general/array/howManyByParam.js +21 -0
  11. package/dist/cjs/general/array/index.d.ts +2 -0
  12. package/dist/cjs/general/array/index.js +2 -0
  13. package/dist/cjs/general/string/index.d.ts +2 -0
  14. package/dist/cjs/general/string/index.js +2 -0
  15. package/dist/cjs/general/string/secureHTML.d.ts +8 -0
  16. package/dist/cjs/general/string/secureHTML.js +13 -0
  17. package/dist/cjs/general/string/strategies/XSSSanitizer.d.ts +8 -0
  18. package/dist/cjs/general/string/strategies/XSSSanitizer.js +19 -0
  19. package/dist/cjs/globalization/interfaces/export/II18nExportingModal.d.ts +20 -0
  20. package/dist/cjs/globalization/interfaces/filters/II18nFilterDisplay.d.ts +1 -0
  21. package/dist/cjs/globalization/labels/export/I18N_EXPORT_MODAL.js +20 -0
  22. package/dist/cjs/globalization/labels/filters/I18N_FILTER_DISPLAY.js +1 -0
  23. package/dist/cjs/interfaces/SatinizerStrategy.d.ts +3 -0
  24. package/dist/cjs/interfaces/SatinizerStrategy.js +2 -0
  25. package/dist/filters/adapters/index.d.ts +1 -0
  26. package/dist/filters/adapters/index.js +1 -0
  27. package/dist/filters/adapters/transformFilters.d.ts +61 -0
  28. package/dist/filters/adapters/transformFilters.js +428 -0
  29. package/dist/filters/helpers/common/getDateProperties.d.ts +6 -0
  30. package/dist/filters/helpers/common/getDateProperties.js +1 -1
  31. package/dist/filters/helpers/settings/getFilterSettings.js +1 -1
  32. package/dist/filters/interfaces/common/IFSScopeID.d.ts +4 -0
  33. package/dist/general/array/howManyByParam.d.ts +8 -0
  34. package/dist/general/array/howManyByParam.js +17 -0
  35. package/dist/general/array/index.d.ts +2 -0
  36. package/dist/general/array/index.js +2 -0
  37. package/dist/general/string/index.d.ts +2 -0
  38. package/dist/general/string/index.js +2 -0
  39. package/dist/general/string/secureHTML.d.ts +8 -0
  40. package/dist/general/string/secureHTML.js +9 -0
  41. package/dist/general/string/strategies/XSSSanitizer.d.ts +8 -0
  42. package/dist/general/string/strategies/XSSSanitizer.js +15 -0
  43. package/dist/globalization/interfaces/export/II18nExportingModal.d.ts +20 -0
  44. package/dist/globalization/interfaces/filters/II18nFilterDisplay.d.ts +1 -0
  45. package/dist/globalization/labels/export/I18N_EXPORT_MODAL.js +20 -0
  46. package/dist/globalization/labels/filters/I18N_FILTER_DISPLAY.js +1 -0
  47. package/dist/interfaces/SatinizerStrategy.d.ts +3 -0
  48. package/dist/interfaces/SatinizerStrategy.js +1 -0
  49. package/package.json +3 -2
@@ -1,3 +1,4 @@
1
+ export * from "./transformFilters";
1
2
  export * from "./modelAnswerToFilterValue";
2
3
  export * from "./adaptDateGroupingProperty";
3
4
  export * from "./adaptFilterData";
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./transformFilters"), exports);
17
18
  __exportStar(require("./modelAnswerToFilterValue"), exports);
18
19
  __exportStar(require("./adaptDateGroupingProperty"), exports);
19
20
  __exportStar(require("./adaptFilterData"), exports);
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Transform the old filters structure into the new one
3
+ *
4
+ * @deprecated Since 2020, Added back in 2024 but not support provided (unmantained)
5
+ * @param {Object} oldFiltersObj an object with the old filters structure
6
+ * @param {String} section could be 'ANALYZE', 'PB', 'UM' or any other value. Deafult is 'ANYWHERE'
7
+ *
8
+ * @returns {Object} an object with the new filters structure
9
+ *
10
+ * @example
11
+ *
12
+ * const oldPreferenceFilters = {
13
+ * "WWXHAULtR-_-xYOQAdpqT__ENABLED": true,
14
+ * "WWXHAULtR-_-xYOQAdpqT__ALL--ENABLED": true,
15
+ * "WWXHAULtR-_-xYOQAdpqT__COLLAPSED": false,
16
+ * "WWXHAULtR-_-xYOQAdpqT__LABEL": "GLOBAL",
17
+ * "WWXHAULtR-_-xYOQAdpqT-_-AK4M8UV2": {
18
+ * "formulaId": null,
19
+ * "panelId": null,
20
+ * "values": [
21
+ * {
22
+ * "EQUALS": [
23
+ * {
24
+ * "id": "AK4M8UV2a0",
25
+ * "value": "A",
26
+ * "enabled": true,
27
+ * "imageUrl": null
28
+ * },
29
+ * {
30
+ * "id": "AK4M8UV2a1",
31
+ * "value": "B",
32
+ * "enabled": true,
33
+ * "imageUrl": null
34
+ * }
35
+ * ]
36
+ * }
37
+ * ],
38
+ * "bucketId": null,
39
+ * "text": "MC",
40
+ * "title": "MC",
41
+ * "type": "SINGLE_CHOICE",
42
+ * "qid": "AK4M8UV2",
43
+ * "dataset": {
44
+ * "sourceid": "xYOQAdpqT",
45
+ * "name": "Form All Questions",
46
+ * "qrveyid": "xYOQAdpqT",
47
+ * "text": "Form All Questions",
48
+ * "linkid": 0
49
+ * },
50
+ * "enabled": true,
51
+ * "linked": null
52
+ * }
53
+ * };
54
+ *
55
+ * const filterData = transformFilters(oldPreferenceFilters, 'ANALYZE');
56
+ */
57
+ export declare function transformFilters(oldFiltersObj?: {}, section?: string): {
58
+ enabled: boolean;
59
+ logic: any[];
60
+ section: string;
61
+ };
@@ -0,0 +1,432 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformFilters = void 0;
4
+ /* eslint-disable no-nested-ternary */
5
+ const isTokenLabel_1 = require("../../tokens/isTokenLabel");
6
+ const FILTER_VALIDATOR_1 = require("../constants/common/FILTER_VALIDATOR");
7
+ const FILTER_SCOPE_1 = require("../constants/common/FILTER_SCOPE");
8
+ const FILTER_SECTION_1 = require("../constants/common/FILTER_SECTION");
9
+ const FILTER_BACKEND_VALIDATOR_1 = require("../constants/backend/FILTER_BACKEND_VALIDATOR");
10
+ const get_1 = require("../../general/object/get");
11
+ const capitalize_1 = require("../../general/string/capitalize");
12
+ /**
13
+ * Transform the old filters structure into the new one
14
+ *
15
+ * @deprecated Since 2020, Added back in 2024 but not support provided (unmantained)
16
+ * @param {Object} oldFiltersObj an object with the old filters structure
17
+ * @param {String} section could be 'ANALYZE', 'PB', 'UM' or any other value. Deafult is 'ANYWHERE'
18
+ *
19
+ * @returns {Object} an object with the new filters structure
20
+ *
21
+ * @example
22
+ *
23
+ * const oldPreferenceFilters = {
24
+ * "WWXHAULtR-_-xYOQAdpqT__ENABLED": true,
25
+ * "WWXHAULtR-_-xYOQAdpqT__ALL--ENABLED": true,
26
+ * "WWXHAULtR-_-xYOQAdpqT__COLLAPSED": false,
27
+ * "WWXHAULtR-_-xYOQAdpqT__LABEL": "GLOBAL",
28
+ * "WWXHAULtR-_-xYOQAdpqT-_-AK4M8UV2": {
29
+ * "formulaId": null,
30
+ * "panelId": null,
31
+ * "values": [
32
+ * {
33
+ * "EQUALS": [
34
+ * {
35
+ * "id": "AK4M8UV2a0",
36
+ * "value": "A",
37
+ * "enabled": true,
38
+ * "imageUrl": null
39
+ * },
40
+ * {
41
+ * "id": "AK4M8UV2a1",
42
+ * "value": "B",
43
+ * "enabled": true,
44
+ * "imageUrl": null
45
+ * }
46
+ * ]
47
+ * }
48
+ * ],
49
+ * "bucketId": null,
50
+ * "text": "MC",
51
+ * "title": "MC",
52
+ * "type": "SINGLE_CHOICE",
53
+ * "qid": "AK4M8UV2",
54
+ * "dataset": {
55
+ * "sourceid": "xYOQAdpqT",
56
+ * "name": "Form All Questions",
57
+ * "qrveyid": "xYOQAdpqT",
58
+ * "text": "Form All Questions",
59
+ * "linkid": 0
60
+ * },
61
+ * "enabled": true,
62
+ * "linked": null
63
+ * }
64
+ * };
65
+ *
66
+ * const filterData = transformFilters(oldPreferenceFilters, 'ANALYZE');
67
+ */
68
+ function transformFilters(oldFiltersObj = {}, section = FILTER_SECTION_1.FILTER_SECTION.ANYWHERE) {
69
+ const filterData = { enabled: true, logic: [], section };
70
+ const tempScopes = {};
71
+ Object.keys(oldFiltersObj).forEach((key) => {
72
+ if (key.endsWith("__ALL--ENABLED"))
73
+ filterData.enabled = oldFiltersObj[key];
74
+ if (!key.endsWith("ENABLED") &&
75
+ !key.endsWith("LABEL") &&
76
+ !key.endsWith("COLLAPSED")) {
77
+ const filterSeparator = "-_-";
78
+ const keyArray = key.split(filterSeparator);
79
+ const tempArray = [...keyArray];
80
+ tempArray.pop();
81
+ let enabledKey = "__ENABLED";
82
+ let collapsedKey = "__COLLAPSED";
83
+ let labelKey = "__LABEL";
84
+ if (keyArray.length === 5) {
85
+ tempArray.pop();
86
+ enabledKey = "__PANELS--ENABLED";
87
+ collapsedKey = "__PANELS--COLLAPSED";
88
+ labelKey = "__PANELS--LABEL";
89
+ }
90
+ const keyBase = tempArray.join(filterSeparator);
91
+ const scopeLabel = getScopeLabel(oldFiltersObj[keyBase + labelKey]);
92
+ const scopeId = tempArray[tempArray.length - 1] !== "VIEW"
93
+ ? tempArray[tempArray.length - 1]
94
+ : undefined;
95
+ const scopeKey = `${scopeLabel}|${scopeId}`;
96
+ if (!tempScopes[scopeKey]) {
97
+ tempScopes[scopeKey] = {
98
+ enabled: oldFiltersObj[keyBase + enabledKey],
99
+ scope: scopeLabel,
100
+ filters: [],
101
+ uiExtras: {
102
+ scopeid: scopeId,
103
+ collapsed: oldFiltersObj[keyBase + collapsedKey],
104
+ section,
105
+ },
106
+ };
107
+ }
108
+ const filtersObj = validateComplexTypes(oldFiltersObj[key], Object.keys(oldFiltersObj[key].values[0]));
109
+ const validations = Object.keys(filtersObj.values[0]);
110
+ tempScopes[scopeKey].filters.push({
111
+ operator: "AND",
112
+ expressions: [
113
+ {
114
+ operator: "OR",
115
+ uiExtras: {
116
+ expressionid: `${filtersObj.qid}|${scopeId}|${filtersObj.panelid || ""}`,
117
+ },
118
+ expressions: getExpressions(filtersObj, validations, scopeLabel, scopeId, section),
119
+ },
120
+ ],
121
+ });
122
+ }
123
+ });
124
+ filterData.logic = Object.values(tempScopes);
125
+ return filterData;
126
+ }
127
+ exports.transformFilters = transformFilters;
128
+ function validateComplexTypes(oldFiltersItem, validations) {
129
+ if (![
130
+ "IMAGEUPLOAD",
131
+ "TEXTFIELD",
132
+ "LONGTEXT",
133
+ "NAME",
134
+ "ADDRESS",
135
+ "USADDRESS",
136
+ ].includes(oldFiltersItem.type))
137
+ return oldFiltersItem;
138
+ const complexFiltersItem = Object.assign(Object.assign({}, oldFiltersItem), { values: [{}] });
139
+ validations.forEach((valKey) => {
140
+ oldFiltersItem.values[0][valKey].forEach((value) => {
141
+ const newKey = `${valKey}|${(value.targetFilter || value.property || "")
142
+ .toLowerCase()
143
+ .replace("_text", "")
144
+ .replace("_type", "type")}`;
145
+ if (!complexFiltersItem.values[0][newKey]) {
146
+ complexFiltersItem.values[0][newKey] = [value];
147
+ }
148
+ else {
149
+ complexFiltersItem.values[0][newKey].push(value);
150
+ }
151
+ });
152
+ });
153
+ return complexFiltersItem;
154
+ }
155
+ function getScopeLabel(oldScopeLabel) {
156
+ switch (oldScopeLabel) {
157
+ case "GLOBAL":
158
+ return FILTER_SCOPE_1.FILTER_SCOPE.GLOBAL;
159
+ case "PAGE":
160
+ return FILTER_SCOPE_1.FILTER_SCOPE.PAGE;
161
+ case "TAB":
162
+ return FILTER_SCOPE_1.FILTER_SCOPE.TAB;
163
+ case "PANEL":
164
+ return FILTER_SCOPE_1.FILTER_SCOPE.CHART;
165
+ default:
166
+ return oldScopeLabel;
167
+ }
168
+ }
169
+ function getValidationType(oldValidation, columnType, formulaType) {
170
+ switch (oldValidation) {
171
+ case "EQUALS":
172
+ case "EQUAL":
173
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.EQUALS;
174
+ case "NOT_EQUALS":
175
+ case "NOT_EQUAL":
176
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.NOT_EQUAL;
177
+ case "CONTAINS":
178
+ case "CONTAIN":
179
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.CONTAINS;
180
+ case "NOT_CONTAINS":
181
+ case "NOT_CONTAIN":
182
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.NOT_CONTAIN;
183
+ case "LESS_THAN":
184
+ case "LESS_THAN_OR_EQUAL":
185
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.LESS_THAN_EQUAL;
186
+ case "GREATER_THAN":
187
+ case "GREATER_THAN_OR_EQUAL":
188
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.GREATER_THAN_EQUAL;
189
+ case "BETWEEN":
190
+ case "YEAR":
191
+ case "MONTH_YEAR":
192
+ case "QUARTER":
193
+ case "WEEK":
194
+ case "SECOND":
195
+ case "MINUTE":
196
+ case "HOUR":
197
+ case "DAY":
198
+ return ![columnType, formulaType].includes("DATE")
199
+ ? FILTER_VALIDATOR_1.FILTER_VALIDATOR.BETWEEN_INCLUSIVE
200
+ : FILTER_BACKEND_VALIDATOR_1.FILTER_BACKEND_VALIDATOR.RANGE;
201
+ default:
202
+ return oldValidation;
203
+ }
204
+ }
205
+ function getValidator(oldValidation) {
206
+ switch (oldValidation) {
207
+ case "EQUALS":
208
+ case "EQUAL":
209
+ case "YEAR":
210
+ case "MONTH_YEAR":
211
+ case "QUARTER":
212
+ case "WEEK":
213
+ case "SECOND":
214
+ case "MINUTE":
215
+ case "HOUR":
216
+ case "DAY":
217
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.EQUALS;
218
+ case "NOT_EQUALS":
219
+ case "NOT_EQUAL":
220
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.NOT_EQUAL;
221
+ case "CONTAINS":
222
+ case "CONTAIN":
223
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.CONTAINS;
224
+ case "NOT_CONTAINS":
225
+ case "NOT_CONTAIN":
226
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.NOT_CONTAIN;
227
+ case "BETWEEN":
228
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.BETWEEN_INCLUSIVE;
229
+ case "LESS_THAN":
230
+ case "LESS_THAN_OR_EQUAL":
231
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.LESS_THAN_EQUAL;
232
+ case "GREATER_THAN":
233
+ case "GREATER_THAN_OR_EQUAL":
234
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.GREATER_THAN_EQUAL;
235
+ case "IS_EMPTY":
236
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.IS_NULL;
237
+ case "IS_NOT_EMPTY":
238
+ return FILTER_VALIDATOR_1.FILTER_VALIDATOR.IS_NOT_NULL;
239
+ default:
240
+ return oldValidation;
241
+ }
242
+ }
243
+ function getProperty(filterObjItem, validationKey) {
244
+ if (filterObjItem.type === "IMAGE")
245
+ return "answer_id";
246
+ const value = (0, get_1._get)(filterObjItem, `values[0]['${validationKey}'][0]`, {});
247
+ const property = filterObjItem.property || value.property || value.targetFilter;
248
+ return property && property.toUpperCase();
249
+ }
250
+ function getDateProperty(validationKey, columnType, formulaType) {
251
+ if (![columnType, formulaType].includes("DATE"))
252
+ return;
253
+ return [
254
+ "MONTH_YEAR",
255
+ "YEAR",
256
+ "QUARTER",
257
+ "WEEK",
258
+ "HOUR",
259
+ "MINUTE",
260
+ "SECOND",
261
+ ].includes(validationKey)
262
+ ? validationKey.split("_")[0].toLowerCase()
263
+ : "day";
264
+ }
265
+ function getFilterRangeValue(range, minProp = "min", maxProp = "max", extras = {}) {
266
+ return Object.assign({ [minProp]: range.from || range.gte, [maxProp]: range.to || range.lte }, extras);
267
+ }
268
+ function getUiRangeValue(oldValue) {
269
+ if (oldValue.label)
270
+ return (oldValue.label + "").replace("-", " ");
271
+ const range = oldValue.range || oldValue;
272
+ return `${range.from || range.gte} - ${range.to || range.lte}`;
273
+ }
274
+ function getRankingFBvalues(values) {
275
+ const returnValues = [];
276
+ values
277
+ .map((vItem) => (Object.assign(Object.assign({}, vItem), { position: +vItem.position + 1 })))
278
+ .forEach((vItem) => {
279
+ const groupIndex = returnValues.findIndex((group) => group.every((groupItem) => groupItem.value.value !== vItem.value) &&
280
+ group.every((groupItem) => groupItem.position !== vItem.position));
281
+ const returnItem = {
282
+ position: vItem.position,
283
+ value: { enabled: vItem.enabled, value: vItem.value },
284
+ };
285
+ if (groupIndex === -1)
286
+ returnValues.push([returnItem]);
287
+ else
288
+ returnValues[groupIndex].push(returnItem);
289
+ });
290
+ return returnValues;
291
+ }
292
+ function getValues(values, columnType, oldValidation = "EQUAL", destination = "value", formulaType) {
293
+ switch (oldValidation) {
294
+ case "BETWEEN":
295
+ case "YEAR":
296
+ case "MONTH_YEAR":
297
+ return destination === "value"
298
+ ? values.map((val) => getFilterRangeValue(val.value.range || val.value, "gte", "lte"))
299
+ : destination === "uiValue"
300
+ ? values.map((val) => getFilterRangeValue(val.value.range || val.value, "min", "max", {
301
+ enabled: val.enabled,
302
+ value: getUiRangeValue(val.value),
303
+ validationLabel: oldValidation,
304
+ }))
305
+ : ["YEAR", "MONTH_YEAR", "QUARTER"].includes(oldValidation)
306
+ ? values.map((item) => ({ value: getUiRangeValue(item.value) }))
307
+ : values.map((val) => getFilterRangeValue(val.value.range || val.value));
308
+ case "LESS_THAN":
309
+ case "GREATER_THAN": {
310
+ const prop = oldValidation === "LESS_THAN" ? "lte" : "gte";
311
+ return destination === "value"
312
+ ? values.map((val) => getFilterRangeValue({ [prop]: val.value }, "gte", "lte"))
313
+ : destination === "uiValue"
314
+ ? values.map((val) => getFilterRangeValue({ [prop]: val.value }, "min", "max", {
315
+ enabled: val.enabled,
316
+ value: val.value,
317
+ }))
318
+ : values.map((val) => getFilterRangeValue({ [prop]: val.value }));
319
+ }
320
+ case "IS_EMPTY":
321
+ case "IS_NOT_EMPTY": {
322
+ const valueClean = getValidator(oldValidation)
323
+ .toLowerCase()
324
+ .split("_")
325
+ .map((v) => (0, capitalize_1.capitalize)(v))
326
+ .join(" ");
327
+ return destination === "value"
328
+ ? [valueClean]
329
+ : destination === "uiValue"
330
+ ? values.map((val) => ({ value: valueClean, enabled: val.enabled }))
331
+ : [];
332
+ }
333
+ default:
334
+ return getFilterEqualValues(values, columnType, destination, formulaType);
335
+ }
336
+ }
337
+ function getFilterEqualValues(values, columnType, destination = "value", formulaType) {
338
+ if (columnType === "RANKING") {
339
+ return destination === "value"
340
+ ? values.map((item) => ({ position: +item.position, value: item.value }))
341
+ : destination === "uiValue"
342
+ ? values.map((item) => ({
343
+ value: getUiRangeValue({
344
+ from: item.value,
345
+ to: +item.position + 1,
346
+ }),
347
+ enabled: true,
348
+ }))
349
+ : getRankingFBvalues(values);
350
+ }
351
+ return destination === "value"
352
+ ? values.map((item) => {
353
+ let value = item.value;
354
+ if ([columnType, formulaType].includes("DATE") &&
355
+ !(0, isTokenLabel_1.isTokenLabel)(value)) {
356
+ value = getFilterRangeValue(item.value.range || item.value, "gte", "lte");
357
+ }
358
+ else if (columnType === "YES_NO") {
359
+ value = item.value.toLowerCase();
360
+ }
361
+ else if (columnType === "IMAGE") {
362
+ value = item.id || item.answerid || item.answer_id;
363
+ }
364
+ else {
365
+ value = String(item.value);
366
+ }
367
+ return value;
368
+ })
369
+ : values.map((item) => ({
370
+ value: columnType === "YES_NO"
371
+ ? item.value.toLowerCase()
372
+ : [columnType, formulaType].includes("DATE")
373
+ ? item.value.label || item.value
374
+ : String(item.value),
375
+ valueid: columnType === "EXPRESSION" ? undefined : item.id || item.answerid,
376
+ enabled: item.enabled || true,
377
+ }));
378
+ }
379
+ function getFormulaType(oldFiltersItem) {
380
+ if (oldFiltersItem.formulaType)
381
+ return oldFiltersItem.formulaType;
382
+ if (oldFiltersItem.formulaId)
383
+ return oldFiltersItem.type === "NUMERIC"
384
+ ? "number"
385
+ : oldFiltersItem.type === "DATE"
386
+ ? "date"
387
+ : "string";
388
+ }
389
+ function getExpressions(oldFiltersItem, validations, scopeLabel, scopeid, section) {
390
+ const expressions = [];
391
+ validations.forEach((valKey) => {
392
+ const valKeyArray = valKey.split("|");
393
+ const validationKey = valKeyArray[0];
394
+ const property = valKeyArray[1] || getProperty(oldFiltersItem, validationKey);
395
+ const formulaType = getFormulaType(oldFiltersItem);
396
+ const questionType = formulaType ? "FORMULA" : oldFiltersItem.type;
397
+ const expressionItem = {
398
+ enabled: oldFiltersItem.enabled,
399
+ property: property,
400
+ qrveyid: oldFiltersItem.dataset.qrveyid,
401
+ questionid: oldFiltersItem.qid,
402
+ formulaType: formulaType,
403
+ questionType: questionType,
404
+ type: questionType,
405
+ validationType: getValidationType(validationKey, questionType, formulaType && formulaType.toUpperCase()),
406
+ uiExtras: {
407
+ column: {
408
+ dataset: {
409
+ qrveyid: oldFiltersItem.dataset.qrveyid,
410
+ name: oldFiltersItem.dataset.name,
411
+ },
412
+ formulaType: formulaType,
413
+ id: oldFiltersItem.qid,
414
+ qrveyid: oldFiltersItem.dataset.qrveyid,
415
+ text: oldFiltersItem.text,
416
+ type: questionType,
417
+ },
418
+ operator: "AND",
419
+ property: getDateProperty(validationKey, questionType, formulaType && formulaType.toUpperCase()) || property,
420
+ validator: getValidator(validationKey),
421
+ panelid: oldFiltersItem.panelId,
422
+ panelName: oldFiltersItem.panelId ? oldFiltersItem.title : undefined,
423
+ uiHidden: false,
424
+ scope: scopeLabel,
425
+ scopeid,
426
+ section,
427
+ },
428
+ };
429
+ expressions.push(Object.assign(Object.assign({}, expressionItem), { value: getValues(oldFiltersItem.values[0][valKey], questionType, validationKey, "value", formulaType && formulaType.toUpperCase()), uiExtras: Object.assign(Object.assign({}, expressionItem.uiExtras), { values: getValues(oldFiltersItem.values[0][valKey], questionType, validationKey, "values", formulaType && formulaType.toUpperCase()), uiValue: getValues(oldFiltersItem.values[0][valKey], questionType, validationKey, "uiValue", formulaType && formulaType.toUpperCase()) }) }));
430
+ });
431
+ return expressions;
432
+ }
@@ -8,3 +8,9 @@ import { IFValidator } from "../../interfaces/IFValidator";
8
8
  * @returns properties of the Date column
9
9
  */
10
10
  export declare function getDateProperties(column: IColumn, validator: IFValidator): IColumnPropertyInfo[];
11
+ /**
12
+ * Returns True or false when the output format in the date column exists and is a time type
13
+ * @param column Column prop
14
+ * @returns True if The Date Column has a time format, otherwise is false.
15
+ */
16
+ export declare function isDateColumnTimeFormat(column: IColumn): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDateProperties = void 0;
3
+ exports.isDateColumnTimeFormat = exports.getDateProperties = void 0;
4
4
  const isValidatorMatchedToWindow_1 = require("./isValidatorMatchedToWindow");
5
5
  const DATE_DISTINCT_PROPERTY_INFO_LIST_1 = require("../../../dates/constants/DATE_DISTINCT_PROPERTY_INFO_LIST");
6
6
  const DATE_DISTINCT_TIME_PROPERTY_INFO_LIST_1 = require("../../../dates/constants/DATE_DISTINCT_TIME_PROPERTY_INFO_LIST");
@@ -44,3 +44,4 @@ function isDateColumnTimeFormat(column) {
44
44
  const formatDate = (0, get_1._get)(column.outputFormat, "format");
45
45
  return !(0, isEmpty_1.isEmpty)(formatDate) && formatDate.split(" ").length > 1;
46
46
  }
47
+ exports.isDateColumnTimeFormat = isDateColumnTimeFormat;
@@ -19,7 +19,6 @@ const getScopesToDisplay_1 = require("./getScopesToDisplay");
19
19
  */
20
20
  function getFilterSettings(filterSettings, allowedScopes = [], otherSettings) {
21
21
  let settings = (0, mergeDeep_1.mergeDeep)(FILTER_SETTINGS_DEFAULT_1.FILTER_SETTINGS_DEFAULT, (0, objectCopy_1.objectCopy)(filterSettings));
22
- settings = (0, mergeDeep_1.mergeDeep)(settings, otherSettings);
23
22
  const scopesSettings = (0, getScopesToDisplay_1.getScopesToDisplay)(settings).filter((scope) => allowedScopes.includes(scope.id));
24
23
  if (scopesSettings.length > 1) {
25
24
  settings = getFilterSettingsByMultipleScopes(settings, allowedScopes);
@@ -30,6 +29,7 @@ function getFilterSettings(filterSettings, allowedScopes = [], otherSettings) {
30
29
  else {
31
30
  settings = getFilterSettingsByNoScopes(settings);
32
31
  }
32
+ settings = (0, mergeDeep_1.mergeDeep)(settings, otherSettings);
33
33
  return settings;
34
34
  }
35
35
  exports.getFilterSettings = getFilterSettings;
@@ -2,4 +2,8 @@ import { IFScope } from "../IFScope";
2
2
  export interface IFSScopeID {
3
3
  label: IFScope;
4
4
  id?: string;
5
+ /**
6
+ * The ID of the dataset related to the filter
7
+ */
8
+ datasetId?: string;
5
9
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Gets the number of times that the param value exists into the object array
3
+ * @param array the given array
4
+ * @param param the param of the array object to compare
5
+ * @param value the value of the array object to compare
6
+ * @returns the number of times the parameter value exists
7
+ */
8
+ export declare function howManyByParam<T = Record<string, unknown>>(array: T[], param: keyof T, value: unknown): number;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.howManyByParam = void 0;
4
+ /**
5
+ * Gets the number of times that the param value exists into the object array
6
+ * @param array the given array
7
+ * @param param the param of the array object to compare
8
+ * @param value the value of the array object to compare
9
+ * @returns the number of times the parameter value exists
10
+ */
11
+ function howManyByParam(array, param, value) {
12
+ let count = 0;
13
+ if (!Array.isArray(array))
14
+ return count;
15
+ for (const i of array) {
16
+ if (i[param] === value)
17
+ count = count + 1;
18
+ }
19
+ return count;
20
+ }
21
+ exports.howManyByParam = howManyByParam;
@@ -4,5 +4,7 @@ export * from "./flattenDeep";
4
4
  export * from "./getArrayByProperty";
5
5
  export * from "./filterNestedTree";
6
6
  export * from "./getFirstIndexFromArray";
7
+ export * from "./getUniqueArray";
8
+ export * from "./howManyByParam";
7
9
  export * from "./getLastIndexFromArray";
8
10
  export * from "./intersectObjectArrays";
@@ -20,5 +20,7 @@ __exportStar(require("./flattenDeep"), exports);
20
20
  __exportStar(require("./getArrayByProperty"), exports);
21
21
  __exportStar(require("./filterNestedTree"), exports);
22
22
  __exportStar(require("./getFirstIndexFromArray"), exports);
23
+ __exportStar(require("./getUniqueArray"), exports);
24
+ __exportStar(require("./howManyByParam"), exports);
23
25
  __exportStar(require("./getLastIndexFromArray"), exports);
24
26
  __exportStar(require("./intersectObjectArrays"), exports);
@@ -2,3 +2,5 @@ export * from "./capitalize";
2
2
  export * from "./padLeadingZeros";
3
3
  export * from "./parseUrl";
4
4
  export * from "./camelize";
5
+ export * from "./secureHTML";
6
+ export * from "./strategies/XSSSanitizer";
@@ -18,3 +18,5 @@ __exportStar(require("./capitalize"), exports);
18
18
  __exportStar(require("./padLeadingZeros"), exports);
19
19
  __exportStar(require("./parseUrl"), exports);
20
20
  __exportStar(require("./camelize"), exports);
21
+ __exportStar(require("./secureHTML"), exports);
22
+ __exportStar(require("./strategies/XSSSanitizer"), exports);
@@ -0,0 +1,8 @@
1
+ import { SanitizerStrategy } from "../../interfaces/SatinizerStrategy";
2
+ /**
3
+ * Sanitizes HTML using the provided strategy.
4
+ * @param {string} html - HTML to sanitize.
5
+ * @param {SanitizerStrategy} sanitizer - Sanitization strategy.
6
+ * @returns {string} - Sanitized HTML.
7
+ */
8
+ export declare const secureHTML: (html: string, sanitizer: SanitizerStrategy) => string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.secureHTML = void 0;
4
+ /**
5
+ * Sanitizes HTML using the provided strategy.
6
+ * @param {string} html - HTML to sanitize.
7
+ * @param {SanitizerStrategy} sanitizer - Sanitization strategy.
8
+ * @returns {string} - Sanitized HTML.
9
+ */
10
+ const secureHTML = (html, sanitizer) => {
11
+ return sanitizer.sanitize(html);
12
+ };
13
+ exports.secureHTML = secureHTML;
@@ -0,0 +1,8 @@
1
+ import { IFilterXSSOptions } from "xss";
2
+ import { SanitizerStrategy } from "../../../interfaces/SatinizerStrategy";
3
+ export declare class XSSSanitizer implements SanitizerStrategy {
4
+ private attributesBlackList;
5
+ private options;
6
+ constructor(options?: IFilterXSSOptions, attributesBlackList?: string[]);
7
+ sanitize(html: string): string;
8
+ }