UNPKG

@keycloakify/keycloak-admin-ui

Version:
36 lines 1.63 kB
import { arrayToKeyValue, keyValueToArray, } from "../components/key-value-form/key-value-convert"; import { beerify, debeerify } from "../util"; export function toUserFormFields(data) { const attributes = {}; Object.entries(data.attributes || {}).forEach(([k, v]) => (attributes[beerify(k)] = v)); const unmanagedAttributes = arrayToKeyValue(data.unmanagedAttributes); return { ...data, attributes, unmanagedAttributes }; } export function toUserRepresentation(data) { var _a; const username = (_a = data.username) === null || _a === void 0 ? void 0 : _a.trim(); const attributes = Array.isArray(data.attributes) ? keyValueToArray(data.attributes) : Object.fromEntries(Object.entries(data.attributes || {}).map(([k, v]) => [ debeerify(k), v, ])); const unmanagedAttributes = Array.isArray(data.unmanagedAttributes) ? keyValueToArray(data.unmanagedAttributes) : data.unmanagedAttributes; for (const key in unmanagedAttributes) { if (attributes && Object.hasOwn(attributes, key)) { throw Error(`Attribute ${key} is a managed attribute and is already available from the user details.`); } } return { ...data, username, attributes: { ...unmanagedAttributes, ...attributes }, unmanagedAttributes: undefined, }; } export function filterManagedAttributes(attributes = {}, unmanagedAttributes = {}) { return Object.fromEntries(Object.entries(attributes).filter(([key]) => !Object.hasOwn(unmanagedAttributes, key))); } //# sourceMappingURL=form-state.js.map