import {z} from 'zod' export type CmsMediaBridgeEventVisibilityChange = {eventType: 'ALL' | 'ATTENTION_SPAN' | 'MEDIA_PLAYS' | 'MEDIA_PLAYS_PERCENT', showInReporting?: boolean | undefined, showInTimeline?: boolean | undefined, showInWorkflows?: boolean | undefined, updatedAt: number}; export type PatchApiMediaBridge202603AppIdSettingsEventVisibilityArgs = {appId: number, body: CmsMediaBridgeEventVisibilityChange}; export type PatchApiMediaBridge202603AppIdSettingsEventVisibilityOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const cmsMediaBridgeEventVisibilityChange = z.object({eventType: z.enum(["ALL", "ATTENTION_SPAN", "MEDIA_PLAYS", "MEDIA_PLAYS_PERCENT"]), showInReporting: z.boolean().optional(), showInTimeline: z.boolean().optional(), showInWorkflows: z.boolean().optional(), updatedAt: z.number().int()}); 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 or update event visibility settings * * PATCH /media-bridge/2026-03/{appId}/settings/event-visibility * * Also accepts auth: developer_hapikey */ export const patchApiMediaBridge202603AppIdSettingsEventVisibility = async (args: PatchApiMediaBridge202603AppIdSettingsEventVisibilityArgs, options?: PatchApiMediaBridge202603AppIdSettingsEventVisibilityOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, privateApps} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (privateApps !== undefined) headers.set('authorization', `Bearer ${privateApps}`) const url = `${baseUrl.replace(/\/+$/, '')}/media-bridge/2026-03/${encodeURIComponent(String(args.appId))}/settings/event-visibility${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(cmsMediaBridgeEventVisibilityChange, await res.json()) };