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