blob: 197890f6ac6b0859f1fa8a3afeed1645f4c5516c [file] [log] [blame]
Adrià Vilanova Martínez9c418ab2024-12-05 15:34:40 +01001import { ProtobufObject } from '../../common/protojs.types';
2import {
3 Interceptor,
4 InterceptorFilter,
5 InterceptorHandlerPort,
6} from './InterceptorHandler.port';
7
8export default class InterceptorHandlerAdapter
9 implements InterceptorHandlerPort
10{
11 constructor(private interceptors: Interceptor[]) {}
12
13 matchInterceptors(filter: InterceptorFilter, url: string): Interceptor[] {
14 return this.interceptors.filter((interceptor) => {
15 return interceptor.intercepts == filter && interceptor.urlRegex.test(url);
16 });
17 }
18 triggerEvent(eventName: string, body: ProtobufObject, id: number): void {
19 const e = new CustomEvent('TWPT_' + eventName, {
20 detail: {
21 body,
22 id,
23 },
24 });
25 window.dispatchEvent(e);
26 }
27}