next-plugin-agent-tail 0.0.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.
@@ -0,0 +1,24 @@
1
+ //#region src/handler.d.ts
2
+ /**
3
+ * Next.js App Router API route handler.
4
+ *
5
+ * Usage in app/api/__browser-logs/route.ts:
6
+ * export { POST } from "next-plugin-browser-logs/handler"
7
+ */
8
+ declare function POST(request: Request): Promise<Response>;
9
+ /**
10
+ * Pages Router API route handler.
11
+ *
12
+ * Usage in pages/api/__browser-logs.ts:
13
+ * export default pages_handler
14
+ */
15
+ declare function pages_handler(req: {
16
+ method?: string;
17
+ body?: any;
18
+ }, res: {
19
+ status: (code: number) => {
20
+ end: () => void;
21
+ };
22
+ }): void;
23
+ //#endregion
24
+ export { POST, pages_handler };
@@ -0,0 +1,46 @@
1
+ import { format_log_line } from "agent-tail-core";
2
+ import fs from "node:fs";
3
+
4
+ //#region src/handler.ts
5
+ /**
6
+ * Next.js App Router API route handler.
7
+ *
8
+ * Usage in app/api/__browser-logs/route.ts:
9
+ * export { POST } from "next-plugin-browser-logs/handler"
10
+ */
11
+ async function POST(request) {
12
+ const log_path = process.env.__BROWSER_LOGS_PATH;
13
+ if (!log_path) return new Response("Browser logs not configured", { status: 500 });
14
+ try {
15
+ const lines = (await request.json()).map(format_log_line).join("");
16
+ fs.appendFileSync(log_path, lines);
17
+ return new Response(null, { status: 204 });
18
+ } catch {
19
+ return new Response(null, { status: 204 });
20
+ }
21
+ }
22
+ /**
23
+ * Pages Router API route handler.
24
+ *
25
+ * Usage in pages/api/__browser-logs.ts:
26
+ * export default pages_handler
27
+ */
28
+ function pages_handler(req, res) {
29
+ if (req.method !== "POST") {
30
+ res.status(405).end();
31
+ return;
32
+ }
33
+ const log_path = process.env.__BROWSER_LOGS_PATH;
34
+ if (!log_path) {
35
+ res.status(500).end();
36
+ return;
37
+ }
38
+ try {
39
+ const lines = (typeof req.body === "string" ? JSON.parse(req.body) : req.body).map(format_log_line).join("");
40
+ fs.appendFileSync(log_path, lines);
41
+ } catch {}
42
+ res.status(204).end();
43
+ }
44
+
45
+ //#endregion
46
+ export { POST, pages_handler };
@@ -0,0 +1,13 @@
1
+ import { POST, pages_handler } from "./handler.mjs";
2
+ import { BrowserLogsScript } from "./script.mjs";
3
+ import { BrowserLogsOptions, BrowserLogsOptions as BrowserLogsOptions$1, DEFAULT_OPTIONS, LogEntry, ResolvedOptions } from "agent-tail-core";
4
+
5
+ //#region src/with-browser-logs.d.ts
6
+ interface NextConfig {
7
+ env?: Record<string, string>;
8
+ webpack?: (config: any, context: any) => any;
9
+ [key: string]: any;
10
+ }
11
+ declare function with_browser_logs(next_config?: NextConfig, user_options?: BrowserLogsOptions$1): NextConfig;
12
+ //#endregion
13
+ export { type BrowserLogsOptions, BrowserLogsScript, DEFAULT_OPTIONS, type LogEntry, POST, type ResolvedOptions, pages_handler, with_browser_logs };
package/dist/index.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { BrowserLogsScript } from "./script.mjs";
2
+ import { POST, pages_handler } from "./handler.mjs";
3
+ import { DEFAULT_OPTIONS, LogManager, resolve_options } from "agent-tail-core";
4
+
5
+ //#region src/with-browser-logs.ts
6
+ function with_browser_logs(next_config = {}, user_options) {
7
+ const options = resolve_options(user_options);
8
+ const log_manager = new LogManager(options);
9
+ const project_root = process.cwd();
10
+ const log_path = log_manager.initialize(project_root);
11
+ return {
12
+ ...next_config,
13
+ env: {
14
+ ...next_config.env,
15
+ __BROWSER_LOGS_ENDPOINT: options.endpoint,
16
+ __BROWSER_LOGS_PATH: log_path
17
+ },
18
+ webpack(config, context) {
19
+ if (typeof next_config.webpack === "function") config = next_config.webpack(config, context);
20
+ return config;
21
+ }
22
+ };
23
+ }
24
+
25
+ //#endregion
26
+ export { BrowserLogsScript, DEFAULT_OPTIONS, POST, pages_handler, with_browser_logs };
@@ -0,0 +1,29 @@
1
+ import { BrowserLogsOptions } from "agent-tail-core";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
+
4
+ //#region src/script.d.ts
5
+ interface BrowserLogsScriptProps {
6
+ options?: BrowserLogsOptions;
7
+ }
8
+ /**
9
+ * React component that injects the browser log capture script.
10
+ *
11
+ * Usage in app/layout.tsx:
12
+ * import { BrowserLogsScript } from "next-plugin-browser-logs/script"
13
+ *
14
+ * export default function RootLayout({ children }) {
15
+ * return (
16
+ * <html>
17
+ * <head>
18
+ * {process.env.NODE_ENV === "development" && <BrowserLogsScript />}
19
+ * </head>
20
+ * <body>{children}</body>
21
+ * </html>
22
+ * )
23
+ * }
24
+ */
25
+ declare function BrowserLogsScript({
26
+ options: user_options
27
+ }?: BrowserLogsScriptProps): react_jsx_runtime0.JSX.Element;
28
+ //#endregion
29
+ export { BrowserLogsScript };
@@ -0,0 +1,31 @@
1
+ import { generate_client_script, resolve_options } from "agent-tail-core";
2
+ import "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/script.tsx
6
+ /**
7
+ * React component that injects the browser log capture script.
8
+ *
9
+ * Usage in app/layout.tsx:
10
+ * import { BrowserLogsScript } from "next-plugin-browser-logs/script"
11
+ *
12
+ * export default function RootLayout({ children }) {
13
+ * return (
14
+ * <html>
15
+ * <head>
16
+ * {process.env.NODE_ENV === "development" && <BrowserLogsScript />}
17
+ * </head>
18
+ * <body>{children}</body>
19
+ * </html>
20
+ * )
21
+ * }
22
+ */
23
+ function BrowserLogsScript({ options: user_options } = {}) {
24
+ return /* @__PURE__ */ jsx("script", {
25
+ dangerouslySetInnerHTML: { __html: generate_client_script(resolve_options(user_options)) },
26
+ suppressHydrationWarning: true
27
+ });
28
+ }
29
+
30
+ //#endregion
31
+ export { BrowserLogsScript };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "next-plugin-agent-tail",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "Next.js plugin for agent-tail — pipes browser console logs to files on disk during development.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/gillkyle/agent-tail",
10
+ "directory": "packages/next-plugin"
11
+ },
12
+ "author": "Kyle Gill",
13
+ "keywords": ["next", "nextjs", "browser-logs", "console", "logging"],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mts"
18
+ },
19
+ "./handler": {
20
+ "import": "./dist/handler.mjs",
21
+ "types": "./dist/handler.d.mts"
22
+ },
23
+ "./script": {
24
+ "import": "./dist/script.mjs",
25
+ "types": "./dist/script.d.mts"
26
+ }
27
+ },
28
+ "main": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts",
30
+ "files": ["dist"],
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "typecheck": "tsc --noEmit"
34
+ },
35
+ "dependencies": {
36
+ "agent-tail-core": "workspace:*"
37
+ },
38
+ "peerDependencies": {
39
+ "next": ">=13.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "next": "^15.0.0",
43
+ "tsdown": "^0.18.1",
44
+ "react": "^19.0.0",
45
+ "@types/react": "^19.0.0"
46
+ }
47
+ }