import {z} from 'zod' export type GetApiApiV2FleetDeploymentsDeploymentIdArgs = {deployment_id: string}; export type GetApiApiV2FleetDeploymentsDeploymentIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fleetDeploymentFileOp = z.enum(["merge-patch", "delete"]); export const fleetDeploymentOperation = z.object({file_op: fleetDeploymentFileOp, file_path: z.string(), patch: z.record(z.string(), z.unknown()).optional()}); export const fleetDeploymentHostPackage = z.object({current_version: z.string().optional(), initial_version: z.string().optional(), package_name: z.string().optional(), target_version: z.string().optional()}); export const fleetDeploymentV2DetailAgent = z.object({error: z.string().optional(), hostname: z.string().optional(), running_step: z.string().optional(), status: z.string().optional(), status_details: z.string().optional(), versions: z.array(fleetDeploymentHostPackage).optional()}); export const fleetDeploymentV2DetailAttributes = z.object({author: z.string().optional(), canceled_hosts: z.number().int().gte(0).optional(), config_operations: z.array(fleetDeploymentOperation).optional(), duration_seconds: z.number().int().optional(), error_summary: z.string().optional(), estimated_finished_at: z.number().int().optional(), failed_hosts: z.number().int().gte(0).optional(), high_level_status: z.string().optional(), hosts: z.array(fleetDeploymentV2DetailAgent).optional(), is_scheduled: z.boolean().optional(), query: z.string().optional(), running_hosts: z.number().int().gte(0).optional(), schedule_id: z.string().optional(), skipped_hosts: z.number().int().gte(0).optional(), succeeded_hosts: z.number().int().gte(0).optional(), target_versions: z.array(z.string()).optional(), total_hosts: z.number().int().optional(), update_type: z.string().optional()}); export const fleetDeploymentResourceType = z.literal("deployment"); export const fleetDeploymentV2Detail = z.object({attributes: fleetDeploymentV2DetailAttributes, id: z.string(), type: fleetDeploymentResourceType}); export const fleetDeploymentV2DetailResponse = z.object({data: fleetDeploymentV2Detail}); 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 a deployment by ID * * GET /api/v2/fleet/deployments/{deployment_id} * * Also accepts auth: AuthZ */ export const getApiApiV2FleetDeploymentsDeploymentId = async (args: GetApiApiV2FleetDeploymentsDeploymentIdArgs, options?: GetApiApiV2FleetDeploymentsDeploymentIdOptions) => { const {baseUrl = "https://api.datadoghq.com", fetch: fetchFn = fetch, apiKeyAuth, appKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/fleet/deployments/${encodeURIComponent(String(args.deployment_id))}${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(fleetDeploymentV2DetailResponse, await res.json()) };