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

TrustP ID Module: Refactor acronyms handler #8228

Merged
merged 17 commits into from
May 16, 2022
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
37 changes: 9 additions & 28 deletions modules/trustpidSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @module modules/trustpidSystem
* @requires module:modules/userId
*/
import { logInfo, logError } from '../src/utils.js';
import { logInfo } from '../src/utils.js';
import { submodule } from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

Expand All @@ -22,10 +22,9 @@ export const storage = getStorageManager({gvlid: null, moduleName: MODULE_NAME})
* @param event
*/
function messageHandler(event) {
let msg;
try {
if (event && event.data && typeof event.data === 'string' && event.data) {
msg = JSON.parse(event.data);
if (event && event.data && typeof event.data === 'string') {
const msg = JSON.parse(event.data);
if (msg.msgType === 'MNOSELECTOR' && msg.body && msg.body.url) {
let URL = msg.body.url.split('//');
let domainURL = URL[1].split('/');
Expand All @@ -35,7 +34,7 @@ function messageHandler(event) {
}
}
} catch (e) {
logError(e);
logInfo(`${LOG_PREFIX}: Unsupported message caught. Origin: ${event.origin}, data: ${event.data}.`);
}
}

Expand All @@ -44,31 +43,13 @@ function messageHandler(event) {
* @param domain
*/
function getDomainAcronym(domain) {
let acronym = '';
const prefix = '-';
switch (domain) {
case 'tmi.mno.link':
acronym = 'ndye';
break;
case 'tmi.vodafone.de':
acronym = 'pqnx';
break;
case 'tmi.telekom.de':
acronym = 'avgw';
break;
case 'tmi.tmid.es':
acronym = 'kjws';
break;
case 'uat.mno.link':
acronym = 'xxxx';
break;
case 'es.tmiservice.orange.com':
acronym = 'aplw';
break;
default:
return 'none';
const acronym = window.FC_CONF?.TELCO_ACRONYM?.[domain];
if (!acronym) {
logInfo(`${LOG_PREFIX}: No acronym found for domain: ${domain}`);
return;
}
return mnoAcronym = prefix + acronym;
mnoAcronym = prefix + acronym;
}

// Set a listener to handle the iframe response message.
Expand Down
45 changes: 11 additions & 34 deletions modules/trustpidSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,18 @@ trustpid User Id Module.
First, make sure to add the trustpid submodule to your Prebid.js package with:

```
gulp build --modules=userId,adfBidAdapter,trustpidSystem
```

The following configuration parameters are available:

```
pbjs.setConfig({
userSync: {
userIds: [
{
name: 'trustpid',
params: {
maxDelayTime: 1000,
},
bidders: ["adf"],
storage: {
type: "html5",
name: "trustpid",
expires: 1, //days
},
}
],
}
});
gulp build --modules=userId,adfBidAdapter,ixBidAdapter,prebidServerBidAdapter,trustpidSystem
```

## Parameter Descriptions

| Param under userSync.userIds[] | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| name | Required | String | The name of the module | `"trustpid"`
| params | Required | Object | Object with configuration parameters for trustpid User Id submodule | - |
| params.maxDelayTime | Required | Integer | Max amount of time (in seconds) before looking into storage for data | 2500 |
| bidders | Required | Array of Strings | An array of bidder codes to which this user ID may be sent. Currently required and supporting AdformOpenRTB | `["adf"]` |
| storage | Required | Object | Local storage configuration object | - |
| storage.type | Required | String | Type of the storage that would be used to store user ID. Must be `"html5"` to utilise HTML5 local storage. | `"html5"` |
| storage.name | Required | String | The name of the key in local storage where the user ID will be stored. | `"trustpid"` |
| storage.expires | Required | Integer | How long (in days) the user ID information will be stored. For safety reasons, this information is required.| `1` |
| Params under userSync.userIds[] | Type | Description | Example |
| --- | --- | --- | --- |
| name | String | The name of the module | `"trustpid"` |
| params | Object | Object with configuration parameters for trustpid User Id submodule | - |
| params.maxDelayTime | Integer | Max amount of time (in seconds) before looking into storage for data | 2500 |
| bidders | Array of Strings | An array of bidder codes to which this user ID may be sent. Currently required and supporting AdformOpenRTB | [`"adf"`, `"adformPBS"`, `"ix"`] |
| storage | Object | Local storage configuration object | - |
| storage.type | String | Type of the storage that would be used to store user ID. Must be `"html5"` to utilise HTML5 local storage. | `"html5"` |
| storage.name | String | The name of the key in local storage where the user ID will be stored. | `"trustpid"` |
| storage.expires | Integer | How long (in days) the user ID information will be stored. For safety reasons, this information is required.| `1` |
11 changes: 0 additions & 11 deletions modules/userId/userId.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ pbjs.setConfig({
params: {
pid: "0010b00002GYU4eBAH" // Example ID
}
}, {
name: 'trustpid',
params: {
maxDelayTime: 2500
},
bidders: ['adform'],
storage: {
type: 'html5',
name: 'trustpid',
expires: 60
}
}, {
name: "unifiedId",
params: {
Expand Down
61 changes: 42 additions & 19 deletions test/spec/modules/trustpidSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ describe('trustpid System', () => {
});

describe('trustpid getId()', () => {
before(() => {
window.FC_CONF = {
TELCO_ACRONYM: {
'domain.with.acronym': 'acronymValue',
}
};
});

afterEach(() => {
storage.removeDataFromLocalStorage(connectDataKey);
storage.removeDataFromLocalStorage(connectDomainKey);
});

after(() => {
window.FC_CONF = {};
})

it('it should return object with key callback', () => {
expect(trustpidSubmodule.getId()).to.have.property('callback');
});
Expand Down Expand Up @@ -58,41 +70,41 @@ describe('trustpid System', () => {

it('returns {id: {trustpid: data.trustpid}} if we have the right data stored in the localstorage ', () => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
const response = trustpidSubmodule.getId();
expect(response).to.have.property('id');
expect(response.id).to.have.property('trustpid');
expect(response.id.trustpid).to.be.equal('umidValue-xxxx');
expect(response.id.trustpid).to.be.equal('umidValue-acronymValue');
});

it('returns {trustpid: data.trustpid} if we have the right data stored in the localstorage right after the callback is called', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
const response = trustpidSubmodule.getId();
expect(response).to.have.property('callback');
expect(response.callback.toString()).contain('result(callback)');

if (typeof response.callback === 'function') {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
response.callback(function (result) {
expect(result).to.not.be.null;
expect(result).to.have.property('trustpid');
expect(result.trustpid).to.be.equal('umidValue-xxxx');
expect(result.trustpid).to.be.equal('umidValue-acronymValue');
done()
})
}
});

it('returns null if domains don\'t match', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('differentDomainValue'));
Expand All @@ -115,7 +127,7 @@ describe('trustpid System', () => {

it('returns {trustpid: data.trustpid} if we have the right data stored in the localstorage right after 500ms delay', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};

Expand All @@ -125,21 +137,21 @@ describe('trustpid System', () => {

if (typeof response.callback === 'function') {
setTimeout(() => {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
}, 500);
response.callback(function (result) {
expect(result).to.not.be.null;
expect(result).to.have.property('trustpid');
expect(result.trustpid).to.be.equal('umidValue-xxxx');
expect(result.trustpid).to.be.equal('umidValue-acronymValue');
done()
})
}
});

it('returns null if we have the data stored in the localstorage after 500ms delay and the max (waiting) delay is only 200ms ', (done) => {
const idGraph = {
'domain': 'uat.mno.link',
'domain': 'domain.with.acronym',
'umid': 'umidValue',
};

Expand All @@ -149,7 +161,7 @@ describe('trustpid System', () => {

if (typeof response.callback === 'function') {
setTimeout(() => {
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('uat.mno.link'));
storage.setDataInLocalStorage(connectDomainKey, JSON.stringify('domain.with.acronym'));
storage.setDataInLocalStorage(connectDataKey, JSON.stringify(getStorageData(idGraph)));
}, 500);
response.callback(function (result) {
Expand Down Expand Up @@ -191,22 +203,33 @@ describe('trustpid System', () => {
});

describe('trustpid messageHandler for acronyms', () => {
before(() => {
window.FC_CONF = {
TELCO_ACRONYM: {
'domain1': 'abcd',
'domain2': 'efgh',
'domain3': 'ijkl',
}
};
});

afterEach(() => {
storage.removeDataFromLocalStorage(connectDataKey);
storage.removeDataFromLocalStorage(connectDomainKey);
});

after(() => {
window.FC_CONF = {};
})

const domains = [
{domain: 'tmi.mno.link', acronym: 'ndye'},
{domain: 'tmi.vodafone.de', acronym: 'pqnx'},
{domain: 'tmi.telekom.de', acronym: 'avgw'},
{domain: 'tmi.tmid.es', acronym: 'kjws'},
{domain: 'uat.mno.link', acronym: 'xxxx'},
{domain: 'es.tmiservice.orange.com', acronym: 'aplw'},
{domain: 'domain1', acronym: 'abcd'},
{domain: 'domain2', acronym: 'efgh'},
{domain: 'domain3', acronym: 'ijkl'},
];

domains.forEach(({domain, acronym}) => {
it(`correctly sets trustpid value and acronym to ${acronym} for ${domain} domain`, (done) => {
it(`correctly sets trustpid value and acronym to ${acronym} for ${domain}`, (done) => {
const idGraph = {
'domain': domain,
'umid': 'umidValue',
Expand Down