import {z} from 'zod' export type PatchApiV2GroupsIdArgs = {'x-customer-api-key'?: string | undefined, body: {account_id?: (number | null) | undefined, music_profile_id?: (number | null) | undefined, name: string}}; export type PatchApiV2GroupsIdOptions = {baseUrl: string, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV2GroupsIdResponse = z.object({data: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), music_profile_id: z.string().optional(), name: z.string().optional(), analytics: z.object({data: z.object({players: z.number().int().optional(), announcements: z.number().int().optional(), mixes: z.number().int().optional(), radios: z.number().int().optional()}).optional()}).optional()}).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 group * * PATCH /v2/groups/{id} */ export const patchApiV2GroupsId = async (args: PatchApiV2GroupsIdArgs, options: PatchApiV2GroupsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-customer-api-key'] != null) headers.set("x-customer-api-key", String(args['x-customer-api-key'])) if (defaultValue !== undefined) headers.set("x-customer-api-key", defaultValue) const url = `${baseUrl.replace(/\/+$/, '')}/v2/groups/${encodeURIComponent(String(args.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(patchApiV2GroupsIdResponse, await res.json()) };