1- import axios from 'axios' ;
1+ import axios , { AxiosResponse } from 'axios' ;
22import queryString from 'query-string' ;
33
4- import { newHelloRequest } from '../models/hello' ;
4+ import { HelloQuery , newHelloRequest } from '../models/hello' ;
55import { withClientRequestState } from '../utils' ;
66import {
77 ExtendedError ,
@@ -15,35 +15,37 @@ import {
1515import * as types from './types' ;
1616import { receiveHello } from './common' ;
1717import { handleAxiosError } from './utils' ;
18+ import { AppDispatch , PromiseDispatch , RootState } from '../store' ;
19+ import { History } from "history" ;
1820
1921// Modes for logon.
2022export const ModeLogonUsernameEmptyPasswordCookie = '0' ;
2123export const ModeLogonUsernamePassword = '1' ;
2224
23- export function updateInput ( name , value ) {
25+ export function updateInput ( name : string , value ?: string | null ) {
2426 return {
2527 type : types . UPDATE_INPUT ,
2628 name,
2729 value
2830 } ;
2931}
3032
31- export function receiveValidateLogon ( errors ) {
33+ export function receiveValidateLogon ( errors : Error | { [ key : string ] : Error } ) {
3234 return {
3335 type : types . RECEIVE_VALIDATE_LOGON ,
3436 errors
3537 } ;
3638}
3739
38- export function requestLogon ( username , password ) {
40+ export function requestLogon ( username : string , password : string ) {
3941 return {
4042 type : types . REQUEST_LOGON ,
4143 username,
4244 password
4345 } ;
4446}
4547
46- export function receiveLogon ( logon ) {
48+ export function receiveLogon ( logon : { success : boolean , errors : { http : Error } } ) {
4749 const { success, errors } = logon ;
4850
4951 return {
@@ -59,7 +61,7 @@ export function requestConsent(allow=false) {
5961 } ;
6062}
6163
62- export function receiveConsent ( logon ) {
64+ export function receiveConsent ( logon : { success : boolean , errors : { http : Error } } ) {
6365 const { success, errors } = logon ;
6466
6567 return {
@@ -69,8 +71,8 @@ export function receiveConsent(logon) {
6971 } ;
7072}
7173
72- export function executeLogon ( username , password , mode = ModeLogonUsernamePassword ) {
73- return function ( dispatch , getState ) {
74+ export function executeLogon ( username : string , password : string , mode = ModeLogonUsernamePassword ) {
75+ return function ( dispatch : AppDispatch , getState : ( ) => RootState ) {
7476 dispatch ( requestLogon ( username , password ) ) ;
7577 dispatch ( receiveHello ( {
7678 username
@@ -96,7 +98,7 @@ export function executeLogon(username, password, mode=ModeLogonUsernamePassword)
9698
9799 const r = withClientRequestState ( {
98100 params : params ,
99- hello : newHelloRequest ( flow , query )
101+ hello : newHelloRequest ( flow as string , query as HelloQuery )
100102 } ) ;
101103 return axios . post ( './identifier/_/logon' , r , {
102104 headers : {
@@ -118,7 +120,7 @@ export function executeLogon(username, password, mode=ModeLogonUsernamePassword)
118120 } ;
119121 default :
120122 // error.
121- throw new ExtendedError ( ERROR_HTTP_UNEXPECTED_RESPONSE_STATUS , response ) ;
123+ throw new ExtendedError ( ERROR_HTTP_UNEXPECTED_RESPONSE_STATUS , response as AxiosResponse < never > ) ;
122124 }
123125 } ) . then ( response => {
124126 if ( response . state !== r . state ) {
@@ -151,7 +153,7 @@ export function executeLogon(username, password, mode=ModeLogonUsernamePassword)
151153}
152154
153155export function executeConsent ( allow = false , scope = '' ) {
154- return function ( dispatch , getState ) {
156+ return function ( dispatch : AppDispatch , getState : ( ) => RootState ) {
155157 dispatch ( requestConsent ( allow ) ) ;
156158
157159 const { query } = getState ( ) . common ;
@@ -181,7 +183,7 @@ export function executeConsent(allow=false, scope='') {
181183 } ;
182184 default :
183185 // error.
184- throw new ExtendedError ( ERROR_HTTP_UNEXPECTED_RESPONSE_STATUS , response ) ;
186+ throw new ExtendedError ( ERROR_HTTP_UNEXPECTED_RESPONSE_STATUS , response as AxiosResponse < never > ) ;
185187 }
186188 } ) . then ( response => {
187189 if ( response . state !== r . state ) {
@@ -205,10 +207,10 @@ export function executeConsent(allow=false, scope='') {
205207 } ;
206208}
207209
208- export function validateUsernamePassword ( username , password , isSignedIn ) {
209- return function ( dispatch ) {
210+ export function validateUsernamePassword ( username : string , password : string , isSignedIn : boolean ) {
211+ return function ( dispatch : AppDispatch ) {
210212 return new Promise ( ( resolve , reject ) => {
211- const errors = { } ;
213+ const errors : { [ key : string ] : Error } = { } ;
212214
213215 if ( ! username ) {
214216 errors . username = new Error ( ERROR_LOGIN_VALIDATE_MISSINGUSERNAME ) ;
@@ -227,14 +229,14 @@ export function validateUsernamePassword(username, password, isSignedIn) {
227229 } ;
228230}
229231
230- export function executeLogonIfFormValid ( username , password , isSignedIn ) {
231- return ( dispatch ) => {
232+ export function executeLogonIfFormValid ( username : string , password : string , isSignedIn : boolean ) {
233+ return ( dispatch : PromiseDispatch ) => {
232234 return dispatch (
233235 validateUsernamePassword ( username , password , isSignedIn )
234236 ) . then ( ( ) => {
235237 const mode = isSignedIn ? ModeLogonUsernameEmptyPasswordCookie : ModeLogonUsernamePassword ;
236238 return dispatch ( executeLogon ( username , password , mode ) ) ;
237- } ) . catch ( ( errors ) => {
239+ } ) . catch ( ( errors : Error | { [ key : string ] : Error } ) => {
238240 return {
239241 success : false ,
240242 errors : errors
@@ -243,8 +245,9 @@ export function executeLogonIfFormValid(username, password, isSignedIn) {
243245 } ;
244246}
245247
246- export function advanceLogonFlow ( success , history , done = false , extraQuery = { } ) {
247- return ( dispatch , getState ) => {
248+
249+ export function advanceLogonFlow ( success : boolean , history : History , done = false , extraQuery = { } ) {
250+ return ( dispatch :AppDispatch , getState : ( ) => RootState ) => {
248251 if ( ! success ) {
249252 return ;
250253 }
@@ -256,16 +259,16 @@ export function advanceLogonFlow(success, history, done=false, extraQuery={}) {
256259 case 'oauth' :
257260 case 'consent' :
258261 case 'oidc' :
259- if ( hello . details . flow !== flow ) {
262+ if ( hello ? .details ? .flow !== flow ) {
260263 // Ignore requested flow if hello flow does not match.
261264 break ;
262265 }
263266
264- if ( ! done && hello . details . next === 'consent' ) {
267+ if ( ! done && hello ? .details . next === 'consent' ) {
265268 history . replace ( `/consent${ history . location . search } ${ history . location . hash } ` ) ;
266269 return ;
267270 }
268- if ( hello . details . continue_uri ) {
271+ if ( hello ? .details . continue_uri ) {
269272 q . prompt = 'none' ;
270273 window . location . replace ( hello . details . continue_uri + '?' + queryString . stringify ( q ) ) ;
271274 return ;
@@ -276,7 +279,7 @@ export function advanceLogonFlow(success, history, done=false, extraQuery={}) {
276279 default :
277280 // Legacy stupid modes.
278281 if ( q . continue && q . continue . indexOf ( document . location . origin ) === 0 ) {
279- window . location . replace ( q . continue ) ;
282+ window . location . replace ( q . continue as string ) ;
280283 return ;
281284 }
282285 }
0 commit comments