App backfill (wip)
This commit is contained in:
parent
11ea9d90e3
commit
1f56d31ebb
|
@ -36,8 +36,8 @@
|
|||
"kill-server": "kill-port 4001 4002",
|
||||
"kill-all": "yarn run kill-builder && yarn run kill-server",
|
||||
"dev": "yarn run kill-all && lerna link && lerna run --parallel dev:builder --concurrency 1",
|
||||
"dev:noserver": "yarn run kill-builder && lerna link && lerna run dev:stack:up && lerna run --parallel dev:builder --concurrency 1 --ignore @budibase/server --ignore @budibase/worker",
|
||||
"dev:server": "yarn run kill-server && lerna run --parallel dev:builder --concurrency 1 --scope @budibase/worker --scope @budibase/server",
|
||||
"dev:noserver": "yarn run kill-builder && lerna link && lerna run dev:stack:up && lerna run --parallel dev:builder --concurrency 1 --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker",
|
||||
"dev:server": "yarn run kill-server && lerna run --parallel dev:builder --concurrency 1 --scope @budibase/backend-core --scope @budibase/worker --scope @budibase/server",
|
||||
"test": "lerna run test",
|
||||
"lint:eslint": "eslint packages",
|
||||
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"build": "rimraf dist/ && tsc -p tsconfig.build.json",
|
||||
"dev:builder": "rimraf dist/ && tsc -p tsconfig.build.json --watch",
|
||||
"dev:builder": "rimraf dist/ && tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watchAll"
|
||||
},
|
||||
|
|
|
@ -1,32 +1,24 @@
|
|||
const PosthogClient = require("./posthog")
|
||||
const env = require("../environment")
|
||||
const { getTenantId } = require("../context")
|
||||
|
||||
const IdentityType = {
|
||||
TENANT: "tenant",
|
||||
USER: "user",
|
||||
ACCOUNT: "account",
|
||||
}
|
||||
|
||||
const Hosting = {
|
||||
CLOUD: "cloud",
|
||||
SELF: "self",
|
||||
}
|
||||
import PosthogClient from "./PosthogClient"
|
||||
import env from "../environment"
|
||||
import { getTenantId } from "../context"
|
||||
import { Account, Hosting, Event, IdentityType } from "@budibase/types"
|
||||
|
||||
class Analytics {
|
||||
isEnabled: boolean
|
||||
posthog: PosthogClient | undefined
|
||||
|
||||
constructor() {
|
||||
// check enabled before init
|
||||
this.isEnabled = !!(!env.SELF_HOSTED && env.ENABLE_ANALYTICS)
|
||||
this.isEnabled = !!env.ENABLE_ANALYTICS // TODO: use db flag instead
|
||||
if (!this.isEnabled) return
|
||||
|
||||
this.posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
|
||||
this.posthog = new PosthogClient(env.POSTHOG_TOKEN)
|
||||
}
|
||||
|
||||
enabled() {
|
||||
return this.isEnabled
|
||||
}
|
||||
|
||||
identify(type, id, hosting) {
|
||||
identify(type: IdentityType, id: string, hosting?: Hosting) {
|
||||
if (!this.isEnabled) return
|
||||
const tenantId = getTenantId()
|
||||
if (!hosting) {
|
||||
|
@ -35,12 +27,12 @@ class Analytics {
|
|||
const properties = {
|
||||
type,
|
||||
hosting,
|
||||
tenant: tenantId,
|
||||
tenantId,
|
||||
}
|
||||
this.posthog.identify(id, properties)
|
||||
this.posthog!.identify(id, properties)
|
||||
}
|
||||
|
||||
identifyUser(userId) {
|
||||
identifyUser(userId: string) {
|
||||
this.identify(IdentityType.USER, userId)
|
||||
}
|
||||
|
||||
|
@ -54,23 +46,23 @@ class Analytics {
|
|||
this.identify(IdentityType.TENANT, distinctId)
|
||||
}
|
||||
|
||||
identifyAccount(account) {
|
||||
identifyAccount(account: Account) {
|
||||
const distinctId = account.accountId
|
||||
const hosting = account.hosting
|
||||
this.identify(IdentityType.ACCOUNT, distinctId, hosting)
|
||||
}
|
||||
|
||||
captureEvent(eventName, properties) {
|
||||
captureEvent(event: Event, properties: any) {
|
||||
if (!this.isEnabled) return
|
||||
// TODO: get the user id from context
|
||||
const userId = "TESTING_USER_ID"
|
||||
this.posthog.capture(userId, eventName, properties)
|
||||
this.posthog!.capture(userId, event, properties)
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
if (!this.isEnabled) return
|
||||
this.posthog.shutdown()
|
||||
this.posthog!.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analytics
|
||||
export default Analytics
|
|
@ -0,0 +1,27 @@
|
|||
import PostHog from "posthog-node"
|
||||
import { Event } from "@budibase/types"
|
||||
|
||||
class PosthogClient {
|
||||
posthog: PostHog
|
||||
|
||||
constructor(token: string | undefined) {
|
||||
if (!token) {
|
||||
throw new Error("Posthog token is not defined")
|
||||
}
|
||||
this.posthog = new PostHog(token)
|
||||
}
|
||||
|
||||
identify(distinctId: string, properties: any) {
|
||||
this.posthog.identify({ distinctId, properties })
|
||||
}
|
||||
|
||||
capture(userId: string, event: Event, properties: any) {
|
||||
this.posthog.capture({ distinctId: userId, event, properties })
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.posthog.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
export default PosthogClient
|
|
@ -1,4 +0,0 @@
|
|||
const Analytics = require("./analytics")
|
||||
|
||||
const analytics = new Analytics()
|
||||
module.exports = analytics
|
|
@ -0,0 +1,4 @@
|
|||
import Analytics from "./Analytics"
|
||||
|
||||
const analytics = new Analytics()
|
||||
export default analytics
|
|
@ -1,21 +0,0 @@
|
|||
const PostHog = require("posthog-node")
|
||||
|
||||
class PosthogClient {
|
||||
constructor(token) {
|
||||
this.posthog = new PostHog(token)
|
||||
}
|
||||
|
||||
identify(distinctId, properties) {
|
||||
this.posthog.identify({ distinctId, properties })
|
||||
}
|
||||
|
||||
capture(userId, event, properties) {
|
||||
this.posthog.capture({ distinctId: userId, event, properties })
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.posthog.shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PosthogClient
|
|
@ -1,16 +1,17 @@
|
|||
import { getTenantId } from "../context"
|
||||
import { captureEvent } from "../analytics"
|
||||
import analytics from "../analytics"
|
||||
import { Event } from "@budibase/types"
|
||||
|
||||
const logEvent = messsage => {
|
||||
const logEvent = (messsage: string) => {
|
||||
const tenantId = getTenantId()
|
||||
const userId = getTenantId() // TODO
|
||||
console.log(`[audit] [tenant=${tenantId}] [user=${userId}] ${messsage}`)
|
||||
}
|
||||
|
||||
export const processEvent = (event, properties) => {
|
||||
export const processEvent = (event: Event, properties: any) => {
|
||||
// logging
|
||||
logEvent(event)
|
||||
|
||||
// analytics
|
||||
captureEvent(event, properties)
|
||||
analytics.captureEvent(event, properties)
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
import { processEvent } from "../events"
|
||||
import { Events, Account } from "@budibase/types"
|
||||
import { Event, Account } from "@budibase/types"
|
||||
|
||||
export function created(account: Account) {
|
||||
const properties = {}
|
||||
processEvent(Events.ACCOUNT_CREATED, properties)
|
||||
processEvent(Event.ACCOUNT_CREATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(account: Account) {
|
||||
const properties = {}
|
||||
processEvent(Events.ACCOUNT_DELETED, properties)
|
||||
processEvent(Event.ACCOUNT_DELETED, properties)
|
||||
}
|
||||
|
||||
export function verified(account: Account) {
|
||||
const properties = {}
|
||||
processEvent(Events.ACCOUNT_VERIFIED, properties)
|
||||
processEvent(Event.ACCOUNT_VERIFIED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
App,
|
||||
AppCreatedEvent,
|
||||
AppUpdatedEvent,
|
||||
|
@ -17,57 +17,57 @@ import {
|
|||
|
||||
export function created(app: App) {
|
||||
const properties: AppCreatedEvent = {}
|
||||
processEvent(Events.APP_CREATED, properties)
|
||||
processEvent(Event.APP_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(app: App) {
|
||||
const properties: AppUpdatedEvent = {}
|
||||
processEvent(Events.APP_UPDATED, properties)
|
||||
processEvent(Event.APP_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(app: App) {
|
||||
const properties: AppDeletedEvent = {}
|
||||
processEvent(Events.APP_DELETED, properties)
|
||||
processEvent(Event.APP_DELETED, properties)
|
||||
}
|
||||
|
||||
export function published(app: App) {
|
||||
const properties: AppPublishedEvent = {}
|
||||
processEvent(Events.APP_PUBLISHED, properties)
|
||||
processEvent(Event.APP_PUBLISHED, properties)
|
||||
}
|
||||
|
||||
export function unpublished(app: App) {
|
||||
const properties: AppUnpublishedEvent = {}
|
||||
processEvent(Events.APP_UNPUBLISHED, properties)
|
||||
processEvent(Event.APP_UNPUBLISHED, properties)
|
||||
}
|
||||
|
||||
export function fileImported(app: App) {
|
||||
const properties: AppFileImportedEvent = {}
|
||||
processEvent(Events.APP_FILE_IMPORTED, properties)
|
||||
processEvent(Event.APP_FILE_IMPORTED, properties)
|
||||
}
|
||||
|
||||
export function templateImported(templateKey: string) {
|
||||
const properties: AppTemplateImportedEvent = {
|
||||
templateKey,
|
||||
}
|
||||
processEvent(Events.APP_TEMPLATE_IMPORTED, properties)
|
||||
processEvent(Event.APP_TEMPLATE_IMPORTED, properties)
|
||||
}
|
||||
|
||||
export function versionUpdated(app: App) {
|
||||
const properties: AppVersionUpdatedEvent = {}
|
||||
processEvent(Events.APP_VERSION_UPDATED, properties)
|
||||
processEvent(Event.APP_VERSION_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function versionReverted(app: App) {
|
||||
const properties: AppVersionRevertedEvent = {}
|
||||
processEvent(Events.APP_VERSION_REVERTED, properties)
|
||||
processEvent(Event.APP_VERSION_REVERTED, properties)
|
||||
}
|
||||
|
||||
export function reverted(app: App) {
|
||||
const properties: AppRevertedEvent = {}
|
||||
processEvent(Events.APP_REVERTED, properties)
|
||||
processEvent(Event.APP_REVERTED, properties)
|
||||
}
|
||||
|
||||
export function exported(app: App) {
|
||||
const properties: AppExportedEvent = {}
|
||||
processEvent(Events.APP_EXPORTED, properties)
|
||||
processEvent(Event.APP_EXPORTED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
LoginEvent,
|
||||
LoginSource,
|
||||
LogoutEvent,
|
||||
|
@ -15,38 +15,38 @@ export function login(source: LoginSource) {
|
|||
const properties: LoginEvent = {
|
||||
source,
|
||||
}
|
||||
processEvent(Events.AUTH_LOGIN, properties)
|
||||
processEvent(Event.AUTH_LOGIN, properties)
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
const properties: LogoutEvent = {}
|
||||
processEvent(Events.AUTH_LOGOUT, properties)
|
||||
processEvent(Event.AUTH_LOGOUT, properties)
|
||||
}
|
||||
|
||||
export function SSOCreated(type: SSOType) {
|
||||
const properties: SSOCreatedEvent = {
|
||||
type,
|
||||
}
|
||||
processEvent(Events.AUTH_SSO_CREATED, properties)
|
||||
processEvent(Event.AUTH_SSO_CREATED, properties)
|
||||
}
|
||||
|
||||
export function SSOUpdated(type: SSOType) {
|
||||
const properties: SSOUpdatedEvent = {
|
||||
type,
|
||||
}
|
||||
processEvent(Events.AUTH_SSO_UPDATED, properties)
|
||||
processEvent(Event.AUTH_SSO_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function SSOActivated(type: SSOType) {
|
||||
const properties: SSOActivatedEvent = {
|
||||
type,
|
||||
}
|
||||
processEvent(Events.AUTH_SSO_ACTIVATED, properties)
|
||||
processEvent(Event.AUTH_SSO_ACTIVATED, properties)
|
||||
}
|
||||
|
||||
export function SSODeactivated(type: SSOType) {
|
||||
const properties: SSODeactivatedEvent = {
|
||||
type,
|
||||
}
|
||||
processEvent(Events.AUTH_SSO_DEACTIVATED, properties)
|
||||
processEvent(Event.AUTH_SSO_DEACTIVATED, properties)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Automation,
|
||||
Events,
|
||||
Event,
|
||||
AutomationStep,
|
||||
AutomationTrigger,
|
||||
AutomationCreatedEvent,
|
||||
|
@ -14,17 +14,17 @@ import {
|
|||
|
||||
export function created(automation: Automation) {
|
||||
const properties: AutomationCreatedEvent = {}
|
||||
processEvent(Events.AUTOMATION_CREATED, properties)
|
||||
processEvent(Event.AUTOMATION_CREATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(automation: Automation) {
|
||||
const properties: AutomationDeletedEvent = {}
|
||||
processEvent(Events.AUTOMATION_DELETED, properties)
|
||||
processEvent(Event.AUTOMATION_DELETED, properties)
|
||||
}
|
||||
|
||||
export function tested(automation: Automation) {
|
||||
const properties: AutomationTestedEvent = {}
|
||||
processEvent(Events.AUTOMATION_TESTED, properties)
|
||||
processEvent(Event.AUTOMATION_TESTED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -35,12 +35,12 @@ export function tested(automation: Automation) {
|
|||
|
||||
export function stepCreated(automation: Automation, step: AutomationStep) {
|
||||
const properties: AutomationStepCreatedEvent = {}
|
||||
processEvent(Events.AUTOMATION_STEP_CREATED, properties)
|
||||
processEvent(Event.AUTOMATION_STEP_CREATED, properties)
|
||||
}
|
||||
|
||||
export function stepDeleted(automation: Automation, step: AutomationStep) {
|
||||
const properties: AutomationStepDeletedEvent = {}
|
||||
processEvent(Events.AUTOMATION_STEP_DELETED, properties)
|
||||
processEvent(Event.AUTOMATION_STEP_DELETED, properties)
|
||||
}
|
||||
|
||||
export function triggerUpdated(
|
||||
|
@ -48,5 +48,5 @@ export function triggerUpdated(
|
|||
trigger: AutomationTrigger
|
||||
) {
|
||||
const properties: AutomationTriggerUpdatedEvent = {}
|
||||
processEvent(Events.AUTOMATION_TRIGGER_UPDATED, properties)
|
||||
processEvent(Event.AUTOMATION_TRIGGER_UPDATED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
Datasource,
|
||||
DatasourceCreatedEvent,
|
||||
DatasourceUpdatedEvent,
|
||||
|
@ -9,15 +9,15 @@ import {
|
|||
|
||||
export function created(datasource: Datasource) {
|
||||
const properties: DatasourceCreatedEvent = {}
|
||||
processEvent(Events.DATASOURCE_CREATED, properties)
|
||||
processEvent(Event.DATASOURCE_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(datasource: Datasource) {
|
||||
const properties: DatasourceUpdatedEvent = {}
|
||||
processEvent(Events.DATASOURCE_UPDATED, properties)
|
||||
processEvent(Event.DATASOURCE_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(datasource: Datasource) {
|
||||
const properties: DatasourceDeletedEvent = {}
|
||||
processEvent(Events.DATASOURCE_DELETED, properties)
|
||||
processEvent(Event.DATASOURCE_DELETED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
SMTPConfig,
|
||||
SMTPCreatedEvent,
|
||||
SMTPUpdatedEvent,
|
||||
|
@ -8,10 +8,10 @@ import {
|
|||
|
||||
export function SMTPCreated(config: SMTPConfig) {
|
||||
const properties: SMTPCreatedEvent = {}
|
||||
processEvent(Events.EMAIL_SMTP_CREATED, properties)
|
||||
processEvent(Event.EMAIL_SMTP_CREATED, properties)
|
||||
}
|
||||
|
||||
export function SMTPUpdated(config: SMTPConfig) {
|
||||
const properties: SMTPUpdatedEvent = {}
|
||||
processEvent(Events.EMAIL_SMTP_UPDATED, properties)
|
||||
processEvent(Event.EMAIL_SMTP_UPDATED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
Layout,
|
||||
LayoutCreatedEvent,
|
||||
LayoutDeletedEvent,
|
||||
|
@ -8,10 +8,10 @@ import {
|
|||
|
||||
export function created(layout: Layout) {
|
||||
const properties: LayoutCreatedEvent = {}
|
||||
processEvent(Events.LAYOUT_CREATED, properties)
|
||||
processEvent(Event.LAYOUT_CREATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(layout: Layout) {
|
||||
const properties: LayoutDeletedEvent = {}
|
||||
processEvent(Events.LAYOUT_DELETED, properties)
|
||||
processEvent(Event.LAYOUT_DELETED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
License,
|
||||
LicenseActivatedEvent,
|
||||
LicenseDowngradedEvent,
|
||||
|
@ -12,25 +12,25 @@ import {
|
|||
// TODO
|
||||
export function updgraded(license: License) {
|
||||
const properties: LicenseUpgradedEvent = {}
|
||||
processEvent(Events.LICENSE_UPGRADED, properties)
|
||||
processEvent(Event.LICENSE_UPGRADED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
export function downgraded(license: License) {
|
||||
const properties: LicenseDowngradedEvent = {}
|
||||
processEvent(Events.LICENSE_DOWNGRADED, properties)
|
||||
processEvent(Event.LICENSE_DOWNGRADED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
export function updated(license: License) {
|
||||
const properties: LicenseUpdatedEvent = {}
|
||||
processEvent(Events.LICENSE_UPDATED, properties)
|
||||
processEvent(Event.LICENSE_UPDATED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
export function activated(license: License) {
|
||||
const properties: LicenseActivatedEvent = {}
|
||||
processEvent(Events.LICENSE_ACTIVATED, properties)
|
||||
processEvent(Event.LICENSE_ACTIVATED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -39,5 +39,5 @@ export function quotaExceeded(quotaName: string, value: number) {
|
|||
name: quotaName,
|
||||
value,
|
||||
}
|
||||
processEvent(Events.LICENSE_QUOTA_EXCEEDED, properties)
|
||||
processEvent(Event.LICENSE_QUOTA_EXCEEDED, properties)
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
import { processEvent } from "../events"
|
||||
import { Events, VersionCheckedEvent } from "@budibase/types"
|
||||
import { Event, VersionCheckedEvent } from "@budibase/types"
|
||||
|
||||
export function nameUpdated() {
|
||||
const properties = {}
|
||||
processEvent(Events.ORG_NAME_UPDATED, properties)
|
||||
processEvent(Event.ORG_NAME_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function logoUpdated() {
|
||||
const properties = {}
|
||||
processEvent(Events.ORG_LOGO_UPDATED, properties)
|
||||
processEvent(Event.ORG_LOGO_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function platformURLUpdated() {
|
||||
const properties = {}
|
||||
processEvent(Events.ORG_PLATFORM_URL_UPDATED, properties)
|
||||
processEvent(Event.ORG_PLATFORM_URL_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function versionChecked(version: number) {
|
||||
const properties: VersionCheckedEvent = {
|
||||
version,
|
||||
}
|
||||
processEvent(Events.UPDATE_VERSION_CHECKED, properties)
|
||||
processEvent(Event.UPDATE_VERSION_CHECKED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
export function analyticsOptOut() {
|
||||
const properties = {}
|
||||
processEvent(Events.ANALYTICS_OPT_OUT, properties)
|
||||
processEvent(Event.ANALYTICS_OPT_OUT, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
Datasource,
|
||||
Query,
|
||||
QueryCreatedEvent,
|
||||
|
@ -14,17 +14,17 @@ import {
|
|||
|
||||
export const created = (datasource: Datasource, query: Query) => {
|
||||
const properties: QueryCreatedEvent = {}
|
||||
processEvent(Events.QUERY_CREATED, properties)
|
||||
processEvent(Event.QUERY_CREATED, properties)
|
||||
}
|
||||
|
||||
export const updated = (datasource: Datasource, query: Query) => {
|
||||
const properties: QueryUpdatedEvent = {}
|
||||
processEvent(Events.QUERY_UPDATED, properties)
|
||||
processEvent(Event.QUERY_UPDATED, properties)
|
||||
}
|
||||
|
||||
export const deleted = (datasource: Datasource, query: Query) => {
|
||||
const properties: QueryDeletedEvent = {}
|
||||
processEvent(Events.QUERY_DELETED, properties)
|
||||
processEvent(Event.QUERY_DELETED, properties)
|
||||
}
|
||||
|
||||
export const imported = (
|
||||
|
@ -33,7 +33,7 @@ export const imported = (
|
|||
count: any
|
||||
) => {
|
||||
const properties: QueryImportedEvent = {}
|
||||
processEvent(Events.QUERY_IMPORT, properties)
|
||||
processEvent(Event.QUERY_IMPORT, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
@ -44,5 +44,5 @@ export const imported = (
|
|||
|
||||
export const previewed = (datasource: Datasource) => {
|
||||
const properties: QueryPreviewedEvent = {}
|
||||
processEvent(Events.QUERY_PREVIEWED, properties)
|
||||
processEvent(Event.QUERY_PREVIEWED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
Role,
|
||||
RoleAssignedEvent,
|
||||
RoleCreatedEvent,
|
||||
|
@ -14,25 +14,25 @@ import {
|
|||
|
||||
export function created(role: Role) {
|
||||
const properties: RoleCreatedEvent = {}
|
||||
processEvent(Events.ROLE_CREATED, properties)
|
||||
processEvent(Event.ROLE_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(role: Role) {
|
||||
const properties: RoleUpdatedEvent = {}
|
||||
processEvent(Events.ROLE_UPDATED, properties)
|
||||
processEvent(Event.ROLE_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(role: Role) {
|
||||
const properties: RoleDeletedEvent = {}
|
||||
processEvent(Events.ROLE_DELETED, properties)
|
||||
processEvent(Event.ROLE_DELETED, properties)
|
||||
}
|
||||
|
||||
export function assigned(user: User, role: Role) {
|
||||
const properties: RoleAssignedEvent = {}
|
||||
processEvent(Events.ROLE_ASSIGNED, properties)
|
||||
processEvent(Event.ROLE_ASSIGNED, properties)
|
||||
}
|
||||
|
||||
export function unassigned(user: User, role: Role) {
|
||||
const properties: RoleUnassignedEvent = {}
|
||||
processEvent(Events.ROLE_UNASSIGNED, properties)
|
||||
processEvent(Event.ROLE_UNASSIGNED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
RowImportedEvent,
|
||||
RowImportFormat,
|
||||
Table,
|
||||
|
@ -19,5 +19,5 @@ export const imported = (
|
|||
count: number
|
||||
) => {
|
||||
const properties: RowImportedEvent = {}
|
||||
processEvent(Events.ROW_IMPORT, properties)
|
||||
processEvent(Event.ROW_IMPORT, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
Screen,
|
||||
ScreenCreatedEvent,
|
||||
ScreenDeletedEvent,
|
||||
|
@ -8,10 +8,10 @@ import {
|
|||
|
||||
export function created(screen: Screen) {
|
||||
const properties: ScreenCreatedEvent = {}
|
||||
processEvent(Events.SCREEN_CREATED, properties)
|
||||
processEvent(Event.SCREEN_CREATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(screen: Screen) {
|
||||
const properties: ScreenDeletedEvent = {}
|
||||
processEvent(Events.SCREEN_DELETED, properties)
|
||||
processEvent(Event.SCREEN_DELETED, properties)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { processEvent } from "../events"
|
|||
import {
|
||||
App,
|
||||
BuilderServedEvent,
|
||||
Events,
|
||||
Event,
|
||||
AppPreviewServedEvent,
|
||||
AppServedEvent,
|
||||
} from "@budibase/types"
|
||||
|
@ -11,15 +11,15 @@ import {
|
|||
|
||||
export function servedBuilder(version: number) {
|
||||
const properties: BuilderServedEvent = {}
|
||||
processEvent(Events.SERVED_BUILDER, properties)
|
||||
processEvent(Event.SERVED_BUILDER, properties)
|
||||
}
|
||||
|
||||
export function servedApp(app: App) {
|
||||
const properties: AppServedEvent = {}
|
||||
processEvent(Events.SERVED_APP, properties)
|
||||
processEvent(Event.SERVED_APP, properties)
|
||||
}
|
||||
|
||||
export function servedAppPreview(app: App) {
|
||||
const properties: AppPreviewServedEvent = {}
|
||||
processEvent(Events.SERVED_APP_PREVIEW, properties)
|
||||
processEvent(Event.SERVED_APP_PREVIEW, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
TableExportFormat,
|
||||
TableImportFormat,
|
||||
Table,
|
||||
|
@ -15,31 +15,31 @@ import {
|
|||
|
||||
export function created(table: Table) {
|
||||
const properties: TableCreatedEvent = {}
|
||||
processEvent(Events.TABLE_CREATED, properties)
|
||||
processEvent(Event.TABLE_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(table: Table) {
|
||||
const properties: TableUpdatedEvent = {}
|
||||
processEvent(Events.TABLE_UPDATED, properties)
|
||||
processEvent(Event.TABLE_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(table: Table) {
|
||||
const properties: TableDeletedEvent = {}
|
||||
processEvent(Events.TABLE_DELETED, properties)
|
||||
processEvent(Event.TABLE_DELETED, properties)
|
||||
}
|
||||
|
||||
export function exported(table: Table, format: TableExportFormat) {
|
||||
const properties: TableExportedEvent = {}
|
||||
processEvent(Events.TABLE_EXPORTED, properties)
|
||||
processEvent(Event.TABLE_EXPORTED, properties)
|
||||
}
|
||||
|
||||
export function imported(table: Table, format: TableImportFormat) {
|
||||
const properties: TableImportedEvent = {}
|
||||
processEvent(Events.TABLE_IMPORTED, properties)
|
||||
processEvent(Event.TABLE_IMPORTED, properties)
|
||||
}
|
||||
|
||||
// TODO
|
||||
export function permissionUpdated() {
|
||||
const properties = {}
|
||||
processEvent(Events.TABLE_PERMISSION_UPDATED, properties)
|
||||
processEvent(Event.TABLE_PERMISSION_UPDATED, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
User,
|
||||
UserCreatedEvent,
|
||||
UserDeletedEvent,
|
||||
|
@ -19,71 +19,71 @@ import {
|
|||
|
||||
export function created(user: User) {
|
||||
const properties: UserCreatedEvent = {}
|
||||
processEvent(Events.USER_CREATED, properties)
|
||||
processEvent(Event.USER_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(user: User) {
|
||||
const properties: UserUpdatedEvent = {}
|
||||
processEvent(Events.USER_UPDATED, properties)
|
||||
processEvent(Event.USER_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted(user: User) {
|
||||
const properties: UserDeletedEvent = {}
|
||||
processEvent(Events.USER_DELETED, properties)
|
||||
processEvent(Event.USER_DELETED, properties)
|
||||
}
|
||||
|
||||
// PERMISSIONS
|
||||
|
||||
export function permissionAdminAssigned(user: User) {
|
||||
const properties: UserPermissionAssignedEvent = {}
|
||||
processEvent(Events.USER_PERMISSION_ADMIN_ASSIGNED, properties)
|
||||
processEvent(Event.USER_PERMISSION_ADMIN_ASSIGNED, properties)
|
||||
}
|
||||
|
||||
export function permissionAdminRemoved(user: User) {
|
||||
const properties: UserPermissionRemovedEvent = {}
|
||||
processEvent(Events.USER_PERMISSION_ADMIN_REMOVED, properties)
|
||||
processEvent(Event.USER_PERMISSION_ADMIN_REMOVED, properties)
|
||||
}
|
||||
|
||||
export function permissionBuilderAssigned(user: User) {
|
||||
const properties: UserPermissionAssignedEvent = {}
|
||||
processEvent(Events.USER_PERMISSION_BUILDER_ASSIGNED, properties)
|
||||
processEvent(Event.USER_PERMISSION_BUILDER_ASSIGNED, properties)
|
||||
}
|
||||
|
||||
export function permissionBuilderRemoved(user: User) {
|
||||
const properties: UserPermissionRemovedEvent = {}
|
||||
processEvent(Events.USER_PERMISSION_BUILDER_REMOVED, properties)
|
||||
processEvent(Event.USER_PERMISSION_BUILDER_REMOVED, properties)
|
||||
}
|
||||
|
||||
// INVITE
|
||||
|
||||
export function invited(userInfo: any) {
|
||||
const properties: UserInvitedEvent = {}
|
||||
processEvent(Events.USER_INVITED, properties)
|
||||
processEvent(Event.USER_INVITED, properties)
|
||||
}
|
||||
|
||||
export function inviteAccepted(user: User) {
|
||||
const properties: UserInviteAcceptedEvent = {}
|
||||
processEvent(Events.USER_INVITED_ACCEPTED, properties)
|
||||
processEvent(Event.USER_INVITED_ACCEPTED, properties)
|
||||
}
|
||||
|
||||
// PASSWORD
|
||||
|
||||
export function passwordForceReset(user: User) {
|
||||
const properties: UserPasswordForceResetEvent = {}
|
||||
processEvent(Events.USER_PASSWORD_FORCE_RESET, properties)
|
||||
processEvent(Event.USER_PASSWORD_FORCE_RESET, properties)
|
||||
}
|
||||
|
||||
export function passwordUpdated(user: User) {
|
||||
const properties: UserPasswordUpdatedEvent = {}
|
||||
processEvent(Events.USER_PASSWORD_UPDATED, properties)
|
||||
processEvent(Event.USER_PASSWORD_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function passwordResetRequested(user: User) {
|
||||
const properties: UserPasswordResetRequestedEvent = {}
|
||||
processEvent(Events.USER_PASSWORD_RESET_REQUESTED, properties)
|
||||
processEvent(Event.USER_PASSWORD_RESET_REQUESTED, properties)
|
||||
}
|
||||
|
||||
export function passwordReset(user: User) {
|
||||
const properties: UserPasswordResetEvent = {}
|
||||
processEvent(Events.USER_PASSWORD_RESET, properties)
|
||||
processEvent(Event.USER_PASSWORD_RESET, properties)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { processEvent } from "../events"
|
||||
import {
|
||||
Events,
|
||||
Event,
|
||||
ViewCalculationCreatedEvent,
|
||||
ViewCalculationDeletedEvent,
|
||||
ViewCalculationUpdatedEvent,
|
||||
|
@ -20,50 +20,50 @@ import {
|
|||
|
||||
export function created(view: View) {
|
||||
const properties: ViewCreatedEvent = {}
|
||||
processEvent(Events.VIEW_CREATED, properties)
|
||||
processEvent(Event.VIEW_CREATED, properties)
|
||||
}
|
||||
|
||||
export function updated(view: View) {
|
||||
const properties: ViewUpdatedEvent = {}
|
||||
processEvent(Events.VIEW_UPDATED, properties)
|
||||
processEvent(Event.VIEW_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function deleted() {
|
||||
const properties: ViewDeletedEvent = {}
|
||||
processEvent(Events.VIEW_DELETED, properties)
|
||||
processEvent(Event.VIEW_DELETED, properties)
|
||||
}
|
||||
|
||||
export function exported(table: Table, format: TableExportFormat) {
|
||||
const properties: ViewExportedEvent = {}
|
||||
processEvent(Events.VIEW_EXPORTED, properties)
|
||||
processEvent(Event.VIEW_EXPORTED, properties)
|
||||
}
|
||||
|
||||
export function filterCreated() {
|
||||
const properties: ViewFilterCreatedEvent = {}
|
||||
processEvent(Events.VIEW_FILTER_CREATED, properties)
|
||||
processEvent(Event.VIEW_FILTER_CREATED, properties)
|
||||
}
|
||||
|
||||
export function filterUpdated() {
|
||||
const properties: ViewFilterUpdatedEvent = {}
|
||||
processEvent(Events.VIEW_FILTER_UPDATED, properties)
|
||||
processEvent(Event.VIEW_FILTER_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function filterDeleted() {
|
||||
const properties: ViewFilterDeletedEvent = {}
|
||||
processEvent(Events.VIEW_FILTER_DELETED, properties)
|
||||
processEvent(Event.VIEW_FILTER_DELETED, properties)
|
||||
}
|
||||
|
||||
export function calculationCreated() {
|
||||
const properties: ViewCalculationCreatedEvent = {}
|
||||
processEvent(Events.VIEW_CALCULATION_CREATED, properties)
|
||||
processEvent(Event.VIEW_CALCULATION_CREATED, properties)
|
||||
}
|
||||
|
||||
export function calculationUpdated() {
|
||||
const properties: ViewCalculationUpdatedEvent = {}
|
||||
processEvent(Events.VIEW_CALCULATION_UPDATED, properties)
|
||||
processEvent(Event.VIEW_CALCULATION_UPDATED, properties)
|
||||
}
|
||||
|
||||
export function calculationDeleted() {
|
||||
const properties: ViewCalculationDeletedEvent = {}
|
||||
processEvent(Events.VIEW_CALCULATION_DELETED, properties)
|
||||
processEvent(Event.VIEW_CALCULATION_DELETED, properties)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,23 @@ import db from "./db"
|
|||
import errors from "./errors"
|
||||
import * as events from "./events"
|
||||
import * as migrations from "./migrations"
|
||||
import * as users from "./users"
|
||||
import env from "./environment"
|
||||
import accounts from "./cloud/accounts"
|
||||
import tenancy from "./tenancy"
|
||||
import featureFlags from "./featureFlags"
|
||||
import analytics from "./analytics"
|
||||
import sessions from "./security/sessions"
|
||||
import deprovisioning from "./context/deprovision"
|
||||
|
||||
// outer packages
|
||||
import dbPkg from "../db"
|
||||
import redis from "../redis"
|
||||
import objectStore from "../objectStore"
|
||||
import utils from "../utils"
|
||||
import cache from "../cache"
|
||||
import auth from "../auth"
|
||||
import constants from "../constants"
|
||||
|
||||
export = {
|
||||
init(opts: any = {}) {
|
||||
|
@ -9,24 +26,24 @@ export = {
|
|||
},
|
||||
// some default exports from the library, however these ideally shouldn't
|
||||
// be used, instead the syntax require("@budibase/backend-core/db") should be used
|
||||
StaticDatabases: require("./db/utils").StaticDatabases,
|
||||
db: require("../db"),
|
||||
redis: require("../redis"),
|
||||
objectStore: require("../objectStore"),
|
||||
utils: require("../utils"),
|
||||
users: require("./users"),
|
||||
cache: require("../cache"),
|
||||
auth: require("../auth"),
|
||||
constants: require("../constants"),
|
||||
StaticDatabases: dbPkg.StaticDatabases,
|
||||
db: dbPkg,
|
||||
redis,
|
||||
objectStore,
|
||||
utils,
|
||||
users,
|
||||
cache,
|
||||
auth,
|
||||
constants,
|
||||
migrations,
|
||||
errors,
|
||||
...errors.errors,
|
||||
env: require("./environment"),
|
||||
accounts: require("./cloud/accounts"),
|
||||
tenancy: require("./tenancy"),
|
||||
featureFlags: require("./featureFlags"),
|
||||
env,
|
||||
accounts,
|
||||
tenancy,
|
||||
featureFlags,
|
||||
events,
|
||||
analytics: require("./analytics"),
|
||||
sessions: require("./security/sessions"),
|
||||
deprovisioning: require("./context/deprovision"),
|
||||
analytics,
|
||||
sessions,
|
||||
deprovisioning,
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ process.on("SIGTERM", () => {
|
|||
|
||||
// run migrations on startup if not done via http
|
||||
// not recommended in a clustered environment
|
||||
if (!env.HTTP_MIGRATIONS) {
|
||||
if (!env.HTTP_MIGRATIONS && !env.isTest()) {
|
||||
migrations.migrate().catch(err => {
|
||||
console.error("Error performing migrations. Exiting.\n", err)
|
||||
shutdown()
|
||||
|
|
|
@ -8,4 +8,6 @@ import * as app from "./app/app"
|
|||
* Backfill app events.
|
||||
*/
|
||||
|
||||
export const run = async (db: any) => {}
|
||||
export const run = async (appDb: any) => {
|
||||
await app.backfill(appDb)
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
export const backfillAppCreated = () => {}
|
||||
import { events, db } from "@budibase/backend-core"
|
||||
import { App } from "@budibase/types"
|
||||
|
||||
export const backfillAppPublished = () => {}
|
||||
|
||||
// APP_CREATED = "app:created",
|
||||
// APP_PUBLISHED = "app:published",
|
||||
|
||||
// Maybe
|
||||
// APP_TEMPLATE_IMPORTED = "app:template:imported",
|
||||
// APP_FILE_IMPORTED = "app:file:imported",
|
||||
export const backfill = async (appDb: any) => {
|
||||
const app: App = await appDb.get(db.DocumentTypes.APP_METADATA)
|
||||
if (db.isDevAppID(app.appId)) {
|
||||
events.app.created(app)
|
||||
}
|
||||
if (db.isProdAppID(app.appId)) {
|
||||
events.app.published(app)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import * as syncPublishedApps from "../usageQuotas/syncPublishedApps"
|
||||
|
||||
/**
|
||||
* Date:
|
||||
* May 2022
|
|
@ -0,0 +1,2 @@
|
|||
export * as app from "./app"
|
||||
export * as global from "./global"
|
|
@ -6,6 +6,7 @@ import * as quota1 from "./functions/quotas1"
|
|||
import * as appUrls from "./functions/appUrls"
|
||||
import * as developerQuota from "./functions/developerQuota"
|
||||
import * as publishedAppsQuota from "./functions/publishedAppsQuota"
|
||||
import * as backfill from "./functions/backfill"
|
||||
|
||||
export interface Migration {
|
||||
type: string
|
||||
|
@ -59,13 +60,14 @@ export const MIGRATIONS: Migration[] = [
|
|||
},
|
||||
{
|
||||
type: migrations.MIGRATION_TYPES.GLOBAL,
|
||||
name: "event_backfill",
|
||||
fn: publishedAppsQuota.run,
|
||||
name: "event_global_backfill",
|
||||
fn: backfill.global.run,
|
||||
},
|
||||
{
|
||||
type: migrations.MIGRATION_TYPES.APP,
|
||||
name: "event_app_backfill",
|
||||
fn: publishedAppsQuota.run,
|
||||
opts: { all: true },
|
||||
fn: backfill.app.run,
|
||||
},
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export enum Hosting {
|
||||
CLOUD = "cloud",
|
||||
SELF = "self",
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export * from "./hosting"
|
|
@ -1 +1,6 @@
|
|||
export interface Account {}
|
||||
import { Hosting } from "../../core"
|
||||
|
||||
export interface Account {
|
||||
accountId: string
|
||||
hosting: Hosting
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export enum Events {
|
||||
export enum Event {
|
||||
// USER
|
||||
USER_CREATED = "user:created",
|
||||
USER_UPDATED = "user:updated",
|
||||
|
@ -140,6 +140,12 @@ export enum Events {
|
|||
ACCOUNT_VERIFIED = "account:verified",
|
||||
}
|
||||
|
||||
export enum IdentityType {
|
||||
TENANT = "tenant",
|
||||
USER = "user",
|
||||
ACCOUNT = "account",
|
||||
}
|
||||
|
||||
export type RowImportFormat = "csv"
|
||||
export type TableExportFormat = "json" | "csv"
|
||||
export type TableImportFormat = "csv"
|
|
@ -3,7 +3,7 @@ export * from "./auth"
|
|||
export * from "./automation"
|
||||
export * from "./config"
|
||||
export * from "./datasource"
|
||||
export * from "./events"
|
||||
export * from "./event"
|
||||
export * from "./layout"
|
||||
export * from "./license"
|
||||
export * from "./org"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./documents"
|
||||
export * from "./events"
|
||||
export * from "./licensing"
|
||||
export * from "./core"
|
||||
|
|
Loading…
Reference in New Issue