@@ -13,11 +13,12 @@ const SLASH_API_SLASH = "/api/";
13
13
* Call the standard js fetch function, possibly with additional handling suitable
14
14
* for Survey Tool such as setting session headers and debugging
15
15
*
16
- * Session headers are automatically added
16
+ * Session headers are automatically added.
17
+ * Only use this for calling back to the Survey Tool, otherwise session headers will leak.
17
18
*
18
19
* @param {String } resource the url or other resource, or Request object
19
20
* @param {Object } init an object containing any custom settings for the request
20
- * @returns a Promise that resolves to a Response object
21
+ * @returns { Promise< Response> }
21
22
*/
22
23
function doFetch ( resource , init ) {
23
24
if ( ST_AJAX_DEBUG ) {
@@ -27,6 +28,12 @@ function doFetch(resource, init) {
27
28
return fetch ( resource , init ) ;
28
29
}
29
30
31
+ /**
32
+ * re-exported global fetch, in case we want to do any logging or customization.
33
+ * Use this for non-SurveyTool (external) queries
34
+ */
35
+ const fetch = window . fetch ;
36
+
30
37
/**
31
38
* If the current user has a session id, add it to the fetch headers, creating
32
39
* init and/or init.headers if not already defined
@@ -254,6 +261,7 @@ function isApiUrl(url) {
254
261
255
262
export {
256
263
doFetch ,
264
+ fetch ,
257
265
handleFetchErrors ,
258
266
makeApiUrl ,
259
267
makePostData ,
0 commit comments