cloudflare-next-intl 0.6.2 → 0.6.4

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 (142) hide show
  1. package/dist/src/error_handling/create_server_error_action.d.ts +32 -0
  2. package/dist/src/error_handling/create_server_error_action.js +41 -0
  3. package/dist/types/client/components/client_helper_script.d.ts +1 -0
  4. package/dist/types/client/components/client_provider.d.ts +34 -0
  5. package/dist/types/client/components/locale_link.d.ts +30 -0
  6. package/dist/types/client/components/locale_link_client.d.ts +3 -0
  7. package/dist/types/client/functions/get_cookie.bench.d.ts +1 -0
  8. package/dist/types/client/functions/get_cookie.d.ts +10 -0
  9. package/dist/types/client/functions/get_cookie.test.d.ts +1 -0
  10. package/dist/types/client/functions/set_cookie.bench.d.ts +1 -0
  11. package/dist/types/client/functions/set_cookie.d.ts +21 -0
  12. package/dist/types/client/functions/set_cookie.test.d.ts +1 -0
  13. package/dist/types/client/hooks/client_hooks.bench.d.ts +1 -0
  14. package/dist/types/client/hooks/client_hooks.d.ts +28 -0
  15. package/dist/types/client/hooks/use_path_name.bench.d.ts +1 -0
  16. package/dist/types/client/hooks/use_path_name.d.ts +10 -0
  17. package/dist/types/client/index.d.ts +4 -0
  18. package/dist/types/config/cookie_key.bench.d.ts +1 -0
  19. package/dist/types/config/cookie_key.d.ts +5 -0
  20. package/dist/types/config/cookie_key.test.d.ts +1 -0
  21. package/dist/types/config/index.d.ts +4 -0
  22. package/dist/types/config/init_config.bench.d.ts +1 -0
  23. package/dist/types/config/init_config.d.ts +18 -0
  24. package/dist/types/config/init_config.test.d.ts +1 -0
  25. package/dist/types/config/intl_config.d.ts +3 -0
  26. package/dist/types/config/intl_config.test.d.ts +1 -0
  27. package/dist/types/config/intl_sitemap.bench.d.ts +1 -0
  28. package/dist/types/config/intl_sitemap.d.ts +8 -0
  29. package/dist/types/config/intl_sitemap.test.d.ts +1 -0
  30. package/dist/types/config/middleware.bench.d.ts +1 -0
  31. package/dist/types/config/middleware.d.ts +21 -0
  32. package/dist/types/config/middleware.test.d.ts +1 -0
  33. package/dist/types/cookie_consent/client/components/clarity_script.d.ts +10 -0
  34. package/dist/types/cookie_consent/client/components/cookie_consent_analytics.bench.d.ts +1 -0
  35. package/dist/types/cookie_consent/client/components/cookie_consent_analytics.d.ts +19 -0
  36. package/dist/types/cookie_consent/client/components/cookie_consent_dialog.d.ts +35 -0
  37. package/dist/types/cookie_consent/client/components/default_dialog_styles.d.ts +2 -0
  38. package/dist/types/cookie_consent/client/components/default_dialog_text.d.ts +13 -0
  39. package/dist/types/cookie_consent/client/components/default_privacy_policy_link.d.ts +14 -0
  40. package/dist/types/cookie_consent/client/components/dialog_portal.d.ts +11 -0
  41. package/dist/types/cookie_consent/client/components/privacy_policy_update_dialog.d.ts +31 -0
  42. package/dist/types/cookie_consent/client/cookie_consent_provider.bench.d.ts +1 -0
  43. package/dist/types/cookie_consent/client/cookie_consent_provider.d.ts +39 -0
  44. package/dist/types/cookie_consent/client/use_cookie_consent.d.ts +6 -0
  45. package/dist/types/cookie_consent/gdpr_countries.bench.d.ts +1 -0
  46. package/dist/types/cookie_consent/gdpr_countries.d.ts +18 -0
  47. package/dist/types/cookie_consent/gdpr_countries.perf.test.d.ts +1 -0
  48. package/dist/types/cookie_consent/gdpr_countries.test.d.ts +1 -0
  49. package/dist/types/cookie_consent/index.d.ts +10 -0
  50. package/dist/types/cookie_consent/require_config.d.ts +7 -0
  51. package/dist/types/cookie_consent/require_config.test.d.ts +1 -0
  52. package/dist/types/cookie_consent/types.d.ts +57 -0
  53. package/dist/types/error_handling/create_server_error_action.d.ts +19 -0
  54. package/dist/types/error_handling/create_server_error_action.test.d.ts +1 -0
  55. package/dist/types/error_handling/default_ignored_console_errors.d.ts +13 -0
  56. package/dist/types/error_handling/default_ignored_console_errors.test.d.ts +1 -0
  57. package/dist/types/error_handling/format_error_message.d.ts +9 -0
  58. package/dist/types/error_handling/format_error_message.test.d.ts +1 -0
  59. package/dist/types/error_handling/index.d.ts +9 -0
  60. package/dist/types/error_handling/install_console_error_override.bench.d.ts +1 -0
  61. package/dist/types/error_handling/install_console_error_override.d.ts +29 -0
  62. package/dist/types/error_handling/install_console_error_override.perf.test.d.ts +1 -0
  63. package/dist/types/error_handling/install_console_error_override.test.d.ts +1 -0
  64. package/dist/types/error_handling/report_error.bench.d.ts +1 -0
  65. package/dist/types/error_handling/report_error.d.ts +40 -0
  66. package/dist/types/error_handling/report_error.perf.test.d.ts +1 -0
  67. package/dist/types/error_handling/report_error.test.d.ts +1 -0
  68. package/dist/types/error_handling/stringify_unknown.bench.d.ts +1 -0
  69. package/dist/types/error_handling/stringify_unknown.d.ts +12 -0
  70. package/dist/types/error_handling/stringify_unknown.test.d.ts +1 -0
  71. package/dist/types/error_handling/with_error_handling.d.ts +15 -0
  72. package/dist/types/error_handling/with_error_handling.test.d.ts +1 -0
  73. package/dist/types/firebase_auth/client/auth_actions.bench.d.ts +1 -0
  74. package/dist/types/firebase_auth/client/auth_actions.d.ts +46 -0
  75. package/dist/types/firebase_auth/client/auth_actions.test.d.ts +1 -0
  76. package/dist/types/firebase_auth/client/auth_user_cache.bench.d.ts +1 -0
  77. package/dist/types/firebase_auth/client/auth_user_cache.d.ts +4 -0
  78. package/dist/types/firebase_auth/client/auth_user_cache.test.d.ts +1 -0
  79. package/dist/types/firebase_auth/client/auth_user_provider.d.ts +36 -0
  80. package/dist/types/firebase_auth/client/firebase_client.bench.d.ts +1 -0
  81. package/dist/types/firebase_auth/client/firebase_client.d.ts +20 -0
  82. package/dist/types/firebase_auth/client/firebase_client.test.d.ts +1 -0
  83. package/dist/types/firebase_auth/client/use_auth_user.bench.d.ts +1 -0
  84. package/dist/types/firebase_auth/client/use_auth_user.d.ts +12 -0
  85. package/dist/types/firebase_auth/error_messages/default_messages.en.bench.d.ts +1 -0
  86. package/dist/types/firebase_auth/error_messages/default_messages.en.d.ts +1 -0
  87. package/dist/types/firebase_auth/error_messages/default_messages.en.test.d.ts +1 -0
  88. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.bench.d.ts +1 -0
  89. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.d.ts +6 -0
  90. package/dist/types/firebase_auth/error_messages/firebase_auth_error_helper.test.d.ts +1 -0
  91. package/dist/types/firebase_auth/index.d.ts +9 -0
  92. package/dist/types/firebase_auth/middleware/update_session.bench.d.ts +1 -0
  93. package/dist/types/firebase_auth/middleware/update_session.d.ts +22 -0
  94. package/dist/types/firebase_auth/middleware/update_session.test.d.ts +1 -0
  95. package/dist/types/firebase_auth/require_config.bench.d.ts +1 -0
  96. package/dist/types/firebase_auth/require_config.d.ts +8 -0
  97. package/dist/types/firebase_auth/require_config.test.d.ts +1 -0
  98. package/dist/types/firebase_auth/server/auth_user_server_provider.d.ts +29 -0
  99. package/dist/types/firebase_auth/server/firebase_server.bench.d.ts +1 -0
  100. package/dist/types/firebase_auth/server/firebase_server.d.ts +15 -0
  101. package/dist/types/firebase_auth/server/firebase_server.perf.test.d.ts +1 -0
  102. package/dist/types/firebase_auth/server/firebase_server.test.d.ts +1 -0
  103. package/dist/types/firebase_auth/server/use_auth_user_server.bench.d.ts +1 -0
  104. package/dist/types/firebase_auth/server/use_auth_user_server.d.ts +39 -0
  105. package/dist/types/firebase_auth/server/use_auth_user_server.test.d.ts +1 -0
  106. package/dist/types/firebase_auth/types.d.ts +22 -0
  107. package/dist/types/general/cache_variables.bench.d.ts +1 -0
  108. package/dist/types/general/cache_variables.d.ts +14 -0
  109. package/dist/types/general/cache_variables.test.d.ts +1 -0
  110. package/dist/types/general/general_functions.bench.d.ts +1 -0
  111. package/dist/types/general/general_functions.d.ts +2 -0
  112. package/dist/types/general/general_functions.test.d.ts +1 -0
  113. package/dist/types/general/index.d.ts +2 -0
  114. package/dist/types/general/metadata.bench.d.ts +1 -0
  115. package/dist/types/general/metadata.d.ts +38 -0
  116. package/dist/types/general/metadata.test.d.ts +1 -0
  117. package/dist/types/index.d.ts +6 -0
  118. package/dist/types/server/components/helper_script.d.ts +20 -0
  119. package/dist/types/server/components/link.d.ts +25 -0
  120. package/dist/types/server/components/server_provider.d.ts +35 -0
  121. package/dist/types/server/functions/get_user_locale.bench.d.ts +1 -0
  122. package/dist/types/server/functions/get_user_locale.d.ts +3 -0
  123. package/dist/types/server/functions/get_user_locale.test.d.ts +1 -0
  124. package/dist/types/server/functions/locale_static_params.d.ts +15 -0
  125. package/dist/types/server/functions/locale_static_params.test.d.ts +1 -0
  126. package/dist/types/server/functions/server.bench.d.ts +1 -0
  127. package/dist/types/server/functions/server.d.ts +67 -0
  128. package/dist/types/server/functions/server.perf.test.d.ts +1 -0
  129. package/dist/types/server/functions/server.test.d.ts +1 -0
  130. package/dist/types/server/functions/use_functions.bench.d.ts +1 -0
  131. package/dist/types/server/functions/use_functions.d.ts +33 -0
  132. package/dist/types/server/functions/use_functions.test.d.ts +1 -0
  133. package/dist/types/server/index.d.ts +5 -0
  134. package/dist/types/test_utils/mock_intl_config.d.ts +3 -0
  135. package/dist/types/test_utils/mock_next_server.d.ts +5 -0
  136. package/dist/types/theme_switcher/components/icons.d.ts +6 -0
  137. package/dist/types/theme_switcher/components/theme_switcher.d.ts +15 -0
  138. package/dist/types/theme_switcher/components/theme_switcher_button.d.ts +6 -0
  139. package/dist/types/theme_switcher/index.d.ts +1 -0
  140. package/dist/types/types/index.d.ts +1 -0
  141. package/dist/types/types/types.d.ts +548 -0
  142. package/package.json +5 -1
@@ -0,0 +1,548 @@
1
+ import type { NextResponse } from 'next/server';
2
+ import type { Languages } from 'next/dist/lib/metadata/types/alternative-urls-types';
3
+ import type { Videos } from 'next/dist/lib/metadata/types/metadata-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
+ import type { ConsentValue } from '../cookie_consent/types';
7
+ /**
8
+ * Custom middleware hook, run by `intlMiddleware` for your own logic
9
+ * (e.g. auth, feature flags, A/B tests) — on top of the library's own
10
+ * locale routing (locale-prefix rewrite/redirect).
11
+ *
12
+ * STRICT RULE — at most ONE of `rewriteUrl` / `redirectUrl` is ever set, and
13
+ * whichever is set tells you exactly what to do:
14
+ * - `rewriteUrl` set: apply `NextResponse.rewrite(rewriteUrl, { request })`
15
+ * (locale matches the default locale — URL bar stays unchanged).
16
+ * - `redirectUrl` set: apply `NextResponse.redirect(redirectUrl, request)`
17
+ * (locale differs from the URL — visible redirect). The handler only runs
18
+ * for this case when `runHandlerOnRedirect: true` is passed.
19
+ * - BOTH undefined: no locale routing needed (URL already has the right
20
+ * locale prefix). This is where your own logic belongs — return
21
+ * `NextResponse.next({ request })`, or your own redirect (e.g. auth).
22
+ *
23
+ * Returning `null` in any case makes the library apply its own default,
24
+ * which is the same rewrite/redirect/`next()` described above.
25
+ *
26
+ * @param locale The resolved locale for this request (e.g. `"en"`).
27
+ * @param rewriteUrl URL to rewrite to, or `undefined`.
28
+ * @param redirectUrl URL to redirect to, or `undefined`.
29
+ * @returns A `NextResponse` to use for this request, or `null` to
30
+ * let the library build the default one.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * middlewareHandler: (locale, rewriteUrl, redirectUrl) => {
35
+ * if (rewriteUrl) return NextResponse.rewrite(rewriteUrl, { request });
36
+ * if (redirectUrl) return NextResponse.redirect(redirectUrl, request);
37
+ * // No locale routing needed — your own logic goes here.
38
+ * return NextResponse.next({ request });
39
+ * }
40
+ * ```
41
+ */
42
+ export type MiddlewareCustomHandler = (locale: string, rewriteUrl: URL | undefined, redirectUrl: URL | undefined) => NextResponse<unknown> | null | Promise<NextResponse<unknown> | null>;
43
+ /** Your app's list of supported locale codes, e.g. `["en", "de"] as const`. */
44
+ export type Locales = readonly string[];
45
+ /**
46
+ * NOTE: currently unused by `intlMiddleware`'s actual routing logic (it
47
+ * always rewrites for `defaultLocale` and redirects otherwise) — reserved
48
+ * for future use. Setting `localePrefix` on {@link RoutingConfig} has no
49
+ * runtime effect yet.
50
+ */
51
+ export type LocalePrefixMode = 'always' | 'as-needed' | 'never';
52
+ /**
53
+ * The config object you build with `setIntlConfig` and export from the file
54
+ * referenced by the `@intl-config` alias in `next.config` (see the package
55
+ * README's Setup section). Consumed internally by `intlMiddleware`,
56
+ * `getLocale`, `getTranslations`, and friends.
57
+ */
58
+ export interface RoutingConfig<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode> {
59
+ /**
60
+ * All available locales.
61
+ */
62
+ locales: AppLocales;
63
+ /**
64
+ * Used when no locale matches.
65
+ */
66
+ defaultLocale: string;
67
+ /**
68
+ * Configures whether and which prefix is shown for a given locale.
69
+ **/
70
+ localePrefix?: AppLocalePrefixMode;
71
+ /**
72
+ * Can be used to disable the locale cookie or to customize it.
73
+ */
74
+ localeCookie?: false | CookieAttributes;
75
+ /**
76
+ * By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection.
77
+ **/
78
+ localeDetection?: boolean;
79
+ /**
80
+ * Configures the optional `firebase_auth` submodule. Omit entirely (or
81
+ * leave undefined) to keep it fully disabled — no file in this package
82
+ * ever imports `firebase/app`/`firebase/auth` unless a firebase_auth
83
+ * export is actually called, and every such export throws a clear error
84
+ * if this field is missing at call time rather than silently no-op'ing.
85
+ */
86
+ firebaseAuth?: FirebaseAuthRoutingConfig;
87
+ /**
88
+ * Configures the optional `cookie_consent` submodule (cookie-consent +
89
+ * privacy-policy-update banners). Omit entirely to keep it disabled —
90
+ * `useCookieConsent()`/`CookieConsentProvider` will throw a descriptive
91
+ * error if called without this set.
92
+ */
93
+ cookieConsent?: CookieConsentRoutingConfig;
94
+ /**
95
+ * Request-time resolvers shared across submodules. Omit entirely to
96
+ * leave all of them unset.
97
+ */
98
+ generate?: GenerateRoutingConfig;
99
+ /**
100
+ * Configures the optional `error_handling` submodule (shared
101
+ * `withErrorHandling`/`reportError` helpers used internally by this
102
+ * package and available to your own app code). Omit entirely to keep
103
+ * the defaults: enabled, reporting via `console.error`.
104
+ */
105
+ errorHandling?: ErrorHandlingRoutingConfig;
106
+ }
107
+ export interface GenerateRoutingConfig {
108
+ /**
109
+ * Pass `getCloudflareContext` from `@opennextjs/cloudflare` directly
110
+ * (not a dependency of this package, so bring your own import) — its
111
+ * exact overloaded signature is accepted as-is; called internally with
112
+ * `{ async: true }`, so you never need to wrap it yourself. Only
113
+ * `cf.country` is read from the resolved context by `cookieConsent`.
114
+ *
115
+ * Country-based gating (via either `cookieConsent.getCountryCode` or
116
+ * this getter) decides whether the cookie-consent banner is required at
117
+ * all: visitors outside `gdprCountries` skip the banner and get
118
+ * analytics immediately (still gated by `enableAnalyticsInDevMode`).
119
+ * Omit BOTH to require consent for everyone (fail-safe default — the
120
+ * visitor's country can't be determined at all without either getter).
121
+ * Set one of the two getters to scope the banner to GDPR regions only.
122
+ */
123
+ getCloudflareContext?: CookieConsentGetCloudflareContext;
124
+ }
125
+ export interface ErrorHandlingParams {
126
+ /** The caught error, in whatever shape it was thrown/rejected with. */
127
+ error: unknown;
128
+ /** Name of the function/method the error was caught in, e.g. `"resolveRequiresConsent"`. */
129
+ classOrMethodName: string;
130
+ /** Extra context to include in the report (arguments, request info, etc). */
131
+ params?: unknown;
132
+ /** Whether this error originated in a client-side (browser) call. */
133
+ isClient?: boolean;
134
+ /**
135
+ * The visitor's current cookie-consent value (from `useCookieConsent()`
136
+ * or your own server-side resolution), when known. When passed and not
137
+ * `true`, `reportError`/`withErrorHandling` skip reporting entirely —
138
+ * sending error reports to a third party (Telegram, Sentry, etc.)
139
+ * without consent can itself be GDPR-relevant. Omit when consent isn't
140
+ * applicable (e.g. `cookieConsent` isn't configured at all).
141
+ */
142
+ consent?: ConsentValue;
143
+ /**
144
+ * Human-readable one-string summary — `[classOrMethodName] Error:
145
+ * <message>` plus non-empty `Params`/client-origin sections. Set by
146
+ * `reportError` before calling `onError`/`console.error`; read this
147
+ * instead of `error`/`params` directly when you just want something
148
+ * printable. Ignore when passing `params` to `withErrorHandling`
149
+ * yourself — it's always overwritten.
150
+ */
151
+ formattedMessage?: string;
152
+ /**
153
+ * Key used by `config.errorHandling.dedupGate` to dedup this report
154
+ * against the immediately preceding one. Defaults to
155
+ * `` `${classOrMethodName} ${stringifyUnknown(error)} ${stringifyUnknown(params ?? '')}` ``
156
+ * when omitted (built by `reportError` itself) — set this explicitly
157
+ * only if you want a coarser/different dedup key.
158
+ */
159
+ dedupKey?: string;
160
+ }
161
+ export interface ErrorHandlingRoutingConfig {
162
+ /**
163
+ * Whether errors caught by this package's `withErrorHandling`/
164
+ * `reportError` helpers are reported at all. Defaults to `true`. Set
165
+ * `false` to fully disable reporting (errors are still rethrown by
166
+ * `withErrorHandling`, just never reported).
167
+ */
168
+ enable?: boolean;
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).
173
+ */
174
+ onError?: (params: ErrorHandlingParams) => void | Promise<void>;
175
+ /**
176
+ * Whether `reportError`/`withErrorHandling` replace the global
177
+ * `console.error` so every `console.error(...)` call in your app is
178
+ * also routed through `onError` (the original `console.error` still
179
+ * runs afterwards — nothing is swallowed). Defaults to `false`; call
180
+ * `installConsoleErrorOverride()` (or pass this `true` and call
181
+ * `IntlProvider`/`setIntlConfig`'s setup) to install it. Off by default
182
+ * since this package is shared across apps and a global override is a
183
+ * bigger behavior change than a plain function call.
184
+ */
185
+ overrideConsoleError?: boolean;
186
+ /**
187
+ * Substrings matched against the stringified message of each
188
+ * `console.error(...)` call (only consulted when `overrideConsoleError`
189
+ * is `true`) — a match skips reporting it (it's still logged normally).
190
+ * Defaults to `defaultIgnoredConsoleErrors` (this package's own Firebase
191
+ * Auth error codes for expected user-input failures — wrong password,
192
+ * email already in use, etc). Pass your own array to replace the
193
+ * default entirely; pass `[]` to report everything.
194
+ */
195
+ ignoreConsoleErrors?: readonly string[];
196
+ /**
197
+ * Called with the stringified message of each `console.error(...)` call
198
+ * (only consulted when `overrideConsoleError` is `true`), in addition to
199
+ * `ignoreConsoleErrors` — return `true` to skip reporting it (it's still
200
+ * logged normally). Use this for custom filtering logic beyond a plain
201
+ * substring match.
202
+ */
203
+ ignoreConsoleError?: (message: string) => boolean;
204
+ /**
205
+ * Dedup: `reportError` skips reporting an error whose key (`dedupKey`,
206
+ * or a built-in key derived from `classOrMethodName`/`error`/`params`
207
+ * when omitted) matches the immediately preceding reported error's key,
208
+ * within `throttleMs`. On by default (matches this package's own
209
+ * internal call sites and `installConsoleErrorOverride`'s console-loop
210
+ * guard). Set `false` to report every distinct call with no dedup at
211
+ * all.
212
+ *
213
+ * The dedup state lives inside `reportError`'s own module — this is
214
+ * shared mutable state, safe by default only because a fresh JS realm
215
+ * (isolate/Worker instance) starts with it cleared; in a long-lived
216
+ * server process reused across many requests, pass `resetDedup: true`
217
+ * on the first `reportError` call of each request/cron tick to clear it
218
+ * (otherwise one request's errors can suppress another's).
219
+ */
220
+ dedup?: boolean;
221
+ /** Throttle window in ms: the same dedup key reported again within this window is skipped. Defaults to `5000`. Only consulted when `dedup` isn't `false`. */
222
+ throttleMs?: number;
223
+ /** Clears the dedup last-key/timestamp state before processing this call. Pass `true` on the first `reportError` call of each request/cron tick in a long-lived server process. */
224
+ resetDedup?: boolean;
225
+ }
226
+ export interface CookieConsentRoutingConfig {
227
+ /**
228
+ * Date the current privacy policy was last modified, e.g. `"2026-07-20"`
229
+ * or a `Date`. When set, the "privacy policy updated" banner
230
+ * automatically shows to any visitor whose stored consent predates this
231
+ * date. Omit to disable the privacy-policy-update banner entirely (the
232
+ * cookie-consent banner still works independently).
233
+ */
234
+ privacyPolicyDate?: string | Date;
235
+ /**
236
+ * Path to your privacy-policy page, e.g. `"/privacy-policy"`. Used by
237
+ * `CookieConsentDialog`/`PrivacyPolicyUpdateDialog` to render a default
238
+ * link automatically when their `link` prop is omitted. Defaults to
239
+ * `'/privacy-policy'`. Set `false` to render no link by default (still
240
+ * overridable per-dialog via the `link` prop).
241
+ */
242
+ privacyPolicyPath?: string | false;
243
+ /** Cookie-consent cookie name. Defaults to `'__cookie_consent_key__'`. */
244
+ consentCookieName?: string;
245
+ /** Privacy-policy-date cookie name. Defaults to `'__privacy_policy_date_key__'`. */
246
+ privacyPolicyDateCookieName?: string;
247
+ /** Cookie max-age in seconds for both cookies above. Defaults to 1 year (31536000). */
248
+ cookieMaxAge?: number;
249
+ /**
250
+ * Whether `IntlProvider` should automatically render the analytics/ads
251
+ * scripts (Cloudflare Web Analytics beacon, Google Consent Mode + gtag,
252
+ * Microsoft Clarity — whichever config resolves below) once consent is
253
+ * granted, and gate them behind the cookie-consent banner otherwise.
254
+ * Defaults to `true` when `analytics`/`getAnalytics` is set; set `false`
255
+ * to keep `cookieConsent` configured for the dialogs/hook only and wire
256
+ * analytics yourself.
257
+ */
258
+ autoWireAnalytics?: boolean;
259
+ /**
260
+ * Static IDs/tokens for the analytics providers below. Use this OR
261
+ * `getAnalytics`, not both — `getAnalytics` takes precedence when both are
262
+ * set (e.g. values only available at request time from a Cloudflare
263
+ * `env` binding).
264
+ */
265
+ analytics?: CookieConsentAnalyticsConfig;
266
+ /**
267
+ * Resolves the same config at request time — e.g. from Cloudflare's
268
+ * `getCloudflareContext().env` (via `@opennextjs/cloudflare`, not a
269
+ * dependency of this package — pass your own getter). Any field left
270
+ * `undefined` in the returned object disables that provider's script.
271
+ */
272
+ getAnalytics?: () => CookieConsentAnalyticsConfig | Promise<CookieConsentAnalyticsConfig>;
273
+ /**
274
+ * Resolves the visitor's country code directly (ISO 3166-1 alpha-2,
275
+ * e.g. `"DE"`) — the simplest option when you already have it from
276
+ * somewhere (a header, a KV lookup, your own logic). Takes precedence
277
+ * over `getCloudflareContext` when both are set.
278
+ */
279
+ getCountryCode?: () => string | undefined | Promise<string | undefined>;
280
+ /**
281
+ * Country codes (ISO 3166-1 alpha-2) for which the cookie-consent banner
282
+ * is required. Only consulted when `getCountryCode` or
283
+ * `generate.getCloudflareContext` is set. Defaults to the EU/EEA + UK +
284
+ * Switzerland (GDPR/UK-GDPR/nFADP scope). A visitor whose resolved
285
+ * country isn't in this set is treated as NOT requiring consent; a
286
+ * country that couldn't be resolved still requires it (fail-safe:
287
+ * unknown defaults to "ask").
288
+ */
289
+ gdprCountries?: readonly string[];
290
+ /**
291
+ * Whether the auto-wired analytics scripts (see `autoWireAnalytics`)
292
+ * are allowed to load in your local/dev environment. Defaults to
293
+ * `false` — analytics stay off during local development regardless of
294
+ * consent, matching most analytics providers' own recommendation not to
295
+ * pollute production data with dev traffic. Set `true` to test the
296
+ * scripts locally.
297
+ */
298
+ enableAnalyticsInDevMode?: boolean;
299
+ /**
300
+ * Whether `IntlProvider` should automatically render
301
+ * `CookieConsentDialog` and `PrivacyPolicyUpdateDialog` (with their
302
+ * built-in default styling/EN+UK copy) at the end of your app tree.
303
+ * Defaults to `true` whenever `cookieConsent` is set. Set `false` to
304
+ * keep `cookieConsent` configured for `useCookieConsent()`/analytics
305
+ * only and render your own dialogs (or the exported components)
306
+ * yourself, wherever you like in the tree.
307
+ */
308
+ autoWireDialogs?: boolean;
309
+ /**
310
+ * Props forwarded as-is to the auto-wired `CookieConsentDialog`.
311
+ * Ignored when `autoWireDialogs` is `false`.
312
+ */
313
+ dialogProps?: CookieConsentDialogProps;
314
+ /**
315
+ * Props forwarded as-is to the auto-wired `PrivacyPolicyUpdateDialog`.
316
+ * Ignored when `autoWireDialogs` is `false`.
317
+ */
318
+ updateDialogProps?: PrivacyPolicyUpdateDialogProps;
319
+ }
320
+ /**
321
+ * Minimal shape read from your `getCloudflareContext()` return value.
322
+ * `cf.country` is consulted by `cookieConsent` (read defensively at the call
323
+ * site, since `cf`'s real type — `@opennextjs/cloudflare`'s `CfProperties`,
324
+ * a union of the incoming-request and request-init variants — only has
325
+ * `country` on one branch); `ctx.waitUntil` is used by `error_handling` to
326
+ * background error reports instead of awaiting them inline. Typed loosely
327
+ * here so the real (generic) function is assignable to
328
+ * `CookieConsentGetCloudflareContext` without a hard dependency on that
329
+ * package.
330
+ */
331
+ export interface CookieConsentCloudflareContext {
332
+ cf?: Record<string, unknown>;
333
+ ctx?: {
334
+ waitUntil?: (promise: Promise<unknown>) => void;
335
+ };
336
+ }
337
+ /**
338
+ * Matches `@opennextjs/cloudflare`'s `getCloudflareContext` overloaded
339
+ * signature exactly, so that function can be passed as
340
+ * `cookieConsent.getCloudflareContext` directly — this package always
341
+ * calls it with `{ async: true }` internally (the first overload), which is
342
+ * why that overload's return type drives `resolveRequiresConsent`'s
343
+ * awaited result; the sync overload is accepted structurally only so the
344
+ * real function's type (which has both) is assignable as-is.
345
+ */
346
+ export interface CookieConsentGetCloudflareContext {
347
+ (options: {
348
+ async: true;
349
+ }): Promise<CookieConsentCloudflareContext | null>;
350
+ (options?: {
351
+ async: false;
352
+ }): CookieConsentCloudflareContext | null;
353
+ }
354
+ export interface CookieConsentAnalyticsConfig {
355
+ /** Cloudflare Web Analytics beacon token, e.g. `'{"token": "..."}'` (the raw `data-cf-beacon` attribute value). */
356
+ cloudflareBeaconToken?: string;
357
+ /** Google Analytics measurement ID, e.g. `"G-XXXXXXX"`. */
358
+ googleAnalyticsId?: string;
359
+ /** Google Ads conversion ID, e.g. `"AW-XXXXXXXXX"`. */
360
+ googleAdsId?: string;
361
+ /** Google AdSense publisher ID, e.g. `"ca-pub-XXXXXXXXXXXXXXXX"`. */
362
+ googleAdSenseId?: string;
363
+ /**
364
+ * Microsoft Clarity project ID. `@microsoft/clarity` is a real
365
+ * dependency of this package (small, so always installed) — loaded and
366
+ * initialized automatically once consent is granted.
367
+ */
368
+ clarityProjectId?: string;
369
+ }
370
+ export interface FirebaseAuthRoutingConfig {
371
+ /**
372
+ * Whether `intlMiddleware` should automatically run the firebase_auth
373
+ * redirect/session-refresh logic (guest→`redirectAuthPath`, signed-in→
374
+ * `homePath` on auth pages, ID-token refresh) for every request.
375
+ * Defaults to `true` — set `false` to keep `firebaseAuth` configured
376
+ * (e.g. for the client/server providers, actions) while driving the
377
+ * middleware redirect logic yourself instead.
378
+ */
379
+ middlewareEnabled?: boolean;
380
+ /**
381
+ * Whether `IntlProvider` should automatically wrap your app in the
382
+ * client `AuthUserProvider` and call `resolveAuthUser` server-side.
383
+ * Defaults to `true`. Set `false` if you drive auth entirely from your
384
+ * own middleware (like `middlewareEnabled: false`'s manual-override
385
+ * case, but for the client/RSC layer) and don't want this package
386
+ * rendering any auth-related React tree on top of it — e.g. if you
387
+ * only use `intlMiddleware`'s built-in session-refresh/redirect logic
388
+ * and have no use for `useAuthUser()`/`AuthUserProvider` at all.
389
+ */
390
+ autoWireClientProvider?: boolean;
391
+ /** Firebase project's Web API key (`NEXT_PUBLIC_FIREBASE_API_KEY` equivalent). */
392
+ apiKey: string;
393
+ /** Firebase project's auth domain, e.g. "my-app.firebaseapp.com". */
394
+ authDomain: string;
395
+ /** Firebase project ID. */
396
+ projectId: string;
397
+ /** Firebase project's storage bucket. */
398
+ storageBucket?: string;
399
+ /** Firebase project's messaging sender ID. */
400
+ messagingSenderId?: string;
401
+ /** Firebase app ID. */
402
+ appId: string;
403
+ /** Firebase Analytics measurement ID. */
404
+ measurementId?: string;
405
+ /** Path to redirect signed-out users to, e.g. "/login". */
406
+ redirectAuthPath: string;
407
+ /** Path to redirect signed-in users away from auth pages to, e.g. "/". */
408
+ homePath: string;
409
+ /** Path to redirect unverified-email users to. Omit to skip email-verification redirects. */
410
+ verifyEmailPath?: string;
411
+ /** Returns true if the given (locale-stripped) path is an auth page (login/signup/etc). */
412
+ isAuthPath: (path: string) => boolean;
413
+ /** Locale-stripped paths exempt from all auth redirects (e.g. public marketing pages). */
414
+ whiteListPaths?: readonly string[];
415
+ /** Session cookie max-age in seconds. Defaults to 5 days (432000). */
416
+ sessionCookieMaxAge?: number;
417
+ /** Refresh-token cookie max-age in seconds. Defaults to 365 days (31536000). */
418
+ refreshTokenCookieMaxAge?: number;
419
+ /** Session cookie name. Defaults to `'__fa_session__'`. Override this if your app already uses a different name for its Firebase ID-token cookie. */
420
+ sessionCookieName?: string;
421
+ /** Refresh-token cookie name. Defaults to `'__fa_refresh_token__'`. Override this if your app already uses a different name for its Firebase refresh-token cookie. */
422
+ refreshTokenCookieName?: string;
423
+ }
424
+ export interface CookieAttributes {
425
+ /**
426
+ * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
427
+ * domain is set, and most clients will consider the cookie to apply to only
428
+ * the current domain.
429
+ */
430
+ domain?: string | undefined;
431
+ /**
432
+ * Specifies a function that will be used to encode a cookie's value. Since
433
+ * value of a cookie has a limited character set (and must be a simple
434
+ * string), this function can be used to encode a value into a string suited
435
+ * for a cookie's value.
436
+ *
437
+ * The default function is the global `encodeURIComponent`, which will
438
+ * encode a JavaScript string into UTF-8 byte sequences and then URL-encode
439
+ * any that fall outside of the cookie range.
440
+ */
441
+ encode?(value: string): string;
442
+ /**
443
+ * Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
444
+ * no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
445
+ * it on a condition like exiting a web browser application.
446
+ *
447
+ * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
448
+ * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
449
+ * possible not all clients by obey this, so if both are set, they should
450
+ * point to the same date and time.
451
+ */
452
+ expires?: Date | undefined;
453
+ /**
454
+ * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
455
+ * When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
456
+ * default, the `HttpOnly` attribute is not set.
457
+ *
458
+ * *Note* be careful when setting this to true, as compliant clients will
459
+ * not allow client-side JavaScript to see the cookie in `document.cookie`.
460
+ */
461
+ httpOnly?: boolean | undefined;
462
+ /**
463
+ * Specifies the number (in seconds) to be the value for the `Max-Age`
464
+ * `Set-Cookie` attribute. The given number will be converted to an integer
465
+ * by rounding down. By default, no maximum age is set.
466
+ *
467
+ * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
468
+ * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
469
+ * possible not all clients by obey this, so if both are set, they should
470
+ * point to the same date and time.
471
+ */
472
+ maxAge?: number | undefined;
473
+ /**
474
+ * Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
475
+ * attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
476
+ * `Partitioned` attribute is not set.
477
+ *
478
+ * **note** This is an attribute that has not yet been fully standardized, and may change in the future.
479
+ * This also means many clients may ignore this attribute until they understand it.
480
+ *
481
+ * More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
482
+ */
483
+ partitioned?: boolean | undefined;
484
+ /**
485
+ * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
486
+ * By default, the path is considered the "default path".
487
+ */
488
+ path?: string | undefined;
489
+ /**
490
+ * Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
491
+ *
492
+ * - `'low'` will set the `Priority` attribute to `Low`.
493
+ * - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
494
+ * - `'high'` will set the `Priority` attribute to `High`.
495
+ *
496
+ * More information about the different priority levels can be found in
497
+ * [the specification][rfc-west-cookie-priority-00-4.1].
498
+ *
499
+ * **note** This is an attribute that has not yet been fully standardized, and may change in the future.
500
+ * This also means many clients may ignore this attribute until they understand it.
501
+ */
502
+ priority?: "low" | "medium" | "high" | undefined;
503
+ /**
504
+ * Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
505
+ *
506
+ * - `true` will set the `SameSite` attribute to `Strict` for strict same
507
+ * site enforcement.
508
+ * - `false` will not set the `SameSite` attribute.
509
+ * - `'lax'` will set the `SameSite` attribute to Lax for lax same site
510
+ * enforcement.
511
+ * - `'strict'` will set the `SameSite` attribute to Strict for strict same
512
+ * site enforcement.
513
+ * - `'none'` will set the SameSite attribute to None for an explicit
514
+ * cross-site cookie.
515
+ *
516
+ * More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
517
+ *
518
+ * *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
519
+ */
520
+ sameSite?: true | false | "lax" | "strict" | "none" | undefined;
521
+ /**
522
+ * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
523
+ * `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
524
+ *
525
+ * *Note* be careful when setting this to `true`, as compliant clients will
526
+ * not send the cookie back to the server in the future if the browser does
527
+ * not have an HTTPS connection.
528
+ */
529
+ secure?: boolean | undefined;
530
+ }
531
+ export type TranslationEntry = string | TranslationObject;
532
+ export interface TranslationObject {
533
+ [key: string]: TranslationEntry;
534
+ }
535
+ export type ReturnType = string;
536
+ export type TranslatorReturnType = (key: string) => ReturnType;
537
+ export type changeFrequency = 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never' | undefined;
538
+ export type Alternates = {
539
+ languages?: Languages<string> | undefined;
540
+ } | undefined;
541
+ export interface IntlSitemap {
542
+ link?: string;
543
+ changeFrequency?: changeFrequency;
544
+ priority?: number | undefined;
545
+ images?: string[] | undefined;
546
+ lastModified: Date | string | undefined;
547
+ videos?: Videos[] | undefined;
548
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
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",
@@ -159,6 +159,10 @@
159
159
  "./defaultIgnoredConsoleErrors": {
160
160
  "types": "./dist/src/error_handling/default_ignored_console_errors.d.ts",
161
161
  "import": "./dist/src/error_handling/default_ignored_console_errors.js"
162
+ },
163
+ "./createServerErrorAction": {
164
+ "types": "./dist/src/error_handling/create_server_error_action.d.ts",
165
+ "import": "./dist/src/error_handling/create_server_error_action.js"
162
166
  }
163
167
  },
164
168
  "scripts": {