"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.destination = void 0;
const tslib_1 = require("tslib");
const shim_1 = require("../../runtime/shim");
const logrocket_1 = tslib_1.__importDefault(require("logrocket"));
const track_1 = tslib_1.__importDefault(require("./track"));
const identify_1 = tslib_1.__importDefault(require("./identify"));
const actions_core_1 = require("@segment/actions-core");
exports.destination = {
    name: 'Logrocket',
    slug: 'actions-logrocket',
    mode: 'device',
    presets: [
        {
            name: 'Track',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: actions_core_1.defaultValues(track_1.default.fields)
        },
        {
            name: 'Identify',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: actions_core_1.defaultValues(identify_1.default.fields)
        }
    ],
    settings: {
        appID: {
            description: 'The LogRocket app ID.',
            label: 'LogRocket App',
            type: 'string',
            required: true
        },
        networkSanitization: {
            description: 'Sanitize all network request and response bodies from session recordings.',
            label: 'Network Sanitization',
            type: 'boolean',
            required: true,
            default: true
        },
        inputSanitization: {
            description: 'Obfuscate all user-input elements (like <input> and <select>) from session recordings.',
            label: 'Input Sanitization',
            type: 'boolean',
            required: true,
            default: true
        }
    },
    initialize: async ({ settings: { appID, inputSanitization: inputSanitizer, networkSanitization } }, deps) => {
        const requestSanitizer = (request) => {
            if (networkSanitization) {
                request.body = undefined;
                request.headers = {};
            }
            return request;
        };
        const settings = {
            dom: {
                inputSanitizer
            },
            network: {
                requestSanitizer,
                responseSanitizer: requestSanitizer
            }
        };
        logrocket_1.default.init(appID, window.logRocketSettings || settings);
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, '_LRLogger'), 100);
        return logrocket_1.default;
    },
    actions: {
        track: track_1.default,
        identify: identify_1.default
    }
};
exports.default = shim_1.browserDestination(exports.destination);
//# sourceMappingURL=index.js.map