import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdAccountsArgs = {userprofilesId: string, active?: boolean | undefined, ids?: Array | undefined, maxResults?: number | undefined, pageToken?: string | undefined, searchString?: string | undefined, sortField?: ('ID' | 'NAME') | undefined, sortOrder?: ('ASCENDING' | 'DESCENDING') | undefined}; export type GetApiUserprofilesUserprofilesIdAccountsOptions = {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 accountsListResponse = z.object({accounts: z.array(account).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 the list of accounts, possibly filtered. This method supports paging. * * GET /userprofiles/{userprofilesId}/accounts */ export const getApiUserprofilesUserprofilesIdAccounts = async (args: GetApiUserprofilesUserprofilesIdAccountsArgs, options?: GetApiUserprofilesUserprofilesIdAccountsOptions) => { 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.active != null) query.append("active", String(args.active)) for (const item of args.ids ?? []) query.append("ids", String(item)) if (args.maxResults != null) query.append("maxResults", String(args.maxResults)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.searchString != null) query.append("searchString", String(args.searchString)) if (args.sortField != null) query.append("sortField", String(args.sortField)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(accountsListResponse, await res.json()) };