refactor: event/log to event/list
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
ClickHouseResult,
|
||||
EventLog,
|
||||
EventLogQuery,
|
||||
EventList,
|
||||
EventListQuery,
|
||||
RawEventFromClickHouse,
|
||||
} from "@autumn/shared";
|
||||
import { ErrCode, RecaseError } from "@autumn/shared";
|
||||
@@ -14,10 +14,10 @@ import type { ClickHouseClient } from "@clickhouse/client";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import type { AutumnContext } from "@/honoUtils/HonoEnv";
|
||||
|
||||
export class EventLogService {
|
||||
export class EventListService {
|
||||
private static transformRawEvents(
|
||||
rawEvents: RawEventFromClickHouse[],
|
||||
): EventLog[] {
|
||||
): EventList[] {
|
||||
return rawEvents.map((event) => {
|
||||
let properties = {};
|
||||
if (event.properties) {
|
||||
@@ -142,7 +142,7 @@ export class EventLogService {
|
||||
params,
|
||||
}: {
|
||||
ctx: AutumnContext;
|
||||
params: EventLogQuery;
|
||||
params: EventListQuery;
|
||||
}) {
|
||||
const { clickhouseClient, org, env } = ctx;
|
||||
const { starting_after, limit, customer_id, feature_id, time_range } =
|
||||
@@ -167,7 +167,7 @@ export class EventLogService {
|
||||
: [feature_id]
|
||||
: undefined;
|
||||
|
||||
const whereClause = EventLogService.buildWhereConditions({
|
||||
const whereClause = EventListService.buildWhereConditions({
|
||||
customerId: customer_id,
|
||||
eventNames,
|
||||
startDate: time_range?.start,
|
||||
@@ -192,7 +192,7 @@ order by timestamp desc, id desc
|
||||
limit {limit:UInt32};
|
||||
`;
|
||||
|
||||
const queryParams = EventLogService.buildQueryParams({
|
||||
const queryParams = EventListService.buildQueryParams({
|
||||
orgId: org?.id,
|
||||
env,
|
||||
customerId: customer_id,
|
||||
@@ -213,7 +213,7 @@ limit {limit:UInt32};
|
||||
(await result.json()) as ClickHouseResult<RawEventFromClickHouse>;
|
||||
const rawEvents = resultJson.data;
|
||||
|
||||
const events = EventLogService.transformRawEvents(rawEvents);
|
||||
const events = EventListService.transformRawEvents(rawEvents);
|
||||
|
||||
const hasMore = events.length > limit;
|
||||
const list = hasMore ? events.slice(0, limit) : events;
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Hono } from "hono";
|
||||
import type { HonoEnv } from "../../honoUtils/HonoEnv.js";
|
||||
import { handleEventLog } from "./handlers/handleEventLog.js";
|
||||
import { handleEventList } from "./handlers/handleEventList.js";
|
||||
import { handleEventsAggregation } from "./handlers/handleEventsAggregation.js";
|
||||
|
||||
export const eventsRouter = new Hono<HonoEnv>();
|
||||
|
||||
eventsRouter.post("aggregate", ...handleEventsAggregation);
|
||||
eventsRouter.post("log", ...handleEventLog);
|
||||
eventsRouter.post("list", ...handleEventList);
|
||||
|
||||
19
server/src/internal/events/handlers/handleEventList.ts
Normal file
19
server/src/internal/events/handlers/handleEventList.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { EventListResponse } from "@autumn/shared";
|
||||
import { EventListQuerySchema } from "@autumn/shared";
|
||||
import { createRoute } from "@/honoMiddlewares/routeHandler";
|
||||
import { EventListService } from "../EventListService";
|
||||
|
||||
export const handleEventList = createRoute({
|
||||
body: EventListQuerySchema,
|
||||
handler: async (c) => {
|
||||
const ctx = c.get("ctx");
|
||||
const bodyParams = c.req.valid("json");
|
||||
|
||||
const result = await EventListService.getEvents({
|
||||
ctx,
|
||||
params: bodyParams,
|
||||
});
|
||||
|
||||
return c.json<EventListResponse>(result);
|
||||
},
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { EventLogResponse } from "@autumn/shared";
|
||||
import { EventLogQuerySchema } from "@autumn/shared";
|
||||
import { createRoute } from "@/honoMiddlewares/routeHandler";
|
||||
import { EventLogService } from "../EventLogService";
|
||||
|
||||
export const handleEventLog = createRoute({
|
||||
body: EventLogQuerySchema,
|
||||
handler: async (c) => {
|
||||
const ctx = c.get("ctx");
|
||||
const bodyParams = c.req.valid("json");
|
||||
|
||||
const result = await EventLogService.getEvents({
|
||||
ctx,
|
||||
params: bodyParams,
|
||||
});
|
||||
|
||||
return c.json<EventLogResponse>(result);
|
||||
},
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
createCursorPaginatedResponseSchema,
|
||||
} from "../../common/cursorPaginationSchemas";
|
||||
|
||||
export const EventLogQuerySchema = CursorPaginationQuerySchema.extend({
|
||||
export const EventListQuerySchema = CursorPaginationQuerySchema.extend({
|
||||
customer_id: z.string().describe("Filter events by customer ID"),
|
||||
feature_id: z
|
||||
.string()
|
||||
@@ -26,9 +26,9 @@ export const EventLogQuerySchema = CursorPaginationQuerySchema.extend({
|
||||
.describe("Filter events by time range"),
|
||||
});
|
||||
|
||||
export type EventLogQuery = z.infer<typeof EventLogQuerySchema>;
|
||||
export type EventListQuery = z.infer<typeof EventListQuerySchema>;
|
||||
|
||||
export const EventLogSchema = z.object({
|
||||
export const EventListSchema = z.object({
|
||||
id: z.string().describe("Event ID (KSUID)"),
|
||||
timestamp: z.number().describe("Event timestamp (epoch milliseconds)"),
|
||||
event_name: z.string().describe("Name of the event"),
|
||||
@@ -37,9 +37,9 @@ export const EventLogSchema = z.object({
|
||||
properties: z.object({}).describe("Event properties (JSONB)"),
|
||||
});
|
||||
|
||||
export type EventLog = z.infer<typeof EventLogSchema>;
|
||||
export type EventList = z.infer<typeof EventListSchema>;
|
||||
|
||||
export const EventLogResponseSchema =
|
||||
createCursorPaginatedResponseSchema(EventLogSchema);
|
||||
export const EventListResponseSchema =
|
||||
createCursorPaginatedResponseSchema(EventListSchema);
|
||||
|
||||
export type EventLogResponse = z.infer<typeof EventLogResponseSchema>;
|
||||
export type EventListResponse = z.infer<typeof EventListResponseSchema>;
|
||||
@@ -3,11 +3,10 @@ import * as schemas from "./db/schema.js";
|
||||
export { schemas };
|
||||
|
||||
export * from "./api/apiUtils.js";
|
||||
// API MODELS
|
||||
export * from "./api/models.js";
|
||||
|
||||
// Cursor pagination utilities
|
||||
export * from "./api/common/cursorPaginationSchemas.js";
|
||||
// API MODELS
|
||||
export * from "./api/models.js";
|
||||
|
||||
// API VERSIONING SYSTEM
|
||||
export * from "./api/versionUtils/versionUtils.js";
|
||||
@@ -104,7 +103,7 @@ export * from "./api/events/aggregation/eventAggregationSchema.js";
|
||||
export * from "./api/events/insights/query/insightsQueryBody.js";
|
||||
|
||||
// Event Log Models
|
||||
export * from "./api/events/log/eventLogSchema.js";
|
||||
export * from "./api/events/list/eventListSchema.js";
|
||||
|
||||
// Attach Function Response
|
||||
export * from "./models/attachModels/attachFunctionResponse.js";
|
||||
|
||||
@@ -75,7 +75,7 @@ export type GroupedAggregatedRow = {
|
||||
|
||||
export type AggregatedEventRow = FlatAggregatedRow | GroupedAggregatedRow;
|
||||
|
||||
export type EventLogParams = {
|
||||
export type EventListParams = {
|
||||
customer_id: string;
|
||||
feature_id: string | string[];
|
||||
time_range: { start: number; end: number };
|
||||
|
||||
Reference in New Issue
Block a user