@elench/testkit 0.1.63 → 0.1.65

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 (90) hide show
  1. package/lib/coverage/backend-discovery.mjs +6 -30
  2. package/lib/coverage/evidence.mjs +15 -3
  3. package/lib/coverage/evidence.test.mjs +13 -4
  4. package/lib/coverage/fs-walk.mjs +2 -2
  5. package/lib/coverage/graph-builder.mjs +23 -24
  6. package/lib/coverage/next-ir-to-graph.mjs +240 -0
  7. package/node_modules/@elench/next-analysis/package.json +14 -0
  8. package/node_modules/@elench/next-analysis/src/api-routes.mjs +81 -0
  9. package/node_modules/@elench/next-analysis/src/api-routes.test.mjs +22 -0
  10. package/node_modules/@elench/next-analysis/src/app-root.mjs +7 -0
  11. package/node_modules/@elench/next-analysis/src/backend-links.mjs +31 -0
  12. package/node_modules/@elench/next-analysis/src/index.mjs +21 -0
  13. package/node_modules/@elench/next-analysis/src/pages.mjs +68 -0
  14. package/node_modules/@elench/next-analysis/src/project.mjs +94 -0
  15. package/node_modules/@elench/next-analysis/src/project.test.mjs +35 -0
  16. package/node_modules/@elench/next-analysis/src/route-tree.mjs +621 -0
  17. package/node_modules/@elench/next-analysis/src/routes.mjs +41 -0
  18. package/node_modules/@elench/next-analysis/src/routes.test.mjs +25 -0
  19. package/node_modules/@elench/next-analysis/src/server-actions.mjs +53 -0
  20. package/node_modules/@elench/next-analysis/src/server-actions.test.mjs +37 -0
  21. package/node_modules/@elench/next-analysis/src/shared.mjs +209 -0
  22. package/node_modules/@elench/next-analysis/src/swc.mjs +388 -0
  23. package/node_modules/@elench/testkit-bridge/package.json +2 -2
  24. package/node_modules/@elench/testkit-protocol/package.json +1 -1
  25. package/node_modules/@elench/ts-analysis/package.json +10 -0
  26. package/node_modules/@elench/ts-analysis/src/callables.mjs +135 -0
  27. package/node_modules/@elench/ts-analysis/src/callables.test.mjs +55 -0
  28. package/node_modules/@elench/ts-analysis/src/exports.mjs +69 -0
  29. package/node_modules/@elench/ts-analysis/src/exports.test.mjs +50 -0
  30. package/node_modules/@elench/ts-analysis/src/index.mjs +14 -0
  31. package/node_modules/@elench/ts-analysis/src/jsx.mjs +69 -0
  32. package/node_modules/@elench/ts-analysis/src/jsx.test.mjs +43 -0
  33. package/node_modules/@elench/ts-analysis/src/project.mjs +100 -0
  34. package/node_modules/@elench/ts-analysis/src/project.test.mjs +54 -0
  35. package/node_modules/@elench/ts-analysis/src/requests.mjs +141 -0
  36. package/node_modules/@elench/ts-analysis/src/requests.test.mjs +35 -0
  37. package/node_modules/@elench/ts-analysis/src/resolution.mjs +53 -0
  38. package/node_modules/@elench/ts-analysis/src/shared.mjs +32 -0
  39. package/node_modules/@elench/ts-analysis/src/syntax.mjs +27 -0
  40. package/node_modules/@next/routing/README.md +91 -0
  41. package/node_modules/@next/routing/dist/__tests__/captures.test.d.ts +1 -0
  42. package/node_modules/@next/routing/dist/__tests__/conditions.test.d.ts +1 -0
  43. package/node_modules/@next/routing/dist/__tests__/dynamic-after-rewrites.test.d.ts +1 -0
  44. package/node_modules/@next/routing/dist/__tests__/i18n-resolve-routes.test.d.ts +1 -0
  45. package/node_modules/@next/routing/dist/__tests__/i18n.test.d.ts +1 -0
  46. package/node_modules/@next/routing/dist/__tests__/middleware.test.d.ts +1 -0
  47. package/node_modules/@next/routing/dist/__tests__/normalize-next-data.test.d.ts +1 -0
  48. package/node_modules/@next/routing/dist/__tests__/redirects.test.d.ts +1 -0
  49. package/node_modules/@next/routing/dist/__tests__/resolve-routes.test.d.ts +1 -0
  50. package/node_modules/@next/routing/dist/__tests__/rewrites.test.d.ts +1 -0
  51. package/node_modules/@next/routing/dist/destination.d.ts +22 -0
  52. package/node_modules/@next/routing/dist/i18n.d.ts +48 -0
  53. package/node_modules/@next/routing/dist/index.d.ts +5 -0
  54. package/node_modules/@next/routing/dist/index.js +1 -0
  55. package/node_modules/@next/routing/dist/matchers.d.ts +12 -0
  56. package/node_modules/@next/routing/dist/middleware.d.ts +12 -0
  57. package/node_modules/@next/routing/dist/next-data.d.ts +10 -0
  58. package/node_modules/@next/routing/dist/resolve-routes.d.ts +2 -0
  59. package/node_modules/@next/routing/dist/types.d.ts +97 -0
  60. package/node_modules/@next/routing/package.json +39 -0
  61. package/node_modules/@swc/core/README.md +100 -0
  62. package/node_modules/@swc/core/Visitor.d.ts +218 -0
  63. package/node_modules/@swc/core/Visitor.js +1399 -0
  64. package/node_modules/@swc/core/binding.d.ts +59 -0
  65. package/node_modules/@swc/core/binding.js +368 -0
  66. package/node_modules/@swc/core/index.d.ts +120 -0
  67. package/node_modules/@swc/core/index.js +443 -0
  68. package/node_modules/@swc/core/package.json +120 -0
  69. package/node_modules/@swc/core/postinstall.js +148 -0
  70. package/node_modules/@swc/core/spack.d.ts +51 -0
  71. package/node_modules/@swc/core/spack.js +87 -0
  72. package/node_modules/@swc/core/util.d.ts +1 -0
  73. package/node_modules/@swc/core/util.js +104 -0
  74. package/node_modules/@swc/core-linux-x64-gnu/README.md +3 -0
  75. package/node_modules/@swc/core-linux-x64-gnu/package.json +46 -0
  76. package/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node +0 -0
  77. package/node_modules/@swc/counter/CHANGELOG.md +7 -0
  78. package/node_modules/@swc/counter/README.md +7 -0
  79. package/node_modules/@swc/counter/index.js +1 -0
  80. package/node_modules/@swc/counter/package.json +27 -0
  81. package/node_modules/@swc/types/LICENSE +201 -0
  82. package/node_modules/@swc/types/README.md +4 -0
  83. package/node_modules/@swc/types/assumptions.d.ts +92 -0
  84. package/node_modules/@swc/types/assumptions.js +2 -0
  85. package/node_modules/@swc/types/index.d.ts +2049 -0
  86. package/node_modules/@swc/types/index.js +2 -0
  87. package/node_modules/@swc/types/package.json +40 -0
  88. package/package.json +7 -3
  89. package/lib/coverage/next-discovery.mjs +0 -205
  90. package/lib/coverage/next-static-analysis.mjs +0 -1047
@@ -0,0 +1,141 @@
1
+ import ts from "typescript";
2
+ import { createSourceFile, extractStringLiteral } from "./syntax.mjs";
3
+
4
+ const HTTP_WRAPPER_METHODS = {
5
+ getJson: "GET",
6
+ postJson: "POST",
7
+ putJson: "PUT",
8
+ patchJson: "PATCH",
9
+ deleteJson: "DELETE",
10
+ };
11
+
12
+ export function extractHttpRequests(content, options = {}) {
13
+ const filePath = options.filePath || "suite.testkit.ts";
14
+ const normalizeRoute = options.normalizeRoute || defaultNormalizeRoute;
15
+ const sourceFile = createSourceFile(filePath, content);
16
+ const requests = [];
17
+
18
+ const visit = (node) => {
19
+ if (ts.isCallExpression(node)) {
20
+ const request = resolveHttpRequestCall(node, { normalizeRoute, dynamicSegmentToken: options.dynamicSegmentToken });
21
+ if (request) requests.push(request);
22
+ }
23
+ ts.forEachChild(node, visit);
24
+ };
25
+
26
+ visit(sourceFile);
27
+ return dedupeRequests(requests);
28
+ }
29
+
30
+ export function extractPlaywrightVisitedRoutes(content, options = {}) {
31
+ const filePath = options.filePath || "suite.pw.testkit.ts";
32
+ const normalizeRoute = options.normalizeRoute || defaultNormalizeRoute;
33
+ const sourceFile = createSourceFile(filePath, content);
34
+ const routes = [];
35
+
36
+ const visit = (node) => {
37
+ if (ts.isCallExpression(node)) {
38
+ const route = resolveGotoRoute(node, { normalizeRoute, dynamicSegmentToken: options.dynamicSegmentToken });
39
+ if (route) routes.push(route);
40
+ }
41
+ ts.forEachChild(node, visit);
42
+ };
43
+
44
+ visit(sourceFile);
45
+ return [...new Set(routes)];
46
+ }
47
+
48
+ export function extractRouteLiteral(node, options = {}) {
49
+ const normalizeRoute = options.normalizeRoute || defaultNormalizeRoute;
50
+ const literal = extractStringLiteral(node, options);
51
+ if (!literal) return null;
52
+ return normalizeRoute(literal.split("?")[0]);
53
+ }
54
+
55
+ function resolveGotoRoute(callExpression, options) {
56
+ const callee = callExpression.expression;
57
+ if (!ts.isPropertyAccessExpression(callee)) return null;
58
+ if (callee.name.text !== "goto") return null;
59
+ const pathArg = callExpression.arguments[0];
60
+ const literal = extractStringLiteral(pathArg, options);
61
+ if (!literal) return null;
62
+ if (/^https?:\/\//u.test(literal)) {
63
+ try {
64
+ const parsed = new URL(literal);
65
+ if (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") {
66
+ return options.normalizeRoute(parsed.pathname.split("?")[0]);
67
+ }
68
+ } catch {
69
+ return null;
70
+ }
71
+ return null;
72
+ }
73
+ return options.normalizeRoute(literal.split("?")[0]);
74
+ }
75
+
76
+ function resolveHttpRequestCall(callExpression, options) {
77
+ const callee = callExpression.expression;
78
+ if (ts.isIdentifier(callee)) {
79
+ if (callee.text === "fetch") {
80
+ const path = extractRouteLiteral(callExpression.arguments[0], options);
81
+ if (!path || !path.startsWith("/api/")) return null;
82
+ return {
83
+ method: extractFetchMethod(callExpression.arguments[1], options) || "GET",
84
+ path,
85
+ confidence: "high",
86
+ };
87
+ }
88
+
89
+ const method = HTTP_WRAPPER_METHODS[callee.text];
90
+ if (method) {
91
+ const path = extractRouteLiteral(callExpression.arguments[0], options);
92
+ if (!path || !path.startsWith("/api/")) return null;
93
+ return { method, path, confidence: "high" };
94
+ }
95
+
96
+ if (callee.text === "rawReq") {
97
+ const methodLiteral = extractStringLiteral(callExpression.arguments[0], options);
98
+ const path = extractRouteLiteral(callExpression.arguments[1], options);
99
+ if (!methodLiteral || !path) return null;
100
+ return { method: methodLiteral.toUpperCase(), path, confidence: "high" };
101
+ }
102
+ }
103
+
104
+ if (ts.isPropertyAccessExpression(callee) && callee.name.text === "rawReq") {
105
+ const methodLiteral = extractStringLiteral(callExpression.arguments[0], options);
106
+ const path = extractRouteLiteral(callExpression.arguments[1], options);
107
+ if (!methodLiteral || !path) return null;
108
+ return { method: methodLiteral.toUpperCase(), path, confidence: "high" };
109
+ }
110
+
111
+ return null;
112
+ }
113
+
114
+ function extractFetchMethod(node, options) {
115
+ if (!node || !ts.isObjectLiteralExpression(node)) return null;
116
+ for (const property of node.properties) {
117
+ if (!ts.isPropertyAssignment(property)) continue;
118
+ if (property.name.getText() !== "method") continue;
119
+ const value = extractStringLiteral(property.initializer, options);
120
+ return value ? value.toUpperCase() : null;
121
+ }
122
+ return null;
123
+ }
124
+
125
+ function dedupeRequests(requests) {
126
+ const seen = new Set();
127
+ return requests.filter((entry) => {
128
+ const key = `${entry.method}:${entry.path}`;
129
+ if (seen.has(key)) return false;
130
+ seen.add(key);
131
+ return true;
132
+ });
133
+ }
134
+
135
+ function defaultNormalizeRoute(value) {
136
+ const trimmed = String(value || "/").trim();
137
+ if (!trimmed || trimmed === "/") return "/";
138
+ const withLeadingSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
139
+ return withLeadingSlash.length > 1 ? withLeadingSlash.replace(/\/+$/u, "") : withLeadingSlash;
140
+ }
141
+
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { DEFAULT_DYNAMIC_SEGMENT_TOKEN } from "./index.mjs";
3
+ import { extractHttpRequests, extractPlaywrightVisitedRoutes } from "./index.mjs";
4
+
5
+ describe("@elench/ts-analysis requests", () => {
6
+ it("extracts HTTP requests from fetch, wrappers, and rawReq", () => {
7
+ const content = `
8
+ await fetch("/api/projects", { method: "post" });
9
+ await getJson("/api/projects/123");
10
+ await rawReq("DELETE", \`/api/projects/\${projectId}\`);
11
+ await fetch("/not-api/projects");
12
+ `;
13
+
14
+ expect(extractHttpRequests(content, { filePath: "suite.int.testkit.ts" })).toEqual([
15
+ { method: "POST", path: "/api/projects", confidence: "high" },
16
+ { method: "GET", path: "/api/projects/123", confidence: "high" },
17
+ { method: "DELETE", path: `/api/projects/${DEFAULT_DYNAMIC_SEGMENT_TOKEN}`, confidence: "high" },
18
+ ]);
19
+ });
20
+
21
+ it("extracts Playwright visited routes", () => {
22
+ const content = `
23
+ await page.goto("/dashboard");
24
+ await page.goto(\`/projects/\${id}\`);
25
+ await this.page.goto("http://localhost:3000/events");
26
+ await page.goto("https://example.com/external");
27
+ `;
28
+
29
+ expect(extractPlaywrightVisitedRoutes(content, { filePath: "suite.pw.testkit.ts" })).toEqual([
30
+ "/dashboard",
31
+ `/projects/${DEFAULT_DYNAMIC_SEGMENT_TOKEN}`,
32
+ "/events",
33
+ ]);
34
+ });
35
+ });
@@ -0,0 +1,53 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import ts from "typescript";
4
+ import { defaultCompilerOptions, normalizePath } from "./shared.mjs";
5
+
6
+ export function resolveImportToSourceFile(serviceRoot, fromFilePath, specifier, compilerOptions = null) {
7
+ if (!specifier) return null;
8
+ if (specifier.startsWith(".")) {
9
+ const fromDirectory = path.dirname(path.join(serviceRoot, fromFilePath));
10
+ return resolveSourceCandidate(path.resolve(fromDirectory, specifier), serviceRoot);
11
+ }
12
+
13
+ const options = { ...defaultCompilerOptions(serviceRoot), ...(compilerOptions || {}) };
14
+ const containingFile = path.join(serviceRoot, fromFilePath);
15
+ const host = ts.sys;
16
+ const resolved = ts.resolveModuleName(specifier, containingFile, options, host).resolvedModule;
17
+ if (resolved?.resolvedFileName) {
18
+ if (resolved.resolvedFileName.endsWith(".d.ts")) return null;
19
+ return normalizeResolvedFile(serviceRoot, resolved.resolvedFileName);
20
+ }
21
+
22
+ if (specifier.startsWith("@/")) {
23
+ const fromRoot = resolveSourceCandidate(path.join(serviceRoot, specifier.slice(2)), serviceRoot);
24
+ if (fromRoot) return fromRoot;
25
+ return resolveSourceCandidate(path.join(serviceRoot, "src", specifier.slice(2)), serviceRoot);
26
+ }
27
+ return null;
28
+ }
29
+
30
+ export function resolveSourceCandidate(basePath, serviceRoot = null) {
31
+ const direct = [basePath, `${basePath}.ts`, `${basePath}.tsx`, `${basePath}.js`, `${basePath}.jsx`, `${basePath}.mjs`];
32
+ for (const candidate of direct) {
33
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return normalizeResolvedFile(serviceRoot, candidate);
34
+ }
35
+ const indexed = [
36
+ path.join(basePath, "index.ts"),
37
+ path.join(basePath, "index.tsx"),
38
+ path.join(basePath, "index.js"),
39
+ path.join(basePath, "index.jsx"),
40
+ path.join(basePath, "index.mjs"),
41
+ ];
42
+ for (const candidate of indexed) {
43
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return normalizeResolvedFile(serviceRoot, candidate);
44
+ }
45
+ return null;
46
+ }
47
+
48
+ function normalizeResolvedFile(serviceRoot, resolvedFileName) {
49
+ const normalized = normalizePath(resolvedFileName);
50
+ if (!serviceRoot) return normalized;
51
+ return normalizePath(path.relative(serviceRoot, normalized));
52
+ }
53
+
@@ -0,0 +1,32 @@
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ export const DEFAULT_DYNAMIC_SEGMENT_TOKEN = "__TESTKIT_DYNAMIC_SEGMENT__";
5
+
6
+ export function normalizePath(filePath) {
7
+ return String(filePath || "").split(path.sep).join("/");
8
+ }
9
+
10
+ export function scriptKindForFile(filePath) {
11
+ const normalized = normalizePath(filePath);
12
+ if (normalized.endsWith(".tsx")) return ts.ScriptKind.TSX;
13
+ if (normalized.endsWith(".jsx")) return ts.ScriptKind.JSX;
14
+ if (normalized.endsWith(".js")) return ts.ScriptKind.JS;
15
+ return ts.ScriptKind.TS;
16
+ }
17
+
18
+ export function defaultCompilerOptions(rootDir = process.cwd()) {
19
+ return {
20
+ allowJs: true,
21
+ checkJs: false,
22
+ jsx: ts.JsxEmit.Preserve,
23
+ target: ts.ScriptTarget.ESNext,
24
+ module: ts.ModuleKind.ESNext,
25
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
26
+ baseUrl: rootDir,
27
+ paths: {
28
+ "@/*": ["./*", "./src/*"],
29
+ },
30
+ };
31
+ }
32
+
@@ -0,0 +1,27 @@
1
+ import ts from "typescript";
2
+ import { DEFAULT_DYNAMIC_SEGMENT_TOKEN, scriptKindForFile } from "./shared.mjs";
3
+
4
+ export function createSourceFile(filePath, content) {
5
+ return ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, scriptKindForFile(filePath));
6
+ }
7
+
8
+ export function extractStringLiteral(node, options = {}) {
9
+ const dynamicSegmentToken = options.dynamicSegmentToken || DEFAULT_DYNAMIC_SEGMENT_TOKEN;
10
+ if (!node) return null;
11
+ if (ts.isStringLiteralLike(node)) return node.text;
12
+ if (ts.isNoSubstitutionTemplateLiteral(node)) return node.text;
13
+ if (ts.isTemplateExpression(node)) {
14
+ let value = node.head.text;
15
+ for (const span of node.templateSpans) {
16
+ value += dynamicSegmentToken;
17
+ value += span.literal.text;
18
+ }
19
+ return value;
20
+ }
21
+ return null;
22
+ }
23
+
24
+ export function extractLineNumber(node) {
25
+ return ts.getLineAndCharacterOfPosition(node.getSourceFile(), node.getStart()).line + 1;
26
+ }
27
+
@@ -0,0 +1,91 @@
1
+ # @next/routing
2
+
3
+ Shared route resolving package for Next.js.
4
+
5
+ **NOTE: This package is experimental and will become stable along with adapters API**
6
+
7
+ ## Overview
8
+
9
+ This package provides a comprehensive route resolution system that handles rewrites, redirects, middleware invocation, and dynamic route matching with support for conditional routing based on headers, cookies, queries, and host.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @next/routing
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```typescript
20
+ import { resolveRoutes } from '@next/routing'
21
+
22
+ const result = await resolveRoutes({
23
+ url: new URL('https://example.com/api/users'),
24
+ basePath: '',
25
+ requestBody: readableStream,
26
+ headers: new Headers(),
27
+ pathnames: ['/api/users', '/api/posts'],
28
+ routes: {
29
+ beforeMiddleware: [],
30
+ beforeFiles: [],
31
+ afterFiles: [],
32
+ dynamicRoutes: [],
33
+ onMatch: [],
34
+ fallback: [],
35
+ },
36
+ invokeMiddleware: async (ctx) => {
37
+ // Your middleware logic
38
+ return {}
39
+ },
40
+ })
41
+
42
+ if (result.resolvedPathname) {
43
+ console.log('Resolved pathname:', result.resolvedPathname)
44
+ console.log('Resolved query:', result.resolvedQuery)
45
+ console.log('Invocation target:', result.invocationTarget)
46
+ }
47
+ ```
48
+
49
+ ## Route Resolution Flow
50
+
51
+ 1. **beforeMiddleware routes** - Applied before middleware execution
52
+ 2. **invokeMiddleware** - Custom middleware logic
53
+ 3. **beforeFiles routes** - Applied before checking filesystem
54
+ 4. **Static pathname matching** - Check against provided pathnames
55
+ 5. **afterFiles routes** - Applied after filesystem checks
56
+ 6. **dynamicRoutes** - Dynamic route matching with parameter extraction
57
+ 7. **fallback routes** - Final fallback routes
58
+
59
+ ## Route Configuration
60
+
61
+ Each route can have:
62
+
63
+ - `sourceRegex` - Regular expression to match against pathname
64
+ - `destination` - Destination path with support for replacements ($1, $name)
65
+ - `headers` - Headers to apply on match
66
+ - `has` - Conditions that must match
67
+ - `missing` - Conditions that must not match
68
+ - `status` - HTTP status code (3xx for redirects)
69
+
70
+ ### Redirects
71
+
72
+ When a route has:
73
+ - A redirect status code (300-399)
74
+ - Headers containing `Location` or `Refresh`
75
+
76
+ The routing will end immediately and return a `redirect` result with the destination URL and status code.
77
+
78
+ ### Has/Missing Conditions
79
+
80
+ Conditions support:
81
+
82
+ - `header` - Match HTTP headers
83
+ - `cookie` - Match cookies
84
+ - `query` - Match query parameters
85
+ - `host` - Match hostname
86
+
87
+ Values can be:
88
+
89
+ - `undefined` - Match if key exists
90
+ - String - Direct string match
91
+ - Regex string - Match against regex pattern
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Replaces $1, $2, etc. and $name placeholders in the destination string
3
+ * with matches from the regex and has conditions
4
+ */
5
+ export declare function replaceDestination(destination: string, regexMatches: RegExpMatchArray | null, hasCaptures: Record<string, string>): string;
6
+ /**
7
+ * Checks if a destination is an external rewrite (starts with http/https)
8
+ */
9
+ export declare function isExternalDestination(destination: string): boolean;
10
+ /**
11
+ * Applies a destination to a URL, updating the pathname or creating a new URL
12
+ * if it's external
13
+ */
14
+ export declare function applyDestination(currentUrl: URL, destination: string): URL;
15
+ /**
16
+ * Checks if a status code is a redirect status code
17
+ */
18
+ export declare function isRedirectStatus(status: number | undefined): boolean;
19
+ /**
20
+ * Checks if headers contain redirect headers (Location or Refresh)
21
+ */
22
+ export declare function hasRedirectHeaders(headers: Record<string, string>): boolean;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * i18n utilities for locale detection and handling
3
+ */
4
+ export interface I18nDomain {
5
+ defaultLocale: string;
6
+ domain: string;
7
+ http?: true;
8
+ locales?: string[];
9
+ }
10
+ export interface I18nConfig {
11
+ defaultLocale: string;
12
+ domains?: I18nDomain[];
13
+ localeDetection?: false;
14
+ locales: string[];
15
+ }
16
+ /**
17
+ * Detects the domain locale based on hostname or detected locale
18
+ */
19
+ export declare function detectDomainLocale(domains: I18nDomain[] | undefined, hostname: string | undefined, detectedLocale?: string): I18nDomain | undefined;
20
+ /**
21
+ * Normalizes a pathname by removing the locale prefix if present
22
+ */
23
+ export declare function normalizeLocalePath(pathname: string, locales: string[]): {
24
+ pathname: string;
25
+ detectedLocale?: string;
26
+ };
27
+ /**
28
+ * Parses the Accept-Language header and returns the best matching locale
29
+ */
30
+ export declare function getAcceptLanguageLocale(acceptLanguageHeader: string, locales: string[]): string | undefined;
31
+ /**
32
+ * Gets the locale from the NEXT_LOCALE cookie
33
+ */
34
+ export declare function getCookieLocale(cookieHeader: string | undefined, locales: string[]): string | undefined;
35
+ /**
36
+ * Detects the appropriate locale based on path, domain, cookie, and accept-language
37
+ */
38
+ export declare function detectLocale(params: {
39
+ pathname: string;
40
+ hostname: string | undefined;
41
+ cookieHeader: string | undefined;
42
+ acceptLanguageHeader: string | undefined;
43
+ i18n: I18nConfig;
44
+ }): {
45
+ locale: string;
46
+ pathnameWithoutLocale: string;
47
+ localeInPath: boolean;
48
+ };
@@ -0,0 +1,5 @@
1
+ export { resolveRoutes } from './resolve-routes';
2
+ export type { RouteHas, Route, MiddlewareContext, MiddlewareResult, ResolveRoutesParams, ResolveRoutesResult, ResolveRoutesQuery, ResolveRoutesQueryValue, RouteInvocationTarget, } from './types';
3
+ export type { I18nConfig, I18nDomain } from './i18n';
4
+ export { detectLocale, detectDomainLocale, normalizeLocalePath, getAcceptLanguageLocale, getCookieLocale, } from './i18n';
5
+ export { responseToMiddlewareResult } from './middleware';
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={};(()=>{e.d=(t,n)=>{for(var a in n){if(e.o(n,a)&&!e.o(t,a)){Object.defineProperty(t,a,{enumerable:true,get:n[a]})}}}})();(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{e.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof e!=="undefined")e.ab=__dirname+"/";var t={};e.r(t);e.d(t,{detectDomainLocale:()=>detectDomainLocale,detectLocale:()=>detectLocale,getAcceptLanguageLocale:()=>getAcceptLanguageLocale,getCookieLocale:()=>getCookieLocale,normalizeLocalePath:()=>normalizeLocalePath,resolveRoutes:()=>resolveRoutes,responseToMiddlewareResult:()=>responseToMiddlewareResult});function matchesCondition(e,t){if(e===undefined){return{matched:false}}if(t===undefined){return{matched:true,capturedValue:e}}try{const n=new RegExp(t);const a=e.match(n);if(a){return{matched:true,capturedValue:a[0]}}}catch(e){}if(e===t){return{matched:true,capturedValue:e}}return{matched:false}}function getConditionValue(e,t,n){switch(e.type){case"header":return n.get(e.key)||undefined;case"cookie":{const t=n.get("cookie");if(!t)return undefined;const a=t.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n){e[n]=a.join("=")}return e}),{});return a[e.key]}case"query":return t.searchParams.get(e.key)||undefined;case"host":return t.hostname;default:return""}}function normalizeCaptureKey(e){return e.replace(/[^a-zA-Z]/g,"")}function checkHasConditions(e,t,n){if(!e||e.length===0){return{matched:true,captures:{}}}const a={};for(const r of e){const e=getConditionValue(r,t,n);const s=matchesCondition(e,r.value);if(!s.matched){return{matched:false,captures:{}}}if(s.capturedValue!==undefined&&r.type!=="host"){const e=normalizeCaptureKey(r.key);a[e]=s.capturedValue}}return{matched:true,captures:a}}function checkMissingConditions(e,t,n){if(!e||e.length===0){return true}for(const a of e){const e=getConditionValue(a,t,n);const r=matchesCondition(e,a.value);if(r.matched){return false}}return true}function replaceDestination(e,t,n){let a=e;if(t){for(let e=1;e<t.length;e++){const n=t[e];if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}if(t.groups){for(const[e,n]of Object.entries(t.groups)){if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}}}for(const[e,t]of Object.entries(n)){a=a.replace(new RegExp(`\\$${e}`,"g"),t)}return a}function isExternalDestination(e){return e.startsWith("http://")||e.startsWith("https://")}function applyDestination(e,t){if(isExternalDestination(t)){return new URL(t)}const n=new URL(e.toString());const[a,r]=t.split("?");n.pathname=a;if(r){const e=new URLSearchParams(r);for(const[t,a]of e.entries()){n.searchParams.set(t,a)}}return n}function isRedirectStatus(e){if(!e)return false;return e>=300&&e<400}function hasRedirectHeaders(e){const t=Object.keys(e).map((e=>e.toLowerCase()));return t.includes("location")||t.includes("refresh")}function normalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(r.startsWith(s)){let e=r.slice(s.length);if(e.endsWith(".json")){e=e.slice(0,-5)}r=t?`${t}/${e}`:`/${e}`;a.pathname=r}return a}function denormalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(!r.startsWith(s)){let e=r;if(t&&r.startsWith(t)){e=r.slice(t.length)}r=`${t}/_next/data/${n}${e}.json`;a.pathname=r}return a}function detectDomainLocale(e,t,n){if(!e)return undefined;const a=t?.toLowerCase();const r=n?.toLowerCase();for(const t of e){const e=t.domain.split(":",1)[0].toLowerCase();if(a===e||r===t.defaultLocale.toLowerCase()||t.locales?.some((e=>e.toLowerCase()===r))){return t}}return undefined}function normalizeLocalePath(e,t){if(!t||t.length===0){return{pathname:e}}const n=e.split("/",2);if(!n[1]){return{pathname:e}}const a=n[1].toLowerCase();const r=t.map((e=>e.toLowerCase()));const s=r.indexOf(a);if(s<0){return{pathname:e}}const o=t[s];const i=e.slice(o.length+1)||"/";return{pathname:i,detectedLocale:o}}function getAcceptLanguageLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(",").map((e=>{const t=e.trim().split(";");const n=t[0];let a=1;if(t[1]){const e=t[1].match(/q=([0-9.]+)/);if(e&&e[1]){a=parseFloat(e[1])}}return{locale:n,quality:a}})).filter((e=>e.quality>0)).sort(((e,t)=>t.quality-e.quality));const a=new Map;for(const e of t){a.set(e.toLowerCase(),e)}for(const{locale:e}of n){const t=e.toLowerCase();if(a.has(t)){return a.get(t)}}for(const{locale:e}of n){const t=e.toLowerCase().split("-")[0];if(a.has(t)){return a.get(t)}for(const[e,n]of a){if(e.startsWith(t+"-")){return n}}}return undefined}catch(e){return undefined}}function getCookieLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n&&a.length>0){e[n]=decodeURIComponent(a.join("="))}return e}),{});const a=n.NEXT_LOCALE?.toLowerCase();if(!a){return undefined}return t.find((e=>e.toLowerCase()===a))}catch(e){return undefined}}function detectLocale(e){const{pathname:t,hostname:n,cookieHeader:a,acceptLanguageHeader:r,i18n:s}=e;const o=normalizeLocalePath(t,s.locales);if(o.detectedLocale){return{locale:o.detectedLocale,pathnameWithoutLocale:o.pathname,localeInPath:true}}if(s.localeDetection===false){const e=detectDomainLocale(s.domains,n);return{locale:e?.defaultLocale||s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}const i=getCookieLocale(a,s.locales);if(i){return{locale:i,pathnameWithoutLocale:t,localeInPath:false}}const c=getAcceptLanguageLocale(r||"",s.locales);if(c){return{locale:c,pathnameWithoutLocale:t,localeInPath:false}}const l=detectDomainLocale(s.domains,n);if(l){return{locale:l.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}return{locale:s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}function matchRoute(e,t,n){const a=new RegExp(e.sourceRegex);const r=t.pathname.match(a);if(!r){return{matched:false}}const s=checkHasConditions(e.has,t,n);if(!s.matched){return{matched:false}}const o=checkMissingConditions(e.missing,t,n);if(!o){return{matched:false}}const i=e.destination?replaceDestination(e.destination,r,s.captures):undefined;const c=e.headers?Object.fromEntries(Object.entries(e.headers).map((([e,t])=>[replaceDestination(e,r,s.captures),replaceDestination(t,r,s.captures)]))):undefined;return{matched:true,destination:i,headers:c,regexMatches:r,hasCaptures:s.captures}}function processRoutes(e,t,n,a,r){let s=t;let o;for(const t of e){const e=matchRoute(t,s,n);if(e.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){a.set(t,n)}}if(t.status){o=t.status}if(e.destination){if(isRedirectStatus(t.status)&&e.headers&&hasRedirectHeaders(e.headers)){const n=isExternalDestination(e.destination)?new URL(e.destination):applyDestination(s,e.destination);return{url:s,redirect:{url:n,status:t.status},stopped:true,status:o}}if(isExternalDestination(e.destination)){return{url:s,externalRewrite:new URL(e.destination),stopped:true,status:o}}s=applyDestination(s,e.destination);if(s.origin!==r){return{url:s,externalRewrite:s,stopped:true,status:o}}}}}return{url:s,stopped:false,status:o}}function matchesPathname(e,t){for(const n of t){if(e===n){return n}}return undefined}function toResolvedQuery(e){const t={};for(const[n,a]of e.searchParams.entries()){const e=t[n];if(e===undefined){t[n]=a;continue}t[n]=Array.isArray(e)?[...e,a]:[e,a]}return t}function mergeDestinationQueryIntoUrl(e,t){const n=new URL(e.toString());const a=t.split("?")[1];if(!a){return n}const r=new URLSearchParams(a);for(const[e,t]of r.entries()){n.searchParams.set(e,t)}return n}function withResolvedInvocationTarget({result:e,url:t,resolvedPathname:n,invocationPathname:a}){const r=toResolvedQuery(t);return{...e,resolvedPathname:n,resolvedQuery:r,invocationTarget:{pathname:a,query:r}}}function matchDynamicRoute(e,t){const n=new RegExp(t.sourceRegex);const a=e.match(n);if(!a){return{matched:false}}const r={};for(let e=1;e<a.length;e++){if(a[e]!==undefined){r[String(e)]=a[e]}}if(a.groups){Object.assign(r,a.groups)}return{matched:true,params:r,regexMatches:a}}function applyOnMatchHeaders(e,t,n,a){const r=new Headers(a);for(const a of e){const e=matchRoute(a,t,n);if(e.matched&&e.headers){for(const[t,n]of Object.entries(e.headers)){r.set(t,n)}}}return r}function checkDynamicRoutes(e,t,n,a,r,s,o,i,c,l){let d=t;if(l&&c){d=denormalizeNextDataUrl(t,o,i)}for(const t of e){const e=matchDynamicRoute(d.pathname,t);if(e.matched){const o=checkHasConditions(t.has,d,a);const i=checkMissingConditions(t.missing,d,a);if(o.matched&&i){const i=t.destination?replaceDestination(t.destination,e.regexMatches||null,o.captures):undefined;const c=i?i.split("?")[0]:d.pathname;const l=matchesPathname(c,n);if(l){const t=i?mergeDestinationQueryIntoUrl(d,i):d;const n=applyOnMatchHeaders(s,t,a,r);const o=withResolvedInvocationTarget({result:{routeMatches:e.params,resolvedHeaders:n},url:t,resolvedPathname:l,invocationPathname:d.pathname});return{matched:true,result:o,resetUrl:d}}}}}return{matched:false}}async function resolveRoutes(e){const{url:t,basePath:n,requestBody:a,headers:r,pathnames:s,routes:o,invokeMiddleware:i,buildId:c,i18n:l}=e;const{shouldNormalizeNextData:d}=o;let u=new URL(t.toString());let f=new Headers(r);let h=new Headers;let m;const p=t.origin;let g=false;if(d){const e=`${n}/_next/data/${c}/`;g=t.pathname.startsWith(e);if(g){u=normalizeNextDataUrl(u,n,c)}}if(l&&!g){const e=u.pathname.startsWith(n)?u.pathname.slice(n.length)||"/":u.pathname;if(!e.startsWith("/_next/")&&!e.startsWith("/api/")){const t=u.hostname;const a=f.get("cookie")||undefined;const r=f.get("accept-language")||undefined;const s=normalizeLocalePath(e,l.locales);const o=!!s.detectedLocale;const i=detectDomainLocale(l.domains,t);const c=i?.defaultLocale||l.defaultLocale;let d=s.detectedLocale||c;if(l.localeDetection!==false&&!o){const s=detectLocale({pathname:e,hostname:t,cookieHeader:a,acceptLanguageHeader:r,i18n:l});d=s.locale;if(d!==c){const a=detectDomainLocale(l.domains,undefined,d);if(a&&a.domain!==t){const t=a.http?"http":"https";const r=d===a.defaultLocale?"":`/${d}`;const s=new URL(`${t}://${a.domain}${n}${r}${e}${u.search}`);return{redirect:{url:s,status:307},resolvedHeaders:h}}if(!a||a&&a.domain===t){const t=new URL(u.toString());t.pathname=`${n}/${d}${e}`;return{redirect:{url:t,status:307},resolvedHeaders:h}}}}if(!o){const t=d||i?.defaultLocale||l.defaultLocale;u.pathname=`${n}/${t}${e}`}}}const w=processRoutes(o.beforeMiddleware,u,f,h,p);if(w.status){m=w.status}if(w.redirect){return{redirect:w.redirect,resolvedHeaders:h,status:m}}if(w.externalRewrite){return{externalRewrite:w.externalRewrite,resolvedHeaders:h,status:m}}u=w.url;if(g&&d){u=denormalizeNextDataUrl(u,n,c)}const L=await i({url:u,headers:f,requestBody:a});if(L.bodySent){return{middlewareResponded:true}}if(L.requestHeaders){f=new Headers(L.requestHeaders)}if(L.responseHeaders){L.responseHeaders.forEach(((e,t)=>{if(t.toLowerCase()==="set-cookie"){h.append(t,e)}else{h.set(t,e)}}))}if(L.redirect){if(!h.has("location")){h.set("Location",L.redirect.url.toString())}return{resolvedHeaders:h,status:L.redirect.status}}if(L.rewrite){u=L.rewrite;if(u.origin!==p){return{externalRewrite:u,resolvedHeaders:h,status:m}}}if(g&&d){u=normalizeNextDataUrl(u,n,c)}const R=processRoutes(o.beforeFiles,u,f,h,p);if(R.status){m=R.status}if(R.redirect){return{redirect:R.redirect,resolvedHeaders:h,status:m}}if(R.externalRewrite){return{externalRewrite:R.externalRewrite,resolvedHeaders:h,status:m}}u=R.url;if(g&&d){u=denormalizeNextDataUrl(u,n,c)}let y=matchesPathname(u.pathname,s);if(y){for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){const a=e.destination?replaceDestination(e.destination,t.regexMatches||null,n.captures):undefined;const r=a?mergeDestinationQueryIntoUrl(u,a):u;const s=applyOnMatchHeaders(o.onMatch,r,f,h);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:s,status:m},url:r,resolvedPathname:y,invocationPathname:u.pathname})}}}const e=applyOnMatchHeaders(o.onMatch,u,f,h);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:m},url:u,resolvedPathname:y,invocationPathname:u.pathname})}if(g&&d){u=normalizeNextDataUrl(u,n,c)}for(const e of o.afterFiles){const t=matchRoute(e,u,f);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){h.set(e,n)}}if(e.status){m=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:h,status:m}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:h,status:m}}u=applyDestination(u,t.destination);if(u.origin!==p){return{externalRewrite:u,resolvedHeaders:h,status:m}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,h,o.onMatch,n,c,d,g);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:m}}let r=u;if(g&&d){r=denormalizeNextDataUrl(u,n,c)}y=matchesPathname(r.pathname,s);if(y){const e=applyOnMatchHeaders(o.onMatch,r,f,h);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:m},url:r,resolvedPathname:y,invocationPathname:r.pathname})}}}}for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){const a=e.destination?replaceDestination(e.destination,t.regexMatches||null,n.captures):undefined;const r=a?a.split("?")[0]:u.pathname;y=matchesPathname(r,s);if(y){const e=a?mergeDestinationQueryIntoUrl(u,a):u;const n=applyOnMatchHeaders(o.onMatch,e,f,h);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:n,status:m},url:e,resolvedPathname:y,invocationPathname:u.pathname})}}}}for(const e of o.fallback){const t=matchRoute(e,u,f);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){h.set(e,n)}}if(e.status){m=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:h,status:m}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:h,status:m}}u=applyDestination(u,t.destination);if(u.origin!==p){return{externalRewrite:u,resolvedHeaders:h,status:m}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,h,o.onMatch,n,c,d,g);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:m}}let r=u;if(g&&d){r=denormalizeNextDataUrl(u,n,c)}y=matchesPathname(r.pathname,s);if(y){const e=applyOnMatchHeaders(o.onMatch,r,f,h);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:m},url:r,resolvedPathname:y,invocationPathname:r.pathname})}}}}return{resolvedHeaders:h,status:m}}function responseToMiddlewareResult(e,t,a){const r={};const s={};e.headers.forEach(((e,t)=>{if(s[t]){const n=s[t];if(Array.isArray(n)){n.push(e)}else{s[t]=[n,e]}}else{s[t]=e}}));if(s["x-middleware-override-headers"]){const e=new Set;let n=s["x-middleware-override-headers"];if(typeof n==="string"){n=n.split(",")}for(const t of n){e.add(t.trim())}delete s["x-middleware-override-headers"];const a=[];t.forEach(((t,n)=>{if(!e.has(n)){a.push(n)}}));for(const e of a){t.delete(e)}for(const n of e.keys()){const e="x-middleware-request-"+n;const a=s[e];if(a===undefined||a===null){t.delete(n)}else if(Array.isArray(a)){t.set(n,a[0]);for(let e=1;e<a.length;e++){t.append(n,a[e])}}else{t.set(n,a)}delete s[e]}}if(!s["x-middleware-rewrite"]&&!s["x-middleware-next"]&&!s["location"]){s["x-middleware-refresh"]="1"}delete s["x-middleware-next"];const o=new Headers;for(const[e,n]of Object.entries(s)){if(["content-length","x-middleware-rewrite","x-middleware-redirect","x-middleware-refresh"].includes(e)){continue}if(e==="x-middleware-set-cookie"){if(n!==undefined){if(Array.isArray(n)){for(const a of n){t.append(e,a)}}else{t.set(e,n)}}continue}if(n!==undefined){if(Array.isArray(n)){for(const a of n){o.append(e,a);t.append(e,a)}}else{o.set(e,n);t.set(e,n)}}}r.responseHeaders=o;r.requestHeaders=t;if(s["x-middleware-rewrite"]){const e=s["x-middleware-rewrite"];const t=getRelativeURL(e,a.toString());o.set("x-middleware-rewrite",t);try{const e=new URL(t,a);if(e.origin!==a.origin){r.rewrite=e;return r}r.rewrite=e}catch{r.rewrite=new URL(t,a)}}if(s["location"]){const t=s["location"];const i=n.has(e.status);if(i){const n=getRelativeURL(t,a.toString());o.set("location",n);try{const t=new URL(n,a);r.redirect={url:t,status:e.status};return r}catch{r.redirect={url:new URL(n,a),status:e.status};return r}}else{o.set("location",t);return r}}if(s["x-middleware-refresh"]){r.bodySent=true;return r}return r}function getRelativeURL(e,t){try{const n=new URL(e,t);const a=new URL(t);if(n.origin===a.origin){return n.pathname+n.search+n.hash}return n.toString()}catch{return e}}const n=new Set([301,302,303,307,308]);module.exports=t})();
@@ -0,0 +1,12 @@
1
+ import type { RouteHas } from './types';
2
+ /**
3
+ * Checks if all "has" conditions are satisfied
4
+ */
5
+ export declare function checkHasConditions(has: RouteHas[] | undefined, url: URL, headers: Headers): {
6
+ matched: boolean;
7
+ captures: Record<string, string>;
8
+ };
9
+ /**
10
+ * Checks if all "missing" conditions are satisfied (i.e., none of them match)
11
+ */
12
+ export declare function checkMissingConditions(missing: RouteHas[] | undefined, url: URL, headers: Headers): boolean;
@@ -0,0 +1,12 @@
1
+ import type { MiddlewareResult } from './types';
2
+ /**
3
+ * Converts a middleware Response object to a MiddlewareResult.
4
+ * This function processes middleware response headers and applies transformations
5
+ * such as header overrides, rewrites, redirects, and refresh signals.
6
+ *
7
+ * @param response - The Response object returned from middleware
8
+ * @param requestHeaders - The request Headers object to be mutated
9
+ * @param url - The original request URL
10
+ * @returns A MiddlewareResult object with processed headers and routing information
11
+ */
12
+ export declare function responseToMiddlewareResult(response: Response, requestHeaders: Headers, url: URL): MiddlewareResult;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Normalizes Next.js data URL by removing /_next/data/{buildId}/ prefix and .json extension
3
+ * ${basePath}/_next/data/$buildId/$path.json -> ${basePath}/$path
4
+ */
5
+ export declare function normalizeNextDataUrl(url: URL, basePath: string, buildId: string): URL;
6
+ /**
7
+ * Denormalizes URL by adding /_next/data/{buildId}/ prefix and .json extension
8
+ * ${basePath}/$path -> ${basePath}/_next/data/$buildId/$path.json
9
+ */
10
+ export declare function denormalizeNextDataUrl(url: URL, basePath: string, buildId: string): URL;
@@ -0,0 +1,2 @@
1
+ import type { ResolveRoutesParams, ResolveRoutesResult } from './types';
2
+ export declare function resolveRoutes(params: ResolveRoutesParams): Promise<ResolveRoutesResult>;