cloudflare-next-intl 0.3.0 → 0.3.1

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.
@@ -15,6 +15,8 @@ async function getIsBotValue(userAgent) {
15
15
  if (userAgent === null)
16
16
  return false;
17
17
  const { isBot } = await import('next/dist/server/web/spec-extension/user-agent');
18
+ // Unreachable: userAgent is already narrowed to non-null string above,
19
+ // so the ?? '' fallback never triggers.
18
20
  return isBot(userAgent ?? '');
19
21
  }
20
22
  const getIsBotValueCache = cache(getIsBotValue);
@@ -57,7 +59,9 @@ export default async function intlMiddleware(request, options) {
57
59
  let urlLocale;
58
60
  let pathWithoutLocale;
59
61
  // Avoids split('/').filter(Boolean) array allocation on every request:
60
- // scan for the first segment's bounds directly.
62
+ // scan for the first segment's bounds directly. Unreachable:
63
+ // Next.js guarantees pathname always starts with '/', so the else
64
+ // branch (segmentStart = 0) never runs.
61
65
  const segmentStart = pathname.charCodeAt(0) === 47 /* '/' */ ? 1 : 0;
62
66
  let segmentEnd = pathname.indexOf('/', segmentStart);
63
67
  if (segmentEnd === -1)
@@ -38,5 +38,8 @@ export default function firebaseAuthErrorMessage(locale, error) {
38
38
  // fall through to English default
39
39
  }
40
40
  }
41
+ // Unreachable: key is always either a value from ERROR_CODE_TO_KEY (all
42
+ // valid DEFAULT_MESSAGES_EN keys) or the literal 'unknown' fallback
43
+ // above, so DEFAULT_MESSAGES_EN[key] never misses.
41
44
  return DEFAULT_MESSAGES_EN[key] ?? DEFAULT_MESSAGES_EN.unknown;
42
45
  }
@@ -1,19 +1,39 @@
1
1
  import type { User } from 'firebase/auth';
2
2
  /**
3
- * Server Component counterpart of the client `useAuthUser()` hook (from
4
- * `cloudflare-next-intl/useFirebaseAuthUser`'s `default` condition this
5
- * file is that same subpath's `react-server` condition, resolved
6
- * automatically, not a separately-imported function). Reads through the
7
- * same `cache()`-wrapped `getAuthenticatedAppForUser`, so every server
8
- * component calling this within one request shares one lookup.
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.
9
21
  *
10
- * Returns the same `{ user, loading }` shape the client variant's context
11
- * exposes (`loading` is always `false` here — server resolution is
12
- * synchronous with respect to the awaited call), so code reading
13
- * `const { user } = await useAuthUser()` generalizes correctly from
14
- * `const { user } = useAuthUser()` on the client side.
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.
15
34
  */
16
35
  export default function useAuthUser(): Promise<{
17
36
  user: User | null;
18
37
  loading: false;
19
38
  }>;
39
+ export {};
@@ -1,19 +1,37 @@
1
1
  import { getAuthenticatedAppForUser } from './firebase_server';
2
2
  /**
3
- * Server Component counterpart of the client `useAuthUser()` hook (from
4
- * `cloudflare-next-intl/useFirebaseAuthUser`'s `default` condition this
5
- * file is that same subpath's `react-server` condition, resolved
6
- * automatically, not a separately-imported function). Reads through the
7
- * same `cache()`-wrapped `getAuthenticatedAppForUser`, so every server
8
- * component calling this within one request shares one lookup.
9
- *
10
- * Returns the same `{ user, loading }` shape the client variant's context
11
- * exposes (`loading` is always `false` here — server resolution is
12
- * synchronous with respect to the awaited call), so code reading
13
- * `const { user } = await useAuthUser()` generalizes correctly from
14
- * `const { user } = useAuthUser()` on the client side.
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.
15
6
  */
16
- export default async function useAuthUser() {
7
+ async function iGetAuthUser() {
17
8
  const { currentUser } = await getAuthenticatedAppForUser();
18
9
  return { user: currentUser, loading: false };
19
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 const getAuthUser = 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 async function useAuthUser() {
36
+ return getAuthUser();
37
+ }
@@ -51,7 +51,10 @@ export function getTranslationsImpl(locale, messages, namespace, cacheKey) {
51
51
  }
52
52
  }
53
53
  }
54
- // If after traversal, no base translations object was found.
54
+ // If after traversal, no base translations object was found. Unreachable:
55
+ // the loop above always either sets translationsBase or returns early on
56
+ // its final iteration, since namespaceParts always has length >= 1
57
+ // (''.split('.') yields ['']).
55
58
  if (!translationsBase) {
56
59
  return errorAndReturnFallback(`Translations for namespace "${namespace}" could not be found.`, cacheKeyValue, locale, namespace);
57
60
  }
@@ -66,6 +69,9 @@ export function getTranslationsImpl(locale, messages, namespace, cacheKey) {
66
69
  // Traverse the resolved translations base using the key parts.
67
70
  for (let i = 0; i < keyParts.length; i++) {
68
71
  const part = keyParts[i];
72
+ // Unreachable: currentTranslation only ever becomes a string via
73
+ // the reassignment below, which is guarded to only assign
74
+ // non-null objects.
69
75
  if (typeof currentTranslation === 'string') {
70
76
  // Translation key path prematurely leads to a string.
71
77
  console.warn(`Translation key "${key}" in namespace "${namespace}" leads to a string prematurely at "${part}" for locale "${locale}".`);
@@ -91,7 +97,10 @@ export function getTranslationsImpl(locale, messages, namespace, cacheKey) {
91
97
  }
92
98
  }
93
99
  }
94
- // If the loop completes and no string translation was found (e.g., key missing or not a string).
100
+ // If the loop completes and no string translation was found (e.g.,
101
+ // key missing or not a string). Unreachable: keyParts always has
102
+ // length >= 1 (''.split('.') yields ['']), and every branch above
103
+ // returns on the final iteration.
95
104
  console.warn(`Translation key "${key}" in namespace "${namespace}" is missing or not a string for locale "${locale}".`);
96
105
  return key; // Return the key as fallback
97
106
  };
package/llms.txt CHANGED
@@ -30,6 +30,7 @@ other subpath can be used.
30
30
  - `./firebaseAuthClientProvider` — `AuthUserProvider`: client auth-state provider (session cookie sync, auth-page redirects).
31
31
  - `./firebaseAuthServerProvider` — server-side equivalent provider (not used by the default auto-wiring path — see its doc comment).
32
32
  - `./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.
33
+ - `./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.
33
34
  - `./firebaseAuthActions` — `createLoginAction`/`createSignUpAction`/`createForgotPasswordAction`: factories returning React `useActionState`-shaped form actions.
34
35
  - `./firebaseAuthMiddleware` — `updateSession`: session-cookie refresh, called automatically by `./middleware`'s default handler.
35
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",
@@ -104,6 +104,10 @@
104
104
  "import": "./dist/src/firebase_auth/client/use_auth_user.js"
105
105
  }
106
106
  },
107
+ "./getFirebaseAuthUser": {
108
+ "types": "./dist/src/firebase_auth/server/use_auth_user_server.d.ts",
109
+ "import": "./dist/src/firebase_auth/server/use_auth_user_server.js"
110
+ },
107
111
  "./firebaseAuthActions": {
108
112
  "types": "./dist/src/firebase_auth/client/auth_actions.d.ts",
109
113
  "import": "./dist/src/firebase_auth/client/auth_actions.js"
@@ -150,9 +154,9 @@
150
154
  "author": "Demian Ilnutskyi",
151
155
  "license": "MIT",
152
156
  "bugs": {
153
- "url": "https://github.com/DemienIlnutskiy/cloudflare-next-intl/issues"
157
+ "url": "https://github.com/demian-ilnytskyi/cloudflare-next-intl/issues"
154
158
  },
155
- "homepage": "https://github.com/DemienIlnutskiy/cloudflare-next-intl#readme",
159
+ "homepage": "https://github.com/demian-ilnytskyi/cloudflare-next-intl#readme",
156
160
  "peerDependencies": {
157
161
  "firebase": ">=10.0.0",
158
162
  "next": ">=12.0.0",