import { map } from 'lodash' ; import api from 'teleport/services/api' ; import cfg from 'teleport/config' ; import makeSession , { makeParticipant } from './makeSession' ; import { ParticipantList } from './types' ; const service = { create ( { serverId , clusterId , login } ) { const request = { session : { login , cluster_name : clusterId , server_id : serverId , } , } ; return api . post ( cfg . getTerminalSessionUrl ( { clusterId } ) , request ) . then ( response => { const session = makeSession ( response . session ) ; const hostname = session . hostname ? session . hostname : serverId ; return { ... session , hostname , } ; } ) ; } , fetchSession ( { clusterId , sid } ) { return api . get ( cfg . getTerminalSessionUrl ( { sid , clusterId } ) ) . then ( makeSession ) ; } , fetchSessions ( clusterId ) { return api . get ( cfg . getTerminalSessionUrl ( { clusterId } ) ) . then ( response => { if ( response && response . sessions ) { return map ( response . sessions , makeSession ) ; } return [ ] ; } ) ; } , fetchParticipants ( { clusterId } ) { return api . get ( cfg . getTerminalSessionUrl ( { clusterId } ) ) . then ( json => { if ( ! json && ! json . sessions ) { return { } ; } const parties = { } ; json . sessions . forEach ( s => { parties [ s . id ] = map ( s . parties , makeParticipant ) ; } ) ; return parties ; } ) ; } , } ; export default service ; type CreateParams = { serverId : string ; clusterId : string ; login : string ; } ; type FetchSessionParams = { sid : string ; clusterId : string ; } ;