export type WarmUpRequestV2 = {type: string, timestamp: string}; export type CreateApiWarmUpArgs = {'X-WarmUp': boolean, body: WarmUpRequestV2}; export type CreateApiWarmUpOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Warm-up endpoint for initialising WebClient * * POST /warm-up */ export const createApiWarmUp = async (args: CreateApiWarmUpArgs, options: CreateApiWarmUpOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-WarmUp'] != null) headers.set("X-WarmUp", String(args['X-WarmUp'])) const url = `${baseUrl.replace(/\/+$/, '')}/warm-up${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 };