Skip to content

Commit

Permalink
Merge pull request #16 from mashafrancis/main
Browse files Browse the repository at this point in the history
chore: upgrade packages
  • Loading branch information
mashafrancis authored Apr 29, 2024
2 parents 2385cd9 + 16bc9c1 commit 54dfb02
Show file tree
Hide file tree
Showing 51 changed files with 18,957 additions and 13,369 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ prefer-workspace-packages=true

strict-peer-dependencies=false
auto-install-peers=true
public-hoist-pattern[]=*libsql*
46 changes: 23 additions & 23 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
"types": "src/index/ts",
"type": "module",
"dependencies": {
"@clickhouse/client": "^0.2.2",
"@clickhouse/client-web": "^0.2.2",
"@heimdall-logs/clickhouse": "0.0.1",
"@heimdall-logs/db": "0.0.1",
"@heimdall-logs/logger": "0.0.1",
"@hono/node-server": "^1.2.0",
"@libsql/client": "^0.3.5",
"@t3-oss/env-core": "^0.6.1",
"@types/request-ip": "^0.0.39",
"@types/tar": "^6.1.6",
"@vercel/kv": "^0.2.3",
"@clickhouse/client": "^1.0.1",
"@clickhouse/client-web": "^1.0.1",
"@heimdall-logs/clickhouse": "workspace:*",
"@heimdall-logs/db": "workspace:*",
"@heimdall-logs/logger": "workspace:*",
"@hono/node-server": "^1.3.1",
"@libsql/client": "0.4.0-pre.5",
"@t3-oss/env-core": "^0.7.1",
"@types/request-ip": "^0.0.41",
"@types/tar": "^6.1.13",
"@vercel/kv": "^1.0.1",
"detect-browser": "^5.3.0",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.28.6",
"hono": "^3.7.3",
"isbot": "^3.7.0",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.30.9",
"hono": "^3.11.2",
"isbot": "^5.1.6",
"jsonwebtoken": "^9.0.2",
"kafkajs": "^2.2.4",
"kysely": "^0.26.3",
"kysely": "^0.27.3",
"kysely-planetscale": "^1.4.0",
"maxmind": "^4.3.14",
"ora": "^7.0.1",
"maxmind": "^4.3.18",
"ora": "^8.0.1",
"request-ip": "^3.3.0",
"tar": "^6.2.0",
"tsx": "^3.13.0",
"zod": "^3.22.2"
"tar": "^7.0.1",
"tsx": "^4.7.3",
"zod": "^3.23.4"
},
"devDependencies": {
"@heimdall-logs/types": "0.0.1",
"@types/jsonwebtoken": "^9.0.3"
"@heimdall-logs/types": "workspace:*",
"@types/jsonwebtoken": "^9.0.6"
},
"exports": {
".": {
Expand Down
17 changes: 10 additions & 7 deletions apps/api/src/db/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const hitsQuery = (
JSONExtract(properties, 'os', 'String') as os,
event,
timestamp
from heimdall_logs.event
from default.event
WHERE ${
startDate && `timestamp >= '${startDate}' AND`
} timestamp <= '${endDate}' AND websiteId = '${websiteId}' AND event = 'hits'`;
Expand All @@ -39,7 +39,7 @@ export const customEventsQuery = (
websiteId: string
) =>
`select *
from heimdall_logs.event
from default.event
WHERE timestamp >= '${startDate}'
AND timestamp <= '${endDate}'
AND websiteId = '${websiteId}'
Expand All @@ -50,19 +50,22 @@ export const tracesQuery = (
endDate: string,
websiteId: string
) =>
`select *
from heimdall_logs.otel_traces
`SELECT *
FROM default.otel_traces
WHERE Timestamp >= '${startDate}'
AND Timestamp <= '${endDate}'
AND ServiceName = '${websiteId}'
AND SpanName != 'click'
ORDER BY Timestamp DESC
LIMIT 100`;

export const dummyTracesQuery = (startDate: string, endDate: string) =>
`select *
from heimdall_logs.demo_otel_traces
from default.demo_otel_traces
WHERE Timestamp >= '${startDate}'
AND Timestamp <= '${endDate}'
LIMIT 1000`;
ORDER BY Timestamp DESC
LIMIT 50`;

const createEvent = () => {
return async ({
Expand Down Expand Up @@ -124,7 +127,7 @@ const createEvent = () => {
} else {
await client
.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: [value],
format: 'JSONEachRow',
})
Expand Down
1 change: 0 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ app.get('/', async (c) => {
if (err) {
throw err;
}
//@ts-expect-error
if (decoded.website !== websiteId) {
throw Error;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const createEvents: RouteType = async ({ rawBody, req }) => {
events.map(async (event) => {
await client
.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: {
id: event.id,
sessionId,
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/routes/pageview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createPageview: RouteType = async ({ rawBody, req }) => {
const session = await client
.query({
query: `select *
from heimdall_logs.event
from default.event
where sessionId = '${sessionId}'
limit 1`,
format: 'JSONEachRow',
Expand All @@ -48,7 +48,7 @@ export const createPageview: RouteType = async ({ rawBody, req }) => {
const referrerDomain = properties.referrerDomain ?? 'unknown';
try {
await client.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: [
{
id: pageId,
Expand Down Expand Up @@ -106,7 +106,7 @@ export const updatePageDuration: RouteType = async ({ rawBody }) => {
const query = await client
.query({
query: `select *
from heimdall_logs.event
from default.event
where id = '${pageId}'`,
format: 'JSONEachRow',
})
Expand All @@ -120,7 +120,7 @@ export const updatePageDuration: RouteType = async ({ rawBody }) => {
try {
await client
.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: [
{
...pageview,
Expand All @@ -132,7 +132,7 @@ export const updatePageDuration: RouteType = async ({ rawBody }) => {
.catch((e) => console.log(e));
await client
.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: [
{
...pageview,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const createSession: RouteType = async ({ req, rawBody }) => {
const device = os ? getDevice(screenWidth, os) ?? 'desktop' : 'unknown';
await client
.insert({
table: 'heimdall_logs.event',
table: 'default.event',
values: [
{
id: pageId,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createVisitor: RouteType = async ({ rawBody }) => {
try {
const { websiteId, id, data } = body.data;
await client.insert({
table: 'heimdall_logs.visitor',
table: 'default.visitor',
values: {
id,
identifiedId: data.identifiedId ?? id,
Expand Down
89 changes: 89 additions & 0 deletions apps/web/components/dashboard/speed-insight/chart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { useIsMobile } from "@/hooks/use-viewport";
import { LucideIcon } from "lucide-react";
import { Bar, BarChart, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
import { Stat } from "./stats";

export const SpeedChart = ({
data,
Icon,
activeStat,
bar,
isLoading
}: { data?: { date: string; value: string }[]; Icon: LucideIcon; activeStat: Stat, bar: boolean, isLoading: boolean }) => {
const isMobile = useIsMobile()
const ParentDiv = bar ? BarChart : LineChart;
return (
<ResponsiveContainer width="100%" height={isMobile ? 250 : 400} className=" rounded-lg">
{!data?.length ?
<div className=" flex flex-col justify-center gap-2">
<div className="text-2xl font-bold text-center ">
{isLoading ? (
<p className=" text-sm font-medium italic">hmm loading...</p>
) : (
<>
<p>No Data Just Yet</p>
<p className=" text-sm font-light">
if you haven`&apos;t setup tracker refer to the{" "}
<a
href="https://loglib.io/docs"
target="_blank"
className=" text-blue-700 underline"
rel="noreferrer"
>
docs{" "}
</a>
how to do that.
</p>
</>
)}
</div>
</div>
: <ParentDiv data={data}>
{bar ? (
<Bar dataKey="value" fill="#1b1917" />
) : (
<Line dataKey="value" fill="#fff" label={activeStat.name} stroke="#494141" />
)}
<XAxis
dataKey="date"
stroke="#888888"
fontSize={12}
tickLine={false}
axisLine={false}
/>
<YAxis
stroke="#888888"
interval="preserveStartEnd"
fontSize={12}
tickLine={false}
width={10}
axisLine={false}
tickMargin={0}
/>
<Tooltip
contentStyle={{
backgroundColor: "black",
borderRadius: "10px",
color: "black",
}}
label="visitors"
cursor={false}
content={({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip dark:bg-black bg-white/10 px-2 border rounded-md border-gray-700 py-2">
<div className=" flex items-center gap-2 dark:text-emphasis text-black">
<Icon size={16} />
<p className=" font-medium">{`${activeStat.formatter(payload[0]?.value as number)}`}</p>
</div>
<p className="text-gray-400 text-sm">{label}</p>
</div>
);
}
return null;
}}
/>
</ParentDiv>}
</ResponsiveContainer>
);
};
Loading

0 comments on commit 54dfb02

Please sign in to comment.