import {z} from 'zod' export type LookbackConfiguration = {clickDuration?: number | undefined, postImpressionActivitiesDuration?: number | undefined}; export type ReportsConfiguration = {exposureToConversionEnabled?: boolean | undefined, lookbackConfiguration?: LookbackConfiguration | undefined, reportGenerationTimeZoneId?: unknown | undefined}; export type Account = {accountPermissionIds?: Array | undefined, accountProfile?: ('ACCOUNT_PROFILE_BASIC' | 'ACCOUNT_PROFILE_STANDARD') | undefined, active?: boolean | undefined, activeAdsLimitTier?: ('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') | undefined, activeViewOptOut?: boolean | undefined, availablePermissionIds?: Array | undefined, countryId?: unknown | undefined, currencyId?: unknown | undefined, defaultCreativeSizeId?: unknown | undefined, description?: string | undefined, id?: unknown | undefined, kind?: string | undefined, locale?: string | undefined, maximumImageSize?: unknown | undefined, name?: string | undefined, nielsenOcrEnabled?: boolean | undefined, reportsConfiguration?: ReportsConfiguration | undefined, shareReportsWithTwitter?: boolean | undefined, teaserSizeLimit?: unknown | undefined}; export type UpdateApiUserprofilesUserprofilesIdAccountsArgs = {userprofilesId: string, body: Account}; export type UpdateApiUserprofilesUserprofilesIdAccountsOptions = {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 }; /** * Updates an existing account. * * PUT /userprofiles/{userprofilesId}/accounts */ export const updateApiUserprofilesUserprofilesIdAccounts = async (args: UpdateApiUserprofilesUserprofilesIdAccountsArgs, options?: UpdateApiUserprofilesUserprofilesIdAccountsOptions) => { const {baseUrl = "https://dfareporting.googleapis.com/dfareporting/v5", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(account, await res.json()) };