import {z} from 'zod' export type UpdateApiApiTeamsIdArgs = {id: number, body: {name?: string | undefined, description?: (string | null) | undefined, default_email_integration_id?: (number | null) | undefined, decoration?: (Record | null) | undefined, members?: (Array<{id?: number | undefined, name?: (string | null) | undefined, email?: (string | null) | undefined, meta: unknown}>) | undefined}}; export type UpdateApiApiTeamsIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const team = z.object({id: z.number().int().optional(), uri: z.string().optional(), name: z.string().optional(), description: z.string().nullable().optional(), default_email_integration_id: z.number().int().gte(1).nullable().optional(), decoration: z.object({}).nullable().optional(), members: z.array(z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), email: z.string().max(320).nullable().optional(), meta: z.unknown()})).optional(), created_datetime: 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 }; /** * Update a team * * PUT /api/teams/{id} */ export const updateApiApiTeamsId = async (args: UpdateApiApiTeamsIdArgs, options?: UpdateApiApiTeamsIdOptions) => { const {baseUrl = "https://your-domain.gorgias.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/teams/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(team, await res.json()) };