Adrià Vilanova MartÃnez | 9c418ab | 2024-12-05 15:34:40 +0100 | [diff] [blame] | 1 | import FetchProxy from '../../../xhrInterceptor/fetchProxy/FetchProxy'; |
| 2 | import InterceptorHandlerAdapter from '../../../xhrInterceptor/interceptors/InterceptorHandler.adapter'; |
| 3 | import interceptors from '../../../xhrInterceptor/interceptors/interceptors'; |
| 4 | import {KILL_SWITCH_LOCALSTORAGE_KEY, KILL_SWITCH_LOCALSTORAGE_VALUE} from '../../../xhrInterceptor/killSwitchHandler.js'; |
| 5 | import MessageIdTracker from '../../../xhrInterceptor/MessageIdTracker'; |
| 6 | import ResponseModifierAdapter from '../../../xhrInterceptor/ResponseModifier.adapter'; |
| 7 | import createMessageRemoveParentRef from '../../../xhrInterceptor/responseModifiers/createMessageRemoveParentRef'; |
| 8 | import flattenThread from '../../../xhrInterceptor/responseModifiers/flattenThread'; |
| 9 | import loadMoreThread from '../../../xhrInterceptor/responseModifiers/loadMoreThread'; |
| 10 | import { Modifier } from '../../../xhrInterceptor/responseModifiers/types'; |
| 11 | import XHRProxy from '../../../xhrInterceptor/XHRProxy'; |
| 12 | |
| 13 | export const responseModifiers: Modifier[] = [ |
| 14 | loadMoreThread, |
| 15 | flattenThread, |
| 16 | createMessageRemoveParentRef, |
| 17 | ]; |
| 18 | |
| 19 | if (window.localStorage.getItem(KILL_SWITCH_LOCALSTORAGE_KEY) !== |
| 20 | KILL_SWITCH_LOCALSTORAGE_VALUE) { |
| 21 | const responseModifier = new ResponseModifierAdapter(responseModifiers); |
| 22 | const interceptorHandler = new InterceptorHandlerAdapter(interceptors.interceptors); |
| 23 | const messageIdTracker = new MessageIdTracker(); |
| 24 | |
| 25 | new XHRProxy(responseModifier, messageIdTracker); |
| 26 | |
| 27 | const fetchProxy = new FetchProxy(responseModifier, interceptorHandler, messageIdTracker); |
| 28 | fetchProxy.enableInterception(); |
| 29 | } |