export type Credential = {username?: string | undefined, password?: string | undefined}; export type CreateApiUsersAuthenticateArgs = {body: Credential}; export type CreateApiUsersAuthenticateOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Authenticate user * * POST /users/authenticate */ export const createApiUsersAuthenticate = async (args: CreateApiUsersAuthenticateArgs, options?: CreateApiUsersAuthenticateOptions) => { const {baseUrl = "http://localhost:8081/ims-users/resources", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/users/authenticate${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 };