export type ClientRenderZoneRequest = {data: {[key: string]: Record}, zone_name: string}; export type CreateApiV5ZonesArgs = {body: ClientRenderZoneRequest}; export type CreateApiV5ZonesOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; /** * Render a zone with the name in the body * * POST /v5/zones * * Also accepts auth: QUERY, COOKIE */ export const createApiV5Zones = async (args: CreateApiV5ZonesArgs, options?: CreateApiV5ZonesOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v5/zones${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 };