ADD CROSS DOMAIN SUPPORT

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-26 22:35:29 +02:00
parent a0c8199474
commit 41143ca5f8
26 changed files with 514 additions and 126 deletions

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "clients" ADD COLUMN "crossDomain" BOOLEAN NOT NULL DEFAULT false;

View File

@@ -171,6 +171,7 @@ model Client {
organization Organization? @relation(fields: [organizationId], references: [id])
organizationId String?
cors String?
crossDomain Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt

View File

@@ -16,5 +16,8 @@ export async function getClientsByOrganizationSlug(organizationSlug: string) {
include: {
project: true,
},
orderBy: {
createdAt: 'asc',
},
});
}

View File

@@ -18,11 +18,12 @@ export interface EventsQueuePayloadIncomingEvent {
latitude: number | undefined;
};
headers: {
origin: string | undefined;
ua: string | undefined;
};
currentDeviceId: string;
previousDeviceId: string;
currentDeviceIdDeprecated: string;
previousDeviceIdDeprecated: string;
};
}
export interface EventsQueuePayloadCreateEvent {

View File

@@ -1,5 +1,3 @@
import { clerkClient } from '@clerk/fastify';
import { db, getProjectById } from '@openpanel/db';
import { cacheable } from '@openpanel/redis';

View File

@@ -1,4 +1,4 @@
import { randomUUID } from 'crypto';
import crypto from 'crypto';
import { z } from 'zod';
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
@@ -14,6 +14,7 @@ export const clientRouter = createTRPCRouter({
id: z.string(),
name: z.string(),
cors: z.string().nullable(),
crossDomain: z.boolean().optional(),
})
)
.mutation(({ input }) => {
@@ -24,6 +25,7 @@ export const clientRouter = createTRPCRouter({
data: {
name: input.name,
cors: input.cors ?? null,
crossDomain: input.crossDomain,
},
});
}),
@@ -34,11 +36,12 @@ export const clientRouter = createTRPCRouter({
projectId: z.string(),
organizationSlug: z.string(),
cors: z.string().nullable(),
crossDomain: z.boolean().optional(),
type: z.enum(['read', 'write', 'root']).optional(),
})
)
.mutation(async ({ input }) => {
const secret = randomUUID();
const secret = `sec_${crypto.randomBytes(10).toString('hex')}`;
const data: Prisma.ClientCreateArgs['data'] = {
organizationSlug: input.organizationSlug,
organizationId: input.organizationSlug,
@@ -47,6 +50,7 @@ export const clientRouter = createTRPCRouter({
type: input.type ?? 'write',
cors: input.cors ? stripTrailingSlash(input.cors) : null,
secret: await hashPassword(secret),
crossDomain: input.crossDomain ?? false,
};
const client = await db.client.create({ data });

View File

@@ -1,7 +1,7 @@
import { randomUUID } from 'crypto';
import crypto from 'crypto';
import type { z } from 'zod';
import { hashPassword, slug, stripTrailingSlash } from '@openpanel/common';
import { hashPassword, stripTrailingSlash } from '@openpanel/common';
import { db, getId, getOrganizationBySlug, getUserById } from '@openpanel/db';
import type { ProjectType } from '@openpanel/db';
import { zOnboardingProject } from '@openpanel/validation';
@@ -66,7 +66,7 @@ export const onboardingRouter = createTRPCRouter({
},
});
const secret = randomUUID();
const secret = `sec_${crypto.randomBytes(10).toString('hex')}`;
const client = await db.client.create({
data: {
name: `${project.name} Client`,