instance Id is gone from API module
This commit is contained in:
parent
d7b09f5b65
commit
4dcd482a4f
|
@ -1,10 +1,6 @@
|
||||||
const apiCall = (method, instanceId) => async (url, body) => {
|
const apiCall = method => async (url, body) => {
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-user-agent": "Budibase Builder",
|
|
||||||
}
|
|
||||||
if (instanceId) {
|
|
||||||
headers["x-budibase-instanceid"] = instanceId
|
|
||||||
}
|
}
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
|
@ -21,20 +17,10 @@ export const patch = apiCall("PATCH")
|
||||||
export const del = apiCall("DELETE")
|
export const del = apiCall("DELETE")
|
||||||
export const put = apiCall("PUT")
|
export const put = apiCall("PUT")
|
||||||
|
|
||||||
// usage: api(instanceId).post(...) ... will supply instance Id in header
|
export default {
|
||||||
const api = instanceId => ({
|
post: apiCall("POST"),
|
||||||
post: apiCall("POST", instanceId),
|
get: apiCall("GET"),
|
||||||
get: apiCall("GET", instanceId),
|
patch: apiCall("PATCH"),
|
||||||
patch: apiCall("PATCH", instanceId),
|
delete: apiCall("DELETE"),
|
||||||
delete: apiCall("DELETE", instanceId),
|
put: apiCall("PUT"),
|
||||||
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
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ export const getBackendUiStore = () => {
|
||||||
store.actions = {
|
store.actions = {
|
||||||
database: {
|
database: {
|
||||||
select: async db => {
|
select: async db => {
|
||||||
const modelsResponse = await api(db._id).get(`/api/models`)
|
const modelsResponse = await api.get(`/api/models`)
|
||||||
const viewsResponse = await api(db._id).get(`/api/views`)
|
const viewsResponse = await api.get(`/api/views`)
|
||||||
const models = await modelsResponse.json()
|
const models = await modelsResponse.json()
|
||||||
const views = await viewsResponse.json()
|
const views = await viewsResponse.json()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
|
|
|
@ -12,7 +12,7 @@ const workflowActions = store => ({
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
create: async ({ instanceId, name }) => {
|
create: async ({ name }) => {
|
||||||
const workflow = {
|
const workflow = {
|
||||||
name,
|
name,
|
||||||
definition: {
|
definition: {
|
||||||
|
@ -20,7 +20,7 @@ const workflowActions = store => ({
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const CREATE_WORKFLOW_URL = `/api/workflows`
|
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()
|
const json = await response.json()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.workflows = state.workflows.concat(json.workflow)
|
state.workflows = state.workflows.concat(json.workflow)
|
||||||
|
@ -28,9 +28,9 @@ const workflowActions = store => ({
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
save: async ({ instanceId, workflow }) => {
|
save: async ({ workflow }) => {
|
||||||
const UPDATE_WORKFLOW_URL = `/api/workflows`
|
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()
|
const json = await response.json()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
const existingIdx = state.workflows.findIndex(
|
const existingIdx = state.workflows.findIndex(
|
||||||
|
@ -42,9 +42,9 @@ const workflowActions = store => ({
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
update: async ({ instanceId, workflow }) => {
|
update: async ({ workflow }) => {
|
||||||
const UPDATE_WORKFLOW_URL = `/api/workflows`
|
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()
|
const json = await response.json()
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
const existingIdx = state.workflows.findIndex(
|
const existingIdx = state.workflows.findIndex(
|
||||||
|
@ -55,10 +55,10 @@ const workflowActions = store => ({
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
delete: async ({ instanceId, workflow }) => {
|
delete: async ({ workflow }) => {
|
||||||
const { _id, _rev } = workflow
|
const { _id, _rev } = workflow
|
||||||
const DELETE_WORKFLOW_URL = `/api/workflows/${_id}/${_rev}`
|
const DELETE_WORKFLOW_URL = `/api/workflows/${_id}/${_rev}`
|
||||||
await api(instanceId).delete(DELETE_WORKFLOW_URL)
|
await api.delete(DELETE_WORKFLOW_URL)
|
||||||
|
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
const existingIdx = state.workflows.findIndex(
|
const existingIdx = state.workflows.findIndex(
|
||||||
|
|
|
@ -53,12 +53,10 @@
|
||||||
let views = []
|
let views = []
|
||||||
let currentPage = 0
|
let currentPage = 0
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if ($backendUiStore.selectedView) {
|
if ($backendUiStore.selectedView) {
|
||||||
api
|
api
|
||||||
.fetchDataForView($backendUiStore.selectedView, instanceId)
|
.fetchDataForView($backendUiStore.selectedView)
|
||||||
.then(records => {
|
.then(records => {
|
||||||
data = records || []
|
data = records || []
|
||||||
headers = Object.keys($backendUiStore.selectedModel.schema).filter(
|
headers = Object.keys($backendUiStore.selectedModel.schema).filter(
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
export async function createUser(user, instanceId) {
|
export async function createUser(user) {
|
||||||
const CREATE_USER_URL = `/api/users`
|
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()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,22 +14,22 @@ export async function createDatabase(appname, instanceName) {
|
||||||
return await response.json()
|
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 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
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveRecord(record, instanceId, modelId) {
|
export async function saveRecord(record, modelId) {
|
||||||
const SAVE_RECORDS_URL = `/api/${modelId}/records`
|
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()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchDataForView(viewName, instanceId) {
|
export async function fetchDataForView(viewName) {
|
||||||
const FETCH_RECORDS_URL = `/api/views/${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()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
let fieldToEdit
|
let fieldToEdit
|
||||||
|
|
||||||
$: modelFields = model.schema ? Object.entries(model.schema) : []
|
$: modelFields = model.schema ? Object.entries(model.schema) : []
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
|
|
||||||
function editField() {}
|
function editField() {}
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@
|
||||||
|
|
||||||
async function saveModel() {
|
async function saveModel() {
|
||||||
const SAVE_MODEL_URL = `/api/models`
|
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()
|
const newModel = await response.json()
|
||||||
backendUiStore.actions.models.create(newModel)
|
backendUiStore.actions.models.create(newModel)
|
||||||
onClosed()
|
onClosed()
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
let errors = []
|
let errors = []
|
||||||
let selectedModel
|
let selectedModel
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
|
|
||||||
$: modelSchema = $backendUiStore.selectedModel
|
$: modelSchema = $backendUiStore.selectedModel
|
||||||
? Object.entries($backendUiStore.selectedModel.schema)
|
? Object.entries($backendUiStore.selectedModel.schema)
|
||||||
: []
|
: []
|
||||||
|
@ -49,7 +47,6 @@
|
||||||
...record,
|
...record,
|
||||||
modelId: $backendUiStore.selectedModel._id,
|
modelId: $backendUiStore.selectedModel._id,
|
||||||
},
|
},
|
||||||
instanceId,
|
|
||||||
$backendUiStore.selectedModel._id
|
$backendUiStore.selectedModel._id
|
||||||
)
|
)
|
||||||
if (recordResponse.errors) {
|
if (recordResponse.errors) {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
async function saveView() {
|
async function saveView() {
|
||||||
const SAVE_VIEW_URL = `/api/views`
|
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 => {
|
backendUiStore.update(state => {
|
||||||
state.views = [...state.views, response.view]
|
state.views = [...state.views, response.view]
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
let accessLevelId
|
let accessLevelId
|
||||||
|
|
||||||
$: valid = username && password && accessLevelId
|
$: valid = username && password && accessLevelId
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
$: appId = $store.appId
|
$: appId = $store.appId
|
||||||
|
|
||||||
async function createUser() {
|
async function createUser() {
|
||||||
const user = { name: username, username, password, accessLevelId }
|
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)
|
backendUiStore.actions.users.create(response)
|
||||||
onClosed()
|
onClosed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
export let record
|
export let record
|
||||||
export let onClosed
|
export let onClosed
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase._id
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -25,7 +24,7 @@
|
||||||
<ActionButton
|
<ActionButton
|
||||||
alert
|
alert
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
await api.deleteRecord(record, instanceId)
|
await api.deleteRecord(record)
|
||||||
backendUiStore.actions.records.delete(record)
|
backendUiStore.actions.records.delete(record)
|
||||||
onClosed()
|
onClosed()
|
||||||
}}>
|
}}>
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
async function deleteModel(modelToDelete) {
|
async function deleteModel(modelToDelete) {
|
||||||
const DELETE_MODEL_URL = `/api/models/${node._id}/${node._rev}`
|
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 => {
|
backendUiStore.update(state => {
|
||||||
state.models = state.models.filter(
|
state.models = state.models.filter(
|
||||||
model => model._id !== modelToDelete._id
|
model => model._id !== modelToDelete._id
|
||||||
|
|
|
@ -12,12 +12,11 @@
|
||||||
|
|
||||||
$: currentAppInfo = {
|
$: currentAppInfo = {
|
||||||
appname: $store.appname,
|
appname: $store.appname,
|
||||||
instanceId: $backendUiStore.selectedDatabase._id,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchUsers() {
|
async function fetchUsers() {
|
||||||
const FETCH_USERS_URL = `/api/users`
|
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()
|
const users = await response.json()
|
||||||
backendUiStore.update(state => {
|
backendUiStore.update(state => {
|
||||||
state.users = users
|
state.users = users
|
||||||
|
|
|
@ -37,7 +37,6 @@ exports.defaultHeaders = (appId, instanceId) => {
|
||||||
return {
|
return {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
Cookie: [`builder:token=${builderToken}`],
|
Cookie: [`builder:token=${builderToken}`],
|
||||||
"x-user-agent": "Budibase Builder",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue