import {z} from 'zod' export type ProtosOpenapiV1BulkTriageRequest = {autotriage_verdict?: ('true_positive' | 'false_positive') | undefined, categories?: Array | undefined, component_tags?: Array | undefined, confidence?: ('low' | 'medium' | 'high') | undefined, dependencies?: Array | undefined, epss_probability?: Array | undefined, exposures?: Array | undefined, include_historical?: boolean | undefined, issue_ids?: Array | undefined, issue_type: 'sast' | 'sca' | 'secrets', limit?: number | undefined, new_note?: string | undefined, new_triage_reason?: ('acceptable_risk' | 'false_positive' | 'no_time' | 'no_triage_reason' | 'duplicate') | undefined, new_triage_state?: ('ignored' | 'reviewing' | 'fixing' | 'reopened' | 'provisionally_ignored') | undefined, policies?: Array | undefined, policy_mode?: Array | undefined, pro_only?: boolean | undefined, project_tags?: Array | undefined, ref?: string | undefined, repos?: Array | undefined, repository_visibility?: Array | undefined, rules?: Array | undefined, ruleset?: Array | undefined, secret_types?: Array | undefined, severities?: Array | undefined, since?: string | undefined, status?: ('open' | 'fixed' | 'ignored' | 'reviewing' | 'fixing' | 'provisionally_ignored') | undefined, transitivities?: Array | undefined, triage_reasons?: Array | undefined, validation_state?: Array | undefined}; export type CreateApiApiV1DeploymentsDeploymentSlugTriageArgs = {deploymentSlug: string, body: ProtosOpenapiV1BulkTriageRequest}; export type CreateApiApiV1DeploymentsDeploymentSlugTriageOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosOpenapiV1BulkTriageResponse = z.object({num_triaged: z.number().int(), triaged_issues: z.array(z.number().int())}); 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 }; /** * Bulk triage * * POST /api/v1/deployments/{deploymentSlug}/triage */ export const createApiApiV1DeploymentsDeploymentSlugTriage = async (args: CreateApiApiV1DeploymentsDeploymentSlugTriageArgs, options: CreateApiApiV1DeploymentsDeploymentSlugTriageOptions) => { 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/v1/deployments/${encodeURIComponent(String(args.deploymentSlug))}/triage${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(protosOpenapiV1BulkTriageResponse, await res.json()) };