github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/services/share.ts (about) 1 /* eslint-disable import/prefer-default-export */ 2 import { Result } from '@webapp/util/fp'; 3 import type { ZodError } from 'zod'; 4 import { Profile } from '@pyroscope/models/src'; 5 import { 6 FlamegraphDotComResponse, 7 flamegraphDotComResponseScheme, 8 } from '@webapp/models/flamegraphDotComResponse'; 9 import type { RequestError } from './base'; 10 import { request, parseResponse } from './base'; 11 12 interface shareWithFlamegraphDotcomProps { 13 flamebearer: Profile; 14 name?: string; 15 groupByTag?: string; 16 groupByTagValue?: string; 17 } 18 19 export async function shareWithFlamegraphDotcom({ 20 flamebearer, 21 name, 22 groupByTag, 23 groupByTagValue, 24 }: shareWithFlamegraphDotcomProps): Promise< 25 Result<FlamegraphDotComResponse, RequestError | ZodError> 26 > { 27 const response = await request('/export', { 28 method: 'POST', 29 body: JSON.stringify({ 30 name, 31 groupByTag, 32 groupByTagValue, 33 // TODO: 34 // use buf.toString 35 profile: btoa(JSON.stringify(flamebearer)), 36 type: 'application/json', 37 }), 38 }); 39 40 if (response.isOk) { 41 return parseResponse(response, flamegraphDotComResponseScheme); 42 } 43 44 return Result.err<FlamegraphDotComResponse, RequestError>(response.error); 45 }