@highfivve/ad-tag 5.8.34 → 5.9.0

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.
@@ -0,0 +1,8 @@
1
+ export const resolveModuleConfig = (base, isLabelConditionMet) => {
2
+ const { overrides = [], ...defaultConfig } = base;
3
+ const matchedOverrideIndex = overrides.findIndex(isLabelConditionMet);
4
+ const match = overrides[matchedOverrideIndex];
5
+ return match
6
+ ? { config: match.config, matchedOverrideIndex, matchedCondition: match }
7
+ : { config: defaultConfig, matchedOverrideIndex: -1 };
8
+ };
package/lib/ads/moli.js CHANGED
@@ -9,6 +9,7 @@ import * as adUnitPath from './adUnitPath';
9
9
  import { extractTopPrivateDomainFromHostname } from '../util/extractTopPrivateDomainFromHostname';
10
10
  import { detectGeoFromBrowser } from '../util/detectGeoFromTimezone';
11
11
  import { createLabelConfigService } from './labelConfigService';
12
+ import { resolveModuleConfig } from './moduleConfigOverrides';
12
13
  import { allowRefreshAdSlot, allowRequestAds } from './spa';
13
14
  import { QueryParameters } from 'ad-tag/util/queryParameters';
14
15
  import { BrowserStorageKeys } from 'ad-tag/util/browserStorageKeys';
@@ -244,21 +245,31 @@ export const createMoliTag = (window) => {
244
245
  getLogger(state.runtimeConfig, window).debug('MoliGlobal', 'configure modules', state.config.modules ?? {});
245
246
  const labelService = createLabelConfigService(state.config?.labelSizeConfig || [], state.runtimeConfig.labels, window);
246
247
  modules
247
- .filter(module => {
248
+ .map(module => {
248
249
  const moduleName = module.name;
249
- const moduleConfig = state.config?.modules?.[moduleName];
250
- if (moduleConfig?.labelCondition) {
251
- const areLabelConditionsMet = labelService.isLabelConditionMet(moduleConfig.labelCondition);
252
- if (!areLabelConditionsMet) {
253
- getLogger(state.runtimeConfig, window).debug('MoliGlobal', `skipping configuration of ${module.moduleType} module ${moduleName} due to label condition not met.`);
254
- return false;
255
- }
250
+ const base = state.config?.modules?.[moduleName];
251
+ if (!base) {
252
+ return null;
253
+ }
254
+ const { config: effectiveConfig, matchedOverrideIndex, matchedCondition } = resolveModuleConfig(base, labelService.isLabelConditionMet);
255
+ if (matchedOverrideIndex >= 0) {
256
+ getLogger(state.runtimeConfig, window).debug('MoliGlobal', `module ${moduleName}: applying config override #${matchedOverrideIndex}`, matchedCondition);
256
257
  }
257
- return true;
258
+ if (effectiveConfig.labelCondition &&
259
+ !labelService.isLabelConditionMet(effectiveConfig.labelCondition)) {
260
+ getLogger(state.runtimeConfig, window).debug('MoliGlobal', `skipping configuration of ${module.moduleType} module ${moduleName} due to label condition not met.`);
261
+ return null;
262
+ }
263
+ const resolvedModulesConfig = {
264
+ ...state.config?.modules,
265
+ [moduleName]: effectiveConfig
266
+ };
267
+ return { module, resolvedModulesConfig };
258
268
  })
259
- .forEach(module => {
269
+ .filter((entry) => entry !== null)
270
+ .forEach(({ module, resolvedModulesConfig }) => {
260
271
  try {
261
- module.configure__(state.config?.modules ?? {});
272
+ module.configure__(resolvedModulesConfig);
262
273
  getLogger(state.runtimeConfig, window).debug('MoliGlobal', `configure ${module.moduleType} module ${module.name}`, module.config__());
263
274
  state.runtimeConfig.adPipelineConfig.initSteps.push(...module.initSteps__());
264
275
  state.runtimeConfig.adPipelineConfig.configureSteps.push(...module.configureSteps__());
@@ -1,3 +1,3 @@
1
1
  export const packageJson = {
2
- version: '5.8.34'
2
+ version: '5.9.0'
3
3
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highfivve/ad-tag",
3
- "version": "5.8.34",
3
+ "version": "5.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "An ad tag implementation called moli",
6
6
  "main": "./lib/index.js",