import axios from 'axios' ; import { testParams } from '../core' ; interface Service { unique_name : string ; sid : string ; } const realm = testParams . config . region ? `${ testParams . config . region }.` : '' ; const baseUrl = `https://serverless.${ realm }twilio.com/v1` ; const auth = { username : testParams . secrets . api . accountSid , password : testParams . secrets . api . authToken , } ; const get = async ( uri ) => { return axios . get ( `${ baseUrl }/${ uri }` , { auth } ) . then ( ( resp ) => resp . data ) ; } ; const remove = async ( uri ) => { return axios . delete ( `${ baseUrl }/${ uri }` , { auth } ) ; } ; export const getServiceSid = async ( ) : Promise < Service > => { return get ( 'Services' ) . then ( ( list ) => list . services . find ( ( service ) => service . unique_name === 'default' ) ) ; } ; export const deleteEnvironments = async ( serviceSid ) : Promise < void > => { const list = await get ( `Services/${ serviceSid }/Environments` ) ; for ( const environment of list . environments ) { await remove ( `Services/${ serviceSid }/Environments/${ environment . sid }` ) ; } } ;