UNPKG

n8n-nodes-tanss-api

Version:
81 lines 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TanssAuthentication = void 0; const n8n_workflow_1 = require("n8n-workflow"); class TanssAuthentication { constructor() { this.description = { displayName: 'TANSS Authentication', name: 'tanssAuthentication', icon: 'file:tanss.svg', group: ['transform'], version: 1, subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}', description: 'Handles TANSS API Authentication', defaults: { name: 'TANSS Authentication', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'tanssApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', options: [ { name: 'Login', value: 'login', description: 'Login to the TANSS API', action: 'Login to the TANSS API', }, ], default: 'login', noDataExpression: true, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const credentials = await this.getCredentials('tanssApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials returned!'); } for (let i = 0; i < items.length; i++) { const operation = this.getNodeParameter('operation', i); if (operation === 'login') { const username = credentials.username; const password = credentials.password; const baseURL = credentials.baseURL; const url = `${baseURL.replace(/\/+$/, '')}/backend/api/v1/login`; const requestOptions = { method: 'POST', url, body: { username, password }, json: true, }; try { const responseData = await this.helpers.request(requestOptions); returnData.push({ json: responseData }); } catch (error) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Login failed: ${error.message}`); } } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The operation "${operation}" is not recognized.`); } } return [returnData]; } } exports.TanssAuthentication = TanssAuthentication; //# sourceMappingURL=TanssAuthentication.node.js.map