Skip to content

Commit

Permalink
SharedIdSystem: add configurable inserter
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Jan 15, 2025
1 parent b5f9de7 commit 476a8fb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
12 changes: 9 additions & 3 deletions modules/sharedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,15 @@ export const sharedIdSystemSubmodule = {

domainOverride: domainOverrideToRootDomain(storage, 'sharedId'),
eids: {
'pubcid': {
source: 'pubcid.org',
atype: 1
'pubcid'(values, config) {
const eid = {
source: 'pubcid.org',
uids: values.map(id => ({id, atype: 1}))
}
if (config?.params?.inserter != null) {
eid.inserter = config.params.inserter;
}
return eid;
},
}
};
Expand Down
2 changes: 2 additions & 0 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export function createEidsArray(bidRequestUserId, eidConfigs = EID_CONFIG) {
if (!Array.isArray(eids)) {
eids = [eids];
}
eids.forEach(eid => eid.uids = eid.uids.filter(({id}) => isStr(id)))
eids = eids.filter(({uids}) => uids?.length > 0);
} catch (e) {
logError(`Could not generate EID for "${name}"`, e);
}
Expand Down
26 changes: 25 additions & 1 deletion test/spec/modules/sharedIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {sharedIdSystemSubmodule, storage} from 'modules/sharedIdSystem.js';
import {coppaDataHandler} from 'src/adapterManager';
import {config} from 'src/config.js';

import sinon from 'sinon';
import * as utils from 'src/utils.js';
import {createEidsArray} from '../../../modules/userId/eids.js';
import {attachIdSystem} from '../../../modules/userId/index.js';
import {attachIdSystem, init} from '../../../modules/userId/index.js';
import {getGlobal} from '../../../src/prebidGlobal.js';

let expect = require('chai').expect;

Expand Down Expand Up @@ -97,6 +99,9 @@ describe('SharedId System', function () {
before(() => {
attachIdSystem(sharedIdSystemSubmodule);
});
afterEach(() => {
config.resetConfig();
});
it('pubCommonId', function() {
const userId = {
pubcid: 'some-random-id-value'
Expand All @@ -108,5 +113,24 @@ describe('SharedId System', function () {
uids: [{id: 'some-random-id-value', atype: 1}]
});
});

it('should set inserter, if provided in config', async () => {
config.setConfig({
userSync: {
userIds: [{
name: 'sharedId',
params: {
inserter: 'mock-inserter'
},
value: {pubcid: 'mock-id'}
}]
}
});
const eids = getGlobal().getUserIdsAsEids();
sinon.assert.match(eids[0], {
source: 'pubcid.org',
inserter: 'mock-inserter'
})
})
})
});
19 changes: 19 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ describe('User ID', function () {
]);
});

it('should filter out non-string uid returned by generator functions', () => {
const eids = createEidsArray({
mockId2v3: [null, 'id1', 123],
});
expect(eids[0].uids).to.eql([
{
atype: 2,
id: 'id1'
}
]);
});

it('should filter out entire EID if none of the uids are strings', () => {
const eids = createEidsArray({
mockId2v3: [null],
});
expect(eids).to.eql([]);
})

it('should group UIDs by everything except uid', () => {
const eids = createEidsArray({
mockId1: ['mock-1-1', 'mock-1-2'],
Expand Down

0 comments on commit 476a8fb

Please sign in to comment.