import {z} from 'zod' export type ProtosDeploymentV1UpdateDeploymentRequest = {deploymentId?: string | undefined, displayName?: string | undefined, defaultUserRole?: ('ORG_ROLE_ADMIN' | 'ORG_ROLE_MEMBER' | 'ORG_ROLE_IMPERSONATOR' | 'ORG_ROLE_READONLY') | undefined}; export type PatchApiApiAgentDeploymentsDeploymentIdArgs = {deploymentId: string, body: ProtosDeploymentV1UpdateDeploymentRequest}; export type PatchApiApiAgentDeploymentsDeploymentIdOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosDeploymentV1FeatureFlag = z.object({name: z.string().optional(), expiresAt: z.string().optional()}); export const protosDeploymentV1DeploymentFeatures = z.object({featureFlags: z.array(protosDeploymentV1FeatureFlag).optional(), hasAutofix: z.boolean().optional(), hasDeepsemgrep: z.boolean().optional(), hasTriageViaComment: z.boolean().optional(), hasDependencyQuery: z.boolean().optional(), defaultUserRole: z.enum(["ORG_ROLE_ADMIN", "ORG_ROLE_MEMBER", "ORG_ROLE_IMPERSONATOR", "ORG_ROLE_READONLY"]).optional(), editorSemgrepVersion: z.string().optional(), nosemgrepDisabled: z.boolean().optional()}); export const protosDeploymentV1Deployment = z.object({id: z.string().optional(), name: z.string().optional(), displayName: z.string().optional(), slug: z.string().optional(), sourceType: z.string().optional(), features: protosDeploymentV1DeploymentFeatures.optional(), organizationId: z.string().optional()}); export const protosDeploymentV1UpdateDeploymentResponse = z.object({deployment: protosDeploymentV1Deployment.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 }; /** * Update Deployment * * PATCH /api/agent/deployments/{deploymentId} * * Also accepts auth: SemgrepJWT */ export const patchApiApiAgentDeploymentsDeploymentId = async (args: PatchApiApiAgentDeploymentsDeploymentIdArgs, options: PatchApiApiAgentDeploymentsDeploymentIdOptions) => { 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/agent/deployments/${encodeURIComponent(String(args.deploymentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(protosDeploymentV1UpdateDeploymentResponse, await res.json()) };