cloudflare-next-intl 0.10.34 → 0.13.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.
Files changed (180) hide show
  1. package/README.md +2 -0
  2. package/dist/src/client/components/client_extensions.d.ts +20 -0
  3. package/dist/src/client/components/client_extensions.js +37 -0
  4. package/dist/src/client/components/client_helper_script.d.ts +2 -1
  5. package/dist/src/client/components/client_helper_script.js +2 -15
  6. package/dist/src/client/components/client_provider.d.ts +7 -16
  7. package/dist/src/client/components/client_provider.js +6 -36
  8. package/dist/src/client/components/client_provider_static.d.ts +2 -21
  9. package/dist/src/client/components/client_provider_static.js +2 -26
  10. package/dist/src/client/components/locale_link.d.ts +2 -8
  11. package/dist/src/client/components/locale_link.js +2 -8
  12. package/dist/src/client/components/locale_link_client.d.ts +2 -3
  13. package/dist/src/client/components/locale_link_client.js +2 -30
  14. package/dist/src/client/components/locale_provider.d.ts +2 -13
  15. package/dist/src/client/components/locale_provider.js +2 -8
  16. package/dist/src/client/functions/get_cookie.d.ts +2 -1
  17. package/dist/src/client/functions/get_cookie.js +2 -32
  18. package/dist/src/client/functions/set_cookie.d.ts +2 -5
  19. package/dist/src/client/functions/set_cookie.js +2 -17
  20. package/dist/src/client/hooks/client_hooks.d.ts +1 -3
  21. package/dist/src/client/hooks/client_hooks.js +1 -19
  22. package/dist/src/client/hooks/use_path_name.d.ts +2 -1
  23. package/dist/src/client/hooks/use_path_name.js +2 -17
  24. package/dist/src/client/index.d.ts +7 -3
  25. package/dist/src/client/index.js +7 -3
  26. package/dist/src/client_messages_scan/index.d.ts +1 -3
  27. package/dist/src/client_messages_scan/index.js +1 -3
  28. package/dist/src/client_messages_scan/match_namespace.d.ts +1 -1
  29. package/dist/src/client_messages_scan/match_namespace.js +1 -3
  30. package/dist/src/client_messages_scan/scan_file.d.ts +1 -16
  31. package/dist/src/client_messages_scan/scan_file.js +1 -175
  32. package/dist/src/client_messages_scan/scan_project.d.ts +1 -16
  33. package/dist/src/client_messages_scan/scan_project.js +1 -67
  34. package/dist/src/config/cookie_key.d.ts +2 -5
  35. package/dist/src/config/cookie_key.js +2 -5
  36. package/dist/src/config/init_config.js +13 -31
  37. package/dist/src/config/intl_config.js +12 -7
  38. package/dist/src/config/intl_sitemap.d.ts +2 -8
  39. package/dist/src/config/intl_sitemap.js +2 -28
  40. package/dist/src/config/middleware.d.ts +9 -6
  41. package/dist/src/config/middleware.js +11 -173
  42. package/dist/src/cookie_consent/client/cookie_consent_provider.d.ts +3 -1
  43. package/dist/src/cookie_consent/client/cookie_consent_provider.js +3 -3
  44. package/dist/src/db/resolve_db_config.js +2 -0
  45. package/dist/src/error_handling/clear_client_cache.d.ts +2 -1
  46. package/dist/src/error_handling/clear_client_cache.js +2 -17
  47. package/dist/src/error_handling/create_server_error_action.d.ts +2 -3
  48. package/dist/src/error_handling/create_server_error_action.js +2 -6
  49. package/dist/src/error_handling/default_ignored_console_errors.d.ts +1 -1
  50. package/dist/src/error_handling/default_ignored_console_errors.js +1 -33
  51. package/dist/src/error_handling/format_error_message.d.ts +2 -2
  52. package/dist/src/error_handling/format_error_message.js +2 -16
  53. package/dist/src/error_handling/index.d.ts +1 -13
  54. package/dist/src/error_handling/index.js +1 -10
  55. package/dist/src/error_handling/install_console_error_override.d.ts +2 -3
  56. package/dist/src/error_handling/install_console_error_override.js +2 -39
  57. package/dist/src/error_handling/install_global_error_override.d.ts +2 -2
  58. package/dist/src/error_handling/install_global_error_override.js +2 -30
  59. package/dist/src/error_handling/is_stale_deploy_error.d.ts +2 -4
  60. package/dist/src/error_handling/is_stale_deploy_error.js +2 -51
  61. package/dist/src/error_handling/match_error_message.d.ts +1 -2
  62. package/dist/src/error_handling/match_error_message.js +1 -10
  63. package/dist/src/error_handling/merge_report_params.d.ts +2 -2
  64. package/dist/src/error_handling/merge_report_params.js +2 -9
  65. package/dist/src/error_handling/report_client_error.d.ts +2 -3
  66. package/dist/src/error_handling/report_client_error.js +2 -15
  67. package/dist/src/error_handling/report_client_error_action.d.ts +1 -2
  68. package/dist/src/error_handling/report_client_error_action.js +1 -6
  69. package/dist/src/error_handling/report_client_error_core.d.ts +1 -3
  70. package/dist/src/error_handling/report_client_error_core.js +1 -26
  71. package/dist/src/error_handling/report_error.d.ts +2 -9
  72. package/dist/src/error_handling/report_error.js +2 -73
  73. package/dist/src/error_handling/stringify_unknown.d.ts +2 -5
  74. package/dist/src/error_handling/stringify_unknown.js +2 -57
  75. package/dist/src/error_handling/use_stale_deploy_recovery.d.ts +2 -4
  76. package/dist/src/error_handling/use_stale_deploy_recovery.js +2 -141
  77. package/dist/src/error_handling/with_error_handling.d.ts +2 -9
  78. package/dist/src/error_handling/with_error_handling.js +2 -13
  79. package/dist/src/firebase_auth/client/auth_actions.d.ts +1 -6
  80. package/dist/src/firebase_auth/client/auth_actions.js +1 -93
  81. package/dist/src/firebase_auth/client/auth_user_provider.d.ts +2 -8
  82. package/dist/src/firebase_auth/client/auth_user_provider.js +2 -283
  83. package/dist/src/firebase_auth/client/components/auto_firebase_performance_events.d.ts +2 -1
  84. package/dist/src/firebase_auth/client/components/auto_firebase_performance_events.js +2 -29
  85. package/dist/src/firebase_auth/client/firebase_client.d.ts +1 -33
  86. package/dist/src/firebase_auth/client/firebase_client.js +1 -218
  87. package/dist/src/firebase_auth/client/use_auth_user.d.ts +2 -2
  88. package/dist/src/firebase_auth/client/use_auth_user.js +2 -10
  89. package/dist/src/firebase_auth/index.d.ts +1 -10
  90. package/dist/src/firebase_auth/index.js +1 -8
  91. package/dist/src/firebase_auth/middleware/update_session.d.ts +2 -27
  92. package/dist/src/firebase_auth/middleware/update_session.js +2 -328
  93. package/dist/src/firebase_auth/server/auth_user_server_provider.d.ts +2 -5
  94. package/dist/src/firebase_auth/server/auth_user_server_provider.js +2 -37
  95. package/dist/src/firebase_auth/server/resolve_optional_auth_user.d.ts +2 -7
  96. package/dist/src/firebase_auth/server/resolve_optional_auth_user.js +2 -15
  97. package/dist/src/firebase_auth/server/use_auth_user_server.d.ts +2 -11
  98. package/dist/src/firebase_auth/server/use_auth_user_server.js +2 -9
  99. package/dist/src/firebase_auth/types.d.ts +1 -31
  100. package/dist/src/firebase_auth/types.js +1 -1
  101. package/dist/src/firebase_auth_check/index.d.ts +1 -2
  102. package/dist/src/firebase_auth_check/index.js +1 -2
  103. package/dist/src/general/cache_variables.d.ts +1 -10
  104. package/dist/src/general/cache_variables.js +1 -25
  105. package/dist/src/general/general_functions.d.ts +1 -2
  106. package/dist/src/general/general_functions.js +1 -110
  107. package/dist/src/general/index.d.ts +1 -2
  108. package/dist/src/general/index.js +1 -2
  109. package/dist/src/general/metadata.d.ts +1 -13
  110. package/dist/src/general/metadata.js +1 -29
  111. package/dist/src/general/pick_client_messages.d.ts +2 -2
  112. package/dist/src/general/pick_client_messages.js +2 -17
  113. package/dist/src/image_optimizer/next_image_shim.js +15 -17
  114. package/dist/src/server/components/helper_script.d.ts +4 -2
  115. package/dist/src/server/components/helper_script.js +20 -321
  116. package/dist/src/server/components/link.d.ts +2 -10
  117. package/dist/src/server/components/link.js +2 -143
  118. package/dist/src/server/components/server_provider.d.ts +4 -3
  119. package/dist/src/server/components/server_provider.js +15 -23
  120. package/dist/src/server/components/server_provider_static.d.ts +4 -3
  121. package/dist/src/server/components/server_provider_static.js +12 -24
  122. package/dist/src/server/functions/geo.d.ts +1 -8
  123. package/dist/src/server/functions/geo.js +1 -223
  124. package/dist/src/server/functions/get_user_locale.d.ts +1 -3
  125. package/dist/src/server/functions/get_user_locale.js +1 -38
  126. package/dist/src/server/functions/locale_static_params.d.ts +1 -3
  127. package/dist/src/server/functions/locale_static_params.js +1 -4
  128. package/dist/src/server/functions/server.d.ts +1 -8
  129. package/dist/src/server/functions/server.js +1 -67
  130. package/dist/src/server/functions/use_functions.d.ts +1 -6
  131. package/dist/src/server/functions/use_functions.js +1 -30
  132. package/dist/src/theme_switcher/components/theme_switcher.d.ts +2 -5
  133. package/dist/src/theme_switcher/components/theme_switcher.js +2 -16
  134. package/dist/src/types/index.d.ts +1 -1
  135. package/dist/src/types/index.js +1 -1
  136. package/dist/src/types/types.d.ts +8 -158
  137. package/dist/src/types/types.js +2 -3
  138. package/dist/src/vite/index.d.ts +3 -1
  139. package/dist/src/vite/index.js +3 -1
  140. package/dist/src/vite/plugin.d.ts +2 -0
  141. package/dist/src/vite/plugin.js +8 -0
  142. package/dist/src/vite/static_not_found_no_store.d.ts +10 -0
  143. package/dist/src/vite/static_not_found_no_store.js +19 -0
  144. package/dist/src/vite/tailwind_sources_plugin.d.ts +8 -0
  145. package/dist/src/vite/tailwind_sources_plugin.js +58 -0
  146. package/dist/src/vite/vinext_route_wiring_fix.d.ts +8 -0
  147. package/dist/src/vite/vinext_route_wiring_fix.js +85 -3
  148. package/package.json +10 -3
  149. package/dist/src/firebase_auth/client/auth_user_cache.d.ts +0 -4
  150. package/dist/src/firebase_auth/client/auth_user_cache.js +0 -12
  151. package/dist/src/firebase_auth/client/auth_user_context.d.ts +0 -10
  152. package/dist/src/firebase_auth/client/auth_user_context.js +0 -4
  153. package/dist/src/firebase_auth/decode_jwt_payload.d.ts +0 -5
  154. package/dist/src/firebase_auth/decode_jwt_payload.js +0 -20
  155. package/dist/src/firebase_auth/error_messages/default_messages.en.d.ts +0 -1
  156. package/dist/src/firebase_auth/error_messages/default_messages.en.js +0 -14
  157. package/dist/src/firebase_auth/error_messages/firebase_auth_error_helper.d.ts +0 -1
  158. package/dist/src/firebase_auth/error_messages/firebase_auth_error_helper.js +0 -37
  159. package/dist/src/firebase_auth/is_whitelisted.d.ts +0 -1
  160. package/dist/src/firebase_auth/is_whitelisted.js +0 -5
  161. package/dist/src/firebase_auth/preserve_redirect_query.d.ts +0 -2
  162. package/dist/src/firebase_auth/preserve_redirect_query.js +0 -9
  163. package/dist/src/firebase_auth/require_config.d.ts +0 -2
  164. package/dist/src/firebase_auth/require_config.js +0 -7
  165. package/dist/src/firebase_auth/server/clear_session_action.d.ts +0 -1
  166. package/dist/src/firebase_auth/server/clear_session_action.js +0 -14
  167. package/dist/src/firebase_auth/server/firebase_server.d.ts +0 -6
  168. package/dist/src/firebase_auth/server/firebase_server.js +0 -92
  169. package/dist/src/firebase_auth/server/mint_server_app_check_token.d.ts +0 -5
  170. package/dist/src/firebase_auth/server/mint_server_app_check_token.js +0 -84
  171. package/dist/src/firebase_auth/server/sign_custom_token_remote.d.ts +0 -5
  172. package/dist/src/firebase_auth/server/sign_custom_token_remote.js +0 -26
  173. package/dist/src/firebase_auth_check/check_firebase_auth_config.d.ts +0 -34
  174. package/dist/src/firebase_auth_check/check_firebase_auth_config.js +0 -606
  175. package/dist/src/firebase_auth_check/load_resolved_firebase_auth.d.ts +0 -9
  176. package/dist/src/firebase_auth_check/load_resolved_firebase_auth.js +0 -64
  177. package/dist/src/theme_switcher/components/icons.d.ts +0 -6
  178. package/dist/src/theme_switcher/components/icons.js +0 -7
  179. package/dist/src/theme_switcher/components/theme_switcher_button.d.ts +0 -6
  180. package/dist/src/theme_switcher/components/theme_switcher_button.js +0 -24
@@ -1,175 +1 @@
1
- import ts from "typescript";
2
- const HOOK_MODULES = new Set(["cloudflare-next-intl/use", "cloudflare-next-intl/client", "cloudflare-next-intl"]);
3
- function topLevel(ns) {
4
- return ns.split(".")[0];
5
- }
6
- function literalsOfType(node, sf, aliases) {
7
- if (!node)
8
- return null;
9
- if (ts.isLiteralTypeNode(node) && ts.isStringLiteral(node.literal))
10
- return [node.literal.text];
11
- if (ts.isUnionTypeNode(node)) {
12
- const out = [];
13
- for (const t of node.types) {
14
- const r = literalsOfType(t, sf, aliases);
15
- if (!r)
16
- return null;
17
- out.push(...r);
18
- }
19
- return out;
20
- }
21
- if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName))
22
- return literalsOfType(aliases.get(node.typeName.text), sf, aliases);
23
- return null;
24
- }
25
- function componentName(fn) {
26
- if ((ts.isFunctionDeclaration(fn) || ts.isFunctionExpression(fn)) && fn.name)
27
- return fn.name.text;
28
- if ((ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) && ts.isVariableDeclaration(fn.parent) && ts.isIdentifier(fn.parent.name))
29
- return fn.parent.name.text;
30
- return null;
31
- }
32
- function propOf(arg, propParams) {
33
- if (ts.isIdentifier(arg)) {
34
- const p = propParams.get(arg.text);
35
- return p ?? null;
36
- }
37
- if (ts.isTemplateExpression(arg) && arg.head.text === "" && ts.isIdentifier(arg.templateSpans[0].expression)) {
38
- const p = propParams.get(arg.templateSpans[0].expression.text);
39
- return p ?? null;
40
- }
41
- return null;
42
- }
43
- export function findJsxPropValues(file, code, component, prop) {
44
- if (!code.includes(`<${component}`))
45
- return [];
46
- const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
47
- const values = [];
48
- let unresolved = false;
49
- const visit = (node) => {
50
- if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && node.tagName.getText() === component) {
51
- let value = null;
52
- for (const attr of node.attributes.properties) {
53
- if (ts.isJsxSpreadAttribute(attr)) {
54
- value = null;
55
- break;
56
- }
57
- if (attr.name.getText() !== prop)
58
- continue;
59
- const init = attr.initializer;
60
- if (init && ts.isStringLiteral(init))
61
- value = init.text;
62
- else if (init && ts.isJsxExpression(init) && init.expression && (ts.isStringLiteral(init.expression) || ts.isNoSubstitutionTemplateLiteral(init.expression)))
63
- value = init.expression.text;
64
- }
65
- if (value === null)
66
- unresolved = true;
67
- else
68
- values.push(value);
69
- }
70
- ts.forEachChild(node, visit);
71
- };
72
- visit(sf);
73
- return unresolved ? null : values;
74
- }
75
- export function scanFile(file, code) {
76
- const result = { namespaces: [], dynamicCalls: [], usesRoot: false };
77
- if (!code.includes("useTranslations"))
78
- return result;
79
- const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
80
- const hookNames = new Set();
81
- const consts = new Map();
82
- const typeAliases = new Map();
83
- const paramTypes = new Map();
84
- const propParams = new Map();
85
- const collect = (node) => {
86
- if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && HOOK_MODULES.has(node.moduleSpecifier.text)) {
87
- const named = node.importClause?.namedBindings;
88
- if (named && ts.isNamedImports(named)) {
89
- for (const el of named.elements)
90
- if ((el.propertyName ?? el.name).text === "useTranslations")
91
- hookNames.add(el.name.text);
92
- }
93
- }
94
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer)
95
- consts.set(node.name.text, node.initializer);
96
- if (ts.isTypeAliasDeclaration(node))
97
- typeAliases.set(node.name.text, node.type);
98
- if (ts.isParameter(node) && node.type) {
99
- if (ts.isIdentifier(node.name))
100
- paramTypes.set(node.name.text, node.type);
101
- const component = componentName(node.parent);
102
- if (component && ts.isObjectBindingPattern(node.name)) {
103
- for (const el of node.name.elements) {
104
- if (!ts.isIdentifier(el.name))
105
- continue;
106
- const key = (el.propertyName && ts.isIdentifier(el.propertyName) ? el.propertyName : el.name).text;
107
- propParams.set(el.name.text, { component, name: key });
108
- }
109
- }
110
- if (ts.isObjectBindingPattern(node.name) && ts.isTypeLiteralNode(node.type)) {
111
- for (const el of node.name.elements) {
112
- if (!ts.isIdentifier(el.name))
113
- continue;
114
- const key = (el.propertyName && ts.isIdentifier(el.propertyName) ? el.propertyName : el.name).text;
115
- const member = node.type.members.find((m) => ts.isPropertySignature(m) && ts.isIdentifier(m.name) && m.name.text === key);
116
- if (member?.type)
117
- paramTypes.set(el.name.text, member.type);
118
- }
119
- }
120
- }
121
- ts.forEachChild(node, collect);
122
- };
123
- collect(sf);
124
- if (hookNames.size === 0)
125
- return result;
126
- const resolve = (expr, depth = 0) => {
127
- if (depth > 5)
128
- return null;
129
- if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr))
130
- return [expr.text];
131
- if (ts.isTemplateExpression(expr) && expr.head.text.includes(".")) {
132
- const top = expr.head.text.split(".")[0];
133
- if (top)
134
- return [top];
135
- }
136
- if (ts.isParenthesizedExpression(expr) || ts.isAsExpression(expr))
137
- return resolve(expr.expression, depth + 1);
138
- if (ts.isConditionalExpression(expr)) {
139
- const a = resolve(expr.whenTrue, depth + 1);
140
- const b = resolve(expr.whenFalse, depth + 1);
141
- return a && b ? [...a, ...b] : null;
142
- }
143
- if (ts.isIdentifier(expr)) {
144
- const init = consts.get(expr.text);
145
- if (init)
146
- return resolve(init, depth + 1);
147
- return literalsOfType(paramTypes.get(expr.text), sf, typeAliases);
148
- }
149
- return null;
150
- };
151
- const found = new Set();
152
- const visit = (node) => {
153
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && hookNames.has(node.expression.text)) {
154
- const arg = node.arguments[0];
155
- if (!arg)
156
- result.usesRoot = true;
157
- else {
158
- const values = resolve(arg);
159
- if (values)
160
- values.forEach((v) => found.add(topLevel(v)));
161
- else {
162
- const call = { file, line: sf.getLineAndCharacterOfPosition(arg.getStart()).line + 1, text: arg.getText() };
163
- const prop = propOf(arg, propParams);
164
- if (prop)
165
- call.prop = prop;
166
- result.dynamicCalls.push(call);
167
- }
168
- }
169
- }
170
- ts.forEachChild(node, visit);
171
- };
172
- visit(sf);
173
- result.namespaces = [...found];
174
- return result;
175
- }
1
+ export * from "cloudflare-next-intl-intl/internal/scanFile";
@@ -1,16 +1 @@
1
- import { matchesNamespacePattern } from "./match_namespace.js";
2
- import { type DynamicCall } from "./scan_file.js";
3
- export { matchesNamespacePattern };
4
- export interface ScanProjectOptions {
5
- root: string;
6
- dirs?: string[];
7
- packages?: string[];
8
- fallbackNamespaces?: string[];
9
- onDynamic?: "all" | "fallback";
10
- }
11
- export interface ClientMessagesManifest {
12
- namespaces: string[] | true;
13
- dynamicCalls: DynamicCall[];
14
- scannedFiles: number;
15
- }
16
- export declare function scanProject(opts: ScanProjectOptions): ClientMessagesManifest;
1
+ export * from "cloudflare-next-intl-intl/internal/scanProject";
@@ -1,67 +1 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { matchesNamespacePattern } from "./match_namespace.js";
4
- import { findJsxPropValues, scanFile } from "./scan_file.js";
5
- export { matchesNamespacePattern };
6
- const EXT = /\.(tsx?|jsx?|mjs)$/;
7
- const SKIP_DIRS = new Set(["node_modules", "dist", ".next", ".git"]);
8
- function walk(dir, out, skipNodeModules) {
9
- for (const name of readdirSync(dir)) {
10
- const full = join(dir, name);
11
- if (statSync(full).isDirectory()) {
12
- if (SKIP_DIRS.has(name) && (skipNodeModules || name !== "dist"))
13
- continue;
14
- walk(full, out, skipNodeModules);
15
- }
16
- else if (EXT.test(name) && !/\.(test|spec|bench)\./.test(name) && !name.endsWith(".d.ts"))
17
- out.push(full);
18
- }
19
- }
20
- export function scanProject(opts) {
21
- const files = [];
22
- for (const d of opts.dirs ?? ["src", "app", "components", "pages", "shared", "modules", "lib"]) {
23
- const full = join(opts.root, d);
24
- if (existsSync(full))
25
- walk(full, files, true);
26
- }
27
- const found = new Set(opts.fallbackNamespaces ?? []);
28
- for (const pkg of opts.packages ?? []) {
29
- const pkgDir = join(opts.root, "node_modules", pkg);
30
- const pjPath = join(pkgDir, "package.json");
31
- if (!existsSync(pjPath))
32
- continue;
33
- const pj = JSON.parse(readFileSync(pjPath, "utf8"));
34
- if (Array.isArray(pj.i18n?.namespaces))
35
- pj.i18n.namespaces.forEach((n) => found.add(n));
36
- else
37
- walk(pkgDir, files, false);
38
- }
39
- let dynamicCalls = [];
40
- let usesRoot = false;
41
- const sources = new Map();
42
- for (const f of files) {
43
- const code = readFileSync(f, "utf8");
44
- sources.set(f, code);
45
- const r = scanFile(f, code);
46
- r.namespaces.forEach((n) => found.add(n));
47
- dynamicCalls.push(...r.dynamicCalls);
48
- usesRoot || (usesRoot = r.usesRoot);
49
- }
50
- dynamicCalls = dynamicCalls.filter((call) => {
51
- if (!call.prop)
52
- return true;
53
- const values = [];
54
- for (const [f, code] of sources) {
55
- const v = findJsxPropValues(f, code, call.prop.component, call.prop.name);
56
- if (v === null)
57
- return true;
58
- values.push(...v);
59
- }
60
- if (values.length === 0)
61
- return true;
62
- values.forEach((v) => found.add(v.split(".")[0]));
63
- return false;
64
- });
65
- const sendAll = usesRoot || (dynamicCalls.length > 0 && (opts.onDynamic ?? "all") === "all");
66
- return { namespaces: sendAll ? true : [...found].sort(), dynamicCalls, scannedFiles: files.length };
67
- }
1
+ export * from "cloudflare-next-intl-intl/internal/scanProject";
@@ -1,7 +1,4 @@
1
- export declare const localeCookieName = "__user_locale_key__";
2
- export declare const isBotCookieKey = "__is_bot_key__";
3
- export declare const isDarkCookieKey = "__is_dark_key__";
1
+ export * from 'cloudflare-next-intl-intl/internal/cookieKey';
2
+ export { isDarkCookieKey } from 'cloudflare-next-intl-theme/cookieKey';
4
3
  export declare const cookieConsentCookieKey = "__cookie_consent_key__";
5
4
  export declare const privacyPolicyDateCookieKey = "__privacy_policy_date_key__";
6
- export declare const countryCookieKey = "__cf_country__";
7
- export declare const timezoneCookieKey = "__cf_timezone__";
@@ -1,7 +1,4 @@
1
- export const localeCookieName = '__user_locale_key__';
2
- export const isBotCookieKey = '__is_bot_key__';
3
- export const isDarkCookieKey = '__is_dark_key__';
1
+ export * from 'cloudflare-next-intl-intl/internal/cookieKey';
2
+ export { isDarkCookieKey } from 'cloudflare-next-intl-theme/cookieKey';
4
3
  export const cookieConsentCookieKey = '__cookie_consent_key__';
5
4
  export const privacyPolicyDateCookieKey = '__privacy_policy_date_key__';
6
- export const countryCookieKey = '__cf_country__';
7
- export const timezoneCookieKey = '__cf_timezone__';
@@ -1,36 +1,18 @@
1
- import { setStaleDeployPatterns } from '../error_handling/is_stale_deploy_error.js';
2
- const FIREBASE_AUTH_PATH_FIELDS = [
3
- 'redirectAuthPath',
4
- 'homePath',
5
- 'verifyEmailPath',
6
- 'resetPasswordPath',
7
- 'recoverEmailPath',
8
- 'actionLinkPath',
9
- ];
10
- function normalizeFirebaseAuthPaths(config) {
11
- const fa = config.firebaseAuth;
12
- if (!fa)
13
- return config;
14
- let changed = false;
15
- const normalizedFa = { ...fa };
16
- for (const field of FIREBASE_AUTH_PATH_FIELDS) {
17
- const value = normalizedFa[field];
18
- if (typeof value === 'string' && value !== '' && !value.startsWith('/')) {
19
- console.warn(`[cloudflare-next-intl] firebaseAuth.${field} ("${value}") is missing its leading "/" — ` +
20
- `auto-corrected to "/${value}". Paths are compared against the URL pathname (always ` +
21
- `"/"-prefixed), so without this fix the check would never match and silently disable the ` +
22
- `redirect/exemption for this path. Fix your config to avoid this warning.`);
23
- normalizedFa[field] = `/${value}`;
24
- changed = true;
25
- }
26
- }
27
- if (!changed)
28
- return config;
29
- return { ...config, firebaseAuth: normalizedFa };
30
- }
1
+ import { setIntlConfig as coreSetIntlConfig } from 'cloudflare-next-intl-intl/setIntlConfig';
2
+ import { normalizeFirebaseAuthConfig } from 'cloudflare-next-intl-auth/normalizeConfig';
3
+ import reportError from 'cloudflare-next-intl-errors/internal/reportError';
4
+ import { setStaleDeployPatterns } from 'cloudflare-next-intl-errors/isStaleDeployError';
31
5
  export function setIntlConfig(config) {
6
+ const fa = config.firebaseAuth;
7
+ const normalizedFa = normalizeFirebaseAuthConfig(fa);
8
+ const resolvedConfig = normalizedFa !== fa ? { ...config, firebaseAuth: normalizedFa } : config;
32
9
  if (config.errorHandling?.staleDeployPatterns) {
33
10
  setStaleDeployPatterns(config.errorHandling.staleDeployPatterns);
34
11
  }
35
- return normalizeFirebaseAuthPaths(config);
12
+ const onError = config.onError ?? ((error, source) => {
13
+ void reportError({ errorHandling: config.errorHandling, generate: config.generate }, { error, classOrMethodName: source });
14
+ });
15
+ const finalConfig = { ...resolvedConfig, onError };
16
+ coreSetIntlConfig(finalConfig);
17
+ return finalConfig;
36
18
  }
@@ -4,12 +4,17 @@ function getConfig() {
4
4
  if (value) {
5
5
  return intlConfig;
6
6
  }
7
- else {
8
- throw Error('cloudflare-next-intl: the `@intl-config` alias is not set. ' +
9
- 'Create a config file (e.g. `src/i18n/intl_config.ts`) that default-exports ' +
10
- 'your `RoutingConfig` (see `setIntlConfig`), then point `@intl-config` at it via ' +
11
- 'your bundler/tsconfig path alias — see the README "Setup" section, step 2.');
12
- }
7
+ throw Error('cloudflare-next-intl: the `@intl-config` alias is not set. ' +
8
+ 'Create a config file (e.g. `src/i18n/intl_config.ts`) that default-exports ' +
9
+ 'your `RoutingConfig` (see `setIntlConfig`), then point `@intl-config` at it via ' +
10
+ 'your bundler/tsconfig path alias — see the README "Setup" section, step 2.');
13
11
  }
14
- const config = getConfig();
12
+ const config = new Proxy({}, {
13
+ get(target, prop) {
14
+ if (prop === 'then' || prop === 'default' || typeof prop === 'symbol') {
15
+ return Reflect.get(target, prop);
16
+ }
17
+ return getConfig()[prop];
18
+ },
19
+ });
15
20
  export default config;
@@ -1,8 +1,2 @@
1
- import type { MetadataRoute } from 'next';
2
- import type { IntlSitemap } from '../types/types.js';
3
- declare function generateIntlSitemapIml({ intlSitemap, url }: {
4
- intlSitemap: IntlSitemap[];
5
- url: string;
6
- }): MetadataRoute.Sitemap;
7
- declare const generateIntlSitemap: typeof generateIntlSitemapIml;
8
- export default generateIntlSitemap;
1
+ export * from 'cloudflare-next-intl-intl/internal/intlSitemap';
2
+ export { default } from 'cloudflare-next-intl-intl/internal/intlSitemap';
@@ -1,28 +1,2 @@
1
- import { languages } from '../general/metadata.js';
2
- import config from './intl_config.js';
3
- import { cache } from 'react';
4
- function generateAlternates(url, link) {
5
- return {
6
- languages: languages(url, link),
7
- };
8
- }
9
- function generateIntlSitemapIml({ intlSitemap, url }) {
10
- const sitemap = [];
11
- for (const customRoute of intlSitemap) {
12
- const linkPart = customRoute.link == '/' ? undefined : customRoute.link;
13
- const alternates = generateAlternates(url, linkPart);
14
- for (const locale of config.locales) {
15
- const localeValue = locale === config.defaultLocale ? '' : `/${locale}`;
16
- const localeUrl = url + localeValue;
17
- sitemap.push({
18
- ...customRoute,
19
- alternates: alternates,
20
- url: localeUrl + (linkPart ?? ''),
21
- });
22
- }
23
- }
24
- sitemap.sort((a, b) => (a.url < b.url ? -1 : a.url > b.url ? 1 : 0));
25
- return sitemap;
26
- }
27
- const generateIntlSitemap = cache(generateIntlSitemapIml);
28
- export default generateIntlSitemap;
1
+ export * from 'cloudflare-next-intl-intl/internal/intlSitemap';
2
+ export { default } from 'cloudflare-next-intl-intl/internal/intlSitemap';
@@ -1,8 +1,11 @@
1
- import type { NextRequest } from 'next/server.js';
2
- import { NextResponse } from 'next/server.js';
3
- import type { MiddlewareCustomHandler } from '../types/types.js';
4
- export declare const localesSet: Set<string>;
5
- export default function intlMiddleware(request: NextRequest, options?: {
1
+ import { createIntlMiddleware, localesSet, type IntlMiddlewareContext, type IntlMiddlewareHook } from 'cloudflare-next-intl-intl/middleware';
2
+ import type { NextResponse } from 'next/server.js';
3
+ import type { MiddlewareCustomHandler } from 'cloudflare-next-intl-intl/types';
4
+ export declare const defaultAfterResponse: IntlMiddlewareHook;
5
+ export { createIntlMiddleware, localesSet, type IntlMiddlewareContext, type IntlMiddlewareHook, };
6
+ export type IntlMiddleware = (request: any, options?: {
6
7
  middlewareHandler?: MiddlewareCustomHandler;
7
8
  runHandlerOnRedirect?: boolean;
8
- }): Promise<NextResponse<unknown>>;
9
+ }) => Promise<NextResponse>;
10
+ declare const intlMiddleware: IntlMiddleware;
11
+ export default intlMiddleware;
@@ -1,177 +1,15 @@
1
- import { NextResponse } from 'next/server.js';
2
- import { languageDetecotr } from '../server/functions/get_user_locale.js';
1
+ import { createIntlMiddleware, localesSet, } from 'cloudflare-next-intl-intl/middleware';
3
2
  import config from './intl_config.js';
4
- import { countryCookieKey, isBotCookieKey, localeCookieName, timezoneCookieKey } from './cookie_key.js';
5
- import { cache } from 'react';
6
- import reportError from '../error_handling/report_error.js';
7
- import { defaultCountryHeaderNames, defaultTimezoneHeaderNames } from '../server/functions/geo.js';
8
- const sameSite = false;
9
- const defaultCookieOption = {
10
- path: '/',
11
- maxAge: 2592000,
12
- httpOnly: false,
13
- secure: false,
14
- sameSite: sameSite,
15
- };
16
- let userAgentModule;
17
- async function getIsBotValue(userAgent) {
18
- if (userAgent === null)
19
- return false;
20
- if (!userAgentModule) {
21
- userAgentModule = await import('next/dist/server/web/spec-extension/user-agent');
22
- }
23
- return userAgentModule.isBot(userAgent ?? '');
24
- }
25
- const getIsBotValueCache = cache(getIsBotValue);
26
- export const localesSet = new Set(config.locales);
27
3
  let updateSessionModule;
28
- function getFirstHeaderValue(headers, names) {
29
- for (const name of names) {
30
- const value = headers.get(name);
31
- if (value)
32
- return value;
33
- }
34
- return undefined;
35
- }
36
- export default async function intlMiddleware(request, options) {
37
- try {
38
- let initialChosenLocale;
39
- const existingLocaleCookie = request.cookies.get(localeCookieName)?.value;
40
- let isSEOBot = undefined;
41
- if (existingLocaleCookie && localesSet.has(existingLocaleCookie)) {
42
- initialChosenLocale = existingLocaleCookie;
43
- }
44
- else {
45
- const userAgent = request.headers.get('user-agent');
46
- isSEOBot = await getIsBotValueCache(userAgent);
47
- initialChosenLocale = isSEOBot ? config.defaultLocale : languageDetecotr(request.headers.get('accept-language'));
48
- }
49
- const { pathname, search, hash } = request.nextUrl;
50
- let urlLocale;
51
- let pathWithoutLocale;
52
- const segmentStart = pathname.charCodeAt(0) === 47 ? 1 : 0;
53
- let segmentEnd = pathname.indexOf('/', segmentStart);
54
- if (segmentEnd === -1)
55
- segmentEnd = pathname.length;
56
- const languageValue = pathname.slice(segmentStart, segmentEnd);
57
- if (languageValue && localesSet.has(languageValue)) {
58
- urlLocale = languageValue;
59
- let rest = pathname.slice(segmentEnd);
60
- if (rest.endsWith('/'))
61
- rest = rest.slice(0, -1);
62
- if (rest.includes('//')) {
63
- rest = '/' + rest.split('/').filter(Boolean).join('/');
64
- }
65
- pathWithoutLocale = rest || '/';
66
- }
67
- else {
68
- pathWithoutLocale = pathname;
69
- }
70
- const effectiveLocaleForRequest = urlLocale ?? initialChosenLocale;
71
- const cf = request.cf;
72
- const countryHeaderNames = config.cookieConsent?.countryHeaderNames
73
- ?? config.generate?.countryHeaderNames
74
- ?? defaultCountryHeaderNames;
75
- const timezoneHeaderNames = config.generate?.timezoneHeaderNames
76
- ?? defaultTimezoneHeaderNames;
77
- const countryCookieName = config.cookieConsent?.countryCookieName
78
- ?? config.generate?.countryCookieName
79
- ?? countryCookieKey;
80
- const timezoneCookieName = config.generate?.timezoneCookieName
81
- ?? timezoneCookieKey;
82
- const country = cf?.country || getFirstHeaderValue(request.headers, countryHeaderNames);
83
- const timezone = cf?.timezone || getFirstHeaderValue(request.headers, timezoneHeaderNames);
84
- const requestHeaders = new Headers(request.headers);
85
- requestHeaders.set('x-pathname', pathWithoutLocale);
86
- requestHeaders.set('x-search', search);
87
- if (country) {
88
- requestHeaders.set('x-cf-country', country);
89
- }
90
- if (timezone) {
91
- requestHeaders.set('x-cf-timezone', timezone);
92
- }
93
- let response;
94
- let isRedirect = false;
95
- let rewriteUrl;
96
- let redirectUrl;
97
- if (!urlLocale) {
98
- const targetPath = `/${effectiveLocaleForRequest}${pathWithoutLocale === '/' ? '' : pathWithoutLocale}`;
99
- const localeUrl = new URL(`${targetPath}${search}${hash}`, request.url);
100
- if (initialChosenLocale === config.defaultLocale) {
101
- rewriteUrl = localeUrl;
102
- response = NextResponse.rewrite(localeUrl, { request: { headers: requestHeaders } });
103
- }
104
- else {
105
- isRedirect = true;
106
- redirectUrl = localeUrl;
107
- response = NextResponse.redirect(localeUrl, request);
108
- }
4
+ export const defaultAfterResponse = async (response, ctx) => {
5
+ if (config.firebaseAuth && config.firebaseAuth.middlewareEnabled !== false) {
6
+ if (!updateSessionModule) {
7
+ updateSessionModule = await import('../firebase_auth/middleware/update_session.js');
109
8
  }
110
- else {
111
- response = NextResponse.next({
112
- request: {
113
- headers: requestHeaders,
114
- },
115
- });
116
- }
117
- if (options?.middlewareHandler && (!isRedirect || options.runHandlerOnRedirect)) {
118
- const customResponse = await options.middlewareHandler(effectiveLocaleForRequest, rewriteUrl, redirectUrl);
119
- if (customResponse) {
120
- response = customResponse;
121
- }
122
- }
123
- if (!existingLocaleCookie ||
124
- existingLocaleCookie !== effectiveLocaleForRequest) {
125
- response.cookies.set(localeCookieName, effectiveLocaleForRequest, defaultCookieOption);
126
- if (isSEOBot !== undefined) {
127
- response.cookies.set(isBotCookieKey, isSEOBot.toString(), {
128
- ...defaultCookieOption,
129
- maxAge: 31536000,
130
- secure: process.env.NODE_ENV === 'production',
131
- httpOnly: true,
132
- });
133
- }
134
- }
135
- response.headers.set('Content-Language', effectiveLocaleForRequest);
136
- response.headers.set('x-pathname', pathWithoutLocale);
137
- response.headers.set('x-search', search);
138
- if (country) {
139
- response.headers.set('x-cf-country', country);
140
- response.cookies.set(countryCookieName, country, {
141
- path: '/',
142
- maxAge: 86400,
143
- httpOnly: false,
144
- secure: process.env.NODE_ENV === 'production',
145
- sameSite: 'lax',
146
- });
147
- }
148
- if (timezone) {
149
- response.headers.set('x-cf-timezone', timezone);
150
- response.cookies.set(timezoneCookieName, timezone, {
151
- path: '/',
152
- maxAge: 86400,
153
- httpOnly: false,
154
- secure: process.env.NODE_ENV === 'production',
155
- sameSite: 'lax',
156
- });
157
- }
158
- if (!isRedirect && config.firebaseAuth && config.firebaseAuth.middlewareEnabled !== false) {
159
- if (!updateSessionModule) {
160
- updateSessionModule = await import('../firebase_auth/middleware/update_session.js');
161
- }
162
- response = await updateSessionModule.default(request, response, effectiveLocaleForRequest, (refreshedRequest) => rewriteUrl
163
- ? NextResponse.rewrite(rewriteUrl, { request: refreshedRequest })
164
- : NextResponse.next({ request: refreshedRequest }));
165
- }
166
- return response;
9
+ return updateSessionModule.default(ctx.request, response, ctx.locale, ctx.next);
167
10
  }
168
- catch (e) {
169
- void reportError({ errorHandling: config.errorHandling, generate: config.generate }, {
170
- error: e,
171
- classOrMethodName: 'intlMiddleware',
172
- });
173
- return NextResponse.next({
174
- request,
175
- });
176
- }
177
- }
11
+ return response;
12
+ };
13
+ export { createIntlMiddleware, localesSet, };
14
+ const intlMiddleware = createIntlMiddleware({ afterResponse: defaultAfterResponse });
15
+ export default intlMiddleware;
@@ -1,6 +1,8 @@
1
1
  import type { CookieConsentContextType } from '../types.js';
2
+ import type { CookieConsentRoutingConfig } from '../../types/types.js';
2
3
  export declare const CookieConsentContext: import("react").Context<CookieConsentContextType | null>;
3
- export default function CookieConsentProvider({ requiresConsent: requiresConsentProp, children }: {
4
+ export default function CookieConsentProvider({ requiresConsent: requiresConsentProp, cookieConsentConfig, children, }: {
4
5
  requiresConsent?: boolean;
6
+ cookieConsentConfig?: CookieConsentRoutingConfig;
5
7
  children: React.ReactNode;
6
8
  }): React.ReactElement;
@@ -17,9 +17,9 @@ function parseConsent(raw) {
17
17
  return null;
18
18
  }
19
19
  const defaultGdprCountriesSet = new Set(defaultGdprCountries);
20
- export default function CookieConsentProvider({ requiresConsent: requiresConsentProp = true, children }) {
20
+ export default function CookieConsentProvider({ requiresConsent: requiresConsentProp = true, cookieConsentConfig, children, }) {
21
21
  const { consentCookieName, dateCookieName, maxAge, policyDate, privacyPolicyPath, showPrivacyPolicy, gdprCountries } = useMemo(() => {
22
- const cc = requireCookieConsentConfig(config.cookieConsent);
22
+ const cc = requireCookieConsentConfig(cookieConsentConfig ?? config.cookieConsent);
23
23
  return {
24
24
  consentCookieName: cc.consentCookieName ?? cookieConsentCookieKey,
25
25
  dateCookieName: cc.privacyPolicyDateCookieName ?? privacyPolicyDateCookieKey,
@@ -29,7 +29,7 @@ export default function CookieConsentProvider({ requiresConsent: requiresConsent
29
29
  showPrivacyPolicy: cc.showPrivacyPolicy ?? true,
30
30
  gdprCountries: cc.gdprCountries,
31
31
  };
32
- }, []);
32
+ }, [cookieConsentConfig]);
33
33
  const [consent, setConsentState] = useState(null);
34
34
  const [privacyPolicyUpdated, setPrivacyPolicyUpdated] = useState(false);
35
35
  const [isMounted, setIsMounted] = useState(false);
@@ -17,8 +17,10 @@ export default async function resolveDbConfig(dbOverride) {
17
17
  let base = { locales: [], defaultLocale: '' };
18
18
  try {
19
19
  base = (await import('../config/intl_config.js')).default;
20
+ void base.locales;
20
21
  }
21
22
  catch {
23
+ base = { locales: [], defaultLocale: '' };
22
24
  }
23
25
  const db = dbOverride ?? base.db;
24
26
  return {