import {z} from 'zod' export type OrganizationUrl = string; export type Metadata = Record; export type UserBase = {id?: number | undefined, url?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, phone_number?: (string | null) | undefined, password?: string | undefined, date_joined?: string | undefined, username?: string | undefined, groups?: Array | undefined, organization?: OrganizationUrl | undefined, queues?: Array | undefined, is_active?: boolean | undefined, last_login?: (string | null) | undefined, ui_settings?: Record | undefined, metadata?: Metadata | undefined, oidc_id?: (string | null) | undefined, auth_type?: ('sso' | 'password') | undefined, deleted?: boolean | undefined}; export type PatchApiApiV1AuthUserArgs = {body: UserBase}; export type PatchApiApiV1AuthUserOptions = {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 }; /** * Partial update current user * * PATCH /api/v1/auth/user */ export const patchApiApiV1AuthUser = async (args: PatchApiApiV1AuthUserArgs, options?: PatchApiApiV1AuthUserOptions) => { 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/user${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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()) };