@klnap/next-proxy-chain 1.0.4 → 1.0.5
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.
- package/CHANGELOG.md +8 -1
- package/LICENSE +1 -1
- package/README.md +5 -22
- package/dist/index.cjs +23 -21
- package/dist/index.d.cts +22 -22
- package/dist/index.d.ts +22 -22
- package/dist/index.js +23 -21
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.0.5] - 2026-10-29
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Host folder prefix rewrite logic lives in a dedicated module with unit coverage; runtime behavior is unchanged.
|
|
14
|
+
- README lists peer requirements and trims redundant install/badge copy.
|
|
15
|
+
|
|
9
16
|
## [1.0.4] - 2026-08-27
|
|
10
17
|
|
|
11
18
|
### Breaking
|
|
@@ -34,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
34
41
|
|
|
35
42
|
- `headerMergeStrategy` applies only to **response** headers. Request overrides stay last-write-wins.
|
|
36
43
|
- Package metadata: `repository`, `bugs`, `homepage`.
|
|
37
|
-
- Tests run on `bun:test`; removed Typedoc site
|
|
44
|
+
- Tests run on `bun:test`; removed Typedoc site from the package repo.
|
|
38
45
|
|
|
39
46
|
## [1.0.3] - 2026-08-26
|
|
40
47
|
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Composable request pipeline for Next.js middleware and proxy.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
`next` `>=15.0.0` (peer dependency).
|
|
8
10
|
|
|
9
11
|
---
|
|
10
12
|
|
|
@@ -22,24 +24,6 @@ Composable request pipeline for Next.js middleware and proxy.
|
|
|
22
24
|
|
|
23
25
|
---
|
|
24
26
|
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install @klnap/next-proxy-chain
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Or with your preferred package manager:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
pnpm add @klnap/next-proxy-chain
|
|
35
|
-
# or
|
|
36
|
-
bun add @klnap/next-proxy-chain
|
|
37
|
-
# or
|
|
38
|
-
yarn add @klnap/next-proxy-chain
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
27
|
## Quick Start
|
|
44
28
|
|
|
45
29
|
```typescript
|
|
@@ -230,7 +214,6 @@ A rule (`ProxyFn`) can return:
|
|
|
230
214
|
## Links
|
|
231
215
|
|
|
232
216
|
- [GitHub](https://github.com/klnap/next-proxy-chain)
|
|
233
|
-
- [npm](https://www.npmjs.com/package/@klnap/next-proxy-chain?activeTab=code)
|
|
234
217
|
|
|
235
218
|
---
|
|
236
219
|
|
package/dist/index.cjs
CHANGED
|
@@ -31,9 +31,6 @@ __export(index_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(index_exports);
|
|
33
33
|
|
|
34
|
-
// src/core/engine.ts
|
|
35
|
-
var import_server2 = require("next/server");
|
|
36
|
-
|
|
37
34
|
// src/core/constants.ts
|
|
38
35
|
var NEXT = /* @__PURE__ */ Symbol.for("proxy-chain.next");
|
|
39
36
|
var DEFAULT_BLOCKED_REQUEST_HEADERS = Object.freeze([
|
|
@@ -70,6 +67,9 @@ function createProxyContext() {
|
|
|
70
67
|
return /* @__PURE__ */ new Map();
|
|
71
68
|
}
|
|
72
69
|
|
|
70
|
+
// src/core/engine.ts
|
|
71
|
+
var import_server2 = require("next/server");
|
|
72
|
+
|
|
73
73
|
// src/core/headers.ts
|
|
74
74
|
function normalizeHeaderName(name) {
|
|
75
75
|
return name.toLowerCase();
|
|
@@ -212,6 +212,26 @@ function applyMergedToResponse(res, headers, cookies, dropHeaders) {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// src/core/host-folder-prefix.ts
|
|
216
|
+
function physicalFolderPrefix(raw) {
|
|
217
|
+
return "/" + raw.replace(/^\/+|\/+$/g, "").split("/").filter((seg) => !/^\(.*\)$/.test(seg)).join("/");
|
|
218
|
+
}
|
|
219
|
+
function applyFolderPrefix(rewriteUrl, folder, baseUrl) {
|
|
220
|
+
try {
|
|
221
|
+
const parsed = new URL(rewriteUrl, baseUrl);
|
|
222
|
+
if (!parsed.pathname.startsWith(folder)) {
|
|
223
|
+
parsed.pathname = folder + (parsed.pathname === "/" ? "" : parsed.pathname);
|
|
224
|
+
return parsed.toString();
|
|
225
|
+
}
|
|
226
|
+
return rewriteUrl;
|
|
227
|
+
} catch {
|
|
228
|
+
if (!rewriteUrl.startsWith(folder)) {
|
|
229
|
+
return folder + (rewriteUrl === "/" ? "" : rewriteUrl);
|
|
230
|
+
}
|
|
231
|
+
return rewriteUrl;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
215
235
|
// src/core/logger.ts
|
|
216
236
|
var LEVEL_RANK = {
|
|
217
237
|
debug: 10,
|
|
@@ -634,24 +654,6 @@ function resolveConfig(overrides, fallbackCreateContext) {
|
|
|
634
654
|
assertFiniteRuleTimeoutMs(config.ruleTimeoutMs);
|
|
635
655
|
return config;
|
|
636
656
|
}
|
|
637
|
-
function physicalFolderPrefix(raw) {
|
|
638
|
-
return "/" + raw.replace(/^\/+|\/+$/g, "").split("/").filter((seg) => !/^\(.*\)$/.test(seg)).join("/");
|
|
639
|
-
}
|
|
640
|
-
function applyFolderPrefix(rewriteUrl, folder, baseUrl) {
|
|
641
|
-
try {
|
|
642
|
-
const parsed = new URL(rewriteUrl, baseUrl);
|
|
643
|
-
if (!parsed.pathname.startsWith(folder)) {
|
|
644
|
-
parsed.pathname = folder + (parsed.pathname === "/" ? "" : parsed.pathname);
|
|
645
|
-
return parsed.toString();
|
|
646
|
-
}
|
|
647
|
-
return rewriteUrl;
|
|
648
|
-
} catch {
|
|
649
|
-
if (!rewriteUrl.startsWith(folder)) {
|
|
650
|
-
return folder + (rewriteUrl === "/" ? "" : rewriteUrl);
|
|
651
|
-
}
|
|
652
|
-
return rewriteUrl;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
657
|
function proxyChain(optionsOrEntries, maybeEntries) {
|
|
656
658
|
const options = Array.isArray(optionsOrEntries) ? {} : optionsOrEntries;
|
|
657
659
|
const entries = (Array.isArray(optionsOrEntries) ? optionsOrEntries : maybeEntries) ?? [];
|
package/dist/index.d.cts
CHANGED
|
@@ -61,7 +61,7 @@ type ProxyFn<TContext = ProxyContext> = (req: NextRequest, ctx: TContext, event:
|
|
|
61
61
|
type ProxyRule<TContext = ProxyContext> = BaseProxyRule<ProxyFn<TContext>>;
|
|
62
62
|
type DefinedProxy<TContext = ProxyContext> = ProxyFn<TContext> & ((filter: ProxyPathFilter) => ProxyRule<TContext>);
|
|
63
63
|
type Entry<TContext = ProxyContext> = ProxyFn<TContext> | ProxyRule<TContext>;
|
|
64
|
-
type MergeStrategy =
|
|
64
|
+
type MergeStrategy = 'last-write-wins' | 'first-write-wins' | ((key: string, existing: string, incoming: string) => string | null);
|
|
65
65
|
interface ChainLogger {
|
|
66
66
|
debug: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
67
67
|
info: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
@@ -111,6 +111,27 @@ interface ChainConfig<TContext = ProxyContext> {
|
|
|
111
111
|
}
|
|
112
112
|
type ProxyChainOptions<TContext = ProxyContext> = Partial<ChainConfig<TContext>>;
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Optional request and response header mutations.
|
|
118
|
+
* @returns NextResult token indicating pipeline continuation.
|
|
119
|
+
*/
|
|
120
|
+
declare function next(options?: NextOptions): NextResult;
|
|
121
|
+
/**
|
|
122
|
+
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
123
|
+
*
|
|
124
|
+
* @param value - Value to test.
|
|
125
|
+
* @returns True if value is a NextResult continuation token.
|
|
126
|
+
*/
|
|
127
|
+
declare function isNextResult(value: unknown): value is NextResult;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates an isolated per-request context instance.
|
|
131
|
+
* Backed by Map to eliminate prototype pollution risks.
|
|
132
|
+
*/
|
|
133
|
+
declare function createProxyContext(): ProxyContext;
|
|
134
|
+
|
|
114
135
|
/**
|
|
115
136
|
* Creates a reusable, scope-aware proxy rule function.
|
|
116
137
|
*
|
|
@@ -139,21 +160,6 @@ declare function proxyChain<TContext>(options: ProxyChainOptions<TContext> & {
|
|
|
139
160
|
createContext: (req: NextRequest, event: NextFetchEvent) => TContext;
|
|
140
161
|
}, entries: Entry<TContext>[]): ProxyHandler;
|
|
141
162
|
|
|
142
|
-
/**
|
|
143
|
-
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
144
|
-
*
|
|
145
|
-
* @param options - Optional request and response header mutations.
|
|
146
|
-
* @returns NextResult token indicating pipeline continuation.
|
|
147
|
-
*/
|
|
148
|
-
declare function next(options?: NextOptions): NextResult;
|
|
149
|
-
/**
|
|
150
|
-
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
151
|
-
*
|
|
152
|
-
* @param value - Value to test.
|
|
153
|
-
* @returns True if value is a NextResult continuation token.
|
|
154
|
-
*/
|
|
155
|
-
declare function isNextResult(value: unknown): value is NextResult;
|
|
156
|
-
|
|
157
163
|
/**
|
|
158
164
|
* Builds a compiled Host matcher RegExp from domain names, `*.example.com` wildcards, or regex patterns.
|
|
159
165
|
*/
|
|
@@ -166,12 +172,6 @@ declare function host(matcher: HostMatcher): RegExp;
|
|
|
166
172
|
*/
|
|
167
173
|
declare function path(pattern: string | RegExp): RegExp;
|
|
168
174
|
|
|
169
|
-
/**
|
|
170
|
-
* Creates an isolated per-request context instance.
|
|
171
|
-
* Backed by Map to eliminate prototype pollution risks.
|
|
172
|
-
*/
|
|
173
|
-
declare function createProxyContext(): ProxyContext;
|
|
174
|
-
|
|
175
175
|
declare class RuleTimeoutError extends Error {
|
|
176
176
|
readonly ruleName: string;
|
|
177
177
|
readonly timeoutMs: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ type ProxyFn<TContext = ProxyContext> = (req: NextRequest, ctx: TContext, event:
|
|
|
61
61
|
type ProxyRule<TContext = ProxyContext> = BaseProxyRule<ProxyFn<TContext>>;
|
|
62
62
|
type DefinedProxy<TContext = ProxyContext> = ProxyFn<TContext> & ((filter: ProxyPathFilter) => ProxyRule<TContext>);
|
|
63
63
|
type Entry<TContext = ProxyContext> = ProxyFn<TContext> | ProxyRule<TContext>;
|
|
64
|
-
type MergeStrategy =
|
|
64
|
+
type MergeStrategy = 'last-write-wins' | 'first-write-wins' | ((key: string, existing: string, incoming: string) => string | null);
|
|
65
65
|
interface ChainLogger {
|
|
66
66
|
debug: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
67
67
|
info: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
@@ -111,6 +111,27 @@ interface ChainConfig<TContext = ProxyContext> {
|
|
|
111
111
|
}
|
|
112
112
|
type ProxyChainOptions<TContext = ProxyContext> = Partial<ChainConfig<TContext>>;
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Optional request and response header mutations.
|
|
118
|
+
* @returns NextResult token indicating pipeline continuation.
|
|
119
|
+
*/
|
|
120
|
+
declare function next(options?: NextOptions): NextResult;
|
|
121
|
+
/**
|
|
122
|
+
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
123
|
+
*
|
|
124
|
+
* @param value - Value to test.
|
|
125
|
+
* @returns True if value is a NextResult continuation token.
|
|
126
|
+
*/
|
|
127
|
+
declare function isNextResult(value: unknown): value is NextResult;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates an isolated per-request context instance.
|
|
131
|
+
* Backed by Map to eliminate prototype pollution risks.
|
|
132
|
+
*/
|
|
133
|
+
declare function createProxyContext(): ProxyContext;
|
|
134
|
+
|
|
114
135
|
/**
|
|
115
136
|
* Creates a reusable, scope-aware proxy rule function.
|
|
116
137
|
*
|
|
@@ -139,21 +160,6 @@ declare function proxyChain<TContext>(options: ProxyChainOptions<TContext> & {
|
|
|
139
160
|
createContext: (req: NextRequest, event: NextFetchEvent) => TContext;
|
|
140
161
|
}, entries: Entry<TContext>[]): ProxyHandler;
|
|
141
162
|
|
|
142
|
-
/**
|
|
143
|
-
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
144
|
-
*
|
|
145
|
-
* @param options - Optional request and response header mutations.
|
|
146
|
-
* @returns NextResult token indicating pipeline continuation.
|
|
147
|
-
*/
|
|
148
|
-
declare function next(options?: NextOptions): NextResult;
|
|
149
|
-
/**
|
|
150
|
-
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
151
|
-
*
|
|
152
|
-
* @param value - Value to test.
|
|
153
|
-
* @returns True if value is a NextResult continuation token.
|
|
154
|
-
*/
|
|
155
|
-
declare function isNextResult(value: unknown): value is NextResult;
|
|
156
|
-
|
|
157
163
|
/**
|
|
158
164
|
* Builds a compiled Host matcher RegExp from domain names, `*.example.com` wildcards, or regex patterns.
|
|
159
165
|
*/
|
|
@@ -166,12 +172,6 @@ declare function host(matcher: HostMatcher): RegExp;
|
|
|
166
172
|
*/
|
|
167
173
|
declare function path(pattern: string | RegExp): RegExp;
|
|
168
174
|
|
|
169
|
-
/**
|
|
170
|
-
* Creates an isolated per-request context instance.
|
|
171
|
-
* Backed by Map to eliminate prototype pollution risks.
|
|
172
|
-
*/
|
|
173
|
-
declare function createProxyContext(): ProxyContext;
|
|
174
|
-
|
|
175
175
|
declare class RuleTimeoutError extends Error {
|
|
176
176
|
readonly ruleName: string;
|
|
177
177
|
readonly timeoutMs: number;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/core/engine.ts
|
|
2
|
-
import { NextRequest, NextResponse as NextResponse2 } from "next/server";
|
|
3
|
-
|
|
4
1
|
// src/core/constants.ts
|
|
5
2
|
var NEXT = /* @__PURE__ */ Symbol.for("proxy-chain.next");
|
|
6
3
|
var DEFAULT_BLOCKED_REQUEST_HEADERS = Object.freeze([
|
|
@@ -37,6 +34,9 @@ function createProxyContext() {
|
|
|
37
34
|
return /* @__PURE__ */ new Map();
|
|
38
35
|
}
|
|
39
36
|
|
|
37
|
+
// src/core/engine.ts
|
|
38
|
+
import { NextRequest, NextResponse as NextResponse2 } from "next/server";
|
|
39
|
+
|
|
40
40
|
// src/core/headers.ts
|
|
41
41
|
function normalizeHeaderName(name) {
|
|
42
42
|
return name.toLowerCase();
|
|
@@ -179,6 +179,26 @@ function applyMergedToResponse(res, headers, cookies, dropHeaders) {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
// src/core/host-folder-prefix.ts
|
|
183
|
+
function physicalFolderPrefix(raw) {
|
|
184
|
+
return "/" + raw.replace(/^\/+|\/+$/g, "").split("/").filter((seg) => !/^\(.*\)$/.test(seg)).join("/");
|
|
185
|
+
}
|
|
186
|
+
function applyFolderPrefix(rewriteUrl, folder, baseUrl) {
|
|
187
|
+
try {
|
|
188
|
+
const parsed = new URL(rewriteUrl, baseUrl);
|
|
189
|
+
if (!parsed.pathname.startsWith(folder)) {
|
|
190
|
+
parsed.pathname = folder + (parsed.pathname === "/" ? "" : parsed.pathname);
|
|
191
|
+
return parsed.toString();
|
|
192
|
+
}
|
|
193
|
+
return rewriteUrl;
|
|
194
|
+
} catch {
|
|
195
|
+
if (!rewriteUrl.startsWith(folder)) {
|
|
196
|
+
return folder + (rewriteUrl === "/" ? "" : rewriteUrl);
|
|
197
|
+
}
|
|
198
|
+
return rewriteUrl;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
182
202
|
// src/core/logger.ts
|
|
183
203
|
var LEVEL_RANK = {
|
|
184
204
|
debug: 10,
|
|
@@ -601,24 +621,6 @@ function resolveConfig(overrides, fallbackCreateContext) {
|
|
|
601
621
|
assertFiniteRuleTimeoutMs(config.ruleTimeoutMs);
|
|
602
622
|
return config;
|
|
603
623
|
}
|
|
604
|
-
function physicalFolderPrefix(raw) {
|
|
605
|
-
return "/" + raw.replace(/^\/+|\/+$/g, "").split("/").filter((seg) => !/^\(.*\)$/.test(seg)).join("/");
|
|
606
|
-
}
|
|
607
|
-
function applyFolderPrefix(rewriteUrl, folder, baseUrl) {
|
|
608
|
-
try {
|
|
609
|
-
const parsed = new URL(rewriteUrl, baseUrl);
|
|
610
|
-
if (!parsed.pathname.startsWith(folder)) {
|
|
611
|
-
parsed.pathname = folder + (parsed.pathname === "/" ? "" : parsed.pathname);
|
|
612
|
-
return parsed.toString();
|
|
613
|
-
}
|
|
614
|
-
return rewriteUrl;
|
|
615
|
-
} catch {
|
|
616
|
-
if (!rewriteUrl.startsWith(folder)) {
|
|
617
|
-
return folder + (rewriteUrl === "/" ? "" : rewriteUrl);
|
|
618
|
-
}
|
|
619
|
-
return rewriteUrl;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
624
|
function proxyChain(optionsOrEntries, maybeEntries) {
|
|
623
625
|
const options = Array.isArray(optionsOrEntries) ? {} : optionsOrEntries;
|
|
624
626
|
const entries = (Array.isArray(optionsOrEntries) ? optionsOrEntries : maybeEntries) ?? [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klnap/next-proxy-chain",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Composable request pipeline for Next.js middleware and proxy.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"typecheck": "tsc -p tsconfig.json",
|
|
53
53
|
"test": "bun test",
|
|
54
54
|
"test:watch": "bun test --watch",
|
|
55
|
+
"lint": "biome check .",
|
|
55
56
|
"clean": "rm -rf dist coverage",
|
|
56
57
|
"prepublishOnly": "bun run clean && bun run typecheck && bun test && bun run build"
|
|
57
58
|
},
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@types/bun": "^1.4.0",
|
|
64
|
+
"@biomejs/biome": "2.5.14",
|
|
63
65
|
"@types/node": "^20",
|
|
64
66
|
"next": "16.3.2",
|
|
65
67
|
"tsup": "^8.4.0",
|