From d69c58b46970455e1cf7e06dd6e4641ea065a720 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Wed, 7 Aug 2024 09:33:50 -0700 Subject: [PATCH] chore(storage-browser): expose additional input output types (#13682) * chore(storage-browser): expose additional internal types * address feedback * remove 'applicationArn' from listCallerAccessGrant unit test * Update packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts Co-authored-by: Caleb Pollman --------- Co-authored-by: Ashwin Kumar Co-authored-by: Caleb Pollman --- .../apis/listCallerAccessGrants.test.ts | 3 --- .../apis/listCallerAccessGrants.ts | 5 ++-- .../storage/src/storageBrowser/apis/types.ts | 3 +-- packages/storage/src/storageBrowser/index.ts | 8 ++++++ .../locationCredentialsStore/create.ts | 8 +++--- packages/storage/src/storageBrowser/types.ts | 25 +++++++------------ 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts b/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts index bff4b4e07bd..54a90d66206 100644 --- a/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts +++ b/packages/storage/__tests__/storageBrowser/apis/listCallerAccessGrants.test.ts @@ -117,19 +117,16 @@ describe('listCallerAccessGrants', () => { scope: 's3://bucket/*', type: 'BUCKET', permission: 'READ', - applicationArn: undefined, }, { scope: 's3://bucket/path/*', type: 'PREFIX', permission: 'READWRITE', - applicationArn: undefined, }, { scope: 's3://bucket/path/to/object', type: 'OBJECT', permission: 'READ', - applicationArn: 'arn:123', }, ]); expect(nextToken).toBeUndefined(); diff --git a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts index 12836d59880..157657b09d4 100644 --- a/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts +++ b/packages/storage/src/storageBrowser/apis/listCallerAccessGrants.ts @@ -6,7 +6,7 @@ import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-clie import { logger } from '../../utils'; import { listCallerAccessGrants as listCallerAccessGrantsClient } from '../../providers/s3/utils/client/s3control'; -import { AccessGrant, LocationType, Permission } from '../types'; +import { LocationAccess, LocationType, Permission } from '../types'; import { StorageError } from '../../errors/StorageError'; import { getStorageUserAgentValue } from '../../providers/s3/utils/userAgent'; @@ -51,7 +51,7 @@ export const listCallerAccessGrants = async ( }, ); - const accessGrants: AccessGrant[] = + const accessGrants: LocationAccess[] = CallerAccessGrantsList?.map(grant => { // These values are correct from service mostly, but we add assertions to make TSC happy. assertPermission(grant.Permission); @@ -60,7 +60,6 @@ export const listCallerAccessGrants = async ( return { scope: grant.GrantScope, permission: grant.Permission, - applicationArn: grant.ApplicationArn, type: parseGrantType(grant.GrantScope!), }; }) ?? []; diff --git a/packages/storage/src/storageBrowser/apis/types.ts b/packages/storage/src/storageBrowser/apis/types.ts index c97a7c4bbdd..d0892c42b52 100644 --- a/packages/storage/src/storageBrowser/apis/types.ts +++ b/packages/storage/src/storageBrowser/apis/types.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import { - AccessGrant, CredentialsProvider, ListLocationsInput, ListLocationsOutput, @@ -18,7 +17,7 @@ export interface ListCallerAccessGrantsInput extends ListLocationsInput { region: string; } -export type ListCallerAccessGrantsOutput = ListLocationsOutput; +export type ListCallerAccessGrantsOutput = ListLocationsOutput; export interface GetDataAccessInput { accountId: string; diff --git a/packages/storage/src/storageBrowser/index.ts b/packages/storage/src/storageBrowser/index.ts index 72878852a09..94c741b857c 100644 --- a/packages/storage/src/storageBrowser/index.ts +++ b/packages/storage/src/storageBrowser/index.ts @@ -14,4 +14,12 @@ export { GetLocationCredentials, ListLocations, LocationCredentialsStore, + CreateLocationCredentialsStoreInput, + LocationCredentials, + ListLocationsInput, + ListLocationsOutput, + GetLocationCredentialsInput, + GetLocationCredentialsOutput, + Permission, } from './types'; +export { AWSTemporaryCredentials } from '../providers/s3/types/options'; diff --git a/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts b/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts index ce4e9126612..05d68004f43 100644 --- a/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts +++ b/packages/storage/src/storageBrowser/locationCredentialsStore/create.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { + CreateLocationCredentialsStoreInput, CredentialsLocation, - GetLocationCredentials, LocationCredentialsStore, } from '../types'; import { StorageValidationErrorCode } from '../../errors/types/validation'; @@ -12,9 +12,9 @@ import { LocationCredentialsProvider } from '../../providers/s3/types/options'; import { createStore, getValue, removeStore } from './registry'; -export const createLocationCredentialsStore = (input: { - handler: GetLocationCredentials; -}): LocationCredentialsStore => { +export const createLocationCredentialsStore = ( + input: CreateLocationCredentialsStoreInput, +): LocationCredentialsStore => { const storeSymbol = createStore(input.handler); const store = { diff --git a/packages/storage/src/storageBrowser/types.ts b/packages/storage/src/storageBrowser/types.ts index 1199cf0e851..94d0c1f6eac 100644 --- a/packages/storage/src/storageBrowser/types.ts +++ b/packages/storage/src/storageBrowser/types.ts @@ -71,35 +71,24 @@ export interface LocationCredentials extends Partial { readonly credentials: AWSTemporaryCredentials; } -export interface AccessGrant extends LocationAccess { - /** - * The Amazon Resource Name (ARN) of an AWS IAM Identity Center application - * associated with your Identity Center instance. If the grant includes an - * application ARN, the grantee can only access the S3 data through this - * application. - */ - readonly applicationArn: string | undefined; -} - /** * @internal */ -export interface ListLocationsOutput { - locations: T[]; +export interface ListLocationsInput { + pageSize?: number; nextToken?: string; } - /** * @internal */ -export interface ListLocationsInput { - pageSize?: number; +export interface ListLocationsOutput { + locations: LocationAccess[]; nextToken?: string; } export type ListLocations = ( input?: ListLocationsInput, -) => Promise>; +) => Promise; export type GetLocationCredentialsInput = CredentialsLocation; export type GetLocationCredentialsOutput = LocationCredentials; @@ -108,6 +97,10 @@ export type GetLocationCredentials = ( input: GetLocationCredentialsInput, ) => Promise; +export interface CreateLocationCredentialsStoreInput { + handler: GetLocationCredentials; +} + export interface LocationCredentialsStore { /** * Get location-specific credentials. It uses a cache internally to optimize performance when