"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_fields_1 = require("../common-fields");
const contants_1 = require("../contants");
const action = {
    title: 'Track',
    description: `Send track calls to ${contants_1.IntegrationName}.`,
    defaultSubscription: 'type = "track"',
    fields: {
        eventName: {
            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' }
        },
        traits: {
            type: 'object',
            required: false,
            description: 'The Traits of the track call',
            label: 'Event Traits',
            default: { '@path': '$.context.traits' }
        },
        ...common_fields_1.commonFields
    },
    perform: (request, data) => {
        return request(`${contants_1.IntegrationBaseUrl}/events/track`, {
            method: 'post',
            headers: {
                Authorization: `Basic ${data.settings.apiKey}`
            },
            json: { ...data.payload, apiKey: data.settings.apiKey }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map