Merge branch 'develop' into invalid_route_settings_section
# Conflicts: # packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte
This commit is contained in:
commit
0f3cb8e2ff
|
@ -7,6 +7,7 @@ on:
|
|||
|
||||
env:
|
||||
POSTHOG_TOKEN: ${{ secrets.POSTHOG_TOKEN }}
|
||||
INTERCOM_TOKEN: ${{ secrets.INTERCOM_TOKEN }}
|
||||
POSTHOG_URL: ${{ secrets.POSTHOG_URL }}
|
||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||
|
||||
|
|
|
@ -4,9 +4,16 @@ on:
|
|||
push:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release_self_host:
|
||||
description: 'Release to self hosters? (Y/N)'
|
||||
required: true
|
||||
default: 'N'
|
||||
|
||||
env:
|
||||
POSTHOG_TOKEN: ${{ secrets.POSTHOG_TOKEN }}
|
||||
INTERCOM_TOKEN: ${{ secrets.INTERCOM_TOKEN }}
|
||||
POSTHOG_URL: ${{ secrets.POSTHOG_URL }}
|
||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||
|
||||
|
@ -47,6 +54,18 @@ jobs:
|
|||
uses: "WyriHaximus/github-action-get-previous-tag@v1"
|
||||
|
||||
- name: Build/release Docker images
|
||||
if: ${{ github.event.inputs.release_self_host != 'Y' }}
|
||||
run: |
|
||||
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
|
||||
yarn build
|
||||
yarn build:docker
|
||||
env:
|
||||
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_API_KEY }}
|
||||
BUDIBASE_RELEASE_VERSION: ${{ steps.previoustag.outputs.tag }}
|
||||
|
||||
- name: Build/release Docker images (Self Host)
|
||||
if: ${{ github.event.inputs.release_self_host == 'Y' }}
|
||||
run: |
|
||||
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
|
||||
yarn build
|
||||
|
@ -68,4 +87,3 @@ jobs:
|
|||
charts_dir: docs
|
||||
env:
|
||||
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
|
@ -128,6 +128,6 @@ static_resources:
|
|||
- endpoint:
|
||||
address:
|
||||
socket_address:
|
||||
address: couchdb-service.budibase.svc.cluster.local
|
||||
address: budibase-prod-svc-couchdb
|
||||
port_value: 5984
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
"lint:fix": "yarn run lint:fix:ts && yarn run lint:fix:prettier && yarn run lint:fix:eslint",
|
||||
"test:e2e": "lerna run cy:test",
|
||||
"test:e2e:ci": "lerna run cy:ci",
|
||||
"build:docker": "lerna run build:docker && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh $BUDIBASE_RELEASE_VERSION release && cd -",
|
||||
"build:docker": "lerna run build:docker && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh $BUDIBASE_RELEASE_VERSION && cd -",
|
||||
"build:docker:production": "lerna run build:docker && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh $BUDIBASE_RELEASE_VERSION release && cd -",
|
||||
"build:docker:develop": "node scripts/pinVersions && lerna run build:docker && cd hosting/scripts/linux/ && ./release-to-docker-hub.sh develop && cd -",
|
||||
"release:helm": "./scripts/release_helm_chart.sh",
|
||||
"multi:enable": "lerna run multi:enable",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/auth",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"description": "Authentication middlewares for budibase builder and apps",
|
||||
"main": "src/index.js",
|
||||
"author": "Budibase",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const env = require("../src/environment")
|
||||
|
||||
env._set("SELF_HOSTED", "1")
|
||||
env._set("NODE_ENV", "jest")
|
||||
env._set("JWT_SECRET", "test-jwtsecret")
|
||||
env._set("LOG_LEVEL", "silent")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const redis = require("../redis/authRedis")
|
||||
const { getTenantId, lookupTenantId, getGlobalDB } = require("../tenancy")
|
||||
const env = require("../environment")
|
||||
const accounts = require("../cloud/accounts")
|
||||
|
||||
const EXPIRY_SECONDS = 3600
|
||||
|
||||
|
@ -9,6 +11,15 @@ const EXPIRY_SECONDS = 3600
|
|||
const populateFromDB = async (userId, tenantId) => {
|
||||
const user = await getGlobalDB(tenantId).get(userId)
|
||||
user.budibaseAccess = true
|
||||
|
||||
if (!env.SELF_HOSTED) {
|
||||
const account = await accounts.getAccount(user.email)
|
||||
if (account) {
|
||||
user.account = account
|
||||
user.accountPortalAccess = true
|
||||
}
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const API = require("./api")
|
||||
const env = require("../environment")
|
||||
|
||||
const api = new API(env.ACCOUNT_PORTAL_URL)
|
||||
|
||||
// TODO: Authorization
|
||||
|
||||
exports.getAccount = async email => {
|
||||
const payload = {
|
||||
email,
|
||||
}
|
||||
const response = await api.post(`/api/accounts/search`, {
|
||||
body: payload,
|
||||
})
|
||||
const json = await response.json()
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw Error(`Error getting account by email ${email}`, json)
|
||||
}
|
||||
|
||||
return json[0]
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
const fetch = require("node-fetch")
|
||||
class API {
|
||||
constructor(host) {
|
||||
this.host = host
|
||||
}
|
||||
|
||||
apiCall =
|
||||
method =>
|
||||
async (url = "", options = {}) => {
|
||||
if (!options.headers) {
|
||||
options.headers = {}
|
||||
}
|
||||
|
||||
if (!options.headers["Content-Type"]) {
|
||||
options.headers = {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
...options.headers,
|
||||
}
|
||||
}
|
||||
|
||||
let json = options.headers["Content-Type"] === "application/json"
|
||||
|
||||
const requestOptions = {
|
||||
method: method,
|
||||
body: json ? JSON.stringify(options.body) : options.body,
|
||||
headers: options.headers,
|
||||
// TODO: See if this is necessary
|
||||
credentials: "include",
|
||||
}
|
||||
|
||||
const resp = await fetch(`${this.host}${url}`, requestOptions)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
post = this.apiCall("POST")
|
||||
get = this.apiCall("GET")
|
||||
patch = this.apiCall("PATCH")
|
||||
del = this.apiCall("DELETE")
|
||||
put = this.apiCall("PUT")
|
||||
}
|
||||
|
||||
module.exports = API
|
|
@ -75,6 +75,9 @@ function isDevApp(app) {
|
|||
* @return {null|string} The tenant ID found within the app ID.
|
||||
*/
|
||||
exports.getTenantIDFromAppID = appId => {
|
||||
if (!appId) {
|
||||
return null
|
||||
}
|
||||
const split = appId.split(SEPARATOR)
|
||||
const hasDev = split[1] === DocumentTypes.DEV
|
||||
if ((hasDev && split.length === 3) || (!hasDev && split.length === 2)) {
|
||||
|
@ -236,9 +239,12 @@ exports.getAllApps = async (CouchDB, { dev, all, idsOnly } = {}) => {
|
|||
const split = dbName.split(SEPARATOR)
|
||||
// it is an app, check the tenantId
|
||||
if (split[0] === DocumentTypes.APP) {
|
||||
const noTenantId = split.length === 2 || split[1] === DocumentTypes.DEV
|
||||
// tenantId is always right before the UUID
|
||||
const possibleTenantId = split[split.length - 2]
|
||||
|
||||
const noTenantId =
|
||||
split.length === 2 || possibleTenantId === DocumentTypes.DEV
|
||||
|
||||
return (
|
||||
(tenantId === DEFAULT_TENANT_ID && noTenantId) ||
|
||||
possibleTenantId === tenantId
|
||||
|
|
|
@ -16,9 +16,12 @@ module.exports = {
|
|||
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
||||
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
||||
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
||||
AWS_REGION: process.env.AWS_REGION,
|
||||
MINIO_URL: process.env.MINIO_URL,
|
||||
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
||||
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||
ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
|
||||
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
|
||||
isTest,
|
||||
_set(key, value) {
|
||||
process.env[key] = value
|
||||
|
|
|
@ -12,6 +12,7 @@ const {
|
|||
auditLog,
|
||||
tenancy,
|
||||
appTenancy,
|
||||
authError,
|
||||
} = require("./middleware")
|
||||
const { setDB } = require("./db")
|
||||
const userCache = require("./cache/user")
|
||||
|
@ -60,6 +61,7 @@ module.exports = {
|
|||
buildTenancyMiddleware: tenancy,
|
||||
buildAppTenancyMiddleware: appTenancy,
|
||||
auditLog,
|
||||
authError,
|
||||
},
|
||||
cache: {
|
||||
user: userCache,
|
||||
|
|
|
@ -2,6 +2,7 @@ const jwt = require("./passport/jwt")
|
|||
const local = require("./passport/local")
|
||||
const google = require("./passport/google")
|
||||
const oidc = require("./passport/oidc")
|
||||
const { authError } = require("./passport/utils")
|
||||
const authenticated = require("./authenticated")
|
||||
const auditLog = require("./auditLog")
|
||||
const tenancy = require("./tenancy")
|
||||
|
@ -16,4 +17,5 @@ module.exports = {
|
|||
auditLog,
|
||||
tenancy,
|
||||
appTenancy,
|
||||
authError,
|
||||
}
|
||||
|
|
|
@ -27,7 +27,11 @@ async function authenticate(accessToken, refreshToken, profile, done) {
|
|||
* from couchDB rather than environment variables, using this factory is necessary for dynamically configuring passport.
|
||||
* @returns Dynamically configured Passport Google Strategy
|
||||
*/
|
||||
exports.strategyFactory = async function (config, callbackUrl) {
|
||||
exports.strategyFactory = async function (
|
||||
config,
|
||||
callbackUrl,
|
||||
verify = authenticate
|
||||
) {
|
||||
try {
|
||||
const { clientID, clientSecret } = config
|
||||
|
||||
|
@ -43,7 +47,7 @@ exports.strategyFactory = async function (config, callbackUrl) {
|
|||
clientSecret: config.clientSecret,
|
||||
callbackURL: callbackUrl,
|
||||
},
|
||||
authenticate
|
||||
verify
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
|
|
@ -104,7 +104,7 @@ describe("third party common", () => {
|
|||
_id: id,
|
||||
email: email,
|
||||
}
|
||||
const response = await db.post(dbUser)
|
||||
const response = await db.put(dbUser)
|
||||
dbUser._rev = response.rev
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ exports.authenticateThirdParty = async function (
|
|||
dbUser = await syncUser(dbUser, thirdPartyUser)
|
||||
|
||||
// create or sync the user
|
||||
const response = await db.post(dbUser)
|
||||
const response = await db.put(dbUser)
|
||||
dbUser._rev = response.rev
|
||||
|
||||
// authenticate
|
||||
|
|
|
@ -73,6 +73,7 @@ exports.ObjectStore = bucket => {
|
|||
AWS.config.update({
|
||||
accessKeyId: env.MINIO_ACCESS_KEY,
|
||||
secretAccessKey: env.MINIO_SECRET_KEY,
|
||||
region: env.AWS_REGION,
|
||||
})
|
||||
const config = {
|
||||
s3ForcePathStyle: true,
|
||||
|
|
|
@ -56,7 +56,6 @@ function init() {
|
|||
if (CLIENT) {
|
||||
CLIENT.disconnect()
|
||||
}
|
||||
|
||||
const { redisProtocolUrl, opts, host, port } = getRedisOptions(CLUSTERED)
|
||||
|
||||
if (CLUSTERED) {
|
||||
|
|
|
@ -30,6 +30,10 @@ exports.invalidateSessions = async (userId, sessionId = null) => {
|
|||
sessions.push({ key: makeSessionID(userId, sessionId) })
|
||||
} else {
|
||||
sessions = await getSessionsForUser(userId)
|
||||
sessions.forEach(
|
||||
session =>
|
||||
(session.key = makeSessionID(session.userId, session.sessionId))
|
||||
)
|
||||
}
|
||||
const client = await redis.getSessionClient()
|
||||
const promises = []
|
||||
|
|
|
@ -63,6 +63,7 @@ exports.tryAddTenant = async (tenantId, userId, email) => {
|
|||
}
|
||||
if (emailDoc) {
|
||||
emailDoc.tenantId = tenantId
|
||||
emailDoc.userId = userId
|
||||
promises.push(db.put(emailDoc))
|
||||
}
|
||||
if (tenants.tenantIds.indexOf(tenantId) === -1) {
|
||||
|
|
|
@ -4470,9 +4470,9 @@ tmp@^0.0.33:
|
|||
os-tmpdir "~1.0.2"
|
||||
|
||||
tmpl@1.0.x:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
|
||||
integrity sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"
|
||||
integrity sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==
|
||||
|
||||
to-fast-properties@^2.0.0:
|
||||
version "2.0.0"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/bbui",
|
||||
"description": "A UI solution used in the different Budibase projects.",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"license": "AGPL-3.0",
|
||||
"svelte": "src/index.js",
|
||||
"module": "dist/bbui.es.js",
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
export let enableTime = true
|
||||
export let value = null
|
||||
export let placeholder = null
|
||||
export let appendTo = null
|
||||
export let appendTo = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const flatpickrId = `${generateID()}-wrapper`
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
export let error = null
|
||||
export let enableTime = true
|
||||
export let placeholder = null
|
||||
export let appendTo = null
|
||||
export let appendTo = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const onChange = e => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/builder",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"license": "AGPL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -65,10 +65,10 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "^0.9.125-alpha.13",
|
||||
"@budibase/client": "^0.9.125-alpha.13",
|
||||
"@budibase/bbui": "^0.9.140-alpha.6",
|
||||
"@budibase/client": "^0.9.140-alpha.6",
|
||||
"@budibase/colorpicker": "1.1.2",
|
||||
"@budibase/string-templates": "^0.9.125-alpha.13",
|
||||
"@budibase/string-templates": "^0.9.140-alpha.6",
|
||||
"@sentry/browser": "5.19.1",
|
||||
"@spectrum-css/page": "^3.0.1",
|
||||
"@spectrum-css/vars": "^3.0.1",
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
<script>
|
||||
import { onMount } from "svelte"
|
||||
import { Router } from "@roxi/routify"
|
||||
import { routes } from "../.routify/routes"
|
||||
import { initialise } from "builderStore"
|
||||
import { NotificationDisplay } from "@budibase/bbui"
|
||||
import { parse, stringify } from "qs"
|
||||
import HelpIcon from "components/common/HelpIcon.svelte"
|
||||
|
||||
onMount(async () => {
|
||||
await initialise()
|
||||
})
|
||||
|
||||
const queryHandler = { parse, stringify }
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
import * as Sentry from "@sentry/browser"
|
||||
import posthog from "posthog-js"
|
||||
import api from "builderStore/api"
|
||||
|
||||
let analyticsEnabled
|
||||
const posthogConfigured = process.env.POSTHOG_TOKEN && process.env.POSTHOG_URL
|
||||
const sentryConfigured = process.env.SENTRY_DSN
|
||||
|
||||
const FEEDBACK_SUBMITTED_KEY = "budibase:feedback_submitted"
|
||||
const APP_FIRST_STARTED_KEY = "budibase:first_run"
|
||||
const feedbackHours = 12
|
||||
|
||||
async function activate() {
|
||||
if (analyticsEnabled === undefined) {
|
||||
// only the server knows the true NODE_ENV
|
||||
// this was an issue as NODE_ENV = 'cypress' on the server,
|
||||
// but 'production' on the client
|
||||
const response = await api.get("/api/analytics")
|
||||
analyticsEnabled = (await response.json()).enabled === true
|
||||
}
|
||||
if (!analyticsEnabled) return
|
||||
if (sentryConfigured) Sentry.init({ dsn: process.env.SENTRY_DSN })
|
||||
if (posthogConfigured) {
|
||||
posthog.init(process.env.POSTHOG_TOKEN, {
|
||||
autocapture: false,
|
||||
capture_pageview: false,
|
||||
api_host: process.env.POSTHOG_URL,
|
||||
})
|
||||
posthog.set_config({ persistence: "cookie" })
|
||||
}
|
||||
}
|
||||
|
||||
function identify(id) {
|
||||
if (!analyticsEnabled || !id) return
|
||||
if (posthogConfigured) posthog.identify(id)
|
||||
if (sentryConfigured)
|
||||
Sentry.configureScope(scope => {
|
||||
scope.setUser({ id: id })
|
||||
})
|
||||
}
|
||||
|
||||
async function identifyByApiKey(apiKey) {
|
||||
if (!analyticsEnabled) return true
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://03gaine137.execute-api.eu-west-1.amazonaws.com/prod/account/id?api_key=${apiKey.trim()}`
|
||||
)
|
||||
if (response.status === 200) {
|
||||
const id = await response.json()
|
||||
|
||||
await api.put("/api/keys/userId", { value: id })
|
||||
identify(id)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
function captureException(err) {
|
||||
if (!analyticsEnabled) return
|
||||
Sentry.captureException(err)
|
||||
captureEvent("Error", { error: err.message ? err.message : err })
|
||||
}
|
||||
|
||||
function captureEvent(eventName, props = {}) {
|
||||
if (!analyticsEnabled || !process.env.POSTHOG_TOKEN) return
|
||||
props.sourceApp = "builder"
|
||||
posthog.capture(eventName, props)
|
||||
}
|
||||
|
||||
if (!localStorage.getItem(APP_FIRST_STARTED_KEY)) {
|
||||
localStorage.setItem(APP_FIRST_STARTED_KEY, Date.now())
|
||||
}
|
||||
|
||||
const isFeedbackTimeElapsed = sinceDateStr => {
|
||||
const sinceDate = parseFloat(sinceDateStr)
|
||||
const feedbackMilliseconds = feedbackHours * 60 * 60 * 1000
|
||||
return Date.now() > sinceDate + feedbackMilliseconds
|
||||
}
|
||||
|
||||
function submitFeedback(values) {
|
||||
if (!analyticsEnabled || !process.env.POSTHOG_TOKEN) return
|
||||
localStorage.setItem(FEEDBACK_SUBMITTED_KEY, Date.now())
|
||||
|
||||
const prefixedValues = Object.entries(values).reduce((obj, [key, value]) => {
|
||||
obj[`feedback_${key}`] = value
|
||||
return obj
|
||||
}, {})
|
||||
|
||||
posthog.capture("Feedback Submitted", prefixedValues)
|
||||
}
|
||||
|
||||
function requestFeedbackOnDeploy() {
|
||||
if (!analyticsEnabled || !process.env.POSTHOG_TOKEN) return false
|
||||
const lastSubmittedStr = localStorage.getItem(FEEDBACK_SUBMITTED_KEY)
|
||||
if (!lastSubmittedStr) return true
|
||||
return isFeedbackTimeElapsed(lastSubmittedStr)
|
||||
}
|
||||
|
||||
function highlightFeedbackIcon() {
|
||||
if (!analyticsEnabled || !process.env.POSTHOG_TOKEN) return false
|
||||
const lastSubmittedStr = localStorage.getItem(FEEDBACK_SUBMITTED_KEY)
|
||||
if (lastSubmittedStr) return isFeedbackTimeElapsed(lastSubmittedStr)
|
||||
const firstRunStr = localStorage.getItem(APP_FIRST_STARTED_KEY)
|
||||
if (!firstRunStr) return false
|
||||
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,
|
||||
identifyByApiKey,
|
||||
captureException,
|
||||
captureEvent,
|
||||
requestFeedbackOnDeploy,
|
||||
submitFeedback,
|
||||
highlightFeedbackIcon,
|
||||
disabled: () => {
|
||||
if (analyticsEnabled == null) {
|
||||
return true
|
||||
}
|
||||
return ifAnalyticsEnabled(disabled)
|
||||
},
|
||||
optIn: ifAnalyticsEnabled(optIn),
|
||||
optOut: ifAnalyticsEnabled(optOut),
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
export default class IntercomClient {
|
||||
constructor(token) {
|
||||
this.token = token
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate intercom using their provided script.
|
||||
*/
|
||||
init() {
|
||||
if (!this.token) return
|
||||
|
||||
const token = this.token
|
||||
|
||||
var w = window
|
||||
var ic = w.Intercom
|
||||
if (typeof ic === "function") {
|
||||
ic("reattach_activator")
|
||||
ic("update", w.intercomSettings)
|
||||
} else {
|
||||
var d = document
|
||||
var i = function () {
|
||||
i.c(arguments)
|
||||
}
|
||||
i.q = []
|
||||
i.c = function (args) {
|
||||
i.q.push(args)
|
||||
}
|
||||
w.Intercom = i
|
||||
var l = function () {
|
||||
var s = d.createElement("script")
|
||||
s.type = "text/javascript"
|
||||
s.async = true
|
||||
s.src = "https://widget.intercom.io/widget/" + token
|
||||
var x = d.getElementsByTagName("script")[0]
|
||||
x.parentNode.insertBefore(s, x)
|
||||
}
|
||||
if (document.readyState === "complete") {
|
||||
l()
|
||||
} else if (w.attachEvent) {
|
||||
w.attachEvent("onload", l)
|
||||
} else {
|
||||
w.addEventListener("load", l, false)
|
||||
}
|
||||
|
||||
this.initialised = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the intercom chat bubble.
|
||||
* @param {Object} user - user to identify
|
||||
* @returns Intercom global object
|
||||
*/
|
||||
show(user = {}) {
|
||||
if (!this.initialised) return
|
||||
|
||||
return window.Intercom("boot", {
|
||||
app_id: this.token,
|
||||
...user,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Update intercom user details and messages.
|
||||
* @returns Intercom global object
|
||||
*/
|
||||
update() {
|
||||
if (!this.initialised) return
|
||||
|
||||
return window.Intercom("update")
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture analytics events and send them to intercom.
|
||||
* @param {String} event - event identifier
|
||||
* @param {Object} props - properties for the event
|
||||
* @returns Intercom global object
|
||||
*/
|
||||
captureEvent(event, props = {}) {
|
||||
if (!this.initialised) return
|
||||
|
||||
return window.Intercom("trackEvent", event, props)
|
||||
}
|
||||
|
||||
/**
|
||||
* Disassociate the user from the current session.
|
||||
* @returns Intercom global object
|
||||
*/
|
||||
logout() {
|
||||
if (!this.initialised) return
|
||||
|
||||
return window.Intercom("shutdown")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
import posthog from "posthog-js"
|
||||
import { Events } from "./constants"
|
||||
|
||||
export default class PosthogClient {
|
||||
constructor(token, url) {
|
||||
this.token = token
|
||||
this.url = url
|
||||
}
|
||||
|
||||
init() {
|
||||
if (!this.token || !this.url) return
|
||||
|
||||
posthog.init(this.token, {
|
||||
autocapture: false,
|
||||
capture_pageview: false,
|
||||
api_host: this.url,
|
||||
})
|
||||
posthog.set_config({ persistence: "cookie" })
|
||||
|
||||
this.initialised = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the posthog context to the current user
|
||||
* @param {String} id - unique user id
|
||||
*/
|
||||
identify(id) {
|
||||
if (!this.initialised) return
|
||||
|
||||
posthog.identify(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user metadata associated with current user in posthog
|
||||
* @param {Object} meta - user fields
|
||||
*/
|
||||
updateUser(meta) {
|
||||
if (!this.initialised) return
|
||||
|
||||
posthog.people.set(meta)
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture analytics events and send them to posthog.
|
||||
* @param {String} event - event identifier
|
||||
* @param {Object} props - properties for the event
|
||||
*/
|
||||
captureEvent(eventName, props) {
|
||||
if (!this.initialised) return
|
||||
|
||||
props.sourceApp = "builder"
|
||||
posthog.capture(eventName, props)
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit NPS feedback to posthog.
|
||||
* @param {Object} values - NPS Values
|
||||
*/
|
||||
npsFeedback(values) {
|
||||
if (!this.initialised) return
|
||||
|
||||
localStorage.setItem(Events.NPS.SUBMITTED, Date.now())
|
||||
|
||||
const prefixedFeedback = {}
|
||||
for (let key in values) {
|
||||
prefixedFeedback[`feedback_${key}`] = values[key]
|
||||
}
|
||||
|
||||
posthog.capture(Events.NPS.SUBMITTED, prefixedFeedback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset posthog user back to initial state on logout.
|
||||
*/
|
||||
logout() {
|
||||
if (!this.initialised) return
|
||||
|
||||
posthog.reset()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import * as Sentry from "@sentry/browser"
|
||||
|
||||
export default class SentryClient {
|
||||
constructor(dsn) {
|
||||
this.dsn = dsn
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.dsn) {
|
||||
Sentry.init({ dsn: this.dsn })
|
||||
|
||||
this.initalised = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture an exception and send it to sentry.
|
||||
* @param {Error} err - JS error object
|
||||
*/
|
||||
captureException(err) {
|
||||
if (!this.initalised) return
|
||||
|
||||
Sentry.captureException(err)
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify user in sentry.
|
||||
* @param {String} id - Unique user id
|
||||
*/
|
||||
identify(id) {
|
||||
if (!this.initalised) return
|
||||
|
||||
Sentry.configureScope(scope => {
|
||||
scope.setUser({ id })
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
export const Events = {
|
||||
BUILDER: {
|
||||
STARTED: "Builder Started",
|
||||
},
|
||||
COMPONENT: {
|
||||
CREATED: "Added Component",
|
||||
},
|
||||
DATASOURCE: {
|
||||
CREATED: "Datasource Created",
|
||||
UPDATED: "Datasource Updated",
|
||||
},
|
||||
TABLE: {
|
||||
CREATED: "Table Created",
|
||||
},
|
||||
VIEW: {
|
||||
CREATED: "View Created",
|
||||
ADDED_FILTER: "Added View Filter",
|
||||
ADDED_CALCULATE: "Added View Calculate",
|
||||
},
|
||||
SCREEN: {
|
||||
CREATED: "Screen Created",
|
||||
},
|
||||
AUTOMATION: {
|
||||
CREATED: "Automation Created",
|
||||
SAVED: "Automation Saved",
|
||||
BLOCK_ADDED: "Added Automation Block",
|
||||
},
|
||||
NPS: {
|
||||
SUBMITTED: "budibase:feedback_submitted",
|
||||
},
|
||||
APP: {
|
||||
CREATED: "budibase:app_created",
|
||||
PUBLISHED: "budibase:app_published",
|
||||
UNPUBLISHED: "budibase:app_unpublished",
|
||||
},
|
||||
ANALYTICS: {
|
||||
OPT_IN: "budibase:analytics_opt_in",
|
||||
OPT_OUT: "budibase:analytics_opt_out",
|
||||
},
|
||||
USER: {
|
||||
INVITE: "budibase:portal_user_invite",
|
||||
},
|
||||
SMTP: {
|
||||
SAVED: "budibase:smtp_saved",
|
||||
},
|
||||
SSO: {
|
||||
SAVED: "budibase:sso_saved",
|
||||
},
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
import api from "builderStore/api"
|
||||
import PosthogClient from "./PosthogClient"
|
||||
import IntercomClient from "./IntercomClient"
|
||||
import SentryClient from "./SentryClient"
|
||||
import { Events } from "./constants"
|
||||
import { auth } from "stores/portal"
|
||||
import { get } from "svelte/store"
|
||||
|
||||
const posthog = new PosthogClient(
|
||||
process.env.POSTHOG_TOKEN,
|
||||
process.env.POSTHOG_URL
|
||||
)
|
||||
const sentry = new SentryClient(process.env.SENTRY_DSN)
|
||||
const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
|
||||
|
||||
class AnalyticsHub {
|
||||
constructor() {
|
||||
this.clients = [posthog, sentry, intercom]
|
||||
}
|
||||
|
||||
async activate() {
|
||||
// Setting the analytics env var off in the backend overrides org/tenant settings
|
||||
const analyticsStatus = await api.get("/api/analytics")
|
||||
const json = await analyticsStatus.json()
|
||||
|
||||
// Multitenancy disabled on the backend
|
||||
if (!json.enabled) return
|
||||
|
||||
const tenantId = get(auth).tenantId
|
||||
|
||||
if (tenantId) {
|
||||
const res = await api.get(
|
||||
`/api/global/configs/public?tenantId=${tenantId}`
|
||||
)
|
||||
const orgJson = await res.json()
|
||||
|
||||
// analytics opted out for the tenant
|
||||
if (orgJson.config?.analytics === false) return
|
||||
}
|
||||
|
||||
this.clients.forEach(client => client.init())
|
||||
this.enabled = true
|
||||
}
|
||||
|
||||
identify(id, metadata) {
|
||||
posthog.identify(id)
|
||||
if (metadata) {
|
||||
posthog.updateUser(metadata)
|
||||
}
|
||||
sentry.identify(id)
|
||||
}
|
||||
|
||||
captureException(err) {
|
||||
sentry.captureException(err)
|
||||
}
|
||||
|
||||
captureEvent(eventName, props = {}) {
|
||||
posthog.captureEvent(eventName, props)
|
||||
intercom.captureEvent(eventName, props)
|
||||
}
|
||||
|
||||
showChat(user) {
|
||||
intercom.show(user)
|
||||
}
|
||||
|
||||
submitFeedback(values) {
|
||||
posthog.npsFeedback(values)
|
||||
}
|
||||
|
||||
async logout() {
|
||||
posthog.logout()
|
||||
intercom.logout()
|
||||
}
|
||||
}
|
||||
|
||||
const analytics = new AnalyticsHub()
|
||||
|
||||
export { Events }
|
||||
export default analytics
|
|
@ -443,7 +443,10 @@ function bindingReplacement(bindableProperties, textWithBindings, convertTo) {
|
|||
for (let from of convertFromProps) {
|
||||
if (shouldReplaceBinding(newBoundValue, from, convertTo)) {
|
||||
const binding = bindableProperties.find(el => el[convertFrom] === from)
|
||||
newBoundValue = newBoundValue.replace(from, binding[convertTo])
|
||||
newBoundValue = newBoundValue.replace(
|
||||
new RegExp(from, "gi"),
|
||||
binding[convertTo]
|
||||
)
|
||||
}
|
||||
}
|
||||
result = result.replace(boundValue, newBoundValue)
|
||||
|
|
|
@ -3,7 +3,6 @@ import { getAutomationStore } from "./store/automation"
|
|||
import { getHostingStore } from "./store/hosting"
|
||||
import { getThemeStore } from "./store/theme"
|
||||
import { derived, writable } from "svelte/store"
|
||||
import analytics from "analytics"
|
||||
import { FrontendTypes, LAYOUT_NAMES } from "../constants"
|
||||
import { findComponent } from "./storeUtils"
|
||||
|
||||
|
@ -55,13 +54,4 @@ export const mainLayout = derived(store, $store => {
|
|||
|
||||
export const selectedAccessRole = writable("BASIC")
|
||||
|
||||
export const initialise = async () => {
|
||||
try {
|
||||
await analytics.activate()
|
||||
analytics.captureEvent("Builder Started")
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
export const screenSearchString = writable(null)
|
||||
|
|
|
@ -2,7 +2,7 @@ import { writable } from "svelte/store"
|
|||
import api from "../../api"
|
||||
import Automation from "./Automation"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
const automationActions = store => ({
|
||||
fetch: async () => {
|
||||
|
@ -45,21 +45,24 @@ const automationActions = store => ({
|
|||
return state
|
||||
})
|
||||
},
|
||||
save: async ({ automation }) => {
|
||||
save: async automation => {
|
||||
const UPDATE_AUTOMATION_URL = `/api/automations`
|
||||
const response = await api.put(UPDATE_AUTOMATION_URL, automation)
|
||||
const json = await response.json()
|
||||
store.update(state => {
|
||||
const newAutomation = json.automation
|
||||
const existingIdx = state.automations.findIndex(
|
||||
existing => existing._id === automation._id
|
||||
)
|
||||
state.automations.splice(existingIdx, 1, json.automation)
|
||||
state.automations = state.automations
|
||||
store.actions.select(json.automation)
|
||||
if (existingIdx !== -1) {
|
||||
state.automations.splice(existingIdx, 1, newAutomation)
|
||||
state.automations = [...state.automations]
|
||||
store.actions.select(newAutomation)
|
||||
return state
|
||||
}
|
||||
})
|
||||
},
|
||||
delete: async ({ automation }) => {
|
||||
delete: async automation => {
|
||||
const { _id, _rev } = automation
|
||||
const DELETE_AUTOMATION_URL = `/api/automations/${_id}/${_rev}`
|
||||
await api.delete(DELETE_AUTOMATION_URL)
|
||||
|
@ -69,17 +72,17 @@ const automationActions = store => ({
|
|||
existing => existing._id === _id
|
||||
)
|
||||
state.automations.splice(existingIdx, 1)
|
||||
state.automations = state.automations
|
||||
state.automations = [...state.automations]
|
||||
state.selectedAutomation = null
|
||||
state.selectedBlock = null
|
||||
return state
|
||||
})
|
||||
},
|
||||
trigger: async ({ automation }) => {
|
||||
trigger: async automation => {
|
||||
const { _id } = automation
|
||||
return await api.post(`/api/automations/${_id}/trigger`)
|
||||
},
|
||||
test: async ({ automation }, testData) => {
|
||||
test: async (automation, testData) => {
|
||||
const { _id } = automation
|
||||
const response = await api.post(`/api/automations/${_id}/test`, testData)
|
||||
const json = await response.json()
|
||||
|
@ -107,7 +110,7 @@ const automationActions = store => ({
|
|||
state.selectedBlock = newBlock
|
||||
return state
|
||||
})
|
||||
analytics.captureEvent("Added Automation Block", {
|
||||
analytics.captureEvent(Events.AUTOMATION.BLOCK_ADDED, {
|
||||
name: block.name,
|
||||
})
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import { fetchComponentLibDefinitions } from "../loadComponentLibraries"
|
||||
import api from "../api"
|
||||
import { FrontendTypes } from "constants"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import {
|
||||
findComponentType,
|
||||
findComponentParent,
|
||||
|
@ -215,6 +215,13 @@ export const getFrontendStore = () => {
|
|||
if (screenToDelete._id === state.selectedScreenId) {
|
||||
state.selectedScreenId = null
|
||||
}
|
||||
//remove the link for this screen
|
||||
screenDeletePromises.push(
|
||||
store.actions.components.links.delete(
|
||||
screenToDelete.routing.route,
|
||||
screenToDelete.props._instanceName
|
||||
)
|
||||
)
|
||||
}
|
||||
return state
|
||||
})
|
||||
|
@ -443,7 +450,7 @@ export const getFrontendStore = () => {
|
|||
})
|
||||
|
||||
// Log event
|
||||
analytics.captureEvent("Added Component", {
|
||||
analytics.captureEvent(Events.COMPONENT.CREATED, {
|
||||
name: componentInstance._component,
|
||||
})
|
||||
|
||||
|
@ -646,6 +653,36 @@ export const getFrontendStore = () => {
|
|||
// Save layout
|
||||
await store.actions.layouts.save(layout)
|
||||
},
|
||||
delete: async (url, title) => {
|
||||
const layout = get(mainLayout)
|
||||
if (!layout) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add link setting to main layout
|
||||
if (layout.props._component.endsWith("layout")) {
|
||||
// If using a new SDK, add to the layout component settings
|
||||
layout.props.links = layout.props.links.filter(
|
||||
link => !(link.text === title && link.url === url)
|
||||
)
|
||||
} else {
|
||||
// If using an old SDK, add to the navigation component
|
||||
// TODO: remove this when we can assume everyone has updated
|
||||
const nav = findComponentType(
|
||||
layout.props,
|
||||
"@budibase/standard-components/navigation"
|
||||
)
|
||||
if (!nav) {
|
||||
return
|
||||
}
|
||||
|
||||
nav._children = nav._children.filter(
|
||||
child => !(child.url === url && child.text === title)
|
||||
)
|
||||
}
|
||||
// Save layout
|
||||
await store.actions.layouts.save(layout)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -38,10 +38,9 @@
|
|||
actionVal
|
||||
)
|
||||
automationStore.actions.addBlockToAutomation(newBlock)
|
||||
await automationStore.actions.save({
|
||||
instanceId,
|
||||
automation: $automationStore.selectedAutomation?.automation,
|
||||
})
|
||||
await automationStore.actions.save(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -124,7 +123,7 @@
|
|||
padding: var(--spectrum-alias-item-padding-s);
|
||||
background: var(--spectrum-alias-background-color-secondary);
|
||||
transition: 0.3s all;
|
||||
border: solid #3b3d3c;
|
||||
border: solid var(--spectrum-alias-border-color);
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
border-width: 2px;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<script>
|
||||
import { automationStore } from "builderStore"
|
||||
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import FlowItem from "./FlowItem.svelte"
|
||||
import TestDataModal from "./TestDataModal.svelte"
|
||||
|
||||
import { flip } from "svelte/animate"
|
||||
import { fade, fly } from "svelte/transition"
|
||||
import {
|
||||
|
@ -13,13 +12,12 @@
|
|||
notifications,
|
||||
Modal,
|
||||
} from "@budibase/bbui"
|
||||
import { database } from "stores/backend"
|
||||
|
||||
export let automation
|
||||
export let onSelect
|
||||
let testDataModal
|
||||
let blocks
|
||||
$: instanceId = $database._id
|
||||
let confirmDeleteDialog
|
||||
|
||||
$: {
|
||||
blocks = []
|
||||
|
@ -32,16 +30,16 @@
|
|||
}
|
||||
|
||||
async function deleteAutomation() {
|
||||
await automationStore.actions.delete({
|
||||
instanceId,
|
||||
automation: $automationStore.selectedAutomation?.automation,
|
||||
})
|
||||
await automationStore.actions.delete(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
notifications.success("Automation deleted.")
|
||||
}
|
||||
|
||||
async function testAutomation() {
|
||||
const result = await automationStore.actions.trigger({
|
||||
automation: $automationStore.selectedAutomation.automation,
|
||||
})
|
||||
const result = await automationStore.actions.trigger(
|
||||
$automationStore.selectedAutomation.automation
|
||||
)
|
||||
if (result.status === 200) {
|
||||
notifications.success(
|
||||
`Automation ${$automationStore.selectedAutomation.automation.name} triggered successfully.`
|
||||
|
@ -64,8 +62,14 @@
|
|||
style="display:flex;
|
||||
color: var(--spectrum-global-color-gray-400);"
|
||||
>
|
||||
<span on:click={() => deleteAutomation()} class="iconPadding">
|
||||
<Icon name="DeleteOutline" />
|
||||
<span class="iconPadding">
|
||||
<div class="icon">
|
||||
<Icon
|
||||
on:click={confirmDeleteDialog.show}
|
||||
hoverable
|
||||
name="DeleteOutline"
|
||||
/>
|
||||
</div>
|
||||
</span>
|
||||
<ActionButton
|
||||
on:click={() => {
|
||||
|
@ -93,6 +97,17 @@
|
|||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<ConfirmDialog
|
||||
bind:this={confirmDeleteDialog}
|
||||
okText="Delete Automation"
|
||||
onOk={deleteAutomation}
|
||||
title="Confirm Deletion"
|
||||
>
|
||||
Are you sure you wish to delete the automation
|
||||
<i>{automation.name}?</i>
|
||||
This action cannot be undone.
|
||||
</ConfirmDialog>
|
||||
|
||||
<Modal bind:this={testDataModal} width="30%">
|
||||
<TestDataModal {testAutomation} />
|
||||
</Modal>
|
||||
|
@ -140,7 +155,7 @@
|
|||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.iconPadding {
|
||||
.icon {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
padding-right: var(--spacing-m);
|
||||
|
|
|
@ -52,10 +52,9 @@
|
|||
|
||||
async function deleteStep() {
|
||||
automationStore.actions.deleteAutomationBlock(block)
|
||||
await automationStore.actions.save({
|
||||
instanceId,
|
||||
automation: $automationStore.selectedAutomation?.automation,
|
||||
})
|
||||
await automationStore.actions.save(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -42,7 +42,10 @@
|
|||
disabled={isError}
|
||||
onConfirm={() => {
|
||||
automationStore.actions.addTestDataToAutomation(testData)
|
||||
automationStore.actions.test($automationStore.selectedAutomation, testData)
|
||||
automationStore.actions.test(
|
||||
$automationStore.selectedAutomation?.automation,
|
||||
testData
|
||||
)
|
||||
}}
|
||||
cancelText="Cancel"
|
||||
>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import { automationStore } from "builderStore"
|
||||
import { notifications } from "@budibase/bbui"
|
||||
import { Input, ModalContent, Layout, Body, Icon } from "@budibase/bbui"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
let name
|
||||
let selectedTrigger
|
||||
|
@ -29,15 +29,14 @@
|
|||
webhookModal.show
|
||||
}
|
||||
|
||||
await automationStore.actions.save({
|
||||
instanceId,
|
||||
automation: $automationStore.selectedAutomation?.automation,
|
||||
})
|
||||
await automationStore.actions.save(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
|
||||
notifications.success(`Automation ${name} created.`)
|
||||
|
||||
$goto(`./${$automationStore.selectedAutomation.automation._id}`)
|
||||
analytics.captureEvent("Automation Created", { name })
|
||||
analytics.captureEvent(Events.AUTOMATION.CREATED, { name })
|
||||
}
|
||||
$: triggers = Object.entries($automationStore.blockDefinitions.TRIGGER)
|
||||
|
||||
|
@ -103,7 +102,7 @@
|
|||
padding: var(--spectrum-alias-item-padding-s);
|
||||
background: var(--spectrum-alias-background-color-secondary);
|
||||
transition: 0.3s all;
|
||||
border: solid #3b3d3c;
|
||||
border: solid var(--spectrum-alias-border-color);
|
||||
border-radius: 5px;
|
||||
box-sizing: border-box;
|
||||
border-width: 2px;
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
<script>
|
||||
import { goto } from "@roxi/routify"
|
||||
import { automationStore } from "builderStore"
|
||||
import { database } from "stores/backend"
|
||||
import { ActionMenu, MenuItem, notifications, Icon } from "@budibase/bbui"
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import UpdateAutomationModal from "components/automation/AutomationPanel/UpdateAutomationModal.svelte"
|
||||
|
||||
export let automation
|
||||
|
||||
let confirmDeleteDialog
|
||||
$: instanceId = $database._id
|
||||
let updateAutomationDialog
|
||||
|
||||
async function deleteAutomation() {
|
||||
await automationStore.actions.delete({
|
||||
instanceId,
|
||||
automation,
|
||||
})
|
||||
await automationStore.actions.delete(automation)
|
||||
notifications.success("Automation deleted.")
|
||||
$goto("../automate")
|
||||
}
|
||||
|
@ -24,9 +21,8 @@
|
|||
<div slot="control" class="icon">
|
||||
<Icon s hoverable name="MoreSmallList" />
|
||||
</div>
|
||||
<MenuItem noClose icon="Delete" on:click={confirmDeleteDialog.show}>
|
||||
Delete
|
||||
</MenuItem>
|
||||
<MenuItem icon="Edit" on:click={updateAutomationDialog.show}>Edit</MenuItem>
|
||||
<MenuItem icon="Delete" on:click={confirmDeleteDialog.show}>Delete</MenuItem>
|
||||
</ActionMenu>
|
||||
|
||||
<ConfirmDialog
|
||||
|
@ -39,6 +35,7 @@
|
|||
<i>{automation.name}?</i>
|
||||
This action cannot be undone.
|
||||
</ConfirmDialog>
|
||||
<UpdateAutomationModal {automation} bind:this={updateAutomationDialog} />
|
||||
|
||||
<style>
|
||||
div.icon {
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<script>
|
||||
import { automationStore } from "builderStore"
|
||||
import { notifications } from "@budibase/bbui"
|
||||
import { Icon, Input, ModalContent, Modal } from "@budibase/bbui"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
let name
|
||||
let error = ""
|
||||
let modal
|
||||
|
||||
export let automation
|
||||
export let onCancel = undefined
|
||||
|
||||
export const show = () => {
|
||||
name = automation?.name
|
||||
modal.show()
|
||||
}
|
||||
export const hide = () => {
|
||||
modal.hide()
|
||||
}
|
||||
|
||||
async function saveAutomation() {
|
||||
const updatedAutomation = {
|
||||
...automation,
|
||||
name,
|
||||
}
|
||||
await automationStore.actions.save(updatedAutomation)
|
||||
notifications.success(`Automation ${name} updated successfully.`)
|
||||
analytics.captureEvent(Events.AUTOMATION.SAVED, { name })
|
||||
hide()
|
||||
}
|
||||
|
||||
function checkValid(evt) {
|
||||
name = evt.target.value
|
||||
if (!name) {
|
||||
error = "Name is required"
|
||||
return
|
||||
}
|
||||
error = ""
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:this={modal} on:hide={onCancel}>
|
||||
<ModalContent
|
||||
title="Edit Automation"
|
||||
confirmText="Save"
|
||||
size="L"
|
||||
onConfirm={saveAutomation}
|
||||
disabled={error}
|
||||
>
|
||||
<Input bind:value={name} label="Name" on:input={checkValid} {error} />
|
||||
<a
|
||||
slot="footer"
|
||||
target="_blank"
|
||||
href="https://docs.budibase.com/automate/introduction-to-automate"
|
||||
>
|
||||
<Icon name="InfoOutline" />
|
||||
<span>Learn about automations</span>
|
||||
</a>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
a {
|
||||
color: var(--ink);
|
||||
font-size: 14px;
|
||||
vertical-align: middle;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
a span {
|
||||
text-decoration: underline;
|
||||
margin-left: var(--spectrum-alias-item-padding-s);
|
||||
}
|
||||
</style>
|
|
@ -20,7 +20,6 @@
|
|||
import QueryParamSelector from "./QueryParamSelector.svelte"
|
||||
import CronBuilder from "./CronBuilder.svelte"
|
||||
import Editor from "components/integration/QueryEditor.svelte"
|
||||
import { database } from "stores/backend"
|
||||
import { debounce } from "lodash"
|
||||
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||
import FilterDrawer from "components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte"
|
||||
|
@ -35,13 +34,11 @@
|
|||
let drawer
|
||||
let tempFilters = lookForFilters(schemaProperties) || []
|
||||
let fillWidth = true
|
||||
|
||||
$: stepId = block.stepId
|
||||
$: bindings = getAvailableBindings(
|
||||
block || $automationStore.selectedBlock,
|
||||
$automationStore.selectedAutomation?.automation?.definition
|
||||
)
|
||||
$: instanceId = $database._id
|
||||
|
||||
$: inputData = testData ? testData : block.inputs
|
||||
$: tableId = inputData ? inputData.tableId : null
|
||||
|
@ -56,10 +53,9 @@
|
|||
testData[key] = e.detail
|
||||
} else {
|
||||
block.inputs[key] = e.detail
|
||||
await automationStore.actions.save({
|
||||
instanceId,
|
||||
automation: $automationStore.selectedAutomation?.automation,
|
||||
})
|
||||
await automationStore.actions.save(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
}
|
||||
},
|
||||
isTestModal ? 0 : 800
|
||||
|
@ -211,7 +207,7 @@
|
|||
{:else if value.customType === "webhookUrl"}
|
||||
<WebhookDisplay value={inputData[key]} />
|
||||
{:else if value.customType === "triggerSchema"}
|
||||
<SchemaSetup on:change={e => onChange(e, key)} value={value[key]} />
|
||||
<SchemaSetup on:change={e => onChange(e, key)} value={inputData[key]} />
|
||||
{:else if value.customType === "code"}
|
||||
<CodeEditorModal>
|
||||
<pre>{JSON.stringify(bindings, null, 2)}</pre>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { tables } from "stores/backend"
|
||||
import { Select } from "@budibase/bbui"
|
||||
import { Select, Toggle, DatePicker, Multiselect } from "@budibase/bbui"
|
||||
import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte"
|
||||
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
|
@ -44,13 +44,31 @@
|
|||
<div class="schema-fields">
|
||||
{#each schemaFields as [field, schema]}
|
||||
{#if !schema.autocolumn}
|
||||
{#if schemaHasOptions(schema)}
|
||||
{#if schemaHasOptions(schema) && schema.type !== "array"}
|
||||
<Select
|
||||
on:change={e => onChange(e, field)}
|
||||
label={field}
|
||||
value={value[field]}
|
||||
options={schema.constraints.inclusion}
|
||||
/>
|
||||
{:else if schema.type === "datetime"}
|
||||
<DatePicker
|
||||
label={field}
|
||||
value={value[field]}
|
||||
on:change={e => onChange(e, field)}
|
||||
/>
|
||||
{:else if schema.type === "boolean"}
|
||||
<Toggle
|
||||
text={field}
|
||||
value={value[field]}
|
||||
on:change={e => onChange(e, field)}
|
||||
/>
|
||||
{:else if schema.type === "array"}
|
||||
<Multiselect
|
||||
bind:value={value[field]}
|
||||
label={field}
|
||||
options={schema.constraints.inclusion}
|
||||
/>
|
||||
{:else if schema.type === "string" || schema.type === "number"}
|
||||
{#if $automationStore.selectedAutomation.automation.testData}
|
||||
<ModalBindableInput
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
const dispatch = createEventDispatcher()
|
||||
|
||||
export let value = {}
|
||||
$: fieldsArray = Object.entries(value).map(([name, type]) => ({
|
||||
|
||||
$: fieldsArray = value
|
||||
? Object.entries(value).map(([name, type]) => ({
|
||||
name,
|
||||
type,
|
||||
}))
|
||||
: []
|
||||
|
||||
const typeOptions = [
|
||||
{
|
||||
label: "Text",
|
||||
|
@ -73,7 +77,7 @@
|
|||
<Select
|
||||
value={field.type}
|
||||
on:change={e => {
|
||||
value[field.name] = e.target.value
|
||||
value[field.name] = e.detail
|
||||
dispatch("change", value)
|
||||
}}
|
||||
options={typeOptions}
|
||||
|
@ -88,9 +92,7 @@
|
|||
|
||||
<style>
|
||||
.root {
|
||||
position: relative;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
/* so we can show the "+" button beside the "fields" label*/
|
||||
top: -26px;
|
||||
}
|
||||
|
@ -110,7 +112,6 @@
|
|||
/*grid-template-rows: auto auto;
|
||||
grid-template-columns: auto;*/
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.field :global(select) {
|
||||
|
|
|
@ -18,10 +18,7 @@
|
|||
onMount(async () => {
|
||||
if (!automation?.definition?.trigger?.inputs.schemaUrl) {
|
||||
// save the automation initially
|
||||
await automationStore.actions.save({
|
||||
instanceId,
|
||||
automation,
|
||||
})
|
||||
await automationStore.actions.save(automation)
|
||||
}
|
||||
interval = setInterval(async () => {
|
||||
await automationStore.actions.fetch()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script>
|
||||
import { Select, Label, notifications, ModalContent } from "@budibase/bbui"
|
||||
import { tables, views } from "stores/backend"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import { FIELDS } from "constants/backend"
|
||||
|
||||
const CALCULATIONS = [
|
||||
|
@ -40,7 +40,7 @@
|
|||
function saveView() {
|
||||
views.save(view)
|
||||
notifications.success(`View ${view.name} saved.`)
|
||||
analytics.captureEvent("Added View Calculate", { field: view.field })
|
||||
analytics.captureEvent(Events.VIEW.ADDED_CALCULATE, { field: view.field })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import { goto } from "@roxi/routify"
|
||||
import { views as viewsStore } from "stores/backend"
|
||||
import { tables } from "stores/backend"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
let name
|
||||
let field
|
||||
|
@ -21,7 +21,7 @@
|
|||
field,
|
||||
})
|
||||
notifications.success(`View ${name} created`)
|
||||
analytics.captureEvent("View Created", { name })
|
||||
analytics.captureEvent(Events.VIEW.CREATED, { name })
|
||||
$goto(`../../view/${name}`)
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
Icon,
|
||||
} from "@budibase/bbui"
|
||||
import { tables, views } from "stores/backend"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
const CONDITIONS = [
|
||||
{
|
||||
|
@ -65,7 +65,7 @@
|
|||
function saveView() {
|
||||
views.save(view)
|
||||
notifications.success(`View ${view.name} saved.`)
|
||||
analytics.captureEvent("Added View Filter", {
|
||||
analytics.captureEvent(Events.VIEW.ADDED_FILTER, {
|
||||
filters: JSON.stringify(view.filters),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@
|
|||
|
||||
{#if openDataSources.includes(datasource._id)}
|
||||
<TableNavigator sourceId={datasource._id} />
|
||||
{/if}
|
||||
|
||||
{#each $queries.list.filter(query => query.datasourceId === datasource._id) as query}
|
||||
<NavItem
|
||||
indentLevel={1}
|
||||
|
@ -77,6 +75,7 @@
|
|||
<EditQueryPopover {query} />
|
||||
</NavItem>
|
||||
{/each}
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import { Input, Label, ModalContent, Modal, Context } from "@budibase/bbui"
|
||||
import TableIntegrationMenu from "../TableIntegrationMenu/index.svelte"
|
||||
import CreateTableModal from "components/backend/TableNavigator/modals/CreateTableModal.svelte"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import { getContext } from "svelte"
|
||||
|
||||
const modalContext = getContext(Context.Modal)
|
||||
|
@ -45,7 +45,7 @@
|
|||
plus,
|
||||
})
|
||||
notifications.success(`Datasource ${name} created successfully.`)
|
||||
analytics.captureEvent("Datasource Created", { name, type })
|
||||
analytics.captureEvent(Events.DATASOURCE.CREATED, { name, type })
|
||||
|
||||
// Navigate to new datasource
|
||||
$goto(`./datasource/${response._id}`)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { datasources } from "stores/backend"
|
||||
import { notifications } from "@budibase/bbui"
|
||||
import { Input, ModalContent, Modal } from "@budibase/bbui"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
let error = ""
|
||||
let modal
|
||||
|
@ -35,7 +35,7 @@
|
|||
}
|
||||
await datasources.save(updatedDatasource)
|
||||
notifications.success(`Datasource ${name} updated successfully.`)
|
||||
analytics.captureEvent("Datasource Updated", updatedDatasource)
|
||||
analytics.captureEvent(Events.DATASOURCE.UPDATED, updatedDatasource)
|
||||
hide()
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
Layout,
|
||||
} from "@budibase/bbui"
|
||||
import TableDataImport from "../TableDataImport.svelte"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import screenTemplates from "builderStore/store/screenTemplates"
|
||||
import { buildAutoColumn, getAutoColumnInformation } from "builderStore/utils"
|
||||
import { NEW_ROW_TEMPLATE } from "builderStore/store/screenTemplates/newRowScreen"
|
||||
|
@ -67,7 +67,7 @@
|
|||
// Create table
|
||||
const table = await tables.save(newTable)
|
||||
notifications.success(`Table ${name} created successfully.`)
|
||||
analytics.captureEvent("Table Created", { name })
|
||||
analytics.captureEvent(Events.TABLE.CREATED, { name })
|
||||
|
||||
// Create auto screens
|
||||
if (createAutoscreens) {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
import { onMount, onDestroy } from "svelte"
|
||||
import { Button, Modal, notifications, ModalContent } from "@budibase/bbui"
|
||||
import api from "builderStore/api"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import { store } from "builderStore"
|
||||
|
||||
const DeploymentStatus = {
|
||||
SUCCESS: "SUCCESS",
|
||||
|
@ -23,6 +24,9 @@
|
|||
if (response.status !== 200) {
|
||||
throw new Error(`status ${response.status}`)
|
||||
} else {
|
||||
analytics.captureEvent(Events.APP.PUBLISHED, {
|
||||
appId: $store.appId,
|
||||
})
|
||||
notifications.success(`Application published successfully`)
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import { roles } from "stores/backend"
|
||||
import { Input, Select, ModalContent, Toggle } from "@budibase/bbui"
|
||||
import getTemplates from "builderStore/store/screenTemplates"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
|
||||
|
||||
const CONTAINER = "@budibase/standard-components/container"
|
||||
|
@ -67,7 +67,7 @@
|
|||
|
||||
if (templateIndex !== undefined) {
|
||||
const template = templates[templateIndex]
|
||||
analytics.captureEvent("Screen Created", {
|
||||
analytics.captureEvent(Events.SCREEN.CREATED, {
|
||||
template: template.id || template.name,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -46,7 +46,9 @@
|
|||
}
|
||||
|
||||
automationStore.actions.addBlockToAutomation(newBlock)
|
||||
await automationStore.actions.save($automationStore.selectedAutomation)
|
||||
await automationStore.actions.save(
|
||||
$automationStore.selectedAutomation?.automation
|
||||
)
|
||||
parameters.automationId = $automationStore.selectedAutomation.automation._id
|
||||
delete parameters.newAutomationName
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
import { admin } from "stores/portal"
|
||||
import { string, mixed, object } from "yup"
|
||||
import api, { get, post } from "builderStore/api"
|
||||
import analytics from "analytics"
|
||||
import analytics, { Events } from "analytics"
|
||||
import { onMount } from "svelte"
|
||||
import { capitalise } from "helpers"
|
||||
import { goto } from "@roxi/routify"
|
||||
|
@ -98,9 +98,9 @@
|
|||
throw new Error(appJson.message)
|
||||
}
|
||||
|
||||
analytics.captureEvent("App Created", {
|
||||
analytics.captureEvent(Events.APP.CREATED, {
|
||||
name: $values.name,
|
||||
appId: appJson._id,
|
||||
appId: appJson.instance._id,
|
||||
template,
|
||||
})
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
}
|
||||
|
||||
// redirect to account portal for authentication in the cloud
|
||||
if ($admin.cloud && $admin.accountPortalUrl) {
|
||||
if (!$auth.user && $admin.cloud && $admin.accountPortalUrl) {
|
||||
window.location.href = $admin.accountPortalUrl
|
||||
}
|
||||
})
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
username,
|
||||
password,
|
||||
})
|
||||
|
||||
if ($auth?.user?.forceResetPassword) {
|
||||
$goto("./reset")
|
||||
} else {
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
} from "@budibase/bbui"
|
||||
import CreateAppModal from "components/start/CreateAppModal.svelte"
|
||||
import UpdateAppModal from "components/start/UpdateAppModal.svelte"
|
||||
import api, { del } from "builderStore/api"
|
||||
import analytics from "analytics"
|
||||
import { del } from "builderStore/api"
|
||||
import { onMount } from "svelte"
|
||||
import { apps, auth, admin } from "stores/portal"
|
||||
import download from "downloadjs"
|
||||
|
@ -49,7 +48,7 @@
|
|||
if (sortBy === "status") {
|
||||
return enrichedApps.sort((a, b) => {
|
||||
if (a.status === b.status) {
|
||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1
|
||||
return a.name?.toLowerCase() < b.name?.toLowerCase() ? -1 : 1
|
||||
}
|
||||
return a.status === AppStatus.DEPLOYED ? -1 : 1
|
||||
})
|
||||
|
@ -61,19 +60,11 @@
|
|||
})
|
||||
} else {
|
||||
return enrichedApps.sort((a, b) => {
|
||||
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1
|
||||
return a.name?.toLowerCase() < b.name?.toLowerCase() ? -1 : 1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const checkKeys = async () => {
|
||||
const response = await api.get(`/api/keys/`)
|
||||
const keys = await response.json()
|
||||
if (keys.userId) {
|
||||
analytics.identify(keys.userId)
|
||||
}
|
||||
}
|
||||
|
||||
const initiateAppCreation = () => {
|
||||
creationModal.show()
|
||||
creatingApp = true
|
||||
|
@ -188,7 +179,6 @@
|
|||
}
|
||||
|
||||
onMount(async () => {
|
||||
checkKeys()
|
||||
await apps.load()
|
||||
loaded = true
|
||||
})
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
import api from "builderStore/api"
|
||||
import { organisation, auth, admin } from "stores/portal"
|
||||
import { uuid } from "builderStore/uuid"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
$: tenantId = $auth.tenantId
|
||||
$: multiTenancyEnabled = $admin.multiTenancy
|
||||
|
@ -209,6 +210,7 @@
|
|||
providers[res.type]._id = res._id
|
||||
})
|
||||
notifications.success(`Settings saved.`)
|
||||
analytics.captureEvent(Events.SSO.SAVED)
|
||||
})
|
||||
.catch(err => {
|
||||
notifications.error(`Failed to update auth settings. ${err}`)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import { email } from "stores/portal"
|
||||
import api from "builderStore/api"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
const ConfigTypes = {
|
||||
SMTP: "smtp",
|
||||
|
@ -69,6 +70,7 @@
|
|||
smtpConfig._rev = json._rev
|
||||
smtpConfig._id = json._id
|
||||
notifications.success(`Settings saved.`)
|
||||
analytics.captureEvent(Events.SMTP.SAVED)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
} from "@budibase/bbui"
|
||||
import { createValidationStore, emailValidator } from "helpers/validation"
|
||||
import { users } from "stores/portal"
|
||||
import analytics, { Events } from "analytics"
|
||||
|
||||
export let disabled
|
||||
|
||||
|
@ -25,6 +26,7 @@
|
|||
notifications.error(res.message)
|
||||
} else {
|
||||
notifications.success(res.message)
|
||||
analytics.captureEvent(Events.USER.INVITE, { type: selected })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
}
|
||||
|
||||
const values = writable({
|
||||
analytics: !analytics.disabled(),
|
||||
analytics: analytics.enabled,
|
||||
company: $organisation.company,
|
||||
platformUrl: $organisation.platformUrl,
|
||||
logo: $organisation.logoUrl
|
||||
|
@ -48,13 +48,6 @@
|
|||
async function saveConfig() {
|
||||
loading = true
|
||||
|
||||
// Set analytics preference
|
||||
if ($values.analytics) {
|
||||
analytics.optIn()
|
||||
} else {
|
||||
analytics.optOut()
|
||||
}
|
||||
|
||||
// Upload logo if required
|
||||
if ($values.logo && !$values.logo.url) {
|
||||
await uploadLogo($values.logo)
|
||||
|
@ -64,6 +57,7 @@
|
|||
const config = {
|
||||
company: $values.company ?? "",
|
||||
platformUrl: $values.platformUrl ?? "",
|
||||
analytics: $values.analytics,
|
||||
}
|
||||
// remove logo if required
|
||||
if (!$values.logo) {
|
||||
|
|
|
@ -3,6 +3,11 @@ import { get } from "builderStore/api"
|
|||
import { AppStatus } from "../../constants"
|
||||
import api from "../../builderStore/api"
|
||||
|
||||
const extractAppId = id => {
|
||||
const split = id?.split("_") || []
|
||||
return split.length ? split[split.length - 1] : null
|
||||
}
|
||||
|
||||
export function createAppStore() {
|
||||
const store = writable([])
|
||||
|
||||
|
@ -18,7 +23,7 @@ export function createAppStore() {
|
|||
|
||||
// First append all dev app version
|
||||
devApps.forEach(app => {
|
||||
const id = app.appId.substring(8)
|
||||
const id = extractAppId(app.appId)
|
||||
appMap[id] = {
|
||||
...app,
|
||||
devId: app.appId,
|
||||
|
@ -28,7 +33,13 @@ export function createAppStore() {
|
|||
|
||||
// Then merge with all prod app versions
|
||||
deployedApps.forEach(app => {
|
||||
const id = app.appId.substring(4)
|
||||
const id = extractAppId(app.appId)
|
||||
|
||||
// Skip any deployed apps which don't have a dev counterpart
|
||||
if (!appMap[id]) {
|
||||
return
|
||||
}
|
||||
|
||||
appMap[id] = {
|
||||
...appMap[id],
|
||||
...app,
|
||||
|
@ -40,7 +51,7 @@ export function createAppStore() {
|
|||
// Transform into an array and clean up
|
||||
const apps = Object.values(appMap)
|
||||
apps.forEach(app => {
|
||||
app.appId = app.devId.substring(8)
|
||||
app.appId = extractAppId(app.devId)
|
||||
delete app._id
|
||||
delete app._rev
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { derived, writable, get } from "svelte/store"
|
||||
import api from "../../builderStore/api"
|
||||
import { admin } from "stores/portal"
|
||||
import analytics from "analytics"
|
||||
|
||||
export function createAuthStore() {
|
||||
const auth = writable({
|
||||
|
@ -49,6 +50,21 @@ export function createAuthStore() {
|
|||
}
|
||||
return store
|
||||
})
|
||||
|
||||
if (user) {
|
||||
analytics.activate().then(() => {
|
||||
analytics.identify(user._id, user)
|
||||
if (user.size === "100+" || user.size === "10000+") {
|
||||
analytics.showChat({
|
||||
email: user.email,
|
||||
created_at: user.createdAt || Date.now(),
|
||||
name: user.name,
|
||||
user_id: user._id,
|
||||
tenant: user.tenantId,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function setOrganisation(tenantId) {
|
||||
|
|
|
@ -22,6 +22,9 @@ export default ({ mode }) => {
|
|||
isProduction ? "production" : "development"
|
||||
),
|
||||
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
|
||||
"process.env.INTERCOM_TOKEN": JSON.stringify(
|
||||
process.env.INTERCOM_TOKEN
|
||||
),
|
||||
"process.env.POSTHOG_URL": JSON.stringify(process.env.POSTHOG_URL),
|
||||
"process.env.SENTRY_DSN": JSON.stringify(process.env.SENTRY_DSN),
|
||||
}),
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/cli",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
||||
"main": "src/index.js",
|
||||
"bin": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/client",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"license": "MPL-2.0",
|
||||
"module": "dist/budibase-client.js",
|
||||
"main": "dist/budibase-client.js",
|
||||
|
@ -19,9 +19,9 @@
|
|||
"dev:builder": "rollup -cw"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "^0.9.125-alpha.13",
|
||||
"@budibase/standard-components": "^0.9.124",
|
||||
"@budibase/string-templates": "^0.9.125-alpha.13",
|
||||
"@budibase/bbui": "^0.9.140-alpha.6",
|
||||
"@budibase/standard-components": "^0.9.139",
|
||||
"@budibase/string-templates": "^0.9.140-alpha.6",
|
||||
"regexparam": "^1.3.0",
|
||||
"shortid": "^2.2.15",
|
||||
"svelte-spa-router": "^3.0.5"
|
||||
|
|
|
@ -28,59 +28,10 @@
|
|||
chalk "^2.0.0"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@budibase/bbui@^0.9.125-alpha.11":
|
||||
version "0.9.130"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.130.tgz#cad02a7aa16324eb7a056c5dc0162444fa917964"
|
||||
integrity sha512-ULOC++363K8QEMasmsDmleF7AzjulFk/ZxGPlOJcVKJU8Bx5wG1uNFgTyJyGpmnbUWHd67eYUEettfH7I+VoOw==
|
||||
dependencies:
|
||||
"@adobe/spectrum-css-workflow-icons" "^1.2.1"
|
||||
"@spectrum-css/actionbutton" "^1.0.1"
|
||||
"@spectrum-css/actiongroup" "^1.0.1"
|
||||
"@spectrum-css/avatar" "^3.0.2"
|
||||
"@spectrum-css/button" "^3.0.1"
|
||||
"@spectrum-css/buttongroup" "^3.0.2"
|
||||
"@spectrum-css/checkbox" "^3.0.2"
|
||||
"@spectrum-css/dialog" "^3.0.1"
|
||||
"@spectrum-css/divider" "^1.0.3"
|
||||
"@spectrum-css/dropzone" "^3.0.2"
|
||||
"@spectrum-css/fieldgroup" "^3.0.2"
|
||||
"@spectrum-css/fieldlabel" "^3.0.1"
|
||||
"@spectrum-css/icon" "^3.0.1"
|
||||
"@spectrum-css/illustratedmessage" "^3.0.2"
|
||||
"@spectrum-css/inputgroup" "^3.0.2"
|
||||
"@spectrum-css/label" "^2.0.10"
|
||||
"@spectrum-css/link" "^3.1.1"
|
||||
"@spectrum-css/menu" "^3.0.1"
|
||||
"@spectrum-css/modal" "^3.0.1"
|
||||
"@spectrum-css/pagination" "^3.0.3"
|
||||
"@spectrum-css/picker" "^1.0.1"
|
||||
"@spectrum-css/popover" "^3.0.1"
|
||||
"@spectrum-css/progressbar" "^1.0.2"
|
||||
"@spectrum-css/progresscircle" "^1.0.2"
|
||||
"@spectrum-css/radio" "^3.0.2"
|
||||
"@spectrum-css/search" "^3.0.2"
|
||||
"@spectrum-css/sidenav" "^3.0.2"
|
||||
"@spectrum-css/statuslight" "^3.0.2"
|
||||
"@spectrum-css/stepper" "^3.0.3"
|
||||
"@spectrum-css/switch" "^1.0.2"
|
||||
"@spectrum-css/table" "^3.0.1"
|
||||
"@spectrum-css/tabs" "^3.0.1"
|
||||
"@spectrum-css/tags" "^3.0.2"
|
||||
"@spectrum-css/textfield" "^3.0.1"
|
||||
"@spectrum-css/toast" "^3.0.1"
|
||||
"@spectrum-css/tooltip" "^3.0.3"
|
||||
"@spectrum-css/treeview" "^3.0.2"
|
||||
"@spectrum-css/typography" "^3.0.1"
|
||||
"@spectrum-css/underlay" "^2.0.9"
|
||||
"@spectrum-css/vars" "^3.0.1"
|
||||
dayjs "^1.10.4"
|
||||
svelte-flatpickr "^3.1.0"
|
||||
svelte-portal "^1.0.0"
|
||||
|
||||
"@budibase/bbui@^0.9.129":
|
||||
version "0.9.129"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.129.tgz#989bf60d404772d4b308382faba7adac6518ec3e"
|
||||
integrity sha512-U3uO9K3m7Ph5RQpzXx5IIy94s/KdU9Q8eJXFQwH6neYIKQk3OFo8br5px5C7lE38mtazqq9XvQy0f+MUarKk4A==
|
||||
"@budibase/bbui@^0.9.125-alpha.17":
|
||||
version "0.9.133"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.133.tgz#91a2fb24abaaf91d2cb1e00eb51c493c1290f9ad"
|
||||
integrity sha512-xbMmc/hee1QRNW7TrbGUBmLr1hMHXqUDA6rdl9N2PGfHFuFWbqlD8PWYanHmLevVet+CjkuKGPSbBghFK2pQyQ==
|
||||
dependencies:
|
||||
"@adobe/spectrum-css-workflow-icons" "^1.2.1"
|
||||
"@spectrum-css/actionbutton" "^1.0.1"
|
||||
|
@ -154,28 +105,10 @@
|
|||
to-gfm-code-block "^0.1.1"
|
||||
year "^0.2.1"
|
||||
|
||||
"@budibase/standard-components@^0.9.124":
|
||||
version "0.9.129"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/standard-components/-/standard-components-0.9.129.tgz#f2cdead99b8f25177c4c291be3032fb9ffd1dac3"
|
||||
integrity sha512-RYWBcrz4MGICg9neIPQ4CbU3WTTJoTofi2D4pwA+qvvN3uhqOCcFIZ3+yadZ5Akz2qwMztQ8WDvetowm2srZcA==
|
||||
dependencies:
|
||||
"@budibase/bbui" "^0.9.129"
|
||||
"@spectrum-css/button" "^3.0.3"
|
||||
"@spectrum-css/card" "^3.0.3"
|
||||
"@spectrum-css/divider" "^1.0.3"
|
||||
"@spectrum-css/link" "^3.1.3"
|
||||
"@spectrum-css/page" "^3.0.1"
|
||||
"@spectrum-css/typography" "^3.0.2"
|
||||
"@spectrum-css/vars" "^3.0.1"
|
||||
apexcharts "^3.22.1"
|
||||
dayjs "^1.10.5"
|
||||
svelte-apexcharts "^1.0.2"
|
||||
svelte-flatpickr "^3.1.0"
|
||||
|
||||
"@budibase/string-templates@^0.9.125-alpha.11":
|
||||
version "0.9.130"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-0.9.130.tgz#1be8affcba0dc8ff2b8044c65dd378dc76a165d0"
|
||||
integrity sha512-DXO6Um18/k16i3hYilxvQ4RYNHhd29OJGbzjfQZ2v7z4Oin5y+WMZzpjX1hQS5g9f/CBbzu7qd7EHiz/n8gMqg==
|
||||
"@budibase/string-templates@^0.9.125-alpha.17":
|
||||
version "0.9.133"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-0.9.133.tgz#221d81e080dc4485dcffa989d16e2bbed39f9055"
|
||||
integrity sha512-SMHcSPwHYdAqol9YCcMoYawp5/ETr9TqGZCUsL+hUUq+LritPwu/miQ++SVvRTQbOR7Mker0S9LO3H8mwYkW8w==
|
||||
dependencies:
|
||||
"@budibase/handlebars-helpers" "^0.11.4"
|
||||
dayjs "^1.10.4"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/server",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "0.9.125-alpha.13",
|
||||
"version": "0.9.140-alpha.6",
|
||||
"description": "Budibase Web Server",
|
||||
"main": "src/index.js",
|
||||
"repository": {
|
||||
|
@ -13,7 +13,7 @@
|
|||
"postbuild": "copyfiles -u 1 src/**/*.svelte dist/ && copyfiles -u 1 src/**/*.hbs dist/ && copyfiles -u 1 src/**/*.json dist/",
|
||||
"test": "jest --coverage --maxWorkers=2",
|
||||
"test:watch": "jest --watch",
|
||||
"predocker": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client",
|
||||
"predocker": "copyfiles -f ../client/dist/budibase-client.js ../standard-components/manifest.json client",
|
||||
"build:docker": "yarn run predocker && docker build . -t app-service",
|
||||
"run:docker": "node dist/index.js",
|
||||
"dev:stack:up": "node scripts/dev/manage.js up",
|
||||
|
@ -23,10 +23,9 @@
|
|||
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
|
||||
"lint": "eslint --fix src/",
|
||||
"lint:fix": "yarn run format && yarn run lint",
|
||||
"initialise": "node scripts/initialise.js",
|
||||
"multi:enable": "node scripts/multiTenancy.js enable",
|
||||
"multi:disable": "node scripts/multiTenancy.js disable",
|
||||
"selfhost:enable": "node scripts/selfhost.js enable",
|
||||
"selfhost:disable": "node scripts/selfhost.js disable"
|
||||
"multi:disable": "node scripts/multiTenancy.js disable"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
|
@ -49,8 +48,7 @@
|
|||
"!src/automations/tests/**/*",
|
||||
"!src/utilities/fileProcessor.js",
|
||||
"!src/utilities/fileSystem/**/*",
|
||||
"!src/utilities/redis.js",
|
||||
"!src/api/controllers/row/internalSearch.js"
|
||||
"!src/utilities/redis.js"
|
||||
],
|
||||
"coverageReporters": [
|
||||
"lcov",
|
||||
|
@ -64,9 +62,9 @@
|
|||
"author": "Budibase",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@budibase/auth": "^0.9.125-alpha.13",
|
||||
"@budibase/client": "^0.9.125-alpha.13",
|
||||
"@budibase/string-templates": "^0.9.125-alpha.13",
|
||||
"@budibase/auth": "^0.9.140-alpha.6",
|
||||
"@budibase/client": "^0.9.140-alpha.6",
|
||||
"@budibase/string-templates": "^0.9.140-alpha.6",
|
||||
"@elastic/elasticsearch": "7.10.0",
|
||||
"@koa/router": "8.0.0",
|
||||
"@sendgrid/mail": "7.1.1",
|
||||
|
@ -98,12 +96,13 @@
|
|||
"lodash": "4.17.21",
|
||||
"mongodb": "3.6.3",
|
||||
"mssql": "6.2.3",
|
||||
"mysql": "^2.18.1",
|
||||
"mysql": "2.18.1",
|
||||
"node-fetch": "2.6.0",
|
||||
"open": "7.3.0",
|
||||
"pg": "8.5.1",
|
||||
"pino-pretty": "4.0.0",
|
||||
"pouchdb": "7.2.1",
|
||||
"pouchdb-adapter-memory": "^7.2.1",
|
||||
"pouchdb-all-dbs": "1.0.2",
|
||||
"pouchdb-find": "^7.2.2",
|
||||
"pouchdb-replication-stream": "1.2.9",
|
||||
|
@ -118,7 +117,7 @@
|
|||
"devDependencies": {
|
||||
"@babel/core": "^7.14.3",
|
||||
"@babel/preset-env": "^7.14.4",
|
||||
"@budibase/standard-components": "^0.9.124",
|
||||
"@budibase/standard-components": "^0.9.139",
|
||||
"@jest/test-sequencer": "^24.8.0",
|
||||
"@types/bull": "^3.15.1",
|
||||
"@types/jest": "^26.0.23",
|
||||
|
@ -133,7 +132,6 @@
|
|||
"express": "^4.17.1",
|
||||
"jest": "^27.0.5",
|
||||
"nodemon": "^2.0.4",
|
||||
"pouchdb-adapter-memory": "^7.2.1",
|
||||
"prettier": "^2.3.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"supertest": "^4.0.2",
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
version: "3.8"
|
||||
services:
|
||||
db:
|
||||
container_name: postgres-vehicle
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_USER: root
|
||||
POSTGRES_PASSWORD: root
|
||||
POSTGRES_DB: main
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
#- pg_data:/var/lib/postgresql/data/
|
||||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
|
||||
pgadmin:
|
||||
container_name: pgadmin
|
||||
image: dpage/pgadmin4
|
||||
restart: always
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: root@root.com
|
||||
PGADMIN_DEFAULT_PASSWORD: root
|
||||
ports:
|
||||
- "5050:80"
|
||||
|
||||
#volumes:
|
||||
# pg_data:
|
|
@ -0,0 +1,52 @@
|
|||
SELECT 'CREATE DATABASE main'
|
||||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'main')\gexec
|
||||
CREATE TABLE Vehicles (
|
||||
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
|
||||
Registration text COLLATE pg_catalog."default",
|
||||
Make text COLLATE pg_catalog."default",
|
||||
Model text COLLATE pg_catalog."default",
|
||||
Colour text COLLATE pg_catalog."default",
|
||||
Year smallint,
|
||||
CONSTRAINT Vehicles_pkey PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE ServiceLog (
|
||||
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1 ),
|
||||
Description text COLLATE pg_catalog."default",
|
||||
VehicleId bigint,
|
||||
ServiceDate timestamp without time zone,
|
||||
Category text COLLATE pg_catalog."default",
|
||||
Mileage bigint,
|
||||
CONSTRAINT ServiceLog_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT vehicle_foreign_key FOREIGN KEY (VehicleId)
|
||||
REFERENCES Vehicles (id) MATCH SIMPLE
|
||||
ON UPDATE NO ACTION
|
||||
ON DELETE NO ACTION
|
||||
);
|
||||
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('FAZ 9837','Volkswagen','Polo','White',2002);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('JHI 8827','BMW','M3','Black',2013);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('D903PI','Volvo','XC40','Grey',2014);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('YFI002','Volkswagen','Golf','Dark Blue',2018);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('HGT5677','Skoda','Octavia','Graphite',2009);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('PPF9276','Skoda','Octavia','Graphite',2021);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('J893FT','Toyota','Corolla','Red',2015);
|
||||
INSERT INTO Vehicles (Registration, Make, Model, Colour, Year)
|
||||
VALUES ('MJK776','Honda','HR-V','Silver',2015);
|
||||
|
||||
|
||||
INSERT INTO ServiceLog (Description, VehicleId, ServiceDate, Category, Mileage)
|
||||
VALUES ('Change front brakes', 1, '2021-05-04', 'Brakes', 20667);
|
||||
INSERT INTO ServiceLog (Description, VehicleId, ServiceDate, Category, Mileage)
|
||||
VALUES ('Tyres - full set', 1, '2021-05-04', 'Brakes', 20667);
|
||||
INSERT INTO ServiceLog (Description, VehicleId, ServiceDate, Category, Mileage)
|
||||
VALUES ('Engine tune up', 2, '2021-07-14', 'Brakes', 50889);
|
||||
INSERT INTO ServiceLog (Description, VehicleId, ServiceDate, Category, Mileage)
|
||||
VALUES ('Replace transmission', 3, '2021-09-26', 'Transmission', 98002);
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
docker-compose down
|
||||
docker volume prune -f
|
|
@ -1,6 +1,7 @@
|
|||
const { tmpdir } = require("os")
|
||||
const env = require("../src/environment")
|
||||
|
||||
env._set("SELF_HOSTED", "1")
|
||||
env._set("NODE_ENV", "jest")
|
||||
env._set("JWT_SECRET", "test-jwtsecret")
|
||||
env._set("CLIENT_ID", "test-client-id")
|
||||
|
|
|
@ -2,6 +2,6 @@ const env = require("../../environment")
|
|||
|
||||
exports.isEnabled = async function (ctx) {
|
||||
ctx.body = {
|
||||
enabled: env.ENABLE_ANALYTICS === "true",
|
||||
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,15 +189,27 @@ exports.trigger = async function (ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
function prepareTestInput(input) {
|
||||
// prepare the test parameters
|
||||
if (input.id && input.row) {
|
||||
input.row._id = input.id
|
||||
}
|
||||
if (input.revision && input.row) {
|
||||
input.row._rev = input.revision
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
exports.test = async function (ctx) {
|
||||
const appId = ctx.appId
|
||||
const db = new CouchDB(appId)
|
||||
let automation = await db.get(ctx.params.id)
|
||||
await setTestFlag(automation._id)
|
||||
const testInput = prepareTestInput(ctx.request.body)
|
||||
const response = await triggers.externalTrigger(
|
||||
automation,
|
||||
{
|
||||
...ctx.request.body,
|
||||
...testInput,
|
||||
appId,
|
||||
},
|
||||
{ getResponses: true }
|
||||
|
|
|
@ -51,7 +51,7 @@ exports.buildSchemaFromDb = async function (ctx) {
|
|||
await connector.buildSchema(datasource._id, datasource.entities)
|
||||
datasource.entities = connector.tables
|
||||
|
||||
const response = await db.post(datasource)
|
||||
const response = await db.put(datasource)
|
||||
datasource._rev = response.rev
|
||||
|
||||
ctx.body = datasource
|
||||
|
@ -89,7 +89,7 @@ exports.save = async function (ctx) {
|
|||
...ctx.request.body,
|
||||
}
|
||||
|
||||
const response = await db.post(datasource)
|
||||
const response = await db.put(datasource)
|
||||
datasource._rev = response.rev
|
||||
|
||||
// Drain connection pools when configuration is changed
|
||||
|
|
|
@ -437,7 +437,11 @@ module External {
|
|||
for (let [colName, { isMany, rows, tableId }] of Object.entries(
|
||||
related
|
||||
)) {
|
||||
const table = this.getTable(tableId)
|
||||
const table: Table = this.getTable(tableId)
|
||||
// if its not the foreign key skip it, nothing to do
|
||||
if (table.primary && table.primary.indexOf(colName) !== -1) {
|
||||
continue
|
||||
}
|
||||
for (let row of rows) {
|
||||
const filters = buildFilters(generateIdForRow(row, table), {}, table)
|
||||
// safety check, if there are no filters on deletion bad things happen
|
||||
|
|
|
@ -5,17 +5,22 @@ const {
|
|||
generateRowID,
|
||||
DocumentTypes,
|
||||
InternalTables,
|
||||
generateMemoryViewID,
|
||||
} = require("../../../db/utils")
|
||||
const userController = require("../user")
|
||||
const {
|
||||
inputProcessing,
|
||||
outputProcessing,
|
||||
processAutoColumn,
|
||||
} = require("../../../utilities/rowProcessor")
|
||||
const { FieldTypes } = require("../../../constants")
|
||||
const { isEqual } = require("lodash")
|
||||
const { validate, findRow } = require("./utils")
|
||||
const { fullSearch, paginatedSearch } = require("./internalSearch")
|
||||
const { getGlobalUsersFromMetadata } = require("../../../utilities/global")
|
||||
const inMemoryViews = require("../../../db/inMemoryView")
|
||||
const env = require("../../../environment")
|
||||
const { migrateToInMemoryView } = require("../view/utils")
|
||||
|
||||
const CALCULATION_TYPES = {
|
||||
SUM: "sum",
|
||||
|
@ -25,17 +30,84 @@ const CALCULATION_TYPES = {
|
|||
|
||||
async function storeResponse(ctx, db, row, oldTable, table) {
|
||||
row.type = "row"
|
||||
const response = await db.put(row)
|
||||
// don't worry about rev, tables handle rev/lastID updates
|
||||
// if another row has been written since processing this will
|
||||
// handle the auto ID clash
|
||||
if (!isEqual(oldTable, table)) {
|
||||
try {
|
||||
await db.put(table)
|
||||
} catch (err) {
|
||||
if (err.status === 409) {
|
||||
const updatedTable = await db.get(table._id)
|
||||
let response = processAutoColumn(null, updatedTable, row, {
|
||||
reprocessing: true,
|
||||
})
|
||||
await db.put(response.table)
|
||||
row = response.row
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
const response = await db.put(row)
|
||||
row._rev = response.rev
|
||||
// process the row before return, to include relationships
|
||||
row = await outputProcessing(ctx, table, row, { squash: false })
|
||||
return { row, table }
|
||||
}
|
||||
|
||||
// doesn't do the outputProcessing
|
||||
async function getRawTableData(ctx, db, tableId) {
|
||||
let rows
|
||||
if (tableId === InternalTables.USER_METADATA) {
|
||||
await userController.fetchMetadata(ctx)
|
||||
rows = ctx.body
|
||||
} else {
|
||||
const response = await db.allDocs(
|
||||
getRowParams(tableId, null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
rows = response.rows.map(row => row.doc)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
async function getView(db, viewName) {
|
||||
let viewInfo
|
||||
async function getFromDesignDoc() {
|
||||
const designDoc = await db.get("_design/database")
|
||||
viewInfo = designDoc.views[viewName]
|
||||
return viewInfo
|
||||
}
|
||||
let migrate = false
|
||||
if (env.SELF_HOSTED) {
|
||||
viewInfo = await getFromDesignDoc()
|
||||
} else {
|
||||
try {
|
||||
viewInfo = await db.get(generateMemoryViewID(viewName))
|
||||
if (viewInfo) {
|
||||
viewInfo = viewInfo.view
|
||||
}
|
||||
} catch (err) {
|
||||
// check if it can be retrieved from design doc (needs migrated)
|
||||
if (err.status !== 404) {
|
||||
viewInfo = null
|
||||
} else {
|
||||
viewInfo = await getFromDesignDoc()
|
||||
migrate = !!viewInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
if (migrate) {
|
||||
await migrateToInMemoryView(db, viewName)
|
||||
}
|
||||
if (!viewInfo) {
|
||||
throw "View does not exist."
|
||||
}
|
||||
return viewInfo
|
||||
}
|
||||
|
||||
exports.patch = async ctx => {
|
||||
const appId = ctx.appId
|
||||
const db = new CouchDB(appId)
|
||||
|
@ -139,15 +211,18 @@ exports.fetchView = async ctx => {
|
|||
|
||||
const db = new CouchDB(appId)
|
||||
const { calculation, group, field } = ctx.query
|
||||
const designDoc = await db.get("_design/database")
|
||||
const viewInfo = designDoc.views[viewName]
|
||||
if (!viewInfo) {
|
||||
throw "View does not exist."
|
||||
}
|
||||
const response = await db.query(`database/${viewName}`, {
|
||||
const viewInfo = await getView(db, viewName)
|
||||
let response
|
||||
if (env.SELF_HOSTED) {
|
||||
response = await db.query(`database/${viewName}`, {
|
||||
include_docs: !calculation,
|
||||
group: !!group,
|
||||
})
|
||||
} else {
|
||||
const tableId = viewInfo.meta.tableId
|
||||
const data = await getRawTableData(ctx, db, tableId)
|
||||
response = await inMemoryViews.runView(viewInfo, calculation, group, data)
|
||||
}
|
||||
|
||||
let rows
|
||||
if (!calculation) {
|
||||
|
@ -191,19 +266,9 @@ exports.fetch = async ctx => {
|
|||
const appId = ctx.appId
|
||||
const db = new CouchDB(appId)
|
||||
|
||||
let rows,
|
||||
table = await db.get(ctx.params.tableId)
|
||||
if (ctx.params.tableId === InternalTables.USER_METADATA) {
|
||||
await userController.fetchMetadata(ctx)
|
||||
rows = ctx.body
|
||||
} else {
|
||||
const response = await db.allDocs(
|
||||
getRowParams(ctx.params.tableId, null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
rows = response.rows.map(row => row.doc)
|
||||
}
|
||||
const tableId = ctx.params.tableId
|
||||
let table = await db.get(tableId)
|
||||
let rows = await getRawTableData(ctx, db, tableId)
|
||||
return outputProcessing(ctx, table, rows)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ const { InternalTables } = require("../../../db/utils")
|
|||
const userController = require("../user")
|
||||
const { FieldTypes } = require("../../../constants")
|
||||
const { integrations } = require("../../../integrations")
|
||||
const { processStringSync } = require("@budibase/string-templates")
|
||||
|
||||
validateJs.extend(validateJs.validators.datetime, {
|
||||
parse: function (value) {
|
||||
|
@ -73,6 +74,11 @@ exports.validate = async ({ appId, tableId, row, table }) => {
|
|||
errors[fieldName] = "Field not in list"
|
||||
}
|
||||
})
|
||||
} else if (table.schema[fieldName].type === FieldTypes.FORMULA) {
|
||||
res = validateJs.single(
|
||||
processStringSync(table.schema[fieldName].formula, row),
|
||||
constraints
|
||||
)
|
||||
} else {
|
||||
res = validateJs.single(row[fieldName], constraints)
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ exports.save = async function (ctx) {
|
|||
if (updatedRows && updatedRows.length !== 0) {
|
||||
await db.bulkDocs(updatedRows)
|
||||
}
|
||||
const result = await db.post(tableToSave)
|
||||
const result = await db.put(tableToSave)
|
||||
tableToSave._rev = result.rev
|
||||
|
||||
tableToSave = await tableSaveFunctions.after(tableToSave)
|
||||
|
|
|
@ -68,23 +68,17 @@ exports.handleDataImport = async (appId, user, table, dataImport) => {
|
|||
// Populate the table with rows imported from CSV in a bulk update
|
||||
const data = await csvParser.transform(dataImport)
|
||||
|
||||
let finalData = []
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let row = data[i]
|
||||
row._id = generateRowID(table._id)
|
||||
row.tableId = table._id
|
||||
const processed = inputProcessing(user, table, row)
|
||||
const processed = inputProcessing(user, table, row, {
|
||||
noAutoRelationships: true,
|
||||
})
|
||||
table = processed.table
|
||||
row = processed.row
|
||||
|
||||
// make sure link rows are up to date
|
||||
row = await linkRows.updateLinks({
|
||||
appId,
|
||||
eventType: linkRows.EventType.ROW_SAVE,
|
||||
row,
|
||||
tableId: row.tableId,
|
||||
table,
|
||||
})
|
||||
|
||||
for (let [fieldName, schema] of Object.entries(table.schema)) {
|
||||
// check whether the options need to be updated for inclusion as part of the data import
|
||||
if (
|
||||
|
@ -98,10 +92,20 @@ exports.handleDataImport = async (appId, user, table, dataImport) => {
|
|||
]
|
||||
}
|
||||
}
|
||||
data[i] = row
|
||||
|
||||
// make sure link rows are up to date
|
||||
finalData.push(
|
||||
linkRows.updateLinks({
|
||||
appId,
|
||||
eventType: linkRows.EventType.ROW_SAVE,
|
||||
row,
|
||||
tableId: row.tableId,
|
||||
table,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
await db.bulkDocs(data)
|
||||
await db.bulkDocs(await Promise.all(finalData))
|
||||
let response = await db.put(table)
|
||||
table._rev = response._rev
|
||||
}
|
||||
|
|
|
@ -2,49 +2,24 @@ const CouchDB = require("../../../db")
|
|||
const viewTemplate = require("./viewBuilder")
|
||||
const { apiFileReturn } = require("../../../utilities/fileSystem")
|
||||
const exporters = require("./exporters")
|
||||
const { saveView, getView, getViews, deleteView } = require("./utils")
|
||||
const { fetchView } = require("../row")
|
||||
const { ViewNames } = require("../../../db/utils")
|
||||
|
||||
const controller = {
|
||||
fetch: async ctx => {
|
||||
exports.fetch = async ctx => {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const response = []
|
||||
ctx.body = await getViews(db)
|
||||
}
|
||||
|
||||
for (let name of Object.keys(designDoc.views)) {
|
||||
// Only return custom views, not built ins
|
||||
if (Object.values(ViewNames).indexOf(name) !== -1) {
|
||||
continue
|
||||
}
|
||||
response.push({
|
||||
name,
|
||||
...designDoc.views[name],
|
||||
})
|
||||
}
|
||||
|
||||
ctx.body = response
|
||||
},
|
||||
save: async ctx => {
|
||||
exports.save = async ctx => {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const { originalName, ...viewToSave } = ctx.request.body
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = viewTemplate(viewToSave)
|
||||
|
||||
if (!viewToSave.name) {
|
||||
ctx.throw(400, "Cannot create view without a name")
|
||||
}
|
||||
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[viewToSave.name]: view,
|
||||
}
|
||||
|
||||
// view has been renamed
|
||||
if (originalName) {
|
||||
delete designDoc.views[originalName]
|
||||
}
|
||||
|
||||
await db.put(designDoc)
|
||||
await saveView(db, originalName, viewToSave.name, view)
|
||||
|
||||
// add views to table document
|
||||
const table = await db.get(ctx.request.body.tableId)
|
||||
|
@ -53,39 +28,33 @@ const controller = {
|
|||
view.meta.schema = table.schema
|
||||
}
|
||||
table.views[viewToSave.name] = view.meta
|
||||
|
||||
if (originalName) {
|
||||
delete table.views[originalName]
|
||||
}
|
||||
|
||||
await db.put(table)
|
||||
|
||||
ctx.body = {
|
||||
...table.views[viewToSave.name],
|
||||
name: viewToSave.name,
|
||||
}
|
||||
},
|
||||
destroy: async ctx => {
|
||||
}
|
||||
|
||||
exports.destroy = async ctx => {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const viewName = decodeURI(ctx.params.viewName)
|
||||
const view = designDoc.views[viewName]
|
||||
delete designDoc.views[viewName]
|
||||
|
||||
await db.put(designDoc)
|
||||
|
||||
const view = await deleteView(db, viewName)
|
||||
const table = await db.get(view.meta.tableId)
|
||||
delete table.views[viewName]
|
||||
await db.put(table)
|
||||
|
||||
ctx.body = view
|
||||
},
|
||||
exportView: async ctx => {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const designDoc = await db.get("_design/database")
|
||||
const viewName = decodeURI(ctx.query.view)
|
||||
}
|
||||
|
||||
exports.exportView = async ctx => {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
const viewName = decodeURI(ctx.query.view)
|
||||
const view = await getView(db, viewName)
|
||||
|
||||
const view = designDoc.views[viewName]
|
||||
const format = ctx.query.format
|
||||
if (!format) {
|
||||
ctx.throw(400, "Format must be specified, either csv or json")
|
||||
|
@ -122,7 +91,4 @@ const controller = {
|
|||
// send down the file
|
||||
ctx.attachment(filename)
|
||||
ctx.body = apiFileReturn(exporter(headers, ctx.body))
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = controller
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
const {
|
||||
ViewNames,
|
||||
generateMemoryViewID,
|
||||
getMemoryViewParams,
|
||||
} = require("../../../db/utils")
|
||||
const env = require("../../../environment")
|
||||
|
||||
exports.getView = async (db, viewName) => {
|
||||
if (env.SELF_HOSTED) {
|
||||
const designDoc = await db.get("_design/database")
|
||||
return designDoc.views[viewName]
|
||||
} else {
|
||||
const viewDoc = await db.get(generateMemoryViewID(viewName))
|
||||
return viewDoc.view
|
||||
}
|
||||
}
|
||||
|
||||
exports.getViews = async db => {
|
||||
const response = []
|
||||
if (env.SELF_HOSTED) {
|
||||
const designDoc = await db.get("_design/database")
|
||||
for (let name of Object.keys(designDoc.views)) {
|
||||
// Only return custom views, not built ins
|
||||
if (Object.values(ViewNames).indexOf(name) !== -1) {
|
||||
continue
|
||||
}
|
||||
response.push({
|
||||
name,
|
||||
...designDoc.views[name],
|
||||
})
|
||||
}
|
||||
} else {
|
||||
const views = (
|
||||
await db.allDocs(
|
||||
getMemoryViewParams({
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
).rows.map(row => row.doc)
|
||||
for (let viewDoc of views) {
|
||||
response.push({
|
||||
name: viewDoc.name,
|
||||
...viewDoc.view,
|
||||
})
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
exports.saveView = async (db, originalName, viewName, viewTemplate) => {
|
||||
if (env.SELF_HOSTED) {
|
||||
const designDoc = await db.get("_design/database")
|
||||
designDoc.views = {
|
||||
...designDoc.views,
|
||||
[viewName]: viewTemplate,
|
||||
}
|
||||
// view has been renamed
|
||||
if (originalName) {
|
||||
delete designDoc.views[originalName]
|
||||
}
|
||||
await db.put(designDoc)
|
||||
} else {
|
||||
const id = generateMemoryViewID(viewName)
|
||||
const originalId = originalName ? generateMemoryViewID(originalName) : null
|
||||
const viewDoc = {
|
||||
_id: id,
|
||||
view: viewTemplate,
|
||||
name: viewName,
|
||||
tableId: viewTemplate.meta.tableId,
|
||||
}
|
||||
try {
|
||||
const old = await db.get(id)
|
||||
if (originalId) {
|
||||
const originalDoc = await db.get(originalId)
|
||||
await db.remove(originalDoc._id, originalDoc._rev)
|
||||
}
|
||||
if (old && old._rev) {
|
||||
viewDoc._rev = old._rev
|
||||
}
|
||||
} catch (err) {
|
||||
// didn't exist, just skip
|
||||
}
|
||||
await db.put(viewDoc)
|
||||
}
|
||||
}
|
||||
|
||||
exports.deleteView = async (db, viewName) => {
|
||||
if (env.SELF_HOSTED) {
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = designDoc.views[viewName]
|
||||
delete designDoc.views[viewName]
|
||||
await db.put(designDoc)
|
||||
return view
|
||||
} else {
|
||||
const id = generateMemoryViewID(viewName)
|
||||
const viewDoc = await db.get(id)
|
||||
await db.remove(viewDoc._id, viewDoc._rev)
|
||||
return viewDoc.view
|
||||
}
|
||||
}
|
||||
|
||||
exports.migrateToInMemoryView = async (db, viewName) => {
|
||||
// delete the view initially
|
||||
const designDoc = await db.get("_design/database")
|
||||
const view = designDoc.views[viewName]
|
||||
delete designDoc.views[viewName]
|
||||
await db.put(designDoc)
|
||||
await exports.saveView(db, null, viewName, view)
|
||||
}
|
|
@ -205,7 +205,7 @@ describe("/views", () => {
|
|||
})
|
||||
|
||||
describe("exportView", () => {
|
||||
it("should be able to delete a view", async () => {
|
||||
it("should be able to export a view", async () => {
|
||||
await config.createTable(priceTable())
|
||||
await config.createRow()
|
||||
const view = await config.createView()
|
||||
|
|
|
@ -7,9 +7,10 @@ const Queue = env.isTest()
|
|||
: require("bull")
|
||||
const { JobQueues } = require("../constants")
|
||||
const { utils } = require("@budibase/auth/redis")
|
||||
const { opts } = utils.getRedisOptions()
|
||||
const { opts, redisProtocolUrl } = utils.getRedisOptions()
|
||||
|
||||
let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
|
||||
const redisConfig = redisProtocolUrl || { redis: opts }
|
||||
let automationQueue = new Queue(JobQueues.AUTOMATIONS, redisConfig)
|
||||
|
||||
exports.pathPrefix = "/bulladmin"
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ exports.run = async function ({ inputs, context }) {
|
|||
let stdout,
|
||||
success = true
|
||||
try {
|
||||
stdout = execSync(command, { timeout: 500 })
|
||||
stdout = execSync(command, { timeout: 500 }).toString()
|
||||
} catch (err) {
|
||||
stdout = err.message
|
||||
success = false
|
||||
|
|
|
@ -2,6 +2,7 @@ const rowController = require("../../api/controllers/row")
|
|||
const automationUtils = require("../automationUtils")
|
||||
const env = require("../../environment")
|
||||
const usage = require("../../utilities/usageQuota")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
exports.definition = {
|
||||
name: "Create Row",
|
||||
|
@ -69,16 +70,12 @@ exports.run = async function ({ inputs, appId, apiKey, emitter }) {
|
|||
}
|
||||
}
|
||||
// have to clean up the row, remove the table from it
|
||||
const ctx = {
|
||||
const ctx = buildCtx(appId, emitter, {
|
||||
body: inputs.row,
|
||||
params: {
|
||||
tableId: inputs.row.tableId,
|
||||
},
|
||||
request: {
|
||||
body: inputs.row,
|
||||
},
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
inputs.row = await automationUtils.cleanUpRow(
|
||||
|
@ -86,7 +83,7 @@ exports.run = async function ({ inputs, appId, apiKey, emitter }) {
|
|||
inputs.row.tableId,
|
||||
inputs.row
|
||||
)
|
||||
if (env.isProd()) {
|
||||
if (env.USE_QUOTAS) {
|
||||
await usage.update(apiKey, usage.Properties.ROW, 1)
|
||||
}
|
||||
await rowController.save(ctx)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const rowController = require("../../api/controllers/row")
|
||||
const env = require("../../environment")
|
||||
const usage = require("../../utilities/usageQuota")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
exports.definition = {
|
||||
description: "Delete a row from your database",
|
||||
|
@ -60,19 +61,16 @@ exports.run = async function ({ inputs, appId, apiKey, emitter }) {
|
|||
},
|
||||
}
|
||||
}
|
||||
let ctx = {
|
||||
params: {
|
||||
tableId: inputs.tableId,
|
||||
},
|
||||
request: {
|
||||
|
||||
let ctx = buildCtx(appId, emitter, {
|
||||
body: {
|
||||
_id: inputs.id,
|
||||
_rev: inputs.revision,
|
||||
},
|
||||
params: {
|
||||
tableId: inputs.tableId,
|
||||
},
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
if (env.isProd()) {
|
||||
|
|
|
@ -97,12 +97,16 @@ exports.run = async function ({ inputs }) {
|
|||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
if (headers && headers.length !== 0) {
|
||||
if (headers) {
|
||||
try {
|
||||
const customHeaders = JSON.parse(headers)
|
||||
const customHeaders =
|
||||
typeof headers === "string" ? JSON.parse(headers) : headers
|
||||
request.headers = { ...request.headers, ...customHeaders }
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return {
|
||||
success: false,
|
||||
response: "Unable to process headers, must be a JSON object.",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const rowController = require("../../api/controllers/row")
|
||||
const tableController = require("../../api/controllers/table")
|
||||
const { FieldTypes } = require("../../constants")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
const SortOrders = {
|
||||
ASCENDING: "ascending",
|
||||
|
@ -70,12 +71,11 @@ exports.definition = {
|
|||
}
|
||||
|
||||
async function getTable(appId, tableId) {
|
||||
const ctx = {
|
||||
const ctx = buildCtx(appId, null, {
|
||||
params: {
|
||||
id: tableId,
|
||||
},
|
||||
appId,
|
||||
}
|
||||
})
|
||||
await tableController.find(ctx)
|
||||
return ctx.body
|
||||
}
|
||||
|
@ -89,11 +89,10 @@ exports.run = async function ({ inputs, appId }) {
|
|||
sortType =
|
||||
fieldType === FieldTypes.NUMBER ? FieldTypes.NUMBER : FieldTypes.STRING
|
||||
}
|
||||
const ctx = {
|
||||
const ctx = buildCtx(appId, null, {
|
||||
params: {
|
||||
tableId,
|
||||
},
|
||||
request: {
|
||||
body: {
|
||||
sortOrder,
|
||||
sortType,
|
||||
|
@ -101,9 +100,7 @@ exports.run = async function ({ inputs, appId }) {
|
|||
query: filters || {},
|
||||
limit,
|
||||
},
|
||||
},
|
||||
appId,
|
||||
}
|
||||
})
|
||||
try {
|
||||
await rowController.search(ctx)
|
||||
return {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const rowController = require("../../api/controllers/row")
|
||||
const automationUtils = require("../automationUtils")
|
||||
const { buildCtx } = require("./utils")
|
||||
|
||||
exports.definition = {
|
||||
name: "Update Row",
|
||||
|
@ -72,19 +73,15 @@ exports.run = async function ({ inputs, appId, emitter }) {
|
|||
}
|
||||
|
||||
// have to clean up the row, remove the table from it
|
||||
const ctx = {
|
||||
params: {
|
||||
rowId: inputs.rowId,
|
||||
},
|
||||
request: {
|
||||
const ctx = buildCtx(appId, emitter, {
|
||||
body: {
|
||||
...inputs.row,
|
||||
_id: inputs.rowId,
|
||||
},
|
||||
params: {
|
||||
rowId: inputs.rowId,
|
||||
},
|
||||
appId,
|
||||
eventEmitter: emitter,
|
||||
}
|
||||
})
|
||||
|
||||
try {
|
||||
inputs.row = await automationUtils.cleanUpRowById(
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
const PouchDB = require("pouchdb")
|
||||
const memory = require("pouchdb-adapter-memory")
|
||||
const newid = require("./newid")
|
||||
|
||||
PouchDB.plugin(memory)
|
||||
const Pouch = PouchDB.defaults({
|
||||
prefix: undefined,
|
||||
adapter: "memory",
|
||||
})
|
||||
|
||||
exports.runView = async (view, calculation, group, data) => {
|
||||
// use a different ID each time for the DB, make sure they
|
||||
// are always unique for each query, don't want overlap
|
||||
// which could cause 409s
|
||||
const db = new Pouch(newid())
|
||||
// write all the docs to the in memory Pouch (remove revs)
|
||||
await db.bulkDocs(
|
||||
data.map(row => ({
|
||||
...row,
|
||||
_rev: undefined,
|
||||
}))
|
||||
)
|
||||
let fn = (doc, emit) => emit(doc._id)
|
||||
eval("fn = " + view.map.replace("function (doc)", "function (doc, emit)"))
|
||||
const queryFns = {
|
||||
meta: view.meta,
|
||||
map: fn,
|
||||
}
|
||||
if (view.reduce) {
|
||||
queryFns.reduce = view.reduce
|
||||
}
|
||||
const response = await db.query(queryFns, {
|
||||
include_docs: !calculation,
|
||||
group: !!group,
|
||||
})
|
||||
// need to fix the revs to be totally accurate
|
||||
for (let row of response.rows) {
|
||||
if (!row._rev || !row._id) {
|
||||
continue
|
||||
}
|
||||
const found = data.find(possible => possible._id === row._id)
|
||||
if (found) {
|
||||
row._rev = found._rev
|
||||
}
|
||||
}
|
||||
await db.destroy()
|
||||
return response
|
||||
}
|
|
@ -76,9 +76,12 @@ async function getFullLinkedDocs(ctx, appId, links) {
|
|||
// create DBs
|
||||
const db = new CouchDB(appId)
|
||||
const linkedRowIds = links.map(link => link.id)
|
||||
let linked = (await db.allDocs(getMultiIDParams(linkedRowIds))).rows.map(
|
||||
const uniqueRowIds = [...new Set(linkedRowIds)]
|
||||
let dbRows = (await db.allDocs(getMultiIDParams(uniqueRowIds))).rows.map(
|
||||
row => row.doc
|
||||
)
|
||||
// convert the unique db rows back to a full list of linked rows
|
||||
const linked = linkedRowIds.map(id => dbRows.find(row => row._id === id))
|
||||
// need to handle users as specific cases
|
||||
let [users, other] = partition(linked, linkRow =>
|
||||
linkRow._id.startsWith(USER_METDATA_PREFIX)
|
||||
|
@ -112,7 +115,7 @@ exports.updateLinks = async function (args) {
|
|||
let linkController = new LinkController(args)
|
||||
try {
|
||||
if (
|
||||
!(await linkController.doesTableHaveLinkedFields()) &&
|
||||
!(await linkController.doesTableHaveLinkedFields(table)) &&
|
||||
(oldTable == null ||
|
||||
!(await linkController.doesTableHaveLinkedFields(oldTable)))
|
||||
) {
|
||||
|
|
|
@ -39,6 +39,7 @@ const DocumentTypes = {
|
|||
QUERY: "query",
|
||||
DEPLOYMENTS: "deployments",
|
||||
METADATA: "metadata",
|
||||
MEM_VIEW: "view",
|
||||
}
|
||||
|
||||
const ViewNames = {
|
||||
|
@ -348,6 +349,14 @@ exports.getMetadataParams = (type, entityId = null, otherProps = {}) => {
|
|||
return getDocParams(DocumentTypes.METADATA, docId, otherProps)
|
||||
}
|
||||
|
||||
exports.generateMemoryViewID = viewName => {
|
||||
return `${DocumentTypes.MEM_VIEW}${SEPARATOR}${viewName}`
|
||||
}
|
||||
|
||||
exports.getMemoryViewParams = (otherProps = {}) => {
|
||||
return getDocParams(DocumentTypes.MEM_VIEW, null, otherProps)
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be used with the db.allDocs to get a list of IDs
|
||||
*/
|
||||
|
|
|
@ -66,3 +66,10 @@ module.exports = {
|
|||
return !isDev()
|
||||
},
|
||||
}
|
||||
|
||||
// convert any strings to numbers if required, like "0" would be true otherwise
|
||||
for (let [key, value] of Object.entries(module.exports)) {
|
||||
if (typeof value === "string" && !isNaN(parseInt(value))) {
|
||||
module.exports[key] = parseInt(value)
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue