Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sublime Bid Adapter : refactoring notifyId, bid request validation, & device detection fix #7327

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const DEFAULT_CURRENCY = 'EUR';
const DEFAULT_PROTOCOL = 'https';
const DEFAULT_TTL = 600;
const SUBLIME_ANTENNA = 'antenna.ayads.co';
const SUBLIME_VERSION = '0.7.3';
const SUBLIME_VERSION = '0.8.0';

/**
* Identify the current device type
* @returns {string}
*/
function detectDevice() {
const isMobile = /(?:phone|windowss+phone|ipod|blackberry|Galaxy Nexus|SM-G892A|(?:android|bbd+|meego|silk|googlebot) .+?mobile|palm|windowss+ce|opera mini|avantgo|docomo)/i;
const isMobile = /(?:phone|windows\s+phone|ipod|blackberry|Galaxy Nexus|SM-G892A|(?:android|bbd+|meego|silk|googlebot) .+?mobile|palm|windows\s+ce|opera mini|avantgo|docomo)/i;

const isTablet = /(?:ipad|playbook|Tablet|(?:android|bb\\d+|meego|silk)(?! .+? mobile))/i;
const isTablet = /(?:ipad|playbook|Tablet|(?:android|bb\d+|meego|silk)(?! .+? mobile))/i;

return (
(isMobile.test(navigator.userAgent) && 'm') || // mobile
Expand All @@ -27,6 +27,16 @@ function detectDevice() {
);
}

const UUID_V4_RE = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
/**
* Checks whether a notifyId is well-formed
* @param {*} value
* @returns {boolean}
*/
function isValidNotifyId(value) {
return UUID_V4_RE.test(value);
}

/**
* Debug log message
* @param {String} msg
Expand All @@ -53,6 +63,26 @@ export function setState(value) {
log('State has been updated :', state);
}

/**
* Get a notifyId from bid params or from sublime global
* @param {Object} params - The bid params
* @return {string}
*/
function getNotifyId(params) {
const sublime = window.sublime = window.sublime || {};

let notifyId = params.notifyId || sublime.notifyId;
if (!notifyId) {
notifyId = utils.generateUUID();
log('generating a notifyId', notifyId);
}
if (!sublime.notifyId) {
sublime.notifyId = notifyId;
}

return notifyId;
}

/**
* Send pixel to our debug endpoint
* @param {string} eventName - Event name that will be send in the e= query string
Expand Down Expand Up @@ -91,6 +121,16 @@ export function sendEvent(eventName, sspName) {
* @return {Boolean} True if this is a valid bid, and false otherwise.
*/
function isBidRequestValid(bid) {
const notifyId = getNotifyId(bid.params);
if (!isValidNotifyId(notifyId)) {
log(`invalid notifyId format, got "${notifyId}"`);
return false;
}
if (notifyId !== window.sublime.notifyId) {
log(`notifyId mismatch: params [${bid.params.notifyId}] / sublime [${window.sublime.notifyId}]`);
return false;
}

return !!Number(bid.params.zoneId);
}

Expand Down Expand Up @@ -127,9 +167,11 @@ function buildRequests(validBidRequests, bidderRequest) {
const bidHost = bid.params.bidHost || DEFAULT_BID_HOST;
const protocol = bid.params.protocol || DEFAULT_PROTOCOL;

const notifyId = getNotifyId(bid.params);

setState({
transactionId: bid.transactionId,
notifyId: bid.params.notifyId,
notifyId,
zoneId: bid.params.zoneId,
debug: bid.params.debug || false,
});
Expand All @@ -146,7 +188,7 @@ function buildRequests(validBidRequests, bidderRequest) {
h: size[1],
})),
transactionId: bid.transactionId,
notifyId: bid.params.notifyId,
notifyId,
zoneId: bid.params.zoneId,
};

Expand Down Expand Up @@ -250,15 +292,18 @@ export const spec = {
code: BIDDER_CODE,
gvlid: BIDDER_GVLID,
aliases: [],
isBidRequestValid: isBidRequestValid,
buildRequests: buildRequests,
interpretResponse: interpretResponse,
onBidWon: onBidWon,
onTimeout: onTimeout,
isBidRequestValid,
buildRequests,
interpretResponse,
onBidWon,
onTimeout,
// Exposed for test purpose
sendEvent: sendEvent,
setState: setState,
state: state,
sendEvent,
setState,
state,
detectDevice,
getNotifyId,
isValidNotifyId,
};

registerBidder(spec);
Loading