Add timezone to served events
This commit is contained in:
parent
500e697974
commit
54df92a8c3
6 changed files with 29 additions and 14 deletions
|
@ -7,22 +7,26 @@ import {
|
||||||
AppServedEvent,
|
AppServedEvent,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
export async function servedBuilder() {
|
export async function servedBuilder(timezone: string) {
|
||||||
const properties: BuilderServedEvent = {}
|
const properties: BuilderServedEvent = {
|
||||||
|
timezone,
|
||||||
|
}
|
||||||
await publishEvent(Event.SERVED_BUILDER, properties)
|
await publishEvent(Event.SERVED_BUILDER, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function servedApp(app: App) {
|
export async function servedApp(app: App, timezone: string) {
|
||||||
const properties: AppServedEvent = {
|
const properties: AppServedEvent = {
|
||||||
appVersion: app.version,
|
appVersion: app.version,
|
||||||
|
timezone,
|
||||||
}
|
}
|
||||||
await publishEvent(Event.SERVED_APP, properties)
|
await publishEvent(Event.SERVED_APP, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function servedAppPreview(app: App) {
|
export async function servedAppPreview(app: App, timezone: string) {
|
||||||
const properties: AppPreviewServedEvent = {
|
const properties: AppPreviewServedEvent = {
|
||||||
appId: app.appId,
|
appId: app.appId,
|
||||||
appVersion: app.version,
|
appVersion: app.version,
|
||||||
|
timezone,
|
||||||
}
|
}
|
||||||
await publishEvent(Event.SERVED_APP_PREVIEW, properties)
|
await publishEvent(Event.SERVED_APP_PREVIEW, properties)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,10 @@ export const buildAnalyticsEndpoints = API => ({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
analyticsPing: async ({ source }) => {
|
analyticsPing: async ({ source }) => {
|
||||||
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: "/api/bbtel/ping",
|
url: "/api/bbtel/ping",
|
||||||
body: { source },
|
body: { source, timezone },
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,14 +19,14 @@ export const ping = async (ctx: any) => {
|
||||||
let appId = context.getAppId()
|
let appId = context.getAppId()
|
||||||
|
|
||||||
if (isDevAppID(appId)) {
|
if (isDevAppID(appId)) {
|
||||||
await events.serve.servedAppPreview(appInfo)
|
await events.serve.servedAppPreview(appInfo, body.timezone)
|
||||||
} else {
|
} else {
|
||||||
await events.serve.servedApp(appInfo)
|
await events.serve.servedApp(appInfo, body.timezone)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case PingSource.BUILDER: {
|
case PingSource.BUILDER: {
|
||||||
await events.serve.servedBuilder()
|
await events.serve.servedBuilder(body.timezone)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ describe("/static", () => {
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let app
|
let app
|
||||||
|
|
||||||
|
const timezone = "Europe/London"
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -17,22 +19,25 @@ describe("/static", () => {
|
||||||
it("should ping from builder", async () => {
|
it("should ping from builder", async () => {
|
||||||
await request
|
await request
|
||||||
.post("/api/bbtel/ping")
|
.post("/api/bbtel/ping")
|
||||||
.send({source: "builder"})
|
.send({source: "builder", timezone})
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(events.serve.servedBuilder).toBeCalledTimes(1)
|
expect(events.serve.servedBuilder).toBeCalledTimes(1)
|
||||||
|
expect(events.serve.servedBuilder).toBeCalledWith(timezone)
|
||||||
|
expect(events.serve.servedApp).not.toBeCalled()
|
||||||
|
expect(events.serve.servedAppPreview).not.toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should ping from app preview", async () => {
|
it("should ping from app preview", async () => {
|
||||||
await request
|
await request
|
||||||
.post("/api/bbtel/ping")
|
.post("/api/bbtel/ping")
|
||||||
.send({source: "app"})
|
.send({source: "app", timezone})
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(events.serve.servedAppPreview).toBeCalledTimes(1)
|
expect(events.serve.servedAppPreview).toBeCalledTimes(1)
|
||||||
expect(events.serve.servedAppPreview).toBeCalledWith(config.getApp())
|
expect(events.serve.servedAppPreview).toBeCalledWith(config.getApp(), timezone)
|
||||||
expect(events.serve.servedApp).not.toBeCalled()
|
expect(events.serve.servedApp).not.toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -42,12 +47,12 @@ describe("/static", () => {
|
||||||
|
|
||||||
await request
|
await request
|
||||||
.post("/api/bbtel/ping")
|
.post("/api/bbtel/ping")
|
||||||
.send({source: "app"})
|
.send({source: "app", timezone})
|
||||||
.set(headers)
|
.set(headers)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(events.serve.servedApp).toBeCalledTimes(1)
|
expect(events.serve.servedApp).toBeCalledTimes(1)
|
||||||
expect(events.serve.servedApp).toBeCalledWith(config.getProdApp())
|
expect(events.serve.servedApp).toBeCalledWith(config.getProdApp(), timezone)
|
||||||
expect(events.serve.servedAppPreview).not.toBeCalled()
|
expect(events.serve.servedAppPreview).not.toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,4 +5,5 @@ export enum PingSource {
|
||||||
|
|
||||||
export interface AnalyticsPingRequest {
|
export interface AnalyticsPingRequest {
|
||||||
source: PingSource
|
source: PingSource
|
||||||
|
timezone: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
import { BaseEvent } from "./event"
|
import { BaseEvent } from "./event"
|
||||||
|
|
||||||
export interface BuilderServedEvent extends BaseEvent {}
|
export interface BuilderServedEvent extends BaseEvent {
|
||||||
|
timezone: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface AppServedEvent extends BaseEvent {
|
export interface AppServedEvent extends BaseEvent {
|
||||||
appVersion: string
|
appVersion: string
|
||||||
|
timezone: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppPreviewServedEvent extends BaseEvent {
|
export interface AppPreviewServedEvent extends BaseEvent {
|
||||||
appVersion: string
|
appVersion: string
|
||||||
|
timezone: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue