"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const unified_fields_1 = require("../unified-fields");
const payload_transformer_1 = require("../payload-transformer");
const action = {
    title: 'Track Page View',
    description: 'Forward page view event to RoadwayAI.',
    defaultSubscription: 'type = "page"',
    fields: (0, unified_fields_1.getTrackPageViewFields)(),
    perform: async (request, { settings, payload }) => {
        const flattenedPayload = (0, payload_transformer_1.flattenPayload)(payload);
        return request(`https://production.api.roadwayai.com/api/v1/segment/events/page`, {
            method: 'POST',
            headers: {
                'x-api-key': settings.apiKey
            },
            json: [flattenedPayload]
        });
    },
    performBatch: async (request, { settings, payload }) => {
        const transformedPayloads = (0, payload_transformer_1.flattenPayloadBatch)(payload);
        return request(`https://production.api.roadwayai.com/api/v1/segment/events/page`, {
            method: 'POST',
            headers: {
                'x-api-key': settings.apiKey
            },
            json: transformedPayloads
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map