Skip to content

Commit 5421bb4

Browse files
debugging module: Added type definitions (#14911)
* Added type definitions for the debugging module * Make intercept property optional * Allow null to drop a bid
1 parent 404c353 commit 5421bb4

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

modules/debugging/debugging.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import { makebidInterceptor } from './bidInterceptor.js';
22
import { makePbsInterceptor } from './pbsInterceptor.js';
33
import { addHooks, removeHooks } from './legacy.js';
44

5+
/**
6+
* @typedef {import('./debuggingModule.d.ts').DebugModuleConfiguration} DebugModuleConfiguration
7+
*/
8+
59
const interceptorHooks = [];
610
let bidInterceptor;
711
let enabled = false;
812

13+
/**
14+
* @param {DebugModuleConfiguration} debugConfig Configuration of the debug module
15+
*/
916
function enableDebugging(debugConfig, { fromSession = false, config, hook, logger }) {
1017
config.setConfig({ debug: true });
1118
bidInterceptor.updateConfig(debugConfig);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type { BidRequest } from "../../src/adapterManager";
2+
import type { Bid } from "../../src/bidfactory";
3+
import type { BidderCode } from "../../src/types/common";
4+
5+
export type DebugModuleConfiguration = {
6+
enabled?: boolean;
7+
/**
8+
* Rules are evaluated on each bid in the order they are provided: the first one that has a matching when definition takes the bid out of the normal auction flow and replaces it according to its then definition.
9+
*/
10+
intercept?: InterceptRule[]
11+
}
12+
13+
export type InterceptRule = {
14+
/**
15+
* Decides which bids should be intercepted by this rule
16+
*/
17+
when: MatchRule;
18+
/**
19+
* Decides the contents of the bids that are intercepted by this rule
20+
*/
21+
then?: ReplaceRule;
22+
options?: RuleOptions;
23+
}
24+
25+
type MatchRule =
26+
/**
27+
* The match rule can be provided as a function that takes the bid request as its only argument and returns `true` if the bid should be intercepted, `false` otherwise.
28+
*/
29+
| ((bidRequest: BidRequest<BidderCode | null>) => boolean)
30+
/**
31+
* Alternatively, the rule can be expressed as an `object`, and it matches if for each key-value pair:
32+
* - `bidRequest[key] === value`, or
33+
* - `value` is a function and `value(bidRequest[key])` is `true`, or
34+
* - `value` is a regular expression and it matches `bidRequest[key]`.
35+
*/
36+
| {
37+
[K in keyof BidRequest<BidderCode | null>]?: BidRequest<BidderCode | null>[K] | ((value: BidRequest<BidderCode | null>[K]) => boolean) | RegExp
38+
};
39+
40+
type ReplaceRule =
41+
/**
42+
* The replace rule can be provided as a function that takes the bid request as its only argument and returns an object with the desired response properties.
43+
* The function can return `null` to indicate that there is no bid.
44+
*/
45+
| ((bidRequest: BidRequest<BidderCode | null>) => Partial<Bid> | null)
46+
/**
47+
* Alternatively, the rule can be expressed as an `object`, and its key-value pairs will appear in the response as follows:
48+
* - if `value` is a function, then `bidResponse[key]` will be set to `value(bidRequest)`;
49+
* - otherwise, `bidResponse[key]` will be set to `value`.
50+
*/
51+
| {
52+
[K in keyof Bid]?: Bid[K] | ((request: BidRequest<BidderCode | null>) => Bid[K]);
53+
}
54+
/**
55+
* Indicates no bid.
56+
*/
57+
| null;
58+
59+
type RuleOptions = {
60+
/**
61+
* Delay (in milliseconds) before intercepted bids are injected into the auction.
62+
* Can be used to simulate network latency.
63+
*
64+
* Defaults to zero.
65+
*/
66+
delay?: number
67+
}
68+
69+
declare module '../../src/config' {
70+
interface Config {
71+
/**
72+
* This module allows to “intercept” bids and replace their contents with arbitrary data for the purposes of testing and development.
73+
*
74+
* Bids intercepted in this way are never seen by bid adapters or their backend SSPs, but they are nonetheless injected into the auction as if they originated from them.
75+
*/
76+
debugging?: DebugModuleConfiguration;
77+
}
78+
}
79+
80+
export {}

0 commit comments

Comments
 (0)