• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / 16197995703

10 Jul 2025 02:32PM UTC coverage: 96.232% (+0.003%) from 96.229%
16197995703

push

github

web-flow
Linting: remove exception (#13518)

* bump coveralls

* remove exceptions

* results

* eslint fix

* Update package-lock.json

* Update package-lock.json

* Core: remove codex comments and unused lint rule (#13520)

---------

Co-authored-by: Demetrio Girardi <dgirardi@prebid.org>

39174 of 48116 branches covered (81.42%)

9842 of 9975 new or added lines in 861 files covered. (98.67%)

15 existing lines in 8 files now uncovered.

192483 of 200020 relevant lines covered (96.23%)

88.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.93
/modules/deepintentBidAdapter.js
1
import { generateUUID, deepSetValue, deepAccess, isArray, isFn, isPlainObject, logError, logWarn } from '../src/utils.js';
1✔
2
import { registerBidder } from '../src/adapters/bidderFactory.js';
3
import { BANNER, VIDEO } from '../src/mediaTypes.js';
4
import { COMMON_ORTB_VIDEO_PARAMS, formatResponse } from '../libraries/deepintentUtils/index.js';
5
const BIDDER_CODE = 'deepintent';
1✔
6
const GVL_ID = 541;
1✔
7
const BIDDER_ENDPOINT = 'https://prebid.deepintent.com/prebid';
1✔
8
const USER_SYNC_URL = 'https://cdn.deepintent.com/syncpixel.html';
1✔
9
const DI_M_V = '1.0.0';
1✔
10
export const ORTB_VIDEO_PARAMS = {
1✔
11
  ...COMMON_ORTB_VIDEO_PARAMS,
12
  'plcmt': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 5),
×
13
  'delivery': (value) => [1, 2, 3].indexOf(value) !== -1,
×
14
  'pos': (value) => [0, 1, 2, 3, 4, 5, 6, 7].indexOf(value) !== -1,
×
15
};
16
export const spec = {
1✔
17
  code: BIDDER_CODE,
18
  gvlid: GVL_ID,
19
  supportedMediaTypes: [BANNER, VIDEO],
20
  aliases: [],
21

22
  // tagId is mandatory param
23
  isBidRequestValid: bid => {
24
    let valid = false;
5✔
25
    if (bid && bid.params && bid.params.tagId) {
5✔
26
      if (typeof bid.params.tagId === 'string' || bid.params.tagId instanceof String) {
4✔
27
        if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) {
3✔
28
          if (bid.mediaTypes[VIDEO].hasOwnProperty('context')) {
2✔
29
            valid = true;
1✔
30
          }
31
        } else {
32
          valid = true;
1✔
33
        }
34
      }
35
    }
36
    return valid;
5✔
37
  },
38
  interpretResponse: function(bidResponse, bidRequest) {
39
    const responses = [];
4✔
40
    if (bidResponse && bidResponse.body) {
4✔
41
      try {
4✔
42
        const bids = bidResponse.body.seatbid && bidResponse.body.seatbid[0] ? bidResponse.body.seatbid[0].bid : [];
4!
43
        if (bids) {
4✔
44
          bids.forEach(bidObj => {
4✔
45
            const newBid = formatResponse(bidObj);
4✔
46
            const mediaType = _checkMediaType(bidObj);
4✔
47
            if (mediaType === BANNER) {
4✔
48
              newBid.mediaType = BANNER;
1✔
49
            } else if (mediaType === VIDEO) {
3✔
50
              newBid.mediaType = VIDEO;
1✔
51
              newBid.vastXml = bidObj.adm;
1✔
52
            }
53
            responses.push(newBid);
4✔
54
          });
55
        }
56
      } catch (err) {
57
        logError(err);
×
58
      }
59
    }
60
    return responses;
4✔
61
  },
62
  buildRequests: function (validBidRequests, bidderRequest) {
63
    var user = validBidRequests.map(bid => buildUser(bid));
25✔
64
    clean(user);
25✔
65
    const openRtbBidRequest = {
25✔
66
      id: generateUUID(),
67
      at: 1,
68
      imp: validBidRequests.map(bid => buildImpression(bid)),
25✔
69
      site: buildSite(bidderRequest),
70
      device: buildDevice(),
71
      user: user && user.length === 1 ? user[0] : {}
75!
72
    };
73

74
    if (bidderRequest && bidderRequest.uspConsent) {
25✔
75
      deepSetValue(openRtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent);
1✔
76
    }
77

78
    if (bidderRequest && bidderRequest.gdprConsent) {
25✔
79
      deepSetValue(openRtbBidRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
1✔
80
      deepSetValue(openRtbBidRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0));
1!
81
    }
82

83
    // GPP Consent
84
    if (bidderRequest?.gppConsent?.gppString) {
25✔
85
      deepSetValue(openRtbBidRequest, 'regs.gpp', bidderRequest.gppConsent.gppString);
1✔
86
      deepSetValue(openRtbBidRequest, 'regs.gpp_sid', bidderRequest.gppConsent.applicableSections);
1✔
87
    } else if (bidderRequest?.ortb2?.regs?.gpp) {
24✔
88
      deepSetValue(openRtbBidRequest, 'regs.gpp', bidderRequest.ortb2.regs.gpp);
1✔
89
      deepSetValue(openRtbBidRequest, 'regs.gpp_sid', bidderRequest.ortb2.regs.gpp_sid);
1✔
90
    }
91

92
    // coppa compliance
93
    if (bidderRequest?.ortb2?.regs?.coppa) {
25✔
94
      deepSetValue(openRtbBidRequest, 'regs.coppa', 1);
1✔
95
    }
96

97
    injectEids(openRtbBidRequest, validBidRequests);
25✔
98

99
    return {
25✔
100
      method: 'POST',
101
      url: BIDDER_ENDPOINT,
102
      data: JSON.stringify(openRtbBidRequest),
103
      options: {
104
        contentType: 'application/json'
105
      }
106
    };
107
  },
108
  /**
109
   * Register User Sync.
110
   */
111
  getUserSyncs: syncOptions => {
112
    if (syncOptions.iframeEnabled) {
1✔
113
      return [{
1✔
114
        type: 'iframe',
115
        url: USER_SYNC_URL
116
      }];
117
    }
118
  }
119

120
};
121
function _checkMediaType(bid) {
122
  const videoRegex = new RegExp(/VAST\s+version/);
4✔
123
  let mediaType;
124
  if (bid.adm && bid.adm.indexOf('deepintent_wrapper') >= 0) {
4✔
125
    mediaType = BANNER;
1✔
126
  } else if (videoRegex.test(bid.adm)) {
3✔
127
    mediaType = VIDEO;
1✔
128
  }
129
  return mediaType;
4✔
130
}
131

132
function clean(obj) {
133
  for (const propName in obj) {
25✔
134
    if (obj[propName] === null || obj[propName] === undefined) {
25✔
135
      delete obj[propName];
4✔
136
    }
137
  }
138
}
139

140
function buildImpression(bid) {
141
  let impression = {};
25✔
142
  const floor = getFloor(bid);
25✔
143
  impression = {
25✔
144
    id: bid.bidId,
145
    tagid: bid.params.tagId || '',
25!
146
    ...(!isNaN(floor) && { bidfloor: floor }),
27✔
147
    secure: window.location.protocol === 'https:' ? 1 : 0,
25!
148
    displaymanager: 'di_prebid',
149
    displaymanagerver: DI_M_V,
150
    ext: buildCustomParams(bid)
151
  };
152
  if (deepAccess(bid, 'mediaTypes.banner')) {
25✔
153
    impression['banner'] = buildBanner(bid);
21✔
154
  }
155
  if (deepAccess(bid, 'mediaTypes.video')) {
25✔
156
    impression['video'] = _buildVideo(bid);
4✔
157
  }
158
  return impression;
25✔
159
}
160

161
function getFloor(bidRequest) {
162
  if (!isFn(bidRequest.getFloor)) {
25✔
163
    return bidRequest.params?.bidfloor;
25✔
164
  }
165

NEW
166
  const floor = bidRequest.getFloor({
×
167
    currency: 'USD',
168
    mediaType: '*',
169
    size: '*'
170
  });
171

172
  if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
×
173
    return floor.floor;
×
174
  }
175
  return null;
×
176
}
177

178
function _buildVideo(bid) {
179
  const videoObj = {};
4✔
180
  const videoAdUnitParams = deepAccess(bid, 'mediaTypes.video', {});
4✔
181
  const videoBidderParams = deepAccess(bid, 'params.video', {});
4✔
182
  const computedParams = {};
4✔
183

184
  if (Array.isArray(videoAdUnitParams.playerSize)) {
4✔
185
    const tempSize = (Array.isArray(videoAdUnitParams.playerSize[0])) ? videoAdUnitParams.playerSize[0] : videoAdUnitParams.playerSize;
4!
186
    computedParams.w = tempSize[0];
4✔
187
    computedParams.h = tempSize[1];
4✔
188
  }
189

190
  const videoParams = {
4✔
191
    ...computedParams,
192
    ...videoAdUnitParams,
193
    ...videoBidderParams
194
  };
195

196
  Object.keys(ORTB_VIDEO_PARAMS).forEach(paramName => {
4✔
197
    if (videoParams.hasOwnProperty(paramName)) {
92✔
198
      if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) {
48!
199
        videoObj[paramName] = videoParams[paramName];
48✔
200
      } else {
201
        logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`);
×
202
      }
203
    }
204
  });
205

206
  return videoObj;
4✔
207
};
208

209
function buildCustomParams(bid) {
210
  if (bid.params && bid.params.custom) {
25✔
211
    return {
21✔
212
      deepintent: bid.params.custom
213

214
    }
215
  } else {
216
    return {}
4✔
217
  }
218
}
219
function buildUser(bid) {
220
  if (bid && bid.params && bid.params.user) {
25✔
221
    return {
21✔
222
      id: bid.params.user.id && typeof bid.params.user.id == 'string' ? bid.params.user.id : undefined,
63!
223
      buyeruid: bid.params.user.buyeruid && typeof bid.params.user.buyeruid == 'string' ? bid.params.user.buyeruid : undefined,
63!
224
      yob: bid.params.user.yob && typeof bid.params.user.yob == 'number' ? bid.params.user.yob : null,
63!
225
      gender: bid.params.user.gender && typeof bid.params.user.gender == 'string' ? bid.params.user.gender : undefined,
63!
226
      keywords: bid.params.user.keywords && typeof bid.params.user.keywords == 'string' ? bid.params.user.keywords : undefined,
42!
227
      customdata: bid.params.user.customdata && typeof bid.params.user.customdata == 'string' ? bid.params.user.customdata : undefined
42!
228
    }
229
  }
230
}
231

232
function injectEids(openRtbBidRequest, validBidRequests) {
233
  const bidUserIdAsEids = deepAccess(validBidRequests, '0.userIdAsEids');
25✔
234
  if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) {
25!
235
    deepSetValue(openRtbBidRequest, 'user.eids', bidUserIdAsEids);
×
236
    deepSetValue(openRtbBidRequest, 'user.ext.eids', bidUserIdAsEids);
×
237
  }
238
}
239

240
function buildBanner(bid) {
241
  if (deepAccess(bid, 'mediaTypes.banner')) {
21✔
242
    // Get Sizes from MediaTypes Object, Will always take first size, will be overrided by params for exact w,h
243
    if (deepAccess(bid, 'mediaTypes.banner.sizes') && !bid.params.height && !bid.params.width) {
21!
244
      const sizes = deepAccess(bid, 'mediaTypes.banner.sizes');
21✔
245
      if (isArray(sizes) && sizes.length > 0) {
21✔
246
        return {
21✔
247
          h: sizes[0][1],
248
          w: sizes[0][0],
249
          pos: bid && bid.params && bid.params.pos ? bid.params.pos : 0
84!
250
        }
251
      }
252
    } else {
253
      return {
×
254
        h: bid.params.height,
255
        w: bid.params.width,
256
        pos: bid && bid.params && bid.params.pos ? bid.params.pos : 0
×
257
      }
258
    }
259
  }
260
}
261

262
function buildSite(bidderRequest) {
263
  const site = {};
25✔
264
  if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.page) {
25!
265
    site.page = bidderRequest.refererInfo.page;
×
266
    site.domain = bidderRequest.refererInfo.domain;
×
267
  }
268
  return site;
25✔
269
}
270

271
function buildDevice() {
272
  return {
25✔
273
    ua: navigator.userAgent,
274
    js: 1,
275
    dnt: (navigator.doNotTrack == 'yes' || navigator.doNotTrack === '1') ? 1 : 0,
75!
276
    h: screen.height,
277
    w: screen.width,
278
    language: navigator.language
279
  }
280
}
281

282
registerBidder(spec);
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc