github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/services/apps.ts (about) 1 import { App, appsModel } from '@webapp/models/app'; 2 import { Result } from '@webapp/util/fp'; 3 import type { ZodError } from 'zod'; 4 import type { RequestError } from './base'; 5 import { parseResponse, request } from './base'; 6 7 export interface FetchAppsError { 8 message?: string; 9 } 10 11 export async function fetchApps(): Promise< 12 Result<App[], RequestError | ZodError> 13 > { 14 const response = await request('/api/apps'); 15 16 if (response.isOk) { 17 return parseResponse(response, appsModel); 18 } 19 20 return Result.err<App[], RequestError>(response.error); 21 } 22 23 export async function deleteApp(data: { 24 name: string; 25 }): Promise<Result<boolean, RequestError | ZodError>> { 26 const { name } = data; 27 const response = await request(`/api/apps`, { 28 method: 'DELETE', 29 body: JSON.stringify({ name }), 30 }); 31 32 if (response.isOk) { 33 return Result.ok(true); 34 } 35 36 return Result.err<boolean, RequestError>(response.error); 37 }