UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

32 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deepLApiRequest = deepLApiRequest; const n8n_workflow_1 = require("n8n-workflow"); async function deepLApiRequest(method, resource, body = {}, qs = {}, uri, headers = {}) { const proApiEndpoint = 'https://api.deepl.com/v2'; const freeApiEndpoint = 'https://api-free.deepl.com/v2'; const credentials = await this.getCredentials('deepLApi'); const options = { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, method, form: body, qs, uri: uri || `${credentials.apiPlan === 'pro' ? proApiEndpoint : freeApiEndpoint}${resource}`, json: true, }; try { if (Object.keys(headers).length !== 0) { options.headers = Object.assign({}, options.headers, headers); } if (Object.keys(body).length === 0) { delete options.body; } return await this.helpers.requestWithAuthentication.call(this, 'deepLApi', options); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } //# sourceMappingURL=GenericFunctions.js.map