import {z} from 'zod' export type GetApiV01AppsOwnerNameAppNameSymbolsArgs = {owner_name: string, app_name: string}; export type GetApiV01AppsOwnerNameAppNameSymbolsOptions = {baseUrl?: string | undefined, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV01AppsOwnerNameAppNameSymbolsResponse = z.array(z.object({symbol_id: z.string(), type: z.enum(["Apple", "JavaScript", "Breakpad", "AndroidProguard", "UWP"]), app_id: z.string(), platform: z.string(), url: z.string(), origin: z.enum(["System", "User"]), alternate_symbol_ids: z.array(z.string()), status: z.enum(["available", "ignored"]), version: z.string().optional(), build: z.string().optional(), symbol_upload_id: z.string()})); 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 }; /** * Returns the list of all symbols for the provided application * * GET /v0.1/apps/{owner_name}/{app_name}/symbols */ export const getApiV01AppsOwnerNameAppNameSymbols = async (args: GetApiV01AppsOwnerNameAppNameSymbolsArgs, options?: GetApiV01AppsOwnerNameAppNameSymbolsOptions) => { 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 (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))}/symbols${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(getApiV01AppsOwnerNameAppNameSymbolsResponse, await res.json()) };