import {z} from 'zod' export type ProtosCommonV1PaginationOptions = {pageToken?: string | undefined, pageSize?: number | undefined, sortBy?: string | undefined}; export type ProtosDeploymentV1ListDeploymentUsersFilter = {query?: string | undefined, pruneGithub?: boolean | undefined, showActive?: boolean | undefined, filterMembers?: ('MEMBER_FILTER_TYPE_ADMIN_ONLY' | 'MEMBER_FILTER_TYPE_NON_ADMIN_ONLY') | undefined, memberIds?: Array | undefined}; export type ProtosDeploymentV1ListDeploymentUsersRequest = {deploymentId?: string | undefined, options?: ProtosCommonV1PaginationOptions | undefined, filters?: ProtosDeploymentV1ListDeploymentUsersFilter | undefined}; export type CreateApiApiAgentDeploymentsDeploymentIdUsersListArgs = {deploymentId: string, body: ProtosDeploymentV1ListDeploymentUsersRequest}; export type CreateApiApiAgentDeploymentsDeploymentIdUsersListOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosPermissionsCommonV1GroupUser = z.object({userId: z.string().optional(), role: z.enum(["ROLE_ADMINISTRATOR", "ROLE_MANAGER", "ROLE_DEVELOPER", "ROLE_READ_ONLY", "ROLE_NO_ACCESS"]).optional()}); export const protosPermissionsCommonV1Group = z.object({id: z.string().optional(), deploymentId: z.string().optional(), name: z.string().optional(), slug: z.string().optional(), description: z.string().optional(), repositoryIds: z.array(z.string()).optional(), users: z.array(protosPermissionsCommonV1GroupUser).optional(), isDefault: z.boolean().optional(), projectManagementType: z.enum(["PROJECT_MANAGEMENT_TYPE_UNMANAGED", "PROJECT_MANAGEMENT_TYPE_ALL_PROJECTS"]).optional(), parentGroupId: z.string().optional(), childGroupIds: z.array(z.string()).optional(), repositoryCount: z.string().optional(), userCount: z.string().optional(), childGroupCount: z.string().optional()}); export const protosDeploymentV1GroupWithRole = z.object({group: protosPermissionsCommonV1Group.optional(), role: z.enum(["ROLE_ADMINISTRATOR", "ROLE_MANAGER", "ROLE_DEVELOPER", "ROLE_READ_ONLY", "ROLE_NO_ACCESS"]).optional()}); export const protosDeploymentV1DeploymentUser = z.object({id: z.string().optional(), orgRole: z.enum(["ORG_ROLE_ADMIN", "ORG_ROLE_MEMBER", "ORG_ROLE_IMPERSONATOR", "ORG_ROLE_READONLY"]).optional(), authentication: z.array(z.string()).optional(), since: z.string().optional(), lastUpdatedAt: z.string().optional(), groups: z.array(protosDeploymentV1GroupWithRole).optional(), name: z.string().optional(), login: z.string().optional(), email: z.string().optional(), avatarUrl: z.string().optional(), active: z.boolean().optional()}); export const protosDeploymentV1ListDeploymentUsersResponse = z.object({users: z.array(protosDeploymentV1DeploymentUser).optional(), pageToken: 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 Users * * POST /api/agent/deployments/{deploymentId}/users/list * * Also accepts auth: SemgrepJWT */ export const createApiApiAgentDeploymentsDeploymentIdUsersList = async (args: CreateApiApiAgentDeploymentsDeploymentIdUsersListArgs, options: CreateApiApiAgentDeploymentsDeploymentIdUsersListOptions) => { 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))}/users/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(protosDeploymentV1ListDeploymentUsersResponse, await res.json()) };