From 4dcd482a4fed1ae7201c539df39a2a582c940a57 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Fri, 19 Jun 2020 17:19:30 +0100 Subject: [PATCH] instance Id is gone from API module --- packages/builder/src/builderStore/api.js | 30 +++++-------------- .../builder/src/builderStore/store/backend.js | 4 +-- .../src/builderStore/store/workflow/index.js | 16 +++++----- .../ModelDataTable/ModelDataTable.svelte | 4 +-- .../components/database/ModelDataTable/api.js | 16 +++++----- .../CreateEditModel/CreateEditModel.svelte | 3 +- .../modals/CreateEditRecord.svelte | 3 -- .../modals/CreateEditView.svelte | 2 +- .../ModelDataTable/modals/CreateUser.svelte | 3 +- .../ModelDataTable/modals/DeleteRecord.svelte | 3 +- .../nav/SchemaManagementDrawer.svelte | 2 +- .../src/components/nav/UsersList.svelte | 3 +- .../src/api/routes/tests/couchTestUtils.js | 1 - 13 files changed, 33 insertions(+), 57 deletions(-) diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/builderStore/api.js index 795aaf8cd7..116222409f 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/builderStore/api.js @@ -1,10 +1,6 @@ -const apiCall = (method, instanceId) => async (url, body) => { +const apiCall = method => async (url, body) => { const headers = { "Content-Type": "application/json", - "x-user-agent": "Budibase Builder", - } - if (instanceId) { - headers["x-budibase-instanceid"] = instanceId } const response = await fetch(url, { method: method, @@ -21,20 +17,10 @@ export const patch = apiCall("PATCH") export const del = apiCall("DELETE") export const put = apiCall("PUT") -// usage: api(instanceId).post(...) ... will supply instance Id in header -const api = instanceId => ({ - post: apiCall("POST", instanceId), - get: apiCall("GET", instanceId), - patch: apiCall("PATCH", instanceId), - delete: apiCall("DELETE", instanceId), - put: apiCall("PUT", instanceId), -}) - -// usage: api.post(...)... will not supply instanceid in header -api.post = apiCall("POST") -api.get = apiCall("GET") -api.patch = apiCall("PATCH") -api.delete = apiCall("DELETE") -api.put = apiCall("PUT") - -export default api +export default { + post: apiCall("POST"), + get: apiCall("GET"), + patch: apiCall("PATCH"), + delete: apiCall("DELETE"), + put: apiCall("PUT"), +} diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 6efb980506..53bdaa3360 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -24,8 +24,8 @@ export const getBackendUiStore = () => { store.actions = { database: { select: async db => { - const modelsResponse = await api(db._id).get(`/api/models`) - const viewsResponse = await api(db._id).get(`/api/views`) + const modelsResponse = await api.get(`/api/models`) + const viewsResponse = await api.get(`/api/views`) const models = await modelsResponse.json() const views = await viewsResponse.json() store.update(state => { diff --git a/packages/builder/src/builderStore/store/workflow/index.js b/packages/builder/src/builderStore/store/workflow/index.js index 7c814c27ee..d794868df3 100644 --- a/packages/builder/src/builderStore/store/workflow/index.js +++ b/packages/builder/src/builderStore/store/workflow/index.js @@ -12,7 +12,7 @@ const workflowActions = store => ({ return state }) }, - create: async ({ instanceId, name }) => { + create: async ({ name }) => { const workflow = { name, definition: { @@ -20,7 +20,7 @@ const workflowActions = store => ({ }, } const CREATE_WORKFLOW_URL = `/api/workflows` - const response = await api(instanceId).post(CREATE_WORKFLOW_URL, workflow) + const response = await api.post(CREATE_WORKFLOW_URL, workflow) const json = await response.json() store.update(state => { state.workflows = state.workflows.concat(json.workflow) @@ -28,9 +28,9 @@ const workflowActions = store => ({ return state }) }, - save: async ({ instanceId, workflow }) => { + save: async ({ workflow }) => { const UPDATE_WORKFLOW_URL = `/api/workflows` - const response = await api(instanceId).put(UPDATE_WORKFLOW_URL, workflow) + const response = await api.put(UPDATE_WORKFLOW_URL, workflow) const json = await response.json() store.update(state => { const existingIdx = state.workflows.findIndex( @@ -42,9 +42,9 @@ const workflowActions = store => ({ return state }) }, - update: async ({ instanceId, workflow }) => { + update: async ({ workflow }) => { const UPDATE_WORKFLOW_URL = `/api/workflows` - const response = await api(instanceId).put(UPDATE_WORKFLOW_URL, workflow) + const response = await api.put(UPDATE_WORKFLOW_URL, workflow) const json = await response.json() store.update(state => { const existingIdx = state.workflows.findIndex( @@ -55,10 +55,10 @@ const workflowActions = store => ({ return state }) }, - delete: async ({ instanceId, workflow }) => { + delete: async ({ workflow }) => { const { _id, _rev } = workflow const DELETE_WORKFLOW_URL = `/api/workflows/${_id}/${_rev}` - await api(instanceId).delete(DELETE_WORKFLOW_URL) + await api.delete(DELETE_WORKFLOW_URL) store.update(state => { const existingIdx = state.workflows.findIndex( diff --git a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte index f1d49894a0..8eb6defa8f 100644 --- a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte +++ b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte @@ -53,12 +53,10 @@ let views = [] let currentPage = 0 - $: instanceId = $backendUiStore.selectedDatabase._id - $: { if ($backendUiStore.selectedView) { api - .fetchDataForView($backendUiStore.selectedView, instanceId) + .fetchDataForView($backendUiStore.selectedView) .then(records => { data = records || [] headers = Object.keys($backendUiStore.selectedModel.schema).filter( diff --git a/packages/builder/src/components/database/ModelDataTable/api.js b/packages/builder/src/components/database/ModelDataTable/api.js index 9fb6651983..f50290b091 100644 --- a/packages/builder/src/components/database/ModelDataTable/api.js +++ b/packages/builder/src/components/database/ModelDataTable/api.js @@ -1,8 +1,8 @@ import api from "builderStore/api" -export async function createUser(user, instanceId) { +export async function createUser(user) { const CREATE_USER_URL = `/api/users` - const response = await api(instanceId).post(CREATE_USER_URL, user) + const response = await api.post(CREATE_USER_URL, user) return await response.json() } @@ -14,22 +14,22 @@ export async function createDatabase(appname, instanceName) { return await response.json() } -export async function deleteRecord(record, instanceId) { +export async function deleteRecord(record) { const DELETE_RECORDS_URL = `/api/${record._modelId}/records/${record._id}/${record._rev}` - const response = await api(instanceId).delete(DELETE_RECORDS_URL) + const response = await api.delete(DELETE_RECORDS_URL) return response } -export async function saveRecord(record, instanceId, modelId) { +export async function saveRecord(record, modelId) { const SAVE_RECORDS_URL = `/api/${modelId}/records` - const response = await api(instanceId).post(SAVE_RECORDS_URL, record) + const response = await api.post(SAVE_RECORDS_URL, record) return await response.json() } -export async function fetchDataForView(viewName, instanceId) { +export async function fetchDataForView(viewName) { const FETCH_RECORDS_URL = `/api/views/${viewName}` - const response = await api(instanceId).get(FETCH_RECORDS_URL) + const response = await api.get(FETCH_RECORDS_URL) return await response.json() } diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte index 6fb6cc8a2f..9e80ec4ca1 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte @@ -18,7 +18,6 @@ let fieldToEdit $: modelFields = model.schema ? Object.entries(model.schema) : [] - $: instanceId = $backendUiStore.selectedDatabase._id function editField() {} @@ -28,7 +27,7 @@ async function saveModel() { const SAVE_MODEL_URL = `/api/models` - const response = await api(instanceId).post(SAVE_MODEL_URL, model) + const response = await api.post(SAVE_MODEL_URL, model) const newModel = await response.json() backendUiStore.actions.models.create(newModel) onClosed() diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte index 62688d58e3..a97cdc0ca1 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte @@ -14,8 +14,6 @@ let errors = [] let selectedModel - $: instanceId = $backendUiStore.selectedDatabase._id - $: modelSchema = $backendUiStore.selectedModel ? Object.entries($backendUiStore.selectedModel.schema) : [] @@ -49,7 +47,6 @@ ...record, modelId: $backendUiStore.selectedModel._id, }, - instanceId, $backendUiStore.selectedModel._id ) if (recordResponse.errors) { diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte index 6f9f5dac1a..53cb3e2cc6 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte @@ -30,7 +30,7 @@ async function saveView() { const SAVE_VIEW_URL = `/api/views` - const response = await api(instanceId).post(SAVE_VIEW_URL, view) + const response = await api.post(SAVE_VIEW_URL, view) backendUiStore.update(state => { state.views = [...state.views, response.view] return state diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte index d5c924405f..60b77111d3 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte @@ -10,12 +10,11 @@ let accessLevelId $: valid = username && password && accessLevelId - $: instanceId = $backendUiStore.selectedDatabase._id $: appId = $store.appId async function createUser() { const user = { name: username, username, password, accessLevelId } - const response = await api.createUser(user, instanceId) + const response = await api.createUser(user) backendUiStore.actions.users.create(response) onClosed() } diff --git a/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte index 05ecfcd85f..aa192b32eb 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/DeleteRecord.svelte @@ -6,7 +6,6 @@ export let record export let onClosed - $: instanceId = $backendUiStore.selectedDatabase._id
@@ -25,7 +24,7 @@ { - await api.deleteRecord(record, instanceId) + await api.deleteRecord(record) backendUiStore.actions.records.delete(record) onClosed() }}> diff --git a/packages/builder/src/components/nav/SchemaManagementDrawer.svelte b/packages/builder/src/components/nav/SchemaManagementDrawer.svelte index de7d010894..9465c85140 100644 --- a/packages/builder/src/components/nav/SchemaManagementDrawer.svelte +++ b/packages/builder/src/components/nav/SchemaManagementDrawer.svelte @@ -53,7 +53,7 @@ async function deleteModel(modelToDelete) { const DELETE_MODEL_URL = `/api/models/${node._id}/${node._rev}` - const response = await api(instanceId).delete(DELETE_MODEL_URL) + const response = await api.delete(DELETE_MODEL_URL) backendUiStore.update(state => { state.models = state.models.filter( model => model._id !== modelToDelete._id diff --git a/packages/builder/src/components/nav/UsersList.svelte b/packages/builder/src/components/nav/UsersList.svelte index 29bc4a4ed3..e213aa066c 100644 --- a/packages/builder/src/components/nav/UsersList.svelte +++ b/packages/builder/src/components/nav/UsersList.svelte @@ -12,12 +12,11 @@ $: currentAppInfo = { appname: $store.appname, - instanceId: $backendUiStore.selectedDatabase._id, } async function fetchUsers() { const FETCH_USERS_URL = `/api/users` - const response = await api(currentAppInfo.instanceId).get(FETCH_USERS_URL) + const response = await api.get(FETCH_USERS_URL) const users = await response.json() backendUiStore.update(state => { state.users = users diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index 9b8aedd453..17f096ec6b 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -37,7 +37,6 @@ exports.defaultHeaders = (appId, instanceId) => { return { Accept: "application/json", Cookie: [`builder:token=${builderToken}`], - "x-user-agent": "Budibase Builder", } }