@aws-amplify/storage
Version:
Storage category of aws-amplify
38 lines (36 loc) • 1.89 kB
JavaScript
;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.listPaths = listPaths;
const core_1 = require("@aws-amplify/core");
const assertValidationError_1 = require("../../../errors/utils/assertValidationError");
const validation_1 = require("../../../errors/types/validation");
const resolveLocationsForCurrentSession_1 = require("./resolveLocationsForCurrentSession");
const getHighestPrecedenceUserGroup_1 = require("./getHighestPrecedenceUserGroup");
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 ?? (0, core_1.getGlobalContext)();
const { Storage, Auth } = ctx.resourcesConfig;
const s3Config = Storage?.S3;
(0, assertValidationError_1.assertValidationError)(!!s3Config, validation_1.StorageValidationErrorCode.NoS3Config);
const authConfig = Auth?.Cognito;
(0, assertValidationError_1.assertValidationError)(!!authConfig, validation_1.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 = (0, getHighestPrecedenceUserGroup_1.getHighestPrecedenceUserGroup)(groups, currentUserGroups);
const locations = (0, resolveLocationsForCurrentSession_1.resolveLocationsForCurrentSession)({
buckets,
isAuthenticated: !!tokens,
identityId,
userGroup: userGroupToUse,
});
return { locations };
}
//# sourceMappingURL=listPaths.js.map