1
+ //#region imports
2
+
1
3
import {
2
4
BBAuth ,
5
+ BBContextArgs ,
3
6
BBContextProvider
4
7
} from '@blackbaud/auth-client' ;
5
8
6
- import { SkyuxConfig } from './config' ;
7
-
8
- import { SkyAppRuntimeConfigParams } from './params' ;
9
-
10
- function addQSParam ( url : string , name : string , value : string ) : string {
11
- const urlAndFragment = url . split ( '#' ) ;
9
+ import {
10
+ SkyuxConfig
11
+ } from './config' ;
12
12
13
- urlAndFragment [ 0 ] += urlAndFragment [ 0 ] . indexOf ( '?' ) >= 0 ? '&' : '?' ;
14
- urlAndFragment [ 0 ] += `${ name } =${ encodeURIComponent ( value ) } ` ;
13
+ import {
14
+ SkyAppRuntimeConfigParams
15
+ } from './params' ;
15
16
16
- return urlAndFragment . join ( '#' ) ;
17
- }
17
+ //#endregion
18
18
19
19
export class SkyAppBootstrapper {
20
20
@@ -23,35 +23,36 @@ export class SkyAppBootstrapper {
23
23
public static processBootstrapConfig ( ) : Promise < any > {
24
24
if ( SkyAppBootstrapper . config && SkyAppBootstrapper . config . auth ) {
25
25
return BBAuth . getToken ( )
26
- . then ( ( token ) => {
27
- const url = this . getUrl ( ) ;
26
+ . then ( ( ) => {
27
+ const currentUrl = this . getUrl ( ) ;
28
28
29
29
const params = new SkyAppRuntimeConfigParams (
30
- url ,
30
+ currentUrl ,
31
31
this . config . params
32
32
) ;
33
33
34
- const currentEnvId = params . get ( 'envid' ) ;
35
-
36
- return BBContextProvider . ensureContext ( {
37
- envId : currentEnvId ,
34
+ const ensureContextArgs : BBContextArgs = {
35
+ envId : params . get ( 'envid' ) ,
38
36
envIdRequired : params . isRequired ( 'envid' ) ,
37
+ leId : params . get ( 'leid' ) ,
38
+ leIdRequired : params . isRequired ( 'leid' ) ,
39
39
svcId : params . get ( 'svcid' ) ,
40
40
svcIdRequired : params . isRequired ( 'svcid' ) ,
41
- url : url
42
- } ) . then ( ( { envId } ) => {
43
- // The context provider was able to provide an environment ID when none
44
- // was supplied to the app; add it to the URL's query string and continue
45
- // loading the app. Downstream constructors of SkyAppRuntimeConfigParams
46
- // will then pick up the environment ID from the query string.
47
- if ( ! currentEnvId && envId ) {
48
- history . replaceState (
49
- { } ,
50
- '' ,
51
- addQSParam ( url , 'envid' , envId )
52
- ) ;
53
- }
54
- } ) ;
41
+ url : currentUrl
42
+ } ;
43
+
44
+ return BBContextProvider . ensureContext ( ensureContextArgs )
45
+ . then ( ( args ) => {
46
+ // The URL will remain the same if the required context is already present, in which
47
+ // case there's no need to update the URL.
48
+ if ( args . url !== currentUrl ) {
49
+ history . replaceState (
50
+ { } ,
51
+ '' ,
52
+ args . url
53
+ ) ;
54
+ }
55
+ } ) ;
55
56
} ) ;
56
57
} else {
57
58
return Promise . resolve ( ) ;
0 commit comments