@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.
- package/lib/ads/moduleConfigOverrides.js +8 -0
- package/lib/ads/moli.js +22 -11
- package/lib/gen/packageJson.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
.
|
|
248
|
+
.map(module => {
|
|
248
249
|
const moduleName = module.name;
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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
|
-
.
|
|
269
|
+
.filter((entry) => entry !== null)
|
|
270
|
+
.forEach(({ module, resolvedModulesConfig }) => {
|
|
260
271
|
try {
|
|
261
|
-
module.configure__(
|
|
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__());
|
package/lib/gen/packageJson.js
CHANGED