@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
93 lines • 3.42 kB
JavaScript
const groupFunctions = {
delete: ["delClientRoleMappings", "delRealmRoleMappings"],
listEffective: [
"listRoleMappings",
"listCompositeRealmRoleMappings",
"listCompositeClientRoleMappings",
],
listAvailable: [
"listAvailableClientRoleMappings",
"listAvailableRealmRoleMappings",
],
};
const clientFunctions = {
delete: ["delClientScopeMappings", "delRealmScopeMappings"],
listEffective: [
"listScopeMappings",
"listCompositeRealmScopeMappings",
"listCompositeClientScopeMappings",
],
listAvailable: [
"listAvailableClientScopeMappings",
"listAvailableRealmScopeMappings",
],
};
const mapping = {
groups: groupFunctions,
users: groupFunctions,
clientScopes: clientFunctions,
clients: clientFunctions,
roles: {
delete: ["delCompositeRoles", "delCompositeRoles"],
listEffective: [
"getCompositeRoles",
"getCompositeRoles",
"getCompositeRolesForClient",
],
listAvailable: ["listRoles", "find"],
},
};
const castAdminClient = (adminClient, resource) => adminClient[resource];
const applyQuery = (adminClient, type, query, ...params) => castAdminClient(adminClient, type)[query](...params);
export const deleteMapping = (adminClient, type, id, rows) => rows.map((row) => {
var _a, _b, _c;
const role = { id: row.role.id, name: row.role.name };
const query = (_a = mapping[type]) === null || _a === void 0 ? void 0 : _a.delete[row.client ? 0 : 1];
return applyQuery(adminClient, type, query, {
id,
clientUniqueId: (_b = row.client) === null || _b === void 0 ? void 0 : _b.id,
client: (_c = row.client) === null || _c === void 0 ? void 0 : _c.id,
roles: [role],
}, [role]);
});
export const getMapping = async (adminClient, type, id) => {
const query = mapping[type].listEffective[0];
const result = applyQuery(adminClient, type, query, { id });
if (type !== "roles") {
return result;
}
const roles = await result;
const clientRoles = await Promise.all(roles
.filter((r) => r.clientRole)
.map(async (role) => {
const client = await adminClient.clients.findOne({
id: role.containerId,
});
role.containerId = client === null || client === void 0 ? void 0 : client.clientId;
return { ...client, mappings: [role] };
}));
return {
clientMappings: clientRoles,
realmMappings: roles.filter((r) => !r.clientRole),
};
};
export const getEffectiveRoles = async (adminClient, type, id) => {
const query = mapping[type].listEffective[1];
if (type !== "roles") {
return (await applyQuery(adminClient, type, query, { id })).map((role) => ({
role,
}));
}
const roles = await applyQuery(adminClient, type, query, { id });
const parentRoles = await Promise.all(roles
.filter((r) => r.composite)
.map((r) => applyQuery(adminClient, type, query, { id: r.id })));
return [...roles, ...parentRoles.flat()].map((role) => ({ role }));
};
export const getAvailableRoles = async (adminClient, type, params) => {
const query = mapping[type].listAvailable[1];
return (await applyQuery(adminClient, type, query, params)).map((role) => ({
role,
}));
};
//# sourceMappingURL=queries.js.map