"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const action = {
    title: 'Send',
    defaultSubscription: 'type = track or type = page or type = screen or type = identify or type = group',
    description: 'Send Segment analytics data to Equals',
    fields: {
        data: {
            label: 'Data',
            description: 'Payload to deliver to Equals. Detaults to sending the entire Segment payload.',
            type: 'object',
            required: true,
            defaultObjectUI: 'object',
            default: { '@path': '$.' }
        }
    },
    perform: (request, { payload, settings }) => {
        try {
            return request(settings.url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'User-Agent': 'Segment Equals Destination'
                },
                json: payload.data
            });
        }
        catch (error) {
            if (error instanceof TypeError) {
                throw new actions_core_1.PayloadValidationError(error.message);
            }
            throw error;
        }
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map