import { Command , flags } from '@oclif/command' ; import { prompt } from 'inquirer' ; import { Telemetry } from '../analytics/telemetry' ; import { BotonicAPIService } from '../botonic-api-service' ; export default class Run extends Command { static description = 'Log in to Botonic' ; static examples = [ ] ; static flags = { path : flags . string ( { char : 'p' , description : 'Path to botonic project. Defaults to current dir.' , } ) , } ; static args = [ ] ; private botonicApiService : BotonicAPIService = new BotonicAPIService ( ) ; private telemetry = new Telemetry ( ) ; async run ( ) { this . telemetry . trackLogin ( ) ; await this . logInUser ( ) ; } askLoginInfo ( ) { return prompt ( [ { type : 'input' , name : 'email' , message : 'email:' , } , { type : 'password' , name : 'password' , mask : '*' , message : 'password:' , } , ] ) ; } async logInUser ( ) { const userData = await this . askLoginInfo ( ) ; await this . botonicApiService . login ( userData . email , userData . password ) . then ( ( ) => { console . log ( 'Successful log in!' . green ) ; return ; } , err => { console . log ( 'Error: ' . red , err . response . data . error_description . red ) ; } ) ; } }