From 15ead1b6ca20bf8bfd27c421633a70a4b428299c Mon Sep 17 00:00:00 2001 From: ashika112 <155593080+ashika112@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:07:10 -0700 Subject: [PATCH] Chore: Remove createAmplifyAdapter & refactor (#13974) remove createAmplifyAdapter & refactor --- .../createAmplifyAuthConfigAdapter.test.ts | 137 ------------ .../getPaginatedLocations.test.ts | 90 -------- .../getHighestPrecedenceUserGroup.test.ts | 2 +- .../apis/listPaths/listPaths.test.ts | 202 ++++++++++++++++++ .../resolveLocationsForCurrentSession.test.ts | 4 +- .../createAmplifyAuthConfigAdapter.ts | 16 -- .../createAmplifyListLocationsHandler.ts | 61 ------ .../getPaginatedLocations.ts | 41 ---- .../getHighestPrecedenceUserGroup.ts | 0 .../src/internals/apis/listPaths/index.ts | 4 + .../src/internals/apis/listPaths/listPaths.ts | 37 ++++ .../resolveLocationsForCurrentSession.ts | 8 +- packages/storage/src/internals/index.ts | 7 +- .../src/internals/types/credentials.ts | 14 -- 14 files changed, 255 insertions(+), 368 deletions(-) delete mode 100644 packages/storage/__tests__/internals/amplifyAuthAdapter/createAmplifyAuthConfigAdapter.test.ts delete mode 100644 packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.test.ts rename packages/storage/__tests__/internals/{amplifyAuthAdapter => apis/listPaths}/getHighestPrecedenceUserGroup.test.ts (93%) create mode 100644 packages/storage/__tests__/internals/apis/listPaths/listPaths.test.ts rename packages/storage/__tests__/internals/{amplifyAuthAdapter => apis/listPaths}/resolveLocationsForCurrentSession.test.ts (93%) delete mode 100644 packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyAuthConfigAdapter.ts delete mode 100644 packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyListLocationsHandler.ts delete mode 100644 packages/storage/src/internals/amplifyAuthConfigAdapter/getPaginatedLocations.ts rename packages/storage/src/internals/{amplifyAuthConfigAdapter => apis/listPaths}/getHighestPrecedenceUserGroup.ts (100%) create mode 100644 packages/storage/src/internals/apis/listPaths/index.ts create mode 100644 packages/storage/src/internals/apis/listPaths/listPaths.ts rename packages/storage/src/internals/{amplifyAuthConfigAdapter => apis/listPaths}/resolveLocationsForCurrentSession.ts (87%) diff --git a/packages/storage/__tests__/internals/amplifyAuthAdapter/createAmplifyAuthConfigAdapter.test.ts b/packages/storage/__tests__/internals/amplifyAuthAdapter/createAmplifyAuthConfigAdapter.test.ts deleted file mode 100644 index 171210f8599..00000000000 --- a/packages/storage/__tests__/internals/amplifyAuthAdapter/createAmplifyAuthConfigAdapter.test.ts +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { Amplify, fetchAuthSession } from '@aws-amplify/core'; - -import { resolveLocationsForCurrentSession } from '../../../src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession'; -import { createAmplifyAuthConfigAdapter } from '../../../src/internals'; - -jest.mock('@aws-amplify/core', () => ({ - ConsoleLogger: jest.fn(), - Amplify: { - getConfig: jest.fn(), - Auth: { - getConfig: jest.fn(), - fetchAuthSession: jest.fn(), - }, - }, - fetchAuthSession: jest.fn(), -})); -jest.mock( - '../../../src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession', -); - -const credentials = { - accessKeyId: 'accessKeyId', - sessionToken: 'sessionToken', - secretAccessKey: 'secretAccessKey', -}; -const identityId = 'identityId'; - -const mockGetConfig = jest.mocked(Amplify.getConfig); -const mockFetchAuthSession = fetchAuthSession as jest.Mock; -const mockResolveLocationsFromCurrentSession = - resolveLocationsForCurrentSession as jest.Mock; - -const mockAuthConfig = { - Auth: { - Cognito: { - userPoolClientId: 'userPoolClientId', - userPoolId: 'userPoolId', - identityPoolId: 'identityPoolId', - groups: [{ admin: { precedence: 0 } }], - }, - }, -}; - -describe('createAmplifyAuthConfigAdapter', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - mockGetConfig.mockReturnValue({ - ...mockAuthConfig, - Storage: { - S3: { - bucket: 'bucket1', - region: 'region1', - buckets: { - 'bucket-1': { - bucketName: 'bucket-1', - region: 'region1', - paths: {}, - }, - }, - }, - }, - }); - mockFetchAuthSession.mockResolvedValue({ - credentials, - identityId, - tokens: { - accessToken: { payload: {} }, - }, - }); - - it('should return an AuthConfigAdapter with listLocations function', async () => { - const adapter = createAmplifyAuthConfigAdapter(); - expect(adapter).toHaveProperty('listLocations'); - const { listLocations } = adapter; - await listLocations(); - expect(mockFetchAuthSession).toHaveBeenCalled(); - }); - - it('should return empty locations when buckets are not defined', async () => { - mockGetConfig.mockReturnValue({ - ...mockAuthConfig, - Storage: { S3: { buckets: undefined } }, - }); - - const adapter = createAmplifyAuthConfigAdapter(); - const result = await adapter.listLocations(); - - expect(result).toEqual({ locations: [] }); - }); - - it('should generate locations correctly when buckets are defined', async () => { - const mockBuckets = { - bucket1: { - bucketName: 'bucket1', - region: 'region1', - paths: { - '/path1': { - entityidentity: ['read', 'write'], - groupsadmin: ['read'], - }, - }, - }, - }; - - mockGetConfig.mockReturnValue({ - ...mockAuthConfig, - Storage: { S3: { buckets: mockBuckets } }, - }); - mockResolveLocationsFromCurrentSession.mockReturnValue([ - { - type: 'PREFIX', - permission: ['read', 'write'], - bucket: 'bucket1', - prefix: '/path1', - }, - ]); - - const adapter = createAmplifyAuthConfigAdapter(); - const result = await adapter.listLocations(); - - expect(result).toEqual({ - locations: [ - { - type: 'PREFIX', - permission: ['read', 'write'], - bucket: 'bucket1', - prefix: '/path1', - }, - ], - }); - }); -}); diff --git a/packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.test.ts b/packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.test.ts deleted file mode 100644 index 15809d88085..00000000000 --- a/packages/storage/__tests__/internals/amplifyAuthAdapter/getPaginatedLocations.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { getPaginatedLocations } from '../../../src/internals/amplifyAuthConfigAdapter/getPaginatedLocations'; -import { PathAccess } from '../../../src/internals/types/credentials'; - -describe('getPaginatedLocations', () => { - const mockLocations: PathAccess[] = [ - { - type: 'PREFIX', - permission: ['read'], - bucket: 'bucket1', - prefix: 'path1/', - }, - { - type: 'PREFIX', - permission: ['write'], - bucket: 'bucket2', - prefix: 'path2/', - }, - { - type: 'PREFIX', - permission: ['read', 'write'], - bucket: 'bucket3', - prefix: 'path3/', - }, - ]; - - it('should return all locations when no pagination is specified', () => { - const result = getPaginatedLocations({ locations: mockLocations }); - expect(result).toEqual({ locations: mockLocations }); - }); - - it('should return paginated locations when pageSize is specified', () => { - const result = getPaginatedLocations({ - locations: mockLocations, - pageSize: 2, - }); - expect(result).toEqual({ - locations: mockLocations.slice(0, 2), - nextToken: '1', - }); - }); - - it('should return paginated locations when pageSize and nextToken are specified', () => { - const result = getPaginatedLocations({ - locations: mockLocations, - pageSize: 1, - nextToken: '2', - }); - expect(result).toEqual({ - locations: mockLocations.slice(1, 2), - nextToken: '1', - }); - }); - - it('should return empty locations when locations array is empty', () => { - const result = getPaginatedLocations({ locations: [], pageSize: 2 }); - expect(result).toEqual({ locations: [] }); - }); - - it('should return empty location when nextToken is beyond array length', () => { - const result = getPaginatedLocations({ - locations: mockLocations, - pageSize: 2, - nextToken: '5', - }); - expect(result).toEqual({ locations: [], nextToken: undefined }); - }); - - it('should return all remaining location when page size is greater than remaining locations length', () => { - const result = getPaginatedLocations({ - locations: mockLocations, - pageSize: 5, - nextToken: '2', - }); - expect(result).toEqual({ - locations: mockLocations.slice(-2), - nextToken: undefined, - }); - }); - - it('should return undefined nextToken when end of array is reached', () => { - const result = getPaginatedLocations({ - locations: mockLocations, - pageSize: 5, - }); - expect(result).toEqual({ - locations: mockLocations.slice(0, 3), - nextToken: undefined, - }); - }); -}); diff --git a/packages/storage/__tests__/internals/amplifyAuthAdapter/getHighestPrecedenceUserGroup.test.ts b/packages/storage/__tests__/internals/apis/listPaths/getHighestPrecedenceUserGroup.test.ts similarity index 93% rename from packages/storage/__tests__/internals/amplifyAuthAdapter/getHighestPrecedenceUserGroup.test.ts rename to packages/storage/__tests__/internals/apis/listPaths/getHighestPrecedenceUserGroup.test.ts index bf1055797a0..76897ebc0ca 100644 --- a/packages/storage/__tests__/internals/amplifyAuthAdapter/getHighestPrecedenceUserGroup.test.ts +++ b/packages/storage/__tests__/internals/apis/listPaths/getHighestPrecedenceUserGroup.test.ts @@ -4,7 +4,7 @@ import { UserGroupConfig, getHighestPrecedenceUserGroup, -} from '../../../src/internals/amplifyAuthConfigAdapter/getHighestPrecedenceUserGroup'; +} from '../../../../src/internals/apis/listPaths/getHighestPrecedenceUserGroup'; const userGroupsFromConfig: UserGroupConfig = [ { diff --git a/packages/storage/__tests__/internals/apis/listPaths/listPaths.test.ts b/packages/storage/__tests__/internals/apis/listPaths/listPaths.test.ts new file mode 100644 index 00000000000..dfe1a711c5a --- /dev/null +++ b/packages/storage/__tests__/internals/apis/listPaths/listPaths.test.ts @@ -0,0 +1,202 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { Amplify, AuthTokens, fetchAuthSession } from '@aws-amplify/core'; + +import { resolveLocationsForCurrentSession } from '../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession'; +import { getHighestPrecedenceUserGroup } from '../../../../src/internals/apis/listPaths/getHighestPrecedenceUserGroup'; +import { listPaths } from '../../../../src/internals'; + +jest.mock('@aws-amplify/core', () => ({ + ConsoleLogger: jest.fn(), + Amplify: { + getConfig: jest.fn(), + Auth: { + getConfig: jest.fn(), + fetchAuthSession: jest.fn(), + }, + }, + fetchAuthSession: jest.fn(), +})); +jest.mock( + '../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession', +); +jest.mock( + '../../../../src/internals/apis/listPaths/getHighestPrecedenceUserGroup', +); + +const credentials = { + accessKeyId: 'accessKeyId', + sessionToken: 'sessionToken', + secretAccessKey: 'secretAccessKey', +}; +const identityId = 'identityId'; + +const mockGetConfig = jest.mocked(Amplify.getConfig); +const mockFetchAuthSession = jest.mocked(fetchAuthSession); +const mockResolveLocationsFromCurrentSession = + resolveLocationsForCurrentSession as jest.Mock; +const mockGetHighestPrecedenceUserGroup = jest.mocked( + getHighestPrecedenceUserGroup, +); + +const mockAuthConfig = { + Auth: { + Cognito: { + userPoolClientId: 'userPoolClientId', + userPoolId: 'userPoolId', + identityPoolId: 'identityPoolId', + groups: [{ admin: { precedence: 0 } }], + }, + }, +}; +const mockBuckets = { + bucket1: { + bucketName: 'bucket1', + region: 'region1', + paths: { + '/path1': { + authenticated: ['read', 'write'], + groupsadmin: ['read'], + guest: ['read'], + }, + }, + }, +}; + +describe('listPaths', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + mockGetConfig.mockReturnValue({ + ...mockAuthConfig, + Storage: { + S3: { + bucket: 'bucket1', + region: 'region1', + buckets: { + 'bucket-1': { + bucketName: 'bucket-1', + region: 'region1', + paths: {}, + }, + }, + }, + }, + }); + mockFetchAuthSession.mockResolvedValue({ + credentials, + identityId, + tokens: { + accessToken: { payload: {} }, + }, + }); + + it('should return empty locations when buckets are not defined', async () => { + mockGetConfig.mockReturnValue({ + ...mockAuthConfig, + Storage: { S3: { buckets: undefined } }, + }); + + const result = await listPaths(); + + expect(result).toEqual({ locations: [] }); + }); + + it('should generate locations correctly when buckets are defined', async () => { + mockGetConfig.mockReturnValue({ + ...mockAuthConfig, + Storage: { S3: { buckets: mockBuckets } }, + }); + mockResolveLocationsFromCurrentSession.mockReturnValue([ + { + type: 'PREFIX', + permission: ['read', 'write'], + bucket: 'bucket1', + prefix: '/path1', + }, + ]); + + const result = await listPaths(); + + expect(result).toEqual({ + locations: [ + { + type: 'PREFIX', + permission: ['read', 'write'], + bucket: 'bucket1', + prefix: '/path1', + }, + ], + }); + }); + + it('should call resolveLocations with authenticated false for unauthenticated user', async () => { + mockGetConfig.mockReturnValue({ + Auth: { + Cognito: { + userPoolClientId: 'userPoolClientId', + userPoolId: 'userPoolId', + identityPoolId: 'identityPoolId', + groups: [{ admin: { precedence: 0 } }], + }, + }, + + Storage: { S3: { buckets: mockBuckets } }, + }); + mockFetchAuthSession.mockResolvedValue({ + tokens: undefined, + identityId: undefined, + }); + mockResolveLocationsFromCurrentSession.mockReturnValue({ + locations: { + type: 'PREFIX', + permission: ['read'], + bucket: 'bucket1', + prefix: '/path1', + }, + }); + await listPaths(); + + expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalled(); + expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalledWith({ + buckets: mockBuckets, + isAuthenticated: false, + identityId: undefined, + userGroup: undefined, + }); + }); + + it('should call resolveLocations with right userGroup when provided', async () => { + mockGetConfig.mockReturnValue({ + Auth: { + Cognito: { + userPoolClientId: 'userPoolClientId', + userPoolId: 'userPoolId', + identityPoolId: 'identityPoolId', + groups: [{ admin: { precedence: 0 } }], + }, + }, + + Storage: { S3: { buckets: mockBuckets } }, + }); + mockFetchAuthSession.mockResolvedValue({ + tokens: { + accessToken: { payload: {} }, + } as AuthTokens, + identityId: 'identityId', + }); + mockGetHighestPrecedenceUserGroup.mockReturnValue('admin'); + + await listPaths(); + + expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalled(); + expect(mockResolveLocationsFromCurrentSession).toHaveBeenCalledWith({ + buckets: mockBuckets, + isAuthenticated: true, + identityId: 'identityId', + userGroup: 'admin', + }); + }); +}); diff --git a/packages/storage/__tests__/internals/amplifyAuthAdapter/resolveLocationsForCurrentSession.test.ts b/packages/storage/__tests__/internals/apis/listPaths/resolveLocationsForCurrentSession.test.ts similarity index 93% rename from packages/storage/__tests__/internals/amplifyAuthAdapter/resolveLocationsForCurrentSession.test.ts rename to packages/storage/__tests__/internals/apis/listPaths/resolveLocationsForCurrentSession.test.ts index 14119e9e80b..3040ca68d5a 100644 --- a/packages/storage/__tests__/internals/amplifyAuthAdapter/resolveLocationsForCurrentSession.test.ts +++ b/packages/storage/__tests__/internals/apis/listPaths/resolveLocationsForCurrentSession.test.ts @@ -1,5 +1,5 @@ -import { resolveLocationsForCurrentSession } from '../../../src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession'; -import { BucketInfo } from '../../../src/providers/s3/types/options'; +import { resolveLocationsForCurrentSession } from '../../../../src/internals/apis/listPaths/resolveLocationsForCurrentSession'; +import { BucketInfo } from '../../../../src/providers/s3/types/options'; describe('resolveLocationsForCurrentSession', () => { const mockBuckets: Record = { diff --git a/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyAuthConfigAdapter.ts b/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyAuthConfigAdapter.ts deleted file mode 100644 index 39ab73de29f..00000000000 --- a/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyAuthConfigAdapter.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { ListPaths } from '../types/credentials'; - -import { createAmplifyListLocationsHandler } from './createAmplifyListLocationsHandler'; - -export interface AuthConfigAdapter { - listLocations: ListPaths; -} - -export const createAmplifyAuthConfigAdapter = (): AuthConfigAdapter => { - const listLocations = createAmplifyListLocationsHandler(); - - return { listLocations }; -}; diff --git a/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyListLocationsHandler.ts b/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyListLocationsHandler.ts deleted file mode 100644 index f8150a34d04..00000000000 --- a/packages/storage/src/internals/amplifyAuthConfigAdapter/createAmplifyListLocationsHandler.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { Amplify, fetchAuthSession } from '@aws-amplify/core'; - -import { ListPaths, PathAccess } from '../types/credentials'; - -import { getPaginatedLocations } from './getPaginatedLocations'; -import { resolveLocationsForCurrentSession } from './resolveLocationsForCurrentSession'; -import { getHighestPrecedenceUserGroup } from './getHighestPrecedenceUserGroup'; - -export const createAmplifyListLocationsHandler = (): ListPaths => { - const { buckets } = Amplify.getConfig().Storage!.S3!; - const { groups } = Amplify.getConfig().Auth!.Cognito; - - let cachedResult: Record | null = null; - - return async function listLocations(input = {}) { - if (!buckets) { - return { locations: [] }; - } - const { pageSize, nextToken } = input; - - const { tokens, identityId } = await fetchAuthSession(); - const currentUserGroups = tokens?.accessToken.payload['cognito:groups'] as - | string[] - | undefined; - - const userGroupToUse = getHighestPrecedenceUserGroup( - groups, - currentUserGroups, - ); - - const cacheKey = - JSON.stringify({ identityId, userGroup: userGroupToUse }) + `${!!tokens}`; - - if (cachedResult && cachedResult[cacheKey]) - return getPaginatedLocations({ - locations: cachedResult[cacheKey].locations, - pageSize, - nextToken, - }); - - cachedResult = {}; - - const locations = resolveLocationsForCurrentSession({ - buckets, - isAuthenticated: !!tokens, - identityId, - userGroup: userGroupToUse, - }); - - cachedResult[cacheKey] = { locations }; - - return getPaginatedLocations({ - locations: cachedResult[cacheKey].locations, - pageSize, - nextToken, - }); - }; -}; diff --git a/packages/storage/src/internals/amplifyAuthConfigAdapter/getPaginatedLocations.ts b/packages/storage/src/internals/amplifyAuthConfigAdapter/getPaginatedLocations.ts deleted file mode 100644 index 93c501a92dd..00000000000 --- a/packages/storage/src/internals/amplifyAuthConfigAdapter/getPaginatedLocations.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import { PathAccess } from '../types/credentials'; - -export const getPaginatedLocations = ({ - locations, - pageSize, - nextToken, -}: { - locations: PathAccess[]; - pageSize?: number; - nextToken?: string; -}) => { - if (pageSize) { - if (nextToken) { - if (Number(nextToken) > locations.length) { - return { locations: [], nextToken: undefined }; - } - const start = -nextToken; - const end = start + pageSize < 0 ? start + pageSize : undefined; - - return { - locations: locations.slice(start, end), - nextToken: end ? `${-end}` : undefined, - }; - } - - return { - locations: locations.slice(0, pageSize), - nextToken: - locations.length > pageSize - ? `${locations.length - pageSize}` - : undefined, - }; - } - - return { - locations, - }; -}; diff --git a/packages/storage/src/internals/amplifyAuthConfigAdapter/getHighestPrecedenceUserGroup.ts b/packages/storage/src/internals/apis/listPaths/getHighestPrecedenceUserGroup.ts similarity index 100% rename from packages/storage/src/internals/amplifyAuthConfigAdapter/getHighestPrecedenceUserGroup.ts rename to packages/storage/src/internals/apis/listPaths/getHighestPrecedenceUserGroup.ts diff --git a/packages/storage/src/internals/apis/listPaths/index.ts b/packages/storage/src/internals/apis/listPaths/index.ts new file mode 100644 index 00000000000..cf04534bf0f --- /dev/null +++ b/packages/storage/src/internals/apis/listPaths/index.ts @@ -0,0 +1,4 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +export { listPaths } from './listPaths'; diff --git a/packages/storage/src/internals/apis/listPaths/listPaths.ts b/packages/storage/src/internals/apis/listPaths/listPaths.ts new file mode 100644 index 00000000000..2add687dfa4 --- /dev/null +++ b/packages/storage/src/internals/apis/listPaths/listPaths.ts @@ -0,0 +1,37 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { Amplify, fetchAuthSession } from '@aws-amplify/core'; + +import { ListPathsOutput } from '../../types/credentials'; + +import { resolveLocationsForCurrentSession } from './resolveLocationsForCurrentSession'; +import { getHighestPrecedenceUserGroup } from './getHighestPrecedenceUserGroup'; + +export const listPaths = async (): Promise => { + const { buckets } = Amplify.getConfig().Storage!.S3!; + const { groups } = Amplify.getConfig().Auth!.Cognito; + + if (!buckets) { + return { locations: [] }; + } + + const { tokens, identityId } = await fetchAuthSession(); + const currentUserGroups = tokens?.accessToken.payload['cognito:groups'] as + | string[] + | undefined; + + const userGroupToUse = getHighestPrecedenceUserGroup( + groups, + currentUserGroups, + ); + + const locations = resolveLocationsForCurrentSession({ + buckets, + isAuthenticated: !!tokens, + identityId, + userGroup: userGroupToUse, + }); + + return { locations }; +}; diff --git a/packages/storage/src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession.ts b/packages/storage/src/internals/apis/listPaths/resolveLocationsForCurrentSession.ts similarity index 87% rename from packages/storage/src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession.ts rename to packages/storage/src/internals/apis/listPaths/resolveLocationsForCurrentSession.ts index 9071c2386ae..49121692ef3 100644 --- a/packages/storage/src/internals/amplifyAuthConfigAdapter/resolveLocationsForCurrentSession.ts +++ b/packages/storage/src/internals/apis/listPaths/resolveLocationsForCurrentSession.ts @@ -1,9 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { PathAccess } from '../types/credentials'; -import { BucketInfo } from '../../providers/s3/types/options'; -import { ENTITY_IDENTITY_URL } from '../utils/constants'; -import { StorageAccess } from '../types/common'; +import { PathAccess } from '../../types/credentials'; +import { BucketInfo } from '../../../providers/s3/types/options'; +import { ENTITY_IDENTITY_URL } from '../../utils/constants'; +import { StorageAccess } from '../../types/common'; const resolvePermissions = ( accessRule: Record, diff --git a/packages/storage/src/internals/index.ts b/packages/storage/src/internals/index.ts index e8c0ce1b83c..197b899b424 100644 --- a/packages/storage/src/internals/index.ts +++ b/packages/storage/src/internals/index.ts @@ -3,7 +3,7 @@ export { StorageSubpathStrategy } from '../types/options'; -export { Permission, LocationType } from './types/common'; +export { Permission, LocationType, StorageAccess } from './types/common'; /* Internal APIs @@ -43,10 +43,12 @@ export { uploadData } from './apis/uploadData'; export { downloadData } from './apis/downloadData'; export { copy } from './apis/copy'; +/** Default Auth exports */ +export { listPaths } from './apis/listPaths'; + /* CredentialsStore exports */ -export { createAmplifyAuthConfigAdapter } from './amplifyAuthConfigAdapter/createAmplifyAuthConfigAdapter'; export { CredentialsLocation, ListLocations, @@ -55,6 +57,7 @@ export { ListLocationsInput, ListLocationsOutput, CredentialsProvider, + ListPathsOutput, } from './types/credentials'; export { diff --git a/packages/storage/src/internals/types/credentials.ts b/packages/storage/src/internals/types/credentials.ts index f0800f14c34..9b825650e62 100644 --- a/packages/storage/src/internals/types/credentials.ts +++ b/packages/storage/src/internals/types/credentials.ts @@ -94,23 +94,9 @@ export interface PathAccess { prefix: string; } -/** - * @internal - */ -export interface ListPathsInput { - pageSize?: number; - nextToken?: string; -} - /** * @internal */ export interface ListPathsOutput { locations: PathAccess[]; - nextToken?: string; } - -/** - * @internal - */ -export type ListPaths = (input?: ListPathsInput) => Promise;