'use strict' ; import { isObject } from './utils' ; import { isValidSD } from './events' ; import { logMessages } from './constants' ; import type { NetworkConfiguration , TrackerConfiguration , SessionConfiguration , EmitterConfiguration , SubjectConfiguration , GdprConfiguration , GCConfiguration , GlobalContext , InitTrackerConfiguration } from './types' ; /**
 * Configuration properties
 */ const networkProps = [ 'endpoint' , 'method' ] ; const trackerProps = [ 'appId' , 'devicePlatform' , 'base64Encoding' , 'logLevel' , 'applicationContext' , 'platformContext' , 'geoLocationContext' , 'sessionContext' , 'screenContext' , 'screenViewAutotracking' , 'lifecycleAutotracking' , 'installAutotracking' , 'exceptionAutotracking' , 'diagnosticAutotracking' ] ; const sessionProps = [ 'foregroundTimeout' , 'backgroundTimeout' ] ; const emitterProps = [ 'bufferOption' , 'emitRange' , 'threadPoolSize' , 'byteLimitPost' , 'byteLimitGet' , ] ; const subjectProps = [ 'userId' , 'networkUserId' , 'domainUserId' , 'useragent' , 'ipAddress' , 'timezone' , 'language' , 'screenResolution' , 'screenViewport' , 'colorDepth' ] ; const gdprProps = [ 'basisForProcessing' , 'documentId' , 'documentVersion' , 'documentDescription' ] ; const gcProps = [ 'tag' , 'globalContexts' ] ; param config { Object } param defaultKeys { Array } returns function isValidConfig < Type > ( config , defaultKeys ) { return Object . keys ( config ) . every ( key => defaultKeys . includes ( key ) ) ; } param config { Object } returns function isValidNetworkConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , networkProps ) || typeof config . endpoint !== 'string' || ! config . endpoint ) { return false ; } return true ; } param config { Object } returns function isValidTrackerConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , trackerProps ) ) { return false ; } return true ; } param config { Object } returns function isValidSessionConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , sessionProps ) || ! sessionProps . every ( key => Object . keys ( config as SessionConfiguration ) . includes ( key ) ) ) { return false ; } return true ; } param config { Object } returns function isValidEmitterConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , emitterProps ) ) { return false ; } return true ; } param arr { Object } returns function isScreenSize < Type > ( arr ) { return Array . isArray ( arr ) && arr . length === 2 && arr . every ( < Type > ( n ) => typeof n === 'number' ) ; } param config { Object } returns function isValidSubjectConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , subjectProps ) ) { return false ; } if ( Object . prototype . hasOwnProperty . call ( config , 'screenResolution' ) && config . screenResolution !== null && ! isScreenSize ( config . screenResolution as unknown ) ) { return false ; } if ( Object . prototype . hasOwnProperty . call ( config , 'screenViewport' ) && config . screenViewport !== null && ! isScreenSize ( config . screenViewport as unknown ) ) { return false ; } return true ; } param config { Object } returns function isValidGdprConf ( config ) { if ( ! isObject ( config ) || ! isValidConfig ( config , gdprProps ) || ! gdprProps . every ( key => Object . keys ( config as GdprConfiguration ) . includes ( key ) ) || ! [ 'consent' , 'contract' , 'legal_obligation' , 'legitimate_interests' , 'public_task' , 'vital_interests' ] . includes ( config . basisForProcessing ) ) { return false ; } return true ; } param gc { Object } returns function isValidGC ( gc ) { return isObject ( gc ) && isValidConfig ( gc , gcProps ) && typeof gc . tag === 'string' && Array . isArray ( gc . globalContexts ) && gc . globalContexts . every ( c => isValidSD ( c ) ) ; } param config { Object } returns function isValidGCConf ( config ) { if ( ! Array . isArray ( config ) ) { return false ; } if ( ! config . every ( gc => isValidGC ( gc as GlobalContext ) ) ) { return false ; } return true ; } param init { Object } returns function initValidate ( init ) { if ( typeof init . namespace !== 'string' || ! init . namespace ) { return Promise . reject ( new Error ( logMessages . namespace ) ) ; } if ( ! Object . prototype . hasOwnProperty . call ( init , 'networkConfig' ) || ! isValidNetworkConf ( init . networkConfig as NetworkConfiguration ) ) { return Promise . reject ( new Error ( logMessages . network ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'trackerConfig' ) && ! isValidTrackerConf ( init . trackerConfig as TrackerConfiguration ) ) { return Promise . reject ( new Error ( logMessages . tracker ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'sessionConfig' ) && ( ! isValidSessionConf ( init . sessionConfig as SessionConfiguration ) ) ) { return Promise . reject ( new Error ( logMessages . session ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'emitterConfig' ) && ! isValidEmitterConf ( init . emitterConfig as EmitterConfiguration ) ) { return Promise . reject ( new Error ( logMessages . emitter ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'subjectConfig' ) && ! isValidSubjectConf ( init . subjectConfig as SubjectConfiguration ) ) { return Promise . reject ( new Error ( logMessages . subject ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'gdprConfig' ) && ! isValidGdprConf ( init . gdprConfig as GdprConfiguration ) ) { return Promise . reject ( new Error ( logMessages . gdpr ) ) ; } if ( Object . prototype . hasOwnProperty . call ( init , 'gcConfig' ) && ! isValidGCConf ( init . gcConfig as GCConfiguration ) ) { return Promise . reject ( new Error ( logMessages . gc ) ) ; } return Promise . resolve ( true ) ; } export { isValidNetworkConf , isValidTrackerConf , isValidSessionConf , isValidEmitterConf , isValidSubjectConf , isValidGdprConf , isValidGCConf , isValidGC , isScreenSize , initValidate , } ;