import {z} from 'zod' export type GetApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsArgs = {orgId: string, appId: string, pipelineId: string, env?: string | undefined, status?: Array | undefined, completed?: boolean | undefined, created_after?: string | undefined, created_before?: string | undefined, per_page?: number | undefined, page?: string | undefined}; export type GetApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pipelineRun = z.object({id: z.string(), etag: z.string(), org_id: z.string(), app_id: z.string(), env_ids: z.array(z.string()), pipeline_id: z.string(), pipeline_version: z.string(), status: z.string(), status_message: z.string(), created_at: z.string(), created_by: z.string(), executing_at: z.string().optional(), cancellation_requested_at: z.string().optional(), completed_at: z.string().optional(), timeout_seconds: z.number().int(), trigger: z.string(), inputs: z.record(z.string(), z.unknown()), run_as: z.string(), concurrency_group: z.string().optional(), waiting_for: z.record(z.string(), z.string())}); export const getApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsResponse = z.array(pipelineRun); 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 runs within a pipeline ordered newest to oldest. * * GET /orgs/{orgId}/apps/{appId}/pipelines/{pipelineId}/runs */ export const getApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRuns = async (args: GetApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsArgs, options?: GetApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsOptions) => { const {baseUrl = "https://api.humanitec.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.env != null) query.append("env", String(args.env)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.completed != null) query.append("completed", String(args.completed)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.page != null) query.append("page", String(args.page)) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.orgId))}/apps/${encodeURIComponent(String(args.appId))}/pipelines/${encodeURIComponent(String(args.pipelineId))}/runs${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(getApiOrgsOrgIdAppsAppIdPipelinesPipelineIdRunsResponse, await res.json()) };