From 6941beec65f337e63b0429d342a5fb80e7561727 Mon Sep 17 00:00:00 2001 From: Michael Polidori Date: Thu, 9 Mar 2023 07:58:37 -0500 Subject: [PATCH] Add getPackages for generating sitemap (#251) --- lib/dms.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/dms.js b/lib/dms.js index f518ea98..d8514ded 100644 --- a/lib/dms.js +++ b/lib/dms.js @@ -13,10 +13,17 @@ class DmsModel { } async getJsonResponse(params, action) { + let url - let query = querystring.stringify(params) + if (params !== {}) { + + let query = querystring.stringify(params) + + url = new URL(resolve(this.api, action + '?' + query)) + } else { + url = new URL(resolve(this.api, action)) + } - let url = new URL(resolve(this.api, action + '?' + query)) let response = await fetch(url, { headers: { 'User-Agent': 'frontend-v2/latest (internal API call from frontend app)' } }) @@ -50,6 +57,18 @@ class DmsModel { return response.result } + async getPackages(context, limit = 1000, offset = 0) { + const action = 'package_search' + const params = { + rows: limit, + start: offset + } + + const response = await this.getJsonResponse(params, action) + + return response.result.results + } + async getPackage(name, includeViewsAndSchema = true) { const action = 'package_show' const params = {