mod-build 4.0.93-beta.1 → 4.0.94-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,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.94
4
+
5
+ - Adding default quadlink data to the window object
6
+
3
7
  ## 4.0.93
4
8
 
5
9
  - Removing the conditional on when to download `recaptcha.html` and that should be available whenever we need it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.93-beta.1",
3
+ "version": "4.0.94-beta.1",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -4,6 +4,9 @@ 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
+ if (config.defaultQuadlinkData) {
8
+ window.defaultQuadlinkData = config.defaultQuadlinkData;
9
+ }
7
10
  const { domain, pathSubdirectory } = config;
8
11
  if (domain) {
9
12
  if (domain.includes('/')) {
@@ -0,0 +1,47 @@
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/src/data/default-quad-link-values.json';
6
+
7
+ function getDomainLookupKey(config) {
8
+ const domain = config.website_name || config.domain;
9
+ return domain ? domain.toLowerCase() : null;
10
+ }
11
+
12
+ export default async function grabDefaultQuadLinkValues(config) {
13
+ const { nodeEnv } = defaultSettings;
14
+
15
+ if (!nodeEnv) {
16
+ throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
17
+ }
18
+
19
+ const lookupKey = getDomainLookupKey(config);
20
+ if (!lookupKey) {
21
+ console.warn('grab-default-quad-link-values: config.domain or config.website_name is required');
22
+ config.defaultQuadlinkData = {};
23
+ return;
24
+ }
25
+
26
+ const cachebuster = Math.round(Date.now() / 1000);
27
+ const url = `https://${nodeEnv}${QUAD_LINK_VALUES_PATH}?cb=${cachebuster}`;
28
+
29
+ console.log(`Fetching default quad link values from ${url}`);
30
+
31
+ const resp = await fetchWithRetry(url);
32
+ if (resp.status !== 200) {
33
+ throw new Error(`${resp.status}: Error while fetching ${url}`);
34
+ }
35
+
36
+ const quadLinkValuesByDomain = await resp.json();
37
+ const defaultQuadlinkData = quadLinkValuesByDomain[lookupKey];
38
+
39
+ if (!defaultQuadlinkData) {
40
+ console.warn(`grab-default-quad-link-values: no entry found for domain "${lookupKey}"`);
41
+ config.defaultQuadlinkData = {};
42
+ return;
43
+ }
44
+
45
+ config.defaultQuadlinkData = defaultQuadlinkData;
46
+ console.log(`grab-default-quad-link-values: loaded data for "${lookupKey}"`);
47
+ }
package/tasks/serve.js CHANGED
@@ -5,6 +5,7 @@ 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';
8
9
  import getDefaultTradeQuestions from './get-default-trade-questions.js';
9
10
  import grabFormHelpers from './grab-form-helpers.js';
10
11
  import grabJSDoc from './grab-jsdoc.js';
@@ -17,6 +18,7 @@ export async function startModBuild(config) {
17
18
  createStylelintFile();
18
19
  await grabGlobalFonts(config);
19
20
  await grabB2BData(config);
21
+ await grabDefaultQuadLinkValues(config);
20
22
  await grabCdn(config);
21
23
  await getDefaultTradeQuestions(config);
22
24
  await Promise.all([
@@ -28,4 +30,5 @@ export async function startModBuild(config) {
28
30
  await grabSharedScripts(config);
29
31
  });
30
32
  await updateConfig(config);
33
+
31
34
  }