Skip to content

Commit

Permalink
fix(core): amplify configure with storage path type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Kumar committed Dec 18, 2024
1 parent 8bc823f commit ca54f16
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
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
21 changes: 20 additions & 1 deletion packages/core/src/parseAmplifyOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ function getMfaStatus(
return 'off';
}

// interface BucketInfoFoo {
// bucketName: string;
// region: string;
// // paths?: Record<string, Record<string, string[] | undefined>>;
// paths?: Partial<Record<string, Record<string, string[] | undefined>>>;
// }

function createBucketInfoMap(
buckets: AmplifyOutputsStorageBucketProperties[],
): Record<string, BucketInfo> {
Expand All @@ -383,10 +390,22 @@ function createBucketInfoMap(
);
}

const sanitizedPaths = paths
? 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
3 changes: 2 additions & 1 deletion packages/core/src/singleton/AmplifyOutputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export interface AmplifyOutputsStorageBucketProperties {
/** Region for the bucket */
aws_region: string;
/** Paths to object with access permissions */
paths?: Record<string, Record<string, string[] | undefined>>;
// paths?: Record<string, Record<string, string[] | undefined>>;
paths?: Partial<Record<string, Record<string, string[] | undefined>>>;
}
export interface AmplifyOutputsStorageProperties {
/** Default region for Storage */
Expand Down

0 comments on commit ca54f16

Please sign in to comment.