import type { AxiosRequestConfig } from 'axios' ; import type { HttpClient } from '../../http/' ; import type { Provider , Service , ServiceWhitelistData , Services } from './' ; export class ServiceAPI { constructor ( private readonly client ) { } public static readonly URL = { PROVIDERS : '/providers' , SERVICES : 'services' , TEAMS : '/teams' , WHITELIST : 'whitelist' , WHITELISTED : 'whitelisted' , } ; public async getServices ( limit = 100 , start ? , tags ? ) { const config = { method : 'get' , params : { size : limit , start , tags , } , url : `/${ ServiceAPI . URL . SERVICES }` , } ; const response = await this . client . sendJSON < Services > ( config ) ; return response . data ; } public async getTeamServices ( teamId , limit = 100 ) { const config = { method : 'get' , params : { prefix : undefined , size : limit , start : undefined , } , url : `${ ServiceAPI . URL . TEAMS }/${ teamId }/${ ServiceAPI . URL . SERVICES }/${ ServiceAPI . URL . WHITELISTED }` , } ; const response = await this . client . sendJSON < Services > ( config ) ; return response . data ; } public async getProvider ( providerId ) { const config = { method : 'get' , url : `${ ServiceAPI . URL . PROVIDERS }/${ providerId }` , } ; const response = await this . client . sendJSON < Provider > ( config ) ; return response . data ; } public async getProviderServices ( providerId ) { const config = { method : 'get' , url : `${ ServiceAPI . URL . PROVIDERS }/${ providerId }/${ ServiceAPI . URL . SERVICES }` , } ; const response = await this . client . sendJSON < Services > ( config ) ; return response . data ; } public async getService ( providerId , serviceId ) { const config = { method : 'get' , url : `${ ServiceAPI . URL . PROVIDERS }/${ providerId }/${ ServiceAPI . URL . SERVICES }/${ serviceId }` , } ; const response = await this . client . sendJSON < Service > ( config ) ; return response . data ; } public async postServiceWhitelist ( teamId , whitelistData ) { const config = { data : whitelistData , method : 'post' , url : `${ ServiceAPI . URL . TEAMS }/${ teamId }/${ ServiceAPI . URL . SERVICES }/${ ServiceAPI . URL . WHITELIST }` , } ; const response = await this . client . sendJSON < Services > ( config ) ; return response . data ; } }