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

release(required): Amplify JS release #13719

Merged
merged 17 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions .github/integ-config/integ-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,14 @@ tests:
sample_name: [storage-gen2]
spec: storage-gen2
browser: *minimal_browser_list
- test_name: storage-guest-access
desc: 'Next Storage guest access'
- test_name: integ_next_storage
desc: 'Next Storage Auth'
framework: next
category: storage
sample_name: [guest-access]
sample_name: [storage-auth]
spec: storage-client-server
browser: *minimal_browser_list
browser: [chrome] # firefox issues with secure cookies in cypress, manual testing works fine

# INAPPMESSAGING
- test_name: integ_in_app_messaging
desc: 'React InApp Messaging'
Expand Down
54 changes: 27 additions & 27 deletions packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,31 +293,31 @@
"name": "[Analytics] record (Pinpoint)",
"path": "./dist/esm/analytics/index.mjs",
"import": "{ record }",
"limit": "17.09 kB"
"limit": "17.18 kB"
},
{
"name": "[Analytics] record (Kinesis)",
"path": "./dist/esm/analytics/kinesis/index.mjs",
"import": "{ record }",
"limit": "48.56 kB"
"limit": "48.61 kB"
},
{
"name": "[Analytics] record (Kinesis Firehose)",
"path": "./dist/esm/analytics/kinesis-firehose/index.mjs",
"import": "{ record }",
"limit": "45.68 kB"
"limit": "45.76 kB"
},
{
"name": "[Analytics] record (Personalize)",
"path": "./dist/esm/analytics/personalize/index.mjs",
"import": "{ record }",
"limit": "49.50 kB"
"limit": "49.58 kB"
},
{
"name": "[Analytics] identifyUser (Pinpoint)",
"path": "./dist/esm/analytics/index.mjs",
"import": "{ identifyUser }",
"limit": "15.59 kB"
"limit": "15.68 kB"
},
{
"name": "[Analytics] enable",
Expand Down Expand Up @@ -353,13 +353,13 @@
"name": "[Auth] resetPassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ resetPassword }",
"limit": "12.44 kB"
"limit": "12.53 kB"
},
{
"name": "[Auth] confirmResetPassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmResetPassword }",
"limit": "12.39 kB"
"limit": "12.47 kB"
},
{
"name": "[Auth] signIn (Cognito)",
Expand All @@ -371,7 +371,7 @@
"name": "[Auth] resendSignUpCode (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ resendSignUpCode }",
"limit": "12.40 kB"
"limit": "12.49 kB"
},
{
"name": "[Auth] confirmSignUp (Cognito)",
Expand All @@ -383,31 +383,31 @@
"name": "[Auth] confirmSignIn (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmSignIn }",
"limit": "28.27 kB"
"limit": "28.38 kB"
},
{
"name": "[Auth] updateMFAPreference (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ updateMFAPreference }",
"limit": "11.74 kB"
"limit": "11.83 kB"
},
{
"name": "[Auth] fetchMFAPreference (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ fetchMFAPreference }",
"limit": "11.78 kB"
"limit": "11.86 kB"
},
{
"name": "[Auth] verifyTOTPSetup (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ verifyTOTPSetup }",
"limit": "12.6 kB"
"limit": "12.71 kB"
},
{
"name": "[Auth] updatePassword (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ updatePassword }",
"limit": "12.63 kB"
"limit": "12.73 kB"
},
{
"name": "[Auth] setUpTOTP (Cognito)",
Expand All @@ -419,85 +419,85 @@
"name": "[Auth] updateUserAttributes (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ updateUserAttributes }",
"limit": "11.87 kB"
"limit": "11.95 kB"
},
{
"name": "[Auth] getCurrentUser (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ getCurrentUser }",
"limit": "7.75 kB"
"limit": "7.85 kB"
},
{
"name": "[Auth] confirmUserAttribute (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ confirmUserAttribute }",
"limit": "12.61 kB"
"limit": "12.71 kB"
},
{
"name": "[Auth] signInWithRedirect (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ signInWithRedirect }",
"limit": "21.10 kB"
"limit": "21.15 kB"
},
{
"name": "[Auth] fetchUserAttributes (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ fetchUserAttributes }",
"limit": "11.69 kB"
"limit": "11.77 kB"
},
{
"name": "[Auth] Basic Auth Flow (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ signIn, signOut, fetchAuthSession, confirmSignIn }",
"limit": "30.06 kB"
"limit": "30.15 kB"
},
{
"name": "[Auth] OAuth Auth Flow (Cognito)",
"path": "./dist/esm/auth/index.mjs",
"import": "{ signInWithRedirect, signOut, fetchAuthSession }",
"limit": "21.47 kB"
"limit": "21.58 kB"
},
{
"name": "[Storage] copy (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ copy }",
"limit": "14.54 kB"
"limit": "14.86 kB"
},
{
"name": "[Storage] downloadData (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ downloadData }",
"limit": "15.17 kB"
"limit": "15.45 kB"
},
{
"name": "[Storage] getProperties (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ getProperties }",
"limit": "14.43 kB"
"limit": "14.70 kB"
},
{
"name": "[Storage] getUrl (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ getUrl }",
"limit": "15.64 kB"
"limit": "15.90 kB"
},
{
"name": "[Storage] list (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ list }",
"limit": "15.04 kB"
"limit": "15.30 kB"
},
{
"name": "[Storage] remove (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ remove }",
"limit": "14.29 kB"
"limit": "14.56 kB"
},
{
"name": "[Storage] uploadData (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ uploadData }",
"limit": "19.66 kB"
"limit": "19.90 kB"
}
]
}
65 changes: 65 additions & 0 deletions packages/core/__tests__/parseAmplifyOutputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,71 @@ describe('parseAmplifyOutputs tests', () => {
},
});
});
it('should parse storage multi bucket', () => {
const amplifyOutputs: AmplifyOutputs = {
version: '1',
storage: {
aws_region: 'us-west-2',
bucket_name: 'storage-bucket-test',
buckets: [
{
name: 'default-bucket',
bucket_name: 'storage-bucket-test',
aws_region: 'us-west-2',
},
{
name: 'bucket-2',
bucket_name: 'storage-bucket-test-2',
aws_region: 'us-west-2',
},
],
},
};

const result = parseAmplifyOutputs(amplifyOutputs);

expect(result).toEqual({
Storage: {
S3: {
bucket: 'storage-bucket-test',
region: 'us-west-2',
buckets: {
'bucket-2': {
bucketName: 'storage-bucket-test-2',
region: 'us-west-2',
},
'default-bucket': {
bucketName: 'storage-bucket-test',
region: 'us-west-2',
},
},
},
},
});
});
it('should throw for storage multi bucket parsing with same friendly name', () => {
const amplifyOutputs: AmplifyOutputs = {
version: '1',
storage: {
aws_region: 'us-west-2',
bucket_name: 'storage-bucket-test',
buckets: [
{
name: 'default-bucket',
bucket_name: 'storage-bucket-test',
aws_region: 'us-west-2',
},
{
name: 'default-bucket',
bucket_name: 'storage-bucket-test-2',
aws_region: 'us-west-2',
},
],
},
};

expect(() => parseAmplifyOutputs(amplifyOutputs)).toThrow();
});
});

describe('analytics tests', () => {
Expand Down
28 changes: 26 additions & 2 deletions packages/core/src/parseAmplifyOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* This is because JSON schema contains keys with snake_case */
/* eslint-disable camelcase */

/* Does not like exahaustive checks */
/* Does not like exhaustive checks */
/* eslint-disable no-case-declarations */

import {
Expand All @@ -25,11 +25,13 @@ import {
AmplifyOutputsDataProperties,
AmplifyOutputsGeoProperties,
AmplifyOutputsNotificationsProperties,
AmplifyOutputsStorageBucketProperties,
AmplifyOutputsStorageProperties,
} from './singleton/AmplifyOutputs/types';
import {
AnalyticsConfig,
AuthConfig,
BucketInfo,
GeoConfig,
LegacyConfig,
ResourcesConfig,
Expand All @@ -56,12 +58,13 @@ function parseStorage(
return undefined;
}

const { bucket_name, aws_region } = amplifyOutputsStorageProperties;
const { bucket_name, aws_region, buckets } = amplifyOutputsStorageProperties;

return {
S3: {
bucket: bucket_name,
region: aws_region,
buckets: buckets && createBucketInfoMap(buckets),
},
};
}
Expand Down Expand Up @@ -333,3 +336,24 @@ function getMfaStatus(

return 'off';
}

function createBucketInfoMap(
buckets: AmplifyOutputsStorageBucketProperties[],
): Record<string, BucketInfo> {
const mappedBuckets: Record<string, BucketInfo> = {};

buckets.forEach(({ name, bucket_name: bucketName, aws_region: region }) => {
if (name in mappedBuckets) {
throw new Error(
`Duplicate friendly name found: ${name}. Name must be unique.`,
);
}

mappedBuckets[name] = {
bucketName,
region,
};
});

return mappedBuckets;
}
12 changes: 12 additions & 0 deletions packages/core/src/singleton/AmplifyOutputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,21 @@ export interface AmplifyOutputsAuthProperties {
mfa_methods?: string[];
}

export interface AmplifyOutputsStorageBucketProperties {
/** Friendly bucket name provided in Amplify Outputs */
name: string;
/** Actual S3 bucket name given */
bucket_name: string;
/** Region for the bucket */
aws_region: string;
}
export interface AmplifyOutputsStorageProperties {
/** Default region for Storage */
aws_region: string;
/** Default bucket for Storage */
bucket_name: string;
/** List of buckets for Storage */
buckets?: AmplifyOutputsStorageBucketProperties[];
}

export interface AmplifyOutputsGeoProperties {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/singleton/Storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { AtLeastOne } from '../types';
/** @deprecated This may be removed in the next major version. */
export type StorageAccessLevel = 'guest' | 'protected' | 'private';

/** Information on bucket used to store files/objects */
export interface BucketInfo {
/** Actual bucket name */
bucketName: string;
/** Region of the bucket */
region: string;
}
export interface S3ProviderConfig {
S3: {
bucket?: string;
Expand All @@ -16,6 +23,8 @@ export interface S3ProviderConfig {
* @internal
*/
dangerouslyConnectToHttpEndpointForTesting?: string;
/** Map of friendly name for bucket to its information */
buckets?: Record<string, BucketInfo>;
};
}

Expand Down
Loading
Loading