import {z} from 'zod' export type PasswordChange = {new_password1: string, new_password2: string, old_password: string}; export type CreateApiApiV1AuthPasswordChangeArgs = {body: PasswordChange}; export type CreateApiApiV1AuthPasswordChangeOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationUrl = z.string(); export const metadata = z.object({}); export const user = z.object({id: z.number().int(), url: z.string(), first_name: z.string(), last_name: z.string(), email: z.string(), phone_number: z.string().nullable(), password: z.string(), date_joined: z.string(), username: z.string(), groups: z.array(z.string()), organization: organizationUrl, queues: z.array(z.string()), is_active: z.boolean(), last_login: z.string().nullable(), ui_settings: z.object({}), metadata: metadata, oidc_id: z.string().nullable(), auth_type: z.enum(["sso", "password"]), deleted: z.boolean()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Change password * * POST /api/v1/auth/password/change */ export const createApiApiV1AuthPasswordChange = async (args: CreateApiApiV1AuthPasswordChangeArgs, options?: CreateApiApiV1AuthPasswordChangeOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/auth/password/change${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 validateResponse(user, await res.json()) };