cloudflare-next-intl 0.4.6 → 0.5.0

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.
@@ -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
+ : true;
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.0",
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",