import {z} from 'zod' export type GetApiUserprofilesUserprofilesIdMobileAppsArgs = {userprofilesId: string, directories?: (Array<'UNKNOWN' | 'APPLE_APP_STORE' | 'GOOGLE_PLAY_STORE' | 'ROKU_APP_STORE' | 'AMAZON_FIRETV_APP_STORE' | 'PLAYSTATION_APP_STORE' | 'APPLE_TV_APP_STORE' | 'XBOX_APP_STORE' | 'SAMSUNG_TV_APP_STORE' | 'ANDROID_TV_APP_STORE' | 'GENERIC_CTV_APP_STORE'>) | undefined, ids?: Array | undefined, maxResults?: number | undefined, pageToken?: string | undefined, searchString?: string | undefined}; export type GetApiUserprofilesUserprofilesIdMobileAppsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const mobileApp = z.object({directory: z.enum(["UNKNOWN", "APPLE_APP_STORE", "GOOGLE_PLAY_STORE", "ROKU_APP_STORE", "AMAZON_FIRETV_APP_STORE", "PLAYSTATION_APP_STORE", "APPLE_TV_APP_STORE", "XBOX_APP_STORE", "SAMSUNG_TV_APP_STORE", "ANDROID_TV_APP_STORE", "GENERIC_CTV_APP_STORE"]).optional(), id: z.string().optional(), kind: z.string().optional(), publisherName: z.string().optional(), title: z.string().optional()}); export const mobileAppsListResponse = z.object({kind: z.string().optional(), mobileApps: z.array(mobileApp).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 list of available mobile apps. * * GET /userprofiles/{userprofilesId}/mobileApps */ export const getApiUserprofilesUserprofilesIdMobileApps = async (args: GetApiUserprofilesUserprofilesIdMobileAppsArgs, options?: GetApiUserprofilesUserprofilesIdMobileAppsOptions) => { 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") for (const item of args.directories ?? []) query.append("directories", String(item)) 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 (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/userprofiles/${encodeURIComponent(String(args.userprofilesId))}/mobileApps${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(mobileAppsListResponse, await res.json()) };