@aws-amplify/storage
Version:
Storage category of aws-amplify
1 lines • 2.38 kB
Source Map (JSON)
{"version":3,"file":"getHighestPrecedenceUserGroup.mjs","sources":["../../../../../src/internals/apis/listPaths/getHighestPrecedenceUserGroup.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Given the Cognito user groups associated to current user session\n * and all the user group configurations defined by backend.\n * This function returns the user group with the highest precedence.\n * Reference: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-user-groups.html#assigning-precedence-values-to-groups\n *\n * @param {UserGroupConfig} userGroupsFromConfig - User groups with their precedence values based on Amplify outputs.\n * @param {string[]} currentUserGroups - The list of current user's groups.\n * @returns {string | undefined} - The user group with the highest precedence (0), or undefined if no matching group is found.\n */\nexport const getHighestPrecedenceUserGroup = (userGroupsFromConfig, currentUserGroups) => {\n if (userGroupsFromConfig && currentUserGroups) {\n const precedenceMap = userGroupsFromConfig.reduce((acc, group) => {\n Object.entries(group).forEach(([key, value]) => {\n acc[key] = value.precedence;\n });\n return acc;\n }, {});\n const sortedUserGroup = currentUserGroups\n .filter(group => Object.prototype.hasOwnProperty.call(precedenceMap, group))\n .sort((a, b) => precedenceMap[a] - precedenceMap[b]);\n return sortedUserGroup[0];\n }\n return undefined;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,6BAA6B,GAAG,CAAC,oBAAoB,EAAE,iBAAiB,KAAK;AAC1F,IAAI,IAAI,oBAAoB,IAAI,iBAAiB,EAAE;AACnD,QAAQ,MAAM,aAAa,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,KAAK;AAC1E,YAAY,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAC5D,gBAAgB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,UAAU;AAC3C,aAAa,CAAC;AACd,YAAY,OAAO,GAAG;AACtB,SAAS,EAAE,EAAE,CAAC;AACd,QAAQ,MAAM,eAAe,GAAG;AAChC,aAAa,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC;AACvF,aAAa,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAChE,QAAQ,OAAO,eAAe,CAAC,CAAC,CAAC;AACjC;AACA,IAAI,OAAO,SAAS;AACpB;;;;"}