UNPKG

n8n-nodes-digital-ocean

Version:

n8n community node to work with the Digital Ocean API

38 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.digitalOceanApiRequest = digitalOceanApiRequest; exports.digitalOceanApiRequestAllItems = digitalOceanApiRequestAllItems; async function digitalOceanApiRequest(method, resource, body = {}, qs = {}, uri, option = {}) { const authenticationMethod = this.getNodeParameter('authentication', 0); let options = { method: method, qs, body, url: uri || `https://api.digitalocean.com/v2/${resource}`, json: true, }; options = Object.assign({}, options, option); if (Object.keys(options.body).length === 0) { delete options.body; } const credentialType = authenticationMethod === 'accessToken' ? 'digitalOceanApi' : 'digitalOceanOAuth2Api'; return this.helpers.httpRequestWithAuthentication.call(this, credentialType, options); } async function digitalOceanApiRequestAllItems(propertyName, method, resource, body = {}, query = {}) { var _a, _b, _c; const returnData = []; let responseData; let uri; do { query.per_page = 20; responseData = await digitalOceanApiRequest.call(this, method, resource, body, query, uri); uri = ((_a = responseData.links.pages) === null || _a === void 0 ? void 0 : _a.next) || undefined; returnData.push.apply(returnData, responseData[propertyName]); const limit = query.limit; if (limit && limit <= returnData.length) { return returnData; } } while (((_b = responseData.links.pages) === null || _b === void 0 ? void 0 : _b.next) !== undefined && ((_c = responseData.links.pages) === null || _c === void 0 ? void 0 : _c.next) !== null); return returnData; } //# sourceMappingURL=GenericFunctions.js.map