cloudflare-next-intl 0.6.28 → 0.6.29

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.
@@ -26,6 +26,12 @@ import { type ReportErrorConfig } from './report_error';
26
26
  * boundary (Next.js server actions serialize arguments; an `Error` instance
27
27
  * doesn't survive that intact) and `isClient: true` is set automatically.
28
28
  *
29
+ * Also attaches `requestContext: { path, userAgent, referer }` (best-effort,
30
+ * via `next/headers` — see `resolveRequestContext`) alongside your own
31
+ * `params`, so `onError`/the console report shows WHERE the error happened,
32
+ * not just what it was — useful when diagnosing a client error without a
33
+ * repro, since the page and browser are often the missing piece.
34
+ *
29
35
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
30
36
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
31
37
  */
@@ -1,5 +1,26 @@
1
1
  import reportError from './report_error';
2
2
  import stringifyUnknown from './stringify_unknown';
3
+ /**
4
+ * Reads request context (page path, user agent, referer) via `next/headers`
5
+ * for a client-originated error report. `path` comes from `x-pathname`, set
6
+ * by `intlMiddleware` (this package's own middleware) — falls back to
7
+ * `undefined` when a header is missing (e.g. middleware didn't run for this
8
+ * request) rather than throwing.
9
+ */
10
+ async function resolveRequestContext() {
11
+ try {
12
+ const { headers } = await import('next/headers');
13
+ const headerList = await headers();
14
+ return {
15
+ path: headerList.get('x-pathname') ?? undefined,
16
+ userAgent: headerList.get('user-agent') ?? undefined,
17
+ referer: headerList.get('referer') ?? undefined,
18
+ };
19
+ }
20
+ catch {
21
+ return {};
22
+ }
23
+ }
3
24
  /**
4
25
  * Builds a function that reports a client-originated error via
5
26
  * `reportError`, meant to be re-exported directly from your OWN
@@ -26,15 +47,28 @@ import stringifyUnknown from './stringify_unknown';
26
47
  * boundary (Next.js server actions serialize arguments; an `Error` instance
27
48
  * doesn't survive that intact) and `isClient: true` is set automatically.
28
49
  *
50
+ * Also attaches `requestContext: { path, userAgent, referer }` (best-effort,
51
+ * via `next/headers` — see `resolveRequestContext`) alongside your own
52
+ * `params`, so `onError`/the console report shows WHERE the error happened,
53
+ * not just what it was — useful when diagnosing a client error without a
54
+ * repro, since the page and browser are often the missing piece.
55
+ *
29
56
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
30
57
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
31
58
  */
32
59
  export default function createServerErrorAction(config) {
33
60
  return async function reportClientError(error, classOrMethodName, params) {
61
+ const requestContext = await resolveRequestContext();
62
+ const isPlainParamsObject = typeof params === 'object' && params !== null && !Array.isArray(params);
63
+ const mergedParams = params === undefined
64
+ ? { requestContext }
65
+ : isPlainParamsObject
66
+ ? { ...params, requestContext }
67
+ : { params, requestContext };
34
68
  await reportError(config, {
35
69
  error: stringifyUnknown(error, true),
36
70
  classOrMethodName,
37
- params,
71
+ params: mergedParams,
38
72
  isClient: true,
39
73
  });
40
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.6.28",
3
+ "version": "0.6.29",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",