"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dayjs_1 = __importDefault(require("dayjs"));
const constants_1 = require("../constants");
const action = {
    title: 'Send events',
    description: 'Send event track calls to Toplyne',
    defaultSubscription: 'type = "track"',
    fields: {
        userId: {
            type: 'string',
            label: 'User ID',
            description: 'The ID of the user to send events for. Required if anonymousId is not provided',
            required: false,
            default: { '@path': '$.userId' }
        },
        anonymousId: {
            type: 'string',
            label: 'Anonymous ID',
            description: 'The anonymous ID of the user to send events for. Required if userId is not provided',
            required: false,
            default: { '@path': '$.anonymousId' }
        },
        accountId: {
            type: 'string',
            label: 'Account ID',
            description: 'The ID of the account to send events for',
            required: false,
            default: { '@path': '$.context.groupId' }
        },
        eventName: {
            type: 'string',
            label: 'Event Name',
            description: 'The name of the event to send',
            required: true,
            default: { '@path': '$.event' }
        },
        timestamp: {
            type: 'datetime',
            label: 'Timestamp',
            description: 'The timestamp of the event',
            required: true,
            default: { '@path': '$.timestamp' }
        },
        eventProperties: {
            type: 'object',
            label: 'Event Properties',
            description: 'The properties of the event',
            required: false,
            default: { '@path': '$.properties' }
        }
    },
    perform: (request, data) => {
        return request(`${constants_1.baseUrl}/upload/events`, {
            json: {
                events: [
                    {
                        ...data.payload,
                        timestamp: (0, dayjs_1.default)(data.payload.timestamp).unix()
                    }
                ]
            }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map