@clxmedia/clxforms-client 1.0.12 → 1.0.14
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/layout-filter.d.ts +5 -0
- package/dist/layout-filter.js +76 -0
- package/dist/layout-processor.d.ts +1 -2
- package/dist/layout-processor.js +0 -73
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CLXFormLayoutProcessor, ProcessedCLXFormSection, ProcessedCLXFormStep, ProcessedCLXFormLayout } from './layout-processor';
|
|
2
|
+
export { CLXFormLayoutFilter, FilteredCLXFormLayout, } from './layout-filter';
|
|
2
3
|
export { CLXRulesetProcessor } from './rules-processor';
|
|
3
4
|
export { CLXRulesEngine } from './rules-engine';
|
|
4
5
|
export { CLXFormConstants } from './constants';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLXFormConstants = exports.CLXRulesEngine = exports.CLXRulesetProcessor = exports.CLXFormLayoutProcessor = void 0;
|
|
3
|
+
exports.CLXFormConstants = exports.CLXRulesEngine = exports.CLXRulesetProcessor = exports.CLXFormLayoutFilter = exports.CLXFormLayoutProcessor = void 0;
|
|
4
4
|
var layout_processor_1 = require("./layout-processor");
|
|
5
5
|
Object.defineProperty(exports, "CLXFormLayoutProcessor", { enumerable: true, get: function () { return layout_processor_1.CLXFormLayoutProcessor; } });
|
|
6
|
+
var layout_filter_1 = require("./layout-filter");
|
|
7
|
+
Object.defineProperty(exports, "CLXFormLayoutFilter", { enumerable: true, get: function () { return layout_filter_1.CLXFormLayoutFilter; } });
|
|
6
8
|
var rules_processor_1 = require("./rules-processor");
|
|
7
9
|
Object.defineProperty(exports, "CLXRulesetProcessor", { enumerable: true, get: function () { return rules_processor_1.CLXRulesetProcessor; } });
|
|
8
10
|
var rules_engine_1 = require("./rules-engine");
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLXFormLayoutFilter = void 0;
|
|
4
|
+
const slugExtractor = (rs) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return (_a = rs === null || rs === void 0 ? void 0 : rs.rules) === null || _a === void 0 ? void 0 : _a.reduce((acc, rule) => {
|
|
7
|
+
const subject = rule.subject;
|
|
8
|
+
if (subject) {
|
|
9
|
+
return acc.concat(subject);
|
|
10
|
+
}
|
|
11
|
+
return acc.concat(slugExtractor(rule));
|
|
12
|
+
}, []);
|
|
13
|
+
};
|
|
14
|
+
const determineUsedSlugs = (steps) => {
|
|
15
|
+
return steps.reduce((acc, step) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
for (const section of step.sections) {
|
|
18
|
+
for (const ql of section.question_layouts) {
|
|
19
|
+
acc.add(ql.form_question_slug);
|
|
20
|
+
const conditionSlugs = slugExtractor(ql.conditions);
|
|
21
|
+
const overrideSlugs = (_b = (_a = ql.overrides) === null || _a === void 0 ? void 0 : _a.max_select_override) === null || _b === void 0 ? void 0 : _b.reduce((acc, rule) => {
|
|
22
|
+
return acc.concat(slugExtractor(rule === null || rule === void 0 ? void 0 : rule.ruleset));
|
|
23
|
+
}, []);
|
|
24
|
+
conditionSlugs === null || conditionSlugs === void 0 ? void 0 : conditionSlugs.forEach((slug) => acc.add(slug));
|
|
25
|
+
overrideSlugs === null || overrideSlugs === void 0 ? void 0 : overrideSlugs.forEach((slug) => acc.add(slug));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, new Set());
|
|
30
|
+
};
|
|
31
|
+
const CLXFormLayoutFilter = (processedLayout) => {
|
|
32
|
+
const filtered = {
|
|
33
|
+
form: processedLayout.form,
|
|
34
|
+
usedSlugs: new Set(),
|
|
35
|
+
steps: processedLayout.steps
|
|
36
|
+
.map((step) => {
|
|
37
|
+
return {
|
|
38
|
+
id: step.id,
|
|
39
|
+
name: step.name,
|
|
40
|
+
description: step.description,
|
|
41
|
+
is_gate: step.is_gate,
|
|
42
|
+
sections: step.sections
|
|
43
|
+
.map((section) => {
|
|
44
|
+
return {
|
|
45
|
+
id: section.id,
|
|
46
|
+
name: section.name,
|
|
47
|
+
question_layouts: section.question_layouts
|
|
48
|
+
.map((ql) => {
|
|
49
|
+
return {
|
|
50
|
+
id: ql.id,
|
|
51
|
+
form_question_slug: ql.form_question_slug,
|
|
52
|
+
is_enabled: ql.is_enabled,
|
|
53
|
+
is_required: ql.is_required,
|
|
54
|
+
conditions: ql.conditions,
|
|
55
|
+
overrides: ql.overrides,
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
.filter((ql) => {
|
|
59
|
+
return ql.is_enabled;
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
})
|
|
63
|
+
.filter((section) => {
|
|
64
|
+
return section.question_layouts.length > 0;
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
})
|
|
68
|
+
.filter((step) => {
|
|
69
|
+
return step.sections.length > 0;
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
filtered.usedSlugs = determineUsedSlugs(filtered.steps);
|
|
73
|
+
;
|
|
74
|
+
return filtered;
|
|
75
|
+
};
|
|
76
|
+
exports.CLXFormLayoutFilter = CLXFormLayoutFilter;
|
|
@@ -22,14 +22,13 @@ export type ProcessedCLXFormLayout = {
|
|
|
22
22
|
stats?: FormStats;
|
|
23
23
|
};
|
|
24
24
|
export type FilteredCLXFormLayout = ProcessedCLXFormLayout & {
|
|
25
|
-
usedSlugs: string
|
|
25
|
+
usedSlugs: Set<string>;
|
|
26
26
|
};
|
|
27
27
|
export declare const CLXFormLayoutProcessor: ({ mode, responseData, formRights }: {
|
|
28
28
|
mode: CLXFormMode;
|
|
29
29
|
responseData: CLXFormResponses;
|
|
30
30
|
formRights: XperienceAbility;
|
|
31
31
|
}) => {
|
|
32
|
-
filter: (pl: ProcessedCLXFormLayout) => FilteredCLXFormLayout;
|
|
33
32
|
process: (layout: CLXFormLayout) => ProcessedCLXFormLayout;
|
|
34
33
|
processRuleSet: (ruleSet?: CLXFormRuleSet) => boolean;
|
|
35
34
|
};
|
package/dist/layout-processor.js
CHANGED
|
@@ -76,78 +76,6 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
76
76
|
const value = responseData[key];
|
|
77
77
|
return !!value && value.type === 'BOOLEAN' && value.value;
|
|
78
78
|
};
|
|
79
|
-
const slugExtractor = (rs) => {
|
|
80
|
-
var _a;
|
|
81
|
-
return (_a = rs === null || rs === void 0 ? void 0 : rs.rules) === null || _a === void 0 ? void 0 : _a.reduce((acc, rule) => {
|
|
82
|
-
const subject = rule.subject;
|
|
83
|
-
if (subject) {
|
|
84
|
-
return acc.concat(subject);
|
|
85
|
-
}
|
|
86
|
-
return acc.concat(slugExtractor(rule));
|
|
87
|
-
}, []);
|
|
88
|
-
};
|
|
89
|
-
const determineUsedSlugs = (steps) => {
|
|
90
|
-
const activeSlugs = steps.reduce((acc, step) => {
|
|
91
|
-
var _a, _b;
|
|
92
|
-
for (const section of step.sections) {
|
|
93
|
-
for (const ql of section.question_layouts) {
|
|
94
|
-
acc.add(ql.form_question_slug);
|
|
95
|
-
const conditionSlugs = slugExtractor(ql.conditions);
|
|
96
|
-
const overrideSlugs = (_b = (_a = ql.overrides) === null || _a === void 0 ? void 0 : _a.max_select_override) === null || _b === void 0 ? void 0 : _b.reduce((acc, rule) => {
|
|
97
|
-
return acc.concat(slugExtractor(rule === null || rule === void 0 ? void 0 : rule.ruleset));
|
|
98
|
-
}, []);
|
|
99
|
-
conditionSlugs === null || conditionSlugs === void 0 ? void 0 : conditionSlugs.forEach((slug) => acc.add(slug));
|
|
100
|
-
overrideSlugs === null || overrideSlugs === void 0 ? void 0 : overrideSlugs.forEach((slug) => acc.add(slug));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return acc;
|
|
104
|
-
}, new Set());
|
|
105
|
-
return Array.from(activeSlugs);
|
|
106
|
-
};
|
|
107
|
-
const filter = (pl) => {
|
|
108
|
-
const filtered = {
|
|
109
|
-
form: pl.form,
|
|
110
|
-
steps: pl.steps
|
|
111
|
-
.map((step) => {
|
|
112
|
-
return {
|
|
113
|
-
id: step.id,
|
|
114
|
-
name: step.name,
|
|
115
|
-
description: step.description,
|
|
116
|
-
is_gate: step.is_gate,
|
|
117
|
-
sections: step.sections
|
|
118
|
-
.map((section) => {
|
|
119
|
-
return {
|
|
120
|
-
id: section.id,
|
|
121
|
-
name: section.name,
|
|
122
|
-
question_layouts: section.question_layouts
|
|
123
|
-
.map((ql) => {
|
|
124
|
-
return {
|
|
125
|
-
id: ql.id,
|
|
126
|
-
form_question_slug: ql.form_question_slug,
|
|
127
|
-
is_enabled: ql.is_enabled,
|
|
128
|
-
is_required: ql.is_required,
|
|
129
|
-
conditions: ql.conditions,
|
|
130
|
-
overrides: ql.overrides,
|
|
131
|
-
};
|
|
132
|
-
})
|
|
133
|
-
.filter((ql) => {
|
|
134
|
-
return ql.is_enabled;
|
|
135
|
-
}),
|
|
136
|
-
};
|
|
137
|
-
})
|
|
138
|
-
.filter((section) => {
|
|
139
|
-
return section.question_layouts.length > 0;
|
|
140
|
-
}),
|
|
141
|
-
};
|
|
142
|
-
})
|
|
143
|
-
.filter((step) => {
|
|
144
|
-
return step.sections.length > 0;
|
|
145
|
-
}),
|
|
146
|
-
};
|
|
147
|
-
filtered.usedSlugs = determineUsedSlugs(filtered.steps);
|
|
148
|
-
;
|
|
149
|
-
return filtered;
|
|
150
|
-
};
|
|
151
79
|
const MockProcessor = (layout) => {
|
|
152
80
|
return {
|
|
153
81
|
form: layout.form,
|
|
@@ -183,7 +111,6 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
183
111
|
return { form: layout.form, steps, stats: gatherFormStats(steps) };
|
|
184
112
|
};
|
|
185
113
|
return {
|
|
186
|
-
filter,
|
|
187
114
|
process,
|
|
188
115
|
processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet
|
|
189
116
|
};
|