-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathisSentryRequestUrl.ts
More file actions
42 lines (35 loc) · 1.3 KB
/
Copy pathisSentryRequestUrl.ts
File metadata and controls
42 lines (35 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Client, DsnComponents, Hub } from '@sentry/types';
/**
* Checks whether given url points to Sentry server
* @param url url to verify
*
* TODO(v8): Remove Hub fallback type
*/
// eslint-disable-next-line deprecation/deprecation
export function isSentryRequestUrl(url: string, hubOrClient: Hub | Client | undefined): boolean {
const client =
hubOrClient && isHub(hubOrClient)
? // eslint-disable-next-line deprecation/deprecation
hubOrClient.getClient()
: hubOrClient;
const dsn = client && client.getDsn();
const tunnel = client && client.getOptions().tunnel;
return checkDsn(url, dsn) || checkTunnel(url, tunnel);
}
function checkTunnel(url: string, tunnel: string | undefined): boolean {
if (!tunnel) {
return false;
}
return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
}
function checkDsn(url: string, dsn: DsnComponents | undefined): boolean {
return dsn ? url.includes(dsn.host) : false;
}
function removeTrailingSlash(str: string): string {
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
}
// eslint-disable-next-line deprecation/deprecation
function isHub(hubOrClient: Hub | Client | undefined): hubOrClient is Hub {
// eslint-disable-next-line deprecation/deprecation
return (hubOrClient as Hub).getClient !== undefined;
}