"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const optimizely_client_1 = require("./optimizely-client");
const action = {
    title: 'Sync Audience',
    description: 'Sync a Segment Engage Audience to Optimizely Data Platform',
    defaultSubscription: 'type = "track" or type = "identify"',
    fields: {
        custom_audience_name: {
            label: 'Custom Audience Name',
            description: 'Name of custom audience to add or remove the user from',
            type: 'string',
            unsafe_hidden: true,
            required: true,
            default: {
                '@path': '$.context.personas.computation_key'
            }
        },
        segment_computation_action: {
            label: 'Segment Computation Action',
            description: "Hidden field used to verify that the payload is generated by an Audience. Payloads not containing computation_class = 'audience' or 'journey_step' will be dropped before the perform() fuction call.",
            type: 'string',
            unsafe_hidden: true,
            required: true,
            default: {
                '@path': '$.context.personas.computation_class'
            },
            choices: [{ label: 'Audience', value: 'audience' }, { label: 'journey_step', value: 'journey_step' }]
        },
        segment_computation_id: {
            label: 'Segment Computation ID',
            description: 'Segment computation ID',
            type: 'string',
            unsafe_hidden: true,
            required: true,
            default: {
                '@path': '$.context.personas.computation_id'
            }
        },
        optimizelyUserId: {
            label: 'Optimizely User ID',
            description: 'The user identifier to sync to the Optimizely Audience',
            type: 'string',
            required: true,
            allowNull: false,
            default: {
                '@if': {
                    exists: { '@path': '$.userId' },
                    then: { '@path': '$.userId' },
                    else: { '@path': '$.anonymousId' }
                }
            }
        },
        timestamp: {
            label: 'Timestamp',
            type: 'string',
            unsafe_hidden: true,
            required: true,
            description: 'Timestamp indicates when the user was added or removed from the Audience',
            default: {
                '@path': '$.timestamp'
            }
        },
        enable_batching: {
            label: 'Enable Batching',
            description: 'Enable batching of event data to Optimizely.',
            type: 'boolean',
            default: true,
            unsafe_hidden: true
        },
        batch_size: {
            label: 'Batch Size',
            description: 'Number of events to batch before sending to Optimizely.',
            type: 'integer',
            default: 100,
            unsafe_hidden: true
        },
        batch_keys: {
            label: 'Batch Keys',
            description: 'The keys to use for batching events.',
            type: 'string',
            multiple: true,
            required: false,
            default: ['custom_audience_name'],
            unsafe_hidden: true
        },
        traitsOrProperties: {
            label: 'Traits or Properties',
            description: 'User traits (for identify calls) or event properties (for track calls) to include with the audience sync.',
            type: 'object',
            required: false,
            unsafe_hidden: true,
            default: {
                '@if': {
                    exists: { '@path': '$.traits' },
                    then: { '@path': '$.traits' },
                    else: { '@path': '$.properties' }
                }
            }
        }
    },
    perform: async (request, data) => {
        const optimizelyClient = new optimizely_client_1.OptimizelyClient(request, data);
        await optimizelyClient.send();
    },
    performBatch: async (request, data) => {
        const optimizelyClient = new optimizely_client_1.OptimizelyClient(request, data);
        await optimizelyClient.send();
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map