export type ChangePasswordRequest = {oldPassword: string, newPassword: string}; export type CreateApiApiV1AuthChangePasswordArgs = {body: ChangePasswordRequest}; export type CreateApiApiV1AuthChangePasswordOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Change password using current one * * POST /api/v1/auth/change-password */ export const createApiApiV1AuthChangePassword = async (args: CreateApiApiV1AuthChangePasswordArgs, options: CreateApiApiV1AuthChangePasswordOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/auth/change-password${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 };