"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 V2',
    description: 'Sets user identity variables. Creates a new FullStory user if no user matching the given uid is found.',
    platform: 'cloud',
    defaultSubscription: 'type = "identify"',
    fields: {
        uid: {
            type: 'string',
            required: false,
            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'
            }
        },
        properties: {
            type: 'object',
            required: false,
            description: 'The Segment traits to be forwarded to FullStory',
            label: 'Traits',
            default: {
                '@path': '$.traits'
            }
        }
    },
    perform: (request, { payload, settings }) => {
        const { properties, anonymousId, uid, email, displayName } = payload;
        const normalizedProperties = (0, vars_1.normalizePropertyNames)(properties);
        if (anonymousId) {
            normalizedProperties.segmentAnonymousId = anonymousId;
        }
        const requestBody = {
            uid,
            ...(email !== undefined && { email }),
            ...(displayName !== undefined && { display_name: displayName }),
            properties: {
                ...normalizedProperties
            }
        };
        const { url, options } = (0, request_params_1.createUserRequestParams)(settings, requestBody);
        return request(url, options);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map