"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const __1 = require("..");
const action = {
    title: 'Forward to Courier',
    description: 'Forward track, group and identify events to Courier',
    defaultSubscription: `type = "track" or type = "identify" or type = "group"`,
    fields: {
        data: {
            label: 'Payload',
            description: 'All payload data',
            type: 'object',
            required: true,
            default: { '@path': '$.' },
            unsafe_hidden: true
        },
        segment_computation_action: {
            label: 'Segment Computation Action',
            description: "Segment computation class used to determine if input event is from an Engage Audience'",
            type: 'string',
            unsafe_hidden: true,
            default: {
                '@path': '$.context.personas.computation_class'
            }
        }
    },
    perform: (request, { settings, payload }) => {
        if (payload?.segment_computation_action === 'audience') {
            throw new actions_core_1.PayloadValidationError('This Action does not support sending Engage Audiences. Please use the Sync Audience Action.');
        }
        if (!['track', 'group', 'identify'].includes(payload.data.type)) {
            throw new actions_core_1.PayloadValidationError('Event type must be either track, group or identify');
        }
        const domain = (0, __1.getDomain)(settings.region);
        return request(`${domain}/inbound/segment`, {
            method: 'POST',
            json: payload.data
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map