From f80c5d6a463d5dfcde6a50ae8784162744c3c479 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 30 Jan 2020 23:45:38 +0530 Subject: [PATCH 01/13] :recycle: Refactor --- pages/index.vue | 154 ++++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 97 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index f3a5e56ae..f439c03d1 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1822,12 +1822,10 @@ export default { } const protocol = "^(https?:\\/\\/)?"; const validIP = new RegExp( - protocol + - "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + `${protocol}(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$` ); const validHostname = new RegExp( - protocol + - "(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$" + `${protocol}(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$` ); return validIP.test(this.url) || validHostname.test(this.url); }, @@ -1885,39 +1883,20 @@ export default { if (this.requestType === "JavaScript XHR") { const requestString = []; requestString.push("const xhr = new XMLHttpRequest()"); - const user = - this.auth === "Basic Auth" ? "'" + this.httpUser + "'" : null; + const user = this.auth === "Basic Auth" ? `'${this.httpUser}'` : null; const pswd = - this.auth === "Basic Auth" ? "'" + this.httpPassword + "'" : null; + this.auth === "Basic Auth" ? `'${this.httpPassword}'` : null; requestString.push( - "xhr.open('" + - this.method + - "', '" + - this.url + - this.pathName + - this.queryString + - "', true, " + - user + - ", " + - pswd + - ")" + `xhr.open('${this.method}', '${this.url}${this.pathName}${this.queryString}', true, ${user}, ${pswd})` ); if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") { requestString.push( - "xhr.setRequestHeader('Authorization', 'Bearer " + - this.bearerToken + - "')" + `xhr.setRequestHeader('Authorization', 'Bearer ${this.bearerToken}')` ); } if (this.headers) { - this.headers.forEach(element => { - requestString.push( - "xhr.setRequestHeader('" + - element.key + - "', '" + - element.value + - "')" - ); + this.headers.forEach(({ key, value }) => { + requestString.push(`xhr.setRequestHeader('${key}', '${value}')`); }); } if (["POST", "PUT", "PATCH"].includes(this.method)) { @@ -1925,14 +1904,12 @@ export default { ? this.rawParams : this.rawRequestBody; requestString.push( - "xhr.setRequestHeader('Content-Length', " + requestBody.length + ")" + `xhr.setRequestHeader('Content-Length', ${requestBody.length})` ); requestString.push( - "xhr.setRequestHeader('Content-Type', '" + - this.contentType + - "; charset=utf-8')" + `xhr.setRequestHeader('Content-Type', '${this.contentType}; charset=utf-8')` ); - requestString.push("xhr.send(" + requestBody + ")"); + requestString.push(`xhr.send(${requestBody})`); } else { requestString.push("xhr.send()"); } @@ -1941,40 +1918,36 @@ export default { const requestString = []; let headers = []; requestString.push( - 'fetch("' + this.url + this.pathName + this.queryString + '", {\n' + `fetch("${this.url}${this.pathName}${this.queryString}", {\n` ); - requestString.push(' method: "' + this.method + '",\n'); + requestString.push(` method: "${this.method}",\n`); if (this.auth === "Basic Auth") { - const basic = this.httpUser + ":" + this.httpPassword; + const basic = `${this.httpUser}:${this.httpPassword}`; headers.push( - ' "Authorization": "Basic ' + - window.btoa(unescape(encodeURIComponent(basic))) + - '",\n' + ` "Authorization": "Basic ${window.btoa( + unescape(encodeURIComponent(basic)) + )}",\n` ); } else if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") { - headers.push( - ' "Authorization": "Bearer ' + this.bearerToken + '",\n' - ); + headers.push(` "Authorization": "Bearer ${this.bearerToken}",\n`); } if (["POST", "PUT", "PATCH"].includes(this.method)) { const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; - requestString.push(" body: " + requestBody + ",\n"); - headers.push(' "Content-Length": ' + requestBody.length + ",\n"); + requestString.push(` body: ${requestBody},\n`); + headers.push(` "Content-Length": ${requestBody.length},\n`); headers.push( - ' "Content-Type": "' + this.contentType + '; charset=utf-8",\n' + ` "Content-Type": "${this.contentType}; charset=utf-8",\n` ); } if (this.headers) { - this.headers.forEach(element => { - headers.push( - ' "' + element.key + '": "' + element.value + '",\n' - ); + this.headers.forEach(({ key, value }) => { + headers.push(` "${key}": "${value}",\n`); }); } headers = headers.join("").slice(0, -2); - requestString.push(" headers: {\n" + headers + "\n },\n"); + requestString.push(` headers: {\n${headers}\n },\n`); requestString.push(' credentials: "same-origin"\n'); requestString.push("}).then(function(response) {\n"); requestString.push(" response.status\n"); @@ -1988,40 +1961,36 @@ export default { return requestString.join(""); } else if (this.requestType === "cURL") { const requestString = []; - requestString.push("curl -X " + this.method + " \n"); + requestString.push(`curl -X ${this.method} \n`); requestString.push( - " '" + this.url + this.pathName + this.queryString + "' \n" + ` '${this.url}${this.pathName}${this.queryString}' \n` ); if (this.auth === "Basic Auth") { - const basic = this.httpUser + ":" + this.httpPassword; + const basic = `${this.httpUser}:${this.httpPassword}`; requestString.push( - " -H 'Authorization: Basic " + - window.btoa(unescape(encodeURIComponent(basic))) + - "' \n" + ` -H 'Authorization: Basic ${window.btoa( + unescape(encodeURIComponent(basic)) + )}' \n` ); } else if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") { requestString.push( - " -H 'Authorization: Bearer " + this.bearerToken + "' \n" + ` -H 'Authorization: Bearer ${this.bearerToken}' \n` ); } if (this.headers) { - this.headers.forEach(element => { - requestString.push( - " -H '" + element.key + ": " + element.value + "' \n" - ); + this.headers.forEach(({ key, value }) => { + requestString.push(` -H '${key}: ${value}' \n`); }); } if (["POST", "PUT", "PATCH"].includes(this.method)) { const requestBody = this.rawInput ? this.rawParams : this.rawRequestBody; + requestString.push(` -H 'Content-Length: ${requestBody.length}' \n`); requestString.push( - " -H 'Content-Length: " + requestBody.length + "' \n" + ` -H 'Content-Type: ${this.contentType}; charset=utf-8' \n` ); - requestString.push( - " -H 'Content-Type: " + this.contentType + "; charset=utf-8' \n" - ); - requestString.push(" -d '" + requestBody + "' \n"); + requestString.push(` -d '${requestBody}' \n`); } return requestString.join("").slice(0, -2); } @@ -2283,8 +2252,8 @@ export default { } }, getQueryStringFromPath() { - let queryString, - pathParsed = url.parse(this.path); + let queryString; + let pathParsed = url.parse(this.path); return (queryString = pathParsed.query ? pathParsed.query : ""); }, queryStringToArray(queryString) { @@ -2295,9 +2264,8 @@ export default { })); }, pathInputHandler() { - let queryString = this.getQueryStringFromPath(), - params = this.queryStringToArray(queryString); - + let queryString = this.getQueryStringFromPath(); + let params = this.queryStringToArray(queryString); this.paramsWatchEnabled = false; this.params = params; }, @@ -2418,7 +2386,7 @@ export default { const aux = document.createElement("textarea"); const copy = this.responseType === "application/json" - ? JSON.stringify(this.response.body) + ? JSON.stringify(this.response.body, null, 2) : this.response.body; aux.innerText = copy; document.body.appendChild(aux); @@ -2433,17 +2401,12 @@ export default { downloadResponse() { const dataToWrite = JSON.stringify(this.response.body, null, 2); const file = new Blob([dataToWrite], { type: this.responseType }); - const a = document.createElement("a"), - url = URL.createObjectURL(file); + const a = document.createElement("a"); + const url = URL.createObjectURL(file); a.href = url; - a.download = ( - this.url + - this.path + - " [" + - this.method + - "] on " + - Date() - ).replace(/\./g, "[dot]"); + a.download = `${this.url + this.path} [${ + this.method + }] on ${Date()}`.replace(/\./g, "[dot]"); document.body.appendChild(a); a.click(); this.$refs.downloadResponse.innerHTML = this.doneButton; @@ -2511,13 +2474,12 @@ export default { history.replaceState( window.location.href, "", - "/?" + - encodeURI( - flats - .concat(deeps, bodyParams) - .join("") - .slice(0, -1) - ) + `/?${encodeURI( + flats + .concat(deeps, bodyParams) + .join("") + .slice(0, -1) + )}` ); }, setRouteQueries(queries) { @@ -2714,8 +2676,8 @@ export default { let file = this.$refs.payload.files[0]; if (file !== undefined && file !== null) { let reader = new FileReader(); - reader.onload = e => { - this.rawParams = e.target.result; + reader.onload = ({ target }) => { + this.rawParams = target.result; }; reader.readAsText(file); this.$toast.info(this.$t("file_imported"), { @@ -2807,7 +2769,7 @@ export default { removeOAuthTokenReq(index) { const oldTokenReqs = this.tokenReqs.slice(); let targetReqIndex = this.tokenReqs.findIndex( - tokenReq => tokenReq.name === this.tokenReqName + ({ name }) => name === this.tokenReqName ); if (targetReqIndex < 0) return; this.$store.commit("removeOAuthTokenReq", targetReqIndex); @@ -2822,10 +2784,8 @@ export default { } }); }, - tokenReqChange(event) { - let targetReq = this.tokenReqs.find( - tokenReq => tokenReq.name === event.target.value - ); + tokenReqChange({ target }) { + let targetReq = this.tokenReqs.find(({ name }) => name === target.value); let { oidcDiscoveryUrl, authUrl, From 1d6d8af748466b674928f2daedabf2e5f8289cae Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Fri, 31 Jan 2020 00:18:20 +0530 Subject: [PATCH 02/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ace-editor.vue | 15 ++++++--------- pages/doc.vue | 4 ++-- pages/graphql.vue | 16 ++++++++-------- pages/realtime.vue | 12 ++++-------- pages/settings.vue | 18 +++++++++--------- 5 files changed, 29 insertions(+), 36 deletions(-) diff --git a/components/ace-editor.vue b/components/ace-editor.vue index 3f2745147..5065b7994 100644 --- a/components/ace-editor.vue +++ b/components/ace-editor.vue @@ -55,8 +55,8 @@ export default { mounted() { const editor = ace.edit(this.$refs.editor, { - theme: "ace/theme/" + this.defineTheme(), - mode: "ace/mode/" + this.lang, + theme: `ace/theme/${this.defineTheme()}`, + mode: `ace/mode/${this.lang}`, ...this.options }); @@ -74,13 +74,10 @@ export default { methods: { defineTheme() { - if (this.theme) { - return this.theme; - } else { - return ( - this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME - ); - } + if (this.theme) return this.theme; + return ( + this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME + ); } }, diff --git a/pages/doc.vue b/pages/doc.vue index 963687d4d..07dabf4de 100644 --- a/pages/doc.vue +++ b/pages/doc.vue @@ -363,8 +363,8 @@ export default { let file = this.$refs.collectionUpload.files[0]; if (file !== undefined && file !== null) { let reader = new FileReader(); - reader.onload = e => { - this.collectionJSON = e.target.result; + reader.onload = ({ target }) => { + this.collectionJSON = target.result; }; reader.readAsText(file); this.$toast.info(this.$t("file_imported"), { diff --git a/pages/graphql.vue b/pages/graphql.vue index 127f74428..f81d37145 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -531,7 +531,10 @@ export default { return this.$store.state.gql.variablesJSONString; }, set(value) { - this.$store.commit("setGQLState", { value, attribute: "variablesJSONString" }); + this.$store.commit("setGQLState", { + value, + attribute: "variablesJSONString" + }); } }, headerString() { @@ -620,7 +623,7 @@ export default { this.headers.forEach(header => { headers[header.key] = header.value; }); - + let variables = JSON.parse(this.variableString); const gqlQueryString = this.gqlQueryString; @@ -780,13 +783,10 @@ export default { downloadResponse() { const dataToWrite = JSON.stringify(this.schemaString, null, 2); const file = new Blob([dataToWrite], { type: "application/json" }); - const a = document.createElement("a"), - url = URL.createObjectURL(file); + const a = document.createElement("a"); + const url = URL.createObjectURL(file); a.href = url; - a.download = (this.url + " on " + Date() + ".graphql").replace( - /\./g, - "[dot]" - ); + a.download = `${this.url} on ${Date()}.graphql`.replace(/\./g, "[dot]"); document.body.appendChild(a); a.click(); this.$refs.downloadResponse.innerHTML = this.doneButton; diff --git a/pages/realtime.vue b/pages/realtime.vue index 1ef1a49b6..9e97c4d06 100644 --- a/pages/realtime.vue +++ b/pages/realtime.vue @@ -211,24 +211,20 @@ export default { urlValid() { const protocol = "^(wss?:\\/\\/)?"; const validIP = new RegExp( - protocol + - "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + `${protocol}(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$` ); const validHostname = new RegExp( - protocol + - "(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$" + `${protocol}(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$` ); return validIP.test(this.url) || validHostname.test(this.url); }, serverValid() { const protocol = "^(https?:\\/\\/)?"; const validIP = new RegExp( - protocol + - "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" + `${protocol}(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$` ); const validHostname = new RegExp( - protocol + - "(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$" + `${protocol}(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9/])$` ); return validIP.test(this.server) || validHostname.test(this.server); } diff --git a/pages/settings.vue b/pages/settings.vue index 5b4e13bf2..f09131f8a 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -398,9 +398,9 @@ export default { firebase .auth() .signInWithPopup(provider) - .then(res => { - if (res.additionalUserInfo.isNewUser) { - this.$toast.info(this.$t("turn_on") + " " + this.$t("sync"), { + .then(({ additionalUserInfo }) => { + if (additionalUserInfo.isNewUser) { + this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, { icon: "sync", duration: null, closeOnSwipe: false, @@ -427,9 +427,9 @@ export default { firebase .auth() .signInWithPopup(provider) - .then(res => { - if (res.additionalUserInfo.isNewUser) { - this.$toast.info(this.$t("turn_on") + " " + this.$t("sync"), { + .then(({ additionalUserInfo }) => { + if (additionalUserInfo.isNewUser) { + this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, { icon: "sync", duration: null, closeOnSwipe: false, @@ -458,14 +458,14 @@ export default { fb.writeSettings("syncHistory", true); fb.writeSettings("syncCollections", false); }, - resetProxy(e) { + resetProxy({ target }) { this.settings.PROXY_URL = `https://postwoman.apollotv.xyz/`; - e.target.innerHTML = this.doneButton; + target.innerHTML = this.doneButton; this.$toast.info(this.$t("cleared"), { icon: "clear_all" }); setTimeout( - () => (e.target.innerHTML = 'clear_all'), + () => (target.innerHTML = 'clear_all'), 1000 ); } From c32c6e0363db228044bb7169ac849c32f83583f1 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Fri, 31 Jan 2020 18:25:55 +0530 Subject: [PATCH 03/13] :recycle: Refactor --- components/ace-editor.vue | 4 +++- pages/index.vue | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/ace-editor.vue b/components/ace-editor.vue index 5065b7994..d6f14389a 100644 --- a/components/ace-editor.vue +++ b/components/ace-editor.vue @@ -74,7 +74,9 @@ export default { methods: { defineTheme() { - if (this.theme) return this.theme; + if (this.theme) { + return this.theme; + } return ( this.$store.state.postwoman.settings.THEME_ACE_EDITOR || DEFAULT_THEME ); diff --git a/pages/index.vue b/pages/index.vue index f439c03d1..a91a37949 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1884,10 +1884,10 @@ export default { const requestString = []; requestString.push("const xhr = new XMLHttpRequest()"); const user = this.auth === "Basic Auth" ? `'${this.httpUser}'` : null; - const pswd = + const password = this.auth === "Basic Auth" ? `'${this.httpPassword}'` : null; requestString.push( - `xhr.open('${this.method}', '${this.url}${this.pathName}${this.queryString}', true, ${user}, ${pswd})` + `xhr.open('${this.method}', '${this.url}${this.pathName}${this.queryString}', true, ${user}, ${password})` ); if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") { requestString.push( From a9564086b0aae8efd0b5248c941dfc0fa80ee5e1 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 31 Jan 2020 19:44:49 +0530 Subject: [PATCH 04/13] refactor: destructuring assignment and other tweaks --- pages/index.vue | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index a91a37949..69d1fcb3d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2515,13 +2515,12 @@ export default { observer.observe(requestElement); }, handleImport() { - let textarea = document.getElementById("import-text"); - let text = textarea.value; + const { value: text } = document.getElementById("import-text"); try { - let parsedCurl = parseCurlCommand(text); - let url = new URL(parsedCurl.url.replace(/"/g, "").replace(/'/g, "")); - this.url = url.origin; - this.path = url.pathname; + const parsedCurl = parseCurlCommand(text); + const { origin, pathname } = new URL(parsedCurl.url.replace(/"/g, "").replace(/'/g, "")); + this.url = origin; + this.path = pathname; this.headers = []; if (parsedCurl.headers) { for (const key of Object.keys(parsedCurl.headers)) { From b05cd2e6e4c427d3ccc6d5ba872ee5349685a4a3 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 31 Jan 2020 19:45:52 +0530 Subject: [PATCH 05/13] refactor: stick with Es6 semantics --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 69d1fcb3d..34a843faf 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2525,7 +2525,7 @@ export default { if (parsedCurl.headers) { for (const key of Object.keys(parsedCurl.headers)) { this.$store.commit("addHeaders", { - key: key, + key, value: parsedCurl.headers[key] }); } From 5429e493ea43309050704c52d86c83b26d928d56 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 31 Jan 2020 19:47:19 +0530 Subject: [PATCH 06/13] refactor: stylistic update --- pages/index.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 34a843faf..b020ecdb8 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2491,7 +2491,9 @@ export default { if (key === "rawParams") { this.rawInput = true; this.rawParams = queries["rawParams"]; - } else if (typeof this[key] === "string") this[key] = queries[key]; + } else if (typeof this[key] === "string") { + this[key] = queries[key]; + } } }, observeRequestButton() { From d77e3745bb2c0a7d4e5d49d3608cc9a9eca2ab4c Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 31 Jan 2020 19:50:24 +0530 Subject: [PATCH 07/13] refactor: stylistic update --- pages/index.vue | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index b020ecdb8..49412e20d 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2259,7 +2259,7 @@ export default { queryStringToArray(queryString) { let queryParsed = querystring.parse(queryString); return Object.keys(queryParsed).map(key => ({ - key: key, + key, value: queryParsed[key] })); }, @@ -2334,8 +2334,8 @@ export default { }, copyRequest() { if (navigator.share) { - let time = new Date().toLocaleTimeString(); - let date = new Date().toLocaleDateString(); + const time = new Date().toLocaleTimeString(); + const date = new Date().toLocaleDateString(); navigator .share({ title: `Postwoman`, @@ -2452,7 +2452,8 @@ export default { const haveItems = [...this[key]].length; if (haveItems && this[key]["value"] !== "") { return `${key}=${JSON.stringify(this[key])}&`; - } else return ""; + } + return ""; }; let flats = [ "method", @@ -2466,8 +2467,8 @@ export default { ] .filter(item => item !== null) .map(item => flat(item)); - let deeps = ["headers", "params"].map(item => deep(item)); - let bodyParams = this.rawInput + const deeps = ["headers", "params"].map(item => deep(item)); + const bodyParams = this.rawInput ? [flat("rawParams")] : [deep("bodyParams")]; From 2b165a065c08e26e3991d759f93dbb536fac8563 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:26:31 +0530 Subject: [PATCH 08/13] refactor: stick with the enforced style --- pages/index.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 49412e20d..943780b49 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1504,8 +1504,11 @@ export default { this.rawInput = !this.knownContentTypes.includes(val); }, rawInput(status) { - if (status && this.rawParams === "") this.rawParams = "{}"; - else this.setRouteQueryState(); + if (status && this.rawParams === "") { + this.rawParams = "{}"; + } else { + this.setRouteQueryState(); + } }, "response.body": function(val) { if ( From ef434ca8040a97cc98d2b61498c5902162a75f8c Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:30:35 +0530 Subject: [PATCH 09/13] refactor: destructuring assignment --- pages/index.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 943780b49..c1168c9c5 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1839,8 +1839,8 @@ export default { return this.path.match(/^([^?]*)\??/)[1]; }, rawRequestBody() { - const { bodyParams } = this; - if (this.contentType === "application/json") { + const { bodyParams, contentType } = this; + if (contentType === "application/json") { try { const obj = JSON.parse( `{${bodyParams From fa15457ce4c766eaeda3767ff1bd5ffeb6262e0f Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:44:24 +0530 Subject: [PATCH 10/13] refactor: let to const --- pages/index.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index c1168c9c5..46ce61a08 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2256,19 +2256,19 @@ export default { }, getQueryStringFromPath() { let queryString; - let pathParsed = url.parse(this.path); + const pathParsed = url.parse(this.path); return (queryString = pathParsed.query ? pathParsed.query : ""); }, queryStringToArray(queryString) { - let queryParsed = querystring.parse(queryString); + const queryParsed = querystring.parse(queryString); return Object.keys(queryParsed).map(key => ({ key, value: queryParsed[key] })); }, pathInputHandler() { - let queryString = this.getQueryStringFromPath(); - let params = this.queryStringToArray(queryString); + const queryString = this.getQueryStringFromPath(); + const params = this.queryStringToArray(queryString); this.paramsWatchEnabled = false; this.params = params; }, From 3bd22f6b78ed34cf0354899cac000b7299992eb0 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:48:06 +0530 Subject: [PATCH 11/13] refactor: let to const --- pages/index.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 46ce61a08..da0fb1b5a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2678,9 +2678,9 @@ export default { }, uploadPayload() { this.rawInput = true; - let file = this.$refs.payload.files[0]; + const file = this.$refs.payload.files[0]; if (file !== undefined && file !== null) { - let reader = new FileReader(); + const reader = new FileReader(); reader.onload = ({ target }) => { this.rawParams = target.result; }; @@ -2721,7 +2721,7 @@ export default { } }, async oauthRedirectReq() { - let tokenInfo = await oauthRedirect(); + const tokenInfo = await oauthRedirect(); if (tokenInfo.hasOwnProperty("access_token")) { this.bearerToken = tokenInfo.access_token; this.addOAuthToken({ @@ -2773,7 +2773,7 @@ export default { }, removeOAuthTokenReq(index) { const oldTokenReqs = this.tokenReqs.slice(); - let targetReqIndex = this.tokenReqs.findIndex( + const targetReqIndex = this.tokenReqs.findIndex( ({ name }) => name === this.tokenReqName ); if (targetReqIndex < 0) return; @@ -2790,7 +2790,7 @@ export default { }); }, tokenReqChange({ target }) { - let targetReq = this.tokenReqs.find(({ name }) => name === target.value); + const targetReq = this.tokenReqs.find(({ name }) => name === target.value); let { oidcDiscoveryUrl, authUrl, From ad041a5cf1ec5c9c7d79fe1768cdaee62d40150b Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:49:09 +0530 Subject: [PATCH 12/13] refactor: tweaks --- pages/index.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index da0fb1b5a..77c39403e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2790,15 +2790,15 @@ export default { }); }, tokenReqChange({ target }) { - const targetReq = this.tokenReqs.find(({ name }) => name === target.value); - let { + const { details, name } = this.tokenReqs.find(({ name }) => name === target.value); + const { oidcDiscoveryUrl, authUrl, accessTokenUrl, clientId, scope - } = targetReq.details; - this.tokenReqName = targetReq.name; + } = details; + this.tokenReqName = name; this.oidcDiscoveryUrl = oidcDiscoveryUrl; this.authUrl = authUrl; this.accessTokenUrl = accessTokenUrl; From 0f55b8ee8a3939618f8ceb56521eb61a2e1792c1 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Sat, 1 Feb 2020 22:56:25 +0530 Subject: [PATCH 13/13] refactor: minor tweak --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 77c39403e..956c0395f 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1852,7 +1852,7 @@ export default { ) .join()}}` ); - return JSON.stringify(obj); + return JSON.stringify(obj, null, 2); } catch (ex) { return "invalid"; }