import { PluginServiceHTTPClient , PluginsClient , PluginVersionsClient , ConfigurationsClient , ConfiguredPluginsClient , ReleasesClient , PluginVersionResource , PluginResource , ReleaseResource , ConfigurationResource , ConfiguredPluginResourcePage , } from 'flex-plugins-api-client' ; import { PluginServiceHttpOption } from 'flex-plugins-api-client/dist/clients/client' ; import { logger } from 'flex-dev-utils' ; import { testParams } from '../core' ; import * as serverlessApi from './serverless-api' ; const options = { } ; if ( testParams . config . region ) { options . region = testParams . config . region ; } const client = new PluginServiceHTTPClient ( testParams . secrets . api . accountSid , testParams . secrets . api . authToken , options ) ; const pluginsClient = new PluginsClient ( client ) ; const versionsClient = new PluginVersionsClient ( client ) ; const configurationsClient = new ConfigurationsClient ( client ) ; const configuredPluginsClient = new ConfiguredPluginsClient ( client ) ; const releasesClient = new ReleasesClient ( client ) ; const cleanup = async ( ) : Promise < void > => { logger . info ( 'Cleaning up plugins-api' ) ; const activeRelease = await releasesClient . active ( ) ; const resource = await configurationsClient . create ( { Name : 'E2E Test Cleanup' , Description : 'Empty Configuration' , Plugins : [ ] , } ) ; await releasesClient . create ( { ConfigurationId : resource . sid , } ) ; if ( activeRelease ) { const list = await configuredPluginsClient . list ( activeRelease . configuration_sid ) ; for ( const plugin of list . plugins ) { await versionsClient . archive ( plugin . plugin_sid , plugin . plugin_version_sid ) ; } } const service = await serverlessApi . getServiceSid ( ) ; await serverlessApi . deleteEnvironments ( service . sid ) ; } ; const getPluginVersion = async ( name , version ) : Promise < PluginVersionResource > => { return versionsClient . get ( name , version ) ; } ; const getLatestPluginVersion = async ( name ) : Promise < PluginVersionResource | null > => { try { return await versionsClient . latest ( name ) ; } catch ( e ) { return null ; } } ; const getPlugin = async ( name ) : Promise < PluginResource > => { return pluginsClient . get ( name ) ; } ; const getActiveRelease = async ( ) : Promise < ReleaseResource | null > => { return releasesClient . active ( ) ; } ; const getConfiguration = async ( sid ) : Promise < ConfigurationResource > => { return configurationsClient . get ( sid ) ; } ; const getActivePlugins = async ( sid ) : Promise < ConfiguredPluginResourcePage > => { return configuredPluginsClient . list ( sid ) ; } ; export default { cleanup , getPluginVersion , getLatestPluginVersion , getPlugin , getActiveRelease , getConfiguration , getActivePlugins , } ;