/
pbjsORTB.js
35 lines (31 loc) · 1.06 KB
/
pbjsORTB.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
export const PROCESSOR_TYPES = ['request', 'imp', 'bidResponse', 'response'];
export const PROCESSOR_DIALECTS = ['default', 'pbs'];
export const [REQUEST, IMP, BID_RESPONSE, RESPONSE] = PROCESSOR_TYPES;
export const [DEFAULT, PBS] = PROCESSOR_DIALECTS;
const types = new Set(PROCESSOR_TYPES);
export function processorRegistry() {
const processors = {};
return {
registerOrtbProcessor({type, name, fn, priority = 0, dialects = [DEFAULT]}) {
if (!types.has(type)) {
throw new Error(`ORTB processor type must be one of: ${PROCESSOR_TYPES.join(', ')}`)
}
dialects.forEach(dialect => {
if (!processors.hasOwnProperty(dialect)) {
processors[dialect] = {};
}
if (!processors[dialect].hasOwnProperty(type)) {
processors[dialect][type] = {};
}
processors[dialect][type][name] = {
priority,
fn
}
})
},
getProcessors(dialect) {
return processors[dialect] || {};
}
}
}
export const {registerOrtbProcessor, getProcessors} = processorRegistry();