From 918d59f1466d2c90c6a9ed086c6ad70e6b3d45ea Mon Sep 17 00:00:00 2001 From: Sabine Schaller Date: Thu, 22 Feb 2024 12:57:28 +0100 Subject: [PATCH] chore: enable prettier on bruno collection --- .prettierignore | 2 - postman/collections/Interledger/bruno.json | 7 +- .../Interledger/scripts/scripts.js | 93 +++++++++++-------- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/.prettierignore b/.prettierignore index 5943306df0..6014a7ea47 100644 --- a/.prettierignore +++ b/.prettierignore @@ -14,7 +14,5 @@ build **/styles/*.css .docusaurus .cache-loader -postman -.postman packages/documentation/src/content/docs/apis .astro \ No newline at end of file diff --git a/postman/collections/Interledger/bruno.json b/postman/collections/Interledger/bruno.json index 32f0580340..a4d3d0e1a2 100644 --- a/postman/collections/Interledger/bruno.json +++ b/postman/collections/Interledger/bruno.json @@ -2,8 +2,5 @@ "version": "1", "name": "Interledger", "type": "collection", - "ignore": [ - "node_modules", - ".git" - ] -} \ No newline at end of file + "ignore": ["node_modules", ".git"] +} diff --git a/postman/collections/Interledger/scripts/scripts.js b/postman/collections/Interledger/scripts/scripts.js index 752320a04d..262c97e48f 100644 --- a/postman/collections/Interledger/scripts/scripts.js +++ b/postman/collections/Interledger/scripts/scripts.js @@ -2,30 +2,33 @@ 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) @@ -33,10 +36,10 @@ const scripts = { ) }, - 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'), @@ -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 { @@ -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; \ No newline at end of file +module.exports = scripts