UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

70 lines 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.microsoftApiRequest = microsoftApiRequest; exports.microsoftApiRequestAllItems = microsoftApiRequestAllItems; exports.microsoftApiRequestAllItemsSkip = microsoftApiRequestAllItemsSkip; exports.prepareMessage = prepareMessage; const n8n_workflow_1 = require("n8n-workflow"); async function microsoftApiRequest(method, resource, body = {}, qs = {}, uri, headers = {}) { const options = { headers: { 'Content-Type': 'application/json', }, method, body, qs, uri: uri || `https://graph.microsoft.com${resource}`, json: true, }; try { if (Object.keys(headers).length !== 0) { options.headers = Object.assign({}, options.headers, headers); } return await this.helpers.requestOAuth2.call(this, 'microsoftTeamsOAuth2Api', options); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), error); } } async function microsoftApiRequestAllItems(propertyName, method, endpoint, body = {}, query = {}) { const returnData = []; let responseData; let uri; do { responseData = await microsoftApiRequest.call(this, method, endpoint, body, query, uri); uri = responseData['@odata.nextLink']; returnData.push.apply(returnData, responseData[propertyName]); const limit = query.limit; if (limit && limit <= returnData.length) { return returnData; } } while (responseData['@odata.nextLink'] !== undefined); return returnData; } async function microsoftApiRequestAllItemsSkip(propertyName, method, endpoint, body = {}, query = {}) { const returnData = []; let responseData; query.$top = 100; query.$skip = 0; do { responseData = await microsoftApiRequest.call(this, method, endpoint, body, query); query.$skip += query.$top; returnData.push.apply(returnData, responseData[propertyName]); } while (responseData.value.length !== 0); return returnData; } function prepareMessage(message, messageType, includeLinkToWorkflow, instanceId) { if (includeLinkToWorkflow) { const { id } = this.getWorkflow(); const link = `${this.getInstanceBaseUrl()}workflow/${id}?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent('n8n-nodes-base.microsoftTeams')}${instanceId ? '_' + instanceId : ''}`; messageType = 'html'; message = `${message}<br><br><em> Powered by <a href="${link}">this n8n workflow</a> </em>`; } return { body: { contentType: messageType, content: message, }, }; } //# sourceMappingURL=GenericFunctions.js.map