From cd11ea96fa26f4225eea02fd8c8480d029650250 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Wed, 14 Aug 2019 16:50:50 +0200 Subject: [PATCH] :bug: Fixed issue in utils/backend --- .circleci/config.yml | 8 +++ packages/utils/src/backend/index.js | 85 ++++++++++++++++------------- 2 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000000..8e041859d6f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,8 @@ +version: 2 + jobs: + build: + docker: + - image: circleci/node:lts + steps: + - checkout + - run: npm install --global lerna && lerna bootstrap diff --git a/packages/utils/src/backend/index.js b/packages/utils/src/backend/index.js index 7d19ce9d92a..7b86f6610b4 100644 --- a/packages/utils/src/backend/index.js +++ b/packages/utils/src/backend/index.js @@ -1,61 +1,68 @@ -import axios from 'axios' +import axios from "axios"; function useBackend(baseURL, timeout = 10000) { // Configure Axios - const api = axios.create({ baseURL, timeout }) + const api = axios.create({ baseURL, timeout }); // Helper method for Authorization header const auth = token => ({ - headers: { Authorization: 'Bearer ' + token } - }) + headers: { Authorization: "Bearer " + token } + }); - const backend = {} + const backend = {}; // Oauth - backend.initOauth = data => api.post('/oauth/init', data) // Init Oauth (to get state) - backend.providerLogin = data => api.post('/oauth/login', data) // Finalize Oauth login + backend.initOauth = data => api.post("/oauth/init", data); // Init Oauth (to get state) + backend.providerLogin = data => api.post("/oauth/login", data); // Finalize Oauth login // Signup flow - backend.signup = (email, password, language) => api.post('/signup', { email, password, language }) // Signup - backend.confirm = confirmId => api.post('/account', { id: confirmId }) // Confirm - backend.createAccount = (confirmId, consent) => api.post('/account', { id: confirmId, consent }) // Create account + backend.signup = (email, password, language) => + api.post("/signup", { email, password, language }); // Signup + backend.confirm = confirmId => api.post("/account", { id: confirmId }); // Confirm + backend.createAccount = (confirmId, consent) => + api.post("/account", { id: confirmId, consent }); // Create account // Other non-authenticated calls - backend.login = (username, password) => api.post('/login', { username, password }) // Login - backend.confirmationLogin = id => api.post('/confirm/login', { id }) // Confirmation-based login - backend.resetPassword = username => api.post('/reset/password', { username: username }) // Ask for a password reset - backend.loadGist = handle => api.get('/gist/' + handle) // Load recipe/gist anonymously - backend.loadPatrons = handle => api.get('/patrons') // Load patron list + backend.login = (username, password) => + api.post("/login", { username, password }); // Login + backend.confirmationLogin = id => api.post("/confirm/login", { id }); // Confirmation-based login + backend.resetPassword = username => + api.post("/reset/password", { username: username }); // Ask for a password reset + backend.loadGist = handle => api.get("/gist/" + handle); // Load recipe/gist anonymously + backend.loadPatrons = handle => api.get("/patrons"); // Load patron list // Users - backend.profile = (username, token) => api.get('/users/' + username, auth(token)) // Load user profile - backend.account = token => api.get('/account', auth(token)) // Try to authenticate based on stored token - backend.export = token => api.get('/export', auth(token)) // Export data - backend.restrict = token => api.get('/restrict', auth(token)) // Restrict data processing (freeze account) - backend.remove = token => api.get('/remove', auth(token)) // Remove account - backend.saveAccount = (data, token) => api.put('/account', data, auth(token)) // Update account - backend.availableUsername = (data, token) => api.post('/available/username', data, auth(token)) // Check is a username is available - backend.setPassword = (data, token) => api.post('/set/password', data, auth(token)) // (re)set a new password + backend.profile = (username, token) => + api.get("/users/" + username, auth(token)); // Load user profile + backend.account = token => api.get("/account", auth(token)); // Try to authenticate based on stored token + backend.export = token => api.get("/export", auth(token)); // Export data + backend.restrict = token => api.get("/restrict", auth(token)); // Restrict data processing (freeze account) + backend.remove = token => api.get("/remove", auth(token)); // Remove account + backend.saveAccount = (data, token) => api.put("/account", data, auth(token)); // Update account + backend.availableUsername = (data, token) => + api.post("/available/username", data, auth(token)); // Check is a username is available + backend.setPassword = (data, token) => + api.post("/set/password", data, auth(token)); // (re)set a new password // Models - backend.createModel = (data, token) => api.post('/model', data, auth(token)) // Create model - backend.saveModel = (handle, data, token) => api.put('/model/' + handle, data, auth(token)) // Update model - backend.removeModel = (handle, token) => api.delete('/model/' + handle, auth(token)) // Remove model - backend.removeModels = (data, token) => api.post('/remove/models', data, auth(token)) // Delete multiple models + backend.createModel = (data, token) => api.post("/models", data, auth(token)); // Create model + backend.saveModel = (handle, data, token) => + api.put("/models/" + handle, data, auth(token)); // Update model + backend.removeModel = (handle, token) => + api.delete("/models/" + handle, auth(token)); // Remove model + //backend.removeModels = (data, token) => api.post('/remove/models', data, auth(token)) // Delete multiple models // Recipes - backend.loadRecipe = (handle, token) => api.get('/recipe/' + handle, auth(token)) // Load recipe - backend.createRecipe = (data, token) => api.post('/recipe', data, auth(token)) // Create recipe - backend.removeRecipe = (handle, token) => api.delete('/recipe/' + handle, auth(token)) // Remove recipe - backend.saveRecipe = (handle, data, token) => api.put('/recipe/' + handle, data, auth(token)) // Update recipe + backend.loadRecipe = (handle, token) => + api.get("/recipes/" + handle, auth(token)); // Load recipe + backend.createRecipe = (data, token) => + api.post("/recipes", data, auth(token)); // Create recipe + backend.removeRecipe = (handle, token) => + api.delete("/recipes/" + handle, auth(token)); // Remove recipe + backend.saveRecipe = (handle, data, token) => + api.put("/recipes/" + handle, data, auth(token)); // Update recipe - //backend.createDraft = (data, token) => api.post("/draft", data, auth(token)); // Create draft - //backend.saveDraft = (handle, data, token) => - // api.put("/draft/" + handle, data, auth(token)); // Update draft - //backend.removeDrafts = (data, token) => - // api.post("/remove/drafts", data, auth(token)); // Delete multiple drafts - - return backend + return backend; } -export default useBackend +export default useBackend;