"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const omit_1 = __importDefault(require("lodash/omit"));
const properties_1 = require("../properties");
const action = {
    title: 'Page Event',
    description: 'Send a page event to Kameleoon',
    defaultSubscription: 'type = "page"',
    fields: {
        anonymousId: {
            type: 'string',
            description: 'Anonymous id',
            label: 'Anonymous ID',
            default: { '@path': '$.anonymousId' }
        },
        userId: {
            type: 'string',
            description: 'The ID associated with the user',
            label: 'User ID',
            default: { '@path': '$.userId' }
        },
        type: {
            label: 'Type',
            type: 'string',
            required: true,
            description: 'The type of the event',
            default: {
                '@path': '$.type'
            }
        },
        properties: {
            type: 'object',
            required: false,
            description: 'Page properties',
            label: 'Properties',
            default: { '@path': '$.properties' }
        },
        kameleoonVisitorCode: {
            type: 'string',
            required: false,
            description: 'Kameleoon Visitor Code - a unique identifier for the user',
            label: 'Kameleoon Visitor Code',
            default: { '@path': '$.properties.kameleoonVisitorCode' }
        },
        name: {
            type: 'string',
            required: false,
            description: 'The name of the page',
            label: 'Page Name',
            default: {
                '@path': '$.name'
            }
        },
        context: {
            type: 'object',
            required: false,
            description: 'Context properties to send with the event',
            label: 'Context properties',
            default: { '@path': '$.context' }
        },
        timestamp: {
            type: 'string',
            format: 'date-time',
            required: true,
            description: 'The timestamp of the event',
            label: 'Timestamp',
            default: { '@path': '$.timestamp' }
        },
        messageId: {
            type: 'string',
            required: false,
            description: 'The Segment messageId',
            label: 'MessageId',
            default: { '@path': '$.messageId' }
        }
    },
    perform: (request, data) => {
        const payload = {
            ...(0, omit_1.default)(data.payload, ['kameleoonVisitorCode']),
            properties: {
                ...(data.payload.properties || {}),
                kameleoonVisitorCode: data.payload.kameleoonVisitorCode
            }
        };
        return request(properties_1.BASE_URL, {
            headers: {
                authorization: `Basic ${data.settings.apiKey}`,
                'x-segment-settings': data.settings.sitecode
            },
            method: 'post',
            json: payload
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map