import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdAccountsAccountsIdArgs = {userprofilesId: string, accountsId: string}; export type GetApiUserprofilesUserprofilesIdAccountsAccountsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const lookbackConfiguration = z.object({clickDuration: z.number().int().optional(), postImpressionActivitiesDuration: z.number().int().optional()}); export const reportsConfiguration = z.object({exposureToConversionEnabled: z.boolean().optional(), lookbackConfiguration: lookbackConfiguration.optional(), reportGenerationTimeZoneId: z.string().optional()}); export const account = z.object({accountPermissionIds: z.array(z.string()).optional(), accountProfile: z.enum(["ACCOUNT_PROFILE_BASIC", "ACCOUNT_PROFILE_STANDARD"]).optional(), active: z.boolean().optional(), activeAdsLimitTier: z.enum(["ACTIVE_ADS_TIER_40K", "ACTIVE_ADS_TIER_75K", "ACTIVE_ADS_TIER_100K", "ACTIVE_ADS_TIER_200K", "ACTIVE_ADS_TIER_300K", "ACTIVE_ADS_TIER_500K", "ACTIVE_ADS_TIER_750K", "ACTIVE_ADS_TIER_1M"]).optional(), activeViewOptOut: z.boolean().optional(), availablePermissionIds: z.array(z.string()).optional(), countryId: z.string().optional(), currencyId: z.string().optional(), defaultCreativeSizeId: z.string().optional(), description: z.string().optional(), id: z.string().optional(), kind: z.string().optional(), locale: z.string().optional(), maximumImageSize: z.string().optional(), name: z.string().optional(), nielsenOcrEnabled: z.boolean().optional(), reportsConfiguration: reportsConfiguration.optional(), shareReportsWithTwitter: z.boolean().optional(), teaserSizeLimit: 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 }; /** * Gets one account by ID. * * GET /userprofiles/{userprofilesId}/accounts/{accountsId} */ export const getApiUserprofilesUserprofilesIdAccountsAccountsId = async (args: GetApiUserprofilesUserprofilesIdAccountsAccountsIdArgs, options?: GetApiUserprofilesUserprofilesIdAccountsAccountsIdOptions) => { 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))}/accounts/${encodeURIComponent(String(args.accountsId))}${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(account, await res.json()) };