UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

42 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.googleApiRequest = googleApiRequest; const n8n_workflow_1 = require("n8n-workflow"); const GenericFunctions_1 = require("../GenericFunctions"); async function googleApiRequest(method, resource, body = {}, qs = {}) { const authenticationMethod = this.getNodeParameter('authentication', 0, 'serviceAccount'); const options = { headers: { 'Content-Type': 'application/json', }, method, body, qs, uri: `https://slides.googleapis.com/v1${resource}`, json: true, }; if (!Object.keys(body).length) { delete options.body; } if (!Object.keys(qs).length) { delete options.qs; } try { if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); const { access_token } = await GenericFunctions_1.getGoogleAccessToken.call(this, credentials, 'slides'); options.headers.Authorization = `Bearer ${access_token}`; return await this.helpers.request(options); } else { return await this.helpers.requestOAuth2.call(this, 'googleSlidesOAuth2Api', options); } } catch (error) { if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') { error.statusCode = '401'; } throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } //# sourceMappingURL=GenericFunctions.js.map