import { browserDestination } from '../../runtime/shim';
import LogRocket from 'logrocket';
import track from './track';
import identify from './identify';
import { defaultValues } from '@segment/actions-core';
export const destination = {
    name: 'Logrocket',
    slug: 'actions-logrocket',
    mode: 'device',
    presets: [
        {
            name: 'Track',
            subscribe: 'type = "track"',
            partnerAction: 'track',
            mapping: defaultValues(track.fields)
        },
        {
            name: 'Identify',
            subscribe: 'type = "identify"',
            partnerAction: 'identify',
            mapping: defaultValues(identify.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.init(appID, window.logRocketSettings || settings);
        await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, '_LRLogger'), 100);
        return LogRocket;
    },
    actions: {
        track,
        identify
    }
};
export default browserDestination(destination);
//# sourceMappingURL=index.js.map