All files / State/Shared/Util ingestGlobalConfigFromEnvironment.js

100% Statements 17/17
75% Branches 3/4
100% Functions 4/4
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x               315x   1x   1x 13x   13x 10x   3x     13x     1x 6x   6x     6x                                                                
import pathOr from 'ramda/src/pathOr';
import partial from 'ramda/src/partial';
 
/**
 * @param {string[]} path,
 * @param {any} [default='']
 * @return {any}
 */
 
const ingestGlobalProp = (...path) => pathOr('', ['dazn', ...path], window);
 
const ingestServiceDictionaryProp = partial(ingestGlobalProp, ['startupData', 'ServiceDictionary']);
 
const isPersonalisationEnabled = () => {
    let hasOptedOut = ingestGlobalProp('userProfile', 'Preferences', 'OptedOutFromPersonalisation');
 
    if (typeof hasOptedOut === 'string') {
        hasOptedOut = hasOptedOut === 'true';
    } else {
        hasOptedOut = Boolean(hasOptedOut);
    }
 
    return !hasOptedOut;
};
 
const isCaptionsEnabled = () => {
    const enableClosedCaptions = ingestGlobalProp('dazn', 'startupData', 'FeatureToggles', 'ClosedCaptionsV1');
 
    return enableClosedCaptions === '' ? false : enableClosedCaptions;
};
 
const ingestGlobalConfigFromEnvironment = () => ({
    serviceUrls: {
        playback: ingestServiceDictionaryProp('Playback', 'Versions', 'v2', 'ServicePath'),
        resumePoints: ingestServiceDictionaryProp('ResumePoint', 'Versions', 'v1', 'ServicePath'),
        precision: ingestServiceDictionaryProp('PlaybackPrecision', 'Versions', 'v1', 'ServicePath'),
        userActions: ingestServiceDictionaryProp('UserActions', 'Versions', 'v1', 'ServicePath'),
        userActionsWatched: `${ingestServiceDictionaryProp('UserActions', 'Versions', 'v1', 'ServicePath')}/watched`,
    },
    environment: {
        manufacturer: ingestGlobalProp('manufacturer'),
        platform: ingestGlobalProp('platform'),
        viewerId: ingestGlobalProp('userProfile', 'ViewerId'),
        language: ingestGlobalProp('userProfile', 'UserLanguageLocaleKey'),
        personalisationEnabled: isPersonalisationEnabled(),
    },
    analytics: {
        convivaCustomerKey: ingestGlobalProp('startupData', 'Conviva', 'CustomerKey'),
    },
    text: {
        liveLabel: ingestGlobalProp('resourceStringsData', 'Strings', 'player_live'),
    },
    captions: {
        enable: isCaptionsEnabled(),
    },
});
 
export {
    ingestGlobalConfigFromEnvironment as default,
    ingestGlobalProp,
    ingestServiceDictionaryProp,
    isPersonalisationEnabled,
};