surrge 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +403 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +53 -0
- package/dist/collector.d.ts +8 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/dashboard/html.d.ts +2 -0
- package/dist/dashboard/html.d.ts.map +1 -0
- package/dist/dashboard/index.d.ts +3 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +140 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10874 -0
- package/dist/instrumentation/console.d.ts +2 -0
- package/dist/instrumentation/console.d.ts.map +1 -0
- package/dist/instrumentation/errors.d.ts +2 -0
- package/dist/instrumentation/errors.d.ts.map +1 -0
- package/dist/instrumentation/fetch.d.ts +2 -0
- package/dist/instrumentation/fetch.d.ts.map +1 -0
- package/dist/instrumentation/index.d.ts +2 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/stdout.d.ts +2 -0
- package/dist/instrumentation/stdout.d.ts.map +1 -0
- package/dist/loader.d.ts +3 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +10987 -0
- package/dist/metrics.d.ts +3 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/patch/bun.d.ts +2 -0
- package/dist/patch/bun.d.ts.map +1 -0
- package/dist/patch/node.d.ts +2 -0
- package/dist/patch/node.d.ts.map +1 -0
- package/dist/patch/utils.d.ts +6 -0
- package/dist/patch/utils.d.ts.map +1 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +10869 -0
- package/dist/storage/db.d.ts +72 -0
- package/dist/storage/db.d.ts.map +1 -0
- package/dist/storage/schema.d.ts +3 -0
- package/dist/storage/schema.d.ts.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Client } from "@libsql/client";
|
|
2
|
+
export type Log = {
|
|
3
|
+
id: number;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
level: string;
|
|
6
|
+
message: string;
|
|
7
|
+
metadata: string | null;
|
|
8
|
+
};
|
|
9
|
+
export type Request = {
|
|
10
|
+
id: number;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
method: string;
|
|
13
|
+
url: string;
|
|
14
|
+
status: number | null;
|
|
15
|
+
duration: number | null;
|
|
16
|
+
direction: "in" | "out";
|
|
17
|
+
};
|
|
18
|
+
export type Error = {
|
|
19
|
+
id: number;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
message: string;
|
|
22
|
+
stack: string | null;
|
|
23
|
+
fingerprint: string;
|
|
24
|
+
};
|
|
25
|
+
export type PageView = {
|
|
26
|
+
id: number;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
path: string;
|
|
29
|
+
referrer: string | null;
|
|
30
|
+
visitor_id: string | null;
|
|
31
|
+
country: string | null;
|
|
32
|
+
device: string | null;
|
|
33
|
+
browser: string | null;
|
|
34
|
+
};
|
|
35
|
+
export type Metric = {
|
|
36
|
+
id: number;
|
|
37
|
+
timestamp: number;
|
|
38
|
+
memory_rss: number | null;
|
|
39
|
+
memory_heap: number | null;
|
|
40
|
+
cpu_user: number | null;
|
|
41
|
+
cpu_system: number | null;
|
|
42
|
+
event_loop_lag: number | null;
|
|
43
|
+
load_avg: number | null;
|
|
44
|
+
};
|
|
45
|
+
export declare const init: (path?: string) => Client;
|
|
46
|
+
export declare const reset: () => void;
|
|
47
|
+
export declare const db: () => Client;
|
|
48
|
+
export declare const insertLog: (log: Omit<Log, "id">) => void;
|
|
49
|
+
export declare const recentLogs: (limit?: number) => Promise<Log[]>;
|
|
50
|
+
export declare const insertRequest: (request: Omit<Request, "id">) => void;
|
|
51
|
+
export declare const recentRequests: (limit?: number) => Promise<Request[]>;
|
|
52
|
+
export declare const insertError: (error: Omit<Error, "id">) => void;
|
|
53
|
+
export declare const recentErrors: (limit?: number) => Promise<Error[]>;
|
|
54
|
+
export declare const insertPageView: (view: Omit<PageView, "id">) => void;
|
|
55
|
+
export declare const recentPageViews: (limit?: number) => Promise<PageView[]>;
|
|
56
|
+
export declare const insertMetric: (metric: Omit<Metric, "id">) => void;
|
|
57
|
+
export declare const recentMetrics: (limit?: number) => Promise<Metric[]>;
|
|
58
|
+
export type Analytics = {
|
|
59
|
+
totalViews: number;
|
|
60
|
+
uniqueVisitors: number;
|
|
61
|
+
topPaths: {
|
|
62
|
+
path: string;
|
|
63
|
+
count: number;
|
|
64
|
+
}[];
|
|
65
|
+
topReferrers: {
|
|
66
|
+
referrer: string;
|
|
67
|
+
count: number;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
70
|
+
export declare const analytics: () => Promise<Analytics>;
|
|
71
|
+
export declare const cleanup: () => Promise<void>;
|
|
72
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/storage/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,gBAAgB,CAAC;AAI3D,MAAM,MAAM,GAAG,GAAG;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,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3 @@
|
|
|
1
|
+
export declare const SCHEMA = "\n-- Logs (7 days rolling)\nCREATE TABLE IF NOT EXISTS logs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp INTEGER NOT NULL,\n level TEXT NOT NULL,\n message TEXT NOT NULL,\n metadata TEXT\n);\n\n-- HTTP Requests (7 days rolling)\nCREATE TABLE IF NOT EXISTS requests (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp INTEGER NOT NULL,\n method TEXT NOT NULL,\n url TEXT NOT NULL,\n status INTEGER,\n duration INTEGER,\n direction TEXT NOT NULL DEFAULT 'in'\n);\n\n-- Errors (7 days rolling)\nCREATE TABLE IF NOT EXISTS errors (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp INTEGER NOT NULL,\n message TEXT NOT NULL,\n stack TEXT,\n fingerprint TEXT NOT NULL\n);\n\n-- Page Views (7 days rolling)\nCREATE TABLE IF NOT EXISTS page_views (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp INTEGER NOT NULL,\n path TEXT NOT NULL,\n referrer TEXT,\n visitor_id TEXT,\n country TEXT,\n device TEXT,\n browser TEXT\n);\n\n-- Server Metrics (7 days rolling)\nCREATE TABLE IF NOT EXISTS server_metrics (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n timestamp INTEGER NOT NULL,\n memory_rss INTEGER,\n memory_heap INTEGER,\n cpu_user INTEGER,\n cpu_system INTEGER,\n event_loop_lag REAL,\n load_avg REAL\n);\n\n-- Indexes for common queries\nCREATE INDEX IF NOT EXISTS idx_logs_timestamp ON logs(timestamp);\nCREATE INDEX IF NOT EXISTS idx_requests_timestamp ON requests(timestamp);\nCREATE INDEX IF NOT EXISTS idx_errors_timestamp ON errors(timestamp);\nCREATE INDEX IF NOT EXISTS idx_errors_fingerprint ON errors(fingerprint);\nCREATE INDEX IF NOT EXISTS idx_page_views_timestamp ON page_views(timestamp);\nCREATE INDEX IF NOT EXISTS idx_page_views_path ON page_views(path);\nCREATE INDEX IF NOT EXISTS idx_server_metrics_timestamp ON server_metrics(timestamp);\n";
|
|
2
|
+
export declare const RETENTION_DAYS = 7;
|
|
3
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/storage/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,mxDA8DlB,CAAC;AAEF,eAAO,MAAM,cAAc,IAAI,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "surrge",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "One-line observability + analytics for Node.js/Bun",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./register": {
|
|
12
|
+
"types": "./dist/register.d.ts",
|
|
13
|
+
"import": "./dist/register.js"
|
|
14
|
+
},
|
|
15
|
+
"./loader": {
|
|
16
|
+
"types": "./dist/loader.d.ts",
|
|
17
|
+
"import": "./dist/loader.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"surrge": "./dist/cli.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"preuninstall": "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
|
|
30
|
+
"build": "bun run build:dashboard && bun run build:bundle && bun run build:types",
|
|
31
|
+
"build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
|
|
32
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
33
|
+
"build:dashboard": "cd src/dashboard/ui && bun run build.ts",
|
|
34
|
+
"dev:dashboard": "cd src/dashboard/ui && bun run dev",
|
|
35
|
+
"dev": "bun --watch src/index.ts",
|
|
36
|
+
"test": "bun test",
|
|
37
|
+
"check": "tsc --noEmit",
|
|
38
|
+
"lint": "biome check --write .",
|
|
39
|
+
"prepublishOnly": "bun run check && bun test && bun run build",
|
|
40
|
+
"push": "npm publish",
|
|
41
|
+
"db": "./bin/db.sh"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@libsql/client": "^0.14.0",
|
|
45
|
+
"hono": "^4.6.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@biomejs/biome": "^2.3.10",
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"bun-types": "^1.3.5",
|
|
51
|
+
"express": "^5.2.1",
|
|
52
|
+
"typescript": "^5.7.0"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"observability",
|
|
56
|
+
"analytics",
|
|
57
|
+
"logging",
|
|
58
|
+
"monitoring",
|
|
59
|
+
"metrics",
|
|
60
|
+
"tracing",
|
|
61
|
+
"sqlite",
|
|
62
|
+
"embedded",
|
|
63
|
+
"bun",
|
|
64
|
+
"nodejs"
|
|
65
|
+
],
|
|
66
|
+
"license": "MIT",
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18.0.0"
|
|
69
|
+
},
|
|
70
|
+
"repository": {
|
|
71
|
+
"type": "git",
|
|
72
|
+
"url": "git+https://github.com/blakbelt78/surrge.git"
|
|
73
|
+
},
|
|
74
|
+
"homepage": "https://github.com/blakbelt78/surrge#readme",
|
|
75
|
+
"bugs": {
|
|
76
|
+
"url": "https://github.com/blakbelt78/surrge/issues"
|
|
77
|
+
},
|
|
78
|
+
"author": "blakbelt78",
|
|
79
|
+
"sideEffects": [
|
|
80
|
+
"./dist/register.js",
|
|
81
|
+
"./dist/loader.js",
|
|
82
|
+
"./dist/hooks.js"
|
|
83
|
+
]
|
|
84
|
+
}
|