import {z} from 'zod' export type ProtosPermissionsV2DeploymentTeamsFilter = {name?: string | undefined}; export type ProtosPermissionsV2ListDeploymentTeamsRequest = {limit?: unknown | undefined, cursor?: string | undefined, filter?: ProtosPermissionsV2DeploymentTeamsFilter | undefined}; export type CreateApiApiPermissionsV2DeploymentsDeploymentIdTeamsListArgs = {deploymentId: number, body: ProtosPermissionsV2ListDeploymentTeamsRequest}; export type CreateApiApiPermissionsV2DeploymentsDeploymentIdTeamsListOptions = {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 protosPermissionsV2ListDeploymentTeamsResponse = z.object({teams: z.array(protosPermissionsV2Team).optional(), cursor: z.string().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 }; /** * List deployment teams * * POST /api/permissions/v2/deployments/{deploymentId}/teams/list * * Also accepts auth: SemgrepJWT */ export const createApiApiPermissionsV2DeploymentsDeploymentIdTeamsList = async (args: CreateApiApiPermissionsV2DeploymentsDeploymentIdTeamsListArgs, options: CreateApiApiPermissionsV2DeploymentsDeploymentIdTeamsListOptions) => { 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/list${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(protosPermissionsV2ListDeploymentTeamsResponse, await res.json()) };