From 53b2ffc21e5b9b13149e254f7f3099cbc6d61aca Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 14:26:52 -0400 Subject: [PATCH] WIP: added get workspace method --- src/CollectionAdvanced.js | 29 +++++++++++++++++++++++++++++ src/DeployIncremental.js | 18 ++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index a96db63..a291834 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -77,6 +77,7 @@ class CollectionAdvanced extends Collection { // TODO: Add proper description const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection') folderCreateEnvironments.auth = this.authAPIKey() + folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id)) localCollection.item.splice(1, 0, folderCreateEnvironments) // insert test environment into Utils folder @@ -197,6 +198,34 @@ class CollectionAdvanced extends Collection { script.script.id = Utils.GenID(hash) // RB: to big for uuidv5 return script } + + // utilities end points from JSON file + + endPointGetWorkspaces (folderParentId) { + const endPoint = { + folder: folderParentId, + name: 'Get Workspaces', + description: "Gets all [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). The response includes your workspaces and any workspaces that you have access to.\n\n**Note:**\n\nThis endpoint's response contains the `visibility` field. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace:\n\n- `personal` — Only you can access the workspace.\n- `team` — All team members can access the workspace.\n- `private` — Only invited team members can access the workspace ([Professional and Enterprise plans only](https://www.postman.com/pricing)).\n- `public` — Everyone can access the workspace.\n- `partner` — Only invited team members and [partners](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/partner-workspaces/) can access the workspace ([Enterprise Ultimate plans](https://www.postman.com/pricing) only).", + method: 'GET', + url: 'https://api.getpostman.com/workspaces', + queryParams: [ + { + key: 'type', + value: '', + description: 'The type of workspace to filter the response by:\n\n* `personal`\n* `team`\n* `private`\n* `public`\n* `partner`', + enabled: false + }, + { + key: 'include', + value: '', + description: "Include the following information in the endpoint's response:\n- `mocks:deactivated` — Include all deactivated mock servers in the response.", + enabled: false + } + ] + } + endPoint.id = Utils.GenID(JSON.stringify(endPoint)) + return endPoint + } } module.exports = CollectionAdvanced diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index f44b2b4..0f6192b 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -114,6 +114,7 @@ const checkFolderSortChanges = (remoteCollection, localCollection) => { const remoteFolders = remoteCollection.collection.item .map(folder => ({ id: folder.id })) const localFolders = localCollection.item + .filter(folder => !folder.folder) .map(folder => ({ id: folder.id })) const remoteFoldersHash = GenID(JSON.stringify(remoteFolders)) @@ -200,6 +201,8 @@ async function mergeFolders (remoteCollection, localCollection) { const localFolders = localCollection.item const newFolders = localFolders.filter(localFolder => !remoteFolders.find(remoteFolder => remoteFolder.id === localFolder.id)) + + // TODO: RB: need a method to return all remot folders independent where they are in the collection const oldFolders = remoteFolders.filter(remoteFolder => !localFolders.find(localFolder => localFolder.id === remoteFolder.id)) let hasChanges = newFolders.length > 0 || oldFolders.length > 0 @@ -273,13 +276,18 @@ async function mergeRequests (remoteCollection, localCollection) { // // need to handle the case where the folder is empty // in that case the item property is undefined - const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) + let remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) // subfolders exist in the local collection as root folders // but in the remote collection they are in the parent folder // so we need to handle the case where the subfolder // exists as a root element in the local collection // but not in the remote collection + if (!remoteRemoteFolder) { + // try locating inside the first level items + remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.item.id === localFolder.item.id))) + } + if (!remoteRemoteFolder) { continue } @@ -308,7 +316,13 @@ async function mergeRequests (remoteCollection, localCollection) { // create new requests for (const request of newRequests) { - const pmRequest = pmConvert.requestFromLocal(request) + // check request format and convert if necessary + let pmRequest = null + if (!request.request) { // => Postman Format + pmRequest = request + } else { // => OpenAPI Format + pmRequest = pmConvert.requestFromLocal(request) + } const msg = ` Creating new request [${request.name}]` await new pmAPI.Request(remoteCollection.collection.info.uid)