import {z} from 'zod' export type GetApiV01PublicSdkAppsAppSecretReleasesLatestArgs = {app_secret: string}; export type GetApiV01PublicSdkAppsAppSecretReleasesLatestOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV01PublicSdkAppsAppSecretReleasesLatestResponse = z.object({id: z.number().int(), app_name: z.string(), app_display_name: z.string(), app_os: z.string().optional(), version: z.string(), origin: z.enum(["hockeyapp", "appcenter"]).optional(), short_version: z.string(), release_notes: z.string().optional(), provisioning_profile_name: z.string().optional(), provisioning_profile_type: z.enum(["adhoc", "enterprise", "other"]).optional(), provisioning_profile_expiry_date: z.string().optional(), is_provisioning_profile_syncing: z.boolean().optional(), size: z.number().int().optional(), min_os: z.string().optional(), device_family: z.string().optional(), android_min_api_level: z.string().optional(), bundle_identifier: z.string().optional(), package_hashes: z.array(z.string()).optional(), fingerprint: z.string().optional(), uploaded_at: z.string(), download_url: z.string().optional(), secondary_download_url: z.string().optional(), app_icon_url: z.string(), install_url: z.string().optional(), destination_type: z.enum(["group", "store", "tester"]).optional(), distribution_groups: z.array(z.object({id: z.string(), name: z.string().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()})).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(), is_udid_provisioned: z.boolean().optional(), can_resign: z.boolean().optional(), build: z.object({branch_name: z.string().optional(), commit_hash: z.string().optional(), commit_message: z.string().optional()}).optional(), enabled: z.boolean(), status: z.string().optional(), is_external_build: z.boolean().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 }; /** * Get the latest public release for the given app. * * GET /v0.1/public/sdk/apps/{app_secret}/releases/latest */ export const getApiV01PublicSdkAppsAppSecretReleasesLatest = async (args: GetApiV01PublicSdkAppsAppSecretReleasesLatestArgs, options?: GetApiV01PublicSdkAppsAppSecretReleasesLatestOptions) => { const {baseUrl = "https://api.appcenter.ms", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v0.1/public/sdk/apps/${encodeURIComponent(String(args.app_secret))}/releases/latest${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(getApiV01PublicSdkAppsAppSecretReleasesLatestResponse, await res.json()) };