@vestig/next 0.3.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/README.md +290 -0
- package/dist/client/hooks.d.ts +95 -0
- package/dist/client/hooks.d.ts.map +1 -0
- package/dist/client/hooks.js +128 -0
- package/dist/client/hooks.js.map +1 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +9 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/provider.d.ts +66 -0
- package/dist/client/provider.d.ts.map +1 -0
- package/dist/client/provider.js +126 -0
- package/dist/client/provider.js.map +1 -0
- package/dist/client/transport.d.ts +59 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +148 -0
- package/dist/client/transport.js.map +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +47 -0
- package/dist/client.js.map +1 -0
- package/dist/config/defaults.d.ts +10 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +72 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +116 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +27 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +21 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +31 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/route/handler.d.ts +56 -0
- package/dist/route/handler.d.ts.map +1 -0
- package/dist/route/handler.js +250 -0
- package/dist/route/handler.js.map +1 -0
- package/dist/route/index.d.ts +2 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +3 -0
- package/dist/route/index.js.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +10 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/middleware.d.ts +108 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/middleware.js +182 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/route-handler.d.ts +93 -0
- package/dist/server/route-handler.d.ts.map +1 -0
- package/dist/server/route-handler.js +160 -0
- package/dist/server/route-handler.js.map +1 -0
- package/dist/server/server-action.d.ts +74 -0
- package/dist/server/server-action.d.ts.map +1 -0
- package/dist/server/server-action.js +132 -0
- package/dist/server/server-action.js.map +1 -0
- package/dist/server/server-component.d.ts +87 -0
- package/dist/server/server-component.d.ts.map +1 -0
- package/dist/server/server-component.js +122 -0
- package/dist/server/server-component.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/headers.d.ts +38 -0
- package/dist/utils/headers.d.ts.map +1 -0
- package/dist/utils/headers.js +42 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/metadata.d.ts +41 -0
- package/dist/utils/metadata.d.ts.map +1 -0
- package/dist/utils/metadata.js +46 -0
- package/dist/utils/metadata.js.map +1 -0
- package/dist/utils/timing.d.ts +31 -0
- package/dist/utils/timing.d.ts.map +1 -0
- package/dist/utils/timing.js +46 -0
- package/dist/utils/timing.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define vestig configuration with type safety
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // vestig.config.ts
|
|
7
|
+
* import { defineConfig } from '@vestig/next/config'
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* level: 'debug',
|
|
11
|
+
* sanitize: 'gdpr',
|
|
12
|
+
* next: {
|
|
13
|
+
* endpoint: '/api/vestig',
|
|
14
|
+
* middleware: {
|
|
15
|
+
* timing: true,
|
|
16
|
+
* },
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function defineConfig(config) {
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
// Re-export from loader for convenience
|
|
25
|
+
export { loadConfig, getConfig } from './loader';
|
|
26
|
+
export { getDefaultConfig } from './defaults';
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAoGA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAAC,MAAwB;IACpD,OAAO,MAAM,CAAA;AACd,CAAC;AAED,wCAAwC;AACxC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VestigNextConfig } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* Set global configuration
|
|
4
|
+
* This should be called once at app startup if you want to override defaults
|
|
5
|
+
*/
|
|
6
|
+
export declare function setConfig(config: Partial<VestigNextConfig>): void;
|
|
7
|
+
/**
|
|
8
|
+
* Get current configuration
|
|
9
|
+
* Returns cached config or defaults
|
|
10
|
+
*/
|
|
11
|
+
export declare function getConfig(): VestigNextConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Clear cached configuration (useful for testing)
|
|
14
|
+
*/
|
|
15
|
+
export declare function clearConfigCache(): void;
|
|
16
|
+
/**
|
|
17
|
+
* Load configuration - returns cached or default config
|
|
18
|
+
* This is a sync version for compatibility
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadConfig(): Promise<VestigNextConfig>;
|
|
21
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAEjE;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,gBAAgB,CAE5C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;GAGG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAE5D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { deepMerge, getDefaultConfig } from './defaults';
|
|
2
|
+
// Module-level cached config (set once during app initialization)
|
|
3
|
+
let cachedConfig = null;
|
|
4
|
+
/**
|
|
5
|
+
* Set global configuration
|
|
6
|
+
* This should be called once at app startup if you want to override defaults
|
|
7
|
+
*/
|
|
8
|
+
export function setConfig(config) {
|
|
9
|
+
cachedConfig = deepMerge(getDefaultConfig(), config);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get current configuration
|
|
13
|
+
* Returns cached config or defaults
|
|
14
|
+
*/
|
|
15
|
+
export function getConfig() {
|
|
16
|
+
return cachedConfig ?? getDefaultConfig();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Clear cached configuration (useful for testing)
|
|
20
|
+
*/
|
|
21
|
+
export function clearConfigCache() {
|
|
22
|
+
cachedConfig = null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load configuration - returns cached or default config
|
|
26
|
+
* This is a sync version for compatibility
|
|
27
|
+
*/
|
|
28
|
+
export async function loadConfig() {
|
|
29
|
+
return getConfig();
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGxD,kEAAkE;AAClE,IAAI,YAAY,GAA4B,IAAI,CAAA;AAEhD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,MAAiC;IAC1D,YAAY,GAAG,SAAS,CAAC,gBAAgB,EAAE,EAAE,MAAM,CAAC,CAAA;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS;IACxB,OAAO,YAAY,IAAI,gBAAgB,EAAE,CAAA;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC/B,YAAY,GAAG,IAAI,CAAA;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC/B,OAAO,SAAS,EAAE,CAAA;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vestig/next - First-class Next.js 15+ integration for vestig logging
|
|
3
|
+
*
|
|
4
|
+
* @example Server Components
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { getLogger } from '@vestig/next'
|
|
7
|
+
*
|
|
8
|
+
* export default async function Page() {
|
|
9
|
+
* const log = await getLogger('my-page')
|
|
10
|
+
* log.info('Rendering page')
|
|
11
|
+
* return <div>Hello</div>
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Route Handlers
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { withVestig } from '@vestig/next'
|
|
18
|
+
*
|
|
19
|
+
* export const GET = withVestig(async (req, { log }) => {
|
|
20
|
+
* log.info('Handling request')
|
|
21
|
+
* return Response.json({ ok: true })
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Server Actions
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { vestigAction } from '@vestig/next'
|
|
28
|
+
*
|
|
29
|
+
* export const createUser = vestigAction(async (data, { log }) => {
|
|
30
|
+
* log.info('Creating user')
|
|
31
|
+
* return await db.users.create({ data })
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
export { getLogger, getRequestContext, createChildLogger } from './server/server-component';
|
|
38
|
+
export { withVestig, createRouteHandlers } from './server/route-handler';
|
|
39
|
+
export { vestigAction, createVestigAction } from './server/server-action';
|
|
40
|
+
export type { Logger, LoggerConfig, LogLevel, LogEntry, LogMetadata, LogContext, Transport, SanitizePreset, SanitizeConfig, RouteHandlerContext, RouteHandler, WithVestigOptions, ActionContext, ServerAction, VestigActionOptions, VestigProviderProps, } from './types';
|
|
41
|
+
export type { VestigNextConfig, VestigNextOptions, VestigNextMiddlewareConfig, VestigNextServerConfig, VestigNextClientConfig, VestigNextDevToolsConfig, } from './config';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAG3F,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAGxE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAGzE,YAAY,EAEX,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,cAAc,EAEd,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,GACnB,MAAM,SAAS,CAAA;AAGhB,YAAY,EACX,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,GACxB,MAAM,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vestig/next - First-class Next.js 15+ integration for vestig logging
|
|
3
|
+
*
|
|
4
|
+
* @example Server Components
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { getLogger } from '@vestig/next'
|
|
7
|
+
*
|
|
8
|
+
* export default async function Page() {
|
|
9
|
+
* const log = await getLogger('my-page')
|
|
10
|
+
* log.info('Rendering page')
|
|
11
|
+
* return <div>Hello</div>
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Route Handlers
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { withVestig } from '@vestig/next'
|
|
18
|
+
*
|
|
19
|
+
* export const GET = withVestig(async (req, { log }) => {
|
|
20
|
+
* log.info('Handling request')
|
|
21
|
+
* return Response.json({ ok: true })
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Server Actions
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { vestigAction } from '@vestig/next'
|
|
28
|
+
*
|
|
29
|
+
* export const createUser = vestigAction(async (data, { log }) => {
|
|
30
|
+
* log.info('Creating user')
|
|
31
|
+
* return await db.users.create({ data })
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
// Server Components
|
|
38
|
+
export { getLogger, getRequestContext, createChildLogger } from './server/server-component';
|
|
39
|
+
// Route Handlers
|
|
40
|
+
export { withVestig, createRouteHandlers } from './server/route-handler';
|
|
41
|
+
// Server Actions
|
|
42
|
+
export { vestigAction, createVestigAction } from './server/server-action';
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE3F,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAExE,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type LogEntry } from 'vestig';
|
|
2
|
+
/**
|
|
3
|
+
* Options for createVestigHandler
|
|
4
|
+
*/
|
|
5
|
+
export interface VestigHandlerOptions {
|
|
6
|
+
/** Max logs to keep in memory (default: 500) */
|
|
7
|
+
maxLogs?: number;
|
|
8
|
+
/** Enable SSE streaming (default: development only) */
|
|
9
|
+
enableSSE?: boolean;
|
|
10
|
+
/** Callback for custom log processing */
|
|
11
|
+
onLog?: (entry: LogEntry) => void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create vestig API route handlers
|
|
15
|
+
*
|
|
16
|
+
* Provides:
|
|
17
|
+
* - GET: SSE stream for real-time log viewing (dev only)
|
|
18
|
+
* - POST: Receive logs from client
|
|
19
|
+
* - DELETE: Clear log store (dev only)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // app/api/vestig/route.ts
|
|
24
|
+
* import { createVestigHandler } from '@vestig/next/route'
|
|
25
|
+
*
|
|
26
|
+
* export const { GET, POST, DELETE } = createVestigHandler()
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // With custom options
|
|
32
|
+
* export const { GET, POST, DELETE } = createVestigHandler({
|
|
33
|
+
* maxLogs: 1000,
|
|
34
|
+
* onLog: async (entry) => {
|
|
35
|
+
* // Send to external logging service
|
|
36
|
+
* await sendToDatadog(entry)
|
|
37
|
+
* },
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createVestigHandler(options?: VestigHandlerOptions): {
|
|
42
|
+
GET: (request: Request) => Promise<Response>;
|
|
43
|
+
POST: (request: Request) => Promise<Response>;
|
|
44
|
+
DELETE: () => Promise<Response>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Pre-configured route handlers for direct export
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // app/api/vestig/route.ts
|
|
52
|
+
* export { GET, POST, DELETE } from '@vestig/next/route'
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const GET: (request: Request) => Promise<Response>, POST: (request: Request) => Promise<Response>, DELETE: () => Promise<Response>;
|
|
56
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/route/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAA6B,MAAM,QAAQ,CAAA;AA2FjE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,yCAAyC;IACzC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB;mBAMzC,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;oBAyD1B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;kBA8E/B,OAAO,CAAC,QAAQ,CAAC;EAa1C;AAED;;;;;;;;GAQG;AACH,eAAO,MAAQ,GAAG,YA/JW,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,EA+JpC,IAAI,YAtGM,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,EAsG/B,MAAM,QAxBN,OAAO,CAAC,QAAQ,CAwBgB,CAAA"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createLogger } from 'vestig';
|
|
2
|
+
import { loadConfig } from '../config/loader';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory log store for SSE streaming (development only)
|
|
5
|
+
*/
|
|
6
|
+
class LogStore {
|
|
7
|
+
logs = [];
|
|
8
|
+
subscribers = new Set();
|
|
9
|
+
maxLogs;
|
|
10
|
+
constructor(maxLogs = 500) {
|
|
11
|
+
this.maxLogs = maxLogs;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Add a single log entry
|
|
15
|
+
*/
|
|
16
|
+
add(entry) {
|
|
17
|
+
// Ensure entry has an ID
|
|
18
|
+
const entryWithId = {
|
|
19
|
+
...entry,
|
|
20
|
+
id: entry.id ?? crypto.randomUUID(),
|
|
21
|
+
};
|
|
22
|
+
this.logs.push(entryWithId);
|
|
23
|
+
// Trim if over limit
|
|
24
|
+
if (this.logs.length > this.maxLogs) {
|
|
25
|
+
this.logs.shift();
|
|
26
|
+
}
|
|
27
|
+
// Notify subscribers
|
|
28
|
+
for (const callback of this.subscribers) {
|
|
29
|
+
try {
|
|
30
|
+
callback(entryWithId);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Subscriber may have errored, ignore
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Add multiple log entries
|
|
39
|
+
*/
|
|
40
|
+
addBatch(entries) {
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
this.add(entry);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Subscribe to new log entries
|
|
47
|
+
*/
|
|
48
|
+
subscribe(callback) {
|
|
49
|
+
this.subscribers.add(callback);
|
|
50
|
+
return () => this.subscribers.delete(callback);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get recent log entries
|
|
54
|
+
*/
|
|
55
|
+
getRecent(count = 50) {
|
|
56
|
+
return this.logs.slice(-count);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clear all logs
|
|
60
|
+
*/
|
|
61
|
+
clear() {
|
|
62
|
+
this.logs = [];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get total count
|
|
66
|
+
*/
|
|
67
|
+
get count() {
|
|
68
|
+
return this.logs.length;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Singleton log store
|
|
72
|
+
let logStore = null;
|
|
73
|
+
function getLogStore(maxLogs) {
|
|
74
|
+
if (!logStore) {
|
|
75
|
+
logStore = new LogStore(maxLogs);
|
|
76
|
+
}
|
|
77
|
+
return logStore;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create vestig API route handlers
|
|
81
|
+
*
|
|
82
|
+
* Provides:
|
|
83
|
+
* - GET: SSE stream for real-time log viewing (dev only)
|
|
84
|
+
* - POST: Receive logs from client
|
|
85
|
+
* - DELETE: Clear log store (dev only)
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // app/api/vestig/route.ts
|
|
90
|
+
* import { createVestigHandler } from '@vestig/next/route'
|
|
91
|
+
*
|
|
92
|
+
* export const { GET, POST, DELETE } = createVestigHandler()
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* // With custom options
|
|
98
|
+
* export const { GET, POST, DELETE } = createVestigHandler({
|
|
99
|
+
* maxLogs: 1000,
|
|
100
|
+
* onLog: async (entry) => {
|
|
101
|
+
* // Send to external logging service
|
|
102
|
+
* await sendToDatadog(entry)
|
|
103
|
+
* },
|
|
104
|
+
* })
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function createVestigHandler(options = {}) {
|
|
108
|
+
const store = getLogStore(options.maxLogs);
|
|
109
|
+
/**
|
|
110
|
+
* GET - SSE stream for real-time log viewing (development only)
|
|
111
|
+
*/
|
|
112
|
+
async function GET(request) {
|
|
113
|
+
const config = await loadConfig();
|
|
114
|
+
const enableSSE = options.enableSSE ?? config.next?.devTools?.enabled ?? false;
|
|
115
|
+
if (!enableSSE) {
|
|
116
|
+
return Response.json({ error: 'SSE streaming is disabled in production' }, { status: 403 });
|
|
117
|
+
}
|
|
118
|
+
const stream = new ReadableStream({
|
|
119
|
+
start(controller) {
|
|
120
|
+
const encoder = new TextEncoder();
|
|
121
|
+
// Send recent logs first
|
|
122
|
+
const recent = store.getRecent();
|
|
123
|
+
for (const entry of recent) {
|
|
124
|
+
try {
|
|
125
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify(entry)}\n\n`));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Stream may be closed
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Subscribe to new logs
|
|
132
|
+
const unsubscribe = store.subscribe((entry) => {
|
|
133
|
+
try {
|
|
134
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify(entry)}\n\n`));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Stream closed, cleanup
|
|
138
|
+
unsubscribe();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Handle client disconnect via abort signal
|
|
142
|
+
request.signal.addEventListener('abort', () => {
|
|
143
|
+
unsubscribe();
|
|
144
|
+
try {
|
|
145
|
+
controller.close();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// Already closed
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return new Response(stream, {
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'text/event-stream',
|
|
156
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
157
|
+
Connection: 'keep-alive',
|
|
158
|
+
'X-Accel-Buffering': 'no', // Disable nginx buffering
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* POST - Receive logs from client
|
|
164
|
+
*/
|
|
165
|
+
async function POST(request) {
|
|
166
|
+
try {
|
|
167
|
+
const body = await request.json();
|
|
168
|
+
// Support single entry or batch
|
|
169
|
+
const entries = Array.isArray(body.entries)
|
|
170
|
+
? body.entries
|
|
171
|
+
: body.entry
|
|
172
|
+
? [body.entry]
|
|
173
|
+
: [body];
|
|
174
|
+
// Validate entries
|
|
175
|
+
for (const entry of entries) {
|
|
176
|
+
if (!entry.timestamp || !entry.level || !entry.message) {
|
|
177
|
+
return Response.json({
|
|
178
|
+
error: 'Invalid log entry',
|
|
179
|
+
details: 'Each entry must have timestamp, level, and message',
|
|
180
|
+
}, { status: 400 });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Add to store
|
|
184
|
+
store.addBatch(entries);
|
|
185
|
+
// Call custom handler if provided
|
|
186
|
+
if (options.onLog) {
|
|
187
|
+
for (const entry of entries) {
|
|
188
|
+
try {
|
|
189
|
+
await options.onLog(entry);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.warn('[vestig] onLog handler error:', error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Also log to server if configured (re-emit client logs)
|
|
197
|
+
const config = await loadConfig();
|
|
198
|
+
if (config.next?.server) {
|
|
199
|
+
const serverLogger = createLogger({
|
|
200
|
+
level: config.level,
|
|
201
|
+
enabled: config.enabled,
|
|
202
|
+
sanitize: config.sanitize,
|
|
203
|
+
structured: config.next.server.structured,
|
|
204
|
+
namespace: 'client', // Mark as from client
|
|
205
|
+
});
|
|
206
|
+
for (const entry of entries) {
|
|
207
|
+
const method = entry.level;
|
|
208
|
+
if (typeof serverLogger[method] === 'function') {
|
|
209
|
+
;
|
|
210
|
+
serverLogger[method](entry.message, entry.metadata);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return Response.json({
|
|
215
|
+
success: true,
|
|
216
|
+
count: entries.length,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return Response.json({
|
|
221
|
+
error: 'Invalid request',
|
|
222
|
+
details: error instanceof Error ? error.message : 'Unknown error',
|
|
223
|
+
}, { status: 400 });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* DELETE - Clear log store (development only)
|
|
228
|
+
*/
|
|
229
|
+
async function DELETE() {
|
|
230
|
+
const config = await loadConfig();
|
|
231
|
+
const enableDelete = config.next?.devTools?.enabled ?? false;
|
|
232
|
+
if (!enableDelete) {
|
|
233
|
+
return Response.json({ error: 'Log clearing is disabled in production' }, { status: 403 });
|
|
234
|
+
}
|
|
235
|
+
store.clear();
|
|
236
|
+
return Response.json({ success: true });
|
|
237
|
+
}
|
|
238
|
+
return { GET, POST, DELETE };
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Pre-configured route handlers for direct export
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* // app/api/vestig/route.ts
|
|
246
|
+
* export { GET, POST, DELETE } from '@vestig/next/route'
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export const { GET, POST, DELETE } = createVestigHandler();
|
|
250
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/route/handler.ts"],"names":[],"mappings":"AAAA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AE,CAAA;QACb,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAC7B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAA6B,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getLogger, getRequestContext, createChildLogger } from './server-component';
|
|
2
|
+
export { withVestig, createRouteHandlers } from './route-handler';
|
|
3
|
+
export { vestigAction, createVestigAction } from './server-action';
|
|
4
|
+
export { vestigMiddleware, createVestigMiddleware, createMiddlewareMatcher } from './middleware';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAGpF,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAGjE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGlE,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Server-side exports for @vestig/next
|
|
2
|
+
// Server Components
|
|
3
|
+
export { getLogger, getRequestContext, createChildLogger } from './server-component';
|
|
4
|
+
// Route Handlers
|
|
5
|
+
export { withVestig, createRouteHandlers } from './route-handler';
|
|
6
|
+
// Server Actions
|
|
7
|
+
export { vestigAction, createVestigAction } from './server-action';
|
|
8
|
+
// Middleware (also available from @vestig/next/middleware)
|
|
9
|
+
export { vestigMiddleware, createVestigMiddleware, createMiddlewareMatcher } from './middleware';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,oBAAoB;AACpB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAEpF,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAEjE,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAElE,2DAA2D;AAC3D,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import type { NextRequest } from 'next/server';
|
|
3
|
+
import { type LogLevel, type SanitizePreset } from 'vestig';
|
|
4
|
+
export interface MiddlewareOptions {
|
|
5
|
+
/** Log level for the middleware logger */
|
|
6
|
+
level?: LogLevel;
|
|
7
|
+
/** Enable/disable logging */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/** PII sanitization preset */
|
|
10
|
+
sanitize?: SanitizePreset;
|
|
11
|
+
/** Namespace for middleware logs */
|
|
12
|
+
namespace?: string;
|
|
13
|
+
/** Paths to skip (prefix matching) */
|
|
14
|
+
skipPaths?: string[];
|
|
15
|
+
/** Custom header name for request ID */
|
|
16
|
+
requestIdHeader?: string;
|
|
17
|
+
/** Enable request/response timing logs */
|
|
18
|
+
timing?: boolean;
|
|
19
|
+
/** Log level for incoming requests */
|
|
20
|
+
requestLogLevel?: LogLevel;
|
|
21
|
+
/** Log level for outgoing responses */
|
|
22
|
+
responseLogLevel?: LogLevel;
|
|
23
|
+
/** Use structured JSON output */
|
|
24
|
+
structured?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create vestig middleware with custom configuration
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // middleware.ts
|
|
32
|
+
* import { createVestigMiddleware } from '@vestig/next/middleware'
|
|
33
|
+
*
|
|
34
|
+
* export const middleware = createVestigMiddleware({
|
|
35
|
+
* skipPaths: ['/health', '/metrics'],
|
|
36
|
+
* })
|
|
37
|
+
*
|
|
38
|
+
* export const config = {
|
|
39
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createVestigMiddleware(options?: MiddlewareOptions): (request: NextRequest) => NextResponse<unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Pre-configured vestig middleware for direct export (deprecated, use proxy instead)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // middleware.ts (deprecated in Next.js 16+)
|
|
50
|
+
* export { vestigMiddleware as middleware } from '@vestig/next/middleware'
|
|
51
|
+
*
|
|
52
|
+
* export const config = {
|
|
53
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
* @deprecated Use createVestigProxy for Next.js 16+
|
|
57
|
+
*/
|
|
58
|
+
export declare const vestigMiddleware: (request: NextRequest) => NextResponse<unknown>;
|
|
59
|
+
export type { MiddlewareOptions as ProxyOptions };
|
|
60
|
+
/**
|
|
61
|
+
* Create vestig proxy for Next.js 16+ (replaces middleware)
|
|
62
|
+
*
|
|
63
|
+
* In Next.js 16, middleware.ts was renamed to proxy.ts and runs on Node.js runtime
|
|
64
|
+
* instead of Edge runtime.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // proxy.ts (Next.js 16+)
|
|
69
|
+
* import { createVestigProxy } from '@vestig/next/middleware'
|
|
70
|
+
*
|
|
71
|
+
* export const proxy = createVestigProxy({
|
|
72
|
+
* skipPaths: ['/health', '/metrics'],
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* export const config = {
|
|
76
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function createVestigProxy(options?: MiddlewareOptions): (request: NextRequest) => NextResponse<unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* Pre-configured vestig proxy for direct export
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // proxy.ts (Next.js 16+)
|
|
87
|
+
* export { vestigProxy as proxy } from '@vestig/next/middleware'
|
|
88
|
+
*
|
|
89
|
+
* export const config = {
|
|
90
|
+
* matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare const vestigProxy: (request: NextRequest) => NextResponse<unknown>;
|
|
95
|
+
/**
|
|
96
|
+
* Helper to create proxy/middleware config matcher
|
|
97
|
+
*/
|
|
98
|
+
export declare function createProxyMatcher(options?: {
|
|
99
|
+
include?: string[];
|
|
100
|
+
exclude?: string[];
|
|
101
|
+
}): {
|
|
102
|
+
matcher: string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Use createProxyMatcher instead
|
|
106
|
+
*/
|
|
107
|
+
export declare const createMiddlewareMatcher: typeof createProxyMatcher;
|
|
108
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EACN,KAAK,QAAQ,EAEb,KAAK,cAAc,EAKnB,MAAM,QAAQ,CAAA;AAIf,MAAM,WAAW,iBAAiB;IACjC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,sCAAsC;IACtC,eAAe,CAAC,EAAE,QAAQ,CAAA;IAC1B,uCAAuC;IACvC,gBAAgB,CAAC,EAAE,QAAQ,CAAA;IAC3B,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAmCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,iBAAsB,IAGpC,SAAS,WAAW,2BA2ErD;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,YA3Fc,WAAW,0B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