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/xhrInterceptor/interceptors/InterceptorHandler.adapter.ts b/src/xhrInterceptor/interceptors/InterceptorHandler.adapter.ts
new file mode 100644
index 0000000..197890f
--- /dev/null
+++ b/src/xhrInterceptor/interceptors/InterceptorHandler.adapter.ts
@@ -0,0 +1,27 @@
+import { ProtobufObject } from '../../common/protojs.types';
+import {
+  Interceptor,
+  InterceptorFilter,
+  InterceptorHandlerPort,
+} from './InterceptorHandler.port';
+
+export default class InterceptorHandlerAdapter
+  implements InterceptorHandlerPort
+{
+  constructor(private interceptors: Interceptor[]) {}
+
+  matchInterceptors(filter: InterceptorFilter, url: string): Interceptor[] {
+    return this.interceptors.filter((interceptor) => {
+      return interceptor.intercepts == filter && interceptor.urlRegex.test(url);
+    });
+  }
+  triggerEvent(eventName: string, body: ProtobufObject, id: number): void {
+    const e = new CustomEvent('TWPT_' + eventName, {
+      detail: {
+        body,
+        id,
+      },
+    });
+    window.dispatchEvent(e);
+  }
+}