import {z} from 'zod' export type ProtosAutomationsV1Condition = {mode?: ('MODE_ALL' | 'MODE_ANY' | 'MODE_NONE' | 'MODE_UNKNOWN') | undefined, type?: ('CONDITION_TYPE_REPOSITORY_ID' | 'CONDITION_TYPE_REPOSITORY_TAG_ID' | 'CONDITION_TYPE_PRIMARY_REF' | 'CONDITION_TYPE_PATH' | 'CONDITION_TYPE_REF' | 'CONDITION_TYPE_SEVERITY' | 'CONDITION_TYPE_CONFIDENCE' | 'CONDITION_TYPE_PRODUCT' | 'CONDITION_TYPE_POLICY' | 'CONDITION_TYPE_REACHABILITY' | 'CONDITION_TYPE_TRANSITIVITY' | 'CONDITION_TYPE_UPGRADE_AVAILABILITY' | 'CONDITION_TYPE_EPSS_CATEGORY' | 'CONDITION_TYPE_VALIDATION_STATE' | 'CONDITION_TYPE_CVE' | 'CONDITION_TYPE_REPOSITORY_VISIBILITY' | 'CONDITION_TYPE_SECRET_TYPE' | 'CONDITION_TYPE_AI_VERDICT' | 'CONDITION_TYPE_AI_TAG' | 'CONDITION_TYPE_AGGREGATE_STATE' | 'CONDITION_TYPE_HAS_EXTERNAL_TICKET' | 'CONDITION_TYPE_VULNERABILITY_ID' | 'CONDITION_TYPE_UNKNOWN' | 'CONDITION_TYPE_MALICIOUS_DEPENDENCY' | 'CONDITION_TYPE_RULE_ID' | 'CONDITION_TYPE_RULESET_ID' | 'CONDITION_TYPE_WORKFLOW_ID' | 'CONDITION_TYPE_VULNERABILITY_CLASS' | 'CONDITION_TYPE_TRIAGE_STATE') | undefined, values?: Array | undefined}; export type ProtosAutomationsV1Filters = {mode?: ('MODE_ALL' | 'MODE_ANY' | 'MODE_NONE' | 'MODE_UNKNOWN') | undefined, conditions?: Array | undefined}; export type ProtosAutomationsV1Action = {type?: ('ACTION_TYPE_BLOCK' | 'ACTION_TYPE_PR_COMMENT' | 'ACTION_TYPE_JIRA' | 'ACTION_TYPE_SLACK_APP' | 'ACTION_TYPE_EMAIL' | 'ACTION_TYPE_WEBHOOK' | 'ACTION_TYPE_SLACK_WEBHOOK' | 'ACTION_TYPE_S3' | 'ACTION_TYPE_UNKNOWN' | 'ACTION_TYPE_WIZ' | 'ACTION_TYPE_TRIAGE' | 'ACTION_TYPE_DEVELOPER_EXCEPTION_REQUESTS') | undefined, config?: {[key: string]: string} | undefined}; export type ProtosAutomationsV1Automation = {filters?: ProtosAutomationsV1Filters | undefined, actions?: Array | undefined, active?: boolean | undefined, name?: string | undefined, description?: string | undefined, createdBy?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, id?: string | undefined, updatedBy?: string | undefined, internalOnly?: boolean | undefined, triggerSource?: ('TRIGGER_SOURCE_SCAN' | 'TRIGGER_SOURCE_AI_ANALYSIS' | 'TRIGGER_SOURCE_MANUAL' | 'TRIGGER_SOURCE_SUPPLY_CHAIN_INCIDENT' | 'TRIGGER_SOURCE_WORKFLOW' | 'TRIGGER_SOURCE_ISSUE_TRIAGED') | undefined}; export type ProtosAutomationsV1CreateAutomationRequest = {deploymentId?: string | undefined, automation?: ProtosAutomationsV1Automation | undefined}; export type CreateApiApiNotificationsDeploymentsDeploymentIdAutomationsArgs = {deploymentId: string, body: ProtosAutomationsV1CreateAutomationRequest}; export type CreateApiApiNotificationsDeploymentsDeploymentIdAutomationsOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosAutomationsV1Condition = z.object({mode: z.enum(["MODE_ALL", "MODE_ANY", "MODE_NONE", "MODE_UNKNOWN"]).optional(), type: z.enum(["CONDITION_TYPE_REPOSITORY_ID", "CONDITION_TYPE_REPOSITORY_TAG_ID", "CONDITION_TYPE_PRIMARY_REF", "CONDITION_TYPE_PATH", "CONDITION_TYPE_REF", "CONDITION_TYPE_SEVERITY", "CONDITION_TYPE_CONFIDENCE", "CONDITION_TYPE_PRODUCT", "CONDITION_TYPE_POLICY", "CONDITION_TYPE_REACHABILITY", "CONDITION_TYPE_TRANSITIVITY", "CONDITION_TYPE_UPGRADE_AVAILABILITY", "CONDITION_TYPE_EPSS_CATEGORY", "CONDITION_TYPE_VALIDATION_STATE", "CONDITION_TYPE_CVE", "CONDITION_TYPE_REPOSITORY_VISIBILITY", "CONDITION_TYPE_SECRET_TYPE", "CONDITION_TYPE_AI_VERDICT", "CONDITION_TYPE_AI_TAG", "CONDITION_TYPE_AGGREGATE_STATE", "CONDITION_TYPE_HAS_EXTERNAL_TICKET", "CONDITION_TYPE_VULNERABILITY_ID", "CONDITION_TYPE_UNKNOWN", "CONDITION_TYPE_MALICIOUS_DEPENDENCY", "CONDITION_TYPE_RULE_ID", "CONDITION_TYPE_RULESET_ID", "CONDITION_TYPE_WORKFLOW_ID", "CONDITION_TYPE_VULNERABILITY_CLASS", "CONDITION_TYPE_TRIAGE_STATE"]).optional(), values: z.array(z.string()).optional()}); export const protosAutomationsV1Filters = z.object({mode: z.enum(["MODE_ALL", "MODE_ANY", "MODE_NONE", "MODE_UNKNOWN"]).optional(), conditions: z.array(protosAutomationsV1Condition).optional()}); export const protosAutomationsV1Action = z.object({type: z.enum(["ACTION_TYPE_BLOCK", "ACTION_TYPE_PR_COMMENT", "ACTION_TYPE_JIRA", "ACTION_TYPE_SLACK_APP", "ACTION_TYPE_EMAIL", "ACTION_TYPE_WEBHOOK", "ACTION_TYPE_SLACK_WEBHOOK", "ACTION_TYPE_S3", "ACTION_TYPE_UNKNOWN", "ACTION_TYPE_WIZ", "ACTION_TYPE_TRIAGE", "ACTION_TYPE_DEVELOPER_EXCEPTION_REQUESTS"]).optional(), config: z.record(z.string(), z.string()).optional()}); export const protosAutomationsV1Automation = z.object({filters: protosAutomationsV1Filters.optional(), actions: z.array(protosAutomationsV1Action).optional(), active: z.boolean().optional(), name: z.string().optional(), description: z.string().optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), id: z.string().optional(), updatedBy: z.string().optional(), internalOnly: z.boolean().optional(), triggerSource: z.enum(["TRIGGER_SOURCE_SCAN", "TRIGGER_SOURCE_AI_ANALYSIS", "TRIGGER_SOURCE_MANUAL", "TRIGGER_SOURCE_SUPPLY_CHAIN_INCIDENT", "TRIGGER_SOURCE_WORKFLOW", "TRIGGER_SOURCE_ISSUE_TRIAGED"]).optional()}); export const protosAutomationsV1CreateAutomationResponse = z.object({automation: protosAutomationsV1Automation.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 }; /** * Create Automation * * POST /api/notifications/deployments/{deploymentId}/automations * * Also accepts auth: SemgrepJWT */ export const createApiApiNotificationsDeploymentsDeploymentIdAutomations = async (args: CreateApiApiNotificationsDeploymentsDeploymentIdAutomationsArgs, options: CreateApiApiNotificationsDeploymentsDeploymentIdAutomationsOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/notifications/deployments/${encodeURIComponent(String(args.deploymentId))}/automations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(protosAutomationsV1CreateAutomationResponse, await res.json()) };