Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 390a188

Browse files
Updated bootstrapper to resolve required legal entity context (#461)
* Updated bootstrapper to resolve required legal entity context * Removed console log
1 parent ff3a083 commit 390a188

File tree

3 files changed

+53
-48
lines changed

3 files changed

+53
-48
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@angular/platform-browser": "4.3.6",
4343
"@angular/platform-browser-dynamic": "4.3.6",
4444
"@angular/router": "4.3.6",
45-
"@blackbaud/auth-client": "2.7.0",
45+
"@blackbaud/auth-client": "2.8.0",
4646
"@blackbaud/skyux-lib-help": "1.3.0",
4747
"@blackbaud/skyux-logger": "1.0.2",
4848
"@ngtools/webpack": "1.3.1",

runtime/bootstrapper.spec.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('bootstrapper', () => {
1515
function validateContextProvided(testEnvId: string, testUrl: string, expectedUrl: string) {
1616
let contextPromiseResolve: any;
1717

18-
const contextPromise = new Promise((resolve, reject) => {
18+
const contextPromise = new Promise((resolve) => {
1919
contextPromiseResolve = resolve;
2020
});
2121

@@ -33,18 +33,23 @@ describe('bootstrapper', () => {
3333
};
3434

3535
SkyAppBootstrapper.processBootstrapConfig().then(() => {
36-
expect(historyReplaceStateSpy).toHaveBeenCalledWith(
37-
{},
38-
'',
39-
expectedUrl
40-
);
36+
if (testUrl === expectedUrl) {
37+
expect(historyReplaceStateSpy).not.toHaveBeenCalled();
38+
} else {
39+
expect(historyReplaceStateSpy).toHaveBeenCalledWith(
40+
{},
41+
'',
42+
expectedUrl
43+
);
44+
}
4145

4246
resolve();
4347
});
4448

4549
contextPromiseResolve({
4650
envId: testEnvId,
47-
svcId: 'abc'
51+
svcId: 'abc',
52+
url: 'https://example.com?envid=123'
4853
});
4954
});
5055
}
@@ -92,16 +97,15 @@ describe('bootstrapper', () => {
9297
'https://example.com',
9398
'https://example.com?envid=123'
9499
)
95-
.then(() => validateContextProvided(
96-
'12&3',
97-
'https://example.com#test',
98-
'https://example.com?envid=12%263#test'
99-
))
100-
.then(() => validateContextProvided(
100+
.then(done);
101+
});
102+
103+
it('should not replace state when the resolved URL matches the current URL', (done) => {
104+
validateContextProvided(
101105
'123',
102-
'https://example.com?svcid=abc',
103-
'https://example.com?svcid=abc&envid=123'
104-
))
106+
'https://example.com?envid=123',
107+
'https://example.com?envid=123'
108+
)
105109
.then(done);
106110
});
107111

runtime/bootstrapper.ts

+32-31
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
//#region imports
2+
13
import {
24
BBAuth,
5+
BBContextArgs,
36
BBContextProvider
47
} from '@blackbaud/auth-client';
58

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';
1212

13-
urlAndFragment[0] += urlAndFragment[0].indexOf('?') >= 0 ? '&' : '?';
14-
urlAndFragment[0] += `${name}=${encodeURIComponent(value)}`;
13+
import {
14+
SkyAppRuntimeConfigParams
15+
} from './params';
1516

16-
return urlAndFragment.join('#');
17-
}
17+
//#endregion
1818

1919
export class SkyAppBootstrapper {
2020

@@ -23,35 +23,36 @@ export class SkyAppBootstrapper {
2323
public static processBootstrapConfig(): Promise<any> {
2424
if (SkyAppBootstrapper.config && SkyAppBootstrapper.config.auth) {
2525
return BBAuth.getToken()
26-
.then((token) => {
27-
const url = this.getUrl();
26+
.then(() => {
27+
const currentUrl = this.getUrl();
2828

2929
const params = new SkyAppRuntimeConfigParams(
30-
url,
30+
currentUrl,
3131
this.config.params
3232
);
3333

34-
const currentEnvId = params.get('envid');
35-
36-
return BBContextProvider.ensureContext({
37-
envId: currentEnvId,
34+
const ensureContextArgs: BBContextArgs = {
35+
envId: params.get('envid'),
3836
envIdRequired: params.isRequired('envid'),
37+
leId: params.get('leid'),
38+
leIdRequired: params.isRequired('leid'),
3939
svcId: params.get('svcid'),
4040
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+
});
5556
});
5657
} else {
5758
return Promise.resolve();

0 commit comments

Comments
 (0)