import * as Cfg from '../config' ; import * as Alerts from '../alerts' ; import { FF_PREFIX , getRobotAnalyticsData } from '../analytics' ; import { getConnectedRobot } from '../discovery' ; import { getIntercomAppId , bootIntercom , updateIntercomProfile , setUserId , } from './intercom-binding' ; import * as Pipettes from '../pipettes' ; import * as RobotSettings from '../robot-settings' ; import * as SystemInfo from '../system-info' ; import * as Constants from './constants' ; import type { Action , State } from '../types' ; import type { Config } from '../config/types' ; import type { SupportProfileUpdate } from './types' ; type SupportConfig = Config [ 'support' ] ; export function initializeProfile ( config ) { setUserId ( config . userId ) ; bootIntercom ( { app_id : getIntercomAppId ( ) , created_at : config . createdAt , [ Constants . PROFILE_APP_VERSION ] : _PKG_VERSION_ , } ) ; } export function updateProfile ( update ) { updateIntercomProfile ( update ) ; } export function makeProfileUpdate ( action , state ) { switch ( action . type ) { case 'robot:CONNECT_RESPONSE' : case RobotSettings . FETCH_SETTINGS_SUCCESS : case RobotSettings . UPDATE_SETTING_SUCCESS : case Pipettes . FETCH_PIPETTES_SUCCESS : { const robot = getConnectedRobot ( state ) ; const robotData = getRobotAnalyticsData ( state ) ; if ( ! robot || ! robotData || ( action . type !== 'robot:CONNECT_RESPONSE' && action . payload . robotName !== robot . name ) ) { return null ; } const update = { [ Constants . PROFILE_ROBOT_NAME ] : robot . name , [ Constants . PROFILE_ROBOT_API_VERSION ] : robotData . robotApiServerVersion , [ Constants . PROFILE_ROBOT_SMOOTHIE_VERSION ] : robotData . robotSmoothieVersion , [ Constants . PROFILE_PIPETTE_MODEL_LEFT ] : robotData . robotLeftPipette , [ Constants . PROFILE_PIPETTE_MODEL_RIGHT ] : robotData . robotRightPipette , } ; Object . keys ( robotData ) . filter ( key => key . startsWith ( FF_PREFIX ) ) . map ( key => [ key . slice ( FF_PREFIX . length ) , robotData [ key ] ] ) . forEach ( ( [ key , value ] ) => ( update [ `${ Constants . PROFILE_FEATURE_FLAG } ${ key }` ] = value ) ) ; return update ; } case SystemInfo . INITIALIZED : case SystemInfo . USB_DEVICE_ADDED : case SystemInfo . NETWORK_INTERFACES_CHANGED : { return SystemInfo . getU2EDeviceAnalyticsProps ( state ) ; } case Cfg . VALUE_UPDATED : { return { appUpdatesIgnored : Alerts . getAlertIsPermanentlyIgnored ( state , Alerts . ALERT_APP_UPDATE_AVAILABLE ) , } ; } } return null ; }