export type Question = {grouping_hash: string, name: string, email: string, question: string, url?: string | undefined}; export type CreateApiQuestionsStoreArgs = {store: string, apikey: string, body: Question}; export type CreateApiQuestionsStoreOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new Question * * POST /questions/store */ export const createApiQuestionsStore = async (args: CreateApiQuestionsStoreArgs, options?: CreateApiQuestionsStoreOptions) => { const {baseUrl = "https://api.reviews.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.store != null) query.append("store", String(args.store)) if (args.apikey != null) query.append("apikey", String(args.apikey)) const url = `${baseUrl.replace(/\/+$/, '')}/questions/store${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 };