Skip to content

Commit

Permalink
202406 postman update (#51)
Browse files Browse the repository at this point in the history
* update JS RSA Sign lib to v11_1_0

* default time out in all requests to 5 minutes

* default time out in all requests to 5 minutes

* fix typos

* fix lint

* fix form-data and binary body params missing
  • Loading branch information
barduinor authored Jun 17, 2024
1 parent 4c77b05 commit fb10165
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 57 deletions.
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"standard.enable": false
"standard.enable": false,
"cSpell.words": [
"apikey",
"formdata",
"JSRSA",
"noauth",
"OPENAPI",
"pmak",
"prerequest",
"uuidv",
"wokspaceid"
]
}
4 changes: 2 additions & 2 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ class Collection {
header: this.header(endpoint),
body: this.body(endpoint)
}
const requesstId = Utils.GenID(folderId + JSON.stringify(request))
request.id = requesstId
const requestId = Utils.GenID(folderId + JSON.stringify(request))
request.id = requestId
return request
}

Expand Down
16 changes: 8 additions & 8 deletions src/CollectionAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const Collection = require('./Collection')
* Main difference are:
* - The collectionPreRequest() method - PreScript for the collection
* - The authForEndPoint() method - All endpoints inherit from the collection
* - The defaultAuth() method - Default auth for collection is now Baearer Token
* - The getItemEvents() method - Items do not have events/scripts, these are inhereted from the collection
* - The defaultAuth() method - Default auth for collection is now Bearer Token
* - The getItemEvents() method - Items do not have events/scripts, these are inherited from the collection
*/
class CollectionAdvanced extends Collection {
/**
Expand Down Expand Up @@ -101,14 +101,14 @@ class CollectionAdvanced extends Collection {
localCollection.item.unshift(folderUtilities)

// insert create environment into Utils folder
let description = "These requests will help you to create an enviroment that will support the automatic token request or refresh.\n\nFor this you'll need:\n\n- A Postman API key that you can configure in your account settings\n- The ID of your workspace (you can use the \"Get Workspaces\" request to list them all)\n \n\nEach request will create the environment with the specific variables necessary for the token request or refresh.\n\nYou can fill in the required data on the request body, or alternatively, fill in the data in the environment.\n\nEither way this data will end up in your postman account.\n\nYou can create multiple environments for multiple Box Applications, and quickly switch betwene them.\n\n**Steps**:\n\n- Goto your account and under API keys generate a new api key\n- In Postman, under environments, global, create a varibale named personal-pm-pmak as a secret and paste the PMAK you created in the previous step. Remember to save.\n- In this collection, under the create environments, use the get workspaces to identify the current workspace, and copy its id.\n- In. Postman, under environments, global, create a variable named wokspaceid and paste the id you copied from the previous step. Remember to save.\n \n\nYou're all set."
let description = "These requests will help you to create an environment that will support the automatic token request or refresh.\n\nFor this you'll need:\n\n- A Postman API key that you can configure in your account settings\n- The ID of your workspace (you can use the \"Get Workspaces\" request to list them all)\n \n\nEach request will create the environment with the specific variables necessary for the token request or refresh.\n\nYou can fill in the required data on the request body, or alternatively, fill in the data in the environment.\n\nEither way this data will end up in your postman account.\n\nYou can create multiple environments for multiple Box Applications, and quickly switch between them.\n\n**Steps**:\n\n- Goto your account and under API keys generate a new api key\n- In Postman, under environments, global, create a variable named personal-pm-pmak as a secret and paste the PMAK you created in the previous step. Remember to save.\n- In this collection, under the create environments, use the get workspaces to identify the current workspace, and copy its id.\n- In. Postman, under environments, global, create a variable named wokspaceid and paste the id you copied from the previous step. Remember to save.\n \n\nYou're all set."
const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, description)
folderCreateEnvironments.auth = this.authAPIKey()
folderCreateEnvironments.id = null
folderCreateEnvironments.id = Utils.GenID(folderUtilities.id + JSON.stringify(folderCreateEnvironments))

folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id))
folderCreateEnvironments.item.push(this.endPointCreateBaererEnvironment(folderCreateEnvironments.id))
folderCreateEnvironments.item.push(this.endPointCreateBearerEnvironment(folderCreateEnvironments.id))
folderCreateEnvironments.item.push(this.endPointCreateOAuthEnvironment(folderCreateEnvironments.id))
folderCreateEnvironments.item.push(this.endPointCreateCCGEnvironment(folderCreateEnvironments.id))
folderCreateEnvironments.item.push(this.endPointCreateJWTEnvironment(folderCreateEnvironments.id))
Expand All @@ -123,7 +123,7 @@ class CollectionAdvanced extends Collection {
localCollection.item.splice(2, 0, folderTestEnvironments)

// insert Authorize OAuth Box App Helper into Utils folder
description = "I order to use OAuth 2.0, you must first authorize the application.\n\nYou also need to re-authorize the application if the refresh token has expired, which in case of Box is 60 days.\n\nTo use this you will need the following from your Box application:\n\n- Client ID\n- Cleint Secret\n- Redirect URI configured as: [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback)\n \n\nTo start the process:\n\n- Select an OAuth environment that has at least the cliend and secret id's\n- Open the authorization tab in Postman, scroll all the way down and press \"Get New Access Token\"\n \n\nTo view the token retreived using this helper:\n\n- Open this Authorization tab\n- Under. Current Token, Token\n \n\nUpdate your OAuth enviroment settings with the information from this token:\n\n- Copy the access token to access token\n- Copy refresh token to refresh token\n- You can ignore the expire at\n- But you must set the refresh token expires at\n- Add 4,000,000 to the time stamp you got back\n \n\nAs you use the api, new access and refresh tokens will be fetch automatically."
description = "I order to use OAuth 2.0, you must first authorize the application.\n\nYou also need to re-authorize the application if the refresh token has expired, which in case of Box is 60 days.\n\nTo use this you will need the following from your Box application:\n\n- Client ID\n- Client Secret\n- Redirect URI configured as: [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback)\n \n\nTo start the process:\n\n- Select an OAuth environment that has at least the client and secret id's\n- Open the authorization tab in Postman, scroll all the way down and press \"Get New Access Token\"\n \n\nTo view the token retrieved using this helper:\n\n- Open this Authorization tab\n- Under. Current Token, Token\n \n\nUpdate your OAuth environment settings with the information from this token:\n\n- Copy the access token to access token\n- Copy refresh token to refresh token\n- You can ignore the expire at\n- But you must set the refresh token expires at\n- Add 4,000,000 to the time stamp you got back\n \n\nAs you use the api, new access and refresh tokens will be fetch automatically."
const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, description)
folderAuthorizeOAuthBoxAppHelper.auth = this.authOAuth2AutoRefresh()
folderAuthorizeOAuthBoxAppHelper.id = null
Expand All @@ -140,7 +140,7 @@ class CollectionAdvanced extends Collection {
}

defaultAuth () {
// RB: Default auth for collection is now Baearer Token
// RB: Default auth for collection is now Bearer Token
return this.authBearerToken()
}

Expand Down Expand Up @@ -218,7 +218,7 @@ class CollectionAdvanced extends Collection {
* Adds a pre-request script to an API call
*/
getItemEvents (endpoint, itemId) {
// RB: Items do not have events/scripts, these are inhereted from the collection
// RB: Items do not have events/scripts, these are inherited from the collection
return []
}

Expand Down Expand Up @@ -280,7 +280,7 @@ class CollectionAdvanced extends Collection {
return endPoint
}

endPointCreateBaererEnvironment (folderParentId) {
endPointCreateBearerEnvironment (folderParentId) {
const endPoint = {
name: 'Create Bearer Token Environment',
dataMode: 'raw',
Expand Down
4 changes: 2 additions & 2 deletions src/CollectionAdvancedUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Utitlity objects specific for Postman Collection
// Utility objects specific for Postman Collection
// These are not related with the Box Platform API
// Therefor they are not in the OpenAPI json
//
// These can be injected in using a flag in via the DeploymentIcremental.js script
// These can be injected in using a flag in via the DeploymentIncremental.js script
// and should be invoked in the releaseAdvanced.js script
const Utils = require('./Utils')

Expand Down
10 changes: 5 additions & 5 deletions src/DeployBulk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// const pmConvert = require('./PostmanCovertions')
// const pmConvert = require('./PostmanConversions')
const pmAPI = require('./postmanAPI')

const deployColectionHead = async (privateRemoteCollectionID, localCollection) => {
const deployCollectionHead = async (privateRemoteCollectionID, localCollection) => {
const collectionHead = { ...localCollection }
collectionHead.item = []
const msg = `\nDeploying collection head ${collectionHead.info.name} to ${privateRemoteCollectionID}`
Expand All @@ -15,7 +15,7 @@ const deployColectionHead = async (privateRemoteCollectionID, localCollection) =
})
}

const deployColectionFull = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => {
const deployCollectionFull = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => {
let msg = `\nDeploying full collection ${localCollection.info.name} to ${privateRemoteCollectionId}`
console.log(msg + '...')
await new pmAPI.Collection(privateRemoteCollectionId)
Expand Down Expand Up @@ -57,6 +57,6 @@ const handlePostmanAPIError = (error) => {
}

module.exports = {
deployColectionHead,
deployColectionFull
deployCollectionHead,
deployCollectionFull
}
32 changes: 16 additions & 16 deletions src/DeployIncremental.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Deploy collection inncrementally
// Deploy collection incrementally
// ---------------------------------------------------------------
// Cycle through the collection objects and deploy them one by one
// ---------------------------------------------------------------
Expand All @@ -13,7 +13,7 @@
// Except for folders which would force the update of the entire collection.
// ---------------------------------------------------------------

const pmConvert = require('./PostmanCovertions')
const pmConvert = require('./PostmanConversions')
const pmAPI = require('./postmanAPI')
const { GenID } = require('./Utils')

Expand All @@ -22,8 +22,8 @@ const deployIncremental = async (privateRemoteCollectionId, localCollection, pub

console.log('Incremental deployment of collection ', localCollection.info.name)

// const collectioHeadHasChanged =
await upadteCollectionHead(remoteCollection, localCollection)
// const collectionHeadHasChanged =
await updateCollectionHead(remoteCollection, localCollection)

remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId)

Expand All @@ -46,7 +46,7 @@ const deployIncremental = async (privateRemoteCollectionId, localCollection, pub
// and in the next run the public collection will NOT be updated
// because there are no changes in the private collection

// if (!(collectioHeadHasChanged || foldersHaveChanged || requestsHaveChanged || responsesHaveChanged)) {
// if (!(collectionHeadHasChanged || foldersHaveChanged || requestsHaveChanged || responsesHaveChanged)) {
// console.log('Incremental deployment of collection ', localCollection.info.name, ' completed\n\n')
// return
// }
Expand All @@ -61,8 +61,8 @@ const deployIncremental = async (privateRemoteCollectionId, localCollection, pub
console.log('Incremental deployment of collection ', localCollection.info.name, ' completed\n\n')
}

async function upadteCollectionHead (remoteCollection, localCollection) {
// the colelction head shoul dbe updated if there are changes in
async function updateCollectionHead (remoteCollection, localCollection) {
// the collection head should be updated if there are changes in
// Authorization
// Pre-request Script
// Tests
Expand Down Expand Up @@ -126,7 +126,7 @@ const checkFolderSortChanges = (remoteCollection, localCollection) => {
const checkInfoChanges = (remoteCollection, localEmptyCollection) => {
// collection info does not have a specific id
// so we need to generate a hash and compare them
// The hash is only beig generated for name, description and schema
// The hash is only being generated for name, description and schema

const { name, description, schema } = remoteCollection.collection.info
const remoteInfo = { name, description, schema }
Expand Down Expand Up @@ -255,7 +255,7 @@ async function mergeFolders (remoteCollection, localCollection) {
// const order = localFolders.map(folder => folder.id)
// const msg = ' Sorting folders'

// // create a temporsary root folder
// // create a temporary root folder
// const rootFolder = await new pmAPI.Folder(remoteCollection.collection.info.uid)
// .create({ id: GenID(), name: 'root', folders: order })
// .catch((error) => {
Expand Down Expand Up @@ -322,9 +322,9 @@ async function mergeRequests (remoteCollection, localCollection) {
console.log(msg, '-> FAIL')
handlePostmanAPIError(error)
})
// console.log('\nequest', request)
// console.log('\npmRequest', pmRequest)
// console.log('\nremoteRequest', remoteRequest)
// console.log('\n request', request)
// console.log('\n pmRequest', pmRequest)
// console.log('\n remoteRequest', remoteRequest)
}

// delete old requests
Expand Down Expand Up @@ -391,8 +391,8 @@ async function mergeResponses (remoteCollection, localCollection) {
const newResponses = localResponses.filter(localResponse => !remoteResponses.find(remoteResponse => remoteResponse.id === localResponse.id))
const oldResponses = remoteResponses.filter(remoteResponse => !localResponses.find(localResponse => localResponse.id === remoteResponse.id))

const ResponsesInReqquestHaveChanges = newResponses.length > 0 || oldResponses.length > 0
if (!ResponsesInReqquestHaveChanges) {
const ResponsesInRequestHaveChanges = newResponses.length > 0 || oldResponses.length > 0
if (!ResponsesInRequestHaveChanges) {
console.log(' In Request: ', localRequest.name, '-> No changes')
continue
}
Expand Down Expand Up @@ -428,7 +428,7 @@ async function mergeResponses (remoteCollection, localCollection) {
}

// updating the requests with the order of the responses, doesn't seem to be necessary
if (ResponsesInReqquestHaveChanges) {
if (ResponsesInRequestHaveChanges) {
// sort responses in requests
const responsesOrder = localResponses.map(response => response.id)
const msg = ` Sorting responses in request [${localRequest.name}]`
Expand All @@ -443,7 +443,7 @@ async function mergeResponses (remoteCollection, localCollection) {
handlePostmanAPIError(error)
})
}
anyResponseHasChanged = anyResponseHasChanged || ResponsesInReqquestHaveChanges
anyResponseHasChanged = anyResponseHasChanged || ResponsesInRequestHaveChanges
}
}
return anyResponseHasChanged
Expand Down
26 changes: 24 additions & 2 deletions src/PostmanCovertions.js → src/PostmanConversions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Postman Convertions
// Postman Conversions
// ------------------------------------------------------------
// Handles the conversions from the local generated object
// to the postman api specific objects.
Expand All @@ -17,8 +17,15 @@ const requestFromLocal = (localRequest) => {
let dataMode = null
let rawModeData = null
if (localRequest.request.body && localRequest.request.body.urlencoded) {
data = dataFromLocalURLEncode(localRequest.request.body.urlencoded)
dataMode = localRequest.request.body.mode
if (dataMode === 'formdata') {
dataMode = 'params'
data = dataFromFormData(localRequest.request.body.formdata)
} else if (dataMode === 'file') {
dataMode = 'binary'
} else {
data = dataFromLocalURLEncode(localRequest.request.body.urlencoded)
}
rawModeData = localRequest.request.body.raw
}

Expand Down Expand Up @@ -137,6 +144,21 @@ const dataFromLocalURLEncode = (localFormData) => {
return data
}

const dataFromFormData = (localFormData) => {
const data = []
for (const param of localFormData) {
const item = {
key: param.key,
description: param.description,
value: param.value,
enabled: !param.disabled,
type: param.type
}
data.push(item)
}
return data
}

module.exports = {
requestFromLocal,
responseFromLocal
Expand Down
Loading

0 comments on commit fb10165

Please sign in to comment.