import {z} from 'zod' export type GetApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsArgs = {top: number, owner_name: string, app_name: string}; export type GetApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsOptions = {baseUrl?: string | undefined, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsResponse = z.object({total_crash_count: z.number().int(), groups: z.array(z.object({symbol_group_id: z.string(), crash_count: z.number().int().optional(), error_count: z.number().int().optional(), app_id: z.string(), app_ver: z.string(), app_build: z.string(), last_modified: z.string(), missing_symbols: z.array(z.object({symbol_id: z.string(), name: z.string(), platform: z.string().optional(), status: z.enum(["missing", "ignored", "available"])})), status: z.enum(["active", "pending", "closed"])}))}); 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 top N (ordered by crash count) of crash groups by missing symbol * * GET /v0.1/apps/{owner_name}/{app_name}/diagnostics/symbol_groups */ export const getApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroups = async (args: GetApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsArgs, options?: GetApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsOptions) => { const {baseUrl = "https://api.appcenter.ms", fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.top != null) query.append("top", String(args.top)) if (APIToken !== undefined) headers.set("X-API-Token", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/v0.1/apps/${encodeURIComponent(String(args.owner_name))}/${encodeURIComponent(String(args.app_name))}/diagnostics/symbol_groups${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(getApiV01AppsOwnerNameAppNameDiagnosticsSymbolGroupsResponse, await res.json()) };