import {z} from 'zod' export type GetApiApiAtlasV2GroupsGroupIdCustomDBRolesRolesRoleNameArgs = {envelope?: boolean | undefined, groupId: string, pretty?: boolean | undefined, roleName: string}; export type GetApiApiAtlasV2GroupsGroupIdCustomDBRolesRolesRoleNameOptions = {baseUrl?: string | undefined, ServiceAccounts?: string | undefined, fetch?: typeof fetch | undefined}; export const databasePermittedNamespaceResource = z.object({cluster: z.boolean(), collection: z.string(), db: z.string()}); export const databasePrivilegeAction = z.object({action: z.enum(["FIND", "INSERT", "REMOVE", "UPDATE", "BYPASS_DOCUMENT_VALIDATION", "USE_UUID", "KILL_OP", "BYPASS_DEFAULT_MAX_TIME_MS", "CREATE_COLLECTION", "CREATE_INDEX", "DROP_COLLECTION", "ENABLE_PROFILER", "KILL_ANY_CURSOR", "ANALYZE", "CHANGE_STREAM", "COLL_MOD", "COMPACT", "CONVERT_TO_CAPPED", "DROP_DATABASE", "DROP_INDEX", "RE_INDEX", "RENAME_COLLECTION_SAME_DB", "SET_USER_WRITE_BLOCK", "BYPASS_USER_WRITE_BLOCK", "LIST_SESSIONS", "KILL_ANY_SESSION", "COLL_STATS", "CONN_POOL_STATS", "DB_HASH", "DB_STATS", "GET_CMD_LINE_OPTS", "GET_LOG", "GET_PARAMETER", "GET_SHARD_MAP", "HOST_INFO", "IN_PROG", "LIST_DATABASES", "LIST_COLLECTIONS", "LIST_INDEXES", "LIST_SHARDS", "NET_STAT", "REPL_SET_GET_CONFIG", "REPL_SET_GET_STATUS", "SERVER_STATUS", "VALIDATE", "SHARDING_STATE", "TOP", "SQL_GET_SCHEMA", "SQL_SET_SCHEMA", "VIEW_ALL_HISTORY", "OUT_TO_S3", "OUT_TO_AZURE", "OUT_TO_GCS", "STORAGE_GET_CONFIG", "STORAGE_SET_CONFIG", "FLUSH_ROUTER_CONFIG", "ENABLE_SHARDING", "CHECK_METADATA_CONSISTENCY", "MOVE_CHUNK", "SPLIT_CHUNK", "ANALYZE_SHARD_KEY", "REFINE_COLLECTION_SHARD_KEY", "CLEAR_JUMBO_FLAG", "RESHARD_COLLECTION", "SHARDED_DATA_DISTRIBUTION", "GET_STREAM_PROCESSOR", "CREATE_STREAM_PROCESSOR", "PROCESS_STREAM_PROCESSOR", "MODIFY_STREAM_PROCESSOR", "START_STREAM_PROCESSOR", "STOP_STREAM_PROCESSOR", "DROP_STREAM_PROCESSOR", "SAMPLE_STREAM_PROCESSOR", "LIST_STREAM_PROCESSORS", "LIST_CONNECTIONS", "STREAM_PROCESSOR_STATS", "CREATE_SEARCH_INDEX", "DROP_SEARCH_INDEX", "LIST_SEARCH_INDEXES", "UPDATE_SEARCH_INDEX"]), resources: z.array(databasePermittedNamespaceResource)}); export const databaseInheritedRole = z.object({db: z.string(), role: z.string()}); export const userCustomDBRole = z.object({actions: z.array(databasePrivilegeAction).optional(), inheritedRoles: z.array(databaseInheritedRole).optional(), roleName: z.string()}); 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 }; /** * Return One Custom Role in One Project * * GET /api/atlas/v2/groups/{groupId}/customDBRoles/roles/{roleName} * * Also accepts auth: DigestAuth */ export const getApiApiAtlasV2GroupsGroupIdCustomDBRolesRolesRoleName = async (args: GetApiApiAtlasV2GroupsGroupIdCustomDBRolesRolesRoleNameArgs, options?: GetApiApiAtlasV2GroupsGroupIdCustomDBRolesRolesRoleNameOptions) => { const {baseUrl = "https://cloud.mongodb.com", fetch: fetchFn = fetch, ServiceAccounts} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.atlas.2023-01-01+json") if (args.envelope != null) query.append("envelope", String(args.envelope)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (ServiceAccounts !== undefined) headers.set('authorization', `Bearer ${ServiceAccounts}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/atlas/v2/groups/${encodeURIComponent(String(args.groupId))}/customDBRoles/roles/${encodeURIComponent(String(args.roleName))}${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(userCustomDBRole, await res.json()) };