UNPKG

@tuanltntu/n8n-nodes-bitrix24

Version:

Comprehensive n8n community node for Bitrix24 API integration with CRM, Tasks, Chat, Telephony, and more

97 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestConnectionResourceHandler = void 0; const n8n_workflow_1 = require("n8n-workflow"); const ResourceHandlerBase_1 = require("./ResourceHandlerBase"); /** * Handles test connection operations for Bitrix24 */ class TestConnectionResourceHandler extends ResourceHandlerBase_1.ResourceHandlerBase { constructor(executeFunctions, returnData, options = {}) { super(executeFunctions, returnData, options); } /** * Process test connection operations */ async process() { for (let i = 0; i < this.items.length; i++) { try { const operation = this.getNodeParameter("operation", i); switch (operation) { case "testOAuth2": await this.handleTestOAuth2(i); break; case "testWebhook": await this.handleTestWebhook(i); break; default: throw new n8n_workflow_1.NodeOperationError(this.executeFunctions.getNode(), `The operation "${operation}" is not supported for test connection`, { itemIndex: i }); } } catch (error) { if (this.continueOnFail()) { this.returnData.push({ json: { error: error.message } }); continue; } throw error; } } return this.returnData; } /** * Test OAuth2 connection */ async handleTestOAuth2(itemIndex) { console.log("TestConnectionResourceHandler: Testing OAuth2 connection..."); const result = await this.testOAuth2Connection(itemIndex); // Add detailed connection diagnostics to the return data this.returnData.push({ json: { success: result.success, connectionType: "OAuth2", timestamp: new Date().toISOString(), details: result, }, }); } /** * Test webhook connection */ async handleTestWebhook(itemIndex) { console.log("TestConnectionResourceHandler: Testing webhook connection..."); try { // Make a simple API call using webhook auth const endpoint = "user.current"; const result = await this.makeApiCall(endpoint, {}, {}, itemIndex); console.log("TestConnectionResourceHandler: Webhook test result:", JSON.stringify(result, null, 2)); // Determine if test was successful const success = result && !result.error; // Add connection diagnostics to the return data this.returnData.push({ json: { success, connectionType: "Webhook", timestamp: new Date().toISOString(), details: result, }, }); } catch (error) { console.error("TestConnectionResourceHandler: Webhook test failed:", error); this.returnData.push({ json: { success: false, connectionType: "Webhook", timestamp: new Date().toISOString(), error: error.message, details: error, }, }); if (!this.continueOnFail()) { throw error; } } } } exports.TestConnectionResourceHandler = TestConnectionResourceHandler; //# sourceMappingURL=TestConnectionResourceHandler.js.map