import {z} from 'zod' export type BuildStatusFilter = 'queued' | 'waiting' | 'building' | 'finished' | 'failed' | 'canceled' | 'timeout' | 'skipped'; export type GetApiApiV3TeamsTeamIdBuildsArgs = {app_id?: (string | null) | undefined, status?: (BuildStatusFilter | null) | undefined, workflow_id?: (string | null) | undefined, branch?: (string | null) | undefined, tag?: (string | null) | undefined, label?: (Array | null) | undefined, cursor: unknown, page_size?: number | undefined, team_id: string}; export type GetApiApiV3TeamsTeamIdBuildsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workflowSource = z.enum(["file", "ui"]); export const workflow = z.object({id: z.string(), source: workflowSource, name: z.string().nullable().optional()}); export const buildStatus = z.enum(["initializing", "queued", "waiting", "preparing", "fetching", "testing", "building", "publishing", "finishing", "finished", "failed", "canceled", "timeout", "skipped"]); export const artifactType = z.enum(["aab", "aar", "apk", "app", "bundle", "coverage_binary", "coverage_data", "device_recording", "directory", "dsym", "flutter_drive_log", "flutter_web_build_dir", "glob_matched", "ios_uitest_package", "ios_xctest_package", "ipa", "jar", "lint_result", "linux_app", "log", "logcat", "msix", "pkg", "proguard_map", "ios_simulator_log", "snap", "static_lib", "sylph_artefact_dir", "test_results_bundle", "windows_exe", "xcarchive", "xcodebuild_log"]); export const artifact = z.object({name: z.string(), size_in_bytes: z.number().int(), type: artifactType, short_lived_download_url: z.string(), version_code: z.string().nullable(), version_name: z.string().nullable()}); export const releaseNote = z.object({language: z.string(), text: z.string()}); export const commit = z.object({hash: z.string().nullable().optional(), avatar_url: z.string().nullable().optional(), author_name: z.string().nullable().optional(), author_email: z.string().nullable().optional(), message: z.string().nullable().optional(), url: z.string().nullable().optional()}); export const pullRequest = z.object({number: z.number().int(), source_branch: z.string(), destination_branch: z.string()}); export const appStoreConnectTaskStatus = z.enum(["initiated", "pending", "processing", "finished", "timeout", "failed"]); export const buildSummary = z.object({id: z.string(), app_id: z.string(), workflow: workflow, status: buildStatus, index: z.number().int(), artifacts: z.array(artifact), labels: z.array(z.string()), release_notes: z.array(releaseNote), created_at: z.string(), priority: z.number().int(), commit: commit.nullable().optional(), branch: z.string().nullable().optional(), tag: z.string().nullable().optional(), pull_request: pullRequest.nullable().optional(), app_store_connect_status: appStoreConnectTaskStatus.nullable().optional(), started_at: z.string().nullable().optional(), finished_at: z.string().nullable().optional()}); export const buildSummaryCursorPagination = z.object({data: z.array(buildSummary), page_size: z.number().int(), cursor: z.unknown()}); 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 }; /** * List team builds * * GET /api/v3/teams/{team_id}/builds */ export const getApiApiV3TeamsTeamIdBuilds = async (args: GetApiApiV3TeamsTeamIdBuildsArgs, options?: GetApiApiV3TeamsTeamIdBuildsOptions) => { const {baseUrl = "https://codemagic.io", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.app_id != null) query.append("app_id", String(args.app_id)) if (args.status != null) query.append("status", String(args.status)) if (args.workflow_id != null) query.append("workflow_id", String(args.workflow_id)) if (args.branch != null) query.append("branch", String(args.branch)) if (args.tag != null) query.append("tag", String(args.tag)) for (const item of args.label ?? []) query.append("label", String(item)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (apiKey !== undefined) headers.set("x-auth-token", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/teams/${encodeURIComponent(String(args.team_id))}/builds${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(buildSummaryCursorPagination, await res.json()) };