mirror of https://github.com/Budibase/budibase.git
39 changed files with 237 additions and 198 deletions
@ -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 { 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 tenantId = getTenantId() |
||||
const userId = getTenantId() // TODO
|
const userId = getTenantId() // TODO
|
||||
console.log(`[audit] [tenant=${tenantId}] [user=${userId}] ${messsage}`) |
console.log(`[audit] [tenant=${tenantId}] [user=${userId}] ${messsage}`) |
||||
} |
} |
||||
|
|
||||
export const processEvent = (event, properties) => { |
export const processEvent = (event: Event, properties: any) => { |
||||
// logging
|
// logging
|
||||
logEvent(event) |
logEvent(event) |
||||
|
|
||||
// analytics
|
// analytics
|
||||
captureEvent(event, properties) |
analytics.captureEvent(event, properties) |
||||
} |
} |
||||
@ -1,17 +1,17 @@ |
|||||
import { processEvent } from "../events" |
import { processEvent } from "../events" |
||||
import { Events, Account } from "@budibase/types" |
import { Event, Account } from "@budibase/types" |
||||
|
|
||||
export function created(account: Account) { |
export function created(account: Account) { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ACCOUNT_CREATED, properties) |
processEvent(Event.ACCOUNT_CREATED, properties) |
||||
} |
} |
||||
|
|
||||
export function deleted(account: Account) { |
export function deleted(account: Account) { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ACCOUNT_DELETED, properties) |
processEvent(Event.ACCOUNT_DELETED, properties) |
||||
} |
} |
||||
|
|
||||
export function verified(account: Account) { |
export function verified(account: Account) { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ACCOUNT_VERIFIED, properties) |
processEvent(Event.ACCOUNT_VERIFIED, properties) |
||||
} |
} |
||||
|
|||||
@ -1,30 +1,30 @@ |
|||||
import { processEvent } from "../events" |
import { processEvent } from "../events" |
||||
import { Events, VersionCheckedEvent } from "@budibase/types" |
import { Event, VersionCheckedEvent } from "@budibase/types" |
||||
|
|
||||
export function nameUpdated() { |
export function nameUpdated() { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ORG_NAME_UPDATED, properties) |
processEvent(Event.ORG_NAME_UPDATED, properties) |
||||
} |
} |
||||
|
|
||||
export function logoUpdated() { |
export function logoUpdated() { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ORG_LOGO_UPDATED, properties) |
processEvent(Event.ORG_LOGO_UPDATED, properties) |
||||
} |
} |
||||
|
|
||||
export function platformURLUpdated() { |
export function platformURLUpdated() { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ORG_PLATFORM_URL_UPDATED, properties) |
processEvent(Event.ORG_PLATFORM_URL_UPDATED, properties) |
||||
} |
} |
||||
|
|
||||
export function versionChecked(version: number) { |
export function versionChecked(version: number) { |
||||
const properties: VersionCheckedEvent = { |
const properties: VersionCheckedEvent = { |
||||
version, |
version, |
||||
} |
} |
||||
processEvent(Events.UPDATE_VERSION_CHECKED, properties) |
processEvent(Event.UPDATE_VERSION_CHECKED, properties) |
||||
} |
} |
||||
|
|
||||
// TODO
|
// TODO
|
||||
export function analyticsOptOut() { |
export function analyticsOptOut() { |
||||
const properties = {} |
const properties = {} |
||||
processEvent(Events.ANALYTICS_OPT_OUT, properties) |
processEvent(Event.ANALYTICS_OPT_OUT, properties) |
||||
} |
} |
||||
|
|||||
@ -1,10 +1,12 @@ |
|||||
export const backfillAppCreated = () => {} |
import { events, db } from "@budibase/backend-core" |
||||
|
import { App } from "@budibase/types" |
||||
|
|
||||
export const backfillAppPublished = () => {} |
export const backfill = async (appDb: any) => { |
||||
|
const app: App = await appDb.get(db.DocumentTypes.APP_METADATA) |
||||
// APP_CREATED = "app:created",
|
if (db.isDevAppID(app.appId)) { |
||||
// APP_PUBLISHED = "app:published",
|
events.app.created(app) |
||||
|
} |
||||
// Maybe
|
if (db.isProdAppID(app.appId)) { |
||||
// APP_TEMPLATE_IMPORTED = "app:template:imported",
|
events.app.published(app) |
||||
// APP_FILE_IMPORTED = "app:file:imported",
|
} |
||||
|
} |
||||
|
|||||
@ -1,5 +1,3 @@ |
|||||
import * as syncPublishedApps from "../usageQuotas/syncPublishedApps" |
|
||||
|
|
||||
/** |
/** |
||||
* Date: |
* Date: |
||||
* May 2022 |
* May 2022 |
||||
@ -0,0 +1,2 @@ |
|||||
|
export * as app from "./app" |
||||
|
export * as global from "./global" |
||||
@ -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,3 +1,4 @@ |
|||||
export * from "./documents" |
export * from "./documents" |
||||
export * from "./events" |
export * from "./events" |
||||
export * from "./licensing" |
export * from "./licensing" |
||||
|
export * from "./core" |
||||
|
|||||
Loading…
Reference in new issue