export type PostV1SpamTestsId = {type: 'all' | 'btob' | 'btoc'}; export type CreateApiV1SpamTestsIdArgs = {id: string, 'x-api-key': string, body: PostV1SpamTestsId}; export type CreateApiV1SpamTestsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update a given test * * POST /v1/spam_tests/{id} */ export const createApiV1SpamTestsId = async (args: CreateApiV1SpamTestsIdArgs, options?: CreateApiV1SpamTestsIdOptions) => { const {baseUrl = "https://api.mailreach.co/api", 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(/\/+$/, '')}/v1/spam_tests/${encodeURIComponent(String(args.id))}${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 };