UNPKG

@aws-amplify/storage

Version:

Storage category of aws-amplify

37 lines (34 loc) 1.66 kB
import { getGlobalContext } from '@aws-amplify/core'; import { assertValidationError } from '../../../errors/utils/assertValidationError.mjs'; import { StorageValidationErrorCode } from '../../../errors/types/validation.mjs'; import { resolveLocationsForCurrentSession } from './resolveLocationsForCurrentSession.mjs'; import { getHighestPrecedenceUserGroup } from './getHighestPrecedenceUserGroup.mjs'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 async function listPaths(maybeCtx) { // Resolve the optional leading context. The global context is resolved at // CALL time (never cached) so zero-arg callers follow live configuration. const ctx = maybeCtx ?? getGlobalContext(); const { Storage, Auth } = ctx.resourcesConfig; const s3Config = Storage?.S3; assertValidationError(!!s3Config, StorageValidationErrorCode.NoS3Config); const authConfig = Auth?.Cognito; assertValidationError(!!authConfig, StorageValidationErrorCode.NoAuthConfig); const { buckets } = s3Config; const { groups } = authConfig; if (!buckets) { return { locations: [] }; } const { tokens, identityId } = await ctx.fetchAuthSession(); const currentUserGroups = tokens?.accessToken.payload['cognito:groups']; const userGroupToUse = getHighestPrecedenceUserGroup(groups, currentUserGroups); const locations = resolveLocationsForCurrentSession({ buckets, isAuthenticated: !!tokens, identityId, userGroup: userGroupToUse, }); return { locations }; } export { listPaths }; //# sourceMappingURL=listPaths.mjs.map