File tree Expand file tree Collapse file tree 4 files changed +20
-12
lines changed
Expand file tree Collapse file tree 4 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -93,19 +93,11 @@ export class RequestClient {
9393 }
9494
9595 if ( token ) {
96- if ( ! request . headers ) {
97- request . headers = { } ;
98- }
99- request . headers [ "Authorization" ] = "Bearer " + ( token . hasOwnProperty ( "accessToken" ) ? ( token as AccessToken ) . accessToken : token ) ;
96+ request . headers ! [ "Authorization" ] = "Bearer " + ( token . hasOwnProperty ( "accessToken" ) ? ( token as AccessToken ) . accessToken : token ) ;
10097 }
10198
10299 if ( Utility . isRunningWithinPortals ( ) ) {
103- try {
104- const token = await ( window as any ) . shell . getTokenDeferred ( ) ;
105- request . headers [ "__RequestVerificationToken" ] = token ;
106- } catch ( error ) {
107- throw new Error ( "Unable to fetch token from shell. Error: " + ( error as Error ) ?. message ) ;
108- }
100+ request . headers ! [ "__RequestVerificationToken" ] = await global . window . shell ! . getTokenDeferred ( ) ;
109101 }
110102
111103 const url = request . apiConfig ? request . apiConfig . url : config . dataApi . url ;
Original file line number Diff line number Diff line change @@ -167,3 +167,11 @@ export declare namespace Core {
167167 async ?: boolean ;
168168 }
169169}
170+
171+ declare global {
172+ interface Window {
173+ shell ?: {
174+ getTokenDeferred : ( ) => Promise < string > ;
175+ } ;
176+ }
177+ }
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ export class Utility {
162162 * @returns {boolean }
163163 */
164164 static isRunningWithinPortals ( ) : boolean {
165- return global . DWA_BROWSER ? ! ! ( global . window as any ) . shell : false ;
165+ return global . DWA_BROWSER ? ! ! global . window . shell : false ;
166166 }
167167
168168 static isObject ( obj : any ) : boolean {
Original file line number Diff line number Diff line change @@ -126,7 +126,11 @@ describe("xhr -", () => {
126126 } ;
127127
128128 //@ts -ignore
129- global . window . shell = { } ;
129+ global . window . shell = {
130+ getTokenDeferred : async ( ) => {
131+ return "token" ;
132+ } ,
133+ } ;
130134 //@ts -ignore
131135 global . window . location = { } ;
132136 //@ts -ignore
@@ -177,6 +181,10 @@ describe("xhr -", () => {
177181 expect ( requests [ 0 ] . requestBody ) . to . be . undefined ;
178182 } ) ;
179183
184+ it ( "sends the correct __RequestVerificationToken header" , function ( ) {
185+ expect ( requests [ 0 ] . requestHeaders [ "__RequestVerificationToken" ] ) . to . be . eq ( "token" ) ;
186+ } ) ;
187+
180188 it ( "sends the correct If-Match header" , function ( ) {
181189 expect ( requests [ 0 ] . requestHeaders [ "If-Match" ] ) . to . be . undefined ;
182190 } ) ;
You can’t perform that action at this time.
0 commit comments