"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestApiPlugin = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
const RestApiPluginVersions = {
    V1: '0.0.1',
    V7: '0.0.7',
    V8: '0.0.8',
    V13: '0.0.13'
};
exports.RestApiPlugin = {
    id: index_js_1.REST_API_BASE_PLUGIN_ID,
    name: 'REST API',
    moduleName: 'RestApiPlugin',
    modulePath: 'plugins/restApi/RestApiPlugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/restapi.png`,
    docsUrl: `${constants_js_1.DOCS_BASE_URL}/rest-api`,
    isStreamable: true,
    type: index_js_1.PluginType.API,
    responseType: index_js_1.PluginResponseType.JSON,
    hasRawRequest: true,
    rawRequestName: 'Executed request',
    datasourceTemplate: {
        sections: []
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        gridCss: {
                            gridTemplateColumns: '120px calc(100% - 130px)'
                        },
                        rowItems: [
                            {
                                name: index_js_1.RestApiFields.HTTP_METHOD,
                                label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.HTTP_METHOD),
                                startVersion: RestApiPluginVersions.V1,
                                componentType: index_js_1.FormComponentType.DROPDOWN,
                                initialValue: index_js_1.HttpMethod.GET,
                                rules: [{ required: true }],
                                renderSelectedOptionWithStyles: true,
                                options: [
                                    {
                                        key: index_js_1.HttpMethod.GET,
                                        value: index_js_1.HttpMethod.GET,
                                        displayName: index_js_1.HttpMethod.GET,
                                        textColor: (0, index_js_1.getMethodColor)(index_js_1.HttpMethod.GET)
                                    },
                                    {
                                        key: index_js_1.HttpMethod.POST,
                                        value: index_js_1.HttpMethod.POST,
                                        displayName: index_js_1.HttpMethod.POST,
                                        textColor: (0, index_js_1.getMethodColor)(index_js_1.HttpMethod.POST)
                                    },
                                    {
                                        key: index_js_1.HttpMethod.PUT,
                                        value: index_js_1.HttpMethod.PUT,
                                        displayName: index_js_1.HttpMethod.PUT,
                                        textColor: (0, index_js_1.getMethodColor)(index_js_1.HttpMethod.PUT)
                                    },
                                    {
                                        key: index_js_1.HttpMethod.DELETE,
                                        value: index_js_1.HttpMethod.DELETE,
                                        displayName: index_js_1.HttpMethod.DELETE,
                                        textColor: (0, index_js_1.getMethodColor)(index_js_1.HttpMethod.DELETE)
                                    },
                                    {
                                        key: index_js_1.HttpMethod.PATCH,
                                        value: index_js_1.HttpMethod.PATCH,
                                        displayName: index_js_1.HttpMethod.PATCH,
                                        textColor: (0, index_js_1.getMethodColor)(index_js_1.HttpMethod.PATCH)
                                    }
                                ]
                            },
                            {
                                name: index_js_1.RestApiFields.PATH,
                                label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.PATH),
                                startVersion: RestApiPluginVersions.V1,
                                componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                                placeholder: 'https://www.example.com/api?filter={{Dropdown1.selectedOptionValue}}',
                                rules: [{ required: true, message: 'URL is required' }]
                            }
                        ],
                        subtitle: `Authenticating with OAuth 2.0, Firebase, or Basic Auth? Create a [REST API Integration](/integrations/restapiintegration)`
                    }
                ]
            },
            {
                name: 'tabs',
                layout: index_js_1.FormSectionLayout.TABS,
                items: [
                    {
                        name: index_js_1.RestApiFields.HEADERS,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.HEADERS),
                        startVersion: RestApiPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST,
                        initialValue: [
                            { key: 'Content-Type', value: 'application/json' },
                            { key: '', value: '' }
                        ],
                        secretsNames: ['Authorization']
                    },
                    {
                        name: index_js_1.RestApiFields.PARAMS,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.PARAMS),
                        startVersion: RestApiPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST,
                        initialValue: [{ key: '', value: '' }]
                    },
                    {
                        name: index_js_1.RestApiFields.BODY,
                        label: (0, index_js_1.getRestApiBodyLabel)(index_js_1.RestApiBodyDataType.JSON),
                        startVersion: RestApiPluginVersions.V1,
                        endVersion: RestApiPluginVersions.V7,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.JSON
                    },
                    {
                        name: index_js_1.RestApiFields.BODY_TYPE,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.BODY_TYPE),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: index_js_1.RestApiBodyDataType.JSON,
                        options: Object.values(index_js_1.RestApiBodyDataType).map((bodyType) => ({
                            displayName: (0, index_js_1.getRestApiDataTypeDisplayName)(bodyType),
                            value: bodyType,
                            key: bodyType
                        }))
                    },
                    {
                        name: index_js_1.RestApiFields.BODY,
                        label: (0, index_js_1.getRestApiBodyLabel)(index_js_1.RestApiBodyDataType.JSON),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.JSON,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.JSON]
                            }
                        }
                    },
                    {
                        name: index_js_1.RestApiFields.BODY,
                        label: (0, index_js_1.getRestApiBodyLabel)(index_js_1.RestApiBodyDataType.RAW),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.TEXT,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.RAW]
                            }
                        }
                    },
                    {
                        name: index_js_1.RestApiFields.FORM_DATA,
                        label: (0, index_js_1.getRestApiBodyLabel)(index_js_1.RestApiBodyDataType.FORM),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.FIELD_LIST_FORM,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.FORM]
                            }
                        },
                        initialValue: [{ key: '', value: '' }]
                    },
                    {
                        name: index_js_1.RestApiFields.FILE_FORM_KEY,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.FILE_FORM_KEY),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        initialValue: 'file',
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.FILE_FORM]
                            }
                        }
                    },
                    {
                        name: index_js_1.RestApiFields.FILE_NAME,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.FILE_NAME),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.FILE_FORM]
                            }
                        }
                    },
                    {
                        name: index_js_1.RestApiFields.BODY,
                        label: (0, index_js_1.getRestApiBodyLabel)(index_js_1.RestApiBodyDataType.FILE_FORM),
                        startVersion: RestApiPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.TEXT,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.FILE_FORM]
                            }
                        }
                    }
                ]
            },
            {
                name: 'bottom',
                items: [
                    {
                        name: index_js_1.RestApiFields.RESPONSE_TYPE,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.RESPONSE_TYPE),
                        startVersion: RestApiPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: index_js_1.ActionResponseType.AUTO,
                        rules: [{ required: true }],
                        options: [
                            {
                                key: index_js_1.ActionResponseType.AUTO,
                                value: index_js_1.ActionResponseType.AUTO,
                                displayName: 'Auto'
                            },
                            {
                                key: index_js_1.ActionResponseType.JSON,
                                value: index_js_1.ActionResponseType.JSON,
                                displayName: 'JSON'
                            },
                            {
                                key: index_js_1.ActionResponseType.TEXT,
                                value: index_js_1.ActionResponseType.TEXT,
                                displayName: 'Text'
                            },
                            {
                                key: index_js_1.ActionResponseType.BINARY,
                                value: index_js_1.ActionResponseType.BINARY,
                                displayName: 'Binary'
                            },
                            {
                                key: index_js_1.ActionResponseType.RAW,
                                value: index_js_1.ActionResponseType.RAW,
                                displayName: 'Raw'
                            }
                        ]
                    }
                ]
            },
            {
                name: 'additionalSettings',
                sectionHeader: 'Additional Settings',
                isCollapsible: true,
                defaultCollapsed: true,
                asTitle: false,
                items: [
                    {
                        name: index_js_1.RestApiFields.VERBOSE_HTTP_OUTPUT,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.VERBOSE_HTTP_OUTPUT),
                        lightLabelText: true,
                        startVersion: RestApiPluginVersions.V13,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: false,
                        showConfirm: false,
                        renderIconFirst: true
                    },
                    {
                        name: index_js_1.RestApiFields.DO_NOT_FAIL_ON_REQUEST_ERROR,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.DO_NOT_FAIL_ON_REQUEST_ERROR),
                        lightLabelText: true,
                        startVersion: RestApiPluginVersions.V13,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: false,
                        showConfirm: false,
                        renderIconFirst: true,
                        inverseValue: true
                    }
                ]
            }
        ]
    },
    demoData: {
        path: 'https://xkcd.com/info.0.json',
        httpMethod: index_js_1.HttpMethod.GET
    }
};
//# sourceMappingURL=restApi.js.map