diff --git a/packages/storage/src/providers/s3/apis/list.ts b/packages/storage/src/providers/s3/apis/list.ts index 2037b237a64..22e060debec 100644 --- a/packages/storage/src/providers/s3/apis/list.ts +++ b/packages/storage/src/providers/s3/apis/list.ts @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { AmplifyV6 } from '@aws-amplify/core'; import { ListObjectsV2Input, ListObjectsV2Output, diff --git a/packages/storage/src/providers/s3/types/index.ts b/packages/storage/src/providers/s3/types/index.ts index a74968c698f..f0344224469 100644 --- a/packages/storage/src/providers/s3/types/index.ts +++ b/packages/storage/src/providers/s3/types/index.ts @@ -1,7 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -export { S3TransferOptions, S3GetUrlOptions, S3UploadOptions } from './options'; +export { + S3TransferOptions, + S3GetUrlOptions, + S3UploadOptions, + GetKeyWithPrefixOptions, +} from './options'; export { S3DownloadDataResult, S3DownloadFileResult, diff --git a/packages/storage/src/providers/s3/types/options.ts b/packages/storage/src/providers/s3/types/options.ts index 8a595ecfd28..e08b8e75d1e 100644 --- a/packages/storage/src/providers/s3/types/options.ts +++ b/packages/storage/src/providers/s3/types/options.ts @@ -3,6 +3,7 @@ import { TransferProgressEvent } from '../../../types'; import { StorageOptions } from '../../../types/params'; +import { StorageAccessLevel } from '@aws-amplify/core'; type S3Options = StorageOptions & { /** @@ -57,3 +58,9 @@ export type S3UploadOptions = S3TransferOptions & { */ metadata?: Record; }; + +export type GetKeyWithPrefixOptions = { + accessLevel: StorageAccessLevel; + targetIdentityId?: string; + key: string; +}; diff --git a/packages/storage/src/providers/s3/utils/getKeyWithPrefix.ts b/packages/storage/src/providers/s3/utils/getKeyWithPrefix.ts index 4252584dd8d..517be9fd63f 100644 --- a/packages/storage/src/providers/s3/utils/getKeyWithPrefix.ts +++ b/packages/storage/src/providers/s3/utils/getKeyWithPrefix.ts @@ -3,12 +3,13 @@ import { AmplifyV6, StorageAccessLevel } from '@aws-amplify/core'; import { prefixResolver as defaultPrefixResolver } from '../../../utils/prefixResolver'; +import { GetKeyWithPrefixOptions } from '../types'; -export function getKeyWithPrefix( - accessLevel: StorageAccessLevel, - targetIdentityId: string, - key: string -) { +export function getKeyWithPrefix({ + accessLevel, + targetIdentityId, + key, +}: GetKeyWithPrefixOptions) { const { prefixResolver = defaultPrefixResolver } = AmplifyV6.libraryOptions?.Storage ?? {}; return ( diff --git a/packages/storage/src/providers/s3/utils/resolveStorageConfig.ts b/packages/storage/src/providers/s3/utils/resolveStorageConfig.ts index b4df14d791f..e8e6294a565 100644 --- a/packages/storage/src/providers/s3/utils/resolveStorageConfig.ts +++ b/packages/storage/src/providers/s3/utils/resolveStorageConfig.ts @@ -5,11 +5,14 @@ import { AmplifyV6 } from '@aws-amplify/core'; import { assertValidationError } from '../../../errors/utils/assertValidationError'; import { StorageValidationErrorCode } from '../../../errors/types/validation'; +const DEFAULT_ACCESS_LEVEL = 'guest'; + export function resolveStorageConfig() { const { bucket, region } = AmplifyV6.getConfig()?.Storage ?? {}; assertValidationError(!!bucket, StorageValidationErrorCode.NoBucket); assertValidationError(!!region, StorageValidationErrorCode.NoRegion); - const { defaultAccessLevel } = AmplifyV6.libraryOptions?.Storage ?? {}; + const { defaultAccessLevel = DEFAULT_ACCESS_LEVEL } = + AmplifyV6.libraryOptions?.Storage ?? {}; return { defaultAccessLevel, bucket, diff --git a/packages/storage/src/types/params.ts b/packages/storage/src/types/params.ts index d133f5eaf62..2fd5eca9766 100644 --- a/packages/storage/src/types/params.ts +++ b/packages/storage/src/types/params.ts @@ -6,8 +6,8 @@ import { Credentials } from '@aws-sdk/types'; export type StorageConfig = { - region?: string; - credentials?: Credentials; + region: string; + credentials: Credentials; }; export type StorageOptions =