diff --git a/package-lock.json b/package-lock.json index eb9094a..d18e5dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "auth0-deploy-cli-extension", - "version": "2.3.1", + "version": "2.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3dfbe85..d6d58ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-deploy-cli-extension", - "version": "2.3.1", + "version": "2.3.2", "description": "The Auth0 Deploy Extension allows you to use the Auth0 Deploy CLI to configure your Auth0 Tenant", "engines": { "node": ">=8" diff --git a/server/lib/queries.js b/server/lib/queries.js index 4ba1064..4bcb6f7 100644 --- a/server/lib/queries.js +++ b/server/lib/queries.js @@ -3,6 +3,8 @@ import request from 'superagent'; import { managementApi } from 'auth0-extension-tools'; import config from './config'; +const PER_PAGE = 100; + const getToken = (req) => { const isAdministrator = req.user && req.user.access_token && req.user.access_token.length; if (isAdministrator) { @@ -12,11 +14,11 @@ const getToken = (req) => { return managementApi.getAccessTokenCached(config('AUTH0_DOMAIN'), config('AUTH0_CLIENT_ID'), config('AUTH0_CLIENT_SECRET')); }; -const makeRequest = (req, path, method, payload) => +const makeRequest = (req, path, method, query) => new Promise((resolve) => getToken(req).then(token => { request(method, `https://${config('AUTH0_DOMAIN')}/api/v2/${path}`) - .send(payload || {}) + .query(query) .set('Content-Type', 'application/json') .set('Authorization', `Bearer ${token}`) .end((err, res) => { @@ -28,8 +30,21 @@ const makeRequest = (req, path, method, payload) => }); })); +const requestAll = (req, resource, page, allResults) => { + page = page || 0; + allResults = allResults || []; + return makeRequest(req, resource, 'GET', { page, per_page: PER_PAGE }).then((result) => { + allResults = allResults.concat(result || []); + if (result && result.length === PER_PAGE) { + return requestAll(req, resource, page + 1, allResults); + } else { + return allResults; + } + }); +}; + export const getResourceServer = (req, identifier) => - makeRequest(req, 'resource-servers', 'GET') + requestAll(req, 'resource-servers') .then(items => items.find(item => item.identifier === identifier)); export const getClient = (req, clientId) =>