cloudflare-next-intl 0.8.19 → 0.8.21

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.
@@ -115,6 +115,29 @@ export default async function connectToPostgres(config, resolved) {
115
115
  connectionString = resolved ?? await resolveConnectionString(db);
116
116
  const { Client } = await import('pg');
117
117
  const created = serializeQueries(new Client({ connectionString }));
118
+ // The shared client outlives a single request (see the module doc)
119
+ // and Hyperdrive/Postgres can close its idle socket at any time. `pg`
120
+ // surfaces that as an `'error'` event on the `Client`, which is an
121
+ // `EventEmitter` — with no listener, Node treats it as unhandled and
122
+ // throws, crashing whatever unrelated request happens to be running
123
+ // in the isolate at that moment. Listening here converts it into a
124
+ // clean reset so the next call reconnects instead.
125
+ created.on('error', (error) => {
126
+ if (client === created) {
127
+ client = null;
128
+ connectionString = null;
129
+ connectionPromise = null;
130
+ }
131
+ // `pg` emits "Connection terminated"/"Connection terminated
132
+ // unexpectedly" (lib/client.js) — never "Connection closed" —
133
+ // when the idle socket dies outside a query. That's the
134
+ // expected shape of this event (Hyperdrive/Postgres recycling
135
+ // the connection, not a query failure): swallow it entirely,
136
+ // don't report or log it.
137
+ if (/connection terminated/i.test(error.message))
138
+ return;
139
+ void reportError({ errorHandling: config.errorHandling, generate: config.generate }, { error, classOrMethodName: 'db.connectToPostgres.clientError' });
140
+ });
118
141
  client = created;
119
142
  await created.connect();
120
143
  return created;
@@ -34,7 +34,8 @@ import { type ReportErrorConfig } from './report_error';
34
34
  * `config.errorHandling.ignoreConsoleErrors` (default
35
35
  * `defaultIgnoredConsoleErrors` — this package's own Firebase Auth error
36
36
  * codes for expected user-input failures) and `ignoreConsoleError` both
37
- * skip reporting a matching call while still logging it normally.
37
+ * skip reporting a matching call while still logging it normally — checked
38
+ * inside `reportError` itself, so this override doesn't duplicate the check.
38
39
  *
39
40
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
40
41
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
@@ -1,6 +1,4 @@
1
1
  import reportError, { consoleOverrideState } from './report_error';
2
- import stringifyUnknown from './stringify_unknown';
3
- import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
4
2
  /**
5
3
  * Replaces the global `console.error` so every `console.error(...)` call is
6
4
  * also routed through `config.errorHandling.onError`/`reportError` — the
@@ -36,7 +34,8 @@ import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
36
34
  * `config.errorHandling.ignoreConsoleErrors` (default
37
35
  * `defaultIgnoredConsoleErrors` — this package's own Firebase Auth error
38
36
  * codes for expected user-input failures) and `ignoreConsoleError` both
39
- * skip reporting a matching call while still logging it normally.
37
+ * skip reporting a matching call while still logging it normally — checked
38
+ * inside `reportError` itself, so this override doesn't duplicate the check.
40
39
  *
41
40
  * @param config Pass the relevant slices of your `RoutingConfig` directly —
42
41
  * `{ errorHandling: config.errorHandling, generate: config.generate }`.
@@ -58,12 +57,6 @@ export default function installConsoleErrorOverride(config, isClient) {
58
57
  if (!suppressOnClient) {
59
58
  originalConsoleError(message, ...optionalParams);
60
59
  }
61
- const stringified = stringifyUnknown(message, isClient);
62
- const ignoreList = config.errorHandling?.ignoreConsoleErrors ?? defaultIgnoredConsoleErrors;
63
- if (ignoreList.some((ignored) => stringified.includes(ignored)))
64
- return;
65
- if (config.errorHandling?.ignoreConsoleError?.(stringified))
66
- return;
67
60
  void reportError(config, { error: message, classOrMethodName: 'Global Console Error Handler', params: optionalParams, isClient });
68
61
  };
69
62
  override.__isErrorHandlingOverride = true;
@@ -1,5 +1,6 @@
1
1
  import formatErrorMessage from './format_error_message';
2
2
  import stringifyUnknown from './stringify_unknown';
3
+ import { defaultIgnoredConsoleErrors } from './default_ignored_console_errors';
3
4
  const DEFAULT_THROTTLE_MS = 5000;
4
5
  // Set by `installConsoleErrorOverride` once it patches `console.error`.
5
6
  // When active, THAT override is the sole place that ever calls the real
@@ -105,6 +106,18 @@ export default async function reportError(config, params) {
105
106
  return;
106
107
  if (params.consent !== undefined && params.consent !== true)
107
108
  return;
109
+ // `ignoreConsoleErrors`/`ignoreConsoleError` used to only be consulted by
110
+ // `installConsoleErrorOverride`'s patched `console.error` — any direct
111
+ // `reportError`/`reportClientError` call (a caught DB/query error, an
112
+ // error boundary's `reportClientError(error, ...)`, etc.) skipped this
113
+ // check entirely and always reached `onError`. Checking it here instead
114
+ // makes every path share the one ignore list.
115
+ const stringified = stringifyUnknown(params.error, params.isClient);
116
+ const ignoreList = errorHandling?.ignoreConsoleErrors ?? defaultIgnoredConsoleErrors;
117
+ if (ignoreList.some((ignored) => stringified.includes(ignored)))
118
+ return;
119
+ if (errorHandling?.ignoreConsoleError?.(stringified))
120
+ return;
108
121
  if (errorHandling?.dedup !== false) {
109
122
  const throttleMs = errorHandling?.throttleMs ?? DEFAULT_THROTTLE_MS;
110
123
  const dedupKey = buildDedupKey(params);
@@ -44,3 +44,40 @@ export declare function createSignUpAction(locale: string, messages: AuthActionM
44
44
  * <form action={action}>...</form>
45
45
  */
46
46
  export declare function createForgotPasswordAction(locale: string, actionCodeSettings?: AuthActionCodeSettings): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
47
+ /**
48
+ * Builds a "send sign-in link" server action for React's `useActionState`
49
+ * form hook, for passwordless email-link sign-in. Same shape as
50
+ * {@link createLoginAction}.
51
+ *
52
+ * `formData` must contain an `email` field.
53
+ *
54
+ * @param locale Used to localize the returned error message.
55
+ * @param actionCodeSettings Required. `actionCodeSettings.url` is the page
56
+ * the emailed link points to (must handle completion via a future
57
+ * `completeSignInWithLink` action); `handleCodeInApp` should be `true`.
58
+ * @returns A form action: `{ success: true, email }` on success (the
59
+ * trimmed email, for the caller to persist as `emailForSignIn` before
60
+ * the user leaves this device/tab), `{ error }` on failure.
61
+ * @example
62
+ * const [state, action] = useActionState(
63
+ * createSendSignInLinkAction(locale, { url: completeUrl, handleCodeInApp: true }),
64
+ * {},
65
+ * );
66
+ * <form action={action}>...</form>
67
+ */
68
+ export declare function createSendSignInLinkAction(locale: string, actionCodeSettings: AuthActionCodeSettings): (_prevState: AuthFormState, formData: FormData) => Promise<AuthFormState>;
69
+ /**
70
+ * Completes a passwordless email-link sign-in. Called directly (not via
71
+ * `useActionState`) from an effect on the link-landing page, once the URL
72
+ * and the user's email (recovered from `localStorage`, or re-entered if
73
+ * the link was opened on a different device) are both known.
74
+ *
75
+ * @param locale Used to localize the returned error message.
76
+ * @param url The full URL the user landed on (`window.location.href`).
77
+ * @param email The email address to complete sign-in for.
78
+ * @returns `{ success: true }` on success, `{ error }` if the URL isn't a
79
+ * valid sign-in link or sign-in otherwise fails.
80
+ * @example
81
+ * const result = await completeSignInWithLink(locale, window.location.href, email);
82
+ */
83
+ export declare function completeSignInWithLink(locale: string, url: string, email: string): Promise<AuthFormState>;
@@ -100,3 +100,68 @@ export function createForgotPasswordAction(locale, actionCodeSettings) {
100
100
  }
101
101
  };
102
102
  }
103
+ /**
104
+ * Builds a "send sign-in link" server action for React's `useActionState`
105
+ * form hook, for passwordless email-link sign-in. Same shape as
106
+ * {@link createLoginAction}.
107
+ *
108
+ * `formData` must contain an `email` field.
109
+ *
110
+ * @param locale Used to localize the returned error message.
111
+ * @param actionCodeSettings Required. `actionCodeSettings.url` is the page
112
+ * the emailed link points to (must handle completion via a future
113
+ * `completeSignInWithLink` action); `handleCodeInApp` should be `true`.
114
+ * @returns A form action: `{ success: true, email }` on success (the
115
+ * trimmed email, for the caller to persist as `emailForSignIn` before
116
+ * the user leaves this device/tab), `{ error }` on failure.
117
+ * @example
118
+ * const [state, action] = useActionState(
119
+ * createSendSignInLinkAction(locale, { url: completeUrl, handleCodeInApp: true }),
120
+ * {},
121
+ * );
122
+ * <form action={action}>...</form>
123
+ */
124
+ export function createSendSignInLinkAction(locale, actionCodeSettings) {
125
+ return async function sendSignInLinkAction(_prevState, formData) {
126
+ requireFirebaseAuthConfig(config.firebaseAuth);
127
+ const { auth } = await getFirebaseAuthClient();
128
+ const { sendSignInLinkToEmail } = await getFirebaseAuthModule();
129
+ const email = (formData.get('email')?.toString() ?? '').trim();
130
+ try {
131
+ await sendSignInLinkToEmail(auth, email, actionCodeSettings);
132
+ return { success: true, email };
133
+ }
134
+ catch (e) {
135
+ return { error: firebaseAuthErrorMessage(locale, e) };
136
+ }
137
+ };
138
+ }
139
+ /**
140
+ * Completes a passwordless email-link sign-in. Called directly (not via
141
+ * `useActionState`) from an effect on the link-landing page, once the URL
142
+ * and the user's email (recovered from `localStorage`, or re-entered if
143
+ * the link was opened on a different device) are both known.
144
+ *
145
+ * @param locale Used to localize the returned error message.
146
+ * @param url The full URL the user landed on (`window.location.href`).
147
+ * @param email The email address to complete sign-in for.
148
+ * @returns `{ success: true }` on success, `{ error }` if the URL isn't a
149
+ * valid sign-in link or sign-in otherwise fails.
150
+ * @example
151
+ * const result = await completeSignInWithLink(locale, window.location.href, email);
152
+ */
153
+ export async function completeSignInWithLink(locale, url, email) {
154
+ requireFirebaseAuthConfig(config.firebaseAuth);
155
+ const { auth } = await getFirebaseAuthClient();
156
+ const { isSignInWithEmailLink, signInWithEmailLink } = await getFirebaseAuthModule();
157
+ if (!isSignInWithEmailLink(auth, url)) {
158
+ return { error: firebaseAuthErrorMessage(locale, { code: 'auth/invalid-action-code' }) };
159
+ }
160
+ try {
161
+ await signInWithEmailLink(auth, email, url);
162
+ return { success: true };
163
+ }
164
+ catch (e) {
165
+ return { error: firebaseAuthErrorMessage(locale, e) };
166
+ }
167
+ }
@@ -2,7 +2,7 @@ export { default as FirebaseAuthClientProvider } from './client/auth_user_provid
2
2
  export { default as FirebaseAuthServerProvider } from './server/auth_user_server_provider';
3
3
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
4
4
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
5
- export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
5
+ export { createLoginAction, createSignUpAction, createForgotPasswordAction, createSendSignInLinkAction, completeSignInWithLink, } from './client/auth_actions';
6
6
  export { default as clearFirebaseAuthSession } from './server/clear_session_action';
7
7
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
8
8
  export { getFirebaseAuthClient, getFirebasePerformanceSync } from './client/firebase_client';
@@ -8,7 +8,7 @@ export { default as FirebaseAuthServerProvider } from './server/auth_user_server
8
8
  // DOES resolve correctly per-environment) rather than through this barrel.
9
9
  export { default as useFirebaseAuthUserClient } from './client/use_auth_user';
10
10
  export { default as useFirebaseAuthUserServer } from './server/use_auth_user_server';
11
- export { createLoginAction, createSignUpAction, createForgotPasswordAction } from './client/auth_actions';
11
+ export { createLoginAction, createSignUpAction, createForgotPasswordAction, createSendSignInLinkAction, completeSignInWithLink, } from './client/auth_actions';
12
12
  export { default as clearFirebaseAuthSession } from './server/clear_session_action';
13
13
  export { default as updateFirebaseAuthSession, defaultSessionCookieName as firebaseAuthSessionCookieName } from './middleware/update_session';
14
14
  export { getFirebaseAuthClient, getFirebasePerformanceSync } from './client/firebase_client';
@@ -13,6 +13,7 @@ export interface SerializedAuthUser {
13
13
  export type AuthFormState = {
14
14
  error?: string;
15
15
  success?: boolean;
16
+ email?: string;
16
17
  };
17
18
  /** Overrides for the default English auth error/status messages. */
18
19
  export interface AuthActionMessages {
package/llms.txt CHANGED
@@ -34,7 +34,7 @@ other subpath can be used.
34
34
  - `./firebaseAuthServerProvider` — server-side equivalent provider (not used by the default auto-wiring path — see its doc comment).
35
35
  - `./useFirebaseAuthUser` — `useAuthUser()`; resolves to RSC or client implementation via the `react-server` condition. Client variant throws `"useAuthUser must be used within an AuthUserProvider"` if called outside one.
36
36
  - `./getFirebaseAuthUser` — `getAuthUser()`; unconditional server-only export of the same RSC implementation `useFirebaseAuthUser` resolves to via `react-server`. Use this when you want `await` to be visible from the type itself — TypeScript doesn't evaluate the `react-server` condition, so `useFirebaseAuthUser` always types as its client (sync) signature in editors regardless of call site.
37
- - `./firebaseAuthActions` — `createLoginAction`/`createSignUpAction`/`createForgotPasswordAction`: factories returning React `useActionState`-shaped form actions.
37
+ - `./firebaseAuthActions` — `createLoginAction`/`createSignUpAction`/`createForgotPasswordAction`: factories returning React `useActionState`-shaped form actions. `createSendSignInLinkAction`: same factory shape, for passwordless email-link sign-in — returns `{ success: true, email }` so the caller can persist the trimmed email (e.g. to `localStorage`) for the completion step. `completeSignInWithLink(locale, url, email)`: plain async function (not `useActionState`-shaped) that completes a passwordless sign-in from the emailed link's landing page — call from an effect on mount, not a form submit.
38
38
  - `./firebaseAuthMiddleware` — `updateSession`: session-cookie refresh, called automatically by `./middleware`'s default handler.
39
39
 
40
40
  ## `cookieConsent*` subpaths (require `cookieConsent` set on your `RoutingConfig`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.8.19",
3
+ "version": "0.8.21",
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",