import {z} from 'zod' export type GetApiApiAgentDeploymentsDeploymentIdUsersArgs = {deploymentId: string, pruneGithub?: boolean | undefined, showActive?: boolean | undefined}; export type GetApiApiAgentDeploymentsDeploymentIdUsersOptions = {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 protosDeploymentV1GetDeploymentUsersResponse = z.object({users: z.array(protosDeploymentV1DeploymentUser).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 Deployment Users * * GET /api/agent/deployments/{deploymentId}/users * * Also accepts auth: SemgrepJWT */ export const getApiApiAgentDeploymentsDeploymentIdUsers = async (args: GetApiApiAgentDeploymentsDeploymentIdUsersArgs, options: GetApiApiAgentDeploymentsDeploymentIdUsersOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pruneGithub != null) query.append("pruneGithub", String(args.pruneGithub)) if (args.showActive != null) query.append("showActive", String(args.showActive)) if (SemgrepWebToken !== undefined) headers.set('authorization', `Bearer ${SemgrepWebToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/agent/deployments/${encodeURIComponent(String(args.deploymentId))}/users${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(protosDeploymentV1GetDeploymentUsersResponse, await res.json()) };