export type MD5 = string; export type SubmitReportRequest = {benchmark_id?: MD5 | undefined, nonce?: number | undefined}; export type CreateApiSubmitReportArgs = {'X-Api-Key'?: MD5 | undefined, body: SubmitReportRequest}; export type CreateApiSubmitReportOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Submit a report * * POST /submit-report */ export const createApiSubmitReport = async (args: CreateApiSubmitReportArgs, options?: CreateApiSubmitReportOptions) => { const {baseUrl = "https://mainnet-api.tig.foundation", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Api-Key'] != null) headers.set("X-Api-Key", String(args['X-Api-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/submit-report${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };