Skip to content

Commit

Permalink
Merge branch 'next' into temp-signOut
Browse files Browse the repository at this point in the history
  • Loading branch information
elorzafe authored Aug 25, 2023
2 parents 197d855 + b6f7a01 commit 8c7fd33
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 116 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
"test": "npm run lint && jest -w 1 --coverage",
"test:size": "size-limit",
"test:size": "echo \"No-op\"",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
},
"size-limit": [
Expand Down
7 changes: 0 additions & 7 deletions packages/auth/build.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/auth/internals/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 77.44"
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 77.44"
},
"typesVersions": {
">=3.8": {
Expand Down
22 changes: 1 addition & 21 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO: remove Auth and AuthClass imports/exports
// import { Auth } from './Auth';
// tslint:disable-next-line no-duplicate-imports
// import type { AuthClass } from './Auth';
import {
CognitoHostedUIIdentityProvider,
SignUpParams,
GRAPHQL_AUTH_MODE,
} from './types/Auth';
// import {
// CognitoUser,
// CookieStorage,
// appendToCognitoUserAgent,
// } from 'amazon-cognito-identity-js';
import { AuthErrorStrings } from './common/AuthErrorStrings';

/**
* @deprecated use named import
*/
// export default Auth;
export {
// Auth,
// CognitoUser,
// CookieStorage,
CognitoHostedUIIdentityProvider,
SignUpParams,
// appendToCognitoUserAgent,
AuthErrorStrings,
GRAPHQL_AUTH_MODE,
};
// export type { AuthClass };

// Provider specific types
// Default provider APIs & types
export * from './providers/cognito';

// Category specific types
export * from './types';

export { fetchAuthSession } from '@aws-amplify/core';
3 changes: 0 additions & 3 deletions packages/auth/src/internals/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/auth/tsconfig.build.json

This file was deleted.

2 changes: 0 additions & 2 deletions packages/aws-amplify/__tests__/exports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ describe('aws-amplify', () => {
"Amplify",
"AmplifyV6",
"withSSRContext",
"Storage",
"StorageClass",
]
`);
});
Expand Down
3 changes: 0 additions & 3 deletions packages/aws-amplify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ export { DefaultAmplifyV6 as AmplifyV6 } from './initSingleton';

// TODO(v6): Remove legacy SSR utility when new utilities available
export { withSSRContext } from './ssr/withSSRContext';

// TODO(v6): Remove these category exports as categories come on-line
export { Storage, StorageClass } from '@aws-amplify/storage';
18 changes: 9 additions & 9 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"typings.d.ts",
"internals",
"polyfills",
"**/package.json"
"server"
],
"dependencies": {
"@aws-crypto/sha256-js": "1.2.2",
Expand Down Expand Up @@ -90,37 +90,37 @@
"name": "Core (ServiceWorker)",
"path": "./lib-esm/index.js",
"import": "{ ServiceWorker }",
"limit": "2.41 kB"
"limit": "19.6 kB"
},
{
"name": "Core (Hub)",
"path": "./lib-esm/index.js",
"import": "{ Hub }",
"limit": "2.05 kB"
"limit": "2.3 kB"
},
{
"name": "Core (I18n)",
"path": "./lib-esm/index.js",
"import": "{ I18n }",
"limit": "2.17 kB"
"limit": "6.1 kB"
},
{
"name": "Core (Logger)",
"path": "./lib-esm/index.js",
"import": "{ Logger }",
"limit": "1.2 kB"
"limit": "1.3 kB"
},
{
"name": "Core (Credentials)",
"path": "./lib-esm/index.js",
"import": "{ Credentials }",
"limit": "13.78 kB"
"limit": "14.1 kB"
},
{
"name": "Core (Signer)",
"path": "./lib-esm/index.js",
"import": "{ Signer }",
"limit": "7.4 kB"
"limit": "19.6 kB"
},
{
"name": "Custom clients (fetch handler)",
Expand Down Expand Up @@ -162,13 +162,13 @@
"name": "Cache (default browser storage)",
"path": "./lib-esm/index.js",
"import": "{ Cache }",
"limit": "4.66 kB"
"limit": "7.8 kB"
},
{
"name": "Cache (in-memory)",
"path": "./lib-esm/index.js",
"import": "{ InMemoryCache }",
"limit": "4.35 kB"
"limit": "7.9 kB"
}
],
"jest": {
Expand Down
4 changes: 3 additions & 1 deletion packages/storage/__tests__/Storage-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { AWSS3Provider as AWSStorageProvider } from '../src/providers/AWSS3Provi
import { Storage as StorageClass } from '../src/Storage';
import {
S3ProviderListOutput,
Storage as StorageCategory,
StorageProvider,
} from '../src';
import {
StorageInstance as StorageCategory
} from '../src/Storage'
import { isCancelError } from '../src/AwsClients/S3/utils';
import { getPrefix } from '../src/common/S3ClientUtils';
import { AWSS3UploadTask } from '../src/providers/AWSS3UploadTask';
Expand Down
140 changes: 140 additions & 0 deletions packages/storage/__tests__/providers/s3/remove.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Credentials } from '@aws-sdk/types';
import { AmplifyV6 } from '@aws-amplify/core';
import { deleteObject } from '../../../src/AwsClients/S3';
import { remove } from '../../../src/providers/s3/apis';

jest.mock('../../../src/AwsClients/S3');
jest.mock('@aws-amplify/core', () => {
const core = jest.requireActual('@aws-amplify/core');
return {
...core,
fetchAuthSession: jest.fn(),
AmplifyV6: {
...core.AmplifyV6,
getConfig: jest.fn(),
Auth: {
...core.AmplifyV6.Auth,
fetchAuthSession: jest.fn(),
},
},
};
});
const mockDeleteObject = deleteObject as jest.Mock;
const key = 'key';
const bucket = 'bucket';
const region = 'region';
const targetIdentityId = 'targetIdentityId';
const removeResult = { key };
const credentials: Credentials = {
accessKeyId: 'accessKeyId',
sessionToken: 'sessionToken',
secretAccessKey: 'secretAccessKey',
};
const deleteObjectClientConfig = {
credentials,
region,
};

describe('remove API', () => {
beforeAll(() => {
(AmplifyV6.Auth.fetchAuthSession as jest.Mock).mockResolvedValue({
credentials,
identityId: targetIdentityId,
});
(AmplifyV6.getConfig as jest.Mock).mockReturnValue({
Storage: {
bucket: 'bucket',
region: 'region',
},
});
});
describe('Happy Path Cases:', () => {
beforeEach(() => {
mockDeleteObject.mockImplementation(() => {
return {
Metadata: { key: 'value' },
};
});
});
afterEach(() => {
jest.clearAllMocks();
});

it('Should remove object with default accessLevel', async () => {
expect.assertions(3);
expect(await remove({ key })).toEqual(removeResult);
expect(deleteObject).toBeCalledTimes(1);
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, {
Bucket: bucket,
Key: `public/${key}`,
});
});

it('Should remove object with guest accessLevel', async () => {
expect.assertions(3);
expect(await remove({ key, options: { accessLevel: 'guest' } })).toEqual(
removeResult
);
expect(deleteObject).toBeCalledTimes(1);
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, {
Bucket: bucket,
Key: `public/${key}`,
});
});

it('Should remove object with private accessLevel', async () => {
expect.assertions(3);
const accessLevel = 'private';
expect(await remove({ key, options: { accessLevel } })).toEqual(
removeResult
);
expect(deleteObject).toBeCalledTimes(1);
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, {
Bucket: bucket,
Key: `${accessLevel}/${targetIdentityId}/${key}`,
});
});

it('Should remove object with protected accessLevel', async () => {
expect.assertions(3);
const accessLevel = 'protected';
expect(
await remove({ key, options: { accessLevel, targetIdentityId } })
).toEqual(removeResult);
expect(deleteObject).toBeCalledTimes(1);
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, {
Bucket: bucket,
Key: `${accessLevel}/${targetIdentityId}/${key}`,
});
});
});

describe('Error Path Cases:', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('Should return a not found error', async () => {
mockDeleteObject.mockRejectedValueOnce(
Object.assign(new Error(), {
$metadata: { httpStatusCode: 404 },
name: 'NotFound',
})
);
expect.assertions(3);
const key = 'wrongKey';
try {
await remove({ key });
} catch (error) {
expect(deleteObject).toBeCalledTimes(1);
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, {
Bucket: bucket,
Key: `public/${key}`,
});
expect(error.$metadata.httpStatusCode).toBe(404);
}
});
});
});
9 changes: 1 addition & 8 deletions packages/storage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// TODO: (ashwinkumar6) cleanup old exports
import { Storage, StorageInstance } from './Storage';
export { AWSS3Provider } from './providers/AWSS3Provider';
export { Storage as StorageClass, StorageInstance as Storage };
export {
uploadData,
uploadFile,
downloadData,
downloadFile,
remove,
list,
getProperties,
copy,
getUrl,
} from './providers/s3';
export * from './types';

export { isCancelError } from './AwsClients/S3/runtime';
export * from './types';
Loading

0 comments on commit 8c7fd33

Please sign in to comment.