import {z} from 'zod' export type GetApiPhonesSupportedAppsArgs = {platform?: ('android' | 'ios' | 'both') | undefined, category?: ('social' | 'productivity' | 'entertainment' | 'shopping' | 'finance' | 'utilities' | 'browser' | 'messaging' | 'other') | undefined}; export type GetApiPhonesSupportedAppsOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const phoneAppSummary = z.object({android_package_name: z.string(), app_metadata: z.record(z.string(), z.unknown()), category: z.enum(["social", "productivity", "entertainment", "shopping", "finance", "utilities", "browser", "messaging", "other"]), created_at: z.string(), description: z.string().nullable(), icon_url: z.string().nullable(), id: z.string(), ios_app_store_id: z.string().nullable(), is_supported: z.boolean(), model_datasets: z.array(z.string()).nullable(), model_status: z.enum(["pending", "training", "trained", "failed"]), model_trained_at: z.string().nullable(), name: z.string(), platform: z.enum(["android", "ios", "both"]), slug: z.string(), updated_at: z.string(), version: z.string().nullable()}); export const phoneSupportedAppsResponse = z.object({$schema: z.string().optional(), phone_apps: z.array(phoneAppSummary).nullable(), total: z.number().int()}); 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 }; /** * List supported apps * * GET /phones/supported-apps */ export const getApiPhonesSupportedApps = async (args: GetApiPhonesSupportedAppsArgs, options: GetApiPhonesSupportedAppsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.platform != null) query.append("platform", String(args.platform)) if (args.category != null) query.append("category", String(args.category)) if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/phones/supported-apps${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(phoneSupportedAppsResponse, await res.json()) };