import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdTvCampaignDetailsTvCampaignDetailsIdArgs = {userprofilesId: string, tvCampaignDetailsId: string, accountId?: unknown | undefined, countryDartId?: unknown | undefined, tvDataProvider?: ('INVALID_TV_DATA_PROVIDER' | 'INTAGE_JP' | 'IBOPE_AR' | 'IBOPE_BR' | 'IBOPE_CL' | 'IBOPE_CO' | 'TNS_VN' | 'COMSCORE_NATIONAL_US' | 'COMSCORE_CA' | 'SAMBA_AU') | undefined}; export type GetApiUserprofilesUserprofilesIdTvCampaignDetailsTvCampaignDetailsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const tvCampaignTimepoint = z.object({dateWindow: z.enum(["WEEKS_UNSPECIFIED", "DAYS_ONE", "WEEKS_ONE", "WEEKS_FOUR", "WEEKS_EIGHT", "WEEKS_TWELVE"]).optional(), spend: z.number().optional(), startDate: z.string().optional()}); export const tvCampaignDetail = z.object({id: z.string().optional(), kind: z.string().optional(), timepoints: z.array(tvCampaignTimepoint).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 }; /** * Gets one TvCampaignDetail by ID. * * GET /userprofiles/{userprofilesId}/tvCampaignDetails/{tvCampaignDetailsId} */ export const getApiUserprofilesUserprofilesIdTvCampaignDetailsTvCampaignDetailsId = async (args: GetApiUserprofilesUserprofilesIdTvCampaignDetailsTvCampaignDetailsIdArgs, options?: GetApiUserprofilesUserprofilesIdTvCampaignDetailsTvCampaignDetailsIdOptions) => { const {baseUrl = "https://dfareporting.googleapis.com/dfareporting/v5", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.accountId != null) query.append("accountId", String(args.accountId)) if (args.countryDartId != null) query.append("countryDartId", String(args.countryDartId)) if (args.tvDataProvider != null) query.append("tvDataProvider", String(args.tvDataProvider)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/userprofiles/${encodeURIComponent(String(args.userprofilesId))}/tvCampaignDetails/${encodeURIComponent(String(args.tvCampaignDetailsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(tvCampaignDetail, await res.json()) };