export type PasswordResetIn = {old_password: string, new_password: string}; export type CreateApiUsersPasswdArgs = {cookie_name?: (string | null) | undefined, body: PasswordResetIn}; export type CreateApiUsersPasswdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Change own password * * POST /users/passwd */ export const createApiUsersPasswd = async (args: CreateApiUsersPasswdArgs, options?: CreateApiUsersPasswdOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/users/passwd${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 };