import {z} from 'zod' export type GetApiV2TeamsTeamIdUsersArgs = {team_id: string, userId?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV2TeamsTeamIdUsersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svauthPublicTeamUserRole = z.enum(["TEAM_USER_ROLE_UNSPECIFIED", "TEAM_USER_ROLE_AGENT", "TEAM_USER_ROLE_MANAGER", "TEAM_USER_ROLE_BUILDER", "TEAM_USER_ROLE_VIEWER", "TEAM_USER_ROLE_CONTRIBUTOR", "TEAM_USER_ROLE_DRAFTER", "TEAM_USER_ROLE_READONLY_AGENT", "TEAM_USER_ROLE_APP_BUILDER"]); export const googleProtobufTimestamp = z.string(); export const svauthPublicTeamUser = z.object({teamId: z.string().optional(), userId: z.string().optional(), role: svauthPublicTeamUserRole.optional(), createdAt: googleProtobufTimestamp.optional(), id: z.string().optional()}); export const svauthPublicListTeamUsersResponse = z.object({data: z.array(svauthPublicTeamUser).optional(), nextPageToken: z.string().nullable().optional()}); 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 Team Users * * GET /v2/teams/{team_id}/users */ export const getApiV2TeamsTeamIdUsers = async (args: GetApiV2TeamsTeamIdUsersArgs, options?: GetApiV2TeamsTeamIdUsersOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userId != null) query.append("userId", String(args.userId)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/teams/${encodeURIComponent(String(args.team_id))}/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(svauthPublicListTeamUsersResponse, await res.json()) };