import {z} from 'zod' export type GetApiV01AppsOwnerNameAppNameReleasesArgs = {published_only?: boolean | undefined, scope?: string | undefined, top?: number | undefined, releaseId?: number | undefined, owner_name: string, app_name: string}; export type GetApiV01AppsOwnerNameAppNameReleasesOptions = {baseUrl?: string | undefined, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV01AppsOwnerNameAppNameReleasesResponse = z.array(z.object({id: z.number().int(), version: z.string(), origin: z.enum(["hockeyapp", "appcenter"]).optional(), short_version: z.string(), enabled: z.boolean(), uploaded_at: z.string(), destination_type: z.enum(["group", "store", "tester"]).optional(), distribution_groups: z.array(z.object({id: z.string(), name: z.string().optional(), is_latest: z.boolean().optional()})).optional(), distribution_stores: z.array(z.object({id: z.string(), name: z.string().optional(), type: z.enum(["intune", "googleplay", "apple", "none"]).optional(), publishing_status: z.string().optional(), is_latest: z.boolean().optional()})).optional(), destinations: z.array(z.object({id: z.string(), name: z.string().optional(), is_latest: z.boolean().optional(), type: z.enum(["intune", "googleplay", "apple", "none"]).optional(), publishing_status: z.string().optional(), destination_type: z.enum(["group", "store", "tester"]).optional(), display_name: z.string().optional()})).optional(), build: z.object({branch_name: z.string().optional(), commit_hash: z.string().optional(), commit_message: z.string().optional()}).optional(), is_external_build: z.boolean().optional(), file_extension: 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 }; /** * Return basic information about releases. * * GET /v0.1/apps/{owner_name}/{app_name}/releases */ export const getApiV01AppsOwnerNameAppNameReleases = async (args: GetApiV01AppsOwnerNameAppNameReleasesArgs, options?: GetApiV01AppsOwnerNameAppNameReleasesOptions) => { 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.published_only != null) query.append("published_only", String(args.published_only)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.top != null) query.append("top", String(args.top)) if (args.releaseId != null) query.append("releaseId", String(args.releaseId)) 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))}/releases${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(getApiV01AppsOwnerNameAppNameReleasesResponse, await res.json()) };