cloudflare-next-intl 0.4.6 → 0.5.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.
@@ -2,20 +2,29 @@
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import useCookieConsent from '../use_cookie_consent';
4
4
  import DefaultPrivacyPolicyLink from './default_privacy_policy_link';
5
+ import { getLocaleCache } from '../../../general/cache_variables';
6
+ import { defaultCookieConsentText } from './default_dialog_text';
7
+ import { defaultCookieDialogClassNames } from './default_dialog_styles';
5
8
  /**
6
9
  * Cookie-consent banner. Renders `null` once `consent` is already decided.
7
10
  * Every visual aspect is overridable via `classNames`/`styles` (per-slot) or
8
11
  * `render` (full custom markup) — none of it is hardcoded to Tailwind or any
9
12
  * particular design system.
10
13
  */
11
- export default function CookieConsentDialog({ message = 'We use cookies to improve your experience.', link, privacyPolicyLinkText = 'Privacy Policy', acceptText = 'Accept', declineText = 'Necessary only', hideDecline = false, id = 'cookie-consent-dialog', classNames, styles, render, }) {
14
+ export default function CookieConsentDialog({ message, link, privacyPolicyLinkText, acceptText, declineText, hideDecline = false, id = 'cookie-consent-dialog', classNames, styles, render, }) {
12
15
  const { consent, setConsent, privacyPolicyPath } = useCookieConsent();
13
16
  if (consent !== null)
14
17
  return null;
15
18
  if (render)
16
19
  return _jsx(_Fragment, { children: render({ setConsent }) });
20
+ const text = defaultCookieConsentText[getLocaleCache() ?? 'en'] ?? defaultCookieConsentText.en;
21
+ const resolvedMessage = message ?? text.message;
22
+ const resolvedPrivacyPolicyLinkText = privacyPolicyLinkText ?? text.privacyPolicyLinkText;
23
+ const resolvedAcceptText = acceptText ?? text.acceptText;
24
+ const resolvedDeclineText = declineText ?? text.declineText;
25
+ const resolvedClassNames = { ...defaultCookieDialogClassNames, ...classNames };
17
26
  const resolvedLink = link !== undefined
18
27
  ? link
19
- : _jsx(DefaultPrivacyPolicyLink, { privacyPolicyPath: privacyPolicyPath, text: privacyPolicyLinkText });
20
- return (_jsxs("div", { id: id, role: "dialog", "aria-modal": "false", "aria-labelledby": `${id}-title`, className: classNames?.root, style: styles?.root, children: [_jsxs("p", { id: `${id}-title`, className: classNames?.message, style: styles?.message, children: [message, resolvedLink ? _jsxs("span", { className: classNames?.link, style: styles?.link, children: [" ", resolvedLink] }) : null] }), _jsxs("div", { className: classNames?.actions, style: styles?.actions, children: [!hideDecline && (_jsx("button", { type: "button", onClick: () => setConsent(false), className: classNames?.declineButton, style: styles?.declineButton, children: declineText })), _jsx("button", { type: "button", onClick: () => setConsent(true), className: classNames?.acceptButton, style: styles?.acceptButton, children: acceptText })] })] }));
28
+ : _jsx(DefaultPrivacyPolicyLink, { privacyPolicyPath: privacyPolicyPath, text: resolvedPrivacyPolicyLinkText, className: resolvedClassNames.link });
29
+ return (_jsxs("div", { id: id, role: "dialog", "aria-modal": "false", "aria-labelledby": `${id}-title`, className: resolvedClassNames.root, style: styles?.root, children: [_jsxs("p", { id: `${id}-title`, className: resolvedClassNames.message, style: styles?.message, children: [resolvedMessage, resolvedLink ? _jsxs("span", { children: [" ", resolvedLink] }) : null] }), _jsxs("div", { className: resolvedClassNames.actions, style: styles?.actions, children: [!hideDecline && (_jsx("button", { type: "button", onClick: () => setConsent(false), className: resolvedClassNames.declineButton, style: styles?.declineButton, children: resolvedDeclineText })), _jsx("button", { type: "button", onClick: () => setConsent(true), className: resolvedClassNames.acceptButton, style: styles?.acceptButton, children: resolvedAcceptText })] })] }));
21
30
  }
@@ -0,0 +1,2 @@
1
+ import type { CookieDialogClassNames } from '../../types';
2
+ export declare const defaultCookieDialogClassNames: CookieDialogClassNames;
@@ -0,0 +1,9 @@
1
+ export const defaultCookieDialogClassNames = {
2
+ root: 'fixed bottom-0 w-full bg-cyan-50 dark:bg-cyan-950 text-gray-800 dark:text-gray-200 z-20 flex flex-col sm:flex-row sm:justify-between items-center gap-3 sticky border-t border-t-gray-600 dark:border-t-gray-400 rounded-t-2xl px-4 py-3',
3
+ message: 'text-sm sm:text-base text-gray-600 dark:text-gray-300',
4
+ link: 'underline font-bold duration-200 text-gray-600 hover:text-cyan-800 dark:text-gray-200 dark:hover:text-gray-100 active:text-cyan-700',
5
+ actions: 'flex flex-row gap-2',
6
+ acceptButton: 'cursor-pointer bg-blue-600 text-white rounded-full px-4 py-2 hover:bg-blue-700 active:bg-blue-800 duration-200 dark:bg-blue-800 dark:hover:bg-blue-700 dark:active:bg-blue-900',
7
+ declineButton: 'cursor-pointer bg-blue-200 text-gray-800 rounded-full px-4 py-2 hover:bg-blue-300 active:bg-blue-400 duration-200 dark:bg-cyan-900 dark:text-white dark:hover:bg-cyan-800 dark:active:bg-cyan-950',
8
+ closeButton: 'cursor-pointer bg-blue-200 rounded-full p-2 hover:bg-blue-300 active:bg-blue-400 duration-200 dark:bg-blue-800 dark:text-white dark:hover:bg-blue-700 dark:active:bg-blue-900',
9
+ };
@@ -0,0 +1,13 @@
1
+ export interface CookieConsentDefaultText {
2
+ message: string;
3
+ privacyPolicyLinkText: string;
4
+ acceptText: string;
5
+ declineText: string;
6
+ }
7
+ export interface PrivacyPolicyUpdateDefaultText {
8
+ message: string;
9
+ privacyPolicyLinkText: string;
10
+ closeText: string;
11
+ }
12
+ export declare const defaultCookieConsentText: Record<string, CookieConsentDefaultText>;
13
+ export declare const defaultPrivacyPolicyUpdateText: Record<string, PrivacyPolicyUpdateDefaultText>;
@@ -0,0 +1,26 @@
1
+ export const defaultCookieConsentText = {
2
+ en: {
3
+ message: 'We use cookies to improve your experience.',
4
+ privacyPolicyLinkText: 'Privacy Policy',
5
+ acceptText: 'Accept',
6
+ declineText: 'Necessary only',
7
+ },
8
+ uk: {
9
+ message: 'Ми використовуємо файли cookie, щоб покращити ваш досвід.',
10
+ privacyPolicyLinkText: 'Політика конфіденційності',
11
+ acceptText: 'Прийняти',
12
+ declineText: 'Тільки необхідні',
13
+ },
14
+ };
15
+ export const defaultPrivacyPolicyUpdateText = {
16
+ en: {
17
+ message: 'Our privacy policy has been updated.',
18
+ privacyPolicyLinkText: 'Learn more',
19
+ closeText: 'Got it',
20
+ },
21
+ uk: {
22
+ message: 'Нашу політику конфіденційності було оновлено.',
23
+ privacyPolicyLinkText: 'Дізнатися більше',
24
+ closeText: 'Зрозуміло',
25
+ },
26
+ };
@@ -2,20 +2,28 @@
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import useCookieConsent from '../use_cookie_consent';
4
4
  import DefaultPrivacyPolicyLink from './default_privacy_policy_link';
5
+ import { getLocaleCache } from '../../../general/cache_variables';
6
+ import { defaultPrivacyPolicyUpdateText } from './default_dialog_text';
7
+ import { defaultCookieDialogClassNames } from './default_dialog_styles';
5
8
  /**
6
9
  * "Privacy policy updated" banner. Auto-enabled only when
7
10
  * `cookieConsent.privacyPolicyDate` is set on the `RoutingConfig` — renders
8
11
  * `null` otherwise, or once acknowledged. Every visual aspect is overridable
9
12
  * via `classNames`/`styles` (per-slot) or `render` (full custom markup).
10
13
  */
11
- export default function PrivacyPolicyUpdateDialog({ message = 'Our privacy policy has been updated.', link, privacyPolicyLinkText = 'Learn more', closeText = 'Got it', id = 'privacy-policy-update-dialog', classNames, styles, render, }) {
14
+ export default function PrivacyPolicyUpdateDialog({ message, link, privacyPolicyLinkText, closeText, id = 'privacy-policy-update-dialog', classNames, styles, render, }) {
12
15
  const { privacyPolicyUpdated, acknowledgePrivacyPolicyUpdate, privacyPolicyPath } = useCookieConsent();
13
16
  if (!privacyPolicyUpdated)
14
17
  return null;
15
18
  if (render)
16
19
  return _jsx(_Fragment, { children: render({ acknowledge: acknowledgePrivacyPolicyUpdate }) });
20
+ const text = defaultPrivacyPolicyUpdateText[getLocaleCache() ?? 'en'] ?? defaultPrivacyPolicyUpdateText.en;
21
+ const resolvedMessage = message ?? text.message;
22
+ const resolvedPrivacyPolicyLinkText = privacyPolicyLinkText ?? text.privacyPolicyLinkText;
23
+ const resolvedCloseText = closeText ?? text.closeText;
24
+ const resolvedClassNames = { ...defaultCookieDialogClassNames, ...classNames };
17
25
  const resolvedLink = link !== undefined
18
26
  ? link
19
- : _jsx(DefaultPrivacyPolicyLink, { privacyPolicyPath: privacyPolicyPath, text: privacyPolicyLinkText });
20
- return (_jsxs("div", { id: id, role: "dialog", "aria-modal": "false", "aria-labelledby": `${id}-title`, className: classNames?.root, style: styles?.root, children: [_jsxs("p", { id: `${id}-title`, className: classNames?.message, style: styles?.message, children: [message, resolvedLink ? _jsxs("span", { className: classNames?.link, style: styles?.link, children: [" ", resolvedLink] }) : null] }), _jsx("button", { type: "button", onClick: acknowledgePrivacyPolicyUpdate, "aria-label": closeText, className: classNames?.closeButton, style: styles?.closeButton, children: closeText })] }));
27
+ : _jsx(DefaultPrivacyPolicyLink, { privacyPolicyPath: privacyPolicyPath, text: resolvedPrivacyPolicyLinkText, className: resolvedClassNames.link });
28
+ return (_jsxs("div", { id: id, role: "dialog", "aria-modal": "false", "aria-labelledby": `${id}-title`, className: resolvedClassNames.root, style: styles?.root, children: [_jsxs("p", { id: `${id}-title`, className: resolvedClassNames.message, style: styles?.message, children: [resolvedMessage, resolvedLink ? _jsxs("span", { children: [" ", resolvedLink] }) : null] }), _jsx("button", { type: "button", onClick: acknowledgePrivacyPolicyUpdate, "aria-label": resolvedCloseText, className: resolvedClassNames.closeButton, style: styles?.closeButton, children: resolvedCloseText })] }));
21
29
  }
@@ -8,8 +8,8 @@ export declare const defaultGdprCountries: readonly string[];
8
8
  /**
9
9
  * Resolves whether the cookie-consent banner is required for a visitor.
10
10
  *
11
- * - Neither getter set: country-based gating is off entirely consent is
12
- * never required (the simplest opt-in-by-default setup).
11
+ * - Neither getter set: fail-safe consent is required by default since
12
+ * the visitor's country can't be determined at all.
13
13
  * - Either getter set: fail-safe — a country that couldn't be resolved
14
14
  * still requires consent; only a resolved country OUTSIDE
15
15
  * `gdprCountries` skips the banner. `getCountryCode` takes precedence
@@ -33,8 +33,8 @@ function getGdprCountriesSet(gdprCountries) {
33
33
  /**
34
34
  * Resolves whether the cookie-consent banner is required for a visitor.
35
35
  *
36
- * - Neither getter set: country-based gating is off entirely consent is
37
- * never required (the simplest opt-in-by-default setup).
36
+ * - Neither getter set: fail-safe consent is required by default since
37
+ * the visitor's country can't be determined at all.
38
38
  * - Either getter set: fail-safe — a country that couldn't be resolved
39
39
  * still requires consent; only a resolved country OUTSIDE
40
40
  * `gdprCountries` skips the banner. `getCountryCode` takes precedence
@@ -42,7 +42,7 @@ function getGdprCountriesSet(gdprCountries) {
42
42
  */
43
43
  export default async function resolveRequiresConsent(getCountryCode, getCloudflareContext, gdprCountries) {
44
44
  if (!getCountryCode && !getCloudflareContext)
45
- return false;
45
+ return true;
46
46
  const countryCode = getCountryCode
47
47
  ? await getCountryCode()
48
48
  : (await getCloudflareContext({ async: true }))?.cf?.country;
@@ -59,8 +59,17 @@ export default async function LocationzationProvider({ language, messages, child
59
59
  let analyticsSecrets;
60
60
  let requiresConsent = true;
61
61
  if (config.cookieConsent) {
62
- requiresConsent = await resolveRequiresConsent(config.cookieConsent.getCountryCode, config.cookieConsent.getCloudflareContext, config.cookieConsent.gdprCountries);
63
62
  const isDevEnvironment = process.env.NODE_ENV === 'development';
63
+ // `getCloudflareContext` under `next dev`'s Cloudflare dev shim can
64
+ // crash the local workerd process (a native RPC panic, not a
65
+ // catchable JS error — see cloudflare/workers-sdk#8687) merely by
66
+ // being called, regardless of what it resolves to. `getCountryCode`
67
+ // is caller-supplied and may be dev-safe, so only skip the
68
+ // `getCloudflareContext` path in dev; fail-safe to `true`
69
+ // (banner shown) same as an unresolved country would.
70
+ requiresConsent = !isDevEnvironment
71
+ ? await resolveRequiresConsent(config.cookieConsent.getCountryCode, config.cookieConsent.getCloudflareContext, config.cookieConsent.gdprCountries)
72
+ : false;
64
73
  const analyticsAllowedInEnv = config.cookieConsent.enableAnalyticsInDevMode === true || !isDevEnvironment;
65
74
  if (config.cookieConsent.autoWireAnalytics !== false && analyticsAllowedInEnv) {
66
75
  analyticsSecrets = config.cookieConsent.getSecrets
@@ -155,10 +155,9 @@ export interface CookieConsentRoutingConfig {
155
155
  * `getCloudflareContext`) decides whether the cookie-consent banner is
156
156
  * required at all: visitors outside `gdprCountries` skip the banner and
157
157
  * get analytics immediately (still gated by `enableAnalyticsInDevMode`).
158
- * Omit BOTH to skip country-based gating entirely — the banner is never
159
- * shown and consent is treated as implicitly granted for everyone. This
160
- * is the simplest opt-in-by-default setup; set one of the two getters
161
- * once you need real GDPR-region gating.
158
+ * Omit BOTH to require consent for everyone (fail-safe default — the
159
+ * visitor's country can't be determined at all without either getter).
160
+ * Set one of the two getters to scope the banner to GDPR regions only.
162
161
  */
163
162
  getCloudflareContext?: CookieConsentGetCloudflareContext;
164
163
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.4.6",
3
+ "version": "0.5.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",
@@ -201,7 +201,6 @@
201
201
  "devDependencies": {
202
202
  "@eslint/eslintrc": "^3",
203
203
  "@eslint/js": "^9.27.0",
204
- "@microsoft/clarity": "^1.0.2",
205
204
  "@testing-library/dom": "^10.4.1",
206
205
  "@testing-library/jest-dom": "^7.0.0",
207
206
  "@testing-library/react": "^16.3.2",