Skip to content

Commit

Permalink
chore: enable prettier on bruno collection
Browse files Browse the repository at this point in the history
  • Loading branch information
sabineschaller committed Feb 22, 2024
1 parent 0a2b715 commit 918d59f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 48 deletions.
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ build
**/styles/*.css
.docusaurus
.cache-loader
postman
.postman
packages/documentation/src/content/docs/apis
.astro
7 changes: 2 additions & 5 deletions postman/collections/Interledger/bruno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
"version": "1",
"name": "Interledger",
"type": "collection",
"ignore": [
"node_modules",
".git"
]
}
"ignore": ["node_modules", ".git"]
}
93 changes: 52 additions & 41 deletions postman/collections/Interledger/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,44 @@ const fetch = require('node-fetch')
const url = require('url')

const scripts = {

sanitizeUrl: function() {
return req.getUrl()
sanitizeUrl: function () {
return req
.getUrl()
.replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key))
.replace(/localhost:([3,4])000/g, (_, key) =>
key === '3' ? bru.getEnvVar('host3000') : bru.getEnvVar('host4000')
)
},

sanitizeBody: function() {
sanitizeBody: function () {
let requestBody = req.getBody()
if (!(req.getMethod() === 'POST' && requestBody)) return undefined
if (typeof requestBody === 'object'){
if (typeof requestBody === 'object') {
requestBody = JSON.stringify(requestBody)
}
return JSON.parse(requestBody
return JSON.parse(
requestBody
.replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key))
.replace(/http:\/\/localhost:([3,4])000/g, (_, key) => key === '3'
? 'https://' + bru.getEnvVar('host3000')
: 'https://' + bru.getEnvVar('host4000'))
.replace(/http:\/\/localhost:([3,4])000/g, (_, key) =>
key === '3'
? 'https://' + bru.getEnvVar('host3000')
: 'https://' + bru.getEnvVar('host4000')
)
)
},

sanitizeHeaders: function() {
sanitizeHeaders: function () {
return JSON.parse(
JSON.stringify(req.getHeaders()).replace(/{{([A-Za-z]\w+)}}/g, (_, key) =>
bru.getEnvVar(key)
)
)
},

requestSigHeaders: async function(url, method, headers, body) {
requestSigHeaders: async function (url, method, headers, body) {
const response = await fetch(bru.getEnvVar('signatureUrl'), {
method: 'post',
headers: {'Content-Type': 'application/json'},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
keyId: bru.getEnvVar('clientKeyId'),
base64Key: bru.getEnvVar('clientPrivateKey'),
Expand All @@ -51,46 +54,53 @@ const scripts = {
return await response.json()
},

setHeaders: function(headers) {
setHeaders: function (headers) {
for (let [key, value] of Object.entries(headers)) {
req.setHeader(key, value)
}
},

addSignatureHeaders: async function() {
addSignatureHeaders: async function () {
const url = this.sanitizeUrl()
const headers = this.sanitizeHeaders()
const body = this.sanitizeBody()
req.setBody(body)
const signatureHeaders = await this.requestSigHeaders(url, req.getMethod(), headers, body)
const signatureHeaders = await this.requestSigHeaders(
url,
req.getMethod(),
headers,
body
)
this.setHeaders(signatureHeaders)
},

addHostHeader: function(hostVarName) {
const requestUrl = url.parse(req.getUrl()
.replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key)))

if (hostVarName){
bru.setEnvVar(hostVarName, requestUrl.protocol + '//' + requestUrl.host);

addHostHeader: function (hostVarName) {
const requestUrl = url.parse(
req.getUrl().replace(/{{([A-Za-z]\w+)}}/g, (_, key) => bru.getEnvVar(key))
)

if (hostVarName) {
bru.setEnvVar(hostVarName, requestUrl.protocol + '//' + requestUrl.host)
}

if(requestUrl.hostname === 'localhost'){
const hostHeader = requestUrl.port === '3000'

if (requestUrl.hostname === 'localhost') {
const hostHeader =
requestUrl.port === '3000'
? bru.getEnvVar('host3000')
: bru.getEnvVar('host4000')
req.headers.host = hostHeader
req.headers.host = hostHeader
}
},

storeTokenDetails: function() {
const body = res.getBody();
bru.setEnvVar("accessToken", body?.access_token?.value);
bru.setEnvVar("continueToken", body.continue.access_token.value);
bru.setEnvVar("continueId", body.continue.uri.split("/").pop());
bru.setEnvVar("tokenId", body?.access_token?.manage.split('/').pop())
storeTokenDetails: function () {
const body = res.getBody()
bru.setEnvVar('accessToken', body?.access_token?.value)
bru.setEnvVar('continueToken', body.continue.access_token.value)
bru.setEnvVar('continueId', body.continue.uri.split('/').pop())
bru.setEnvVar('tokenId', body?.access_token?.manage.split('/').pop())
},

getWalletAddressId: async function(host, publicName, varName) {
getWalletAddressId: async function (host, publicName, varName) {
const getWalletAddressesQuery = `
query GetWalletAddresses {
walletAddresses {
Expand All @@ -107,16 +117,17 @@ const scripts = {

const postRequest = {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({query: getWalletAddressesQuery})
};

headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: getWalletAddressesQuery })
}

const response = await fetch(`${bru.getEnvVar(host)}/graphql`, postRequest);
const body = await response.json();
const walletAddressId = body.data.walletAddresses.edges.map(e => e.node).find(node => node.publicName === publicName)?.id
const response = await fetch(`${bru.getEnvVar(host)}/graphql`, postRequest)
const body = await response.json()
const walletAddressId = body.data.walletAddresses.edges
.map((e) => e.node)
.find((node) => node.publicName === publicName)?.id
bru.setEnvVar(varName, walletAddressId)
}
}

module.exports = scripts;
module.exports = scripts

0 comments on commit 918d59f

Please sign in to comment.