mod-build 4.0.36-beta.1 → 4.0.37-beta.1

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
@@ -1,3 +1,8 @@
1
+ ## 4.0.37
2
+
3
+ - Updated `getConsentCaptureLanguage` to include the `profileId` version of the display name API.
4
+ *Currently being used for Best Company branded form pages.*
5
+
1
6
  ## 4.0.36
2
7
 
3
8
  - Included an option for `service` to be appended to the `brandedIncludeServiceConsentCapture` for consent capture.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.36-beta.1",
3
+ "version": "4.0.37-beta.1",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -148,6 +148,41 @@ const fetchTcpaFromSitegenie = async (config, tempConfig, pathSubdirectory) => {
148
148
  });
149
149
  };
150
150
 
151
+ function findVendorKey(config) {
152
+ if (Array.isArray(config)) {
153
+ for (let item of config) {
154
+ const result = findVendorKey(item);
155
+ if (result) {
156
+ return result;
157
+ }
158
+ }
159
+ } else if (typeof config === 'object' && config !== null) {
160
+ if (config.name === 'Match' && config.value !== undefined) {
161
+ return config.value;
162
+ }
163
+ for (let key in config) {
164
+ const result = findVendorKey(config[key]);
165
+ if (result) {
166
+ return result;
167
+ }
168
+ }
169
+ }
170
+ return null;
171
+ }
172
+
173
+ async function embedBrandedDisplayName(apiUrl, consentCaptureObject, key, service) {
174
+ let resp = '';
175
+ const getBrandedDisplayName = await axios.get(apiUrl);
176
+ if (getBrandedDisplayName.status !== 200) {
177
+ throw new Error(`${resp.status}: Error while getting branded display name from HS Form Service`);
178
+ }
179
+
180
+ const brandedDisplayName = getBrandedDisplayName.data.data[key];
181
+ consentCaptureObject.brandedConsentCapture.tcpaStart = consentCaptureObject.brandedConsentCapture.tcpaStart.replace(/<span data-branded-consent><\/span>/g, `<span data-branded-consent>${brandedDisplayName}</span>`);
182
+ consentCaptureObject.brandedIncludeExclusivelyConsentCapture.tcpaStart = consentCaptureObject.brandedIncludeExclusivelyConsentCapture.tcpaStart.replace(/<span data-branded-consent><\/span>/g, `<span data-branded-consent>${brandedDisplayName}</span>`);
183
+ consentCaptureObject.brandedIncludeServiceConsentCapture.tcpaStart = consentCaptureObject.brandedIncludeServiceConsentCapture.tcpaStart.replace(/<span data-branded-consent><\/span>/g, `<span data-branded-consent>${brandedDisplayName}</span>`).replace(/<span data-service><\/span>/g, `<span data-service>${service}</span>`);
184
+ }
185
+
151
186
  const getConsentCaptureLanguage = async function(config, tempConfig) {
152
187
  await new Promise((resolve) => {
153
188
  consentCaptureAxiosInstance.get(`https://${defaultSettings.nodeEnv}/quote/resources/mod-site/consent-capture/tcpa.json`)
@@ -156,8 +191,7 @@ const getConsentCaptureLanguage = async function(config, tempConfig) {
156
191
  throw new Error(`${resp.status}: Error while fetching tcpa.json`);
157
192
  }
158
193
 
159
- let brandedDisplayName = '',
160
- consentCaptureObject = resp.data,
194
+ let consentCaptureObject = resp.data,
161
195
  service = config.service ? config.service.toLowerCase().replace('_', ' ') : config.primary_trade.toLowerCase().replace('_', ' ');
162
196
 
163
197
  const brandedSiteIdentifiers = await axios.get(`https://${defaultSettings.nodeEnv}/quote/resources/mod-site/data/branded-site-identifiers.json`);
@@ -166,20 +200,37 @@ const getConsentCaptureLanguage = async function(config, tempConfig) {
166
200
  }
167
201
 
168
202
  if (config.isBranded) {
169
- const websiteName = config.website_name;
203
+ const websiteName = config.website_name,
204
+ apiDomain = 'https://form-service-hs.qnst.com/';
205
+
206
+ let apiUrl = '';
207
+
170
208
  if (brandedSiteIdentifiers.data[websiteName] && brandedSiteIdentifiers.data[websiteName].vendorPublicIdentifier) {
171
- const vendorPublicIdentifier = brandedSiteIdentifiers.data[websiteName].vendorPublicIdentifier,
172
- apiDomain = 'https://form-service-hs.qnst.com/',
173
- apiUrl = `${apiDomain}utils/vendor-display-name?vendorKeys=${vendorPublicIdentifier}`;
209
+ const vendorPublicIdentifier = brandedSiteIdentifiers.data[websiteName].vendorPublicIdentifier;
210
+
211
+ apiUrl = `${apiDomain}utils/vendor-display-name?vendorKeys=${vendorPublicIdentifier}`;
174
212
 
175
213
  const getBrandedDisplayName = await axios.get(apiUrl);
176
214
  if (getBrandedDisplayName.status !== 200) {
177
215
  throw new Error(`${resp.status}: Error while getting branded display name from HS Form Service`);
178
216
  }
179
217
 
180
- brandedDisplayName = getBrandedDisplayName.data.data[vendorPublicIdentifier];
181
- consentCaptureObject.brandedConsentCapture.tcpaStart = resp.data.brandedConsentCapture.tcpaStart.replace(/<span data-branded-consent><\/span>/g, `<span data-branded-consent>${brandedDisplayName}</span>`);
182
- consentCaptureObject.brandedIncludeServiceConsentCapture.tcpaStart = resp.data.brandedIncludeServiceConsentCapture.tcpaStart.replace(/<span data-branded-consent><\/span>/g, `<span data-branded-consent>${brandedDisplayName}</span>`).replace(/<span data-service><\/span>/g, `<span data-service>${service}</span>`);
218
+ await embedBrandedDisplayName(apiUrl, consentCaptureObject, vendorPublicIdentifier, service);
219
+ } else {
220
+ const vendorKey = findVendorKey(config),
221
+ profileApiDomain = 'https://api.modernize.com/',
222
+ profileApiUrl = `${profileApiDomain}v1/client-profiles/profiles?filters[matches][]=${vendorKey},QMP`;
223
+
224
+ if (vendorKey !== null) {
225
+ const getBrandedProfileId = await axios.get(profileApiUrl);
226
+ if (getBrandedProfileId.status !== 200) {
227
+ throw new Error(`${resp.status}: Error while getting branded display name from HS Form Service`);
228
+ }
229
+ const brandedProfileId = getBrandedProfileId.data.data[0].profileId;
230
+ apiUrl = `${apiDomain}utils/vendor-display-name?profileId=${brandedProfileId}`;
231
+
232
+ await embedBrandedDisplayName(apiUrl, consentCaptureObject, brandedProfileId, service);
233
+ }
183
234
  }
184
235
  }
185
236
 
@@ -284,4 +335,4 @@ export default async function(config) {
284
335
 
285
336
  fs.writeFileSync(`${defaultSettings.srcFolder}/${defaultSettings.tmpFolder}/config.json`, JSON.stringify(tempConfig, null, 2));
286
337
  }
287
- }
338
+ }