Skip to content

Commit

Permalink
cleanup and sqaush
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Palladino committed Jul 2, 2024
1 parent ef6c09e commit 70d3afe
Show file tree
Hide file tree
Showing 6 changed files with 4,496 additions and 4,422 deletions.
1 change: 1 addition & 0 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"reconciliationRtdProvider",
"relevadRtdProvider",
"sirdataRtdProvider",
"symitriDapRtdProvider",
"timeoutRtdProvider",
"weboramaRtdProvider"
],
Expand Down
17 changes: 9 additions & 8 deletions modules/akamaiDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
* @requires module:modules/realTimeData
*/

import {
import {
createRtdProvider
} from './symitriDapRtdProvider'/* eslint prebid/validate-imports: "off" */
} from './symitriDapRtdProvider.js'/* eslint prebid/validate-imports: "off" */

export const {
addRealTimeData,
getRealTimeData,
generateRealTimeData,
rtdSubmodule: akamaiDapRtdSubmodule,
export const {
addRealTimeData,
getRealTimeData,
generateRealTimeData,
rtdSubmodule: akamaiDapRtdSubmodule,
storage,
dapUtils,
DAP_TOKEN,
DAP_MEMBERSHIP,
DAP_ENCRYPTED_MEMBERSHIP,
DAP_SS_ID,
DAP_DEFAULT_TOKEN_TTL,
DAP_MAX_RETRY_TOKENIZE,
DAP_CLIENT_ENTROPY
} = createRtdProvider('dap');
} = createRtdProvider('dap', 'akamaidap', 'Akamai');
182 changes: 85 additions & 97 deletions modules/symitriDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import {MODULE_TYPE_RTD} from '../src/activities/modules.js';
/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
*/

export function createRtdProvider(moduleName) {

export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
const MODULE_NAME = 'realTimeData';
const SUBMODULE_NAME = 'dap';
const MODULE_CODE = 'symitri';
const SUBMODULE_NAME = moduleName;
const MODULE_CODE = moduleCode;

const DAP_TOKEN = 'async_dap_token';
const DAP_MEMBERSHIP = 'async_dap_membership';
Expand Down Expand Up @@ -70,7 +68,7 @@ export function createRtdProvider(moduleName) {
* @param {Object} rtdConfig
* @param {Object} userConsent
*/
export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
let entropyDict = JSON.parse(storage.getDataFromLocalStorage(DAP_CLIENT_ENTROPY));
let loadScriptPromise = new Promise((resolve, reject) => {
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) {
Expand Down Expand Up @@ -145,13 +143,13 @@ export function createRtdProvider(moduleName) {
}

/** @type {RtdSubmodule} */
const symitriDapRtdSubmodule = {
const rtdSubmodule = {
name: SUBMODULE_NAME,
getBidRequestData: getRealTimeData,
init: init
};

submodule(MODULE_NAME, symitriDapRtdSubmodule);
submodule(MODULE_NAME, rtdSubmodule);
const dapUtils = {

callDapAPIs: function(bidConfig, onDone, rtdConfig, userConsent) {
Expand Down Expand Up @@ -215,11 +213,11 @@ export function createRtdProvider(moduleName) {
item.token = token;
storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(item));
dapUtils.dapLog('Successfully updated and stored token; expires at ' + item.expires_at);
let dapSSID = xhr.getResponseHeader('Symitri-DAP-SS-ID');
let dapSSID = xhr.getResponseHeader(headerPrefix + '-DAP-SS-ID');
if (dapSSID) {
storage.setDataInLocalStorage(DAP_SS_ID, JSON.stringify(dapSSID));
}
let deviceId100 = xhr.getResponseHeader('Symitri-DAP-100');
let deviceId100 = xhr.getResponseHeader(headerPrefix + '-DAP-100');
if (deviceId100 != null) {
storage.setDataInLocalStorage('dap_deviceId100', deviceId100);
dapUtils.dapLog('Successfully stored DAP 100 Device ID: ' + deviceId100);
Expand Down Expand Up @@ -494,6 +492,40 @@ export function createRtdProvider(moduleName) {
*
******************************************************************************/

dapValidationHelper: function(config, onDone, token, onError) {
if (onError == null) {
onError = function(xhr, status, error, onDone) {};
}

if (config == null || typeof (config) == typeof (undefined)) {
onError(null, 'Invalid config object', 'ClientError', onDone);
return [ config, true ];
}

if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
config.api_version = 'x1';
}

if (typeof (config.api_version) != 'string') {
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
return [ config, true ];
}

if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
return [ config, true ];
}

if (token) {
if (typeof (token) != 'string') {
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
return [ config, true ];
}
}

return [ config, false ];
},

/**
* SYNOPSIS
*
Expand Down Expand Up @@ -534,14 +566,9 @@ export function createRtdProvider(moduleName) {
* function( xhr, status, error ) { ; } // handle error
*/
dapTokenize: function(config, identity, onDone, onSuccess = null, onError = null) {
if (onError == null) {
onError = function(xhr, status, error, onDone) {};
}

if (config == null || typeof (config) == typeof (undefined)) {
onError(null, 'Invalid config object', 'ClientError', onDone);
return;
}
let hasTokenizeError;
[ config, hasTokenizeError ] = this.dapValidationHelper(config, onDone, null, onError);
if (hasTokenizeError) { return; }

if (typeof (config.domain) != 'string') {
onError(null, 'Invalid config.domain: must be a string', 'ClientError', onDone);
Expand All @@ -553,20 +580,6 @@ export function createRtdProvider(moduleName) {
return;
}

if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
config.api_version = 'x1';
}

if (typeof (config.api_version) != 'string') {
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
return;
}

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

if (identity == null || typeof (identity) == typeof (undefined)) {
onError(null, 'Invalid identity object', 'ClientError', onDone);
return;
Expand Down Expand Up @@ -611,7 +624,7 @@ export function createRtdProvider(moduleName) {
let customHeaders = {'Content-Type': 'application/json'};
let dapSSID = JSON.parse(storage.getDataFromLocalStorage(DAP_SS_ID));
if (dapSSID) {
customHeaders['Symitri-DAP-SS-ID'] = dapSSID;
customHeaders[headerPrefix + '-DAP-SS-ID'] = dapSSID;
}

let url = 'https://' + config.api_hostname + path;
Expand All @@ -621,7 +634,7 @@ export function createRtdProvider(moduleName) {
switch (config.api_version) {
case 'x1':
case 'x1-dev':
token = request.getResponseHeader('Symitri-DAP-Token');
token = request.getResponseHeader(headerPrefix + '-DAP-Token');
break;
}
onSuccess(token, request.status, request, onDone);
Expand Down Expand Up @@ -671,33 +684,15 @@ export function createRtdProvider(moduleName) {
*
*/
dapMembership: function(config, token, onDone, onSuccess = null, onError = null) {
if (onError == null) {
onError = function(xhr, status, error, onDone) {};
}
let hasMembershipError;
[ config, hasMembershipError ] = this.dapValidationHelper(config, onDone, token, onError);
if (hasMembershipError) { return; }

if (config == null || typeof (config) == typeof (undefined)) {
onError(null, 'Invalid config object', 'ClientError', onDone);
return;
}

if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
config.api_version = 'x1';
}

if (typeof (config.api_version) != 'string') {
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
return;
}

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

if (token == null || typeof (token) != 'string') {
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
return;
}
let path = '/data-activation/' +
config.api_version +
'/token/' + token +
Expand Down Expand Up @@ -754,49 +749,25 @@ export function createRtdProvider(moduleName) {
*
*/
dapEncryptedMembership: function(config, token, onDone, onSuccess = null, onError = null) {
if (onError == null) {
onError = function(xhr, status, error, onDone) {};
}

if (config == null || typeof (config) == typeof (undefined)) {
onError(null, 'Invalid config object', 'ClientError', onDone);
return;
}
let hasEncryptedMembershipError;
[ config, hasEncryptedMembershipError ] = this.dapValidationHelper(config, onDone, token, onError);
if (hasEncryptedMembershipError) { return; }

if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) {
config.api_version = 'x1';
}

if (typeof (config.api_version) != 'string') {
onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError', onDone);
return;
}

if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) {
onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError', onDone);
return;
}
let cb = {
success: (response, request) => {
let encToken = request.getResponseHeader(headerPrefix + '-DAP-Token');
onSuccess(encToken, request.status, request, onDone);
},
error: (error, request) => { onError(request, request.status, error, onDone); }
};

if (token == null || typeof (token) != 'string') {
onError(null, 'Invalid token: must be a non-null string', 'ClientError', onDone);
return;
}
let path = '/data-activation/' +
config.api_version +
'/token/' + token +
'/membership/encrypt';

let url = 'https://' + config.api_hostname + path;

let cb = {
success: (response, request) => {
let encToken = request.getResponseHeader('Symitri-DAP-Token');
onSuccess(encToken, request.status, request, onDone);
},
error: (error, request) => {
onError(request, request.status, error, onDone);
}
};
ajax(url, cb, undefined, {
method: 'GET',
customHeaders: {
Expand All @@ -806,19 +777,36 @@ export function createRtdProvider(moduleName) {
});
}
}

return {
addRealTimeData,
getRealTimeData,
generateRealTimeData,
rtdSubmodule,
storage,
dapUtils,
DAP_TOKEN,
DAP_MEMBERSHIP,
DAP_ENCRYPTED_MEMBERSHIP,
DAP_SS_ID,
DAP_DEFAULT_TOKEN_TTL,
DAP_MAX_RETRY_TOKENIZE,
DAP_CLIENT_ENTROPY
};
}

export const {
addRealTimeData,
getRealTimeData,
generateRealTimeData,
rtdSubmodule: akamaiDapRtdSubmodule,
export const {
addRealTimeData,
getRealTimeData,
generateRealTimeData,
rtdSubmodule: symitriDapRtdSubmodule,
storage,
dapUtils,
DAP_TOKEN,
DAP_MEMBERSHIP,
DAP_ENCRYPTED_MEMBERSHIP,
DAP_SS_ID,
DAP_DEFAULT_TOKEN_TTL,
DAP_MAX_RETRY_TOKENIZE,
DAP_CLIENT_ENTROPY
} = createRtdProvider('symitriDap');
} = createRtdProvider('symitriDap', 'symitridap', 'Symitri');
Loading

0 comments on commit 70d3afe

Please sign in to comment.