import {z} from 'zod' export type TeamRolePatchPayload = {name?: string | undefined, view_chatbots?: boolean | undefined, edit_chatbots?: boolean | undefined, create_chatbot?: boolean | undefined, edit_customization?: boolean | undefined, share_chatbots?: boolean | undefined, edit_safety?: boolean | undefined, view_chat_logs?: boolean | undefined, edit_api_key?: boolean | undefined, edit_whatsapp_integration?: boolean | undefined, edit_intercom_integration?: boolean | undefined, analytics?: boolean | undefined, live_agents?: boolean | undefined, assign_avatar?: boolean | undefined, create_avatar?: boolean | undefined, edit_avatar?: boolean | undefined}; export type PatchApiTeamRolesTeamRoleIdArgs = {team_role_id: string, team_id: string, body: TeamRolePatchPayload}; export type PatchApiTeamRolesTeamRoleIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const permissionResponse = z.object({name: z.string(), label: z.string().optional(), value: z.boolean().optional(), category: z.string().optional(), help_text: z.string().optional()}); export const teamRoleResponse = z.object({id: z.string(), date_created: z.string(), date_updated: z.string(), name: z.string(), team_id: z.string().optional(), permissions: z.array(permissionResponse)}); 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 }; /** * Update Team Role * * PATCH /team-roles/{team_role_id} * * Also accepts auth: OAuth2PasswordBearer */ export const patchApiTeamRolesTeamRoleId = async (args: PatchApiTeamRolesTeamRoleIdArgs, options: PatchApiTeamRolesTeamRoleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/team-roles/${encodeURIComponent(String(args.team_role_id))}${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(teamRoleResponse, await res.json()) };