cloudflare-next-intl 0.9.5 → 0.9.7

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 (30) hide show
  1. package/dist/src/client/components/client_provider.js +1 -1
  2. package/dist/src/client/components/client_provider_static.js +1 -1
  3. package/dist/src/client/components/locale_link.d.ts +1 -1
  4. package/dist/src/client/components/locale_link_client.js +1 -1
  5. package/dist/src/client/hooks/use_path_name.js +1 -1
  6. package/dist/src/config/middleware.d.ts +2 -2
  7. package/dist/src/config/middleware.js +1 -1
  8. package/dist/src/cookie_consent/client/components/auto_analytics_events.js +1 -1
  9. package/dist/src/cookie_consent/client/components/cookie_consent_analytics.js +1 -1
  10. package/dist/src/cookie_consent/client/components/default_privacy_policy_link.js +1 -1
  11. package/dist/src/cookie_consent/client/cookie_consent_provider.js +1 -1
  12. package/dist/src/db/connection.js +10 -0
  13. package/dist/src/db/context.js +20 -38
  14. package/dist/src/error_handling/create_server_error_action.js +1 -1
  15. package/dist/src/firebase_auth/client/auth_user_provider.js +1 -1
  16. package/dist/src/firebase_auth/middleware/update_session.d.ts +1 -1
  17. package/dist/src/firebase_auth/middleware/update_session.js +1 -1
  18. package/dist/src/firebase_auth/server/auth_user_server_provider.js +3 -3
  19. package/dist/src/firebase_auth/server/clear_session_action.js +1 -1
  20. package/dist/src/firebase_auth/server/firebase_server.js +1 -1
  21. package/dist/src/image_optimizer/next_image_shim.d.ts +2 -2
  22. package/dist/src/image_optimizer/next_image_shim.js +1 -1
  23. package/dist/src/server/components/link.d.ts +1 -1
  24. package/dist/src/server/components/link.js +1 -1
  25. package/dist/src/server/components/server_provider.js +2 -2
  26. package/dist/src/server/components/server_provider_static.js +2 -2
  27. package/dist/src/server/functions/geo.js +2 -2
  28. package/dist/src/server/functions/server.js +2 -2
  29. package/dist/src/types/types.d.ts +1 -1
  30. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
4
4
  import { createContext, useMemo } from "react";
5
- import dynamic from "next/dynamic";
5
+ import dynamic from "next/dynamic.js";
6
6
  import config from "@intl-config";
7
7
  import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
8
8
  import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
4
4
  import { createContext, useMemo } from "react";
5
- import dynamic from "next/dynamic";
5
+ import dynamic from "next/dynamic.js";
6
6
  import config from "@intl-config";
7
7
  import installConsoleErrorOverride from "../../error_handling/install_console_error_override.js";
8
8
  import installGlobalErrorOverride from "../../error_handling/install_global_error_override.js";
@@ -1,4 +1,4 @@
1
- import { type LinkProps } from 'next/link';
1
+ import { type LinkProps } from 'next/link.js';
2
2
  import { type ComponentProps } from 'react';
3
3
  type NextLinkProps = Omit<ComponentProps<'a'>, keyof LinkProps> & Omit<LinkProps, 'locale' | 'href' | 'prefetch' | 'onNavigate' | 'hrefLang' | 'replace' | 'scroll'>;
4
4
  export type LocaleLinkProps = NextLinkProps & {
@@ -5,7 +5,7 @@ import config from '../../config/intl_config.js';
5
5
  import usePathname from '../hooks/use_path_name.js';
6
6
  import { localeCookieName } from '../../config/cookie_key.js';
7
7
  import setCookie from '../functions/set_cookie.js';
8
- import { useSearchParams } from 'next/navigation';
8
+ import { useSearchParams } from 'next/navigation.js';
9
9
  function ClientLocaleLinkComponent({ locale, className, ...rest }, ref) {
10
10
  const pathname = usePathname();
11
11
  const searchParams = useSearchParams();
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { usePathname as nextUsePathname } from "next/navigation";
2
+ import { usePathname as nextUsePathname } from "next/navigation.js";
3
3
  import { useLocale } from "./client_hooks.js";
4
4
  export default function usePathname() {
5
5
  const pathname = nextUsePathname();
@@ -1,5 +1,5 @@
1
- import type { NextRequest } from 'next/server';
2
- import { NextResponse } from 'next/server';
1
+ import type { NextRequest } from 'next/server.js';
2
+ import { NextResponse } from 'next/server.js';
3
3
  import type { MiddlewareCustomHandler } from '../types/types.js';
4
4
  export declare const localesSet: Set<string>;
5
5
  export default function intlMiddleware(request: NextRequest, options?: {
@@ -1,4 +1,4 @@
1
- import { NextResponse } from 'next/server';
1
+ import { NextResponse } from 'next/server.js';
2
2
  import { languageDetecotr } from '../server/functions/get_user_locale.js';
3
3
  import config from './intl_config.js';
4
4
  import { isBotCookieKey, localeCookieName } from './cookie_key.js';
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { usePathname } from 'next/navigation';
2
+ import { usePathname } from 'next/navigation.js';
3
3
  import { useReportWebVitals } from 'next/web-vitals';
4
4
  import { useEffect } from 'react';
5
5
  import useCookieConsent from '../use_cookie_consent.js';
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect } from 'react';
4
- import dynamic from 'next/dynamic';
4
+ import dynamic from 'next/dynamic.js';
5
5
  import useCookieConsent from '../use_cookie_consent.js';
6
6
  const ClarityScript = dynamic(() => import('./clarity_script.js'));
7
7
  export default function CookieConsentAnalytics({ config }) {
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import NextLink from 'next/link';
3
+ import NextLink from 'next/link.js';
4
4
  import config from '../../../config/intl_config.js';
5
5
  import { getLocaleCache } from '../../../general/cache_variables.js';
6
6
  export default function DefaultPrivacyPolicyLink({ privacyPolicyPath, text, className, style }) {
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useCallback, useEffect, useMemo, useState } from 'react';
4
- import { usePathname } from 'next/navigation';
4
+ import { usePathname } from 'next/navigation.js';
5
5
  import config from '../../config/intl_config.js';
6
6
  import requireCookieConsentConfig from '../require_config.js';
7
7
  import getCookie from '../../client/functions/get_cookie.js';
@@ -21,6 +21,14 @@ async function resolveConnectionString(db, generate) {
21
21
  'to a connection string, or to a function returning one (e.g. reading a ' +
22
22
  'Hyperdrive binding off `env` or `getCloudflareContext().env`).');
23
23
  }
24
+ async function resetSessionState(client) {
25
+ try {
26
+ await client.query('discard all');
27
+ }
28
+ catch {
29
+ await client.query('reset role').catch(() => undefined);
30
+ }
31
+ }
24
32
  export async function withDbClient(config, queryFn) {
25
33
  const db = config.db;
26
34
  requireDbConfig(db);
@@ -33,6 +41,7 @@ export async function withDbClient(config, queryFn) {
33
41
  try {
34
42
  await client.connect();
35
43
  connected = true;
44
+ await resetSessionState(client);
36
45
  }
37
46
  catch (error) {
38
47
  const message = error instanceof Error ? error.message : String(error ?? '');
@@ -83,6 +92,7 @@ export async function connectToPostgres(config) {
83
92
  void reportError({ errorHandling: config.errorHandling, generate: config.generate }, { error, classOrMethodName: 'db.connectToPostgres.clientError' });
84
93
  });
85
94
  await client.connect();
95
+ await resetSessionState(client);
86
96
  return client;
87
97
  }
88
98
  export async function disconnectPostgres(client) {
@@ -126,10 +126,6 @@ function injectUidComment(sql, userId) {
126
126
  }
127
127
  return sql;
128
128
  }
129
- function isSelectOnly(sql) {
130
- const text = typeof sql === 'string' ? sql : sql?.text;
131
- return typeof text === 'string' && /^(select|with)\b/i.test(text.trimStart());
132
- }
133
129
  export async function withUserDb(fn, uid, dbOverride) {
134
130
  const config = await resolveDbConfig(dbOverride);
135
131
  const db = config.db;
@@ -144,17 +140,29 @@ export async function withUserDb(fn, uid, dbOverride) {
144
140
  return await withDbClient(config, async (client) => {
145
141
  const rawClient = client;
146
142
  const setSessionState = async () => {
147
- await rawClient.query(`select set_config('request.jwt.claims', $1, false)`, [JSON.stringify({ sub: userId })]);
148
- await rawClient.query(`set role "${role.replace(/"/g, '""')}"`);
143
+ await rawClient.query(`select set_config('request.jwt.claims', $1, true)`, [JSON.stringify({ sub: userId })]);
144
+ await rawClient.query(`set local role "${role.replace(/"/g, '""')}"`);
149
145
  };
150
146
  let inTransaction = false;
151
- let sessionStateSet = false;
152
147
  let gate = Promise.resolve();
153
148
  const serialize = (op) => {
154
149
  const run = gate.then(op, op);
155
150
  gate = run.catch(() => undefined);
156
151
  return run;
157
152
  };
153
+ const beginWithIdentity = async () => {
154
+ if (inTransaction)
155
+ return;
156
+ await rawClient.query('begin');
157
+ try {
158
+ await setSessionState();
159
+ }
160
+ catch (error) {
161
+ await rawClient.query('rollback').catch(() => undefined);
162
+ throw error;
163
+ }
164
+ inTransaction = true;
165
+ };
158
166
  const interceptingClient = new Proxy(client, {
159
167
  get(target, prop) {
160
168
  if (prop === 'query') {
@@ -164,16 +172,7 @@ export async function withUserDb(fn, uid, dbOverride) {
164
172
  const isCommitOrRollback = /^(commit|rollback)\b/i.test(text.trimStart());
165
173
  if (isBegin) {
166
174
  return await serialize(async () => {
167
- if (!sessionStateSet) {
168
- await rawClient.query('begin');
169
- inTransaction = true;
170
- await setSessionState();
171
- sessionStateSet = true;
172
- }
173
- else if (!inTransaction) {
174
- await rawClient.query('begin');
175
- inTransaction = true;
176
- }
175
+ await beginWithIdentity();
177
176
  return { rows: [], rowCount: 0 };
178
177
  });
179
178
  }
@@ -187,27 +186,7 @@ export async function withUserDb(fn, uid, dbOverride) {
187
186
  return { rows: [], rowCount: 0 };
188
187
  });
189
188
  }
190
- await serialize(async () => {
191
- if (!sessionStateSet) {
192
- if (isSelectOnly(sql)) {
193
- await rawClient.query('begin');
194
- inTransaction = true;
195
- await setSessionState();
196
- await rawClient.query('commit');
197
- inTransaction = false;
198
- }
199
- else {
200
- await rawClient.query('begin');
201
- inTransaction = true;
202
- await setSessionState();
203
- }
204
- sessionStateSet = true;
205
- }
206
- else if (!inTransaction && !isSelectOnly(sql)) {
207
- await rawClient.query('begin');
208
- inTransaction = true;
209
- }
210
- });
189
+ await serialize(beginWithIdentity);
211
190
  const targetClient = target;
212
191
  return targetClient.query(injectUidComment(sql, userId), ...args);
213
192
  };
@@ -218,15 +197,18 @@ export async function withUserDb(fn, uid, dbOverride) {
218
197
  });
219
198
  const { drizzle } = await import('drizzle-orm/node-postgres');
220
199
  const drizzleHandle = drizzle(interceptingClient);
200
+ const resetRole = () => rawClient.query('reset role').catch(() => undefined);
221
201
  try {
222
202
  const result = await fn(await postgresDb(drizzleHandle, interceptingClient));
223
203
  if (inTransaction)
224
204
  await rawClient.query('commit');
205
+ await resetRole();
225
206
  return result;
226
207
  }
227
208
  catch (err) {
228
209
  if (inTransaction)
229
210
  await rawClient.query('rollback').catch(() => undefined);
211
+ await resetRole();
230
212
  throw err;
231
213
  }
232
214
  });
@@ -2,7 +2,7 @@ import reportError from './report_error.js';
2
2
  import stringifyUnknown from './stringify_unknown.js';
3
3
  async function resolveRequestContext() {
4
4
  try {
5
- const { headers } = await import('next/headers');
5
+ const { headers } = await import('next/headers.js');
6
6
  const headerList = await headers();
7
7
  return {
8
8
  path: headerList.get('x-pathname') ?? undefined,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useCallback, useEffect, useRef, useState } from 'react';
4
- import { useRouter } from 'next/navigation';
4
+ import { useRouter } from 'next/navigation.js';
5
5
  import usePathname from '../../client/hooks/use_path_name.js';
6
6
  import config from '@intl-config';
7
7
  import requireFirebaseAuthConfig from '../require_config.js';
@@ -1,4 +1,4 @@
1
- import { NextResponse, type NextRequest } from 'next/server';
1
+ import { NextResponse, type NextRequest } from 'next/server.js';
2
2
  import config from '@intl-config';
3
3
  export declare const defaultSessionCookieName = "__fa_session__";
4
4
  export declare const defaultRefreshTokenCookieName = "__fa_refresh_token__";
@@ -1,4 +1,4 @@
1
- import { NextResponse } from 'next/server';
1
+ import { NextResponse } from 'next/server.js';
2
2
  import config from '@intl-config';
3
3
  import decodeJwtPayload from '../decode_jwt_payload.js';
4
4
  import isWhitelisted from '../is_whitelisted.js';
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import dynamic from 'next/dynamic';
3
- import { headers } from 'next/headers';
4
- import { redirect } from 'next/navigation';
2
+ import dynamic from 'next/dynamic.js';
3
+ import { headers } from 'next/headers.js';
4
+ import { redirect } from 'next/navigation.js';
5
5
  import config from '@intl-config';
6
6
  import requireFirebaseAuthConfig from '../require_config.js';
7
7
  import { getAuthenticatedAppForUser } from './firebase_server.js';
@@ -1,5 +1,5 @@
1
1
  "use server";
2
- import { cookies } from "next/headers";
2
+ import { cookies } from "next/headers.js";
3
3
  import config from "@intl-config";
4
4
  import { defaultRefreshTokenCookieName, defaultSessionCookieName } from "../middleware/update_session.js";
5
5
  export default async function clearSessionAction() {
@@ -1,4 +1,4 @@
1
- import { cookies } from 'next/headers';
1
+ import { cookies } from 'next/headers.js';
2
2
  import { cache } from 'react';
3
3
  import config from '@intl-config';
4
4
  import requireFirebaseAuthConfig from '../require_config.js';
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
- import { getImageProps as nextGetImageProps } from "next/image";
3
- import type { ImageProps } from "next/image";
2
+ import { getImageProps as nextGetImageProps } from "next/image.js";
3
+ import type { ImageProps } from "next/image.js";
4
4
  import { getImageBlurSvg } from "./blur_svg.js";
5
5
  import type { OptimizedImage } from "./types.js";
6
6
  export type ManifestEntry = OptimizedImage;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import NextImage, { getImageProps as nextGetImageProps } from "next/image";
2
+ import NextImage, { getImageProps as nextGetImageProps } from "next/image.js";
3
3
  import { getImageBlurSvg } from "./blur_svg.js";
4
4
  import { ImgWithFallback } from "./img_with_fallback.js";
5
5
  function pickVariant(entry, requestedWidth) {
@@ -1,4 +1,4 @@
1
- import { type LinkProps } from 'next/link';
1
+ import { type LinkProps } from 'next/link.js';
2
2
  import { type ComponentProps } from 'react';
3
3
  type NextLinkProps = Omit<ComponentProps<'a'>, keyof LinkProps> & Omit<LinkProps, 'locale'>;
4
4
  declare const Link: import("react").ForwardRefExoticComponent<Omit<NextLinkProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement>>;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import LinkComponent from 'next/link';
2
+ import LinkComponent from 'next/link.js';
3
3
  import { forwardRef, } from 'react';
4
4
  import config from '../../config/intl_config.js';
5
5
  import { getLocaleCache } from '../../general/cache_variables.js';
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
3
3
  import { getMessage } from "../functions/server.js";
4
- import dynamic from "next/dynamic";
4
+ import dynamic from "next/dynamic.js";
5
5
  import { localesSet } from "../../config/middleware.js";
6
6
  import config from "../../config/intl_config.js";
7
7
  import resolveRequiresConsent from "../../cookie_consent/gdpr_countries.js";
@@ -11,7 +11,7 @@ const LocationzationClientProvider = dynamic(() => import("../../client/componen
11
11
  let authUserServerProviderModule;
12
12
  export default async function LocationzationProvider({ language, messages, staticSafe = true, children }) {
13
13
  if (!localesSet.has(language)) {
14
- const { notFound } = await import("next/navigation");
14
+ const { notFound } = await import("next/navigation.js");
15
15
  notFound();
16
16
  }
17
17
  if (language) {
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { setLocaleCache, setMessageForLocaleCache } from "../../general/cache_variables.js";
3
3
  import { getMessage } from "../functions/server.js";
4
- import dynamic from "next/dynamic";
4
+ import dynamic from "next/dynamic.js";
5
5
  import { localesSet } from "../../config/middleware.js";
6
6
  import config from "../../config/intl_config.js";
7
7
  import resolveRequiresConsent from "../../cookie_consent/gdpr_countries.js";
@@ -10,7 +10,7 @@ import reportError from "../../error_handling/report_error.js";
10
10
  const LocationzationClientProvider = dynamic(() => import("../../client/components/client_provider_static.js"));
11
11
  export default async function LocationzationProvider({ language, messages, children }) {
12
12
  if (!localesSet.has(language)) {
13
- const { notFound } = await import("next/navigation");
13
+ const { notFound } = await import("next/navigation.js");
14
14
  notFound();
15
15
  }
16
16
  if (config.firebaseAuth) {
@@ -48,7 +48,7 @@ export async function getCountry(input, generate, headerNames) {
48
48
  }
49
49
  }
50
50
  try {
51
- const { headers } = await import('next/headers');
51
+ const { headers } = await import('next/headers.js');
52
52
  const h = await headers();
53
53
  const country = extractFromHeaderNames(h, names);
54
54
  if (country)
@@ -101,7 +101,7 @@ export async function getTimezone(input, fallback, generate, headerNames) {
101
101
  }
102
102
  }
103
103
  try {
104
- const { headers } = await import('next/headers');
104
+ const { headers } = await import('next/headers.js');
105
105
  const h = await headers();
106
106
  const tz = extractFromHeaderNames(h, names);
107
107
  if (tz)
@@ -19,7 +19,7 @@ async function iGetMessage(locale) {
19
19
  }
20
20
  catch {
21
21
  if (!localesSet.has(locale)) {
22
- const { notFound } = await import("next/navigation");
22
+ const { notFound } = await import("next/navigation.js");
23
23
  notFound();
24
24
  return {};
25
25
  }
@@ -47,7 +47,7 @@ async function iGetLocale() {
47
47
  }
48
48
  try {
49
49
  if (!nextHeadersModule) {
50
- nextHeadersModule = await import("next/headers");
50
+ nextHeadersModule = await import("next/headers.js");
51
51
  }
52
52
  const cookieStore = await nextHeadersModule.cookies();
53
53
  const localeCookie = cookieStore.get(localeCookieName);
@@ -1,4 +1,4 @@
1
- import type { NextResponse } from 'next/server';
1
+ import type { NextResponse } from 'next/server.js';
2
2
  import type { Languages } from 'next/dist/lib/metadata/types/alternative-urls-types';
3
3
  import type { Videos } from 'next/dist/lib/metadata/types/metadata-types';
4
4
  import type { CookieConsentDialogProps } from '../cookie_consent/client/components/cookie_consent_dialog.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
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",