import { init as sentryInit, captureException as sentryCaptureException, addBreadcrumb as sentryAddBreadcrumb, setTags as sentrySetTags, setContext, httpClientIntegration, httpContextIntegration, extraErrorDataIntegration, } from "@sentry/react";
/**
 * ignoreErrors and denyUrls are intended to block Sentry exceptions from 3rd
 * party extensions / globals that may be contaminating our Sentry logs.
 *
 * More info: https://docs.sentry.io/clients/javascript/tips/#decluttering-sentry
 */
const ignoreErrors = [
    // Random plugins/extensions
    "top.GLOBALS",
    // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html
    "originalCreateNotification",
    "canvas.contentDocument",
    "MyApp_RemoveAllHighlights",
    "http://tt.epicplay.com",
    "Can't find variable: ZiteReader",
    "jigsaw is not defined",
    "ComboSearch is not defined",
    "http://loading.retry.widdit.com/",
    "atomicFindClose",
    // Facebook borked
    "fb_xd_fragment",
    // ISP "optimizing" proxy - `Cache-Control: no-transform` seems to reduce this. (thanks @acdha)
    // See http://stackoverflow.com/questions/4113268/how-to-stop-javascript-injection-from-vodafone-proxy
    "bmi_SafeAddOnload",
    "EBCallBackMessageReceived",
    // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
    "conduitPage",
    // Generic error code from errors outside the security sandbox
    // You can delete this if using raven.js > 1.0, which ignores these automatically.
    "Script error.",
    // Avast extension error
    "_avast_submit",
    // Likely 3rd party making duplicate variable declaration. Also ignored in other Sentry configs: https://gist.github.com/pioug/b006c983538538066ea871d299d8e8bc
    "change_ua",
    /**
     * Ignore error being caused by Launch Darkly failed request when user is using uBlock. More info: https://github.com/launchdarkly/js-client-sdk/issues/255
     */
    "A network error occurred.",
    /**
     * Ignore Unhandled rejection error occuring specifically on Safari used on mac OS. More info: More info: https://github.com/WordPress/openverse-frontend/issues/1632
     */
    "Non-Error promise rejection captured with value: Not implemented on this platform",
    /**
     * Ignore error "TypeError annule". When the page loads, the refresh button changes to cross button,
     * now if some api request is in progress during this page loading time and the user click this cross button, then iOS chrome/safari throws this error.
     */
    "TypeError: annulé",
    "TypeError: cancelled",
    /**
     * Ignoring error caused by Safari extensions. Extension at fault seems to be 1Password. There's not enough data to share.
     */
    "Error: Error response received for message <get-frame-manager-configuration>",
    /**
     * Ignoring error when it fails to load a resource. Most resources exist, seems to be a low connection issue
     */
    "TypeError: Load failed",
    /**
     * Ignoring error caused by CefSharp Chromium bot attempting to interact with page.
     */
    /^Non-Error promise rejection captured with value: Object Not Found Matching Id:\d+, MethodName:(update|simulateEvent), ParamCount:\d+$/,
];
const denyUrls = [
    // Google Adsense
    /pagead\/js/i,
    // Facebook flakiness
    /graph\.facebook\.com/i,
    // Facebook blocked
    /connect\.facebook\.net\/en_US\/all\.js/i,
    // Woopra flakiness
    /eatdifferent\.com\.woopra-ns\.com/i,
    /static\.woopra\.com\/js\/woopra\.js/i,
    // Chrome extensions
    /extensions\//i,
    /^chrome:\/\//i,
    // Other plugins
    /127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
    /webappstoolbarba\.texthelp\.com\//i,
    /metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
    // Seems to be google checking for internet connection
    /maps\.googleapis\.com\/maps\/api\/mapsjs\/gen_204\//i,
];
const allowUrls = [/staging.locallogic.co/, /sdk.locallogic.co/];
const CONSOLE_LOG_IDENTIFER = "[Local Logic] ";
/**
 * This is a light wrapper around Sentry. We can augment different Sentry
 * methods to be more useful to our needs.
 */
class ErrorTracker {
    constructor() {
        var _a, _b, _c, _d, _e;
        sentryInit({
            dsn: "https://19707ff4ff7f420b9369a3e15041c787@o227377.ingest.sentry.io/6677584",
            tracesSampleRate: import.meta.env.VITE_SENTRY_TRACE_SAMPLE_RATE || 0.01,
            // Default values, we can adjust if this is too much/little
            // This sets the sample rate to be 10%
            replaysSessionSampleRate: 0.1,
            replaysOnErrorSampleRate: 0.5,
            environment: import.meta.env.MODE,
            enabled: import.meta.env.MODE === "production" ||
                import.meta.env.VITE_SENTRY_ENABLED === "true",
            ignoreErrors,
            denyUrls,
            allowUrls,
            release: VITE_COMMIT_SHA,
            integrations: [
                httpClientIntegration(),
                httpContextIntegration(),
                extraErrorDataIntegration(),
            ],
            sendDefaultPii: true,
            // Default is 3, but we have a lot of nested objects
            normalizeDepth: 5,
        });
        setContext("LocalLogic", {
            referrer: document.referrer,
            sdks_app_version: FULL_APP_VERSION,
            sdks_app_path: (_b = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname) === null || _b === void 0 ? void 0 : _b.substring(
            // The ?? - 1 is to fix "Unsafe arithmetic operation on optional chaining. It can result in NaN."
            ((_e = (_d = (_c = window === null || window === void 0 ? void 0 : window.location) === null || _c === void 0 ? void 0 : _c.pathname) === null || _d === void 0 ? void 0 : _d.lastIndexOf("/")) !== null && _e !== void 0 ? _e : -1) + 1),
        });
    }
    captureException(error) {
        this.log(error.message, "error");
        sentryCaptureException(error);
    }
    addBreadCrumb(category, message, data, level = "info") {
        sentryAddBreadcrumb({
            category,
            message,
            data,
            level,
        });
    }
    setTags(tags) {
        sentrySetTags(tags);
    }
    /**
     * Generate useful console logs for debugging
     */
    log(message, type = "info") {
        console[type](CONSOLE_LOG_IDENTIFER + message);
    }
}
const singletonErrorTracker = Object.freeze(new ErrorTracker());
export default singletonErrorTracker;
//# sourceMappingURL=index.js.map