import {z} from 'zod' export type GetApiV01SdkAppsAppSecretReleasesReleaseHashArgs = {app_secret: string, release_hash: string, udid?: string | undefined}; export type GetApiV01SdkAppsAppSecretReleasesReleaseHashOptions = {baseUrl?: string | undefined, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV01SdkAppsAppSecretReleasesReleaseHashResponse = 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 }; /** * If 'latest' is not specified then it will return the specified release if it's enabled. If 'latest' is specified, regardless of whether a release hash is provided, the latest enabled release is returned. * * GET /v0.1/sdk/apps/{app_secret}/releases/{release_hash} */ export const getApiV01SdkAppsAppSecretReleasesReleaseHash = async (args: GetApiV01SdkAppsAppSecretReleasesReleaseHashArgs, options?: GetApiV01SdkAppsAppSecretReleasesReleaseHashOptions) => { 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.udid != null) query.append("udid", String(args.udid)) if (APIToken !== undefined) headers.set("X-API-Token", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/v0.1/sdk/apps/${encodeURIComponent(String(args.app_secret))}/releases/${encodeURIComponent(String(args.release_hash))}${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(getApiV01SdkAppsAppSecretReleasesReleaseHashResponse, await res.json()) };