"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const request_params_1 = require("../request-params");
const vars_1 = require("../vars");
const action = {
    title: 'Identify User',
    description: 'Sets user identity variables',
    platform: 'cloud',
    defaultSubscription: 'type = "identify"',
    fields: {
        userId: {
            type: 'string',
            required: true,
            description: "The user's id",
            label: 'User ID',
            default: {
                '@path': '$.userId'
            }
        },
        anonymousId: {
            type: 'string',
            required: false,
            description: "The user's anonymous id",
            label: 'Anonymous ID',
            default: {
                '@path': '$.anonymousId'
            }
        },
        displayName: {
            type: 'string',
            required: false,
            description: "The user's display name",
            label: 'Display Name',
            default: {
                '@path': '$.traits.name'
            }
        },
        email: {
            type: 'string',
            required: false,
            description: "The user's email",
            label: 'Email',
            default: {
                '@path': '$.traits.email'
            }
        },
        traits: {
            type: 'object',
            required: false,
            description: 'The Segment traits to be forwarded to FullStory',
            label: 'Traits',
            default: {
                '@path': '$.traits'
            }
        }
    },
    perform: (request, { payload, settings }) => {
        const { traits, anonymousId, userId, email, displayName } = payload;
        const normalizedTraits = (0, vars_1.normalizePropertyNames)(traits, { camelCase: true, typeSuffix: true });
        if (anonymousId) {
            normalizedTraits.segmentAnonymousId_str = anonymousId;
        }
        const requestBody = {
            ...normalizedTraits,
            ...(email !== undefined && { email }),
            ...(displayName !== undefined && { displayName })
        };
        const { url, options } = (0, request_params_1.setUserPropertiesRequestParams)(settings, userId, requestBody);
        return request(url, options);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map