rename IServiceCreateEventPayload
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
1b613538cc
commit
0fea45c9f7
@@ -4,7 +4,7 @@ import superjson from 'superjson';
|
||||
import type * as WebSocket from 'ws';
|
||||
|
||||
import { getSuperJson } from '@openpanel/common';
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
import {
|
||||
getEvents,
|
||||
getLiveVisitors,
|
||||
@@ -81,7 +81,7 @@ export function wsVisitors(
|
||||
|
||||
const message = (channel: string, message: string) => {
|
||||
if (channel === 'event:received') {
|
||||
const event = getSuperJson<IServiceCreateEventPayload>(message);
|
||||
const event = getSuperJson<IServiceEvent>(message);
|
||||
if (event?.projectId === params.projectId) {
|
||||
getLiveVisitors(params.projectId).then((count) => {
|
||||
connection.socket.send(String(count));
|
||||
@@ -142,7 +142,7 @@ export async function wsProjectEvents(
|
||||
getRedisSub().subscribe(subscribeToEvent);
|
||||
|
||||
const message = async (channel: string, message: string) => {
|
||||
const event = getSuperJson<IServiceCreateEventPayload>(message);
|
||||
const event = getSuperJson<IServiceEvent>(message);
|
||||
if (event?.projectId === params.projectId) {
|
||||
const profile = await getProfileById(event.profileId, event.projectId);
|
||||
connection.socket.send(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Fragment } from 'react';
|
||||
import { Widget, WidgetHead } from '@/components/widget';
|
||||
import { isSameDay } from 'date-fns';
|
||||
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
|
||||
import { EventListItem } from '../event-list/event-list-item';
|
||||
|
||||
@@ -14,7 +14,7 @@ function showDateHeader(a: Date, b?: Date) {
|
||||
}
|
||||
|
||||
interface EventListProps {
|
||||
data: IServiceCreateEventPayload[];
|
||||
data: IServiceEvent[];
|
||||
}
|
||||
export function EventConversionsList({ data }: EventListProps) {
|
||||
return (
|
||||
@@ -28,7 +28,7 @@ export function EventConversionsList({ data }: EventListProps) {
|
||||
{showDateHeader(item.createdAt, list[index - 1]?.createdAt) && (
|
||||
<div className="flex flex-row justify-between gap-2 [&:not(:first-child)]:mt-12">
|
||||
<div className="flex gap-2">
|
||||
<div className="bg-def-200 border-def-200 flex h-8 items-center gap-2 rounded border px-3 text-sm font-medium leading-none">
|
||||
<div className="flex h-8 items-center gap-2 rounded border border-def-200 bg-def-200 px-3 text-sm font-medium leading-none">
|
||||
{item.createdAt.toLocaleDateString()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,12 +16,12 @@ import {
|
||||
} from '@/hooks/useEventQueryFilters';
|
||||
import { round } from 'mathjs';
|
||||
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
|
||||
import { EventEdit } from './event-edit';
|
||||
|
||||
interface Props {
|
||||
event: IServiceCreateEventPayload;
|
||||
event: IServiceEvent;
|
||||
open: boolean;
|
||||
setOpen: Dispatch<SetStateAction<boolean>>;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import { cn } from '@/utils/cn';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
|
||||
import {
|
||||
EventIconColors,
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
} from './event-icon';
|
||||
|
||||
interface Props {
|
||||
event: IServiceCreateEventPayload;
|
||||
event: IServiceEvent;
|
||||
open: boolean;
|
||||
setOpen: Dispatch<SetStateAction<boolean>>;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export function EventEdit({ event, open, setOpen }: Props) {
|
||||
setIcon(name);
|
||||
}}
|
||||
className={cn(
|
||||
'bg-def-200 inline-flex h-8 w-8 flex-shrink-0 cursor-pointer items-center justify-center rounded-md transition-all',
|
||||
'inline-flex h-8 w-8 flex-shrink-0 cursor-pointer items-center justify-center rounded-md bg-def-200 transition-all',
|
||||
name === selectedIcon
|
||||
? 'scale-110 ring-1 ring-black'
|
||||
: '[&_svg]:opacity-50'
|
||||
|
||||
@@ -9,15 +9,12 @@ import { cn } from '@/utils/cn';
|
||||
import { getProfileName } from '@/utils/getters';
|
||||
import Link from 'next/link';
|
||||
|
||||
import type {
|
||||
IServiceCreateEventPayload,
|
||||
IServiceEventMinimal,
|
||||
} from '@openpanel/db';
|
||||
import type { IServiceEvent, IServiceEventMinimal } from '@openpanel/db';
|
||||
|
||||
import { EventDetails } from './event-details';
|
||||
import { EventIcon } from './event-icon';
|
||||
|
||||
type EventListItemProps = IServiceEventMinimal | IServiceCreateEventPayload;
|
||||
type EventListItemProps = IServiceEventMinimal | IServiceEvent;
|
||||
|
||||
export function EventListItem(props: EventListItemProps) {
|
||||
const { organizationSlug, projectId } = useAppParams();
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
|
||||
import { isSameDay } from 'date-fns';
|
||||
import { GanttChartIcon } from 'lucide-react';
|
||||
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
|
||||
import { EventListItem } from './event-list-item';
|
||||
import EventListener from './event-listener';
|
||||
@@ -20,7 +20,7 @@ function showDateHeader(a: Date, b?: Date) {
|
||||
}
|
||||
|
||||
interface EventListProps {
|
||||
data: IServiceCreateEventPayload[];
|
||||
data: IServiceEvent[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ function EventList({ data, count }: EventListProps) {
|
||||
<div className="flex flex-row justify-between gap-2 [&:not(:first-child)]:mt-12">
|
||||
{index === 0 ? <EventListener /> : <div />}
|
||||
<div className="flex gap-2">
|
||||
<div className="bg-def-200 border-def-200 flex h-8 items-center gap-2 rounded border px-3 text-sm font-medium leading-none">
|
||||
<div className="flex h-8 items-center gap-2 rounded border border-def-200 bg-def-200 px-3 text-sm font-medium leading-none">
|
||||
{item.createdAt.toLocaleDateString()}
|
||||
</div>
|
||||
{index === 0 && (
|
||||
|
||||
@@ -5,20 +5,17 @@ import { EventListItem } from '@/app/(app)/[organizationSlug]/[projectId]/events
|
||||
import useWS from '@/hooks/useWS';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
|
||||
import type {
|
||||
IServiceCreateEventPayload,
|
||||
IServiceEventMinimal,
|
||||
} from '@openpanel/db';
|
||||
import type { IServiceEvent, IServiceEventMinimal } from '@openpanel/db';
|
||||
|
||||
type Props = {
|
||||
events: (IServiceEventMinimal | IServiceCreateEventPayload)[];
|
||||
events: (IServiceEventMinimal | IServiceEvent)[];
|
||||
projectId: string;
|
||||
limit: number;
|
||||
};
|
||||
|
||||
const RealtimeLiveEvents = ({ events, projectId, limit }: Props) => {
|
||||
const [state, setState] = useState(events ?? []);
|
||||
useWS<IServiceEventMinimal | IServiceCreateEventPayload>(
|
||||
useWS<IServiceEventMinimal | IServiceEvent>(
|
||||
`/live/events/${projectId}`,
|
||||
(event) => {
|
||||
setState((p) => [event, ...p].slice(0, limit));
|
||||
|
||||
@@ -10,22 +10,20 @@ import { CheckCircle2Icon, CheckIcon, Loader2 } from 'lucide-react';
|
||||
|
||||
import type {
|
||||
IServiceClient,
|
||||
IServiceCreateEventPayload,
|
||||
IServiceEvent,
|
||||
IServiceProject,
|
||||
} from '@openpanel/db';
|
||||
|
||||
type Props = {
|
||||
project: IServiceProject;
|
||||
client: IServiceClient | null;
|
||||
events: IServiceCreateEventPayload[];
|
||||
events: IServiceEvent[];
|
||||
onVerified: (verified: boolean) => void;
|
||||
};
|
||||
|
||||
const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
const [events, setEvents] = useState<IServiceCreateEventPayload[]>(
|
||||
_events ?? []
|
||||
);
|
||||
useWS<IServiceCreateEventPayload>(
|
||||
const [events, setEvents] = useState<IServiceEvent[]>(_events ?? []);
|
||||
useWS<IServiceEvent>(
|
||||
`/live/events/${client?.projectId}?type=received`,
|
||||
(data) => {
|
||||
setEvents((prev) => [...prev, data]);
|
||||
|
||||
@@ -6,10 +6,7 @@ import { LinkButton } from '@/components/ui/button';
|
||||
import { cn } from '@/utils/cn';
|
||||
import Link from 'next/link';
|
||||
|
||||
import type {
|
||||
IServiceCreateEventPayload,
|
||||
IServiceProjectWithClients,
|
||||
} from '@openpanel/db';
|
||||
import type { IServiceEvent, IServiceProjectWithClients } from '@openpanel/db';
|
||||
|
||||
import OnboardingLayout, {
|
||||
OnboardingDescription,
|
||||
@@ -18,7 +15,7 @@ import VerifyListener from './onboarding-verify-listener';
|
||||
|
||||
type Props = {
|
||||
project: IServiceProjectWithClients;
|
||||
events: IServiceCreateEventPayload[];
|
||||
events: IServiceEvent[];
|
||||
};
|
||||
|
||||
const Verify = ({ project, events }: Props) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
parsePath,
|
||||
toISOString,
|
||||
} from '@openpanel/common';
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceCreateEventPayload, IServiceEvent } from '@openpanel/db';
|
||||
import { createEvent } from '@openpanel/db';
|
||||
import { getLastScreenViewFromProfileId } from '@openpanel/db/src/services/event.service';
|
||||
import { eventsQueue, findJobByPrefix, sessionsQueue } from '@openpanel/queue';
|
||||
@@ -70,7 +70,7 @@ export async function incomingEvent(job: Job<EventsQueuePayloadIncomingEvent>) {
|
||||
projectId,
|
||||
});
|
||||
|
||||
const payload: Omit<IServiceCreateEventPayload, 'id'> = {
|
||||
const payload: Omit<IServiceEvent, 'id'> = {
|
||||
name: body.name,
|
||||
deviceId: event?.deviceId || '',
|
||||
sessionId: event?.sessionId || '',
|
||||
@@ -146,7 +146,7 @@ export async function incomingEvent(job: Job<EventsQueuePayloadIncomingEvent>) {
|
||||
);
|
||||
}
|
||||
|
||||
const payload: Omit<IServiceCreateEventPayload, 'id'> = {
|
||||
const payload: IServiceCreateEventPayload = {
|
||||
name: body.name,
|
||||
deviceId: sessionEndPayload.deviceId,
|
||||
sessionId: sessionEndPayload.sessionId,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ch, TABLE_NAMES } from '../clickhouse-client';
|
||||
import { transformEvent } from '../services/event.service';
|
||||
import type {
|
||||
IClickhouseEvent,
|
||||
IServiceCreateEventPayload,
|
||||
IServiceEvent,
|
||||
} from '../services/event.service';
|
||||
import type {
|
||||
Find,
|
||||
@@ -187,22 +187,19 @@ export class EventBuffer extends RedisBuffer<IClickhouseEvent> {
|
||||
];
|
||||
};
|
||||
|
||||
public findMany: FindMany<IClickhouseEvent, IServiceCreateEventPayload> =
|
||||
async (callback) => {
|
||||
return this.getQueue(-1)
|
||||
.then((queue) => {
|
||||
return queue
|
||||
.filter(callback)
|
||||
.map((item) => transformEvent(item.event));
|
||||
})
|
||||
.catch(() => {
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
public find: Find<IClickhouseEvent, IServiceCreateEventPayload> = async (
|
||||
public findMany: FindMany<IClickhouseEvent, IServiceEvent> = async (
|
||||
callback
|
||||
) => {
|
||||
return this.getQueue(-1)
|
||||
.then((queue) => {
|
||||
return queue.filter(callback).map((item) => transformEvent(item.event));
|
||||
})
|
||||
.catch(() => {
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
public find: Find<IClickhouseEvent, IServiceEvent> = async (callback) => {
|
||||
return this.getQueue(-1)
|
||||
.then((queue) => {
|
||||
const match = queue.find(callback);
|
||||
|
||||
@@ -62,9 +62,7 @@ export interface IClickhouseEvent {
|
||||
meta?: EventMeta;
|
||||
}
|
||||
|
||||
export function transformEvent(
|
||||
event: IClickhouseEvent
|
||||
): IServiceCreateEventPayload {
|
||||
export function transformEvent(event: IClickhouseEvent): IServiceEvent {
|
||||
return {
|
||||
id: event.id,
|
||||
name: event.name,
|
||||
@@ -98,7 +96,12 @@ export function transformEvent(
|
||||
};
|
||||
}
|
||||
|
||||
export interface IServiceCreateEventPayload {
|
||||
export type IServiceCreateEventPayload = Omit<
|
||||
IServiceEvent,
|
||||
'id' | 'importedAt' | 'profile' | 'meta'
|
||||
>;
|
||||
|
||||
export interface IServiceEvent {
|
||||
id: string;
|
||||
name: string;
|
||||
deviceId: string;
|
||||
@@ -169,7 +172,7 @@ function maskString(str: string, mask = '*') {
|
||||
}
|
||||
|
||||
export function transformMinimalEvent(
|
||||
event: IServiceCreateEventPayload
|
||||
event: IServiceEvent
|
||||
): IServiceEventMinimal {
|
||||
return {
|
||||
id: event.id,
|
||||
@@ -201,7 +204,7 @@ export async function getLiveVisitors(projectId: string) {
|
||||
export async function getEvents(
|
||||
sql: string,
|
||||
options: GetEventsOptions = {}
|
||||
): Promise<IServiceCreateEventPayload[]> {
|
||||
): Promise<IServiceEvent[]> {
|
||||
const events = await chQuery<IClickhouseEvent>(sql);
|
||||
if (options.profile) {
|
||||
const ids = events.map((e) => e.profile_id);
|
||||
@@ -230,12 +233,7 @@ export async function getEvents(
|
||||
return events.map(transformEvent);
|
||||
}
|
||||
|
||||
export async function createEvent(
|
||||
payload: Omit<
|
||||
IServiceCreateEventPayload,
|
||||
'id' | 'importedAt' | 'profile' | 'meta'
|
||||
>
|
||||
) {
|
||||
export async function createEvent(payload: IServiceCreateEventPayload) {
|
||||
if (!payload.profileId) {
|
||||
payload.profileId = payload.deviceId;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Queue } from 'bullmq';
|
||||
|
||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
import { getRedisQueue } from '@openpanel/redis';
|
||||
import type { PostEventPayload } from '@openpanel/sdk';
|
||||
|
||||
@@ -26,12 +26,12 @@ export interface EventsQueuePayloadIncomingEvent {
|
||||
}
|
||||
export interface EventsQueuePayloadCreateEvent {
|
||||
type: 'createEvent';
|
||||
payload: Omit<IServiceCreateEventPayload, 'id'>;
|
||||
payload: Omit<IServiceEvent, 'id'>;
|
||||
}
|
||||
export interface EventsQueuePayloadCreateSessionEnd {
|
||||
type: 'createSessionEnd';
|
||||
payload: Pick<
|
||||
IServiceCreateEventPayload,
|
||||
IServiceEvent,
|
||||
'deviceId' | 'sessionId' | 'profileId' | 'projectId'
|
||||
>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user