export type User = {id?: string | undefined, username?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, email?: string | undefined, org?: string | undefined, role?: (Array<'user' | 'author' | 'admin'>) | undefined}; export type CreateApiUsersArgs = {body: User}; export type CreateApiUsersOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; /** * Admin Only! Create user (handled by IDP for now) * * POST /users */ export const createApiUsers = async (args: CreateApiUsersArgs, options?: CreateApiUsersOptions) => { 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(/\/+$/, '')}/users${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 };