"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestApiIntegrationPlugin = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
const index_js_2 = require("./shared/index.js");
exports.RestApiIntegrationPlugin = {
    id: index_js_1.ExtendedIntegrationPluginId.REST_API,
    name: 'REST API',
    moduleName: 'RestApiIntegrationPlugin',
    modulePath: 'plugins/restApiIntegration/RestApiIntegrationPlugin',
    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,
    hasTest: false,
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        placeholder: 'Example API',
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        name: 'urlBase',
                        label: 'Base URL',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_WITH_METADATA_OPTIONS,
                        placeholder: 'https://www.example.com/api',
                        rules: [{ required: true, message: 'Base URL is required' }],
                        valueAccessor: 'url',
                        listAccessor: 'metadata.openApiSpec.servers'
                    },
                    {
                        label: 'OpenAPI spec name',
                        name: 'openApiSpecRef',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        hidden: true
                    }
                ]
            },
            ...(0, index_js_2.authSections)({
                startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                pluginId: index_js_1.ExtendedIntegrationPluginId.REST_API,
                pluginName: 'REST API',
                enabledMethods: {
                    basic: true,
                    firebase: true,
                    oauth: true,
                    bearer: true,
                    apiKey: true
                }
            }),
            {
                name: 'tabs',
                layout: index_js_1.FormSectionLayout.TABS,
                items: [
                    {
                        name: index_js_2.RestApiIntegrationPluginMergedFieldNames.HEADERS,
                        label: 'Headers',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST,
                        secretsNames: ['Authorization']
                    },
                    {
                        name: index_js_2.RestApiIntegrationPluginMergedFieldNames.PARAMS,
                        label: 'Params',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        name: 'openApiAction',
                        label: 'Action',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.OPENAPI_ACTION_DROPDOWN,
                        initialValue: index_js_1.GENERIC_HTTP_REQUEST
                    },
                    {
                        gridCss: {
                            gridTemplateColumns: '120px calc(100% - 130px)'
                        },
                        rowItems: [
                            {
                                name: index_js_1.RestApiFields.HTTP_METHOD,
                                label: '',
                                startVersion: index_js_2.RestApiIntegrationPluginVersions.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.URL_PATH,
                                label: '',
                                startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                                componentType: index_js_1.FormComponentType.URL_INPUT_TEXT,
                                placeholder: '/v1/users'
                            }
                        ]
                    }
                ]
            },
            {
                name: 'auth',
                items: [
                    {
                        name: index_js_1.RestApiFields.AUTH_TYPE,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.AUTH_TYPE),
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        disabled: true,
                        hidden: true,
                        initialValue: index_js_1.IntegrationAuthType.NONE,
                        options: Object.values(index_js_1.IntegrationAuthType).map((authType) => ({
                            displayName: (0, index_js_1.getDisplayName)(authType),
                            value: authType,
                            key: authType
                        }))
                    }
                ]
            },
            {
                name: 'tabs',
                layout: index_js_1.FormSectionLayout.TABS,
                items: [
                    {
                        name: index_js_2.RestApiIntegrationPluginMergedFieldNames.HEADERS,
                        label: 'Headers',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST,
                        collapseValue: 'Hide auto-generated headers'
                    },
                    {
                        name: index_js_2.RestApiIntegrationPluginMergedFieldNames.PARAMS,
                        label: 'Query parameters',
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.FIELD_LIST,
                        collapseValue: 'Hide auto-generated parameters'
                    },
                    {
                        name: index_js_1.RestApiFields.BODY,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.BODY),
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.V1,
                        endVersion: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.FIELD_LIST_FORM,
                        display: {
                            show: {
                                bodyType: [index_js_1.RestApiBodyDataType.FORM]
                            }
                        }
                    },
                    {
                        name: index_js_1.RestApiFields.FILE_FORM_KEY,
                        label: (0, index_js_1.getRestApiFieldDisplayName)(index_js_1.RestApiFields.FILE_FORM_KEY),
                        startVersion: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.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: index_js_2.RestApiIntegrationPluginVersions.V14,
                        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: index_js_2.RestApiIntegrationPluginVersions.V14,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: false,
                        showConfirm: false,
                        renderIconFirst: true,
                        inverseValue: true
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=restApiIntegration.js.map