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

feat: custom user agent Auth changes for UI handoff #11606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cfe55be
chore: copy Auth code to InternalAuth
erinleigh90 Jul 7, 2023
9ba4d67
feat: add customUserAgentDetails param to InternalAuth methods
erinleigh90 Jul 10, 2023
3c0eb2b
feat: make AuthClass extend InternalAuthClass, override functions wit…
erinleigh90 Jul 10, 2023
8eac22a
build: export auth internals from /internals scope
erinleigh90 Jul 10, 2023
8d3f5d5
fix: changes signUp back to method type instead of prop so Auth can e…
erinleigh90 Jul 10, 2023
d33fc45
chore: update auth lint settings to allow class arrow functions to en…
erinleigh90 Jul 10, 2023
800c1f1
fix: add overloaded method signature back in - unrelated change
erinleigh90 Jul 10, 2023
838161b
test: fix auth tests by mocking InternalAuthClass instead of AuthClass
erinleigh90 Jul 10, 2023
e0d55cf
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Jul 11, 2023
6edc14e
chore: change arrow methods to normal functions
erinleigh90 Jul 12, 2023
f01cf5a
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Jul 31, 2023
b39528d
fix: remove async from overridden async functions
erinleigh90 Aug 2, 2023
db0ebeb
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Aug 2, 2023
01d5c2e
chore: increase bundle size limits
erinleigh90 Aug 2, 2023
25bd44d
fix: remove internalSignUp and fix rest attr with overload and any
erinleigh90 Aug 7, 2023
c860289
fix: remove internalSignUp and fix rest attr with overload and any
erinleigh90 Aug 7, 2023
164290a
chore: update jsdocs
erinleigh90 Aug 7, 2023
a01e68d
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Aug 7, 2023
bea961c
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Aug 7, 2023
0693193
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Aug 7, 2023
fd9b48d
chore: increase bundle size limits
erinleigh90 Aug 7, 2023
fc38ad6
Merge branch 'main' into feat/custom-user-agent-ui/auth
erinleigh90 Aug 7, 2023
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
2 changes: 1 addition & 1 deletion packages/api-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"name": "API (GraphQL client)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, GraphQLAPI }",
"limit": "88.92 kB"
"limit": "89.51 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"name": "API (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, API }",
"limit": "89.68 kB"
"limit": "90.27 kB"
}
],
"jest": {
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/__tests__/auth-attribute-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'amazon-cognito-identity-js';

import { AuthOptions } from '../src/types';
import { InternalAuthClass } from '../src/internals/InternalAuth';

const authOptions: AuthOptions = {
userPoolId: 'us-west-2_0xxxxxxxx',
Expand All @@ -22,7 +23,7 @@ const authOptions: AuthOptions = {
describe('User-Attribute-validation', () => {
it('Check-non-verified-attributes', async () => {
const spyonAuthUserAttributes = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementation((user: CognitoUser) => {
const emailAttribute = new CognitoUserAttribute({
Name: 'email',
Expand Down
51 changes: 26 additions & 25 deletions packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ import { Credentials, StorageHelper, Hub } from '@aws-amplify/core';
import { AuthError, NoUserPoolError } from '../src/Errors';
import { AuthErrorTypes } from '../src/types/Auth';
import { mockDeviceArray, transformedMockData } from './mockData';
import { InternalAuthClass } from '../src/internals/InternalAuth';

const authOptions: AuthOptions = {
userPoolId: 'awsUserPoolsId',
Expand Down Expand Up @@ -1646,7 +1647,7 @@ describe('auth unit test', () => {
describe('userAttributes', () => {
test('happy case', async () => {
const spyon = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(user => {
return new Promise((res: any, rej) => {
res('session');
Expand All @@ -1670,7 +1671,7 @@ describe('auth unit test', () => {

test('get userattributes failed', async () => {
const spyon = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(user => {
return new Promise((res: any, rej) => {
res('session');
Expand Down Expand Up @@ -1720,7 +1721,7 @@ describe('auth unit test', () => {
});

const spyon2 = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(session);
Expand Down Expand Up @@ -1809,7 +1810,7 @@ describe('auth unit test', () => {
});

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(user);
Expand Down Expand Up @@ -2299,15 +2300,15 @@ describe('auth unit test', () => {
});

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(user);
});
});

const spyon2 = jest
.spyOn(Auth.prototype, 'verifyUserAttribute')
.spyOn(InternalAuthClass.prototype, 'verifyUserAttribute')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res();
Expand All @@ -2318,7 +2319,7 @@ describe('auth unit test', () => {

expect.assertions(2);
expect(spyon).toBeCalled();
expect(spyon2).toBeCalledWith(user, 'attr');
expect(spyon2).toBeCalledWith(user, 'attr', undefined);

spyon.mockClear();
spyon2.mockClear();
Expand All @@ -2334,15 +2335,15 @@ describe('auth unit test', () => {
});

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(user);
});
});

const spyon2 = jest
.spyOn(Auth.prototype, 'verifyUserAttributeSubmit')
.spyOn(InternalAuthClass.prototype, 'verifyUserAttributeSubmit')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res();
Expand Down Expand Up @@ -2414,7 +2415,7 @@ describe('auth unit test', () => {
};

const spyonAuth = jest
.spyOn(Auth.prototype, 'currentUserCredentials')
.spyOn(InternalAuthClass.prototype, 'currentUserCredentials')
.mockImplementationOnce(() => {
return new Promise((resolve, reject) => {
resolve();
Expand Down Expand Up @@ -2505,7 +2506,7 @@ describe('auth unit test', () => {
const newPassword = 'newPassword1.';

const spyon = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(session);
Expand Down Expand Up @@ -2835,15 +2836,15 @@ describe('auth unit test', () => {
});

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(user);
});
});

const spyon2 = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementationOnce(() => {
auth['credentials'] = {
IdentityPoolId: 'identityPoolId',
Expand Down Expand Up @@ -2902,7 +2903,7 @@ describe('auth unit test', () => {
});

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res({
Expand All @@ -2912,15 +2913,15 @@ describe('auth unit test', () => {
});

const spyon2 = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
rej('err');
});
});

const spyon3 = jest
.spyOn(Auth.prototype, 'currentCredentials')
.spyOn(InternalAuthClass.prototype, 'currentCredentials')
.mockImplementationOnce(() => {
return Promise.resolve({
IdentityPoolId: 'identityPoolId',
Expand Down Expand Up @@ -2952,7 +2953,7 @@ describe('auth unit test', () => {
auth['credentials_source'] = 'aws';

const spyon = jest
.spyOn(Auth.prototype, 'currentUserPoolUser')
.spyOn(InternalAuthClass.prototype, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(null);
Expand Down Expand Up @@ -3009,7 +3010,7 @@ describe('auth unit test', () => {
};

const spyon = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(() => {
return new Promise((res, rej) => {
res(session);
Expand Down Expand Up @@ -3169,7 +3170,7 @@ describe('auth unit test', () => {
const attributeNames = ['email', 'phone_number'];

const spyon = jest
.spyOn(Auth.prototype, 'userSession')
.spyOn(InternalAuthClass.prototype, 'userSession')
.mockImplementationOnce(() => {
return new Promise(res => {
res(session);
Expand Down Expand Up @@ -3416,7 +3417,7 @@ describe('auth unit test', () => {
return Promise.resolve('cred' as any);
});
const spyon2 = jest
.spyOn(Auth.prototype, 'currentAuthenticatedUser')
.spyOn(InternalAuthClass.prototype, 'currentAuthenticatedUser')
.mockImplementation(() => {
if (!user) return Promise.reject('error');
else return Promise.resolve(user);
Expand Down Expand Up @@ -3490,7 +3491,7 @@ describe('auth unit test', () => {
return Promise.resolve('cred' as any);
});
const spyon2 = jest
.spyOn(Auth.prototype, 'currentAuthenticatedUser')
.spyOn(InternalAuthClass.prototype, 'currentAuthenticatedUser')
.mockImplementation(() => {
if (!user) return Promise.reject('error');
else return Promise.resolve(user);
Expand All @@ -3516,7 +3517,7 @@ describe('auth unit test', () => {
describe('handleAuthResponse test', () => {
beforeAll(() => {
jest
.spyOn(Auth.prototype, 'currentAuthenticatedUser')
.spyOn(InternalAuthClass.prototype, 'currentAuthenticatedUser')
.mockImplementation(() => {
throw new Error('no user logged in');
});
Expand Down Expand Up @@ -3729,7 +3730,7 @@ describe('auth unit test', () => {
describe('verifiedContact test', () => {
test('happy case with unverified', async () => {
const spyon = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementationOnce(() => {
return new Promise((res: any, rej) => {
res([
Expand Down Expand Up @@ -3761,7 +3762,7 @@ describe('auth unit test', () => {

test('happy case with verified', async () => {
const spyon = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementationOnce(() => {
return new Promise((res: any, rej) => {
res([
Expand Down Expand Up @@ -3801,7 +3802,7 @@ describe('auth unit test', () => {

test('happy case with verified as strings', async () => {
const spyon = jest
.spyOn(Auth.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.mockImplementationOnce(() => {
return new Promise((res: any, rej) => {
res([
Expand Down
5 changes: 3 additions & 2 deletions packages/auth/__tests__/totp-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ import {
CognitoAccessToken,
} from 'amazon-cognito-identity-js';
import { Hub } from '@aws-amplify/core';
import { InternalAuthClass } from '../src/internals/InternalAuth';

const authOptions: any = {
Auth: {
Expand Down Expand Up @@ -429,7 +430,7 @@ describe('auth unit test', () => {

const spyon = jest.spyOn(CognitoUser.prototype, 'setUserMfaPreference');
const spyon2 = jest
.spyOn(Auth.prototype, 'getPreferredMFA')
.spyOn(InternalAuthClass.prototype, 'getPreferredMFA')
.mockImplementationOnce(() => {
return Promise.resolve('SMS_MFA');
});
Expand All @@ -454,7 +455,7 @@ describe('auth unit test', () => {
callback(new Error('err'), null);
});
const spyon2 = jest
.spyOn(Auth.prototype, 'getPreferredMFA')
.spyOn(InternalAuthClass.prototype, 'getPreferredMFA')
.mockImplementationOnce(() => {
return Promise.resolve('SMS_MFA');
});
Expand Down
8 changes: 8 additions & 0 deletions packages/auth/internals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@aws-amplify/auth/internals",
"types": "../lib-esm/internals/index.d.ts",
"main": "../lib/internals/index.js",
"module": "../lib-esm/internals/index.js",
"react-native": "../lib-esm/internals/index.js",
"sideEffects": false
}
5 changes: 3 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"files": [
"lib",
"lib-esm",
"src"
"src",
"internals"
],
"dependencies": {
"@aws-amplify/core": "5.8.0",
Expand All @@ -59,7 +60,7 @@
"name": "Auth (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Auth }",
"limit": "55.73 kB"
"limit": "56.29 kB"
}
],
"jest": {
Expand Down
Loading