mod-build 4.0.94-beta.2 → 4.0.94-beta.4
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/package.json
CHANGED
package/src/scripts/globals.js
CHANGED
|
@@ -4,9 +4,7 @@ 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
|
-
|
|
8
|
-
window.defaultQuadlinkData = config.defaultQuadlinkData;
|
|
9
|
-
}
|
|
7
|
+
window.defaultQuadlinkData = config.defaultQuadlinkData;
|
|
10
8
|
const { domain, pathSubdirectory } = config;
|
|
11
9
|
if (domain) {
|
|
12
10
|
if (domain.includes('/')) {
|
|
@@ -4,11 +4,99 @@ import { createRetryFetch } from '../src/scripts/retry-fetch.js';
|
|
|
4
4
|
const fetchWithRetry = createRetryFetch();
|
|
5
5
|
const QUAD_LINK_VALUES_PATH = '/quote/resources/mod-site/data/default-quad-link-values.json';
|
|
6
6
|
|
|
7
|
+
const MULTI_SERVICE_DOMAINS = [
|
|
8
|
+
'quotes.improvementcenter.com',
|
|
9
|
+
'callrestorationpro.com',
|
|
10
|
+
'modernize.com',
|
|
11
|
+
'powerhomedeals.com'
|
|
12
|
+
];
|
|
13
|
+
|
|
7
14
|
function getDomainLookupKey(config) {
|
|
8
15
|
const domain = config.website_name || config.domain;
|
|
9
16
|
return domain ? domain.toLowerCase() : null;
|
|
10
17
|
}
|
|
11
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
|
+
|
|
12
100
|
export default async function grabDefaultQuadLinkValues(config) {
|
|
13
101
|
const { nodeEnv } = defaultSettings;
|
|
14
102
|
|
|
@@ -34,14 +122,15 @@ export default async function grabDefaultQuadLinkValues(config) {
|
|
|
34
122
|
}
|
|
35
123
|
|
|
36
124
|
const quadLinkValuesByDomain = await resp.json();
|
|
37
|
-
const defaultQuadlinkData = quadLinkValuesByDomain
|
|
125
|
+
const defaultQuadlinkData = resolveDefaultQuadlinkData(quadLinkValuesByDomain, config);
|
|
38
126
|
|
|
39
127
|
if (!defaultQuadlinkData) {
|
|
40
|
-
console.warn(`grab-default-quad-link-values: no
|
|
128
|
+
console.warn(`grab-default-quad-link-values: no quad link data resolved for "${lookupKey}" (pathSubdirectory: "${config.pathSubdirectory || ''}")`);
|
|
41
129
|
config.defaultQuadlinkData = {};
|
|
42
130
|
return;
|
|
43
131
|
}
|
|
44
132
|
|
|
45
133
|
config.defaultQuadlinkData = defaultQuadlinkData;
|
|
46
|
-
console.log(
|
|
134
|
+
console.log(defaultQuadlinkData);
|
|
135
|
+
console.log(`grab-default-quad-link-values: resolved quad link data for "${lookupKey}" (pathSubdirectory: "${config.pathSubdirectory || ''}")`);
|
|
47
136
|
}
|