export type ChannelGroupRequest = {group_id: string, permission: 'read' | 'write' | 'manage'}; export type CreateApiChannelsChannelNameGroupsArgs = {channel_name: string, body: ChannelGroupRequest}; export type CreateApiChannelsChannelNameGroupsOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; /** * Add new group to the channel * * POST /channels/{channel_name}/groups */ export const createApiChannelsChannelNameGroups = async (args: CreateApiChannelsChannelNameGroupsArgs, options?: CreateApiChannelsChannelNameGroupsOptions) => { const {baseUrl = "https://api.anaconda.cloud/api", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/channels/${encodeURIComponent(String(args.channel_name))}/groups${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 };