import {z} from 'zod' export type ProtosPermissionsV2TeamRepositoryAction = {repositoryId?: unknown | undefined, action?: ('UPDATE_ACTION_ADD' | 'UPDATE_ACTION_UPDATE' | 'UPDATE_ACTION_REMOVE') | undefined}; export type ProtosPermissionsV2TeamUserAction = {userId?: unknown | undefined, action?: ('UPDATE_ACTION_ADD' | 'UPDATE_ACTION_UPDATE' | 'UPDATE_ACTION_REMOVE') | undefined, role?: ('TEAM_ROLE_MEMBER' | 'TEAM_ROLE_MANAGER' | 'TEAM_ROLE_READONLY') | undefined}; export type ProtosPermissionsV2TeamUpdate = {name?: string | undefined, repositories?: Array | undefined, users?: Array | undefined}; export type ProtosPermissionsV2UpdateDeploymentTeamRequest = {team?: ProtosPermissionsV2TeamUpdate | undefined}; export type PatchApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdArgs = {deploymentId: number, teamId: number, body: ProtosPermissionsV2UpdateDeploymentTeamRequest}; export type PatchApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosPermissionsV2Team = z.object({id: z.string().optional(), deploymentId: z.string().optional(), name: z.string().optional(), slug: z.string().optional(), parentTeamId: z.string().optional(), repositoryCount: z.string().optional(), userCount: z.string().optional(), childTeamCount: z.string().optional(), isProjectDefault: z.boolean().optional(), isUserDefault: z.boolean().optional(), authorizedScopes: z.array(z.enum(["TEAM_SCOPE_UNSPECIFIED", "TEAM_SCOPE_DIRECT_MEMBER", "TEAM_SCOPE_MANAGE"])).optional()}); export const protosPermissionsV2UpdateDeploymentTeamResponse = z.object({team: protosPermissionsV2Team.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 a deployment RBAC team * * PATCH /api/permissions/v2/deployments/{deploymentId}/teams/{teamId} * * Also accepts auth: SemgrepJWT */ export const patchApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamId = async (args: PatchApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdArgs, options: PatchApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdOptions) => { 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/permissions/v2/deployments/${encodeURIComponent(String(args.deploymentId))}/teams/${encodeURIComponent(String(args.teamId))}${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(protosPermissionsV2UpdateDeploymentTeamResponse, await res.json()) };