"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utility_1 = require("../utility");
const action = {
    title: 'Page Visit',
    description: `Sends Segment's page event to VWO`,
    fields: {
        url: {
            description: 'URL of the webpage',
            label: 'Page URL',
            required: false,
            type: 'string',
            default: {
                '@path': '$.context.page.url'
            }
        },
        vwoUuid: {
            description: 'VWO UUID',
            label: 'VWO UUID',
            required: true,
            type: 'string',
            default: {
                '@path': '$.properties.vwo_uuid'
            }
        },
        page: {
            description: 'Contains context information regarding a webpage',
            label: 'Page',
            required: false,
            type: 'object',
            default: {
                '@path': '$.context.page'
            }
        },
        ip: {
            description: 'IP address of the user',
            label: 'IP Address',
            required: false,
            type: 'string',
            default: {
                '@path': '$.context.ip'
            }
        },
        userAgent: {
            description: 'User-Agent of the user',
            label: 'User Agent',
            required: false,
            type: 'string',
            default: {
                '@path': '$.context.userAgent'
            }
        },
        timestamp: {
            description: 'Timestamp on the event',
            label: 'Timestamp',
            required: false,
            type: 'string',
            default: {
                '@path': '$.timestamp'
            }
        }
    },
    defaultSubscription: 'type = "page"',
    perform: (request, { settings, payload }) => {
        const eventName = (0, utility_1.sanitiseEventName)('pageView');
        const { headers, structuredPayload } = (0, utility_1.formatPayload)(eventName, payload, false, false, settings.apikey, settings.vwoAccountId);
        structuredPayload.d.event.props['url'] = payload.url;
        const region = settings.region || 'US';
        const host = utility_1.hosts[region];
        const endpoint = `${host}/events/t?en=${eventName}&a=${settings.vwoAccountId}`;
        return request(endpoint, {
            method: 'POST',
            json: structuredPayload,
            headers
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map