@vestig/next 0.11.4 → 0.13.0

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.
Files changed (37) hide show
  1. package/dist/client/error-boundary.d.ts +22 -0
  2. package/dist/client/error-boundary.d.ts.map +1 -1
  3. package/dist/client/error-boundary.js +89 -2
  4. package/dist/client/error-boundary.js.map +1 -1
  5. package/dist/client/provider.d.ts +2 -0
  6. package/dist/client/provider.d.ts.map +1 -1
  7. package/dist/client/provider.js +16 -2
  8. package/dist/client/provider.js.map +1 -1
  9. package/dist/db/index.d.ts +1 -1
  10. package/dist/db/index.d.ts.map +1 -1
  11. package/dist/db/index.js +1 -1
  12. package/dist/db/index.js.map +1 -1
  13. package/dist/db/query-logger.d.ts +6 -0
  14. package/dist/db/query-logger.d.ts.map +1 -1
  15. package/dist/db/query-logger.js +77 -7
  16. package/dist/db/query-logger.js.map +1 -1
  17. package/dist/wide-events/context.d.ts +73 -0
  18. package/dist/wide-events/context.d.ts.map +1 -0
  19. package/dist/wide-events/context.js +86 -0
  20. package/dist/wide-events/context.js.map +1 -0
  21. package/dist/wide-events/helpers.d.ts +138 -0
  22. package/dist/wide-events/helpers.d.ts.map +1 -0
  23. package/dist/wide-events/helpers.js +182 -0
  24. package/dist/wide-events/helpers.js.map +1 -0
  25. package/dist/wide-events/index.d.ts +63 -0
  26. package/dist/wide-events/index.d.ts.map +1 -0
  27. package/dist/wide-events/index.js +67 -0
  28. package/dist/wide-events/index.js.map +1 -0
  29. package/dist/wide-events/middleware.d.ts +65 -0
  30. package/dist/wide-events/middleware.d.ts.map +1 -0
  31. package/dist/wide-events/middleware.js +160 -0
  32. package/dist/wide-events/middleware.js.map +1 -0
  33. package/dist/wide-events/server-action.d.ts +91 -0
  34. package/dist/wide-events/server-action.d.ts.map +1 -0
  35. package/dist/wide-events/server-action.js +158 -0
  36. package/dist/wide-events/server-action.js.map +1 -0
  37. package/package.json +9 -2
@@ -0,0 +1,138 @@
1
+ import { getWideEvent, getWideEventElapsed, requireWideEvent } from './context';
2
+ export { getWideEvent, requireWideEvent, getWideEventElapsed };
3
+ /**
4
+ * Set user information on the current wide event.
5
+ *
6
+ * This is a convenience function for setting common user fields.
7
+ *
8
+ * @param user - User information to set
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { setWideEventUser } from '@vestig/next/wide-events'
13
+ *
14
+ * // In your auth middleware or route handler
15
+ * setWideEventUser({
16
+ * id: user.id,
17
+ * subscription: user.plan,
18
+ * role: user.role,
19
+ * })
20
+ * ```
21
+ */
22
+ export declare function setWideEventUser(user: {
23
+ id?: string;
24
+ email?: string;
25
+ name?: string;
26
+ subscription?: string;
27
+ role?: string;
28
+ [key: string]: unknown;
29
+ }): void;
30
+ /**
31
+ * Set performance metrics on the current wide event.
32
+ *
33
+ * @param metrics - Performance metrics to set
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { setWideEventPerformance } from '@vestig/next/wide-events'
38
+ *
39
+ * // After database query
40
+ * setWideEventPerformance({
41
+ * db_query_ms: queryTime,
42
+ * db_rows: results.length,
43
+ * })
44
+ * ```
45
+ */
46
+ export declare function setWideEventPerformance(metrics: Record<string, number | string>): void;
47
+ /**
48
+ * Add a custom field to the current wide event.
49
+ *
50
+ * @param category - Field category (e.g., 'order', 'payment', 'feature')
51
+ * @param key - Field key
52
+ * @param value - Field value
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { setWideEventField } from '@vestig/next/wide-events'
57
+ *
58
+ * setWideEventField('order', 'id', orderId)
59
+ * setWideEventField('order', 'total', order.total)
60
+ * setWideEventField('order', 'items', order.items.length)
61
+ * ```
62
+ */
63
+ export declare function setWideEventField(category: string, key: string, value: unknown): void;
64
+ /**
65
+ * Add multiple fields to a category on the current wide event.
66
+ *
67
+ * @param category - Field category
68
+ * @param fields - Fields to merge
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { mergeWideEventFields } from '@vestig/next/wide-events'
73
+ *
74
+ * mergeWideEventFields('payment', {
75
+ * method: 'stripe',
76
+ * amount: 9999,
77
+ * currency: 'usd',
78
+ * status: 'succeeded',
79
+ * })
80
+ * ```
81
+ */
82
+ export declare function mergeWideEventFields(category: string, fields: Record<string, unknown>): void;
83
+ /**
84
+ * Add feature flag information to the current wide event.
85
+ *
86
+ * @param flags - Feature flag values
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * import { setWideEventFeatureFlags } from '@vestig/next/wide-events'
91
+ *
92
+ * setWideEventFeatureFlags({
93
+ * new_checkout: true,
94
+ * beta_features: false,
95
+ * experiment_id: 'exp-123',
96
+ * })
97
+ * ```
98
+ */
99
+ export declare function setWideEventFeatureFlags(flags: Record<string, boolean | string | number>): void;
100
+ /**
101
+ * Add error information to the current wide event.
102
+ *
103
+ * This should be called when an error occurs during request processing.
104
+ * The wide event will be marked as 'error' status when finalized.
105
+ *
106
+ * @param error - The error that occurred
107
+ * @param additionalContext - Additional context about the error
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { setWideEventError } from '@vestig/next/wide-events'
112
+ *
113
+ * try {
114
+ * await processPayment(order)
115
+ * } catch (error) {
116
+ * setWideEventError(error, { orderId: order.id })
117
+ * throw error
118
+ * }
119
+ * ```
120
+ */
121
+ export declare function setWideEventError(error: Error | unknown, additionalContext?: Record<string, unknown>): void;
122
+ /**
123
+ * Create a timing helper for tracking sub-operations within a request.
124
+ *
125
+ * @param name - Name of the operation being timed
126
+ * @returns A function to call when the operation completes
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { timeWideEventOperation } from '@vestig/next/wide-events'
131
+ *
132
+ * const endDbQuery = timeWideEventOperation('db_users_query')
133
+ * const users = await db.users.findMany()
134
+ * endDbQuery()
135
+ * ```
136
+ */
137
+ export declare function timeWideEventOperation(name: string): () => void;
138
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/wide-events/helpers.ts"],"names":[],"mappings":"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;GAcG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAU/D"}
@@ -0,0 +1,182 @@
1
+ import { getWideEvent, getWideEventElapsed, requireWideEvent } from './context';
2
+ // Re-export context functions as helpers
3
+ export { getWideEvent, requireWideEvent, getWideEventElapsed };
4
+ /**
5
+ * Set user information on the current wide event.
6
+ *
7
+ * This is a convenience function for setting common user fields.
8
+ *
9
+ * @param user - User information to set
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { setWideEventUser } from '@vestig/next/wide-events'
14
+ *
15
+ * // In your auth middleware or route handler
16
+ * setWideEventUser({
17
+ * id: user.id,
18
+ * subscription: user.plan,
19
+ * role: user.role,
20
+ * })
21
+ * ```
22
+ */
23
+ export function setWideEventUser(user) {
24
+ const event = getWideEvent();
25
+ if (!event)
26
+ return;
27
+ // Set userId in context for tail sampling VIP detection
28
+ if (user.id) {
29
+ event.setContext({ userId: user.id });
30
+ }
31
+ // Set user fields
32
+ event.merge('user', user);
33
+ }
34
+ /**
35
+ * Set performance metrics on the current wide event.
36
+ *
37
+ * @param metrics - Performance metrics to set
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * import { setWideEventPerformance } from '@vestig/next/wide-events'
42
+ *
43
+ * // After database query
44
+ * setWideEventPerformance({
45
+ * db_query_ms: queryTime,
46
+ * db_rows: results.length,
47
+ * })
48
+ * ```
49
+ */
50
+ export function setWideEventPerformance(metrics) {
51
+ const event = getWideEvent();
52
+ if (!event)
53
+ return;
54
+ event.merge('performance', metrics);
55
+ }
56
+ /**
57
+ * Add a custom field to the current wide event.
58
+ *
59
+ * @param category - Field category (e.g., 'order', 'payment', 'feature')
60
+ * @param key - Field key
61
+ * @param value - Field value
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * import { setWideEventField } from '@vestig/next/wide-events'
66
+ *
67
+ * setWideEventField('order', 'id', orderId)
68
+ * setWideEventField('order', 'total', order.total)
69
+ * setWideEventField('order', 'items', order.items.length)
70
+ * ```
71
+ */
72
+ export function setWideEventField(category, key, value) {
73
+ const event = getWideEvent();
74
+ if (!event)
75
+ return;
76
+ event.set(category, key, value);
77
+ }
78
+ /**
79
+ * Add multiple fields to a category on the current wide event.
80
+ *
81
+ * @param category - Field category
82
+ * @param fields - Fields to merge
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { mergeWideEventFields } from '@vestig/next/wide-events'
87
+ *
88
+ * mergeWideEventFields('payment', {
89
+ * method: 'stripe',
90
+ * amount: 9999,
91
+ * currency: 'usd',
92
+ * status: 'succeeded',
93
+ * })
94
+ * ```
95
+ */
96
+ export function mergeWideEventFields(category, fields) {
97
+ const event = getWideEvent();
98
+ if (!event)
99
+ return;
100
+ event.merge(category, fields);
101
+ }
102
+ /**
103
+ * Add feature flag information to the current wide event.
104
+ *
105
+ * @param flags - Feature flag values
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * import { setWideEventFeatureFlags } from '@vestig/next/wide-events'
110
+ *
111
+ * setWideEventFeatureFlags({
112
+ * new_checkout: true,
113
+ * beta_features: false,
114
+ * experiment_id: 'exp-123',
115
+ * })
116
+ * ```
117
+ */
118
+ export function setWideEventFeatureFlags(flags) {
119
+ const event = getWideEvent();
120
+ if (!event)
121
+ return;
122
+ event.merge('feature_flags', flags);
123
+ }
124
+ /**
125
+ * Add error information to the current wide event.
126
+ *
127
+ * This should be called when an error occurs during request processing.
128
+ * The wide event will be marked as 'error' status when finalized.
129
+ *
130
+ * @param error - The error that occurred
131
+ * @param additionalContext - Additional context about the error
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * import { setWideEventError } from '@vestig/next/wide-events'
136
+ *
137
+ * try {
138
+ * await processPayment(order)
139
+ * } catch (error) {
140
+ * setWideEventError(error, { orderId: order.id })
141
+ * throw error
142
+ * }
143
+ * ```
144
+ */
145
+ export function setWideEventError(error, additionalContext) {
146
+ const event = getWideEvent();
147
+ if (!event)
148
+ return;
149
+ const err = error instanceof Error ? error : new Error(String(error));
150
+ event.merge('error', {
151
+ name: err.name,
152
+ message: err.message,
153
+ stack: err.stack?.split('\n').slice(0, 10).join('\n'),
154
+ ...additionalContext,
155
+ });
156
+ }
157
+ /**
158
+ * Create a timing helper for tracking sub-operations within a request.
159
+ *
160
+ * @param name - Name of the operation being timed
161
+ * @returns A function to call when the operation completes
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * import { timeWideEventOperation } from '@vestig/next/wide-events'
166
+ *
167
+ * const endDbQuery = timeWideEventOperation('db_users_query')
168
+ * const users = await db.users.findMany()
169
+ * endDbQuery()
170
+ * ```
171
+ */
172
+ export function timeWideEventOperation(name) {
173
+ const startTime = performance.now();
174
+ const event = getWideEvent();
175
+ return () => {
176
+ const duration = performance.now() - startTime;
177
+ if (event) {
178
+ event.set('performance', `${name}_ms`, duration);
179
+ }
180
+ };
181
+ }
182
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/wide-events/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE/E,yCAAyC;AACzC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAA;AAE9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAOhC;IACA,MAAM,KAAK,GAAG,YAAY,EAAE,CAAA;IAC5B,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,wDAAwD;IACxD,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACtC,CAAC;IAED,kBAAkB;IAClB,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,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O,EAAE;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACrD,GAAG,iBAAiB;KACpB,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IAClD,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,YAAY,EAAE,CAAA;IAE5B,OAAO,GAAG,EAAE;QACX,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QAC9C,IAAI,KAAK,EAAE,CAAC;YACX,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,IAAI,KAAK,EAAE,QAAQ,CAAC,CAAA;QACjD,CAAC;IACF,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Wide Events integration for Next.js
3
+ *
4
+ * Wide Events (also called Canonical Log Lines) capture comprehensive context
5
+ * about complete operations in a single structured event, making debugging
6
+ * and observability significantly easier.
7
+ *
8
+ * @example Middleware setup
9
+ * ```typescript
10
+ * // middleware.ts
11
+ * import { createWideEventMiddleware } from '@vestig/next/wide-events'
12
+ *
13
+ * export const middleware = createWideEventMiddleware({
14
+ * tailSampling: {
15
+ * enabled: true,
16
+ * alwaysKeepStatuses: ['error'],
17
+ * slowThresholdMs: 2000,
18
+ * successSampleRate: 0.1,
19
+ * },
20
+ * })
21
+ * ```
22
+ *
23
+ * @example Server Actions
24
+ * ```typescript
25
+ * // app/actions/user.ts
26
+ * 'use server'
27
+ *
28
+ * import { withWideEvent, setWideEventUser } from '@vestig/next/wide-events'
29
+ *
30
+ * export const createUser = withWideEvent(
31
+ * async (data, { event }) => {
32
+ * const user = await db.users.create({ data })
33
+ * setWideEventUser({ id: user.id, email: user.email })
34
+ * return user
35
+ * },
36
+ * { name: 'action.user.create' }
37
+ * )
38
+ * ```
39
+ *
40
+ * @example Enriching from route handlers
41
+ * ```typescript
42
+ * // app/api/checkout/route.ts
43
+ * import { getWideEvent, setWideEventField } from '@vestig/next/wide-events'
44
+ *
45
+ * export async function POST(request: Request) {
46
+ * const event = getWideEvent()
47
+ * if (event) {
48
+ * event.set('order', 'id', orderId)
49
+ * event.set('payment', 'method', 'stripe')
50
+ * }
51
+ * // ...
52
+ * }
53
+ * ```
54
+ *
55
+ * @packageDocumentation
56
+ */
57
+ export { getWideEvent, requireWideEvent, getWideEventElapsed, runWithWideEvent, runWithWideEventAsync, type WideEventRequestContext, } from './context';
58
+ export { createWideEventMiddleware, wideEventMiddleware, type WideEventMiddlewareOptions, } from './middleware';
59
+ export { setWideEventUser, setWideEventPerformance, setWideEventField, mergeWideEventFields, setWideEventFeatureFlags, setWideEventError, timeWideEventOperation, } from './helpers';
60
+ export { withWideEvent, createWideEventAction, type WideEventActionOptions, type WideEventActionContext, type WideEventServerAction, } from './server-action';
61
+ export type { WideEvent, WideEventBuilder, WideEventConfig, WideEventContext, WideEventEndOptions, WideEventFields, WideEventStatus, TailSamplingConfig, } from 'vestig';
62
+ export { createWideEvent } from 'vestig';
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wide-events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAGH,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,uBAAuB,GAC5B,MAAM,WAAW,CAAA;AAGlB,OAAO,EACN,yBAAyB,EACzB,mBAAmB,EACnB,KAAK,0BAA0B,GAC/B,MAAM,cAAc,CAAA;AAGrB,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,GACtB,MAAM,WAAW,CAAA;AAGlB,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC1B,MAAM,iBAAiB,CAAA;AAGxB,YAAY,EACX,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,kBAAkB,GAClB,MAAM,QAAQ,CAAA;AAGf,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Wide Events integration for Next.js
3
+ *
4
+ * Wide Events (also called Canonical Log Lines) capture comprehensive context
5
+ * about complete operations in a single structured event, making debugging
6
+ * and observability significantly easier.
7
+ *
8
+ * @example Middleware setup
9
+ * ```typescript
10
+ * // middleware.ts
11
+ * import { createWideEventMiddleware } from '@vestig/next/wide-events'
12
+ *
13
+ * export const middleware = createWideEventMiddleware({
14
+ * tailSampling: {
15
+ * enabled: true,
16
+ * alwaysKeepStatuses: ['error'],
17
+ * slowThresholdMs: 2000,
18
+ * successSampleRate: 0.1,
19
+ * },
20
+ * })
21
+ * ```
22
+ *
23
+ * @example Server Actions
24
+ * ```typescript
25
+ * // app/actions/user.ts
26
+ * 'use server'
27
+ *
28
+ * import { withWideEvent, setWideEventUser } from '@vestig/next/wide-events'
29
+ *
30
+ * export const createUser = withWideEvent(
31
+ * async (data, { event }) => {
32
+ * const user = await db.users.create({ data })
33
+ * setWideEventUser({ id: user.id, email: user.email })
34
+ * return user
35
+ * },
36
+ * { name: 'action.user.create' }
37
+ * )
38
+ * ```
39
+ *
40
+ * @example Enriching from route handlers
41
+ * ```typescript
42
+ * // app/api/checkout/route.ts
43
+ * import { getWideEvent, setWideEventField } from '@vestig/next/wide-events'
44
+ *
45
+ * export async function POST(request: Request) {
46
+ * const event = getWideEvent()
47
+ * if (event) {
48
+ * event.set('order', 'id', orderId)
49
+ * event.set('payment', 'method', 'stripe')
50
+ * }
51
+ * // ...
52
+ * }
53
+ * ```
54
+ *
55
+ * @packageDocumentation
56
+ */
57
+ // Context functions
58
+ export { getWideEvent, requireWideEvent, getWideEventElapsed, runWithWideEvent, runWithWideEventAsync, } from './context';
59
+ // Middleware
60
+ export { createWideEventMiddleware, wideEventMiddleware, } from './middleware';
61
+ // Helpers
62
+ export { setWideEventUser, setWideEventPerformance, setWideEventField, mergeWideEventFields, setWideEventFeatureFlags, setWideEventError, timeWideEventOperation, } from './helpers';
63
+ // Server Actions
64
+ export { withWideEvent, createWideEventAction, } from './server-action';
65
+ // Re-export createWideEvent for advanced use cases
66
+ export { createWideEvent } from 'vestig';
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wide-events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,oBAAoB;AACpB,OAAO,EACN,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GAErB,MAAM,WAAW,CAAA;AAElB,aAAa;AACb,OAAO,EACN,yBAAyB,EACzB,mBAAmB,GAEnB,MAAM,cAAc,CAAA;AAErB,UAAU;AACV,OAAO,EACN,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,GACtB,MAAM,WAAW,CAAA;AAElB,iBAAiB;AACjB,OAAO,EACN,aAAa,EACb,qBAAqB,GAIrB,MAAM,iBAAiB,CAAA;AAcxB,mDAAmD;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA"}
@@ -0,0 +1,65 @@
1
+ import { NextResponse } from 'next/server';
2
+ import type { NextRequest } from 'next/server';
3
+ import { type LogLevel, type SanitizePreset, type TailSamplingConfig } from 'vestig';
4
+ /**
5
+ * Options for the wide event middleware
6
+ */
7
+ export interface WideEventMiddlewareOptions {
8
+ /** Log level for the logger */
9
+ level?: LogLevel;
10
+ /** Enable/disable wide event logging */
11
+ enabled?: boolean;
12
+ /** PII sanitization preset */
13
+ sanitize?: SanitizePreset;
14
+ /** Paths to skip (prefix matching) */
15
+ skipPaths?: string[];
16
+ /** Custom header name for request ID */
17
+ requestIdHeader?: string;
18
+ /** Use structured JSON output */
19
+ structured?: boolean;
20
+ /** Tail sampling configuration for wide events */
21
+ tailSampling?: TailSamplingConfig;
22
+ }
23
+ /**
24
+ * Create wide event middleware for Next.js
25
+ *
26
+ * This middleware automatically creates a wide event for each request
27
+ * and populates it with HTTP context. The wide event is available
28
+ * throughout the request lifecycle via `getWideEvent()`.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // middleware.ts
33
+ * import { createWideEventMiddleware } from '@vestig/next/wide-events'
34
+ *
35
+ * export const middleware = createWideEventMiddleware({
36
+ * skipPaths: ['/health', '/metrics'],
37
+ * tailSampling: {
38
+ * enabled: true,
39
+ * alwaysKeepStatuses: ['error'],
40
+ * slowThresholdMs: 2000,
41
+ * successSampleRate: 0.1,
42
+ * },
43
+ * })
44
+ *
45
+ * export const config = {
46
+ * matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
47
+ * }
48
+ * ```
49
+ */
50
+ export declare function createWideEventMiddleware(options?: WideEventMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
51
+ /**
52
+ * Pre-configured wide event middleware for direct export
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // middleware.ts
57
+ * export { wideEventMiddleware as middleware } from '@vestig/next/wide-events'
58
+ *
59
+ * export const config = {
60
+ * matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
61
+ * }
62
+ * ```
63
+ */
64
+ export declare const wideEventMiddleware: (request: NextRequest) => Promise<NextResponse<unknown>>;
65
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/wide-events/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,EACnB,KAAK,kBAAkB,EAMvB,MAAM,QAAQ,CAAA;AAIf;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C,+BAA+B;IAC/B,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,wCAAwC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,iCAAiC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,kDAAkD;IAClD,YAAY,CAAC,EAAE,kBAAkB,CAAA;CACjC;AA8BD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAE,0BAA+B,IAGvC,SAAS,WAAW,oCA2G9D;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,YA1HoB,WAAW,mCA0HD,CAAA"}