isSentryRequestUrl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. /**
  3. * Checks whether given url points to Sentry server
  4. * @param url url to verify
  5. *
  6. * TODO(v8): Remove Hub fallback type
  7. */
  8. function isSentryRequestUrl(url, hubOrClient) {
  9. const client =
  10. hubOrClient && isHub(hubOrClient)
  11. ? // eslint-disable-next-line deprecation/deprecation
  12. hubOrClient.getClient()
  13. : hubOrClient;
  14. const dsn = client && client.getDsn();
  15. const tunnel = client && client.getOptions().tunnel;
  16. return checkDsn(url, dsn) || checkTunnel(url, tunnel);
  17. }
  18. function checkTunnel(url, tunnel) {
  19. if (!tunnel) {
  20. return false;
  21. }
  22. return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
  23. }
  24. function checkDsn(url, dsn) {
  25. return dsn ? url.includes(dsn.host) : false;
  26. }
  27. function removeTrailingSlash(str) {
  28. return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
  29. }
  30. function isHub(hubOrClient) {
  31. // eslint-disable-next-line deprecation/deprecation
  32. return (hubOrClient ).getClient !== undefined;
  33. }
  34. exports.isSentryRequestUrl = isSentryRequestUrl;
  35. //# sourceMappingURL=isSentryRequestUrl.js.map