import {z} from 'zod' export type SvauthPublicTeamUserRole = '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 type CreateApiV2TeamsTeamIdUsersArgs = {team_id: string, body: {userId: string, role: SvauthPublicTeamUserRole}}; export type CreateApiV2TeamsTeamIdUsersOptions = {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 svauthPublicCreateTeamUserResponse = z.object({data: svauthPublicTeamUser.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 }; /** * Create Team User * * POST /v2/teams/{team_id}/users */ export const createApiV2TeamsTeamIdUsers = async (args: CreateApiV2TeamsTeamIdUsersArgs, options?: CreateApiV2TeamsTeamIdUsersOptions) => { const {baseUrl = "https://public.api.serval.com", 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(/\/+$/, '')}/v2/teams/${encodeURIComponent(String(args.team_id))}/users${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(svauthPublicCreateTeamUserResponse, await res.json()) };