"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmtpPlugin = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
// TODO (jason) change these constant values as these are pulled from Sendgrid
// superblocksmail is set up as a verified domain in Sendgrid under a different account than superblockshq.com.
// The current setup allows us to use any address with that domain.
const SMTP_INTEGRATION_SENDER_ADDRESS_DEFAULT = 'app@acme.com';
const SMTP_INTEGRATION_SENDER_NAME_DEFAULT = 'Acme App';
const SmtpPluginVersions = {
    V1: '0.0.1'
};
var SmtpActionFieldNames;
(function (SmtpActionFieldNames) {
    SmtpActionFieldNames["FROM"] = "from";
    SmtpActionFieldNames["TO"] = "to";
    SmtpActionFieldNames["REPLY_TO"] = "replyTo";
    SmtpActionFieldNames["CC"] = "cc";
    SmtpActionFieldNames["BCC"] = "bcc";
    SmtpActionFieldNames["SUBJECT"] = "subject";
    SmtpActionFieldNames["BODY"] = "body";
    SmtpActionFieldNames["ATTACHMENTS"] = "attachments";
})(SmtpActionFieldNames || (SmtpActionFieldNames = {}));
var SmtpDatasourceFieldNames;
(function (SmtpDatasourceFieldNames) {
    SmtpDatasourceFieldNames["HOST"] = "connection.host";
    SmtpDatasourceFieldNames["PORT"] = "connection.port";
    SmtpDatasourceFieldNames["USERNAME"] = "connection.username";
    SmtpDatasourceFieldNames["PASSWORD"] = "connection.password";
    SmtpDatasourceFieldNames["SECURE"] = "connection.secure";
})(SmtpDatasourceFieldNames || (SmtpDatasourceFieldNames = {}));
const SmtpActionFieldsMap = {
    [SmtpActionFieldNames.FROM]: {
        name: SmtpActionFieldNames.FROM,
        label: 'From',
        startVersion: SmtpPluginVersions.V1,
        // Using the defaults directly since we will have to refactor this plugin when we allow
        // user specified API key and/or sender through delegation.
        placeholder: `"${SMTP_INTEGRATION_SENDER_NAME_DEFAULT}" <${SMTP_INTEGRATION_SENDER_ADDRESS_DEFAULT}>`,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        rules: [{ required: true, message: 'From is required' }]
    },
    [SmtpActionFieldNames.REPLY_TO]: {
        name: SmtpActionFieldNames.REPLY_TO,
        label: 'Reply To',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: 'helpdesk@acme.com',
        rules: [{ required: false }]
    },
    [SmtpActionFieldNames.TO]: {
        name: SmtpActionFieldNames.TO,
        label: 'To',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: 'jane@acme.com, rahul@acme.com',
        rules: [{ required: true, message: 'To is required' }]
    },
    [SmtpActionFieldNames.CC]: {
        name: SmtpActionFieldNames.CC,
        label: 'Cc',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: 'emilia@acme.com, jose@acme.com'
    },
    [SmtpActionFieldNames.BCC]: {
        name: SmtpActionFieldNames.BCC,
        label: 'Bcc',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: 'huang@acme.com, sofia@acme.com'
    },
    [SmtpActionFieldNames.SUBJECT]: {
        name: SmtpActionFieldNames.SUBJECT,
        label: 'Subject',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: 'Daily Usage Report',
        rules: [{ required: true, message: 'Subject is required' }]
    },
    [SmtpActionFieldNames.BODY]: {
        name: SmtpActionFieldNames.BODY,
        label: 'Body',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: `Supports both plain text and html. For example:
<h3 style="color:Tomato;">There were a total of {{Step1.output.count}} API calls made today.</h3>`,
        style: {
            minHeight: '100px'
        },
        rules: [{ required: true, message: 'Body is required' }]
    },
    [SmtpActionFieldNames.ATTACHMENTS]: {
        name: SmtpActionFieldNames.ATTACHMENTS,
        label: 'File Attachments Object Array',
        startVersion: SmtpPluginVersions.V1,
        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
        placeholder: `Specify email attachments as an array of Superblocks file entities in one of the following ways:

1. Use uploaded files directly:
{{FilePicker1.files}}

2. Specify files programmatically:
{{[ { name: "test.csv", contents: Step1.output, type: "text/csv" },
FilePicker1.files[0] ]}}
    `,
        style: {
            minHeight: '100px'
        }
    }
};
exports.SmtpPlugin = {
    id: 'smtp',
    name: 'SMTP',
    moduleName: 'SmtpPlugin',
    modulePath: 'plugins/smtp/SmtpPlugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/smtp.png`,
    // TODO(docs-v2): no smtp page exists in docs-v2; add one or remove this line
    docsUrl: undefined,
    type: index_js_1.PluginType.API,
    responseType: index_js_1.PluginResponseType.JSON,
    hasRawRequest: true,
    rawRequestName: 'Executed request',
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: SmtpPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        placeholder: 'SMTP Server',
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Host',
                        name: SmtpDatasourceFieldNames.HOST,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Host is required' }],
                        startVersion: SmtpPluginVersions.V1
                    },
                    {
                        label: 'Port',
                        name: SmtpDatasourceFieldNames.PORT,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Port is required' }],
                        initialValue: '587',
                        startVersion: SmtpPluginVersions.V1
                    },
                    {
                        label: 'Username',
                        name: SmtpDatasourceFieldNames.USERNAME,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Username is required' }],
                        startVersion: SmtpPluginVersions.V1
                    },
                    {
                        label: 'Password',
                        name: SmtpDatasourceFieldNames.PASSWORD,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Password is required' }],
                        startVersion: SmtpPluginVersions.V1,
                        dataType: index_js_1.InputDataType.PASSWORD
                    },
                    {
                        label: 'Enable TLS',
                        name: SmtpDatasourceFieldNames.SECURE,
                        startVersion: SmtpPluginVersions.V1,
                        initialValue: false,
                        componentType: index_js_1.FormComponentType.CHECKBOX
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: Object.values(SmtpActionFieldsMap)
            }
        ]
    }
};
//# sourceMappingURL=smtp.js.map