@pega/react-sdk-overrides 0.23.26 → 8.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/lib/designSystemExtension/AlertBanner/AlertBanner.tsx +47 -0
  2. package/lib/designSystemExtension/AlertBanner/index.tsx +1 -0
  3. package/lib/designSystemExtension/Banner/Banner.tsx +12 -1
  4. package/lib/designSystemExtension/CaseSummaryFields/CaseSummaryFields.tsx +15 -10
  5. package/lib/designSystemExtension/DetailsFields/DetailsFields.tsx +10 -11
  6. package/lib/designSystemExtension/FieldGroup/FieldGroup.tsx +10 -3
  7. package/lib/designSystemExtension/FieldGroupList/FieldGroupList.tsx +11 -5
  8. package/lib/designSystemExtension/FieldValueList/FieldValueList.tsx +11 -3
  9. package/lib/designSystemExtension/Operator/Operator.tsx +30 -21
  10. package/lib/designSystemExtension/Pulse/Pulse.tsx +11 -7
  11. package/lib/designSystemExtension/RichTextEditor/RichTextEditor.tsx +121 -0
  12. package/lib/designSystemExtension/RichTextEditor/index.tsx +1 -0
  13. package/lib/designSystemExtension/WssQuickCreate/WssQuickCreate.tsx +12 -3
  14. package/lib/field/AutoComplete/AutoComplete.tsx +37 -18
  15. package/lib/field/CancelAlert/CancelAlert.tsx +21 -12
  16. package/lib/field/Checkbox/Checkbox.tsx +41 -17
  17. package/lib/field/Currency/Currency.tsx +23 -15
  18. package/lib/field/Currency/currency-utils.ts +1 -2
  19. package/lib/field/Date/Date.tsx +31 -17
  20. package/lib/field/DateTime/DateTime.tsx +26 -15
  21. package/lib/field/Decimal/Decimal.tsx +82 -19
  22. package/lib/field/Dropdown/Dropdown.tsx +57 -14
  23. package/lib/field/Email/Email.tsx +17 -9
  24. package/lib/field/Integer/Integer.tsx +15 -7
  25. package/lib/field/Percentage/Percentage.tsx +15 -7
  26. package/lib/field/Phone/Phone.tsx +21 -12
  27. package/lib/field/RadioButtons/RadioButtons.tsx +54 -27
  28. package/lib/field/RichText/RichText.tsx +93 -0
  29. package/lib/field/RichText/index.tsx +1 -0
  30. package/lib/field/ScalarList/ScalarList.tsx +64 -0
  31. package/lib/field/ScalarList/config-ext.json +8 -0
  32. package/lib/field/ScalarList/index.tsx +1 -0
  33. package/lib/field/SemanticLink/SemanticLink.tsx +26 -25
  34. package/lib/field/SemanticLink/utils.ts +2 -1
  35. package/lib/field/TextArea/TextArea.tsx +14 -5
  36. package/lib/field/TextContent/TextContent.tsx +10 -1
  37. package/lib/field/TextInput/TextInput.tsx +40 -11
  38. package/lib/field/Time/Time.tsx +29 -26
  39. package/lib/field/URL/URL.tsx +24 -8
  40. package/lib/field/UserReference/UserReference.tsx +52 -60
  41. package/lib/helpers/{attachmentHelpers.js → attachmentHelpers.ts} +5 -5
  42. package/lib/helpers/auth.js +741 -390
  43. package/lib/helpers/authManager.ts +933 -0
  44. package/lib/helpers/case-utils.tsx +103 -0
  45. package/lib/helpers/common-utils.ts +4 -0
  46. package/lib/helpers/config_access.js +63 -145
  47. package/lib/helpers/data_page.ts +2 -1
  48. package/lib/helpers/date-format-utils.ts +29 -19
  49. package/lib/helpers/{event-utils.js → event-utils.ts} +1 -1
  50. package/lib/helpers/{field-group-utils.js → field-group-utils.ts} +4 -3
  51. package/lib/helpers/formatters/{Currency.js → Currency.ts} +13 -12
  52. package/lib/helpers/formatters/{CurrencyMap.js → CurrencyMap.ts} +8 -5
  53. package/lib/helpers/formatters/{Date.js → Date.ts} +2 -2
  54. package/lib/helpers/formatters/{common.js → common.ts} +4 -4
  55. package/lib/helpers/formatters/{index.js → index.ts} +3 -3
  56. package/lib/helpers/simpleTableHelpers.ts +10 -6
  57. package/lib/helpers/state-utils.tsx +47 -0
  58. package/lib/helpers/template-utils.ts +3 -4
  59. package/lib/helpers/utils.ts +12 -4
  60. package/lib/helpers/versionHelpers.ts +0 -1
  61. package/lib/infra/ActionButtons/ActionButtons.tsx +13 -18
  62. package/lib/infra/Assignment/Assignment.tsx +38 -32
  63. package/lib/infra/AssignmentCard/AssignmentCard.tsx +15 -19
  64. package/lib/infra/Containers/FlowContainer/FlowContainer.tsx +76 -64
  65. package/lib/infra/Containers/FlowContainer/{helpers.js → helpers.ts} +18 -16
  66. package/lib/infra/Containers/ModalViewContainer/ModalViewContainer.tsx +41 -27
  67. package/lib/infra/Containers/ViewContainer/ViewContainer.tsx +19 -28
  68. package/lib/infra/DashboardFilter/DashboardFilter.tsx +16 -20
  69. package/lib/infra/DashboardFilter/filterUtils.tsx +3 -1
  70. package/lib/infra/DeferLoad/DeferLoad.tsx +16 -19
  71. package/lib/infra/ErrorBoundary/ErrorBoundary.tsx +20 -19
  72. package/lib/infra/MultiStep/MultiStep.tsx +24 -24
  73. package/lib/infra/NavBar/NavBar.tsx +23 -24
  74. package/lib/infra/Reference/Reference.tsx +13 -18
  75. package/lib/infra/Region/Region.tsx +8 -6
  76. package/lib/infra/RootContainer/RootContainer.tsx +32 -39
  77. package/lib/infra/Stages/Stages.tsx +15 -9
  78. package/lib/infra/VerticalTabs/LeftAlignVerticalTabs/LeftAlignVerticalTabs.tsx +8 -1
  79. package/lib/infra/VerticalTabs/VerticalTabs/VerticalTabs.tsx +12 -12
  80. package/lib/infra/View/View.tsx +28 -56
  81. package/lib/template/AppShell/AppShell.tsx +51 -34
  82. package/lib/template/BannerPage/BannerPage.tsx +26 -31
  83. package/lib/template/CaseSummary/CaseSummary.tsx +15 -8
  84. package/lib/template/CaseView/CaseView.tsx +137 -100
  85. package/lib/template/CaseViewActionsMenu/CaseViewActionsMenu.tsx +27 -27
  86. package/lib/template/Confirmation/Confirmation.tsx +29 -52
  87. package/lib/template/DataReference/DataReference.tsx +50 -52
  88. package/lib/template/DefaultForm/DefaultForm.tsx +29 -20
  89. package/lib/template/DefaultForm/utils/index.ts +33 -0
  90. package/lib/template/Details/Details/Details.tsx +16 -17
  91. package/lib/template/Details/DetailsSubTabs/DetailsSubTabs.tsx +13 -16
  92. package/lib/template/Details/DetailsThreeColumn/DetailsThreeColumn.tsx +19 -18
  93. package/lib/template/Details/DetailsTwoColumn/DetailsTwoColumn.tsx +20 -18
  94. package/lib/template/FieldGroupTemplate/FieldGroupTemplate.tsx +24 -27
  95. package/lib/template/InlineDashboard/InlineDashboard.tsx +11 -7
  96. package/lib/template/InlineDashboardPage/InlineDashboardPage.tsx +19 -17
  97. package/lib/template/ListPage/ListPage.tsx +14 -13
  98. package/lib/template/ListView/ListView.tsx +140 -152
  99. package/lib/template/ListView/{hooks.js → hooks.ts} +3 -1
  100. package/lib/template/ListView/{utils.js → utils.ts} +172 -23
  101. package/lib/template/MultiReferenceReadOnly/MultiReferenceReadOnly.tsx +12 -17
  102. package/lib/template/NarrowWide/NarrowWide/NarrowWide.tsx +16 -1
  103. package/lib/template/NarrowWide/NarrowWideDetails/NarrowWideDetails.tsx +19 -18
  104. package/lib/template/NarrowWide/NarrowWideForm/NarrowWideForm.tsx +9 -1
  105. package/lib/template/NarrowWide/NarrowWidePage/NarrowWidePage.tsx +17 -17
  106. package/lib/template/OneColumn/OneColumn/OneColumn.tsx +8 -7
  107. package/lib/template/OneColumn/OneColumnPage/OneColumnPage.tsx +10 -10
  108. package/lib/template/OneColumn/OneColumnTab/OneColumnTab.tsx +5 -7
  109. package/lib/template/PromotedFilters/PromotedFilters.tsx +23 -17
  110. package/lib/template/SimpleTable/SimpleTable/SimpleTable.tsx +103 -6
  111. package/lib/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx +28 -7
  112. package/lib/template/SimpleTable/SimpleTableSelect/SimpleTableSelect.tsx +26 -31
  113. package/lib/template/SingleReferenceReadOnly/SingleReferenceReadOnly.tsx +34 -36
  114. package/lib/template/SubTabs/SubTabs.tsx +10 -11
  115. package/lib/template/SubTabs/tabUtils.ts +0 -2
  116. package/lib/template/TwoColumn/TwoColumn/TwoColumn.tsx +10 -15
  117. package/lib/template/TwoColumn/TwoColumnPage/TwoColumnPage.tsx +10 -10
  118. package/lib/template/TwoColumn/TwoColumnTab/TwoColumnTab.tsx +10 -12
  119. package/lib/template/WideNarrow/WideNarrow/WideNarrow.tsx +17 -3
  120. package/lib/template/WideNarrow/WideNarrowDetails/WideNarrowDetails.tsx +35 -25
  121. package/lib/template/WideNarrow/WideNarrowForm/WideNarrowForm.tsx +7 -1
  122. package/lib/template/WideNarrow/WideNarrowPage/WideNarrowPage.tsx +15 -17
  123. package/lib/template/WssNavBar/WssNavBar.tsx +20 -3
  124. package/lib/widget/AppAnnouncement/AppAnnouncement.tsx +13 -21
  125. package/lib/widget/Attachment/Attachment.css +15 -3
  126. package/lib/widget/Attachment/Attachment.tsx +51 -32
  127. package/lib/widget/CaseHistory/CaseHistory.tsx +13 -11
  128. package/lib/widget/FileUtility/ActionButtonsForFileUtil/ActionButtonsForFileUtil.tsx +13 -1
  129. package/lib/widget/FileUtility/FileUtility/FileUtility.tsx +40 -26
  130. package/lib/widget/Followers/Followers.tsx +10 -11
  131. package/lib/widget/QuickCreate/QuickCreate.tsx +15 -6
  132. package/lib/widget/SummaryItem/SummaryItem.tsx +12 -4
  133. package/lib/widget/SummaryList/SummaryList.tsx +17 -3
  134. package/lib/widget/ToDo/ToDo.tsx +69 -104
  135. package/package.json +1 -1
  136. package/lib/helpers/authManager.js +0 -631
  137. /package/lib/helpers/formatters/{Boolean.js → Boolean.ts} +0 -0
  138. /package/lib/helpers/{reactContextHelpers.js → reactContextHelpers.ts} +0 -0
  139. /package/lib/template/ListView/{DefaultViewMeta.js → DefaultViewMeta.ts} +0 -0
@@ -1,631 +0,0 @@
1
- // This file wraps various calls related to logging in, logging out, etc.
2
- // that use the auth.html/auth.js to do the work of logging in via OAuth 2.0.
3
-
4
- import { getSdkConfig, SdkConfigAccess } from './config_access';
5
- import PegaAuth from './auth';
6
-
7
- // eslint-disable-next-line import/no-mutable-exports
8
- export let gbLoggedIn = sessionStorage.getItem('rsdk_AH') !== null;
9
- // eslint-disable-next-line import/no-mutable-exports
10
- export let gbLoginInProgress = sessionStorage.getItem("rsdk_loggingIn") !== null;
11
- // other sessionStorage items: rsdk_appName
12
-
13
- // will store the PegaAuth instance
14
- let authMgr = null;
15
- // Since this variable is loaded in a separate instance in the popup scenario, use storage to coordinate across the two
16
- let usePopupForRestOfSession = sessionStorage.getItem("rsdk_popup") === "1";
17
- let gbC11NBootstrapInProgress = false;
18
- // Some non Pega OAuth 2.0 Authentication in use (Basic or Custom for service package)
19
- let gbCustomAuth = false;
20
-
21
- /*
22
- * Set to use popup experience for rest of session
23
- */
24
- const forcePopupForReauths = ( bForce ) => {
25
- if( bForce ) {
26
- sessionStorage.setItem("rsdk_popup", "1");
27
- usePopupForRestOfSession = true;
28
- } else {
29
- sessionStorage.removeItem("rsdk_popup");
30
- usePopupForRestOfSession = false;
31
- }
32
- };
33
-
34
- const setNoInitialRedirect = (bNoInitialRedirect ) => {
35
- if( bNoInitialRedirect ) {
36
- forcePopupForReauths(true);
37
- sessionStorage.setItem("rsdk_noRedirect", "1");
38
- } else {
39
- sessionStorage.removeItem("rsdk_noRedirect");
40
- }
41
- };
42
-
43
- const isLoginExpired = () => {
44
- let bExpired = true;
45
- const sLoginStart = sessionStorage.getItem("rsdk_loggingIn");
46
- if( sLoginStart !== null ) {
47
- const currTime = Date.now();
48
- bExpired = currTime - parseInt(sLoginStart, 10) > 60000;
49
- }
50
- return bExpired;
51
- };
52
-
53
- /**
54
- * Clean up any web storage allocated for the user session.
55
- */
56
- const clearAuthMgr = (bFullReauth=false) => {
57
- // Remove any local storage for the user
58
- if( !gbCustomAuth ) {
59
- sessionStorage.removeItem('rsdk_AH');
60
- }
61
- if( !bFullReauth ) {
62
- sessionStorage.removeItem("rsdk_CI");
63
- }
64
- sessionStorage.removeItem("rsdk_TI");
65
- sessionStorage.removeItem("rsdk_UI");
66
- sessionStorage.removeItem("rsdk_loggingIn");
67
- gbLoggedIn = false;
68
- gbLoginInProgress = false;
69
- forcePopupForReauths(bFullReauth);
70
- // Not removing the authMgr structure itself...as it can be leveraged on next login
71
- };
72
-
73
- export const authNoRedirect = () => {
74
- return sessionStorage.getItem("rsdk_noRedirect") === "1";
75
- };
76
-
77
- /**
78
- * Initialize OAuth config structure members and create authMgr instance
79
- * bInit - governs whether to create new sessionStorage or load existing one
80
- */
81
- const initOAuth = (bInit) => {
82
- return getSdkConfig().then( sdkConfig => {
83
- const sdkConfigAuth = sdkConfig.authConfig;
84
- const sdkConfigServer = sdkConfig.serverConfig;
85
- let pegaUrl = sdkConfigServer.infinityRestServerUrl;
86
- const bNoInitialRedirect = authNoRedirect();
87
-
88
- // Construct default OAuth endpoints (if not explicitly specified)
89
- if (pegaUrl) {
90
- // Cope with trailing slash being present
91
- if (!pegaUrl.endsWith('/')) {
92
- pegaUrl += '/';
93
- }
94
- if (!sdkConfigAuth.authorize) {
95
- sdkConfigAuth.authorize = `${pegaUrl}PRRestService/oauth2/v1/authorize`;
96
- }
97
- if (!sdkConfigAuth.token) {
98
- sdkConfigAuth.token = `${pegaUrl}PRRestService/oauth2/v1/token`;
99
- }
100
- if (!sdkConfigAuth.revoke) {
101
- sdkConfigAuth.revoke = `${pegaUrl}PRRestService/oauth2/v1/revoke`;
102
- }
103
- if( !sdkConfigAuth.redirectUri ) {
104
- sdkConfigAuth.redirectUri = `${window.location.origin}${window.location.pathname}`;
105
- }
106
- if (!sdkConfigAuth.userinfo) {
107
- const appAliasSeg = sdkConfigServer.appAlias ? `app/${sdkConfigServer.appAlias}/` : '';
108
- sdkConfigAuth.userinfo = `${pegaUrl}${appAliasSeg}api/oauthclients/v1/userinfo/JSON`;
109
- }
110
- }
111
- // Auth service alias
112
- if( !sdkConfigAuth.authService) {
113
- sdkConfigAuth.authService = "pega";
114
- }
115
-
116
- // Construct path to auth.html (used for case when not doing a main window redirect)
117
- let sNoMainRedirectUri=sdkConfigAuth.redirectUri;
118
- const nLastPathSep = sNoMainRedirectUri.lastIndexOf("/");
119
- sNoMainRedirectUri = nLastPathSep !== -1 ? `${sNoMainRedirectUri.substring(0,nLastPathSep+1)}auth.html` : `${sNoMainRedirectUri}/auth.html`;
120
-
121
- const authConfig = {
122
- clientId: bNoInitialRedirect ? sdkConfigAuth.mashupClientId : sdkConfigAuth.portalClientId,
123
- authorizeUri: sdkConfigAuth.authorize,
124
- tokenUri: sdkConfigAuth.token,
125
- revokeUri: sdkConfigAuth.revoke,
126
- userinfoUri: sdkConfigAuth.userinfo,
127
- redirectUri: bNoInitialRedirect || usePopupForRestOfSession
128
- ? sNoMainRedirectUri
129
- : sdkConfigAuth.redirectUri,
130
- authService: sdkConfigAuth.authService,
131
- appAlias: sdkConfigServer.appAlias || '',
132
- useLocking: true
133
- };
134
- // If no clientId is specified assume not OAuth but custom auth
135
- if( !authConfig.clientId ) {
136
- gbCustomAuth = true;
137
- return;
138
- }
139
- if( 'silentTimeout' in sdkConfigAuth ) {
140
- authConfig.silentTimeout = sdkConfigAuth.silentTimeout;
141
- }
142
- if( bNoInitialRedirect ) {
143
- authConfig.userIdentifier = sdkConfigAuth.mashupUserIdentifier;
144
- authConfig.password = sdkConfigAuth.mashupPassword;
145
- }
146
- if( 'iframeLoginUI' in sdkConfigAuth ){
147
- authConfig.iframeLoginUI = sdkConfigAuth.iframeLoginUI.toString().toLowerCase() === 'true';
148
- }
149
-
150
- // Check if sessionStorage exists (and if so if for same authorize endpoint). Otherwise, assume
151
- // sessionStorage is out of date (user just edited endpoints). Else, logout required to clear
152
- // sessionStorage and get other endpoints updates.
153
- // Doing this as sessionIndex might have been added to this storage structure
154
- let sSI = sessionStorage.getItem("rsdk_CI");
155
- if( sSI ) {
156
- try {
157
- const oSI = JSON.parse(sSI);
158
- if( oSI.authorizeUri !== authConfig.authorizeUri ||
159
- oSI.appAlias !== authConfig.appAlias ||
160
- oSI.clientId !== authConfig.clientId ||
161
- oSI.userIdentifier !== authConfig.userIdentifier ||
162
- oSI.password !== authConfig.password) {
163
- clearAuthMgr();
164
- sSI = null;
165
- }
166
- } catch(e) {
167
- // do nothing
168
- }
169
- }
170
-
171
- if( !sSI || bInit ) {
172
- sessionStorage.setItem('rsdk_CI', JSON.stringify(authConfig));
173
- }
174
- authMgr = new PegaAuth('rsdk_CI');
175
- });
176
- };
177
-
178
- const getAuthMgr = ( bInit ) => {
179
- return new Promise( (resolve) => {
180
- let idNextCheck = null;
181
- const fnCheckForAuthMgr = () => {
182
- if( PegaAuth && !authMgr ) {
183
- initOAuth( bInit );
184
- }
185
- if(authMgr) {
186
- if( idNextCheck ) {
187
- clearInterval(idNextCheck);
188
- }
189
- return resolve(authMgr);
190
- }
191
- }
192
- fnCheckForAuthMgr();
193
- idNextCheck = setInterval(fnCheckForAuthMgr, 10);
194
- });
195
- };
196
-
197
- export const sdkGetAuthHeader = () => {
198
- return sessionStorage.getItem("rsdk_AH");
199
- };
200
-
201
- /**
202
- * Initiate the process to get the Constellation bootstrap shell loaded and initialized
203
- * @param {Object} authConfig
204
- * @param {Object} tokenInfo
205
- * @param {Function} authTokenUpdated - callback invoked when Constellation JS Engine silently updates
206
- * an expired access_token
207
- * @param {Function} fnReauth - callback invoked when a full or custom reauth is needed
208
- */
209
- const constellationInit = (authConfig, tokenInfo, authTokenUpdated, fnReauth) => {
210
- const constellationBootConfig = {};
211
- const sdkConfigServer = SdkConfigAccess.getSdkConfigServer();
212
-
213
- // Set up constellationConfig with data that bootstrapWithAuthHeader expects
214
- constellationBootConfig.customRendering = true;
215
- constellationBootConfig.restServerUrl = sdkConfigServer.infinityRestServerUrl;
216
- // NOTE: Needs a trailing slash! So add one if not provided
217
- if( !sdkConfigServer.sdkContentServerUrl.endsWith('/') ) {
218
- sdkConfigServer.sdkContentServerUrl = `${sdkConfigServer.sdkContentServerUrl}/`;
219
- }
220
- constellationBootConfig.staticContentServerUrl = `${sdkConfigServer.sdkContentServerUrl}constellation/`;
221
- if( !constellationBootConfig.staticContentServerUrl.endsWith('/') ) {
222
- constellationBootConfig.staticContentServerUrl = `${constellationBootConfig.staticContentServerUrl}/`;
223
- }
224
- // If appAlias specified, use it
225
- if( sdkConfigServer.appAlias ) {
226
- constellationBootConfig.appAlias = sdkConfigServer.appAlias;
227
- }
228
-
229
- if( tokenInfo ) {
230
- // Pass in auth info to Constellation
231
- constellationBootConfig.authInfo = {
232
- authType: "OAuth2.0",
233
- tokenInfo,
234
- // Set whether we want constellation to try to do a full re-Auth or not ()
235
- // true doesn't seem to be working in SDK scenario so always passing false for now
236
- popupReauth: false /* !authNoRedirect() */,
237
- client_id: authConfig.clientId,
238
- authentication_service: authConfig.authService,
239
- redirect_uri: authConfig.redirectUri,
240
- endPoints: {
241
- authorize: authConfig.authorizeUri,
242
- token: authConfig.tokenUri,
243
- revoke: authConfig.revokeUri
244
- },
245
- // TODO: setup callback so we can update own storage
246
- onTokenRetrieval: authTokenUpdated
247
- }
248
- } else {
249
- constellationBootConfig.authorizationHeader = sdkGetAuthHeader();
250
- }
251
-
252
-
253
- // Turn off dynamic load components (should be able to do it here instead of after load?)
254
- constellationBootConfig.dynamicLoadComponents = false;
255
-
256
- if( gbC11NBootstrapInProgress ) {
257
- return;
258
- } else {
259
- gbC11NBootstrapInProgress = true;
260
- }
261
-
262
- // Note that staticContentServerUrl already ends with a slash (see above), so no slash added.
263
- // In order to have this import succeed and to have it done with the webpackIgnore magic comment tag.
264
- // See: https://webpack.js.org/api/module-methods/
265
- import(/* webpackIgnore: true */ `${constellationBootConfig.staticContentServerUrl}bootstrap-shell.js`).then((bootstrapShell) => {
266
- // NOTE: once this callback is done, we lose the ability to access loadMashup.
267
- // So, create a reference to it
268
- window.myLoadMashup = bootstrapShell.loadMashup;
269
- window.myLoadPortal = bootstrapShell.loadPortal;
270
- window.myLoadDefaultPortal = bootstrapShell.loadDefaultPortal;
271
-
272
- bootstrapShell.bootstrapWithAuthHeader(constellationBootConfig, 'shell').then(() => {
273
- // eslint-disable-next-line no-console
274
- console.log('Bootstrap successful!');
275
- gbC11NBootstrapInProgress = false;
276
-
277
- // Setup listener for the reauth event
278
- if( tokenInfo ) {
279
- // eslint-disable-next-line no-undef
280
- PCore.getPubSubUtils().subscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_FULL_REAUTH, fnReauth, "authFullReauth");
281
- } else {
282
- // customReauth event introduced with 8.8
283
- // eslint-disable-next-line no-undef
284
- const sEvent = PCore.getConstants().PUB_SUB_EVENTS.EVENT_CUSTOM_REAUTH;
285
- if( sEvent ) {
286
- // eslint-disable-next-line no-undef
287
- PCore.getPubSubUtils().subscribe(sEvent, fnReauth, "doReauth");
288
- }
289
- }
290
-
291
- // Fire SdkConstellationReady event so bridge and app route can do expected post PCore initializations
292
- const event = new CustomEvent('SdkConstellationReady', {});
293
- document.dispatchEvent(event);
294
- })
295
- .catch( e => {
296
- // Assume error caught is because token is not valid and attempt a full reauth
297
- // eslint-disable-next-line no-console
298
- console.error(`Constellation JS Engine bootstrap failed. ${e}`);
299
- gbC11NBootstrapInProgress = false;
300
- fnReauth();
301
- })
302
- });
303
- /* Ends here */
304
- };
305
-
306
- export const updateLoginStatus = () => {
307
- const sAuthHdr = sdkGetAuthHeader();
308
- gbLoggedIn = sAuthHdr && sAuthHdr.length > 0;
309
- };
310
-
311
- const getCurrentTokens = () => {
312
- let tokens = null;
313
- const sTI = sessionStorage.getItem('rsdk_TI');
314
- if(sTI) {
315
- try {
316
- tokens = JSON.parse(sTI);
317
- } catch(e) {
318
- tokens = null;
319
- }
320
- }
321
- return tokens;
322
- };
323
-
324
- const fireTokenAvailable = (token, bLoadC11N=true) => {
325
- if( !token ) {
326
- // This is used on page reload to load the token from sessionStorage and carry on
327
- token = getCurrentTokens();
328
- if( !token ) {
329
- return;
330
- }
331
- }
332
-
333
- sessionStorage.setItem('rsdk_AH', `${token.token_type} ${token.access_token}`);
334
- updateLoginStatus();
335
-
336
- // gbLoggedIn is getting updated in updateLoginStatus
337
- gbLoggedIn = true;
338
- gbLoginInProgress = false;
339
- sessionStorage.removeItem("rsdk_loggingIn");
340
- forcePopupForReauths(true);
341
-
342
- const sSI = sessionStorage.getItem("rsdk_CI");
343
- let authConfig = null;
344
- if( sSI ) {
345
- try {
346
- authConfig = JSON.parse(sSI);
347
- } catch(e) {
348
- // do nothing
349
- }
350
- }
351
-
352
- if( !window.PCore && bLoadC11N ) {
353
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
354
- constellationInit( authConfig, token, authTokenUpdated, authFullReauth );
355
- }
356
-
357
- /*
358
- // Create and dispatch the SdkLoggedIn event to trigger constellationInit
359
- const event = new CustomEvent('SdkLoggedIn', { detail: { authConfig, tokenInfo: token } });
360
- document.dispatchEvent(event);
361
- */
362
- };
363
-
364
- const processTokenOnLogin = ( token, bLoadC11N=true ) => {
365
- sessionStorage.setItem("rsdk_TI", JSON.stringify(token));
366
- if( window.PCore ) {
367
- window.PCore.getAuthUtils().setTokens(token);
368
- } else {
369
- fireTokenAvailable(token, bLoadC11N);
370
- }
371
- };
372
-
373
- const updateRedirectUri = (aMgr, sRedirectUri) => {
374
- const sSI = sessionStorage.getItem("rsdk_CI");
375
- let authConfig = null;
376
- if( sSI ) {
377
- try {
378
- authConfig = JSON.parse(sSI);
379
- } catch(e) {
380
- // do nothing
381
- }
382
- }
383
- authConfig.redirectUri = sRedirectUri;
384
- sessionStorage.setItem("rsdk_CI", JSON.stringify(authConfig));
385
- aMgr.reloadConfig();
386
- };
387
-
388
-
389
- // TODO: Cope with 401 and refresh token if possible (or just hope that it succeeds during login)
390
- /**
391
- * Retrieve UserInfo for current authentication service
392
- */
393
- export const getUserInfo = (bUseSS=true) => {
394
- const ssUserInfo = sessionStorage.getItem("rsdk_UI");
395
- let userInfo = null;
396
- if( bUseSS && ssUserInfo ) {
397
- try {
398
- userInfo = JSON.parse(ssUserInfo);
399
- return Promise.resolve(userInfo);
400
- } catch(e) {
401
- // do nothing
402
- }
403
- }
404
- getAuthMgr(false).then( (aMgr) => {
405
- const tokenInfo = getCurrentTokens();
406
- return aMgr.getUserinfo(tokenInfo.access_token).then( data => {
407
- userInfo = data;
408
- if( userInfo ) {
409
- sessionStorage.setItem("rsdk_UI", JSON.stringify(userInfo));
410
- } else {
411
- sessionStorage.removeItem("rsdk_UI");
412
- }
413
- return Promise.resolve(userInfo);
414
- });
415
- });
416
-
417
- };
418
-
419
- export const login = (bFullReauth=false) => {
420
-
421
- if( gbCustomAuth ) return;
422
-
423
- gbLoginInProgress = true;
424
- // Needed so a redirect to login screen and back will know we are still in process of logging in
425
- sessionStorage.setItem("rsdk_loggingIn", `${Date.now()}`);
426
-
427
- getAuthMgr(!bFullReauth).then( (aMgr) => {
428
- const bMainRedirect = !authNoRedirect();
429
- const sdkConfigAuth = SdkConfigAccess.getSdkConfigAuth();
430
- let sRedirectUri=sdkConfigAuth.redirectUri;
431
-
432
- // If initial main redirect is OK, redirect to main page, otherwise will authorize in a popup window
433
- if (bMainRedirect && !bFullReauth) {
434
- // update redirect uri to be the root
435
- updateRedirectUri(aMgr, sRedirectUri);
436
- aMgr.loginRedirect();
437
- // Don't have token til after the redirect
438
- return Promise.resolve(undefined);
439
- } else {
440
- // Construct path to redirect uri
441
- const nLastPathSep = sRedirectUri.lastIndexOf("/");
442
- sRedirectUri = nLastPathSep !== -1 ? `${sRedirectUri.substring(0,nLastPathSep+1)}auth.html` : `${sRedirectUri}/auth.html`;
443
- // Set redirectUri to static auth.html
444
- updateRedirectUri(aMgr, sRedirectUri);
445
- return new Promise( (resolve, reject) => {
446
- aMgr.login().then(token => {
447
- processTokenOnLogin(token);
448
- // getUserInfo();
449
- resolve(token.access_token);
450
- }).catch( (e) => {
451
- gbLoginInProgress = false;
452
- sessionStorage.removeItem("rsdk_loggingIn");
453
- // eslint-disable-next-line no-console
454
- console.log(e);
455
- reject(e);
456
- });
457
- });
458
- }
459
- });
460
-
461
- };
462
-
463
- export const authRedirectCallback = ( href, fnLoggedInCB=null ) => {
464
- // Get code from href and swap for token
465
- const aHrefParts = href.split('?');
466
- const urlParams = new URLSearchParams(aHrefParts.length>1 ? `?${aHrefParts[1]}` : '');
467
- const code = urlParams.get("code");
468
-
469
- getAuthMgr(false).then( (aMgr) => {
470
- aMgr.getToken(code).then(token => {
471
- if( token && token.access_token ) {
472
- processTokenOnLogin(token, false);
473
- // getUserInfo();
474
- if( fnLoggedInCB ) {
475
- fnLoggedInCB( token.access_token );
476
- }
477
- }
478
- });
479
- });
480
- };
481
-
482
- /**
483
- * Silent or visible login based on login status
484
- * @param {string} appName - unique name for application route (will be used to clear an session storage for another route)
485
- * @param {boolean} noMainRedirect - avoid the initial main window redirect that happens in scenarios where it is OK to transition
486
- * away from the main page
487
- * @param {boolean} deferLogin - defer logging in (if not already authenticated)
488
- */
489
- export const loginIfNecessary = (appName, noMainRedirect=false, deferLogin=false) => {
490
- // If no initial redirect status of page changed...clearAuthMgr
491
- const currNoMainRedirect = authNoRedirect();
492
- const currAppName = sessionStorage.getItem("rsdk_appName");
493
- if( appName !== currAppName || noMainRedirect !== currNoMainRedirect) {
494
- clearAuthMgr();
495
- sessionStorage.setItem("rsdk_appName", appName);
496
- }
497
- setNoInitialRedirect(noMainRedirect);
498
- // If custom auth no need to do any OAuth logic
499
- if( gbCustomAuth ) {
500
- if( !window.PCore ) {
501
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
502
- constellationInit( null, null, null, authCustomReauth );
503
- }
504
- return;
505
- }
506
-
507
- if( window.location.href.indexOf("?code") !== -1 ) {
508
- // initialize authMgr
509
- initOAuth(false);
510
- return getAuthMgr(false).then(() => {
511
- authRedirectCallback(window.location.href, ()=> {
512
- window.location.href = window.location.pathname;
513
- });
514
- });
515
- }
516
- if( !deferLogin && (!gbLoginInProgress || isLoginExpired()) ) {
517
- initOAuth(false);
518
- return getAuthMgr(false).then(() => {
519
- updateLoginStatus();
520
- if( gbLoggedIn ) {
521
- fireTokenAvailable(getCurrentTokens());
522
- // getUserInfo();
523
- } else {
524
- return login();
525
- }
526
- });
527
- }
528
- };
529
-
530
- export const getHomeUrl = () => {
531
- return `${window.location.origin}/`;
532
- };
533
-
534
-
535
- export const authIsMainRedirect = () => {
536
- // Even with main redirect, we want to use it only for the first login (so it doesn't wipe out any state or the reload)
537
- return !authNoRedirect() && !usePopupForRestOfSession;
538
- };
539
-
540
- // Passive update where just session storage is updated so can be used on a window refresh
541
- export const authTokenUpdated = (tokenInfo ) => {
542
- sessionStorage.setItem("rsdk_TI", JSON.stringify(tokenInfo));
543
- };
544
-
545
- export const logout = () => {
546
- sessionStorage.removeItem('rsdk_portalName');
547
- return new Promise((resolve) => {
548
- const fnClearAndResolve = () => {
549
- clearAuthMgr();
550
-
551
- const event = new Event('SdkLoggedOut');
552
- document.dispatchEvent(event);
553
-
554
- resolve();
555
- };
556
- if( gbCustomAuth ) {
557
- sessionStorage.removeItem("rsdk_AH");
558
- fnClearAndResolve();
559
- return;
560
- }
561
- const tokenInfo = getCurrentTokens();
562
- if( tokenInfo && tokenInfo.access_token ) {
563
- if( window.PCore ) {
564
- window.PCore.getAuthUtils().revokeTokens().then(() => {
565
- fnClearAndResolve();
566
- }).catch(err => {
567
- // eslint-disable-next-line no-console
568
- console.log("Error:",err?.message);
569
- });
570
- } else {
571
- getAuthMgr(false).then( (aMgr) => {
572
- aMgr.revokeTokens(tokenInfo.access_token, tokenInfo.refresh_token)
573
- .then(() => {
574
- // Go to finally
575
- })
576
- .finally(() => {
577
- fnClearAndResolve();
578
- });
579
- });
580
- }
581
- } else {
582
- fnClearAndResolve();
583
- }
584
- });
585
- };
586
-
587
- // Callback routine for custom event to ask for updated tokens
588
- export const authUpdateTokens = (token) => {
589
- processTokenOnLogin( token );
590
- };
591
-
592
-
593
- // Initiate a full OAuth re-authorization (any refresh token has also expired).
594
- export const authFullReauth = () => {
595
- const bHandleHere = true; // Other alternative is to raise an event and have someone else handle it
596
-
597
- if( bHandleHere ) {
598
- // Don't want to do a full clear of authMgr as will loose sessionIndex. Rather just clear the tokens
599
- clearAuthMgr(true);
600
- login(true);
601
- } else {
602
- // Fire the SdkFullReauth event to indicate a new token is needed (PCore.getAuthUtils.setTokens method
603
- // should be used to communicate the new token to Constellation JS Engine.
604
- const event = new CustomEvent('SdkFullReauth', { detail: authUpdateTokens });
605
- document.dispatchEvent(event);
606
- }
607
- };
608
-
609
- // Set the custom authorization header for the SDK (and Constellation JS Engine) to
610
- // utilize for every DX API request
611
- export const sdkSetAuthHeader = (authHeader) => {
612
- // set this within session storage so it survives a browser reload
613
- if( authHeader ) {
614
- sessionStorage.setItem("rsdk_AH", authHeader);
615
- // setAuthorizationHeader method not available til 8.8 so do safety check
616
- if( window.PCore?.getAuthUtils().setAuthorizationHeader ) {
617
- window.PCore.getAuthUtils().setAuthorizationHeader(authHeader);
618
- }
619
- } else {
620
- sessionStorage.removeItem("rsdk_AH");
621
- }
622
- gbCustomAuth = true;
623
- };
624
-
625
- // Initiate a custom re-authorization.
626
- export const authCustomReauth = () => {
627
- // Fire the SdkCustomReauth event to indicate a new authHeader is needed. Event listener should invoke sdkSetAuthHeader
628
- // to communicate the new token to sdk (and Constellation JS Engine)
629
- const event = new CustomEvent('SdkCustomReauth', { detail: sdkSetAuthHeader });
630
- document.dispatchEvent(event);
631
- };