@djangocfg/nextjs 2.1.216 → 2.1.217
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/dist/config/index.mjs +13 -3
- package/dist/config/index.mjs.map +1 -1
- package/dist/index.mjs +13 -3
- package/dist/index.mjs.map +1 -1
- package/dist/monitor/index.d.mts +22 -0
- package/dist/monitor/index.mjs +23 -0
- package/dist/monitor/index.mjs.map +1 -0
- package/package.json +20 -10
- package/src/monitor/index.ts +27 -0
- package/src/monitor/withMonitor.ts +33 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { ServerMonitorConfig, serverMonitor } from '@djangocfg/monitor/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* withMonitor — Route Handler wrapper for @djangocfg/nextjs
|
|
5
|
+
*
|
|
6
|
+
* Catches unhandled errors from a Next.js Route Handler,
|
|
7
|
+
* forwards them to serverMonitor, then re-throws so Next.js
|
|
8
|
+
* still returns a 500 response normally.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // app/api/orders/route.ts
|
|
12
|
+
* import { withMonitor } from '@djangocfg/nextjs/monitor'
|
|
13
|
+
*
|
|
14
|
+
* export const POST = withMonitor(async (req) => {
|
|
15
|
+
* // handler code
|
|
16
|
+
* return Response.json({ ok: true })
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
type RouteHandler = (req: Request, ctx?: unknown) => Promise<Response> | Response;
|
|
20
|
+
declare function withMonitor(handler: RouteHandler): RouteHandler;
|
|
21
|
+
|
|
22
|
+
export { withMonitor };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/monitor/index.ts
|
|
2
|
+
import { serverMonitor as serverMonitor2 } from "@djangocfg/monitor/server";
|
|
3
|
+
|
|
4
|
+
// src/monitor/withMonitor.ts
|
|
5
|
+
import { serverMonitor } from "@djangocfg/monitor/server";
|
|
6
|
+
function withMonitor(handler) {
|
|
7
|
+
return async (req, ctx) => {
|
|
8
|
+
try {
|
|
9
|
+
return await handler(req, ctx);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
try {
|
|
12
|
+
await serverMonitor.captureError(err, { url: req.url });
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
serverMonitor2 as serverMonitor,
|
|
21
|
+
withMonitor
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/monitor/index.ts","../../src/monitor/withMonitor.ts"],"sourcesContent":["/**\n * @djangocfg/nextjs/monitor\n *\n * Server-side monitor utilities for Next.js Route Handlers and Server Components.\n *\n * Configure once in lib/monitor.ts, then use withMonitor() or serverMonitor directly.\n *\n * @example\n * // lib/monitor.ts\n * import { serverMonitor } from '@djangocfg/nextjs/monitor'\n * serverMonitor.configure({\n * project: process.env.PROJECT_NAME ?? 'my-app',\n * environment: process.env.NODE_ENV,\n * baseUrl: process.env.NEXT_PUBLIC_API_URL,\n * })\n * export { serverMonitor }\n *\n * // app/api/orders/route.ts\n * import { withMonitor } from '@djangocfg/nextjs/monitor'\n * export const POST = withMonitor(async (req) => {\n * // ...\n * })\n */\n\nexport { serverMonitor } from '@djangocfg/monitor/server'\nexport type { ServerMonitorConfig } from '@djangocfg/monitor/server'\nexport { withMonitor } from './withMonitor'\n","/**\n * withMonitor — Route Handler wrapper for @djangocfg/nextjs\n *\n * Catches unhandled errors from a Next.js Route Handler,\n * forwards them to serverMonitor, then re-throws so Next.js\n * still returns a 500 response normally.\n *\n * @example\n * // app/api/orders/route.ts\n * import { withMonitor } from '@djangocfg/nextjs/monitor'\n *\n * export const POST = withMonitor(async (req) => {\n * // handler code\n * return Response.json({ ok: true })\n * })\n */\n\nimport { serverMonitor } from '@djangocfg/monitor/server'\n\ntype RouteHandler = (req: Request, ctx?: unknown) => Promise<Response> | Response\n\nexport function withMonitor(handler: RouteHandler): RouteHandler {\n return async (req: Request, ctx?: unknown): Promise<Response> => {\n try {\n return await handler(req, ctx)\n } catch (err) {\n try {\n await serverMonitor.captureError(err, { url: req.url })\n } catch { /* never crash */ }\n throw err\n }\n }\n}\n"],"mappings":";AAwBA,SAAS,iBAAAA,sBAAqB;;;ACP9B,SAAS,qBAAqB;AAIvB,SAAS,YAAY,SAAqC;AAC/D,SAAO,OAAO,KAAc,QAAqC;AAC/D,QAAI;AACF,aAAO,MAAM,QAAQ,KAAK,GAAG;AAAA,IAC/B,SAAS,KAAK;AACZ,UAAI;AACF,cAAM,cAAc,aAAa,KAAK,EAAE,KAAK,IAAI,IAAI,CAAC;AAAA,MACxD,QAAQ;AAAA,MAAoB;AAC5B,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["serverMonitor"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/nextjs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.217",
|
|
4
4
|
"description": "Next.js server utilities: sitemap, health, OG images, contact forms, navigation, config",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nextjs",
|
|
@@ -89,6 +89,11 @@
|
|
|
89
89
|
"import": "./dist/pwa/worker/index.mjs",
|
|
90
90
|
"default": "./dist/pwa/worker/index.mjs"
|
|
91
91
|
},
|
|
92
|
+
"./monitor": {
|
|
93
|
+
"types": "./dist/monitor/index.d.mts",
|
|
94
|
+
"import": "./dist/monitor/index.mjs",
|
|
95
|
+
"default": "./dist/monitor/index.mjs"
|
|
96
|
+
},
|
|
92
97
|
"./i18n": {
|
|
93
98
|
"types": "./dist/i18n/index.d.mts",
|
|
94
99
|
"import": "./dist/i18n/index.mjs",
|
|
@@ -148,11 +153,15 @@
|
|
|
148
153
|
"ai-docs": "tsx src/ai/cli.ts"
|
|
149
154
|
},
|
|
150
155
|
"peerDependencies": {
|
|
151
|
-
"@djangocfg/i18n": "^2.1.
|
|
152
|
-
"@djangocfg/
|
|
156
|
+
"@djangocfg/i18n": "^2.1.217",
|
|
157
|
+
"@djangocfg/monitor": "^2.1.217",
|
|
158
|
+
"@djangocfg/ui-core": "^2.1.217",
|
|
153
159
|
"next": "^16.0.10"
|
|
154
160
|
},
|
|
155
161
|
"peerDependenciesMeta": {
|
|
162
|
+
"@djangocfg/monitor": {
|
|
163
|
+
"optional": true
|
|
164
|
+
},
|
|
156
165
|
"@djangocfg/ui-core": {
|
|
157
166
|
"optional": true
|
|
158
167
|
}
|
|
@@ -168,14 +177,15 @@
|
|
|
168
177
|
"serwist": "^9.2.3"
|
|
169
178
|
},
|
|
170
179
|
"devDependencies": {
|
|
171
|
-
"@djangocfg/i18n": "^2.1.
|
|
172
|
-
"@djangocfg/
|
|
173
|
-
"@djangocfg/
|
|
174
|
-
"@djangocfg/
|
|
175
|
-
"@djangocfg/
|
|
180
|
+
"@djangocfg/i18n": "^2.1.217",
|
|
181
|
+
"@djangocfg/monitor": "^2.1.217",
|
|
182
|
+
"@djangocfg/ui-core": "^2.1.217",
|
|
183
|
+
"@djangocfg/imgai": "workspace:*",
|
|
184
|
+
"@djangocfg/layouts": "^2.1.217",
|
|
185
|
+
"@djangocfg/typescript-config": "^2.1.217",
|
|
176
186
|
"@types/node": "^24.7.2",
|
|
177
|
-
"@types/react": "19.
|
|
178
|
-
"@types/react-dom": "19.
|
|
187
|
+
"@types/react": "^19.1.0",
|
|
188
|
+
"@types/react-dom": "^19.1.0",
|
|
179
189
|
"@types/semver": "^7.7.1",
|
|
180
190
|
"@types/webpack": "^5.28.5",
|
|
181
191
|
"@vercel/og": "^0.8.5",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @djangocfg/nextjs/monitor
|
|
3
|
+
*
|
|
4
|
+
* Server-side monitor utilities for Next.js Route Handlers and Server Components.
|
|
5
|
+
*
|
|
6
|
+
* Configure once in lib/monitor.ts, then use withMonitor() or serverMonitor directly.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // lib/monitor.ts
|
|
10
|
+
* import { serverMonitor } from '@djangocfg/nextjs/monitor'
|
|
11
|
+
* serverMonitor.configure({
|
|
12
|
+
* project: process.env.PROJECT_NAME ?? 'my-app',
|
|
13
|
+
* environment: process.env.NODE_ENV,
|
|
14
|
+
* baseUrl: process.env.NEXT_PUBLIC_API_URL,
|
|
15
|
+
* })
|
|
16
|
+
* export { serverMonitor }
|
|
17
|
+
*
|
|
18
|
+
* // app/api/orders/route.ts
|
|
19
|
+
* import { withMonitor } from '@djangocfg/nextjs/monitor'
|
|
20
|
+
* export const POST = withMonitor(async (req) => {
|
|
21
|
+
* // ...
|
|
22
|
+
* })
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { serverMonitor } from '@djangocfg/monitor/server'
|
|
26
|
+
export type { ServerMonitorConfig } from '@djangocfg/monitor/server'
|
|
27
|
+
export { withMonitor } from './withMonitor'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withMonitor — Route Handler wrapper for @djangocfg/nextjs
|
|
3
|
+
*
|
|
4
|
+
* Catches unhandled errors from a Next.js Route Handler,
|
|
5
|
+
* forwards them to serverMonitor, then re-throws so Next.js
|
|
6
|
+
* still returns a 500 response normally.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // app/api/orders/route.ts
|
|
10
|
+
* import { withMonitor } from '@djangocfg/nextjs/monitor'
|
|
11
|
+
*
|
|
12
|
+
* export const POST = withMonitor(async (req) => {
|
|
13
|
+
* // handler code
|
|
14
|
+
* return Response.json({ ok: true })
|
|
15
|
+
* })
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { serverMonitor } from '@djangocfg/monitor/server'
|
|
19
|
+
|
|
20
|
+
type RouteHandler = (req: Request, ctx?: unknown) => Promise<Response> | Response
|
|
21
|
+
|
|
22
|
+
export function withMonitor(handler: RouteHandler): RouteHandler {
|
|
23
|
+
return async (req: Request, ctx?: unknown): Promise<Response> => {
|
|
24
|
+
try {
|
|
25
|
+
return await handler(req, ctx)
|
|
26
|
+
} catch (err) {
|
|
27
|
+
try {
|
|
28
|
+
await serverMonitor.captureError(err, { url: req.url })
|
|
29
|
+
} catch { /* never crash */ }
|
|
30
|
+
throw err
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|