mod-build 4.0.94-beta.5 → 4.0.94
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 +1 -1
- package/package.json +1 -1
- package/src/scripts/globals.js +0 -1
- package/tasks/serve.js +0 -4
- package/tasks/templates.js +15 -8
- package/tasks/grab-default-quad-link-values.js +0 -137
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/scripts/globals.js
CHANGED
|
@@ -4,7 +4,6 @@ import { showUtilityProviders } from './default/show-utility-providers.js';
|
|
|
4
4
|
|
|
5
5
|
function globalFunctions(config) {
|
|
6
6
|
window.gtm_container_ID = config.gtm_container_ID;
|
|
7
|
-
window.defaultQuadlinkData = config.defaultQuadlinkData;
|
|
8
7
|
const { domain, pathSubdirectory } = config;
|
|
9
8
|
if (domain) {
|
|
10
9
|
if (domain.includes('/')) {
|
package/tasks/serve.js
CHANGED
|
@@ -5,7 +5,6 @@ import grabSharedComponents from './grab-shared-components.js';
|
|
|
5
5
|
import grabSharedScripts from './grab-shared-scripts.js';
|
|
6
6
|
import grabCdn from './grab-cdn.js';
|
|
7
7
|
import grabB2BData from './grab-b2b-data.js';
|
|
8
|
-
import grabDefaultQuadLinkValues from './grab-default-quad-link-values.js';
|
|
9
8
|
import getDefaultTradeQuestions from './get-default-trade-questions.js';
|
|
10
9
|
import grabFormHelpers from './grab-form-helpers.js';
|
|
11
10
|
import grabJSDoc from './grab-jsdoc.js';
|
|
@@ -18,10 +17,8 @@ export async function startModBuild(config) {
|
|
|
18
17
|
createStylelintFile();
|
|
19
18
|
await grabGlobalFonts(config);
|
|
20
19
|
await grabB2BData(config);
|
|
21
|
-
await grabDefaultQuadLinkValues(config);
|
|
22
20
|
await grabCdn(config);
|
|
23
21
|
await getDefaultTradeQuestions(config);
|
|
24
|
-
console.log(config.defaultQuadlinkData);
|
|
25
22
|
await Promise.all([
|
|
26
23
|
grabSharedComponents(config),
|
|
27
24
|
grabFormHelpers(config),
|
|
@@ -31,5 +28,4 @@ export async function startModBuild(config) {
|
|
|
31
28
|
await grabSharedScripts(config);
|
|
32
29
|
});
|
|
33
30
|
await updateConfig(config);
|
|
34
|
-
|
|
35
31
|
}
|
package/tasks/templates.js
CHANGED
|
@@ -202,23 +202,30 @@ const getConsentCaptureLanguage = async function(config, tempConfig) {
|
|
|
202
202
|
let consentCaptureObject = await resp.json(),
|
|
203
203
|
service = config.service ? config.service.toLowerCase().replace('_', ' ') : config.primary_trade.toLowerCase().replace('_', ' ');
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
throw new Error(`${brandedSiteIdentifiersResp.status}: Error while fetching branded-site-identifiers.json`);
|
|
208
|
-
}
|
|
205
|
+
if (config.isBranded) {
|
|
206
|
+
let brandedSiteIdentifiersData = {};
|
|
209
207
|
|
|
210
|
-
|
|
208
|
+
if (!config.brandedSiteIdentifiers?.publicKey) {
|
|
209
|
+
const brandedSiteIdentifiersResp = await fetch(`https://${defaultSettings.nodeEnv}/quote/resources/mod-site/data/branded-site-identifiers.json`);
|
|
210
|
+
if (brandedSiteIdentifiersResp.status !== 200) {
|
|
211
|
+
throw new Error(`${brandedSiteIdentifiersResp.status}: Error while fetching branded-site-identifiers.json`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
brandedSiteIdentifiersData = await brandedSiteIdentifiersResp.json();
|
|
215
|
+
}
|
|
211
216
|
|
|
212
|
-
if (config.isBranded) {
|
|
213
217
|
const websiteName = config.website_name.toLowerCase(),
|
|
214
218
|
companyName = config.company_name,
|
|
215
219
|
apiDomain = 'https://form-service-hs.qnst.com/';
|
|
216
220
|
|
|
217
221
|
let apiUrl = '';
|
|
222
|
+
let publicKey = config.brandedSiteIdentifiers?.publicKey || null;
|
|
218
223
|
|
|
219
|
-
if (brandedSiteIdentifiersData[websiteName] && (brandedSiteIdentifiersData[websiteName].publicKey || brandedSiteIdentifiersData[websiteName][companyName] && brandedSiteIdentifiersData[websiteName][companyName].publicKey)) {
|
|
220
|
-
|
|
224
|
+
if (!publicKey && brandedSiteIdentifiersData[websiteName] && (brandedSiteIdentifiersData[websiteName].publicKey || brandedSiteIdentifiersData[websiteName][companyName] && brandedSiteIdentifiersData[websiteName][companyName].publicKey)) {
|
|
225
|
+
publicKey = brandedSiteIdentifiersData[websiteName][companyName] ? brandedSiteIdentifiersData[websiteName][companyName].publicKey : brandedSiteIdentifiersData[websiteName].publicKey;
|
|
226
|
+
}
|
|
221
227
|
|
|
228
|
+
if (publicKey) {
|
|
222
229
|
apiUrl = `${apiDomain}utils/vendor-display-name?publicKey=${encodeURIComponent(publicKey)}`;
|
|
223
230
|
const getBrandedDisplayName = await fetch(apiUrl);
|
|
224
231
|
if (getBrandedDisplayName.status !== 200) {
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { defaultSettings } from '../src/data/config.js';
|
|
2
|
-
import { createRetryFetch } from '../src/scripts/retry-fetch.js';
|
|
3
|
-
|
|
4
|
-
const fetchWithRetry = createRetryFetch();
|
|
5
|
-
const QUAD_LINK_VALUES_PATH = '/quote/resources/mod-site/data/default-quad-link-values.json';
|
|
6
|
-
|
|
7
|
-
const MULTI_SERVICE_DOMAINS = [
|
|
8
|
-
'quotes.improvementcenter.com',
|
|
9
|
-
'callrestorationpro.com',
|
|
10
|
-
'modernize.com',
|
|
11
|
-
'powerhomedeals.com'
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
function getDomainLookupKey(config) {
|
|
15
|
-
const domain = config.website_name || config.domain;
|
|
16
|
-
return domain ? domain.toLowerCase() : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function normalizePage(config) {
|
|
20
|
-
const name = config.website_name || config.domain || '';
|
|
21
|
-
return name.replace(/(qa\.?|staging\.?|www\.?)/gi, '').toLowerCase();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getPathSubdirectory(config) {
|
|
25
|
-
return config.pathSubdirectory || config.siteData?.pathSubdirectory || '';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function buildLandingPageWithNoQuery(page, pathSubdirectory) {
|
|
29
|
-
const pathPart = pathSubdirectory.replace(/^\/+|\/+$/g, '');
|
|
30
|
-
return pathPart ? `${page}/${pathPart}` : page;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isQuadLinkLeaf(value) {
|
|
34
|
-
return value && typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'c');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isMultiServiceDomain(page) {
|
|
38
|
-
return MULTI_SERVICE_DOMAINS.some((domain) => page.indexOf(domain) > -1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getLastPathSegment(pathSubdirectory) {
|
|
42
|
-
const segment = pathSubdirectory.replace(/^\/+|\/+$/g, '').split('/').filter(Boolean).pop();
|
|
43
|
-
return segment ? segment.replace(/-/g, '') : '';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function resolveDefaultQuadlinkData(quadLinkValuesByDomain, config) {
|
|
47
|
-
const page = normalizePage(config);
|
|
48
|
-
const domainData = quadLinkValuesByDomain[page];
|
|
49
|
-
|
|
50
|
-
if (!domainData) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (isQuadLinkLeaf(domainData)) {
|
|
55
|
-
return domainData;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const pathSubdirectory = getPathSubdirectory(config);
|
|
59
|
-
const landingPageWithNoQuery = buildLandingPageWithNoQuery(page, pathSubdirectory);
|
|
60
|
-
|
|
61
|
-
if (page.includes('bestcompany')) {
|
|
62
|
-
const pathSegments = landingPageWithNoQuery.split('/');
|
|
63
|
-
let service = pathSegments[2];
|
|
64
|
-
|
|
65
|
-
if (!service) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
service = service.replace(/-/g, '');
|
|
70
|
-
return domainData[service];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (isMultiServiceDomain(page)) {
|
|
74
|
-
if (landingPageWithNoQuery.indexOf('cost-calculator') > -1) {
|
|
75
|
-
const pathSegments = landingPageWithNoQuery.split('/');
|
|
76
|
-
let service = pathSegments[2]?.replace(/-/g, '') || 'default';
|
|
77
|
-
const costCalculator = domainData['cost-calculator'];
|
|
78
|
-
|
|
79
|
-
if (!costCalculator) {
|
|
80
|
-
return domainData.default;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
service = typeof costCalculator[service] !== 'undefined' ? service : 'default';
|
|
84
|
-
return costCalculator[service];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let service = landingPageWithNoQuery.replace(/\/$/g, '').replace(/^(?:[^/]*\/)+/g, '');
|
|
88
|
-
|
|
89
|
-
if (typeof domainData[service] === 'undefined') {
|
|
90
|
-
const pathService = getLastPathSegment(pathSubdirectory);
|
|
91
|
-
service = typeof domainData[pathService] !== 'undefined' ? pathService : 'default';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return domainData[service];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return domainData;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default async function grabDefaultQuadLinkValues(config) {
|
|
101
|
-
const { nodeEnv } = defaultSettings;
|
|
102
|
-
|
|
103
|
-
if (!nodeEnv) {
|
|
104
|
-
throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const lookupKey = getDomainLookupKey(config);
|
|
108
|
-
if (!lookupKey) {
|
|
109
|
-
console.warn('grab-default-quad-link-values: config.domain or config.website_name is required');
|
|
110
|
-
config.defaultQuadlinkData = {};
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const cachebuster = Math.round(Date.now() / 1000);
|
|
115
|
-
const url = `https://${nodeEnv}${QUAD_LINK_VALUES_PATH}?cb=${cachebuster}`;
|
|
116
|
-
|
|
117
|
-
console.log(`Fetching default quad link values from ${url}`);
|
|
118
|
-
|
|
119
|
-
const resp = await fetchWithRetry(url);
|
|
120
|
-
if (resp.status !== 200) {
|
|
121
|
-
throw new Error(`${resp.status}: Error while fetching ${url}`);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const quadLinkValuesByDomain = await resp.json();
|
|
125
|
-
const defaultQuadlinkData = resolveDefaultQuadlinkData(quadLinkValuesByDomain, config);
|
|
126
|
-
|
|
127
|
-
if (!defaultQuadlinkData) {
|
|
128
|
-
console.warn(`grab-default-quad-link-values: no quad link data resolved for "${lookupKey}" (pathSubdirectory: "${config.pathSubdirectory || ''}")`);
|
|
129
|
-
config.defaultQuadlinkData = {};
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
config.defaultQuadlinkData = defaultQuadlinkData;
|
|
134
|
-
console.log(defaultQuadlinkData);
|
|
135
|
-
console.log(config.defaultQuadlinkData);
|
|
136
|
-
console.log(`grab-default-quad-link-values: resolved quad link data for "${lookupKey}" (pathSubdirectory: "${config.pathSubdirectory || ''}")`);
|
|
137
|
-
}
|