cloudflare-next-intl 0.6.4 → 0.6.6

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 (154) hide show
  1. package/dist/src/client/components/client_provider.js +2 -0
  2. package/dist/src/error_handling/default_ignored_console_errors.js +6 -0
  3. package/dist/src/error_handling/index.d.ts +1 -0
  4. package/dist/src/error_handling/index.js +1 -0
  5. package/dist/src/error_handling/install_global_error_override.d.ts +20 -0
  6. package/dist/src/error_handling/install_global_error_override.js +44 -0
  7. package/dist/src/error_handling/report_error.d.ts +7 -3
  8. package/dist/src/error_handling/report_error.js +21 -10
  9. package/dist/src/firebase_auth/client/auth_user_provider.js +26 -21
  10. package/dist/src/firebase_auth/index.d.ts +1 -0
  11. package/dist/src/firebase_auth/index.js +1 -0
  12. package/dist/src/firebase_auth/server/clear_session_action.d.ts +7 -0
  13. package/dist/src/firebase_auth/server/clear_session_action.js +20 -0
  14. package/dist/src/types/types.d.ts +28 -3
  15. package/package.json +5 -1
  16. package/dist/types/client/components/client_helper_script.d.ts +0 -1
  17. package/dist/types/client/components/client_provider.d.ts +0 -34
  18. package/dist/types/client/components/locale_link.d.ts +0 -30
  19. package/dist/types/client/components/locale_link_client.d.ts +0 -3
  20. package/dist/types/client/functions/get_cookie.bench.d.ts +0 -1
  21. package/dist/types/client/functions/get_cookie.d.ts +0 -10
  22. package/dist/types/client/functions/get_cookie.test.d.ts +0 -1
  23. package/dist/types/client/functions/set_cookie.bench.d.ts +0 -1
  24. package/dist/types/client/functions/set_cookie.d.ts +0 -21
  25. package/dist/types/client/functions/set_cookie.test.d.ts +0 -1
  26. package/dist/types/client/hooks/client_hooks.bench.d.ts +0 -1
  27. package/dist/types/client/hooks/client_hooks.d.ts +0 -28
  28. package/dist/types/client/hooks/use_path_name.bench.d.ts +0 -1
  29. package/dist/types/client/hooks/use_path_name.d.ts +0 -10
  30. package/dist/types/client/index.d.ts +0 -4
  31. package/dist/types/config/cookie_key.bench.d.ts +0 -1
  32. package/dist/types/config/cookie_key.d.ts +0 -5
  33. package/dist/types/config/cookie_key.test.d.ts +0 -1
  34. package/dist/types/config/index.d.ts +0 -4
  35. package/dist/types/config/init_config.bench.d.ts +0 -1
  36. package/dist/types/config/init_config.d.ts +0 -18
  37. package/dist/types/config/init_config.test.d.ts +0 -1
  38. package/dist/types/config/intl_config.d.ts +0 -3
  39. package/dist/types/config/intl_config.test.d.ts +0 -1
  40. package/dist/types/config/intl_sitemap.bench.d.ts +0 -1
  41. package/dist/types/config/intl_sitemap.d.ts +0 -8
  42. package/dist/types/config/intl_sitemap.test.d.ts +0 -1
  43. package/dist/types/config/middleware.bench.d.ts +0 -1
  44. package/dist/types/config/middleware.d.ts +0 -21
  45. package/dist/types/config/middleware.test.d.ts +0 -1
  46. package/dist/types/cookie_consent/client/components/clarity_script.d.ts +0 -10
  47. package/dist/types/cookie_consent/client/components/cookie_consent_analytics.bench.d.ts +0 -1
  48. package/dist/types/cookie_consent/client/components/cookie_consent_analytics.d.ts +0 -19
  49. package/dist/types/cookie_consent/client/components/cookie_consent_dialog.d.ts +0 -35
  50. package/dist/types/cookie_consent/client/components/default_dialog_styles.d.ts +0 -2
  51. package/dist/types/cookie_consent/client/components/default_dialog_text.d.ts +0 -13
  52. package/dist/types/cookie_consent/client/components/default_privacy_policy_link.d.ts +0 -14
  53. package/dist/types/cookie_consent/client/components/dialog_portal.d.ts +0 -11
  54. package/dist/types/cookie_consent/client/components/privacy_policy_update_dialog.d.ts +0 -31
  55. package/dist/types/cookie_consent/client/cookie_consent_provider.bench.d.ts +0 -1
  56. package/dist/types/cookie_consent/client/cookie_consent_provider.d.ts +0 -39
  57. package/dist/types/cookie_consent/client/use_cookie_consent.d.ts +0 -6
  58. package/dist/types/cookie_consent/gdpr_countries.bench.d.ts +0 -1
  59. package/dist/types/cookie_consent/gdpr_countries.d.ts +0 -18
  60. package/dist/types/cookie_consent/gdpr_countries.perf.test.d.ts +0 -1
  61. package/dist/types/cookie_consent/gdpr_countries.test.d.ts +0 -1
  62. package/dist/types/cookie_consent/index.d.ts +0 -10
  63. package/dist/types/cookie_consent/require_config.d.ts +0 -7
  64. package/dist/types/cookie_consent/require_config.test.d.ts +0 -1
  65. package/dist/types/cookie_consent/types.d.ts +0 -57
  66. package/dist/types/error_handling/create_server_error_action.d.ts +0 -19
  67. package/dist/types/error_handling/create_server_error_action.test.d.ts +0 -1
  68. package/dist/types/error_handling/default_ignored_console_errors.d.ts +0 -13
  69. package/dist/types/error_handling/default_ignored_console_errors.test.d.ts +0 -1
  70. package/dist/types/error_handling/format_error_message.d.ts +0 -9
  71. package/dist/types/error_handling/format_error_message.test.d.ts +0 -1
  72. package/dist/types/error_handling/index.d.ts +0 -9
  73. package/dist/types/error_handling/install_console_error_override.bench.d.ts +0 -1
  74. package/dist/types/error_handling/install_console_error_override.d.ts +0 -29
  75. package/dist/types/error_handling/install_console_error_override.perf.test.d.ts +0 -1
  76. package/dist/types/error_handling/install_console_error_override.test.d.ts +0 -1
  77. package/dist/types/error_handling/report_error.bench.d.ts +0 -1
  78. package/dist/types/error_handling/report_error.d.ts +0 -40
  79. package/dist/types/error_handling/report_error.perf.test.d.ts +0 -1
  80. package/dist/types/error_handling/report_error.test.d.ts +0 -1
  81. package/dist/types/error_handling/stringify_unknown.bench.d.ts +0 -1
  82. package/dist/types/error_handling/stringify_unknown.d.ts +0 -12
  83. package/dist/types/error_handling/stringify_unknown.test.d.ts +0 -1
  84. package/dist/types/error_handling/with_error_handling.d.ts +0 -15
  85. package/dist/types/error_handling/with_error_handling.test.d.ts +0 -1
  86. package/dist/types/firebase_auth/client/auth_actions.bench.d.ts +0 -1
  87. package/dist/types/firebase_auth/client/auth_actions.d.ts +0 -46
  88. package/dist/types/firebase_auth/client/auth_actions.test.d.ts +0 -1
  89. package/dist/types/firebase_auth/client/auth_user_cache.bench.d.ts +0 -1
  90. package/dist/types/firebase_auth/client/auth_user_cache.d.ts +0 -4
  91. package/dist/types/firebase_auth/client/auth_user_cache.test.d.ts +0 -1
  92. package/dist/types/firebase_auth/client/auth_user_provider.d.ts +0 -36
  93. package/dist/types/firebase_auth/client/firebase_client.bench.d.ts +0 -1
  94. package/dist/types/firebase_auth/client/firebase_client.d.ts +0 -20
  95. package/dist/types/firebase_auth/client/firebase_client.test.d.ts +0 -1
  96. package/dist/types/firebase_auth/client/use_auth_user.bench.d.ts +0 -1
  97. package/dist/types/firebase_auth/client/use_auth_user.d.ts +0 -12
  98. package/dist/types/firebase_auth/error_messages/default_messages.en.bench.d.ts +0 -1
  99. package/dist/types/firebase_auth/error_messages/default_messages.en.d.ts +0 -1
  100. package/dist/types/firebase_auth/error_messages/default_messages.en.test.d.ts +0 -1
  101. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.bench.d.ts +0 -1
  102. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.d.ts +0 -6
  103. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.test.d.ts +0 -1
  104. package/dist/types/firebase_auth/index.d.ts +0 -9
  105. package/dist/types/firebase_auth/middleware/update_session.bench.d.ts +0 -1
  106. package/dist/types/firebase_auth/middleware/update_session.d.ts +0 -22
  107. package/dist/types/firebase_auth/middleware/update_session.test.d.ts +0 -1
  108. package/dist/types/firebase_auth/require_config.bench.d.ts +0 -1
  109. package/dist/types/firebase_auth/require_config.d.ts +0 -8
  110. package/dist/types/firebase_auth/require_config.test.d.ts +0 -1
  111. package/dist/types/firebase_auth/server/auth_user_server_provider.d.ts +0 -29
  112. package/dist/types/firebase_auth/server/firebase_server.bench.d.ts +0 -1
  113. package/dist/types/firebase_auth/server/firebase_server.d.ts +0 -15
  114. package/dist/types/firebase_auth/server/firebase_server.perf.test.d.ts +0 -1
  115. package/dist/types/firebase_auth/server/firebase_server.test.d.ts +0 -1
  116. package/dist/types/firebase_auth/server/use_auth_user_server.bench.d.ts +0 -1
  117. package/dist/types/firebase_auth/server/use_auth_user_server.d.ts +0 -39
  118. package/dist/types/firebase_auth/server/use_auth_user_server.test.d.ts +0 -1
  119. package/dist/types/firebase_auth/types.d.ts +0 -22
  120. package/dist/types/general/cache_variables.bench.d.ts +0 -1
  121. package/dist/types/general/cache_variables.d.ts +0 -14
  122. package/dist/types/general/cache_variables.test.d.ts +0 -1
  123. package/dist/types/general/general_functions.bench.d.ts +0 -1
  124. package/dist/types/general/general_functions.d.ts +0 -2
  125. package/dist/types/general/general_functions.test.d.ts +0 -1
  126. package/dist/types/general/index.d.ts +0 -2
  127. package/dist/types/general/metadata.bench.d.ts +0 -1
  128. package/dist/types/general/metadata.d.ts +0 -38
  129. package/dist/types/general/metadata.test.d.ts +0 -1
  130. package/dist/types/index.d.ts +0 -6
  131. package/dist/types/server/components/helper_script.d.ts +0 -20
  132. package/dist/types/server/components/link.d.ts +0 -25
  133. package/dist/types/server/components/server_provider.d.ts +0 -35
  134. package/dist/types/server/functions/get_user_locale.bench.d.ts +0 -1
  135. package/dist/types/server/functions/get_user_locale.d.ts +0 -3
  136. package/dist/types/server/functions/get_user_locale.test.d.ts +0 -1
  137. package/dist/types/server/functions/locale_static_params.d.ts +0 -15
  138. package/dist/types/server/functions/locale_static_params.test.d.ts +0 -1
  139. package/dist/types/server/functions/server.bench.d.ts +0 -1
  140. package/dist/types/server/functions/server.d.ts +0 -67
  141. package/dist/types/server/functions/server.perf.test.d.ts +0 -1
  142. package/dist/types/server/functions/server.test.d.ts +0 -1
  143. package/dist/types/server/functions/use_functions.bench.d.ts +0 -1
  144. package/dist/types/server/functions/use_functions.d.ts +0 -33
  145. package/dist/types/server/functions/use_functions.test.d.ts +0 -1
  146. package/dist/types/server/index.d.ts +0 -5
  147. package/dist/types/test_utils/mock_intl_config.d.ts +0 -3
  148. package/dist/types/test_utils/mock_next_server.d.ts +0 -5
  149. package/dist/types/theme_switcher/components/icons.d.ts +0 -6
  150. package/dist/types/theme_switcher/components/theme_switcher.d.ts +0 -15
  151. package/dist/types/theme_switcher/components/theme_switcher_button.d.ts +0 -6
  152. package/dist/types/theme_switcher/index.d.ts +0 -1
  153. package/dist/types/types/index.d.ts +0 -1
  154. package/dist/types/types/types.d.ts +0 -548
@@ -5,6 +5,7 @@ import { createContext, useMemo } from "react";
5
5
  import dynamic from "next/dynamic";
6
6
  import config from "@intl-config";
7
7
  import installConsoleErrorOverride from "../../error_handling/install_console_error_override";
8
+ import installGlobalErrorOverride from "../../error_handling/install_global_error_override";
8
9
  export const LocaleContext = createContext(undefined);
9
10
  // Hoisted to module scope — calling `dynamic()` inside the component body
10
11
  // creates a brand-new component identity every render, forcing React to
@@ -22,6 +23,7 @@ export default function LocationzationClientProvider({ language, messages, initi
22
23
  setLocaleCache(language);
23
24
  setMessageForLocaleCache(language, messages);
24
25
  installConsoleErrorOverride(config, true);
26
+ installGlobalErrorOverride(config);
25
27
  // `LocaleContext.Provider` stays the outermost element here — the
26
28
  // client `AuthUserProvider` (and its descendants calling
27
29
  // usePathname()/useLocale()) must render as a CHILD of it, not a
@@ -24,4 +24,10 @@ export const defaultIgnoredConsoleErrors = [
24
24
  'auth/expired-action-code',
25
25
  'auth/invalid-action-code',
26
26
  'auth/user-token-expired',
27
+ 'The `punycode` module is deprecated. Please use a userland alternative instead.',
28
+ 'failed to pipe response',
29
+ 'Failed to fetch RSC payload',
30
+ ...(process.env.NODE_ENV === 'development'
31
+ ? ['A DurableObjectNamespace in the config referenced the class "DOQueueHandler", but no such Durable Object class is exported from the worker. Please make sure the class name matches,']
32
+ : []),
27
33
  ];
@@ -3,6 +3,7 @@ export type { WithErrorHandlingOptions } from './with_error_handling';
3
3
  export { default as reportError } from './report_error';
4
4
  export type { ReportErrorConfig } from './report_error';
5
5
  export { default as installConsoleErrorOverride } from './install_console_error_override';
6
+ export { default as installGlobalErrorOverride } from './install_global_error_override';
6
7
  export { default as stringifyUnknown } from './stringify_unknown';
7
8
  export { default as formatErrorMessage } from './format_error_message';
8
9
  export { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
@@ -1,6 +1,7 @@
1
1
  export { default as withErrorHandling } from './with_error_handling';
2
2
  export { default as reportError } from './report_error';
3
3
  export { default as installConsoleErrorOverride } from './install_console_error_override';
4
+ export { default as installGlobalErrorOverride } from './install_global_error_override';
4
5
  export { default as stringifyUnknown } from './stringify_unknown';
5
6
  export { default as formatErrorMessage } from './format_error_message';
6
7
  export { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
@@ -0,0 +1,20 @@
1
+ import { type ReportErrorConfig } from './report_error';
2
+ /**
3
+ * Client-only: attaches `window.addEventListener('error'|'unhandledrejection', ...)`
4
+ * handlers that route through `config.errorHandling.onError`/`reportError` —
5
+ * catches uncaught exceptions and unhandled promise rejections that never go
6
+ * through `console.error` at all (unlike `installConsoleErrorOverride`),
7
+ * e.g. Next.js's own internal "Failed to fetch RSC payload" navigation
8
+ * fallback. Neither handler calls `event.preventDefault()` — the browser's
9
+ * own default handling (logging to the console) still happens, nothing is
10
+ * swallowed. Safe to call more than once (a no-op after the first call in
11
+ * this JS realm). Takes effect when `config.errorHandling.overrideWindowErrors`
12
+ * is `true`, or when it's omitted and `overrideConsoleError` is `true` (so
13
+ * enabling `overrideConsoleError` alone catches everything by default; pass
14
+ * `overrideWindowErrors: false` explicitly to opt out of just this part).
15
+ * No-op when `window` doesn't exist (server-side).
16
+ *
17
+ * @param config Pass the relevant slices of your `RoutingConfig` directly —
18
+ * `{ errorHandling: config.errorHandling, generate: config.generate }`.
19
+ */
20
+ export default function installGlobalErrorOverride(config: ReportErrorConfig | undefined): void;
@@ -0,0 +1,44 @@
1
+ import reportError from './report_error';
2
+ import stringifyUnknown from './stringify_unknown';
3
+ /**
4
+ * Client-only: attaches `window.addEventListener('error'|'unhandledrejection', ...)`
5
+ * handlers that route through `config.errorHandling.onError`/`reportError` —
6
+ * catches uncaught exceptions and unhandled promise rejections that never go
7
+ * through `console.error` at all (unlike `installConsoleErrorOverride`),
8
+ * e.g. Next.js's own internal "Failed to fetch RSC payload" navigation
9
+ * fallback. Neither handler calls `event.preventDefault()` — the browser's
10
+ * own default handling (logging to the console) still happens, nothing is
11
+ * swallowed. Safe to call more than once (a no-op after the first call in
12
+ * this JS realm). Takes effect when `config.errorHandling.overrideWindowErrors`
13
+ * is `true`, or when it's omitted and `overrideConsoleError` is `true` (so
14
+ * enabling `overrideConsoleError` alone catches everything by default; pass
15
+ * `overrideWindowErrors: false` explicitly to opt out of just this part).
16
+ * No-op when `window` doesn't exist (server-side).
17
+ *
18
+ * @param config Pass the relevant slices of your `RoutingConfig` directly —
19
+ * `{ errorHandling: config.errorHandling, generate: config.generate }`.
20
+ */
21
+ export default function installGlobalErrorOverride(config) {
22
+ const enabled = config?.errorHandling?.overrideWindowErrors ?? config?.errorHandling?.overrideConsoleError;
23
+ if (enabled !== true)
24
+ return;
25
+ if (typeof window === 'undefined')
26
+ return;
27
+ if (window.__isGlobalErrorOverrideInstalled)
28
+ return;
29
+ window.__isGlobalErrorOverrideInstalled = true;
30
+ window.addEventListener('error', (event) => {
31
+ void reportError(config, {
32
+ error: event.error ?? stringifyUnknown(event.message, true),
33
+ classOrMethodName: 'Global Window Error Handler',
34
+ isClient: true,
35
+ });
36
+ });
37
+ window.addEventListener('unhandledrejection', (event) => {
38
+ void reportError(config, {
39
+ error: event.reason,
40
+ classOrMethodName: 'Global Unhandled Rejection Handler',
41
+ isClient: true,
42
+ });
43
+ });
44
+ }
@@ -4,13 +4,17 @@ export interface ReportErrorConfig {
4
4
  generate?: GenerateRoutingConfig;
5
5
  }
6
6
  /**
7
- * Reports `params` via `config.errorHandling.onError` (default
8
- * `console.error(params.formattedMessage)`), unless
7
+ * Reports `params`: logs `params.formattedMessage` via the real
8
+ * `console.error` (unless `config.errorHandling.logToConsole` is `false`)
9
+ * AND calls `config.errorHandling.onError` when set — both run, not one
10
+ * instead of the other, so wiring `onError` (Sentry, Telegram, etc) never
11
+ * silently loses the console output. Skips reporting entirely when
9
12
  * `config.errorHandling.enable === false`, `params.consent` is set and not
10
13
  * `true` (reporting to a third party without cookie consent can itself be
11
14
  * GDPR-relevant), or dedup throttles it (on by default — see
12
15
  * `errorHandling.dedup`/`throttleMs`/`resetDedup`). Never throws — a broken
13
- * reporter must not mask the original error.
16
+ * `onError` must not mask the original error (falls back to logging via the
17
+ * real console instead).
14
18
  *
15
19
  * Always overwrites `params.formattedMessage` with a fresh
16
20
  * `formatErrorMessage(params)` before reporting — a human-readable one-line
@@ -1,6 +1,13 @@
1
1
  import formatErrorMessage from './format_error_message';
2
2
  import stringifyUnknown from './stringify_unknown';
3
3
  const DEFAULT_THROTTLE_MS = 5000;
4
+ // Captured once at module load — BEFORE `installConsoleErrorOverride` can
5
+ // ever patch `console.error` — so `callOnError`'s own fallback/always-log
6
+ // path calls the real console, never the override. Calling a possibly-
7
+ // patched `console.error` here would loop straight back into
8
+ // `reportError` (the override's job is to call `reportError`), producing
9
+ // a duplicate (or, if `onError` itself throws, an infinite) report.
10
+ const originalConsoleError = console.error.bind(console);
4
11
  // Module-scope dedup state — safe by default only because a fresh JS realm
5
12
  // (isolate/Worker instance) starts with it cleared. In a long-lived server
6
13
  // process reused across many requests, pass `resetDedup: true` on the first
@@ -13,26 +20,30 @@ function buildDedupKey(params) {
13
20
  }
14
21
  async function callOnError(config, params) {
15
22
  const paramsWithFormattedMessage = { ...params, formattedMessage: formatErrorMessage(params) };
16
- try {
17
- if (config?.onError) {
23
+ if (config?.logToConsole !== false) {
24
+ originalConsoleError(paramsWithFormattedMessage.formattedMessage);
25
+ }
26
+ if (config?.onError) {
27
+ try {
18
28
  await config.onError(paramsWithFormattedMessage);
19
29
  }
20
- else {
21
- console.error(paramsWithFormattedMessage.formattedMessage);
30
+ catch {
31
+ originalConsoleError(paramsWithFormattedMessage.formattedMessage);
22
32
  }
23
33
  }
24
- catch {
25
- console.error(paramsWithFormattedMessage.formattedMessage);
26
- }
27
34
  }
28
35
  /**
29
- * Reports `params` via `config.errorHandling.onError` (default
30
- * `console.error(params.formattedMessage)`), unless
36
+ * Reports `params`: logs `params.formattedMessage` via the real
37
+ * `console.error` (unless `config.errorHandling.logToConsole` is `false`)
38
+ * AND calls `config.errorHandling.onError` when set — both run, not one
39
+ * instead of the other, so wiring `onError` (Sentry, Telegram, etc) never
40
+ * silently loses the console output. Skips reporting entirely when
31
41
  * `config.errorHandling.enable === false`, `params.consent` is set and not
32
42
  * `true` (reporting to a third party without cookie consent can itself be
33
43
  * GDPR-relevant), or dedup throttles it (on by default — see
34
44
  * `errorHandling.dedup`/`throttleMs`/`resetDedup`). Never throws — a broken
35
- * reporter must not mask the original error.
45
+ * `onError` must not mask the original error (falls back to logging via the
46
+ * real console instead).
36
47
  *
37
48
  * Always overwrites `params.formattedMessage` with a fresh
38
49
  * `formatErrorMessage(params)` before reporting — a human-readable one-line
@@ -9,6 +9,7 @@ import { getFirebaseAuthClient, getFirebaseAuthModule } from './firebase_client'
9
9
  import { setAuthUserCache } from './auth_user_cache';
10
10
  import { defaultRefreshTokenCookieName, defaultSessionCookieName } from '../middleware/update_session';
11
11
  import setCookie from '../../client/functions/set_cookie';
12
+ import clearSessionAction from '../server/clear_session_action';
12
13
  // `null` default (instead of a `{ loading: true, ... }` stand-in) lets
13
14
  // `useAuthUser` distinguish "not wrapped in AuthUserProvider" (throw) from
14
15
  // "wrapped, still loading" (`loading: true`).
@@ -25,6 +26,25 @@ function writeRefreshTokenCookie(refreshTokenCookieName, user, maxAge) {
25
26
  function clearRefreshTokenCookie(refreshTokenCookieName) {
26
27
  setCookie({ name: refreshTokenCookieName, value: '', maxAge: 0 });
27
28
  }
29
+ async function clearSession(sessionCookieName, refreshTokenCookieName) {
30
+ clearSessionCookie(sessionCookieName);
31
+ clearRefreshTokenCookie(refreshTokenCookieName);
32
+ try {
33
+ await clearSessionAction();
34
+ }
35
+ catch (e) {
36
+ console.error('AuthUserProvider: clearSessionAction failed', e);
37
+ }
38
+ }
39
+ async function writeSession(user, sessionCookieName, maxAge, refreshTokenCookieName, refreshTokenMaxAge) {
40
+ try {
41
+ writeRefreshTokenCookie(refreshTokenCookieName, user, refreshTokenMaxAge);
42
+ }
43
+ catch (e) {
44
+ console.error('AuthUserProvider: refresh-token cookie sync failed', e);
45
+ }
46
+ writeSessionCookie(sessionCookieName, await user.getIdToken(true), maxAge);
47
+ }
28
48
  /**
29
49
  * Client-side auth-state provider for `firebase_auth`. Wrap your root layout
30
50
  * (or a client boundary below it) with this to make `useAuthUser()`
@@ -94,18 +114,10 @@ export default function AuthUserProvider({ initialUser = null, children }) {
94
114
  const previous = syncedSignedIn.current;
95
115
  try {
96
116
  if (user) {
97
- try {
98
- writeRefreshTokenCookie(refreshTokenCookieName, user, refreshTokenMaxAge);
99
- }
100
- catch (e) {
101
- console.error('AuthUserProvider: refresh-token cookie sync failed', e);
102
- }
103
- const token = await user.getIdToken(true);
104
- writeSessionCookie(sessionCookieName, token, maxAge);
117
+ await writeSession(user, sessionCookieName, maxAge, refreshTokenCookieName, refreshTokenMaxAge);
105
118
  }
106
- else if (previous) {
107
- clearSessionCookie(sessionCookieName);
108
- clearRefreshTokenCookie(refreshTokenCookieName);
119
+ else {
120
+ await clearSession(sessionCookieName, refreshTokenCookieName);
109
121
  }
110
122
  }
111
123
  catch (e) {
@@ -147,13 +159,7 @@ export default function AuthUserProvider({ initialUser = null, children }) {
147
159
  try {
148
160
  const { reload } = await getFirebaseAuthModule();
149
161
  await reload(user);
150
- try {
151
- writeRefreshTokenCookie(refreshTokenCookieName, user, refreshTokenMaxAge);
152
- }
153
- catch (e) {
154
- console.error('AuthUserProvider: refresh-token cookie sync failed', e);
155
- }
156
- writeSessionCookie(sessionCookieName, await user.getIdToken(true), maxAge);
162
+ await writeSession(user, sessionCookieName, maxAge, refreshTokenCookieName, refreshTokenMaxAge);
157
163
  setAuthUserCache(user);
158
164
  setState({ user, loading: false });
159
165
  }
@@ -176,9 +182,8 @@ export default function AuthUserProvider({ initialUser = null, children }) {
176
182
  await signOut(auth);
177
183
  }
178
184
  finally {
179
- clearSessionCookie(sessionCookieName);
180
- clearRefreshTokenCookie(refreshTokenCookieName);
181
- window.location.assign(fa.redirectAuthPath);
185
+ await clearSession(sessionCookieName, refreshTokenCookieName);
186
+ router.push(fa.redirectAuthPath);
182
187
  }
183
188
  // eslint-disable-next-line react-hooks/exhaustive-deps
184
189
  }, [fa.redirectAuthPath, sessionCookieName, refreshTokenCookieName]);
@@ -3,6 +3,7 @@ export { default as FirebaseAuthServerProvider } from './server/auth_user_server
3
3
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
4
4
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
5
5
  export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
6
+ export { default as clearFirebaseAuthSession } from './server/clear_session_action';
6
7
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
7
8
  export { getFirebaseAuthClient } from './client/firebase_client';
8
9
  export type { SerializedAuthUser, AuthFormState, AuthActionMessages, AuthUser } from './types';
@@ -9,5 +9,6 @@ export { default as FirebaseAuthServerProvider } from './server/auth_user_server
9
9
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
10
10
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
11
11
  export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
12
+ export { default as clearFirebaseAuthSession } from './server/clear_session_action';
12
13
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
13
14
  export { getFirebaseAuthClient } from './client/firebase_client';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Server action: clears the httpOnly session/refresh-token cookies.
3
+ * `document.cookie` on the client can't touch httpOnly cookies, so
4
+ * `AuthUserProvider`'s `logout()` calls this instead of clearing them
5
+ * itself.
6
+ */
7
+ export default function clearSessionAction(): Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use server";
2
+ import { cookies } from "next/headers";
3
+ import config from "@intl-config";
4
+ import { defaultRefreshTokenCookieName, defaultSessionCookieName } from "../middleware/update_session";
5
+ /**
6
+ * Server action: clears the httpOnly session/refresh-token cookies.
7
+ * `document.cookie` on the client can't touch httpOnly cookies, so
8
+ * `AuthUserProvider`'s `logout()` calls this instead of clearing them
9
+ * itself.
10
+ */
11
+ export default async function clearSessionAction() {
12
+ const fa = config.firebaseAuth;
13
+ if (!fa)
14
+ return;
15
+ const sessionCookieName = fa.sessionCookieName ?? defaultSessionCookieName;
16
+ const refreshTokenCookieName = fa.refreshTokenCookieName ?? defaultRefreshTokenCookieName;
17
+ const cookieStore = await cookies();
18
+ cookieStore.delete(sessionCookieName);
19
+ cookieStore.delete(refreshTokenCookieName);
20
+ }
@@ -167,11 +167,22 @@ export interface ErrorHandlingRoutingConfig {
167
167
  */
168
168
  enable?: boolean;
169
169
  /**
170
- * Called with the caught error whenever one is reported. Defaults to
171
- * `console.error`. Use this to wire your own error-tracking/logging
172
- * transport (Sentry, Telegram, etc).
170
+ * Called with the caught error whenever one is reported, in ADDITION to
171
+ * the always-on `console.error(params.formattedMessage)` (see
172
+ * `logToConsole` to disable that). Use this to wire your own
173
+ * error-tracking/logging transport (Sentry, Telegram, etc) alongside the
174
+ * console log, not instead of it. Omit to just log to the console.
173
175
  */
174
176
  onError?: (params: ErrorHandlingParams) => void | Promise<void>;
177
+ /**
178
+ * Whether `reportError` also logs `params.formattedMessage` via the
179
+ * real, unpatched `console.error` (captured at module load, before
180
+ * `installConsoleErrorOverride` can touch it — so this never loops back
181
+ * into `reportError` even when the override is installed). Defaults to
182
+ * `true`. Set `false` if `onError` is your only sink and you don't want
183
+ * console output at all.
184
+ */
185
+ logToConsole?: boolean;
175
186
  /**
176
187
  * Whether `reportError`/`withErrorHandling` replace the global
177
188
  * `console.error` so every `console.error(...)` call in your app is
@@ -201,6 +212,20 @@ export interface ErrorHandlingRoutingConfig {
201
212
  * substring match.
202
213
  */
203
214
  ignoreConsoleError?: (message: string) => boolean;
215
+ /**
216
+ * Whether the client `LocationzationClientProvider` also installs
217
+ * `window.addEventListener('error'|'unhandledrejection', ...)` handlers
218
+ * that route through `onError`/`reportError` the same way
219
+ * `overrideConsoleError` does for `console.error(...)` calls. Catches
220
+ * uncaught exceptions and unhandled promise rejections that never go
221
+ * through `console.error` at all — e.g. Next.js's own internal
222
+ * "Failed to fetch RSC payload" navigation-fallback error. Defaults to
223
+ * `overrideConsoleError`'s value (so setting just `overrideConsoleError:
224
+ * true` catches everything by default) — pass `false` explicitly to
225
+ * enable console overriding without the window listeners. No-op on the
226
+ * server (no `window` there).
227
+ */
228
+ overrideWindowErrors?: boolean;
204
229
  /**
205
230
  * Dedup: `reportError` skips reporting an error whose key (`dedupKey`,
206
231
  * or a built-in key derived from `classOrMethodName`/`error`/`params`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
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",
@@ -148,6 +148,10 @@
148
148
  "types": "./dist/src/error_handling/install_console_error_override.d.ts",
149
149
  "import": "./dist/src/error_handling/install_console_error_override.js"
150
150
  },
151
+ "./installGlobalErrorOverride": {
152
+ "types": "./dist/src/error_handling/install_global_error_override.d.ts",
153
+ "import": "./dist/src/error_handling/install_global_error_override.js"
154
+ },
151
155
  "./stringifyUnknown": {
152
156
  "types": "./dist/src/error_handling/stringify_unknown.d.ts",
153
157
  "import": "./dist/src/error_handling/stringify_unknown.js"
@@ -1 +0,0 @@
1
- export default function ClientHelperScript(): null;
@@ -1,34 +0,0 @@
1
- import type { TranslationObject } from "../../types/types";
2
- import type { SerializedAuthUser } from "../../firebase_auth/types";
3
- import type { CookieConsentAnalyticsConfig } from "../../types/types";
4
- import type { CookieConsentDialogProps } from "../../cookie_consent/client/components/cookie_consent_dialog";
5
- import type { PrivacyPolicyUpdateDialogProps } from "../../cookie_consent/client/components/privacy_policy_update_dialog";
6
- interface LocaleContextType {
7
- language: string;
8
- messages: TranslationObject;
9
- }
10
- export declare const LocaleContext: import("react").Context<LocaleContextType | undefined>;
11
- export default function LocationzationClientProvider({ language, messages, initialAuthUser, skipAuthProvider, analyticsConfig, requiresConsent, autoWireDialogs, dialogProps, updateDialogProps, children }: {
12
- language: string;
13
- messages: TranslationObject;
14
- initialAuthUser?: SerializedAuthUser | null;
15
- /** Set when `firebaseAuth.autoWireClientProvider` is `false` — skips wrapping `children` in the client `AuthUserProvider` entirely. */
16
- skipAuthProvider?: boolean;
17
- /** Resolved server-side from `cookieConsent.analytics`/`getAnalytics` when `autoWireAnalytics` isn't `false`. */
18
- analyticsConfig?: CookieConsentAnalyticsConfig;
19
- /**
20
- * Resolved server-side from `cookieConsent.getCountryCode`/`gdprCountries`.
21
- * `false` means the visitor's country doesn't require the consent
22
- * banner — `CookieConsentProvider` seeds consent as implicitly granted
23
- * for a first-time visitor instead of `null`.
24
- */
25
- requiresConsent?: boolean;
26
- /** From `cookieConsent.autoWireDialogs` — renders `CookieConsentDialog`/`PrivacyPolicyUpdateDialog` automatically when `true` (default). */
27
- autoWireDialogs?: boolean;
28
- /** From `cookieConsent.dialogProps` — forwarded as-is to the auto-wired `CookieConsentDialog`. */
29
- dialogProps?: CookieConsentDialogProps;
30
- /** From `cookieConsent.updateDialogProps` — forwarded as-is to the auto-wired `PrivacyPolicyUpdateDialog`. */
31
- updateDialogProps?: PrivacyPolicyUpdateDialogProps;
32
- children: React.ReactNode;
33
- }): Component;
34
- export {};
@@ -1,30 +0,0 @@
1
- import { type LinkProps } from 'next/link';
2
- import { type ComponentProps } from 'react';
3
- type NextLinkProps = Omit<ComponentProps<'a'>, keyof LinkProps> & Omit<LinkProps, 'locale' | 'href' | 'prefetch' | 'onNavigate' | 'hrefLang' | 'replace' | 'scroll'>;
4
- export type LocaleLinkProps = NextLinkProps & {
5
- locale: string;
6
- };
7
- /**
8
- * Client-only link component for linking to a SPECIFIC locale — e.g. a
9
- * language switcher. Import from `cloudflare-next-intl/LocaleLink`.
10
- *
11
- * For normal in-app navigation that should stay on the current locale, use
12
- * the server-side `Link` (`cloudflare-next-intl/Link`) instead — it infers
13
- * the locale automatically and doesn't require `"use client"`.
14
- *
15
- * Renders inside a `Suspense` boundary; falls back to a disabled `<a>`
16
- * (`pointer-events-none`) while resolving.
17
- *
18
- * @param locale Required. The locale to link to (e.g. `"de"`), prepended to
19
- * `href` regardless of the current locale.
20
- *
21
- * @example
22
- * ```tsx
23
- * "use client";
24
- * import LocaleLink from "cloudflare-next-intl/LocaleLink";
25
- *
26
- * <LocaleLink href="/about" locale="de">Über uns</LocaleLink> // -> "/de/about"
27
- * ```
28
- */
29
- declare const LocaleLink: import("react").ForwardRefExoticComponent<Omit<LocaleLinkProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement>>;
30
- export default LocaleLink;
@@ -1,3 +0,0 @@
1
- import type { LocaleLinkProps } from './locale_link';
2
- declare const LocaleLinkClient: import("react").ForwardRefExoticComponent<Omit<LocaleLinkProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement>>;
3
- export default LocaleLinkClient;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * Client-only: reads a `document.cookie` value by name. Pairs with
3
- * {@link setCookie} for your OWN client-side cookies — this package's
4
- * locale/theme cookies are managed internally, you don't need this for those.
5
- *
6
- * @param name Cookie name to look up.
7
- * @returns The decoded cookie value, or `null` if not found (or on error,
8
- * logged instead of thrown).
9
- */
10
- export default function getCookie(name: string): string | null;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- /**
2
- * Client-only: sets a `document.cookie` value directly. Not used by this
3
- * package's own locale handling (that goes through `intlMiddleware` server-side)
4
- * — this is a small utility for your OWN client-side cookies (e.g. a
5
- * "dismissed banner" flag).
6
- *
7
- * @param name Cookie name.
8
- * @param value Cookie value; stringified via template literal (no encoding
9
- * applied — avoid values containing `;`). Must be a primitive
10
- * (`string`/`number`/`boolean`) — objects would silently serialize to
11
- * `"[object Object]"`.
12
- * @param maxAge Seconds until expiry. Defaults to 1 year.
13
- *
14
- * Always `path=/; SameSite=Lax`. Swallows errors (e.g. in restrictive
15
- * environments) and logs them instead of throwing.
16
- */
17
- export default function setCookie({ name, value, maxAge }: {
18
- name: string;
19
- value: string | number | boolean;
20
- maxAge?: number;
21
- }): void;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import type { TranslatorReturnType } from "../../types/types";
2
- /**
3
- * Client Component `useLocale` — reached via the default condition of the
4
- * `cloudflare-next-intl/use` subpath (Server Components get the
5
- * `use_functions.ts` variant automatically instead; always import from
6
- * `"cloudflare-next-intl/use"`, never this file directly).
7
- *
8
- * Reads the locale from React context set up by `IntlProvider`.
9
- *
10
- * @returns The current locale (e.g. `"en"`).
11
- * @throws If rendered outside `IntlProvider`.
12
- * @example
13
- * const locale = useLocale(); // "en"
14
- */
15
- export declare function useLocale(): string;
16
- /**
17
- * Client Component `useTranslations` — see {@link useLocale} for the
18
- * subpath-resolution note.
19
- *
20
- * @param namespace Dot-separated key prefix into your messages file.
21
- * @returns A `(key: string) => string` translation function, memoized on
22
- * `[language, messages, namespace]`.
23
- * @throws If rendered outside `IntlProvider`.
24
- * @example
25
- * const t = useTranslations("Index");
26
- * return <h1>{t("title")}</h1>;
27
- */
28
- export declare function useTranslations(namespace: string): TranslatorReturnType;
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * Client hook: like `next/navigation`'s `usePathname`, but with the locale
3
- * segment stripped — so `/de/about` returns `/about`, matching the
4
- * locale-agnostic paths used elsewhere in this package (e.g. `Link` href).
5
- * Must be used inside `IntlProvider`/`LocaleContext` (via {@link useLocale}).
6
- *
7
- * @returns The current pathname without its locale prefix (e.g. `/about`, or
8
- * `/` for the root).
9
- */
10
- export default function usePathname(): string;
@@ -1,4 +0,0 @@
1
- export { default as LocaleLink } from './components/locale_link';
2
- export { default as usePathname } from './hooks/use_path_name';
3
- export { default as setCookieClient } from './functions/set_cookie';
4
- export { default as getCookieClient } from './functions/get_cookie';
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export declare const localeCookieName = "__user_locale_key__";
2
- export declare const isBotCookieKey = "__is_bot_key__";
3
- export declare const isDarkCookieKey = "__is_dark_key__";
4
- export declare const cookieConsentCookieKey = "__cookie_consent_key__";
5
- export declare const privacyPolicyDateCookieKey = "__privacy_policy_date_key__";
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export { isBotCookieKey, localeCookieName, isDarkCookieKey, cookieConsentCookieKey, privacyPolicyDateCookieKey } from './cookie_key';
2
- export { default as intlMiddleware } from './middleware';
3
- export { setIntlConfig } from './init_config';
4
- export { default as generateIntlSitemap } from './intl_sitemap';
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- import type { LocalePrefixMode, Locales, RoutingConfig } from '../types/types';
2
- /**
3
- * Defines and type-checks your app's i18n routing config.
4
- *
5
- * Identity function at runtime — it exists purely so TypeScript infers
6
- * `AppLocales`/`AppLocalePrefixMode` from the literal config object you pass
7
- * in, giving you autocomplete/type errors on `locale` params elsewhere.
8
- *
9
- * Export the result from the file referenced by `@intl-config` (see your
10
- * `next.config`), e.g.:
11
- * ```ts
12
- * export default setIntlConfig({
13
- * locales: ["en", "fr"] as const,
14
- * defaultLocale: "en",
15
- * });
16
- * ```
17
- */
18
- export declare function setIntlConfig<const AppLocales extends Locales, const AppLocalePrefixMode extends LocalePrefixMode = 'as-needed'>(config: RoutingConfig<AppLocales, AppLocalePrefixMode>): RoutingConfig<AppLocales, AppLocalePrefixMode>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { LocalePrefixMode, Locales, RoutingConfig } from '../types/types';
2
- declare const config: RoutingConfig<Locales, LocalePrefixMode>;
3
- export default config;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};