diff --git a/packages/storage/__tests__/providers/s3/apis/copy.test.ts b/packages/storage/__tests__/providers/s3/apis/copy.test.ts index 7e951c9ec09..24dda7bcd3f 100644 --- a/packages/storage/__tests__/providers/s3/apis/copy.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/copy.test.ts @@ -199,15 +199,15 @@ describe('copy API', () => { test.each([ { - sourcePath: '/sourcePathAsString', + sourcePath: 'sourcePathAsString', expectedSourcePath: 'sourcePathAsString', - destinationPath: '/destinationPathAsString', + destinationPath: 'destinationPathAsString', expectedDestinationPath: 'destinationPathAsString', }, { - sourcePath: () => '/sourcePathAsFunction', + sourcePath: () => 'sourcePathAsFunction', expectedSourcePath: 'sourcePathAsFunction', - destinationPath: () => '/destinationPathAsFunction', + destinationPath: () => 'destinationPathAsFunction', expectedDestinationPath: 'destinationPathAsFunction', }, ])( diff --git a/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts b/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts index b309c9e6c33..88e9cb21eb7 100644 --- a/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/downloadData.test.ts @@ -218,11 +218,11 @@ describe('downloadData with path', () => { test.each([ { - path: '/path', + path: 'path', expectedKey: 'path', }, { - path: () => '/path', + path: () => 'path', expectedKey: 'path', }, ])( diff --git a/packages/storage/__tests__/providers/s3/apis/utils/validateStorageOperationInput.test.ts b/packages/storage/__tests__/providers/s3/apis/utils/validateStorageOperationInput.test.ts index b6cfd102525..cf9f38318d1 100644 --- a/packages/storage/__tests__/providers/s3/apis/utils/validateStorageOperationInput.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/utils/validateStorageOperationInput.test.ts @@ -13,7 +13,7 @@ import { describe('validateStorageOperationInput', () => { it('should return inputType as STORAGE_INPUT_PATH and objectKey as testPath when input is path as string', () => { - const input = { path: '/testPath' }; + const input = { path: 'testPath' }; const result = validateStorageOperationInput(input); expect(result).toEqual({ inputType: STORAGE_INPUT_PATH, @@ -24,7 +24,7 @@ describe('validateStorageOperationInput', () => { it('should return inputType as STORAGE_INPUT_PATH and objectKey as result of path function when input is path as function', () => { const input = { path: ({ identityId }: { identityId?: string }) => - `/testPath/${identityId}`, + `testPath/${identityId}`, }; const result = validateStorageOperationInput(input, '123'); expect(result).toEqual({ @@ -42,8 +42,8 @@ describe('validateStorageOperationInput', () => { }); }); - it('should throw an error when input path does not start with a /', () => { - const input = { path: 'test' } as any; + it('should throw an error when input path starts with a /', () => { + const input = { path: '/leading-slash-path' }; expect(() => validateStorageOperationInput(input)).toThrow( validationErrorMap[ StorageValidationErrorCode.InvalidStoragePathInput diff --git a/packages/storage/src/errors/types/validation.ts b/packages/storage/src/errors/types/validation.ts index c56299878c2..01954a896ec 100644 --- a/packages/storage/src/errors/types/validation.ts +++ b/packages/storage/src/errors/types/validation.ts @@ -63,6 +63,6 @@ export const validationErrorMap: AmplifyErrorMap = { message: 'Missing path or key parameter in Input.', }, [StorageValidationErrorCode.InvalidStoragePathInput]: { - message: 'Input `path` is missing a leading slash (/).', + message: 'Input `path` does not allow a leading slash (/).', }, }; diff --git a/packages/storage/src/providers/s3/types/options.ts b/packages/storage/src/providers/s3/types/options.ts index 5de24ebd4c9..7990f798aba 100644 --- a/packages/storage/src/providers/s3/types/options.ts +++ b/packages/storage/src/providers/s3/types/options.ts @@ -20,8 +20,16 @@ interface CommonOptions { /** @deprecated This may be removed in the next major version. */ type ReadOptions = - | { accessLevel?: 'guest' | 'private' } - | { accessLevel: 'protected'; targetIdentityId?: string }; + | { + /** @deprecated This may be removed in the next major version. */ + accessLevel?: 'guest' | 'private'; + } + | { + /** @deprecated This may be removed in the next major version. */ + accessLevel: 'protected'; + /** @deprecated This may be removed in the next major version. */ + targetIdentityId?: string; + }; /** @deprecated This may be removed in the next major version. */ interface WriteOptions { diff --git a/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts b/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts index 2c7f740fe53..12e71f10fdb 100644 --- a/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts +++ b/packages/storage/src/providers/s3/utils/validateStorageOperationInput.ts @@ -21,13 +21,13 @@ export const validateStorageOperationInput = ( const { path } = input; const objectKey = typeof path === 'string' ? path : path({ identityId }); assertValidationError( - objectKey.startsWith('/'), + !objectKey.startsWith('/'), StorageValidationErrorCode.InvalidStoragePathInput, ); return { inputType: STORAGE_INPUT_PATH, - objectKey: objectKey.slice(1), + objectKey, }; } else { return { inputType: STORAGE_INPUT_KEY, objectKey: input.key };