fix: add FetchProxy
This will let us intercept fetch requests (until now we're only proxying
XMLHttpRequest), in order to fix the issues we're experiencing with some
features.
Bug: twpowertools:229
Change-Id: I277473c05479ca39bb6183a51855382124890bde
diff --git a/src/entryPoints/communityConsole/injections/xhrProxy.ts b/src/entryPoints/communityConsole/injections/xhrProxy.ts
new file mode 100644
index 0000000..1ad5d9d
--- /dev/null
+++ b/src/entryPoints/communityConsole/injections/xhrProxy.ts
@@ -0,0 +1,29 @@
+import FetchProxy from '../../../xhrInterceptor/fetchProxy/FetchProxy';
+import InterceptorHandlerAdapter from '../../../xhrInterceptor/interceptors/InterceptorHandler.adapter';
+import interceptors from '../../../xhrInterceptor/interceptors/interceptors';
+import {KILL_SWITCH_LOCALSTORAGE_KEY, KILL_SWITCH_LOCALSTORAGE_VALUE} from '../../../xhrInterceptor/killSwitchHandler.js';
+import MessageIdTracker from '../../../xhrInterceptor/MessageIdTracker';
+import ResponseModifierAdapter from '../../../xhrInterceptor/ResponseModifier.adapter';
+import createMessageRemoveParentRef from '../../../xhrInterceptor/responseModifiers/createMessageRemoveParentRef';
+import flattenThread from '../../../xhrInterceptor/responseModifiers/flattenThread';
+import loadMoreThread from '../../../xhrInterceptor/responseModifiers/loadMoreThread';
+import { Modifier } from '../../../xhrInterceptor/responseModifiers/types';
+import XHRProxy from '../../../xhrInterceptor/XHRProxy';
+
+export const responseModifiers: Modifier[] = [
+ loadMoreThread,
+ flattenThread,
+ createMessageRemoveParentRef,
+];
+
+if (window.localStorage.getItem(KILL_SWITCH_LOCALSTORAGE_KEY) !==
+ KILL_SWITCH_LOCALSTORAGE_VALUE) {
+ const responseModifier = new ResponseModifierAdapter(responseModifiers);
+ const interceptorHandler = new InterceptorHandlerAdapter(interceptors.interceptors);
+ const messageIdTracker = new MessageIdTracker();
+
+ new XHRProxy(responseModifier, messageIdTracker);
+
+ const fetchProxy = new FetchProxy(responseModifier, interceptorHandler, messageIdTracker);
+ fetchProxy.enableInterception();
+}