import {z} from 'zod' export type GetApiApiV1UsersArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, organization?: Array | undefined, username?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, is_active?: boolean | undefined, last_login?: string | undefined, groups?: string | undefined, queue?: Array | undefined, deleted?: boolean | undefined, ordering?: ('id' | '-id' | 'username' | '-username' | 'first_name' | '-first_name' | 'last_name' | '-last_name' | 'email' | '-email' | 'last_login' | '-last_login' | 'date_joined' | '-date_joined' | 'deleted' | '-deleted' | 'not_deleted' | '-not_deleted') | undefined}; export type GetApiApiV1UsersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); 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 getApiApiV1UsersResponse = z.object({pagination: pagination, results: z.array(user)}); 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 }; /** * List users * * GET /api/v1/users */ export const getApiApiV1Users = async (args: GetApiApiV1UsersArgs, options?: GetApiApiV1UsersOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.id != null) query.append("id", args.id.join(',')) if (args.organization != null) query.append("organization", args.organization.join(',')) if (args.username != null) query.append("username", String(args.username)) if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (args.email != null) query.append("email", String(args.email)) if (args.is_active != null) query.append("is_active", String(args.is_active)) if (args.last_login != null) query.append("last_login", String(args.last_login)) if (args.groups != null) query.append("groups", String(args.groups)) if (args.queue != null) query.append("queue", args.queue.join(',')) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/users${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1UsersResponse, await res.json()) };