From 7a6e677b8927587ec771f3c9bfb18a1b51cd1f99 Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 21:42:40 +0800
Subject: [PATCH 01/18] add arangodb integration
---
.../DatasourceNavigator/icons/ArangoDB.svelte | 22 +++++
.../DatasourceNavigator/icons/index.js | 2 +
packages/server/package.json | 1 +
packages/server/src/integrations/arangodb.js | 87 +++++++++++++++++++
packages/server/src/integrations/index.js | 3 +
5 files changed, 115 insertions(+)
create mode 100644 packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
create mode 100644 packages/server/src/integrations/arangodb.js
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte b/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
new file mode 100644
index 0000000000..0be4ca2663
--- /dev/null
+++ b/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
@@ -0,0 +1,22 @@
+
+
+
+
\ No newline at end of file
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/icons/index.js b/packages/builder/src/components/backend/DatasourceNavigator/icons/index.js
index 4f8d79dbf4..ff38782288 100644
--- a/packages/builder/src/components/backend/DatasourceNavigator/icons/index.js
+++ b/packages/builder/src/components/backend/DatasourceNavigator/icons/index.js
@@ -7,6 +7,7 @@ import S3 from "./S3.svelte"
import Airtable from "./Airtable.svelte"
import SqlServer from "./SQLServer.svelte"
import MySQL from "./MySQL.svelte"
+import ArangoDB from "./ArangoDB.svelte"
export default {
POSTGRES: Postgres,
@@ -18,4 +19,5 @@ export default {
S3: S3,
AIRTABLE: Airtable,
MYSQL: MySQL,
+ ARANGODB: ArangoDB,
}
diff --git a/packages/server/package.json b/packages/server/package.json
index fd8d5196a0..2ee2c79e22 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -56,6 +56,7 @@
"@sendgrid/mail": "^7.1.1",
"@sentry/node": "^5.19.2",
"airtable": "^0.10.1",
+ "arangojs": "^7.2.0",
"aws-sdk": "^2.767.0",
"bcryptjs": "^2.4.3",
"chmodr": "^1.2.0",
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
new file mode 100644
index 0000000000..eefd656cbc
--- /dev/null
+++ b/packages/server/src/integrations/arangodb.js
@@ -0,0 +1,87 @@
+const arangojs = require("arangojs")
+const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
+// const arangodb = arangojs.Database
+const aql = arangojs.aql
+
+const SCHEMA = {
+ docs: "https://github.com/arangodb/arangojs",
+ datasource: {
+ url: {
+ type: FIELD_TYPES.STRING,
+ default: "http://localhost:8529",
+ required: true,
+ },
+ username: {
+ type: FIELD_TYPES.STRING,
+ default: "root",
+ required: true,
+ },
+ password: {
+ type: FIELD_TYPES.PASSWORD,
+ required: true,
+ },
+ databaseName: {
+ type: FIELD_TYPES.STRING,
+ default: "_system",
+ required: true,
+ },
+ collection: {
+ type: FIELD_TYPES.STRING,
+ required: true,
+ },
+ },
+ query: {
+ read: {
+ type: QUERY_TYPES.SQL,
+ },
+ create: {
+ type: QUERY_TYPES.JSON,
+ },
+ },
+}
+
+class ArangoDBIntegration {
+ constructor(config) {
+ config.auth = {
+ username: config.username,
+ password: config.password,
+ }
+
+ this.config = config
+ this.client = arangojs.arangojs(config)
+ }
+
+ async read(query) {
+ try {
+ const result = await this.client.query(query.sql)
+ let rl = []
+ await result.forEach((r)=> rl.push(r))
+ return rl
+ } catch (err) {
+ console.error("Error querying arangodb",err.message)
+ throw err
+ } finally {
+ this.client.close()
+ }
+ }
+
+ async create(query) {
+ const clc = this.client.collection(this.config.collection)
+ try {
+ const result = await this.client.query(aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`)
+ let rl = []
+ await result.forEach((r)=> rl.push(r))
+ return rl
+ } catch (err) {
+ console.error("Error querying arangodb",err.message)
+ throw err
+ } finally {
+ this.client.close()
+ }
+ }
+}
+
+module.exports = {
+ schema: SCHEMA,
+ integration: ArangoDBIntegration,
+}
\ No newline at end of file
diff --git a/packages/server/src/integrations/index.js b/packages/server/src/integrations/index.js
index acb81992a9..8ff89f4900 100644
--- a/packages/server/src/integrations/index.js
+++ b/packages/server/src/integrations/index.js
@@ -7,6 +7,7 @@ const sqlServer = require("./microsoftSqlServer")
const s3 = require("./s3")
const airtable = require("./airtable")
const mysql = require("./mysql")
+const arangodb = require("./arangodb")
const DEFINITIONS = {
POSTGRES: postgres.schema,
@@ -18,6 +19,7 @@ const DEFINITIONS = {
S3: s3.schema,
AIRTABLE: airtable.schema,
MYSQL: mysql.schema,
+ ARANGODB: arangodb.schema,
}
const INTEGRATIONS = {
@@ -30,6 +32,7 @@ const INTEGRATIONS = {
SQL_SERVER: sqlServer.integration,
AIRTABLE: airtable.integration,
MYSQL: mysql.integration,
+ ARANGODB: arangodb.integration,
}
module.exports = {
From 1b6eb426c68e3d29a1057b13aeb1c6ac656b2d0f Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 21:48:29 +0800
Subject: [PATCH 02/18] add arangodb integration
---
packages/server/src/integrations/arangodb.js | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index eefd656cbc..f2aa54667e 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -1,7 +1,5 @@
-const arangojs = require("arangojs")
+const { Database, aql } = require("arangojs")
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
-// const arangodb = arangojs.Database
-const aql = arangojs.aql
const SCHEMA = {
docs: "https://github.com/arangodb/arangojs",
@@ -48,7 +46,7 @@ class ArangoDBIntegration {
}
this.config = config
- this.client = arangojs.arangojs(config)
+ this.client = new Database(config)
}
async read(query) {
From 8996200d8deba244a67932c3607fd71dda16afa2 Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 22:17:39 +0800
Subject: [PATCH 03/18] add arangodb integration
---
packages/server/src/integrations/arangodb.js | 136 ++++++++++---------
1 file changed, 69 insertions(+), 67 deletions(-)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index f2aa54667e..2b3ee1b11b 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -2,84 +2,86 @@ const { Database, aql } = require("arangojs")
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
const SCHEMA = {
- docs: "https://github.com/arangodb/arangojs",
- datasource: {
- url: {
- type: FIELD_TYPES.STRING,
- default: "http://localhost:8529",
- required: true,
- },
- username: {
- type: FIELD_TYPES.STRING,
- default: "root",
- required: true,
- },
- password: {
- type: FIELD_TYPES.PASSWORD,
- required: true,
- },
- databaseName: {
- type: FIELD_TYPES.STRING,
- default: "_system",
- required: true,
- },
- collection: {
- type: FIELD_TYPES.STRING,
- required: true,
- },
+ docs: "https://github.com/arangodb/arangojs",
+ datasource: {
+ url: {
+ type: FIELD_TYPES.STRING,
+ default: "http://localhost:8529",
+ required: true,
},
- query: {
- read: {
- type: QUERY_TYPES.SQL,
- },
- create: {
- type: QUERY_TYPES.JSON,
- },
+ username: {
+ type: FIELD_TYPES.STRING,
+ default: "root",
+ required: true,
},
+ password: {
+ type: FIELD_TYPES.PASSWORD,
+ required: true,
+ },
+ databaseName: {
+ type: FIELD_TYPES.STRING,
+ default: "_system",
+ required: true,
+ },
+ collection: {
+ type: FIELD_TYPES.STRING,
+ required: true,
+ },
+ },
+ query: {
+ read: {
+ type: QUERY_TYPES.SQL,
+ },
+ create: {
+ type: QUERY_TYPES.JSON,
+ },
+ },
}
class ArangoDBIntegration {
- constructor(config) {
- config.auth = {
- username: config.username,
- password: config.password,
- }
-
- this.config = config
- this.client = new Database(config)
+ constructor(config) {
+ config.auth = {
+ username: config.username,
+ password: config.password,
}
- async read(query) {
- try {
- const result = await this.client.query(query.sql)
- let rl = []
- await result.forEach((r)=> rl.push(r))
- return rl
- } catch (err) {
- console.error("Error querying arangodb",err.message)
- throw err
- } finally {
- this.client.close()
- }
- }
+ this.config = config
+ this.client = new Database(config)
+ }
- async create(query) {
- const clc = this.client.collection(this.config.collection)
- try {
- const result = await this.client.query(aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`)
- let rl = []
- await result.forEach((r)=> rl.push(r))
- return rl
- } catch (err) {
- console.error("Error querying arangodb",err.message)
- throw err
- } finally {
- this.client.close()
- }
+ async read(query) {
+ try {
+ const result = await this.client.query(query.sql)
+ let rl = []
+ await result.forEach(r => rl.push(r))
+ return rl
+ } catch (err) {
+ console.error("Error querying arangodb", err.message)
+ throw err
+ } finally {
+ this.client.close()
}
+ }
+
+ async create(query) {
+ const clc = this.client.collection(this.config.collection)
+ try {
+ const result = await this.client.query(
+ aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
+ )
+ let rl = []
+ await result.forEach(r => rl.push(r))
+ return rl
+ } catch (err) {
+ console.error("Error querying arangodb", err.message)
+ throw err
+ } finally {
+ this.client.close()
+ }
+ }
}
module.exports = {
schema: SCHEMA,
integration: ArangoDBIntegration,
-}
\ No newline at end of file
+}
From 0b8987f6a1411e61d1c95f8e52480d938bd745bf Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 22:20:15 +0800
Subject: [PATCH 04/18] add arangodb integration
---
packages/server/src/integrations/arangodb.js | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index 2b3ee1b11b..c886b6b918 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -52,9 +52,7 @@ class ArangoDBIntegration {
async read(query) {
try {
const result = await this.client.query(query.sql)
- let rl = []
- await result.forEach(r => rl.push(r))
- return rl
+ return result.forEach(r => rl.push(r))
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
@@ -69,9 +67,7 @@ class ArangoDBIntegration {
const result = await this.client.query(
aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
)
- let rl = []
- await result.forEach(r => rl.push(r))
- return rl
+ return result.forEach(r => rl.push(r))
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
From 9684def1ae97c1b115be0581e650bf54e156a2e2 Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 22:23:17 +0800
Subject: [PATCH 05/18] fix a little space
---
packages/server/src/integrations/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/server/src/integrations/index.js b/packages/server/src/integrations/index.js
index 8ff89f4900..9f9d5a1530 100644
--- a/packages/server/src/integrations/index.js
+++ b/packages/server/src/integrations/index.js
@@ -32,7 +32,7 @@ const INTEGRATIONS = {
SQL_SERVER: sqlServer.integration,
AIRTABLE: airtable.integration,
MYSQL: mysql.integration,
- ARANGODB: arangodb.integration,
+ ARANGODB: arangodb.integration,
}
module.exports = {
From aeee8af0d8b653854d070b7a733c91680780edfc Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 22:26:53 +0800
Subject: [PATCH 06/18] this commit is ok
---
packages/server/src/integrations/arangodb.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index c886b6b918..f4feed8246 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -52,6 +52,7 @@ class ArangoDBIntegration {
async read(query) {
try {
const result = await this.client.query(query.sql)
+ let rl = []
return result.forEach(r => rl.push(r))
} catch (err) {
console.error("Error querying arangodb", err.message)
@@ -67,6 +68,7 @@ class ArangoDBIntegration {
const result = await this.client.query(
aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
)
+ let rl = []
return result.forEach(r => rl.push(r))
} catch (err) {
console.error("Error querying arangodb", err.message)
From b4ccf9c1d25a019e985b14fc111c29802f35188a Mon Sep 17 00:00:00 2001
From: Andrew Kingston
Date: Thu, 28 Jan 2021 14:29:35 +0000
Subject: [PATCH 07/18] Add current user bindings, and current user
relationships as data sources
---
.../builder/src/builderStore/dataBinding.js | 32 ++++++++++++++++
packages/client/src/api/auth.js | 14 +++++++
.../client/src/components/ClientApp.svelte | 8 +---
.../client/src/components/Component.svelte | 8 ++--
packages/client/src/constants.js | 3 ++
packages/client/src/store/auth.js | 38 +++++++++++++++++--
packages/client/src/utils/componentProps.js | 3 +-
packages/server/src/api/controllers/auth.js | 14 +++++++
packages/server/src/api/routes/auth.js | 1 +
9 files changed, 106 insertions(+), 15 deletions(-)
create mode 100644 packages/client/src/constants.js
diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js
index 022e78c637..679a77ca2b 100644
--- a/packages/builder/src/builderStore/dataBinding.js
+++ b/packages/builder/src/builderStore/dataBinding.js
@@ -2,6 +2,7 @@ import { cloneDeep } from "lodash/fp"
import { get } from "svelte/store"
import { backendUiStore, store } from "builderStore"
import { findAllMatchingComponents, findComponentPath } from "./storeUtils"
+import { TableNames } from "../constants"
// Regex to match all instances of template strings
const CAPTURE_VAR_INSIDE_TEMPLATE = /{{([^}]+)}}/g
@@ -114,6 +115,37 @@ export const getContextBindings = (rootComponent, componentId) => {
})
})
})
+
+ // Add logged in user bindings
+ const tables = get(backendUiStore).tables
+ const userTable = tables.find(table => table._id === TableNames.USERS)
+ const schema = {
+ ...userTable.schema,
+ _id: { type: "string" },
+ _rev: { type: "string" },
+ }
+ const keys = Object.keys(schema).sort()
+ keys.forEach(key => {
+ const fieldSchema = schema[key]
+ // Replace certain bindings with a new property to help display components
+ let runtimeBoundKey = key
+ if (fieldSchema.type === "link") {
+ runtimeBoundKey = `${key}_count`
+ } else if (fieldSchema.type === "attachment") {
+ runtimeBoundKey = `${key}_first`
+ }
+
+ contextBindings.push({
+ type: "context",
+ runtimeBinding: `user.${runtimeBoundKey}`,
+ readableBinding: `Current User.${key}`,
+ fieldSchema,
+ providerId: "user",
+ tableId: TableNames.USERS,
+ field: key,
+ })
+ })
+
return contextBindings
}
diff --git a/packages/client/src/api/auth.js b/packages/client/src/api/auth.js
index ddaaa7a491..9b2988c69d 100644
--- a/packages/client/src/api/auth.js
+++ b/packages/client/src/api/auth.js
@@ -1,4 +1,6 @@
import API from "./api"
+import { enrichRows } from "./rows"
+import { TableNames } from "../constants"
/**
* Performs a log in request.
@@ -15,3 +17,15 @@ export const logIn = async ({ email, password }) => {
body: { email, password },
})
}
+
+/**
+ * Fetches the currently logged in user object
+ */
+export const fetchSelf = async () => {
+ const user = await API.get({ url: "/api/self" })
+ if (user?._id) {
+ return (await enrichRows([user], TableNames.USERS))[0]
+ } else {
+ return null
+ }
+}
diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte
index 659f34568b..d2dce14d34 100644
--- a/packages/client/src/components/ClientApp.svelte
+++ b/packages/client/src/components/ClientApp.svelte
@@ -4,12 +4,7 @@
import Component from "./Component.svelte"
import NotificationDisplay from "./NotificationDisplay.svelte"
import SDK from "../sdk"
- import {
- createDataStore,
- initialise,
- screenStore,
- notificationStore,
- } from "../store"
+ import { createDataStore, initialise, screenStore, authStore } from "../store"
// Provide contexts
setContext("sdk", SDK)
@@ -22,6 +17,7 @@
// Load app config
onMount(async () => {
await initialise()
+ await authStore.actions.fetchUser()
loaded = true
})
diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte
index 208ba21718..140d71ce80 100644
--- a/packages/client/src/components/Component.svelte
+++ b/packages/client/src/components/Component.svelte
@@ -4,7 +4,7 @@
import * as ComponentLibrary from "@budibase/standard-components"
import Router from "./Router.svelte"
import { enrichProps, propsAreSame } from "../utils/componentProps"
- import { bindingStore, builderStore } from "../store"
+ import { authStore, bindingStore, builderStore } from "../store"
export let definition = {}
@@ -23,7 +23,7 @@
$: constructor = getComponentConstructor(definition._component)
$: children = definition._children || []
$: id = definition._id
- $: enrichComponentProps(definition, $dataContext, $bindingStore)
+ $: enrichComponentProps(definition, $dataContext, $bindingStore, $authStore)
$: updateProps(enrichedProps)
$: styles = definition._styles
@@ -67,8 +67,8 @@
}
// Enriches any string component props using handlebars
- const enrichComponentProps = async (definition, context, bindingStore) => {
- enrichedProps = await enrichProps(definition, context, bindingStore)
+ const enrichComponentProps = async (definition, context, bindings, user) => {
+ enrichedProps = await enrichProps(definition, context, bindings, user)
}
// Returns a unique key to let svelte know when to remount components.
diff --git a/packages/client/src/constants.js b/packages/client/src/constants.js
new file mode 100644
index 0000000000..f5bdb4bb10
--- /dev/null
+++ b/packages/client/src/constants.js
@@ -0,0 +1,3 @@
+export const TableNames = {
+ USERS: "ta_users",
+}
diff --git a/packages/client/src/store/auth.js b/packages/client/src/store/auth.js
index d2ce04b604..e01915ec79 100644
--- a/packages/client/src/store/auth.js
+++ b/packages/client/src/store/auth.js
@@ -3,9 +3,10 @@ import { writable, get } from "svelte/store"
import { initialise } from "./initialise"
import { routeStore } from "./routes"
import { builderStore } from "./builder"
+import { TableNames } from "../constants"
const createAuthStore = () => {
- const store = writable("")
+ const store = writable(null)
const goToDefaultRoute = () => {
// Setting the active route forces an update of the active screen ID,
@@ -15,16 +16,20 @@ const createAuthStore = () => {
// Navigating updates the URL to reflect this route
routeStore.actions.navigate("/")
}
+
+ // Logs a user in
const logIn = async ({ email, password }) => {
const user = await API.logIn({ email, password })
if (!user.error) {
- store.set(user.token)
+ store.set(user)
await initialise()
goToDefaultRoute()
}
}
+
+ // Logs a user out
const logOut = async () => {
- store.set("")
+ store.set(null)
const appId = get(builderStore).appId
if (appId) {
for (let environment of ["local", "cloud"]) {
@@ -35,9 +40,34 @@ const createAuthStore = () => {
goToDefaultRoute()
}
+ // Fetches the user object if someone is logged in and has reloaded the page
+ const fetchUser = async () => {
+ // Fetch the first user if inside the builder
+ if (get(builderStore).inBuilder) {
+ const users = await API.fetchTableData(TableNames.USERS)
+ if (!users.error && users[0] != null) {
+ store.set(users[0])
+ }
+ }
+
+ // Or fetch the current user from localstorage in a real app
+ else {
+ if (get(store) == null) {
+ const user = await API.fetchSelf()
+ if (user) {
+ store.set(user)
+ } else {
+ await logOut()
+ }
+ } else {
+ await logOut()
+ }
+ }
+ }
+
return {
subscribe: store.subscribe,
- actions: { logIn, logOut },
+ actions: { logIn, logOut, fetchUser },
}
}
diff --git a/packages/client/src/utils/componentProps.js b/packages/client/src/utils/componentProps.js
index 7b322ec80f..fb421ca9fb 100644
--- a/packages/client/src/utils/componentProps.js
+++ b/packages/client/src/utils/componentProps.js
@@ -21,7 +21,7 @@ export const propsAreSame = (a, b) => {
* Enriches component props.
* Data bindings are enriched, and button actions are enriched.
*/
-export const enrichProps = async (props, dataContexts, dataBindings) => {
+export const enrichProps = async (props, dataContexts, dataBindings, user) => {
// Exclude all private props that start with an underscore
let validProps = {}
Object.entries(props)
@@ -35,6 +35,7 @@ export const enrichProps = async (props, dataContexts, dataBindings) => {
const context = {
...dataContexts,
...dataBindings,
+ user,
data: dataContexts[dataContexts.closestComponentId],
data_draft: dataContexts[`${dataContexts.closestComponentId}_draft`],
}
diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js
index f9c3ef945f..af6e0b2ee2 100644
--- a/packages/server/src/api/controllers/auth.js
+++ b/packages/server/src/api/controllers/auth.js
@@ -57,3 +57,17 @@ exports.authenticate = async ctx => {
ctx.throw(401, "Invalid credentials.")
}
}
+
+exports.fetchSelf = async ctx => {
+ const { userId, appId } = ctx.user
+ if (!userId || !appId) {
+ ctx.body = {}
+ } else {
+ const database = new CouchDB(appId)
+ const user = await database.get(userId)
+ if (user) {
+ delete user.password
+ }
+ ctx.body = user
+ }
+}
diff --git a/packages/server/src/api/routes/auth.js b/packages/server/src/api/routes/auth.js
index b4b68e8929..83053305c9 100644
--- a/packages/server/src/api/routes/auth.js
+++ b/packages/server/src/api/routes/auth.js
@@ -4,5 +4,6 @@ const controller = require("../controllers/auth")
const router = Router()
router.post("/api/authenticate", controller.authenticate)
+router.get("/api/self", controller.fetchSelf)
module.exports = router
From 2168991591e10867330f1b00bbc6bef87cd92b70 Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 22:35:41 +0800
Subject: [PATCH 08/18] cannot return result directly fix it
---
packages/server/src/integrations/arangodb.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index f4feed8246..2b3ee1b11b 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -53,7 +53,8 @@ class ArangoDBIntegration {
try {
const result = await this.client.query(query.sql)
let rl = []
- return result.forEach(r => rl.push(r))
+ await result.forEach(r => rl.push(r))
+ return rl
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
@@ -69,7 +70,8 @@ class ArangoDBIntegration {
aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
)
let rl = []
- return result.forEach(r => rl.push(r))
+ await result.forEach(r => rl.push(r))
+ return rl
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
From 08cbfd705fc5b5884b33d05bf19166e21517307c Mon Sep 17 00:00:00 2001
From: Andrew Kingston
Date: Thu, 28 Jan 2021 14:51:24 +0000
Subject: [PATCH 09/18] Remove logOut call when refreshing the page and not
logged in, to avoid changing the URL
---
packages/client/src/store/auth.js | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/packages/client/src/store/auth.js b/packages/client/src/store/auth.js
index e01915ec79..29ded50ac7 100644
--- a/packages/client/src/store/auth.js
+++ b/packages/client/src/store/auth.js
@@ -52,16 +52,8 @@ const createAuthStore = () => {
// Or fetch the current user from localstorage in a real app
else {
- if (get(store) == null) {
- const user = await API.fetchSelf()
- if (user) {
- store.set(user)
- } else {
- await logOut()
- }
- } else {
- await logOut()
- }
+ const user = await API.fetchSelf()
+ store.set(user)
}
}
From 96d9dd1ef2e55d02bf802a84b938a9fafa1adc54 Mon Sep 17 00:00:00 2001
From: Andrew Kingston
Date: Thu, 28 Jan 2021 14:51:37 +0000
Subject: [PATCH 10/18] Remove log statement
---
packages/server/src/api/controllers/static/index.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js
index 4f3d8d1611..2096b3039e 100644
--- a/packages/server/src/api/controllers/static/index.js
+++ b/packages/server/src/api/controllers/static/index.js
@@ -177,7 +177,6 @@ exports.serveApp = async function(ctx) {
})
const appHbs = fs.readFileSync(`${__dirname}/templates/app.hbs`, "utf8")
- console.log(appHbs)
ctx.body = await processString(appHbs, {
head,
body: html,
From 31925ce3c030712630883bb7eb1c8574f67297fe Mon Sep 17 00:00:00 2001
From: sovlookup <805408477@qq.com>
Date: Thu, 28 Jan 2021 23:08:53 +0800
Subject: [PATCH 11/18] prettify code
---
packages/server/src/integrations/arangodb.js | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/packages/server/src/integrations/arangodb.js b/packages/server/src/integrations/arangodb.js
index 2b3ee1b11b..10449fc967 100644
--- a/packages/server/src/integrations/arangodb.js
+++ b/packages/server/src/integrations/arangodb.js
@@ -52,9 +52,7 @@ class ArangoDBIntegration {
async read(query) {
try {
const result = await this.client.query(query.sql)
- let rl = []
- await result.forEach(r => rl.push(r))
- return rl
+ return result.all()
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
@@ -67,11 +65,9 @@ class ArangoDBIntegration {
const clc = this.client.collection(this.config.collection)
try {
const result = await this.client.query(
- aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
+ aql`INSERT ${query.json} INTO ${clc} RETURN NEW`
)
- let rl = []
- await result.forEach(r => rl.push(r))
- return rl
+ return result.all()
} catch (err) {
console.error("Error querying arangodb", err.message)
throw err
From f9190c1ed779ac5b7041b24d7d3de248de5f8685 Mon Sep 17 00:00:00 2001
From: Martin McKeaveney
Date: Thu, 28 Jan 2021 19:32:13 +0000
Subject: [PATCH 12/18] privacy features + allow builder usage without cloud
API key
---
packages/builder/src/analytics.js | 13 +++
.../DatasourceNavigator/icons/ArangoDB.svelte | 53 ++++++++----
.../components/settings/tabs/APIKeys.svelte | 10 ++-
.../start/BuilderSettingsModal.svelte | 21 +++++
.../components/start/CreateAppModal.svelte | 42 +---------
.../pages/[application]/deploy/index.svelte | 12 +++
packages/builder/src/pages/index.svelte | 5 +-
packages/server/yarn.lock | 81 ++++++++++++++++++-
8 files changed, 172 insertions(+), 65 deletions(-)
diff --git a/packages/builder/src/analytics.js b/packages/builder/src/analytics.js
index f59d71ac30..c68f228c12 100644
--- a/packages/builder/src/analytics.js
+++ b/packages/builder/src/analytics.js
@@ -106,6 +106,16 @@ function highlightFeedbackIcon() {
return isFeedbackTimeElapsed(firstRunStr)
}
+// Opt In/Out
+const ifAnalyticsEnabled = func => () => {
+ if (analyticsEnabled && process.env.POSTHOG_TOKEN) {
+ return func()
+ }
+}
+const disabled = () => posthog.has_opted_out_capturing()
+const optIn = () => posthog.opt_in_capturing()
+const optOut = () => posthog.opt_out_capturing()
+
export default {
activate,
identify,
@@ -115,4 +125,7 @@ export default {
requestFeedbackOnDeploy,
submitFeedback,
highlightFeedbackIcon,
+ disabled: ifAnalyticsEnabled(disabled),
+ optIn: ifAnalyticsEnabled(optIn),
+ optOut: ifAnalyticsEnabled(optOut),
}
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte b/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
index 0be4ca2663..d305c08af0 100644
--- a/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
+++ b/packages/builder/src/components/backend/DatasourceNavigator/icons/ArangoDB.svelte
@@ -3,20 +3,39 @@
export let height = "100"
-
-
\ No newline at end of file
+
diff --git a/packages/builder/src/components/settings/tabs/APIKeys.svelte b/packages/builder/src/components/settings/tabs/APIKeys.svelte
index 8e569596a4..82e66a12fd 100644
--- a/packages/builder/src/components/settings/tabs/APIKeys.svelte
+++ b/packages/builder/src/components/settings/tabs/APIKeys.svelte
@@ -1,6 +1,7 @@