import {z} from 'zod' export type GetApiApiAgentDeploymentsDeploymentIdProjectsProjectIdResolutionConfigsArgs = {deploymentId: number, projectId: number}; export type GetApiApiAgentDeploymentsDeploymentIdProjectsProjectIdResolutionConfigsOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosSmsV2ScaResolutionConfig = z.object({configVersion: z.number().int().optional(), miseTools: z.record(z.string(), z.string()).optional(), envVars: z.record(z.string(), z.string()).optional(), systemPackages: z.array(z.string()).optional(), commands: z.array(z.string()).optional(), outputPath: z.string().optional(), outputFormat: z.literal("SCA_RESOLUTION_OUTPUT_FORMAT_CYCLONEDX_JSON").optional(), resolutionTimeoutS: z.number().int().optional()}); export const protosSmsV2ScaResolutionConfigMapping = z.object({perSubproject: z.record(z.string(), protosSmsV2ScaResolutionConfig).optional()}); export const protosSmsV2GetScaResolutionConfigsResponse = z.object({resolutionConfigs: protosSmsV2ScaResolutionConfigMapping.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 }; /** * Get SCA Resolution Configs * * GET /api/agent/deployments/{deploymentId}/projects/{projectId}/resolution_configs * * Also accepts auth: SemgrepJWT */ export const getApiApiAgentDeploymentsDeploymentIdProjectsProjectIdResolutionConfigs = async (args: GetApiApiAgentDeploymentsDeploymentIdProjectsProjectIdResolutionConfigsArgs, options: GetApiApiAgentDeploymentsDeploymentIdProjectsProjectIdResolutionConfigsOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/agent/deployments/${encodeURIComponent(String(args.deploymentId))}/projects/${encodeURIComponent(String(args.projectId))}/resolution_configs${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(protosSmsV2GetScaResolutionConfigsResponse, await res.json()) };