UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

62 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.microsoftApiRequest = microsoftApiRequest; exports.microsoftApiRequestAllItems = microsoftApiRequestAllItems; exports.microsoftApiRequestAllItemsSkip = microsoftApiRequestAllItemsSkip; const n8n_workflow_1 = require("n8n-workflow"); async function microsoftApiRequest(method, resource, body = {}, qs = {}, uri, _headers = {}, option = { json: true }) { const credentials = await this.getCredentials('microsoftToDoOAuth2Api'); const baseUrl = (typeof credentials.graphApiBaseUrl === 'string' && credentials.graphApiBaseUrl !== '' ? credentials.graphApiBaseUrl : 'https://graph.microsoft.com').replace(/\/+$/, ''); const options = { headers: { 'Content-Type': 'application/json', }, method, body, qs, uri: uri || `${baseUrl}/v1.0/me${resource}`, }; try { Object.assign(options, option); if (Object.keys(qs).length === 0) { delete options.qs; } if (Object.keys(body).length === 0) { delete options.body; } return await this.helpers.requestOAuth2.call(this, 'microsoftToDoOAuth2Api', 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; query.$top = 100; do { responseData = await microsoftApiRequest.call(this, method, endpoint, body, query, uri); uri = responseData['@odata.nextLink']; if (uri?.includes('$top')) { delete query.$top; } returnData.push.apply(returnData, responseData[propertyName]); } 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; } //# sourceMappingURL=GenericFunctions.js.map