"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const request_params_1 = require("../request-params");
const common_definitions_1 = require("../common-definitions");
const action = {
    title: 'Track Event',
    description: 'Sends a track event to Usermaven.',
    fields: {
        event: {
            type: 'string',
            required: true,
            description: 'The event name',
            label: 'Event Name',
            default: { '@path': '$.event' }
        },
        event_attributes: {
            type: 'object',
            required: false,
            description: 'Attributes associated with the event',
            label: 'Event Attributes',
            default: { '@path': '$.properties' }
        },
        user_id: {
            type: 'string',
            required: false,
            description: 'The user id, to uniquely identify the user',
            label: 'User id',
            default: { '@path': '$.userId' }
        },
        user_email: {
            type: 'string',
            required: false,
            description: 'The user email address',
            label: 'Email address',
            default: {
                '@if': {
                    exists: { '@path': '$.properties.email' },
                    then: { '@path': '$.properties.email' },
                    else: { '@path': '$.context.traits.email' }
                }
            }
        },
        user_created_at: {
            type: 'string',
            required: false,
            description: 'The timestamp when the user was created',
            label: 'Created at',
            default: {
                '@if': {
                    exists: { '@path': '$.properties.created_at' },
                    then: { '@path': '$.properties.created_at' },
                    else: { '@path': '$.context.traits.created_at' }
                }
            }
        },
        ...common_definitions_1.commonFields
    },
    perform: (request, { payload, settings }) => {
        const resolvedPayload = (0, request_params_1.resolveRequestPayload)(settings, payload);
        const { url, options } = (0, request_params_1.eventRequestParams)(settings, resolvedPayload);
        return request(url, options);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map