import {z} from 'zod' export type DeploymentGatesEvaluationResultResponseAttributesGateStatus = 'in_progress' | 'pass' | 'fail'; export type DeploymentGateRuleEvaluationType = 'monitor' | 'faulty_deployment_detection'; export type GetApiApiV2DeploymentGatesEvaluationsRulesArgs = {'filter[from]'?: string | undefined, 'filter[to]'?: string | undefined, 'filter[gate_evaluation_id]'?: string | undefined, 'filter[evaluation_id]'?: string | undefined, 'filter[gate_id]'?: string | undefined, 'filter[rule_id]'?: string | undefined, 'filter[service]'?: Array | undefined, 'filter[env]'?: Array | undefined, 'filter[identifier]'?: Array | undefined, 'filter[version]'?: Array | undefined, 'filter[status]'?: Array | undefined, 'filter[type]'?: Array | undefined, 'filter[dry_run]'?: boolean | undefined, 'filter[gate_dry_run]'?: boolean | undefined, 'filter[name]'?: Array | undefined, 'page[size]'?: number | undefined, 'page[cursor]'?: string | undefined}; export type GetApiApiV2DeploymentGatesEvaluationsRulesOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, appKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const deploymentGateRuleEvaluationConfiguration = z.object({allowed_resources: z.array(z.string()).optional(), duration: z.number().int().optional(), excluded_resources: z.array(z.string()).optional(), fail_on_no_data: z.boolean().optional(), fail_on_no_groups_found: z.boolean().optional(), monitor_ids: z.array(z.string()).optional(), query: z.string().optional(), warmup: z.number().int().optional()}); export const deploymentGateRuleFailureMonitor = z.object({id: z.string(), state: z.string(), url: z.string()}); export const deploymentGateRuleFailureNarrative = z.object({hostgroup: z.string(), id: z.string()}); export const deploymentGateRuleFailures = z.object({faulty_apm_resources: z.array(z.string()), monitors: z.array(deploymentGateRuleFailureMonitor), narratives: z.array(deploymentGateRuleFailureNarrative)}); export const deploymentGatesEvaluationResultResponseAttributesGateStatus = z.enum(["in_progress", "pass", "fail"]); export const deploymentGateRuleEvaluationType = z.enum(["monitor", "faulty_deployment_detection"]); export const deploymentGateRuleEvaluationAttributes = z.object({configuration: deploymentGateRuleEvaluationConfiguration, dry_run: z.boolean(), duration_seconds: z.number().int().nullable(), env: z.string(), evaluation_id: z.string(), failures: deploymentGateRuleFailures, finished_at: z.string().nullable(), gate_dry_run: z.boolean(), gate_evaluation_id: z.string(), gate_id: z.string().nullable(), identifier: z.string(), name: z.string(), reason: z.string(), rule_id: z.string().nullable(), service: z.string(), started_at: z.string(), status: deploymentGatesEvaluationResultResponseAttributesGateStatus, type: deploymentGateRuleEvaluationType, version: z.string()}); export const deploymentGateRuleEvaluationDataType = z.literal("deployment_gate_rule_evaluation"); export const deploymentGateRuleEvaluationData = z.object({attributes: deploymentGateRuleEvaluationAttributes, id: z.string(), type: deploymentGateRuleEvaluationDataType}); export const deploymentGateEvaluationPage = z.object({next_cursor: z.string().optional(), size: z.number().int().gte(1).lte(100)}); export const deploymentGateEvaluationListMeta = z.object({page: deploymentGateEvaluationPage}); export const deploymentGateRuleEvaluationsResponse = z.object({data: z.array(deploymentGateRuleEvaluationData), meta: deploymentGateEvaluationListMeta}); 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 deployment gate rule evaluations * * GET /api/v2/deployment_gates/evaluations/rules * * Also accepts auth: AuthZ */ export const getApiApiV2DeploymentGatesEvaluationsRules = async (args: GetApiApiV2DeploymentGatesEvaluationsRulesArgs, options?: GetApiApiV2DeploymentGatesEvaluationsRulesOptions) => { 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 (args['filter[from]'] != null) query.append("filter[from]", String(args['filter[from]'])) if (args['filter[to]'] != null) query.append("filter[to]", String(args['filter[to]'])) if (args['filter[gate_evaluation_id]'] != null) query.append("filter[gate_evaluation_id]", String(args['filter[gate_evaluation_id]'])) if (args['filter[evaluation_id]'] != null) query.append("filter[evaluation_id]", String(args['filter[evaluation_id]'])) if (args['filter[gate_id]'] != null) query.append("filter[gate_id]", String(args['filter[gate_id]'])) if (args['filter[rule_id]'] != null) query.append("filter[rule_id]", String(args['filter[rule_id]'])) for (const item of args['filter[service]'] ?? []) query.append("filter[service]", String(item)) for (const item of args['filter[env]'] ?? []) query.append("filter[env]", String(item)) for (const item of args['filter[identifier]'] ?? []) query.append("filter[identifier]", String(item)) for (const item of args['filter[version]'] ?? []) query.append("filter[version]", String(item)) for (const item of args['filter[status]'] ?? []) query.append("filter[status]", String(item)) for (const item of args['filter[type]'] ?? []) query.append("filter[type]", String(item)) if (args['filter[dry_run]'] != null) query.append("filter[dry_run]", String(args['filter[dry_run]'])) if (args['filter[gate_dry_run]'] != null) query.append("filter[gate_dry_run]", String(args['filter[gate_dry_run]'])) for (const item of args['filter[name]'] ?? []) query.append("filter[name]", String(item)) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[cursor]'] != null) query.append("page[cursor]", String(args['page[cursor]'])) if (apiKeyAuth !== undefined) headers.set("DD-API-KEY", apiKeyAuth) if (appKeyAuth !== undefined) headers.set("DD-APPLICATION-KEY", appKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/deployment_gates/evaluations/rules${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(deploymentGateRuleEvaluationsResponse, await res.json()) };