UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

1 lines 3.47 kB
{"version":3,"file":"resolveLocationsForCurrentSession.mjs","sources":["../../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession.ts"],"sourcesContent":["import { ENTITY_IDENTITY_URL } from '../../utils/constants';\nconst resolvePermissions = (accessRule, isAuthenticated, groups) => {\n if (!isAuthenticated) {\n return {\n permission: accessRule.guest,\n };\n }\n if (groups) {\n const selectedKey = Object.keys(accessRule).find(access => access.includes(groups));\n return {\n permission: selectedKey ? accessRule[selectedKey] : undefined,\n };\n }\n return {\n permission: accessRule.authenticated,\n };\n};\nexport const resolveLocationsForCurrentSession = ({ buckets, isAuthenticated, identityId, userGroup, }) => {\n const locations = [];\n for (const [, bucketInfo] of Object.entries(buckets)) {\n const { bucketName, paths } = bucketInfo;\n if (!paths) {\n continue;\n }\n for (const [path, accessRules] of Object.entries(paths)) {\n const shouldIncludeEntityIdPath = !userGroup &&\n path.includes(ENTITY_IDENTITY_URL) &&\n isAuthenticated &&\n identityId;\n if (shouldIncludeEntityIdPath) {\n locations.push({\n type: 'PREFIX',\n permission: accessRules.entityidentity,\n bucket: bucketName,\n prefix: path.replace(ENTITY_IDENTITY_URL, identityId),\n });\n }\n const location = {\n type: 'PREFIX',\n ...resolvePermissions(accessRules, isAuthenticated, userGroup),\n bucket: bucketName,\n prefix: path,\n };\n if (location.permission)\n locations.push(location);\n }\n }\n return locations;\n};\n"],"names":[],"mappings":";;AACA,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,MAAM,KAAK;AACpE,IAAI,IAAI,CAAC,eAAe,EAAE;AAC1B,QAAQ,OAAO;AACf,YAAY,UAAU,EAAE,UAAU,CAAC,KAAK;AACxC,SAAS;AACT;AACA,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,Q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