-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Prebid 10: normalize EID and schain in FPD; move legacy schain configuration logic to schain module #13343
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
Merged
Merged
Prebid 10: normalize EID and schain in FPD; move legacy schain configuration logic to schain module #13343
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import {config} from '../src/config.js'; | ||
| import {deepClone, logWarn} from '../src/utils.js'; | ||
| import {normalizeFPD} from '../src/fpd/normalize.js'; | ||
|
|
||
|
|
||
| export function applySchainConfig(ortb2Fragments) { | ||
| if (!ortb2Fragments) return ortb2Fragments; | ||
|
|
||
| let warned = false; | ||
| function warnDeprecated() { | ||
| if (!warned) { | ||
| logWarn('The schain module is deprecated and no longer needed; you may provide schain directly as FPD (e.g., "setConfig({ortb2: {source: {schain: {...}})")'); | ||
| warned = true; | ||
| } | ||
| } | ||
|
|
||
| // Apply global schain config if available | ||
| // config's schain will have more precedence over ortb2.source.schain | ||
| const globalSchainConfig = config.getConfig('schain'); | ||
| if (globalSchainConfig && globalSchainConfig.config) { | ||
| warnDeprecated(); | ||
| if (!ortb2Fragments?.global?.source?.schain) { | ||
| applySchainToPath(ortb2Fragments, 'global.source', globalSchainConfig.config); | ||
| } else { | ||
| logWarn('Disregarding global schain config as schain is already provided in FPD') | ||
| } | ||
| } | ||
|
|
||
| // Apply bidder-specific schain configs | ||
| const bidderConfigs = config.getBidderConfig(); | ||
| if (!bidderConfigs) return ortb2Fragments; | ||
|
|
||
| Object.entries(bidderConfigs) | ||
| .filter(([_, cfg]) => cfg.schain) | ||
| .forEach(([bidderCode, cfg]) => { | ||
| warnDeprecated(); | ||
| const bidderPath = `bidder.${bidderCode}.source`; | ||
| const hasSchain = ortb2Fragments?.bidder?.[bidderCode]?.source?.schain; | ||
| if (!hasSchain) { | ||
| applySchainToPath(ortb2Fragments, bidderPath, cfg.schain?.config); | ||
| } else { | ||
| logWarn(`Disregarding schain config for bidder "${bidderCode}" as schain is already provided in FPD`); | ||
| } | ||
| }); | ||
|
|
||
| return ortb2Fragments; | ||
| } | ||
|
|
||
| function applySchainToPath(fragments, path, schainConfig) { | ||
| const parts = path.split('.'); | ||
| let current = fragments; | ||
|
|
||
| // Create path if it doesn't exist | ||
| parts.forEach(part => { | ||
| current[part] = current[part] || {}; | ||
| current = current[part]; | ||
| }); | ||
|
|
||
| // Apply the schain config | ||
| current.schain = deepClone(schainConfig); | ||
| } | ||
|
|
||
| normalizeFPD.before((next, ortb2Fragments) => { | ||
| applySchainConfig(ortb2Fragments); | ||
| next(ortb2Fragments); | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # schain module | ||
|
|
||
| ** DEPRECATED **. | ||
|
|
||
| This module is deprecated since prebid 10; schain may be provided directly as fpd, for example: | ||
|
|
||
| ```typescript | ||
| pbjs.setConfig({ | ||
| ortb2: { | ||
| source: { | ||
| schain: { | ||
| "ver":"1.0", | ||
| "complete": 1, | ||
| "nodes": [ | ||
| { | ||
| "asi":"indirectseller.com", | ||
| "sid":"00001", | ||
| "hp":1 | ||
| }, | ||
|
|
||
| { | ||
| "asi":"indirectseller-2.com", | ||
| "sid":"00002", | ||
| "hp":1 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| You may also use the [FPD validation module](https://docs.prebid.org/dev-docs/modules/validationFpdModule.html) to validate your schain configuration. | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import {deepEqual, deepSetValue, logWarn} from '../utils.js'; | ||
| import {hook} from '../hook.js'; | ||
|
|
||
| export const normalizeFPD = hook('sync', function(ortb2Fragments) { | ||
| [ | ||
| normalizeEIDs, | ||
| normalizeSchain | ||
| ].forEach(normalizer => applyNormalizer(normalizer, ortb2Fragments)); | ||
| return ortb2Fragments; | ||
| }) | ||
|
|
||
| function applyNormalizer(normalizer, ortb2Fragments) { | ||
| ortb2Fragments.global = normalizer(ortb2Fragments.global, 'global FPD'); | ||
| Object.entries(ortb2Fragments.bidder).forEach(([bidder, ortb2]) => { | ||
| ortb2Fragments.bidder[bidder] = normalizer(ortb2, `bidder '${bidder}' FPD`); | ||
| }) | ||
| } | ||
|
|
||
| export function normalizeEIDs(target, context) { | ||
| if (!target) return target; | ||
| const seen = []; | ||
| const eids = [ | ||
| ...(target?.user?.eids ?? []).map(eid => [0, eid]), | ||
| ...(target?.user?.ext?.eids ?? []).map(eid => [1, eid]) | ||
| ].filter(([source, eid]) => { | ||
| if (seen.findIndex(([candidateSource, candidateEid]) => | ||
| source !== candidateSource && deepEqual(candidateEid, eid) | ||
| ) > -1) { | ||
| logWarn(`Found duplicate EID in user.eids and user.ext.eids (${context})`, eid) | ||
| return false; | ||
| } else { | ||
| seen.push([source, eid]); | ||
| return true; | ||
| } | ||
| }); | ||
| if (eids.length > 0) { | ||
| deepSetValue(target, 'user.ext.eids', eids.map(([_, eid]) => eid)); | ||
| } | ||
| delete target?.user?.eids; | ||
| return target; | ||
| } | ||
|
|
||
|
|
||
| export function normalizeSchain(target, context) { | ||
| if (!target) return target; | ||
| const schain = target.source?.schain; | ||
| const extSchain = target.source?.ext?.schain; | ||
| if (schain != null && extSchain != null && !deepEqual(schain, extSchain)) { | ||
| logWarn(`Conflicting source.schain and source.ext.schain (${context}), preferring source.schain`, { | ||
| 'source.schain': schain, | ||
| 'source.ext.schain': extSchain | ||
| }) | ||
| } | ||
| if ((schain ?? extSchain) != null) { | ||
| deepSetValue(target, 'source.ext.schain', schain ?? extSchain); | ||
| } | ||
| delete target.source?.schain; | ||
| return target; | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import {normalizeEIDs, normalizeFPD, normalizeSchain} from '../../../src/fpd/normalize.js'; | ||
| import * as utils from '../../../src/utils'; | ||
|
|
||
| describe('FPD normalization', () => { | ||
| let sandbox; | ||
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| sandbox.stub(utils, 'logWarn'); | ||
| }); | ||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }) | ||
|
|
||
| describe('EIDs', () => { | ||
| it('should merge user.eids into user.ext.eids', () => { | ||
| const fpd = { | ||
| user: { | ||
| eids: [{source: 'idA'}], | ||
| ext: {eids: [{source: 'idB'}]} | ||
| } | ||
| }; | ||
| const result = normalizeEIDs(fpd); | ||
| expect(result.user.eids).to.not.exist; | ||
| expect(result.user.ext.eids).to.deep.have.members([ | ||
| {source: 'idA'}, | ||
| {source: 'idB'} | ||
| ]) | ||
| }); | ||
| it('should remove duplicates', () => { | ||
| const fpd = { | ||
| user: { | ||
| eids: [{source: 'id'}], | ||
| ext: {eids: [{source: 'id'}]} | ||
| } | ||
| } | ||
| expect(normalizeEIDs(fpd).user.ext.eids).to.eql([ | ||
| {source: 'id'} | ||
| ]) | ||
| sinon.assert.called(utils.logWarn); | ||
| }); | ||
| it('should NOT remove duplicates if they come from the same place', () => { | ||
| const fpd = { | ||
| user: { | ||
| eids: [{source: 'id'}, {source: 'id'}] | ||
| } | ||
| } | ||
| expect(normalizeEIDs(fpd).user.ext.eids.length).to.eql(2); | ||
| }); | ||
| it('should do nothing if there are no eids', () => { | ||
| expect(normalizeEIDs({})).to.eql({}); | ||
| }) | ||
| }) | ||
| describe('schain', () => { | ||
| it('should move schain to ext.schain', () => { | ||
| const fpd = { | ||
| source: { | ||
| schain: 'foo' | ||
| } | ||
| } | ||
| expect(normalizeSchain(fpd)).to.deep.equal({ | ||
| source: { | ||
| ext: { | ||
| schain: 'foo' | ||
| } | ||
| } | ||
| }) | ||
| }); | ||
| it('should warn on conflict', () => { | ||
| const fpd = { | ||
| source: { | ||
| schain: 'foo', | ||
| ext: { | ||
| schain: 'bar' | ||
| } | ||
| }, | ||
| } | ||
| expect(normalizeSchain(fpd)).to.eql({ | ||
| source: { | ||
| ext: { | ||
| schain: 'foo' | ||
| } | ||
| } | ||
| }); | ||
| sinon.assert.called(utils.logWarn); | ||
| }); | ||
|
|
||
| it('should do nothing if there is no schain', () => { | ||
| expect(normalizeSchain({})).to.eql({}); | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting edge case :)