UNPKG

@oneacrefund/n8n-nodes-kutt

Version:

This is an n8n community node for the Kutt URL Shortening service

45 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.kuttApiRequest = void 0; async function kuttApiRequest(option = {}) { const credentials = (await this.getCredentials('kuttCredentialsApi')); const options = { baseURL: String(credentials.baseUrl), url: '', headers: { 'X-API-KEY': credentials.token, }, json: true, }; if (Object.keys(option)) { Object.assign(options, option); } const scrollValue = option.scroll; const LIMIT = 50; if (scrollValue) { let skip = 0; let response = []; let fetchMore = true; while (fetchMore) { if (options.qs) { options.qs.skip = skip; options.qs.limit = LIMIT; } else { options.qs = { skip, limit: LIMIT }; } const batch = await this.helpers.httpRequest(options); if (batch && batch['data'] && batch['data'].length) { response = response.concat(batch['data']); } fetchMore = batch && batch.total && batch.total > response.length; skip = response.length; } return response; } else { return await this.helpers.httpRequest(options); } } exports.kuttApiRequest = kuttApiRequest; //# sourceMappingURL=GenericFunctions.js.map