"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const action = {
    title: 'Computed Attribute Sync',
    description: 'Sync Computed Attributes to your Contentstack Experience.',
    defaultSubscription: 'type = "track" or type = "identify"',
    fields: {
        traits: {
            type: 'object',
            default: { '@path': '$.traits' },
            label: 'User traits',
            description: 'User Profile traits to send to Contentstack, for Identify calls'
        },
        properties: {
            type: 'object',
            default: { '@path': '$.properties' },
            label: 'User properties',
            description: 'User Profile properties to send to Contentstack, for Track calls'
        },
        type: {
            type: 'string',
            default: { '@path': '$.type' },
            label: 'Event Type',
            description: 'Type of the event',
            required: true
        },
        userId: {
            type: 'string',
            default: { '@path': '$.userId' },
            label: 'User ID',
            description: 'ID for the user',
            required: true
        }
    },
    perform: (request, { payload, settings }) => {
        const traits = (payload.type === 'track' ? payload.properties : payload.traits) ?? {};
        return request(`${settings.personalizeEdgeApiBaseUrl}/user-attributes`, {
            method: 'patch',
            json: traits,
            headers: {
                'x-cs-eclipse-user-uid': payload?.userId,
                'x-project-uid': settings?.personalizeProjectId ?? ''
            }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map