@clxmedia/clxforms-client 1.0.11 → 1.0.13

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 CHANGED
@@ -1,4 +1,4 @@
1
- export { CLXFormLayoutProcessor, ProcessedCLXFormSection, ProcessedCLXFormStep, ProcessedCLXFormLayout } from './layout-processor';
1
+ export { CLXFormLayoutProcessor, FilteredCLXFormLayout, ProcessedCLXFormSection, ProcessedCLXFormStep, ProcessedCLXFormLayout } from './layout-processor';
2
2
  export { CLXRulesetProcessor } from './rules-processor';
3
3
  export { CLXRulesEngine } from './rules-engine';
4
4
  export { CLXFormConstants } from './constants';
@@ -21,11 +21,15 @@ export type ProcessedCLXFormLayout = {
21
21
  steps: ProcessedCLXFormStep[];
22
22
  stats?: FormStats;
23
23
  };
24
+ export type FilteredCLXFormLayout = ProcessedCLXFormLayout & {
25
+ usedSlugs: Set<string>;
26
+ };
24
27
  export declare const CLXFormLayoutProcessor: ({ mode, responseData, formRights }: {
25
28
  mode: CLXFormMode;
26
29
  responseData: CLXFormResponses;
27
30
  formRights: XperienceAbility;
28
31
  }) => {
32
+ filter: (pl: ProcessedCLXFormLayout) => FilteredCLXFormLayout;
29
33
  process: (layout: CLXFormLayout) => ProcessedCLXFormLayout;
30
34
  processRuleSet: (ruleSet?: CLXFormRuleSet) => boolean;
31
35
  };
@@ -76,6 +76,78 @@ 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
+ return 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
+ };
106
+ const filter = (pl) => {
107
+ const filtered = {
108
+ form: pl.form,
109
+ usedSlugs: new Set(),
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
+ };
79
151
  const MockProcessor = (layout) => {
80
152
  return {
81
153
  form: layout.form,
@@ -111,6 +183,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
111
183
  return { form: layout.form, steps, stats: gatherFormStats(steps) };
112
184
  };
113
185
  return {
186
+ filter,
114
187
  process,
115
188
  processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet
116
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/clxforms-client",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "CLXperience Forms Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",