Compare commits

...

2 commits

Author SHA1 Message Date
Francis Cao
504c459090 update schema validation for link/pixel updates
Some checks failed
Node.js CI / build (postgresql, 18.18, 10) (push) Has been cancelled
2025-10-30 16:13:36 -07:00
Mike Cao
dfe969cabe Fixed pixels/links collect.
Some checks are pending
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run
2025-10-30 12:53:12 -07:00
3 changed files with 13 additions and 8 deletions

View file

@ -24,9 +24,9 @@ export async function GET(request: Request, { params }: { params: Promise<{ link
export async function POST(request: Request, { params }: { params: Promise<{ linkId: string }> }) {
const schema = z.object({
name: z.string(),
url: z.string(),
slug: z.string(),
name: z.string().optional(),
url: z.string().optional(),
slug: z.string().min(8).optional(),
});
const { auth, body, error } = await parseRequest(request, schema);

View file

@ -24,8 +24,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ pixe
export async function POST(request: Request, { params }: { params: Promise<{ pixelId: string }> }) {
const schema = z.object({
name: z.string(),
slug: z.string().min(8),
name: z.string().optional(),
slug: z.string().min(8).optional(),
});
const { auth, body, error } = await parseRequest(request, schema);

View file

@ -82,6 +82,8 @@ export async function POST(request: Request) {
id,
} = payload;
const sourceId = websiteId || pixelId || linkId;
// Cache check
let cache: Cache | null = null;
@ -128,13 +130,13 @@ export async function POST(request: Request) {
const sessionSalt = hash(startOfMonth(createdAt).toUTCString());
const visitSalt = hash(startOfHour(createdAt).toUTCString());
const sessionId = id ? uuid(websiteId, id) : uuid(websiteId, ip, userAgent, sessionSalt);
const sessionId = id ? uuid(sourceId, id) : uuid(sourceId, ip, userAgent, sessionSalt);
// Create a session if not found
if (!clickhouse.enabled && !cache?.sessionId) {
await createSession({
id: sessionId,
websiteId,
websiteId: sourceId,
browser,
os,
device,
@ -206,7 +208,7 @@ export async function POST(request: Request) {
: EVENT_TYPE.pageView;
await saveEvent({
websiteId: websiteId || linkId || pixelId,
websiteId: sourceId,
sessionId,
visitId,
eventType,
@ -270,6 +272,9 @@ export async function POST(request: Request) {
} catch (e) {
const error = serializeError(e);
// eslint-disable-next-line no-console
console.log(error);
return serverError({ errorObject: error });
}
}