"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const validateInput_1 = require("../validateInput");
const commonFields_1 = require("../commonFields");
const action = {
    title: 'Track',
    description: 'Send track calls to Hyperengage.',
    defaultSubscription: 'type = "track"',
    fields: {
        event_name: {
            type: 'string',
            required: true,
            description: 'The name of the event',
            label: 'Event name',
            default: { '@path': '$.event' }
        },
        user_id: {
            type: 'string',
            required: true,
            description: 'The user id, to uniquely identify the user associated with the event',
            label: 'User id',
            default: { '@path': '$.userId' }
        },
        account_id: {
            type: 'string',
            required: false,
            description: 'The account id, to uniquely identify the account associated with the user',
            label: 'Account id',
            default: {
                '@if': {
                    exists: { '@path': '$.context.groupId' },
                    then: { '@path': '$.context.groupId' },
                    else: { '@path': '$.groupId' }
                }
            }
        },
        properties: {
            type: 'object',
            required: false,
            description: 'The properties of the track call',
            label: 'Event properties',
            default: { '@path': '$.properties' }
        },
        ...commonFields_1.commonFields
    },
    perform: (request, data) => {
        return request(`https://events.hyperengage.io/api/v1/s2s/event?token=${data.settings.apiKey}`, {
            method: 'post',
            json: (0, validateInput_1.validateInput)(data.settings, data.payload, 'track')
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map