export type AuthScopes = 'adminAuth' | 'userAuth'; export type User = {displayName?: string | undefined, email: string, password?: string | undefined, ignoreTfa: boolean, scope: AuthScopes, passwordChangeRequired?: boolean | undefined}; export type CreateApiUsersArgs = {body: User}; export type CreateApiUsersOptions = {baseUrl: string, adminAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new user. * * POST /users */ export const createApiUsers = async (args: CreateApiUsersArgs, options: CreateApiUsersOptions) => { const {baseUrl, fetch: fetchFn = fetch, adminAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (adminAuth !== undefined) headers.set("authentication", adminAuth) 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 };