commit
d511d35671
|
@ -17,14 +17,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const res = await fetch(`/api/client/id`)
|
|
||||||
const json = await res.json()
|
|
||||||
|
|
||||||
store.update(state => {
|
|
||||||
state.clientId = json
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
|
|
||||||
window.addEventListener("error", showErrorBanner)
|
window.addEventListener("error", showErrorBanner)
|
||||||
window.addEventListener("unhandledrejection", showErrorBanner)
|
window.addEventListener("unhandledrejection", showErrorBanner)
|
||||||
})
|
})
|
||||||
|
@ -34,8 +26,7 @@
|
||||||
|
|
||||||
<AppNotification />
|
<AppNotification />
|
||||||
|
|
||||||
{#if $store.clientId}
|
<Modal>
|
||||||
<Modal>
|
|
||||||
<Router {routes} />
|
<Router {routes} />
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Fetches the definitions for component library components. This includes
|
* Fetches the definitions for component library components. This includes
|
||||||
* their props and other metadata from components.json.
|
* their props and other metadata from components.json.
|
||||||
* @param {string} clientId - ID of the current client
|
|
||||||
* @param {string} appId - ID of the currently running app
|
* @param {string} appId - ID of the currently running app
|
||||||
*/
|
*/
|
||||||
export const fetchComponentLibDefinitions = async (clientId, appId) => {
|
export const fetchComponentLibDefinitions = async appId => {
|
||||||
const LIB_DEFINITION_URL = `/${clientId}/${appId}/components/definitions`
|
const LIB_DEFINITION_URL = `/${appId}/components/definitions`
|
||||||
try {
|
try {
|
||||||
const libDefinitionResponse = await fetch(LIB_DEFINITION_URL)
|
const libDefinitionResponse = await fetch(LIB_DEFINITION_URL)
|
||||||
return await libDefinitionResponse.json()
|
return await libDefinitionResponse.json()
|
||||||
|
|
|
@ -16,8 +16,8 @@ export const getBackendUiStore = () => {
|
||||||
store.actions = {
|
store.actions = {
|
||||||
database: {
|
database: {
|
||||||
select: async db => {
|
select: async db => {
|
||||||
const modelsResponse = await api.get(`/api/${db.id}/models`)
|
const modelsResponse = await api.get(`/api/${db._id}/models`)
|
||||||
const viewsResponse = await api.get(`/api/${db.id}/views`)
|
const viewsResponse = await api.get(`/api/${db._id}/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 => {
|
||||||
|
@ -37,7 +37,7 @@ export const getBackendUiStore = () => {
|
||||||
}),
|
}),
|
||||||
view: record =>
|
view: record =>
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.breadcrumbs = [state.selectedDatabase.name, record.id]
|
state.breadcrumbs = [state.selectedDatabase.name, record._id]
|
||||||
return state
|
return state
|
||||||
}),
|
}),
|
||||||
select: record =>
|
select: record =>
|
||||||
|
|
|
@ -94,10 +94,7 @@ const setPackage = (store, initial) => async pkg => {
|
||||||
}
|
}
|
||||||
|
|
||||||
initial.libraries = await fetchComponentLibModules(pkg.application)
|
initial.libraries = await fetchComponentLibModules(pkg.application)
|
||||||
initial.components = await fetchComponentLibDefinitions(
|
initial.components = await fetchComponentLibDefinitions(pkg.application._id)
|
||||||
pkg.clientId,
|
|
||||||
pkg.application._id
|
|
||||||
)
|
|
||||||
initial.appname = pkg.application.name
|
initial.appname = pkg.application.name
|
||||||
initial.appId = pkg.application._id
|
initial.appId = pkg.application._id
|
||||||
initial.pages = pkg.pages
|
initial.pages = pkg.pages
|
||||||
|
@ -354,7 +351,7 @@ const addChildComponent = store => (componentToAdd, presetName) => {
|
||||||
|
|
||||||
const presetProps = presetName ? component.presets[presetName] : {}
|
const presetProps = presetName ? component.presets[presetName] : {}
|
||||||
|
|
||||||
const instanceId = get(backendUiStore).selectedDatabase.id;
|
const instanceId = get(backendUiStore).selectedDatabase._id;
|
||||||
|
|
||||||
const newComponent = createProps(component, {
|
const newComponent = createProps(component, {
|
||||||
...presetProps,
|
...presetProps,
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
async function selectRecord(record) {
|
async function selectRecord(record) {
|
||||||
return await api.loadRecord(record.key, {
|
return await api.loadRecord(record.key, {
|
||||||
appname: $store.appname,
|
appname: $store.appname,
|
||||||
instanceId: $backendUiStore.selectedDatabase.id,
|
instanceId: $backendUiStore.selectedDatabase._id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
let views = []
|
let views = []
|
||||||
let currentPage = 0
|
let currentPage = 0
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if ($backendUiStore.selectedView) {
|
if ($backendUiStore.selectedView) {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
export async function createUser(user, appId, instanceId) {
|
export async function createUser(user, appId, instanceId) {
|
||||||
const CREATE_USER_URL = `/api/${appId}/${instanceId}/users`
|
const CREATE_USER_URL = `/api/${instanceId}/users`
|
||||||
const response = await api.post(CREATE_USER_URL, user)
|
const response = await api.post(CREATE_USER_URL, user)
|
||||||
const json = await response.json()
|
return await response.json()
|
||||||
return json.user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createDatabase(clientId, appname, instanceName) {
|
export async function createDatabase(appname, instanceName) {
|
||||||
const CREATE_DATABASE_URL = `/api/${clientId}/${appname}/instances`
|
const CREATE_DATABASE_URL = `/api/${appname}/instances`
|
||||||
const response = await api.post(CREATE_DATABASE_URL, {
|
const response = await api.post(CREATE_DATABASE_URL, {
|
||||||
name: instanceName,
|
name: instanceName,
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,11 +10,10 @@
|
||||||
|
|
||||||
async function createDatabase() {
|
async function createDatabase() {
|
||||||
const response = await api.createDatabase(
|
const response = await api.createDatabase(
|
||||||
$store.clientId,
|
|
||||||
$store.appId,
|
$store.appId,
|
||||||
databaseName
|
databaseName
|
||||||
)
|
)
|
||||||
store.createDatabaseForApp(response.instance)
|
store.createDatabaseForApp(response)
|
||||||
onClosed()
|
onClosed()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
let fieldToEdit
|
let fieldToEdit
|
||||||
|
|
||||||
$: modelFields = model.schema ? Object.entries(model.schema) : []
|
$: modelFields = model.schema ? Object.entries(model.schema) : []
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
|
|
||||||
function editField() {}
|
function editField() {}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
const SAVE_MODEL_URL = `/api/${instanceId}/models`
|
const SAVE_MODEL_URL = `/api/${instanceId}/models`
|
||||||
const response = await api.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.model)
|
backendUiStore.actions.models.create(newModel)
|
||||||
onClosed()
|
onClosed()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
let errors = []
|
let errors = []
|
||||||
let selectedModel
|
let selectedModel
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
|
|
||||||
$: modelSchema = $backendUiStore.selectedModel
|
$: modelSchema = $backendUiStore.selectedModel
|
||||||
? Object.entries($backendUiStore.selectedModel.schema)
|
? Object.entries($backendUiStore.selectedModel.schema)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
let currentSnippetEditor = SNIPPET_EDITORS.MAP
|
let currentSnippetEditor = SNIPPET_EDITORS.MAP
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
|
|
||||||
function deleteView() {}
|
function deleteView() {}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
let password
|
let password
|
||||||
|
|
||||||
$: valid = username && password
|
$: valid = username && password
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
$: appId = $store.appId
|
$: appId = $store.appId
|
||||||
|
|
||||||
async function createUser() {
|
async function createUser() {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
export let record
|
export let record
|
||||||
export let onClosed
|
export let onClosed
|
||||||
|
|
||||||
$: instanceId = $backendUiStore.selectedDatabase.id
|
$: instanceId = $backendUiStore.selectedDatabase._id
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
{#if $backendUiStore.selectedDatabase.id}
|
{#if $backendUiStore.selectedDatabase._id}
|
||||||
<div class="hierarchy">
|
<div class="hierarchy">
|
||||||
<div class="components-list-container">
|
<div class="components-list-container">
|
||||||
<div class="nav-group-header">
|
<div class="nav-group-header">
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
const response = await api.delete(DELETE_DATABASE_URL)
|
const response = await api.delete(DELETE_DATABASE_URL)
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.appInstances = state.appInstances.filter(
|
state.appInstances = state.appInstances.filter(
|
||||||
db => db.id !== database.id
|
db => db._id !== database._id
|
||||||
)
|
)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
@ -28,14 +28,14 @@
|
||||||
{#each $store.appInstances as database}
|
{#each $store.appInstances as database}
|
||||||
<li>
|
<li>
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
{#if database.id === $backendUiStore.selectedDatabase.id}
|
{#if database._id === $backendUiStore.selectedDatabase._id}
|
||||||
<CheckIcon />
|
<CheckIcon />
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
class:active={database.id === $backendUiStore.selectedDatabase.id}
|
class:active={database._id === $backendUiStore.selectedDatabase._id}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
$goto(`./database/${database.id}`), selectDatabase(database)
|
$goto(`./database/${database._id}`), selectDatabase(database)
|
||||||
}}>
|
}}>
|
||||||
{database.name}
|
{database.name}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
$: currentAppInfo = {
|
$: currentAppInfo = {
|
||||||
appname: $store.appname,
|
appname: $store.appname,
|
||||||
instanceId: $backendUiStore.selectedDatabase.id,
|
instanceId: $backendUiStore.selectedDatabase._id,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchUsers() {
|
async function fetchUsers() {
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
{#each $backendUiStore.users as user}
|
{#each $backendUiStore.users as user}
|
||||||
<li>
|
<li>
|
||||||
<i class="ri-user-4-line" />
|
<i class="ri-user-4-line" />
|
||||||
<button class:active={user.id === $store.currentUserId}>
|
<button class:active={user.username === $store.currentUserName}>
|
||||||
{user.name}
|
{user.name}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
let promise = getPackage()
|
let promise = getPackage()
|
||||||
|
|
||||||
async function getPackage() {
|
async function getPackage() {
|
||||||
const res = await fetch(`/api/${$store.clientId}/${application}/appPackage`)
|
const res = await fetch(`/api/${application}/appPackage`)
|
||||||
const pkg = await res.json()
|
const pkg = await res.json()
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if $backendUiStore.selectedDatabase.id}
|
{#if $backendUiStore.selectedDatabase._id}
|
||||||
<ModelDataTable {selectRecord} />
|
<ModelDataTable {selectRecord} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if ($store.appInstances.length > 0) {
|
if ($store.appInstances.length > 0) {
|
||||||
await selectDatabase($store.appInstances[0])
|
await selectDatabase($store.appInstances[0])
|
||||||
$goto(`./${$backendUiStore.selectedDatabase.id}`)
|
$goto(`./${$backendUiStore.selectedDatabase._id}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if ($store.appInstances.length > 0) {
|
if ($store.appInstances.length > 0) {
|
||||||
await selectDatabase($store.appInstances[0])
|
await selectDatabase($store.appInstances[0])
|
||||||
$goto(`../${$backendUiStore.selectedDatabase.id}`)
|
$goto(`../${$backendUiStore.selectedDatabase._id}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
let promise = getApps()
|
let promise = getApps()
|
||||||
|
|
||||||
async function getApps() {
|
async function getApps() {
|
||||||
const res = await fetch(`/api/${$store.clientId}/applications`)
|
const res = await fetch(`/api/applications`)
|
||||||
const json = await res.json()
|
const json = await res.json()
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
|
|
@ -3,10 +3,8 @@ const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
||||||
const chalk = require("chalk")
|
const chalk = require("chalk")
|
||||||
const { serverFileName, xPlatHomeDir } = require("../../common")
|
const { serverFileName, xPlatHomeDir } = require("../../common")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
const initialiseClientDb = require("@budibase/server/src/db/initialiseClientDb")
|
|
||||||
const Sqrl = require("squirrelly")
|
const Sqrl = require("squirrelly")
|
||||||
const uuid = require("uuid")
|
const uuid = require("uuid")
|
||||||
const CouchDB = require("@budibase/server/src/db/client")
|
|
||||||
|
|
||||||
module.exports = opts => {
|
module.exports = opts => {
|
||||||
run(opts)
|
run(opts)
|
||||||
|
@ -15,6 +13,7 @@ module.exports = opts => {
|
||||||
const run = async opts => {
|
const run = async opts => {
|
||||||
try {
|
try {
|
||||||
await ensureAppDir(opts)
|
await ensureAppDir(opts)
|
||||||
|
await setEnvironmentVariables(opts)
|
||||||
await prompts(opts)
|
await prompts(opts)
|
||||||
await createClientDatabase(opts)
|
await createClientDatabase(opts)
|
||||||
await createDevEnvFile(opts)
|
await createDevEnvFile(opts)
|
||||||
|
@ -24,18 +23,22 @@ const run = async opts => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ensureAppDir = async opts => {
|
const setEnvironmentVariables = async opts => {
|
||||||
opts.dir = xPlatHomeDir(opts.dir)
|
|
||||||
await ensureDir(opts.dir)
|
|
||||||
|
|
||||||
if (opts.database === "local") {
|
if (opts.database === "local") {
|
||||||
const dataDir = join(opts.dir, ".data")
|
const dataDir = join(opts.dir, ".data")
|
||||||
await ensureDir(dataDir)
|
await ensureDir(dataDir)
|
||||||
process.env.COUCH_DB_URL =
|
process.env.COUCH_DB_URL =
|
||||||
dataDir + (dataDir.endsWith("/") || dataDir.endsWith("\\") ? "" : "/")
|
dataDir + (dataDir.endsWith("/") || dataDir.endsWith("\\") ? "" : "/")
|
||||||
|
} else {
|
||||||
|
process.env.COUCH_DB_URL = opts.couchDbUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ensureAppDir = async opts => {
|
||||||
|
opts.dir = xPlatHomeDir(opts.dir)
|
||||||
|
await ensureDir(opts.dir)
|
||||||
|
}
|
||||||
|
|
||||||
const prompts = async opts => {
|
const prompts = async opts => {
|
||||||
const questions = [
|
const questions = [
|
||||||
{
|
{
|
||||||
|
@ -56,7 +59,14 @@ const prompts = async opts => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createClientDatabase = async opts => {
|
const createClientDatabase = async opts => {
|
||||||
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const clientDb = require("@budibase/server/src/db/clientDb")
|
||||||
|
|
||||||
if (opts.clientId === "new") {
|
if (opts.clientId === "new") {
|
||||||
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const CouchDB = require("@budibase/server/src/db/client")
|
||||||
const existing = await CouchDB.allDbs()
|
const existing = await CouchDB.allDbs()
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
|
@ -64,12 +74,11 @@ const createClientDatabase = async opts => {
|
||||||
while (isExisting) {
|
while (isExisting) {
|
||||||
i += 1
|
i += 1
|
||||||
opts.clientId = i.toString()
|
opts.clientId = i.toString()
|
||||||
isExisting = existing.includes(`client-${opts.clientId}`)
|
isExisting = existing.includes(clientDb.name(opts.clientId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const db = new CouchDB(`client-${opts.clientId}`)
|
await clientDb.create(opts.clientId)
|
||||||
await initialiseClientDb(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const createDevEnvFile = async opts => {
|
const createDevEnvFile = async opts => {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
const { xPlatHomeDir } = require("../../common")
|
const { xPlatHomeDir } = require("../../common")
|
||||||
const dotenv = require("dotenv")
|
const dotenv = require("dotenv")
|
||||||
const createInstance = require("@budibase/server/src/api/controllers/instance")
|
const { copy, readJSON, writeJSON, exists } = require("fs-extra")
|
||||||
.create
|
|
||||||
const createApplication = require("@budibase/server/src/api/controllers/application")
|
|
||||||
.create
|
|
||||||
const buildPage = require("@budibase/server/src/utilities/builder/buildPage")
|
|
||||||
const { copy, readJSON, writeJSON, remove, exists } = require("fs-extra")
|
|
||||||
const { resolve, join } = require("path")
|
const { resolve, join } = require("path")
|
||||||
const chalk = require("chalk")
|
const chalk = require("chalk")
|
||||||
const { exec } = require("child_process")
|
const { exec } = require("child_process")
|
||||||
|
@ -24,7 +19,9 @@ const run = async opts => {
|
||||||
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
||||||
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red("Error creating new app", error))
|
console.error(
|
||||||
|
chalk.red("Error creating new app", JSON.stringify(error, { space: 2 }))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +34,18 @@ const createAppInstance = async opts => {
|
||||||
body: {},
|
body: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
await createApplication(createAppCtx)
|
// this cannot be a top level require as it will cause
|
||||||
opts.applicationId = createAppCtx.body.id
|
// the environment module to be loaded prematurely
|
||||||
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
|
const appController = require("@budibase/server/src/api/controllers/application")
|
||||||
await createInstance({
|
await appController.create(createAppCtx)
|
||||||
|
|
||||||
|
opts.applicationId = createAppCtx.body._id
|
||||||
|
console.log(chalk.green(`Application Created: ${createAppCtx.body._id}`))
|
||||||
|
|
||||||
|
// this cannot be a top level require as it will cause
|
||||||
|
// the environment module to be loaded prematurely
|
||||||
|
const instanceController = require("@budibase/server/src/api/controllers/instance")
|
||||||
|
await instanceController.create({
|
||||||
params: {
|
params: {
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: process.env.CLIENT_ID,
|
||||||
applicationId: opts.applicationId,
|
applicationId: opts.applicationId,
|
||||||
|
@ -49,6 +54,7 @@ const createAppInstance = async opts => {
|
||||||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(chalk.green(`Default Instance Created`))
|
console.log(chalk.green(`Default Instance Created`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,12 @@ module.exports = ({ dir }) => {
|
||||||
dir = xPlatHomeDir(dir)
|
dir = xPlatHomeDir(dir)
|
||||||
process.env.BUDIBASE_DIR = resolve(dir)
|
process.env.BUDIBASE_DIR = resolve(dir)
|
||||||
require("dotenv").config({ path: resolve(dir, ".env") })
|
require("dotenv").config({ path: resolve(dir, ".env") })
|
||||||
require("@budibase/server/src/app")
|
console.log("dotenv loaded")
|
||||||
console.log(`Budibase Builder running on port ${process.env.PORT}..`)
|
|
||||||
|
// dont make this a variable or top level require
|
||||||
|
// ti will cause environment module to be loaded prematurely
|
||||||
|
require("@budibase/server/src/app")().then(server => {
|
||||||
|
server.on("close", () => console.log("Server Closed"))
|
||||||
|
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
# http://admin:password@localhost:5984
|
# http://admin:password@localhost:5984
|
||||||
COUCH_DB_URL={{couchDbUrl}}
|
COUCH_DB_URL={{couchDbUrl}}
|
||||||
|
|
||||||
# local (PouchDB) - default for dev
|
|
||||||
# remote (CouchDB) - required couch db installation
|
|
||||||
DATABASE_TYPE={{database}}
|
|
||||||
|
|
||||||
# identifies a client database - i.e. group of apps
|
# identifies a client database - i.e. group of apps
|
||||||
CLIENT_ID={{clientId}}
|
CLIENT_ID={{clientId}}
|
||||||
|
|
||||||
|
@ -13,8 +9,7 @@ CLIENT_ID={{clientId}}
|
||||||
ADMIN_SECRET={{adminSecret}}
|
ADMIN_SECRET={{adminSecret}}
|
||||||
|
|
||||||
# used to create cookie hashes
|
# used to create cookie hashes
|
||||||
COOKIE_KEY_1={{cookieKey1}}
|
JWT_SECRET={{cookieKey1}}
|
||||||
COOKIE_KEY_2={{cookieKey2}}
|
|
||||||
|
|
||||||
# port to run http server on
|
# port to run http server on
|
||||||
PORT=4001
|
PORT=4001
|
|
@ -8,14 +8,92 @@
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Start Server",
|
"name": "Start Server",
|
||||||
"program": "${workspaceFolder}/src/index.js"
|
"program": "${workspaceFolder}/../cli/bin/budi"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Jest App Server",
|
"name": "Jest - All",
|
||||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
"args": ["apps", "--runInBand"],
|
"args": [],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Users",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["user.spec", "--runInBand"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Instances",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["instance.spec", "--runInBand"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Records",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["record.spec", "--runInBand"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Models",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["model.spec", "--runInBand"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Views",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["view.spec", "--runInBand"],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"windows": {
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest-cli/bin/jest",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Jest - Applications",
|
||||||
|
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||||
|
"args": ["application.spec", "--runInBand"],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"internalConsoleOptions": "neverOpen",
|
"internalConsoleOptions": "neverOpen",
|
||||||
"disableOptimisticBPs": true,
|
"disableOptimisticBPs": true,
|
||||||
|
|
|
@ -76,11 +76,13 @@
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"nodemon": "^2.0.2",
|
"nodemon": "^2.0.2",
|
||||||
|
"pouchdb-adapter-memory": "^7.2.1",
|
||||||
"server-destroy": "^1.0.1",
|
"server-destroy": "^1.0.1",
|
||||||
"supertest": "^4.0.2"
|
"supertest": "^4.0.2"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node",
|
||||||
|
"setupFiles": ["./scripts/jestSetup.js"]
|
||||||
},
|
},
|
||||||
"gitHead": "b1f4f90927d9e494e513220ef060af28d2d42455"
|
"gitHead": "b1f4f90927d9e494e513220ef060af28d2d42455"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
const { tmpdir } = require("os")
|
||||||
|
|
||||||
|
process.env.NODE_ENV = "jest"
|
||||||
|
process.env.JWT_SECRET = "test-jwtsecret"
|
||||||
|
process.env.CLIENT_ID = "test-client-id"
|
||||||
|
process.env.BUDIBASE_DIR = tmpdir("budibase-unittests")
|
||||||
|
process.env.ADMIN_SECRET = "test-admin-secret"
|
||||||
|
|
||||||
|
// makes the output of the tests messy
|
||||||
|
// but please temporarily enable for debugging :)
|
||||||
|
process.env.LOGGER = "off"
|
|
@ -1,9 +1,12 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const ClientDb = require("../../db/clientDb")
|
||||||
const { getPackageForBuilder } = require("../../utilities/builder")
|
const { getPackageForBuilder } = require("../../utilities/builder")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
const body = await clientDb.query("client/by_type", {
|
const body = await db.query("client/by_type", {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
key: ["app"],
|
key: ["app"],
|
||||||
})
|
})
|
||||||
|
@ -12,14 +15,16 @@ exports.fetch = async function(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchAppPackage = async function(ctx) {
|
exports.fetchAppPackage = async function(ctx) {
|
||||||
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
const application = await clientDb.get(ctx.params.applicationId)
|
const application = await db.get(ctx.params.applicationId)
|
||||||
ctx.body = await getPackageForBuilder(ctx.config, application)
|
ctx.body = await getPackageForBuilder(ctx.config, application)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
const { id, rev } = await clientDb.post({
|
|
||||||
|
const newApplication = {
|
||||||
|
_id: uuid.v4().replace(/-/g, ""),
|
||||||
type: "app",
|
type: "app",
|
||||||
instances: [],
|
instances: [],
|
||||||
userInstanceMap: {},
|
userInstanceMap: {},
|
||||||
|
@ -28,11 +33,10 @@ exports.create = async function(ctx) {
|
||||||
"@budibase/materialdesign-components",
|
"@budibase/materialdesign-components",
|
||||||
],
|
],
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
})
|
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
id,
|
|
||||||
rev,
|
|
||||||
message: `Application ${ctx.request.body.name} created successfully`,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { rev } = await db.post(newApplication)
|
||||||
|
newApplication._rev = rev
|
||||||
|
ctx.body = newApplication
|
||||||
|
ctx.message = `Application ${ctx.request.body.name} created successfully`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const jwt = require("jsonwebtoken")
|
const jwt = require("jsonwebtoken")
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const ClientDb = require("../../db/clientDb")
|
||||||
const bcrypt = require("../../utilities/bcrypt")
|
const bcrypt = require("../../utilities/bcrypt")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.authenticate = async ctx => {
|
exports.authenticate = async ctx => {
|
||||||
const { username, password } = ctx.request.body
|
const { username, password } = ctx.request.body
|
||||||
|
@ -13,7 +15,7 @@ exports.authenticate = async ctx => {
|
||||||
const appId = referer[3]
|
const appId = referer[3]
|
||||||
|
|
||||||
// find the instance that the user is associated with
|
// find the instance that the user is associated with
|
||||||
const db = new CouchDB(`client-${process.env.CLIENT_ID}`)
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
const app = await db.get(appId)
|
const app = await db.get(appId)
|
||||||
const instanceId = app.userInstanceMap[username]
|
const instanceId = app.userInstanceMap[username]
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,18 @@
|
||||||
const CouchDB = require("../../db")
|
const { create, destroy } = require("../../db/clientDb")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.getClientId = async function(ctx) {
|
exports.getClientId = async function(ctx) {
|
||||||
ctx.body = process.env.CLIENT_ID
|
ctx.body = env.CLIENT_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const clientId = `client-${ctx.request.body.clientId}`
|
await create(env.CLIENT_ID)
|
||||||
const db = new CouchDB(clientId)
|
ctx.status = 200
|
||||||
|
ctx.message = `Client Database ${env.CLIENT_ID} successfully provisioned.`
|
||||||
await db.put({
|
|
||||||
_id: "_design/client",
|
|
||||||
views: {
|
|
||||||
by_type: {
|
|
||||||
map: function(doc) {
|
|
||||||
emit([doc.type], doc._id)
|
|
||||||
}.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
message: `Client Database ${clientId} successfully provisioned.`,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
const dbId = `client-${ctx.params.clientId}`
|
await destroy(env.CLIENT_ID)
|
||||||
|
ctx.status = 200
|
||||||
await new CouchDB(dbId).destroy()
|
ctx.message = `Client Database ${env.CLIENT_ID} successfully deleted.`
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
status: 200,
|
|
||||||
message: `Client Database ${dbId} successfully deleted.`,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const ClientDb = require("../../db/clientDb")
|
||||||
const { resolve, join } = require("path")
|
const { resolve, join } = require("path")
|
||||||
const {
|
const {
|
||||||
budibaseTempDir,
|
budibaseTempDir,
|
||||||
budibaseAppsDir,
|
budibaseAppsDir,
|
||||||
} = require("../../utilities/budibaseDir")
|
} = require("../../utilities/budibaseDir")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.fetchAppComponentDefinitions = async function(ctx) {
|
exports.fetchAppComponentDefinitions = async function(ctx) {
|
||||||
const db = new CouchDB(`client-${ctx.params.clientId}`)
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
||||||
const app = await db.get(ctx.params.appId)
|
const app = await db.get(ctx.params.appId)
|
||||||
|
|
||||||
const componentDefinitions = app.componentLibraries.reduce(
|
const componentDefinitions = app.componentLibraries.reduce(
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const client = require("../../db/clientDb")
|
||||||
const uuid = require("uuid")
|
const uuid = require("uuid")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const instanceName = ctx.request.body.name
|
const instanceName = ctx.request.body.name
|
||||||
const instanceId = `app_${ctx.params.applicationId.substring(6)}_inst_${uuid.v4()}`
|
const uid = uuid.v4().replace(/-/g, "")
|
||||||
const { clientId, applicationId } = ctx.params
|
const instanceId = `inst_${ctx.params.applicationId.substring(0,7)}_${uid}`
|
||||||
|
const { applicationId } = ctx.params
|
||||||
|
const clientId = env.CLIENT_ID
|
||||||
const db = new CouchDB(instanceId)
|
const db = new CouchDB(instanceId)
|
||||||
await db.put({
|
await db.put({
|
||||||
_id: "_design/database",
|
_id: "_design/database",
|
||||||
|
@ -29,18 +33,15 @@ exports.create = async function(ctx) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add the new instance under the app clientDB
|
// Add the new instance under the app clientDB
|
||||||
const clientDatabaseId = `client-${clientId}`
|
const clientDb = new CouchDB(client.name(clientId))
|
||||||
const clientDb = new CouchDB(clientDatabaseId)
|
|
||||||
const budibaseApp = await clientDb.get(applicationId)
|
const budibaseApp = await clientDb.get(applicationId)
|
||||||
const instance = { id: instanceId, name: instanceName }
|
const instance = { _id: instanceId, name: instanceName }
|
||||||
budibaseApp.instances.push(instance)
|
budibaseApp.instances.push(instance)
|
||||||
await clientDb.put(budibaseApp)
|
await clientDb.put(budibaseApp)
|
||||||
|
|
||||||
ctx.body = {
|
ctx.status = 200
|
||||||
message: `Instance Database ${instanceName} successfully provisioned.`,
|
ctx.message = `Instance Database ${instanceName} successfully provisioned.`
|
||||||
status: 200,
|
ctx.body = instance
|
||||||
instance,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
|
@ -50,15 +51,13 @@ exports.destroy = async function(ctx) {
|
||||||
|
|
||||||
// remove instance from client application document
|
// remove instance from client application document
|
||||||
const { metadata } = designDoc
|
const { metadata } = designDoc
|
||||||
const clientDb = new CouchDB(metadata.clientId)
|
const clientDb = new CouchDB(client.name(metadata.clientId))
|
||||||
const budibaseApp = await clientDb.get(metadata.applicationId)
|
const budibaseApp = await clientDb.get(metadata.applicationId)
|
||||||
budibaseApp.instances = budibaseApp.instances.filter(
|
budibaseApp.instances = budibaseApp.instances.filter(
|
||||||
instance => instance !== ctx.params.instanceId
|
instance => instance !== ctx.params.instanceId
|
||||||
)
|
)
|
||||||
await clientDb.put(budibaseApp)
|
await clientDb.put(budibaseApp)
|
||||||
|
|
||||||
ctx.body = {
|
ctx.status = 200
|
||||||
message: `Instance Database ${ctx.params.instanceId} successfully destroyed.`,
|
ctx.message = `Instance Database ${ctx.params.instanceId} successfully destroyed.`
|
||||||
status: 200,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
|
@ -11,17 +12,21 @@ exports.fetch = async function(ctx) {
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
const newModel = await db.post({
|
const newModel = {
|
||||||
type: "model",
|
type: "model",
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
})
|
_id: uuid.v4().replace(/-/g, ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await db.post(newModel)
|
||||||
|
newModel._rev = result.rev
|
||||||
|
|
||||||
const designDoc = await db.get("_design/database")
|
const designDoc = await db.get("_design/database")
|
||||||
designDoc.views = {
|
designDoc.views = {
|
||||||
...designDoc.views,
|
...designDoc.views,
|
||||||
[`all_${newModel.id}`]: {
|
[`all_${newModel._id}`]: {
|
||||||
map: `function(doc) {
|
map: `function(doc) {
|
||||||
if (doc.modelId === "${newModel.id}") {
|
if (doc.modelId === "${newModel._id}") {
|
||||||
emit(doc[doc.key], doc._id);
|
emit(doc[doc.key], doc._id);
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
|
@ -29,15 +34,9 @@ exports.create = async function(ctx) {
|
||||||
}
|
}
|
||||||
await db.put(designDoc)
|
await db.put(designDoc)
|
||||||
|
|
||||||
ctx.body = {
|
ctx.status = 200
|
||||||
message: `Model ${ctx.request.body.name} created successfully.`,
|
ctx.message = `Model ${ctx.request.body.name} created successfully.`
|
||||||
status: 200,
|
ctx.body = newModel
|
||||||
model: {
|
|
||||||
_id: newModel.id,
|
|
||||||
_rev: newModel.rev,
|
|
||||||
...ctx.request.body,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update = async function(ctx) {}
|
exports.update = async function(ctx) {}
|
||||||
|
@ -45,8 +44,8 @@ exports.update = async function(ctx) {}
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
|
|
||||||
const model = await db.remove(ctx.params.modelId, ctx.params.revId)
|
await db.remove(ctx.params.modelId, ctx.params.revId)
|
||||||
const modelViewId = `all_${model.id}`
|
const modelViewId = `all_${ctx.params.modelId}`
|
||||||
|
|
||||||
// Delete all records for that model
|
// Delete all records for that model
|
||||||
const records = await db.query(`database/${modelViewId}`)
|
const records = await db.query(`database/${modelViewId}`)
|
||||||
|
@ -59,8 +58,6 @@ exports.destroy = async function(ctx) {
|
||||||
delete designDoc.views[modelViewId]
|
delete designDoc.views[modelViewId]
|
||||||
await db.put(designDoc)
|
await db.put(designDoc)
|
||||||
|
|
||||||
ctx.body = {
|
ctx.status = 200
|
||||||
message: `Model ${model.id} deleted.`,
|
ctx.message = `Model ${ctx.params.modelId} deleted.`
|
||||||
status: 200,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
const Ajv = require("ajv")
|
const Ajv = require("ajv")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
|
||||||
const ajv = new Ajv()
|
const ajv = new Ajv()
|
||||||
|
|
||||||
|
@ -7,6 +8,10 @@ exports.save = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
const record = ctx.request.body
|
const record = ctx.request.body
|
||||||
|
|
||||||
|
if (!record._rev && !record._id) {
|
||||||
|
record._id = uuid.v4().replace(/-/, "")
|
||||||
|
}
|
||||||
|
|
||||||
// validation with ajv
|
// validation with ajv
|
||||||
const model = await db.get(record.modelId)
|
const model = await db.get(record.modelId)
|
||||||
const validate = ajv.compile({
|
const validate = ajv.compile({
|
||||||
|
@ -23,18 +28,15 @@ exports.save = async function(ctx) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingRecord = record._id && (await db.get(record._id))
|
const existingRecord = record._rev && (await db.get(record._id))
|
||||||
|
|
||||||
if (existingRecord) {
|
if (existingRecord) {
|
||||||
const response = await db.put({ ...record, _id: existingRecord._id })
|
const response = await db.put(record)
|
||||||
ctx.body = {
|
record._rev = response.rev
|
||||||
message: `${model.name} updated successfully.`,
|
record.type = "record"
|
||||||
status: 200,
|
ctx.body = record
|
||||||
record: {
|
ctx.status = 200
|
||||||
...record,
|
ctx.message = `${model.name} updated successfully.`
|
||||||
...response,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +47,7 @@ exports.save = async function(ctx) {
|
||||||
// record: record,
|
// record: record,
|
||||||
// })
|
// })
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = record
|
||||||
...record,
|
|
||||||
...response
|
|
||||||
}
|
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.message = `${model.name} created successfully`
|
ctx.message = `${model.name} created successfully`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ const {
|
||||||
budibaseAppsDir,
|
budibaseAppsDir,
|
||||||
budibaseTempDir,
|
budibaseTempDir,
|
||||||
} = require("../../utilities/budibaseDir")
|
} = require("../../utilities/budibaseDir")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.serveBuilder = async function(ctx) {
|
exports.serveBuilder = async function(ctx) {
|
||||||
let builderPath = resolve(__dirname, "../../../builder")
|
let builderPath = resolve(__dirname, "../../../builder")
|
||||||
|
ctx.cookies.set("builder:token", env.ADMIN_SECRET)
|
||||||
await send(ctx, ctx.file, { root: ctx.devPath || builderPath })
|
await send(ctx, ctx.file, { root: ctx.devPath || builderPath })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const clientDb = require("../../db/clientDb")
|
||||||
const bcrypt = require("../../utilities/bcrypt")
|
const bcrypt = require("../../utilities/bcrypt")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
|
const getUserId = userName => `user_${userName}`
|
||||||
|
|
||||||
exports.fetch = async function(ctx) {
|
exports.fetch = async function(ctx) {
|
||||||
const database = new CouchDB(ctx.params.instanceId)
|
const database = new CouchDB(ctx.params.instanceId)
|
||||||
|
@ -13,45 +17,51 @@ exports.fetch = async function(ctx) {
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const database = new CouchDB(ctx.params.instanceId)
|
const database = new CouchDB(ctx.params.instanceId)
|
||||||
|
const appId = (await database.get("_design/database")).metadata.applicationId
|
||||||
const { username, password, name } = ctx.request.body
|
const { username, password, name } = ctx.request.body
|
||||||
|
|
||||||
if (!username || !password) ctx.throw(400, "Username and Password Required.")
|
if (!username || !password) ctx.throw(400, "Username and Password Required.")
|
||||||
|
|
||||||
const response = await database.post({
|
const response = await database.post({
|
||||||
|
_id: getUserId(username),
|
||||||
username,
|
username,
|
||||||
password: await bcrypt.hash(password),
|
password: await bcrypt.hash(password),
|
||||||
name,
|
name: name || username,
|
||||||
type: "user",
|
type: "user",
|
||||||
})
|
})
|
||||||
|
|
||||||
// the clientDB needs to store a map of users against the app
|
// the clientDB needs to store a map of users against the app
|
||||||
const clientDb = new CouchDB(`client-${process.env.CLIENT_ID}`)
|
const db = new CouchDB(clientDb.name(env.CLIENT_ID))
|
||||||
const app = await clientDb.get(ctx.params.appId)
|
const app = await db.get(appId)
|
||||||
|
|
||||||
app.userInstanceMap = {
|
app.userInstanceMap = {
|
||||||
...app.userInstanceMap,
|
...app.userInstanceMap,
|
||||||
[username]: ctx.params.instanceId,
|
[username]: ctx.params.instanceId,
|
||||||
}
|
}
|
||||||
await clientDb.put(app)
|
await db.put(app)
|
||||||
|
|
||||||
|
ctx.status = 200
|
||||||
|
ctx.message = "User created successfully."
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
user: {
|
_rev: response.rev,
|
||||||
id: response.id,
|
|
||||||
rev: response.rev,
|
|
||||||
username,
|
username,
|
||||||
name,
|
name,
|
||||||
},
|
|
||||||
message: `User created successfully.`,
|
|
||||||
status: 200,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async function(ctx) {
|
exports.destroy = async function(ctx) {
|
||||||
const database = new CouchDB(ctx.params.instanceId)
|
const database = new CouchDB(ctx.params.instanceId)
|
||||||
const response = await database.destroy(ctx.params.userId)
|
await database.destroy(getUserId(ctx.params.username))
|
||||||
|
ctx.message = `User ${ctx.params.username} deleted.`
|
||||||
|
ctx.status = 200
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.find = async function(ctx) {
|
||||||
|
const database = new CouchDB(ctx.params.instanceId)
|
||||||
|
const user = await database.get(getUserId(ctx.params.username))
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
...response,
|
username: user.username,
|
||||||
message: `User deleted.`,
|
name: user.name,
|
||||||
status: 200,
|
_rev: user._rev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,17 @@ const controller = {
|
||||||
},
|
},
|
||||||
create: async ctx => {
|
create: async ctx => {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
const { name, ...viewDefinition } = ctx.request.body
|
const newView = ctx.request.body
|
||||||
|
|
||||||
const designDoc = await db.get("_design/database")
|
const designDoc = await db.get("_design/database")
|
||||||
designDoc.views = {
|
designDoc.views = {
|
||||||
...designDoc.views,
|
...designDoc.views,
|
||||||
[name]: viewDefinition,
|
[newView.name]: newView,
|
||||||
}
|
}
|
||||||
const newView = await db.put(designDoc)
|
await db.put(designDoc)
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = newView
|
||||||
view: {
|
ctx.message = `View ${newView.name} created successfully.`
|
||||||
...ctx.request.body,
|
|
||||||
...newView,
|
|
||||||
},
|
|
||||||
message: `View ${name} created successfully.`,
|
|
||||||
status: 200,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
destroy: async ctx => {
|
destroy: async ctx => {
|
||||||
const db = new CouchDB(ctx.params.instanceId)
|
const db = new CouchDB(ctx.params.instanceId)
|
||||||
|
|
|
@ -18,6 +18,7 @@ const {
|
||||||
} = require("./routes")
|
} = require("./routes")
|
||||||
|
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
const env = require("../environment")
|
||||||
|
|
||||||
router
|
router
|
||||||
.use(
|
.use(
|
||||||
|
@ -34,9 +35,9 @@ router
|
||||||
.use(async (ctx, next) => {
|
.use(async (ctx, next) => {
|
||||||
ctx.config = {
|
ctx.config = {
|
||||||
latestPackagesFolder: budibaseAppsDir(),
|
latestPackagesFolder: budibaseAppsDir(),
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: env.JWT_SECRET,
|
||||||
}
|
}
|
||||||
ctx.isDev = process.env.NODE_ENV !== "production"
|
ctx.isDev = env.NODE_ENV !== "production" && env.NODE_ENV !== "jest"
|
||||||
await next()
|
await next()
|
||||||
})
|
})
|
||||||
.use(authenticated)
|
.use(authenticated)
|
||||||
|
@ -46,7 +47,7 @@ router.use(async (ctx, next) => {
|
||||||
try {
|
try {
|
||||||
await next()
|
await next()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.trace(err)
|
if (env.LOGGER !== "off") console.trace(err)
|
||||||
ctx.status = err.status || err.statusCode || 500
|
ctx.status = err.status || err.statusCode || 500
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
message: err.message,
|
message: err.message,
|
||||||
|
|
|
@ -4,8 +4,8 @@ const controller = require("../controllers/application")
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/:clientId/applications", controller.fetch)
|
.get("/api/applications", controller.fetch)
|
||||||
.get("/api/:clientId/:applicationId/appPackage", controller.fetchAppPackage)
|
.get("/api/:applicationId/appPackage", controller.fetchAppPackage)
|
||||||
.post("/api/:clientId/applications", controller.create)
|
.post("/api/applications", controller.create)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../controllers/client")
|
const controller = require("../controllers/client")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router.get("/api/client/id", controller.getClientId)
|
||||||
.get("/api/client/id", controller.getClientId)
|
|
||||||
.post("/api/clients", controller.create)
|
if (env.NODE_ENV === "jest") {
|
||||||
.delete("/api/clients/:clientId", controller.destroy)
|
router
|
||||||
|
.post("/api/client", controller.create)
|
||||||
|
.delete("/api/client", controller.destroy)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -4,7 +4,7 @@ const controller = require("../controllers/component")
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
"/:clientId/:appId/components/definitions",
|
"/:appId/components/definitions",
|
||||||
controller.fetchAppComponentDefinitions
|
controller.fetchAppComponentDefinitions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const controller = require("../controllers/instance")
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.post("/api/:clientId/:applicationId/instances", controller.create)
|
.post("/api/:applicationId/instances", controller.create)
|
||||||
.delete("/api/instances/:instanceId", controller.destroy)
|
.delete("/api/instances/:instanceId", controller.destroy)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
const Router = require("@koa/router")
|
const Router = require("@koa/router")
|
||||||
const controller = require("../controllers/static")
|
const controller = require("../controllers/static")
|
||||||
const { budibaseTempDir } = require("../../utilities/budibaseDir")
|
const { budibaseTempDir } = require("../../utilities/budibaseDir")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router.param("file", async (file, ctx, next) => {
|
||||||
.param("file", async (file, ctx, next) => {
|
|
||||||
ctx.file = file && file.includes(".") ? file : "index.html"
|
ctx.file = file && file.includes(".") ? file : "index.html"
|
||||||
|
|
||||||
// Serving the client library from your local dir in dev
|
// Serving the client library from your local dir in dev
|
||||||
|
@ -14,8 +14,13 @@ router
|
||||||
}
|
}
|
||||||
|
|
||||||
await next()
|
await next()
|
||||||
})
|
})
|
||||||
.get("/_builder/:file*", controller.serveBuilder)
|
|
||||||
|
if (env.NODE_ENV !== "production") {
|
||||||
|
router.get("/_builder/:file*", controller.serveBuilder)
|
||||||
|
}
|
||||||
|
|
||||||
|
router
|
||||||
.get("/:appId/componentlibrary", controller.serveComponentLibrary)
|
.get("/:appId/componentlibrary", controller.serveComponentLibrary)
|
||||||
.get("/:appId/:file*", controller.serveApp)
|
.get("/:appId/:file*", controller.serveApp)
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,58 @@
|
||||||
const supertest = require("supertest");
|
const {
|
||||||
const app = require("../../../app");
|
createClientDatabase,
|
||||||
const { createClientDatabase, destroyDatabase } = require("./couchTestUtils");
|
createApplication,
|
||||||
|
destroyClientDatabase,
|
||||||
|
supertest,
|
||||||
const CLIENT_DB_ID = "client-testing";
|
defaultHeaders
|
||||||
|
} = require("./couchTestUtils")
|
||||||
|
|
||||||
describe("/applications", () => {
|
describe("/applications", () => {
|
||||||
let request;
|
let request
|
||||||
let server;
|
let server
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app;
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
|
||||||
await createClientDatabase();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await createClientDatabase(request)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await destroyClientDatabase(request)
|
||||||
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
server.close();
|
server.close()
|
||||||
await destroyDatabase(CLIENT_DB_ID)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
it("returns a success message when the application is successfully created", done => {
|
it("returns a success message when the application is successfully created", async () => {
|
||||||
request
|
const res = await request
|
||||||
.post("/api/testing/applications")
|
.post("/api/applications")
|
||||||
.send({ name: "My App" })
|
.send({ name: "My App" })
|
||||||
.set("Accept", "application/json")
|
.set(defaultHeaders)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
expect(res.res.statusMessage).toEqual("Application My App created successfully")
|
||||||
expect(res.body.message).toEqual("Application My App created successfully");
|
expect(res.body._id).toBeDefined()
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
});
|
|
||||||
|
describe("fetch", () => {
|
||||||
|
it("lists all applications", async () => {
|
||||||
|
|
||||||
|
await createApplication(request, "app1")
|
||||||
|
await createApplication(request, "app2")
|
||||||
|
|
||||||
|
const res = await request
|
||||||
|
.get("/api/applications")
|
||||||
|
.set(defaultHeaders)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(res.body.length).toBe(2)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
|
@ -1,58 +1,48 @@
|
||||||
const supertest = require("supertest");
|
const {
|
||||||
const app = require("../../../app");
|
createClientDatabase,
|
||||||
const { createClientDatabase, destroyClientDatabase } = require("./couchTestUtils")
|
destroyClientDatabase,
|
||||||
|
supertest,
|
||||||
|
} = require("./couchTestUtils")
|
||||||
|
|
||||||
|
const CLIENT_ID = "test-client-id"
|
||||||
const CLIENT_DB_ID = "client-testing";
|
|
||||||
|
|
||||||
describe("/clients", () => {
|
describe("/clients", () => {
|
||||||
let request;
|
let request;
|
||||||
let server;
|
let server;
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeEach(async () => {
|
||||||
server = app
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterEach(async () => {
|
||||||
server.close();
|
server.close();
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
afterEach(async () => {
|
|
||||||
await destroyClientDatabase();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a success message when the client database is successfully created", done => {
|
it("returns a success message when the client database is successfully created", async () => {
|
||||||
request
|
const res = await request
|
||||||
.post("/api/clients")
|
.post("/api/client")
|
||||||
.send({ clientId: "testing" })
|
.send({ clientId: "testing" })
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
|
||||||
expect(res.body.message).toEqual(`Client Database ${CLIENT_DB_ID} successfully provisioned.`);
|
expect(res.res.statusMessage).toEqual(`Client Database ${process.env.CLIENT_ID} successfully provisioned.`);
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createClientDatabase();
|
db = await createClientDatabase(request);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a success message when the client database is successfully destroyed", async done => {
|
it("returns a success message when the client database is successfully destroyed", async () => {
|
||||||
request
|
const res = await request
|
||||||
.delete(`/api/clients/testing`)
|
.delete(`/api/client`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
expect(res.res.statusMessage).toEqual(`Client Database ${process.env.CLIENT_ID} successfully deleted.`);
|
||||||
expect(res.body.message).toEqual(`Client Database ${CLIENT_DB_ID} successfully deleted.`);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,34 @@
|
||||||
const CouchDB = require("../../../db")
|
const CouchDB = require("../../../db")
|
||||||
const CLIENT_DB_ID = "client-testing"
|
const supertest = require("supertest")
|
||||||
const TEST_APP_ID = "test-app"
|
const app = require("../../../app")
|
||||||
|
|
||||||
exports.createModel = async (instanceId, model) => {
|
exports.supertest = async () => {
|
||||||
|
let request
|
||||||
|
let port = 4002
|
||||||
|
let started = false
|
||||||
|
let server
|
||||||
|
while (!started && port < 4020) {
|
||||||
|
try {
|
||||||
|
server = await app(port)
|
||||||
|
started = true
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code === "EADDRINUSE") port = port + 1
|
||||||
|
else throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!started) throw Error("Application failed to start")
|
||||||
|
|
||||||
|
request = supertest(server)
|
||||||
|
return { request, server }
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.defaultHeaders = {
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: "Basic test-admin-secret",
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.createModel = async (request, instanceId, model) => {
|
||||||
model = model || {
|
model = model || {
|
||||||
name: "TestModel",
|
name: "TestModel",
|
||||||
type: "model",
|
type: "model",
|
||||||
|
@ -11,72 +37,60 @@ exports.createModel = async (instanceId, model) => {
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const db = new CouchDB(instanceId)
|
|
||||||
const response = await db.post(model)
|
|
||||||
|
|
||||||
const designDoc = await db.get("_design/database")
|
const res = await request
|
||||||
designDoc.views = {
|
.post(`/api/${instanceId}/models`)
|
||||||
...designDoc.views,
|
.set(exports.defaultHeaders)
|
||||||
[`all_${response.id}`]: {
|
.send(model)
|
||||||
map: `function(doc) {
|
return res.body
|
||||||
if (doc.modelId === "${response.id}") {
|
|
||||||
emit(doc[doc.key], doc._id);
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
await db.put(designDoc)
|
|
||||||
|
|
||||||
return {
|
|
||||||
...response,
|
|
||||||
...model,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createClientDatabase = async () => {
|
exports.createClientDatabase = async request => {
|
||||||
const db = new CouchDB(CLIENT_DB_ID)
|
const res = await request
|
||||||
|
.post("/api/client")
|
||||||
await db.put({
|
.set(exports.defaultHeaders)
|
||||||
_id: "_design/client",
|
.send({})
|
||||||
views: {
|
return res.body
|
||||||
by_type: {
|
|
||||||
map: function(doc) {
|
|
||||||
emit([doc.type], doc._id)
|
|
||||||
},
|
|
||||||
}.toString(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await db.put({
|
|
||||||
_id: TEST_APP_ID,
|
|
||||||
type: "app",
|
|
||||||
instances: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
return db
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroyClientDatabase = async () => new CouchDB(CLIENT_DB_ID).destroy()
|
exports.createApplication = async (request, name = "test_application") => {
|
||||||
|
const res = await request
|
||||||
exports.createInstanceDatabase = async instanceId => {
|
.post("/api/applications")
|
||||||
const db = new CouchDB(instanceId)
|
.set(exports.defaultHeaders)
|
||||||
|
.send({
|
||||||
await db.put({
|
name,
|
||||||
_id: "_design/database",
|
|
||||||
metadata: {
|
|
||||||
clientId: CLIENT_DB_ID,
|
|
||||||
applicationId: TEST_APP_ID,
|
|
||||||
},
|
|
||||||
views: {
|
|
||||||
by_type: {
|
|
||||||
map: function(doc) {
|
|
||||||
emit([doc.type], doc._id)
|
|
||||||
}.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
return res.body
|
||||||
|
}
|
||||||
|
|
||||||
return db
|
exports.destroyClientDatabase = async request => {
|
||||||
|
await request
|
||||||
|
.delete(`/api/client`)
|
||||||
|
.set(exports.defaultHeaders)
|
||||||
|
.send({})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.createInstance = async (request, appId) => {
|
||||||
|
const res = await request
|
||||||
|
.post(`/api/${appId}/instances`)
|
||||||
|
.set(exports.defaultHeaders)
|
||||||
|
.send({
|
||||||
|
name: "test-instance",
|
||||||
|
})
|
||||||
|
return res.body
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.createUser = async (
|
||||||
|
request,
|
||||||
|
instanceId,
|
||||||
|
username = "bill",
|
||||||
|
password = "bills_password"
|
||||||
|
) => {
|
||||||
|
const res = await request
|
||||||
|
.post(`/api/${instanceId}/users`)
|
||||||
|
.set(exports.defaultHeaders)
|
||||||
|
.send({ name: "Bill", username, password })
|
||||||
|
return res.body
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.insertDocument = async (databaseId, document) => {
|
exports.insertDocument = async (databaseId, document) => {
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
const supertest = require("supertest");
|
|
||||||
const app = require("../../../app");
|
|
||||||
const {
|
const {
|
||||||
createInstanceDatabase,
|
createInstance,
|
||||||
createClientDatabase,
|
createClientDatabase,
|
||||||
destroyClientDatabase
|
createApplication,
|
||||||
|
supertest,
|
||||||
|
defaultHeaders
|
||||||
} = require("./couchTestUtils");
|
} = require("./couchTestUtils");
|
||||||
|
|
||||||
|
|
||||||
const TEST_INSTANCE_ID = "testing-123";
|
|
||||||
const TEST_APP_ID = "test-app";
|
|
||||||
|
|
||||||
describe("/instances", () => {
|
describe("/instances", () => {
|
||||||
let request;
|
let TEST_APP_ID;
|
||||||
let server;
|
let server
|
||||||
|
let request
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
await createClientDatabase(request);
|
||||||
|
TEST_APP_ID = (await createApplication(request))._id
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -25,48 +22,30 @@ describe("/instances", () => {
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("returns a success message when the instance database is successfully created", async () => {
|
||||||
clientDb = await createClientDatabase();
|
const res = await request
|
||||||
});
|
.post(`/api/${TEST_APP_ID}/instances`)
|
||||||
|
.send({ name: "test-instance" })
|
||||||
afterEach(async () => {
|
.set(defaultHeaders)
|
||||||
await destroyClientDatabase();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a success message when the instance database is successfully created", done => {
|
|
||||||
request
|
|
||||||
.post(`/api/testing/${TEST_APP_ID}/instances`)
|
|
||||||
.send({ name: TEST_INSTANCE_ID })
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
|
||||||
expect(res.body.message).toEqual("Instance Database testing-123 successfully provisioned.");
|
expect(res.res.statusMessage).toEqual("Instance Database test-instance successfully provisioned.");
|
||||||
done();
|
expect(res.body._id).toBeDefined();
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
beforeEach(async () => {
|
|
||||||
await createClientDatabase();
|
|
||||||
instanceDb = await createInstanceDatabase(TEST_INSTANCE_ID);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
it("returns a success message when the instance database is successfully deleted", async () => {
|
||||||
await destroyClientDatabase();
|
const instance = await createInstance(request, TEST_APP_ID);
|
||||||
});
|
const res = await request
|
||||||
|
.delete(`/api/instances/${instance._id}`)
|
||||||
it("returns a success message when the instance database is successfully deleted", done => {
|
.set(defaultHeaders)
|
||||||
request
|
|
||||||
.delete(`/api/instances/${TEST_INSTANCE_ID}`)
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
|
||||||
expect(res.body.message).toEqual("Instance Database testing-123 successfully destroyed.");
|
expect(res.res.statusMessage).toEqual(`Instance Database ${instance._id} successfully destroyed.`);
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
const supertest = require("supertest");
|
const {
|
||||||
const app = require("../../../app");
|
createInstance,
|
||||||
const { createInstanceDatabase, createModel } = require("./couchTestUtils");
|
createModel,
|
||||||
|
supertest,
|
||||||
|
createClientDatabase,
|
||||||
const TEST_INSTANCE_ID = "testing-123";
|
createApplication
|
||||||
|
} = require("./couchTestUtils")
|
||||||
|
|
||||||
describe("/models", () => {
|
describe("/models", () => {
|
||||||
let request;
|
let request
|
||||||
let server;
|
let server
|
||||||
|
let app
|
||||||
|
let instance
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app;
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
await createClientDatabase(request)
|
||||||
|
app = await createApplication(request)
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -19,19 +23,14 @@ describe("/models", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
instance = await createInstance(request, app._id);
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await db.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a success message when the model is successfully created", done => {
|
it("returns a success message when the model is successfully created", done => {
|
||||||
request
|
request
|
||||||
.post(`/api/${TEST_INSTANCE_ID}/models`)
|
.post(`/api/${instance._id}/models`)
|
||||||
.send({
|
.send({
|
||||||
name: "TestModel",
|
name: "TestModel",
|
||||||
key: "name",
|
key: "name",
|
||||||
|
@ -43,29 +42,24 @@ describe("/models", () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
.end(async (err, res) => {
|
||||||
expect(res.body.message).toEqual("Model TestModel created successfully.");
|
expect(res.res.statusMessage).toEqual("Model TestModel created successfully.");
|
||||||
expect(res.body.model.name).toEqual("TestModel");
|
expect(res.body.name).toEqual("TestModel");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
let testModel;
|
let testModel
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
instance = await createInstance(request, app._id)
|
||||||
testModel = await createModel(TEST_INSTANCE_ID);
|
testModel = await createModel(request, instance._id, testModel)
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await db.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns all the models for that instance in the response body", done => {
|
it("returns all the models for that instance in the response body", done => {
|
||||||
request
|
request
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/models`)
|
.get(`/api/${instance._id}/models`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
@ -80,25 +74,20 @@ describe("/models", () => {
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
let testModel;
|
let testModel;
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
instance = await createInstance(request, app._id)
|
||||||
testModel = await createModel(TEST_INSTANCE_ID);
|
testModel = await createModel(request, instance._id, testModel)
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await db.destroy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a success response when a model is deleted.", done => {
|
it("returns a success response when a model is deleted.", done => {
|
||||||
request
|
request
|
||||||
.delete(`/api/${TEST_INSTANCE_ID}/models/${testModel.id}/${testModel.rev}`)
|
.delete(`/api/${instance._id}/models/${testModel._id}/${testModel._rev}`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (_, res) => {
|
.end(async (_, res) => {
|
||||||
expect(res.body.message).toEqual(`Model ${testModel.id} deleted.`);
|
expect(res.res.statusMessage).toEqual(`Model ${testModel._id} deleted.`);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
const supertest = require("supertest");
|
const {
|
||||||
const app = require("../../../app");
|
createApplication,
|
||||||
const { createInstanceDatabase, createModel } = require("./couchTestUtils");
|
createClientDatabase,
|
||||||
|
createInstance,
|
||||||
const TEST_INSTANCE_ID = "testing-123";
|
createModel,
|
||||||
|
supertest
|
||||||
const CONTACT_MODEL = {
|
} = require("./couchTestUtils");
|
||||||
"name": "Contact",
|
|
||||||
"type": "model",
|
|
||||||
"key": "name",
|
|
||||||
"schema": {
|
|
||||||
"name": { "type": "string" },
|
|
||||||
"age": { "type": "number" }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("/records", () => {
|
describe("/records", () => {
|
||||||
let request;
|
let request
|
||||||
let server;
|
let server
|
||||||
let db;
|
let instance
|
||||||
|
let model
|
||||||
|
let record
|
||||||
|
let app
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app;
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
await createClientDatabase(request)
|
||||||
|
app = await createApplication(request)
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -29,95 +25,94 @@ describe("/records", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("save, load, update, delete", () => {
|
describe("save, load, update, delete", () => {
|
||||||
let record;
|
|
||||||
let model;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
instance = await createInstance(request, app._id)
|
||||||
model = await createModel(TEST_INSTANCE_ID, CONTACT_MODEL)
|
model = await createModel(request, instance._id)
|
||||||
record = {
|
record = {
|
||||||
name: "Test Contact",
|
name: "Test Contact",
|
||||||
status: "new",
|
status: "new",
|
||||||
modelId: model.id
|
modelId: model._id
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
const createRecord = async r =>
|
||||||
await db.destroy();
|
await request
|
||||||
});
|
.post(`/api/${instance._id}/records`)
|
||||||
|
.send(r || record)
|
||||||
it("returns a success message when the record is created", done => {
|
|
||||||
request
|
|
||||||
.post(`/api/${TEST_INSTANCE_ID}/records`)
|
|
||||||
.send(record)
|
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
|
||||||
expect(res.res.statusMessage).toEqual("Contact created successfully")
|
it("returns a success message when the record is created", async () => {
|
||||||
|
const res = await createRecord()
|
||||||
|
expect(res.res.statusMessage).toEqual(`${model.name} created successfully`)
|
||||||
expect(res.body.name).toEqual("Test Contact")
|
expect(res.body.name).toEqual("Test Contact")
|
||||||
expect(res.body._rev).toBeDefined()
|
expect(res.body._rev).toBeDefined()
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("updates a record successfully", async () => {
|
it("updates a record successfully", async () => {
|
||||||
const existing = await db.post(record);
|
const rec = await createRecord()
|
||||||
|
const existing = rec.body
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(`/api/${TEST_INSTANCE_ID}/records`)
|
.post(`/api/${instance._id}/records`)
|
||||||
.send({
|
.send({
|
||||||
_id: existing.id,
|
_id: existing._id,
|
||||||
_rev: existing.rev,
|
_rev: existing._rev,
|
||||||
modelId: model.id,
|
modelId: model._id,
|
||||||
name: "Updated Name",
|
name: "Updated Name",
|
||||||
})
|
})
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body.message).toEqual("Contact updated successfully.")
|
expect(res.res.statusMessage).toEqual(`${model.name} updated successfully.`)
|
||||||
expect(res.body.record.name).toEqual("Updated Name")
|
expect(res.body.name).toEqual("Updated Name")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should load a record", async () => {
|
it("should load a record", async () => {
|
||||||
const existing = await db.post(record);
|
const rec = await createRecord()
|
||||||
|
const existing = rec.body
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/records/${existing.id}`)
|
.get(`/api/${instance._id}/records/${existing._id}`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body).toEqual({
|
expect(res.body).toEqual({
|
||||||
...record,
|
...record,
|
||||||
_id: existing.id,
|
_id: existing._id,
|
||||||
_rev: existing.rev
|
_rev: existing._rev,
|
||||||
|
type: "record",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should list all records for given modelId", async () => {
|
it("should list all records for given modelId", async () => {
|
||||||
const newRecord = {
|
const newRecord = {
|
||||||
modelId: model.id,
|
modelId: model._id,
|
||||||
name: "Second Contact",
|
name: "Second Contact",
|
||||||
status: "new"
|
status: "new"
|
||||||
}
|
}
|
||||||
|
await createRecord()
|
||||||
await db.post(newRecord);
|
await createRecord(newRecord)
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/all_${newRecord.modelId}/records`)
|
.get(`/api/${instance._id}/all_${newRecord.modelId}/records`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body.length).toBe(1)
|
expect(res.body.length).toBe(2)
|
||||||
expect(res.body[0].name).toEqual(newRecord.name);
|
expect(res.body.find(r => r.name === newRecord.name)).toBeDefined()
|
||||||
|
expect(res.body.find(r => r.name === record.name)).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("load should return 404 when record does not exist", async () => {
|
it("load should return 404 when record does not exist", async () => {
|
||||||
|
await createRecord()
|
||||||
await request
|
await request
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/records/not-a-valid-id`)
|
.get(`/api/${instance._id}/records/not-a-valid-id`)
|
||||||
.set("Accept", "application/json")
|
.set("Accept", "application/json")
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(404)
|
.expect(404)
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
const supertest = require("supertest");
|
|
||||||
const app = require("../../../app");
|
|
||||||
const {
|
const {
|
||||||
createInstanceDatabase
|
createClientDatabase,
|
||||||
} = require("./couchTestUtils");
|
createApplication,
|
||||||
|
createInstance,
|
||||||
|
supertest,
|
||||||
const TEST_INSTANCE_ID = "testing-123";
|
defaultHeaders,
|
||||||
const TEST_USER = {
|
createUser,
|
||||||
name: "Dave"
|
} = require("./couchTestUtils")
|
||||||
}
|
|
||||||
|
|
||||||
describe("/users", () => {
|
describe("/users", () => {
|
||||||
let request;
|
let request
|
||||||
let server;
|
let server
|
||||||
|
let app
|
||||||
|
let instance
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app
|
({ request, server } = await supertest(server))
|
||||||
request = supertest(server);
|
await createClientDatabase(request)
|
||||||
|
app = await createApplication(request)
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
instance = await createInstance(request, app._id)
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -24,52 +28,35 @@ describe("/users", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("returns a list of users from an instance db", async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
await createUser(request, instance._id, "brenda", "brendas_password")
|
||||||
});
|
await createUser(request, instance._id, "pam", "pam_password")
|
||||||
|
const res = await request
|
||||||
afterEach(async () => {
|
.get(`/api/${instance._id}/users`)
|
||||||
await db.destroy();
|
.set(defaultHeaders)
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a list of users from an instance db", done => {
|
|
||||||
request
|
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/users`)
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
|
||||||
const user = res.body[0];
|
expect(res.body.length).toBe(2)
|
||||||
expect(user.name).toEqual(TEST_USER.name);
|
expect(res.body.find(u => u.username === "brenda")).toBeDefined()
|
||||||
done();
|
expect(res.body.find(u => u.username === "pam")).toBeDefined()
|
||||||
});
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
it("returns a success message when a user is successfully created", async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
const res = await request
|
||||||
});
|
.post(`/api/${instance._id}/users`)
|
||||||
|
.set(defaultHeaders)
|
||||||
afterEach(async () => {
|
.send({ name: "Bill", username: "bill", password: "bills_password" })
|
||||||
await db.destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a success message when a user is successfully created", done => {
|
|
||||||
request
|
|
||||||
.post(`/api/${TEST_INSTANCE_ID}/users`)
|
|
||||||
.send({ name: "Bill", username: "bill1", password: "password" })
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.expect('Content-Type', /json/)
|
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
.expect('Content-Type', /json/)
|
||||||
expect(res.body.message).toEqual("User created successfully.");
|
|
||||||
done();
|
expect(res.res.statusMessage).toEqual("User created successfully.");
|
||||||
});
|
expect(res.body._id).toBeUndefined()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
const supertest = require("supertest");
|
const {
|
||||||
const app = require("../../../app");
|
createClientDatabase,
|
||||||
const { createInstanceDatabase, createModel, destroyDatabase } = require("./couchTestUtils");
|
createApplication,
|
||||||
|
createInstance,
|
||||||
|
createModel,
|
||||||
const TEST_INSTANCE_ID = "testing-123";
|
supertest,
|
||||||
|
defaultHeaders
|
||||||
|
} = require("./couchTestUtils")
|
||||||
|
|
||||||
describe("/views", () => {
|
describe("/views", () => {
|
||||||
let request;
|
let request
|
||||||
let server;
|
let server
|
||||||
let db;
|
let app
|
||||||
|
let instance
|
||||||
|
let model
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
server = app;
|
({ request, server } = await supertest())
|
||||||
request = supertest(server);
|
await createClientDatabase(request)
|
||||||
});
|
app = await createApplication(request)
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
server.close();
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("create", () => {
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
instance = await createInstance(request, app._id)
|
||||||
});
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterAll(async () => {
|
||||||
db && await db.destroy();
|
server.close()
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns a success message when the view is successfully created", done => {
|
const createView = async () =>
|
||||||
request
|
await request
|
||||||
.post(`/api/${TEST_INSTANCE_ID}/views`)
|
.post(`/api/${instance._id}/views`)
|
||||||
.send({
|
.send({
|
||||||
name: "TestView",
|
name: "TestView",
|
||||||
map: `function(doc) {
|
map: `function(doc) {
|
||||||
|
@ -40,39 +40,34 @@ describe("/views", () => {
|
||||||
}`,
|
}`,
|
||||||
reduce: `function(keys, values) { }`
|
reduce: `function(keys, values) { }`
|
||||||
})
|
})
|
||||||
.set("Accept", "application/json")
|
.set(defaultHeaders)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (err, res) => {
|
|
||||||
expect(res.body.message).toEqual("View TestView created successfully.");
|
describe("create", () => {
|
||||||
expect(res.body.id).toEqual("_design/database");
|
|
||||||
done();
|
it("returns a success message when the view is successfully created", async () => {
|
||||||
});
|
const res = await createView()
|
||||||
|
expect(res.res.statusMessage).toEqual("View TestView created successfully.");
|
||||||
|
expect(res.body.name).toEqual("TestView");
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
let db;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
db = await createInstanceDatabase(TEST_INSTANCE_ID);
|
model = await createModel(request, instance._id);
|
||||||
await createModel(TEST_INSTANCE_ID);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
it("should only return custom views", async () => {
|
||||||
await db.destroy();
|
const view = await createView()
|
||||||
});
|
const res = await request
|
||||||
|
.get(`/api/${instance._id}/views`)
|
||||||
it("returns a list of all the views that exist in the instance database", done => {
|
.set(defaultHeaders)
|
||||||
request
|
|
||||||
.get(`/api/${TEST_INSTANCE_ID}/views`)
|
|
||||||
.set("Accept", "application/json")
|
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(async (_, res) => {
|
expect(res.body.length).toBe(1)
|
||||||
expect(res.body.by_type).toBeDefined();
|
expect(res.body.find(v => v.name === view.body.name)).toBeDefined()
|
||||||
done();
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,8 @@ const router = Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
.get("/api/:instanceId/users", controller.fetch)
|
.get("/api/:instanceId/users", controller.fetch)
|
||||||
.post("/api/:appId/:instanceId/users", controller.create)
|
.get("/api/:instanceId/users/:username", controller.find)
|
||||||
.delete("/api/:instanceId/users/:userId", controller.destroy)
|
.post("/api/:instanceId/users", controller.create)
|
||||||
|
.delete("/api/:instanceId/users/:username", controller.destroy)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -2,14 +2,30 @@ const Koa = require("koa")
|
||||||
const logger = require("koa-logger")
|
const logger = require("koa-logger")
|
||||||
const api = require("./api")
|
const api = require("./api")
|
||||||
const koaBody = require("koa-body")
|
const koaBody = require("koa-body")
|
||||||
|
const env = require("./environment")
|
||||||
|
const http = require("http")
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
|
|
||||||
// set up top level koa middleware
|
// set up top level koa middleware
|
||||||
app.use(koaBody({ multipart: true }))
|
app.use(koaBody({ multipart: true }))
|
||||||
app.use(logger())
|
|
||||||
|
if (env.LOGGER !== "off") app.use(logger())
|
||||||
|
|
||||||
// api routes
|
// api routes
|
||||||
app.use(api.routes())
|
app.use(api.routes())
|
||||||
|
|
||||||
module.exports = app.listen(process.env.PORT || 4001)
|
module.exports = async port => {
|
||||||
|
port = port || env.PORT || 4001
|
||||||
|
const server = http.createServer(app.callback())
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
server.on("error", e => {
|
||||||
|
if (e.code === "EADDRINUSE") {
|
||||||
|
reject(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
server.listen({ port }, () => {
|
||||||
|
resolve(server)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
const PouchDB = require("pouchdb")
|
const PouchDB = require("pouchdb")
|
||||||
const allDbs = require("pouchdb-all-dbs")
|
const allDbs = require("pouchdb-all-dbs")
|
||||||
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
||||||
|
const env = require("../environment")
|
||||||
|
|
||||||
const COUCH_DB_URL = process.env.COUCH_DB_URL || `leveldb://${budibaseAppsDir()}/`
|
const COUCH_DB_URL = env.COUCH_DB_URL || `leveldb://${budibaseAppsDir().replace(/\\/g, "/")}/.data/`
|
||||||
|
const isInMemory = env.NODE_ENV === "jest"
|
||||||
|
|
||||||
|
if (isInMemory) PouchDB.plugin(require("pouchdb-adapter-memory"))
|
||||||
|
|
||||||
const Pouch = PouchDB.defaults({
|
const Pouch = PouchDB.defaults({
|
||||||
prefix: COUCH_DB_URL,
|
prefix: isInMemory ? undefined : COUCH_DB_URL,
|
||||||
|
adapter: isInMemory ? "memory" : undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
allDbs(Pouch)
|
allDbs(Pouch)
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
const CouchDB = require("./client")
|
||||||
|
|
||||||
|
exports.create = async clientId => {
|
||||||
|
const dbId = exports.name(clientId)
|
||||||
|
const db = new CouchDB(dbId)
|
||||||
|
await db.put({
|
||||||
|
_id: "_design/client",
|
||||||
|
views: {
|
||||||
|
by_type: {
|
||||||
|
map: `function(doc) {
|
||||||
|
emit([doc.type], doc._id)
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.destroy = async function(clientId) {
|
||||||
|
const dbId = exports.name(clientId)
|
||||||
|
await new CouchDB(dbId).destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.name = function(clientId) {
|
||||||
|
return `client_${clientId}`
|
||||||
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
module.exports = async db => {
|
|
||||||
const doc = await db.put({
|
|
||||||
_id: "_design/client",
|
|
||||||
views: {
|
|
||||||
by_type: {
|
|
||||||
map: `function(doc) {
|
|
||||||
emit([doc.type], doc._id)
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
console.log(doc)
|
|
||||||
}
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
CLIENT_ID: process.env.CLIENT_ID,
|
||||||
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
|
JWT_SECRET: process.env.JWT_SECRET,
|
||||||
|
BUDIBASE_DIR: process.env.BUDIBASE_DIR,
|
||||||
|
ADMIN_SECRET: process.env.ADMIN_SECRET,
|
||||||
|
PORT: process.env.PORT,
|
||||||
|
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
||||||
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
||||||
|
LOGGER: process.env.LOGGER,
|
||||||
|
}
|
|
@ -1,10 +1,23 @@
|
||||||
const jwt = require("jsonwebtoken")
|
const jwt = require("jsonwebtoken")
|
||||||
const STATUS_CODES = require("../utilities/statusCodes");
|
const STATUS_CODES = require("../utilities/statusCodes")
|
||||||
|
const env = require("../environment")
|
||||||
|
|
||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
if (ctx.isDev) {
|
const authHeader = ctx.get("Authorization")
|
||||||
|
|
||||||
|
if (
|
||||||
|
authHeader &&
|
||||||
|
authHeader.startsWith("Basic") &&
|
||||||
|
authHeader.split(" ")[1] === env.ADMIN_SECRET
|
||||||
|
) {
|
||||||
ctx.isAuthenticated = true
|
ctx.isAuthenticated = true
|
||||||
await next();
|
await next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.isDev && ctx.cookies.get("builder:token") === env.ADMIN_SECRET) {
|
||||||
|
ctx.isAuthenticated = true
|
||||||
|
await next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const bcrypt = require("bcryptjs")
|
const bcrypt = require("bcryptjs")
|
||||||
|
const env = require("../environment")
|
||||||
|
|
||||||
const SALT_ROUNDS = process.env.SALT_ROUNDS || 10
|
const SALT_ROUNDS = env.SALT_ROUNDS || 10
|
||||||
|
|
||||||
exports.hash = async data => {
|
exports.hash = async data => {
|
||||||
const salt = await bcrypt.genSalt(SALT_ROUNDS)
|
const salt = await bcrypt.genSalt(SALT_ROUNDS)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
const { homedir, tmpdir } = require("os")
|
const { homedir, tmpdir } = require("os")
|
||||||
|
const env = require("../environment")
|
||||||
|
|
||||||
module.exports.budibaseAppsDir = function() {
|
module.exports.budibaseAppsDir = function() {
|
||||||
return process.env.BUDIBASE_DIR || join(homedir(), ".budibase")
|
return env.BUDIBASE_DIR || join(homedir(), ".budibase")
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.budibaseTempDir = function() {
|
module.exports.budibaseTempDir = function() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ const {
|
||||||
rmdir,
|
rmdir,
|
||||||
} = require("fs-extra")
|
} = require("fs-extra")
|
||||||
const { join, dirname, resolve } = require("path")
|
const { join, dirname, resolve } = require("path")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
const buildPage = require("./buildPage")
|
const buildPage = require("./buildPage")
|
||||||
const getPages = require("./getPages")
|
const getPages = require("./getPages")
|
||||||
|
@ -31,7 +32,7 @@ module.exports.getPackageForBuilder = async (config, application) => {
|
||||||
|
|
||||||
application,
|
application,
|
||||||
|
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: env.CLIENT_ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -576,6 +576,13 @@ abort-controller@3.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
event-target-shim "^5.0.0"
|
event-target-shim "^5.0.0"
|
||||||
|
|
||||||
|
abstract-leveldown@2.4.1:
|
||||||
|
version "2.4.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-2.4.1.tgz#b3bfedb884eb693a12775f0c55e9f0a420ccee64"
|
||||||
|
integrity sha1-s7/tuITraToSd18MVenwpCDM7mQ=
|
||||||
|
dependencies:
|
||||||
|
xtend "~4.0.0"
|
||||||
|
|
||||||
abstract-leveldown@^6.2.1:
|
abstract-leveldown@^6.2.1:
|
||||||
version "6.3.0"
|
version "6.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.3.0.tgz#d25221d1e6612f820c35963ba4bd739928f6026a"
|
resolved "https://registry.yarnpkg.com/abstract-leveldown/-/abstract-leveldown-6.3.0.tgz#d25221d1e6612f820c35963ba4bd739928f6026a"
|
||||||
|
@ -4271,6 +4278,11 @@ ltgt@2.2.1, ltgt@^2.1.2:
|
||||||
resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5"
|
resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5"
|
||||||
integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=
|
integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=
|
||||||
|
|
||||||
|
ltgt@~2.1.3:
|
||||||
|
version "2.1.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.1.3.tgz#10851a06d9964b971178441c23c9e52698eece34"
|
||||||
|
integrity sha1-EIUaBtmWS5cReEQcI8nlJpjuzjQ=
|
||||||
|
|
||||||
lunr@^2.3.5:
|
lunr@^2.3.5:
|
||||||
version "2.3.8"
|
version "2.3.8"
|
||||||
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.8.tgz#a8b89c31f30b5a044b97d2d28e2da191b6ba2072"
|
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.8.tgz#a8b89c31f30b5a044b97d2d28e2da191b6ba2072"
|
||||||
|
@ -4322,6 +4334,17 @@ media-typer@0.3.0:
|
||||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||||
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=
|
||||||
|
|
||||||
|
memdown@1.2.4:
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/memdown/-/memdown-1.2.4.tgz#cd9a34aaf074d53445a271108eb4b8dd4ec0f27f"
|
||||||
|
integrity sha1-zZo0qvB01TRFonEQjrS43U7A8n8=
|
||||||
|
dependencies:
|
||||||
|
abstract-leveldown "2.4.1"
|
||||||
|
functional-red-black-tree "^1.0.1"
|
||||||
|
immediate "^3.2.3"
|
||||||
|
inherits "~2.0.1"
|
||||||
|
ltgt "~2.1.3"
|
||||||
|
|
||||||
merge-stream@^2.0.0:
|
merge-stream@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
||||||
|
@ -4905,6 +4928,47 @@ posix-character-classes@^0.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
|
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
|
||||||
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=
|
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=
|
||||||
|
|
||||||
|
pouchdb-adapter-leveldb-core@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-adapter-leveldb-core/-/pouchdb-adapter-leveldb-core-7.2.1.tgz#71bf2a05755689e2b05e78e796003a18ebf65a69"
|
||||||
|
integrity sha512-kwNsaM1pYDVz6LG9z2/7Tfcuw5iZJ5u8IqzjxMAGCfurScMaF4e7IJnVWqAceWSiaCrp91DbCULhrl4SH8iTDg==
|
||||||
|
dependencies:
|
||||||
|
argsarray "0.0.1"
|
||||||
|
buffer-from "1.1.0"
|
||||||
|
double-ended-queue "2.1.0-0"
|
||||||
|
levelup "4.1.0"
|
||||||
|
pouchdb-adapter-utils "7.2.1"
|
||||||
|
pouchdb-binary-utils "7.2.1"
|
||||||
|
pouchdb-collections "7.2.1"
|
||||||
|
pouchdb-errors "7.2.1"
|
||||||
|
pouchdb-json "7.2.1"
|
||||||
|
pouchdb-md5 "7.2.1"
|
||||||
|
pouchdb-merge "7.2.1"
|
||||||
|
pouchdb-utils "7.2.1"
|
||||||
|
sublevel-pouchdb "7.2.1"
|
||||||
|
through2 "3.0.1"
|
||||||
|
|
||||||
|
pouchdb-adapter-memory@^7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-adapter-memory/-/pouchdb-adapter-memory-7.2.1.tgz#70341b54093b6bda3ab6e78482c8d00b906178e9"
|
||||||
|
integrity sha512-W4+9+xol95NIdDlk2KVxhv81QWRx/P4L9CPGdh7nqGtzuhVbvqMEqZN24XauIoBaaDy1LLkCyXMvChNt3GHBRQ==
|
||||||
|
dependencies:
|
||||||
|
memdown "1.2.4"
|
||||||
|
pouchdb-adapter-leveldb-core "7.2.1"
|
||||||
|
pouchdb-utils "7.2.1"
|
||||||
|
|
||||||
|
pouchdb-adapter-utils@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-adapter-utils/-/pouchdb-adapter-utils-7.2.1.tgz#d2583bc5c6bfcd6cf0d20acd54cb51683a196d37"
|
||||||
|
integrity sha512-asMAhH6mJRgz6JFEvaS/gMcfWR9pCM+DLPzzIN5vSAm8jUEaMApCONx86xhBwVgzAJ8aVzrG11J9D5iJlM7LSQ==
|
||||||
|
dependencies:
|
||||||
|
pouchdb-binary-utils "7.2.1"
|
||||||
|
pouchdb-collections "7.2.1"
|
||||||
|
pouchdb-errors "7.2.1"
|
||||||
|
pouchdb-md5 "7.2.1"
|
||||||
|
pouchdb-merge "7.2.1"
|
||||||
|
pouchdb-utils "7.2.1"
|
||||||
|
|
||||||
pouchdb-all-dbs@^1.0.2:
|
pouchdb-all-dbs@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/pouchdb-all-dbs/-/pouchdb-all-dbs-1.0.2.tgz#8fa1aa4b01665e00e0da9c61bf6dbb99eca05d3c"
|
resolved "https://registry.yarnpkg.com/pouchdb-all-dbs/-/pouchdb-all-dbs-1.0.2.tgz#8fa1aa4b01665e00e0da9c61bf6dbb99eca05d3c"
|
||||||
|
@ -4916,6 +4980,45 @@ pouchdb-all-dbs@^1.0.2:
|
||||||
pouchdb-promise "5.4.3"
|
pouchdb-promise "5.4.3"
|
||||||
tiny-queue "^0.2.0"
|
tiny-queue "^0.2.0"
|
||||||
|
|
||||||
|
pouchdb-binary-utils@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-binary-utils/-/pouchdb-binary-utils-7.2.1.tgz#ad23ed63d09699e7e6244f846b5cf07c6d9d4b8b"
|
||||||
|
integrity sha512-kbzOOYti/3d8s2bQY5EfJVd7c9E84q4oEpr1M8fOOHKnINZFteKkZQywD4roblUnew0Obyhvozif4LAr3CMZFg==
|
||||||
|
dependencies:
|
||||||
|
buffer-from "1.1.0"
|
||||||
|
|
||||||
|
pouchdb-collections@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-collections/-/pouchdb-collections-7.2.1.tgz#768c2c578b22eda9ac0c92a4b1106d18f3c113fb"
|
||||||
|
integrity sha512-cqe3GY3wDq2j59tnh+5ZV0bZj1O+YWiBz4qM7HEcgrEXnc29ADvXXPp71tmcpZUCR39bzLKyYtadAQu7FpOeOA==
|
||||||
|
|
||||||
|
pouchdb-errors@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-errors/-/pouchdb-errors-7.2.1.tgz#798f5279a0d363d6b93c97a1b65ee903f61af143"
|
||||||
|
integrity sha512-/tBP+eWY6a62UoZnJ6JJlNmbNpNS5FgVimkqwLMrFQkXpbJlhshYDeJ5PHR0W3Rlfc54GMZC7m4KhJt9kG/CkA==
|
||||||
|
dependencies:
|
||||||
|
inherits "2.0.4"
|
||||||
|
|
||||||
|
pouchdb-json@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-json/-/pouchdb-json-7.2.1.tgz#41836bdffed1d1b6207793f0b26bf771105c0c61"
|
||||||
|
integrity sha512-YGRX/qDl+iEX2vz23kzBtMoH0hpb9xASKnEGZPH76BTDq4RQ+eUOxyXU9E1fPdQhsq8+0pcEQN7VCnFEdQ7MUQ==
|
||||||
|
dependencies:
|
||||||
|
vuvuzela "1.0.3"
|
||||||
|
|
||||||
|
pouchdb-md5@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-md5/-/pouchdb-md5-7.2.1.tgz#2b057b148b3f31491d77c4dd6b6139af31b07f66"
|
||||||
|
integrity sha512-TJqGtNguctPiSai5b4+oTPi9oOcxSbNolkUtxRBxklf8kw+PNsDUi1H0DIFmA57n0qHCU19PXdbEVYlUhv/PAA==
|
||||||
|
dependencies:
|
||||||
|
pouchdb-binary-utils "7.2.1"
|
||||||
|
spark-md5 "3.0.0"
|
||||||
|
|
||||||
|
pouchdb-merge@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-merge/-/pouchdb-merge-7.2.1.tgz#d9301a4e92ccb14347ef8cc6a01caa63e3950fcd"
|
||||||
|
integrity sha512-TgxXPw1sZERwihoWSzLIdvn5MP1YKhYNaB0UuvYjboK+WUpCLh5WEeNTJi6WwUD9Yoc66QxP9D3qmfNEjd1BHQ==
|
||||||
|
|
||||||
pouchdb-promise@5.4.3:
|
pouchdb-promise@5.4.3:
|
||||||
version "5.4.3"
|
version "5.4.3"
|
||||||
resolved "https://registry.yarnpkg.com/pouchdb-promise/-/pouchdb-promise-5.4.3.tgz#331d670b1989d5a03f268811214f27f54150cb2b"
|
resolved "https://registry.yarnpkg.com/pouchdb-promise/-/pouchdb-promise-5.4.3.tgz#331d670b1989d5a03f268811214f27f54150cb2b"
|
||||||
|
@ -4923,6 +5026,20 @@ pouchdb-promise@5.4.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
lie "3.0.4"
|
lie "3.0.4"
|
||||||
|
|
||||||
|
pouchdb-utils@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/pouchdb-utils/-/pouchdb-utils-7.2.1.tgz#5dec1c53c8ecba717e5762311e9a1def2d4ebf9c"
|
||||||
|
integrity sha512-ZInfRpKtJ2HwLz2Dv3NEona9khvGud0rWzvQGwUs1zoaOoSB5XxK3ui5s5fLpBrONgz0WcTB49msOUq4oAUzFg==
|
||||||
|
dependencies:
|
||||||
|
argsarray "0.0.1"
|
||||||
|
clone-buffer "1.0.0"
|
||||||
|
immediate "3.0.6"
|
||||||
|
inherits "2.0.4"
|
||||||
|
pouchdb-collections "7.2.1"
|
||||||
|
pouchdb-errors "7.2.1"
|
||||||
|
pouchdb-md5 "7.2.1"
|
||||||
|
uuid "3.3.3"
|
||||||
|
|
||||||
pouchdb@^7.2.1:
|
pouchdb@^7.2.1:
|
||||||
version "7.2.1"
|
version "7.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/pouchdb/-/pouchdb-7.2.1.tgz#619e3d5c2463ddd94a4b1bf40d44408c46e9de79"
|
resolved "https://registry.yarnpkg.com/pouchdb/-/pouchdb-7.2.1.tgz#619e3d5c2463ddd94a4b1bf40d44408c46e9de79"
|
||||||
|
@ -5888,6 +6005,16 @@ strip-json-comments@~2.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
|
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
|
||||||
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
||||||
|
|
||||||
|
sublevel-pouchdb@7.2.1:
|
||||||
|
version "7.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/sublevel-pouchdb/-/sublevel-pouchdb-7.2.1.tgz#ce3ec06c91ee5afb5ab1bb7abbb905fd4dcc8c38"
|
||||||
|
integrity sha512-pliYcLDubhpe8ONw3P09CehULjuNopl6ybj6N0YudOg+FidqEYgJUgN/1n7ZqVrcXCDHws9g6lN1srlQta5/XQ==
|
||||||
|
dependencies:
|
||||||
|
inherits "2.0.4"
|
||||||
|
level-codec "9.0.1"
|
||||||
|
ltgt "2.2.1"
|
||||||
|
readable-stream "1.0.33"
|
||||||
|
|
||||||
sumchecker@^3.0.1:
|
sumchecker@^3.0.1:
|
||||||
version "3.0.1"
|
version "3.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-3.0.1.tgz#6377e996795abb0b6d348e9b3e1dfb24345a8e42"
|
resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-3.0.1.tgz#6377e996795abb0b6d348e9b3e1dfb24345a8e42"
|
||||||
|
|
Loading…
Reference in New Issue