import * as jsonic from 'jsonic' ; import { ManualServerConfig } from '../model/server' ; export function parseManualServerConfig ( userInput ) { const indexOfFirstBrace = userInput . indexOf ( '{' ) ; if ( indexOfFirstBrace >= 0 ) { userInput = userInput . substring ( indexOfFirstBrace ) ; } const indexOfLastBrace = userInput . lastIndexOf ( '}' ) ; if ( indexOfLastBrace >= 0 ) { userInput = userInput . substring ( 0 , indexOfLastBrace + 1 ) ; } userInput = userInput . replace ( /\s+/g , '' ) ; const config = jsonic ( userInput ) as ManualServerConfig ; if ( ! config . apiUrl ) { throw new Error ( 'no apiUrl field' ) ; } if ( ! config . certSha256 ) { throw new Error ( 'no certSha256 field' ) ; } return config ; }