import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdBillingProfilesBillingProfilesIdBillingRatesArgs = {userprofilesId: string, billingProfilesId: string}; export type GetApiUserprofilesUserprofilesIdBillingProfilesBillingProfilesIdBillingRatesOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const billingRateTieredRate = z.object({highValue: z.string().optional(), lowValue: z.string().optional(), rateInMicros: z.string().optional()}); export const billingRate = z.object({currencyCode: z.string().optional(), endDate: z.string().optional(), id: z.string().optional(), name: z.string().optional(), rateInMicros: z.string().optional(), startDate: z.string().optional(), tieredRates: z.array(billingRateTieredRate).optional(), type: z.enum(["AD_SERVING", "CLICKS", "MINIMUM_SERVICE", "PATH_TO_CONVERSION", "RICH_MEDIA_INPAGE", "RICH_MEDIA_EXPANDING", "RICH_MEDIA_FLOATING", "RICH_MEDIA_VIDEO", "RICH_MEDIA_TEASER", "RICH_MEDIA_VPAID", "INSTREAM_VIDEO", "PIXEL", "TRACKING", "TRAFFICKING_FEATURE", "CUSTOM_REPORTS", "EXPOSURE_TO_CONVERSION", "DATA_TRANSFER", "DATA_TRANSFER_SETUP", "STARTUP", "STATEMENT_OF_WORK", "PROVIDED_LIST", "PROVIDED_LIST_SETUP", "ENHANCED_FORMATS", "TRACKING_AD_IMPRESSIONS", "TRACKING_AD_CLICKS", "NIELSEN_DIGITAL_AD_RATINGS_FEE", "INSTREAM_VIDEO_REDIRECT", "INSTREAM_VIDEO_VPAID", "DISPLAY_AD_SERVING", "VIDEO_AD_SERVING", "AUDIO_AD_SERVING", "ADVANCED_DISPLAY_AD_SERVING"]).optional(), unitOfMeasure: z.enum(["CPM", "CPC", "EA", "P2C"]).optional()}); export const billingRatesListResponse = z.object({billingRates: z.array(billingRate).optional(), kind: z.string().optional(), nextPageToken: z.string().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 billing rates. This method supports paging. * * GET /userprofiles/{userprofilesId}/billingProfiles/{billingProfilesId}/billingRates */ export const getApiUserprofilesUserprofilesIdBillingProfilesBillingProfilesIdBillingRates = async (args: GetApiUserprofilesUserprofilesIdBillingProfilesBillingProfilesIdBillingRatesArgs, options?: GetApiUserprofilesUserprofilesIdBillingProfilesBillingProfilesIdBillingRatesOptions) => { 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 (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/userprofiles/${encodeURIComponent(String(args.userprofilesId))}/billingProfiles/${encodeURIComponent(String(args.billingProfilesId))}/billingRates${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(billingRatesListResponse, await res.json()) };