From ca54f16ff8599387db21ad4ca54b6f0e053467ed Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Wed, 18 Dec 2024 16:19:45 -0500 Subject: [PATCH] fix(core): amplify configure with storage path type issue --- .../__tests__/parseAmplifyOutputs.test.ts | 21 +++++++++++++++++++ packages/core/src/parseAmplifyOutputs.ts | 21 ++++++++++++++++++- .../src/singleton/AmplifyOutputs/types.ts | 3 ++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/core/__tests__/parseAmplifyOutputs.test.ts b/packages/core/__tests__/parseAmplifyOutputs.test.ts index 9ae814334c1..d5302b847a1 100644 --- a/packages/core/__tests__/parseAmplifyOutputs.test.ts +++ b/packages/core/__tests__/parseAmplifyOutputs.test.ts @@ -318,6 +318,17 @@ describe('parseAmplifyOutputs tests', () => { }, }, }, + { + name: 'bucket-2', + bucket_name: 'storage-bucket-test-2', + aws_region: 'us-west-2', + paths: { + 'public/*': { + guest: ['get', 'list', 'write', 'delete'], + authenticated: ['get', 'list', 'write', 'delete'], + }, + }, + }, ], }, }; @@ -344,6 +355,16 @@ describe('parseAmplifyOutputs tests', () => { }, }, }, + 'bucket-2': { + bucketName: 'storage-bucket-test-2', + region: 'us-west-2', + paths: { + 'public/*': { + authenticated: ['get', 'list', 'write', 'delete'], + guest: ['get', 'list', 'write', 'delete'], + }, + }, + }, }, }, }, diff --git a/packages/core/src/parseAmplifyOutputs.ts b/packages/core/src/parseAmplifyOutputs.ts index 0fcbd0eebee..f54be47c05c 100644 --- a/packages/core/src/parseAmplifyOutputs.ts +++ b/packages/core/src/parseAmplifyOutputs.ts @@ -370,6 +370,13 @@ function getMfaStatus( return 'off'; } +// interface BucketInfoFoo { +// bucketName: string; +// region: string; +// // paths?: Record>; +// paths?: Partial>>; +// } + function createBucketInfoMap( buckets: AmplifyOutputsStorageBucketProperties[], ): Record { @@ -383,10 +390,22 @@ function createBucketInfoMap( ); } + const sanitizedPaths = paths + ? Object.entries(paths).reduce< + Record> + >((acc, [key, value]) => { + if (value !== undefined) { + acc[key] = value; + } + + return acc; + }, {}) + : undefined; + mappedBuckets[name] = { bucketName, region, - paths, + paths: sanitizedPaths, }; }, ); diff --git a/packages/core/src/singleton/AmplifyOutputs/types.ts b/packages/core/src/singleton/AmplifyOutputs/types.ts index 4146037a9ce..cdc6b0953d6 100644 --- a/packages/core/src/singleton/AmplifyOutputs/types.ts +++ b/packages/core/src/singleton/AmplifyOutputs/types.ts @@ -53,7 +53,8 @@ export interface AmplifyOutputsStorageBucketProperties { /** Region for the bucket */ aws_region: string; /** Paths to object with access permissions */ - paths?: Record>; + // paths?: Record>; + paths?: Partial>>; } export interface AmplifyOutputsStorageProperties { /** Default region for Storage */