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

Conversation

ashwinkumar6
Copy link
Member

Description of changes

Amplify configure with storage, with multiple buckets with unique paths throws a type error Type 'undefined' is not assignable to type 'Record<string, string[] | undefined>. This PR loosens this type to avoid this error.

Description of how you validated changes

  • Updated unit test to check parsing logic for multiple buckets
  • Tested that the following with amplify.configure does not throw any type error
	"storage": {
		"aws_region": "us-west-2",
		"bucket_name": "mock-bucket-1",
		"buckets": [
			{
				"name": "mock-bucket-1",
				"bucket_name": "bucket1",
				"aws_region": "us-west-2",
				"paths": {
					"sub/*": {
						"authenticated": ["get", "list"]
					},
					"public/*": {
						"guest": ["get", "list", "write", "delete"],
						"authenticated": ["write", "get", "list", "delete"]
					}
				}
			},
			{
				"name": "mock-bucket-2",
				"bucket_name": "bucket2",
				"aws_region": "us-west-2",
				"paths": {
					"public/*": {
						"guest": ["get", "list", "write", "delete"],
						"authenticated": ["write", "get", "list", "delete"]
					}
				}
			}
		]
	}
  • amplify.getConfig returns the correct config

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -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)

@@ -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.

@ashwinkumar6 ashwinkumar6 changed the title chore(ci): remove storage-browser integ test auth0 deps fix(core): amplify configure with storage path type issue Dec 18, 2024
AllanZhengYP
AllanZhengYP previously approved these changes Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants