Fix some flow errors

This commit is contained in:
SleepWalker 2018-05-03 08:15:09 +03:00
parent 9760eba3af
commit 6e9542f592
15 changed files with 86 additions and 47 deletions

View File

@ -80,7 +80,7 @@
"exports-loader": "^0.6.3", "exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "^1.0.0", "extract-text-webpack-plugin": "^1.0.0",
"file-loader": "^0.11.0", "file-loader": "^0.11.0",
"flow-bin": "0.54.1", "flow-bin": "0.71.0",
"fontgen-loader": "^0.2.1", "fontgen-loader": "^0.2.1",
"html-loader": "^0.4.3", "html-loader": "^0.4.3",
"html-webpack-plugin": "^2.0.0", "html-webpack-plugin": "^2.0.0",

View File

@ -30,7 +30,7 @@ export default class MeasureHeight extends PureComponent<{
}> { }> {
static defaultProps = { static defaultProps = {
shouldMeasure: (prevState: any, newState: any) => prevState !== newState, shouldMeasure: (prevState: any, newState: any) => prevState !== newState,
onMeasure: (height) => {} // eslint-disable-line onMeasure: (height: number) => {} // eslint-disable-line
}; };
el: ?HTMLDivElement; el: ?HTMLDivElement;

View File

@ -1,6 +1,6 @@
// @flow // @flow
import type { OauthData } from 'services/api/oauth';
import { browserHistory } from 'services/history'; import { browserHistory } from 'services/history';
import logger from 'services/logger'; import logger from 'services/logger';
import localStorage from 'services/localStorage'; import localStorage from 'services/localStorage';
import loader from 'services/loader'; import loader from 'services/loader';
@ -316,16 +316,7 @@ const KNOWN_SCOPES = [
* *
* @return {Promise} * @return {Promise}
*/ */
export function oAuthValidate(oauthData: { export function oAuthValidate(oauthData: OauthData) {
clientId: string,
redirectUrl: string,
responseType: string,
description: string,
scope: string,
prompt: 'none' | 'consent' | 'select_account',
loginHint?: string,
state?: string
}) {
// TODO: move to oAuth actions? // TODO: move to oAuth actions?
// test request: /oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session&description=foo // test request: /oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session&description=foo
return wrapInLoader((dispatch) => return wrapInLoader((dispatch) =>
@ -370,23 +361,27 @@ export function oAuthValidate(oauthData: {
export function oAuthComplete(params: {accept?: bool} = {}) { export function oAuthComplete(params: {accept?: bool} = {}) {
return wrapInLoader((dispatch, getState) => return wrapInLoader((dispatch, getState) =>
oauth.complete(getState().auth.oauth, params) oauth.complete(getState().auth.oauth, params)
.then((resp: Object) => { .then((resp) => {
localStorage.removeItem('oauthData'); localStorage.removeItem('oauthData');
if (resp.redirectUri.startsWith('static_page')) { if (resp.redirectUri.startsWith('static_page')) {
resp.code = resp.redirectUri.match(/code=(.+)&/)[1]; const code = (resp.redirectUri.match(/code=(.+)&/) || [])[1];
resp.redirectUri = resp.redirectUri.match(/^(.+)\?/)[1]; const displayCode = resp.redirectUri === 'static_page_with_code';
resp.displayCode = resp.redirectUri === 'static_page_with_code'; resp.redirectUri = (resp.redirectUri.match(/^(.+)\?/) || [])[1];
dispatch(setOAuthCode({ dispatch(setOAuthCode({
success: resp.success, success: resp.success,
code: resp.code, code,
displayCode: resp.displayCode displayCode
})); }));
} }
return resp; return resp;
}, (resp) => { }, (resp: {
acceptRequired: bool,
} | {
unauthorized: bool,
}) => {
if (resp.acceptRequired) { if (resp.acceptRequired) {
dispatch(requirePermissionsAccept()); dispatch(requirePermissionsAccept());
@ -398,7 +393,9 @@ export function oAuthComplete(params: {accept?: bool} = {}) {
); );
} }
function handleOauthParamsValidation(resp = {}) { function handleOauthParamsValidation(resp: {
userMessage?: string,
} | Object = {}) {
dispatchBsod(); dispatchBsod();
localStorage.removeItem('oauthData'); localStorage.removeItem('oauthData');

View File

@ -139,7 +139,7 @@ class LanguageSwitcher extends Component<{
}; };
onFilterKeyPress() { onFilterKeyPress() {
return (event: SyntheticInputEvent<HTMLInputElement>) => { return (event: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (event.key !== 'Enter' || this.state.filter === '') { if (event.key !== 'Enter' || this.state.filter === '') {
return; return;
} }

View File

@ -16,7 +16,7 @@ import type { User } from 'components/user';
class Profile extends Component<{ class Profile extends Component<{
user: User user: User
}> { }> {
UUID: ?HTMLDivElement; UUID: ?HTMLElement;
render() { render() {
const { user } = this.props; const { user } = this.props;
@ -134,11 +134,13 @@ class Profile extends Component<{
} }
} }
setUUID(el: ?HTMLDivElement) { setUUID(el: ?HTMLElement) {
this.UUID = el; this.UUID = el;
} }
} }
export default connect((state) => ({ export default connect(({ user }): {
user: state.user, user: User,
} => ({
user,
}))(Profile); }))(Profile);

View File

@ -112,10 +112,14 @@ export default class Input extends FormInputComponent<{
} }
getValue() { getValue() {
return this.el.value; return this.el || this.el.value;
} }
focus() { focus() {
if (!this.el) {
return;
}
this.el.focus(); this.el.focus();
setTimeout(this.el.focus.bind(this.el), 10); setTimeout(this.el.focus.bind(this.el), 10);
} }

View File

@ -19,6 +19,8 @@ const PrivateRoute = ({account, component: Component, ...rest}: {
)}/> )}/>
); );
export default connect((state) => ({ export default connect((state): {
account: ?Account,
} => ({
account: getActiveAccount(state) account: getActiveAccount(state)
}))(PrivateRoute); }))(PrivateRoute);

View File

@ -99,6 +99,12 @@ function renderPanelTransition(factory) {
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
export default withRouter(connect((state) => ({ export default withRouter(connect((state): {
client: {
id: string,
name: string,
description: string
}
} => ({
client: state.auth.client client: state.auth.client
}))(AuthPage)); }))(AuthPage));

View File

@ -84,4 +84,4 @@ class MultiFactorAuthPage extends Component<{
}; };
} }
export default connect(({user}) => ({user}))(MultiFactorAuthPage); export default connect(({user}): { user: User } => ({user}))(MultiFactorAuthPage);

View File

@ -143,11 +143,11 @@ export default class RulesPage extends Component<{
this.props.history.replace(newPath); this.props.history.replace(newPath);
} }
static getTitleHash(sectionIndex) { static getTitleHash(sectionIndex: number) {
return `rule-${sectionIndex + 1}`; return `rule-${sectionIndex + 1}`;
} }
static getRuleHash(sectionIndex, ruleIndex) { static getRuleHash(sectionIndex: number, ruleIndex: number) {
return `${RulesPage.getTitleHash(sectionIndex)}-${ruleIndex + 1}`; return `${RulesPage.getTitleHash(sectionIndex)}-${ruleIndex + 1}`;
} }
} }

View File

@ -1,5 +1,6 @@
// @flow // @flow
/* eslint camelcase: off */ /* eslint camelcase: off */
import type { Resp } from 'services/request';
import request from 'services/request'; import request from 'services/request';
export type OauthAppResponse = { export type OauthAppResponse = {
@ -17,6 +18,28 @@ export type OauthAppResponse = {
minecraftServerIp?: string, minecraftServerIp?: string,
}; };
type OauthRequestData = {
client_id: string,
redirect_uri: string,
response_type: string,
description: string,
scope: string,
prompt: string,
login_hint?: string,
state?: string,
};
export type OauthData = {
clientId: string,
redirectUrl: string,
responseType: string,
description: string,
scope: string,
prompt: 'none' | 'consent' | 'select_account',
loginHint?: string,
state?: string
};
type FormPayloads = { type FormPayloads = {
name?: string, name?: string,
description?: string, description?: string,
@ -26,14 +49,17 @@ type FormPayloads = {
}; };
export default { export default {
validate(oauthData: Object) { validate(oauthData: OauthData) {
return request.get( return request.get(
'/api/oauth2/v1/validate', '/api/oauth2/v1/validate',
getOAuthRequest(oauthData) getOAuthRequest(oauthData)
).catch(handleOauthParamsValidation); ).catch(handleOauthParamsValidation);
}, },
complete(oauthData: Object, params: Object = {}) { complete(oauthData: OauthData, params: {accept?: bool} = {}): Promise<Resp<{
success: bool,
redirectUri: string,
}>> {
const query = request.buildQuery(getOAuthRequest(oauthData)); const query = request.buildQuery(getOAuthRequest(oauthData));
return request.post( return request.post(
@ -44,7 +70,8 @@ export default {
// user declined permissions // user declined permissions
return { return {
success: false, success: false,
redirectUri: resp.redirectUri redirectUri: resp.redirectUri,
originalResponse: resp.originalResponse,
}; };
} }
@ -64,27 +91,27 @@ export default {
}); });
}, },
create(type: string, formParams: FormPayloads): Promise<{success: bool, data: OauthAppResponse}> { create(type: string, formParams: FormPayloads): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
return request.post(`/api/v1/oauth2/${type}`, formParams); return request.post(`/api/v1/oauth2/${type}`, formParams);
}, },
update(clientId: string, formParams: FormPayloads): Promise<{success: bool, data: OauthAppResponse}> { update(clientId: string, formParams: FormPayloads): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
return request.put(`/api/v1/oauth2/${clientId}`, formParams); return request.put(`/api/v1/oauth2/${clientId}`, formParams);
}, },
getApp(clientId: string): Promise<OauthAppResponse> { getApp(clientId: string): Promise<Resp<OauthAppResponse>> {
return request.get(`/api/v1/oauth2/${clientId}`); return request.get(`/api/v1/oauth2/${clientId}`);
}, },
getAppsByUser(userId: number): Promise<Array<OauthAppResponse>> { getAppsByUser(userId: number): Promise<Resp<Array<OauthAppResponse>>> {
return request.get(`/api/v1/accounts/${userId}/oauth2/clients`); return request.get(`/api/v1/accounts/${userId}/oauth2/clients`);
}, },
reset(clientId: string, regenerateSecret: bool = false): Promise<{success: bool, data: OauthAppResponse}> { reset(clientId: string, regenerateSecret: bool = false): Promise<Resp<{success: bool, data: OauthAppResponse}>> {
return request.post(`/api/v1/oauth2/${clientId}/reset${regenerateSecret ? '?regenerateSecret' : ''}`); return request.post(`/api/v1/oauth2/${clientId}/reset${regenerateSecret ? '?regenerateSecret' : ''}`);
}, },
delete(clientId: string): Promise<{success: bool}> { delete(clientId: string): Promise<Resp<{success: bool}>> {
return request.delete(`/api/v1/oauth2/${clientId}`); return request.delete(`/api/v1/oauth2/${clientId}`);
}, },
}; };
@ -99,7 +126,7 @@ export default {
* *
* @return {object} * @return {object}
*/ */
function getOAuthRequest(oauthData) { function getOAuthRequest(oauthData: OauthData): OauthRequestData {
return { return {
client_id: oauthData.clientId, client_id: oauthData.clientId,
redirect_uri: oauthData.redirectUrl, redirect_uri: oauthData.redirectUrl,

View File

@ -59,6 +59,7 @@ export interface AuthContext {
getState(): Object; getState(): Object;
navigate(route: string): void; navigate(route: string): void;
getRequest(): Request; getRequest(): Request;
prevState: AbstractState;
} }
export default class AuthFlow implements AuthContext { export default class AuthFlow implements AuthContext {

View File

@ -1,10 +1,10 @@
// @flow // @flow
import type { AuthContext } from 'services/authFlow';
import logger from 'services/logger'; import logger from 'services/logger';
import AbstractState from './AbstractState'; import AbstractState from './AbstractState';
import ActivationState from './ActivationState'; import ActivationState from './ActivationState';
import RegisterState from './RegisterState'; import RegisterState from './RegisterState';
import type { AuthContext } from 'services/authFlow';
export default class ResendActivationState extends AbstractState { export default class ResendActivationState extends AbstractState {
enter(context: AuthContext) { enter(context: AuthContext) {

View File

@ -9,8 +9,8 @@ import copyToClipboard from 'copy-to-clipboard';
* @return {Promise<*>} * @return {Promise<*>}
*/ */
export default async function copy(content: string): Promise<void> { export default async function copy(content: string): Promise<void> {
// $FlowFixMe there is no typing for navigator.clipboard
if (navigator.clipboard) { if (navigator.clipboard) {
// $FlowFixMe there is no typing for navigator.clipboard
return navigator.clipboard.writeText(content); return navigator.clipboard.writeText(content);
} }

View File

@ -2829,9 +2829,9 @@ flatten@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
flow-bin@0.54.1: flow-bin@0.71.0:
version "0.54.1" version "0.71.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.54.1.tgz#7101bcccf006dc0652714a8aef0c72078a760510" resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.71.0.tgz#fd1b27a6458c3ebaa5cb811853182ed631918b70"
fontgen-loader@^0.2.1: fontgen-loader@^0.2.1:
version "0.2.1" version "0.2.1"