From 66eecf5e37240f1b88ec4b55c8191a06cac3c602 Mon Sep 17 00:00:00 2001 From: Levin Rickert Date: Sun, 16 Feb 2020 15:48:10 +0100 Subject: [PATCH 01/24] Unify Chrome and Firefox extensions --- functions/network.js | 7 +++++++ functions/strategies/ExtensionStrategy.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 functions/strategies/ExtensionStrategy.js diff --git a/functions/network.js b/functions/network.js index 9294ba03638..591d8f4d3ca 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,4 +1,5 @@ import AxiosStrategy from "./strategies/AxiosStrategy"; +import ExtensionStrategy from "./strategies/ExtensionStrategy"; import FirefoxStrategy from "./strategies/FirefoxStrategy"; import ChromeStrategy, { hasChromeExtensionInstalled } from "./strategies/ChromeStrategy"; @@ -9,6 +10,12 @@ const isExtensionsAllowed = ({ state }) => { const runAppropriateStrategy = (req, store) => { if (isExtensionsAllowed(store)) { + if (typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== 'undefined') { + return ExtensionStrategy(req, store); + } + + // The following strategies are deprecated and kept to support older version of the extensions + // Chrome Provides a chrome object for scripts to access // Check its availability to say whether you are in Google Chrome if (window.chrome && hasChromeExtensionInstalled()) { diff --git a/functions/strategies/ExtensionStrategy.js b/functions/strategies/ExtensionStrategy.js new file mode 100644 index 00000000000..3305f0b6ef4 --- /dev/null +++ b/functions/strategies/ExtensionStrategy.js @@ -0,0 +1,22 @@ +const extensionWithProxy = async (req, { state }) => { + const { data } = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({ + method: "post", + url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", + data: req + }); + return data; +}; + +const extensionWithoutProxy = async (req, _store) => { + const res = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest(req); + return res; +}; + +const extensionStrategy = (req, store) => { + if (store.state.postwoman.settings.PROXY_ENABLED) { + return extensionWithProxy(req, store); + } + return extensionWithoutProxy(req, store); +}; + +export default extensionStrategy; From 4665dbc37288834cdadcc99817a75c1b3f55d3a3 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Wed, 19 Feb 2020 09:29:49 +0530 Subject: [PATCH 02/24] :rotating_light: Lint --- functions/headers.js | 2 +- functions/strategies/ChromeStrategy.js | 78 ++++++++++++++------------ layouts/default.vue | 2 +- store/postwoman.js | 12 ++-- 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/functions/headers.js b/functions/headers.js index 9fbc2938e51..ffc6b5d5f34 100644 --- a/functions/headers.js +++ b/functions/headers.js @@ -121,4 +121,4 @@ export const commonHeaders = [ "X-Requested-With", "X-Robots-Tag", "X-UA-Compatible" -] +]; diff --git a/functions/strategies/ChromeStrategy.js b/functions/strategies/ChromeStrategy.js index 03c05ea0caa..1c525e3ed53 100644 --- a/functions/strategies/ChromeStrategy.js +++ b/functions/strategies/ChromeStrategy.js @@ -5,45 +5,53 @@ const EXTENSION_ID = "amknoiejhlmhancpahfcfcfhllgkpbld"; // Also check for the presence of window.chrome object to confirm smooth operations export const hasChromeExtensionInstalled = () => { return document.getElementById("chromePWExtensionDetect") !== null; -} +}; -const chromeWithoutProxy = (req, _store) => new Promise((resolve, reject) => { - chrome.runtime.sendMessage( - EXTENSION_ID, { - messageType: "send-req", - data: { - config: req - } - }, (message) => { - if (message.data.error) { - reject(message.data.error); - } else { - resolve(message.data.response); +const chromeWithoutProxy = (req, _store) => + new Promise((resolve, reject) => { + chrome.runtime.sendMessage( + EXTENSION_ID, + { + messageType: "send-req", + data: { + config: req + } + }, + message => { + if (message.data.error) { + reject(message.data.error); + } else { + resolve(message.data.response); + } } - } - ); -}); + ); + }); -const chromeWithProxy = (req, { state }) => new Promise((resolve, reject) => { - chrome.runtime.sendMessage( - EXTENSION_ID, { - messageType: "send-req", - data: { - config: { - method: "post", - url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", - data: req +const chromeWithProxy = (req, { state }) => + new Promise((resolve, reject) => { + chrome.runtime.sendMessage( + EXTENSION_ID, + { + messageType: "send-req", + data: { + config: { + method: "post", + url: + state.postwoman.settings.PROXY_URL || + "https://postwoman.apollotv.xyz/", + data: req + } + } + }, + message => { + if (message.data.error) { + reject(error); + } else { + resolve(message.data.response.data); } } - }, (message) => { - if (message.data.error) { - reject(error); - } else { - resolve(message.data.response.data); - } - } - ) -}); + ); + }); const chromeStrategy = (req, store) => { if (store.state.postwoman.settings.PROXY_ENABLED) { @@ -51,6 +59,6 @@ const chromeStrategy = (req, store) => { } else { return chromeWithoutProxy(req, store); } -} +}; export default chromeStrategy; diff --git a/layouts/default.vue b/layouts/default.vue index 4302a71f88e..cbe410f1715 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -715,7 +715,7 @@ export default { .then(() => {}) .catch(console.error); } else { - // fallback + // fallback } } }, diff --git a/store/postwoman.js b/store/postwoman.js index ab79729efc9..a0e93faaf26 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -57,11 +57,11 @@ export const SETTINGS_KEYS = [ * e.g. 'auth' */ "URL_EXCLUDES", - + /** * A boolean value indicating whether to use the browser extensions * to run the requests - */ + */ "EXTENSIONS_ENABLED" ]; @@ -118,7 +118,9 @@ export const mutations = { addNewCollection({ collections }, collection) { const { name } = collection; - const duplicateCollection = collections.some(item => item.name.toLowerCase() === name.toLowerCase()); + const duplicateCollection = collections.some( + item => item.name.toLowerCase() === name.toLowerCase() + ); if (duplicateCollection) { this.$toast.info("Duplicate collection"); return; @@ -139,7 +141,9 @@ export const mutations = { editCollection({ collections }, payload) { const { collection, collectionIndex } = payload; const { name } = collection; - const duplicateCollection = collections.some(item => item.name.toLowerCase() === name.toLowerCase()); + const duplicateCollection = collections.some( + item => item.name.toLowerCase() === name.toLowerCase() + ); if (duplicateCollection) { this.$toast.info("Duplicate collection"); return; From 73a2a0a127d682cd3394d1535bb1ff762067c4e0 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 20 Feb 2020 08:01:22 +0530 Subject: [PATCH 03/24] :zap: Updated color codes, minor UI tweaks --- assets/css/styles.scss | 23 ++++++++++------------- components/settings/swatch.vue | 1 + layouts/default.vue | 6 +++--- pages/settings.vue | 7 ++++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/assets/css/styles.scss b/assets/css/styles.scss index 2bb3bba07fa..8ceacb2b59a 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -22,13 +22,11 @@ $responsiveWidth: 768px; ::-webkit-scrollbar { width: 4px; height: 4px; - border-radius: 4px; - background-color: var(--bg-light-color); + background-color: var(--bg-dark-color); } ::-webkit-scrollbar-thumb { background-color: var(--fg-light-color); - border-radius: 8px; &:hover { background-color: var(--fg-color); @@ -62,7 +60,6 @@ body { scroll-behavior: smooth; } -// Make theme transition smoother. body.afterLoad { transition: background-color 0.2s ease-in-out; } @@ -76,6 +73,10 @@ a { color: inherit; text-decoration: none; transition: all 0.2s ease-in-out; + + &.link { + color: var(--ac-color); + } } header, @@ -146,7 +147,8 @@ footer { z-index: 1; height: 100vh; padding: 0 8px; - background-color: var(--bg-light-color); + background-color: var(--bg-dark-color); + transition: all 0.2s ease-in-out; } .main { @@ -186,7 +188,6 @@ nav.primary-nav { color: var(--fg-light-color); fill: var(--fg-light-color); margin: 8px 0; - transition: all 0.2s ease-in-out; &:hover { color: var(--fg-color); @@ -422,7 +423,6 @@ button { color: var(--act-color); fill: var(--act-color); box-shadow: inset 0 0 0 2px var(--fg-color); - transition: all 0.2s ease-in-out; } &.icon { @@ -437,7 +437,6 @@ button { color: var(--fg-color); fill: var(--fg-color); box-shadow: none; - transition: all 0.2s ease-in-out; } } @@ -472,7 +471,6 @@ button { fieldset { margin: 16px 0; border-radius: 16px; - transition: all 0.2s ease-in-out; background-color: var(--bg-dark-color); } @@ -565,7 +563,6 @@ code { &:not([readonly]):not(.ace_editor):active, &:not([readonly]):not(.ace_editor):focus { box-shadow: inset 0 0 0 2px var(--fg-light-color); - transition: all 0.2s ease-in-out; } } @@ -576,7 +573,6 @@ code { &:active, &:focus { box-shadow: inset 0 0 0 2px var(--fg-light-color); - transition: all 0.2s ease-in-out; } } @@ -884,18 +880,19 @@ input[type="radio"]:checked + label + .tab { padding: 0; width: 100%; background-color: var(--bg-color); - transition: all 0.2s ease-in-out; box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.45); } nav.primary-nav { flex-flow: row nowrap; overflow: auto; - justify-content: space-around; + justify-content: space-between; + background-color: var(--bg-dark-color); a { background-color: transparent; margin: 8px; + flex: 1; &.nuxt-link-exact-active { background-color: transparent; diff --git a/components/settings/swatch.vue b/components/settings/swatch.vue index 0d0dc870b3b..55373c58d98 100644 --- a/components/settings/swatch.vue +++ b/components/settings/swatch.vue @@ -20,6 +20,7 @@ border-radius: 100%; border: 3px solid var(--bg-dark-color); cursor: pointer; + transition: all 0.2s ease-in-out; &.fg { color: var(--act-color); diff --git a/layouts/default.vue b/layouts/default.vue index cbe410f1715..2308fe97127 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -408,7 +408,7 @@
diff --git a/pages/settings.vue b/pages/settings.vue index 490ca804c33..aa780be218a 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -206,7 +206,12 @@ {{ $t("postwoman_official_proxy_hosting") }}
{{ $t("read_the") }} -
+ {{ $t("apollotv_privacy_policy") }} .

From 09a35cf10ad91a386cbf4c8960ec89a68d9093f8 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Thu, 20 Feb 2020 08:52:42 +0530 Subject: [PATCH 04/24] =?UTF-8?q?=F0=9F=9A=A8=20Lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/network.js | 22 ++++++++++++---------- functions/strategies/ChromeStrategy.js | 19 +++++++++---------- functions/strategies/ExtensionStrategy.js | 3 ++- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/functions/network.js b/functions/network.js index 591d8f4d3ca..22ff13364ae 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,16 +1,17 @@ import AxiosStrategy from "./strategies/AxiosStrategy"; import ExtensionStrategy from "./strategies/ExtensionStrategy"; import FirefoxStrategy from "./strategies/FirefoxStrategy"; -import ChromeStrategy, { hasChromeExtensionInstalled } from "./strategies/ChromeStrategy"; +import ChromeStrategy, { + hasChromeExtensionInstalled +} from "./strategies/ChromeStrategy"; -const isExtensionsAllowed = ({ state }) => { - return typeof state.postwoman.settings.EXTENSIONS_ENABLED === 'undefined' - || state.postwoman.settings.EXTENSIONS_ENABLED; -} +const isExtensionsAllowed = ({ state }) => + typeof state.postwoman.settings.EXTENSIONS_ENABLED === "undefined" || + state.postwoman.settings.EXTENSIONS_ENABLED; const runAppropriateStrategy = (req, store) => { if (isExtensionsAllowed(store)) { - if (typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== 'undefined') { + if (typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== "undefined") { return ExtensionStrategy(req, store); } @@ -19,7 +20,7 @@ const runAppropriateStrategy = (req, store) => { // Chrome Provides a chrome object for scripts to access // Check its availability to say whether you are in Google Chrome if (window.chrome && hasChromeExtensionInstalled()) { - return ChromeStrategy(req, store); + return ChromeStrategy(req, store); } // The firefox plugin injects a function to send requests through it // If that is available, then we can use the FirefoxStrategy @@ -29,10 +30,11 @@ const runAppropriateStrategy = (req, store) => { } return AxiosStrategy(req, store); -} +}; const sendNetworkRequest = (req, store) => - runAppropriateStrategy(req, store) - .finally(() => window.$nuxt.$loading.finish()); + runAppropriateStrategy(req, store).finally(() => + window.$nuxt.$loading.finish() + ); export { sendNetworkRequest }; diff --git a/functions/strategies/ChromeStrategy.js b/functions/strategies/ChromeStrategy.js index 1c525e3ed53..fe88338cb2f 100644 --- a/functions/strategies/ChromeStrategy.js +++ b/functions/strategies/ChromeStrategy.js @@ -3,9 +3,8 @@ const EXTENSION_ID = "amknoiejhlmhancpahfcfcfhllgkpbld"; // Check if the Chrome Extension is present // The Chrome extension injects an empty span to help detection. // Also check for the presence of window.chrome object to confirm smooth operations -export const hasChromeExtensionInstalled = () => { - return document.getElementById("chromePWExtensionDetect") !== null; -}; +export const hasChromeExtensionInstalled = () => + document.getElementById("chromePWExtensionDetect") !== null; const chromeWithoutProxy = (req, _store) => new Promise((resolve, reject) => { @@ -17,11 +16,11 @@ const chromeWithoutProxy = (req, _store) => config: req } }, - message => { - if (message.data.error) { - reject(message.data.error); + ({ data }) => { + if (data.error) { + reject(data.error); } else { - resolve(message.data.response); + resolve(data.response); } } ); @@ -43,11 +42,11 @@ const chromeWithProxy = (req, { state }) => } } }, - message => { - if (message.data.error) { + ({ data }) => { + if (data.error) { reject(error); } else { - resolve(message.data.response.data); + resolve(data.response.data); } } ); diff --git a/functions/strategies/ExtensionStrategy.js b/functions/strategies/ExtensionStrategy.js index 3305f0b6ef4..837498a1df3 100644 --- a/functions/strategies/ExtensionStrategy.js +++ b/functions/strategies/ExtensionStrategy.js @@ -1,7 +1,8 @@ const extensionWithProxy = async (req, { state }) => { const { data } = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({ method: "post", - url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", + url: + state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", data: req }); return data; From d2b73a89420cbbb64d1720f7433252db5952509a Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 20 Feb 2020 09:45:19 +0530 Subject: [PATCH 05/24] refactor: nested destructuring --- store/postwoman.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/postwoman.js b/store/postwoman.js index a0e93faaf26..acab677593b 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -139,8 +139,8 @@ export const mutations = { }, editCollection({ collections }, payload) { - const { collection, collectionIndex } = payload; - const { name } = collection; + const { collection: { name }, collectionIndex } = payload; + // const { name } = collection; const duplicateCollection = collections.some( item => item.name.toLowerCase() === name.toLowerCase() ); From 5a56081a29fa2664997ba36fb2a438ad005c694a Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 20 Feb 2020 09:46:07 +0530 Subject: [PATCH 06/24] fix: remove unused code snippet --- store/postwoman.js | 1 - 1 file changed, 1 deletion(-) diff --git a/store/postwoman.js b/store/postwoman.js index acab677593b..4b8eb235c04 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -140,7 +140,6 @@ export const mutations = { editCollection({ collections }, payload) { const { collection: { name }, collectionIndex } = payload; - // const { name } = collection; const duplicateCollection = collections.some( item => item.name.toLowerCase() === name.toLowerCase() ); From 33f2341f7f05b034383015ec79dfe9f97cf3785c Mon Sep 17 00:00:00 2001 From: Levin Rickert Date: Thu, 20 Feb 2020 19:22:10 +0100 Subject: [PATCH 07/24] Update link to extension repo in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0093dee1540..fa60e90b528 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ _**All `i18n` contributions are welcome to `i18n` [branch](https://github.com/li - **[CLI β](https://github.com/postwoman-io/postwoman-cli)** - A CLI solution for Postwoman - **Browser Extensions** - Browser extensions that simplifies access to Postwoman - [![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_16x16.png) **Firefox**](https://addons.mozilla.org/en-US/firefox/addon/postwoman) ([GitHub](https://github.com/AndrewBastin/postwoman-firefox))  |  [![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_16x16.png) **Chrome**](https://chrome.google.com/webstore/detail/postwoman-extension-for-c/amknoiejhlmhancpahfcfcfhllgkpbld) ([GitHub](https://github.com/AndrewBastin/postwoman-chrome)) + [![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_16x16.png) **Firefox**](https://addons.mozilla.org/en-US/firefox/addon/postwoman)  |  [![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_16x16.png) **Chrome**](https://chrome.google.com/webstore/detail/postwoman-extension-for-c/amknoiejhlmhancpahfcfcfhllgkpbld) ([GitHub](https://github.com/AndrewBastin/postwoman-extension)) >**Extensions fixes `CORS` issues.** From f636e7dbd4c88e9464296c4ae0541f762332d443 Mon Sep 17 00:00:00 2001 From: Levin Rickert Date: Thu, 20 Feb 2020 19:36:30 +0100 Subject: [PATCH 08/24] Adapt extension check to new extensions --- functions/network.js | 6 ++++-- functions/strategies/ExtensionStrategy.js | 3 +++ layouts/default.vue | 8 +++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/functions/network.js b/functions/network.js index 22ff13364ae..57cc634b87e 100644 --- a/functions/network.js +++ b/functions/network.js @@ -1,5 +1,7 @@ import AxiosStrategy from "./strategies/AxiosStrategy"; -import ExtensionStrategy from "./strategies/ExtensionStrategy"; +import ExtensionStrategy, { + hasExtensionInstalled +} from "./strategies/ExtensionStrategy"; import FirefoxStrategy from "./strategies/FirefoxStrategy"; import ChromeStrategy, { hasChromeExtensionInstalled @@ -11,7 +13,7 @@ const isExtensionsAllowed = ({ state }) => const runAppropriateStrategy = (req, store) => { if (isExtensionsAllowed(store)) { - if (typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== "undefined") { + if (hasExtensionInstalled()) { return ExtensionStrategy(req, store); } diff --git a/functions/strategies/ExtensionStrategy.js b/functions/strategies/ExtensionStrategy.js index 837498a1df3..e12e167e8df 100644 --- a/functions/strategies/ExtensionStrategy.js +++ b/functions/strategies/ExtensionStrategy.js @@ -1,3 +1,6 @@ +export const hasExtensionInstalled = () => + typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== "undefined"; + const extensionWithProxy = async (req, { state }) => { const { data } = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({ method: "post", diff --git a/layouts/default.vue b/layouts/default.vue index 2308fe97127..7c0ec7f1714 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -668,7 +668,7 @@ diff --git a/components/environments/editEnvironment.vue b/components/environments/editEnvironment.vue new file mode 100644 index 00000000000..adb3dc92016 --- /dev/null +++ b/components/environments/editEnvironment.vue @@ -0,0 +1,206 @@ + + + diff --git a/components/environments/environment.vue b/components/environments/environment.vue new file mode 100644 index 00000000000..8fda531985b --- /dev/null +++ b/components/environments/environment.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/components/environments/importExportEnvironment.vue b/components/environments/importExportEnvironment.vue new file mode 100644 index 00000000000..3072f6ad499 --- /dev/null +++ b/components/environments/importExportEnvironment.vue @@ -0,0 +1,170 @@ + + + diff --git a/components/environments/index.vue b/components/environments/index.vue new file mode 100644 index 00000000000..c66e2fd0fcc --- /dev/null +++ b/components/environments/index.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/lang/en-US.js b/lang/en-US.js index 9191cec5fe0..eba422b4bb5 100644 --- a/lang/en-US.js +++ b/lang/en-US.js @@ -45,6 +45,14 @@ export default { preview_html: "Preview HTML", history: "History", collections: "Collections", + environment: "Environment", + new_environment: "New Environment", + my_new_environment: "My New Environment", + edit_environment: "Edit Environment", + env_variable_list: "Variable List", + invalid_environment_name: "Please provide a valid name for the environment", + use_environment: "Use environment", + add_one_variable: "(add at least one variable)", import_curl: "Import cURL", import: "Import", generate_code: "Generate code", diff --git a/pages/index.vue b/pages/index.vue index e74fd46ea72..7096306ad81 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1075,6 +1075,11 @@
+ + +
+ +
@@ -1451,7 +1456,8 @@ export default { saveRequestAs: () => import("../components/collections/saveRequestAs"), Editor: AceEditor, inputform: () => import("../components/firebase/inputform"), - ballsfeed: () => import("../components/firebase/feeds") + ballsfeed: () => import("../components/firebase/feeds"), + environments: () => import("../components/environments") }, data() { return { @@ -2039,6 +2045,14 @@ export default { } }, methods: { + useSelectedEnvironment(environment) { + let preRequestScriptString = '' + for (let variable of environment.variables) { + preRequestScriptString = preRequestScriptString + `pw.env.set('${variable.key}', '${variable.value}');\n` + } + this.preRequestScript = preRequestScriptString + this.showPreRequestScript = true + }, checkCollections() { const checkCollectionAvailability = this.$store.state.postwoman.collections && diff --git a/store/postwoman.js b/store/postwoman.js index ab79729efc9..945932e3309 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -74,6 +74,13 @@ export const state = () => ({ requests: [] } ], + environments: [ + { + name: "My Env Variables", + variables: [] + } + ], + editingEnvironment: {}, selectedRequest: {}, editingRequest: {} }); @@ -102,6 +109,61 @@ export const mutations = { settings[key] = value; }, + removeVariables({ editingEnvironment }, value) { + editingEnvironment.variables = value + }, + + setEditingEnvironment(state, value ) { + state.editingEnvironment = {...value} + }, + + setVariableKey({ editingEnvironment }, { index, value }) { + editingEnvironment.variables[index].key = value; + }, + + setVariableValue({ editingEnvironment }, { index, value }) { + editingEnvironment.variables[index].value = value; + }, + + removeVariable({ editingEnvironment }, variables) { + editingEnvironment.variables = variables; + }, + + addVariable({ editingEnvironment }, value) { + editingEnvironment.variables.push(value); + }, + + replaceEnvironments(state, environments) { + state.environments = environments; + }, + + importAddEnvironments(state, environments) { + state.environments = [...state.environments, ...environments]; + + let index = 0; + for (let environment of state.environments) { + environment.environmentIndex = index; + index += 1; + } + }, + + removeEnvironment({ environments }, environmentIndex) { + environments.splice(environmentIndex, 1); + }, + + saveEnvironment({ environments }, payload) { + const { environment, environmentIndex } = payload; + const { name } = environment; + const duplicateEnvironment = environments.some(item => { + return item.environmentIndex !== environmentIndex && item.name.toLowerCase() === name.toLowerCase() + }); + if (duplicateEnvironment) { + this.$toast.info("Duplicate environment"); + return; + } + environments[environmentIndex] = environment; + }, + replaceCollections(state, collections) { state.collections = collections; }, @@ -323,3 +385,9 @@ export const mutations = { state.selectedRequest = Object.assign({}, request); } }; + +// export const getters = { +// getEditingEnvironment: state => { +// return state.editingEnvironment +// } +// } From 010be95ed5ffb4bbbbaa11eba614f45b6cdc3419 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Sun, 23 Feb 2020 22:43:12 +0530 Subject: [PATCH 17/24] Lint + few best practices --- components/environments/addEnvironment.vue | 11 ++-- components/environments/editEnvironment.vue | 50 +++++++++++-------- .../environments/importExportEnvironment.vue | 6 +-- components/environments/index.vue | 23 ++++++--- store/postwoman.js | 19 ++++--- 5 files changed, 63 insertions(+), 46 deletions(-) diff --git a/components/environments/addEnvironment.vue b/components/environments/addEnvironment.vue index b68768213e9..23c53d1ac36 100644 --- a/components/environments/addEnvironment.vue +++ b/components/environments/addEnvironment.vue @@ -43,7 +43,6 @@ diff --git a/store/postwoman.js b/store/postwoman.js index 951cf402773..afffa7528c5 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -110,11 +110,11 @@ export const mutations = { }, removeVariables({ editingEnvironment }, value) { - editingEnvironment.variables = value + editingEnvironment.variables = value; }, - setEditingEnvironment(state, value ) { - state.editingEnvironment = {...value} + setEditingEnvironment(state, value) { + state.editingEnvironment = { ...value }; }, setVariableKey({ editingEnvironment }, { index, value }) { @@ -154,9 +154,11 @@ export const mutations = { saveEnvironment({ environments }, payload) { const { environment, environmentIndex } = payload; const { name } = environment; - const duplicateEnvironment = environments.some(item => { - return item.environmentIndex !== environmentIndex && item.name.toLowerCase() === name.toLowerCase() - }); + const duplicateEnvironment = environments.some( + item => + item.environmentIndex !== environmentIndex && + item.name.toLowerCase() === name.toLowerCase() + ); if (duplicateEnvironment) { this.$toast.info("Duplicate environment"); return; @@ -201,7 +203,10 @@ export const mutations = { }, editCollection({ collections }, payload) { - const { collection: { name }, collectionIndex } = payload; + const { + collection: { name }, + collectionIndex + } = payload; const duplicateCollection = collections.some( item => item.name.toLowerCase() === name.toLowerCase() ); From d24c572d7f383847dfeeb3f6dc4e2e5e5083c634 Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Mon, 24 Feb 2020 00:30:22 +0530 Subject: [PATCH 18/24] Firebase sync --- .../collections/importExportCollections.vue | 133 +++++++++++------- components/environments/addEnvironment.vue | 12 ++ .../environments/importExportEnvironment.vue | 16 ++- components/environments/index.vue | 17 ++- functions/fb.js | 29 ++++ lang/en-US.js | 4 +- pages/index.vue | 18 +-- pages/settings.vue | 11 +- 8 files changed, 164 insertions(+), 76 deletions(-) diff --git a/components/collections/importExportCollections.vue b/components/collections/importExportCollections.vue index 6d79fb21e74..44ebe6c1361 100644 --- a/components/collections/importExportCollections.vue +++ b/components/collections/importExportCollections.vue @@ -121,12 +121,19 @@ export default { let content = event.target.result; let collections = JSON.parse(content); if (collections[0]) { - let [ name, folders, requests ] = Object.keys(collections[0]) - if (name === 'name' && folders === 'folders' && requests === 'requests') { + let [name, folders, requests] = Object.keys(collections[0]); + if ( + name === "name" && + folders === "folders" && + requests === "requests" + ) { // Do nothing } - } else if (collections.info && collections.info.schema.includes('v2.1.0')) { - collections = this.parsePostmanCollection(collections) + } else if ( + collections.info && + collections.info.schema.includes("v2.1.0") + ) { + collections = this.parsePostmanCollection(collections); } else { return this.failedImport(); } @@ -141,11 +148,18 @@ export default { let content = event.target.result; let collections = JSON.parse(content); if (collections[0]) { - let [ name, folders, requests ] = Object.keys(collections[0]) - if (name === 'name' && folders === 'folders' && requests === 'requests') { + let [name, folders, requests] = Object.keys(collections[0]); + if ( + name === "name" && + folders === "folders" && + requests === "requests" + ) { // Do nothing } - } else if (collections.info && collections.info.schema.includes('v2.1.0')) { + } else if ( + collections.info && + collections.info.schema.includes("v2.1.0") + ) { collections = this.parsePostmanCollection(collections); } else { return this.failedImport(); @@ -188,28 +202,38 @@ export default { }); }, parsePostmanCollection(collection, folders = true) { - let postwomanCollection = folders ? [{ - "name": "", - "folders": [], - "requests": [] - }] + let postwomanCollection = folders + ? [ + { + name: "", + folders: [], + requests: [] + } + ] : { - "name": "", - "requests": [] - }; - for(let collectionItem of collection.item) { + name: "", + requests: [] + }; + for (let collectionItem of collection.item) { if (collectionItem.request) { if (postwomanCollection[0]) { - postwomanCollection[0].name = collection.info ? collection.info.name : ""; - postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem)); + postwomanCollection[0].name = collection.info + ? collection.info.name + : ""; + postwomanCollection[0].requests.push( + this.parsePostmanRequest(collectionItem) + ); } else { - postwomanCollection.name = collection.name ? collection.name - : ""; - postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem)); + postwomanCollection.name = collection.name ? collection.name : ""; + postwomanCollection.requests.push( + this.parsePostmanRequest(collectionItem) + ); } } else if (collectionItem.item) { if (collectionItem.item[0]) { - postwomanCollection[0].folders.push(this.parsePostmanCollection(collectionItem, false)); + postwomanCollection[0].folders.push( + this.parsePostmanCollection(collectionItem, false) + ); } } } @@ -217,46 +241,51 @@ export default { }, parsePostmanRequest(requestObject) { let pwRequest = { - "url": "", - "path": "", - "method": "", - "auth": "", - "httpUser": "", - "httpPassword": "", - "passwordFieldType": "password", - "bearerToken": "", - "headers": [], - "params": [], - "bodyParams": [], - "rawParams": "", - "rawInput": false, - "contentType": "", - "requestType": "", - "name": "", + url: "", + path: "", + method: "", + auth: "", + httpUser: "", + httpPassword: "", + passwordFieldType: "password", + bearerToken: "", + headers: [], + params: [], + bodyParams: [], + rawParams: "", + rawInput: false, + contentType: "", + requestType: "", + name: "" }; pwRequest.name = requestObject.name; - let requestObjectUrl = requestObject.request.url.raw.match(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/); + let requestObjectUrl = requestObject.request.url.raw.match( + /^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/ + ); pwRequest.url = requestObjectUrl[1]; pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : ""; pwRequest.method = requestObject.request.method; - let itemAuth = requestObject.request.auth ? requestObject.request.auth - : ""; - let authType = itemAuth ? itemAuth.type + let itemAuth = requestObject.request.auth + ? requestObject.request.auth : ""; + let authType = itemAuth ? itemAuth.type : ""; if (authType === "basic") { pwRequest.auth = "Basic Auth"; - pwRequest.httpUser = itemAuth.basic[0].key === "username" - ? itemAuth.basic[0].value - : itemAuth.basic[1].value; - pwRequest.httpPassword = itemAuth.basic[0].key === "password" - ? itemAuth.basic[0].value - : itemAuth.basic[1].value; + pwRequest.httpUser = + itemAuth.basic[0].key === "username" + ? itemAuth.basic[0].value + : itemAuth.basic[1].value; + pwRequest.httpPassword = + itemAuth.basic[0].key === "password" + ? itemAuth.basic[0].value + : itemAuth.basic[1].value; } else if (authType === "oauth2") { pwRequest.auth = "OAuth 2.0"; - pwRequest.bearerToken = itemAuth.oauth2[0].key === "accessToken" - ? itemAuth.oauth2[0].value - : itemAuth.oauth2[1].value; + pwRequest.bearerToken = + itemAuth.oauth2[0].key === "accessToken" + ? itemAuth.oauth2[0].value + : itemAuth.oauth2[1].value; } else if (authType === "bearer") { pwRequest.auth = "Bearer Token"; pwRequest.bearerToken = itemAuth.bearer[0].value; @@ -280,7 +309,7 @@ export default { if (requestObject.request.body.mode === "urlencoded") { let params = requestObject.request.body.urlencoded; pwRequest.bodyParams = params ? params : []; - for(let param of pwRequest.bodyParams) { + for (let param of pwRequest.bodyParams) { delete param.type; } } else if (requestObject.request.body.mode === "raw") { diff --git a/components/environments/addEnvironment.vue b/components/environments/addEnvironment.vue index 23c53d1ac36..a87873e18ac 100644 --- a/components/environments/addEnvironment.vue +++ b/components/environments/addEnvironment.vue @@ -43,6 +43,8 @@ diff --git a/functions/fb.js b/functions/fb.js index c73a655fcd2..32076b51d34 100644 --- a/functions/fb.js +++ b/functions/fb.js @@ -26,6 +26,7 @@ export const fb = { currentSettings: [], currentHistory: [], currentCollections: [], + currentEnvironments: [], writeFeeds: async (message, label) => { const dt = { createdOn: new Date(), @@ -112,6 +113,21 @@ export const fb = { .doc("sync") .set(cl) .catch(e => console.error("error updating", cl, e)); + }, + writeEnvironments: async environment => { + const ev = { + updatedOn: new Date(), + author: fb.currentUser.uid, + author_name: fb.currentUser.displayName, + author_image: fb.currentUser.photoURL, + environment: environment + }; + usersCollection + .doc(fb.currentUser.uid) + .collection("environments") + .doc("sync") + .set(ev) + .catch(e => console.error("error updating", ev, e)); } }; @@ -186,6 +202,19 @@ firebase.auth().onAuthStateChanged(user => { }); fb.currentCollections = collections[0].collection; }); + + usersCollection + .doc(fb.currentUser.uid) + .collection("environments") + .onSnapshot(environmentsRef => { + const environments = []; + environmentsRef.forEach(doc => { + const environment = doc.data(); + environment.id = doc.id; + environments.push(environment); + }); + fb.currentEnvironments = environments[0].environment; + }); } else { fb.currentUser = null; } diff --git a/lang/en-US.js b/lang/en-US.js index 6986063e332..e541cdf08a1 100644 --- a/lang/en-US.js +++ b/lang/en-US.js @@ -256,7 +256,8 @@ export default { enter_curl: "Enter cURL", empty: "Empty", extensions: "Extensions", - extensions_use_toggle: "Use the browser extension to send requests (if present)", + extensions_use_toggle: + "Use the browser extension to send requests (if present)", extensions_info1: "Browser extension that simplifies access to Postwoman", extensions_info2: "Get Postwoman browser extension!", installed: "Installed", @@ -267,6 +268,7 @@ export default { sync: "Sync", syncHistory: "History", syncCollections: "Collections", + syncEnvironments: "Environments", turn_on: "Turn on", login_first: "Login first", paste_a_note: "Paste a note", diff --git a/pages/index.vue b/pages/index.vue index 95bc8fe09cc..85fd5938f66 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1086,7 +1086,7 @@
- +
    @@ -1456,7 +1456,7 @@ export default { saveRequestAs: () => import("../components/collections/saveRequestAs"), Editor: AceEditor, inputform: () => import("../components/firebase/inputform"), - ballsfeed: () => import("../components/firebase/feeds"), + notes: () => import("../components/firebase/feeds"), environments: () => import("../components/environments") }, data() { @@ -2047,12 +2047,14 @@ export default { }, methods: { useSelectedEnvironment(environment) { - let preRequestScriptString = '' + let preRequestScriptString = ""; for (let variable of environment.variables) { - preRequestScriptString = preRequestScriptString + `pw.env.set('${variable.key}', '${variable.value}');\n` + preRequestScriptString = + preRequestScriptString + + `pw.env.set('${variable.key}', '${variable.value}');\n`; } - this.preRequestScript = preRequestScriptString - this.showPreRequestScript = true + this.preRequestScript = preRequestScriptString; + this.showPreRequestScript = true; }, checkCollections() { const checkCollectionAvailability = @@ -2247,7 +2249,7 @@ export default { }; this.$refs.historyComponent.addEntry(entry); if (fb.currentUser !== null) { - if (fb.currentSettings[1].value) { + if (fb.currentSettings[2].value) { fb.writeHistory(entry); } } @@ -2284,7 +2286,7 @@ export default { }; this.$refs.historyComponent.addEntry(entry); if (fb.currentUser !== null) { - if (fb.currentSettings[1].value) { + if (fb.currentSettings[2].value) { fb.writeHistory(entry); } } diff --git a/pages/settings.vue b/pages/settings.vue index 345ceea7305..bd8ba090a51 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -38,7 +38,7 @@ {{ setting.value ? $t("enabled") : $t("disabled") }}

    -

    +