Skip to content

Commit

Permalink
Merge pull request #94 from 33Across/33across_hem_via_config
Browse files Browse the repository at this point in the history
Allow to send hashed email via config parameters
  • Loading branch information
carlosfelix authored Dec 16, 2024
2 parents d2dd2ee + 380b77e commit 118c1a6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
16 changes: 10 additions & 6 deletions modules/33acrossIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function calculateResponseObj(response) {
};
}

function calculateQueryStringParams(pid, gdprConsentData, enabledStorageTypes) {
function calculateQueryStringParams({ pid, hem }, gdprConsentData, enabledStorageTypes) {
const uspString = uspDataHandler.getConsentData();
const coppaValue = coppaDataHandler.getCoppa();
const gppConsent = gppDataHandler.getConsentData();
Expand Down Expand Up @@ -98,9 +98,9 @@ function calculateQueryStringParams(pid, gdprConsentData, enabledStorageTypes) {
params.tp = encodeURIComponent(tp);
}

const hem = getStoredValue(STORAGE_HEM_KEY, enabledStorageTypes);
if (hem) {
params.sha256 = encodeURIComponent(hem);
const hemParam = hem || getStoredValue(STORAGE_HEM_KEY, enabledStorageTypes);
if (hemParam) {
params.sha256 = encodeURIComponent(hemParam);
}

return params;
Expand Down Expand Up @@ -194,7 +194,11 @@ export const thirtyThreeAcrossIdSubmodule = {
return;
}

const { pid, storeFpid = DEFAULT_1PID_SUPPORT, storeTpid = DEFAULT_TPID_SUPPORT, apiUrl = API_URL } = params;
const {
storeFpid = DEFAULT_1PID_SUPPORT,
storeTpid = DEFAULT_TPID_SUPPORT, apiUrl = API_URL,
...options
} = params;

return {
callback(cb) {
Expand Down Expand Up @@ -235,7 +239,7 @@ export const thirtyThreeAcrossIdSubmodule = {

cb();
}
}, calculateQueryStringParams(pid, gdprConsentData, enabledStorageTypes), {
}, calculateQueryStringParams(options, gdprConsentData, enabledStorageTypes), {
method: 'GET',
withCredentials: true
});
Expand Down
1 change: 1 addition & 0 deletions modules/33acrossIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following settings are available in the `params` property in `userSync.userI
| Param name | Scope | Type | Description | Example |
| --- | --- | --- | --- | --- |
| pid | Required | String | Partner ID provided by 33Across | `"0010b00002GYU4eBAH"` |
| hem | Optional | String | Hashed email address in sha256 format | `"ba4235544d6c91865fbf70fa1bdb70f2d375ded1b2b946b21c675dcbe9968cdc"` |
| storeFpid | Optional | Boolean | Indicates whether a supplemental first-party ID may be stored to improve addressability, this feature is enabled by default | `true` (default) or `false` |
| storeTpid | Optional | Boolean | Indicates whether a supplemental third-party ID may be stored to improve addressability, this feature is enabled by default | `true` (default) or `false` |

Expand Down
91 changes: 60 additions & 31 deletions test/spec/modules/33acrossIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,20 +906,22 @@ describe('33acrossIdSystem', () => {
});
});

context('when a hashed email is present in local storage', () => {
context('when a hashed email is provided via configuration options', () => {
it('should call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
pid: '12345',
hem: '33acrossIdHmValue+'
},
enabledStorageTypes: [ 'html5' ],
storage: {}
});

// Prioritizes the hem given via config options over the one stored in LS.
sinon.stub(storage, 'getDataFromLocalStorage')
.withArgs('33acrossIdHm')
.returns('33acrossIdHmValue+');
.returns('33acrossIdHmValueLS');

callback(completeCallback);

Expand All @@ -931,45 +933,72 @@ describe('33acrossIdSystem', () => {
});
});

context('when a hashed email is present in cookie storage', () => {
it('should call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
},
enabledStorageTypes: [ 'cookie' ],
storage: {}
});
context('when a hashed email is NOT provided via configuration options', () => {
context('but it\'s provided via local storage', () => {
it('should call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
},
enabledStorageTypes: [ 'html5' ],
storage: {}
});

sinon.stub(storage, 'getCookie')
.withArgs('33acrossIdHm')
.returns('33acrossIdHmValue');
sinon.stub(storage, 'getDataFromLocalStorage')
.withArgs('33acrossIdHm')
.returns('33acrossIdHmValue+');

callback(completeCallback);
callback(completeCallback);

const [request] = server.requests;
const [request] = server.requests;

expect(request.url).to.contain('sha256=33acrossIdHmValue');
expect(request.url).to.contain('sha256=33acrossIdHmValue%2B');

storage.getCookie.restore();
storage.getDataFromLocalStorage.restore();
});
});
});

context('when a hashed email is not present in storage', () => {
it('should not call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
}
context('but it\'s provided via cookie storage', () => {
it('should call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
},
enabledStorageTypes: [ 'cookie' ],
storage: {}
});

sinon.stub(storage, 'getCookie')
.withArgs('33acrossIdHm')
.returns('33acrossIdHmValue');

callback(completeCallback);

const [request] = server.requests;

expect(request.url).to.contain('sha256=33acrossIdHmValue');

storage.getCookie.restore();
});
});

callback(completeCallback);
context('and hashed email is not present in storage', () => {
it('should not call endpoint with the hashed email included', () => {
const completeCallback = () => {};
const { callback } = thirtyThreeAcrossIdSubmodule.getId({
params: {
pid: '12345'
}
});

const [request] = server.requests;
callback(completeCallback);

expect(request.url).not.to.contain('sha256=');
const [request] = server.requests;

expect(request.url).not.to.contain('sha256=');
});
});
});

Expand Down

0 comments on commit 118c1a6

Please sign in to comment.