mod-build 4.0.60-beta.1 → 4.0.60-beta.5

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 4.0.60
4
4
 
5
- - Applying merging of default trade questions and default form config on all the `steps` objects found.
5
+ - Adding VWO variation ID to the body tag as an attribute `data-vwo-test-id`
6
6
 
7
7
  ## 4.0.59
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.60-beta.1",
3
+ "version": "4.0.60-beta.5",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -10,6 +10,12 @@
10
10
  n: variationName
11
11
  }
12
12
  }
13
+ if (variationId != 1 && window.addVwoTestAttribute) {
14
+ // Control is assigned variation ID 1 - variations receive incremented IDs starting from 2
15
+ const adjustedVariationId = variationId - 1;
16
+ const vwoTestAttrValue = `${experimentId}-${adjustedVariationId}`;
17
+ document.body.setAttribute('data-vwo-test', vwoTestAttrValue);
18
+ }
13
19
  }
14
20
  }]);
15
21
 
@@ -3,173 +3,6 @@ import merge from 'lodash.merge';
3
3
  import axios from 'axios';
4
4
  import { defaultSettings } from '../src/data/config.js';
5
5
 
6
- function applyDefaultTradeConfigOnSteps(config, steps) {
7
- if (!config || typeof config !== 'object') return;
8
-
9
- if (data.steps && typeof data.steps === 'object' && data.steps.items) {
10
- mergeDefaultTradeQuestions(config, steps);
11
- }
12
- // Recursively go through all object properties
13
- for (const key in data) {
14
- if (data.hasOwnProperty(key)) {
15
- const value = data[key];
16
- if (typeof value === 'object' && value !== null) {
17
- applyDefaultTradeConfigOnSteps(value, steps);
18
- }
19
- }
20
- }
21
- }
22
-
23
- function mergeDefaultTradeQuestions(config, steps) {
24
- if (!config || !config.steps || !config.steps.items || !Array.isArray(config.steps.items)) {
25
- return;
26
- }
27
-
28
- config.steps.items.forEach((item) => {
29
- const stepName = item.attributes.data['step-name'];
30
- if (steps[stepName]) {
31
- if (!item.stepContent) {
32
- item.stepContent = {};
33
- }
34
-
35
- if (!item.stepContent.fields) {
36
- item.stepContent.fields = [];
37
- }
38
- const defaultStepFields = steps[stepName].fields;
39
- let defaultStepOptions = [];
40
- let defaultQuestionLegend = {};
41
- defaultStepFields.forEach((defaultField) => {
42
- defaultStepOptions = defaultField.options;
43
- defaultQuestionLegend = defaultField.legend;
44
- });
45
-
46
- item.stepContent.fields.forEach((field) => {
47
- if (field.legend) {
48
- field.legend = merge(defaultQuestionLegend, field.legend);
49
- } else {
50
- field.legend = defaultQuestionLegend;
51
- }
52
-
53
- if (field && field.remove) {
54
- if (field.remove.includes('all')) {
55
- defaultStepOptions = [];
56
- } else {
57
- defaultStepOptions = defaultStepOptions.filter((_, i) => !field.remove.includes(i));
58
- }
59
- }
60
-
61
- if (field.fieldType === 'radio') {
62
- if (!field.errorMessage) {
63
- field.errorMessage = 'Professionals need this info to generate a quote.';
64
- }
65
-
66
- if (field.options && Array.isArray(field.options) && field.options.length) {
67
- field.options.forEach((option) => {
68
- if (typeof option.update === 'number') {
69
- if (option.attributes && option.attributes.checked === false) {
70
- delete option.attributes.checked;
71
- delete defaultStepOptions[option.update].attributes.checked;
72
- }
73
- merge(defaultStepOptions[option.update], option);
74
- } else {
75
- if (typeof option.insertAt === 'number') {
76
- defaultStepOptions.splice(option.insertAt, 0, option);
77
- } else {
78
- defaultStepOptions.push(option);
79
- }
80
- }
81
- });
82
- }
83
- field.options = defaultStepOptions;
84
- } else {
85
- if (field && Array.isArray(field) && field.length) {
86
- if (typeof field.update === 'number') {
87
- merge(defaultStepFields[field.update], field);
88
- } else {
89
- if (typeof field.insertAt === 'number') {
90
- defaultStepFields.splice(field.insertAt, 0, field);
91
- } else {
92
- defaultStepFields.push(field);
93
- }
94
- }
95
- }
96
-
97
- field = defaultStepFields;
98
- }
99
- });
100
-
101
- // extra question block
102
- if (item.stepContent.extraQuestionBlock) {
103
- if (!item.stepContent.extraQuestionBlock.fields) {
104
- item.stepContent.extraQuestionBlock.fields = [];
105
- }
106
-
107
- const defaultExtraQuestionFields = steps[stepName].extraQuestionBlock.fields;
108
- let defaultExtraQuestionOptions = [];
109
- let defaultExtraQuestionLegend = {};
110
- defaultExtraQuestionFields.forEach((defaultExtraQuestionField) => {
111
- defaultExtraQuestionOptions = defaultExtraQuestionField.options;
112
- defaultExtraQuestionLegend = defaultExtraQuestionField.legend;
113
- });
114
- item.stepContent.extraQuestionBlock.fields.forEach((field) => {
115
-
116
- if (field.legend) {
117
- field.legend = merge(defaultExtraQuestionLegend, field.legend);
118
- } else {
119
- field.legend = defaultExtraQuestionLegend;
120
- }
121
-
122
- if (field && field.remove) {
123
- if (field.remove.includes('all')) {
124
- defaultExtraQuestionOptions = [];
125
- } else {
126
- defaultExtraQuestionOptions = defaultExtraQuestionOptions.filter((_, i) => !field.remove.includes(i));
127
- }
128
- }
129
-
130
- if (field.fieldType === 'radio') {
131
- if (!field.errorMessage) {
132
- field.errorMessage = 'Professionals need this info to generate a quote.';
133
- }
134
-
135
- if (field.options && Array.isArray(field.options) && field.options.length) {
136
- field.options.forEach((option, optionIndex) => {
137
- if (typeof option.update === 'number') {
138
- if (option.attributes && option.attributes.checked === false) {
139
- delete option.attributes.checked;
140
- delete defaultStepOptions[option.update].attributes.checked;
141
- }
142
- merge(defaultExtraQuestionOptions[option.update], option);
143
- } else {
144
- if (typeof option.insertAt === 'number') {
145
- defaultExtraQuestionOptions.splice(option.insertAt, 0, option);
146
- } else {
147
- defaultExtraQuestionOptions.push(option);
148
- }
149
- }
150
- });
151
- }
152
- field.options = defaultExtraQuestionOptions;
153
- } else {
154
- if (field && Array.isArray(field) && field.length) {
155
- if (typeof field.update === 'number') {
156
- merge(defaultExtraQuestionFields[field.update], field);
157
- } else {
158
- if (typeof field.insertAt === 'number') {
159
- defaultExtraQuestionFields.splice(field.insertAt, 0, field);
160
- } else {
161
- defaultExtraQuestionFields.push(field);
162
- }
163
- }
164
- }
165
- field = defaultExtraQuestionFields;
166
- }
167
- });
168
- }
169
- }
170
- });
171
- }
172
-
173
6
  export default async function(config) {
174
7
  if (config.useStepsConfig) {
175
8
  console.log('Starting get-default-trade-questions...');
@@ -202,7 +35,149 @@ export default async function(config) {
202
35
  steps.OwnHome = commonQuestions.OwnHome;
203
36
  steps.BuyTimeframe = commonQuestions.BuyTimeframe;
204
37
 
205
- applyDefaultTradeConfigOnSteps(config, steps);
38
+ config.steps.items.forEach((item) => {
39
+ const stepName = item.attributes.data['step-name'];
40
+ if (steps[stepName]) {
41
+ if (!item.stepContent) {
42
+ item.stepContent = {};
43
+ }
44
+
45
+ if (!item.stepContent.fields) {
46
+ item.stepContent.fields = [];
47
+ }
48
+ const defaultStepFields = steps[stepName].fields;
49
+ let defaultStepOptions = [];
50
+ let defaultQuestionLegend = {};
51
+ defaultStepFields.forEach((defaultField) => {
52
+ defaultStepOptions = defaultField.options;
53
+ defaultQuestionLegend = defaultField.legend;
54
+ });
55
+
56
+ item.stepContent.fields.forEach((field) => {
57
+ if (field.legend) {
58
+ field.legend = merge(defaultQuestionLegend, field.legend);
59
+ } else {
60
+ field.legend = defaultQuestionLegend;
61
+ }
62
+
63
+ if (field && field.remove) {
64
+ if (field.remove.includes('all')) {
65
+ defaultStepOptions = [];
66
+ } else {
67
+ defaultStepOptions = defaultStepOptions.filter((_, i) => !field.remove.includes(i));
68
+ }
69
+ }
70
+
71
+ if (field.fieldType === 'radio') {
72
+ if (!field.errorMessage) {
73
+ field.errorMessage = 'Professionals need this info to generate a quote.';
74
+ }
75
+
76
+ if (field.options && Array.isArray(field.options) && field.options.length) {
77
+ field.options.forEach((option) => {
78
+ if (typeof option.update === 'number') {
79
+ if (option.attributes && option.attributes.checked === false) {
80
+ delete option.attributes.checked;
81
+ delete defaultStepOptions[option.update].attributes.checked;
82
+ }
83
+ merge(defaultStepOptions[option.update], option);
84
+ } else {
85
+ if (typeof option.insertAt === 'number') {
86
+ defaultStepOptions.splice(option.insertAt, 0, option);
87
+ } else {
88
+ defaultStepOptions.push(option);
89
+ }
90
+ }
91
+ });
92
+ }
93
+ field.options = defaultStepOptions;
94
+ } else {
95
+ if (field && Array.isArray(field) && field.length) {
96
+ if (typeof field.update === 'number') {
97
+ merge(defaultStepFields[field.update], field);
98
+ } else {
99
+ if (typeof field.insertAt === 'number') {
100
+ defaultStepFields.splice(field.insertAt, 0, field);
101
+ } else {
102
+ defaultStepFields.push(field);
103
+ }
104
+ }
105
+ }
106
+
107
+ field = defaultStepFields;
108
+ }
109
+ });
110
+
111
+ // extra question block
112
+ if (item.stepContent.extraQuestionBlock) {
113
+ if (!item.stepContent.extraQuestionBlock.fields) {
114
+ item.stepContent.extraQuestionBlock.fields = [];
115
+ }
116
+
117
+ const defaultExtraQuestionFields = steps[stepName].extraQuestionBlock.fields;
118
+ let defaultExtraQuestionOptions = [];
119
+ let defaultExtraQuestionLegend = {};
120
+ defaultExtraQuestionFields.forEach((defaultExtraQuestionField) => {
121
+ defaultExtraQuestionOptions = defaultExtraQuestionField.options;
122
+ defaultExtraQuestionLegend = defaultExtraQuestionField.legend;
123
+ });
124
+ item.stepContent.extraQuestionBlock.fields.forEach((field) => {
125
+
126
+ if (field.legend) {
127
+ field.legend = merge(defaultExtraQuestionLegend, field.legend);
128
+ } else {
129
+ field.legend = defaultExtraQuestionLegend;
130
+ }
131
+
132
+ if (field && field.remove) {
133
+ if (field.remove.includes('all')) {
134
+ defaultExtraQuestionOptions = [];
135
+ } else {
136
+ defaultExtraQuestionOptions = defaultExtraQuestionOptions.filter((_, i) => !field.remove.includes(i));
137
+ }
138
+ }
139
+
140
+ if (field.fieldType === 'radio') {
141
+ if (!field.errorMessage) {
142
+ field.errorMessage = 'Professionals need this info to generate a quote.';
143
+ }
144
+
145
+ if (field.options && Array.isArray(field.options) && field.options.length) {
146
+ field.options.forEach((option, optionIndex) => {
147
+ if (typeof option.update === 'number') {
148
+ if (option.attributes && option.attributes.checked === false) {
149
+ delete option.attributes.checked;
150
+ delete defaultStepOptions[option.update].attributes.checked;
151
+ }
152
+ merge(defaultExtraQuestionOptions[option.update], option);
153
+ } else {
154
+ if (typeof option.insertAt === 'number') {
155
+ defaultExtraQuestionOptions.splice(option.insertAt, 0, option);
156
+ } else {
157
+ defaultExtraQuestionOptions.push(option);
158
+ }
159
+ }
160
+ });
161
+ }
162
+ field.options = defaultExtraQuestionOptions;
163
+ } else {
164
+ if (field && Array.isArray(field) && field.length) {
165
+ if (typeof field.update === 'number') {
166
+ merge(defaultExtraQuestionFields[field.update], field);
167
+ } else {
168
+ if (typeof field.insertAt === 'number') {
169
+ defaultExtraQuestionFields.splice(field.insertAt, 0, field);
170
+ } else {
171
+ defaultExtraQuestionFields.push(field);
172
+ }
173
+ }
174
+ }
175
+ field = defaultExtraQuestionFields;
176
+ }
177
+ });
178
+ }
179
+ }
180
+ });
206
181
  resolve();
207
182
  })
208
183
  .catch(error => {
@@ -15,26 +15,7 @@ responseInterceptor(axiosInstance);
15
15
  responseInterceptor(tcpaAxiosInstance);
16
16
  responseInterceptor(consentCaptureAxiosInstance);
17
17
 
18
- async function applyDefaultConfigOnSteps(defaultConfig, data, parentConfig) {
19
- if (!data || typeof data !== 'object') return;
20
-
21
- // If "steps" is an object, merge its config
22
- if (data.steps && typeof data.steps === 'object') {
23
- data.steps = await mergeDefaultFormFieldConfig(defaultConfig, data, parentConfig);
24
- }
25
-
26
- // Recursively go through all object properties
27
- for (const key in data) {
28
- if (data.hasOwnProperty(key)) {
29
- const value = data[key];
30
- if (typeof value === 'object' && value !== null) {
31
- await applyDefaultConfigOnSteps(defaultConfig, value, parentConfig);
32
- }
33
- }
34
- }
35
- }
36
-
37
- function mergeDefaultFormFieldConfig(defaultConfig, config, parentConfig) {
18
+ function mergeDefaultFormFieldConfig(defaultConfig, config) {
38
19
  const { steps } = config;
39
20
 
40
21
  if (!steps.items) {
@@ -42,7 +23,7 @@ function mergeDefaultFormFieldConfig(defaultConfig, config, parentConfig) {
42
23
  return steps;
43
24
  }
44
25
 
45
- if (parentConfig.useAccessibleConfig) {
26
+ if (config.useAccessibleConfig) {
46
27
  steps.items.forEach(item => {
47
28
  if (item.stepContent.fields) {
48
29
  item.stepContent.fields = item.stepContent.fields.map(field => {
@@ -79,7 +60,9 @@ const getDefaultFormFieldConfig = async (config, folder = 'accessible-components
79
60
  throw new Error(`${resp.status}: Error while fetching ${folder}/defaultFormFieldConfig.json`);
80
61
  }
81
62
  const defaultConfig = resp.data;
82
- applyDefaultConfigOnSteps(defaultConfig, config, config);
63
+ if (config.steps) {
64
+ config.steps = await mergeDefaultFormFieldConfig(defaultConfig, config);
65
+ }
83
66
  resolve();
84
67
  }).catch(error => {
85
68
  console.error(error);