Skip to content

Commit

Permalink
ID5 ID module: config call as bounce (prebid#11424)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkowalski-id5 authored and f.caspar committed May 14, 2024
1 parent c24f28e commit 3723712
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 116 deletions.
44 changes: 24 additions & 20 deletions modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ export const id5IdSubmodule = {
id5id: {
uid: universalUid,
ext: ext
},
}
};

if (isPlainObject(ext.euid)) {
responseObj.euid = {
uid: ext.euid.uids[0].id,
source: ext.euid.source,
ext: {provider: ID5_DOMAIN}
}
};
}

const abTestingResult = deepAccess(value, 'ab_testing.result');
Expand Down Expand Up @@ -196,15 +196,15 @@ export const id5IdSubmodule = {
}

if (!hasWriteConsentToLocalStorage(consentData)) {
logInfo(LOG_PREFIX + 'Skipping ID5 local storage write because no consent given.')
logInfo(LOG_PREFIX + 'Skipping ID5 local storage write because no consent given.');
return undefined;
}

const resp = function (cbFunction) {
const fetchFlow = new IdFetchFlow(submoduleConfig, consentData, cacheIdObj, uspDataHandler.getConsentData(), gppDataHandler.getConsentData());
fetchFlow.execute()
.then(response => {
cbFunction(response)
cbFunction(response);
})
.catch(error => {
logError(LOG_PREFIX + 'getId fetch encountered an error', error);
Expand All @@ -227,7 +227,7 @@ export const id5IdSubmodule = {
*/
extendId(config, consentData, cacheIdObj) {
if (!hasWriteConsentToLocalStorage(consentData)) {
logInfo(LOG_PREFIX + 'No consent given for ID5 local storage writing, skipping nb increment.')
logInfo(LOG_PREFIX + 'No consent given for ID5 local storage writing, skipping nb increment.');
return cacheIdObj;
}

Expand All @@ -239,12 +239,12 @@ export const id5IdSubmodule = {
},
eids: {
'id5id': {
getValue: function(data) {
return data.uid
getValue: function (data) {
return data.uid;
},
source: ID5_DOMAIN,
atype: 1,
getUidExt: function(data) {
getUidExt: function (data) {
if (data.ext) {
return data.ext;
}
Expand All @@ -264,16 +264,16 @@ export const id5IdSubmodule = {
}
}
}
},
}
};

export class IdFetchFlow {
constructor(submoduleConfig, gdprConsentData, cacheIdObj, usPrivacyData, gppData) {
this.submoduleConfig = submoduleConfig
this.gdprConsentData = gdprConsentData
this.cacheIdObj = cacheIdObj
this.usPrivacyData = usPrivacyData
this.gppData = gppData
this.submoduleConfig = submoduleConfig;
this.gdprConsentData = gdprConsentData;
this.cacheIdObj = cacheIdObj;
this.usPrivacyData = usPrivacyData;
this.gppData = gppData;
}

/**
Expand Down Expand Up @@ -324,7 +324,11 @@ export class IdFetchFlow {
let url = this.submoduleConfig.params.configUrl || ID5_API_CONFIG_URL; // override for debug/test purposes only
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(this.submoduleConfig)
body: JSON.stringify({
...this.submoduleConfig,
bounce: true
}),
credentials: 'include'
});
if (!response.ok) {
throw new Error('Error while calling config endpoint: ', response);
Expand All @@ -342,7 +346,7 @@ export class IdFetchFlow {
const extensionsUrl = extensionsCallConfig.url;
const method = extensionsCallConfig.method || 'GET';
const body = method === 'GET' ? undefined : JSON.stringify(extensionsCallConfig.body || {});
const response = await fetch(extensionsUrl, { method, body });
const response = await fetch(extensionsUrl, {method, body});
if (!response.ok) {
throw new Error('Error while calling extensions endpoint: ', response);
}
Expand All @@ -360,7 +364,7 @@ export class IdFetchFlow {
...additionalData,
extensions: extensionsData
});
const response = await fetch(fetchUrl, { method: 'POST', body, credentials: 'include' });
const response = await fetch(fetchUrl, {method: 'POST', body, credentials: 'include'});
if (!response.ok) {
throw new Error('Error while calling fetch endpoint: ', response);
}
Expand Down Expand Up @@ -456,7 +460,7 @@ function validateConfig(config) {
return false;
}

const partner = config.params.partner
const partner = config.params.partner;
if (typeof partner === 'string' || partner instanceof String) {
let parsedPartnerId = parseInt(partner);
if (isNaN(parsedPartnerId) || parsedPartnerId < 0) {
Expand Down Expand Up @@ -566,8 +570,8 @@ export function storeInLocalStorage(key, value, expDays) {
*/
function hasWriteConsentToLocalStorage(consentData) {
const hasGdpr = consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies;
const localstorageConsent = deepAccess(consentData, `vendorData.purpose.consents.1`)
const id5VendorConsent = deepAccess(consentData, `vendorData.vendor.consents.${GVLID.toString()}`)
const localstorageConsent = deepAccess(consentData, `vendorData.purpose.consents.1`);
const id5VendorConsent = deepAccess(consentData, `vendorData.vendor.consents.${GVLID.toString()}`);
if (hasGdpr && (!localstorageConsent || !id5VendorConsent)) {
return false;
}
Expand Down
Loading

0 comments on commit 3723712

Please sign in to comment.