diff --git a/packages/amplify-ui/src/Section.css b/packages/amplify-ui/src/Section.css index acf16c24977..2445ee2c922 100644 --- a/packages/amplify-ui/src/Section.css +++ b/packages/amplify-ui/src/Section.css @@ -1,64 +1,67 @@ @import './Theme.css'; .container { - font-weight: 400; + font-weight: 400; } .actionRow { - margin-bottom: 15px; + margin-bottom: 15px; } .sectionHeader { - color: var(--deepSquidInk); - margin-bottom: 24px; - font-size: 18px; - font-weight: 500; + color: var(--deepSquidInk); + margin-bottom: 24px; + font-size: 18px; + font-weight: 500; } .sectionHeaderHint { - color: var(--grey); - font-size: 16px; - font-weight: 400; - margin-top: 4px; + color: var(--grey); + font-size: 16px; + font-weight: 400; + margin-top: 4px; } .sectionBody { - margin-bottom: 30px; + margin-bottom: 30px; +} + +.sectionHeaderContent { } .sectionFooter { - font-size: 14px; - color: var(--grey); - display: flex; - flex-direction: row-reverse; - align-items: flex-start; + font-size: 14px; + color: var(--grey); + display: flex; + flex-direction: row-reverse; + align-items: flex-start; } .sectionFooterPrimaryContent { - margin-left: auto; + margin-left: auto; } .sectionFooterSecondaryContent { - margin-right: auto; - align-self: center; + margin-right: auto; + align-self: center; } @media only screen and (max-width: 599px) { - .sectionFooter { - flex-wrap: wrap; - } + .sectionFooter { + flex-wrap: wrap; + } - .sectionFooterPrimaryContent { - width: 100%; - margin-bottom: 32px; - } + .sectionFooterPrimaryContent { + width: 100%; + margin-bottom: 32px; + } - .sectionFooterPrimaryContent > button { - width: 100%; - } + .sectionFooterPrimaryContent > button { + width: 100%; + } - .sectionFooterSecondaryContent { - text-align: center; - flex: 0 0 100%; - } -} \ No newline at end of file + .sectionFooterSecondaryContent { + text-align: center; + flex: 0 0 100%; + } +} diff --git a/packages/amplify-ui/src/Section.css.d.ts b/packages/amplify-ui/src/Section.css.d.ts index 7ca8882d778..365eb8d8359 100644 --- a/packages/amplify-ui/src/Section.css.d.ts +++ b/packages/amplify-ui/src/Section.css.d.ts @@ -4,6 +4,7 @@ export const actionRow: string; export const sectionHeader: string; export const sectionHeaderHint: string; export const sectionBody: string; +export const sectionHeaderContent: string; export const sectionFooter: string; export const sectionFooterPrimaryContent: string; export const sectionFooterSecondaryContent: string; diff --git a/packages/aws-amplify-react/__mocks__/styleMock.js b/packages/aws-amplify-react/__mocks__/styleMock.ts similarity index 100% rename from packages/aws-amplify-react/__mocks__/styleMock.js rename to packages/aws-amplify-react/__mocks__/styleMock.ts diff --git a/packages/aws-amplify-react/__tests__/Amplify-UI/Amplify-UI-Components-React-test.js b/packages/aws-amplify-react/__tests__/Amplify-UI/Amplify-UI-Components-React-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Amplify-UI/Amplify-UI-Components-React-test.js rename to packages/aws-amplify-react/__tests__/Amplify-UI/Amplify-UI-Components-React-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.js.snap b/packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.tsx.snap similarity index 97% rename from packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.js.snap rename to packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.tsx.snap index 9e1ac84deac..0436fbad90b 100644 --- a/packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.js.snap +++ b/packages/aws-amplify-react/__tests__/Amplify-UI/__snapshots__/Amplify-UI-Components-React-test.tsx.snap @@ -102,6 +102,7 @@ exports[`AmplifyUi test render SectionHeader correctly 1`] = ` exports[`AmplifyUi test render SectionHeaderContent correctly 1`] = ` `; diff --git a/packages/aws-amplify-react/__tests__/AmplifyMessageMap-test.js b/packages/aws-amplify-react/__tests__/AmplifyMessageMap-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/AmplifyMessageMap-test.js rename to packages/aws-amplify-react/__tests__/AmplifyMessageMap-test.tsx diff --git a/packages/aws-amplify-react/__tests__/AmplifyUI-test.js b/packages/aws-amplify-react/__tests__/AmplifyUI-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/AmplifyUI-test.js rename to packages/aws-amplify-react/__tests__/AmplifyUI-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Analytics/__snapshots__/trackLifecycle-test.js.snap b/packages/aws-amplify-react/__tests__/Analytics/__snapshots__/trackLifecycle-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Analytics/__snapshots__/trackLifecycle-test.js.snap rename to packages/aws-amplify-react/__tests__/Analytics/__snapshots__/trackLifecycle-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Analytics/trackLifecycle-test.js b/packages/aws-amplify-react/__tests__/Analytics/trackLifecycle-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Analytics/trackLifecycle-test.js rename to packages/aws-amplify-react/__tests__/Analytics/trackLifecycle-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/AuthPiece-test.js b/packages/aws-amplify-react/__tests__/Auth/AuthPiece-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/AuthPiece-test.js rename to packages/aws-amplify-react/__tests__/Auth/AuthPiece-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Authenticator-test.js b/packages/aws-amplify-react/__tests__/Auth/Authenticator-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Authenticator-test.js rename to packages/aws-amplify-react/__tests__/Auth/Authenticator-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/ConfirmSignIn-test.js b/packages/aws-amplify-react/__tests__/Auth/ConfirmSignIn-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/ConfirmSignIn-test.js rename to packages/aws-amplify-react/__tests__/Auth/ConfirmSignIn-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js b/packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.js rename to packages/aws-amplify-react/__tests__/Auth/ConfirmSignUp-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/FederatedSignIn-test.js b/packages/aws-amplify-react/__tests__/Auth/FederatedSignIn-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/FederatedSignIn-test.js rename to packages/aws-amplify-react/__tests__/Auth/FederatedSignIn-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/ForgotPassword-test.js b/packages/aws-amplify-react/__tests__/Auth/ForgotPassword-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/ForgotPassword-test.js rename to packages/aws-amplify-react/__tests__/Auth/ForgotPassword-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Greetings-test.js b/packages/aws-amplify-react/__tests__/Auth/Greetings-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Greetings-test.js rename to packages/aws-amplify-react/__tests__/Auth/Greetings-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/PhoneField-test.js b/packages/aws-amplify-react/__tests__/Auth/PhoneField-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/PhoneField-test.js rename to packages/aws-amplify-react/__tests__/Auth/PhoneField-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/index-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/index-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/index-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/index-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAmazon-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAmazon-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAmazon-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAmazon-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAuth0-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAuth0-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAuth0-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withAuth0-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withFacebook-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withFacebook-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withFacebook-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withFacebook-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withGoogle-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withGoogle-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withGoogle-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withGoogle-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withOAuth-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withOAuth-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withOAuth-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/Provider/__snapshots__/withOAuth-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/index-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/index-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/index-test.js rename to packages/aws-amplify-react/__tests__/Auth/Provider/index-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withAmazon-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/withAmazon-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/withAmazon-test.js rename to packages/aws-amplify-react/__tests__/Auth/Provider/withAmazon-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withAuth0-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/withAuth0-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/withAuth0-test.js rename to packages/aws-amplify-react/__tests__/Auth/Provider/withAuth0-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withFacebook-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/withFacebook-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/withFacebook-test.js rename to packages/aws-amplify-react/__tests__/Auth/Provider/withFacebook-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.js deleted file mode 100644 index 39079a9d640..00000000000 --- a/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.js +++ /dev/null @@ -1,486 +0,0 @@ -import Auth from '@aws-amplify/auth'; -import * as React from 'react'; -import { Component } from 'react'; -import withGoogle, { - GoogleButton -} from '../../../src/Auth/Provider/withGoogle'; -import { SignInButton, Button } from '../../../src/AmplifyUI'; - -describe('withGoogle test', () => { - describe('render test', () => { - test('render correctly', () => { - window.gapi = null; - const MockComp = class extends Component { - render() { - return
; - } - }; - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - }); - }); - - describe('signIn test', () => { - test('happy case with connected response', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - window.gapi = { - auth2: { - getAuthInstance() { - return { - signIn() { - return new Promise((res, rej) => { - res('googleUser'); - }); - } - }; - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - const spyon = jest - .spyOn(comp, 'federatedSignIn') - .mockImplementationOnce(() => { - return; - }); - - await comp.signIn(); - - expect(spyon).toBeCalledWith('googleUser'); - - spyon.mockClear(); - }); - - test('with an onError handler', async () => { - const onErrorMock = jest.fn(); - - const MockComp = class extends Component { - render() { - return
; - } - }; - - window.gapi = { - auth2: { - getAuthInstance() { - return { - signIn() { - return { - then: (success, error) => error('error') - }; - } - }; - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - comp.signIn(); - - expect(onErrorMock).toBeCalledWith('error'); - - onErrorMock.mockClear(); - }); - - test('without an onError handler', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - window.gapi = { - auth2: { - getAuthInstance() { - return { - signIn() { - return { - then: (success, error) => error('error') - }; - } - }; - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - expect(() => comp.signIn()).toThrowError('error'); - }); - }); - - describe('federatedSignIn', () => { - test('happy case', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - const googleUser = { - getAuthResponse() { - return { - id_token: 'id_token', - expires_at: 0 - }; - }, - getBasicProfile() { - return { - getEmail() { - return 'email'; - }, - getName() { - return 'name'; - } - getImageUrl() { - return 'picture'; - } - }; - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - const spyon = jest - .spyOn(Auth, 'federatedSignIn') - .mockImplementationOnce(() => { - return new Promise((res, rej) => { - res('credentials'); - }); - }); - - const spyon_currentUser = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => { - return Promise.resolve('user'); - }); - - await comp.federatedSignIn(googleUser); - - expect(spyon).toBeCalledWith( - 'google', - { expires_at: 0, token: 'id_token' }, - { email: 'email', name: 'name', picture: 'picture' } - ); - - spyon.mockClear(); - spyon_currentUser.mockClear(); - }); - - test('happy case with onStateChange exists', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - const mockFn = jest.fn(); - - const googleUser = { - getAuthResponse() { - return { - id_token: 'id_token', - expires_at: 0 - }; - }, - getBasicProfile() { - return { - getEmail() { - return 'email'; - }, - getName() { - return 'name'; - } - getImageUrl() { - return 'picture'; - } - }; - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - wrapper.setProps({ - onStateChange: mockFn - }); - - const spyon = jest - .spyOn(Auth, 'federatedSignIn') - .mockImplementationOnce(() => { - return new Promise((res, rej) => { - res('credentials'); - }); - }); - - const spyon_currentUser = jest.spyOn(Auth, 'currentAuthenticatedUser').mockImplementationOnce(() => { - return Promise.resolve('user'); - }); - - await comp.federatedSignIn(googleUser); - - expect(spyon).toBeCalledWith( - 'google', - { expires_at: 0, token: 'id_token' }, - { email: 'email', name: 'name', picture: 'picture' } - ); - expect(mockFn).toBeCalledWith('signedIn', 'user'); - - spyon.mockClear(); - spyon_currentUser.mockClear(); - }); - }); - - describe('initGapi test', () => { - test('happy case', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - window.gapi = { - load(path, callback) { - callback(); - }, - auth2: { - init(params) { - return new Promise((res, rej) => { - res('ga'); - }); - }, - getAuthInstance() { - return { - signIn() { - return new Promise((res, rej) => { - res('googleUser'); - }); - } - }; - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - await comp.initGapi(); - }); - }); - - describe.skip('refreshGoogleToken test', () => { - test('happy case', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - const authResponse = { - id_token: 'id_token', - expires_at: 0 - }; - - const googleAuth = { - currentUser: { - get() { - // google User - return { - isSignedIn() { - return true; - }, - reloadAuthResponse() { - return new Promise((res, rej) => { - res(authResponse); - }); - }, - getBasicProfile() { - return { - getEmail() { return 'email'; }, - getName() { return 'name'; }, - getImageUrl() { return 'picture'; } - }; - } - }; - } - } - }; - - window.gapi = { - auth2: { - getAuthInstance() { - // googleAuth - return new Promise((res, rej) => { - res(googleAuth); - }); - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - const spyon = jest - .spyOn(Auth, 'federatedSignIn').mockImplementationOnce(() => { return Promise.resolve(); }); - - await comp.refreshGoogleToken(); - - spyon.mockClear(); - - }); - - test('not signed in', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - const authResponse = { - id_token: 'id_token', - expires_at: 0 - }; - - const googleAuth = { - currentUser: { - get() { - // google User - return { - isSignedIn() { - return false; - } - }; - } - } - }; - - window.gapi = { - auth2: { - getAuthInstance() { - // googleAuth - return new Promise((res, rej) => { - res(googleAuth); - }); - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - await comp.refreshGoogleToken(); - - }); - - test('no auth2', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - window.gapi = null - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - await comp.refreshGoogleToken(); - }); - - test('no googleAuth instance', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - window.gapi = { - auth2: { - getAuthInstance() { - // googleAuth - return new Promise((res, rej) => { - res(null); - }); - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - await comp.refreshGoogleToken(); - }); - }); - - describe('google signOut test', () => { - test('happy case', async () => { - const MockComp = class extends Component { - render() { - return
; - } - }; - - const mockFn = jest.fn(); - window.gapi = { - auth2: { - getAuthInstance() { - return Promise.resolve({ - signOut: mockFn - }); - } - } - }; - - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - await comp.signOut(); - - expect(mockFn).toBeCalled(); - }); - - test('no auth2', async () => { - window.gapi = null; - const MockComp = class extends Component { - render() { - return
; - } - }; - const Comp = withGoogle(MockComp); - const wrapper = shallow(); - const comp = wrapper.instance(); - - - expect(await comp.signOut()).toBeUndefined(); - }); - }); - -}); - -describe('GoogleButton test', () => { - describe('render test', () => { - test('render correctly', () => { - window.gapi = null; - const wrapper = shallow(); - - expect(wrapper).toMatchSnapshot(); - }); - }); -}); diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.tsx b/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.tsx new file mode 100644 index 00000000000..4905130f675 --- /dev/null +++ b/packages/aws-amplify-react/__tests__/Auth/Provider/withGoogle-test.tsx @@ -0,0 +1,495 @@ +import Auth from '@aws-amplify/auth'; +import * as React from 'react'; +import { Component } from 'react'; +import withGoogle, { + GoogleButton, +} from '../../../src/Auth/Provider/withGoogle'; +import { SignInButton, Button } from '../../../src/AmplifyUI'; + +describe('withGoogle test', () => { + describe('render test', () => { + test('render correctly', () => { + window.gapi = null; + const MockComp = class extends Component { + render() { + return
; + } + }; + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + }); + }); + + describe('signIn test', () => { + test('happy case with connected response', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + window.gapi = { + auth2: { + getAuthInstance() { + return { + signIn() { + return new Promise((res, rej) => { + res('googleUser'); + }); + }, + }; + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + const spyon = jest + .spyOn(comp, 'federatedSignIn') + .mockImplementationOnce(() => { + return; + }); + + await comp.signIn(); + + expect(spyon).toBeCalledWith('googleUser'); + + spyon.mockClear(); + }); + + test('with an onError handler', async () => { + const onErrorMock = jest.fn(); + + const MockComp = class extends Component { + render() { + return
; + } + }; + + window.gapi = { + auth2: { + getAuthInstance() { + return { + signIn() { + return { + then: (success, error) => error('error'), + }; + }, + }; + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + comp.signIn(); + + expect(onErrorMock).toBeCalledWith('error'); + + onErrorMock.mockClear(); + }); + + test('without an onError handler', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + window.gapi = { + auth2: { + getAuthInstance() { + return { + signIn() { + return { + then: (success, error) => error('error'), + }; + }, + }; + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + expect(() => comp.signIn()).toThrowError('error'); + }); + }); + + describe('federatedSignIn', () => { + test('happy case', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + const googleUser = { + getAuthResponse() { + return { + id_token: 'id_token', + expires_at: 0, + }; + }, + getBasicProfile() { + return { + getEmail() { + return 'email'; + }, + getName() { + return 'name'; + }, + getImageUrl() { + return 'picture'; + }, + }; + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + const spyon = jest + .spyOn(Auth, 'federatedSignIn') + .mockImplementationOnce(() => { + return new Promise((res, rej) => { + res('credentials'); + }); + }); + + const spyon_currentUser = jest + .spyOn(Auth, 'currentAuthenticatedUser') + .mockImplementationOnce(() => { + return Promise.resolve('user'); + }); + + await comp.federatedSignIn(googleUser); + + expect(spyon).toBeCalledWith( + 'google', + { expires_at: 0, token: 'id_token' }, + { email: 'email', name: 'name', picture: 'picture' } + ); + + spyon.mockClear(); + spyon_currentUser.mockClear(); + }); + + test('happy case with onStateChange exists', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + const mockFn = jest.fn(); + + const googleUser = { + getAuthResponse() { + return { + id_token: 'id_token', + expires_at: 0, + }; + }, + getBasicProfile() { + return { + getEmail() { + return 'email'; + }, + getName() { + return 'name'; + }, + getImageUrl() { + return 'picture'; + }, + }; + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + wrapper.setProps({ + onStateChange: mockFn, + }); + + const spyon = jest + .spyOn(Auth, 'federatedSignIn') + .mockImplementationOnce(() => { + return new Promise((res, rej) => { + res('credentials'); + }); + }); + + const spyon_currentUser = jest + .spyOn(Auth, 'currentAuthenticatedUser') + .mockImplementationOnce(() => { + return Promise.resolve('user'); + }); + + await comp.federatedSignIn(googleUser); + + expect(spyon).toBeCalledWith( + 'google', + { expires_at: 0, token: 'id_token' }, + { email: 'email', name: 'name', picture: 'picture' } + ); + expect(mockFn).toBeCalledWith('signedIn', 'user'); + + spyon.mockClear(); + spyon_currentUser.mockClear(); + }); + }); + + describe('initGapi test', () => { + test('happy case', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + window.gapi = { + load(path, callback) { + callback(); + }, + auth2: { + init(params) { + return new Promise((res, rej) => { + res('ga'); + }); + }, + getAuthInstance() { + return { + signIn() { + return new Promise((res, rej) => { + res('googleUser'); + }); + }, + }; + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + await comp.initGapi(); + }); + }); + + describe.skip('refreshGoogleToken test', () => { + test('happy case', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + const authResponse = { + id_token: 'id_token', + expires_at: 0, + }; + + const googleAuth = { + currentUser: { + get() { + // google User + return { + isSignedIn() { + return true; + }, + reloadAuthResponse() { + return new Promise((res, rej) => { + res(authResponse); + }); + }, + getBasicProfile() { + return { + getEmail() { + return 'email'; + }, + getName() { + return 'name'; + }, + getImageUrl() { + return 'picture'; + }, + }; + }, + }; + }, + }, + }; + + window.gapi = { + auth2: { + getAuthInstance() { + // googleAuth + return new Promise((res, rej) => { + res(googleAuth); + }); + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + const spyon = jest + .spyOn(Auth, 'federatedSignIn') + .mockImplementationOnce(() => { + return Promise.resolve(); + }); + + await comp.refreshGoogleToken(); + + spyon.mockClear(); + }); + + test('not signed in', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + const authResponse = { + id_token: 'id_token', + expires_at: 0, + }; + + const googleAuth = { + currentUser: { + get() { + // google User + return { + isSignedIn() { + return false; + }, + }; + }, + }, + }; + + window.gapi = { + auth2: { + getAuthInstance() { + // googleAuth + return new Promise((res, rej) => { + res(googleAuth); + }); + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + await comp.refreshGoogleToken(); + }); + + test('no auth2', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + window.gapi = null; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + await comp.refreshGoogleToken(); + }); + + test('no googleAuth instance', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + window.gapi = { + auth2: { + getAuthInstance() { + // googleAuth + return new Promise((res, rej) => { + res(null); + }); + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + await comp.refreshGoogleToken(); + }); + }); + + describe('google signOut test', () => { + test('happy case', async () => { + const MockComp = class extends Component { + render() { + return
; + } + }; + + const mockFn = jest.fn(); + window.gapi = { + auth2: { + getAuthInstance() { + return Promise.resolve({ + signOut: mockFn, + }); + }, + }, + }; + + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + await comp.signOut(); + + expect(mockFn).toBeCalled(); + }); + + test('no auth2', async () => { + window.gapi = null; + const MockComp = class extends Component { + render() { + return
; + } + }; + const Comp = withGoogle(MockComp); + const wrapper = shallow(); + const comp = wrapper.instance(); + + expect(await comp.signOut()).toBeUndefined(); + }); + }); +}); + +describe('GoogleButton test', () => { + describe('render test', () => { + test('render correctly', () => { + window.gapi = null; + const wrapper = shallow(); + + expect(wrapper).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/aws-amplify-react/__tests__/Auth/Provider/withOAuth-test.js b/packages/aws-amplify-react/__tests__/Auth/Provider/withOAuth-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/Provider/withOAuth-test.js rename to packages/aws-amplify-react/__tests__/Auth/Provider/withOAuth-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/RequireNewPassword-test.js b/packages/aws-amplify-react/__tests__/Auth/RequireNewPassword-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/RequireNewPassword-test.js rename to packages/aws-amplify-react/__tests__/Auth/RequireNewPassword-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/SignIn-test.js b/packages/aws-amplify-react/__tests__/Auth/SignIn-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/SignIn-test.js rename to packages/aws-amplify-react/__tests__/Auth/SignIn-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/SignOut-test.js b/packages/aws-amplify-react/__tests__/Auth/SignOut-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/SignOut-test.js rename to packages/aws-amplify-react/__tests__/Auth/SignOut-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/SignUp-test.js b/packages/aws-amplify-react/__tests__/Auth/SignUp-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/SignUp-test.js rename to packages/aws-amplify-react/__tests__/Auth/SignUp-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/TOTPSetup-test.js b/packages/aws-amplify-react/__tests__/Auth/TOTPSetup-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/TOTPSetup-test.js rename to packages/aws-amplify-react/__tests__/Auth/TOTPSetup-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/VerifyContact-test.js b/packages/aws-amplify-react/__tests__/Auth/VerifyContact-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/VerifyContact-test.js rename to packages/aws-amplify-react/__tests__/Auth/VerifyContact-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Authenticator-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Authenticator-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/Authenticator-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/Authenticator-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignIn-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignIn-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignIn-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignIn-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/ConfirmSignUp-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/FederatedSignIn-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/FederatedSignIn-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/FederatedSignIn-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/FederatedSignIn-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ForgotPassword-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/ForgotPassword-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/ForgotPassword-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/ForgotPassword-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/Greetings-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/PhoneField-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/PhoneField-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/PhoneField-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/PhoneField-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/RequireNewPassword-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/RequireNewPassword-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/RequireNewPassword-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/RequireNewPassword-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignIn-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignIn-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignIn-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignIn-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignOut-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/SignUp-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/TOTPSetup-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/TOTPSetup-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/TOTPSetup-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/TOTPSetup-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/VerifyContact-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/VerifyContact-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/VerifyContact-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/VerifyContact-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/__snapshots__/index-test.js.snap b/packages/aws-amplify-react/__tests__/Auth/__snapshots__/index-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/__snapshots__/index-test.js.snap rename to packages/aws-amplify-react/__tests__/Auth/__snapshots__/index-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Auth/index-test.js b/packages/aws-amplify-react/__tests__/Auth/index-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Auth/index-test.js rename to packages/aws-amplify-react/__tests__/Auth/index-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Storage/Common-test.js b/packages/aws-amplify-react/__tests__/Storage/Common-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/Common-test.js rename to packages/aws-amplify-react/__tests__/Storage/Common-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Storage/S3Album-test.js b/packages/aws-amplify-react/__tests__/Storage/S3Album-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/S3Album-test.js rename to packages/aws-amplify-react/__tests__/Storage/S3Album-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Storage/S3Image-test.js b/packages/aws-amplify-react/__tests__/Storage/S3Image-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/S3Image-test.js rename to packages/aws-amplify-react/__tests__/Storage/S3Image-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Storage/S3Text-test.js b/packages/aws-amplify-react/__tests__/Storage/S3Text-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/S3Text-test.js rename to packages/aws-amplify-react/__tests__/Storage/S3Text-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Album-test.js.snap b/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Album-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Album-test.js.snap rename to packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Album-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Image-test.js.snap b/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Image-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Image-test.js.snap rename to packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Image-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Text-test.js.snap b/packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Text-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Text-test.js.snap rename to packages/aws-amplify-react/__tests__/Storage/__snapshots__/S3Text-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Widget/PhotoPicker-test.js b/packages/aws-amplify-react/__tests__/Widget/PhotoPicker-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/PhotoPicker-test.js rename to packages/aws-amplify-react/__tests__/Widget/PhotoPicker-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Widget/Picker-test.js b/packages/aws-amplify-react/__tests__/Widget/Picker-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/Picker-test.js rename to packages/aws-amplify-react/__tests__/Widget/Picker-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Widget/SelectMFAType-test.js b/packages/aws-amplify-react/__tests__/Widget/SelectMFAType-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/SelectMFAType-test.js rename to packages/aws-amplify-react/__tests__/Widget/SelectMFAType-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Widget/TOTPSetupComp-test.js b/packages/aws-amplify-react/__tests__/Widget/TOTPSetupComp-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/TOTPSetupComp-test.js rename to packages/aws-amplify-react/__tests__/Widget/TOTPSetupComp-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Widget/TextPicker-test.js b/packages/aws-amplify-react/__tests__/Widget/TextPicker-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/TextPicker-test.js rename to packages/aws-amplify-react/__tests__/Widget/TextPicker-test.tsx diff --git a/packages/aws-amplify-react/__tests__/Widget/__snapshots__/PhotoPicker-test.js.snap b/packages/aws-amplify-react/__tests__/Widget/__snapshots__/PhotoPicker-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/__snapshots__/PhotoPicker-test.js.snap rename to packages/aws-amplify-react/__tests__/Widget/__snapshots__/PhotoPicker-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Widget/__snapshots__/Picker-test.js.snap b/packages/aws-amplify-react/__tests__/Widget/__snapshots__/Picker-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/__snapshots__/Picker-test.js.snap rename to packages/aws-amplify-react/__tests__/Widget/__snapshots__/Picker-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Widget/__snapshots__/SelectMFAType-test.js.snap b/packages/aws-amplify-react/__tests__/Widget/__snapshots__/SelectMFAType-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/__snapshots__/SelectMFAType-test.js.snap rename to packages/aws-amplify-react/__tests__/Widget/__snapshots__/SelectMFAType-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Widget/__snapshots__/TOTPSetupComp-test.js.snap b/packages/aws-amplify-react/__tests__/Widget/__snapshots__/TOTPSetupComp-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/__snapshots__/TOTPSetupComp-test.js.snap rename to packages/aws-amplify-react/__tests__/Widget/__snapshots__/TOTPSetupComp-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/Widget/__snapshots__/TextPicker-test.js.snap b/packages/aws-amplify-react/__tests__/Widget/__snapshots__/TextPicker-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/Widget/__snapshots__/TextPicker-test.js.snap rename to packages/aws-amplify-react/__tests__/Widget/__snapshots__/TextPicker-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/XR/IconButton-test.js b/packages/aws-amplify-react/__tests__/XR/IconButton-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/IconButton-test.js rename to packages/aws-amplify-react/__tests__/XR/IconButton-test.tsx diff --git a/packages/aws-amplify-react/__tests__/XR/Loading-test.js b/packages/aws-amplify-react/__tests__/XR/Loading-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/Loading-test.js rename to packages/aws-amplify-react/__tests__/XR/Loading-test.tsx diff --git a/packages/aws-amplify-react/__tests__/XR/SumerianScene-test.js b/packages/aws-amplify-react/__tests__/XR/SumerianScene-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/SumerianScene-test.js rename to packages/aws-amplify-react/__tests__/XR/SumerianScene-test.tsx diff --git a/packages/aws-amplify-react/__tests__/XR/Tooltip-test.js b/packages/aws-amplify-react/__tests__/XR/Tooltip-test.tsx similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/Tooltip-test.js rename to packages/aws-amplify-react/__tests__/XR/Tooltip-test.tsx diff --git a/packages/aws-amplify-react/__tests__/XR/__snapshots__/IconButton-test.js.snap b/packages/aws-amplify-react/__tests__/XR/__snapshots__/IconButton-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/__snapshots__/IconButton-test.js.snap rename to packages/aws-amplify-react/__tests__/XR/__snapshots__/IconButton-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/XR/__snapshots__/Loading-test.js.snap b/packages/aws-amplify-react/__tests__/XR/__snapshots__/Loading-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/__snapshots__/Loading-test.js.snap rename to packages/aws-amplify-react/__tests__/XR/__snapshots__/Loading-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/XR/__snapshots__/SumerianScene-test.js.snap b/packages/aws-amplify-react/__tests__/XR/__snapshots__/SumerianScene-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/__snapshots__/SumerianScene-test.js.snap rename to packages/aws-amplify-react/__tests__/XR/__snapshots__/SumerianScene-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/XR/__snapshots__/Tooltip-test.js.snap b/packages/aws-amplify-react/__tests__/XR/__snapshots__/Tooltip-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/XR/__snapshots__/Tooltip-test.js.snap rename to packages/aws-amplify-react/__tests__/XR/__snapshots__/Tooltip-test.tsx.snap diff --git a/packages/aws-amplify-react/__tests__/__snapshots__/AmplifyUI-test.js.snap b/packages/aws-amplify-react/__tests__/__snapshots__/AmplifyUI-test.tsx.snap similarity index 100% rename from packages/aws-amplify-react/__tests__/__snapshots__/AmplifyUI-test.js.snap rename to packages/aws-amplify-react/__tests__/__snapshots__/AmplifyUI-test.tsx.snap diff --git a/packages/aws-amplify-react/package.json b/packages/aws-amplify-react/package.json index cce09aabad1..01bdecacaa6 100644 --- a/packages/aws-amplify-react/package.json +++ b/packages/aws-amplify-react/package.json @@ -3,6 +3,7 @@ "version": "2.4.4", "description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.", "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "test": "tslint 'src/**/*.ts' && jest --coverage --updateSnapshot --maxWorkers 2", "build": "npm run clean && tsc -p .", @@ -16,6 +17,9 @@ "lint": "tslint 'src/**/*.ts'" }, "devDependencies": { + "@types/react": "^16.0.41", + "@types/react-dom": "^16.0.11", + "aws-amplify": "^1.1.36", "enzyme": "^3.1.0", "enzyme-adapter-react-16": "^1.0.3", "enzyme-to-json": "^3.2.1", @@ -62,7 +66,7 @@ "/node_modules/" ], "moduleNameMapper": { - "\\.(css|less|scss|sass)$": "/__mocks__/styleMock.js" + "\\.(css|less|scss|sass)$": "/__mocks__/styleMock.ts" } }, "dependencies": { diff --git a/packages/aws-amplify-react/src/API/GraphQL/Connect.js b/packages/aws-amplify-react/src/API/GraphQL/Connect.tsx similarity index 87% rename from packages/aws-amplify-react/src/API/GraphQL/Connect.js rename to packages/aws-amplify-react/src/API/GraphQL/Connect.tsx index 343b8a64d28..8ad330e1011 100644 --- a/packages/aws-amplify-react/src/API/GraphQL/Connect.js +++ b/packages/aws-amplify-react/src/API/GraphQL/Connect.tsx @@ -2,7 +2,24 @@ import regeneratorRuntime from 'regenerator-runtime/runtime'; import { Component } from 'react'; import API from '@aws-amplify/api'; -export default class Connect extends Component { +export interface IConnectProps { + mutation?: any; + onSubscriptionMsg?: (prevData: any) => any; + query?: any; + subscription?: any; +} + +export interface IConnectState { + loading: boolean; + data: any; + errors: any; + mutation: any; +} + +export default class Connect extends Component { + public subSubscription; + private mounted: boolean; + constructor(props) { super(props); @@ -34,7 +51,9 @@ export default class Connect extends Component { this.setState({ loading: true }); const { + // @ts-ignore query: { query, variables = {} } = {}, + // @ts-ignore mutation: { query: mutation, mutationVariables = {} } = {}, subscription, onSubscriptionMsg = prevData => prevData, @@ -70,6 +89,7 @@ export default class Connect extends Component { const response = await API.graphql({ query, variables }); + // @ts-ignore data = response.data; } catch (err) { data = err.data; @@ -78,6 +98,7 @@ export default class Connect extends Component { } if (hasValidMutation) { + // @ts-ignore mutationProp = async variables => { const result = await API.graphql({ query: mutation, variables }); @@ -95,9 +116,11 @@ export default class Connect extends Component { variables: subsVars, }); + // @ts-ignore this.subSubscription = observable.subscribe({ next: ({ value: { data } }) => { const { data: prevData } = this.state; + // @ts-ignore const newData = onSubscriptionMsg(prevData, data); if (this.mounted) { this.setState({ data: newData }); @@ -136,7 +159,9 @@ export default class Connect extends Component { const { query: prevQueryObj, mutation: prevMutationObj } = prevProps; // query + // @ts-ignore const { query: newQuery, variables: newQueryVariables } = newQueryObj || {}; + // @ts-ignore const { query: prevQuery, variables: prevQueryVariables } = prevQueryObj || {}; const queryChanged = @@ -144,8 +169,10 @@ export default class Connect extends Component { JSON.stringify(prevQueryVariables) !== JSON.stringify(newQueryVariables); // mutation + // @ts-ignore const { query: newMutation, variables: newMutationVariables } = newMutationObj || {}; + // @ts-ignore const { query: prevMutation, variables: prevMutationVariables } = prevMutationObj || {}; const mutationChanged = @@ -160,6 +187,7 @@ export default class Connect extends Component { render() { const { data, loading, mutation, errors } = this.state; + // @ts-ignore return this.props.children({ data, errors, loading, mutation }) || null; } } diff --git a/packages/aws-amplify-react/src/API/GraphQL/index.js b/packages/aws-amplify-react/src/API/GraphQL/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/API/GraphQL/index.js rename to packages/aws-amplify-react/src/API/GraphQL/index.tsx diff --git a/packages/aws-amplify-react/src/API/index.js b/packages/aws-amplify-react/src/API/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/API/index.js rename to packages/aws-amplify-react/src/API/index.tsx diff --git a/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.jsx b/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.tsx similarity index 99% rename from packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.jsx rename to packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.tsx index 2699adf90f0..bf89663e28d 100644 --- a/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.jsx +++ b/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Components-React.tsx @@ -391,6 +391,7 @@ export const Toast = props => { ); }; +// @ts-ignore Toast.defaultProps = { onClose: () => void 0, }; diff --git a/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme-Sample.jsx b/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme-Sample.tsx similarity index 100% rename from packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme-Sample.jsx rename to packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme-Sample.tsx diff --git a/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme.jsx b/packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme.tsx similarity index 100% rename from packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme.jsx rename to packages/aws-amplify-react/src/Amplify-UI/Amplify-UI-Theme.tsx diff --git a/packages/aws-amplify-react/src/Amplify-UI/data-test-attributes.js b/packages/aws-amplify-react/src/Amplify-UI/data-test-attributes.tsx similarity index 100% rename from packages/aws-amplify-react/src/Amplify-UI/data-test-attributes.js rename to packages/aws-amplify-react/src/Amplify-UI/data-test-attributes.tsx diff --git a/packages/aws-amplify-react/src/AmplifyI18n.js b/packages/aws-amplify-react/src/AmplifyI18n.tsx similarity index 100% rename from packages/aws-amplify-react/src/AmplifyI18n.js rename to packages/aws-amplify-react/src/AmplifyI18n.tsx diff --git a/packages/aws-amplify-react/src/AmplifyMessageMap.js b/packages/aws-amplify-react/src/AmplifyMessageMap.tsx similarity index 98% rename from packages/aws-amplify-react/src/AmplifyMessageMap.js rename to packages/aws-amplify-react/src/AmplifyMessageMap.tsx index c9bf96c4f85..d55a4f3401c 100644 --- a/packages/aws-amplify-react/src/AmplifyMessageMap.js +++ b/packages/aws-amplify-react/src/AmplifyMessageMap.tsx @@ -26,6 +26,7 @@ export const MapEntries = [ ]; export default function AmplifyMessageMap(message) { + // @ts-ignore const match = MapEntries.filter(entry => entry[1].test(message)); if (match.length === 0) { return message; diff --git a/packages/aws-amplify-react/src/AmplifyTheme.jsx b/packages/aws-amplify-react/src/AmplifyTheme.tsx similarity index 100% rename from packages/aws-amplify-react/src/AmplifyTheme.jsx rename to packages/aws-amplify-react/src/AmplifyTheme.tsx diff --git a/packages/aws-amplify-react/src/AmplifyUI.jsx b/packages/aws-amplify-react/src/AmplifyUI.tsx similarity index 100% rename from packages/aws-amplify-react/src/AmplifyUI.jsx rename to packages/aws-amplify-react/src/AmplifyUI.tsx diff --git a/packages/aws-amplify-react/src/Analytics/index.jsx b/packages/aws-amplify-react/src/Analytics/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/Analytics/index.jsx rename to packages/aws-amplify-react/src/Analytics/index.tsx diff --git a/packages/aws-amplify-react/src/Analytics/trackLifecycle.jsx b/packages/aws-amplify-react/src/Analytics/trackLifecycle.tsx similarity index 94% rename from packages/aws-amplify-react/src/Analytics/trackLifecycle.jsx rename to packages/aws-amplify-react/src/Analytics/trackLifecycle.tsx index aa8708e7c4e..bdd441f4d51 100644 --- a/packages/aws-amplify-react/src/Analytics/trackLifecycle.jsx +++ b/packages/aws-amplify-react/src/Analytics/trackLifecycle.tsx @@ -28,7 +28,10 @@ export function trackLifecycle( trackerName, events = Default_Track_Events ) { - return class WithTrackLifecycle extends Component { + return class WithTrackLifecycle extends Component { + public trackerName: string; + public trackEvents: string[]; + constructor(props) { super(props); this.trackerName = trackerName; diff --git a/packages/aws-amplify-react/src/Analytics/trackUpdate.jsx b/packages/aws-amplify-react/src/Analytics/trackUpdate.tsx similarity index 94% rename from packages/aws-amplify-react/src/Analytics/trackUpdate.jsx rename to packages/aws-amplify-react/src/Analytics/trackUpdate.tsx index 66a7528174a..2d202f3e531 100644 --- a/packages/aws-amplify-react/src/Analytics/trackUpdate.jsx +++ b/packages/aws-amplify-react/src/Analytics/trackUpdate.tsx @@ -16,7 +16,9 @@ import { Component } from 'react'; import Analytics from '@aws-amplify/analytics'; export function trackUpdate(Comp, trackerName) { - return class extends Component { + return class extends Component { + public trackerName: string; + constructor(props) { super(props); this.trackerName = trackerName; diff --git a/packages/aws-amplify-react/src/Auth/AuthPiece.jsx b/packages/aws-amplify-react/src/Auth/AuthPiece.tsx similarity index 87% rename from packages/aws-amplify-react/src/Auth/AuthPiece.jsx rename to packages/aws-amplify-react/src/Auth/AuthPiece.tsx index c196d874934..ed248a7a2e8 100644 --- a/packages/aws-amplify-react/src/Auth/AuthPiece.jsx +++ b/packages/aws-amplify-react/src/Auth/AuthPiece.tsx @@ -15,7 +15,7 @@ import * as React from 'react'; import { ConsoleLogger as Logger, I18n } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; -import countryDialCodes from './common/country-dial-codes.js'; +import countryDialCodes from './common/country-dial-codes'; import { FormField, Input, @@ -32,7 +32,30 @@ const labelMap = { [UsernameAttributes.USERNAME]: 'Username', }; -export default class AuthPiece extends React.Component { +export interface IAuthPieceProps { + authData?: any; + authState?: string; + hide?: any; + onAuthEvent?: any; + onStateChange?: (state: string, data?) => void; + track?: () => void; + theme?: any; + usernameAttributes?: UsernameAttributes; +} + +export interface IAuthPieceState { + username?: any; +} + +export default class AuthPiece< + Props extends IAuthPieceProps, + State extends IAuthPieceState +> extends React.Component { + public _validAuthStates: string[]; + public _isHidden: boolean; + public inputs: any; + public phone_number: any; + constructor(props) { super(props); @@ -156,7 +179,7 @@ export default class AuthPiece extends React.Component { } } - changeState(state, data) { + changeState(state, data?) { if (this.props.onStateChange) { this.props.onStateChange(state, data); } @@ -177,12 +200,15 @@ export default class AuthPiece extends React.Component { handleInputChange(evt) { this.inputs = this.inputs || {}; const { name, value, type, checked } = evt.target; + // @ts-ignore const check_type = ['radio', 'checkbox'].includes(type); this.inputs[name] = check_type ? checked : value; this.inputs['checkedValue'] = check_type ? value : null; } + // @ts-ignore render() { + // @ts-ignore if (!this._validAuthStates.includes(this.props.authState)) { this._isHidden = true; this.inputs = {}; @@ -200,6 +226,6 @@ export default class AuthPiece extends React.Component { } showComponent(theme) { - throw "You must implement showComponent(theme) and don't forget to set this._validAuthStates."; + throw 'You must implement showComponent(theme) and don\'t forget to set this._validAuthStates.'; } } diff --git a/packages/aws-amplify-react/src/Auth/AuthStateWrapper.jsx b/packages/aws-amplify-react/src/Auth/AuthStateWrapper.tsx similarity index 85% rename from packages/aws-amplify-react/src/Auth/AuthStateWrapper.jsx rename to packages/aws-amplify-react/src/Auth/AuthStateWrapper.tsx index 92336002008..097fc6b927f 100644 --- a/packages/aws-amplify-react/src/Auth/AuthStateWrapper.jsx +++ b/packages/aws-amplify-react/src/Auth/AuthStateWrapper.tsx @@ -7,7 +7,23 @@ import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; const logger = new Logger('AuthStateWrapper'); -export default class AuthStateWrapper extends Component { +export interface IAuthStateWrapperProps { + amplifyConfig?: any; + authState?: string; + onStateChange?: any; + theme?: any; +} + +export interface IAuthStateWrapperState { + authData?: any; + authState: string; + error?: any; +} + +export default class AuthStateWrapper extends Component< + IAuthStateWrapperProps, + IAuthStateWrapperState +> { constructor(props) { super(props); @@ -51,11 +67,13 @@ export default class AuthStateWrapper extends Component { } checkUser() { + // @ts-ignore if (!Auth || typeof Auth.currentUser !== 'function') { throw new Error( 'No Auth module found, please ensure @aws-amplify/auth is imported' ); } + // @ts-ignore return Auth.currentUser() .then(user => { const state = user ? 'signedIn' : 'signIn'; @@ -71,6 +89,7 @@ export default class AuthStateWrapper extends Component { if (!child) { return null; } + // @ts-ignore return React.cloneElement(child, { authState, authData, diff --git a/packages/aws-amplify-react/src/Auth/Authenticator.jsx b/packages/aws-amplify-react/src/Auth/Authenticator.tsx similarity index 89% rename from packages/aws-amplify-react/src/Auth/Authenticator.jsx rename to packages/aws-amplify-react/src/Auth/Authenticator.tsx index 98dcb02dd27..f737ef85da6 100644 --- a/packages/aws-amplify-react/src/Auth/Authenticator.jsx +++ b/packages/aws-amplify-react/src/Auth/Authenticator.tsx @@ -26,6 +26,7 @@ import VerifyContact from './VerifyContact'; import ForgotPassword from './ForgotPassword'; import TOTPSetup from './TOTPSetup'; import Constants from './common/constants'; +import { UsernameAttributes } from './common/types'; import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; import AmplifyMessageMap from '../AmplifyMessageMap'; @@ -38,7 +39,35 @@ const AUTHENTICATOR_AUTHSTATE = 'amplify-authenticator-authState'; export const EmptyContainer = ({ children }) => <>{children}; -export default class Authenticator extends Component { +export interface IAuthenticatorProps { + amplifyConfig?: any; + authData?: any; + authState?: string; + container?: any; + errorMessage?: (message: string) => string; + federated?: any; + hide?: any[]; + hideDefault?: boolean; + onStateChange?: (authState: string, data?) => void; + signUpConfig?: any; + theme?: any; + usernameAttributes?: UsernameAttributes; +} + +export interface IAuthenticatorState { + authData?; + authState: string; + error?: string; + showToast?: boolean; +} + +export default class Authenticator extends Component< + IAuthenticatorProps, + IAuthenticatorState +> { + public _initialAuthState: string; + public _isMounted: boolean; + constructor(props) { super(props); @@ -133,7 +162,7 @@ export default class Authenticator extends Component { } } - handleStateChange(state, data) { + handleStateChange(state, data?) { logger.debug('authenticator state change ' + state, data); if (state === this.state.authState) { return; @@ -214,17 +243,27 @@ export default class Authenticator extends Component { const default_children = [ , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , + // @ts-ignore , ]; + // @ts-ignore const props_children_override = React.Children.map( props_children, child => child.props.override @@ -236,6 +275,7 @@ export default class Authenticator extends Component { const render_props_children = React.Children.map( props_children, (child, index) => { + // @ts-ignore return React.cloneElement(child, { key: 'aws-amplify-authenticator-props-children-' + index, theme, @@ -254,6 +294,7 @@ export default class Authenticator extends Component { const render_default_children = hideDefault ? [] : React.Children.map(default_children, (child, index) => { + // @ts-ignore return React.cloneElement(child, { key: 'aws-amplify-authenticator-default-children-' + index, theme, diff --git a/packages/aws-amplify-react/src/Auth/ConfirmSignIn.jsx b/packages/aws-amplify-react/src/Auth/ConfirmSignIn.tsx similarity index 93% rename from packages/aws-amplify-react/src/Auth/ConfirmSignIn.jsx rename to packages/aws-amplify-react/src/Auth/ConfirmSignIn.tsx index a079b7041cb..9b6423c7ced 100644 --- a/packages/aws-amplify-react/src/Auth/ConfirmSignIn.jsx +++ b/packages/aws-amplify-react/src/Auth/ConfirmSignIn.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger, JS } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { FormSection, FormField, @@ -35,8 +35,15 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('ConfirmSignIn'); -export default class ConfirmSignIn extends AuthPiece { - constructor(props) { +export interface IConfirmSignInState extends IAuthPieceState { + mfaType: string; +} + +export default class ConfirmSignIn extends AuthPiece< + IAuthPieceProps, + IConfirmSignInState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['confirmSignIn']; diff --git a/packages/aws-amplify-react/src/Auth/ConfirmSignUp.jsx b/packages/aws-amplify-react/src/Auth/ConfirmSignUp.tsx similarity index 95% rename from packages/aws-amplify-react/src/Auth/ConfirmSignUp.jsx rename to packages/aws-amplify-react/src/Auth/ConfirmSignUp.tsx index 9562b7ab8e7..5aa007ad580 100644 --- a/packages/aws-amplify-react/src/Auth/ConfirmSignUp.jsx +++ b/packages/aws-amplify-react/src/Auth/ConfirmSignUp.tsx @@ -15,7 +15,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { FormSection, SectionHeader, @@ -35,8 +35,11 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('ConfirmSignUp'); -export default class ConfirmSignUp extends AuthPiece { - constructor(props) { +export default class ConfirmSignUp extends AuthPiece< + IAuthPieceProps, + IAuthPieceState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['confirmSignUp']; diff --git a/packages/aws-amplify-react/src/Auth/FederatedSignIn.jsx b/packages/aws-amplify-react/src/Auth/FederatedSignIn.tsx similarity index 90% rename from packages/aws-amplify-react/src/Auth/FederatedSignIn.jsx rename to packages/aws-amplify-react/src/Auth/FederatedSignIn.tsx index d891e0e6084..3004132820c 100644 --- a/packages/aws-amplify-react/src/Auth/FederatedSignIn.jsx +++ b/packages/aws-amplify-react/src/Auth/FederatedSignIn.tsx @@ -23,7 +23,15 @@ import { const logger = new Logger('FederatedSignIn'); -export class FederatedButtons extends Component { +export interface IFederatedButtonsProps { + authState: any; + federated: any; + onAuthEvent?: any; + onStateChange: any; + theme: any; +} + +export class FederatedButtons extends Component { google(google_client_id) { if (!google_client_id) { return null; @@ -88,6 +96,7 @@ export class FederatedButtons extends Component { return null; } const { theme, onStateChange } = this.props; + // @ts-ignore return ( { render() { const { authState, onStateChange } = this.props; const federated = this.props.federated || {}; @@ -163,11 +178,14 @@ export default class FederatedSignIn extends Component { ); } + // @ts-ignore const { oauth = {} } = Auth.configure(); // backward compatibility if (oauth['domain']) { federated.oauth_config = Object.assign({}, federated.oauth_config, oauth); + // @ts-ignore } else if (oauth.awsCognito) { + // @ts-ignore federated.oauth_config = Object.assign( {}, federated.oauth_config, @@ -175,7 +193,9 @@ export default class FederatedSignIn extends Component { ); } + // @ts-ignore if (oauth.auth0) { + // @ts-ignore federated.auth0 = Object.assign({}, federated.auth0, oauth.auth0); } @@ -186,6 +206,7 @@ export default class FederatedSignIn extends Component { ); return null; } + // @ts-ignore if (!['signIn', 'signedOut', 'signedUp'].includes(authState)) { return null; } diff --git a/packages/aws-amplify-react/src/Auth/ForgotPassword.jsx b/packages/aws-amplify-react/src/Auth/ForgotPassword.tsx similarity index 93% rename from packages/aws-amplify-react/src/Auth/ForgotPassword.jsx rename to packages/aws-amplify-react/src/Auth/ForgotPassword.tsx index caf83069f67..5ba42f487e5 100644 --- a/packages/aws-amplify-react/src/Auth/ForgotPassword.jsx +++ b/packages/aws-amplify-react/src/Auth/ForgotPassword.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; import { @@ -37,8 +37,15 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('ForgotPassword'); -export default class ForgotPassword extends AuthPiece { - constructor(props) { +export interface IForgotPasswordState extends IAuthPieceState { + delivery: any; +} + +export default class ForgotPassword extends AuthPiece< + IAuthPieceProps, + IForgotPasswordState +> { + constructor(props: IAuthPieceProps) { super(props); this.send = this.send.bind(this); @@ -77,6 +84,7 @@ export default class ForgotPassword extends AuthPiece { Auth.forgotPasswordSubmit(username, code, password) .then(data => { logger.debug(data); + // @ts-ignore this.changeState('signIn'); this.setState({ delivery: null }); }) diff --git a/packages/aws-amplify-react/src/Auth/Greetings.jsx b/packages/aws-amplify-react/src/Auth/Greetings.tsx similarity index 89% rename from packages/aws-amplify-react/src/Auth/Greetings.jsx rename to packages/aws-amplify-react/src/Auth/Greetings.tsx index 18f1ed1e17f..49bb170be57 100644 --- a/packages/aws-amplify-react/src/Auth/Greetings.jsx +++ b/packages/aws-amplify-react/src/Auth/Greetings.tsx @@ -14,7 +14,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger, Hub } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { NavBar, Nav, @@ -37,8 +37,25 @@ import { UsernameAttributes } from './common/types'; const logger = new Logger('Greetings'); -export default class Greetings extends AuthPiece { - constructor(props) { +export interface IGreetingsProps extends IAuthPieceProps { + federated?: any; + inGreeting?: string; + outGreeting?: string; +} + +export interface IGreetingsState extends IAuthPieceState { + authData?: any; + authState?: string; + stateFromStorage?: boolean; +} + +export default class Greetings extends AuthPiece< + IGreetingsProps, + IGreetingsState +> { + private _isMounted: boolean; + + constructor(props: IGreetingsProps) { super(props); this.state = {}; this.onHubCapsule = this.onHubCapsule.bind(this); @@ -137,7 +154,7 @@ export default class Greetings extends AuthPiece { return ( {message} - {this.renderSignOutButton(theme)} + {this.renderSignOutButton()} ); } @@ -150,16 +167,25 @@ export default class Greetings extends AuthPiece { amazon_client_id, auth0, } = federated; + // @ts-ignore const config = Auth.configure(); const { oauth = {} } = config; + // @ts-ignore const googleClientId = google_client_id || config.googleClientId; + // @ts-ignore const facebookAppId = facebook_app_id || config.facebookClientId; + // @ts-ignore const amazonClientId = amazon_client_id || config.amazonClientId; + // @ts-ignore const auth0_config = auth0 || oauth.auth0; + // @ts-ignore if (googleClientId) SignOut = withGoogle(SignOut); + // @ts-ignore if (facebookAppId) SignOut = withFacebook(SignOut); + // @ts-ignore if (amazonClientId) SignOut = withAmazon(SignOut); + // @ts-ignore if (auth0_config) SignOut = withAuth0(SignOut); const stateAndProps = Object.assign({}, this.props, this.state); diff --git a/packages/aws-amplify-react/src/Auth/Loading.jsx b/packages/aws-amplify-react/src/Auth/Loading.tsx similarity index 86% rename from packages/aws-amplify-react/src/Auth/Loading.jsx rename to packages/aws-amplify-react/src/Auth/Loading.tsx index c02b93fd1e2..802e2f1bd8a 100644 --- a/packages/aws-amplify-react/src/Auth/Loading.jsx +++ b/packages/aws-amplify-react/src/Auth/Loading.tsx @@ -14,7 +14,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger } from '@aws-amplify/core'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import AmplifyTheme from '../AmplifyTheme'; import { FormSection, @@ -25,8 +25,11 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('Loading'); -export default class Loading extends AuthPiece { - constructor(props) { +export default class Loading extends AuthPiece< + IAuthPieceProps, + IAuthPieceState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['loading']; diff --git a/packages/aws-amplify-react/src/Auth/PhoneField.jsx b/packages/aws-amplify-react/src/Auth/PhoneField.tsx similarity index 85% rename from packages/aws-amplify-react/src/Auth/PhoneField.jsx rename to packages/aws-amplify-react/src/Auth/PhoneField.tsx index 72a13ab4910..594e6051505 100644 --- a/packages/aws-amplify-react/src/Auth/PhoneField.jsx +++ b/packages/aws-amplify-react/src/Auth/PhoneField.tsx @@ -6,11 +6,24 @@ import { SelectInput, } from '../Amplify-UI/Amplify-UI-Components-React'; import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; -import countryDialCodes from './common/country-dial-codes.js'; +import countryDialCodes from './common/country-dial-codes'; import { I18n } from '@aws-amplify/core'; import { auth } from '../Amplify-UI/data-test-attributes'; -class PhoneField extends React.Component { +interface IPhoneFieldProps { + defaultDialCode?: string; + label?: string; + onChangeText: (string) => void; + placeholder?: string; + required?: boolean; + theme?: any; +} + +interface IPhoneFieldState {} + +class PhoneField extends React.Component { + private inputs: any; + constructor(props) { super(props); this.handleInputChange = this.handleInputChange.bind(this); diff --git a/packages/aws-amplify-react/src/Auth/Provider/index.jsx b/packages/aws-amplify-react/src/Auth/Provider/index.tsx similarity index 97% rename from packages/aws-amplify-react/src/Auth/Provider/index.jsx rename to packages/aws-amplify-react/src/Auth/Provider/index.tsx index 4a7a05112a4..95312b4868c 100644 --- a/packages/aws-amplify-react/src/Auth/Provider/index.jsx +++ b/packages/aws-amplify-react/src/Auth/Provider/index.tsx @@ -27,12 +27,14 @@ export { default as withOAuth, OAuthButton } from './withOAuth'; export { default as withAuth0, Auth0Button } from './withAuth0'; export function withFederated(Comp) { + // @ts-ignore const Federated = withAuth0( withOAuth(withAmazon(withGoogle(withFacebook(Comp)))) ); return class extends Component { render() { + // @ts-ignore const federated = this.props.federated || {}; return ; } diff --git a/packages/aws-amplify-react/src/Auth/Provider/withAmazon.jsx b/packages/aws-amplify-react/src/Auth/Provider/withAmazon.tsx similarity index 98% rename from packages/aws-amplify-react/src/Auth/Provider/withAmazon.jsx rename to packages/aws-amplify-react/src/Auth/Provider/withAmazon.tsx index d2d5baa31c7..c66734656ae 100644 --- a/packages/aws-amplify-react/src/Auth/Provider/withAmazon.jsx +++ b/packages/aws-amplify-react/src/Auth/Provider/withAmazon.tsx @@ -28,8 +28,8 @@ import Constants from '../common/constants'; const logger = new Logger('withAmazon'); export default function withAmazon(Comp) { - return class extends Component { - constructor(props) { + return class extends Component { + constructor(props: any) { super(props); this.initAmazon = this.initAmazon.bind(this); diff --git a/packages/aws-amplify-react/src/Auth/Provider/withAuth0.jsx b/packages/aws-amplify-react/src/Auth/Provider/withAuth0.tsx similarity index 97% rename from packages/aws-amplify-react/src/Auth/Provider/withAuth0.jsx rename to packages/aws-amplify-react/src/Auth/Provider/withAuth0.tsx index f52bbe9affd..2158067b224 100644 --- a/packages/aws-amplify-react/src/Auth/Provider/withAuth0.jsx +++ b/packages/aws-amplify-react/src/Auth/Provider/withAuth0.tsx @@ -29,8 +29,10 @@ import Constants from '../common/constants'; const logger = new Logger('withAuth0'); export default function withAuth0(Comp, options) { - return class extends Component { - constructor(props) { + return class extends Component { + public _auth0; + + constructor(props: any) { super(props); this._auth0 = null; @@ -56,7 +58,9 @@ export default function withAuth0(Comp, options) { } initialize() { + // @ts-ignore const { oauth = {} } = Auth.configure(); + // @ts-ignore const config = this.props.auth0 || options || oauth.auth0; const { onError, onStateChange, authState, onAuthEvent } = this.props; if (!config) { @@ -138,6 +142,7 @@ export default function withAuth0(Comp, options) { signOut(opts = {}) { const auth0 = window.auth0_client; + // @ts-ignore const { returnTo, clientID, federated } = opts; if (!auth0) { logger.debug('auth0 sdk undefined'); @@ -189,4 +194,5 @@ const Button = props => ( ); +// @ts-ignore export const Auth0Button = withAuth0(Button); diff --git a/packages/aws-amplify-react/src/Auth/Provider/withFacebook.jsx b/packages/aws-amplify-react/src/Auth/Provider/withFacebook.tsx similarity index 98% rename from packages/aws-amplify-react/src/Auth/Provider/withFacebook.jsx rename to packages/aws-amplify-react/src/Auth/Provider/withFacebook.tsx index 41a578caed7..1672344a678 100644 --- a/packages/aws-amplify-react/src/Auth/Provider/withFacebook.jsx +++ b/packages/aws-amplify-react/src/Auth/Provider/withFacebook.tsx @@ -28,8 +28,8 @@ import Constants from '../common/constants'; const logger = new Logger('withFacebook'); export default function withFacebook(Comp) { - return class extends Component { - constructor(props) { + return class extends Component { + constructor(props: any) { super(props); this.fbAsyncInit = this.fbAsyncInit.bind(this); @@ -188,7 +188,7 @@ export default function withFacebook(Comp) { }; } -const Button = props => ( +const Button = (props: any) => ( { + constructor(props: any) { super(props); this.initGapi = this.initGapi.bind(this); diff --git a/packages/aws-amplify-react/src/Auth/Provider/withOAuth.jsx b/packages/aws-amplify-react/src/Auth/Provider/withOAuth.tsx similarity index 93% rename from packages/aws-amplify-react/src/Auth/Provider/withOAuth.jsx rename to packages/aws-amplify-react/src/Auth/Provider/withOAuth.tsx index 5f9da531996..665135ea1bb 100644 --- a/packages/aws-amplify-react/src/Auth/Provider/withOAuth.jsx +++ b/packages/aws-amplify-react/src/Auth/Provider/withOAuth.tsx @@ -24,8 +24,8 @@ import { } from '../../Amplify-UI/Amplify-UI-Components-React'; export default function withOAuth(Comp) { - return class extends Component { - constructor(props) { + return class extends Component { + constructor(props: any) { super(props); this.signIn = this.signIn.bind(this); } @@ -40,7 +40,7 @@ export default function withOAuth(Comp) { }; } -const Button = props => ( +const Button = (props: any) => ( props.OAuthSignIn()} diff --git a/packages/aws-amplify-react/src/Auth/RequireNewPassword.jsx b/packages/aws-amplify-react/src/Auth/RequireNewPassword.tsx similarity index 95% rename from packages/aws-amplify-react/src/Auth/RequireNewPassword.jsx rename to packages/aws-amplify-react/src/Auth/RequireNewPassword.tsx index 1db8d01e8e9..28db1a1f66f 100644 --- a/packages/aws-amplify-react/src/Auth/RequireNewPassword.jsx +++ b/packages/aws-amplify-react/src/Auth/RequireNewPassword.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { I18n, JS, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import AmplifyTheme from '../AmplifyTheme'; import { FormSection, @@ -34,8 +34,11 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('RequireNewPassword'); -export default class RequireNewPassword extends AuthPiece { - constructor(props) { +export default class RequireNewPassword extends AuthPiece< + IAuthPieceProps, + IAuthPieceState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['requireNewPassword']; diff --git a/packages/aws-amplify-react/src/Auth/SignIn.jsx b/packages/aws-amplify-react/src/Auth/SignIn.tsx similarity index 94% rename from packages/aws-amplify-react/src/Auth/SignIn.jsx rename to packages/aws-amplify-react/src/Auth/SignIn.tsx index c00b3770fa9..f19a6e4f81f 100644 --- a/packages/aws-amplify-react/src/Auth/SignIn.jsx +++ b/packages/aws-amplify-react/src/Auth/SignIn.tsx @@ -15,7 +15,7 @@ import * as React from 'react'; import { I18n, JS, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { FederatedButtons } from './FederatedSignIn'; import SignUp from './SignUp'; import ForgotPassword from './ForgotPassword'; @@ -39,8 +39,17 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('SignIn'); -export default class SignIn extends AuthPiece { - constructor(props) { +export interface ISignInProps extends IAuthPieceProps { + federated?: any; + override?: any; +} + +export interface ISignInState extends IAuthPieceState { + loading?: boolean; +} + +export default class SignIn extends AuthPiece { + constructor(props: ISignInProps) { super(props); this.checkContact = this.checkContact.bind(this); diff --git a/packages/aws-amplify-react/src/Auth/SignOut.jsx b/packages/aws-amplify-react/src/Auth/SignOut.tsx similarity index 88% rename from packages/aws-amplify-react/src/Auth/SignOut.jsx rename to packages/aws-amplify-react/src/Auth/SignOut.tsx index 3df209fa446..b29343f0c98 100644 --- a/packages/aws-amplify-react/src/Auth/SignOut.jsx +++ b/packages/aws-amplify-react/src/Auth/SignOut.tsx @@ -15,7 +15,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger, Hub } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { NavButton } from '../Amplify-UI/Amplify-UI-Components-React'; import AmplifyTheme from '../Amplify-UI/Amplify-UI-Theme'; @@ -25,8 +25,24 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('SignOut'); -export default class SignOut extends AuthPiece { - constructor(props) { +export interface ISignOutProps extends IAuthPieceProps { + googleSignOut?: any; + facebookSignOut?: any; + amazonSignOut?: any; + auth0SignOut?: any; + stateFromStorage?: any; +} + +export interface ISignOutState extends IAuthPieceState { + authData?: any; + authState?: any; + stateFromStorage?: any; +} + +export default class SignOut extends AuthPiece { + public _isMounted: boolean; + + constructor(props: ISignOutProps) { super(props); this.signOut = this.signOut.bind(this); @@ -108,6 +124,7 @@ export default class SignOut extends AuthPiece { amazonSignOut, auth0SignOut, } = this.props; + // @ts-ignore switch (payload.provider) { case Constants.GOOGLE: if (googleSignOut) googleSignOut(); @@ -122,6 +139,7 @@ export default class SignOut extends AuthPiece { else logger.debug('No Amazon signout method provided'); break; case Constants.AUTH0: + // @ts-ignore if (auth0SignOut) auth0SignOut(payload.opts); else logger.debug('No Auth0 signout method provided'); break; diff --git a/packages/aws-amplify-react/src/Auth/SignUp.jsx b/packages/aws-amplify-react/src/Auth/SignUp.tsx similarity index 92% rename from packages/aws-amplify-react/src/Auth/SignUp.jsx rename to packages/aws-amplify-react/src/Auth/SignUp.tsx index d6d39d67da9..f7cfb69c106 100644 --- a/packages/aws-amplify-react/src/Auth/SignUp.jsx +++ b/packages/aws-amplify-react/src/Auth/SignUp.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import { FormSection, SectionHeader, @@ -34,19 +34,36 @@ import { import { auth } from '../Amplify-UI/data-test-attributes'; -import countryDialCodes from './common/country-dial-codes.js'; +import countryDialCodes from './common/country-dial-codes'; import signUpWithUsernameFields, { signUpWithEmailFields, signUpWithPhoneNumberFields, } from './common/default-sign-up-fields'; import { UsernameAttributes } from './common/types'; +import { ISignUpField } from './common/default-sign-up-fields'; import { valid } from 'semver'; import { PhoneField } from './PhoneField'; const logger = new Logger('SignUp'); -export default class SignUp extends AuthPiece { - constructor(props) { +export interface ISignUpConfig { + defaultCountryCode?: number | string; + header?: string; + hideAllDefaults?: boolean; + hiddenDefaults?: string[]; + signUpFields?: ISignUpField[]; +} + +export interface ISignUpProps extends IAuthPieceProps { + signUpConfig?: ISignUpConfig; +} + +export default class SignUp extends AuthPiece { + public defaultSignUpFields: ISignUpField[]; + public header: string; + public signUpFields: ISignUpField[]; + + constructor(props: ISignUpProps) { super(props); this._validAuthStates = ['signUp']; @@ -100,6 +117,7 @@ export default class SignUp extends AuthPiece { this.props.signUpConfig.hiddenDefaults.length > 0 ) { this.defaultSignUpFields = this.defaultSignUpFields.filter(d => { + // @ts-ignore return !this.props.signUpConfig.hiddenDefaults.includes(d.key); }); } @@ -171,6 +189,7 @@ export default class SignUp extends AuthPiece { getDefaultDialCode() { return this.props.signUpConfig && this.props.signUpConfig.defaultCountryCode && + // @ts-ignore countryDialCodes.indexOf( `+${this.props.signUpConfig.defaultCountryCode}` ) !== '-1' @@ -212,6 +231,7 @@ export default class SignUp extends AuthPiece { const inputVals = Object.values(this.inputs); inputKeys.forEach((key, index) => { + // @ts-ignore if ( !['username', 'password', 'checkedValue', 'dial_code'].includes(key) ) { @@ -248,6 +268,7 @@ export default class SignUp extends AuthPiece { } Auth.signUp(signup_info) .then(data => { + // @ts-ignore this.changeState('confirmSignUp', data.user.username); }) .catch(err => this.error(err)); diff --git a/packages/aws-amplify-react/src/Auth/TOTPSetup.jsx b/packages/aws-amplify-react/src/Auth/TOTPSetup.tsx similarity index 90% rename from packages/aws-amplify-react/src/Auth/TOTPSetup.jsx rename to packages/aws-amplify-react/src/Auth/TOTPSetup.tsx index bc097bc8324..03672d63e25 100644 --- a/packages/aws-amplify-react/src/Auth/TOTPSetup.jsx +++ b/packages/aws-amplify-react/src/Auth/TOTPSetup.tsx @@ -14,15 +14,18 @@ import * as React from 'react'; import { JS, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import TOTPSetupComp from '../Widget/TOTPSetupComp'; import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('TOTPSetup'); -export default class TOTPSetup extends AuthPiece { - constructor(props) { +export default class TOTPSetup extends AuthPiece< + IAuthPieceProps, + IAuthPieceState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['TOTPSetup']; diff --git a/packages/aws-amplify-react/src/Auth/VerifyContact.jsx b/packages/aws-amplify-react/src/Auth/VerifyContact.tsx similarity index 94% rename from packages/aws-amplify-react/src/Auth/VerifyContact.jsx rename to packages/aws-amplify-react/src/Auth/VerifyContact.tsx index 36c2676c486..668387dfddf 100644 --- a/packages/aws-amplify-react/src/Auth/VerifyContact.jsx +++ b/packages/aws-amplify-react/src/Auth/VerifyContact.tsx @@ -15,7 +15,7 @@ import * as React from 'react'; import { I18n, ConsoleLogger as Logger } from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; -import AuthPiece from './AuthPiece'; +import AuthPiece, { IAuthPieceProps, IAuthPieceState } from './AuthPiece'; import AmplifyTheme from '../AmplifyTheme'; import { FormSection, @@ -34,8 +34,15 @@ import { auth } from '../Amplify-UI/data-test-attributes'; const logger = new Logger('VerifyContact'); -export default class VerifyContact extends AuthPiece { - constructor(props) { +export interface IVerifyContactState extends IAuthPieceState { + verifyAttr: any; +} + +export default class VerifyContact extends AuthPiece< + IAuthPieceProps, + IVerifyContactState +> { + constructor(props: IAuthPieceProps) { super(props); this._validAuthStates = ['verifyContact']; diff --git a/packages/aws-amplify-react/src/Auth/common/constants.js b/packages/aws-amplify-react/src/Auth/common/constants.tsx similarity index 100% rename from packages/aws-amplify-react/src/Auth/common/constants.js rename to packages/aws-amplify-react/src/Auth/common/constants.tsx diff --git a/packages/aws-amplify-react/src/Auth/common/country-dial-codes.js b/packages/aws-amplify-react/src/Auth/common/country-dial-codes.tsx similarity index 100% rename from packages/aws-amplify-react/src/Auth/common/country-dial-codes.js rename to packages/aws-amplify-react/src/Auth/common/country-dial-codes.tsx diff --git a/packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.js b/packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.tsx similarity index 80% rename from packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.js rename to packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.tsx index 1aa92035c22..4e96e619d90 100644 --- a/packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.js +++ b/packages/aws-amplify-react/src/Auth/common/default-sign-up-fields.tsx @@ -1,3 +1,14 @@ +export interface ISignUpField { + label: string; + key: string; + placeholder: string; + required: boolean; + displayOrder: number; + invalid?: boolean; + custom?: boolean; + type?: string; +} + export default [ { label: 'Username', @@ -31,7 +42,7 @@ export default [ }, ]; -export const signUpWithEmailFields = [ +export const signUpWithEmailFields: ISignUpField[] = [ { label: 'Email', key: 'email', @@ -57,7 +68,7 @@ export const signUpWithEmailFields = [ }, ]; -export const signUpWithPhoneNumberFields = [ +export const signUpWithPhoneNumberFields: ISignUpField[] = [ { label: 'Phone Number', key: 'phone_number', diff --git a/packages/aws-amplify-react/src/Auth/index.jsx b/packages/aws-amplify-react/src/Auth/index.tsx similarity index 96% rename from packages/aws-amplify-react/src/Auth/index.jsx rename to packages/aws-amplify-react/src/Auth/index.tsx index 47268427178..9728466b864 100644 --- a/packages/aws-amplify-react/src/Auth/index.jsx +++ b/packages/aws-amplify-react/src/Auth/index.tsx @@ -46,7 +46,9 @@ export function withAuthenticator( theme = null, signUpConfig = {} ) { - return class extends Component { + return class extends Component { + public authConfig: any; + constructor(props) { super(props); @@ -143,7 +145,8 @@ export class AuthenticatorWrapper extends Component { return (
- {this.props.children(this.state.auth)} + {// @ts-ignore + this.props.children(this.state.auth)}
); } diff --git a/packages/aws-amplify-react/src/Interactions/ChatBot.jsx b/packages/aws-amplify-react/src/Interactions/ChatBot.tsx similarity index 92% rename from packages/aws-amplify-react/src/Interactions/ChatBot.jsx rename to packages/aws-amplify-react/src/Interactions/ChatBot.tsx index 82c619bc08a..1c311ef7afb 100644 --- a/packages/aws-amplify-react/src/Interactions/ChatBot.jsx +++ b/packages/aws-amplify-react/src/Interactions/ChatBot.tsx @@ -16,7 +16,8 @@ import { ConsoleLogger as Logger } from '@aws-amplify/core'; const logger = new Logger('ChatBot'); -const styles = { +// @ts-ignore +const styles: { [pname: string]: React.CSSProperties } = { itemMe: { padding: 10, fontSize: 12, @@ -36,10 +37,12 @@ const styles = { display: 'inline-block', width: 'calc(100% - 90px - 15px)', }), + // @ts-ignore button: Object.assign({}, Button, { width: '60px', float: 'right', }), + // @ts-ignore mic: Object.assign({}, Button, { width: '40px', float: 'right', @@ -62,12 +65,45 @@ const defaultVoiceConfig = { let audioControl; -export class ChatBot extends Component { +export interface IChatBotProps { + botName?: string; + clearOnComplete?: boolean; + conversationModeOn?: boolean; + onComplete: any; + textEnabled?: boolean; + theme?: any; + title?: string; + voiceConfig?: any; + voiceEnabled?: boolean; + welcomeMessage?: string; +} + +export interface IChatBotDialog { + message: string; + from: string; +} + +export interface IChatBotState { + audioInput?: any; + continueConversation: boolean; + currentVoiceState: any; + dialog: IChatBotDialog[]; + inputDisabled: boolean; + inputText: string; + lexResponse?: any; + micButtonDisabled: boolean; + micText: string; +} + +export class ChatBot extends Component { + private listItemsRef: any; + constructor(props) { super(props); if (this.props.voiceEnabled) { - require('./aws-lex-audio.js'); + require('./aws-lex-audio'); + // @ts-ignore audioControl = new global.LexAudio.audioControl(); } if (!this.props.textEnabled && this.props.voiceEnabled) { @@ -106,6 +142,7 @@ export class ChatBot extends Component { this.changeInputText = this.changeInputText.bind(this); this.listItems = this.listItems.bind(this); this.submit = this.submit.bind(this); + // @ts-ignore this.listItemsRef = React.createRef(); this.onSilenceHandler = this.onSilenceHandler.bind(this); this.doneSpeakingHandler = this.doneSpeakingHandler.bind(this); @@ -184,7 +221,9 @@ export class ChatBot extends Component { micButtonDisabled: true, dialog: [ ...this.state.dialog, + // @ts-ignore { message: response.inputTranscript, from: 'me' }, + // @ts-ignore response && { from: 'bot', message: response.message }, ], inputText: '', @@ -314,6 +353,7 @@ export class ChatBot extends Component { ); this.setState({ + // @ts-ignore dialog: [ ...this.state.dialog, response && { from: 'bot', message: response.message }, @@ -355,6 +395,7 @@ export class ChatBot extends Component { 'No Interactions module found, please ensure @aws-amplify/interactions is imported' ); } + // @ts-ignore Interactions.onComplete(botName, this.getOnComplete(onComplete, this)); } } @@ -368,6 +409,7 @@ export class ChatBot extends Component { 'No Interactions module found, please ensure @aws-amplify/interactions is imported' ); } + // @ts-ignore Interactions.onComplete(botName, this.getOnComplete(onComplete, this)); } } @@ -467,7 +509,7 @@ function ChatBotInputs(props) { const textEnabled = props.textEnabled; const styles = props.styles; const onChange = props.onChange; - const inputDisabled = props.inputDisabled; + let inputDisabled = props.inputDisabled; const micButtonDisabled = props.micButtonDisabled; const inputText = props.inputText; const onSubmit = props.onSubmit; @@ -517,6 +559,7 @@ function ChatBotInputs(props) { ); } +// @ts-ignore ChatBot.defaultProps = { title: '', botName: '', diff --git a/packages/aws-amplify-react/src/Interactions/aws-lex-audio.js b/packages/aws-amplify-react/src/Interactions/aws-lex-audio.tsx similarity index 99% rename from packages/aws-amplify-react/src/Interactions/aws-lex-audio.js rename to packages/aws-amplify-react/src/Interactions/aws-lex-audio.tsx index 42740dcaff5..dfdb5209501 100644 --- a/packages/aws-amplify-react/src/Interactions/aws-lex-audio.js +++ b/packages/aws-amplify-react/src/Interactions/aws-lex-audio.tsx @@ -12,6 +12,7 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// @ts-ignore (function e(t, n, r) { function s(o, u) { if (!n[o]) { @@ -281,6 +282,7 @@ }; if (this.checkAudioSupport) { + // @ts-ignore supportsAudio(); } @@ -358,15 +360,18 @@ this.onError('A Bot name must be provided.'); return; } + // @ts-ignore if (!AWS.config.credentials) { this.onError('AWS Credentials must be provided.'); return; } + // @ts-ignore if (!AWS.config.region) { this.onError('A Region value must be provided.'); return; } + // @ts-ignore lexruntime = new AWS.LexRuntime(); this.onSilence = function() { @@ -585,6 +590,7 @@ wcache[key] = key; } sources[wkey] = [ + // @ts-ignore Function(['require', 'module', 'exports'], '(' + fn + ')(self)'), wcache, ]; @@ -594,6 +600,7 @@ var scache = {}; scache[wkey] = wkey; sources[skey] = [ + // @ts-ignore Function( ['require'], // try to call default if defined to also support babel esmodule @@ -639,6 +646,8 @@ '},{},[' + stringify(skey) + '])'; + + // @ts-ignore var URL = window.URL || window.webkitURL || window.mozURL || window.msURL; @@ -648,6 +657,7 @@ } var workerUrl = URL.createObjectURL(blob); var worker = new Worker(workerUrl); + // @ts-ignore worker.objectURL = workerUrl; return worker; }; @@ -819,6 +829,7 @@ */ var requestDevice = function() { if (typeof audio_context === 'undefined') { + // @ts-ignore window.AudioContext = window.AudioContext || window.webkitAudioContext; audio_context = new AudioContext(); @@ -896,6 +907,7 @@ var audioBlob = new Blob([encodedWav], { type: 'application/octet-stream', }); + // @ts-ignore postMessage(audioBlob); } diff --git a/packages/aws-amplify-react/src/Interactions/index.jsx b/packages/aws-amplify-react/src/Interactions/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/Interactions/index.jsx rename to packages/aws-amplify-react/src/Interactions/index.tsx diff --git a/packages/aws-amplify-react/src/Storage/Common.js b/packages/aws-amplify-react/src/Storage/Common.tsx similarity index 100% rename from packages/aws-amplify-react/src/Storage/Common.js rename to packages/aws-amplify-react/src/Storage/Common.tsx diff --git a/packages/aws-amplify-react/src/Storage/S3Album.js b/packages/aws-amplify-react/src/Storage/S3Album.tsx similarity index 92% rename from packages/aws-amplify-react/src/Storage/S3Album.js rename to packages/aws-amplify-react/src/Storage/S3Album.tsx index 379adc83c0b..fa1430fd6d2 100644 --- a/packages/aws-amplify-react/src/Storage/S3Album.js +++ b/packages/aws-amplify-react/src/Storage/S3Album.tsx @@ -24,7 +24,35 @@ import S3Text from './S3Text'; const logger = new Logger('Storage.S3Album'); -export default class S3Album extends Component { +export interface IS3AlbumProps { + contentType?: any; + fileToKey?: any; + filter?: any; + identityId: any; + level?: any; + onClickItem?: any; + onError?: any; + onLoad?: any; + onPick?: any; + onSelect?: any; + track?: any; + path: any; + picker: any; + pickerTitle?: string; + select?: any; + sort?: any; + theme?: any; + translateItem?: any; + ts?: any; +} + +export interface IS3AlbumState { + items: any; + theme?: any; + ts: any; +} + +export default class S3Album extends Component { _isMounted = false; constructor(props) { super(props); @@ -218,6 +246,7 @@ export default class S3Album extends Component { return sort(list); } + // @ts-ignore if (['string', 'undefined'].includes(typeof_sort)) { const sort_str = sort ? sort : 'lastModified'; const parts = sort_str.split(/\s+/); diff --git a/packages/aws-amplify-react/src/Storage/S3Image.js b/packages/aws-amplify-react/src/Storage/S3Image.tsx similarity index 89% rename from packages/aws-amplify-react/src/Storage/S3Image.js rename to packages/aws-amplify-react/src/Storage/S3Image.tsx index 1f5e999bf36..0cec7b78244 100644 --- a/packages/aws-amplify-react/src/Storage/S3Image.js +++ b/packages/aws-amplify-react/src/Storage/S3Image.tsx @@ -24,7 +24,34 @@ import { calcKey } from './Common'; const logger = new Logger('Storage.S3Image'); -export default class S3Image extends Component { +export interface IS3ImageProps { + body?: any; + contentType?: any; + fileToKey?: any; + hidden?: any; + identityId?: any; + imgKey?: any; + level?: any; + onClick?: any; + onError?: any; + onLoad?: any; + path?: any; + picker?: any; + selected?: any; + src?: any; + style?: any; + theme?: any; + track?: any; + translate?: + | string + | ((params: { type: string; key: string; content: string }) => string); +} + +export interface IS3ImageState { + src; +} + +export default class S3Image extends Component { _isMounted = false; constructor(props) { super(props); @@ -168,7 +195,7 @@ export default class S3Image extends Component { } const { selected } = this.props; - const containerStyle = { position: 'relative' }; + const containerStyle: React.CSSProperties = { position: 'relative' }; return (
string); + hidden?: any; + identityId?: any; + level?: string; + onClick?: any; + onError?: any; + onLoad?: any; + path?: any; + picker?: any; + selected?: any; + style?: any; + theme?: any; + text?: string; + textKey?: string; + track?: any; + translate?: + | string + | ((params: { type: string; key: string; content: string }) => string); +} + +export interface IS3TextState { + text: string; + textKey: string; +} + +export default class S3Text extends Component { _isMounted = false; constructor(props) { super(props); @@ -54,6 +84,7 @@ export default class S3Text extends Component { }) .then(data => { logger.debug(data); + // @ts-ignore const text = data.Body.toString('utf8'); if (this._isMounted) { this.setState({ text }); @@ -177,7 +208,7 @@ export default class S3Text extends Component { } const { selected } = this.props; - const containerStyle = { position: 'relative' }; + const containerStyle: React.CSSProperties = { position: 'relative' }; return (
{text}
diff --git a/packages/aws-amplify-react/src/Storage/index.js b/packages/aws-amplify-react/src/Storage/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/Storage/index.js rename to packages/aws-amplify-react/src/Storage/index.tsx diff --git a/packages/aws-amplify-react/src/Widget/PhotoPicker.js b/packages/aws-amplify-react/src/Widget/PhotoPicker.tsx similarity index 87% rename from packages/aws-amplify-react/src/Widget/PhotoPicker.js rename to packages/aws-amplify-react/src/Widget/PhotoPicker.tsx index b4c07dfc5e9..266d2f0e84f 100644 --- a/packages/aws-amplify-react/src/Widget/PhotoPicker.js +++ b/packages/aws-amplify-react/src/Widget/PhotoPicker.tsx @@ -30,7 +30,25 @@ const PickerPreview = { const logger = new Logger('PhotoPicker'); -export default class PhotoPicker extends Component { +export interface IPhotoPickerProps { + headerHint?: string; + headerText?: string; + onLoad?: (dataUrl: any) => void; + onPick?: (data: any) => void; + preview?: 'hidden'; + previewSrc?: string; + title?: string; + theme?: any; +} + +export interface IPhotoPickerState { + previewSrc?: string; +} + +export default class PhotoPicker extends Component< + IPhotoPickerProps, + IPhotoPickerState +> { constructor(props) { super(props); diff --git a/packages/aws-amplify-react/src/Widget/Picker.js b/packages/aws-amplify-react/src/Widget/Picker.tsx similarity index 91% rename from packages/aws-amplify-react/src/Widget/Picker.js rename to packages/aws-amplify-react/src/Widget/Picker.tsx index 36959ad8bfd..4aeba32639d 100644 --- a/packages/aws-amplify-react/src/Widget/Picker.js +++ b/packages/aws-amplify-react/src/Widget/Picker.tsx @@ -31,7 +31,14 @@ const PickerInput = { const logger = new Logger('Picker'); -export default class Picker extends Component { +export interface IPickerProps { + accept?: string; + onPick?: (data: any) => void; + title?: string; + theme?: any; +} + +export default class Picker extends Component { handleInput(e) { const that = this; diff --git a/packages/aws-amplify-react/src/Widget/SelectMFAType.jsx b/packages/aws-amplify-react/src/Widget/SelectMFAType.tsx similarity index 90% rename from packages/aws-amplify-react/src/Widget/SelectMFAType.jsx rename to packages/aws-amplify-react/src/Widget/SelectMFAType.tsx index 1894f74f91f..af180531918 100644 --- a/packages/aws-amplify-react/src/Widget/SelectMFAType.jsx +++ b/packages/aws-amplify-react/src/Widget/SelectMFAType.tsx @@ -31,7 +31,30 @@ import TOTPSetupComp from './TOTPSetupComp'; const logger = new Logger('SelectMFAType'); -export default class SelectMFAType extends Component { +export interface IMFATypes { + SMS: boolean; + TOTP: boolean; + Optional: boolean; +} + +export interface ISelectMFATypeProps { + authData; + MFATypes: IMFATypes; + theme?: any; +} + +export interface ISelectMFATypeState { + selectMessage: string | null; + showToast?: boolean; + TOTPSetup: boolean; +} + +export default class SelectMFAType extends Component< + ISelectMFATypeProps, + ISelectMFATypeState +> { + public inputs: any; + constructor(props) { super(props); @@ -52,6 +75,7 @@ export default class SelectMFAType extends Component { }); this.inputs = {}; const { name, value, type, checked } = evt.target; + // @ts-ignore const check_type = ['radio', 'checkbox'].includes(type); this.inputs[value] = check_type ? checked : value; } @@ -177,7 +201,7 @@ export default class SelectMFAType extends Component { } render() { - const theme = this.props.theme ? theme : AmplifyTheme; + const theme = this.props.theme ? this.props.theme : AmplifyTheme; return (
{this.selectView(theme)} diff --git a/packages/aws-amplify-react/src/Widget/TOTPSetupComp.jsx b/packages/aws-amplify-react/src/Widget/TOTPSetupComp.tsx similarity index 92% rename from packages/aws-amplify-react/src/Widget/TOTPSetupComp.jsx rename to packages/aws-amplify-react/src/Widget/TOTPSetupComp.tsx index b4ccf6688fe..4728413cdf5 100644 --- a/packages/aws-amplify-react/src/Widget/TOTPSetupComp.jsx +++ b/packages/aws-amplify-react/src/Widget/TOTPSetupComp.tsx @@ -34,7 +34,23 @@ const QRCode = require('qrcode.react'); const logger = new Logger('TOTPSetupComp'); -export default class TOTPSetupComp extends Component { +export interface ITOTPSetupCompProps { + authData?: any; + onTOTPEvent?: (event: any, data: any, user: any) => void; + theme?: any; +} + +export interface ITOTPSetupCompState { + code: string | null; + setupMessage: string | null; +} + +export default class TOTPSetupComp extends Component< + ITOTPSetupCompProps, + ITOTPSetupCompState +> { + public inputs: any; + constructor(props) { super(props); @@ -64,6 +80,7 @@ export default class TOTPSetupComp extends Component { this.setState({ setupMessage: null }); this.inputs = {}; const { name, value, type, checked } = evt.target; + // @ts-ignore const check_type = ['radio', 'checkbox'].includes(type); this.inputs[name] = check_type ? checked : value; } diff --git a/packages/aws-amplify-react/src/Widget/TextPicker.js b/packages/aws-amplify-react/src/Widget/TextPicker.tsx similarity index 86% rename from packages/aws-amplify-react/src/Widget/TextPicker.js rename to packages/aws-amplify-react/src/Widget/TextPicker.tsx index 13e39c4a98f..54b30af2866 100644 --- a/packages/aws-amplify-react/src/Widget/TextPicker.js +++ b/packages/aws-amplify-react/src/Widget/TextPicker.tsx @@ -26,7 +26,23 @@ const PickerPreview = { const logger = new Logger('TextPicker'); -export default class TextPicker extends Component { +export interface ITextPickerProps { + onLoad?: (dataUrl: any) => void; + onPick?: (data: any) => void; + preview?: 'hidden'; + previewText?: string; + theme?: any; + title?: string; +} + +export interface ITextPickerState { + previewText: string; +} + +export default class TextPicker extends Component< + ITextPickerProps, + ITextPickerState +> { constructor(props) { super(props); diff --git a/packages/aws-amplify-react/src/Widget/index.js b/packages/aws-amplify-react/src/Widget/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/Widget/index.js rename to packages/aws-amplify-react/src/Widget/index.tsx diff --git a/packages/aws-amplify-react/src/XR/IconButton.jsx b/packages/aws-amplify-react/src/XR/IconButton.tsx similarity index 100% rename from packages/aws-amplify-react/src/XR/IconButton.jsx rename to packages/aws-amplify-react/src/XR/IconButton.tsx diff --git a/packages/aws-amplify-react/src/XR/Loading.jsx b/packages/aws-amplify-react/src/XR/Loading.tsx similarity index 100% rename from packages/aws-amplify-react/src/XR/Loading.jsx rename to packages/aws-amplify-react/src/XR/Loading.tsx diff --git a/packages/aws-amplify-react/src/XR/SumerianScene.jsx b/packages/aws-amplify-react/src/XR/SumerianScene.tsx similarity index 94% rename from packages/aws-amplify-react/src/XR/SumerianScene.jsx rename to packages/aws-amplify-react/src/XR/SumerianScene.tsx index 92dc164470d..f766881fda9 100644 --- a/packages/aws-amplify-react/src/XR/SumerianScene.jsx +++ b/packages/aws-amplify-react/src/XR/SumerianScene.tsx @@ -24,7 +24,24 @@ const SCENE_DOM_ID = 'scene-dom-id'; const logger = new Logger('SumerianScene'); -class SumerianScene extends React.Component { +interface ISumerianSceneProps { + sceneName: string; +} + +interface ISumerianSceneState { + showEnableAudio: boolean; + muted: boolean; + loading: boolean; + percentage: number; + isFullscreen: boolean; + sceneError: any; + isVRPresentationActive: boolean; +} + +class SumerianScene extends React.Component< + ISumerianSceneProps, + ISumerianSceneState +> { constructor(props) { super(props); @@ -138,7 +155,7 @@ class SumerianScene extends React.Component { async maximize() { const sceneDomElement = document.getElementById(SCENE_CONTAINER_DOM_ID); - await sceneDomElement.requestFullScreen(); + await sceneDomElement.requestFullscreen(); } async minimize() { diff --git a/packages/aws-amplify-react/src/XR/Tooltip.jsx b/packages/aws-amplify-react/src/XR/Tooltip.tsx similarity index 100% rename from packages/aws-amplify-react/src/XR/Tooltip.jsx rename to packages/aws-amplify-react/src/XR/Tooltip.tsx diff --git a/packages/aws-amplify-react/src/XR/index.jsx b/packages/aws-amplify-react/src/XR/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/XR/index.jsx rename to packages/aws-amplify-react/src/XR/index.tsx diff --git a/packages/aws-amplify-react/src/browser.d.ts b/packages/aws-amplify-react/src/browser.d.ts new file mode 100644 index 00000000000..46701382710 --- /dev/null +++ b/packages/aws-amplify-react/src/browser.d.ts @@ -0,0 +1,17 @@ +declare interface Document { + exitFullscreen: () => void; + mozCancelFullScreen: () => void; + webkitExitFullscreen: () => void; + fullscreenElement: () => void; + mozFullScreenElement: () => void; + webkitFullscreenElement: () => void; +} + +declare interface Window { + amazon: any; + auth0: any; + auth0_client: any; + FB: any; + fbAsyncInit: any; + gapi: any; +} diff --git a/packages/aws-amplify-react/src/index.jsx b/packages/aws-amplify-react/src/index.tsx similarity index 100% rename from packages/aws-amplify-react/src/index.jsx rename to packages/aws-amplify-react/src/index.tsx diff --git a/packages/aws-amplify-react/tsconfig.json b/packages/aws-amplify-react/tsconfig.json index 957a9f4a2c9..ac4da1add73 100644 --- a/packages/aws-amplify-react/tsconfig.json +++ b/packages/aws-amplify-react/tsconfig.json @@ -1,67 +1,65 @@ { - "compilerOptions": { - /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": [ - "es5", - "es2015", - "dom", - "esnext.asynciterable", - "es2017.object" - ], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - /* Strict Type-Checking Options */ - "strict": false, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - /* Module Resolution Options */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - "typeRoots": [ - "./node_modules/@types", - "../../node_modules/@types" - ], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - // "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - /* Source Map Options */ - // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - "skipLibCheck": true - }, - "include": [ - "src/**/*" - ] - } \ No newline at end of file + "compilerOptions": { + /* Basic Options */ + "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, + "lib": [ + "es5", + "es2015", + "dom", + "esnext.asynciterable", + "es2017.object" + ] /* Specify library files to be included in the compilation. */, + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + "jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */, + "declaration": true /* Generates corresponding '.d.ts' file. */, + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true /* Generates corresponding '.map' file. */, + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": false /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */, + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": [ + "./node_modules/@types", + "../../node_modules/@types" + ] /* List of folders to include type definitions from. */, + // "types": [], /* Type declaration files to be included in compilation. */ + "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */, + // "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + "skipLibCheck": true + }, + "include": ["src/**/*"] +}