Merge branch 'master' of github.com:Budibase/budibase into develop

This commit is contained in:
mike12345567 2022-06-17 11:41:34 +01:00
commit 7050ffc2cb
34 changed files with 192 additions and 98 deletions

View File

@ -93,6 +93,10 @@ spec:
value: {{ .Values.globals.selfHosted | quote }} value: {{ .Values.globals.selfHosted | quote }}
- name: SENTRY_DSN - name: SENTRY_DSN
value: {{ .Values.globals.sentryDSN }} value: {{ .Values.globals.sentryDSN }}
- name: ENABLE_ANALYTICS
value: {{ .Values.globals.enableAnalytics | quote }}
- name: POSTHOG_TOKEN
value: {{ .Values.globals.posthogToken }}
- name: ACCOUNT_PORTAL_URL - name: ACCOUNT_PORTAL_URL
value: {{ .Values.globals.accountPortalUrl | quote }} value: {{ .Values.globals.accountPortalUrl | quote }}
- name: ACCOUNT_PORTAL_API_KEY - name: ACCOUNT_PORTAL_API_KEY

View File

@ -89,7 +89,7 @@ affinity: {}
globals: globals:
appVersion: "latest" appVersion: "latest"
budibaseEnv: PRODUCTION budibaseEnv: PRODUCTION
enableAnalytics: true enableAnalytics: "1"
sentryDSN: "" sentryDSN: ""
posthogToken: "phc_fg5I3nDOf6oJVMHSaycEhpPdlgS8rzXG2r6F2IpxCHS" posthogToken: "phc_fg5I3nDOf6oJVMHSaycEhpPdlgS8rzXG2r6F2IpxCHS"
logLevel: info logLevel: info

View File

@ -1,5 +1,5 @@
{ {
"version": "1.0.200-alpha.3", "version": "1.0.206",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/backend-core", "name": "@budibase/backend-core",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase backend core libraries used in server and worker", "description": "Budibase backend core libraries used in server and worker",
"main": "dist/src/index.js", "main": "dist/src/index.js",
"types": "dist/src/index.d.ts", "types": "dist/src/index.d.ts",
@ -13,6 +13,7 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"scripts": { "scripts": {
"prebuild": "rimraf dist/", "prebuild": "rimraf dist/",
"prepack": "cp package.json dist",
"build": "tsc -p tsconfig.build.json", "build": "tsc -p tsconfig.build.json",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"test": "jest", "test": "jest",
@ -56,7 +57,7 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@budibase/types": "^1.0.200-alpha.3", "@budibase/types": "^1.0.206",
"@shopify/jest-koa-mocks": "3.1.5", "@shopify/jest-koa-mocks": "3.1.5",
"@types/jest": "27.5.1", "@types/jest": "27.5.1",
"@types/koa": "2.0.52", "@types/koa": "2.0.52",

View File

@ -14,7 +14,6 @@ import {
CloudAccount, CloudAccount,
UserIdentity, UserIdentity,
InstallationGroup, InstallationGroup,
isSelfHostAccount,
UserContext, UserContext,
Group, Group,
} from "@budibase/types" } from "@budibase/types"
@ -36,6 +35,7 @@ const pkg = require("../../package.json")
*/ */
export const getCurrentIdentity = async (): Promise<Identity> => { export const getCurrentIdentity = async (): Promise<Identity> => {
let identityContext = identityCtx.getIdentity() let identityContext = identityCtx.getIdentity()
const environment = getDeploymentEnvironment()
let identityType let identityType
@ -47,36 +47,47 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
if (identityType === IdentityType.INSTALLATION) { if (identityType === IdentityType.INSTALLATION) {
const installationId = await getInstallationId() const installationId = await getInstallationId()
const hosting = getHostingFromEnv()
return { return {
id: formatDistinctId(installationId, identityType), id: formatDistinctId(installationId, identityType),
hosting,
type: identityType, type: identityType,
installationId, installationId,
environment,
} }
} else if (identityType === IdentityType.TENANT) { } else if (identityType === IdentityType.TENANT) {
const installationId = await getInstallationId() const installationId = await getInstallationId()
const tenantId = await getEventTenantId(context.getTenantId()) const tenantId = await getEventTenantId(context.getTenantId())
const hosting = getHostingFromEnv()
return { return {
id: formatDistinctId(tenantId, identityType), id: formatDistinctId(tenantId, identityType),
type: identityType, type: identityType,
hosting,
installationId, installationId,
tenantId, tenantId,
environment,
} }
} else if (identityType === IdentityType.USER) { } else if (identityType === IdentityType.USER) {
const userContext = identityContext as UserContext const userContext = identityContext as UserContext
const tenantId = await getEventTenantId(context.getTenantId()) const tenantId = await getEventTenantId(context.getTenantId())
let installationId: string | undefined const installationId = await getInstallationId()
// self host account users won't have installation const account = userContext.account
if (!userContext.account || !isSelfHostAccount(userContext.account)) { let hosting
installationId = await getInstallationId() if (account) {
hosting = account.hosting
} else {
hosting = getHostingFromEnv()
} }
return { return {
id: userContext._id, id: userContext._id,
type: identityType, type: identityType,
hosting,
installationId, installationId,
tenantId, tenantId,
environment,
} }
} else { } else {
throw new Error("Unknown identity type") throw new Error("Unknown identity type")
@ -91,12 +102,14 @@ export const identifyInstallationGroup = async (
const type = IdentityType.INSTALLATION const type = IdentityType.INSTALLATION
const hosting = getHostingFromEnv() const hosting = getHostingFromEnv()
const version = pkg.version const version = pkg.version
const environment = getDeploymentEnvironment()
const group: InstallationGroup = { const group: InstallationGroup = {
id, id,
type, type,
hosting, hosting,
version, version,
environment,
} }
await identifyGroup(group, timestamp) await identifyGroup(group, timestamp)
@ -112,6 +125,8 @@ export const identifyTenantGroup = async (
): Promise<void> => { ): Promise<void> => {
const id = await getEventTenantId(tenantId) const id = await getEventTenantId(tenantId)
const type = IdentityType.TENANT const type = IdentityType.TENANT
const installationId = await getInstallationId()
const environment = getDeploymentEnvironment()
let hosting: Hosting let hosting: Hosting
let profession: string | undefined let profession: string | undefined
@ -129,6 +144,8 @@ export const identifyTenantGroup = async (
id, id,
type, type,
hosting, hosting,
environment,
installationId,
profession, profession,
companySize, companySize,
} }
@ -154,10 +171,13 @@ export const identifyUser = async (
const verified = const verified =
account && account?.budibaseUserId === user._id ? account.verified : false account && account?.budibaseUserId === user._id ? account.verified : false
const installationId = await getInstallationId() const installationId = await getInstallationId()
const hosting = account ? account.hosting : getHostingFromEnv()
const environment = getDeploymentEnvironment()
const identity: UserIdentity = { const identity: UserIdentity = {
id, id,
type, type,
hosting,
installationId, installationId,
tenantId, tenantId,
verified, verified,
@ -165,6 +185,7 @@ export const identifyUser = async (
providerType, providerType,
builder, builder,
admin, admin,
environment,
} }
await identify(identity, timestamp) await identify(identity, timestamp)
@ -177,6 +198,9 @@ export const identifyAccount = async (account: Account) => {
let providerType = isSSOAccount(account) ? account.providerType : undefined let providerType = isSSOAccount(account) ? account.providerType : undefined
const verified = account.verified const verified = account.verified
const accountHolder = true const accountHolder = true
const hosting = account.hosting
const installationId = await getInstallationId()
const environment = getDeploymentEnvironment()
if (isCloudAccount(account)) { if (isCloudAccount(account)) {
if (account.budibaseUserId) { if (account.budibaseUserId) {
@ -188,10 +212,13 @@ export const identifyAccount = async (account: Account) => {
const identity: UserIdentity = { const identity: UserIdentity = {
id, id,
type, type,
hosting,
installationId,
tenantId, tenantId,
providerType, providerType,
verified, verified,
accountHolder, accountHolder,
environment,
} }
await identify(identity) await identify(identity)
@ -211,6 +238,14 @@ export const identifyGroup = async (
await processors.identifyGroup(group, timestamp) await processors.identifyGroup(group, timestamp)
} }
const getDeploymentEnvironment = () => {
if (env.isDev()) {
return "development"
} else {
return env.DEPLOYMENT_ENVIRONMENT
}
}
const getHostingFromEnv = () => { const getHostingFromEnv = () => {
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD
} }

View File

@ -7,14 +7,17 @@ import PosthogProcessor from "./PosthogProcessor"
/** /**
* Events that are always captured. * Events that are always captured.
*/ */
const EVENT_WHITELIST = [Event.VERSION_UPGRADED, Event.VERSION_DOWNGRADED] const EVENT_WHITELIST = [
Event.INSTALLATION_VERSION_UPGRADED,
Event.INSTALLATION_VERSION_DOWNGRADED,
]
const IDENTITY_WHITELIST = [IdentityType.INSTALLATION, IdentityType.TENANT] const IDENTITY_WHITELIST = [IdentityType.INSTALLATION, IdentityType.TENANT]
export default class AnalyticsProcessor implements EventProcessor { export default class AnalyticsProcessor implements EventProcessor {
posthog: PosthogProcessor | undefined posthog: PosthogProcessor | undefined
constructor() { constructor() {
if (env.POSTHOG_TOKEN) { if (env.POSTHOG_TOKEN && !env.isTest()) {
this.posthog = new PosthogProcessor(env.POSTHOG_TOKEN) this.posthog = new PosthogProcessor(env.POSTHOG_TOKEN)
} }
} }

View File

@ -23,7 +23,8 @@ export default class PosthogProcessor implements EventProcessor {
): Promise<void> { ): Promise<void> {
properties.version = pkg.version properties.version = pkg.version
properties.service = env.SERVICE properties.service = env.SERVICE
properties.environment = env.DEPLOYMENT_ENVIRONMENT properties.environment = identity.environment
properties.hosting = identity.hosting
const appId = context.getAppId() const appId = context.getAppId()
if (appId) { if (appId) {

View File

@ -15,5 +15,5 @@ export * as table from "./table"
export * as serve from "./serve" export * as serve from "./serve"
export * as user from "./user" export * as user from "./user"
export * as view from "./view" export * as view from "./view"
export * as version from "./version" export * as installation from "./installation"
export * as backfill from "./backfill" export * as backfill from "./backfill"

View File

@ -1,11 +1,11 @@
import { publishEvent } from "../events" import { publishEvent } from "../events"
import { Event, VersionCheckedEvent, VersionChangeEvent } from "@budibase/types" import { Event, VersionCheckedEvent, VersionChangeEvent } from "@budibase/types"
export async function checked(version: string) { export async function versionChecked(version: string) {
const properties: VersionCheckedEvent = { const properties: VersionCheckedEvent = {
currentVersion: version, currentVersion: version,
} }
await publishEvent(Event.VERSION_CHECKED, properties) await publishEvent(Event.INSTALLATION_VERSION_CHECKED, properties)
} }
export async function upgraded(from: string, to: string) { export async function upgraded(from: string, to: string) {
@ -14,7 +14,7 @@ export async function upgraded(from: string, to: string) {
to, to,
} }
await publishEvent(Event.VERSION_UPGRADED, properties) await publishEvent(Event.INSTALLATION_VERSION_UPGRADED, properties)
} }
export async function downgraded(from: string, to: string) { export async function downgraded(from: string, to: string) {
@ -22,5 +22,10 @@ export async function downgraded(from: string, to: string) {
from, from,
to, to,
} }
await publishEvent(Event.VERSION_DOWNGRADED, properties) await publishEvent(Event.INSTALLATION_VERSION_DOWNGRADED, properties)
}
export async function firstStartup() {
const properties = {}
await publishEvent(Event.INSTALLATION_FIRST_STARTUP, properties)
} }

View File

@ -84,9 +84,9 @@ export const checkInstallVersion = async (): Promise<void> => {
}, },
async () => { async () => {
if (isUpgrade) { if (isUpgrade) {
await events.version.upgraded(currentVersion, newVersion) await events.installation.upgraded(currentVersion, newVersion)
} else if (isDowngrade) { } else if (isDowngrade) {
await events.version.downgraded(currentVersion, newVersion) await events.installation.downgraded(currentVersion, newVersion)
} }
} }
) )

View File

@ -55,7 +55,7 @@ jest.spyOn(events.org, "logoUpdated")
jest.spyOn(events.org, "platformURLUpdated") jest.spyOn(events.org, "platformURLUpdated")
jest.spyOn(events.org, "analyticsOptOut") jest.spyOn(events.org, "analyticsOptOut")
jest.spyOn(events.version, "checked") jest.spyOn(events.installation, "versionChecked")
jest.spyOn(events.query, "created") jest.spyOn(events.query, "created")
jest.spyOn(events.query, "updated") jest.spyOn(events.query, "updated")

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/bbui", "name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.", "description": "A UI solution used in the different Budibase projects.",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"module": "dist/bbui.es.js", "module": "dist/bbui.es.js",
@ -38,7 +38,7 @@
], ],
"dependencies": { "dependencies": {
"@adobe/spectrum-css-workflow-icons": "^1.2.1", "@adobe/spectrum-css-workflow-icons": "^1.2.1",
"@budibase/string-templates": "^1.0.200-alpha.3", "@budibase/string-templates": "^1.0.206",
"@spectrum-css/actionbutton": "^1.0.1", "@spectrum-css/actionbutton": "^1.0.1",
"@spectrum-css/actiongroup": "^1.0.1", "@spectrum-css/actiongroup": "^1.0.1",
"@spectrum-css/avatar": "^3.0.2", "@spectrum-css/avatar": "^3.0.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"license": "GPL-3.0", "license": "GPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -69,10 +69,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.0.200-alpha.3", "@budibase/bbui": "^1.0.206",
"@budibase/client": "^1.0.200-alpha.3", "@budibase/client": "^1.0.206",
"@budibase/frontend-core": "^1.0.200-alpha.3", "@budibase/frontend-core": "^1.0.206",
"@budibase/string-templates": "^1.0.200-alpha.3", "@budibase/string-templates": "^1.0.206",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1", "@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1", "@spectrum-css/vars": "^3.0.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/cli", "name": "@budibase/cli",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase CLI, for developers, self hosting and migrations.", "description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js", "main": "src/index.js",
"bin": { "bin": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"license": "MPL-2.0", "license": "MPL-2.0",
"module": "dist/budibase-client.js", "module": "dist/budibase-client.js",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
@ -19,9 +19,9 @@
"dev:builder": "rollup -cw" "dev:builder": "rollup -cw"
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.0.200-alpha.3", "@budibase/bbui": "^1.0.206",
"@budibase/frontend-core": "^1.0.200-alpha.3", "@budibase/frontend-core": "^1.0.206",
"@budibase/string-templates": "^1.0.200-alpha.3", "@budibase/string-templates": "^1.0.206",
"@spectrum-css/button": "^3.0.3", "@spectrum-css/button": "^3.0.3",
"@spectrum-css/card": "^3.0.3", "@spectrum-css/card": "^3.0.3",
"@spectrum-css/divider": "^1.0.3", "@spectrum-css/divider": "^1.0.3",

View File

@ -1,12 +1,12 @@
{ {
"name": "@budibase/frontend-core", "name": "@budibase/frontend-core",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase frontend core libraries used in builder and client", "description": "Budibase frontend core libraries used in builder and client",
"author": "Budibase", "author": "Budibase",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.0.200-alpha.3", "@budibase/bbui": "^1.0.206",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"svelte": "^3.46.2" "svelte": "^3.46.2"
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -77,10 +77,10 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@apidevtools/swagger-parser": "10.0.3", "@apidevtools/swagger-parser": "10.0.3",
"@budibase/backend-core": "^1.0.200-alpha.3", "@budibase/backend-core": "^1.0.206",
"@budibase/client": "^1.0.200-alpha.3", "@budibase/client": "^1.0.206",
"@budibase/pro": "1.0.200-alpha.3", "@budibase/pro": "1.0.206",
"@budibase/string-templates": "^1.0.200-alpha.3", "@budibase/string-templates": "^1.0.206",
"@bull-board/api": "3.7.0", "@bull-board/api": "3.7.0",
"@bull-board/koa": "3.9.4", "@bull-board/koa": "3.9.4",
"@elastic/elasticsearch": "7.10.0", "@elastic/elasticsearch": "7.10.0",
@ -151,7 +151,7 @@
"@babel/core": "7.17.4", "@babel/core": "7.17.4",
"@babel/preset-env": "7.16.11", "@babel/preset-env": "7.16.11",
"@budibase/standard-components": "^0.9.139", "@budibase/standard-components": "^0.9.139",
"@budibase/types": "^1.0.200-alpha.3", "@budibase/types": "^1.0.206",
"@jest/test-sequencer": "24.9.0", "@jest/test-sequencer": "24.9.0",
"@types/apidoc": "0.50.0", "@types/apidoc": "0.50.0",
"@types/bson": "4.2.0", "@types/bson": "4.2.0",

View File

@ -131,5 +131,5 @@ exports.getBudibaseVersion = async ctx => {
ctx.body = { ctx.body = {
version, version,
} }
await events.version.checked(version) await events.installation.versionChecked(version)
} }

View File

@ -17,7 +17,6 @@ const { attachmentsRelativeURL } = require("../../../utilities")
const { DocumentTypes, isDevAppID } = require("../../../db/utils") const { DocumentTypes, isDevAppID } = require("../../../db/utils")
const { getAppDB, getAppId } = require("@budibase/backend-core/context") const { getAppDB, getAppId } = require("@budibase/backend-core/context")
const AWS = require("aws-sdk") const AWS = require("aws-sdk")
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
const { events } = require("@budibase/backend-core") const { events } = require("@budibase/backend-core")
async function prepareUpload({ s3Key, bucket, metadata, file }) { async function prepareUpload({ s3Key, bucket, metadata, file }) {
@ -42,7 +41,9 @@ async function prepareUpload({ s3Key, bucket, metadata, file }) {
exports.serveBuilder = async function (ctx) { exports.serveBuilder = async function (ctx) {
let builderPath = resolve(TOP_LEVEL_PATH, "builder") let builderPath = resolve(TOP_LEVEL_PATH, "builder")
await send(ctx, ctx.file, { root: builderPath }) await send(ctx, ctx.file, { root: builderPath })
if (!ctx.file.includes("assets/")) {
await events.serve.servedBuilder() await events.serve.servedBuilder()
}
} }
exports.uploadFile = async function (ctx) { exports.uploadFile = async function (ctx) {
@ -128,6 +129,7 @@ exports.getSignedUploadURL = async function (ctx) {
// Determine type of datasource and generate signed URL // Determine type of datasource and generate signed URL
let signedUrl let signedUrl
let publicUrl let publicUrl
const awsRegion = datasource?.config?.region || "eu-west-1"
if (datasource.source === "S3") { if (datasource.source === "S3") {
const { bucket, key } = ctx.request.body || {} const { bucket, key } = ctx.request.body || {}
if (!bucket || !key) { if (!bucket || !key) {
@ -136,7 +138,7 @@ exports.getSignedUploadURL = async function (ctx) {
} }
try { try {
const s3 = new AWS.S3({ const s3 = new AWS.S3({
region: AWS_REGION, region: awsRegion,
accessKeyId: datasource?.config?.accessKeyId, accessKeyId: datasource?.config?.accessKeyId,
secretAccessKey: datasource?.config?.secretAccessKey, secretAccessKey: datasource?.config?.secretAccessKey,
apiVersion: "2006-03-01", apiVersion: "2006-03-01",
@ -144,7 +146,7 @@ exports.getSignedUploadURL = async function (ctx) {
}) })
const params = { Bucket: bucket, Key: key } const params = { Bucket: bucket, Key: key }
signedUrl = s3.getSignedUrl("putObject", params) signedUrl = s3.getSignedUrl("putObject", params)
publicUrl = `https://${bucket}.s3.${AWS_REGION}.amazonaws.com/${key}` publicUrl = `https://${bucket}.s3.${awsRegion}.amazonaws.com/${key}`
} catch (error) { } catch (error) {
ctx.throw(400, error) ctx.throw(400, error)
} }

View File

@ -33,8 +33,8 @@ describe("/dev", () => {
.expect(200) .expect(200)
expect(res.body.version).toBe(version) expect(res.body.version).toBe(version)
expect(events.version.checked).toBeCalledTimes(1) expect(events.installation.versionChecked).toBeCalledTimes(1)
expect(events.version.checked).toBeCalledWith(version) expect(events.installation.versionChecked).toBeCalledWith(version)
}) })
}) })
}) })

View File

@ -72,7 +72,7 @@ exports.run = async function ({ inputs, appId, emitter }) {
}) })
try { try {
await queryController.executeV1(ctx) await queryController.executeV2(ctx)
const { data, ...rest } = ctx.body const { data, ...rest } = ctx.body
return { return {
response: data, response: data,

View File

@ -66,7 +66,6 @@ module Firebase {
"==", "==",
"<", "<",
"<=", "<=",
"==",
"!=", "!=",
">=", ">=",
">", ">",

View File

@ -20,6 +20,7 @@ const handleError = (e: any, errors?: any) => {
} }
return return
} }
console.trace(e)
throw e throw e
} }

View File

@ -22,10 +22,23 @@ export const backfill = async (appDb: any, timestamp: string | number) => {
const queries: Query[] = await getQueries(appDb) const queries: Query[] = await getQueries(appDb)
for (const query of queries) { for (const query of queries) {
const datasource: Datasource = await getDatasource( let datasource: Datasource
appDb,
query.datasourceId try {
) datasource = await getDatasource(appDb, query.datasourceId)
} catch (e: any) {
// handle known bug where a datasource has been deleted
// and the query has not
if (e.status === 404) {
datasource = {
_id: query.datasourceId,
source: "unknown",
}
} else {
throw e
}
}
await events.query.created(datasource, query, timestamp) await events.query.created(datasource, query, timestamp)
} }

View File

@ -14,6 +14,7 @@ import {
App, App,
TenantBackfillSucceededEvent, TenantBackfillSucceededEvent,
Event, Event,
User,
} from "@budibase/types" } from "@budibase/types"
import env from "../../../environment" import env from "../../../environment"
import { DEFAULT_TIMESTAMP } from "." import { DEFAULT_TIMESTAMP } from "."
@ -94,8 +95,24 @@ export const run = async (db: any) => {
const totals: any = {} const totals: any = {}
const errors: any = [] const errors: any = []
let allUsers: User[] = []
try { try {
const installTimestamp = await getInstallTimestamp(db) allUsers = await users.getUsers(db)
} catch (e: any) {
handleError(e, errors)
}
if (!allUsers || allUsers.length === 0) {
// first time startup - we don't need to backfill anything
// tenant will be identified when admin user is created
if (env.SELF_HOSTED) {
await events.installation.firstStartup()
}
return
}
try {
const installTimestamp = await getInstallTimestamp(db, allUsers)
if (installTimestamp) { if (installTimestamp) {
timestamp = installTimestamp timestamp = installTimestamp
} }
@ -175,11 +192,15 @@ export const isComplete = async (): Promise<boolean> => {
} }
export const getInstallTimestamp = async ( export const getInstallTimestamp = async (
globalDb: any globalDb: any,
allUsers?: User[]
): Promise<number | undefined> => { ): Promise<number | undefined> => {
const allUsers = await users.getUsers(globalDb) if (!allUsers) {
allUsers = await users.getUsers(globalDb)
}
// get the oldest user timestamp // get the oldest user timestamp
if (allUsers) {
const timestamps = allUsers const timestamps = allUsers
.map(user => user.createdAt) .map(user => user.createdAt)
.filter(timestamp => !!timestamp) .filter(timestamp => !!timestamp)
@ -191,4 +212,5 @@ export const getInstallTimestamp = async (
if (timestamps.length) { if (timestamps.length) {
return timestamps[0] return timestamps[0]
} }
}
} }

View File

@ -104,7 +104,6 @@ export const migrate = async (options?: MigrationOptions) => {
const migrateWithLock = async (options?: MigrationOptions) => { const migrateWithLock = async (options?: MigrationOptions) => {
// get a new lock client // get a new lock client
const redlock = await redis.clients.getMigrationsRedlock() const redlock = await redis.clients.getMigrationsRedlock()
// lock for 15 minutes // lock for 15 minutes
const ttl = 1000 * 60 * 15 const ttl = 1000 * 60 * 15

View File

@ -23,6 +23,8 @@ const clearMigrations = async () => {
} }
} }
jest.setTimeout(10000)
describe("migrations", () => { describe("migrations", () => {
const config = new TestConfig() const config = new TestConfig()

View File

@ -1094,10 +1094,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@1.0.200-alpha.0": "@budibase/backend-core@1.0.201-alpha.4":
version "1.0.200-alpha.0" version "1.0.201-alpha.4"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.200-alpha.0.tgz#2fd1e1cc71c07891fd66e37ceaab2cffb0df1106" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.201-alpha.4.tgz#51fda5838e9c51c88c85204ad867811e49b7d34c"
integrity sha512-CZPPuj+WIDTxLVbrv/B4J4rQiNnkRBs3ZWK2AvlVlY9knWuM034MKHPK3YaeQdVofZqkTOfWKZp6KFRroC304g== integrity sha512-5oQMfKPDMpB4x5MzGgOtWFIPzc7RG/uu+rSe65PVwWfp77bDa3kxtCtC1p6vtJuPlb4GYrHqGLtr7WePbJf4fA==
dependencies: dependencies:
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-sdk "2.1030.0" aws-sdk "2.1030.0"
@ -1175,12 +1175,12 @@
svelte-flatpickr "^3.2.3" svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0" svelte-portal "^1.0.0"
"@budibase/pro@1.0.200-alpha.0": "@budibase/pro@1.0.201-alpha.4":
version "1.0.200-alpha.0" version "1.0.201-alpha.4"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.200-alpha.0.tgz#68adc9a61a1b975a990e1a4d4ddf5dba69fc038c" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.201-alpha.4.tgz#5b92dc7a4bb2004bcd43339c863430ea640e0b74"
integrity sha512-GxIxvBjCO7kQxFwASKtGC57C2cAN3oiHU+tTCb57qKtp63GdP1z+iqDLtUEOIXXume9bC1xxTD/LSBMziTrHKg== integrity sha512-fsDlE8O4Y4JpZI3NwBoN8udX4cEx7/ebZ41Q7qD5VwA6Q2niapRcX0MvDmGdjDSVECG+NJU1uqCdg5cDq1Odxw==
dependencies: dependencies:
"@budibase/backend-core" "1.0.200-alpha.0" "@budibase/backend-core" "1.0.201-alpha.4"
node-fetch "^2.6.1" node-fetch "^2.6.1"
"@budibase/standard-components@^0.9.139": "@budibase/standard-components@^0.9.139":
@ -14327,4 +14327,4 @@ z-schema@^5.0.1:
zlib@1.0.5: zlib@1.0.5:
version "1.0.5" version "1.0.5"
resolved "https://registry.yarnpkg.com/zlib/-/zlib-1.0.5.tgz#6e7c972fc371c645a6afb03ab14769def114fcc0" resolved "https://registry.yarnpkg.com/zlib/-/zlib-1.0.5.tgz#6e7c972fc371c645a6afb03ab14769def114fcc0"
integrity sha1-bnyXL8NxxkWmr7A6sUdp3vEU/MA= integrity sha512-40fpE2II+Cd3k8HWTWONfeKE2jL+P42iWJ1zzps5W51qcTsOUKM5Q5m2PFb0CLxlmFAaUuUdJGc3OfZy947v0w==

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/string-templates", "name": "@budibase/string-templates",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Handlebars wrapper for Budibase templating.", "description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs", "main": "src/index.cjs",
"module": "dist/bundle.mjs", "module": "dist/bundle.mjs",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/types", "name": "@budibase/types",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase types", "description": "Budibase types",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,3 +1,5 @@
import { Hosting } from "../hosting"
export enum Event { export enum Event {
// USER // USER
USER_CREATED = "user:created", USER_CREATED = "user:created",
@ -37,10 +39,11 @@ export enum Event {
ORG_LOGO_UPDATED = "org:info:logo:updated", ORG_LOGO_UPDATED = "org:info:logo:updated",
ORG_PLATFORM_URL_UPDATED = "org:platformurl:updated", ORG_PLATFORM_URL_UPDATED = "org:platformurl:updated",
// VERSIONS // INSTALLATION
VERSION_CHECKED = "version:checked", INSTALLATION_VERSION_CHECKED = "installation:version:checked",
VERSION_UPGRADED = "version:upgraded", INSTALLATION_VERSION_UPGRADED = "installation:version:upgraded",
VERSION_DOWNGRADED = "version:downgraded", INSTALLATION_VERSION_DOWNGRADED = "installation:version:downgraded",
INSTALLATION_FIRST_STARTUP = "installation:firstStartup",
// ORG / ANALYTICS // ORG / ANALYTICS
ANALYTICS_OPT_OUT = "analytics:opt:out", ANALYTICS_OPT_OUT = "analytics:opt:out",
@ -157,6 +160,7 @@ export interface BaseEvent {
appId?: string appId?: string
installationId?: string installationId?: string
tenantId?: string tenantId?: string
hosting?: Hosting
} }
export type RowImportFormat = "csv" export type RowImportFormat = "csv"

View File

@ -10,6 +10,8 @@ export enum GroupType {
export interface Group { export interface Group {
id: string id: string
type: IdentityType type: IdentityType
environment: string
hosting: Hosting
} }
export interface TenantGroup extends Group { export interface TenantGroup extends Group {
@ -17,12 +19,11 @@ export interface TenantGroup extends Group {
// as we don't have this at the user level // as we don't have this at the user level
profession?: string // only available in cloud profession?: string // only available in cloud
companySize?: string // only available in cloud companySize?: string // only available in cloud
hosting: Hosting // need hosting at the tenant level for cloud self host accounts installationId: string
} }
export interface InstallationGroup extends Group { export interface InstallationGroup extends Group {
version: string version: string
hosting: Hosting
} }
// IDENTITIES // IDENTITIES
@ -36,6 +37,8 @@ export enum IdentityType {
export interface Identity { export interface Identity {
id: string id: string
type: IdentityType type: IdentityType
hosting: Hosting
environment: string
installationId?: string installationId?: string
tenantId?: string tenantId?: string
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/worker", "name": "@budibase/worker",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "1.0.200-alpha.3", "version": "1.0.206",
"description": "Budibase background service", "description": "Budibase background service",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -34,9 +34,9 @@
"author": "Budibase", "author": "Budibase",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@budibase/backend-core": "^1.0.200-alpha.3", "@budibase/backend-core": "^1.0.206",
"@budibase/pro": "1.0.200-alpha.3", "@budibase/pro": "1.0.206",
"@budibase/string-templates": "^1.0.200-alpha.3", "@budibase/string-templates": "^1.0.206",
"@koa/router": "8.0.8", "@koa/router": "8.0.8",
"@sentry/node": "6.17.7", "@sentry/node": "6.17.7",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",
@ -66,7 +66,7 @@
"server-destroy": "1.0.1" "server-destroy": "1.0.1"
}, },
"devDependencies": { "devDependencies": {
"@budibase/types": "^1.0.200-alpha.3", "@budibase/types": "^1.0.206",
"@types/jest": "26.0.23", "@types/jest": "26.0.23",
"@types/koa": "2.13.4", "@types/koa": "2.13.4",
"@types/koa-router": "7.4.4", "@types/koa-router": "7.4.4",

View File

@ -291,10 +291,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@1.0.200-alpha.0": "@budibase/backend-core@1.0.201-alpha.4":
version "1.0.200-alpha.0" version "1.0.201-alpha.4"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.200-alpha.0.tgz#2fd1e1cc71c07891fd66e37ceaab2cffb0df1106" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.201-alpha.4.tgz#51fda5838e9c51c88c85204ad867811e49b7d34c"
integrity sha512-CZPPuj+WIDTxLVbrv/B4J4rQiNnkRBs3ZWK2AvlVlY9knWuM034MKHPK3YaeQdVofZqkTOfWKZp6KFRroC304g== integrity sha512-5oQMfKPDMpB4x5MzGgOtWFIPzc7RG/uu+rSe65PVwWfp77bDa3kxtCtC1p6vtJuPlb4GYrHqGLtr7WePbJf4fA==
dependencies: dependencies:
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-sdk "2.1030.0" aws-sdk "2.1030.0"
@ -322,12 +322,12 @@
uuid "8.3.2" uuid "8.3.2"
zlib "1.0.5" zlib "1.0.5"
"@budibase/pro@1.0.200-alpha.0": "@budibase/pro@1.0.201-alpha.4":
version "1.0.200-alpha.0" version "1.0.201-alpha.4"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.200-alpha.0.tgz#68adc9a61a1b975a990e1a4d4ddf5dba69fc038c" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.201-alpha.4.tgz#5b92dc7a4bb2004bcd43339c863430ea640e0b74"
integrity sha512-GxIxvBjCO7kQxFwASKtGC57C2cAN3oiHU+tTCb57qKtp63GdP1z+iqDLtUEOIXXume9bC1xxTD/LSBMziTrHKg== integrity sha512-fsDlE8O4Y4JpZI3NwBoN8udX4cEx7/ebZ41Q7qD5VwA6Q2niapRcX0MvDmGdjDSVECG+NJU1uqCdg5cDq1Odxw==
dependencies: dependencies:
"@budibase/backend-core" "1.0.200-alpha.0" "@budibase/backend-core" "1.0.201-alpha.4"
node-fetch "^2.6.1" node-fetch "^2.6.1"
"@cspotcode/source-map-consumer@0.8.0": "@cspotcode/source-map-consumer@0.8.0":