Skip to content

Commit 93bb3f4

Browse files
committed
Convert aws-amplify-vue to Typescript
1 parent 9a1055a commit 93bb3f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2069
-1557
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
"pre-commit": "pretty-quick --staged"
2727
}
2828
},
29-
"workspaces": [
30-
"packages/*"
31-
],
29+
"workspaces": {
30+
"packages": ["packages/*"],
31+
"nohoist": ["**/@vue/**"]
32+
},
3233
"repository": {
3334
"type": "git",
3435
"url": "https://github.com/aws-amplify/amplify-js.git"

packages/amazon-cognito-identity-js/index.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ declare module 'amazon-cognito-identity-js' {
5757
Storage?: ICognitoStorage;
5858
}
5959

60+
export type CognitoSigninChallenge = 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA';
61+
export type CognitoChallenge =
62+
| CognitoSigninChallenge
63+
| 'CUSTOM_CHALLENGE'
64+
| 'DEVICE_SRP_AUTH'
65+
| 'MFA_SETUP'
66+
| 'NEW_PASSWORD_REQUIRED'
67+
| 'SELECT_MFA_TYPE'
68+
| 'DEVICE_PASSWORD_VERIFIER';
69+
6070
export class CognitoUser {
71+
challengeName?: CognitoChallenge;
72+
6173
constructor(data: ICognitoUserData);
6274

6375
public setSignInUserSession(
@@ -316,10 +328,10 @@ declare module 'amazon-cognito-identity-js' {
316328
public isValid(): boolean;
317329
}
318330
/*
319-
export class CognitoIdentityServiceProvider {
320-
public config: AWS.CognitoIdentityServiceProvider.Types.ClientConfiguration;
321-
}
322-
*/
331+
export class CognitoIdentityServiceProvider {
332+
public config: AWS.CognitoIdentityServiceProvider.Types.ClientConfiguration;
333+
}
334+
*/
323335
export class CognitoAccessToken {
324336
payload: { [key: string]: any };
325337

packages/api/src/API.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
1111
* and limitations under the License.
1212
*/
13-
import { OperationDefinitionNode, GraphQLError } from 'graphql';
14-
import { print } from 'graphql/language/printer';
15-
import { parse } from 'graphql/language/parser';
13+
import {
14+
OperationDefinitionNode,
15+
OperationTypeNode,
16+
GraphQLError,
17+
parse,
18+
print,
19+
} from 'graphql';
1620
import * as Observable from 'zen-observable';
1721
import { RestClient as RestClass } from './RestClient';
1822
import Amplify, {
@@ -40,8 +44,7 @@ export default class APIClass {
4044
* @private
4145
*/
4246
private _options;
43-
private _api = null;
44-
private _pubSub = Amplify.PubSub;
47+
private _api: RestClass = null;
4548

4649
/**
4750
* Initialize Storage with AWS configuration
@@ -334,7 +337,7 @@ export default class APIClass {
334337
* to get the operation type
335338
* @param operation
336339
*/
337-
getGraphqlOperationType(operation) {
340+
getGraphqlOperationType(operation: string): OperationTypeNode {
338341
const doc = parse(operation);
339342
const {
340343
definitions: [{ operation: operationType }],

packages/auth/src/Auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
CognitoIdToken,
6060
CognitoRefreshToken,
6161
CognitoAccessToken,
62+
CognitoSigninChallenge,
6263
} from 'amazon-cognito-identity-js';
6364

6465
import { parse } from 'url';
@@ -857,7 +858,7 @@ export default class AuthClass {
857858
public confirmSignIn(
858859
user: CognitoUser | any,
859860
code: string,
860-
mfaType?: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA' | null
861+
mfaType?: CognitoSigninChallenge | null
861862
): Promise<CognitoUser | any> {
862863
if (!code) {
863864
return this.rejectAuthError(AuthErrorTypes.EmptyCode);
@@ -1767,7 +1768,7 @@ export default class AuthClass {
17671768
logger.debug('AWS credentials', credentials);
17681769
}
17691770

1770-
/*
1771+
/*
17711772
Prior to the request we do sign the custom state along with the state we set. This check will verify
17721773
if there is a dash indicated when setting custom state from the request. If a dash is contained
17731774
then there is custom state present on the state string.

packages/aws-amplify-vue/__tests__/Authenticator.test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { shallowMount } from '@vue/test-utils'; // eslint-disable-line
33
import Authenticator from '../src/components/authenticator/Authenticator.vue';
44
import AmplifyEventBus from '../src/events/AmplifyEventBus';
55
import * as components from '../src/components';
6-
import * as AmplifyEntry from '../src/Amplify.vue'; //eslint-disable-line
76
import AmplifyPlugin from '../src/plugins/AmplifyPlugin';
87
import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
98
import dependency from '../src/services/getUser';
@@ -12,15 +11,22 @@ Vue.use(AmplifyPlugin, AmplifyMocks);
1211
jest.mock('../src/services/getUser');
1312

1413
describe('Authenticator', () => {
14+
let authenticator;
15+
16+
beforeEach(() => {
17+
authenticator = new Authenticator();
18+
});
19+
1520
it('has a mounted hook', () => {
16-
expect(typeof Authenticator.mounted).toBe('function');
21+
expect(authenticator.$options.mounted.length).toEqual(1);
22+
expect(typeof authenticator.$options.mounted[0]).toBe('function');
1723
});
1824

1925
it('sets the correct default data', () => {
20-
expect(typeof Authenticator.data).toBe('function');
21-
const defaultData = Authenticator.data();
22-
expect(defaultData.user.username).toBe(null);
23-
expect(defaultData.logger).toEqual({});
26+
expect(typeof authenticator.$options.data).toEqual('function');
27+
const defaultData = authenticator.$options.data();
28+
expect(defaultData.user).toBe(null);
29+
expect(defaultData.logger).toEqual(null);
2430
expect(defaultData.displayMap).toEqual({});
2531
expect(defaultData.error).toEqual('');
2632
});
@@ -122,9 +128,9 @@ describe('Authenticator', () => {
122128
});
123129

124130
it('...should set user and options data on localUser event emission', () => {
125-
const testUser = { username: 'IAMEMITTED' };
131+
const testUser = { getUsername: () => 'IAMEMITTED' };
126132
AmplifyEventBus.$emit('localUser', testUser);
127-
expect(wrapper.vm.user.username).toEqual(testUser.username);
133+
expect(wrapper.vm.user.getUsername()).toEqual(testUser.getUsername());
128134
});
129135
});
130136
});

packages/aws-amplify-vue/__tests__/Chatbot.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable */
22
import Vue from 'vue';
3-
import { shallowMount, mount } from '@vue/test-utils';
4-
import * as AmplifyUI from '@aws-amplify/ui';
3+
import { shallowMount } from '@vue/test-utils';
54
import Chatbot from '../src/components/interactions/Chatbot.vue';
65
import AmplifyEventBus from '../src/events/AmplifyEventBus';
76
import AmplifyPlugin from '../src/plugins/AmplifyPlugin';
@@ -11,16 +10,23 @@ import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
1110
Vue.use(AmplifyPlugin, AmplifyMocks);
1211

1312
describe('Chatbot', () => {
13+
let chatbot;
14+
15+
beforeEach(() => {
16+
chatbot = new Chatbot();
17+
});
18+
1419
it('has a mounted hook', () => {
15-
expect(typeof Chatbot.mounted).toBe('function');
20+
expect(chatbot.$options.mounted.length).toEqual(1);
21+
expect(typeof chatbot.$options.mounted[0]).toBe('function');
1622
});
1723

1824
it('sets the correct default data', () => {
19-
expect(typeof Chatbot.data).toBe('function');
20-
const defaultData = Chatbot.data();
25+
expect(typeof chatbot.$options.data).toBe('function');
26+
const defaultData = chatbot.$options.data();
2127
expect(defaultData.inputText).toBe('');
2228
expect(defaultData.messages.length).toEqual(0);
23-
expect(defaultData.logger).toEqual({});
29+
expect(defaultData.logger).toEqual(null);
2430
expect(defaultData.error).toEqual('');
2531
});
2632

packages/aws-amplify-vue/__tests__/ConfirmSignIn.test.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
1111
Vue.use(AmplifyPlugin, AmplifyMocks);
1212

1313
describe('ConfirmSignIn', () => {
14+
let confirmSignIn;
15+
16+
beforeEach(() => {
17+
confirmSignIn = new ConfirmSignIn();
18+
});
19+
1420
it('has a mounted hook', () => {
15-
expect(typeof ConfirmSignIn.mounted).toBe('function');
21+
expect(confirmSignIn.$options.mounted.length).toEqual(1);
22+
expect(typeof confirmSignIn.$options.mounted[0]).toBe('function');
1623
});
1724

1825
it('sets the correct default data', () => {
19-
expect(typeof ConfirmSignIn.data).toBe('function');
20-
const defaultData = ConfirmSignIn.data();
26+
expect(typeof confirmSignIn.$options.data).toBe('function');
27+
const defaultData = confirmSignIn.$options.data();
2128
expect(defaultData.code).toBe('');
22-
expect(defaultData.logger).toEqual({});
29+
expect(defaultData.logger).toEqual(null);
2330
expect(defaultData.error).toEqual('');
2431
});
2532

@@ -33,7 +40,13 @@ describe('ConfirmSignIn', () => {
3340

3441
describe('...when it is mounted without props...', () => {
3542
beforeEach(() => {
36-
wrapper = shallowMount(ConfirmSignIn);
43+
wrapper = shallowMount(ConfirmSignIn, {
44+
propsData: {
45+
confirmSignInConfig: {
46+
user: {}
47+
}
48+
}
49+
});
3750
});
3851

3952
it('...it should use the amplify plugin with passed modules', () => {
@@ -62,7 +75,7 @@ describe('ConfirmSignIn', () => {
6275

6376
it('...have default options', () => {
6477
expect(wrapper.vm.options.header).toEqual('i18n Confirm Sign In');
65-
expect(Object.keys(wrapper.vm.options.user).length).toEqual(0);
78+
expect(wrapper.vm.options.user).toEqual({});
6679
});
6780

6881
it('...should set the error property when a valid user is not received', () => {

packages/aws-amplify-vue/__tests__/ConfirmSignUp.test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
1111
Vue.use(AmplifyPlugin, AmplifyMocks);
1212

1313
describe('ConfirmSignUp', () => {
14+
let confirmSignUp;
15+
16+
beforeEach(() => {
17+
confirmSignUp = new ConfirmSignUp();
18+
});
19+
1420
it('has a mounted hook', () => {
15-
expect(typeof ConfirmSignUp.mounted).toBe('function');
21+
expect(confirmSignUp.$options.mounted.length).toEqual(1);
22+
expect(typeof confirmSignUp.$options.mounted[0]).toBe('function');
1623
});
1724

1825
it('sets the correct default data', () => {
19-
expect(typeof ConfirmSignUp.data).toBe('function');
20-
const defaultData = ConfirmSignUp.data();
26+
expect(typeof confirmSignUp.$options.data).toBe('function');
27+
const defaultData = confirmSignUp.$options.data();
2128
expect(defaultData.code).toBe('');
22-
expect(defaultData.logger).toEqual({});
29+
expect(defaultData.logger).toEqual(null);
2330
expect(defaultData.error).toEqual('');
2431
});
2532

packages/aws-amplify-vue/__tests__/Connect.test.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
99
Vue.use(AmplifyPlugin, AmplifyMocks);
1010

1111
describe('Connect', () => {
12+
let connect;
13+
14+
beforeEach(() => {
15+
connect = new Connect();
16+
});
17+
1218
it('has a beforeMount hook', () => {
13-
expect(typeof Connect.beforeMount).toBe('function');
19+
expect(connect.$options.beforeMount.length).toEqual(2);
20+
expect(typeof connect.$options.beforeMount[0]).toBe('function');
21+
expect(typeof connect.$options.beforeMount[1]).toBe('function');
1422
});
1523

16-
it('has a beforeDestroy book', () => {
17-
expect(typeof Connect.beforeDestroy).toBe('function');
24+
it('has a beforeDestroy hook', () => {
25+
expect(connect.$options.beforeDestroy.length).toEqual(1);
26+
expect(typeof connect.$options.beforeDestroy[0]).toBe('function');
1827
});
1928

2029
it('sets the correct default data', () => {
21-
expect(typeof Connect.data).toBe('function');
22-
const defaultData = Connect.data();
30+
expect(typeof connect.$options.data).toBe('function');
31+
const defaultData = connect.$options.data();
2332
expect(defaultData.data).toEqual({});
24-
expect(defaultData.logger).toEqual({});
33+
expect(defaultData.logger).toEqual(null);
2534
expect(defaultData.errors).toEqual([]);
2635
expect(defaultData.loading).toEqual(false);
2736
expect(defaultData.watchedSubscription).toEqual(null);

packages/aws-amplify-vue/__tests__/ForgotPassword.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import * as AmplifyMocks from '../__mocks__/Amplify.mocks';
1111
Vue.use(AmplifyPlugin, AmplifyMocks);
1212

1313
describe('ForgotPassword', () => {
14-
it('has a mounted hook', () => {
15-
expect(typeof ForgotPassword.mounted).toBe('function');
14+
let forgotPassword;
15+
16+
beforeEach(() => {
17+
forgotPassword = new ForgotPassword();
1618
});
1719

1820
it('sets the correct default data', () => {
19-
expect(typeof ForgotPassword.data).toBe('function');
20-
const defaultData = ForgotPassword.data();
21+
expect(typeof forgotPassword.$options.data).toBe('function');
22+
const defaultData = forgotPassword.$options.data();
2123
expect(defaultData.code).toBe('');
22-
expect(defaultData.logger).toEqual({});
24+
expect(defaultData.logger).toEqual(null);
2325
expect(defaultData.error).toEqual('');
2426
});
2527

packages/aws-amplify-vue/__tests__/PhoneField.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import countries from '../src/assets/countries';
1010
Vue.use(AmplifyPlugin, AmplifyMocks);
1111

1212
describe('PhoneField', () => {
13+
let phoneField;
1314
let wrapper = null;
1415
const mockPhoneNumberChanged = jest.fn();
1516
beforeEach(() => {
17+
phoneField = new PhoneField();
1618
wrapper = shallowMount(PhoneField, {
1719
methods: {
1820
emitPhoneNumberChanged: mockPhoneNumberChanged,
@@ -25,8 +27,8 @@ describe('PhoneField', () => {
2527
});
2628

2729
it('sets the correct default data', () => {
28-
expect(typeof PhoneField.data).toBe('function');
29-
const defaultData = PhoneField.data();
30+
expect(typeof phoneField.$options.data).toBe('function');
31+
const defaultData = phoneField.$options.data();
3032
expect(defaultData.countryCode).toEqual('1');
3133
expect(defaultData.local_phone_number).toEqual('');
3234
expect(defaultData.countries).toEqual(countries);

0 commit comments

Comments
 (0)