|
| 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