"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const constants_1 = require("../constants");
const action = {
    title: 'Send User Data',
    description: 'Send user profile details to Jimo',
    defaultSubscription: 'type = "identify"',
    fields: {
        userId: {
            label: 'User ID',
            description: 'The unique user identifier',
            type: 'string',
            required: true,
            default: {
                '@path': '$.userId'
            }
        },
        email: {
            label: 'User email',
            description: 'The email of the user',
            type: 'string',
            required: false,
            default: {
                '@path': '$.traits.email'
            }
        },
        traits: {
            label: 'User Traits',
            description: 'User attributes coming from segment traits',
            type: 'object',
            default: {
                '@path': '$.traits'
            }
        }
    },
    perform: (request, { payload }) => {
        const { userId, traits, email } = payload;
        const restOfTraits = (0, actions_core_1.omit)(traits || {}, ['email']);
        const json = {
            userId,
            ...(email ? { email } : {}),
            ...(Object.entries(restOfTraits).length > 0 ? { traits: restOfTraits } : {})
        };
        return request((0, constants_1.buildJimoUrl)(constants_1.JIMO_USER_PATH), {
            method: 'post',
            json
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map