#305: fix linting errors after installing flow plugin for eslint.

Improve Authflow#run() typing
This commit is contained in:
SleepWalker 2017-09-09 18:04:26 +03:00
parent d1b19a2285
commit 82744f9300
18 changed files with 105 additions and 33 deletions

View File

@ -284,7 +284,7 @@ export function oAuthValidate(oauthData: {
responseType: string,
description: string,
scope: string,
prompt: 'none'|'consent'|'select_account',
prompt: 'none' | 'consent' | 'select_account',
loginHint?: string,
state?: string
}) {
@ -387,7 +387,7 @@ export function setClient({
}
export function resetOAuth() {
return (dispatch: (Function|Object) => void) => {
return (dispatch: (Function | Object) => void) => {
localStorage.removeItem('oauthData');
dispatch(setOAuthRequest({}));
};
@ -399,7 +399,7 @@ export function resetOAuth() {
* @return {function}
*/
export function resetAuth() {
return (dispatch: (Function|Object) => void) => {
return (dispatch: (Function | Object) => void) => {
dispatch(setLogin(null));
dispatch(resetOAuth());
};
@ -474,7 +474,7 @@ export function setLoadingState(isLoading: bool) {
}
function wrapInLoader(fn) {
return (dispatch: (Function|Object) => void, getState: Object) => {
return (dispatch: (Function | Object) => void, getState: Object) => {
dispatch(setLoadingState(true));
const endLoading = () => dispatch(setLoadingState(false));

View File

@ -1,3 +1,4 @@
// @flow
import { combineReducers } from 'redux';
import {

View File

@ -17,7 +17,7 @@ import type { Form } from 'components/ui/form';
const STEPS_TOTAL = 3;
export type MfaStep = 0|1|2;
export type MfaStep = 0 | 1 | 2;
type Props = {
onChangeStep: Function,
confirmationForm: FormModel,

View File

@ -1,2 +1,3 @@
// @flow
export { default } from './MultiFactorAuth';
export type { MfaStep } from './MfaEnable';

View File

@ -15,10 +15,10 @@ import appleLogo from './images/apple.svg';
import windowsLogo from './images/windows.svg';
export default class Instructions extends Component<{}, {
activeOs: null|'android'|'ios'|'windows'
activeOs: null | 'android' | 'ios' | 'windows'
}> {
state: {
activeOs: null|'android'|'ios'|'windows'
activeOs: null | 'android' | 'ios' | 'windows'
} = {
activeOs: null
};
@ -74,7 +74,7 @@ export default class Instructions extends Component<{}, {
);
}
onChangeOs(event: MouseEvent, osName: 'android'|'ios'|'windows') {
onChangeOs(event: MouseEvent, osName: 'android' | 'ios' | 'windows') {
event.preventDefault();
this.setState({

View File

@ -6,7 +6,7 @@ import { FormattedMessage as Message } from 'react-intl';
import messages from '../MultiFactorAuth.intl.json';
import styles from './instructions.scss';
type OS = 'android'|'ios'|'windows';
type OS = 'android' | 'ios' | 'windows';
const linksByOs: {
[key: OS]: {

View File

@ -8,7 +8,7 @@ import icons from 'components/ui/icons.scss';
import messages from '../MultiFactorAuth.intl.json';
import mfaStyles from '../mfa.scss';
export default function MfaStatus({onProceed} : {
export default function MfaStatus({onProceed}: {
onProceed: Function
}) {
return (

View File

@ -72,7 +72,7 @@ export function PanelFooter(props: {
}
export class PanelBodyHeader extends Component<{
type: 'default'|'error',
type: 'default' | 'error',
onClose: Function,
children: *
}, {

View File

@ -8,7 +8,7 @@ const ABORT_ERR = 20;
export default function BsodMiddleware(dispatchBsod: Function, logger: Logger) {
return {
catch<T: Resp<*>|InternalServerError>(resp?: T): Promise<T> {
catch<T: Resp<*> | InternalServerError>(resp?: T): Promise<T> {
if (resp && (
(resp instanceof InternalServerError
&& resp.error.code !== ABORT_ERR

View File

@ -21,7 +21,7 @@ type State = {
isTouched: bool,
isLoading: bool
};
type InputElement = HTMLInputElement|HTMLTextAreaElement;
type InputElement = HTMLInputElement | HTMLTextAreaElement;
export default class Form extends Component<Props, State> {
static defaultProps = {

View File

@ -1,15 +1,15 @@
// @flow
export type Color = 'green'
|'blue'
|'darkBlue'
|'violet'
|'lightViolet'
|'orange'
|'red'
|'black'
|'white';
| 'blue'
| 'darkBlue'
| 'violet'
| 'lightViolet'
| 'orange'
| 'red'
| 'black'
| 'white';
export type Skin = 'dark'|'light';
export type Skin = 'dark' | 'light';
export const COLOR_GREEN: Color = 'green';
export const COLOR_BLUE: Color = 'blue';

View File

@ -13,7 +13,7 @@ export default function Stepper({
totalSteps,
activeStep,
color = COLOR_GREEN
} : {
}: {
totalSteps: number,
activeStep: number,
color: Color

View File

@ -18,7 +18,7 @@ export default class LoggedInPanel extends Component<{
isAccountSwitcherActive: false
};
_isMounted: boolean = false;
_isMounted: bool = false;
el: ?HTMLElement;
componentDidMount() {
@ -95,7 +95,7 @@ export default class LoggedInPanel extends Component<{
*/
function createOnOutsideComponentClickHandler(
getEl: () => ?HTMLElement,
isActive: () => boolean,
isActive: () => bool,
callback: Function
) {
// TODO: we have the same logic in LangMenu

View File

@ -42,20 +42,32 @@ class MultiFactorAuthPage extends Component<{
}
render() {
const step = (parseInt(this.props.match.params.step, 10) || 1) - 1;
const {user} = this.props;
return (
<MultiFactorAuth
isMfaEnabled={user.isOtpEnabled}
onSubmit={this.onSubmit}
step={step}
step={this.getStep()}
onChangeStep={this.onChangeStep}
onComplete={this.onComplete}
/>
);
}
getStep(): MfaStep {
const step = (parseInt(this.props.match.params.step, 10) || 1) - 1;
if (step !== 0
&& step !== 1
&& step !== 2
) { // NOTE: flow does not understand Array.includes()
return 1;
}
return step;
}
onChangeStep = (step: MfaStep) => {
this.props.history.push(`/profile/mfa/step${step + 1}`);
};

View File

@ -32,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
class RootPage extends Component<{
user: User,
isPopupActive: boolean,
isPopupActive: bool,
onLogoClick: Function,
location: {
pathname: string

View File

@ -19,9 +19,40 @@ type Request = {
query: URLSearchParams,
params: Object
};
// TODO: temporary added to improve typing without major refactoring
type ActionId =
| 'updateUser'
| 'authenticate'
| 'logout'
| 'goBack'
| 'redirect'
| 'login'
| 'acceptRules'
| 'forgotPassword'
| 'recoverPassword'
| 'register'
| 'activate'
| 'resendActivation'
| 'contactUs'
| 'setLogin'
| 'setAccountSwitcher'
| 'setErrors'
| 'clearErrors'
| 'oAuthValidate'
| 'oAuthComplete'
| 'setClient'
| 'resetOAuth'
| 'resetAuth'
| 'setOAuthRequest'
| 'setOAuthCode'
| 'requirePermissionsAccept'
| 'setScopes'
| 'setLoadingState';
export interface AuthContext {
run(actionId: string, payload: *): *;
setState(newState: AbstractState): Promise<*>|void;
run(actionId: ActionId, payload?: ?Object): *;
setState(newState: AbstractState): Promise<*> | void;
getState(): Object;
navigate(route: string): void;
getRequest(): Request;
@ -94,7 +125,7 @@ export default class AuthFlow implements AuthContext {
this.state.goBack(this);
}
run(actionId: string, payload: Object): Promise<*> {
run(actionId: ActionId, payload?: ?Object): Promise<*> {
if (!this.actions[actionId]) {
throw new Error(`Action ${actionId} does not exists`);
}

View File

@ -1,10 +1,37 @@
// @flow
import AuthFlow from './AuthFlow';
export type {AuthContext} from './AuthFlow';
import * as actions from 'components/auth/actions';
const availableActions = {
...actions
updateUser: actions.updateUser,
authenticate: actions.authenticate,
logout: actions.logout,
goBack: actions.goBack,
redirect: actions.redirect,
login: actions.login,
acceptRules: actions.acceptRules,
forgotPassword: actions.forgotPassword,
recoverPassword: actions.recoverPassword,
register: actions.register,
activate: actions.activate,
resendActivation: actions.resendActivation,
contactUs: actions.contactUs,
setLogin: actions.setLogin,
setAccountSwitcher: actions.setAccountSwitcher,
setErrors: actions.setErrors,
clearErrors: actions.clearErrors,
oAuthValidate: actions.oAuthValidate,
oAuthComplete: actions.oAuthComplete,
setClient: actions.setClient,
resetOAuth: actions.resetOAuth,
resetAuth: actions.resetAuth,
setOAuthRequest: actions.setOAuthRequest,
setOAuthCode: actions.setOAuthCode,
requirePermissionsAccept: actions.requirePermissionsAccept,
setScopes: actions.setScopes,
setLoadingState: actions.setLoadingState
};
export default new AuthFlow(availableActions);

View File

@ -1,5 +1,5 @@
// @flow
function InternalServerError(error: Error|string|Object, resp?: Response|Object) {
function InternalServerError(error: Error | string | Object, resp?: Response | Object) {
error = error || {};
this.name = 'InternalServerError';