@@ -15,12 +15,10 @@ import {MODULE_TYPE_RTD} from '../src/activities/modules.js';
15
15
/**
16
16
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule } RtdSubmodule
17
17
*/
18
-
19
- export function createRtdProvider ( moduleName ) {
20
-
18
+ export function createRtdProvider ( moduleName , moduleCode , headerPrefix ) {
21
19
const MODULE_NAME = 'realTimeData' ;
22
- const SUBMODULE_NAME = 'dap' ;
23
- const MODULE_CODE = 'symitri' ;
20
+ const SUBMODULE_NAME = moduleName ;
21
+ const MODULE_CODE = moduleCode ;
24
22
25
23
const DAP_TOKEN = 'async_dap_token' ;
26
24
const DAP_MEMBERSHIP = 'async_dap_membership' ;
@@ -70,7 +68,7 @@ export function createRtdProvider(moduleName) {
70
68
* @param {Object } rtdConfig
71
69
* @param {Object } userConsent
72
70
*/
73
- export function getRealTimeData ( bidConfig , onDone , rtdConfig , userConsent ) {
71
+ function getRealTimeData ( bidConfig , onDone , rtdConfig , userConsent ) {
74
72
let entropyDict = JSON . parse ( storage . getDataFromLocalStorage ( DAP_CLIENT_ENTROPY ) ) ;
75
73
let loadScriptPromise = new Promise ( ( resolve , reject ) => {
76
74
if ( rtdConfig && rtdConfig . params && rtdConfig . params . dapEntropyTimeout && Number . isInteger ( rtdConfig . params . dapEntropyTimeout ) ) {
@@ -145,13 +143,13 @@ export function createRtdProvider(moduleName) {
145
143
}
146
144
147
145
/** @type {RtdSubmodule } */
148
- const symitriDapRtdSubmodule = {
146
+ const rtdSubmodule = {
149
147
name : SUBMODULE_NAME ,
150
148
getBidRequestData : getRealTimeData ,
151
149
init : init
152
150
} ;
153
151
154
- submodule ( MODULE_NAME , symitriDapRtdSubmodule ) ;
152
+ submodule ( MODULE_NAME , rtdSubmodule ) ;
155
153
const dapUtils = {
156
154
157
155
callDapAPIs : function ( bidConfig , onDone , rtdConfig , userConsent ) {
@@ -215,11 +213,11 @@ export function createRtdProvider(moduleName) {
215
213
item . token = token ;
216
214
storage . setDataInLocalStorage ( DAP_TOKEN , JSON . stringify ( item ) ) ;
217
215
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') ;
219
217
if ( dapSSID ) {
220
218
storage . setDataInLocalStorage ( DAP_SS_ID , JSON . stringify ( dapSSID ) ) ;
221
219
}
222
- let deviceId100 = xhr . getResponseHeader ( 'Symitri -DAP-100') ;
220
+ let deviceId100 = xhr . getResponseHeader ( headerPrefix + ' -DAP-100') ;
223
221
if ( deviceId100 != null ) {
224
222
storage . setDataInLocalStorage ( 'dap_deviceId100' , deviceId100 ) ;
225
223
dapUtils . dapLog ( 'Successfully stored DAP 100 Device ID: ' + deviceId100 ) ;
@@ -494,6 +492,41 @@ export function createRtdProvider(moduleName) {
494
492
*
495
493
******************************************************************************/
496
494
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
+
497
530
/**
498
531
* SYNOPSIS
499
532
*
@@ -534,14 +567,9 @@ export function createRtdProvider(moduleName) {
534
567
* function( xhr, status, error ) { ; } // handle error
535
568
*/
536
569
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 ; }
545
573
546
574
if ( typeof ( config . domain ) != 'string' ) {
547
575
onError ( null , 'Invalid config.domain: must be a string' , 'ClientError' , onDone ) ;
@@ -553,20 +581,6 @@ export function createRtdProvider(moduleName) {
553
581
return ;
554
582
}
555
583
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
-
570
584
if ( identity == null || typeof ( identity ) == typeof ( undefined ) ) {
571
585
onError ( null , 'Invalid identity object' , 'ClientError' , onDone ) ;
572
586
return ;
@@ -611,7 +625,7 @@ export function createRtdProvider(moduleName) {
611
625
let customHeaders = { 'Content-Type' : 'application/json' } ;
612
626
let dapSSID = JSON . parse ( storage . getDataFromLocalStorage ( DAP_SS_ID ) ) ;
613
627
if ( dapSSID ) {
614
- customHeaders [ 'Symitri -DAP-SS-ID'] = dapSSID ;
628
+ customHeaders [ headerPrefix + ' -DAP-SS-ID'] = dapSSID ;
615
629
}
616
630
617
631
let url = 'https://' + config . api_hostname + path ;
@@ -621,7 +635,7 @@ export function createRtdProvider(moduleName) {
621
635
switch ( config . api_version ) {
622
636
case 'x1' :
623
637
case 'x1-dev' :
624
- token = request . getResponseHeader ( 'Symitri -DAP-Token') ;
638
+ token = request . getResponseHeader ( headerPrefix + ' -DAP-Token') ;
625
639
break ;
626
640
}
627
641
onSuccess ( token , request . status , request , onDone ) ;
@@ -671,33 +685,15 @@ export function createRtdProvider(moduleName) {
671
685
*
672
686
*/
673
687
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 ; }
691
691
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 ) ;
694
694
return ;
695
695
}
696
696
697
- if ( token == null || typeof ( token ) != 'string' ) {
698
- onError ( null , 'Invalid token: must be a non-null string' , 'ClientError' , onDone ) ;
699
- return ;
700
- }
701
697
let path = '/data-activation/' +
702
698
config . api_version +
703
699
'/token/' + token +
@@ -754,33 +750,10 @@ export function createRtdProvider(moduleName) {
754
750
*
755
751
*/
756
752
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 ; }
760
756
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
- }
784
757
let path = '/data-activation/' +
785
758
config . api_version +
786
759
'/token/' + token +
@@ -790,13 +763,12 @@ export function createRtdProvider(moduleName) {
790
763
791
764
let cb = {
792
765
success : ( response , request ) => {
793
- let encToken = request . getResponseHeader ( 'Symitri -DAP-Token') ;
766
+ let encToken = request . getResponseHeader ( headerPrefix + ' -DAP-Token') ;
794
767
onSuccess ( encToken , request . status , request , onDone ) ;
795
768
} ,
796
- error : ( error , request ) => {
797
- onError ( request , request . status , error , onDone ) ;
798
- }
769
+ error : ( error , request ) => { onError ( request , request . status , error , onDone ) ; }
799
770
} ;
771
+
800
772
ajax ( url , cb , undefined , {
801
773
method : 'GET' ,
802
774
customHeaders : {
@@ -806,19 +778,36 @@ export function createRtdProvider(moduleName) {
806
778
} ) ;
807
779
}
808
780
}
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
+ } ;
809
797
}
810
798
811
- export const {
812
- addRealTimeData,
813
- getRealTimeData,
814
- generateRealTimeData,
815
- rtdSubmodule : akamaiDapRtdSubmodule ,
799
+ export const {
800
+ addRealTimeData,
801
+ getRealTimeData,
802
+ generateRealTimeData,
803
+ rtdSubmodule : symitriDapRtdSubmodule ,
816
804
storage,
805
+ dapUtils,
817
806
DAP_TOKEN ,
818
807
DAP_MEMBERSHIP ,
819
808
DAP_ENCRYPTED_MEMBERSHIP ,
820
809
DAP_SS_ID ,
821
810
DAP_DEFAULT_TOKEN_TTL ,
822
811
DAP_MAX_RETRY_TOKENIZE ,
823
812
DAP_CLIENT_ENTROPY
824
- } = createRtdProvider ( 'symitriDap' ) ;
813
+ } = createRtdProvider ( 'symitriDap' , 'symitridap' , 'Symitri' ) ;
0 commit comments