"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const action = {
    title: 'Send',
    description: 'Send any Segment event to Zapier',
    fields: {
        data: {
            label: 'Payload',
            description: 'The payload to send to Zapier',
            type: 'object',
            required: true,
            default: { '@path': '$.' }
        },
        zapSubscriptionUrl: {
            label: 'Zapier Webhook URL',
            description: 'The Zapier webhook URL Segment will send data to. This URL is generated by Zapier when you create a Zap.',
            type: 'string',
            format: 'password',
            readOnly: false,
            required: true
        },
        zapIdentifier: {
            label: 'Zapier Zap Identifier',
            description: 'The Zapier Zap identifier. This is generated by Zapier when you create a Zap.',
            type: 'string',
            readOnly: false,
            required: false
        },
        fql: {
            label: 'Segment FQL Query',
            description: 'The initial Segment FQL query for the Action mapping. This is generated by Zapier when you create a Zap.',
            type: 'string',
            readOnly: false,
            required: false
        }
    },
    perform: (request, { payload }) => {
        const { zapSubscriptionUrl, data } = payload;
        const hosts = ['zapier.com', 'zapier-staging.com'];
        const url = new URL(zapSubscriptionUrl);
        if (!hosts.some((host) => url.hostname.endsWith(host))) {
            throw new actions_core_1.PayloadValidationError(`Invalid Zapier Webhook URL hostname: ${url.hostname}. Must end with one of: ${hosts.join(', ')}`);
        }
        return request(zapSubscriptionUrl, {
            method: 'post',
            json: data
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map