From c895e9887bee9972992585c248b4e9efb0d95718 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 21 Oct 2020 09:19:26 +0100 Subject: [PATCH 01/67] Add initial work on dropdown components --- packages/builder/src/budibase.css | 8 -- .../ComponentSelectionList.svelte | 107 ++++++++++++++---- .../userInterface/FrontendNavigatePane.svelte | 8 +- .../userInterface/ItemTab/Item.svelte | 4 +- .../userInterface/ItemTab/Tab.svelte | 22 +++- .../[application]/frontend/_layout.svelte | 44 +++---- 6 files changed, 129 insertions(+), 64 deletions(-) diff --git a/packages/builder/src/budibase.css b/packages/builder/src/budibase.css index 6dc786f522..1426a7beed 100644 --- a/packages/builder/src/budibase.css +++ b/packages/builder/src/budibase.css @@ -85,14 +85,6 @@ box-sizing: border-box; } -.preview-pane { - grid-column: 2; - margin: 80px 60px; - background: #fff; - border-radius: 5px; - box-shadow: 0 0px 6px rgba(0, 0, 0, 0.05); -} - .budibase__table { border: 1px solid var(--grey-4); background: #fff; diff --git a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte index 00ce42cf61..404cfa102b 100644 --- a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte +++ b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte @@ -3,46 +3,111 @@ import { store } from "builderStore" import components from "./temporaryPanelStructure.js" import CategoryTab from "./CategoryTab.svelte" + import { Popover } from "@budibase/bbui" + import { fade, fly } from "svelte/transition" import Tab from "./ItemTab/Tab.svelte" - export let toggleTab - const categories = components.categories - let selectedCategory = categories[0] + let selectedIndex + let width + $: selectedCategory = selectedIndex == null ? null : categories[selectedIndex] + + const close = () => { + selectedIndex = null + } const onComponentChosen = component => { store.addChildComponent(component._component, component.presetProps) - toggleTab("Navigate") - // Get ID path const path = store.getPathToComponent($store.currentComponentInfo) // Go to correct URL $goto(`./:page/:screen/${path}`) + close() } -
- (selectedCategory = category)} - {selectedCategory} - {categories} /> - -
- onComponentChosen(e.detail)} - {toggleTab} /> +
+
+ {#each categories as category, idx} +
(selectedIndex = idx)} + class:active={selectedCategory === category}> + {category.name} + +
+ {/each}
+ {#if selectedCategory != null} +
+ + {/if}
diff --git a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte index 64c3ee45f4..651cc5c6ac 100644 --- a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte +++ b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte @@ -4,19 +4,17 @@ import PageLayout from "components/userInterface/PageLayout.svelte" import PagesList from "components/userInterface/PagesList.svelte" import NewScreenModal from "components/userInterface/NewScreenModal.svelte" - import { Button, Spacer, Modal } from "@budibase/bbui" + import { Button, Spacer, Modal, Heading } from "@budibase/bbui" let modal +Screens - - - - diff --git a/packages/builder/src/components/userInterface/ItemTab/Item.svelte b/packages/builder/src/components/userInterface/ItemTab/Item.svelte index 7d118afe61..de04bc5208 100644 --- a/packages/builder/src/components/userInterface/ItemTab/Item.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Item.svelte @@ -14,12 +14,12 @@ display: flex; flex-direction: column; cursor: pointer; - padding: 12px 16px 16px 16px; - height: 80px; justify-content: center; align-items: center; background-color: var(--grey-1); border-radius: 5px; + width: 120px; + height: 80px; } .item-item:hover { diff --git a/packages/builder/src/components/userInterface/ItemTab/Tab.svelte b/packages/builder/src/components/userInterface/ItemTab/Tab.svelte index 090fad1dc1..db16acf3d6 100644 --- a/packages/builder/src/components/userInterface/ItemTab/Tab.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Tab.svelte @@ -25,11 +25,13 @@ {#if !list.isCategory} {/if} -{#each list.children as item} - {#if !item.showOnPages || item.showOnPages.includes($store.currentPageName)} - handleClick(item)} /> - {/if} -{/each} +
+ {#each list.children as item} + {#if !item.showOnPages || item.showOnPages.includes($store.currentPageName)} + handleClick(item)} /> + {/if} + {/each} +
diff --git a/packages/builder/src/pages/[application]/frontend/_layout.svelte b/packages/builder/src/pages/[application]/frontend/_layout.svelte index 0aae313ccd..420a1bd2ea 100644 --- a/packages/builder/src/pages/[application]/frontend/_layout.svelte +++ b/packages/builder/src/pages/[application]/frontend/_layout.svelte @@ -32,8 +32,6 @@ settingsView.show() } - let leftNavSwitcher - const lastPartOfName = c => (c ? last(c.split("/")) : "") @@ -41,21 +39,15 @@
- - -
- -
-
- -
-
- +
{#if $store.currentPageName && $store.currentPageName.length > 0} - + +
+ +
{/if}
@@ -73,34 +65,42 @@ .root { display: grid; grid-template-columns: 300px 1fr 300px; - width: 100%; background: var(--grey-1); - flex: 1; - min-height: 0; align-items: stretch; + height: calc(100vh - 60px); } .ui-nav { grid-column: 1; background-color: var(--white); - height: calc(100vh - 69px); - padding: 0; display: flex; flex-direction: column; + gap: var(--spacing-m); + padding: var(--spacing-xl); + overflow-y: auto; + border-right: 1px solid var(--grey-2); } .preview-pane { grid-column: 2; - margin: 40px; + overflow-y: auto; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: stretch; + gap: var(--spacing-m); + } + .preview-content { background: #fff; - border-radius: 5px; + box-shadow: 0 0 12px rgba(0, 0, 0, 0.05); + flex: 1 1 auto; + margin: var(--spacing-xl) 40px; } .components-pane { grid-column: 3; background-color: var(--white); - min-height: 0px; - height: calc(100vh - 69px); + border-left: 1px solid var(--grey-2); } .nav-group-header > div:nth-child(1) { From e1c70f43db96415568f44b28b345003cd0641a8e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 15:11:22 +0100 Subject: [PATCH 02/67] Rename backend to data and frontend to design --- .../src/pages/[application]/{backend => data}/_layout.svelte | 0 .../src/pages/[application]/{backend => data}/index.svelte | 0 .../{backend => data}/table/[selectedTable]/_layout.svelte | 0 .../{backend => data}/table/[selectedTable]/index.svelte | 0 .../relationship/[selectedRow]/[selectedField]/index.svelte | 0 .../table/[selectedTable]/relationship/[selectedRow]/index.svelte | 0 .../table/[selectedTable]/relationship/index.svelte | 0 .../pages/[application]/{backend => data}/table/_layout.svelte | 0 .../src/pages/[application]/{backend => data}/table/index.svelte | 0 .../{backend => data}/view/[selectedView]/_layout.svelte | 0 .../{backend => data}/view/[selectedView]/index.svelte | 0 .../{frontend => design}/[page]/[screen]/_fallback.svelte | 0 .../{frontend => design}/[page]/[screen]/_layout.svelte | 0 .../[application]/{frontend => design}/[page]/_layout.svelte | 0 .../pages/[application]/{frontend => design}/[page]/index.svelte | 0 .../src/pages/[application]/{frontend => design}/_layout.svelte | 0 .../src/pages/[application]/{frontend => design}/index.svelte | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename packages/builder/src/pages/[application]/{backend => data}/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/[selectedTable]/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/[selectedTable]/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/[selectedTable]/relationship/[selectedRow]/[selectedField]/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/[selectedTable]/relationship/[selectedRow]/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/[selectedTable]/relationship/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/table/index.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/view/[selectedView]/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{backend => data}/view/[selectedView]/index.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/[page]/[screen]/_fallback.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/[page]/[screen]/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/[page]/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/[page]/index.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/_layout.svelte (100%) rename packages/builder/src/pages/[application]/{frontend => design}/index.svelte (100%) diff --git a/packages/builder/src/pages/[application]/backend/_layout.svelte b/packages/builder/src/pages/[application]/data/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/_layout.svelte rename to packages/builder/src/pages/[application]/data/_layout.svelte diff --git a/packages/builder/src/pages/[application]/backend/index.svelte b/packages/builder/src/pages/[application]/data/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/index.svelte rename to packages/builder/src/pages/[application]/data/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/[selectedTable]/_layout.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/[selectedTable]/_layout.svelte rename to packages/builder/src/pages/[application]/data/table/[selectedTable]/_layout.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/[selectedTable]/index.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/[selectedTable]/index.svelte rename to packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/[selectedRow]/[selectedField]/index.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/[selectedRow]/[selectedField]/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/[selectedRow]/[selectedField]/index.svelte rename to packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/[selectedRow]/[selectedField]/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/[selectedRow]/index.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/[selectedRow]/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/[selectedRow]/index.svelte rename to packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/[selectedRow]/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/index.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/[selectedTable]/relationship/index.svelte rename to packages/builder/src/pages/[application]/data/table/[selectedTable]/relationship/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/_layout.svelte b/packages/builder/src/pages/[application]/data/table/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/_layout.svelte rename to packages/builder/src/pages/[application]/data/table/_layout.svelte diff --git a/packages/builder/src/pages/[application]/backend/table/index.svelte b/packages/builder/src/pages/[application]/data/table/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/table/index.svelte rename to packages/builder/src/pages/[application]/data/table/index.svelte diff --git a/packages/builder/src/pages/[application]/backend/view/[selectedView]/_layout.svelte b/packages/builder/src/pages/[application]/data/view/[selectedView]/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/view/[selectedView]/_layout.svelte rename to packages/builder/src/pages/[application]/data/view/[selectedView]/_layout.svelte diff --git a/packages/builder/src/pages/[application]/backend/view/[selectedView]/index.svelte b/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/backend/view/[selectedView]/index.svelte rename to packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte diff --git a/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_fallback.svelte b/packages/builder/src/pages/[application]/design/[page]/[screen]/_fallback.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/[page]/[screen]/_fallback.svelte rename to packages/builder/src/pages/[application]/design/[page]/[screen]/_fallback.svelte diff --git a/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte b/packages/builder/src/pages/[application]/design/[page]/[screen]/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte rename to packages/builder/src/pages/[application]/design/[page]/[screen]/_layout.svelte diff --git a/packages/builder/src/pages/[application]/frontend/[page]/_layout.svelte b/packages/builder/src/pages/[application]/design/[page]/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/[page]/_layout.svelte rename to packages/builder/src/pages/[application]/design/[page]/_layout.svelte diff --git a/packages/builder/src/pages/[application]/frontend/[page]/index.svelte b/packages/builder/src/pages/[application]/design/[page]/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/[page]/index.svelte rename to packages/builder/src/pages/[application]/design/[page]/index.svelte diff --git a/packages/builder/src/pages/[application]/frontend/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/_layout.svelte rename to packages/builder/src/pages/[application]/design/_layout.svelte diff --git a/packages/builder/src/pages/[application]/frontend/index.svelte b/packages/builder/src/pages/[application]/design/index.svelte similarity index 100% rename from packages/builder/src/pages/[application]/frontend/index.svelte rename to packages/builder/src/pages/[application]/design/index.svelte From d3714ea9ee6f75c89d5ccf6d2ffc11fdac2ea6a6 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 15:11:46 +0100 Subject: [PATCH 03/67] Update top nav border style --- .../src/pages/[application]/_reset.svelte | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index 87759aef97..a39fd0ce62 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -30,10 +30,10 @@ // e.g. if one of your screens is selected on front end, then // you browse to backend, when you click frontend, you will be // brought back to the same screen - const topItemNavigate = path => () => { - const activeTopNav = $layout.children.find(c => $isActive(c.path)) + const topItemNavigate = (path) => () => { + const activeTopNav = $layout.children.find((c) => $isActive(c.path)) if (!activeTopNav) return - store.update(state => { + store.update((state) => { if (!state.previousTopNavPath) state.previousTopNavPath = {} state.previousTopNavPath[ activeTopNav.path @@ -66,22 +66,26 @@
- + + + +
+
+ + + +
+
@@ -120,7 +124,7 @@ flex: 0 0 auto; height: 60px; background: #fff; - padding: 0px 20px 0 20px; + padding: 0 20px; display: flex; box-sizing: border-box; justify-content: space-between; @@ -166,20 +170,19 @@ font-weight: 500; } - .topnavitemright { + .topnavitemright a { cursor: pointer; color: var(--grey-7); - margin: 0 20px 0 0; - font-weight: 500; - font-size: 1rem; - height: 100%; + margin: 0 12px 0 0; display: flex; - flex: 1; + flex-direction: row; + justify-content: center; align-items: center; - box-sizing: border-box; + height: 24px; + width: 24px; } - .topnavitemright:hover { + .topnavitemright a:hover { color: var(--ink); font-weight: 500; } @@ -205,10 +208,13 @@ text-transform: capitalize; } - .help { - font-size: 24px; + i { + font-size: 18px; color: var(--grey-7); } + i:hover { + color: var(--ink); + } .beta { position: absolute; From 6bead1126483dfebb530e2265729b0737df967af Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:39:50 +0100 Subject: [PATCH 04/67] Update remix icons version to fix line chart icon --- packages/builder/src/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/index.html b/packages/builder/src/index.html index 150d9e23b9..b4073c2d7e 100644 --- a/packages/builder/src/index.html +++ b/packages/builder/src/index.html @@ -7,7 +7,7 @@ Budibase Builder - + From 29dd32320d77db5bec6eaa71e66027f0b074a69a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:42:03 +0100 Subject: [PATCH 05/67] Update screen components hierarchy to use new common component styles --- .../src/components/common/NavItem.svelte | 108 ++++++++++++++++++ .../userInterface/ComponentsHierarchy.svelte | 94 +++------------ .../ComponentsHierarchyChildren.svelte | 103 +++++------------ .../userInterface/PageLayout.svelte | 67 ++--------- 4 files changed, 159 insertions(+), 213 deletions(-) create mode 100644 packages/builder/src/components/common/NavItem.svelte diff --git a/packages/builder/src/components/common/NavItem.svelte b/packages/builder/src/components/common/NavItem.svelte new file mode 100644 index 0000000000..7e21689c3f --- /dev/null +++ b/packages/builder/src/components/common/NavItem.svelte @@ -0,0 +1,108 @@ + + +
+
+ {#if withArrow} +
+ +
+ {/if} + {#if icon} +
+ {/if} +
{text}
+ {#if withActions} +
+ +
+ {/if} +
+
+ + diff --git a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte index add2a99d6a..43a2c07bd9 100644 --- a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte @@ -1,13 +1,12 @@ -
- - - - - Master Screen -
+ {#if $store.currentPreviewItem.name === _layout.title && _layout.component.props._children} {/if} - - From 80e71bff91d0e73c0bbf613f55f798cc5845dd11 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:43:27 +0100 Subject: [PATCH 06/67] Update routing to use new page names --- packages/builder/src/pages/[application]/index.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/pages/[application]/index.svelte b/packages/builder/src/pages/[application]/index.svelte index 4b5dbb6a3e..553908cb2e 100644 --- a/packages/builder/src/pages/[application]/index.svelte +++ b/packages/builder/src/pages/[application]/index.svelte @@ -1,6 +1,6 @@ From 45b86353d2a247bed8c41fa4f55721e159b17646 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:43:52 +0100 Subject: [PATCH 07/67] Improve styles of frontend component blocks --- .../src/components/userInterface/ItemTab/Item.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/userInterface/ItemTab/Item.svelte b/packages/builder/src/components/userInterface/ItemTab/Item.svelte index de04bc5208..ce4f602f03 100644 --- a/packages/builder/src/components/userInterface/ItemTab/Item.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Item.svelte @@ -20,6 +20,7 @@ border-radius: 5px; width: 120px; height: 80px; + color: var(--grey-7); } .item-item:hover { @@ -35,16 +36,16 @@ .item-text { display: flex; flex-direction: column; + margin-top: 5px; } .item-name { - font-size: 14px; - font-weight: 400; + font-size: 12px; + font-weight: 500; text-align: center; } i { font-size: 24px; - color: var(--grey-7); } From 664aacd402cc6f2be9fa6d210a62cbdc7240ca08 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:44:17 +0100 Subject: [PATCH 08/67] Fix top right settings icon styles --- .../src/components/settings/Link.svelte | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/builder/src/components/settings/Link.svelte b/packages/builder/src/components/settings/Link.svelte index 3bb6d6e40d..f28dbae038 100644 --- a/packages/builder/src/components/settings/Link.svelte +++ b/packages/builder/src/components/settings/Link.svelte @@ -1,32 +1,36 @@ - - - +
+ +
From 79cca1956abace23b46760994703b3d58ed17b38 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:44:45 +0100 Subject: [PATCH 09/67] Make OptionSelect styles in line with other components --- .../userInterface/OptionSelect.svelte | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/userInterface/OptionSelect.svelte b/packages/builder/src/components/userInterface/OptionSelect.svelte index aac5c44c07..1c3ee89213 100644 --- a/packages/builder/src/components/userInterface/OptionSelect.svelte +++ b/packages/builder/src/components/userInterface/OptionSelect.svelte @@ -6,13 +6,14 @@ export let options = [] export let value = "" export let styleBindingProperty - export let onChange = value => {} + export let onChange = (value) => {} let open = null let rotate = "" let select let selectMenu let icon + let width = 0 let selectAnchor = null let dimensions = { top: 0, bottom: 0, left: 0 } @@ -22,7 +23,7 @@ let scrollTop = 0 let containerEl = null - const handleStyleBind = value => + const handleStyleBind = (value) => !!styleBindingProperty ? { style: `${styleBindingProperty}: ${value}` } : {} onMount(() => { @@ -91,12 +92,13 @@ "transform-origin": `center ${positionSide}`, [positionSide]: `${dimensions[positionSide]}px`, left: `${dimensions.left.toFixed(0)}px`, + width: `${width}px`, }) - $: isOptionsObject = options.every(o => typeof o === "object") + $: isOptionsObject = options.every((o) => typeof o === "object") $: selectedOption = isOptionsObject - ? options.find(o => o.value === value) + ? options.find((o) => o.value === value) : {} $: if (open && selectMenu) { @@ -108,6 +110,7 @@
span { color: var(--ink); font-weight: 400; - width: 140px; overflow-x: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: var(--font-size-xs); + flex: 1 1 auto; } .bb-select-anchor > i { @@ -208,7 +212,6 @@ box-sizing: border-box; flex-direction: column; opacity: 0; - width: 160px; z-index: 2; color: var(--ink); font-weight: 400; @@ -237,7 +240,7 @@ padding: 5px 0px; cursor: pointer; padding-left: 10px; - font-size: var(--font-size-s); + font-size: var(--font-size-xs); } li:hover { From 1fac774521470ee0ed21e8f41b19cdbda1626134 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 17:46:21 +0100 Subject: [PATCH 10/67] Move components to above app preview --- .../ComponentSelectionList.svelte | 48 ++++++++++++------- .../pages/[application]/design/_layout.svelte | 17 ++++--- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte index 404cfa102b..463c8ea448 100644 --- a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte +++ b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte @@ -9,15 +9,22 @@ import Tab from "./ItemTab/Tab.svelte" const categories = components.categories - let selectedIndex + let selectedCategory let width - $: selectedCategory = selectedIndex == null ? null : categories[selectedIndex] const close = () => { - selectedIndex = null + selectedCategory = null } - const onComponentChosen = component => { + const onCategoryChosen = (category) => { + if (category.isCategory) { + selectedCategory = selectedCategory === category ? null : category + } else { + onComponentChosen(category) + } + } + + const onComponentChosen = (component) => { store.addChildComponent(component._component, component.presetProps) // Get ID path @@ -33,14 +40,15 @@
+ class:open={selectedCategory != null}> {#each categories as category, idx}
(selectedIndex = idx)} + on:click={() => onCategoryChosen(category)} class:active={selectedCategory === category}> - {category.name} - + {#if category.icon}{/if} + {category.name} + {#if category.isCategory}{/if}
{/each}
@@ -49,7 +57,7 @@ {/if}
@@ -61,33 +69,40 @@ } .container { - padding: var(--spacing-xl) 40px; + padding: var(--spacing-l) 40px; display: flex; flex-direction: row; justify-content: flex-start; align-items: center; background-color: white; z-index: 1; + width: calc(100% - 80px); + overflow: hidden; } - .container.border { - border-bottom: 1px solid var(--grey-2); + .container.open { } .category { - color: var(--ink); + color: var(--grey-7); cursor: pointer; - margin-right: var(--spacing-xl); + margin-right: var(--spacing-l); display: flex; flex-direction: row; justify-content: flex-start; align-items: center; gap: var(--spacing-xs); - font-size: var(--font-size-s); + font-size: var(--font-size-xs); + } + .category span { font-weight: 500; + user-select: none; } .category.active, .category:hover { - color: var(--blue); + color: var(--ink); + } + .category i:not(:last-child) { + font-size: 16px; } .overlay { @@ -107,7 +122,6 @@ width: calc(100% - 80px); background-color: white; padding: var(--spacing-xl) 40px; - border-bottom: 1px solid var(--grey-2); box-shadow: 0 0 8px 4px rgba(0, 0, 0, 0.05); } diff --git a/packages/builder/src/pages/[application]/design/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte index 420a1bd2ea..34126e3687 100644 --- a/packages/builder/src/pages/[application]/design/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/_layout.svelte @@ -32,19 +32,18 @@ settingsView.show() } - const lastPartOfName = c => (c ? last(c.split("/")) : "") + const lastPartOfName = (c) => (c ? last(c.split("/")) : "")
-
{#if $store.currentPageName && $store.currentPageName.length > 0} - +
@@ -56,7 +55,6 @@
{/if} -
@@ -64,8 +62,8 @@ diff --git a/packages/builder/src/components/userInterface/SettingsView.svelte b/packages/builder/src/components/userInterface/SettingsView.svelte index d821f1f2e2..fd4733c24e 100644 --- a/packages/builder/src/components/userInterface/SettingsView.svelte +++ b/packages/builder/src/components/userInterface/SettingsView.svelte @@ -18,7 +18,7 @@ let pageScreenProps = ["title", "favicon", "description", "route"] let duplicateName = false - const propExistsOnComponentDef = prop => + const propExistsOnComponentDef = (prop) => pageScreenProps.includes(prop) || prop in componentDefinition.props function handleChange(key, data) { @@ -47,10 +47,10 @@ $: isPage = screenOrPageInstance && screenOrPageInstance.favicon $: screenOrPageDefinition = isPage ? pageDefinition : screenDefinition - const isDuplicateName = name => { + const isDuplicateName = (name) => { let duplicate = false - const lookForDuplicate = rootPops => { + const lookForDuplicate = (rootPops) => { walkProps(rootPops, (inst, cancel) => { if (inst._instanceName === name && inst._id !== componentInstance._id) { duplicate = true @@ -85,50 +85,60 @@ } -{#if screenOrPageInstance} - {#each screenOrPageDefinition as def} - - {/each} -{/if} - -{#if displayNameField} - - {#if duplicateName} - Name must be unique - {/if} -{/if} - -{#if panelDefinition && panelDefinition.length > 0} - {#each panelDefinition as definition} - {#if canRenderControl(definition.key, definition.dependsOn)} +
+ {#if screenOrPageInstance} + {#each screenOrPageDefinition as def} + bindable={false} + control={def.control} + label={def.label} + key={def.key} + value={screenOrPageInstance[def.key]} + onChange={onScreenPropChange} + props={{ ...excludeProps(def, ['control', 'label']) }} /> + {/each} + {/if} + + {#if displayNameField} + + {#if duplicateName} + Name must be unique {/if} - {/each} -{:else} -
This component does not have any settings.
-{/if} + {/if} + + {#if panelDefinition && panelDefinition.length > 0} + {#each panelDefinition as definition} + {#if canRenderControl(definition.key, definition.dependsOn)} + + {/if} + {/each} + {:else} +
This component does not have any settings.
+ {/if} +
From 62da83e27f6b873d851c5ecc5900017f37822ad4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 18:12:15 +0100 Subject: [PATCH 15/67] Adjust screen list column padding to line up with top components bar --- packages/builder/src/pages/[application]/design/_layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/pages/[application]/design/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte index 34126e3687..132aa5552d 100644 --- a/packages/builder/src/pages/[application]/design/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/_layout.svelte @@ -74,7 +74,7 @@ display: flex; flex-direction: column; gap: var(--spacing-m); - padding: var(--spacing-xl); + padding: var(--spacing-l) var(--spacing-xl); overflow-y: auto; border-right: 1px solid var(--grey-2); } From 1c149d7d5c1b11152e668b661023e04886dcfe4e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 18:12:40 +0100 Subject: [PATCH 16/67] Move large create screen button to icon --- .../userInterface/FrontendNavigatePane.svelte | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte index 651cc5c6ac..cf53af2dd5 100644 --- a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte +++ b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte @@ -4,20 +4,41 @@ import PageLayout from "components/userInterface/PageLayout.svelte" import PagesList from "components/userInterface/PagesList.svelte" import NewScreenModal from "components/userInterface/NewScreenModal.svelte" - import { Button, Spacer, Modal, Heading } from "@budibase/bbui" + import { Modal } from "@budibase/bbui" let modal -Screens +
+

Screens

+ +
- - - + + From 5d266c5877461dd0001e3180455c717aba201ce8 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 18:14:29 +0100 Subject: [PATCH 17/67] Fix issue displaying opened status of screens --- .../src/components/userInterface/ComponentsHierarchy.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte index 43a2c07bd9..dae80cf1e7 100644 --- a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte @@ -44,7 +44,7 @@ text={screen.props._instanceName} withArrow={screen.props._children.length} selected={$store.currentComponentInfo._id === screen.props._id} - opened={$store.currentPreviewItem.name !== screen.props._id} + opened={$store.currentPreviewItem.name === screen.props._id} on:click={() => changeScreen(screen)}>
From af19158fb64e870b377fca3f9439cdb569fac931 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 18:14:44 +0100 Subject: [PATCH 18/67] Adjust page button background to be consistent --- packages/builder/src/components/userInterface/PagesList.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/userInterface/PagesList.svelte b/packages/builder/src/components/userInterface/PagesList.svelte index 4cb1f7781b..13351c94e4 100644 --- a/packages/builder/src/components/userInterface/PagesList.svelte +++ b/packages/builder/src/components/userInterface/PagesList.svelte @@ -59,7 +59,7 @@ } .active { - background: var(--grey-3); + background: var(--grey-2); color: var(--ink); } From f56662dac4de22613b60253031a3b44ae38f570b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 18:23:11 +0100 Subject: [PATCH 19/67] Update FlatButton and CategoryTab styles --- .../components/userInterface/CategoryTab.svelte | 6 +++--- .../userInterface/ComponentPropertiesPanel.svelte | 2 +- .../components/userInterface/FlatButton.svelte | 15 +++++++-------- .../src/pages/[application]/design/_layout.svelte | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/builder/src/components/userInterface/CategoryTab.svelte b/packages/builder/src/components/userInterface/CategoryTab.svelte index 15335cbb87..3b5dce84e0 100644 --- a/packages/builder/src/components/userInterface/CategoryTab.svelte +++ b/packages/builder/src/components/userInterface/CategoryTab.svelte @@ -1,7 +1,7 @@
@@ -19,8 +19,8 @@ .tabs { display: flex; list-style: none; - font-size: 18px; - font-weight: 600; + font-size: var(--font-size-m); + font-weight: 500; } li { diff --git a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte index dead297956..7b1c794610 100644 --- a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte +++ b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte @@ -107,7 +107,7 @@ } .instance-name { - font-size: 14px; + font-size: var(--font-size-xs); font-weight: 500; color: var(--grey-7); } diff --git a/packages/builder/src/components/userInterface/FlatButton.svelte b/packages/builder/src/components/userInterface/FlatButton.svelte index f27a2902ee..3ae8eebca3 100644 --- a/packages/builder/src/components/userInterface/FlatButton.svelte +++ b/packages/builder/src/components/userInterface/FlatButton.svelte @@ -3,7 +3,7 @@ export let value = "" export let text = "" export let icon = "" - export let onClick = value => {} + export let onClick = (value) => {} export let selected = false $: useIcon = !!icon @@ -22,23 +22,22 @@ diff --git a/packages/builder/src/components/userInterface/ItemTab/Item.svelte b/packages/builder/src/components/userInterface/ItemTab/Item.svelte index ce4f602f03..e5a67118e9 100644 --- a/packages/builder/src/components/userInterface/ItemTab/Item.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Item.svelte @@ -12,20 +12,16 @@ diff --git a/packages/builder/src/components/userInterface/ItemTab/Tab.svelte b/packages/builder/src/components/userInterface/ItemTab/Tab.svelte index db16acf3d6..4e3aacb9c4 100644 --- a/packages/builder/src/components/userInterface/ItemTab/Tab.svelte +++ b/packages/builder/src/components/userInterface/ItemTab/Tab.svelte @@ -9,7 +9,7 @@ let category = list - const handleClick = item => { + const handleClick = (item) => { if (item.children && item.children.length > 0) { list = item } else { @@ -53,10 +53,12 @@ .list { display: flex; - flex-direction: row; + flex-direction: column; justify-content: flex-start; - align-items: center; - gap: var(--spacing-m); + align-items: stretch; + gap: var(--spacing-s); flex-wrap: wrap; + padding: var(--spacing-l); + min-width: 120px; } diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js index 78258e99f3..1c4bc632a6 100644 --- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js +++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js @@ -631,7 +631,7 @@ export default { }, }, { - name: "Groupedbar", + name: "Grouped Bar", _component: "@budibase/standard-components/groupedbar", description: "Groupedbar chart", icon: "ri-bar-chart-grouped-fill", diff --git a/packages/builder/src/pages/[application]/design/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte index 7bd37902ad..529d97949c 100644 --- a/packages/builder/src/pages/[application]/design/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/_layout.svelte @@ -73,7 +73,7 @@ background-color: var(--white); display: flex; flex-direction: column; - gap: var(--spacing-m); + gap: var(--spacing-l); padding: var(--spacing-l) var(--spacing-xl); overflow-y: auto; border-right: 1px solid var(--grey-2); @@ -86,13 +86,13 @@ flex-direction: column; justify-content: flex-start; align-items: stretch; - gap: var(--spacing-m); + gap: var(--spacing-l); + padding: var(--spacing-l) 40px var(--spacing-xl) 40px; } .preview-content { background: #fff; box-shadow: 0 0 12px rgba(0, 0, 0, 0.05); flex: 1 1 auto; - margin: var(--spacing-xl) 40px; } .components-pane { From 5077f4f435862e5274d129cd2922bacef8daa695 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 22 Oct 2020 20:48:46 +0100 Subject: [PATCH 21/67] Fix property group name font size until a proper fix in BBUI --- .../builder/src/components/userInterface/DesignView.svelte | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/builder/src/components/userInterface/DesignView.svelte b/packages/builder/src/components/userInterface/DesignView.svelte index 34f734ced9..3449ef4816 100644 --- a/packages/builder/src/components/userInterface/DesignView.svelte +++ b/packages/builder/src/components/userInterface/DesignView.svelte @@ -63,6 +63,12 @@ height: 100%; gap: var(--spacing-m); } + .design-view-container :global(.property-group-name .name) { + font-size: var(--font-size-xs); + } + .design-view-container :global(.property-group-container) { + padding: 4px 0; + } .design-view-state-categories { } From 3b869d2ff43e397aa77d417f7c6c95416fc0a9a2 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 10:33:43 +0100 Subject: [PATCH 22/67] Bump BBUI version --- packages/builder/package.json | 2 +- packages/builder/yarn.lock | 259 +--------------------- packages/standard-components/package.json | 2 +- 3 files changed, 10 insertions(+), 253 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index 12067716e9..25c0f9aa4a 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -63,7 +63,7 @@ } }, "dependencies": { - "@budibase/bbui": "^1.44.1", + "@budibase/bbui": "^1.46.0", "@budibase/client": "^0.2.6", "@budibase/colorpicker": "^1.0.1", "@fortawesome/fontawesome-free": "^5.14.0", diff --git a/packages/builder/yarn.lock b/packages/builder/yarn.lock index 5eca5c2364..46c15a2aa3 100644 --- a/packages/builder/yarn.lock +++ b/packages/builder/yarn.lock @@ -709,24 +709,15 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" -"@budibase/bbui@^1.44.1": - version "1.44.1" - resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.44.1.tgz#1bfca2d3a40a14eb0ba136e24afb7139694b4970" - integrity sha512-joFH++mzFJZkMR3ZSv8Q8cE/qNn8o8aZGbHeO57Smiai3h2tjeTyVLuJ+yt3P1XQ8SE13epAp38kvsPosUpbkQ== +"@budibase/bbui@^1.46.0": + version "1.46.0" + resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.46.0.tgz#cfff5ec545a81582e16555c45987f86536b5cc99" + integrity sha512-seuaLSA6iDOzJ3eO0oHzSCTdS1otyNz+8eD5vTLW4bwRH9MZ/xl363acMQDdiCqZk619+WeSqb85fmFTTSJHNQ== dependencies: sirv-cli "^0.4.6" svelte-flatpickr "^2.4.0" svelte-portal "^1.0.0" -"@budibase/client@^0.2.4": - version "0.2.4" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.2.4.tgz#da958faa50c59f6a9c41c692b7a19d6a6ea98bc1" - integrity sha512-MsFbWcsh3t1lyLgTb4UMccjshy6jd3A77lqs1CpXjHr+2LmXwvIriLgruycAvFrtqZzYG+dGe0rWwX0auwaaZw== - dependencies: - deep-equal "^2.0.1" - mustache "^4.0.1" - regexparam "^1.3.0" - "@budibase/colorpicker@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@budibase/colorpicker/-/colorpicker-1.0.1.tgz#940c180e7ebba0cb0756c4c8ef13f5dfab58e810" @@ -1403,11 +1394,6 @@ array-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" -array-filter@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-1.0.0.tgz#baf79e62e6ef4c2a4c0b831232daffec251f9d83" - integrity sha1-uveeYubvTCpMC4MSMtr/7CUfnYM= - array-union@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" @@ -1462,13 +1448,6 @@ atob@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" -available-typed-arrays@^1.0.0, available-typed-arrays@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz#6b098ca9d8039079ee3f77f7b783c4480ba513f5" - integrity sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ== - dependencies: - array-filter "^1.0.0" - aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" @@ -2418,26 +2397,6 @@ decode-uri-component@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" -deep-equal@^2.0.1: - version "2.0.4" - resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.0.4.tgz#6b0b407a074666033169df3acaf128e1c6f3eab6" - integrity sha512-BUfaXrVoCfgkOQY/b09QdO9L3XNoF2XH0A3aY9IQwQL/ZjLOe8FQgCNVl1wiolhsFo8kFdO9zdPViCPbmaJA5w== - dependencies: - es-abstract "^1.18.0-next.1" - es-get-iterator "^1.1.0" - is-arguments "^1.0.4" - is-date-object "^1.0.2" - is-regex "^1.1.1" - isarray "^2.0.5" - object-is "^1.1.3" - object-keys "^1.1.1" - object.assign "^4.1.1" - regexp.prototype.flags "^1.3.0" - side-channel "^1.0.3" - which-boxed-primitive "^1.0.1" - which-collection "^1.0.1" - which-typed-array "^1.1.2" - deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -2607,54 +2566,6 @@ es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5: string.prototype.trimleft "^2.1.1" string.prototype.trimright "^2.1.1" -es-abstract@^1.17.4: - version "1.17.7" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c" - integrity sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g== - dependencies: - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-regex "^1.1.1" - object-inspect "^1.8.0" - object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" - -es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: - version "1.18.0-next.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" - integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== - dependencies: - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-negative-zero "^2.0.0" - is-regex "^1.1.1" - object-inspect "^1.8.0" - object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" - -es-get-iterator@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/es-get-iterator/-/es-get-iterator-1.1.0.tgz#bb98ad9d6d63b31aacdc8f89d5d0ee57bcb5b4c8" - integrity sha512-UfrmHuWQlNMTs35e1ypnvikg6jCz3SK8v8ImvmDsh36fCVUR1MqoFDiyn0/k52C8NqO3YsO8Oe0azeesNuqSsQ== - dependencies: - es-abstract "^1.17.4" - has-symbols "^1.0.1" - is-arguments "^1.0.4" - is-map "^2.0.1" - is-set "^2.0.1" - is-string "^1.0.5" - isarray "^2.0.5" - es-to-primitive@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" @@ -2961,7 +2872,7 @@ for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" -foreach@^2.0.5, foreach@~2.0.1: +foreach@~2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" integrity sha1-C+4AUBiusmDQo6865ljdATbsG5k= @@ -3335,31 +3246,16 @@ is-accessor-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-arguments@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.0.4.tgz#3faf966c7cba0ff437fb31f6250082fcf0448cf3" - integrity sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA== - is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" -is-bigint@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.0.tgz#73da8c33208d00f130e9b5e15d23eac9215601c4" - integrity sha512-t5mGUXC/xRheCK431ylNiSkGGpBp8bHENBcENTkDT6ppwPzEVxNGZRvgvmOEfbWkFhA7D2GEuE2mmQTr78sl2g== - is-binary-path@~2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" dependencies: binary-extensions "^2.0.0" -is-boolean-object@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.0.1.tgz#10edc0900dd127697a92f6f9807c7617d68ac48e" - integrity sha512-TqZuVwa/sppcrhUCAYkGBk7w0yxfQQnxq28fjkO53tnK9FQXmdwz2JS5+GjsWQ6RByES1K40nI+yDic5c9/aAQ== - is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" @@ -3368,11 +3264,6 @@ is-callable@^1.1.4, is-callable@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.5.tgz#f7e46b596890456db74e7f6e976cb3273d06faab" -is-callable@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9" - integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA== - is-ci@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" @@ -3391,7 +3282,7 @@ is-data-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-date-object@^1.0.1, is-date-object@^1.0.2: +is-date-object@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.2.tgz#bda736f2cd8fd06d32844e7743bfa7494c3bfd7e" @@ -3456,25 +3347,10 @@ is-installed-globally@^0.3.2: global-dirs "^2.0.1" is-path-inside "^3.0.1" -is-map@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.1.tgz#520dafc4307bb8ebc33b813de5ce7c9400d644a1" - integrity sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw== - is-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" -is-negative-zero@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.0.tgz#9553b121b0fac28869da9ed459e20c7543788461" - integrity sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE= - -is-number-object@^1.0.3: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.4.tgz#36ac95e741cf18b283fc1ddf5e83da798e3ec197" - integrity sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw== - is-number@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -3531,18 +3407,6 @@ is-regex@^1.0.5: dependencies: has "^1.0.3" -is-regex@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.1.tgz#c6f98aacc546f6cec5468a07b7b153ab564a57b9" - integrity sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg== - dependencies: - has-symbols "^1.0.1" - -is-set@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.1.tgz#d1604afdab1724986d30091575f54945da7e5f43" - integrity sha512-eJEzOtVyenDs1TMzSQ3kU3K+E0GUS9sno+F0OBT97xsgcJsF9nXMBtkT9/kut5JEpM7oL7X/0qxR17K3mcwIAA== - is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -3551,41 +3415,16 @@ is-stream@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" -is-string@^1.0.4, is-string@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6" - integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ== - is-symbol@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.3.tgz#38e1014b9e6329be0de9d24a414fd7441ec61937" dependencies: has-symbols "^1.0.1" -is-typed-array@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.3.tgz#a4ff5a5e672e1a55f99c7f54e59597af5c1df04d" - integrity sha512-BSYUBOK/HJibQ30wWkWold5txYwMUXQct9YHAQJr8fSwvZoiglcqB0pd7vEN23+Tsi9IUEjztdOSzl4qLVYGTQ== - dependencies: - available-typed-arrays "^1.0.0" - es-abstract "^1.17.4" - foreach "^2.0.5" - has-symbols "^1.0.1" - is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" -is-weakmap@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.1.tgz#5008b59bdc43b698201d18f62b37b2ca243e8cf2" - integrity sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA== - -is-weakset@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-weakset/-/is-weakset-2.0.1.tgz#e9a0af88dbd751589f5e50d80f4c98b780884f83" - integrity sha512-pi4vhbhVHGLxohUw7PhGsueT4vRGFoXhP7+RGN0jKIv9+8PWYCQTqtADngrxOm2g46hoH0+g8uZZBzMrvVGDmw== - is-windows@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" @@ -3606,11 +3445,6 @@ isarray@1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" -isarray@^2.0.5: - version "2.0.5" - resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" - integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw== - isbuffer@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/isbuffer/-/isbuffer-0.0.0.tgz#38c146d9df528b8bf9b0701c3d43cf12df3fc39b" @@ -4730,19 +4564,6 @@ object-inspect@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.7.0.tgz#f4f6bd181ad77f006b5ece60bd0b6f398ff74a67" -object-inspect@^1.8.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.8.0.tgz#df807e5ecf53a609cc6bfe93eac3cc7be5b3a9d0" - integrity sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA== - -object-is@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.3.tgz#2e3b9e65560137455ee3bd62aec4d90a2ea1cc81" - integrity sha512-teyqLvFWzLkq5B9ki8FVWA902UER2qkxmdA4nLf+wjOLAWgxzCWZNCxpDq9MvE8MmhWNr+I8w3BN49Vx36Y6Xg== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" - object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" @@ -4774,16 +4595,6 @@ object.assign@^4.1.0: has-symbols "^1.0.0" object-keys "^1.0.11" -object.assign@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.1.tgz#303867a666cdd41936ecdedfb1f8f3e32a478cdd" - integrity sha512-VT/cxmx5yaoHSOTSyrCygIDFco+RsibY2NM0a4RdEeY/4KgqezwFtK1yr3U67xYhqJSlASm2pKhLVzPj2lr4bA== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.0" - has-symbols "^1.0.1" - object-keys "^1.1.1" - object.getownpropertydescriptors@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz#369bf1f9592d8ab89d712dced5cb81c7c5352649" @@ -5264,19 +5075,6 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexp.prototype.flags@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz#7aba89b3c13a64509dabcf3ca8d9fbb9bdf5cb75" - integrity sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.17.0-next.1" - -regexparam@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-1.3.0.tgz#2fe42c93e32a40eff6235d635e0ffa344b92965f" - integrity sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g== - regexpu-core@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.7.0.tgz#fcbf458c50431b0bb7b45d6967b8192d91f3d938" @@ -5684,14 +5482,6 @@ shortid@^2.2.15: dependencies: nanoid "^2.1.0" -side-channel@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.3.tgz#cdc46b057550bbab63706210838df5d4c19519c3" - integrity sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g== - dependencies: - es-abstract "^1.18.0-next.0" - object-inspect "^1.8.0" - signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" @@ -5918,7 +5708,7 @@ string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" -string.prototype.trimend@^1.0.0, string.prototype.trimend@^1.0.1: +string.prototype.trimend@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz#85812a6b847ac002270f5808146064c995fb6913" dependencies: @@ -5941,7 +5731,7 @@ string.prototype.trimright@^2.1.1: es-abstract "^1.17.5" string.prototype.trimend "^1.0.0" -string.prototype.trimstart@^1.0.0, string.prototype.trimstart@^1.0.1: +string.prototype.trimstart@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz#14af6d9f34b053f7cfc89b72f8f2ee14b9039a54" dependencies: @@ -6397,43 +6187,10 @@ whatwg-url@^8.0.0: tr46 "^2.0.2" webidl-conversions "^5.0.0" -which-boxed-primitive@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz#cbe8f838ebe91ba2471bb69e9edbda67ab5a5ec1" - integrity sha512-7BT4TwISdDGBgaemWU0N0OU7FeAEJ9Oo2P1PHRm/FCWoEi2VLWC9b6xvxAA3C/NMpxg3HXVgi0sMmGbNUbNepQ== - dependencies: - is-bigint "^1.0.0" - is-boolean-object "^1.0.0" - is-number-object "^1.0.3" - is-string "^1.0.4" - is-symbol "^1.0.2" - -which-collection@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/which-collection/-/which-collection-1.0.1.tgz#70eab71ebbbd2aefaf32f917082fc62cdcb70906" - integrity sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A== - dependencies: - is-map "^2.0.1" - is-set "^2.0.1" - is-weakmap "^2.0.1" - is-weakset "^2.0.1" - which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" -which-typed-array@^1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.2.tgz#e5f98e56bda93e3dac196b01d47c1156679c00b2" - integrity sha512-KT6okrd1tE6JdZAy3o2VhMoYPh3+J6EMZLyrxBQsZflI1QCZIxMrIYLkosd8Twf+YfknVIHmYQPgJt238p8dnQ== - dependencies: - available-typed-arrays "^1.0.2" - es-abstract "^1.17.5" - foreach "^2.0.5" - function-bind "^1.1.1" - has-symbols "^1.0.1" - is-typed-array "^1.1.3" - which@^1.2.9, which@^1.3.0: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index c7261f319f..13f3e167a9 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -36,7 +36,7 @@ "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "dependencies": { "@beyonk/svelte-googlemaps": "^2.2.0", - "@budibase/bbui": "^1.44.1", + "@budibase/bbui": "^1.46.0", "@budibase/svelte-ag-grid": "^0.0.13", "@fortawesome/fontawesome-free": "^5.14.0", "@svelteschool/svelte-forms": "^0.7.0", From 4e4aa5c525282051f8451f27658231e9a49a344c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 10:34:14 +0100 Subject: [PATCH 23/67] Standardise sizing of all settings and design properties --- .../userInterface/DesignView.svelte | 19 +- .../userInterface/DetailScreenSelect.svelte | 12 +- .../IconSelect/IconSelect.svelte | 582 +++++++++--------- .../userInterface/OptionSelect.svelte | 2 +- .../userInterface/PropertyControl.svelte | 2 +- .../userInterface/PropertyGroup.svelte | 3 +- .../PropertyPanelControls/Input.svelte | 2 +- .../userInterface/ScreenSelect.svelte | 182 +++--- .../userInterface/SettingsView.svelte | 8 +- .../userInterface/TableSelect.svelte | 2 +- .../userInterface/TableViewSelect.svelte | 326 +++++----- 11 files changed, 576 insertions(+), 564 deletions(-) diff --git a/packages/builder/src/components/userInterface/DesignView.svelte b/packages/builder/src/components/userInterface/DesignView.svelte index 3449ef4816..989eaef53b 100644 --- a/packages/builder/src/components/userInterface/DesignView.svelte +++ b/packages/builder/src/components/userInterface/DesignView.svelte @@ -48,7 +48,7 @@ {/each} {:else}
- This component does not have any design properties. + This component doesn't have any design properties.
{/if}
@@ -61,13 +61,7 @@ flex-direction: column; width: 100%; height: 100%; - gap: var(--spacing-m); - } - .design-view-container :global(.property-group-name .name) { - font-size: var(--font-size-xs); - } - .design-view-container :global(.property-group-container) { - padding: 4px 0; + gap: var(--spacing-l); } .design-view-state-categories { @@ -85,10 +79,15 @@ min-height: 0; margin: 0 -20px; padding: 0 20px; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: stretch; + gap: var(--spacing-m); } .no-design { - font-size: var(--font-size-s); - color: var(--grey-6); + font-size: var(--font-size-xs); + color: var(--grey-5); } diff --git a/packages/builder/src/components/userInterface/DetailScreenSelect.svelte b/packages/builder/src/components/userInterface/DetailScreenSelect.svelte index 1e2908ab54..6928a72e9d 100644 --- a/packages/builder/src/components/userInterface/DetailScreenSelect.svelte +++ b/packages/builder/src/components/userInterface/DetailScreenSelect.svelte @@ -15,11 +15,11 @@ return [ ...$store.screens .filter( - screen => + (screen) => screen.props._component.endsWith("/rowdetail") || screen.route.endsWith(":id") ) - .map(screen => ({ + .map((screen) => ({ name: screen.props._instanceName, url: screen.route, sort: screen.props._component, @@ -29,7 +29,13 @@
- + diff --git a/packages/builder/src/components/userInterface/IconSelect/IconSelect.svelte b/packages/builder/src/components/userInterface/IconSelect/IconSelect.svelte index 6141702439..9fac2642d7 100644 --- a/packages/builder/src/components/userInterface/IconSelect/IconSelect.svelte +++ b/packages/builder/src/components/userInterface/IconSelect/IconSelect.svelte @@ -1,291 +1,291 @@ - - -
- -
- -
-
-
- {#each alphabet as letter, idx} - switchLetter(letter)}> - {letter} - - {#if idx !== alphabet.length - 1}-{/if} - {/each} -
-
-
- -
- -
-
-
- pageClick(false)}> - - - {pagerText} - pageClick(true)}> - - -
-
-
- {#if pagedIcons.length > 0} -
- {#if !loading} - {#each pagedIcons as icon} -
(value = icon.value)}> -
- -
-
{icon.label}
-
- {/each} - {/if} -
- {:else} -
-
- {`There is no icons for this ${searchTerm ? 'search' : 'page'}`} -
-
- {/if} -
-
- - + + +
+ +
+ +
+
+
+ {#each alphabet as letter, idx} + switchLetter(letter)}> + {letter} + + {#if idx !== alphabet.length - 1}-{/if} + {/each} +
+
+
+ +
+ +
+
+
+ pageClick(false)}> + + + {pagerText} + pageClick(true)}> + + +
+
+
+ {#if pagedIcons.length > 0} +
+ {#if !loading} + {#each pagedIcons as icon} +
(value = icon.value)}> +
+ +
+
{icon.label}
+
+ {/each} + {/if} +
+ {:else} +
+
+ {`There is no icons for this ${searchTerm ? 'search' : 'page'}`} +
+
+ {/if} +
+
+ + diff --git a/packages/builder/src/components/userInterface/OptionSelect.svelte b/packages/builder/src/components/userInterface/OptionSelect.svelte index 1c3ee89213..d1fbfecff7 100644 --- a/packages/builder/src/components/userInterface/OptionSelect.svelte +++ b/packages/builder/src/components/userInterface/OptionSelect.svelte @@ -175,7 +175,7 @@ .bb-select-anchor { cursor: pointer; display: flex; - padding: var(--spacing-m); + padding: var(--spacing-s) var(--spacing-m); background-color: var(--grey-2); border-radius: var(--border-radius-m); align-items: center; diff --git a/packages/builder/src/components/userInterface/PropertyControl.svelte b/packages/builder/src/components/userInterface/PropertyControl.svelte index c11ec6a0cb..e47d5e17a3 100644 --- a/packages/builder/src/components/userInterface/PropertyControl.svelte +++ b/packages/builder/src/components/userInterface/PropertyControl.svelte @@ -147,7 +147,7 @@ height: 90%; width: 2rem; background: var(--grey-2); - right: 10px; + right: 4px; --spacing-s: 0; border-left: 0.5px solid var(--grey-3); outline-color: var(--blue); diff --git a/packages/builder/src/components/userInterface/PropertyGroup.svelte b/packages/builder/src/components/userInterface/PropertyGroup.svelte index 37b7a11ea2..2fb304f5c8 100644 --- a/packages/builder/src/components/userInterface/PropertyGroup.svelte +++ b/packages/builder/src/components/userInterface/PropertyGroup.svelte @@ -13,7 +13,7 @@ $: style = componentInstance["_styles"][styleCategory] || {} - +
{#each properties as props} diff --git a/packages/builder/src/components/userInterface/PropertyPanelControls/Input.svelte b/packages/builder/src/components/userInterface/PropertyPanelControls/Input.svelte index 1721c1bbb2..3abdb3ecd3 100644 --- a/packages/builder/src/components/userInterface/PropertyPanelControls/Input.svelte +++ b/packages/builder/src/components/userInterface/PropertyPanelControls/Input.svelte @@ -8,4 +8,4 @@ export let name, value, placeholder, type - + diff --git a/packages/builder/src/components/userInterface/ScreenSelect.svelte b/packages/builder/src/components/userInterface/ScreenSelect.svelte index 33174355bb..fb2a24a94e 100644 --- a/packages/builder/src/components/userInterface/ScreenSelect.svelte +++ b/packages/builder/src/components/userInterface/ScreenSelect.svelte @@ -1,88 +1,94 @@ - - -
- - - {/each} - -
- - + + +
+ + + {/each} + +
+ + diff --git a/packages/builder/src/components/userInterface/SettingsView.svelte b/packages/builder/src/components/userInterface/SettingsView.svelte index fd4733c24e..be07eebcea 100644 --- a/packages/builder/src/components/userInterface/SettingsView.svelte +++ b/packages/builder/src/components/userInterface/SettingsView.svelte @@ -125,7 +125,9 @@ {/if} {/each} {:else} -
This component does not have any settings.
+
+ This component doesn't have any additional settings. +
{/if}
@@ -139,9 +141,9 @@ } .empty { - font-size: var(--font-size-s); + font-size: var(--font-size-xs); margin-top: var(--spacing-m); - color: var(--grey-6); + color: var(--grey-5); } .duplicate-name { diff --git a/packages/builder/src/components/userInterface/TableSelect.svelte b/packages/builder/src/components/userInterface/TableSelect.svelte index 6300aa2d61..d72b6031f1 100644 --- a/packages/builder/src/components/userInterface/TableSelect.svelte +++ b/packages/builder/src/components/userInterface/TableSelect.svelte @@ -6,7 +6,7 @@
- {#each $backendUiStore.tables as table} diff --git a/packages/builder/src/components/userInterface/TableViewSelect.svelte b/packages/builder/src/components/userInterface/TableViewSelect.svelte index f38fcc0a72..8adfaaf2a0 100644 --- a/packages/builder/src/components/userInterface/TableViewSelect.svelte +++ b/packages/builder/src/components/userInterface/TableViewSelect.svelte @@ -1,163 +1,163 @@ - - - - - - - - + + + + + + + + From 767846e4c492858c89ea469deae5af81586c0099 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 10:37:28 +0100 Subject: [PATCH 24/67] Add selected styles to component dropdowns --- .../userInterface/ComponentSelectionList.svelte | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte index 617b90edcc..59bf7548e1 100644 --- a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte +++ b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte @@ -12,7 +12,6 @@ $: anchor = selectedIndex === -1 ? null : anchors[selectedIndex] const close = () => { - selectedIndex = null popover.hide() } @@ -38,14 +37,19 @@
onCategoryChosen(category, idx)}> + on:click={() => onCategoryChosen(category, idx)} + class:active={idx === selectedIndex}> {#if category.icon}{/if} {category.name} {#if category.isCategory}{/if}
{/each}
- + (selectedIndex = null)} + bind:this={popover} + {anchor} + align="left"> onComponentChosen(e.detail)} /> @@ -76,6 +80,7 @@ font-weight: 500; user-select: none; } + .category.active, .category:hover { color: var(--ink); } From 5009a3975c2a1c1ce15d8982095c2e364248f15a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 10:55:12 +0100 Subject: [PATCH 25/67] Improve component dropdown responsiveness --- .../components/userInterface/ComponentSelectionList.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte index 59bf7548e1..6f9931f0b0 100644 --- a/packages/builder/src/components/userInterface/ComponentSelectionList.svelte +++ b/packages/builder/src/components/userInterface/ComponentSelectionList.svelte @@ -62,13 +62,14 @@ justify-content: flex-start; align-items: center; z-index: 1; - height: 24px; + min-height: 24px; + flex-wrap: wrap; + gap: var(--spacing-l); } .category { color: var(--grey-7); cursor: pointer; - margin-right: var(--spacing-l); display: flex; flex-direction: row; justify-content: flex-start; From ea946940383855ee8149ee096adf32dc26a1a35f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 12:25:12 +0100 Subject: [PATCH 26/67] Remove deprecated borders on design page --- packages/builder/src/pages/[application]/design/_layout.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/builder/src/pages/[application]/design/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte index 529d97949c..dcf1c9b771 100644 --- a/packages/builder/src/pages/[application]/design/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/_layout.svelte @@ -76,7 +76,6 @@ gap: var(--spacing-l); padding: var(--spacing-l) var(--spacing-xl); overflow-y: auto; - border-right: 1px solid var(--grey-2); } .preview-pane { @@ -98,7 +97,6 @@ .components-pane { grid-column: 3; background-color: var(--white); - border-left: 1px solid var(--grey-2); overflow-y: auto; display: flex; flex-direction: column; From 14b13c7c52caf00ba89e13810a9bc9f3ea9e8a22 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 12:25:22 +0100 Subject: [PATCH 27/67] Update data page to use new styles --- .../components/backend/DataTable/Table.svelte | 73 +++++++------ .../TableNavigator/TableNavigator.svelte | 103 ++++++++++-------- .../modals/CreateTableModal.svelte | 54 ++++----- .../pages/[application]/data/_layout.svelte | 9 +- 4 files changed, 124 insertions(+), 115 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 7bb5ac6a18..e26b68d537 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -51,19 +51,17 @@ } -
-
-

- {title} - {#if loading} -
- -
- {/if} -

-
- -
+
+
+

{title}

+ {#if loading} +
+ +
+ {/if} +
+
+
@@ -125,20 +123,44 @@ bind:currentPage pageItemCount={paginatedData.length} {ITEMS_PER_PAGE} /> - + diff --git a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte index dd691e9e80..e77fec709f 100644 --- a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte +++ b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte @@ -2,8 +2,7 @@ import { goto } from "@sveltech/routify" import { backendUiStore, store } from "builderStore" import { notifier } from "builderStore/store/notifications" - import { Button, Input, Label, ModalContent, Modal } from "@budibase/bbui" - import Spinner from "components/common/Spinner.svelte" + import { Input, Label, ModalContent } from "@budibase/bbui" import TableDataImport from "../TableDataImport.svelte" import analytics from "analytics" import screenTemplates from "builderStore/store/screenTemplates" @@ -22,15 +21,9 @@ let dataImport let error = "" - function resetState() { - name = "" - dataImport = undefined - error = "" - } - function checkValid(evt) { const tableName = evt.target.value - if ($backendUiStore.models?.some(model => model.name === tableName)) { + if ($backendUiStore.models?.some((model) => model.name === tableName)) { error = `Table with name ${tableName} already exists. Please choose another name.` return } @@ -56,8 +49,8 @@ // Create auto screens const screens = screenTemplates($store, [table]) - .filter(template => defaultScreens.includes(template.id)) - .map(template => template.create()) + .filter((template) => defaultScreens.includes(template.id)) + .map((template) => template.create()) for (let screen of screens) { // Record the table that created this screen so we can link it later screen.autoTableId = table._id @@ -74,7 +67,7 @@ } // Create autolink to newly created list page - const listPage = screens.find(screen => + const listPage = screens.find((screen) => screen.props._instanceName.endsWith("List") ) await store.createLink(listPage.route, table.name) @@ -84,23 +77,20 @@ } - - - - -
- - -
-
-
+ + +
+ + +
+
diff --git a/packages/builder/src/pages/[application]/data/_layout.svelte b/packages/builder/src/pages/[application]/data/_layout.svelte index 1ac92b84c9..d52fdffade 100644 --- a/packages/builder/src/pages/[application]/data/_layout.svelte +++ b/packages/builder/src/pages/[application]/data/_layout.svelte @@ -18,18 +18,17 @@ .root { height: calc(100vh - 60px); display: grid; - grid-template-columns: 300px minmax(0, 1fr); - background: var(--grey-1); - line-height: 1; + grid-template-columns: 260px minmax(0, 1fr); + background: var(--grey-2); } .content { flex: 1 1 auto; - padding: var(--spacing-xl) 40px; + padding: var(--spacing-l) 40px; overflow-y: auto; } .nav { overflow-y: auto; background: var(--white); - padding: var(--spacing-xl); + padding: var(--spacing-l) var(--spacing-xl); } From 9a32997591f3bde454aaa7f5fdab6e2894d84ede Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 23 Oct 2020 12:57:35 +0100 Subject: [PATCH 28/67] Reduce unecessary div layers --- .../CreateAutomationModal.svelte | 0 .../TableNavigator/TableNavigator.svelte | 61 ++++++++----------- .../pages/[application]/data/_layout.svelte | 5 ++ 3 files changed, 31 insertions(+), 35 deletions(-) rename packages/builder/src/components/automation/AutomationPanel/{AutomationList => }/CreateAutomationModal.svelte (100%) diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationList/CreateAutomationModal.svelte b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte similarity index 100% rename from packages/builder/src/components/automation/AutomationPanel/AutomationList/CreateAutomationModal.svelte rename to packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte diff --git a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte index e521a1dfc6..0b73074e10 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte @@ -33,49 +33,40 @@ } -
- {#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id} -
-

Tables

- -
-
- {#each $backendUiStore.tables as table} +{#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id} +
+

Tables

+ +
+
+ {#each $backendUiStore.tables as table, idx} + 0} + icon="ri-table-line" + text={table.name} + selected={selectedView === `all_${table._id}`} + on:click={() => selectTable(table)}> + + + {#each Object.keys(table.views || {}) as viewName} selectTable(table)}> - + indentLevel={1} + icon="ri-eye-line" + text={viewName} + selected={selectedView === viewName} + on:click={() => onClickView(table, viewName)}> + - {#each Object.keys(table.views || {}) as viewName} - onClickView(table, viewName)}> - - - {/each} {/each} -
- {/if} -
+ {/each} +
+{/if} From 16de23eea905c33f59ae88981a53cc3c8682f985 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 26 Oct 2020 11:00:34 +0000 Subject: [PATCH 29/67] Add new common components for dropdown styles --- .../common/Dropdowns/DropdownContainer.svelte | 13 +++++ .../common/Dropdowns/DropdownItem.svelte | 57 +++++++++++++++++++ .../src/components/common/Dropdowns/index.js | 2 + 3 files changed, 72 insertions(+) create mode 100644 packages/builder/src/components/common/Dropdowns/DropdownContainer.svelte create mode 100644 packages/builder/src/components/common/Dropdowns/DropdownItem.svelte create mode 100644 packages/builder/src/components/common/Dropdowns/index.js diff --git a/packages/builder/src/components/common/Dropdowns/DropdownContainer.svelte b/packages/builder/src/components/common/Dropdowns/DropdownContainer.svelte new file mode 100644 index 0000000000..f3cea99d7b --- /dev/null +++ b/packages/builder/src/components/common/Dropdowns/DropdownContainer.svelte @@ -0,0 +1,13 @@ + + + diff --git a/packages/builder/src/components/common/Dropdowns/DropdownItem.svelte b/packages/builder/src/components/common/Dropdowns/DropdownItem.svelte new file mode 100644 index 0000000000..a94cc66e12 --- /dev/null +++ b/packages/builder/src/components/common/Dropdowns/DropdownItem.svelte @@ -0,0 +1,57 @@ + + + + + diff --git a/packages/builder/src/components/common/Dropdowns/index.js b/packages/builder/src/components/common/Dropdowns/index.js new file mode 100644 index 0000000000..a95e303ec7 --- /dev/null +++ b/packages/builder/src/components/common/Dropdowns/index.js @@ -0,0 +1,2 @@ +export { default as DropdownContainer } from "./DropdownContainer.svelte" +export { default as DropdownItem } from "./DropdownItem.svelte" From 4ff7499d2660ae31b7bb07eeeed844ebb2877518 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 26 Oct 2020 12:18:34 +0000 Subject: [PATCH 30/67] Update styles across entire automations page --- .../builderStore/store/automation/index.js | 30 ++-- .../AutomationBuilder.svelte | 84 ++------- .../AutomationBuilder/BlockList.svelte | 129 ++++++++++++++ .../{flowchart => FlowChart}/Arrow.svelte | 0 .../AutomationBlockTagline.svelte | 0 .../{flowchart => FlowChart}/FlowChart.svelte | 31 ++-- .../{flowchart => FlowChart}/FlowItem.svelte | 19 +- .../AutomationBuilder/flowchart/api.js | 0 .../AutomationBuilder/flowchart/index.js | 0 .../AutomationPanel/AutomationList.svelte | 34 ++++ .../AutomationList/AutomationList.svelte | 79 --------- .../AutomationPanel/AutomationPanel.svelte | 65 +++---- .../BlockList/AutomationBlock.svelte | 68 -------- .../BlockList/BlockList.svelte | 48 ------ .../EditAutomationPopover.svelte | 86 ++++++++++ .../automation/AutomationPanel/index.js | 3 - .../SetupPanel/AutomationBlockSetup.svelte | 66 ++++--- .../{ParamInputs => }/RowSelector.svelte | 12 +- .../automation/SetupPanel/SetupPanel.svelte | 162 +++++++----------- .../{ParamInputs => }/TableSelector.svelte | 2 +- .../components/automation/SetupPanel/index.js | 1 - .../userInterface/BindableInput.svelte | 2 +- .../[application]/automate/_layout.svelte | 30 +++- .../pages/[application]/automate/index.svelte | 2 +- .../data/table/[selectedTable]/index.svelte | 4 +- .../[application]/data/table/index.svelte | 4 +- .../data/view/[selectedView]/index.svelte | 2 +- 27 files changed, 467 insertions(+), 496 deletions(-) create mode 100644 packages/builder/src/components/automation/AutomationBuilder/BlockList.svelte rename packages/builder/src/components/automation/AutomationBuilder/{flowchart => FlowChart}/Arrow.svelte (100%) rename packages/builder/src/components/automation/AutomationBuilder/{flowchart => FlowChart}/AutomationBlockTagline.svelte (100%) rename packages/builder/src/components/automation/AutomationBuilder/{flowchart => FlowChart}/FlowChart.svelte (69%) rename packages/builder/src/components/automation/AutomationBuilder/{flowchart => FlowChart}/FlowItem.svelte (82%) delete mode 100644 packages/builder/src/components/automation/AutomationBuilder/flowchart/api.js delete mode 100644 packages/builder/src/components/automation/AutomationBuilder/flowchart/index.js create mode 100644 packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte delete mode 100644 packages/builder/src/components/automation/AutomationPanel/AutomationList/AutomationList.svelte delete mode 100644 packages/builder/src/components/automation/AutomationPanel/BlockList/AutomationBlock.svelte delete mode 100644 packages/builder/src/components/automation/AutomationPanel/BlockList/BlockList.svelte create mode 100644 packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte delete mode 100644 packages/builder/src/components/automation/AutomationPanel/index.js rename packages/builder/src/components/automation/SetupPanel/{ParamInputs => }/RowSelector.svelte (82%) rename packages/builder/src/components/automation/SetupPanel/{ParamInputs => }/TableSelector.svelte (88%) delete mode 100644 packages/builder/src/components/automation/SetupPanel/index.js diff --git a/packages/builder/src/builderStore/store/automation/index.js b/packages/builder/src/builderStore/store/automation/index.js index e1db07053e..2c1636b359 100644 --- a/packages/builder/src/builderStore/store/automation/index.js +++ b/packages/builder/src/builderStore/store/automation/index.js @@ -3,14 +3,14 @@ import api from "../../api" import Automation from "./Automation" import { cloneDeep } from "lodash/fp" -const automationActions = store => ({ +const automationActions = (store) => ({ fetch: async () => { const responses = await Promise.all([ api.get(`/api/automations`), api.get(`/api/automations/definitions/list`), ]) - const jsonResponses = await Promise.all(responses.map(x => x.json())) - store.update(state => { + const jsonResponses = await Promise.all(responses.map((x) => x.json())) + store.update((state) => { state.automations = jsonResponses[0] state.blockDefinitions = { TRIGGER: jsonResponses[1].trigger, @@ -31,7 +31,7 @@ const automationActions = store => ({ const CREATE_AUTOMATION_URL = `/api/automations` const response = await api.post(CREATE_AUTOMATION_URL, automation) const json = await response.json() - store.update(state => { + store.update((state) => { state.automations = [...state.automations, json.automation] store.actions.select(json.automation) return state @@ -41,9 +41,9 @@ const automationActions = store => ({ const UPDATE_AUTOMATION_URL = `/api/automations` const response = await api.put(UPDATE_AUTOMATION_URL, automation) const json = await response.json() - store.update(state => { + store.update((state) => { const existingIdx = state.automations.findIndex( - existing => existing._id === automation._id + (existing) => existing._id === automation._id ) state.automations.splice(existingIdx, 1, json.automation) state.automations = state.automations @@ -56,9 +56,9 @@ const automationActions = store => ({ const DELETE_AUTOMATION_URL = `/api/automations/${_id}/${_rev}` await api.delete(DELETE_AUTOMATION_URL) - store.update(state => { + store.update((state) => { const existingIdx = state.automations.findIndex( - existing => existing._id === _id + (existing) => existing._id === _id ) state.automations.splice(existingIdx, 1) state.automations = state.automations @@ -72,24 +72,24 @@ const automationActions = store => ({ const TRIGGER_AUTOMATION_URL = `/api/automations/${_id}/trigger` return await api.post(TRIGGER_AUTOMATION_URL) }, - select: automation => { - store.update(state => { + select: (automation) => { + store.update((state) => { state.selectedAutomation = new Automation(cloneDeep(automation)) state.selectedBlock = null return state }) }, - addBlockToAutomation: block => { - store.update(state => { + addBlockToAutomation: (block) => { + store.update((state) => { const newBlock = state.selectedAutomation.addBlock(cloneDeep(block)) state.selectedBlock = newBlock return state }) }, - deleteAutomationBlock: block => { - store.update(state => { + deleteAutomationBlock: (block) => { + store.update((state) => { const idx = state.selectedAutomation.automation.definition.steps.findIndex( - x => x.id === block.id + (x) => x.id === block.id ) state.selectedAutomation.deleteBlock(block.id) diff --git a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte index c832ddd8bc..a598c6831e 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte @@ -1,93 +1,31 @@ -
+{#if automation} + -
-
- {#if automation} - - - {/if} -
+{:else if automationCount === 0} + Create your first automation to get started +{:else}Select an automation to edit{/if} diff --git a/packages/builder/src/components/automation/AutomationBuilder/BlockList.svelte b/packages/builder/src/components/automation/AutomationBuilder/BlockList.svelte new file mode 100644 index 0000000000..d791f7f98a --- /dev/null +++ b/packages/builder/src/components/automation/AutomationBuilder/BlockList.svelte @@ -0,0 +1,129 @@ + + +
+ {#each tabs as tab, idx} +
onChangeTab(idx)} + class:active={idx === selectedIndex}> + {#if tab.icon}{/if} + {tab.label} + +
+ {/each} +
+ (selectedIndex = null)} + bind:this={popover} + {anchor} + align="left"> + + {#each blocks as [stepId, blockDefinition]} + addBlockToAutomation(stepId, blockDefinition)} /> + {/each} + + + + diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/Arrow.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/Arrow.svelte similarity index 100% rename from packages/builder/src/components/automation/AutomationBuilder/flowchart/Arrow.svelte rename to packages/builder/src/components/automation/AutomationBuilder/FlowChart/Arrow.svelte diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/AutomationBlockTagline.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte similarity index 100% rename from packages/builder/src/components/automation/AutomationBuilder/flowchart/AutomationBlockTagline.svelte rename to packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowChart.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte similarity index 69% rename from packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowChart.svelte rename to packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte index 09a0d097de..b7e3f11bcf 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowChart.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowChart.svelte @@ -18,16 +18,9 @@ blocks = blocks.concat(automation.definition.steps || []) } } - $: automationCount = $automationStore.automations?.length ?? 0 -{#if automationCount === 0} - Create your first automation to get started -{:else if automation == null} - Select an automation to edit -{:else if !blocks.length} - Add some steps to your automation to get started -{/if} +{#if !blocks.length}Add a trigger to your automation to get started{/if}
{#each blocks as block, idx (block.id)}
diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte similarity index 82% rename from packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowItem.svelte rename to packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 2c78875eb1..85fdcf1a1d 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/flowchart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -9,7 +9,12 @@ $: selected = $automationStore.selectedBlock?.id === block.id $: steps = $automationStore.selectedAutomation?.automation?.definition?.steps ?? [] - $: blockIdx = steps.findIndex(step => step.id === block.id) + $: blockIdx = steps.findIndex((step) => step.id === block.id) + $: allowDeleteTrigger = !steps.length + + function deleteStep() { + automationStore.actions.deleteAutomationBlock(block) + }
{#if block.type === 'TRIGGER'}Trigger{:else}Step {blockIdx + 1}{/if}
+ {#if block.type !== 'TRIGGER' || allowDeleteTrigger} + + {/if}

@@ -61,6 +69,7 @@ flex-direction: row; justify-content: flex-start; align-items: center; + gap: var(--spacing-xs); } header span { flex: 1 1 auto; @@ -74,7 +83,13 @@ } header i { font-size: 20px; - margin-right: 5px; + } + header i.delete { + opacity: 0.5; + } + header i.delete:hover { + cursor: pointer; + opacity: 1; } .ACTION { diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/api.js b/packages/builder/src/components/automation/AutomationBuilder/flowchart/api.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/builder/src/components/automation/AutomationBuilder/flowchart/index.js b/packages/builder/src/components/automation/AutomationBuilder/flowchart/index.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte new file mode 100644 index 0000000000..c4a39d69b9 --- /dev/null +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte @@ -0,0 +1,34 @@ + + +

+ {#each $automationStore.automations as automation, idx} + 0} + icon="ri-stackshare-line" + text={automation.name} + selected={automation._id === selectedAutomationId} + on:click={() => automationStore.actions.select(automation)}> + + + {/each} +
+ + diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationList/AutomationList.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationList/AutomationList.svelte deleted file mode 100644 index 328c0d6122..0000000000 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationList/AutomationList.svelte +++ /dev/null @@ -1,79 +0,0 @@ - - -
- -
    - {#each $automationStore.automations as automation} -
  • automationStore.actions.select(automation)}> - - {automation.name} -
  • - {/each} -
-
- - - - - diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte index 9a29025d56..b6a2298a22 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte @@ -1,50 +1,41 @@ - - (selectedTab = 'AUTOMATIONS')}> - Automations - - {#if $automationStore.selectedAutomation} - (selectedTab = 'ADD')}> - Steps - - {/if} - - -{#if selectedTab === 'AUTOMATIONS'} - -{:else if selectedTab === 'ADD'} - -{/if} +
+

Automations

+ +
+ + + + diff --git a/packages/builder/src/components/automation/AutomationPanel/BlockList/BlockList.svelte b/packages/builder/src/components/automation/AutomationPanel/BlockList/BlockList.svelte deleted file mode 100644 index 1455f60ef1..0000000000 --- a/packages/builder/src/components/automation/AutomationPanel/BlockList/BlockList.svelte +++ /dev/null @@ -1,48 +0,0 @@ - - -
- -
- {#each blocks as [stepId, blockDefinition]} - - {/each} -
-
- - diff --git a/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte new file mode 100644 index 0000000000..38cc4d0069 --- /dev/null +++ b/packages/builder/src/components/automation/AutomationPanel/EditAutomationPopover.svelte @@ -0,0 +1,86 @@ + + +
+ +
+ + + + + + + Are you sure you wish to delete the automation + {automation.name}? + This action cannot be undone. + + + diff --git a/packages/builder/src/components/automation/AutomationPanel/index.js b/packages/builder/src/components/automation/AutomationPanel/index.js deleted file mode 100644 index 3ba95ab3b6..0000000000 --- a/packages/builder/src/components/automation/AutomationPanel/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as AutomationPanel } from "./AutomationPanel.svelte" -export { default as BlockList } from "./BlockList/BlockList.svelte" -export { default as AutomationList } from "./AutomationList/AutomationList.svelte" diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 896652dbb7..9165c8411a 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -1,6 +1,6 @@ -
-
{block.name}
- {#each inputs as [key, value]} -
- - {#if value.type === 'string' && value.enum} - - {:else if value.customType === 'password'} - - {:else if value.customType === 'table'} - - {:else if value.customType === 'row'} - - {:else if value.type === 'string' || value.type === 'number'} - - {/if} -
- {/each} -
+
{block.name}
+{#each inputs as [key, value]} +
+ + {#if value.type === 'string' && value.enum} + + {:else if value.customType === 'password'} + + {:else if value.customType === 'table'} + + {:else if value.customType === 'row'} + + {:else if value.type === 'string' || value.type === 'number'} + + {/if} +
+{/each} diff --git a/packages/builder/src/components/automation/SetupPanel/ParamInputs/TableSelector.svelte b/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte similarity index 88% rename from packages/builder/src/components/automation/SetupPanel/ParamInputs/TableSelector.svelte rename to packages/builder/src/components/automation/SetupPanel/TableSelector.svelte index ba0b55cc85..9727fa1d51 100644 --- a/packages/builder/src/components/automation/SetupPanel/ParamInputs/TableSelector.svelte +++ b/packages/builder/src/components/automation/SetupPanel/TableSelector.svelte @@ -6,7 +6,7 @@
- {#each $backendUiStore.tables as table} diff --git a/packages/builder/src/components/automation/SetupPanel/index.js b/packages/builder/src/components/automation/SetupPanel/index.js deleted file mode 100644 index ccfbddaf1c..0000000000 --- a/packages/builder/src/components/automation/SetupPanel/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as SetupPanel } from "./SetupPanel.svelte" diff --git a/packages/builder/src/components/userInterface/BindableInput.svelte b/packages/builder/src/components/userInterface/BindableInput.svelte index 5ba0798718..bb73dfd80d 100644 --- a/packages/builder/src/components/userInterface/BindableInput.svelte +++ b/packages/builder/src/components/userInterface/BindableInput.svelte @@ -43,7 +43,7 @@ width: 24px; background: var(--grey-4); right: var(--spacing-s); - bottom: 9px; + bottom: 5px; } button:hover { background: var(--grey-5); diff --git a/packages/builder/src/pages/[application]/automate/_layout.svelte b/packages/builder/src/pages/[application]/automate/_layout.svelte index 95cf31e2c8..29915e7bd2 100644 --- a/packages/builder/src/pages/[application]/automate/_layout.svelte +++ b/packages/builder/src/pages/[application]/automate/_layout.svelte @@ -1,6 +1,7 @@ @@ -19,21 +20,32 @@
diff --git a/packages/builder/src/pages/[application]/automate/index.svelte b/packages/builder/src/pages/[application]/automate/index.svelte index 36d04677cd..1a15ed48c6 100644 --- a/packages/builder/src/pages/[application]/automate/index.svelte +++ b/packages/builder/src/pages/[application]/automate/index.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte b/packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte index b7ee09a4f3..5491f7b884 100644 --- a/packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte +++ b/packages/builder/src/pages/[application]/data/table/[selectedTable]/index.svelte @@ -11,7 +11,7 @@ diff --git a/packages/builder/src/pages/[application]/data/table/index.svelte b/packages/builder/src/pages/[application]/data/table/index.svelte index 15ed1e299b..d1e2062f5c 100644 --- a/packages/builder/src/pages/[application]/data/table/index.svelte +++ b/packages/builder/src/pages/[application]/data/table/index.svelte @@ -27,7 +27,7 @@ diff --git a/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte b/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte index 3f592e6148..c1f7abc014 100644 --- a/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte +++ b/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte @@ -11,7 +11,7 @@ From 2114822c90f47f7e9d8b1803f35718dff54655ff Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 26 Oct 2020 12:25:26 +0000 Subject: [PATCH 31/67] Fix automation component paths --- .../automation/AutomationBuilder/AutomationBuilder.svelte | 2 +- .../components/automation/AutomationBuilder/BlockList.svelte | 2 +- .../automation/AutomationBuilder/FlowChart/FlowChart.svelte | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte index a598c6831e..ddb86174e2 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte @@ -1,6 +1,6 @@ -
tab", "props": { "className": "string" } }, "tbody": { - "name": "TableBody", + "name": "Table Body", "description": "an HTML tab", "props": { "className": "string" From caab43a312abf04cd812cd0c1f7c2935e3c4443c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 28 Oct 2020 20:28:00 +0000 Subject: [PATCH 53/67] v0.3.0 --- lerna.json | 2 +- packages/builder/package.json | 4 ++-- packages/client/package.json | 2 +- packages/server/package.json | 4 ++-- packages/standard-components/package.json | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lerna.json b/lerna.json index 9d0f9c2a80..df346f7cb9 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.2.6", + "version": "0.3.0", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/builder/package.json b/packages/builder/package.json index 671aaaa5c8..20c2360ae2 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.2.6", + "version": "0.3.0", "license": "AGPL-3.0", "private": true, "scripts": { @@ -64,7 +64,7 @@ }, "dependencies": { "@budibase/bbui": "^1.47.0", - "@budibase/client": "^0.2.6", + "@budibase/client": "^0.3.0", "@budibase/colorpicker": "^1.0.1", "@budibase/svelte-ag-grid": "^0.0.16", "@fortawesome/fontawesome-free": "^5.14.0", diff --git a/packages/client/package.json b/packages/client/package.json index dd5e48b905..ba8ac5d811 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.2.6", + "version": "0.3.0", "license": "MPL-2.0", "main": "dist/budibase-client.js", "module": "dist/budibase-client.esm.mjs", diff --git a/packages/server/package.json b/packages/server/package.json index b7a9aed9da..c7909e5e28 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/server", - "version": "0.2.6", + "version": "0.3.0", "description": "Budibase Web Server", "main": "src/electron.js", "repository": { @@ -40,7 +40,7 @@ "author": "Michael Shanks", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/client": "^0.2.6", + "@budibase/client": "^0.3.0", "@koa/router": "^8.0.0", "@sendgrid/mail": "^7.1.1", "@sentry/node": "^5.19.2", diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index 13f3e167a9..1888fa334e 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -13,7 +13,7 @@ "dev:builder": "rollup -cw" }, "devDependencies": { - "@budibase/client": "^0.2.6", + "@budibase/client": "^0.3.0", "@rollup/plugin-commonjs": "^11.1.0", "lodash": "^4.17.15", "rollup": "^2.11.2", @@ -31,7 +31,7 @@ "keywords": [ "svelte" ], - "version": "0.2.6", + "version": "0.3.0", "license": "MIT", "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "dependencies": { From ea03d099b375fdcbe7cf11d1dcd0412ee2494c0f Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 28 Oct 2020 20:35:06 +0000 Subject: [PATCH 54/67] Initial work into multi-tenancy removal, experiencing issues with test cases at this point. --- packages/builder/yarn.lock | 263 +----------------- .../server/scripts/createApiKeyAndAppId.js | 5 +- packages/server/scripts/jestSetup.js | 11 +- packages/server/scripts/replicateApp.js | 34 +-- .../server/src/api/controllers/analytics.js | 4 +- .../server/src/api/controllers/apikeys.js | 10 +- .../server/src/api/controllers/application.js | 126 +++------ packages/server/src/api/controllers/auth.js | 34 +-- packages/server/src/api/controllers/client.js | 31 --- .../server/src/api/controllers/component.js | 76 +++-- .../server/src/api/controllers/deploy/aws.js | 12 +- .../src/api/controllers/deploy/index.js | 34 +-- .../server/src/api/controllers/instance.js | 33 +-- packages/server/src/api/controllers/static.js | 11 +- packages/server/src/api/controllers/user.js | 16 +- packages/server/src/api/index.js | 4 - packages/server/src/api/routes/application.js | 6 +- packages/server/src/api/routes/client.js | 10 - packages/server/src/api/routes/component.js | 2 +- packages/server/src/api/routes/index.js | 2 - .../src/api/routes/tests/accesslevel.spec.js | 41 ++- .../src/api/routes/tests/application.spec.js | 64 +---- .../src/api/routes/tests/automation.spec.js | 49 ++-- .../src/api/routes/tests/couchTestUtils.js | 69 ++--- .../src/api/routes/tests/instance.spec.js | 12 +- .../server/src/api/routes/tests/row.spec.js | 38 ++- .../server/src/api/routes/tests/table.spec.js | 58 ++-- .../server/src/api/routes/tests/user.spec.js | 34 +-- .../server/src/api/routes/tests/view.spec.js | 33 +-- packages/server/src/app.js | 2 +- packages/server/src/automations/actions.js | 6 +- packages/server/src/automations/index.js | 6 +- .../server/src/automations/steps/createRow.js | 4 +- .../src/automations/steps/createUser.js | 4 +- .../server/src/automations/steps/deleteRow.js | 4 +- packages/server/src/db/clientDb.js | 26 -- packages/server/src/db/dynamoClient.js | 14 +- packages/server/src/db/utils.js | 1 + packages/server/src/environment.js | 8 + .../server/src/middleware/authenticated.js | 6 +- packages/server/src/middleware/authorized.js | 12 +- packages/server/src/middleware/usageQuota.js | 4 +- .../server/src/utilities/builder/index.js | 3 - .../src/utilities/builder/setBuilderToken.js | 8 +- packages/server/src/utilities/index.js | 8 +- .../src/utilities/initialiseBudibase.js | 20 +- packages/server/src/utilities/usageQuota.js | 4 +- packages/server/yarn.lock | 12 - 48 files changed, 351 insertions(+), 923 deletions(-) delete mode 100644 packages/server/src/api/controllers/client.js delete mode 100644 packages/server/src/api/routes/client.js delete mode 100644 packages/server/src/db/clientDb.js diff --git a/packages/builder/yarn.lock b/packages/builder/yarn.lock index 6a195f4a21..21eac0c67a 100644 --- a/packages/builder/yarn.lock +++ b/packages/builder/yarn.lock @@ -718,15 +718,6 @@ svelte-flatpickr "^2.4.0" svelte-portal "^1.0.0" -"@budibase/client@^0.2.6": - version "0.2.6" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.2.6.tgz#de1b4872c7956d386a3b08969eda509bd39d1a64" - integrity sha512-sSoGN0k2Tcc5GewBjFMN+G3h21O9JvakYI33kBKgEVGrdEQLBbry7vRKb+lALeW2Bz65gafZL2joZzL8vnH0lw== - dependencies: - deep-equal "^2.0.1" - mustache "^4.0.1" - regexparam "^1.3.0" - "@budibase/colorpicker@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@budibase/colorpicker/-/colorpicker-1.0.1.tgz#940c180e7ebba0cb0756c4c8ef13f5dfab58e810" @@ -1415,11 +1406,6 @@ array-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" -array-filter@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-1.0.0.tgz#baf79e62e6ef4c2a4c0b831232daffec251f9d83" - integrity sha1-uveeYubvTCpMC4MSMtr/7CUfnYM= - array-union@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" @@ -1474,13 +1460,6 @@ atob@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" -available-typed-arrays@^1.0.0, available-typed-arrays@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz#6b098ca9d8039079ee3f77f7b783c4480ba513f5" - integrity sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ== - dependencies: - array-filter "^1.0.0" - aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" @@ -2430,26 +2409,6 @@ decode-uri-component@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" -deep-equal@^2.0.1: - version "2.0.4" - resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.0.4.tgz#6b0b407a074666033169df3acaf128e1c6f3eab6" - integrity sha512-BUfaXrVoCfgkOQY/b09QdO9L3XNoF2XH0A3aY9IQwQL/ZjLOe8FQgCNVl1wiolhsFo8kFdO9zdPViCPbmaJA5w== - dependencies: - es-abstract "^1.18.0-next.1" - es-get-iterator "^1.1.0" - is-arguments "^1.0.4" - is-date-object "^1.0.2" - is-regex "^1.1.1" - isarray "^2.0.5" - object-is "^1.1.3" - object-keys "^1.1.1" - object.assign "^4.1.1" - regexp.prototype.flags "^1.3.0" - side-channel "^1.0.3" - which-boxed-primitive "^1.0.1" - which-collection "^1.0.1" - which-typed-array "^1.1.2" - deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -2619,54 +2578,6 @@ es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5: string.prototype.trimleft "^2.1.1" string.prototype.trimright "^2.1.1" -es-abstract@^1.17.4: - version "1.17.7" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c" - integrity sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g== - dependencies: - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-regex "^1.1.1" - object-inspect "^1.8.0" - object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" - -es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: - version "1.18.0-next.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" - integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== - dependencies: - es-to-primitive "^1.2.1" - function-bind "^1.1.1" - has "^1.0.3" - has-symbols "^1.0.1" - is-callable "^1.2.2" - is-negative-zero "^2.0.0" - is-regex "^1.1.1" - object-inspect "^1.8.0" - object-keys "^1.1.1" - object.assign "^4.1.1" - string.prototype.trimend "^1.0.1" - string.prototype.trimstart "^1.0.1" - -es-get-iterator@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/es-get-iterator/-/es-get-iterator-1.1.0.tgz#bb98ad9d6d63b31aacdc8f89d5d0ee57bcb5b4c8" - integrity sha512-UfrmHuWQlNMTs35e1ypnvikg6jCz3SK8v8ImvmDsh36fCVUR1MqoFDiyn0/k52C8NqO3YsO8Oe0azeesNuqSsQ== - dependencies: - es-abstract "^1.17.4" - has-symbols "^1.0.1" - is-arguments "^1.0.4" - is-map "^2.0.1" - is-set "^2.0.1" - is-string "^1.0.5" - isarray "^2.0.5" - es-to-primitive@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" @@ -2973,7 +2884,7 @@ for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" -foreach@^2.0.5, foreach@~2.0.1: +foreach@~2.0.1: version "2.0.5" resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99" integrity sha1-C+4AUBiusmDQo6865ljdATbsG5k= @@ -3347,31 +3258,16 @@ is-accessor-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-arguments@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.0.4.tgz#3faf966c7cba0ff437fb31f6250082fcf0448cf3" - integrity sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA== - is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" -is-bigint@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.0.tgz#73da8c33208d00f130e9b5e15d23eac9215601c4" - integrity sha512-t5mGUXC/xRheCK431ylNiSkGGpBp8bHENBcENTkDT6ppwPzEVxNGZRvgvmOEfbWkFhA7D2GEuE2mmQTr78sl2g== - is-binary-path@~2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" dependencies: binary-extensions "^2.0.0" -is-boolean-object@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.0.1.tgz#10edc0900dd127697a92f6f9807c7617d68ac48e" - integrity sha512-TqZuVwa/sppcrhUCAYkGBk7w0yxfQQnxq28fjkO53tnK9FQXmdwz2JS5+GjsWQ6RByES1K40nI+yDic5c9/aAQ== - is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" @@ -3380,11 +3276,6 @@ is-callable@^1.1.4, is-callable@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.5.tgz#f7e46b596890456db74e7f6e976cb3273d06faab" -is-callable@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9" - integrity sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA== - is-ci@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-2.0.0.tgz#6bc6334181810e04b5c22b3d589fdca55026404c" @@ -3403,7 +3294,7 @@ is-data-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-date-object@^1.0.1, is-date-object@^1.0.2: +is-date-object@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.2.tgz#bda736f2cd8fd06d32844e7743bfa7494c3bfd7e" @@ -3468,25 +3359,10 @@ is-installed-globally@^0.3.2: global-dirs "^2.0.1" is-path-inside "^3.0.1" -is-map@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.1.tgz#520dafc4307bb8ebc33b813de5ce7c9400d644a1" - integrity sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw== - is-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" -is-negative-zero@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.0.tgz#9553b121b0fac28869da9ed459e20c7543788461" - integrity sha1-lVOxIbD6wohp2p7UWeIMdUN4hGE= - -is-number-object@^1.0.3: - version "1.0.4" - resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.4.tgz#36ac95e741cf18b283fc1ddf5e83da798e3ec197" - integrity sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw== - is-number@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -3543,18 +3419,6 @@ is-regex@^1.0.5: dependencies: has "^1.0.3" -is-regex@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.1.tgz#c6f98aacc546f6cec5468a07b7b153ab564a57b9" - integrity sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg== - dependencies: - has-symbols "^1.0.1" - -is-set@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.1.tgz#d1604afdab1724986d30091575f54945da7e5f43" - integrity sha512-eJEzOtVyenDs1TMzSQ3kU3K+E0GUS9sno+F0OBT97xsgcJsF9nXMBtkT9/kut5JEpM7oL7X/0qxR17K3mcwIAA== - is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" @@ -3563,41 +3427,16 @@ is-stream@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" -is-string@^1.0.4, is-string@^1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6" - integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ== - is-symbol@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.3.tgz#38e1014b9e6329be0de9d24a414fd7441ec61937" dependencies: has-symbols "^1.0.1" -is-typed-array@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.3.tgz#a4ff5a5e672e1a55f99c7f54e59597af5c1df04d" - integrity sha512-BSYUBOK/HJibQ30wWkWold5txYwMUXQct9YHAQJr8fSwvZoiglcqB0pd7vEN23+Tsi9IUEjztdOSzl4qLVYGTQ== - dependencies: - available-typed-arrays "^1.0.0" - es-abstract "^1.17.4" - foreach "^2.0.5" - has-symbols "^1.0.1" - is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" -is-weakmap@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.1.tgz#5008b59bdc43b698201d18f62b37b2ca243e8cf2" - integrity sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA== - -is-weakset@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/is-weakset/-/is-weakset-2.0.1.tgz#e9a0af88dbd751589f5e50d80f4c98b780884f83" - integrity sha512-pi4vhbhVHGLxohUw7PhGsueT4vRGFoXhP7+RGN0jKIv9+8PWYCQTqtADngrxOm2g46hoH0+g8uZZBzMrvVGDmw== - is-windows@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" @@ -3618,11 +3457,6 @@ isarray@1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" -isarray@^2.0.5: - version "2.0.5" - resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" - integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw== - isbuffer@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/isbuffer/-/isbuffer-0.0.0.tgz#38c146d9df528b8bf9b0701c3d43cf12df3fc39b" @@ -4742,19 +4576,6 @@ object-inspect@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.7.0.tgz#f4f6bd181ad77f006b5ece60bd0b6f398ff74a67" -object-inspect@^1.8.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.8.0.tgz#df807e5ecf53a609cc6bfe93eac3cc7be5b3a9d0" - integrity sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA== - -object-is@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.3.tgz#2e3b9e65560137455ee3bd62aec4d90a2ea1cc81" - integrity sha512-teyqLvFWzLkq5B9ki8FVWA902UER2qkxmdA4nLf+wjOLAWgxzCWZNCxpDq9MvE8MmhWNr+I8w3BN49Vx36Y6Xg== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" - object-keys@^1.0.11, object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" @@ -4786,16 +4607,6 @@ object.assign@^4.1.0: has-symbols "^1.0.0" object-keys "^1.0.11" -object.assign@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.1.tgz#303867a666cdd41936ecdedfb1f8f3e32a478cdd" - integrity sha512-VT/cxmx5yaoHSOTSyrCygIDFco+RsibY2NM0a4RdEeY/4KgqezwFtK1yr3U67xYhqJSlASm2pKhLVzPj2lr4bA== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.0" - has-symbols "^1.0.1" - object-keys "^1.1.1" - object.getownpropertydescriptors@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz#369bf1f9592d8ab89d712dced5cb81c7c5352649" @@ -5276,19 +5087,6 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexp.prototype.flags@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz#7aba89b3c13a64509dabcf3ca8d9fbb9bdf5cb75" - integrity sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.17.0-next.1" - -regexparam@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-1.3.0.tgz#2fe42c93e32a40eff6235d635e0ffa344b92965f" - integrity sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g== - regexpu-core@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.7.0.tgz#fcbf458c50431b0bb7b45d6967b8192d91f3d938" @@ -5701,14 +5499,6 @@ shortid@^2.2.15: dependencies: nanoid "^2.1.0" -side-channel@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.3.tgz#cdc46b057550bbab63706210838df5d4c19519c3" - integrity sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g== - dependencies: - es-abstract "^1.18.0-next.0" - object-inspect "^1.8.0" - signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" @@ -5942,14 +5732,6 @@ string.prototype.trimend@^1.0.0: define-properties "^1.1.3" es-abstract "^1.17.5" -string.prototype.trimend@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.2.tgz#6ddd9a8796bc714b489a3ae22246a208f37bfa46" - integrity sha512-8oAG/hi14Z4nOVP0z6mdiVZ/wqjDtWSLygMigTzAb+7aPEDTleeFf+WrF+alzecxIRkckkJVn+dTlwzJXORATw== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" - string.prototype.trimleft@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz#4408aa2e5d6ddd0c9a80739b087fbc067c03b3cc" @@ -5973,14 +5755,6 @@ string.prototype.trimstart@^1.0.0: define-properties "^1.1.3" es-abstract "^1.17.5" -string.prototype.trimstart@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/string.prototype.trimstart/-/string.prototype.trimstart-1.0.2.tgz#22d45da81015309cd0cdd79787e8919fc5c613e7" - integrity sha512-7F6CdBTl5zyu30BJFdzSTlSlLPwODC23Od+iLoVH8X6+3fvDPPuBVVj9iaB1GOsSTSIgVfsfm27R2FGrAPznWg== - dependencies: - define-properties "^1.1.3" - es-abstract "^1.18.0-next.1" - string_decoder@^1.1.1: version "1.3.0" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" @@ -6430,43 +6204,10 @@ whatwg-url@^8.0.0: tr46 "^2.0.2" webidl-conversions "^5.0.0" -which-boxed-primitive@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz#cbe8f838ebe91ba2471bb69e9edbda67ab5a5ec1" - integrity sha512-7BT4TwISdDGBgaemWU0N0OU7FeAEJ9Oo2P1PHRm/FCWoEi2VLWC9b6xvxAA3C/NMpxg3HXVgi0sMmGbNUbNepQ== - dependencies: - is-bigint "^1.0.0" - is-boolean-object "^1.0.0" - is-number-object "^1.0.3" - is-string "^1.0.4" - is-symbol "^1.0.2" - -which-collection@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/which-collection/-/which-collection-1.0.1.tgz#70eab71ebbbd2aefaf32f917082fc62cdcb70906" - integrity sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A== - dependencies: - is-map "^2.0.1" - is-set "^2.0.1" - is-weakmap "^2.0.1" - is-weakset "^2.0.1" - which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" -which-typed-array@^1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.2.tgz#e5f98e56bda93e3dac196b01d47c1156679c00b2" - integrity sha512-KT6okrd1tE6JdZAy3o2VhMoYPh3+J6EMZLyrxBQsZflI1QCZIxMrIYLkosd8Twf+YfknVIHmYQPgJt238p8dnQ== - dependencies: - available-typed-arrays "^1.0.2" - es-abstract "^1.17.5" - foreach "^2.0.5" - function-bind "^1.1.1" - has-symbols "^1.0.1" - is-typed-array "^1.1.3" - which@^1.2.9, which@^1.3.0: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" diff --git a/packages/server/scripts/createApiKeyAndAppId.js b/packages/server/scripts/createApiKeyAndAppId.js index 223253f19c..76b0893d30 100644 --- a/packages/server/scripts/createApiKeyAndAppId.js +++ b/packages/server/scripts/createApiKeyAndAppId.js @@ -1,5 +1,6 @@ // THIS will create API Keys and App Ids input in a local Dynamo instance if it is running const dynamoClient = require("../src/db/dynamoClient") +const env = require("../src/environment") if (process.argv[2] == null || process.argv[3] == null) { console.error( @@ -11,8 +12,8 @@ if (process.argv[2] == null || process.argv[3] == null) { const FAKE_STRING = "fakestring" // set fake credentials for local dynamo to actually work -process.env.AWS_ACCESS_KEY_ID = "KEY_ID" -process.env.AWS_SECRET_ACCESS_KEY = "SECRET_KEY" +env._set("AWS_ACCESS_KEY_ID", "KEY_ID") +env._set("AWS_SECRET_ACCESS_KEY", "SECRET_KEY") dynamoClient.init("http://localhost:8333") async function run() { diff --git a/packages/server/scripts/jestSetup.js b/packages/server/scripts/jestSetup.js index 8fc7082554..f2841d2709 100644 --- a/packages/server/scripts/jestSetup.js +++ b/packages/server/scripts/jestSetup.js @@ -1,7 +1,8 @@ const { tmpdir } = require("os") +const env = require("../src/environment") -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.LOG_LEVEL = "silent" +env._set("NODE_ENV", "jest") +env._set("JWT_SECRET", "test-jwtsecret") +env._set("CLIENT_ID", "test-client-id") +env._set("BUDIBASE_DIR", tmpdir("budibase-unittests")) +env._set("LOG_LEVEL", "silent") diff --git a/packages/server/scripts/replicateApp.js b/packages/server/scripts/replicateApp.js index 3dba99a528..bbf44a7907 100644 --- a/packages/server/scripts/replicateApp.js +++ b/packages/server/scripts/replicateApp.js @@ -5,14 +5,7 @@ * e.g. node scripts/replicateApp Mike http://admin:password@127.0.0.1:5984 */ -const { resolve, join } = require("path") -const { homedir } = require("os") -const budibaseDir = join(homedir(), ".budibase") -process.env.BUDIBASE_DIR = budibaseDir -require("dotenv").config({ path: resolve(budibaseDir, ".env") }) -const env = require("../src/environment") const CouchDB = require("../src/db") -const clientDbName = require("../src/db/clientDb").name(env.CLIENT_ID) const appName = process.argv[2].toLowerCase() const remoteUrl = process.argv[3] @@ -20,27 +13,26 @@ const remoteUrl = process.argv[3] console.log(`Replicating from ${appName} to ${remoteUrl}/${appName}`) const run = async () => { - const clientDb = new CouchDB(clientDbName) - - const body = await clientDb.query("client/by_type", { - include_docs: true, - key: ["app"], - }) - - const app = body.rows - .map(r => r.doc) - .find(a => a.name == appName || a.name.toLowerCase() === appName) + const allDbs = await CouchDB.allDbs() + const appDbNames = allDbs.filter(dbName => dbName.startsWith("inst_app")) + let apps = [] + for (let dbName of appDbNames) { + const db = new CouchDB(dbName) + apps.push(db.get(dbName)) + } + apps = await Promise.all(apps) + const app = apps.find( + a => a.name === appName || a.name.toLowerCase() === appName + ) if (!app) { console.log( - `Could not find app... apps: ${body.rows.map(r => r.doc.name).join(", ")}` + `Could not find app... apps: ${apps.map(app => app.name).join(", ")}` ) return } - const devInstance = app.instances.find(i => i.name === `dev-${env.CLIENT_ID}`) - - const instanceDb = new CouchDB(devInstance._id) + const instanceDb = new CouchDB(app._id) const remoteDb = new CouchDB(`${remoteUrl}/${appName}`) instanceDb.replicate diff --git a/packages/server/src/api/controllers/analytics.js b/packages/server/src/api/controllers/analytics.js index 025775ac2e..566b4970e9 100644 --- a/packages/server/src/api/controllers/analytics.js +++ b/packages/server/src/api/controllers/analytics.js @@ -1,3 +1,5 @@ +const env = require("../../environment") + exports.isEnabled = async function(ctx) { - ctx.body = JSON.stringify(process.env.ENABLE_ANALYTICS === "true") + ctx.body = JSON.stringify(env.ENABLE_ANALYTICS === "true") } diff --git a/packages/server/src/api/controllers/apikeys.js b/packages/server/src/api/controllers/apikeys.js index 11cf1493da..96754f17cc 100644 --- a/packages/server/src/api/controllers/apikeys.js +++ b/packages/server/src/api/controllers/apikeys.js @@ -2,21 +2,23 @@ const fs = require("fs") const { join } = require("../../utilities/centralPath") const readline = require("readline") const { budibaseAppsDir } = require("../../utilities/budibaseDir") +const env = require("../../environment") const ENV_FILE_PATH = "/.env" exports.fetch = async function(ctx) { ctx.status = 200 ctx.body = { - budibase: process.env.BUDIBASE_API_KEY, - userId: process.env.USERID_API_KEY, + budibase: env.BUDIBASE_API_KEY, + userId: env.USERID_API_KEY, } } exports.update = async function(ctx) { const key = `${ctx.params.key.toUpperCase()}_API_KEY` const value = ctx.request.body.value - // Set process.env - process.env[key] = value + + // set environment variables + env._set(key, value) // Write to file await updateValues([key, value]) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 6e268c3f2e..9f0fdbc524 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -1,5 +1,4 @@ const CouchDB = require("../../db") -const ClientDb = require("../../db/clientDb") const { getPackageForBuilder, buildPage } = require("../../utilities/builder") const env = require("../../environment") const instanceController = require("./instance") @@ -11,89 +10,59 @@ const fs = require("fs-extra") const { join, resolve } = require("../../utilities/centralPath") const { promisify } = require("util") const chmodr = require("chmodr") -const { generateAppID, getAppParams } = require("../../db/utils") const packageJson = require("../../../package.json") +const { DocumentTypes, SEPARATOR } = require("../../db/utils") const { downloadExtractComponentLibraries, } = require("../../utilities/createAppPackage") +const APP_PREFIX = DocumentTypes.APP + SEPARATOR exports.fetch = async function(ctx) { - const db = new CouchDB(ClientDb.name(getClientId(ctx))) - const body = await db.allDocs( - getAppParams(null, { - include_docs: true, - }) - ) - ctx.body = body.rows.map(row => row.doc) + let allDbs = await CouchDB.allDbs() + const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX)) + const apps = [] + for (let dbName of appDbNames) { + const db = new CouchDB(dbName) + apps.push(db.get(dbName)) + } + if (apps.length === 0) { + ctx.body = [] + } else { + ctx.body = await Promise.all(apps) + } } exports.fetchAppPackage = async function(ctx) { - const clientId = await lookupClientId(ctx.params.applicationId) - const db = new CouchDB(ClientDb.name(clientId)) - const application = await db.get(ctx.params.applicationId) + const db = new CouchDB(ctx.params.instanceId) + const application = await db.get(ctx.params.instanceId) ctx.body = await getPackageForBuilder(ctx.config, application) - /* - instance is hardcoded now - this can only change when we move - pages and screens into the database - */ - const devInstance = application.instances.find( - i => i.name === `dev-${clientId}` - ) - setBuilderToken( - ctx, - ctx.params.applicationId, - devInstance._id, - application.version - ) + setBuilderToken(ctx, ctx.params.instanceId, application.version) } exports.create = async function(ctx) { - const clientId = - (ctx.request.body && ctx.request.body.clientId) || env.CLIENT_ID - - if (!clientId) { - ctx.throw(400, "ClientId not suplied") + const createInstCtx = { + request: { + body: { + template: ctx.request.body.template, + }, + }, } - const appId = generateAppID() - // insert an appId -> clientId lookup - const masterDb = new CouchDB("client_app_lookup") - - await masterDb.put({ - _id: appId, - clientId, - }) - - const db = new CouchDB(ClientDb.name(clientId)) - + await instanceController.create(createInstCtx) + const instanceId = createInstCtx.body._id const newApplication = { - _id: appId, + _id: instanceId, type: "app", - instances: [], userInstanceMap: {}, version: packageJson.version, componentLibraries: ["@budibase/standard-components"], name: ctx.request.body.name, template: ctx.request.body.template, + instances: [createInstCtx.body], } + const instanceDb = new CouchDB(instanceId) + await instanceDb.put(newApplication) - const { rev } = await db.put(newApplication) - newApplication._rev = rev - const createInstCtx = { - user: { - appId: newApplication._id, - }, - request: { - body: { - name: `dev-${clientId}`, - template: ctx.request.body.template, - }, - }, - } - - await instanceController.create(createInstCtx) - newApplication.instances.push(createInstCtx.body) - - if (process.env.NODE_ENV !== "jest") { + if (env.NODE_ENV !== "jest") { const newAppFolder = await createEmptyAppPackage(ctx, newApplication) await downloadExtractComponentLibraries(newAppFolder) } @@ -104,9 +73,8 @@ exports.create = async function(ctx) { } exports.update = async function(ctx) { - const clientId = await lookupClientId(ctx.params.applicationId) - const db = new CouchDB(ClientDb.name(clientId)) - const application = await db.get(ctx.params.applicationId) + const db = new CouchDB(ctx.params.instanceId) + const application = await db.get(ctx.params.instanceId) const data = ctx.request.body const newData = { ...application, ...data } @@ -120,16 +88,12 @@ exports.update = async function(ctx) { } exports.delete = async function(ctx) { - const db = new CouchDB(ClientDb.name(getClientId(ctx))) - const app = await db.get(ctx.params.applicationId) - const result = await db.remove(app) - for (let instance of app.instances) { - const instanceDb = new CouchDB(instance._id) - await instanceDb.destroy() - } + const db = new CouchDB(ctx.params.instanceId) + const app = await db.get(ctx.params.instanceId) + const result = await db.destroy() // remove top level directory - await fs.rmdir(join(budibaseAppsDir(), ctx.params.applicationId), { + await fs.rmdir(join(budibaseAppsDir(), ctx.params.instanceId), { recursive: true, }) @@ -222,24 +186,6 @@ const loadScreens = async (appFolder, page) => { return screens } -const lookupClientId = async appId => { - const masterDb = new CouchDB("client_app_lookup") - const { clientId } = await masterDb.get(appId) - return clientId -} - -const getClientId = ctx => { - const clientId = - (ctx.request.body && ctx.request.body.clientId) || - (ctx.query && ctx.query.clientId) || - env.CLIENT_ID - - if (!clientId) { - ctx.throw(400, "ClientId not supplied") - } - return clientId -} - const updateJsonFile = async (filePath, app) => { const json = await readFile(filePath, "utf8") const newJson = sqrl.Render(json, app) diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index f56e8816c8..eb5fd8d11f 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -1,44 +1,26 @@ const jwt = require("jsonwebtoken") const CouchDB = require("../../db") -const ClientDb = require("../../db/clientDb") const bcrypt = require("../../utilities/bcrypt") -const environment = require("../../environment") +const env = require("../../environment") const { getAPIKey } = require("../../utilities/usageQuota") const { generateUserID } = require("../../db/utils") exports.authenticate = async ctx => { - if (!ctx.user.appId) ctx.throw(400, "No appId") + const instanceId = ctx.user.instanceId + if (!instanceId) ctx.throw(400, "No instanceId") const { username, password } = ctx.request.body if (!username) ctx.throw(400, "Username Required.") - if (!password) ctx.throw(400, "Password Required") - - const masterDb = new CouchDB("client_app_lookup") - - const { clientId } = await masterDb.get(ctx.user.appId) - - if (!clientId) { - ctx.throw(400, "ClientId not supplied") - } - // find the instance that the user is associated with - const db = new CouchDB(ClientDb.name(clientId)) - const app = await db.get(ctx.user.appId) - const instanceId = app.userInstanceMap[username] - - if (!instanceId) - ctx.throw( - 500, - "User is not associated with an instance of app", - ctx.user.appId - ) + if (!password) ctx.throw(400, "Password Required.") // Check the user exists in the instance DB by username - const instanceDb = new CouchDB(instanceId) + const db = new CouchDB(instanceId) + const app = await db.get(instanceId) let dbUser try { - dbUser = await instanceDb.get(generateUserID(username)) + dbUser = await db.get(generateUserID(username)) } catch (_) { // do not want to throw a 404 - as this could be // used to determine valid usernames @@ -55,7 +37,7 @@ exports.authenticate = async ctx => { instanceId, } // if in cloud add the user api key - if (environment.CLOUD) { + if (env.CLOUD) { const { apiKey } = await getAPIKey(ctx.user.appId) payload.apiKey = apiKey } diff --git a/packages/server/src/api/controllers/client.js b/packages/server/src/api/controllers/client.js deleted file mode 100644 index 31f901001a..0000000000 --- a/packages/server/src/api/controllers/client.js +++ /dev/null @@ -1,31 +0,0 @@ -const { create, destroy } = require("../../db/clientDb") -const env = require("../../environment") - -exports.getClientId = async function(ctx) { - ctx.body = env.CLIENT_ID -} - -exports.create = async function(ctx) { - const clientId = getClientId(ctx) - await create(clientId) - ctx.status = 200 - ctx.message = `Client Database ${clientId} successfully provisioned.` -} - -exports.destroy = async function(ctx) { - const clientId = getClientId(ctx) - await destroy(clientId) - ctx.status = 200 - ctx.message = `Client Database ${clientId} successfully deleted.` -} - -const getClientId = ctx => { - const clientId = - (ctx.query && ctx.query.clientId) || - (ctx.body && ctx.body.clientId) || - env.CLIENT_ID - if (!clientId) { - ctx.throw(400, "ClientId not supplied") - } - return clientId -} diff --git a/packages/server/src/api/controllers/component.js b/packages/server/src/api/controllers/component.js index 9c5e0df151..e6c25b2d83 100644 --- a/packages/server/src/api/controllers/component.js +++ b/packages/server/src/api/controllers/component.js @@ -1,5 +1,4 @@ const CouchDB = require("../../db") -const ClientDb = require("../../db/clientDb") const { resolve, join } = require("../../utilities/centralPath") const { budibaseTempDir, @@ -7,49 +6,42 @@ const { } = require("../../utilities/budibaseDir") exports.fetchAppComponentDefinitions = async function(ctx) { - const masterDb = new CouchDB("client_app_lookup") - const { clientId } = await masterDb.get(ctx.params.appId) - const db = new CouchDB(ClientDb.name(clientId)) - const app = await db.get(ctx.params.appId) + const db = new CouchDB(ctx.params.instanceId) + const app = await db.get(ctx.params.instanceId) - const componentDefinitions = app.componentLibraries.reduce( - (acc, componentLibrary) => { - let appDirectory = resolve( - budibaseAppsDir(), - ctx.params.appId, - "node_modules" - ) + ctx.body = app.componentLibraries.reduce((acc, componentLibrary) => { + let appDirectory = resolve( + budibaseAppsDir(), + ctx.params.instanceId, + "node_modules" + ) - if (ctx.isDev) { - appDirectory = budibaseTempDir() + if (ctx.isDev) { + appDirectory = budibaseTempDir() + } + + const componentJson = require(join( + appDirectory, + componentLibrary, + ctx.isDev ? "" : "package", + "components.json" + )) + + const result = {} + + // map over the components.json and add the library identifier as a key + // button -> @budibase/standard-components/button + for (let key of Object.keys(componentJson)) { + const fullComponentName = `${componentLibrary}/${key}` + result[fullComponentName] = { + _component: fullComponentName, + ...componentJson[key], } + } - const componentJson = require(join( - appDirectory, - componentLibrary, - ctx.isDev ? "" : "package", - "components.json" - )) - - const result = {} - - // map over the components.json and add the library identifier as a key - // button -> @budibase/standard-components/button - for (key in componentJson) { - const fullComponentName = `${componentLibrary}/${key}` - result[fullComponentName] = { - _component: fullComponentName, - ...componentJson[key], - } - } - - return { - ...acc, - ...result, - } - }, - {} - ) - - ctx.body = componentDefinitions + return { + ...acc, + ...result, + } + }, {}) } diff --git a/packages/server/src/api/controllers/deploy/aws.js b/packages/server/src/api/controllers/deploy/aws.js index 30ee86846b..eea7be052d 100644 --- a/packages/server/src/api/controllers/deploy/aws.js +++ b/packages/server/src/api/controllers/deploy/aws.js @@ -6,7 +6,7 @@ const uuid = require("uuid") const sanitize = require("sanitize-s3-objectkey") const { budibaseAppsDir } = require("../../../utilities/budibaseDir") const PouchDB = require("../../../db") -const environment = require("../../../environment") +const env = require("../../../environment") async function invalidateCDN(cfDistribution, appId) { const cf = new AWS.CloudFront({}) @@ -44,12 +44,12 @@ exports.isInvalidationComplete = async function( exports.updateDeploymentQuota = async function(quota) { const DEPLOYMENT_SUCCESS_URL = - environment.DEPLOYMENT_CREDENTIALS_URL + "deploy/success" + env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success" const response = await fetch(DEPLOYMENT_SUCCESS_URL, { method: "POST", body: JSON.stringify({ - apiKey: process.env.BUDIBASE_API_KEY, + apiKey: env.BUDIBASE_API_KEY, quota, }), headers: { @@ -75,10 +75,10 @@ exports.updateDeploymentQuota = async function(quota) { * @param {quota} quota - current quota being changed with this application */ exports.verifyDeployment = async function({ instanceId, appId, quota }) { - const response = await fetch(process.env.DEPLOYMENT_CREDENTIALS_URL, { + const response = await fetch(env.DEPLOYMENT_CREDENTIALS_URL, { method: "POST", body: JSON.stringify({ - apiKey: process.env.BUDIBASE_API_KEY, + apiKey: env.BUDIBASE_API_KEY, instanceId, appId, quota, @@ -87,7 +87,7 @@ exports.verifyDeployment = async function({ instanceId, appId, quota }) { if (response.status !== 200) { throw new Error( - `Error fetching temporary credentials for api key: ${process.env.BUDIBASE_API_KEY}` + `Error fetching temporary credentials for api key: ${env.BUDIBASE_API_KEY}` ) } diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index ceae868749..0ab7a3791e 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -8,6 +8,7 @@ const { } = require("./aws") const { DocumentTypes, SEPARATOR, UNICODE_MAX } = require("../../../db/utils") const newid = require("../../../db/newid") +const env = require("../../../environment") // the max time we can wait for an invalidation to complete before considering it failed const MAX_PENDING_TIME_MS = 30 * 60000 @@ -80,25 +81,16 @@ function replicate(local, remote) { }) } -async function replicateCouch({ instanceId, clientId, session }) { - const databases = [`client_${clientId}`, "client_app_lookup", instanceId] - - const replications = databases.map(localDbName => { - const localDb = new PouchDB(localDbName) - const remoteDb = new CouchDB( - `${process.env.DEPLOYMENT_DB_URL}/${localDbName}`, - { - fetch: function(url, opts) { - opts.headers.set("Cookie", `${session};`) - return CouchDB.fetch(url, opts) - }, - } - ) - - return replicate(localDb, remoteDb) +async function replicateCouch({ instanceId, session }) { + const localDb = new PouchDB(instanceId) + const remoteDb = new CouchDB(`${env.DEPLOYMENT_DB_URL}/${instanceId}`, { + fetch: function(url, opts) { + opts.headers.set("Cookie", `${session};`) + return CouchDB.fetch(url, opts) + }, }) - await Promise.all(replications) + return replicate(localDb, remoteDb) } async function getCurrentInstanceQuota(instanceId) { @@ -155,7 +147,7 @@ async function storeLocalDeploymentHistory(deployment) { } } -async function deployApp({ instanceId, appId, clientId, deploymentId }) { +async function deployApp({ instanceId, appId, deploymentId }) { try { const instanceQuota = await getCurrentInstanceQuota(instanceId) const verification = await verifyDeployment({ @@ -167,7 +159,6 @@ async function deployApp({ instanceId, appId, clientId, deploymentId }) { console.log(`Uploading assets for appID ${appId} assets to s3..`) const invalidationId = await uploadAppAssets({ - clientId, appId, instanceId, ...verification, @@ -177,7 +168,6 @@ async function deployApp({ instanceId, appId, clientId, deploymentId }) { console.log("Replicating local PouchDB to remote..") await replicateCouch({ instanceId, - clientId, session: verification.couchDbSession, }) @@ -233,9 +223,6 @@ exports.deploymentProgress = async function(ctx) { } exports.deployApp = async function(ctx) { - const clientAppLookupDB = new PouchDB("client_app_lookup") - const { clientId } = await clientAppLookupDB.get(ctx.user.appId) - const deployment = await storeLocalDeploymentHistory({ instanceId: ctx.user.instanceId, appId: ctx.user.appId, @@ -244,7 +231,6 @@ exports.deployApp = async function(ctx) { await deployApp({ ...ctx.user, - clientId, deploymentId: deployment._id, }) diff --git a/packages/server/src/api/controllers/instance.js b/packages/server/src/api/controllers/instance.js index fbee2f72f5..9879919540 100644 --- a/packages/server/src/api/controllers/instance.js +++ b/packages/server/src/api/controllers/instance.js @@ -1,28 +1,18 @@ const fs = require("fs") const CouchDB = require("../../db") -const client = require("../../db/clientDb") -const newid = require("../../db/newid") const { createLinkView } = require("../../db/linkedRows") const { join } = require("../../utilities/centralPath") const { downloadTemplate } = require("../../utilities/templates") +const { generateAppID } = require("../../db/utils") exports.create = async function(ctx) { const instanceName = ctx.request.body.name const template = ctx.request.body.template - const { appId } = ctx.user - const appShortId = appId.substring(0, 7) - const instanceId = `inst_${appShortId}_${newid()}` - - const masterDb = new CouchDB("client_app_lookup") - const { clientId } = await masterDb.get(appId) + const instanceId = generateAppID() const db = new CouchDB(instanceId) await db.put({ _id: "_design/database", - metadata: { - clientId, - applicationId: appId, - }, // view collation information, read before writing any complex views: // https://docs.couchdb.org/en/master/ddocs/views/collation.html#collation-specification views: {}, @@ -30,13 +20,6 @@ exports.create = async function(ctx) { // add view for linked rows await createLinkView(instanceId) - // Add the new instance under the app clientDB - const clientDb = new CouchDB(client.name(clientId)) - const budibaseApp = await clientDb.get(appId) - const instance = { _id: instanceId, name: instanceName } - budibaseApp.instances.push(instance) - await clientDb.put(budibaseApp) - // replicate the template data to the instance DB if (template) { const templatePath = await downloadTemplate(...template.key.split("/")) @@ -51,23 +34,13 @@ exports.create = async function(ctx) { ctx.status = 200 ctx.message = `Instance Database ${instanceName} successfully provisioned.` - ctx.body = instance + ctx.body = { _id: instanceId, name: instanceName } } exports.destroy = async function(ctx) { const db = new CouchDB(ctx.params.instanceId) - const designDoc = await db.get("_design/database") await db.destroy() - // remove instance from client application document - const { metadata } = designDoc - const clientDb = new CouchDB(client.name(metadata.clientId)) - const budibaseApp = await clientDb.get(metadata.applicationId) - budibaseApp.instances = budibaseApp.instances.filter( - instance => instance !== ctx.params.instanceId - ) - await clientDb.put(budibaseApp) - ctx.status = 200 ctx.message = `Instance Database ${ctx.params.instanceId} successfully destroyed.` } diff --git a/packages/server/src/api/controllers/static.js b/packages/server/src/api/controllers/static.js index 791acc8d92..19eb90dc42 100644 --- a/packages/server/src/api/controllers/static.js +++ b/packages/server/src/api/controllers/static.js @@ -13,6 +13,7 @@ const CouchDB = require("../../db") const setBuilderToken = require("../../utilities/builder/setBuilderToken") const fileProcessor = require("../../utilities/fileProcessor") const { AuthTypes } = require("../../constants") +const env = require("../../environment") // this was the version before we started versioning the component library const COMP_LIB_BASE_APP_VERSION = "0.2.5" @@ -38,7 +39,7 @@ exports.uploadFile = async function(ctx) { "attachments" ) - if (process.env.CLOUD) { + if (env.CLOUD) { // remote upload const s3 = new AWS.S3({ params: { @@ -150,7 +151,7 @@ exports.serveApp = async function(ctx) { const appId = ctx.user.appId - if (process.env.CLOUD) { + if (env.CLOUD) { const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/${mainOrAuth}/${ctx.file || "index.production.html"}` @@ -168,7 +169,7 @@ exports.serveAttachment = async function(ctx) { const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments") // Serve from CloudFront - if (process.env.CLOUD) { + if (env.CLOUD) { const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}` const response = await fetch(S3_URL) const body = await response.text() @@ -187,7 +188,7 @@ exports.serveAppAsset = async function(ctx) { const appPath = resolve( budibaseAppsDir(), - ctx.user.appId, + ctx.user.instanceId, "public", mainOrAuth ) @@ -214,7 +215,7 @@ exports.serveComponentLibrary = async function(ctx) { ) } - if (process.env.CLOUD) { + if (env.CLOUD) { let componentLib = "componentlibrary" if (ctx.user.version) { componentLib += `-${ctx.user.version}` diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 4e749f0ff7..192f56180e 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -1,5 +1,4 @@ const CouchDB = require("../../db") -const clientDb = require("../../db/clientDb") const bcrypt = require("../../utilities/bcrypt") const { generateUserID, getUserParams } = require("../../db/utils") const { @@ -18,15 +17,14 @@ exports.fetch = async function(ctx) { } exports.create = async function(ctx) { - const database = new CouchDB(ctx.user.instanceId) - const appId = (await database.get("_design/database")).metadata.applicationId + const db = new CouchDB(ctx.user.instanceId) const { username, password, name, accessLevelId } = ctx.request.body if (!username || !password) { ctx.throw(400, "Username and Password Required.") } - const accessLevel = await checkAccessLevel(database, accessLevelId) + const accessLevel = await checkAccessLevel(db, accessLevelId) if (!accessLevel) ctx.throw(400, "Invalid Access Level") @@ -39,15 +37,9 @@ exports.create = async function(ctx) { accessLevelId, } - const response = await database.post(user) - - const masterDb = new CouchDB("client_app_lookup") - const { clientId } = await masterDb.get(appId) - - // the clientDB needs to store a map of users against the app - const db = new CouchDB(clientDb.name(clientId)) - const app = await db.get(appId) + const response = await db.post(user) + const app = await db.get(ctx.user.instanceId) app.userInstanceMap = { ...app.userInstanceMap, [username]: ctx.user.instanceId, diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index 1986315a51..e9418c518a 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -10,7 +10,6 @@ const { userRoutes, deployRoutes, instanceRoutes, - clientRoutes, applicationRoutes, rowRoutes, tableRoutes, @@ -108,9 +107,6 @@ router.use(applicationRoutes.allowedMethods()) router.use(componentRoutes.routes()) router.use(componentRoutes.allowedMethods()) -router.use(clientRoutes.routes()) -router.use(clientRoutes.allowedMethods()) - router.use(accesslevelRoutes.routes()) router.use(accesslevelRoutes.allowedMethods()) diff --git a/packages/server/src/api/routes/application.js b/packages/server/src/api/routes/application.js index 65e73e95f5..f600eee333 100644 --- a/packages/server/src/api/routes/application.js +++ b/packages/server/src/api/routes/application.js @@ -8,12 +8,12 @@ const router = Router() router .get("/api/applications", authorized(BUILDER), controller.fetch) .get( - "/api/:applicationId/appPackage", + "/api/:instanceId/appPackage", authorized(BUILDER), controller.fetchAppPackage ) - .put("/api/:applicationId", authorized(BUILDER), controller.update) + .put("/api/:instanceId", authorized(BUILDER), controller.update) .post("/api/applications", authorized(BUILDER), controller.create) - .delete("/api/:applicationId", authorized(BUILDER), controller.delete) + .delete("/api/:instanceId", authorized(BUILDER), controller.delete) module.exports = router diff --git a/packages/server/src/api/routes/client.js b/packages/server/src/api/routes/client.js deleted file mode 100644 index 16acf1b7a3..0000000000 --- a/packages/server/src/api/routes/client.js +++ /dev/null @@ -1,10 +0,0 @@ -const Router = require("@koa/router") -const controller = require("../controllers/client") -const authorized = require("../../middleware/authorized") -const { BUILDER } = require("../../utilities/accessLevels") - -const router = Router() - -router.get("/api/client/id", authorized(BUILDER), controller.getClientId) - -module.exports = router diff --git a/packages/server/src/api/routes/component.js b/packages/server/src/api/routes/component.js index 8fbe7ac41a..f9dfff331c 100644 --- a/packages/server/src/api/routes/component.js +++ b/packages/server/src/api/routes/component.js @@ -6,7 +6,7 @@ const { BUILDER } = require("../../utilities/accessLevels") const router = Router() router.get( - "/:appId/components/definitions", + "/:instanceId/components/definitions", authorized(BUILDER), controller.fetchAppComponentDefinitions ) diff --git a/packages/server/src/api/routes/index.js b/packages/server/src/api/routes/index.js index 72688a7de5..434def06b5 100644 --- a/packages/server/src/api/routes/index.js +++ b/packages/server/src/api/routes/index.js @@ -2,7 +2,6 @@ const authRoutes = require("./auth") const pageRoutes = require("./pages") const userRoutes = require("./user") const instanceRoutes = require("./instance") -const clientRoutes = require("./client") const applicationRoutes = require("./application") const tableRoutes = require("./table") const rowRoutes = require("./row") @@ -23,7 +22,6 @@ module.exports = { pageRoutes, userRoutes, instanceRoutes, - clientRoutes, applicationRoutes, rowRoutes, tableRoutes, diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index 79f92e8a69..ae0453e44b 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -1,6 +1,4 @@ const { - createInstance, - createClientDatabase, createApplication, createTable, createView, @@ -17,7 +15,6 @@ const { } = require("../../../utilities/accessLevels") describe("/accesslevels", () => { - let appId let server let request let instanceId @@ -26,18 +23,18 @@ describe("/accesslevels", () => { beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request); - appId = (await createApplication(request))._id }); - afterAll(async () => { - server.close(); + afterAll(done => { + server.close(done) + process.exit(0) }) beforeEach(async () => { - instanceId = (await createInstance(request, appId))._id - table = await createTable(request, appId, instanceId) - view = await createView(request, appId, instanceId, table._id) + let app = await createApplication(request) + instanceId = app.instances[0]._id + table = await createTable(request, instanceId) + view = await createView(request, instanceId, table._id) }) describe("create", () => { @@ -46,7 +43,7 @@ describe("/accesslevels", () => { const res = await request .post(`/api/accesslevels`) .send({ name: "user" }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -64,7 +61,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE }] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -72,7 +69,7 @@ describe("/accesslevels", () => { const res = await request .get(`/api/accesslevels`) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -97,7 +94,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE } ] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -105,12 +102,12 @@ describe("/accesslevels", () => { await request .delete(`/api/accesslevels/${customLevel._id}/${customLevel._rev}`) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect(200) await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect(404) }) }) @@ -120,7 +117,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE }] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -132,13 +129,13 @@ describe("/accesslevels", () => { _rev: customLevel._rev, addedPermissions: [ { itemId: table._id, name: WRITE_TABLE } ] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) const finalRes = await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect(200) expect(finalRes.body.permissions.length).toBe(2) @@ -156,7 +153,7 @@ describe("/accesslevels", () => { { itemId: table._id, name: WRITE_TABLE }, ] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -168,13 +165,13 @@ describe("/accesslevels", () => { _rev: customLevel._rev, removedPermissions: [ { itemId: table._id, name: WRITE_TABLE }] }) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) const finalRes = await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(appId, instanceId)) + .set(defaultHeaders(instanceId)) .expect(200) expect(finalRes.body.permissions.length).toBe(1) diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index d22ab02016..285578b969 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -1,11 +1,8 @@ -const { - createClientDatabase, +const { createApplication, - createInstance, - destroyClientDatabase, builderEndpointShouldBlockNormalUsers, supertest, - TEST_CLIENT_ID, + clearApplications, defaultHeaders, } = require("./couchTestUtils") @@ -18,15 +15,12 @@ describe("/applications", () => { }); beforeEach(async () => { - await createClientDatabase() + await clearApplications(request) }) - afterEach(async () => { - await destroyClientDatabase() - }) - - afterAll(async () => { - server.close() + afterAll(done => { + server.close(done) + process.exit(0) }) describe("create", () => { @@ -42,14 +36,13 @@ describe("/applications", () => { }) it("should apply authorization to endpoint", async () => { - const otherApplication = await createApplication(request) - const instance = await createInstance(request, otherApplication._id) + const otherApplication = await createApplication(request) + const instanceId = otherApplication.instances[0]._id await builderEndpointShouldBlockNormalUsers({ request, method: "POST", url: `/api/applications`, - instanceId: instance._id, - appId: otherApplication._id, + instanceId: instanceId, body: { name: "My App" } }) }) @@ -58,7 +51,6 @@ describe("/applications", () => { describe("fetch", () => { it("lists all applications", async () => { - await createApplication(request, "app1") await createApplication(request, "app2") @@ -71,46 +63,14 @@ describe("/applications", () => { expect(res.body.length).toBe(2) }) - it("lists only applications in requested client databse", async () => { - await createApplication(request, "app1") - await createClientDatabase("new_client") - - const blah = await request - .post("/api/applications") - .send({ name: "app2", clientId: "new_client"}) - .set(defaultHeaders()) - .expect('Content-Type', /json/) - //.expect(200) - - const client1Res = await request - .get(`/api/applications?clientId=${TEST_CLIENT_ID}`) - .set(defaultHeaders()) - .expect('Content-Type', /json/) - .expect(200) - - expect(client1Res.body.length).toBe(1) - expect(client1Res.body[0].name).toBe("app1") - - const client2Res = await request - .get(`/api/applications?clientId=new_client`) - .set(defaultHeaders()) - .expect('Content-Type', /json/) - .expect(200) - - expect(client2Res.body.length).toBe(1) - expect(client2Res.body[0].name).toBe("app2") - - }) - it("should apply authorization to endpoint", async () => { - const otherApplication = await createApplication(request) - const instance = await createInstance(request, otherApplication._id) + const otherApplication = await createApplication(request) + const instanceId = otherApplication.instances[0]._id await builderEndpointShouldBlockNormalUsers({ request, method: "GET", url: `/api/applications`, - instanceId: instance._id, - appId: otherApplication._id, + instanceId: instanceId, }) }) }) diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index f3ebcd2144..b8e5897a4e 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -1,7 +1,5 @@ -const { - createClientDatabase, +const { createApplication, - createInstance, createTable, getAllFromTable, defaultHeaders, @@ -41,27 +39,27 @@ describe("/automations", () => { let request let server let app - let instance + let instanceId let automation let automationId beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request) - app = await createApplication(request) }) beforeEach(async () => { + app = await createApplication(request) + instanceId = app.instances[0]._id if (automation) await destroyDocument(automation.id) - instance = await createInstance(request, app._id) }) - afterAll(async () => { - server.close() + afterAll(done => { + server.close(done) + process.exit(0) }) const createAutomation = async () => { - automation = await insertDocument(instance._id, { + automation = await insertDocument(instanceId, { type: "automation", ...TEST_AUTOMATION }) @@ -72,7 +70,7 @@ describe("/automations", () => { return await request .post(`/api/automations/${automationId}/trigger`) .send({ name: "Test", description: "TEST" }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) } @@ -81,7 +79,7 @@ describe("/automations", () => { it("returns a list of definitions for actions", async () => { const res = await request .get(`/api/automations/action/list`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -92,7 +90,7 @@ describe("/automations", () => { it("returns a list of definitions for triggers", async () => { const res = await request .get(`/api/automations/trigger/list`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -103,7 +101,7 @@ describe("/automations", () => { it("returns a list of definitions for actions", async () => { const res = await request .get(`/api/automations/logic/list`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -114,7 +112,7 @@ describe("/automations", () => { it("returns all of the definitions in one", async () => { const res = await request .get(`/api/automations/definitions/list`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -142,7 +140,7 @@ describe("/automations", () => { it("returns a success message when the automation is successfully created", async () => { const res = await request .post(`/api/automations`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .send(TEST_AUTOMATION) .expect('Content-Type', /json/) .expect(200) @@ -158,8 +156,7 @@ describe("/automations", () => { request, method: "POST", url: `/api/automations`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, body: TEST_AUTOMATION }) }) @@ -167,7 +164,7 @@ describe("/automations", () => { describe("trigger", () => { it("trigger the automation successfully", async () => { - let table = await createTable(request, app._id, instance._id) + let table = await createTable(request, instanceId) TEST_AUTOMATION.definition.trigger.inputs.tableId = table._id TEST_AUTOMATION.definition.steps[0].inputs.row.tableId = table._id await createAutomation() @@ -180,7 +177,7 @@ describe("/automations", () => { expect(res.body.message).toEqual(`Automation ${automation._id} has been triggered.`) expect(res.body.automation.name).toEqual(TEST_AUTOMATION.name) await delay(500) - let elements = await getAllFromTable(request, app._id, instance._id, table._id) + let elements = await getAllFromTable(request, instanceId, table._id) // don't test it unless there are values to test if (elements.length === 1) { expect(elements.length).toEqual(1) @@ -203,7 +200,7 @@ describe("/automations", () => { const res = await request .put(`/api/automations`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .send(automation) .expect('Content-Type', /json/) .expect(200) @@ -218,7 +215,7 @@ describe("/automations", () => { await createAutomation() const res = await request .get(`/api/automations`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -230,8 +227,7 @@ describe("/automations", () => { request, method: "GET", url: `/api/automations`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, }) }) }) @@ -241,7 +237,7 @@ describe("/automations", () => { await createAutomation() const res = await request .delete(`/api/automations/${automation.id}/${automation.rev}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -254,8 +250,7 @@ describe("/automations", () => { request, method: "DELETE", url: `/api/automations/${automation.id}/${automation._rev}`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, }) }) }) diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index bb155d47bb..12f9e11908 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -1,5 +1,4 @@ const CouchDB = require("../../../db") -const { create, destroy } = require("../../../db/clientDb") const supertest = require("supertest") const { POWERUSER_LEVEL_ID, @@ -16,19 +15,18 @@ const TEST_CLIENT_ID = "test-client-id" exports.TEST_CLIENT_ID = TEST_CLIENT_ID exports.supertest = async () => { let request - let server - process.env.PORT = 4002 - server = require("../../../app") + let app + env.PORT = 4002 + app = require("../../../app") - request = supertest(server) - return { request, server } + request = supertest(app) + return { request, app } } -exports.defaultHeaders = (appId, instanceId) => { +exports.defaultHeaders = instanceId => { const builderUser = { userId: "BUILDER", accessLevelId: BUILDER_LEVEL_ID, - appId, instanceId, } @@ -40,7 +38,7 @@ exports.defaultHeaders = (appId, instanceId) => { } } -exports.createTable = async (request, appId, instanceId, table) => { +exports.createTable = async (request, instanceId, table) => { if (table != null && table._id) { delete table._id } @@ -66,19 +64,19 @@ exports.createTable = async (request, appId, instanceId, table) => { const res = await request .post(`/api/tables`) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) .send(table) return res.body } -exports.getAllFromTable = async (request, appId, instanceId, tableId) => { +exports.getAllFromTable = async (request, instanceId, tableId) => { const res = await request .get(`/api/${tableId}/rows`) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) return res.body } -exports.createView = async (request, appId, instanceId, tableId, view) => { +exports.createView = async (request, instanceId, tableId, view) => { view = view || { map: "function(doc) { emit(doc[doc.key], doc._id); } ", tableId: tableId, @@ -86,13 +84,11 @@ exports.createView = async (request, appId, instanceId, tableId, view) => { const res = await request .post(`/api/views`) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) .send(view) return res.body } -exports.createClientDatabase = async id => await create(id || TEST_CLIENT_ID) - exports.createApplication = async (request, name = "test_application") => { const res = await request .post("/api/applications") @@ -103,28 +99,35 @@ exports.createApplication = async (request, name = "test_application") => { return res.body } -exports.destroyClientDatabase = async () => await destroy(TEST_CLIENT_ID) +exports.clearApplications = async request => { + const res = await request + .get("/api/applications") + .set(exports.defaultHeaders()) + for (let app of res.body) { + const appId = app._id + await request.delete(`/api/${appId}`).set(exports.defaultHeaders(appId)) + } +} -exports.createInstance = async (request, appId) => { +exports.createInstance = async request => { const res = await request .post(`/api/instances`) .send({ name: "test-instance2", }) - .set(exports.defaultHeaders(appId)) + .set(exports.defaultHeaders()) return res.body } exports.createUser = async ( request, - appId, instanceId, username = "babs", password = "babs_password" ) => { const res = await request .post(`/api/users`) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) .send({ name: "Bill", username, @@ -136,7 +139,6 @@ exports.createUser = async ( const createUserWithOnePermission = async ( request, - appId, instanceId, permName, itemId @@ -148,19 +150,17 @@ const createUserWithOnePermission = async ( return await createUserWithPermissions( request, - appId, instanceId, permissions, "onePermOnlyUser" ) } -const createUserWithAdminPermissions = async (request, appId, instanceId) => { +const createUserWithAdminPermissions = async (request, instanceId) => { let permissions = await generateAdminPermissions(instanceId) return await createUserWithPermissions( request, - appId, instanceId, permissions, "adminUser" @@ -169,7 +169,6 @@ const createUserWithAdminPermissions = async (request, appId, instanceId) => { const createUserWithAllPermissionExceptOne = async ( request, - appId, instanceId, permName, itemId @@ -181,7 +180,6 @@ const createUserWithAllPermissionExceptOne = async ( return await createUserWithPermissions( request, - appId, instanceId, permissions, "allPermsExceptOneUser" @@ -190,7 +188,6 @@ const createUserWithAllPermissionExceptOne = async ( const createUserWithPermissions = async ( request, - appId, instanceId, permissions, username @@ -198,12 +195,12 @@ const createUserWithPermissions = async ( const accessRes = await request .post(`/api/accesslevels`) .send({ name: "TestLevel", permissions }) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) const password = `password_${username}` await request .post(`/api/users`) - .set(exports.defaultHeaders(appId, instanceId)) + .set(exports.defaultHeaders(instanceId)) .send({ name: username, username, @@ -214,7 +211,7 @@ const createUserWithPermissions = async ( const anonUser = { userId: "ANON", accessLevelId: ANON_LEVEL_ID, - appId: appId, + instanceId: instanceId, version: packageJson.version, } @@ -237,14 +234,12 @@ exports.testPermissionsForEndpoint = async ({ method, url, body, - appId, instanceId, permissionName, itemId, }) => { const headers = await createUserWithOnePermission( request, - appId, instanceId, permissionName, itemId @@ -256,7 +251,6 @@ exports.testPermissionsForEndpoint = async ({ const noPermsHeaders = await createUserWithAllPermissionExceptOne( request, - appId, instanceId, permissionName, itemId @@ -272,14 +266,9 @@ exports.builderEndpointShouldBlockNormalUsers = async ({ method, url, body, - appId, instanceId, }) => { - const headers = await createUserWithAdminPermissions( - request, - appId, - instanceId - ) + const headers = await createUserWithAdminPermissions(request, instanceId) await createRequest(request, method, url, body) .set(headers) diff --git a/packages/server/src/api/routes/tests/instance.spec.js b/packages/server/src/api/routes/tests/instance.spec.js index 3bbed4d8e6..86fd4b8920 100644 --- a/packages/server/src/api/routes/tests/instance.spec.js +++ b/packages/server/src/api/routes/tests/instance.spec.js @@ -1,6 +1,5 @@ const { - createInstance, - createClientDatabase, + createInstance, createApplication, supertest, defaultHeaders @@ -12,12 +11,11 @@ describe("/instances", () => { let request beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request); TEST_APP_ID = (await createApplication(request))._id }); - afterAll(async () => { - server.close(); + afterAll(done => { + server.close(done) }) describe("create", () => { @@ -26,7 +24,7 @@ describe("/instances", () => { const res = await request .post(`/api/instances`) .send({ name: "test-instance" }) - .set(defaultHeaders(TEST_APP_ID)) + .set(defaultHeaders()) .expect('Content-Type', /json/) .expect(200) @@ -42,7 +40,7 @@ describe("/instances", () => { const instance = await createInstance(request, TEST_APP_ID); const res = await request .delete(`/api/instances/${instance._id}`) - .set(defaultHeaders(TEST_APP_ID)) + .set(defaultHeaders()) .expect(200) expect(res.res.statusMessage).toEqual(`Instance Database ${instance._id} successfully destroyed.`); diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index ff8cf672c5..31098c51e4 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -1,7 +1,5 @@ const { createApplication, - createClientDatabase, - createInstance, createTable, supertest, defaultHeaders, @@ -10,24 +8,24 @@ const { describe("/rows", () => { let request let server - let instance + let instanceId let table let row let app beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request) - app = await createApplication(request) + }); - afterAll(async () => { - server.close(); + afterAll(done => { + server.close(done) }) beforeEach(async () => { - instance = await createInstance(request, app._id) - table = await createTable(request, app._id, instance._id) + app = await createApplication(request) + instanceId = app.instances[0]._id + table = await createTable(request, instanceId) row = { name: "Test Contact", description: "original description", @@ -40,14 +38,14 @@ describe("/rows", () => { await request .post(`/api/${r ? r.tableId : row.tableId}/rows`) .send(r || row) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) const loadRow = async id => await request .get(`/api/${table._id}/rows/${id}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -74,7 +72,7 @@ describe("/rows", () => { tableId: table._id, name: "Updated Name", }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -88,7 +86,7 @@ describe("/rows", () => { const res = await request .get(`/api/${table._id}/rows/${existing._id}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -111,7 +109,7 @@ describe("/rows", () => { const res = await request .get(`/api/${table._id}/rows`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -133,7 +131,7 @@ describe("/rows", () => { const res = await request .post(`/api/rows/search`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .send({ keys: rowIds }) @@ -148,7 +146,7 @@ describe("/rows", () => { await createRow() await request .get(`/api/${table._id}/rows/not-a-valid-id`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(404) }) @@ -160,7 +158,7 @@ describe("/rows", () => { const number = {type:"number", constraints: { type: "number", presence: false }} const datetime = {type:"datetime", constraints: { type: "string", presence: false, datetime: {earliest:"", latest: ""} }} - table = await createTable(request, app._id, instance._id, { + table = await createTable(request, instanceId, { name: "TestTable2", type: "table", key: "name", @@ -256,7 +254,7 @@ describe("/rows", () => { tableId: table._id, name: "Updated Name", }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -277,7 +275,7 @@ describe("/rows", () => { const result = await request .post(`/api/${table._id}/rows/validate`) .send({ name: "ivan" }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -289,7 +287,7 @@ describe("/rows", () => { const result = await request .post(`/api/${table._id}/rows/validate`) .send({ name: 1 }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) diff --git a/packages/server/src/api/routes/tests/table.spec.js b/packages/server/src/api/routes/tests/table.spec.js index e3bc9d5f04..388e76f52a 100644 --- a/packages/server/src/api/routes/tests/table.spec.js +++ b/packages/server/src/api/routes/tests/table.spec.js @@ -1,8 +1,6 @@ const { - createInstance, - createTable, - supertest, - createClientDatabase, + createTable, + supertest, createApplication, defaultHeaders, builderEndpointShouldBlockNormalUsers, @@ -13,23 +11,22 @@ describe("/tables", () => { let request let server let app - let instance + let instanceId beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request) - app = await createApplication(request) }); - afterAll(async () => { - server.close(); + afterAll(done => { + server.close(done) }) - describe("create", () => { - beforeEach(async () => { - instance = await createInstance(request, app._id); - }); + beforeEach(async () => { + app = await createApplication(request) + instanceId = app.instances[0]._id + }); + describe("create", () => { it("returns a success message when the table is successfully created", done => { request .post(`/api/tables`) @@ -40,7 +37,7 @@ describe("/tables", () => { name: { type: "string" } } }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) .end(async (err, res) => { @@ -51,14 +48,14 @@ describe("/tables", () => { }) it("renames all the row fields for a table when a schema key is renamed", async () => { - const testTable = await createTable(request, app._id, instance._id); + const testTable = await createTable(request, instanceId); const testRow = await request .post(`/api/${testTable._id}/rows`) .send({ name: "test" }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -77,7 +74,7 @@ describe("/tables", () => { updatedName: { type: "string" } } }) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -86,7 +83,7 @@ describe("/tables", () => { const res = await request .get(`/api/${testTable._id}/rows/${testRow.body._id}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -99,8 +96,7 @@ describe("/tables", () => { request, method: "POST", url: `/api/tables`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, body: { name: "TestTable", key: "name", @@ -116,8 +112,7 @@ describe("/tables", () => { let testTable beforeEach(async () => { - instance = await createInstance(request, app._id) - testTable = await createTable(request, app._id, instance._id, testTable) + testTable = await createTable(request, instanceId, testTable) }); afterEach(() => { @@ -127,7 +122,7 @@ describe("/tables", () => { it("returns all the tables for that instance in the response body", done => { request .get(`/api/tables`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { @@ -143,8 +138,7 @@ describe("/tables", () => { request, method: "GET", url: `/api/tables`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, }) }) }); @@ -153,8 +147,7 @@ describe("/tables", () => { let testTable; beforeEach(async () => { - instance = await createInstance(request, app._id) - testTable = await createTable(request, app._id, instance._id, testTable) + testTable = await createTable(request, instanceId, testTable) }); afterEach(() => { @@ -164,7 +157,7 @@ describe("/tables", () => { it("returns a success response when a table is deleted.", async done => { request .delete(`/api/tables/${testTable._id}/${testTable._rev}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { @@ -174,7 +167,7 @@ describe("/tables", () => { }) it("deletes linked references to the table after deletion", async done => { - const linkedTable = await createTable(request, app._id, instance._id, { + const linkedTable = await createTable(request, instanceId, { name: "LinkedTable", type: "table", key: "name", @@ -197,12 +190,12 @@ describe("/tables", () => { request .delete(`/api/tables/${testTable._id}/${testTable._rev}`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { expect(res.res.statusMessage).toEqual(`Table ${testTable._id} deleted.`); - const dependentTable = await getDocument(instance._id, linkedTable._id) + const dependentTable = await getDocument(instanceId, linkedTable._id) expect(dependentTable.schema.TestTable).not.toBeDefined(); done(); }); @@ -213,8 +206,7 @@ describe("/tables", () => { request, method: "DELETE", url: `/api/tables/${testTable._id}/${testTable._rev}`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, }) }) diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index a17e6fe275..59a13ae8b4 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -1,7 +1,5 @@ -const { - createClientDatabase, +const { createApplication, - createInstance, supertest, defaultHeaders, createUser, @@ -17,30 +15,24 @@ describe("/users", () => { let request let server let app - let instance + let instanceId beforeAll(async () => { ({ request, server } = await supertest(server)) - await createClientDatabase(request) - app = await createApplication(request) }); beforeEach(async () => { - instance = await createInstance(request, app._id) + app = await createApplication(request) + instanceId = app.instances[0]._id }); - afterAll(async () => { - server.close(); - }) - - describe("fetch", () => { - + describe("fetch", () => { it("returns a list of users from an instance db", async () => { - await createUser(request, app._id, instance._id, "brenda", "brendas_password") - await createUser(request, app._id, instance._id, "pam", "pam_password") + await createUser(request, instanceId, "brenda", "brendas_password") + await createUser(request, instanceId, "pam", "pam_password") const res = await request .get(`/api/users`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) @@ -50,13 +42,12 @@ describe("/users", () => { }) it("should apply authorization to endpoint", async () => { - await createUser(request, app._id, instance._id, "brenda", "brendas_password") + await createUser(request, instanceId, "brenda", "brendas_password") await testPermissionsForEndpoint({ request, method: "GET", url: `/api/users`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, permissionName: LIST_USERS, }) }) @@ -68,7 +59,7 @@ describe("/users", () => { it("returns a success message when a user is successfully created", async () => { const res = await request .post(`/api/users`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .send({ name: "Bill", username: "bill", password: "bills_password", accessLevelId: POWERUSER_LEVEL_ID }) .expect(200) .expect('Content-Type', /json/) @@ -83,8 +74,7 @@ describe("/users", () => { method: "POST", body: { name: "brandNewUser", username: "brandNewUser", password: "yeeooo", accessLevelId: POWERUSER_LEVEL_ID }, url: `/api/users`, - instanceId: instance._id, - appId: app._id, + instanceId: instanceId, permissionName: USER_MANAGEMENT, }) }) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index 1265b37f5b..316014fa34 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -1,7 +1,5 @@ -const { - createClientDatabase, +const { createApplication, - createInstance, createTable, supertest, defaultHeaders, @@ -12,7 +10,7 @@ describe("/views", () => { let request let server let app - let instance + let instanceId let table const createView = async (config = { @@ -24,34 +22,33 @@ describe("/views", () => { await request .post(`/api/views`) .send(config) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) const createRow = async row => request .post(`/api/${table._id}/rows`) .send(row) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) beforeAll(async () => { ({ request, server } = await supertest()) - await createClientDatabase(request) - app = await createApplication(request) }) beforeEach(async () => { - instance = await createInstance(request, app._id) + app = await createApplication(request) + instanceId = app.instances[0]._id }) - afterAll(async () => { - server.close() + afterAll(done => { + server.close(done) }) describe("create", () => { beforeEach(async () => { - table = await createTable(request, app._id, instance._id); + table = await createTable(request, instanceId); }) it("returns a success message when the view is successfully created", async () => { @@ -62,7 +59,7 @@ describe("/views", () => { it("updates the table row with the new view metadata", async () => { const res = await createView() expect(res.res.statusMessage).toEqual("View TestView saved successfully."); - const updatedTable = await getDocument(instance._id, table._id) + const updatedTable = await getDocument(instanceId, table._id) expect(updatedTable.views).toEqual({ TestView: { field: "Price", @@ -99,14 +96,14 @@ describe("/views", () => { describe("fetch", () => { beforeEach(async () => { - table = await createTable(request, app._id, instance._id); + table = await createTable(request, instanceId); }); it("returns only custom views", async () => { await createView() const res = await request .get(`/api/views`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) expect(res.body.length).toBe(1) @@ -116,7 +113,7 @@ describe("/views", () => { describe("query", () => { beforeEach(async () => { - table = await createTable(request, app._id, instance._id); + table = await createTable(request, instanceId); }); it("returns data for the created view", async () => { @@ -135,7 +132,7 @@ describe("/views", () => { }) const res = await request .get(`/api/views/TestView?calculation=stats`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) expect(res.body.length).toBe(1) @@ -167,7 +164,7 @@ describe("/views", () => { }) const res = await request .get(`/api/views/TestView?calculation=stats&group=Category`) - .set(defaultHeaders(app._id, instance._id)) + .set(defaultHeaders(instanceId)) .expect('Content-Type', /json/) .expect(200) diff --git a/packages/server/src/app.js b/packages/server/src/app.js index 4157534365..15ae7126ad 100644 --- a/packages/server/src/app.js +++ b/packages/server/src/app.js @@ -30,7 +30,7 @@ app.context.auth = {} app.use(api.routes()) if (electron.app && electron.app.isPackaged) { - process.env.NODE_ENV = "production" + env._set("NODE_ENV", "production") Sentry.init() app.on("error", (err, ctx) => { diff --git a/packages/server/src/automations/actions.js b/packages/server/src/automations/actions.js index b2efae7809..4c282b1aea 100644 --- a/packages/server/src/automations/actions.js +++ b/packages/server/src/automations/actions.js @@ -4,7 +4,7 @@ const updateRow = require("./steps/updateRow") const deleteRow = require("./steps/deleteRow") const createUser = require("./steps/createUser") const outgoingWebhook = require("./steps/outgoingWebhook") -const environment = require("../environment") +const env = require("../environment") const download = require("download") const fetch = require("node-fetch") const { join } = require("../utilities/centralPath") @@ -33,8 +33,8 @@ const BUILTIN_DEFINITIONS = { OUTGOING_WEBHOOK: outgoingWebhook.definition, } -let AUTOMATION_BUCKET = environment.AUTOMATION_BUCKET -let AUTOMATION_DIRECTORY = environment.AUTOMATION_DIRECTORY +let AUTOMATION_BUCKET = env.AUTOMATION_BUCKET +let AUTOMATION_DIRECTORY = env.AUTOMATION_DIRECTORY let MANIFEST = null function buildBundleName(pkgName, version) { diff --git a/packages/server/src/automations/index.js b/packages/server/src/automations/index.js index f407e35a78..9332e5d449 100644 --- a/packages/server/src/automations/index.js +++ b/packages/server/src/automations/index.js @@ -1,6 +1,6 @@ const triggers = require("./triggers") const actions = require("./actions") -const environment = require("../environment") +const env = require("../environment") const workerFarm = require("worker-farm") const singleThread = require("./thread") const { getAPIKey, update, Properties } = require("../utilities/usageQuota") @@ -34,10 +34,10 @@ module.exports.init = function() { actions.init().then(() => { triggers.automationQueue.process(async job => { try { - if (environment.CLOUD && job.data.automation) { + if (env.CLOUD && job.data.automation) { job.data.automation.apiKey = await updateQuota(job.data.automation) } - if (environment.BUDIBASE_ENVIRONMENT === "PRODUCTION") { + if (env.BUDIBASE_ENVIRONMENT === "PRODUCTION") { await runWorker(job) } else { await singleThread(job) diff --git a/packages/server/src/automations/steps/createRow.js b/packages/server/src/automations/steps/createRow.js index f3049974a5..afc3d018ee 100644 --- a/packages/server/src/automations/steps/createRow.js +++ b/packages/server/src/automations/steps/createRow.js @@ -1,6 +1,6 @@ const rowController = require("../../api/controllers/row") const automationUtils = require("../automationUtils") -const environment = require("../../environment") +const env = require("../../environment") const usage = require("../../utilities/usageQuota") module.exports.definition = { @@ -80,7 +80,7 @@ module.exports.run = async function({ inputs, instanceId, apiKey }) { } try { - if (environment.CLOUD) { + if (env.CLOUD) { await usage.update(apiKey, usage.Properties.ROW, 1) } await rowController.save(ctx) diff --git a/packages/server/src/automations/steps/createUser.js b/packages/server/src/automations/steps/createUser.js index 2aee8e8d3a..38eeb5ae1e 100644 --- a/packages/server/src/automations/steps/createUser.js +++ b/packages/server/src/automations/steps/createUser.js @@ -1,6 +1,6 @@ const accessLevels = require("../../utilities/accessLevels") const userController = require("../../api/controllers/user") -const environment = require("../../environment") +const env = require("../../environment") const usage = require("../../utilities/usageQuota") module.exports.definition = { @@ -70,7 +70,7 @@ module.exports.run = async function({ inputs, instanceId, apiKey }) { } try { - if (environment.CLOUD) { + if (env.CLOUD) { await usage.update(apiKey, usage.Properties.USER, 1) } await userController.create(ctx) diff --git a/packages/server/src/automations/steps/deleteRow.js b/packages/server/src/automations/steps/deleteRow.js index 3858296e90..9bece74fa2 100644 --- a/packages/server/src/automations/steps/deleteRow.js +++ b/packages/server/src/automations/steps/deleteRow.js @@ -1,5 +1,5 @@ const rowController = require("../../api/controllers/row") -const environment = require("../../environment") +const env = require("../../environment") const usage = require("../../utilities/usageQuota") module.exports.definition = { @@ -65,7 +65,7 @@ module.exports.run = async function({ inputs, instanceId, apiKey }) { } try { - if (environment.CLOUD) { + if (env.CLOUD) { await usage.update(apiKey, usage.Properties.ROW, -1) } await rowController.destroy(ctx) diff --git a/packages/server/src/db/clientDb.js b/packages/server/src/db/clientDb.js deleted file mode 100644 index b85cd43110..0000000000 --- a/packages/server/src/db/clientDb.js +++ /dev/null @@ -1,26 +0,0 @@ -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}` -} diff --git a/packages/server/src/db/dynamoClient.js b/packages/server/src/db/dynamoClient.js index 6250486bf7..fcba726f84 100644 --- a/packages/server/src/db/dynamoClient.js +++ b/packages/server/src/db/dynamoClient.js @@ -1,7 +1,7 @@ let _ = require("lodash") -let environment = require("../environment") +let env = require("../environment") -const AWS_REGION = environment.AWS_REGION ? environment.AWS_REGION : "eu-west-1" +const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1" const TableInfo = { API_KEYS: { @@ -110,8 +110,8 @@ exports.init = endpoint => { } if (endpoint) { docClientParams.endpoint = endpoint - } else if (environment.DYNAMO_ENDPOINT) { - docClientParams.endpoint = environment.DYNAMO_ENDPOINT + } else if (env.DYNAMO_ENDPOINT) { + docClientParams.endpoint = env.DYNAMO_ENDPOINT } docClient = new AWS.DynamoDB.DocumentClient(docClientParams) } @@ -119,10 +119,10 @@ exports.init = endpoint => { exports.apiKeyTable = new Table(TableInfo.API_KEYS) exports.userTable = new Table(TableInfo.USERS) -if (environment.CLOUD) { +if (env.CLOUD) { exports.init(`https://dynamodb.${AWS_REGION}.amazonaws.com`) } else { - process.env.AWS_ACCESS_KEY_ID = "KEY_ID" - process.env.AWS_SECRET_ACCESS_KEY = "SECRET_KEY" + env._set("AWS_ACCESS_KEY_ID", "KEY_ID") + env._set("AWS_SECRET_ACCESS_KEY", "SECRET_KEY") exports.init("http://localhost:8333") } diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 673a340417..257f367478 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -12,6 +12,7 @@ const DocumentTypes = { APP: "app", ACCESS_LEVEL: "ac", WEBHOOK: "wh", + INSTANCE: "inst", } exports.DocumentTypes = DocumentTypes diff --git a/packages/server/src/environment.js b/packages/server/src/environment.js index 6e8c29cbb1..c6e180de1e 100644 --- a/packages/server/src/environment.js +++ b/packages/server/src/environment.js @@ -21,6 +21,7 @@ module.exports = { COUCH_DB_URL: process.env.COUCH_DB_URL, SALT_ROUNDS: process.env.SALT_ROUNDS, LOGGER: process.env.LOGGER, + LOG_LEVEL: process.env.LOG_LEVEL, AUTOMATION_DIRECTORY: process.env.AUTOMATION_DIRECTORY, AUTOMATION_BUCKET: process.env.AUTOMATION_BUCKET, BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT, @@ -30,4 +31,11 @@ module.exports = { AWS_REGION: process.env.AWS_REGION, DEPLOYMENT_CREDENTIALS_URL: process.env.DEPLOYMENT_CREDENTIALS_URL, BUDIBASE_API_KEY: process.env.BUDIBASE_API_KEY, + USERID_API_KEY: process.env.USERID_API_KEY, + ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, + DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL, + _set(key, value) { + process.env[key] = value + exports[key] = value + }, } diff --git a/packages/server/src/middleware/authenticated.js b/packages/server/src/middleware/authenticated.js index ba5da28f63..b62517e0f9 100644 --- a/packages/server/src/middleware/authenticated.js +++ b/packages/server/src/middleware/authenticated.js @@ -7,7 +7,7 @@ const { BUILDER_LEVEL_ID, ANON_LEVEL_ID, } = require("../utilities/accessLevels") -const environment = require("../environment") +const env = require("../environment") const { AuthTypes } = require("../constants") module.exports = async (ctx, next) => { @@ -21,7 +21,7 @@ module.exports = async (ctx, next) => { let token // if running locally in the builder itself - if (!environment.CLOUD && !appToken) { + if (!env.CLOUD && !appToken) { token = builderToken ctx.auth.authenticated = AuthTypes.BUILDER } else { @@ -32,7 +32,7 @@ module.exports = async (ctx, next) => { if (!token) { ctx.auth.authenticated = false - let appId = process.env.CLOUD ? ctx.subdomains[1] : ctx.params.appId + let appId = env.CLOUD ? ctx.subdomains[1] : ctx.params.appId // if appId can't be determined from path param or subdomain if (!appId && ctx.request.headers.referer) { diff --git a/packages/server/src/middleware/authorized.js b/packages/server/src/middleware/authorized.js index 9f9337b959..71ff5cc1e1 100644 --- a/packages/server/src/middleware/authorized.js +++ b/packages/server/src/middleware/authorized.js @@ -5,7 +5,7 @@ const { BUILDER_LEVEL_ID, BUILDER, } = require("../utilities/accessLevels") -const environment = require("../environment") +const env = require("../environment") const { apiKeyTable } = require("../db/dynamoClient") const { AuthTypes } = require("../constants") @@ -13,14 +13,10 @@ const LOCAL_PASS = new RegExp(["webhooks/trigger", "webhooks/schema"].join("|")) module.exports = (permName, getItemId) => async (ctx, next) => { // webhooks can pass locally - if (!environment.CLOUD && LOCAL_PASS.test(ctx.request.url)) { + if (!env.CLOUD && LOCAL_PASS.test(ctx.request.url)) { return next() } - if ( - environment.CLOUD && - ctx.headers["x-api-key"] && - ctx.headers["x-instanceid"] - ) { + if (env.CLOUD && ctx.headers["x-api-key"] && ctx.headers["x-instanceid"]) { // api key header passed by external webhook const apiKeyInfo = await apiKeyTable.get({ primary: ctx.headers["x-api-key"], @@ -41,7 +37,7 @@ module.exports = (permName, getItemId) => async (ctx, next) => { } // don't expose builder endpoints in the cloud - if (environment.CLOUD && permName === BUILDER) return + if (env.CLOUD && permName === BUILDER) return if (!ctx.auth.authenticated) { ctx.throw(403, "Session not authenticated") diff --git a/packages/server/src/middleware/usageQuota.js b/packages/server/src/middleware/usageQuota.js index eecaa75c8b..58e9c7eddc 100644 --- a/packages/server/src/middleware/usageQuota.js +++ b/packages/server/src/middleware/usageQuota.js @@ -1,6 +1,6 @@ const CouchDB = require("../db") const usageQuota = require("../utilities/usageQuota") -const environment = require("../environment") +const env = require("../environment") // currently only counting new writes and deletes const METHOD_MAP = { @@ -51,7 +51,7 @@ module.exports = async (ctx, next) => { : [ctx.request.files.file] usage = files.map(file => file.size).reduce((total, size) => total + size) } - if (!environment.CLOUD) { + if (!env.CLOUD) { return next() } try { diff --git a/packages/server/src/utilities/builder/index.js b/packages/server/src/utilities/builder/index.js index a74d5cd0b2..900d438636 100644 --- a/packages/server/src/utilities/builder/index.js +++ b/packages/server/src/utilities/builder/index.js @@ -30,10 +30,7 @@ module.exports.getPackageForBuilder = async (config, application) => { return { pages, - application, - - clientId: env.CLIENT_ID, } } diff --git a/packages/server/src/utilities/builder/setBuilderToken.js b/packages/server/src/utilities/builder/setBuilderToken.js index eb1155a207..06e95e7965 100644 --- a/packages/server/src/utilities/builder/setBuilderToken.js +++ b/packages/server/src/utilities/builder/setBuilderToken.js @@ -1,8 +1,8 @@ const { BUILDER_LEVEL_ID } = require("../accessLevels") -const environment = require("../../environment") +const env = require("../../environment") const jwt = require("jsonwebtoken") -module.exports = (ctx, appId, instanceId, version) => { +module.exports = (ctx, instanceId, version) => { const builderUser = { userId: "BUILDER", accessLevelId: BUILDER_LEVEL_ID, @@ -10,8 +10,8 @@ module.exports = (ctx, appId, instanceId, version) => { appId, version, } - if (environment.BUDIBASE_API_KEY) { - builderUser.apiKey = environment.BUDIBASE_API_KEY + if (env.BUDIBASE_API_KEY) { + builderUser.apiKey = env.BUDIBASE_API_KEY } const token = jwt.sign(builderUser, ctx.config.jwtSecret, { expiresIn: "30 days", diff --git a/packages/server/src/utilities/index.js b/packages/server/src/utilities/index.js index e17a01b173..da90941480 100644 --- a/packages/server/src/utilities/index.js +++ b/packages/server/src/utilities/index.js @@ -1,9 +1,11 @@ +const env = require("../environment") + exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms)) exports.isDev = () => { return ( - process.env.NODE_ENV !== "production" && - process.env.NODE_ENV !== "jest" && - process.env.NODE_ENV !== "cypress" + env.NODE_ENV !== "production" && + env.NODE_ENV !== "jest" && + env.NODE_ENV !== "cypress" ) } diff --git a/packages/server/src/utilities/initialiseBudibase.js b/packages/server/src/utilities/initialiseBudibase.js index be3253117c..4e6902a50f 100644 --- a/packages/server/src/utilities/initialiseBudibase.js +++ b/packages/server/src/utilities/initialiseBudibase.js @@ -7,13 +7,7 @@ module.exports = async opts => { await ensureDir(opts.dir) await setCouchDbUrl(opts) - // need an env file to create the client database - await createDevEnvFile(opts) - await createClientDatabase(opts) - - // need to recreate the env file, as we only now have a client id - // quiet flag will force overwrite of config - opts.quiet = true + // need an env file await createDevEnvFile(opts) } @@ -41,15 +35,3 @@ const createDevEnvFile = async opts => { await writeFile(destConfigFile, config, { flag: "w+" }) } } - -const createClientDatabase = async opts => { - // cannot be a top level require as it - // will cause environment module to be loaded prematurely - const clientDb = require("../db/clientDb") - - if (!opts.clientId || opts.clientId === "new") { - opts.clientId = uuid.v4() - } - - await clientDb.create(opts.clientId) -} diff --git a/packages/server/src/utilities/usageQuota.js b/packages/server/src/utilities/usageQuota.js index 33b2103582..81320eaec0 100644 --- a/packages/server/src/utilities/usageQuota.js +++ b/packages/server/src/utilities/usageQuota.js @@ -1,4 +1,4 @@ -const environment = require("../environment") +const env = require("../environment") const { apiKeyTable } = require("../db/dynamoClient") const DEFAULT_USAGE = { @@ -63,7 +63,7 @@ exports.getAPIKey = async appId => { */ exports.update = async (apiKey, property, usage) => { // don't try validate in builder - if (!environment.CLOUD) { + if (!env.CLOUD) { return } try { diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 1e28e09ece..f4ec257f9e 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1352,13 +1352,6 @@ axios@^0.19.2: dependencies: follow-redirects "1.5.10" -axios@^0.21.0: - version "0.21.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca" - integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw== - dependencies: - follow-redirects "^1.10.0" - babel-jest@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-24.9.0.tgz#3fc327cb8467b89d14d7bc70e315104a783ccd54" @@ -3185,11 +3178,6 @@ follow-redirects@1.5.10: dependencies: debug "=3.1.0" -follow-redirects@^1.10.0: - version "1.13.0" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" - integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== - for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" From ffc2c7bd5fddd966b1a05751a9d26e47c507da9f Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 28 Oct 2020 21:27:37 +0000 Subject: [PATCH 55/67] adding cloud check to dev check --- packages/server/src/utilities/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/utilities/index.js b/packages/server/src/utilities/index.js index e17a01b173..f162f25fb1 100644 --- a/packages/server/src/utilities/index.js +++ b/packages/server/src/utilities/index.js @@ -2,6 +2,7 @@ exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms)) exports.isDev = () => { return ( + !process.env.CLOUD && process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "jest" && process.env.NODE_ENV !== "cypress" From 7dee8d668350046b417d4184212e37bbdcf01e26 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 28 Oct 2020 21:30:51 +0000 Subject: [PATCH 56/67] v0.3.1 --- lerna.json | 2 +- packages/builder/package.json | 4 ++-- packages/client/package.json | 2 +- packages/server/package.json | 4 ++-- packages/standard-components/package.json | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lerna.json b/lerna.json index df346f7cb9..c3c28d7881 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.3.0", + "version": "0.3.1", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/builder/package.json b/packages/builder/package.json index 20c2360ae2..3aae8af2d6 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.3.0", + "version": "0.3.1", "license": "AGPL-3.0", "private": true, "scripts": { @@ -64,7 +64,7 @@ }, "dependencies": { "@budibase/bbui": "^1.47.0", - "@budibase/client": "^0.3.0", + "@budibase/client": "^0.3.1", "@budibase/colorpicker": "^1.0.1", "@budibase/svelte-ag-grid": "^0.0.16", "@fortawesome/fontawesome-free": "^5.14.0", diff --git a/packages/client/package.json b/packages/client/package.json index ba8ac5d811..3e16d3c33f 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.3.0", + "version": "0.3.1", "license": "MPL-2.0", "main": "dist/budibase-client.js", "module": "dist/budibase-client.esm.mjs", diff --git a/packages/server/package.json b/packages/server/package.json index c7909e5e28..74a45cee76 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/server", - "version": "0.3.0", + "version": "0.3.1", "description": "Budibase Web Server", "main": "src/electron.js", "repository": { @@ -40,7 +40,7 @@ "author": "Michael Shanks", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/client": "^0.3.0", + "@budibase/client": "^0.3.1", "@koa/router": "^8.0.0", "@sendgrid/mail": "^7.1.1", "@sentry/node": "^5.19.2", diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index 1888fa334e..519089ef35 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -13,7 +13,7 @@ "dev:builder": "rollup -cw" }, "devDependencies": { - "@budibase/client": "^0.3.0", + "@budibase/client": "^0.3.1", "@rollup/plugin-commonjs": "^11.1.0", "lodash": "^4.17.15", "rollup": "^2.11.2", @@ -31,7 +31,7 @@ "keywords": [ "svelte" ], - "version": "0.3.0", + "version": "0.3.1", "license": "MIT", "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "dependencies": { From f621cb0853663cfa9c4f6a92a1eb179fd68ba00c Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 28 Oct 2020 22:13:16 +0000 Subject: [PATCH 57/67] Some quick fixes. --- packages/server/src/api/routes/tests/accesslevel.spec.js | 1 - packages/server/src/api/routes/tests/application.spec.js | 1 - packages/server/src/api/routes/tests/automation.spec.js | 1 - packages/server/src/utilities/builder/setBuilderToken.js | 1 - 4 files changed, 4 deletions(-) diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index ae0453e44b..4f27bc8bc0 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -27,7 +27,6 @@ describe("/accesslevels", () => { afterAll(done => { server.close(done) - process.exit(0) }) beforeEach(async () => { diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index 285578b969..cbf84691e3 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -20,7 +20,6 @@ describe("/applications", () => { afterAll(done => { server.close(done) - process.exit(0) }) describe("create", () => { diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index b8e5897a4e..c28542c348 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -55,7 +55,6 @@ describe("/automations", () => { afterAll(done => { server.close(done) - process.exit(0) }) const createAutomation = async () => { diff --git a/packages/server/src/utilities/builder/setBuilderToken.js b/packages/server/src/utilities/builder/setBuilderToken.js index 06e95e7965..ff057a90eb 100644 --- a/packages/server/src/utilities/builder/setBuilderToken.js +++ b/packages/server/src/utilities/builder/setBuilderToken.js @@ -7,7 +7,6 @@ module.exports = (ctx, instanceId, version) => { userId: "BUILDER", accessLevelId: BUILDER_LEVEL_ID, instanceId, - appId, version, } if (env.BUDIBASE_API_KEY) { From fa00b6662db88b98a206592ecff8127c8942dd0e Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 28 Oct 2020 22:14:13 +0000 Subject: [PATCH 58/67] The removal of CLI package meant there was no way to init the system anymore so nuking budibase directory was unrecoverable, fixing this. --- packages/server/package.json | 3 ++- packages/server/scripts/initialise.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/server/scripts/initialise.js diff --git a/packages/server/package.json b/packages/server/package.json index c7909e5e28..bf34b1c54f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -32,7 +32,8 @@ "build:electron": "electron-builder --dir", "publish:electron": "electron-builder -mwl --publish always", "postinstall": "electron-builder install-app-deps", - "lint": "eslint --fix src/" + "lint": "eslint --fix src/", + "initialise": "node scripts/initialise.js" }, "keywords": [ "budibase" diff --git a/packages/server/scripts/initialise.js b/packages/server/scripts/initialise.js new file mode 100644 index 0000000000..485ebd56a0 --- /dev/null +++ b/packages/server/scripts/initialise.js @@ -0,0 +1,17 @@ +const { join } = require("path") +const { homedir } = require("os") + +const initialiseBudibase = require("../src/utilities/initialiseBudibase") +const DIRECTORY = "~/.budibase" + +function run() { + let opts = {} + let dir = DIRECTORY + opts.quiet = true + opts.dir = dir.startsWith("~") ? join(homedir(), dir.substring(1)) : dir + return initialiseBudibase(opts) +} + +run().then(() => { + console.log("Init complete.") +}) From e74d754f3260b86498cff85e799d155c4672f04a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 28 Oct 2020 22:21:41 +0000 Subject: [PATCH 59/67] fixing attachment height --- .../DataTable/cells/AttachmentCell.svelte | 17 +++++++++++------ .../backend/DataTable/cells/cellRenderers.js | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/cells/AttachmentCell.svelte b/packages/builder/src/components/backend/DataTable/cells/AttachmentCell.svelte index ed97fd366c..b8169f1398 100644 --- a/packages/builder/src/components/backend/DataTable/cells/AttachmentCell.svelte +++ b/packages/builder/src/components/backend/DataTable/cells/AttachmentCell.svelte @@ -12,8 +12,8 @@ {#if FILE_TYPES.IMAGE.includes(file.extension.toLowerCase())} {:else} - .{file.extension} + {file.name} {/if} @@ -33,12 +33,12 @@ } i { - font-size: 36px; - margin-bottom: var(--spacing-m); + font-size: 24px; + position: relative; + top: 5px; } .file { - position: relative; height: 75px; width: 75px; border: 2px dashed var(--grey-7); @@ -46,18 +46,23 @@ display: flex; flex-direction: column; align-items: center; + position: relative; justify-content: center; + overflow: hidden; + text-overflow: ellipsis; } .extension { position: absolute; - top: var(--spacing-s); - left: var(--spacing-s); + top: -5px; + font-size: var(--font-size-xs); font-weight: 500; } span { + font-size: var(--font-size-xs); width: 75px; + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } diff --git a/packages/builder/src/components/backend/DataTable/cells/cellRenderers.js b/packages/builder/src/components/backend/DataTable/cells/cellRenderers.js index 17165f9437..209f23119f 100644 --- a/packages/builder/src/components/backend/DataTable/cells/cellRenderers.js +++ b/packages/builder/src/components/backend/DataTable/cells/cellRenderers.js @@ -31,6 +31,9 @@ export function deleteRowRenderer(params) { export function editRowRenderer(params) { const container = document.createElement("div") + container.style.height = "100%" + container.style.display = "flex" + container.style.alignItems = "center" new EditRow({ target: container, @@ -46,6 +49,9 @@ export function editRowRenderer(params) { function attachmentRenderer(options, constraints, editable) { return params => { const container = document.createElement("div") + container.style.height = "100%" + container.style.display = "flex" + container.style.alignItems = "center" const attachmentInstance = new AttachmentList({ target: container, @@ -64,6 +70,7 @@ function linkedRowRenderer() { let container = document.createElement("div") container.style.display = "grid" container.style.height = "100%" + container.style.alignItems = "center" new RelationshipDisplay({ target: container, From 56f1170ae9ad314762f4880952e9f1f0f2f1a68d Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 28 Oct 2020 22:24:44 +0000 Subject: [PATCH 60/67] Fixing an issue with env variables not getting set correctly. --- packages/server/src/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/environment.js b/packages/server/src/environment.js index c6e180de1e..28fa74ddcd 100644 --- a/packages/server/src/environment.js +++ b/packages/server/src/environment.js @@ -36,6 +36,6 @@ module.exports = { DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL, _set(key, value) { process.env[key] = value - exports[key] = value + module.exports[key] = value }, } From 66e3e3b7a437d70e0a05609ebfb5df3ba38631cf Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 28 Oct 2020 22:37:58 +0000 Subject: [PATCH 61/67] Fixing test cases. --- packages/server/src/api/routes/tests/accesslevel.spec.js | 4 ++-- packages/server/src/api/routes/tests/application.spec.js | 4 ++-- packages/server/src/api/routes/tests/automation.spec.js | 4 ++-- packages/server/src/api/routes/tests/couchTestUtils.js | 8 ++++---- packages/server/src/api/routes/tests/instance.spec.js | 4 ++-- packages/server/src/api/routes/tests/row.spec.js | 4 ++-- packages/server/src/api/routes/tests/table.spec.js | 4 ++-- packages/server/src/api/routes/tests/user.spec.js | 5 +++++ packages/server/src/api/routes/tests/view.spec.js | 4 ++-- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index 4f27bc8bc0..1bc540c046 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -25,8 +25,8 @@ describe("/accesslevels", () => { ({ request, server } = await supertest()) }); - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) beforeEach(async () => { diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index cbf84691e3..179aa1b3ca 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -18,8 +18,8 @@ describe("/applications", () => { await clearApplications(request) }) - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) describe("create", () => { diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index c28542c348..6bda1b7708 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -53,8 +53,8 @@ describe("/automations", () => { if (automation) await destroyDocument(automation.id) }) - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) const createAutomation = async () => { diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index 12f9e11908..df50e3cd7c 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -15,12 +15,12 @@ const TEST_CLIENT_ID = "test-client-id" exports.TEST_CLIENT_ID = TEST_CLIENT_ID exports.supertest = async () => { let request - let app + let server env.PORT = 4002 - app = require("../../../app") + server = require("../../../app") - request = supertest(app) - return { request, app } + request = supertest(server) + return { request, server } } exports.defaultHeaders = instanceId => { diff --git a/packages/server/src/api/routes/tests/instance.spec.js b/packages/server/src/api/routes/tests/instance.spec.js index 86fd4b8920..180d7f44e6 100644 --- a/packages/server/src/api/routes/tests/instance.spec.js +++ b/packages/server/src/api/routes/tests/instance.spec.js @@ -14,8 +14,8 @@ describe("/instances", () => { TEST_APP_ID = (await createApplication(request))._id }); - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) describe("create", () => { diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index 31098c51e4..bd447513f3 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -18,8 +18,8 @@ describe("/rows", () => { }); - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) beforeEach(async () => { diff --git a/packages/server/src/api/routes/tests/table.spec.js b/packages/server/src/api/routes/tests/table.spec.js index 388e76f52a..0c0f64050f 100644 --- a/packages/server/src/api/routes/tests/table.spec.js +++ b/packages/server/src/api/routes/tests/table.spec.js @@ -17,8 +17,8 @@ describe("/tables", () => { ({ request, server } = await supertest()) }); - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) beforeEach(async () => { diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index 59a13ae8b4..010f735c4a 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -26,6 +26,11 @@ describe("/users", () => { instanceId = app.instances[0]._id }); + afterAll(() => { + server.close() + server.destroy() + }) + describe("fetch", () => { it("returns a list of users from an instance db", async () => { await createUser(request, instanceId, "brenda", "brendas_password") diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index 316014fa34..ec30f10f3f 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -42,8 +42,8 @@ describe("/views", () => { instanceId = app.instances[0]._id }) - afterAll(done => { - server.close(done) + afterAll(() => { + server.close() }) describe("create", () => { From 08b0834fe2bda1089d73a763ddac077193ebb812 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 10:21:06 +0000 Subject: [PATCH 62/67] Removing instance API as it was un-used and simplifying the nature of an instance. --- .../builder/src/builderStore/store/index.js | 4 +- .../pages/[application]/design/_layout.svelte | 6 +-- .../server/src/api/controllers/application.js | 46 ++++++++++++----- .../server/src/api/controllers/instance.js | 46 ----------------- packages/server/src/api/index.js | 4 -- packages/server/src/api/routes/index.js | 2 - packages/server/src/api/routes/instance.js | 12 ----- .../src/api/routes/tests/accesslevel.spec.js | 2 +- .../src/api/routes/tests/application.spec.js | 4 +- .../src/api/routes/tests/automation.spec.js | 2 +- .../src/api/routes/tests/couchTestUtils.js | 10 ---- .../src/api/routes/tests/instance.spec.js | 49 ------------------- .../server/src/api/routes/tests/row.spec.js | 2 +- .../server/src/api/routes/tests/table.spec.js | 2 +- .../server/src/api/routes/tests/user.spec.js | 2 +- .../server/src/api/routes/tests/view.spec.js | 2 +- 16 files changed, 47 insertions(+), 148 deletions(-) delete mode 100644 packages/server/src/api/controllers/instance.js delete mode 100644 packages/server/src/api/routes/instance.js delete mode 100644 packages/server/src/api/routes/tests/instance.spec.js diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index 9069682304..0aa3d69ecd 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -137,10 +137,10 @@ const setPackage = (store, initial) => async pkg => { ...Object.values(unauth_screens), ] initial.builtins = [getBuiltin("##builtin/screenslot")] - initial.appInstances = pkg.application.instances + initial.appInstance = pkg.application.instance initial.appId = pkg.application._id store.set(initial) - await backendUiStore.actions.database.select(initial.appInstances[0]) + await backendUiStore.actions.database.select(initial.appInstance) return initial } diff --git a/packages/builder/src/pages/[application]/design/_layout.svelte b/packages/builder/src/pages/[application]/design/_layout.svelte index 13f2b4ee53..c4c67c796e 100644 --- a/packages/builder/src/pages/[application]/design/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/_layout.svelte @@ -7,15 +7,15 @@ import { last } from "lodash/fp" import FrontendNavigatePane from "components/userInterface/FrontendNavigatePane.svelte" - $: instances = $store.appInstances + $: instance = $store.appInstance async function selectDatabase(database) { backendUiStore.actions.database.select(database) } onMount(async () => { - if ($store.appInstances.length > 0 && !$backendUiStore.database) { - await selectDatabase($store.appInstances[0]) + if ($store.appInstance && !$backendUiStore.database) { + await selectDatabase($store.appInstance) } }) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 9f0fdbc524..5e538eb38f 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -1,7 +1,6 @@ const CouchDB = require("../../db") const { getPackageForBuilder, buildPage } = require("../../utilities/builder") const env = require("../../environment") -const instanceController = require("./instance") const { copy, existsSync, readFile, writeFile } = require("fs-extra") const { budibaseAppsDir } = require("../../utilities/budibaseDir") const sqrl = require("squirrelly") @@ -11,12 +10,42 @@ const { join, resolve } = require("../../utilities/centralPath") const { promisify } = require("util") const chmodr = require("chmodr") const packageJson = require("../../../package.json") -const { DocumentTypes, SEPARATOR } = require("../../db/utils") +const { createLinkView } = require("../../db/linkedRows") +const { downloadTemplate } = require("../../utilities/templates") +const { generateAppID, DocumentTypes, SEPARATOR } = require("../../db/utils") const { downloadExtractComponentLibraries, } = require("../../utilities/createAppPackage") const APP_PREFIX = DocumentTypes.APP + SEPARATOR +async function createInstance(template) { + const instanceId = generateAppID() + + const db = new CouchDB(instanceId) + await db.put({ + _id: "_design/database", + // view collation information, read before writing any complex views: + // https://docs.couchdb.org/en/master/ddocs/views/collation.html#collation-specification + views: {}, + }) + // add view for linked rows + await createLinkView(instanceId) + + // replicate the template data to the instance DB + if (template) { + const templatePath = await downloadTemplate(...template.key.split("/")) + const dbDumpReadStream = fs.createReadStream( + join(templatePath, "db", "dump.txt") + ) + const { ok } = await db.load(dbDumpReadStream) + if (!ok) { + throw "Error loading database dump from template." + } + } + + return { _id: instanceId } +} + exports.fetch = async function(ctx) { let allDbs = await CouchDB.allDbs() const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX)) @@ -40,15 +69,8 @@ exports.fetchAppPackage = async function(ctx) { } exports.create = async function(ctx) { - const createInstCtx = { - request: { - body: { - template: ctx.request.body.template, - }, - }, - } - await instanceController.create(createInstCtx) - const instanceId = createInstCtx.body._id + const instance = await createInstance(ctx.request.body.template) + const instanceId = instance._id const newApplication = { _id: instanceId, type: "app", @@ -57,7 +79,7 @@ exports.create = async function(ctx) { componentLibraries: ["@budibase/standard-components"], name: ctx.request.body.name, template: ctx.request.body.template, - instances: [createInstCtx.body], + instance: instance, } const instanceDb = new CouchDB(instanceId) await instanceDb.put(newApplication) diff --git a/packages/server/src/api/controllers/instance.js b/packages/server/src/api/controllers/instance.js deleted file mode 100644 index 9879919540..0000000000 --- a/packages/server/src/api/controllers/instance.js +++ /dev/null @@ -1,46 +0,0 @@ -const fs = require("fs") -const CouchDB = require("../../db") -const { createLinkView } = require("../../db/linkedRows") -const { join } = require("../../utilities/centralPath") -const { downloadTemplate } = require("../../utilities/templates") -const { generateAppID } = require("../../db/utils") - -exports.create = async function(ctx) { - const instanceName = ctx.request.body.name - const template = ctx.request.body.template - const instanceId = generateAppID() - - const db = new CouchDB(instanceId) - await db.put({ - _id: "_design/database", - // view collation information, read before writing any complex views: - // https://docs.couchdb.org/en/master/ddocs/views/collation.html#collation-specification - views: {}, - }) - // add view for linked rows - await createLinkView(instanceId) - - // replicate the template data to the instance DB - if (template) { - const templatePath = await downloadTemplate(...template.key.split("/")) - const dbDumpReadStream = fs.createReadStream( - join(templatePath, "db", "dump.txt") - ) - const { ok } = await db.load(dbDumpReadStream) - if (!ok) { - ctx.throw(500, "Error loading database dump from template.") - } - } - - ctx.status = 200 - ctx.message = `Instance Database ${instanceName} successfully provisioned.` - ctx.body = { _id: instanceId, name: instanceName } -} - -exports.destroy = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) - await db.destroy() - - ctx.status = 200 - ctx.message = `Instance Database ${ctx.params.instanceId} successfully destroyed.` -} diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index e9418c518a..0fbd65501b 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -9,7 +9,6 @@ const { pageRoutes, userRoutes, deployRoutes, - instanceRoutes, applicationRoutes, rowRoutes, tableRoutes, @@ -82,9 +81,6 @@ router.use(rowRoutes.allowedMethods()) router.use(userRoutes.routes()) router.use(userRoutes.allowedMethods()) -router.use(instanceRoutes.routes()) -router.use(instanceRoutes.allowedMethods()) - router.use(automationRoutes.routes()) router.use(automationRoutes.allowedMethods()) diff --git a/packages/server/src/api/routes/index.js b/packages/server/src/api/routes/index.js index 434def06b5..0025c5fabf 100644 --- a/packages/server/src/api/routes/index.js +++ b/packages/server/src/api/routes/index.js @@ -1,7 +1,6 @@ const authRoutes = require("./auth") const pageRoutes = require("./pages") const userRoutes = require("./user") -const instanceRoutes = require("./instance") const applicationRoutes = require("./application") const tableRoutes = require("./table") const rowRoutes = require("./row") @@ -21,7 +20,6 @@ module.exports = { authRoutes, pageRoutes, userRoutes, - instanceRoutes, applicationRoutes, rowRoutes, tableRoutes, diff --git a/packages/server/src/api/routes/instance.js b/packages/server/src/api/routes/instance.js deleted file mode 100644 index 00fce6bb12..0000000000 --- a/packages/server/src/api/routes/instance.js +++ /dev/null @@ -1,12 +0,0 @@ -const Router = require("@koa/router") -const controller = require("../controllers/instance") -const authorized = require("../../middleware/authorized") -const { BUILDER } = require("../../utilities/accessLevels") - -const router = Router() - -router - .post("/api/instances", authorized(BUILDER), controller.create) - .delete("/api/instances/:instanceId", authorized(BUILDER), controller.destroy) - -module.exports = router diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index 1bc540c046..d7958c8f32 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -31,7 +31,7 @@ describe("/accesslevels", () => { beforeEach(async () => { let app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id table = await createTable(request, instanceId) view = await createView(request, instanceId, table._id) }) diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index 179aa1b3ca..6d30701a29 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -36,7 +36,7 @@ describe("/applications", () => { it("should apply authorization to endpoint", async () => { const otherApplication = await createApplication(request) - const instanceId = otherApplication.instances[0]._id + const instanceId = otherApplication.instance._id await builderEndpointShouldBlockNormalUsers({ request, method: "POST", @@ -64,7 +64,7 @@ describe("/applications", () => { it("should apply authorization to endpoint", async () => { const otherApplication = await createApplication(request) - const instanceId = otherApplication.instances[0]._id + const instanceId = otherApplication.instance._id await builderEndpointShouldBlockNormalUsers({ request, method: "GET", diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index 6bda1b7708..fa78cccf0d 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -49,7 +49,7 @@ describe("/automations", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id if (automation) await destroyDocument(automation.id) }) diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index df50e3cd7c..25b8dd964e 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -109,16 +109,6 @@ exports.clearApplications = async request => { } } -exports.createInstance = async request => { - const res = await request - .post(`/api/instances`) - .send({ - name: "test-instance2", - }) - .set(exports.defaultHeaders()) - return res.body -} - exports.createUser = async ( request, instanceId, diff --git a/packages/server/src/api/routes/tests/instance.spec.js b/packages/server/src/api/routes/tests/instance.spec.js deleted file mode 100644 index 180d7f44e6..0000000000 --- a/packages/server/src/api/routes/tests/instance.spec.js +++ /dev/null @@ -1,49 +0,0 @@ -const { - createInstance, - createApplication, - supertest, - defaultHeaders -} = require("./couchTestUtils"); - -describe("/instances", () => { - let TEST_APP_ID; - let server - let request - beforeAll(async () => { - ({ request, server } = await supertest()) - TEST_APP_ID = (await createApplication(request))._id - }); - - afterAll(() => { - server.close() - }) - - describe("create", () => { - - it("returns a success message when the instance database is successfully created", async () => { - const res = await request - .post(`/api/instances`) - .send({ name: "test-instance" }) - .set(defaultHeaders()) - .expect('Content-Type', /json/) - .expect(200) - - expect(res.res.statusMessage).toEqual("Instance Database test-instance successfully provisioned."); - expect(res.body._id).toBeDefined(); - - }) - }); - - describe("destroy", () => { - - it("returns a success message when the instance database is successfully deleted", async () => { - const instance = await createInstance(request, TEST_APP_ID); - const res = await request - .delete(`/api/instances/${instance._id}`) - .set(defaultHeaders()) - .expect(200) - - expect(res.res.statusMessage).toEqual(`Instance Database ${instance._id} successfully destroyed.`); - }) - }); -}); diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index bd447513f3..31f273216f 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -24,7 +24,7 @@ describe("/rows", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id table = await createTable(request, instanceId) row = { name: "Test Contact", diff --git a/packages/server/src/api/routes/tests/table.spec.js b/packages/server/src/api/routes/tests/table.spec.js index 0c0f64050f..193bfb50a6 100644 --- a/packages/server/src/api/routes/tests/table.spec.js +++ b/packages/server/src/api/routes/tests/table.spec.js @@ -23,7 +23,7 @@ describe("/tables", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id }); describe("create", () => { diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index 010f735c4a..497a654fc3 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -23,7 +23,7 @@ describe("/users", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id }); afterAll(() => { diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index ec30f10f3f..0419e7326c 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -39,7 +39,7 @@ describe("/views", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instances[0]._id + instanceId = app.instance._id }) afterAll(() => { From 5b2be03bc306c74a47411d042665b5148104b6c7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 10:28:27 +0000 Subject: [PATCH 63/67] Renaming instanceId -> appId to reduce confusion through the system, there only is one ID now. --- packages/server/scripts/exportAppTemplate.js | 7 +- .../server/src/api/controllers/accesslevel.js | 16 ++--- .../server/src/api/controllers/application.js | 30 ++++---- packages/server/src/api/controllers/auth.js | 11 ++- .../server/src/api/controllers/automation.js | 20 +++--- .../server/src/api/controllers/component.js | 6 +- .../server/src/api/controllers/deploy/aws.js | 12 ++-- .../src/api/controllers/deploy/index.js | 29 ++++---- packages/server/src/api/controllers/row.js | 72 +++++++++---------- packages/server/src/api/controllers/static.js | 10 +-- packages/server/src/api/controllers/table.js | 20 +++--- .../server/src/api/controllers/templates.js | 3 +- packages/server/src/api/controllers/user.js | 14 ++-- .../server/src/api/controllers/view/index.js | 6 +- .../server/src/api/controllers/webhook.js | 8 +-- packages/server/src/api/routes/application.js | 6 +- packages/server/src/api/routes/component.js | 2 +- .../src/api/routes/tests/accesslevel.spec.js | 36 +++++----- .../src/api/routes/tests/application.spec.js | 8 +-- .../src/api/routes/tests/automation.spec.js | 34 ++++----- .../src/api/routes/tests/couchTestUtils.js | 56 +++++++-------- .../server/src/api/routes/tests/row.spec.js | 28 ++++---- .../server/src/api/routes/tests/table.spec.js | 34 ++++----- .../server/src/api/routes/tests/user.spec.js | 18 ++--- .../server/src/api/routes/tests/view.spec.js | 22 +++--- .../server/src/automations/automationUtils.js | 14 ++-- .../server/src/automations/steps/createRow.js | 6 +- .../src/automations/steps/createUser.js | 4 +- .../server/src/automations/steps/deleteRow.js | 4 +- .../server/src/automations/steps/updateRow.js | 6 +- packages/server/src/automations/thread.js | 8 +-- packages/server/src/automations/triggers.js | 8 +-- .../src/db/linkedRows/LinkController.js | 10 +-- packages/server/src/db/linkedRows/index.js | 12 ++-- .../server/src/db/linkedRows/linkUtils.js | 14 ++-- packages/server/src/events/index.js | 8 +-- .../server/src/middleware/authenticated.js | 10 +-- packages/server/src/middleware/authorized.js | 2 +- packages/server/src/middleware/usageQuota.js | 2 +- .../appDirectoryTemplate/pages/main/page.json | 6 +- .../d834fea2-1b3e-4320-ab34-f9009f5ecc59.json | 6 +- .../src/utilities/builder/setBuilderToken.js | 4 +- packages/server/src/utilities/permissions.js | 12 ++-- packages/server/src/utilities/templates.js | 8 +-- 44 files changed, 319 insertions(+), 333 deletions(-) diff --git a/packages/server/scripts/exportAppTemplate.js b/packages/server/scripts/exportAppTemplate.js index 95ab8c718c..4ae2f729ae 100755 --- a/packages/server/scripts/exportAppTemplate.js +++ b/packages/server/scripts/exportAppTemplate.js @@ -3,7 +3,7 @@ const { exportTemplateFromApp } = require("../src/utilities/templates") const yargs = require("yargs") // Script to export a chosen budibase app into a package -// Usage: ./scripts/exportAppTemplate.js export --name=Funky --instanceId=someInstanceId --appId=appId +// Usage: ./scripts/exportAppTemplate.js export --name=Funky --appId=someInstanceId --appId=appId yargs .command( @@ -15,8 +15,8 @@ yargs alias: "n", type: "string", }, - instanceId: { - description: "The instanceId to dump the database for", + appId: { + description: "The appId to dump the database for", alias: "inst", type: "string", }, @@ -30,7 +30,6 @@ yargs console.log("Exporting app..") const exportPath = await exportTemplateFromApp({ templateName: args.name, - instanceId: args.instanceId, appId: args.appId, }) console.log(`Template ${args.name} exported to ${exportPath}`) diff --git a/packages/server/src/api/controllers/accesslevel.js b/packages/server/src/api/controllers/accesslevel.js index ab145a1b76..143c633e42 100644 --- a/packages/server/src/api/controllers/accesslevel.js +++ b/packages/server/src/api/controllers/accesslevel.js @@ -11,7 +11,7 @@ const { } = require("../../db/utils") exports.fetch = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const body = await db.allDocs( getAccessLevelParams(null, { include_docs: true, @@ -23,12 +23,12 @@ exports.fetch = async function(ctx) { { _id: ADMIN_LEVEL_ID, name: "Admin", - permissions: await generateAdminPermissions(ctx.user.instanceId), + permissions: await generateAdminPermissions(ctx.user.appId), }, { _id: POWERUSER_LEVEL_ID, name: "Power User", - permissions: await generatePowerUserPermissions(ctx.user.instanceId), + permissions: await generatePowerUserPermissions(ctx.user.appId), }, ] @@ -36,12 +36,12 @@ exports.fetch = async function(ctx) { } exports.find = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) ctx.body = await db.get(ctx.params.levelId) } exports.update = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const level = await db.get(ctx.params.levelId) level.name = ctx.body.name level.permissions = ctx.request.body.permissions @@ -52,7 +52,7 @@ exports.update = async function(ctx) { } exports.patch = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const level = await db.get(ctx.params.levelId) const { removedPermissions, addedPermissions, _rev } = ctx.request.body @@ -88,7 +88,7 @@ exports.patch = async function(ctx) { } exports.create = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const level = { name: ctx.request.body.name, @@ -105,7 +105,7 @@ exports.create = async function(ctx) { } exports.destroy = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) await db.remove(ctx.params.levelId, ctx.params.rev) ctx.message = `Access Level ${ctx.params.id} deleted successfully` ctx.status = 200 diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 5e538eb38f..0765d50f6d 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -19,9 +19,9 @@ const { const APP_PREFIX = DocumentTypes.APP + SEPARATOR async function createInstance(template) { - const instanceId = generateAppID() + const appId = generateAppID() - const db = new CouchDB(instanceId) + const db = new CouchDB(appId) await db.put({ _id: "_design/database", // view collation information, read before writing any complex views: @@ -29,7 +29,7 @@ async function createInstance(template) { views: {}, }) // add view for linked rows - await createLinkView(instanceId) + await createLinkView(appId) // replicate the template data to the instance DB if (template) { @@ -43,7 +43,7 @@ async function createInstance(template) { } } - return { _id: instanceId } + return { _id: appId } } exports.fetch = async function(ctx) { @@ -62,17 +62,17 @@ exports.fetch = async function(ctx) { } exports.fetchAppPackage = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) - const application = await db.get(ctx.params.instanceId) + const db = new CouchDB(ctx.params.appId) + const application = await db.get(ctx.params.appId) ctx.body = await getPackageForBuilder(ctx.config, application) - setBuilderToken(ctx, ctx.params.instanceId, application.version) + setBuilderToken(ctx, ctx.params.appId, application.version) } exports.create = async function(ctx) { const instance = await createInstance(ctx.request.body.template) - const instanceId = instance._id + const appId = instance._id const newApplication = { - _id: instanceId, + _id: appId, type: "app", userInstanceMap: {}, version: packageJson.version, @@ -81,7 +81,7 @@ exports.create = async function(ctx) { template: ctx.request.body.template, instance: instance, } - const instanceDb = new CouchDB(instanceId) + const instanceDb = new CouchDB(appId) await instanceDb.put(newApplication) if (env.NODE_ENV !== "jest") { @@ -95,8 +95,8 @@ exports.create = async function(ctx) { } exports.update = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) - const application = await db.get(ctx.params.instanceId) + const db = new CouchDB(ctx.params.appId) + const application = await db.get(ctx.params.appId) const data = ctx.request.body const newData = { ...application, ...data } @@ -110,12 +110,12 @@ exports.update = async function(ctx) { } exports.delete = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) - const app = await db.get(ctx.params.instanceId) + const db = new CouchDB(ctx.params.appId) + const app = await db.get(ctx.params.appId) const result = await db.destroy() // remove top level directory - await fs.rmdir(join(budibaseAppsDir(), ctx.params.instanceId), { + await fs.rmdir(join(budibaseAppsDir(), ctx.params.appId), { recursive: true, }) diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index eb5fd8d11f..9576d22da1 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -6,8 +6,8 @@ const { getAPIKey } = require("../../utilities/usageQuota") const { generateUserID } = require("../../db/utils") exports.authenticate = async ctx => { - const instanceId = ctx.user.instanceId - if (!instanceId) ctx.throw(400, "No instanceId") + const appId = ctx.user.appId + if (!appId) ctx.throw(400, "No appId") const { username, password } = ctx.request.body @@ -15,8 +15,8 @@ exports.authenticate = async ctx => { if (!password) ctx.throw(400, "Password Required.") // Check the user exists in the instance DB by username - const db = new CouchDB(instanceId) - const app = await db.get(instanceId) + const db = new CouchDB(appId) + const app = await db.get(appId) let dbUser try { @@ -32,9 +32,8 @@ exports.authenticate = async ctx => { const payload = { userId: dbUser._id, accessLevelId: dbUser.accessLevelId, - appId: ctx.user.appId, version: app.version, - instanceId, + appId, } // if in cloud add the user api key if (env.CLOUD) { diff --git a/packages/server/src/api/controllers/automation.js b/packages/server/src/api/controllers/automation.js index 2127c0a661..5fa618654b 100644 --- a/packages/server/src/api/controllers/automation.js +++ b/packages/server/src/api/controllers/automation.js @@ -56,7 +56,7 @@ async function checkForWebhooks({ user, oldAuto, newAuto }) { !isWebhookTrigger(newAuto) && oldTrigger.webhookId ) { - let db = new CouchDB(user.instanceId) + let db = new CouchDB(user.appId) // need to get the webhook to get the rev const webhook = await db.get(oldTrigger.webhookId) const ctx = { @@ -86,15 +86,15 @@ async function checkForWebhooks({ user, oldAuto, newAuto }) { const id = ctx.body.webhook._id newTrigger.webhookId = id newTrigger.inputs = { - schemaUrl: `api/webhooks/schema/${user.instanceId}/${id}`, - triggerUrl: `api/webhooks/trigger/${user.instanceId}/${id}`, + schemaUrl: `api/webhooks/schema/${user.appId}/${id}`, + triggerUrl: `api/webhooks/trigger/${user.appId}/${id}`, } } return newAuto } exports.create = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) let automation = ctx.request.body automation.appId = ctx.user.appId @@ -117,7 +117,7 @@ exports.create = async function(ctx) { } exports.update = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) let automation = ctx.request.body automation.appId = ctx.user.appId const oldAutomation = await db.get(automation._id) @@ -142,7 +142,7 @@ exports.update = async function(ctx) { } exports.fetch = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const response = await db.allDocs( getAutomationParams(null, { include_docs: true, @@ -152,12 +152,12 @@ exports.fetch = async function(ctx) { } exports.find = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) ctx.body = await db.get(ctx.params.id) } exports.destroy = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const oldAutomation = await db.get(ctx.params.id) await checkForWebhooks({ user: ctx.user, oldAuto: oldAutomation }) ctx.body = await db.remove(ctx.params.id, ctx.params.rev) @@ -190,11 +190,11 @@ module.exports.getDefinitionList = async function(ctx) { *********************/ exports.trigger = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) let automation = await db.get(ctx.params.id) await triggers.externalTrigger(automation, { ...ctx.request.body, - instanceId: ctx.user.instanceId, + appId: ctx.user.appId, }) ctx.status = 200 ctx.body = { diff --git a/packages/server/src/api/controllers/component.js b/packages/server/src/api/controllers/component.js index e6c25b2d83..c58e40eadc 100644 --- a/packages/server/src/api/controllers/component.js +++ b/packages/server/src/api/controllers/component.js @@ -6,13 +6,13 @@ const { } = require("../../utilities/budibaseDir") exports.fetchAppComponentDefinitions = async function(ctx) { - const db = new CouchDB(ctx.params.instanceId) - const app = await db.get(ctx.params.instanceId) + const db = new CouchDB(ctx.params.appId) + const app = await db.get(ctx.params.appId) ctx.body = app.componentLibraries.reduce((acc, componentLibrary) => { let appDirectory = resolve( budibaseAppsDir(), - ctx.params.instanceId, + ctx.params.appId, "node_modules" ) diff --git a/packages/server/src/api/controllers/deploy/aws.js b/packages/server/src/api/controllers/deploy/aws.js index eea7be052d..3e19812a00 100644 --- a/packages/server/src/api/controllers/deploy/aws.js +++ b/packages/server/src/api/controllers/deploy/aws.js @@ -62,24 +62,21 @@ exports.updateDeploymentQuota = async function(quota) { throw new Error(`Error updating deployment quota for API Key`) } - const json = await response.json() - - return json + return await response.json() } /** * Verifies the users API key and * Verifies that the deployment fits within the quota of the user, - * @param {String} instanceId - instanceId being deployed + * @param {String} appId - appId being deployed * @param {String} appId - appId being deployed * @param {quota} quota - current quota being changed with this application */ -exports.verifyDeployment = async function({ instanceId, appId, quota }) { +exports.verifyDeployment = async function({ appId, quota }) { const response = await fetch(env.DEPLOYMENT_CREDENTIALS_URL, { method: "POST", body: JSON.stringify({ apiKey: env.BUDIBASE_API_KEY, - instanceId, appId, quota, }), @@ -159,7 +156,6 @@ exports.prepareUploadForS3 = prepareUploadForS3 exports.uploadAppAssets = async function({ appId, - instanceId, bucket, cfDistribution, accountId, @@ -193,7 +189,7 @@ exports.uploadAppAssets = async function({ } // Upload file attachments - const db = new PouchDB(instanceId) + const db = new PouchDB(appId) let fileUploads try { fileUploads = await db.get("_local/fileuploads") diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index 0ab7a3791e..8b4bb003aa 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -81,9 +81,9 @@ function replicate(local, remote) { }) } -async function replicateCouch({ instanceId, session }) { - const localDb = new PouchDB(instanceId) - const remoteDb = new CouchDB(`${env.DEPLOYMENT_DB_URL}/${instanceId}`, { +async function replicateCouch({ appId, session }) { + const localDb = new PouchDB(appId) + const remoteDb = new CouchDB(`${env.DEPLOYMENT_DB_URL}/${appId}`, { fetch: function(url, opts) { opts.headers.set("Cookie", `${session};`) return CouchDB.fetch(url, opts) @@ -93,8 +93,8 @@ async function replicateCouch({ instanceId, session }) { return replicate(localDb, remoteDb) } -async function getCurrentInstanceQuota(instanceId) { - const db = new PouchDB(instanceId) +async function getCurrentInstanceQuota(appId) { + const db = new PouchDB(appId) const rows = await db.allDocs({ startkey: DocumentTypes.ROW + SEPARATOR, @@ -119,7 +119,7 @@ async function getCurrentInstanceQuota(instanceId) { } async function storeLocalDeploymentHistory(deployment) { - const db = new PouchDB(deployment.instanceId) + const db = new PouchDB(deployment.appId) let deploymentDoc try { @@ -147,11 +147,10 @@ async function storeLocalDeploymentHistory(deployment) { } } -async function deployApp({ instanceId, appId, deploymentId }) { +async function deployApp({ appId, deploymentId }) { try { - const instanceQuota = await getCurrentInstanceQuota(instanceId) + const instanceQuota = await getCurrentInstanceQuota(appId) const verification = await verifyDeployment({ - instanceId, appId, quota: instanceQuota, }) @@ -160,14 +159,13 @@ async function deployApp({ instanceId, appId, deploymentId }) { const invalidationId = await uploadAppAssets({ appId, - instanceId, ...verification, }) // replicate the DB to the couchDB cluster in prod console.log("Replicating local PouchDB to remote..") await replicateCouch({ - instanceId, + appId, session: verification.couchDbSession, }) @@ -175,7 +173,7 @@ async function deployApp({ instanceId, appId, deploymentId }) { await storeLocalDeploymentHistory({ _id: deploymentId, - instanceId, + appId, invalidationId, cfDistribution: verification.cfDistribution, quota: verification.quota, @@ -184,7 +182,7 @@ async function deployApp({ instanceId, appId, deploymentId }) { } catch (err) { await storeLocalDeploymentHistory({ _id: deploymentId, - instanceId, + appId, status: DeploymentStatus.FAILURE, err: err.message, }) @@ -194,7 +192,7 @@ async function deployApp({ instanceId, appId, deploymentId }) { exports.fetchDeployments = async function(ctx) { try { - const db = new PouchDB(ctx.user.instanceId) + const db = new PouchDB(ctx.user.appId) const deploymentDoc = await db.get("_local/deployments") const { updated, deployments } = await checkAllDeployments( deploymentDoc, @@ -211,7 +209,7 @@ exports.fetchDeployments = async function(ctx) { exports.deploymentProgress = async function(ctx) { try { - const db = new PouchDB(ctx.user.instanceId) + const db = new PouchDB(ctx.user.appId) const deploymentDoc = await db.get("_local/deployments") ctx.body = deploymentDoc[ctx.params.deploymentId] } catch (err) { @@ -224,7 +222,6 @@ exports.deploymentProgress = async function(ctx) { exports.deployApp = async function(ctx) { const deployment = await storeLocalDeploymentHistory({ - instanceId: ctx.user.instanceId, appId: ctx.user.appId, status: DeploymentStatus.PENDING, }) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 1e12bf7a78..c4a44581d1 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -28,8 +28,8 @@ validateJs.extend(validateJs.validators.datetime, { }) exports.patch = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) let row = await db.get(ctx.params.id) const table = await db.get(row.tableId) const patchfields = ctx.request.body @@ -56,7 +56,7 @@ exports.patch = async function(ctx) { // returned row is cleaned and prepared for writing to DB row = await linkRows.updateLinks({ - instanceId, + appId, eventType: linkRows.EventType.ROW_UPDATE, row, tableId: row.tableId, @@ -67,15 +67,15 @@ exports.patch = async function(ctx) { row.type = "row" ctx.eventEmitter && - ctx.eventEmitter.emitRow(`row:update`, instanceId, row, table) + ctx.eventEmitter.emitRow(`row:update`, appId, row, table) ctx.body = row ctx.status = 200 ctx.message = `${table.name} updated successfully.` } exports.save = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) let row = ctx.request.body row.tableId = ctx.params.tableId @@ -112,7 +112,7 @@ exports.save = async function(ctx) { // make sure link rows are up to date row = await linkRows.updateLinks({ - instanceId, + appId, eventType: linkRows.EventType.ROW_SAVE, row, tableId: row.tableId, @@ -134,15 +134,15 @@ exports.save = async function(ctx) { row._rev = response.rev ctx.eventEmitter && - ctx.eventEmitter.emitRow(`row:save`, instanceId, row, table) + ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.body = row ctx.status = 200 ctx.message = `${table.name} created successfully` } exports.fetchView = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const { calculation, group, field } = ctx.query const viewName = ctx.params.viewName @@ -160,7 +160,7 @@ exports.fetchView = async function(ctx) { if (!calculation) { response.rows = response.rows.map(row => row.doc) - ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows) + ctx.body = await linkRows.attachLinkInfo(appId, response.rows) } if (calculation === CALCULATION_TYPES.STATS) { @@ -186,8 +186,8 @@ exports.fetchView = async function(ctx) { } exports.fetchTableRows = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const response = await db.allDocs( getRowParams(ctx.params.tableId, null, { include_docs: true, @@ -195,45 +195,45 @@ exports.fetchTableRows = async function(ctx) { ) ctx.body = response.rows.map(row => row.doc) ctx.body = await linkRows.attachLinkInfo( - instanceId, + appId, response.rows.map(row => row.doc) ) } exports.search = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const response = await db.allDocs({ include_docs: true, ...ctx.request.body, }) ctx.body = await linkRows.attachLinkInfo( - instanceId, + appId, response.rows.map(row => row.doc) ) } exports.find = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const row = await db.get(ctx.params.rowId) if (row.tableId !== ctx.params.tableId) { ctx.throw(400, "Supplied tableId does not match the rows tableId") return } - ctx.body = await linkRows.attachLinkInfo(instanceId, row) + ctx.body = await linkRows.attachLinkInfo(appId, row) } exports.destroy = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const row = await db.get(ctx.params.rowId) if (row.tableId !== ctx.params.tableId) { ctx.throw(400, "Supplied tableId doesn't match the row's tableId") return } await linkRows.updateLinks({ - instanceId, + appId, eventType: linkRows.EventType.ROW_DELETE, row, tableId: row.tableId, @@ -243,12 +243,12 @@ exports.destroy = async function(ctx) { // for automations include the row that was deleted ctx.row = row - ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row) + ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row) } exports.validate = async function(ctx) { const errors = await validate({ - instanceId: ctx.user.instanceId, + appId: ctx.user.appId, tableId: ctx.params.tableId, row: ctx.request.body, }) @@ -256,9 +256,9 @@ exports.validate = async function(ctx) { ctx.body = errors } -async function validate({ instanceId, tableId, row, table }) { +async function validate({ appId, tableId, row, table }) { if (!table) { - const db = new CouchDB(instanceId) + const db = new CouchDB(appId) table = await db.get(tableId) } const errors = {} @@ -273,11 +273,11 @@ async function validate({ instanceId, tableId, row, table }) { } exports.fetchEnrichedRow = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const tableId = ctx.params.tableId const rowId = ctx.params.rowId - if (instanceId == null || tableId == null || rowId == null) { + if (appId == null || tableId == null || rowId == null) { ctx.status = 400 ctx.body = { status: 400, @@ -290,7 +290,7 @@ exports.fetchEnrichedRow = async function(ctx) { const [table, row] = await Promise.all([db.get(tableId), db.get(rowId)]) // get the link docs const linkVals = await linkRows.getLinkDocuments({ - instanceId, + appId, tableId, rowId, }) @@ -301,7 +301,7 @@ exports.fetchEnrichedRow = async function(ctx) { }) // need to include the IDs in these rows for any links they may have let linkedRows = await linkRows.attachLinkInfo( - instanceId, + appId, response.rows.map(row => row.doc) ) // insert the link rows in the correct place throughout the main row @@ -375,13 +375,13 @@ const TYPE_TRANSFORM_MAP = { } async function bulkDelete(ctx) { - const instanceId = ctx.user.instanceId + const appId = ctx.user.appId const { rows } = ctx.request.body - const db = new CouchDB(instanceId) + const db = new CouchDB(appId) const linkUpdates = rows.map(row => linkRows.updateLinks({ - instanceId, + appId, eventType: linkRows.EventType.ROW_DELETE, row, tableId: row.tableId, @@ -392,6 +392,6 @@ async function bulkDelete(ctx) { await Promise.all(linkUpdates) rows.forEach(row => { - ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row) + ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row) }) } diff --git a/packages/server/src/api/controllers/static.js b/packages/server/src/api/controllers/static.js index 19eb90dc42..1ebe169417 100644 --- a/packages/server/src/api/controllers/static.js +++ b/packages/server/src/api/controllers/static.js @@ -65,11 +65,11 @@ exports.uploadFile = async function(ctx) { ctx.body = await processLocalFileUploads({ files, outputPath: attachmentsPath, - instanceId: ctx.user.instanceId, + appId: ctx.user.appId, }) } -async function processLocalFileUploads({ files, outputPath, instanceId }) { +async function processLocalFileUploads({ files, outputPath, appId }) { // create attachments dir if it doesnt exist !fs.existsSync(outputPath) && fs.mkdirSync(outputPath, { recursive: true }) @@ -98,7 +98,7 @@ async function processLocalFileUploads({ files, outputPath, instanceId }) { // local document used to track which files need to be uploaded // db.get throws an error if the document doesn't exist // need to use a promise to default - const db = new CouchDB(instanceId) + const db = new CouchDB(appId) await db .get("_local/fileuploads") .then(data => { @@ -130,7 +130,7 @@ exports.performLocalFileProcessing = async function(ctx) { ctx.body = await processLocalFileUploads({ files, outputPath: processedFileOutputPath, - instanceId: ctx.user.instanceId, + appId: ctx.user.appId, }) } catch (err) { ctx.throw(500, err) @@ -188,7 +188,7 @@ exports.serveAppAsset = async function(ctx) { const appPath = resolve( budibaseAppsDir(), - ctx.user.instanceId, + ctx.user.appId, "public", mainOrAuth ) diff --git a/packages/server/src/api/controllers/table.js b/packages/server/src/api/controllers/table.js index 61726d591a..f7021974c5 100644 --- a/packages/server/src/api/controllers/table.js +++ b/packages/server/src/api/controllers/table.js @@ -9,7 +9,7 @@ const { } = require("../../db/utils") exports.fetch = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const body = await db.allDocs( getTableParams(null, { include_docs: true, @@ -19,13 +19,13 @@ exports.fetch = async function(ctx) { } exports.find = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) ctx.body = await db.get(ctx.params.id) } exports.save = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const { dataImport, ...rest } = ctx.request.body const tableToSave = { type: "table", @@ -90,7 +90,7 @@ exports.save = async function(ctx) { // update linked rows await linkRows.updateLinks({ - instanceId, + appId, eventType: oldTable ? linkRows.EventType.TABLE_UPDATED : linkRows.EventType.TABLE_SAVE, @@ -107,7 +107,7 @@ exports.save = async function(ctx) { tableToSave._rev = result.rev ctx.eventEmitter && - ctx.eventEmitter.emitTable(`table:save`, instanceId, tableToSave) + ctx.eventEmitter.emitTable(`table:save`, appId, tableToSave) if (dataImport && dataImport.csvString) { // Populate the table with rows imported from CSV in a bulk update @@ -127,8 +127,8 @@ exports.save = async function(ctx) { } exports.destroy = async function(ctx) { - const instanceId = ctx.user.instanceId - const db = new CouchDB(instanceId) + const appId = ctx.user.appId + const db = new CouchDB(appId) const tableToDelete = await db.get(ctx.params.tableId) // Delete all rows for that table @@ -141,7 +141,7 @@ exports.destroy = async function(ctx) { // update linked rows await linkRows.updateLinks({ - instanceId, + appId, eventType: linkRows.EventType.TABLE_DELETE, table: tableToDelete, }) @@ -150,7 +150,7 @@ exports.destroy = async function(ctx) { await db.remove(tableToDelete) ctx.eventEmitter && - ctx.eventEmitter.emitTable(`table:delete`, instanceId, tableToDelete) + ctx.eventEmitter.emitTable(`table:delete`, appId, tableToDelete) ctx.status = 200 ctx.message = `Table ${ctx.params.tableId} deleted.` } diff --git a/packages/server/src/api/controllers/templates.js b/packages/server/src/api/controllers/templates.js index c7be43b4e3..8e21b3c18b 100644 --- a/packages/server/src/api/controllers/templates.js +++ b/packages/server/src/api/controllers/templates.js @@ -28,12 +28,11 @@ exports.downloadTemplate = async function(ctx) { } exports.exportTemplateFromApp = async function(ctx) { - const { appId, instanceId } = ctx.user + const { appId } = ctx.user const { templateName } = ctx.request.body await exportTemplateFromApp({ appId, - instanceId, templateName, }) diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 192f56180e..da0adff895 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -7,7 +7,7 @@ const { } = require("../../utilities/accessLevels") exports.fetch = async function(ctx) { - const database = new CouchDB(ctx.user.instanceId) + const database = new CouchDB(ctx.user.appId) const data = await database.allDocs( getUserParams(null, { include_docs: true, @@ -17,7 +17,7 @@ exports.fetch = async function(ctx) { } exports.create = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const { username, password, name, accessLevelId } = ctx.request.body if (!username || !password) { @@ -39,10 +39,10 @@ exports.create = async function(ctx) { const response = await db.post(user) - const app = await db.get(ctx.user.instanceId) + const app = await db.get(ctx.user.appId) app.userInstanceMap = { ...app.userInstanceMap, - [username]: ctx.user.instanceId, + [username]: ctx.user.appId, } await db.put(app) @@ -57,7 +57,7 @@ exports.create = async function(ctx) { } exports.update = async function(ctx) { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const user = ctx.request.body const dbUser = db.get(ctx.request.body._id) const newData = { ...dbUser, ...user } @@ -71,14 +71,14 @@ exports.update = async function(ctx) { } exports.destroy = async function(ctx) { - const database = new CouchDB(ctx.user.instanceId) + const database = new CouchDB(ctx.user.appId) await database.destroy(generateUserID(ctx.params.username)) ctx.message = `User ${ctx.params.username} deleted.` ctx.status = 200 } exports.find = async function(ctx) { - const database = new CouchDB(ctx.user.instanceId) + const database = new CouchDB(ctx.user.appId) const user = await database.get(generateUserID(ctx.params.username)) ctx.body = { username: user.username, diff --git a/packages/server/src/api/controllers/view/index.js b/packages/server/src/api/controllers/view/index.js index b0d21b42d1..57d4862b7e 100644 --- a/packages/server/src/api/controllers/view/index.js +++ b/packages/server/src/api/controllers/view/index.js @@ -8,7 +8,7 @@ const { fetchView } = require("../row") const controller = { fetch: async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const designDoc = await db.get("_design/database") const response = [] @@ -26,7 +26,7 @@ const controller = { ctx.body = response }, save: async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const { originalName, ...viewToSave } = ctx.request.body const designDoc = await db.get("_design/database") @@ -63,7 +63,7 @@ const controller = { ctx.message = `View ${viewToSave.name} saved successfully.` }, destroy: async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const designDoc = await db.get("_design/database") const viewName = decodeURI(ctx.params.viewName) diff --git a/packages/server/src/api/controllers/webhook.js b/packages/server/src/api/controllers/webhook.js index 3259a89341..7a343b1b07 100644 --- a/packages/server/src/api/controllers/webhook.js +++ b/packages/server/src/api/controllers/webhook.js @@ -22,7 +22,7 @@ exports.WebhookType = { } exports.fetch = async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const response = await db.allDocs( getWebhookParams(null, { include_docs: true, @@ -32,7 +32,7 @@ exports.fetch = async ctx => { } exports.save = async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) const webhook = ctx.request.body webhook.appId = ctx.user.appId @@ -53,7 +53,7 @@ exports.save = async ctx => { } exports.destroy = async ctx => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) ctx.body = await db.remove(ctx.params.id, ctx.params.rev) } @@ -91,7 +91,7 @@ exports.trigger = async ctx => { await triggers.externalTrigger(target, { body: ctx.request.body, ...ctx.request.body, - instanceId: ctx.params.instance, + appId: ctx.params.instance, }) } ctx.status = 200 diff --git a/packages/server/src/api/routes/application.js b/packages/server/src/api/routes/application.js index f600eee333..aeb815d38c 100644 --- a/packages/server/src/api/routes/application.js +++ b/packages/server/src/api/routes/application.js @@ -8,12 +8,12 @@ const router = Router() router .get("/api/applications", authorized(BUILDER), controller.fetch) .get( - "/api/:instanceId/appPackage", + "/api/:appId/appPackage", authorized(BUILDER), controller.fetchAppPackage ) - .put("/api/:instanceId", authorized(BUILDER), controller.update) + .put("/api/:appId", authorized(BUILDER), controller.update) .post("/api/applications", authorized(BUILDER), controller.create) - .delete("/api/:instanceId", authorized(BUILDER), controller.delete) + .delete("/api/:appId", authorized(BUILDER), controller.delete) module.exports = router diff --git a/packages/server/src/api/routes/component.js b/packages/server/src/api/routes/component.js index f9dfff331c..8fbe7ac41a 100644 --- a/packages/server/src/api/routes/component.js +++ b/packages/server/src/api/routes/component.js @@ -6,7 +6,7 @@ const { BUILDER } = require("../../utilities/accessLevels") const router = Router() router.get( - "/:instanceId/components/definitions", + "/:appId/components/definitions", authorized(BUILDER), controller.fetchAppComponentDefinitions ) diff --git a/packages/server/src/api/routes/tests/accesslevel.spec.js b/packages/server/src/api/routes/tests/accesslevel.spec.js index d7958c8f32..3362cbd713 100644 --- a/packages/server/src/api/routes/tests/accesslevel.spec.js +++ b/packages/server/src/api/routes/tests/accesslevel.spec.js @@ -17,7 +17,7 @@ const { describe("/accesslevels", () => { let server let request - let instanceId + let appId let table let view @@ -31,9 +31,9 @@ describe("/accesslevels", () => { beforeEach(async () => { let app = await createApplication(request) - instanceId = app.instance._id - table = await createTable(request, instanceId) - view = await createView(request, instanceId, table._id) + appId = app.instance._id + table = await createTable(request, appId) + view = await createView(request, appId, table._id) }) describe("create", () => { @@ -42,7 +42,7 @@ describe("/accesslevels", () => { const res = await request .post(`/api/accesslevels`) .send({ name: "user" }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -60,7 +60,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE }] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -68,7 +68,7 @@ describe("/accesslevels", () => { const res = await request .get(`/api/accesslevels`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -76,11 +76,11 @@ describe("/accesslevels", () => { const adminLevel = res.body.find(r => r._id === ADMIN_LEVEL_ID) expect(adminLevel).toBeDefined() - expect(adminLevel.permissions).toEqual(await generateAdminPermissions(instanceId)) + expect(adminLevel.permissions).toEqual(await generateAdminPermissions(appId)) const powerUserLevel = res.body.find(r => r._id === POWERUSER_LEVEL_ID) expect(powerUserLevel).toBeDefined() - expect(powerUserLevel.permissions).toEqual(await generatePowerUserPermissions(instanceId)) + expect(powerUserLevel.permissions).toEqual(await generatePowerUserPermissions(appId)) const customLevelFetched = res.body.find(r => r._id === customLevel._id) expect(customLevelFetched.permissions).toEqual(customLevel.permissions) @@ -93,7 +93,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE } ] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -101,12 +101,12 @@ describe("/accesslevels", () => { await request .delete(`/api/accesslevels/${customLevel._id}/${customLevel._rev}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect(200) await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect(404) }) }) @@ -116,7 +116,7 @@ describe("/accesslevels", () => { const createRes = await request .post(`/api/accesslevels`) .send({ name: "user", permissions: [ { itemId: table._id, name: READ_TABLE }] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -128,13 +128,13 @@ describe("/accesslevels", () => { _rev: customLevel._rev, addedPermissions: [ { itemId: table._id, name: WRITE_TABLE } ] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) const finalRes = await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect(200) expect(finalRes.body.permissions.length).toBe(2) @@ -152,7 +152,7 @@ describe("/accesslevels", () => { { itemId: table._id, name: WRITE_TABLE }, ] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -164,13 +164,13 @@ describe("/accesslevels", () => { _rev: customLevel._rev, removedPermissions: [ { itemId: table._id, name: WRITE_TABLE }] }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) const finalRes = await request .get(`/api/accesslevels/${customLevel._id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect(200) expect(finalRes.body.permissions.length).toBe(1) diff --git a/packages/server/src/api/routes/tests/application.spec.js b/packages/server/src/api/routes/tests/application.spec.js index 6d30701a29..6068d783cb 100644 --- a/packages/server/src/api/routes/tests/application.spec.js +++ b/packages/server/src/api/routes/tests/application.spec.js @@ -36,12 +36,12 @@ describe("/applications", () => { it("should apply authorization to endpoint", async () => { const otherApplication = await createApplication(request) - const instanceId = otherApplication.instance._id + const appId = otherApplication.instance._id await builderEndpointShouldBlockNormalUsers({ request, method: "POST", url: `/api/applications`, - instanceId: instanceId, + appId: appId, body: { name: "My App" } }) }) @@ -64,12 +64,12 @@ describe("/applications", () => { it("should apply authorization to endpoint", async () => { const otherApplication = await createApplication(request) - const instanceId = otherApplication.instance._id + const appId = otherApplication.instance._id await builderEndpointShouldBlockNormalUsers({ request, method: "GET", url: `/api/applications`, - instanceId: instanceId, + appId: appId, }) }) }) diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index fa78cccf0d..226bbad226 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -39,7 +39,7 @@ describe("/automations", () => { let request let server let app - let instanceId + let appId let automation let automationId @@ -49,7 +49,7 @@ describe("/automations", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instance._id + appId = app.instance._id if (automation) await destroyDocument(automation.id) }) @@ -58,7 +58,7 @@ describe("/automations", () => { }) const createAutomation = async () => { - automation = await insertDocument(instanceId, { + automation = await insertDocument(appId, { type: "automation", ...TEST_AUTOMATION }) @@ -69,7 +69,7 @@ describe("/automations", () => { return await request .post(`/api/automations/${automationId}/trigger`) .send({ name: "Test", description: "TEST" }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) } @@ -78,7 +78,7 @@ describe("/automations", () => { it("returns a list of definitions for actions", async () => { const res = await request .get(`/api/automations/action/list`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -89,7 +89,7 @@ describe("/automations", () => { it("returns a list of definitions for triggers", async () => { const res = await request .get(`/api/automations/trigger/list`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -100,7 +100,7 @@ describe("/automations", () => { it("returns a list of definitions for actions", async () => { const res = await request .get(`/api/automations/logic/list`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -111,7 +111,7 @@ describe("/automations", () => { it("returns all of the definitions in one", async () => { const res = await request .get(`/api/automations/definitions/list`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -139,7 +139,7 @@ describe("/automations", () => { it("returns a success message when the automation is successfully created", async () => { const res = await request .post(`/api/automations`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .send(TEST_AUTOMATION) .expect('Content-Type', /json/) .expect(200) @@ -155,7 +155,7 @@ describe("/automations", () => { request, method: "POST", url: `/api/automations`, - instanceId: instanceId, + appId: appId, body: TEST_AUTOMATION }) }) @@ -163,7 +163,7 @@ describe("/automations", () => { describe("trigger", () => { it("trigger the automation successfully", async () => { - let table = await createTable(request, instanceId) + let table = await createTable(request, appId) TEST_AUTOMATION.definition.trigger.inputs.tableId = table._id TEST_AUTOMATION.definition.steps[0].inputs.row.tableId = table._id await createAutomation() @@ -176,7 +176,7 @@ describe("/automations", () => { expect(res.body.message).toEqual(`Automation ${automation._id} has been triggered.`) expect(res.body.automation.name).toEqual(TEST_AUTOMATION.name) await delay(500) - let elements = await getAllFromTable(request, instanceId, table._id) + let elements = await getAllFromTable(request, appId, table._id) // don't test it unless there are values to test if (elements.length === 1) { expect(elements.length).toEqual(1) @@ -199,7 +199,7 @@ describe("/automations", () => { const res = await request .put(`/api/automations`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .send(automation) .expect('Content-Type', /json/) .expect(200) @@ -214,7 +214,7 @@ describe("/automations", () => { await createAutomation() const res = await request .get(`/api/automations`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -226,7 +226,7 @@ describe("/automations", () => { request, method: "GET", url: `/api/automations`, - instanceId: instanceId, + appId: appId, }) }) }) @@ -236,7 +236,7 @@ describe("/automations", () => { await createAutomation() const res = await request .delete(`/api/automations/${automation.id}/${automation.rev}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -249,7 +249,7 @@ describe("/automations", () => { request, method: "DELETE", url: `/api/automations/${automation.id}/${automation._rev}`, - instanceId: instanceId, + appId: appId, }) }) }) diff --git a/packages/server/src/api/routes/tests/couchTestUtils.js b/packages/server/src/api/routes/tests/couchTestUtils.js index 25b8dd964e..83c968323d 100644 --- a/packages/server/src/api/routes/tests/couchTestUtils.js +++ b/packages/server/src/api/routes/tests/couchTestUtils.js @@ -23,11 +23,11 @@ exports.supertest = async () => { return { request, server } } -exports.defaultHeaders = instanceId => { +exports.defaultHeaders = appId => { const builderUser = { userId: "BUILDER", accessLevelId: BUILDER_LEVEL_ID, - instanceId, + appId, } const builderToken = jwt.sign(builderUser, env.JWT_SECRET) @@ -38,7 +38,7 @@ exports.defaultHeaders = instanceId => { } } -exports.createTable = async (request, instanceId, table) => { +exports.createTable = async (request, appId, table) => { if (table != null && table._id) { delete table._id } @@ -64,19 +64,19 @@ exports.createTable = async (request, instanceId, table) => { const res = await request .post(`/api/tables`) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) .send(table) return res.body } -exports.getAllFromTable = async (request, instanceId, tableId) => { +exports.getAllFromTable = async (request, appId, tableId) => { const res = await request .get(`/api/${tableId}/rows`) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) return res.body } -exports.createView = async (request, instanceId, tableId, view) => { +exports.createView = async (request, appId, tableId, view) => { view = view || { map: "function(doc) { emit(doc[doc.key], doc._id); } ", tableId: tableId, @@ -84,7 +84,7 @@ exports.createView = async (request, instanceId, tableId, view) => { const res = await request .post(`/api/views`) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) .send(view) return res.body } @@ -111,13 +111,13 @@ exports.clearApplications = async request => { exports.createUser = async ( request, - instanceId, + appId, username = "babs", password = "babs_password" ) => { const res = await request .post(`/api/users`) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) .send({ name: "Bill", username, @@ -129,29 +129,29 @@ exports.createUser = async ( const createUserWithOnePermission = async ( request, - instanceId, + appId, permName, itemId ) => { - let permissions = await generateAdminPermissions(instanceId) + let permissions = await generateAdminPermissions(appId) permissions = permissions.filter( p => p.name === permName && p.itemId === itemId ) return await createUserWithPermissions( request, - instanceId, + appId, permissions, "onePermOnlyUser" ) } -const createUserWithAdminPermissions = async (request, instanceId) => { - let permissions = await generateAdminPermissions(instanceId) +const createUserWithAdminPermissions = async (request, appId) => { + let permissions = await generateAdminPermissions(appId) return await createUserWithPermissions( request, - instanceId, + appId, permissions, "adminUser" ) @@ -159,18 +159,18 @@ const createUserWithAdminPermissions = async (request, instanceId) => { const createUserWithAllPermissionExceptOne = async ( request, - instanceId, + appId, permName, itemId ) => { - let permissions = await generateAdminPermissions(instanceId) + let permissions = await generateAdminPermissions(appId) permissions = permissions.filter( p => !(p.name === permName && p.itemId === itemId) ) return await createUserWithPermissions( request, - instanceId, + appId, permissions, "allPermsExceptOneUser" ) @@ -178,19 +178,19 @@ const createUserWithAllPermissionExceptOne = async ( const createUserWithPermissions = async ( request, - instanceId, + appId, permissions, username ) => { const accessRes = await request .post(`/api/accesslevels`) .send({ name: "TestLevel", permissions }) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) const password = `password_${username}` await request .post(`/api/users`) - .set(exports.defaultHeaders(instanceId)) + .set(exports.defaultHeaders(appId)) .send({ name: username, username, @@ -201,7 +201,7 @@ const createUserWithPermissions = async ( const anonUser = { userId: "ANON", accessLevelId: ANON_LEVEL_ID, - instanceId: instanceId, + appId: appId, version: packageJson.version, } @@ -224,13 +224,13 @@ exports.testPermissionsForEndpoint = async ({ method, url, body, - instanceId, + appId, permissionName, itemId, }) => { const headers = await createUserWithOnePermission( request, - instanceId, + appId, permissionName, itemId ) @@ -241,7 +241,7 @@ exports.testPermissionsForEndpoint = async ({ const noPermsHeaders = await createUserWithAllPermissionExceptOne( request, - instanceId, + appId, permissionName, itemId ) @@ -256,9 +256,9 @@ exports.builderEndpointShouldBlockNormalUsers = async ({ method, url, body, - instanceId, + appId, }) => { - const headers = await createUserWithAdminPermissions(request, instanceId) + const headers = await createUserWithAdminPermissions(request, appId) await createRequest(request, method, url, body) .set(headers) diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index 31f273216f..507f05cf6c 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -8,7 +8,7 @@ const { describe("/rows", () => { let request let server - let instanceId + let appId let table let row let app @@ -24,8 +24,8 @@ describe("/rows", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instance._id - table = await createTable(request, instanceId) + appId = app.instance._id + table = await createTable(request, appId) row = { name: "Test Contact", description: "original description", @@ -38,14 +38,14 @@ describe("/rows", () => { await request .post(`/api/${r ? r.tableId : row.tableId}/rows`) .send(r || row) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) const loadRow = async id => await request .get(`/api/${table._id}/rows/${id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -72,7 +72,7 @@ describe("/rows", () => { tableId: table._id, name: "Updated Name", }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -86,7 +86,7 @@ describe("/rows", () => { const res = await request .get(`/api/${table._id}/rows/${existing._id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -109,7 +109,7 @@ describe("/rows", () => { const res = await request .get(`/api/${table._id}/rows`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -131,7 +131,7 @@ describe("/rows", () => { const res = await request .post(`/api/rows/search`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .send({ keys: rowIds }) @@ -146,7 +146,7 @@ describe("/rows", () => { await createRow() await request .get(`/api/${table._id}/rows/not-a-valid-id`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(404) }) @@ -158,7 +158,7 @@ describe("/rows", () => { const number = {type:"number", constraints: { type: "number", presence: false }} const datetime = {type:"datetime", constraints: { type: "string", presence: false, datetime: {earliest:"", latest: ""} }} - table = await createTable(request, instanceId, { + table = await createTable(request, appId, { name: "TestTable2", type: "table", key: "name", @@ -254,7 +254,7 @@ describe("/rows", () => { tableId: table._id, name: "Updated Name", }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -275,7 +275,7 @@ describe("/rows", () => { const result = await request .post(`/api/${table._id}/rows/validate`) .send({ name: "ivan" }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -287,7 +287,7 @@ describe("/rows", () => { const result = await request .post(`/api/${table._id}/rows/validate`) .send({ name: 1 }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) diff --git a/packages/server/src/api/routes/tests/table.spec.js b/packages/server/src/api/routes/tests/table.spec.js index 193bfb50a6..67d53a489b 100644 --- a/packages/server/src/api/routes/tests/table.spec.js +++ b/packages/server/src/api/routes/tests/table.spec.js @@ -11,7 +11,7 @@ describe("/tables", () => { let request let server let app - let instanceId + let appId beforeAll(async () => { ({ request, server } = await supertest()) @@ -23,7 +23,7 @@ describe("/tables", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instance._id + appId = app.instance._id }); describe("create", () => { @@ -37,7 +37,7 @@ describe("/tables", () => { name: { type: "string" } } }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) .end(async (err, res) => { @@ -48,14 +48,14 @@ describe("/tables", () => { }) it("renames all the row fields for a table when a schema key is renamed", async () => { - const testTable = await createTable(request, instanceId); + const testTable = await createTable(request, appId); const testRow = await request .post(`/api/${testTable._id}/rows`) .send({ name: "test" }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -74,7 +74,7 @@ describe("/tables", () => { updatedName: { type: "string" } } }) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -83,7 +83,7 @@ describe("/tables", () => { const res = await request .get(`/api/${testTable._id}/rows/${testRow.body._id}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -96,7 +96,7 @@ describe("/tables", () => { request, method: "POST", url: `/api/tables`, - instanceId: instanceId, + appId: appId, body: { name: "TestTable", key: "name", @@ -112,7 +112,7 @@ describe("/tables", () => { let testTable beforeEach(async () => { - testTable = await createTable(request, instanceId, testTable) + testTable = await createTable(request, appId, testTable) }); afterEach(() => { @@ -122,7 +122,7 @@ describe("/tables", () => { it("returns all the tables for that instance in the response body", done => { request .get(`/api/tables`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { @@ -138,7 +138,7 @@ describe("/tables", () => { request, method: "GET", url: `/api/tables`, - instanceId: instanceId, + appId: appId, }) }) }); @@ -147,7 +147,7 @@ describe("/tables", () => { let testTable; beforeEach(async () => { - testTable = await createTable(request, instanceId, testTable) + testTable = await createTable(request, appId, testTable) }); afterEach(() => { @@ -157,7 +157,7 @@ describe("/tables", () => { it("returns a success response when a table is deleted.", async done => { request .delete(`/api/tables/${testTable._id}/${testTable._rev}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { @@ -167,7 +167,7 @@ describe("/tables", () => { }) it("deletes linked references to the table after deletion", async done => { - const linkedTable = await createTable(request, instanceId, { + const linkedTable = await createTable(request, appId, { name: "LinkedTable", type: "table", key: "name", @@ -190,12 +190,12 @@ describe("/tables", () => { request .delete(`/api/tables/${testTable._id}/${testTable._rev}`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) .end(async (_, res) => { expect(res.res.statusMessage).toEqual(`Table ${testTable._id} deleted.`); - const dependentTable = await getDocument(instanceId, linkedTable._id) + const dependentTable = await getDocument(appId, linkedTable._id) expect(dependentTable.schema.TestTable).not.toBeDefined(); done(); }); @@ -206,7 +206,7 @@ describe("/tables", () => { request, method: "DELETE", url: `/api/tables/${testTable._id}/${testTable._rev}`, - instanceId: instanceId, + appId: appId, }) }) diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index 497a654fc3..a569902bae 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -15,7 +15,7 @@ describe("/users", () => { let request let server let app - let instanceId + let appId beforeAll(async () => { ({ request, server } = await supertest(server)) @@ -23,7 +23,7 @@ describe("/users", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instance._id + appId = app.instance._id }); afterAll(() => { @@ -33,11 +33,11 @@ describe("/users", () => { describe("fetch", () => { it("returns a list of users from an instance db", async () => { - await createUser(request, instanceId, "brenda", "brendas_password") - await createUser(request, instanceId, "pam", "pam_password") + await createUser(request, appId, "brenda", "brendas_password") + await createUser(request, appId, "pam", "pam_password") const res = await request .get(`/api/users`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -47,12 +47,12 @@ describe("/users", () => { }) it("should apply authorization to endpoint", async () => { - await createUser(request, instanceId, "brenda", "brendas_password") + await createUser(request, appId, "brenda", "brendas_password") await testPermissionsForEndpoint({ request, method: "GET", url: `/api/users`, - instanceId: instanceId, + appId: appId, permissionName: LIST_USERS, }) }) @@ -64,7 +64,7 @@ describe("/users", () => { it("returns a success message when a user is successfully created", async () => { const res = await request .post(`/api/users`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .send({ name: "Bill", username: "bill", password: "bills_password", accessLevelId: POWERUSER_LEVEL_ID }) .expect(200) .expect('Content-Type', /json/) @@ -79,7 +79,7 @@ describe("/users", () => { method: "POST", body: { name: "brandNewUser", username: "brandNewUser", password: "yeeooo", accessLevelId: POWERUSER_LEVEL_ID }, url: `/api/users`, - instanceId: instanceId, + appId: appId, permissionName: USER_MANAGEMENT, }) }) diff --git a/packages/server/src/api/routes/tests/view.spec.js b/packages/server/src/api/routes/tests/view.spec.js index 0419e7326c..f1ee5d8218 100644 --- a/packages/server/src/api/routes/tests/view.spec.js +++ b/packages/server/src/api/routes/tests/view.spec.js @@ -10,7 +10,7 @@ describe("/views", () => { let request let server let app - let instanceId + let appId let table const createView = async (config = { @@ -22,14 +22,14 @@ describe("/views", () => { await request .post(`/api/views`) .send(config) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) const createRow = async row => request .post(`/api/${table._id}/rows`) .send(row) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) @@ -39,7 +39,7 @@ describe("/views", () => { beforeEach(async () => { app = await createApplication(request) - instanceId = app.instance._id + appId = app.instance._id }) afterAll(() => { @@ -48,7 +48,7 @@ describe("/views", () => { describe("create", () => { beforeEach(async () => { - table = await createTable(request, instanceId); + table = await createTable(request, appId); }) it("returns a success message when the view is successfully created", async () => { @@ -59,7 +59,7 @@ describe("/views", () => { it("updates the table row with the new view metadata", async () => { const res = await createView() expect(res.res.statusMessage).toEqual("View TestView saved successfully."); - const updatedTable = await getDocument(instanceId, table._id) + const updatedTable = await getDocument(appId, table._id) expect(updatedTable.views).toEqual({ TestView: { field: "Price", @@ -96,14 +96,14 @@ describe("/views", () => { describe("fetch", () => { beforeEach(async () => { - table = await createTable(request, instanceId); + table = await createTable(request, appId); }); it("returns only custom views", async () => { await createView() const res = await request .get(`/api/views`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) expect(res.body.length).toBe(1) @@ -113,7 +113,7 @@ describe("/views", () => { describe("query", () => { beforeEach(async () => { - table = await createTable(request, instanceId); + table = await createTable(request, appId); }); it("returns data for the created view", async () => { @@ -132,7 +132,7 @@ describe("/views", () => { }) const res = await request .get(`/api/views/TestView?calculation=stats`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) expect(res.body.length).toBe(1) @@ -164,7 +164,7 @@ describe("/views", () => { }) const res = await request .get(`/api/views/TestView?calculation=stats&group=Category`) - .set(defaultHeaders(instanceId)) + .set(defaultHeaders(appId)) .expect('Content-Type', /json/) .expect(200) diff --git a/packages/server/src/automations/automationUtils.js b/packages/server/src/automations/automationUtils.js index c6284ea3bd..3a66420dd0 100644 --- a/packages/server/src/automations/automationUtils.js +++ b/packages/server/src/automations/automationUtils.js @@ -88,13 +88,13 @@ module.exports.cleanInputValues = (inputs, schema) => { * the automation but is instead part of the Table/Table. This function will get the table schema and use it to instead * perform the cleanInputValues function on the input row. * - * @param {string} instanceId The instance which the Table/Table is contained under. + * @param {string} appId The instance which the Table/Table is contained under. * @param {string} tableId The ID of the Table/Table which the schema is to be retrieved for. * @param {object} row The input row structure which requires clean-up after having been through mustache statements. * @returns {Promise} The cleaned up rows object, will should now have all the required primitive types. */ -module.exports.cleanUpRow = async (instanceId, tableId, row) => { - const db = new CouchDB(instanceId) +module.exports.cleanUpRow = async (appId, tableId, row) => { + const db = new CouchDB(appId) const table = await db.get(tableId) return module.exports.cleanInputValues(row, { properties: table.schema }) @@ -104,13 +104,13 @@ module.exports.cleanUpRow = async (instanceId, tableId, row) => { * A utility function for the cleanUpRow, which can be used if only the row ID is known (not the table ID) to clean * up a row after mustache statements have been replaced. This is specifically useful for the update row action. * - * @param {string} instanceId The instance which the Table/Table is contained under. + * @param {string} appId The instance which the Table/Table is contained under. * @param {string} rowId The ID of the row from which the tableId will be extracted, to get the Table/Table schema. * @param {object} row The input row structure which requires clean-up after having been through mustache statements. * @returns {Promise} The cleaned up rows object, which will now have all the required primitive types. */ -module.exports.cleanUpRowById = async (instanceId, rowId, row) => { - const db = new CouchDB(instanceId) +module.exports.cleanUpRowById = async (appId, rowId, row) => { + const db = new CouchDB(appId) const foundRow = await db.get(rowId) - return module.exports.cleanUpRow(instanceId, foundRow.tableId, row) + return module.exports.cleanUpRow(appId, foundRow.tableId, row) } diff --git a/packages/server/src/automations/steps/createRow.js b/packages/server/src/automations/steps/createRow.js index afc3d018ee..0b7897809a 100644 --- a/packages/server/src/automations/steps/createRow.js +++ b/packages/server/src/automations/steps/createRow.js @@ -58,13 +58,13 @@ module.exports.definition = { }, } -module.exports.run = async function({ inputs, instanceId, apiKey }) { +module.exports.run = async function({ inputs, appId, apiKey }) { // TODO: better logging of when actions are missed due to missing parameters if (inputs.row == null || inputs.row.tableId == null) { return } inputs.row = await automationUtils.cleanUpRow( - instanceId, + appId, inputs.row.tableId, inputs.row ) @@ -76,7 +76,7 @@ module.exports.run = async function({ inputs, instanceId, apiKey }) { request: { body: inputs.row, }, - user: { instanceId }, + user: { appId }, } try { diff --git a/packages/server/src/automations/steps/createUser.js b/packages/server/src/automations/steps/createUser.js index 38eeb5ae1e..07d9f05316 100644 --- a/packages/server/src/automations/steps/createUser.js +++ b/packages/server/src/automations/steps/createUser.js @@ -58,11 +58,11 @@ module.exports.definition = { }, } -module.exports.run = async function({ inputs, instanceId, apiKey }) { +module.exports.run = async function({ inputs, appId, apiKey }) { const { username, password, accessLevelId } = inputs const ctx = { user: { - instanceId: instanceId, + appId: appId, }, request: { body: { username, password, accessLevelId }, diff --git a/packages/server/src/automations/steps/deleteRow.js b/packages/server/src/automations/steps/deleteRow.js index 9bece74fa2..f4884caad3 100644 --- a/packages/server/src/automations/steps/deleteRow.js +++ b/packages/server/src/automations/steps/deleteRow.js @@ -50,7 +50,7 @@ module.exports.definition = { }, } -module.exports.run = async function({ inputs, instanceId, apiKey }) { +module.exports.run = async function({ inputs, appId, apiKey }) { // TODO: better logging of when actions are missed due to missing parameters if (inputs.id == null || inputs.revision == null) { return @@ -61,7 +61,7 @@ module.exports.run = async function({ inputs, instanceId, apiKey }) { rowId: inputs.id, revId: inputs.revision, }, - user: { instanceId }, + user: { appId }, } try { diff --git a/packages/server/src/automations/steps/updateRow.js b/packages/server/src/automations/steps/updateRow.js index e443f7e745..b134ebfa9c 100644 --- a/packages/server/src/automations/steps/updateRow.js +++ b/packages/server/src/automations/steps/updateRow.js @@ -53,13 +53,13 @@ module.exports.definition = { }, } -module.exports.run = async function({ inputs, instanceId }) { +module.exports.run = async function({ inputs, appId }) { if (inputs.rowId == null || inputs.row == null) { return } inputs.row = await automationUtils.cleanUpRowById( - instanceId, + appId, inputs.rowId, inputs.row ) @@ -78,7 +78,7 @@ module.exports.run = async function({ inputs, instanceId }) { request: { body: inputs.row, }, - user: { instanceId }, + user: { appId }, } try { diff --git a/packages/server/src/automations/thread.js b/packages/server/src/automations/thread.js index 6b29fce1c1..26ca8f04a3 100644 --- a/packages/server/src/automations/thread.js +++ b/packages/server/src/automations/thread.js @@ -32,9 +32,9 @@ function recurseMustache(inputs, context) { */ class Orchestrator { constructor(automation, triggerOutput) { - this._instanceId = triggerOutput.instanceId + this._appId = triggerOutput.appId // remove from context - delete triggerOutput.instanceId + delete triggerOutput.appId // step zero is never used as the mustache is zero indexed for customer facing this._context = { steps: [{}], trigger: triggerOutput } this._automation = automation @@ -62,11 +62,11 @@ class Orchestrator { step.inputs, step.schema.inputs ) - // instanceId is always passed + // appId is always passed try { const outputs = await stepFn({ inputs: step.inputs, - instanceId: this._instanceId, + appId: this._appId, apiKey: automation.apiKey, }) if (step.stepId === FILTER_STEP_ID && !outputs.success) { diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index 6dd163ea8e..5d2121df7b 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -122,10 +122,10 @@ const BUILTIN_DEFINITIONS = { } async function queueRelevantRowAutomations(event, eventType) { - if (event.instanceId == null) { - throw `No instanceId specified for ${eventType} - check event emitters.` + if (event.appId == null) { + throw `No appId specified for ${eventType} - check event emitters.` } - const db = new CouchDB(event.instanceId) + const db = new CouchDB(event.appId) let automations = await db.allDocs( getAutomationParams(null, { include_docs: true }) ) @@ -169,7 +169,7 @@ emitter.on("row:delete", async function(event) { async function fillRowOutput(automation, params) { let triggerSchema = automation.definition.trigger let tableId = triggerSchema.inputs.tableId - const db = new CouchDB(params.instanceId) + const db = new CouchDB(params.appId) try { let table = await db.get(tableId) let row = {} diff --git a/packages/server/src/db/linkedRows/LinkController.js b/packages/server/src/db/linkedRows/LinkController.js index 5eed0bb4a8..d6116b76f6 100644 --- a/packages/server/src/db/linkedRows/LinkController.js +++ b/packages/server/src/db/linkedRows/LinkController.js @@ -40,9 +40,9 @@ function LinkDocument( } class LinkController { - constructor({ instanceId, tableId, row, table, oldTable }) { - this._instanceId = instanceId - this._db = new CouchDB(instanceId) + constructor({ appId, tableId, row, table, oldTable }) { + this._appId = appId + this._db = new CouchDB(appId) this._tableId = tableId this._row = row this._table = table @@ -87,7 +87,7 @@ class LinkController { */ getRowLinkDocs(rowId) { return getLinkDocuments({ - instanceId: this._instanceId, + appId: this._appId, tableId: this._tableId, rowId, includeDocs: IncludeDocs.INCLUDE, @@ -99,7 +99,7 @@ class LinkController { */ getTableLinkDocs() { return getLinkDocuments({ - instanceId: this._instanceId, + appId: this._appId, tableId: this._tableId, includeDocs: IncludeDocs.INCLUDE, }) diff --git a/packages/server/src/db/linkedRows/index.js b/packages/server/src/db/linkedRows/index.js index 6f745b6e7c..02af98eef9 100644 --- a/packages/server/src/db/linkedRows/index.js +++ b/packages/server/src/db/linkedRows/index.js @@ -31,7 +31,7 @@ exports.createLinkView = createLinkView * Update link documents for a row or table - this is to be called by the API controller when a change is occurring. * @param {string} eventType states what type of change which is occurring, means this can be expanded upon in the * future quite easily (all updates go through one function). - * @param {string} instanceId The ID of the instance in which the change is occurring. + * @param {string} appId The ID of the instance in which the change is occurring. * @param {string} tableId The ID of the of the table which is being changed. * @param {object|null} row The row which is changing, e.g. created, updated or deleted. * @param {object|null} table If the table has already been retrieved this can be used to reduce database gets. @@ -41,14 +41,14 @@ exports.createLinkView = createLinkView */ exports.updateLinks = async function({ eventType, - instanceId, + appId, row, tableId, table, oldTable, }) { const baseReturnObj = row == null ? table : row - if (instanceId == null) { + if (appId == null) { throw "Cannot operate without an instance ID." } // make sure table ID is set @@ -86,13 +86,13 @@ exports.updateLinks = async function({ /** * Update a row with information about the links that pertain to it. - * @param {string} instanceId The instance in which this row has been created. + * @param {string} appId The instance in which this row has been created. * @param {object} rows The row(s) themselves which is to be updated with info (if applicable). This can be * a single row object or an array of rows - both will be handled. * @returns {Promise} The updated row (this may be the same if no links were found). If an array was input * then an array will be output, object input -> object output. */ -exports.attachLinkInfo = async (instanceId, rows) => { +exports.attachLinkInfo = async (appId, rows) => { // handle a single row as well as multiple let wasArray = true if (!(rows instanceof Array)) { @@ -105,7 +105,7 @@ exports.attachLinkInfo = async (instanceId, rows) => { await Promise.all( tableIds.map(tableId => getLinkDocuments({ - instanceId, + appId, tableId: tableId, includeDocs: IncludeDocs.EXCLUDE, }) diff --git a/packages/server/src/db/linkedRows/linkUtils.js b/packages/server/src/db/linkedRows/linkUtils.js index 5f600cc3cb..dc9d8d3f1e 100644 --- a/packages/server/src/db/linkedRows/linkUtils.js +++ b/packages/server/src/db/linkedRows/linkUtils.js @@ -13,12 +13,12 @@ exports.IncludeDocs = { /** * Creates the link view for the instance, this will overwrite the existing one, but this should only * be called if it is found that the view does not exist. - * @param {string} instanceId The instance to which the view should be added. + * @param {string} appId The instance to which the view should be added. * @returns {Promise} The view now exists, please note that the next view of this query will actually build it, * so it may be slow. */ -exports.createLinkView = async instanceId => { - const db = new CouchDB(instanceId) +exports.createLinkView = async appId => { + const db = new CouchDB(appId) const designDoc = await db.get("_design/database") const view = { map: function(doc) { @@ -47,7 +47,7 @@ exports.createLinkView = async instanceId => { /** * Gets the linking documents, not the linked documents themselves. - * @param {string} instanceId The instance in which we are searching for linked rows. + * @param {string} appId The instance in which we are searching for linked rows. * @param {string} tableId The table which we are searching for linked rows against. * @param {string|null} fieldName The name of column/field which is being altered, only looking for * linking documents that are related to it. If this is not specified then the table level will be assumed. @@ -60,12 +60,12 @@ exports.createLinkView = async instanceId => { * (if any). */ exports.getLinkDocuments = async function({ - instanceId, + appId, tableId, rowId, includeDocs, }) { - const db = new CouchDB(instanceId) + const db = new CouchDB(appId) let params if (rowId != null) { params = { key: [tableId, rowId] } @@ -85,7 +85,7 @@ exports.getLinkDocuments = async function({ } catch (err) { // check if the view doesn't exist, it should for all new instances if (err != null && err.name === "not_found") { - await exports.createLinkView(instanceId) + await exports.createLinkView(appId) return exports.getLinkDocuments(arguments[0]) } else { Sentry.captureException(err) diff --git a/packages/server/src/events/index.js b/packages/server/src/events/index.js index 4c4541741c..237e212293 100644 --- a/packages/server/src/events/index.js +++ b/packages/server/src/events/index.js @@ -11,10 +11,10 @@ const EventEmitter = require("events").EventEmitter * This is specifically quite important for mustache used in automations. */ class BudibaseEmitter extends EventEmitter { - emitRow(eventName, instanceId, row, table = null) { + emitRow(eventName, appId, row, table = null) { let event = { row, - instanceId, + appId, tableId: row.tableId, } if (table) { @@ -27,14 +27,14 @@ class BudibaseEmitter extends EventEmitter { this.emit(eventName, event) } - emitTable(eventName, instanceId, table = null) { + emitTable(eventName, appId, table = null) { const tableId = table._id let event = { table: { ...table, tableId: tableId, }, - instanceId, + appId, tableId: tableId, } event.id = tableId diff --git a/packages/server/src/middleware/authenticated.js b/packages/server/src/middleware/authenticated.js index b62517e0f9..74f133cbde 100644 --- a/packages/server/src/middleware/authenticated.js +++ b/packages/server/src/middleware/authenticated.js @@ -53,9 +53,9 @@ module.exports = async (ctx, next) => { ctx.auth.apiKey = jwtPayload.apiKey ctx.user = { ...jwtPayload, - instanceId: jwtPayload.instanceId, + appId: jwtPayload.appId, accessLevel: await getAccessLevel( - jwtPayload.instanceId, + jwtPayload.appId, jwtPayload.accessLevelId ), } @@ -70,10 +70,10 @@ module.exports = async (ctx, next) => { * Return the full access level object either from constants * or the database based on the access level ID passed. * - * @param {*} instanceId - instanceId of the user + * @param {*} appId - appId of the user * @param {*} accessLevelId - the id of the users access level */ -const getAccessLevel = async (instanceId, accessLevelId) => { +const getAccessLevel = async (appId, accessLevelId) => { if ( accessLevelId === POWERUSER_LEVEL_ID || accessLevelId === ADMIN_LEVEL_ID || @@ -92,7 +92,7 @@ const getAccessLevel = async (instanceId, accessLevelId) => { levelId: accessLevelId, }, user: { - instanceId, + appId, }, } await accessLevelController.find(findAccessContext) diff --git a/packages/server/src/middleware/authorized.js b/packages/server/src/middleware/authorized.js index 71ff5cc1e1..34758903f3 100644 --- a/packages/server/src/middleware/authorized.js +++ b/packages/server/src/middleware/authorized.js @@ -28,7 +28,7 @@ module.exports = (permName, getItemId) => async (ctx, next) => { apiKey: ctx.headers["x-api-key"], } ctx.user = { - instanceId: ctx.headers["x-instanceid"], + appId: ctx.headers["x-instanceid"], } return next() } diff --git a/packages/server/src/middleware/usageQuota.js b/packages/server/src/middleware/usageQuota.js index 58e9c7eddc..39e387bd5a 100644 --- a/packages/server/src/middleware/usageQuota.js +++ b/packages/server/src/middleware/usageQuota.js @@ -27,7 +27,7 @@ function getProperty(url) { } module.exports = async (ctx, next) => { - const db = new CouchDB(ctx.user.instanceId) + const db = new CouchDB(ctx.user.appId) let usage = METHOD_MAP[ctx.req.method] const property = getProperty(ctx.req.url) if (usage == null || property == null) { diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json b/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json index 44d30a65f1..ecd63a6284 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json @@ -30,7 +30,7 @@ "className": "", "onLoad": [], "type": "div", - "_instanceId": "inst_app_80b_f158d4057d2c4bedb0042d42fda8abaf", + "_appId": "inst_app_80b_f158d4057d2c4bedb0042d42fda8abaf", "_instanceName": "Header", "_children": [ { @@ -59,7 +59,7 @@ "borderWidth": "", "borderColor": "", "borderStyle": "", - "_instanceId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", + "_appId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", "_instanceName": "Navigation", "_children": [ { @@ -88,7 +88,7 @@ "underline": false, "fontSize": "", "fontFamily": "initial", - "_instanceId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", + "_appId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", "_instanceName": "Home Link", "_children": [] } diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/main/screens/d834fea2-1b3e-4320-ab34-f9009f5ecc59.json b/packages/server/src/utilities/appDirectoryTemplate/pages/main/screens/d834fea2-1b3e-4320-ab34-f9009f5ecc59.json index 5afcf244f2..4104dcdb1e 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/main/screens/d834fea2-1b3e-4320-ab34-f9009f5ecc59.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/main/screens/d834fea2-1b3e-4320-ab34-f9009f5ecc59.json @@ -36,7 +36,7 @@ "className": "", "text": "Welcome to your Budibase App 👋", "type": "h2", - "_instanceId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", + "_appId": "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", "_instanceName": "Heading", "_children": [] }, @@ -62,7 +62,7 @@ "className": "", "onLoad": [], "type": "div", - "_instanceId": "inst_app_2cc_ca3383f896034e9295345c05f7dfca0c", + "_appId": "inst_app_2cc_ca3383f896034e9295345c05f7dfca0c", "_instanceName": "Video Container", "_children": [ { @@ -88,7 +88,7 @@ }, "_code": "", "embed": "", - "_instanceId": "inst_app_2cc_ca3383f896034e9295345c05f7dfca0c", + "_appId": "inst_app_2cc_ca3383f896034e9295345c05f7dfca0c", "_instanceName": "Rick Astley Video", "_children": [] } diff --git a/packages/server/src/utilities/builder/setBuilderToken.js b/packages/server/src/utilities/builder/setBuilderToken.js index ff057a90eb..fca3e0724f 100644 --- a/packages/server/src/utilities/builder/setBuilderToken.js +++ b/packages/server/src/utilities/builder/setBuilderToken.js @@ -2,11 +2,11 @@ const { BUILDER_LEVEL_ID } = require("../accessLevels") const env = require("../../environment") const jwt = require("jsonwebtoken") -module.exports = (ctx, instanceId, version) => { +module.exports = (ctx, appId, version) => { const builderUser = { userId: "BUILDER", accessLevelId: BUILDER_LEVEL_ID, - instanceId, + appId, version, } if (env.BUDIBASE_API_KEY) { diff --git a/packages/server/src/utilities/permissions.js b/packages/server/src/utilities/permissions.js index 8cd30c9ff8..e1513fd0fa 100644 --- a/packages/server/src/utilities/permissions.js +++ b/packages/server/src/utilities/permissions.js @@ -4,15 +4,15 @@ const automationController = require("../api/controllers/automation") const accessLevels = require("./accessLevels") // this has been broken out to reduce risk of circular dependency from utilities, no enums defined here -const generateAdminPermissions = async instanceId => [ +const generateAdminPermissions = async appId => [ ...accessLevels.adminPermissions, - ...(await generatePowerUserPermissions(instanceId)), + ...(await generatePowerUserPermissions(appId)), ] -const generatePowerUserPermissions = async instanceId => { +const generatePowerUserPermissions = async appId => { const fetchTablesCtx = { user: { - instanceId, + appId, }, } await tableController.fetch(fetchTablesCtx) @@ -20,7 +20,7 @@ const generatePowerUserPermissions = async instanceId => { const fetchViewsCtx = { user: { - instanceId, + appId, }, } await viewController.fetch(fetchViewsCtx) @@ -28,7 +28,7 @@ const generatePowerUserPermissions = async instanceId => { const fetchAutomationsCtx = { user: { - instanceId, + appId, }, } await automationController.fetch(fetchAutomationsCtx) diff --git a/packages/server/src/utilities/templates.js b/packages/server/src/utilities/templates.js index 626f1d003b..11150261ec 100644 --- a/packages/server/src/utilities/templates.js +++ b/packages/server/src/utilities/templates.js @@ -33,11 +33,7 @@ exports.downloadTemplate = async function(type, name) { return join(budibaseAppsDir(), "templates", type, name) } -exports.exportTemplateFromApp = async function({ - appId, - templateName, - instanceId, -}) { +exports.exportTemplateFromApp = async function({ templateName, appId }) { // Copy frontend files const appToExport = join(os.homedir(), ".budibase", appId, "pages") const templatesDir = join(os.homedir(), ".budibase", "templates") @@ -52,7 +48,7 @@ exports.exportTemplateFromApp = async function({ ) // perform couch dump - const instanceDb = new CouchDB(instanceId) + const instanceDb = new CouchDB(appId) await instanceDb.dump(writeStream) return templateOutputPath From 1238147be9b4fa86712c14d1908e0fdceecd14d6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 10:53:39 +0000 Subject: [PATCH 64/67] Updating script that had duplicate key. --- packages/server/scripts/exportAppTemplate.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/server/scripts/exportAppTemplate.js b/packages/server/scripts/exportAppTemplate.js index 4ae2f729ae..72ad797183 100755 --- a/packages/server/scripts/exportAppTemplate.js +++ b/packages/server/scripts/exportAppTemplate.js @@ -15,11 +15,6 @@ yargs alias: "n", type: "string", }, - appId: { - description: "The appId to dump the database for", - alias: "inst", - type: "string", - }, appId: { description: "The appId of the application you want to export", alias: "app", From 5e17e6d61f04901987304ca260617ff37c4562fd Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 10:55:52 +0000 Subject: [PATCH 65/67] linting. --- packages/server/src/api/controllers/row.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index c4a44581d1..ccf26b02e2 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -66,8 +66,7 @@ exports.patch = async function(ctx) { row._rev = response.rev row.type = "row" - ctx.eventEmitter && - ctx.eventEmitter.emitRow(`row:update`, appId, row, table) + ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) ctx.body = row ctx.status = 200 ctx.message = `${table.name} updated successfully.` @@ -133,8 +132,7 @@ exports.save = async function(ctx) { const response = await db.post(row) row._rev = response.rev - ctx.eventEmitter && - ctx.eventEmitter.emitRow(`row:save`, appId, row, table) + ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) ctx.body = row ctx.status = 200 ctx.message = `${table.name} created successfully` From eeecd61058795808d5b691fa25eaf2eabb038042 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 11:04:02 +0000 Subject: [PATCH 66/67] Fixing another linting issue. --- packages/server/src/utilities/builder/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/utilities/builder/index.js b/packages/server/src/utilities/builder/index.js index 900d438636..dbc2ce6bf5 100644 --- a/packages/server/src/utilities/builder/index.js +++ b/packages/server/src/utilities/builder/index.js @@ -10,7 +10,6 @@ const { } = require("fs-extra") const { join, resolve } = require("../centralPath") const { dirname } = require("path") -const env = require("../../environment") const buildPage = require("./buildPage") const getPages = require("./getPages") From c5d856f1930027f83ac8915ad88e940eb105a98c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 29 Oct 2020 11:48:01 +0000 Subject: [PATCH 67/67] Updating for review comments. --- packages/server/src/api/controllers/application.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 0765d50f6d..66cde54fd6 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -49,11 +49,7 @@ async function createInstance(template) { exports.fetch = async function(ctx) { let allDbs = await CouchDB.allDbs() const appDbNames = allDbs.filter(dbName => dbName.startsWith(APP_PREFIX)) - const apps = [] - for (let dbName of appDbNames) { - const db = new CouchDB(dbName) - apps.push(db.get(dbName)) - } + const apps = appDbNames.map(db => new CouchDB(db).get(db)) if (apps.length === 0) { ctx.body = [] } else {