import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdTvCampaignSummariesArgs = {userprofilesId: string, accountId?: unknown | undefined, countryDartId?: unknown | undefined, name?: string | 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 GetApiUserprofilesUserprofilesIdTvCampaignSummariesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const tvCampaignSummary = z.object({endDate: z.string().optional(), grp: z.string().optional(), id: z.string().optional(), impressions: z.string().optional(), kind: z.string().optional(), name: z.string().optional(), spend: z.number().optional(), startDate: z.string().optional(), type: z.enum(["CAMPAIGN_COMPONENT_TYPE_UNSPECIFIED", "COMPANY", "BRAND", "PRODUCT", "CAMPAIGN"]).optional()}); export const tvCampaignSummariesListResponse = z.object({kind: z.string().optional(), tvCampaignSummaries: z.array(tvCampaignSummary).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 }; /** * Retrieves a list of TV campaign summaries. * * GET /userprofiles/{userprofilesId}/tvCampaignSummaries */ export const getApiUserprofilesUserprofilesIdTvCampaignSummaries = async (args: GetApiUserprofilesUserprofilesIdTvCampaignSummariesArgs, options?: GetApiUserprofilesUserprofilesIdTvCampaignSummariesOptions) => { 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.name != null) query.append("name", String(args.name)) 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))}/tvCampaignSummaries${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(tvCampaignSummariesListResponse, await res.json()) };