import {z} from 'zod' export type GetApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdMembersArgs = {deploymentId: number, teamId: number, limit?: number | undefined, cursor?: string | undefined}; export type GetApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdMembersOptions = {baseUrl: string, SemgrepWebToken?: string | undefined, fetch?: typeof fetch | undefined}; export const protosPermissionsV2TeamUser = z.object({userId: z.string().optional(), role: z.enum(["TEAM_ROLE_MEMBER", "TEAM_ROLE_MANAGER", "TEAM_ROLE_READONLY"]).optional()}); export const protosPermissionsV2ListTeamUsersResponse = z.object({deploymentId: z.string().optional(), teamId: z.string().optional(), users: z.array(protosPermissionsV2TeamUser).optional(), limit: z.string().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 an RBAC team's users * * GET /api/permissions/v2/deployments/{deploymentId}/teams/{teamId}/members * * Also accepts auth: SemgrepJWT */ export const getApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdMembers = async (args: GetApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdMembersArgs, options: GetApiApiPermissionsV2DeploymentsDeploymentIdTeamsTeamIdMembersOptions) => { const {baseUrl, fetch: fetchFn = fetch, SemgrepWebToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) 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))}/members${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(protosPermissionsV2ListTeamUsersResponse, await res.json()) };