Skip to content

Commit 6b8e3c3

Browse files
author
Jeff Palladino
committed
cleanup and sqaush
1 parent 8af4870 commit 6b8e3c3

File tree

6 files changed

+4493
-4418
lines changed

6 files changed

+4493
-4418
lines changed

modules/.submodules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"reconciliationRtdProvider",
9898
"relevadRtdProvider",
9999
"sirdataRtdProvider",
100+
"symitriDapRtdProvider",
100101
"timeoutRtdProvider",
101102
"weboramaRtdProvider"
102103
],

modules/akamaiDapRtdProvider.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
* @requires module:modules/realTimeData
77
*/
88

9-
import {
9+
import {
1010
createRtdProvider
11-
} from './symitriDapRtdProvider'/* eslint prebid/validate-imports: "off" */
11+
} from './symitriDapRtdProvider.js'/* eslint prebid/validate-imports: "off" */
1212

13-
export const {
14-
addRealTimeData,
15-
getRealTimeData,
16-
generateRealTimeData,
17-
rtdSubmodule: akamaiDapRtdSubmodule,
13+
export const {
14+
addRealTimeData,
15+
getRealTimeData,
16+
generateRealTimeData,
17+
rtdSubmodule: akamaiDapRtdSubmodule,
1818
storage,
19+
dapUtils,
1920
DAP_TOKEN,
2021
DAP_MEMBERSHIP,
2122
DAP_ENCRYPTED_MEMBERSHIP,
2223
DAP_SS_ID,
2324
DAP_DEFAULT_TOKEN_TTL,
2425
DAP_MAX_RETRY_TOKENIZE,
2526
DAP_CLIENT_ENTROPY
26-
} = createRtdProvider('dap');
27+
} = createRtdProvider('dap', 'akamaidap', 'Akamai');

modules/symitriDapRtdProvider.js

Lines changed: 82 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ import {MODULE_TYPE_RTD} from '../src/activities/modules.js';
1515
/**
1616
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
1717
*/
18-
19-
export function createRtdProvider(moduleName) {
20-
18+
export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
2119
const MODULE_NAME = 'realTimeData';
22-
const SUBMODULE_NAME = 'dap';
23-
const MODULE_CODE = 'symitri';
20+
const SUBMODULE_NAME = moduleName;
21+
const MODULE_CODE = moduleCode;
2422

2523
const DAP_TOKEN = 'async_dap_token';
2624
const DAP_MEMBERSHIP = 'async_dap_membership';
@@ -70,7 +68,7 @@ export function createRtdProvider(moduleName) {
7068
* @param {Object} rtdConfig
7169
* @param {Object} userConsent
7270
*/
73-
export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
71+
function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
7472
let entropyDict = JSON.parse(storage.getDataFromLocalStorage(DAP_CLIENT_ENTROPY));
7573
let loadScriptPromise = new Promise((resolve, reject) => {
7674
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) {
@@ -145,13 +143,13 @@ export function createRtdProvider(moduleName) {
145143
}
146144

147145
/** @type {RtdSubmodule} */
148-
const symitriDapRtdSubmodule = {
146+
const rtdSubmodule = {
149147
name: SUBMODULE_NAME,
150148
getBidRequestData: getRealTimeData,
151149
init: init
152150
};
153151

154-
submodule(MODULE_NAME, symitriDapRtdSubmodule);
152+
submodule(MODULE_NAME, rtdSubmodule);
155153
const dapUtils = {
156154

157155
callDapAPIs: function(bidConfig, onDone, rtdConfig, userConsent) {
@@ -215,11 +213,11 @@ export function createRtdProvider(moduleName) {
215213
item.token = token;
216214
storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(item));
217215
dapUtils.dapLog('Successfully updated and stored token; expires at ' + item.expires_at);
218-
let dapSSID = xhr.getResponseHeader('Symitri-DAP-SS-ID');
216+
let dapSSID = xhr.getResponseHeader(headerPrefix + '-DAP-SS-ID');
219217
if (dapSSID) {
220218
storage.setDataInLocalStorage(DAP_SS_ID, JSON.stringify(dapSSID));
221219
}
222-
let deviceId100 = xhr.getResponseHeader('Symitri-DAP-100');
220+
let deviceId100 = xhr.getResponseHeader(headerPrefix + '-DAP-100');
223221
if (deviceId100 != null) {
224222
storage.setDataInLocalStorage('dap_deviceId100', deviceId100);
225223
dapUtils.dapLog('Successfully stored DAP 100 Device ID: ' + deviceId100);
@@ -494,6 +492,41 @@ export function createRtdProvider(moduleName) {
494492
*
495493
******************************************************************************/
496494

495+
dapValidationHelper: function(config, onDone, token, onError) {
496+
497+
if (onError == null) {
498+
onError = function(xhr, status, error, onDone) {};
499+
}
500+
501+
if (config == null || typeof (config) == typeof (undefined)) {
502+
onError(null, 'Invalid config object', 'ClientError', onDone);
503+
return [ config, true ];
504+
}
505+
506+
if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
507+
config.api_version = 'x1';
508+
}
509+
510+
if (typeof (config.api_version) != 'string') {
511+
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
512+
return [ config, true ];
513+
}
514+
515+
if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
516+
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
517+
return [ config, true ];
518+
}
519+
520+
if (token) {
521+
if (typeof (token) != 'string') {
522+
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
523+
return [ config, true ];
524+
}
525+
}
526+
527+
return [ config, false ];
528+
},
529+
497530
/**
498531
* SYNOPSIS
499532
*
@@ -534,14 +567,9 @@ export function createRtdProvider(moduleName) {
534567
* function( xhr, status, error ) { ; } // handle error
535568
*/
536569
dapTokenize: function(config, identity, onDone, onSuccess = null, onError = null) {
537-
if (onError == null) {
538-
onError = function(xhr, status, error, onDone) {};
539-
}
540-
541-
if (config == null || typeof (config) == typeof (undefined)) {
542-
onError(null, 'Invalid config object', 'ClientError', onDone);
543-
return;
544-
}
570+
let hasTokenizeError;
571+
[ config, hasTokenizeError ] = this.dapValidationHelper(config, onDone, null, onError);
572+
if (hasTokenizeError) {return;}
545573

546574
if (typeof (config.domain) != 'string') {
547575
onError(null, 'Invalid config.domain: must be a string', 'ClientError', onDone);
@@ -553,20 +581,6 @@ export function createRtdProvider(moduleName) {
553581
return;
554582
}
555583

556-
if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
557-
config.api_version = 'x1';
558-
}
559-
560-
if (typeof (config.api_version) != 'string') {
561-
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
562-
return;
563-
}
564-
565-
if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
566-
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
567-
return;
568-
}
569-
570584
if (identity == null || typeof (identity) == typeof (undefined)) {
571585
onError(null, 'Invalid identity object', 'ClientError', onDone);
572586
return;
@@ -611,7 +625,7 @@ export function createRtdProvider(moduleName) {
611625
let customHeaders = {'Content-Type': 'application/json'};
612626
let dapSSID = JSON.parse(storage.getDataFromLocalStorage(DAP_SS_ID));
613627
if (dapSSID) {
614-
customHeaders['Symitri-DAP-SS-ID'] = dapSSID;
628+
customHeaders[headerPrefix + '-DAP-SS-ID'] = dapSSID;
615629
}
616630

617631
let url = 'https://' + config.api_hostname + path;
@@ -621,7 +635,7 @@ export function createRtdProvider(moduleName) {
621635
switch (config.api_version) {
622636
case 'x1':
623637
case 'x1-dev':
624-
token = request.getResponseHeader('Symitri-DAP-Token');
638+
token = request.getResponseHeader(headerPrefix + '-DAP-Token');
625639
break;
626640
}
627641
onSuccess(token, request.status, request, onDone);
@@ -671,33 +685,15 @@ export function createRtdProvider(moduleName) {
671685
*
672686
*/
673687
dapMembership: function(config, token, onDone, onSuccess = null, onError = null) {
674-
if (onError == null) {
675-
onError = function(xhr, status, error, onDone) {};
676-
}
677-
678-
if (config == null || typeof (config) == typeof (undefined)) {
679-
onError(null, 'Invalid config object', 'ClientError', onDone);
680-
return;
681-
}
682-
683-
if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
684-
config.api_version = 'x1';
685-
}
686-
687-
if (typeof (config.api_version) != 'string') {
688-
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
689-
return;
690-
}
688+
let hasMembershipError;
689+
[ config, hasMembershipError ] = this.dapValidationHelper(config, onDone, token, onError);
690+
if (hasMembershipError) {return;}
691691

692-
if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
693-
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
692+
if (typeof (config.domain) != 'string') {
693+
onError(null, 'Invalid config.domain: must be a string', 'ClientError', onDone);
694694
return;
695695
}
696696

697-
if (token == null || typeof (token) != 'string') {
698-
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
699-
return;
700-
}
701697
let path = '/data-activation/' +
702698
config.api_version +
703699
'/token/' + token +
@@ -754,33 +750,10 @@ export function createRtdProvider(moduleName) {
754750
*
755751
*/
756752
dapEncryptedMembership: function(config, token, onDone, onSuccess = null, onError = null) {
757-
if (onError == null) {
758-
onError = function(xhr, status, error, onDone) {};
759-
}
753+
let hasEncryptedMembershipError;
754+
[ config, hasEncryptedMembershipError ] = this.dapValidationHelper(config, onDone, token, onError);
755+
if (hasEncryptedMembershipError) {return;}
760756

761-
if (config == null || typeof (config) == typeof (undefined)) {
762-
onError(null, 'Invalid config object', 'ClientError', onDone);
763-
return;
764-
}
765-
766-
if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
767-
config.api_version = 'x1';
768-
}
769-
770-
if (typeof (config.api_version) != 'string') {
771-
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
772-
return;
773-
}
774-
775-
if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
776-
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
777-
return;
778-
}
779-
780-
if (token == null || typeof (token) != 'string') {
781-
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
782-
return;
783-
}
784757
let path = '/data-activation/' +
785758
config.api_version +
786759
'/token/' + token +
@@ -790,13 +763,12 @@ export function createRtdProvider(moduleName) {
790763

791764
let cb = {
792765
success: (response, request) => {
793-
let encToken = request.getResponseHeader('Symitri-DAP-Token');
766+
let encToken = request.getResponseHeader(headerPrefix + '-DAP-Token');
794767
onSuccess(encToken, request.status, request, onDone);
795768
},
796-
error: (error, request) => {
797-
onError(request, request.status, error, onDone);
798-
}
769+
error: (error, request) => {onError(request, request.status, error, onDone);}
799770
};
771+
800772
ajax(url, cb, undefined, {
801773
method: 'GET',
802774
customHeaders: {
@@ -806,19 +778,36 @@ export function createRtdProvider(moduleName) {
806778
});
807779
}
808780
}
781+
782+
return {
783+
addRealTimeData,
784+
getRealTimeData,
785+
generateRealTimeData,
786+
rtdSubmodule,
787+
storage,
788+
dapUtils,
789+
DAP_TOKEN,
790+
DAP_MEMBERSHIP,
791+
DAP_ENCRYPTED_MEMBERSHIP,
792+
DAP_SS_ID,
793+
DAP_DEFAULT_TOKEN_TTL,
794+
DAP_MAX_RETRY_TOKENIZE,
795+
DAP_CLIENT_ENTROPY
796+
};
809797
}
810798

811-
export const {
812-
addRealTimeData,
813-
getRealTimeData,
814-
generateRealTimeData,
815-
rtdSubmodule: akamaiDapRtdSubmodule,
799+
export const {
800+
addRealTimeData,
801+
getRealTimeData,
802+
generateRealTimeData,
803+
rtdSubmodule: symitriDapRtdSubmodule,
816804
storage,
805+
dapUtils,
817806
DAP_TOKEN,
818807
DAP_MEMBERSHIP,
819808
DAP_ENCRYPTED_MEMBERSHIP,
820809
DAP_SS_ID,
821810
DAP_DEFAULT_TOKEN_TTL,
822811
DAP_MAX_RETRY_TOKENIZE,
823812
DAP_CLIENT_ENTROPY
824-
} = createRtdProvider('symitriDap');
813+
} = createRtdProvider('symitriDap', 'symitridap', 'Symitri');

0 commit comments

Comments
 (0)