"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 pick_1 = __importDefault(require("lodash/pick"));
const utils_1 = require("../utils");
const common_definitions_1 = require("../common-definitions");
const action = {
    title: 'Track Event',
    description: 'Track an event in Encharge for a known or anonymous person.',
    defaultSubscription: 'type = "track"',
    fields: {
        event: {
            type: 'string',
            required: true,
            description: 'The name of the event.',
            label: 'Event Name',
            default: { '@path': '$.event' }
        },
        ...common_definitions_1.propertiesDefinition,
        ...common_definitions_1.userFieldsDefinition,
        ...common_definitions_1.commonFields
    },
    perform: (request, data) => {
        const payload = {
            ...(0, omit_1.default)(data.payload, ['ip', 'userAgent', 'campaign', 'page', 'location', 'user', 'groupId']),
            context: (0, pick_1.default)(data.payload, ['ip', 'userAgent', 'campaign', 'page', 'location', 'groupId']),
            user: {
                email: data.payload.email,
                userId: data.payload.userId,
                segmentAnonymousId: data.payload.segmentAnonymousId,
                ...(data.payload.userFields || {})
            }
        };
        return request(utils_1.enchargeIngestAPIURL, {
            method: 'post',
            json: payload
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map