chore(root): migrate to biome
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { getClientIp, parseIp } from '@/utils/parseIp';
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
|
||||
import { generateDeviceId } from '@openpanel/common';
|
||||
import { generateDeviceId } from '@openpanel/common/server';
|
||||
import { getSalts } from '@openpanel/db';
|
||||
import { eventsQueue } from '@openpanel/queue';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
@@ -13,7 +13,7 @@ export async function postEvent(
|
||||
request: FastifyRequest<{
|
||||
Body: PostEventPayload;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const ip = getClientIp(request)!;
|
||||
const ua = request.headers['user-agent']!;
|
||||
@@ -44,7 +44,7 @@ export async function postEvent(
|
||||
'locked',
|
||||
'EX',
|
||||
10,
|
||||
'NX'
|
||||
'NX',
|
||||
);
|
||||
|
||||
eventsQueue.add('event', {
|
||||
|
||||
@@ -19,7 +19,7 @@ async function getProjectId(
|
||||
projectId?: string;
|
||||
};
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
let projectId = request.query.projectId || request.query.project_id;
|
||||
|
||||
@@ -77,7 +77,7 @@ const eventsScheme = z.object({
|
||||
includes: z
|
||||
.preprocess(
|
||||
(arg) => (typeof arg === 'string' ? [arg] : arg),
|
||||
z.array(z.string())
|
||||
z.array(z.string()),
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
@@ -86,7 +86,7 @@ export async function events(
|
||||
request: FastifyRequest<{
|
||||
Querystring: z.infer<typeof eventsScheme>;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const query = eventsScheme.safeParse(request.query);
|
||||
|
||||
@@ -118,7 +118,7 @@ export async function events(
|
||||
meta: false,
|
||||
...query.data.includes?.reduce(
|
||||
(acc, key) => ({ ...acc, [key]: true }),
|
||||
{}
|
||||
{},
|
||||
),
|
||||
},
|
||||
};
|
||||
@@ -154,7 +154,7 @@ export async function charts(
|
||||
request: FastifyRequest<{
|
||||
Querystring: Record<string, string>;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const query = chartSchemeFull.safeParse(parseQueryString(request.query));
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
|
||||
import { toDots } from '@openpanel/common';
|
||||
import type { IClickhouseEvent } from '@openpanel/db';
|
||||
import { ch, formatClickhouseDate, TABLE_NAMES } from '@openpanel/db';
|
||||
import { TABLE_NAMES, ch, formatClickhouseDate } from '@openpanel/db';
|
||||
|
||||
export async function importEvents(
|
||||
request: FastifyRequest<{
|
||||
Body: IClickhouseEvent[];
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const importedAt = formatClickhouseDate(new Date());
|
||||
const values: IClickhouseEvent[] = request.body.map((event) => {
|
||||
|
||||
@@ -6,11 +6,11 @@ import type * as WebSocket from 'ws';
|
||||
import { getSuperJson } from '@openpanel/common';
|
||||
import type { IServiceEvent } from '@openpanel/db';
|
||||
import {
|
||||
TABLE_NAMES,
|
||||
getEvents,
|
||||
getLiveVisitors,
|
||||
getProfileById,
|
||||
getProfileByIdCached,
|
||||
TABLE_NAMES,
|
||||
transformMinimalEvent,
|
||||
} from '@openpanel/db';
|
||||
import { getRedisCache, getRedisPub, getRedisSub } from '@openpanel/redis';
|
||||
@@ -26,10 +26,10 @@ export async function testVisitors(
|
||||
projectId: string;
|
||||
};
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const events = await getEvents(
|
||||
`SELECT * FROM ${TABLE_NAMES.events} LIMIT 500`
|
||||
`SELECT * FROM ${TABLE_NAMES.events} LIMIT 500`,
|
||||
);
|
||||
const event = events[Math.floor(Math.random() * events.length)];
|
||||
if (!event) {
|
||||
@@ -41,7 +41,7 @@ export async function testVisitors(
|
||||
`live:event:${event.projectId}:${Math.random() * 1000}`,
|
||||
'',
|
||||
'EX',
|
||||
10
|
||||
10,
|
||||
);
|
||||
reply.status(202).send(event);
|
||||
}
|
||||
@@ -52,10 +52,10 @@ export async function testEvents(
|
||||
projectId: string;
|
||||
};
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const events = await getEvents(
|
||||
`SELECT * FROM ${TABLE_NAMES.events} LIMIT 500`
|
||||
`SELECT * FROM ${TABLE_NAMES.events} LIMIT 500`,
|
||||
);
|
||||
const event = events[Math.floor(Math.random() * events.length)];
|
||||
if (!event) {
|
||||
@@ -73,7 +73,7 @@ export function wsVisitors(
|
||||
Params: {
|
||||
projectId: string;
|
||||
};
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { params } = req;
|
||||
|
||||
@@ -122,7 +122,7 @@ export async function wsProjectEvents(
|
||||
token?: string;
|
||||
type?: string;
|
||||
};
|
||||
}>
|
||||
}>,
|
||||
) {
|
||||
const { params, query } = req;
|
||||
const { token } = query;
|
||||
@@ -147,7 +147,7 @@ export async function wsProjectEvents(
|
||||
if (event?.projectId === params.projectId) {
|
||||
const profile = await getProfileByIdCached(
|
||||
event.profileId,
|
||||
event.projectId
|
||||
event.projectId,
|
||||
);
|
||||
connection.socket.send(
|
||||
superjson.stringify(
|
||||
@@ -156,8 +156,8 @@ export async function wsProjectEvents(
|
||||
...event,
|
||||
profile,
|
||||
}
|
||||
: transformMinimalEvent(event)
|
||||
)
|
||||
: transformMinimalEvent(event),
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,8 +4,8 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import icoToPng from 'ico-to-png';
|
||||
import sharp from 'sharp';
|
||||
|
||||
import { createHash } from '@openpanel/common';
|
||||
import { ch, formatClickhouseDate, TABLE_NAMES } from '@openpanel/db';
|
||||
import { createHash } from '@openpanel/common/server';
|
||||
import { TABLE_NAMES, ch, formatClickhouseDate } from '@openpanel/db';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
|
||||
interface GetFaviconParams {
|
||||
@@ -38,7 +38,7 @@ async function getImageBuffer(url: string) {
|
||||
.png()
|
||||
.toBuffer();
|
||||
} catch (error) {
|
||||
logger.error(`Failed to get image from url`, {
|
||||
logger.error('Failed to get image from url', {
|
||||
error,
|
||||
url,
|
||||
});
|
||||
@@ -51,7 +51,7 @@ export async function getFavicon(
|
||||
request: FastifyRequest<{
|
||||
Querystring: GetFaviconParams;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
function sendBuffer(buffer: Buffer, cacheKey?: string) {
|
||||
if (cacheKey) {
|
||||
@@ -95,7 +95,7 @@ export async function getFavicon(
|
||||
}
|
||||
|
||||
const buffer = await getImageBuffer(
|
||||
'https://www.iconsdb.com/icons/download/orange/warning-128.png'
|
||||
'https://www.iconsdb.com/icons/download/orange/warning-128.png',
|
||||
);
|
||||
if (buffer && buffer.byteLength > 0) {
|
||||
return sendBuffer(buffer, hostname);
|
||||
@@ -106,7 +106,7 @@ export async function getFavicon(
|
||||
|
||||
export async function clearFavicons(
|
||||
request: FastifyRequest,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const keys = await getRedisCache().keys('favicon:*');
|
||||
for (const key of keys) {
|
||||
@@ -122,7 +122,7 @@ export async function ping(
|
||||
count: number;
|
||||
};
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
try {
|
||||
await ch.insert({
|
||||
@@ -137,7 +137,7 @@ export async function ping(
|
||||
format: 'JSONEachRow',
|
||||
});
|
||||
reply.status(200).send({
|
||||
message: `Success`,
|
||||
message: 'Success',
|
||||
count: request.body.count,
|
||||
domain: request.body.domain,
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function updateProfile(
|
||||
request: FastifyRequest<{
|
||||
Body: UpdateProfilePayload;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const { profileId, properties, ...rest } = request.body;
|
||||
const projectId = request.projectId;
|
||||
@@ -41,7 +41,7 @@ export async function incrementProfileProperty(
|
||||
request: FastifyRequest<{
|
||||
Body: IncrementProfilePayload;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const { profileId, property, value } = request.body;
|
||||
const projectId = request.projectId;
|
||||
@@ -51,19 +51,19 @@ export async function incrementProfileProperty(
|
||||
return reply.status(404).send('Not found');
|
||||
}
|
||||
|
||||
const parsed = parseInt(
|
||||
const parsed = Number.parseInt(
|
||||
pathOr<string>('0', property.split('.'), profile.properties),
|
||||
10
|
||||
10,
|
||||
);
|
||||
|
||||
if (isNaN(parsed)) {
|
||||
if (Number.isNaN(parsed)) {
|
||||
return reply.status(400).send('Not number');
|
||||
}
|
||||
|
||||
profile.properties = assocPath(
|
||||
property.split('.'),
|
||||
parsed + value,
|
||||
profile.properties
|
||||
profile.properties,
|
||||
);
|
||||
|
||||
await upsertProfile({
|
||||
@@ -80,7 +80,7 @@ export async function decrementProfileProperty(
|
||||
request: FastifyRequest<{
|
||||
Body: IncrementProfilePayload;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const { profileId, property, value } = request.body;
|
||||
const projectId = request.projectId;
|
||||
@@ -90,19 +90,19 @@ export async function decrementProfileProperty(
|
||||
return reply.status(404).send('Not found');
|
||||
}
|
||||
|
||||
const parsed = parseInt(
|
||||
const parsed = Number.parseInt(
|
||||
pathOr<string>('0', property.split('.'), profile.properties),
|
||||
10
|
||||
10,
|
||||
);
|
||||
|
||||
if (isNaN(parsed)) {
|
||||
if (Number.isNaN(parsed)) {
|
||||
return reply.status(400).send('Not number');
|
||||
}
|
||||
|
||||
profile.properties = assocPath(
|
||||
property.split('.'),
|
||||
parsed - value,
|
||||
profile.properties
|
||||
profile.properties,
|
||||
);
|
||||
|
||||
await upsertProfile({
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { GeoLocation } from '@/utils/parseIp';
|
||||
import { getClientIp, parseIp } from '@/utils/parseIp';
|
||||
import { parseUserAgent } from '@/utils/parseUserAgent';
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import { assocPath, path, pathOr, pick } from 'ramda';
|
||||
import { path, assocPath, pathOr, pick } from 'ramda';
|
||||
|
||||
import { generateDeviceId } from '@openpanel/common';
|
||||
import { generateDeviceId } from '@openpanel/common/server';
|
||||
import {
|
||||
createProfileAlias,
|
||||
getProfileById,
|
||||
@@ -31,21 +31,21 @@ export function getStringHeaders(headers: FastifyRequest['headers']) {
|
||||
'openpanel-sdk-version',
|
||||
'openpanel-client-id',
|
||||
],
|
||||
headers
|
||||
)
|
||||
headers,
|
||||
),
|
||||
).reduce(
|
||||
(acc, [key, value]) => ({
|
||||
...acc,
|
||||
[key]: value ? String(value) : undefined,
|
||||
}),
|
||||
{}
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
function getIdentity(body: TrackHandlerPayload): IdentifyPayload | undefined {
|
||||
const identity = path<IdentifyPayload>(
|
||||
['properties', '__identify'],
|
||||
body.payload
|
||||
body.payload,
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -62,7 +62,7 @@ export async function handler(
|
||||
request: FastifyRequest<{
|
||||
Body: TrackHandlerPayload;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const ip =
|
||||
path<string>(['properties', '__ip'], request.body.payload) ||
|
||||
@@ -129,7 +129,7 @@ export async function handler(
|
||||
projectId,
|
||||
geo,
|
||||
ua,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ async function track({
|
||||
'locked',
|
||||
'EX',
|
||||
10,
|
||||
'NX'
|
||||
'NX',
|
||||
);
|
||||
|
||||
eventsQueue.add('event', {
|
||||
@@ -269,19 +269,19 @@ async function increment({
|
||||
throw new Error('Not found');
|
||||
}
|
||||
|
||||
const parsed = parseInt(
|
||||
const parsed = Number.parseInt(
|
||||
pathOr<string>('0', property.split('.'), profile.properties),
|
||||
10
|
||||
10,
|
||||
);
|
||||
|
||||
if (isNaN(parsed)) {
|
||||
if (Number.isNaN(parsed)) {
|
||||
throw new Error('Not number');
|
||||
}
|
||||
|
||||
profile.properties = assocPath(
|
||||
property.split('.'),
|
||||
parsed + (value || 1),
|
||||
profile.properties
|
||||
profile.properties,
|
||||
);
|
||||
|
||||
await upsertProfile({
|
||||
@@ -305,19 +305,19 @@ async function decrement({
|
||||
throw new Error('Not found');
|
||||
}
|
||||
|
||||
const parsed = parseInt(
|
||||
const parsed = Number.parseInt(
|
||||
pathOr<string>('0', property.split('.'), profile.properties),
|
||||
10
|
||||
10,
|
||||
);
|
||||
|
||||
if (isNaN(parsed)) {
|
||||
if (Number.isNaN(parsed)) {
|
||||
throw new Error('Not number');
|
||||
}
|
||||
|
||||
profile.properties = assocPath(
|
||||
property.split('.'),
|
||||
parsed - (value || 1),
|
||||
profile.properties
|
||||
profile.properties,
|
||||
);
|
||||
|
||||
await upsertProfile({
|
||||
|
||||
@@ -33,7 +33,7 @@ export async function clerkWebhook(
|
||||
request: FastifyRequest<{
|
||||
Body: WebhookEvent;
|
||||
}>,
|
||||
reply: FastifyReply
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
const payload = request.body;
|
||||
const verified = verify(payload, request.headers);
|
||||
@@ -49,7 +49,7 @@ export async function clerkWebhook(
|
||||
if (!email) {
|
||||
return Response.json(
|
||||
{ message: 'No email address found' },
|
||||
{ status: 400 }
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user