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,57 @@
1
+ /** Consent value: `true` accepted, `false` necessary-only, `null` not yet decided. */
2
+ export type ConsentValue = boolean | null;
3
+ /** Context value returned by `useCookieConsent()`. */
4
+ export interface CookieConsentContextType {
5
+ /** Current consent value; `null` until the visitor decides. */
6
+ consent: ConsentValue;
7
+ /**
8
+ * `false` until the client has read the stored consent/date cookies once
9
+ * (always `false` during SSR and the first client render, to avoid a
10
+ * hydration mismatch). The default dialog components render nothing
11
+ * until this is `true`, so a returning visitor's decided consent never
12
+ * flashes the banner before disappearing.
13
+ */
14
+ isMounted: boolean;
15
+ /**
16
+ * `true` once a privacy-policy update has been detected (stored consent
17
+ * predates `cookieConsent.privacyPolicyDate`) and hasn't been
18
+ * acknowledged yet. Always `false` when `privacyPolicyDate` is unset.
19
+ */
20
+ privacyPolicyUpdated: boolean;
21
+ /**
22
+ * Accepts (or rejects, with `false`) cookie consent and persists it.
23
+ * Pass `null` to clear the stored decision and reset `consent` back to
24
+ * `null`, so the default `CookieConsentDialog` banner reappears (e.g.
25
+ * for a "cookie settings" button).
26
+ */
27
+ setConsent: (value: ConsentValue) => void;
28
+ /** Acknowledges the privacy-policy update banner and persists the new date. */
29
+ acknowledgePrivacyPolicyUpdate: () => void;
30
+ /**
31
+ * Resolved from `cookieConsent.privacyPolicyPath` (defaults to
32
+ * `'/privacy-policy'`; `false` disables it). Used by the default
33
+ * dialog components to render a privacy-policy link automatically
34
+ * when their `link` prop is omitted.
35
+ */
36
+ privacyPolicyPath: string | false;
37
+ }
38
+ /** Slot-level style/class overrides accepted by the default dialog components. */
39
+ export interface CookieDialogClassNames {
40
+ root?: string;
41
+ message?: string;
42
+ link?: string;
43
+ actions?: string;
44
+ acceptButton?: string;
45
+ declineButton?: string;
46
+ closeButton?: string;
47
+ }
48
+ /** Slot-level inline-style overrides accepted by the default dialog components. */
49
+ export interface CookieDialogStyles {
50
+ root?: React.CSSProperties;
51
+ message?: React.CSSProperties;
52
+ link?: React.CSSProperties;
53
+ actions?: React.CSSProperties;
54
+ acceptButton?: React.CSSProperties;
55
+ declineButton?: React.CSSProperties;
56
+ closeButton?: React.CSSProperties;
57
+ }
@@ -0,0 +1,19 @@
1
+ import type { ErrorHandlingParams } from '../types/types';
2
+ import { type ReportErrorConfig } from './report_error';
3
+ /**
4
+ * Creates a `"use server"` action that reports a client-originated error via
5
+ * `reportError`, so `config` (and anything it closes over — secrets,
6
+ * `Secrets.telegramBotToken`-style env reads inside your `onError`) never
7
+ * has to be imported into client-side code. Call this once (server-side,
8
+ * e.g. next to your `RoutingConfig`) and pass the returned function to
9
+ * client components that need to report an error — they only ever handle
10
+ * the error value itself, never `config`.
11
+ *
12
+ * The error is stringified before crossing the client→server action
13
+ * boundary (Next.js server actions serialize arguments; an `Error` instance
14
+ * doesn't survive that intact) and `isClient: true` is set automatically.
15
+ *
16
+ * @param config Pass the relevant slices of your `RoutingConfig` directly —
17
+ * `{ errorHandling: config.errorHandling, generate: config.generate }`.
18
+ */
19
+ export default function createServerErrorAction(config: ReportErrorConfig | undefined): (error: unknown, classOrMethodName: string, params?: ErrorHandlingParams["params"]) => Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Firebase Auth error codes this package's own `createLoginAction`/
3
+ * `createSignUpAction`/`createForgotPasswordAction` already catch and
4
+ * translate into a localized message (see
5
+ * `firebase_auth/error_messages/firebase_auth_error_helper.ts`) — expected
6
+ * user-input failures (wrong password, email already in use, etc.), not
7
+ * bugs. They never reach `console.error`/`reportError` through this
8
+ * package's own code; this list exists as defense-in-depth for consumers
9
+ * whose own code logs one of these codes directly. Passing your own
10
+ * `ignoreConsoleError` array replaces this default entirely — pass `[]` to
11
+ * report everything.
12
+ */
13
+ export declare const defaultIgnoredConsoleErrors: readonly string[];
@@ -0,0 +1,9 @@
1
+ import type { ErrorHandlingParams } from '../types/types';
2
+ /**
3
+ * Builds a human-readable one-string summary of an `ErrorHandlingParams` —
4
+ * `[classOrMethodName] Error: <message>` followed by non-empty `Params`/
5
+ * `IsClient` sections. Never throws (`stringifyUnknown` is safe). Used as
6
+ * `ErrorHandlingParams.formattedMessage` — read this instead of `error`/
7
+ * `params` directly when you just want something printable.
8
+ */
9
+ export default function formatErrorMessage(params: ErrorHandlingParams): string;
@@ -0,0 +1,9 @@
1
+ export { default as withErrorHandling } from './with_error_handling';
2
+ export type { WithErrorHandlingOptions } from './with_error_handling';
3
+ export { default as reportError } from './report_error';
4
+ export type { ReportErrorConfig } from './report_error';
5
+ export { default as installConsoleErrorOverride } from './install_console_error_override';
6
+ export { default as stringifyUnknown } from './stringify_unknown';
7
+ export { default as formatErrorMessage } from './format_error_message';
8
+ export { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
9
+ export type { ErrorHandlingParams, ErrorHandlingRoutingConfig } from '../types/types';
@@ -0,0 +1,29 @@
1
+ import { type ReportErrorConfig } from './report_error';
2
+ /**
3
+ * Replaces the global `console.error` so every `console.error(...)` call is
4
+ * also routed through `config.errorHandling.onError`/`reportError` — the
5
+ * original `console.error` still runs afterwards, nothing is swallowed.
6
+ * Safe to call more than once (a no-op after the first call in this JS
7
+ * realm — call it separately on the server and on the client, each has its
8
+ * own `console`). Only takes effect when `config.errorHandling.overrideConsoleError`
9
+ * is `true`.
10
+ *
11
+ * A component stuck in a render-error loop calls `console.error` on every
12
+ * render — `reportError`'s own dedup/cap (on by default, see
13
+ * `errorHandling.dedup`/`maxReports`) is what stops that from reporting
14
+ * unboundedly; this function does not duplicate that cap itself.
15
+ *
16
+ * `config.errorHandling.ignoreConsoleErrors` (default
17
+ * `defaultIgnoredConsoleErrors` — this package's own Firebase Auth error
18
+ * codes for expected user-input failures) and `ignoreConsoleError` both
19
+ * skip reporting a matching call while still logging it normally.
20
+ *
21
+ * @param config Pass the relevant slices of your `RoutingConfig` directly —
22
+ * `{ errorHandling: config.errorHandling, generate: config.generate }`.
23
+ * @param isClient Passed through to every report's `ErrorHandlingParams.isClient`
24
+ * — set `true` when installing from client-side code (e.g. the client
25
+ * `LocationzationClientProvider`), omit/`false` on the server. There's no
26
+ * `getCloudflareContext`/`ctx.waitUntil` available in the browser, so
27
+ * client-side reports always await `onError` directly.
28
+ */
29
+ export default function installConsoleErrorOverride(config: ReportErrorConfig | undefined, isClient?: boolean): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import type { ErrorHandlingParams, ErrorHandlingRoutingConfig, GenerateRoutingConfig } from '../types/types';
2
+ export interface ReportErrorConfig {
3
+ errorHandling?: ErrorHandlingRoutingConfig;
4
+ generate?: GenerateRoutingConfig;
5
+ }
6
+ /**
7
+ * Reports `params` via `config.errorHandling.onError` (default
8
+ * `console.error(params.formattedMessage)`), unless
9
+ * `config.errorHandling.enable === false`, `params.consent` is set and not
10
+ * `true` (reporting to a third party without cookie consent can itself be
11
+ * GDPR-relevant), or dedup throttles it (on by default — see
12
+ * `errorHandling.dedup`/`throttleMs`/`resetDedup`). Never throws — a broken
13
+ * reporter must not mask the original error.
14
+ *
15
+ * Always overwrites `params.formattedMessage` with a fresh
16
+ * `formatErrorMessage(params)` before reporting — a human-readable one-line
17
+ * summary (`[classOrMethodName] Error: <message>` plus non-empty sections)
18
+ * instead of the raw `error`/`params` object, for a default reporter (or a
19
+ * simple `onError`) to print directly.
20
+ *
21
+ * When `config.generate?.getCloudflareContext` is set, `waitUntil` is called
22
+ * SYNCHRONOUSLY, in the same tick, with the `callOnError(...)` promise —
23
+ * Cloudflare Workers only extends the request's lifetime for work already
24
+ * registered with `waitUntil` by the time the handler returns; deferring
25
+ * that call through an extra microtask (e.g. `Promise.resolve().then(...)`)
26
+ * risks the isolate tearing down the request before `waitUntil` is ever
27
+ * actually invoked, silently dropping the report. Falls back to awaiting
28
+ * `onError` directly when `getCloudflareContext`/`ctx.waitUntil` is unset or
29
+ * unavailable (e.g. outside a Cloudflare Worker).
30
+ *
31
+ * Passing `params.error` as `null`/`undefined` with `errorHandling.resetDedup: true`
32
+ * and nothing else is a valid "reset-only" call: the dedup state clears and
33
+ * `reportError` returns immediately, without calling `onError` — useful to
34
+ * clear dedup state once at the very start of a request/cron tick, before
35
+ * any handler that might call `reportError` for a real error runs.
36
+ *
37
+ * @param config Pass the relevant slices of your `RoutingConfig` directly —
38
+ * `{ errorHandling: config.errorHandling, generate: config.generate }`.
39
+ */
40
+ export default function reportError(config: ReportErrorConfig | undefined, params: ErrorHandlingParams): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Safely converts an `unknown` value (typically `ErrorHandlingParams.error`)
3
+ * into a string, for logging/dedup-keying/display — never throws.
4
+ *
5
+ * @param isClient Skips resolving function-wrapped/lazy error values on the
6
+ * client (matches `ErrorHandlingParams.isClient`) — running arbitrary
7
+ * caught functions client-side isn't safe the way it is on the server.
8
+ * @param isNested Set when stringifying a value nested inside another
9
+ * object/array — falls back to a plain `JSON.stringify` (no pretty-print)
10
+ * so a single unserializable nested value can't crash the whole report.
11
+ */
12
+ export default function stringifyUnknown(value: unknown, isClient?: boolean, isNested?: boolean): string;
@@ -0,0 +1,15 @@
1
+ import type { ConsentValue } from '../cookie_consent/types';
2
+ import { type ReportErrorConfig } from './report_error';
3
+ export interface WithErrorHandlingOptions {
4
+ /** Pass the relevant slices of your `RoutingConfig` directly — `{ errorHandling: config.errorHandling, generate: config.generate }`. */
5
+ config?: ReportErrorConfig;
6
+ params?: unknown;
7
+ isClient?: boolean;
8
+ consent?: ConsentValue;
9
+ }
10
+ /**
11
+ * Wraps `fn`, reporting (via `options.config`) then rethrowing any error it
12
+ * throws or rejects with. Never swallows — callers keep their own
13
+ * catch/fallback behavior, this only adds reporting on top.
14
+ */
15
+ export default function withErrorHandling<Args extends unknown[], Result>(fn: (...args: Args) => Result | Promise<Result>, classOrMethodName: string, options?: WithErrorHandlingOptions): (...args: Args) => Promise<Result>;
@@ -0,0 +1,46 @@
1
+ import type { AuthActionMessages, AuthFormState } from '../types';
2
+ /**
3
+ * Builds a login server action for React's `useActionState` form hook.
4
+ * The returned function has the `(prevState, formData) => Promise<AuthFormState>`
5
+ * shape `useActionState` expects — pass it directly as the action.
6
+ *
7
+ * `formData` must contain `email` and `password` fields.
8
+ *
9
+ * @param locale Used to localize the returned error message.
10
+ * @param messages Localized action messages (currently unused by this action).
11
+ * @returns A form action: `{ success: true }` on success, `{ error }` on failure.
12
+ * @example
13
+ * const [state, action] = useActionState(createLoginAction(locale, messages), {});
14
+ * <form action={action}>...</form>
15
+ */
16
+ export declare function createLoginAction(locale: string, messages: AuthActionMessages): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
17
+ /**
18
+ * Builds a sign-up server action for React's `useActionState` form hook.
19
+ * Same shape as {@link createLoginAction}.
20
+ *
21
+ * `formData` must contain `email`, `password`, and `confirmPassword` fields.
22
+ *
23
+ * @param locale Used to localize the returned error message.
24
+ * @param messages `messages.mismatch` is returned as the error if
25
+ * `password` !== `confirmPassword`; other fields on `AuthActionMessages`
26
+ * are not read by this action.
27
+ * @returns A form action: `{ success: true }` on success, `{ error }` on failure.
28
+ * @example
29
+ * const [state, action] = useActionState(createSignUpAction(locale, messages), {});
30
+ * <form action={action}>...</form>
31
+ */
32
+ export declare function createSignUpAction(locale: string, messages: AuthActionMessages): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
33
+ /**
34
+ * Builds a forgot-password server action for React's `useActionState` form
35
+ * hook. Same shape as {@link createLoginAction}.
36
+ *
37
+ * `formData` must contain an `email` field.
38
+ *
39
+ * @param locale Used to localize the returned error message.
40
+ * @param messages Localized action messages (currently unused by this action).
41
+ * @returns A form action: `{ success: true }` on success, `{ error }` on failure.
42
+ * @example
43
+ * const [state, action] = useActionState(createForgotPasswordAction(locale, messages), {});
44
+ * <form action={action}>...</form>
45
+ */
46
+ export declare function createForgotPasswordAction(locale: string, messages: AuthActionMessages): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
@@ -0,0 +1,4 @@
1
+ import type { AuthUser } from '../types';
2
+ export declare function setAuthUserCache(user: AuthUser | null): void;
3
+ export declare function getAuthUserCache(): AuthUser | null;
4
+ export declare function isAuthUserLoadingCache(): boolean;
@@ -0,0 +1,36 @@
1
+ import type { AuthUser, SerializedAuthUser } from '../types';
2
+ export interface AuthUserContextType {
3
+ /** Current Firebase user, or `null` if signed out (or not yet resolved while `loading`). */
4
+ user: AuthUser | null;
5
+ /** `true` until the initial auth state has resolved on the client. */
6
+ loading: boolean;
7
+ /** Force-refreshes the current user's ID token/claims and re-syncs the session cookie. */
8
+ reloadUser: () => Promise<void>;
9
+ /** Sends a verification email to the currently signed-in user. */
10
+ sendVerificationEmail: () => Promise<void>;
11
+ /** Signs out, clears the session cookie, and redirects to `firebaseAuth.redirectAuthPath`. */
12
+ logout: () => Promise<void>;
13
+ }
14
+ export declare const AuthUserContext: import("react").Context<AuthUserContextType | null>;
15
+ /**
16
+ * Client-side auth-state provider for `firebase_auth`. Wrap your root layout
17
+ * (or a client boundary below it) with this to make `useAuthUser()`
18
+ * (`cloudflare-next-intl/useFirebaseAuthUser`, client variant) resolve
19
+ * `{ user, loading }` from the live Firebase `onIdTokenChanged` listener,
20
+ * and to get automatic session-cookie sync + redirect-on-sign-out/verify
21
+ * behavior driven by `firebaseAuth.isAuthPath` / `whiteListPaths` /
22
+ * `redirectAuthPath` / `verifyEmailPath` on your `RoutingConfig`.
23
+ *
24
+ * Requires `firebaseAuth` to be set on the config passed to `setIntlConfig`
25
+ * — throws via {@link requireFirebaseAuthConfig} otherwise.
26
+ *
27
+ * @param initialUser Server-resolved user (e.g. from
28
+ * `useFirebaseAuthUser`'s `react-server` variant) to avoid a
29
+ * loading flash on first paint; pass `null`/omit if unavailable.
30
+ * @example
31
+ * <AuthUserProvider initialUser={initialUser}>{children}</AuthUserProvider>
32
+ */
33
+ export default function AuthUserProvider({ initialUser, children }: {
34
+ initialUser?: SerializedAuthUser | null;
35
+ children: React.ReactNode;
36
+ }): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import type { FirebaseApp } from 'firebase/app';
2
+ import type { Auth } from 'firebase/auth';
3
+ /**
4
+ * Lazily loads and initializes `firebase/app`/`firebase/auth` — a dynamic
5
+ * import, not a static one, so consumers who never call a firebase_auth
6
+ * export never pull these packages into their bundle or runtime at all.
7
+ * Throws if `firebaseAuth` is missing from `RoutingConfig` (see
8
+ * `require_config.ts`) instead of silently no-op'ing.
9
+ */
10
+ export declare function getFirebaseAuthClient(): Promise<{
11
+ app: FirebaseApp;
12
+ auth: Auth;
13
+ }>;
14
+ /** Synchronous read of the cached client, or `undefined` before the first `getFirebaseAuthClient()` resolves. */
15
+ export declare function getFirebaseAuthClientSync(): {
16
+ app: FirebaseApp;
17
+ auth: Auth;
18
+ } | undefined;
19
+ /** Memoized `import('firebase/auth')` — see {@link getFirebaseAuthClient} for why this is worth caching. */
20
+ export declare function getFirebaseAuthModule(): Promise<typeof import('firebase/auth')>;
@@ -0,0 +1,12 @@
1
+ import { type AuthUserContextType } from './auth_user_provider';
2
+ /**
3
+ * Reads the current Firebase auth user and its actions from
4
+ * `AuthUserProvider`'s context.
5
+ *
6
+ * @throws If called without an `AuthUserProvider` above it in the tree.
7
+ * @example
8
+ * const { user, loading, logout } = useAuthUser();
9
+ * if (loading) return null;
10
+ * return user ? <button onClick={logout}>Log out</button> : null;
11
+ */
12
+ export default function useAuthUser(): AuthUserContextType;
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_MESSAGES_EN: Record<string, string>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Resolves a Firebase auth error to a user-facing message. If the consumer's
3
+ * locale messages have a `firebaseAuth` namespace with a matching key, that
4
+ * translation is used; otherwise falls back to the bundled English default.
5
+ */
6
+ export default function firebaseAuthErrorMessage(locale: string, error: unknown): string;
@@ -0,0 +1,9 @@
1
+ export { default as FirebaseAuthClientProvider } from './client/auth_user_provider';
2
+ export { default as FirebaseAuthServerProvider } from './server/auth_user_server_provider';
3
+ export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
4
+ export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
5
+ export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
6
+ export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
7
+ export { getFirebaseAuthClient } from './client/firebase_client';
8
+ export type { SerializedAuthUser, AuthFormState, AuthActionMessages, AuthUser } from './types';
9
+ export type { FirebaseAuthRoutingConfig } from '../types/types';
@@ -0,0 +1,22 @@
1
+ import { NextResponse, type NextRequest } from 'next/server';
2
+ export declare const defaultSessionCookieName = "__fa_session__";
3
+ export declare const defaultRefreshTokenCookieName = "__fa_refresh_token__";
4
+ /**
5
+ * Layers Firebase session-cookie validation/refresh and auth redirects onto
6
+ * an already-built middleware response. Called internally by `intlMiddleware`
7
+ * (via dynamic import) when `config.firebaseAuth` is set and
8
+ * `middlewareEnabled !== false` — not intended to be called directly unless
9
+ * that auto-wiring is opted out of.
10
+ *
11
+ * @param baseResponse The response `intlMiddleware` already produced for
12
+ * locale routing (its own next()/rewrite()/redirect(), with the locale
13
+ * cookie / bot cookie / `Content-Language` header already set). On the
14
+ * pass-through path this function returns `baseResponse` itself (with
15
+ * Firebase cookies layered on) so none of that is dropped; on the
16
+ * guest/auth-page redirect paths it returns a NEW response instead, since
17
+ * a redirect response can't also carry forward a rewrite/next decision —
18
+ * its cookies/headers are copied across from `baseResponse` so locale
19
+ * state still survives the redirect.
20
+ * @param locale The effective locale `intlMiddleware` resolved for this request.
21
+ */
22
+ export default function updateSession(request: NextRequest, baseResponse: NextResponse, locale: string): Promise<NextResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { FirebaseAuthRoutingConfig } from '../types/types';
2
+ /**
3
+ * Every firebase_auth export calls this before touching `firebase/*`. Throws
4
+ * instead of silently no-op'ing so a consumer who calls e.g. `useAuthUser()`
5
+ * without setting `firebaseAuth` on their `RoutingConfig` gets an immediate,
6
+ * actionable error rather than a silent null/undefined.
7
+ */
8
+ export default function requireFirebaseAuthConfig(fa: FirebaseAuthRoutingConfig | undefined): asserts fa is FirebaseAuthRoutingConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { SerializedAuthUser } from '../types';
2
+ /**
3
+ * Resolves the signed-in user from the session cookie and performs the
4
+ * authoritative pre-render redirect (guest→`redirectAuthPath`, signed-in→
5
+ * `homePath` on auth pages) — middleware only checks cookie *presence*, not
6
+ * validity; a forged, expired, or otherwise invalid-but-present cookie
7
+ * sails through it. Only this function's token validation
8
+ * (`getAuthenticatedAppForUser`) catches that, so this redirect must happen
9
+ * here, before any HTML is sent — relying solely on the client
10
+ * `AuthUserProvider` effect to redirect afterwards produces a visible
11
+ * flash (page renders signed-in, then bounces). Plain async function, not
12
+ * a component: callers decide where/how to use the resolved user relative
13
+ * to their own component tree (see `AuthUserServerProvider` below for the
14
+ * simple case, and `IntlProvider`'s auto-wiring for the case where ordering
15
+ * against `LocaleContext` matters).
16
+ */
17
+ export declare function resolveAuthUserAndRedirect(): Promise<SerializedAuthUser | null>;
18
+ /**
19
+ * Convenience component for the manual-override path
20
+ * (`firebaseAuth.middlewareEnabled: false`-style manual wiring): resolves +
21
+ * redirects, then wraps `children` in the client `AuthUserProvider`
22
+ * directly. NOT used by the default auto-wiring path — `IntlProvider`/
23
+ * `LocationzationClientProvider` call `resolveAuthUserAndRedirect` and the
24
+ * client `AuthUserProvider` separately instead, so the client provider can
25
+ * render inside `LocaleContext.Provider` rather than outside it.
26
+ */
27
+ export default function AuthUserServerProvider({ children }: {
28
+ children: React.ReactNode;
29
+ }): Promise<import("react").JSX.Element>;
@@ -0,0 +1,15 @@
1
+ import type { FirebaseApp } from 'firebase/app';
2
+ import type { User } from 'firebase/auth';
3
+ /**
4
+ * Resolves the signed-in user on the server from the session cookie.
5
+ * `initializeServerApp` validates the token with the Auth service, so a
6
+ * missing, expired, or forged token yields `currentUser === null`.
7
+ * Wrapped in React's `cache()` so multiple server components in one request
8
+ * share a single Auth service lookup. Lazily imports `firebase/app`/
9
+ * `firebase/auth` — never touched unless this is actually called, and
10
+ * throws if `firebaseAuth` is missing from `RoutingConfig`.
11
+ */
12
+ export declare const getAuthenticatedAppForUser: () => Promise<{
13
+ firebaseServerApp: FirebaseApp | null;
14
+ currentUser: User | null;
15
+ }>;
@@ -0,0 +1,39 @@
1
+ import type { User } from 'firebase/auth';
2
+ /**
3
+ * Resolves the current request's authenticated Firebase user.
4
+ * @returns `{ user, loading: false }` — `loading` is always `false` here;
5
+ * server resolution is synchronous with respect to the awaited call.
6
+ */
7
+ declare function iGetAuthUser(): Promise<{
8
+ user: User | null;
9
+ loading: false;
10
+ }>;
11
+ /**
12
+ * Server Component/Action only: resolves the current request's
13
+ * authenticated Firebase user, same style as {@link getLocale}/
14
+ * {@link getTranslations} — an unconditional, always-`async` export
15
+ * (`cloudflare-next-intl/getFirebaseAuthUser`), so the `await` requirement
16
+ * is visible from the type itself in every editor.
17
+ *
18
+ * Returns the same `{ user, loading }` shape the client `useAuthUser()`
19
+ * hook's context exposes, so `const { user } = await getAuthUser()`
20
+ * generalizes correctly from `const { user } = useAuthUser()` on the client.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { user } = await getAuthUser();
25
+ * ```
26
+ */
27
+ export declare const getAuthUser: typeof iGetAuthUser;
28
+ /**
29
+ * Server Component counterpart of the client `useAuthUser()` hook, reached
30
+ * via `cloudflare-next-intl/useFirebaseAuthUser`'s `react-server` condition
31
+ * (resolved automatically — not meant to be imported directly by name).
32
+ * Prefer {@link getAuthUser} for an unconditional, editor-typed-as-async
33
+ * equivalent.
34
+ */
35
+ export default function useAuthUser(): Promise<{
36
+ user: User | null;
37
+ loading: false;
38
+ }>;
39
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { User } from 'firebase/auth';
2
+ /**
3
+ * Plain, RSC-serializable projection of `firebase/auth`'s `User` — enough
4
+ * for first paint on the server; superseded by the real `User` once the
5
+ * client's `onIdTokenChanged` listener fires.
6
+ */
7
+ export interface SerializedAuthUser {
8
+ uid: string;
9
+ email: string | null;
10
+ emailVerified: boolean;
11
+ displayName: string | null;
12
+ }
13
+ export type AuthFormState = {
14
+ error?: string;
15
+ success?: boolean;
16
+ };
17
+ /** Overrides for the default English auth error/status messages. */
18
+ export interface AuthActionMessages {
19
+ success?: string;
20
+ mismatch?: string;
21
+ }
22
+ export type AuthUser = User | SerializedAuthUser;
@@ -0,0 +1 @@
1
+ export {};