onboarding completed

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-04-16 11:41:15 +02:00
committed by Carl-Gerhard Lindesvärd
parent 97627583ec
commit 7d22d2ddad
79 changed files with 2542 additions and 805 deletions

View File

@@ -1,5 +1,6 @@
import { omit, uniq } from 'ramda';
import { escape } from 'sqlstring';
import superjson from 'superjson';
import { v4 as uuid } from 'uuid';
import { randomSplitName, toDots } from '@openpanel/common';
@@ -113,11 +114,51 @@ export interface IServiceCreateEventPayload {
meta: EventMeta | undefined;
}
export interface IServiceEventMinimal {
id: string;
name: string;
projectId: string;
sessionId: string;
createdAt: Date;
country?: string | undefined;
os?: string | undefined;
browser?: string | undefined;
device?: string | undefined;
brand?: string | undefined;
duration: number;
path: string;
referrer: string | undefined;
meta: EventMeta | undefined;
minimal: boolean;
}
interface GetEventsOptions {
profile?: boolean | Prisma.ProfileSelect;
meta?: boolean | Prisma.EventMetaSelect;
}
export function transformMinimalEvent(
event: IServiceCreateEventPayload
): IServiceEventMinimal {
return {
id: event.id,
name: event.name,
projectId: event.projectId,
sessionId: event.sessionId,
createdAt: event.createdAt,
country: event.country,
os: event.os,
browser: event.browser,
device: event.device,
brand: event.brand,
duration: event.duration,
path: event.path,
referrer: event.referrer,
meta: event.meta,
minimal: true,
};
}
export async function getLiveVisitors(projectId: string) {
const keys = await redis.keys(`live:event:${projectId}:*`);
return keys.length;
@@ -227,7 +268,7 @@ export async function createEvent(
},
});
redisPub.publish('event', JSON.stringify(transformEvent(event)));
redisPub.publish('event', superjson.stringify(transformEvent(event)));
redis.set(
`live:event:${event.project_id}:${event.profile_id}`,
'',

View File

@@ -23,8 +23,9 @@ export function transformOrganization(org: Organization) {
export async function getCurrentOrganizations() {
const session = auth();
if (!session.userId) return [];
const organizations = await clerkClient.users.getOrganizationMembershipList({
userId: session.userId!,
userId: session.userId,
});
return organizations.map((item) => transformOrganization(item.organization));
}

View File

@@ -1,9 +1,14 @@
import { auth } from '@clerk/nextjs';
import type { Project } from '../prisma-client';
import type { Prisma, Project } from '../prisma-client';
import { db } from '../prisma-client';
export type IServiceProject = Project;
export type IServiceProjectWithClients = Prisma.ProjectGetPayload<{
include: {
clients: true;
};
}>;
export async function getProjectById(id: string) {
const res = await db.project.findUnique({
@@ -19,6 +24,23 @@ export async function getProjectById(id: string) {
return res;
}
export async function getProjectWithClients(id: string) {
const res = await db.project.findUnique({
where: {
id,
},
include: {
clients: true,
},
});
if (!res) {
return null;
}
return res;
}
export async function getProjectsByOrganizationSlug(organizationSlug: string) {
return db.project.findMany({
where: {