Skip to content

Commit 8bbf781

Browse files
committed
Remove storage-related functionality from Start.io ID submodule and add support for EIDs.
1 parent 7db3472 commit 8bbf781

3 files changed

Lines changed: 28 additions & 101 deletions

File tree

modules/startioSystem.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1+
/**
2+
* This module adds startio ID support to the User ID module
3+
* The {@link module:modules/userId} module is required
4+
* @module modules/startioSystem
5+
* @requires module:modules/userId
6+
*/
17
import { logError } from '../src/utils.js';
28
import { submodule } from '../src/hook.js';
39
import { ajax } from '../src/ajax.js';
4-
import { getStorageManager, STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } from '../src/storageManager.js';
5-
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
610

711
const MODULE_NAME = 'startioId';
812
const DEFAULT_ENDPOINT = '';
9-
export const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME });
10-
11-
function storeId(id, storageConfig = {}) {
12-
const expires = storageConfig.expires || 365;
13-
const expirationDate = new Date(Date.now() + (expires * 24 * 60 * 60 * 1000));
14-
const storageType = storageConfig.type || '';
15-
const useCookie = !storageType || storageType.includes(STORAGE_TYPE_COOKIES);
16-
const useLocalStorage = !storageType || storageType.includes(STORAGE_TYPE_LOCALSTORAGE);
17-
18-
if (useCookie && storage.cookiesAreEnabled()) {
19-
storage.setCookie(MODULE_NAME, id, expirationDate.toUTCString());
20-
}
21-
22-
if (useLocalStorage && storage.localStorageIsEnabled()) {
23-
storage.setDataInLocalStorage(MODULE_NAME, id);
24-
}
25-
}
2613

2714
export const startioIdSubmodule = {
2815
name: MODULE_NAME,
@@ -33,7 +20,6 @@ export const startioIdSubmodule = {
3320
},
3421
getId(config, consentData, storedId) {
3522
const configParams = (config && config.params) || {};
36-
const storageConfig = (config && config.storage) || {};
3723
const endpoint = configParams.endpoint || DEFAULT_ENDPOINT;
3824

3925
if (storedId) {
@@ -48,7 +34,6 @@ export const startioIdSubmodule = {
4834
const responseObj = JSON.parse(response);
4935
if (responseObj && responseObj.id) {
5036
responseId = responseObj.id;
51-
storeId(responseId, storageConfig);
5237
} else {
5338
logError(`${MODULE_NAME}: Server response missing 'id' field`);
5439
}

modules/startioSystem.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ The below parameters apply only to the Start.io User ID integration.
3434
| params | Required | Object | Container of all module params. | |
3535
| params.endpoint | Required | String | The URL of the Start.io ID endpoint. Must return a JSON object with an `id` field. | `"https://id.startio.example.com/uid"` |
3636
| storage | Optional | Object | Controls how the ID is persisted. Managed by Prebid.js core; see notes below. | |
37-
| storage.type | Optional | String | Storage mechanism. Accepts `cookie`, `html5`, or `cookie&html5`. Defaults to both when omitted. | `"cookie&html5"` |
37+
| storage.name | Required | String | The cookie or local-storage key used to persist the ID. Must match the module name. | `"startioId"` |
38+
| storage.type | Optional | String | Storage mechanism. `"cookie"` for cookies only, `"html5"` for localStorage only. Omit to use both. | `"html5"` |
3839
| storage.expires | Optional | Number | Cookie / storage TTL in days. Defaults to `365`. | `365` |
3940

4041
## Server Response Format

test/spec/modules/startioSystem_spec.js

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as utils from '../../../src/utils.js';
22
import { server } from 'test/mocks/xhr.js';
3-
import { startioIdSubmodule, storage } from 'modules/startioSystem.js';
3+
import { startioIdSubmodule } from 'modules/startioSystem.js';
4+
import { createEidsArray } from '../../../modules/userId/eids.js';
45

56
describe('StartIO ID System', function () {
67
let sandbox;
@@ -17,12 +18,6 @@ describe('StartIO ID System', function () {
1718
beforeEach(function () {
1819
sandbox = sinon.createSandbox();
1920
sandbox.stub(utils, 'logError');
20-
sandbox.stub(storage, 'getCookie').returns(null);
21-
sandbox.stub(storage, 'setCookie');
22-
sandbox.stub(storage, 'getDataFromLocalStorage').returns(null);
23-
sandbox.stub(storage, 'setDataInLocalStorage');
24-
sandbox.stub(storage, 'cookiesAreEnabled').returns(true);
25-
sandbox.stub(storage, 'localStorageIsEnabled').returns(true);
2621
});
2722

2823
afterEach(function () {
@@ -63,6 +58,24 @@ describe('StartIO ID System', function () {
6358
});
6459
});
6560

61+
describe('eid', function () {
62+
it('should generate correct EID', function () {
63+
const TEST_UID = 'test-uid-value';
64+
const eids = createEidsArray(startioIdSubmodule.decode(TEST_UID), new Map(Object.entries(startioIdSubmodule.eids)));
65+
expect(eids).to.eql([
66+
{
67+
source: 'start.io',
68+
uids: [
69+
{
70+
atype: 3,
71+
id: TEST_UID
72+
}
73+
]
74+
}
75+
]);
76+
});
77+
});
78+
6679
describe('getId', function () {
6780
it('should return callback and fire ajax even if no endpoint configured', function () {
6881
const config = { params: {} };
@@ -115,48 +128,6 @@ describe('StartIO ID System', function () {
115128
expect(callbackSpy.lastCall.lastArg).to.equal(serverId);
116129
});
117130

118-
it('should store new ID in both cookie and localStorage by default', function () {
119-
const callbackSpy = sinon.spy();
120-
const callback = startioIdSubmodule.getId(validConfig).callback;
121-
callback(callbackSpy);
122-
123-
const serverId = 'new-server-id-12345';
124-
server.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: serverId }));
125-
126-
expect(storage.setCookie.calledOnce).to.be.true;
127-
expect(storage.setCookie.args[0][0]).to.equal('startioId');
128-
expect(storage.setCookie.args[0][1]).to.equal(serverId);
129-
expect(storage.setDataInLocalStorage.calledOnce).to.be.true;
130-
expect(storage.setDataInLocalStorage.args[0][0]).to.equal('startioId');
131-
expect(storage.setDataInLocalStorage.args[0][1]).to.equal(serverId);
132-
});
133-
134-
it('should store only in cookie when storage type is cookie', function () {
135-
const config = { ...validConfig, storage: { ...validConfig.storage, type: 'cookie' } };
136-
const callbackSpy = sinon.spy();
137-
const callback = startioIdSubmodule.getId(config).callback;
138-
callback(callbackSpy);
139-
140-
const serverId = 'new-server-id-12345';
141-
server.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: serverId }));
142-
143-
expect(storage.setCookie.calledOnce).to.be.true;
144-
expect(storage.setDataInLocalStorage.called).to.be.false;
145-
});
146-
147-
it('should store only in localStorage when storage type is html5', function () {
148-
const config = { ...validConfig, storage: { ...validConfig.storage, type: 'html5' } };
149-
const callbackSpy = sinon.spy();
150-
const callback = startioIdSubmodule.getId(config).callback;
151-
callback(callbackSpy);
152-
153-
const serverId = 'new-server-id-12345';
154-
server.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: serverId }));
155-
156-
expect(storage.setCookie.called).to.be.false;
157-
expect(storage.setDataInLocalStorage.calledOnce).to.be.true;
158-
});
159-
160131
it('should log error if server response is missing id field', function () {
161132
const callbackSpy = sinon.spy();
162133
const callback = startioIdSubmodule.getId(validConfig).callback;
@@ -192,35 +163,5 @@ describe('StartIO ID System', function () {
192163
expect(utils.logError.calledOnce).to.be.true;
193164
expect(utils.logError.args[0][0]).to.include('encountered an error');
194165
});
195-
196-
it('should not store in cookie if cookies are disabled', function () {
197-
storage.cookiesAreEnabled.returns(false);
198-
199-
const callbackSpy = sinon.spy();
200-
const callback = startioIdSubmodule.getId(validConfig).callback;
201-
callback(callbackSpy);
202-
203-
const request = server.requests[0];
204-
const serverId = 'new-server-id-12345';
205-
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: serverId }));
206-
207-
expect(storage.setCookie.called).to.be.false;
208-
expect(storage.setDataInLocalStorage.calledOnce).to.be.true;
209-
});
210-
211-
it('should not store in localStorage if localStorage is disabled', function () {
212-
storage.localStorageIsEnabled.returns(false);
213-
214-
const callbackSpy = sinon.spy();
215-
const callback = startioIdSubmodule.getId(validConfig).callback;
216-
callback(callbackSpy);
217-
218-
const request = server.requests[0];
219-
const serverId = 'new-server-id-12345';
220-
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ id: serverId }));
221-
222-
expect(storage.setCookie.calledOnce).to.be.true;
223-
expect(storage.setDataInLocalStorage.called).to.be.false;
224-
});
225166
});
226167
});

0 commit comments

Comments
 (0)