From c494b047cd96a6690b780140d95a84912e964e59 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Wed, 10 Apr 2019 17:43:39 -0700 Subject: [PATCH 1/2] Add micro-api-client pagination This still requires the pagination parameters to be added to open-api. This is also a breaking change, unfortunately. --- src/open-api/index.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/open-api/index.js b/src/open-api/index.js index 859a5e2..266ec46 100644 --- a/src/open-api/index.js +++ b/src/open-api/index.js @@ -5,7 +5,7 @@ const http = require('http') const fetch = require('node-fetch').default || require('node-fetch') // Webpack will sometimes export default exports in different places const Headers = require('node-fetch').Headers const camelCase = require('lodash.camelcase') -const { JSONHTTPError, TextHTTPError } = require('micro-api-client') +const { JSONHTTPError, TextHTTPError, getPagination } = require('micro-api-client') const debug = require('debug')('netlify:open-api') const { existy, sleep, unixNow } = require('./util') const isStream = require('is-stream') @@ -87,8 +87,6 @@ exports.generateMethod = method => { opts.method = method.verb.toUpperCase() debug(`method: ${opts.method}`) - // TODO: Consider using micro-api-client when it supports node-fetch - async function makeRequest() { let response try { @@ -161,10 +159,8 @@ exports.generateMethod = method => { if (!response.ok) { throw new JSONHTTPError(response, json) } - // TODO: Support pagination - // const pagination = getPagination(response) - // return pagination ? { pagination, items: json } : json - return json + const pagination = getPagination(response) + return pagination ? { pagination, items: json } : json } debug('parsing text') From 9a0f05769ac27b06ce863d3f712dc88bc0bd565f Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Wed, 10 Apr 2019 18:32:59 -0700 Subject: [PATCH 2/2] Add pagination in a non-breaking manner. --- src/open-api/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/open-api/index.js b/src/open-api/index.js index 266ec46..31b48a9 100644 --- a/src/open-api/index.js +++ b/src/open-api/index.js @@ -160,7 +160,8 @@ exports.generateMethod = method => { throw new JSONHTTPError(response, json) } const pagination = getPagination(response) - return pagination ? { pagination, items: json } : json + if (existy(pagination)) json.pagination = pagination + return json } debug('parsing text')