export type ChannelBranch = {branchOf: string, branch: string}; export type CreateApiChannelsArgs = {body: ChannelBranch}; export type CreateApiChannelsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a channel developer branch * * POST /channels */ export const createApiChannels = async (args: CreateApiChannelsArgs, options?: CreateApiChannelsOptions) => { const {baseUrl = "https://developers.bloomreach.io/delivery/site/v2/documents", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/channels${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 };