import {z} from 'zod' export type PaidSeatGroupsPostRequest = {name?: string | undefined, capacity?: number | undefined}; export type CreateApiPaidSeatGroupsIdModifyUserArgs = {id: string, body: PaidSeatGroupsPostRequest}; export type CreateApiPaidSeatGroupsIdModifyUserOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const paidSeatGroupsPostResponse = z.object({id: z.string().optional(), name: z.string().optional(), administrators: z.array(z.object({id: z.string().optional(), name: z.string().optional(), email: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()})).optional(), capacity: z.number().int().optional(), allocated_seats: z.number().int().optional(), description: z.unknown(), created_at: z.string().optional(), updated_at: z.string().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 }; /** * Adds the user to the paid seat group * * POST /paid_seat_groups/{id}/modify_user * * Also accepts auth: ApiKeyAuth, CookieAuth */ export const createApiPaidSeatGroupsIdModifyUser = async (args: CreateApiPaidSeatGroupsIdModifyUserArgs, options?: CreateApiPaidSeatGroupsIdModifyUserOptions) => { const {baseUrl = "https://company.aha.io/api/v1", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json; charset=utf-8") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/paid_seat_groups/${encodeURIComponent(String(args.id))}/modify_user${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(paidSeatGroupsPostResponse, await res.json()) };