-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.js
42 lines (32 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* This module sets default values and validates ortb2 first part data
* @module modules/firstPartyData
*/
import { config } from '../../src/config.js';
import { module, getHook } from '../../src/hook.js';
let submodules = [];
export function registerSubmodules(submodule) {
submodules.push(submodule);
}
export function reset() {
submodules.length = 0;
}
export function processFpd({global = {}, bidder = {}} = {}) {
let modConf = config.getConfig('firstPartyData') || {};
submodules.sort((a, b) => {
return ((a.queue || 1) - (b.queue || 1));
}).forEach(submodule => {
({global = global, bidder = bidder} = submodule.processFpd(modConf, {global, bidder}));
});
return {global, bidder};
}
export function startAuctionHook(fn, req) {
Object.assign(req.ortb2Fragments, processFpd(req.ortb2Fragments));
fn.call(this, req);
}
function setupHook() {
getHook('startAuction').before(startAuctionHook, 10);
}
module('firstPartyData', registerSubmodules);
// Runs setupHook on initial load
setupHook();