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 new file mode 100644 index 00000000000..43ef6636bf6 --- /dev/null +++ b/components/environments/addEnvironment.vue @@ -0,0 +1,94 @@ + + + diff --git a/components/environments/editEnvironment.vue b/components/environments/editEnvironment.vue new file mode 100644 index 00000000000..9c15b33e289 --- /dev/null +++ b/components/environments/editEnvironment.vue @@ -0,0 +1,221 @@ + + + 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..9b834c376b6 --- /dev/null +++ b/components/environments/importExportEnvironment.vue @@ -0,0 +1,173 @@ + + + diff --git a/components/environments/index.vue b/components/environments/index.vue new file mode 100644 index 00000000000..9ea17141054 --- /dev/null +++ b/components/environments/index.vue @@ -0,0 +1,147 @@ + + + + + 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 63b786060b2..bf055db9610 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", @@ -248,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", @@ -259,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 5a199673468..c22b822a419 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1075,13 +1075,18 @@
+ + +
+ +
- +
    @@ -1452,7 +1457,8 @@ 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() { return { @@ -2044,6 +2050,16 @@ 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 && @@ -2237,7 +2253,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); } } @@ -2274,7 +2290,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") }}

    -

    +