export type CreateApiWebhookExecuteTokenArgs = {token: string, queryParam: {[key: string]: Record}, body: {[key: string]: Record}}; export type CreateApiWebhookExecuteTokenOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Accepts a webhook and executes the associated connection. Additional params are sent as a json in body * * POST /webhook/execute/{token} */ export const createApiWebhookExecuteToken = async (args: CreateApiWebhookExecuteTokenArgs, options?: CreateApiWebhookExecuteTokenOptions) => { const {baseUrl = "http://localhost:9090", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.queryParam != null) query.append("queryParam", JSON.stringify(args.queryParam)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/webhook/execute/${encodeURIComponent(String(args.token))}${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 };