diff --git a/init-build.sh b/init-build.sh index 30342538..6a269da5 100755 --- a/init-build.sh +++ b/init-build.sh @@ -52,15 +52,19 @@ then exit 1 fi + OpenWrapNodeModules="${GLOBAL_OPENWRAP_PKG_JSON_DIR_V8_52_0}/node_modules/" + function prebidNpmInstall() { echo "This is SymLinking Start" cd $1 + PrebidJSNodeModules="${GLOBAL_PREBID_PKG_JSON_DIR_V8_52_0}/node_modules/" + symLinkForPrebidNodeModules=node_modules if [ -L $symLinkForPrebidNodeModules ]; then unlink $symLinkForPrebidNodeModules diff --git a/src_new/adapters/prebid.js b/src_new/adapters/prebid.js index 1c10db69..4cec6eb7 100644 --- a/src_new/adapters/prebid.js +++ b/src_new/adapters/prebid.js @@ -10,8 +10,10 @@ var BID = require("../bid.js"); var util = require("../util.js"); var bidManager = require("../bidManager.js"); var CONF = require("../conf.js"); + var COMMON_CONFIG = require("../common.config.js"); + var parentAdapterID = CONSTANTS.COMMON.PARENT_ADAPTER_PREBID; var pbNameSpace = /*CONFIG.isIdentityOnly() ? CONSTANTS.COMMON.IH_NAMESPACE : */ CONSTANTS.COMMON.PREBID_NAMESPACE; @@ -857,6 +859,14 @@ function assignCcpaConfigIfRequired(prebidConfig){ exports.assignCcpaConfigIfRequired = assignCcpaConfigIfRequired; +function assignGppConfigIfRequired(prebidConfig) { + if (CONFIG.getGppConsent()) { + prebidConfig = owIdhubCommon.setConsentConfig(prebidConfig, "gpp", CONFIG.getGppCmpApi(), CONFIG.getGppTimeout()); + } +} + +exports.assignGppConfigIfRequired = assignGppConfigIfRequired; + function assignCurrencyConfigIfRequired(prebidConfig){ if(CONFIG.getAdServerCurrency()){ // get AdServer currency from Config @@ -1042,6 +1052,7 @@ function setPrebidConfig(){ refThis.assignUserSyncConfig(prebidConfig); refThis.assignGdprConfigIfRequired(prebidConfig); refThis.assignCcpaConfigIfRequired(prebidConfig); + refThis.assignGppConfigIfRequired(prebidConfig); refThis.assignCurrencyConfigIfRequired(prebidConfig); refThis.assignSchainConfigIfRequired(prebidConfig); refThis.assignSingleRequestConfigForBidders(prebidConfig); diff --git a/src_new/conf.js b/src_new/conf.js index bcca26f1..db511139 100644 --- a/src_new/conf.js +++ b/src_new/conf.js @@ -25,6 +25,9 @@ exports.pwt = { abTestEnabled:"0", pubAnalyticsAdapter: "0", reduceCodeSize:1, + gpp: "0", + gppCmpApi: "iab", + gppTimeout: "10000", pbGlobalVarNamespace: "owpbjs", owGlobalVarNamespace: "PWT", localStorageAccess: "1" // Added new field for allow local storage feature diff --git a/src_new/config.idhub.js b/src_new/config.idhub.js index c0bfab5a..e2b65753 100644 --- a/src_new/config.idhub.js +++ b/src_new/config.idhub.js @@ -64,6 +64,23 @@ exports.getCCPATimeout = function() { return ccpaTimeout ? window.parseInt(ccpaTimeout) : CONSTANTS.CONFIG.DEFAULT_CCPA_TIMEOUT; }; +// needed +exports.getGppConsent = function () { + var gpp = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CONSENT] || CONSTANTS.CONFIG.DEFAULT_GPP_CONSENT; + return gpp === "1"; +}; + +// needed +exports.getGppCmpApi = function () { + return config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CMPAPI] || CONSTANTS.CONFIG.DEFAULT_GPP_CMPAPI; +}; + +// needed +exports.getGppTimeout = function() { + var gppTimeout = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_TIMEOUT]; + return gppTimeout ? window.parseInt(gppTimeout) : CONSTANTS.CONFIG.DEFAULT_GPP_TIMEOUT; +}; + exports.getProfileID = function () { return config.pwt[CONSTANTS.CONFIG.PROFILE_ID] || "0"; }; diff --git a/src_new/config.js b/src_new/config.js index 4b5f7702..04043030 100644 --- a/src_new/config.js +++ b/src_new/config.js @@ -458,6 +458,22 @@ exports.getMarketplaceBidders = function(){ return config.pwt.marketplaceBidders ? config.pwt.marketplaceBidders.split(',') : false; } + +exports.getGppConsent = function () { + var gpp = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CONSENT] || CONSTANTS.CONFIG.DEFAULT_GPP_CONSENT; + return gpp === "1"; +}; + +exports.getGppCmpApi = function () { + return config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CMPAPI] || CONSTANTS.CONFIG.DEFAULT_GPP_CMPAPI; +}; + +exports.getGppTimeout = function () { + var gppTimeout = config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_TIMEOUT]; + return gppTimeout ? window.parseInt(gppTimeout) : CONSTANTS.CONFIG.DEFAULT_GPP_TIMEOUT; +} + exports.shouldClearTargeting = function () { return window.PWT.shouldClearTargeting !== undefined ? Boolean(window.PWT.shouldClearTargeting) : true; + }; \ No newline at end of file diff --git a/src_new/constants.js b/src_new/constants.js index f3bad791..2cc57e7c 100644 --- a/src_new/constants.js +++ b/src_new/constants.js @@ -112,6 +112,12 @@ exports.CONFIG = { "TIMEOUT_ADJUSTMENT": 50, "SSO_ENABLED": "ssoEnabled", "FLOOR_SOURCE": "floorSource", + "GPP_CONSENT": "gpp", + "GPP_CMPAPI": "gppCmpApi", + "GPP_TIMEOUT": "gppTimeout", + "DEFAULT_GPP_CONSENT": "0", + "DEFAULT_GPP_CMPAPI": "iab", + "DEFAULT_GPP_TIMEOUT": 10000, "GDPR_ACTION_TIMEOUT": "gdprActionTimeout", "PB_GLOBAL_VAR_NAMESPACE": "pbGlobalVarNamespace", "OW_GLOBAL_VAR_NAMESPACE": "owGlobalVarNamespace" diff --git a/src_new/controllers/idhub.js b/src_new/controllers/idhub.js index 84c247de..36b1c9ef 100644 --- a/src_new/controllers/idhub.js +++ b/src_new/controllers/idhub.js @@ -5,7 +5,9 @@ var CONFIG = require("../config.idhub.js"); var CONSTANTS = require("../constants.js"); var util = require("../util.idhub.js"); + var COMMON_CONFIG = require("../common.config.js"); + var refThis = this; var pbNameSpace = CONFIG.isIdentityOnly() ? CONSTANTS.COMMON.IH_NAMESPACE : CONSTANTS.COMMON.PREBID_NAMESPACE; @@ -64,6 +66,12 @@ refThis.setConfig = function(){ timeout: CONFIG.getCCPATimeout(), }; } + + // Set Gpp consent config + if (CONFIG.getGppConsent()) { + prebidConfig = owIdhubCommon.setConsentConfig(prebidConfig, "gpp", CONFIG.getGppCmpApi(), CONFIG.getGppTimeout()); + } + window.IHPWT.ssoEnabled = CONFIG.isSSOEnabled() || false; if(CONFIG.isUserIdModuleEnabled()){ prebidConfig["userSync"]["userIds"] = util.getUserIdConfiguration(); diff --git a/src_new/owIdhubCommon.js b/src_new/owIdhubCommon.js new file mode 100644 index 00000000..f25b4f8e --- /dev/null +++ b/src_new/owIdhubCommon.js @@ -0,0 +1,15 @@ +// NOTE: This file will contains only common code/function used in OW and IDHUB. +// Do not import any other file into it. + + +exports.setConsentConfig = function (prebidConfig, key, cmpApi, timeout) { + prebidConfig = prebidConfig || {}; + if (!prebidConfig["consentManagement"]) { + prebidConfig["consentManagement"] = {}; + } + prebidConfig["consentManagement"][key] = { + cmpApi: cmpApi, + timeout: timeout + }; + return prebidConfig; +}; \ No newline at end of file diff --git a/test/adapters/prebid.spec.js b/test/adapters/prebid.spec.js index e51f85bb..a390bb53 100644 --- a/test/adapters/prebid.spec.js +++ b/test/adapters/prebid.spec.js @@ -1292,6 +1292,10 @@ describe('ADAPTER: Prebid', function() { sinon.spy(CONFIG, 'getCCPATimeout'); sinon.stub(CONFIG, 'getCCPA').returns(true); + sinon.spy(CONFIG, 'getGppTimeout'); + sinon.spy(CONFIG, 'getGppCmpApi'); + sinon.stub(CONFIG, 'getGppConsent').returns(true); + sinon.stub(BM, 'resetBid', function(){}); sinon.stub(BM, 'setSizes', function(){}); @@ -1362,6 +1366,10 @@ describe('ADAPTER: Prebid', function() { CONFIG.getCCPA.restore(); CONFIG.getCCPATimeout.restore(); + CONFIG.getGppConsent.restore(); + CONFIG.getGppCmpApi.restore(); + CONFIG.getGppTimeout.restore(); + BM.resetBid.restore(); BM.setSizes.restore(); @@ -1433,6 +1441,9 @@ describe('ADAPTER: Prebid', function() { CONFIG.getCCPA().should.be.true; CONFIG.getCCPACmpApi().should.be.called; CONFIG.getCCPATimeout().should.be.called; + CONFIG.getGppConsent().should.be.true; + CONFIG.getGppCmpApi().should.be.called; + CONFIG.getGppTimeout().should.be.called; done(); }); diff --git a/test/config.spec.js b/test/config.spec.js index 7d1928bb..30b774c1 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -2412,6 +2412,73 @@ describe('Config', function() { }); }); + + describe('#Gpp', function() { + beforeEach(function(done){ + if(!CONF[CONSTANTS.CONFIG.COMMON]) { + CONF[CONSTANTS.CONFIG.COMMON] = {}; + } + done(); + }); + + describe('#getGpp', function() { + it('is a function', function(done) { + CONFIG.getGppConsent.should.be.a('function'); + done(); + }); + + it('should return true, as it is set to "1"', function(done) { + CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CONSENT] = "1"; + CONFIG.getGppConsent().should.be.true; + done(); + }); + + it('should return default value for gpp which is '+(CONSTANTS.CONFIG.DEFAULT_GPP_CONSENT === "1")+', as it is NOT set', function(done) { + delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CONSENT]; + CONFIG.getGppConsent().should.be.equal((CONSTANTS.CONFIG.DEFAULT_GPP_CONSENT === "1")); + done(); + }); + }); + + describe('#getGppCmpApi', function() { + it('is a function', function(done) { + CONFIG.getGppCmpApi.should.be.a('function'); + done(); + }); + + it('should return iab, as it is set to iab', function(done) { + CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CMPAPI] = 'iab'; + CONFIG.getGppCmpApi().should.be.equal('iab'); + done(); + }); + + it('should return default cmp which is '+CONSTANTS.CONFIG.DEFAULT_GPP_CMPAPI+', as it is NOT set', function(done) { + delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_CMPAPI]; + CONFIG.getGppCmpApi().should.be.equal(CONSTANTS.CONFIG.DEFAULT_GPP_CMPAPI); + done(); + }); + }); + + describe('#getGppTimeout', function() { + it('is a function', function(done) { + CONFIG.getGppTimeout.should.be.a('function'); + done(); + }); + + it('should return 5000, as it is set to 5000', function(done) { + CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_TIMEOUT] = 5000; + CONFIG.getGppTimeout().should.be.equal(5000); + done(); + }); + + it('should return default value for gpp timeout which is '+CONSTANTS.CONFIG.DEFAULT_GPP_TIMEOUT+', as it is NOT set', function(done) { + delete CONF[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.GPP_TIMEOUT]; + CONFIG.getGppTimeout().should.be.equal(CONSTANTS.CONFIG.DEFAULT_GPP_TIMEOUT); + done(); + }); + }); + }); + describe('getOverrideNamespace', function() { var configKey = 'pbGlobalVarNamespace'; var defaultName = 'custPbNamespace'; diff --git a/test/owIdhubCommon.spec.js b/test/owIdhubCommon.spec.js new file mode 100644 index 00000000..6bede58a --- /dev/null +++ b/test/owIdhubCommon.spec.js @@ -0,0 +1,58 @@ +/* global describe, it, xit, sinon, expect */ +// var sinon = require("sinon"); +var should = require("chai").should(); +var expect = require("chai").expect; +var OWIDHUBCOMMON = require("../src_new/owIdhubCommon"); + +describe('owIdhubCommon', function() { + describe('setConsentConfig', function() { + var prebidConfig = {}; + var cmpApi = 'iab'; + var timeout = 2000; + + it('setConsentConfig a function', function(done) { + OWIDHUBCOMMON.setConsentConfig.should.be.a('function'); + done(); + }); + + it('should set consent management config when its not present', function(done) { + var expPrebidConfig = { + consentManagement: { + gpp: { + cmpApi, + timeout + } + } + }; + const actPrebifConfig = OWIDHUBCOMMON.setConsentConfig(prebidConfig, 'gpp', cmpApi, timeout); + expect(actPrebifConfig).to.be.deep.equal(expPrebidConfig); + done(); + }); + + it('should set consent management config when its present', function(done) { + var prebidConfig = { + consentManagement: { + gdpr: { + cmpApi, + timeout + } + } + } + var expPrebidConfig = { + consentManagement: { + gdpr: { + cmpApi, + timeout + }, + gpp: { + cmpApi, + timeout + } + } + }; + const actPrebifConfig = OWIDHUBCOMMON.setConsentConfig(prebidConfig, 'gpp', cmpApi, timeout); + expect(actPrebifConfig).to.be.deep.equal(expPrebidConfig); + done(); + }); + }); +}); \ No newline at end of file