Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): amplify configure with storage path type issue #14088

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/core/__tests__/parseAmplifyOutputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
},
],
},
};
Expand All @@ -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'],
},
},
},
},
},
},
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/parseAmplifyOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,22 @@ function createBucketInfoMap(
);
}

const sanitizedPaths = paths
Copy link
Member Author

@ashwinkumar6 ashwinkumar6 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sanitization step is required to convert Partial<Record<string, ...>> type to Record<string, ...> by removing undefined values. i.e remove Partial.

? Object.entries(paths).reduce<
Record<string, Record<string, string[] | undefined>>
>((acc, [key, value]) => {
if (value !== undefined) {
acc[key] = value;
}

return acc;
}, {})
: undefined;

mappedBuckets[name] = {
bucketName,
region,
paths,
paths: sanitizedPaths,
};
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/singleton/AmplifyOutputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface AmplifyOutputsStorageBucketProperties {
/** Region for the bucket */
aws_region: string;
/** Paths to object with access permissions */
paths?: Record<string, Record<string, string[] | undefined>>;
paths?: Partial<Record<string, Record<string, string[] | undefined>>>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note:
We have added Partial for AmplifyOutputs here but not for the Amplify singleton in itself. Adding Partial to the singleton would mean we would need to update additional APIs that consume path since they expect a stricter type from the singleton.

Hence the additional parsing logic above in parseAmplifyOutputs.ts is required
(same goes auth userGroups as well)

}
export interface AmplifyOutputsStorageProperties {
/** Default region for Storage */
Expand Down
Loading