@klnap/next-proxy-chain 2.0.0 → 3.0.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.
- package/CHANGELOG.md +16 -0
- package/README.md +272 -205
- package/dist/index.cjs +89 -207
- package/dist/index.d.cts +34 -102
- package/dist/index.d.ts +34 -102
- package/dist/index.js +88 -201
- package/docs/api.md +190 -0
- package/docs/concepts.md +88 -0
- package/docs/guides.md +210 -0
- package/docs/security.md +104 -0
- package/llms.txt +17 -0
- package/package.json +7 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
2
2
|
import { NextRequest as NextRequest$1, NextResponse as NextResponse$1 } from 'next/server.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Unique symbol identifying an explicit continue action in the proxy chain pipeline.
|
|
6
|
-
*/
|
|
7
|
-
declare const NEXT: unique symbol;
|
|
8
|
-
/** Marks handlers created by defineHandler(). */
|
|
9
|
-
declare const DEFINED_HANDLER: unique symbol;
|
|
10
|
-
|
|
11
4
|
type RequestMetadata = {
|
|
12
5
|
readonly requestId: string;
|
|
13
6
|
readonly startedAt: number;
|
|
@@ -38,7 +31,7 @@ type NamedHandler = {
|
|
|
38
31
|
};
|
|
39
32
|
type HandlerTrace = (NamedHandler & {
|
|
40
33
|
outcome: "continue";
|
|
41
|
-
source: "undefined" | "NextResponse.next()"
|
|
34
|
+
source: "undefined" | "NextResponse.next()";
|
|
42
35
|
durationMs: number;
|
|
43
36
|
}) | (NamedHandler & {
|
|
44
37
|
outcome: "rewrite";
|
|
@@ -112,34 +105,7 @@ type ChainTrace = {
|
|
|
112
105
|
};
|
|
113
106
|
type TraceCallback = (trace: ChainTrace) => void | Promise<void>;
|
|
114
107
|
type HandlerWhen<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent, context: HandlerContext<TContext>) => boolean | Promise<boolean>;
|
|
115
|
-
type HandlerDebugOptions<TContext extends object = object> = {
|
|
116
|
-
name?: string;
|
|
117
|
-
debug?: DebugLevel;
|
|
118
|
-
timeout?: number;
|
|
119
|
-
onError?: OnErrorHandler<TContext>;
|
|
120
|
-
rules?: {
|
|
121
|
-
include?: RouteScopeList;
|
|
122
|
-
exclude?: RouteScopeList;
|
|
123
|
-
when?: HandlerWhen<TContext>;
|
|
124
|
-
};
|
|
125
|
-
handler: (request: NextRequest, event: NextFetchEvent, context: HandlerContext<TContext>) => Response | NextResult | undefined | void | Promise<Response | NextResult | undefined | void>;
|
|
126
|
-
};
|
|
127
108
|
|
|
128
|
-
/**
|
|
129
|
-
* Configuration options for chain continuation.
|
|
130
|
-
*/
|
|
131
|
-
type NextOptions = {
|
|
132
|
-
/** Request header overrides visible to downstream rules and handlers. */
|
|
133
|
-
request?: HeadersInit;
|
|
134
|
-
/** Response headers merged into the final outgoing response. `set-cookie` is extracted as cookies. */
|
|
135
|
-
headers?: HeadersInit;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Continuation token indicating the pipeline should proceed to subsequent rules.
|
|
139
|
-
*/
|
|
140
|
-
type NextResult = NextOptions & {
|
|
141
|
-
readonly [NEXT]: true;
|
|
142
|
-
};
|
|
143
109
|
type PathMatcher = RegExp | string;
|
|
144
110
|
type HostMatcher = string | RegExp | readonly (string | RegExp)[];
|
|
145
111
|
/**
|
|
@@ -155,8 +121,10 @@ type RouteScopeInput = PathMatcher | {
|
|
|
155
121
|
type RouteScopeList = RouteScopeInput | RouteScopeInput[];
|
|
156
122
|
/** Compiled route scope evaluated during request execution. */
|
|
157
123
|
type CompiledScope = {
|
|
158
|
-
|
|
159
|
-
|
|
124
|
+
/** Independent alternatives with OR semantics; each is anchored and case-insensitive. */
|
|
125
|
+
host?: RegExp[];
|
|
126
|
+
/** Independent alternatives with OR semantics; each keeps its own flags. */
|
|
127
|
+
path?: RegExp[];
|
|
160
128
|
};
|
|
161
129
|
interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
162
130
|
run: TFn;
|
|
@@ -172,21 +140,16 @@ interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
|
172
140
|
exclude?: RouteScopeList;
|
|
173
141
|
};
|
|
174
142
|
}
|
|
175
|
-
type HandlerFilter = {
|
|
176
|
-
include?: RouteScopeList;
|
|
177
|
-
exclude?: RouteScopeList;
|
|
178
|
-
name?: string;
|
|
179
|
-
};
|
|
180
143
|
/**
|
|
181
|
-
* A
|
|
144
|
+
* A chain handler callback uses `(request, event, context)`. Native Next.js `(request, event)` handlers also work.
|
|
182
145
|
*/
|
|
183
|
-
type NativeProxy<TContext extends object = object> = (
|
|
146
|
+
type NativeProxy<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent,
|
|
184
147
|
/** Request context added by chain(); Next.js continues to pass its native event unchanged. */
|
|
185
|
-
context: HandlerContext<TContext>) => NextResponse | Response |
|
|
148
|
+
context: HandlerContext<TContext>) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
186
149
|
/**
|
|
187
150
|
* A single proxy execution function.
|
|
188
151
|
*/
|
|
189
|
-
type HandlerFn<TContext extends object = object> = (
|
|
152
|
+
type HandlerFn<TContext extends object = object> = (request: NextRequest, context: HandlerContext<TContext>, event: NextFetchEvent) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
190
153
|
type HandlerRule<TContext extends object = object> = BaseHandlerRule<HandlerFn<TContext>, TContext>;
|
|
191
154
|
type MergeStrategy = "last-write-wins" | "first-write-wins" | ((key: string, existing: string, incoming: string) => string | null);
|
|
192
155
|
interface ChainLogger {
|
|
@@ -195,25 +158,33 @@ interface ChainLogger {
|
|
|
195
158
|
warn: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
196
159
|
error: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
197
160
|
}
|
|
198
|
-
interface RequestHeaderPolicy {
|
|
199
|
-
blocked?: readonly string[];
|
|
200
|
-
allowed?: readonly string[];
|
|
201
|
-
}
|
|
202
161
|
/**
|
|
203
162
|
* Value returned from `onError`.
|
|
204
163
|
*
|
|
205
164
|
* - `Response` — stop the pipeline and return it
|
|
206
|
-
* - `
|
|
165
|
+
* - `NextResponse.next()` — continue after an ordinary rule error only
|
|
207
166
|
* - `undefined` / `void` / `null` — fail closed (`500`)
|
|
208
167
|
*/
|
|
209
|
-
type OnErrorResult = NextResponse | Response |
|
|
210
|
-
type OnErrorHandler<TContext extends object = object> = (
|
|
168
|
+
type OnErrorResult = NextResponse | Response | undefined | void | null;
|
|
169
|
+
type OnErrorHandler<TContext extends object = object> = (error: unknown,
|
|
211
170
|
/**
|
|
212
171
|
* 0-based index of the rule that threw.
|
|
213
172
|
* `-1` means the error originated in the pipeline engine.
|
|
214
173
|
* Engine-level errors cannot continue; only a `Response` is honored.
|
|
215
174
|
*/
|
|
216
|
-
ruleIndex: number,
|
|
175
|
+
ruleIndex: number, request: NextRequest, context: HandlerContext<TContext>) => OnErrorResult | Promise<OnErrorResult>;
|
|
176
|
+
type HandlerConfig<TContext extends object = object> = {
|
|
177
|
+
name: string;
|
|
178
|
+
rules?: {
|
|
179
|
+
include?: RouteScopeList;
|
|
180
|
+
exclude?: RouteScopeList;
|
|
181
|
+
when?: HandlerWhen<TContext>;
|
|
182
|
+
};
|
|
183
|
+
timeout?: number;
|
|
184
|
+
debug?: DebugLevel;
|
|
185
|
+
onError?: OnErrorHandler<TContext>;
|
|
186
|
+
handle: NativeProxy<TContext>;
|
|
187
|
+
};
|
|
217
188
|
interface ChainConfig<TContext extends object = object> {
|
|
218
189
|
cookieMergeStrategy: MergeStrategy;
|
|
219
190
|
/**
|
|
@@ -228,71 +199,32 @@ interface ChainConfig<TContext extends object = object> {
|
|
|
228
199
|
tracePath?: boolean;
|
|
229
200
|
/** Maximum execution time per handler, including its predicate, in milliseconds. 0 disables timeout. */
|
|
230
201
|
timeout: number;
|
|
231
|
-
requestHeaderPolicy: RequestHeaderPolicy;
|
|
232
202
|
/** Throw an error on startup if the runtime platform does not support request header overrides. */
|
|
233
203
|
strictOverrideCheck?: boolean;
|
|
234
204
|
}
|
|
235
205
|
type ChainOptions<TContext extends object = object> = Partial<ChainConfig<TContext>>;
|
|
236
206
|
|
|
237
|
-
/**
|
|
238
|
-
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
239
|
-
*
|
|
240
|
-
* @param options - Optional request and response header mutations.
|
|
241
|
-
* @returns NextResult token indicating pipeline continuation.
|
|
242
|
-
*/
|
|
243
|
-
declare function next(options?: NextOptions): NextResult;
|
|
244
|
-
/**
|
|
245
|
-
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
246
|
-
*
|
|
247
|
-
* @param value - Value to test.
|
|
248
|
-
* @returns True if value is a NextResult continuation token.
|
|
249
|
-
*/
|
|
250
|
-
declare function isNextResult(value: unknown): value is NextResult;
|
|
251
|
-
|
|
252
207
|
type ProxyHandler = (req: NextRequest$1, event: NextFetchEvent) => Promise<NextResponse$1 | Response>;
|
|
253
208
|
/** Internal executor for the public chain() composition helper. */
|
|
254
209
|
declare function executeChain<TContext extends object = object>(options: ChainOptions<TContext>, entries: HandlerRule<TContext>[]): ProxyHandler;
|
|
255
210
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Defines a native-signature handler with optional chain rules and local settings.
|
|
261
|
-
*/
|
|
262
|
-
declare function defineHandler<TContext extends object = object>(options: HandlerDebugOptions<TContext>): DefinedHandler<TContext>;
|
|
263
|
-
|
|
264
|
-
/** Scope for a tuple entry: `[handler, scope]`. A string, RegExp, or array is shorthand for `include`. */
|
|
265
|
-
type ChainScope = Omit<HandlerFilter, "name"> | PathMatcher | readonly PathMatcher[];
|
|
266
|
-
/** One entry of chain(): a native handler, a defineHandler() result, or a scoped tuple. */
|
|
267
|
-
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | DefinedHandler<TContext> | readonly [NativeProxy<TContext> | DefinedHandler<TContext>, ChainScope];
|
|
211
|
+
/** One entry of chain(): a native handler or configured handler. */
|
|
212
|
+
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | HandlerConfig<TContext>;
|
|
268
213
|
/**
|
|
269
|
-
* Composes native Next.js proxy handlers and
|
|
214
|
+
* Composes native Next.js proxy handlers and configured handlers into one proxy.
|
|
270
215
|
*
|
|
271
216
|
* - A plain function receives native `(request, event)` arguments plus context as a third argument.
|
|
272
|
-
* - A
|
|
273
|
-
* - `
|
|
217
|
+
* - A configured handler receives `(request, event, context)`.
|
|
218
|
+
* - `rules.include` and `rules.exclude` scope configured handlers to paths or hosts.
|
|
274
219
|
*
|
|
275
220
|
* @example
|
|
276
|
-
* export default chain([intlProxy,
|
|
221
|
+
* export default chain([intlProxy, { name: 'auth', rules: { include: '/dashboard/**' }, handle: authProxy }])
|
|
277
222
|
*/
|
|
278
223
|
declare function chain<TContext extends object = object>(entries: readonly ChainEntry<TContext>[], options?: ChainOptions<TContext>): ReturnType<typeof executeChain>;
|
|
279
224
|
|
|
280
225
|
/**
|
|
281
|
-
*
|
|
282
|
-
*/
|
|
283
|
-
declare function host(matcher: HostMatcher): RegExp;
|
|
284
|
-
/**
|
|
285
|
-
* Compiles a path pattern (glob string, param pattern, or RegExp) into a stateless regular expression.
|
|
286
|
-
*
|
|
287
|
-
* - `*` — exactly one path segment
|
|
288
|
-
* - `**` — zero or more subsequent segments
|
|
226
|
+
* Defines a native-signature handler with optional chain rules and local settings.
|
|
289
227
|
*/
|
|
290
|
-
declare function
|
|
291
|
-
|
|
292
|
-
declare class RuleTimeoutError extends Error {
|
|
293
|
-
readonly ruleName: string;
|
|
294
|
-
readonly timeoutMs: number;
|
|
295
|
-
constructor(ruleName: string, timeoutMs: number);
|
|
296
|
-
}
|
|
228
|
+
declare function defineHandler<TContext extends object = object>(options: HandlerConfig<TContext>): HandlerConfig<TContext>;
|
|
297
229
|
|
|
298
|
-
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type
|
|
230
|
+
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type ChainTrace, type DebugLevel, type HandlerConfig, type HandlerContext, type HandlerDiagnosticDetails, type HandlerTrace, type HandlerWhen, type HostMatcher, type MergeStrategy, type NativeProxy, type OnErrorHandler, type OnErrorResult, type PathMatcher, type RequestMetadata, type SkipReason, type TraceCallback, chain, defineHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
|
|
2
2
|
import { NextRequest as NextRequest$1, NextResponse as NextResponse$1 } from 'next/server.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Unique symbol identifying an explicit continue action in the proxy chain pipeline.
|
|
6
|
-
*/
|
|
7
|
-
declare const NEXT: unique symbol;
|
|
8
|
-
/** Marks handlers created by defineHandler(). */
|
|
9
|
-
declare const DEFINED_HANDLER: unique symbol;
|
|
10
|
-
|
|
11
4
|
type RequestMetadata = {
|
|
12
5
|
readonly requestId: string;
|
|
13
6
|
readonly startedAt: number;
|
|
@@ -38,7 +31,7 @@ type NamedHandler = {
|
|
|
38
31
|
};
|
|
39
32
|
type HandlerTrace = (NamedHandler & {
|
|
40
33
|
outcome: "continue";
|
|
41
|
-
source: "undefined" | "NextResponse.next()"
|
|
34
|
+
source: "undefined" | "NextResponse.next()";
|
|
42
35
|
durationMs: number;
|
|
43
36
|
}) | (NamedHandler & {
|
|
44
37
|
outcome: "rewrite";
|
|
@@ -112,34 +105,7 @@ type ChainTrace = {
|
|
|
112
105
|
};
|
|
113
106
|
type TraceCallback = (trace: ChainTrace) => void | Promise<void>;
|
|
114
107
|
type HandlerWhen<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent, context: HandlerContext<TContext>) => boolean | Promise<boolean>;
|
|
115
|
-
type HandlerDebugOptions<TContext extends object = object> = {
|
|
116
|
-
name?: string;
|
|
117
|
-
debug?: DebugLevel;
|
|
118
|
-
timeout?: number;
|
|
119
|
-
onError?: OnErrorHandler<TContext>;
|
|
120
|
-
rules?: {
|
|
121
|
-
include?: RouteScopeList;
|
|
122
|
-
exclude?: RouteScopeList;
|
|
123
|
-
when?: HandlerWhen<TContext>;
|
|
124
|
-
};
|
|
125
|
-
handler: (request: NextRequest, event: NextFetchEvent, context: HandlerContext<TContext>) => Response | NextResult | undefined | void | Promise<Response | NextResult | undefined | void>;
|
|
126
|
-
};
|
|
127
108
|
|
|
128
|
-
/**
|
|
129
|
-
* Configuration options for chain continuation.
|
|
130
|
-
*/
|
|
131
|
-
type NextOptions = {
|
|
132
|
-
/** Request header overrides visible to downstream rules and handlers. */
|
|
133
|
-
request?: HeadersInit;
|
|
134
|
-
/** Response headers merged into the final outgoing response. `set-cookie` is extracted as cookies. */
|
|
135
|
-
headers?: HeadersInit;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* Continuation token indicating the pipeline should proceed to subsequent rules.
|
|
139
|
-
*/
|
|
140
|
-
type NextResult = NextOptions & {
|
|
141
|
-
readonly [NEXT]: true;
|
|
142
|
-
};
|
|
143
109
|
type PathMatcher = RegExp | string;
|
|
144
110
|
type HostMatcher = string | RegExp | readonly (string | RegExp)[];
|
|
145
111
|
/**
|
|
@@ -155,8 +121,10 @@ type RouteScopeInput = PathMatcher | {
|
|
|
155
121
|
type RouteScopeList = RouteScopeInput | RouteScopeInput[];
|
|
156
122
|
/** Compiled route scope evaluated during request execution. */
|
|
157
123
|
type CompiledScope = {
|
|
158
|
-
|
|
159
|
-
|
|
124
|
+
/** Independent alternatives with OR semantics; each is anchored and case-insensitive. */
|
|
125
|
+
host?: RegExp[];
|
|
126
|
+
/** Independent alternatives with OR semantics; each keeps its own flags. */
|
|
127
|
+
path?: RegExp[];
|
|
160
128
|
};
|
|
161
129
|
interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
162
130
|
run: TFn;
|
|
@@ -172,21 +140,16 @@ interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
|
172
140
|
exclude?: RouteScopeList;
|
|
173
141
|
};
|
|
174
142
|
}
|
|
175
|
-
type HandlerFilter = {
|
|
176
|
-
include?: RouteScopeList;
|
|
177
|
-
exclude?: RouteScopeList;
|
|
178
|
-
name?: string;
|
|
179
|
-
};
|
|
180
143
|
/**
|
|
181
|
-
* A
|
|
144
|
+
* A chain handler callback uses `(request, event, context)`. Native Next.js `(request, event)` handlers also work.
|
|
182
145
|
*/
|
|
183
|
-
type NativeProxy<TContext extends object = object> = (
|
|
146
|
+
type NativeProxy<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent,
|
|
184
147
|
/** Request context added by chain(); Next.js continues to pass its native event unchanged. */
|
|
185
|
-
context: HandlerContext<TContext>) => NextResponse | Response |
|
|
148
|
+
context: HandlerContext<TContext>) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
186
149
|
/**
|
|
187
150
|
* A single proxy execution function.
|
|
188
151
|
*/
|
|
189
|
-
type HandlerFn<TContext extends object = object> = (
|
|
152
|
+
type HandlerFn<TContext extends object = object> = (request: NextRequest, context: HandlerContext<TContext>, event: NextFetchEvent) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
190
153
|
type HandlerRule<TContext extends object = object> = BaseHandlerRule<HandlerFn<TContext>, TContext>;
|
|
191
154
|
type MergeStrategy = "last-write-wins" | "first-write-wins" | ((key: string, existing: string, incoming: string) => string | null);
|
|
192
155
|
interface ChainLogger {
|
|
@@ -195,25 +158,33 @@ interface ChainLogger {
|
|
|
195
158
|
warn: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
196
159
|
error: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
197
160
|
}
|
|
198
|
-
interface RequestHeaderPolicy {
|
|
199
|
-
blocked?: readonly string[];
|
|
200
|
-
allowed?: readonly string[];
|
|
201
|
-
}
|
|
202
161
|
/**
|
|
203
162
|
* Value returned from `onError`.
|
|
204
163
|
*
|
|
205
164
|
* - `Response` — stop the pipeline and return it
|
|
206
|
-
* - `
|
|
165
|
+
* - `NextResponse.next()` — continue after an ordinary rule error only
|
|
207
166
|
* - `undefined` / `void` / `null` — fail closed (`500`)
|
|
208
167
|
*/
|
|
209
|
-
type OnErrorResult = NextResponse | Response |
|
|
210
|
-
type OnErrorHandler<TContext extends object = object> = (
|
|
168
|
+
type OnErrorResult = NextResponse | Response | undefined | void | null;
|
|
169
|
+
type OnErrorHandler<TContext extends object = object> = (error: unknown,
|
|
211
170
|
/**
|
|
212
171
|
* 0-based index of the rule that threw.
|
|
213
172
|
* `-1` means the error originated in the pipeline engine.
|
|
214
173
|
* Engine-level errors cannot continue; only a `Response` is honored.
|
|
215
174
|
*/
|
|
216
|
-
ruleIndex: number,
|
|
175
|
+
ruleIndex: number, request: NextRequest, context: HandlerContext<TContext>) => OnErrorResult | Promise<OnErrorResult>;
|
|
176
|
+
type HandlerConfig<TContext extends object = object> = {
|
|
177
|
+
name: string;
|
|
178
|
+
rules?: {
|
|
179
|
+
include?: RouteScopeList;
|
|
180
|
+
exclude?: RouteScopeList;
|
|
181
|
+
when?: HandlerWhen<TContext>;
|
|
182
|
+
};
|
|
183
|
+
timeout?: number;
|
|
184
|
+
debug?: DebugLevel;
|
|
185
|
+
onError?: OnErrorHandler<TContext>;
|
|
186
|
+
handle: NativeProxy<TContext>;
|
|
187
|
+
};
|
|
217
188
|
interface ChainConfig<TContext extends object = object> {
|
|
218
189
|
cookieMergeStrategy: MergeStrategy;
|
|
219
190
|
/**
|
|
@@ -228,71 +199,32 @@ interface ChainConfig<TContext extends object = object> {
|
|
|
228
199
|
tracePath?: boolean;
|
|
229
200
|
/** Maximum execution time per handler, including its predicate, in milliseconds. 0 disables timeout. */
|
|
230
201
|
timeout: number;
|
|
231
|
-
requestHeaderPolicy: RequestHeaderPolicy;
|
|
232
202
|
/** Throw an error on startup if the runtime platform does not support request header overrides. */
|
|
233
203
|
strictOverrideCheck?: boolean;
|
|
234
204
|
}
|
|
235
205
|
type ChainOptions<TContext extends object = object> = Partial<ChainConfig<TContext>>;
|
|
236
206
|
|
|
237
|
-
/**
|
|
238
|
-
* Creates a continuation action instructing the proxy chain to proceed to subsequent rules.
|
|
239
|
-
*
|
|
240
|
-
* @param options - Optional request and response header mutations.
|
|
241
|
-
* @returns NextResult token indicating pipeline continuation.
|
|
242
|
-
*/
|
|
243
|
-
declare function next(options?: NextOptions): NextResult;
|
|
244
|
-
/**
|
|
245
|
-
* Type guard verifying whether a returned value is a proxy continuation token.
|
|
246
|
-
*
|
|
247
|
-
* @param value - Value to test.
|
|
248
|
-
* @returns True if value is a NextResult continuation token.
|
|
249
|
-
*/
|
|
250
|
-
declare function isNextResult(value: unknown): value is NextResult;
|
|
251
|
-
|
|
252
207
|
type ProxyHandler = (req: NextRequest$1, event: NextFetchEvent) => Promise<NextResponse$1 | Response>;
|
|
253
208
|
/** Internal executor for the public chain() composition helper. */
|
|
254
209
|
declare function executeChain<TContext extends object = object>(options: ChainOptions<TContext>, entries: HandlerRule<TContext>[]): ProxyHandler;
|
|
255
210
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Defines a native-signature handler with optional chain rules and local settings.
|
|
261
|
-
*/
|
|
262
|
-
declare function defineHandler<TContext extends object = object>(options: HandlerDebugOptions<TContext>): DefinedHandler<TContext>;
|
|
263
|
-
|
|
264
|
-
/** Scope for a tuple entry: `[handler, scope]`. A string, RegExp, or array is shorthand for `include`. */
|
|
265
|
-
type ChainScope = Omit<HandlerFilter, "name"> | PathMatcher | readonly PathMatcher[];
|
|
266
|
-
/** One entry of chain(): a native handler, a defineHandler() result, or a scoped tuple. */
|
|
267
|
-
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | DefinedHandler<TContext> | readonly [NativeProxy<TContext> | DefinedHandler<TContext>, ChainScope];
|
|
211
|
+
/** One entry of chain(): a native handler or configured handler. */
|
|
212
|
+
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | HandlerConfig<TContext>;
|
|
268
213
|
/**
|
|
269
|
-
* Composes native Next.js proxy handlers and
|
|
214
|
+
* Composes native Next.js proxy handlers and configured handlers into one proxy.
|
|
270
215
|
*
|
|
271
216
|
* - A plain function receives native `(request, event)` arguments plus context as a third argument.
|
|
272
|
-
* - A
|
|
273
|
-
* - `
|
|
217
|
+
* - A configured handler receives `(request, event, context)`.
|
|
218
|
+
* - `rules.include` and `rules.exclude` scope configured handlers to paths or hosts.
|
|
274
219
|
*
|
|
275
220
|
* @example
|
|
276
|
-
* export default chain([intlProxy,
|
|
221
|
+
* export default chain([intlProxy, { name: 'auth', rules: { include: '/dashboard/**' }, handle: authProxy }])
|
|
277
222
|
*/
|
|
278
223
|
declare function chain<TContext extends object = object>(entries: readonly ChainEntry<TContext>[], options?: ChainOptions<TContext>): ReturnType<typeof executeChain>;
|
|
279
224
|
|
|
280
225
|
/**
|
|
281
|
-
*
|
|
282
|
-
*/
|
|
283
|
-
declare function host(matcher: HostMatcher): RegExp;
|
|
284
|
-
/**
|
|
285
|
-
* Compiles a path pattern (glob string, param pattern, or RegExp) into a stateless regular expression.
|
|
286
|
-
*
|
|
287
|
-
* - `*` — exactly one path segment
|
|
288
|
-
* - `**` — zero or more subsequent segments
|
|
226
|
+
* Defines a native-signature handler with optional chain rules and local settings.
|
|
289
227
|
*/
|
|
290
|
-
declare function
|
|
291
|
-
|
|
292
|
-
declare class RuleTimeoutError extends Error {
|
|
293
|
-
readonly ruleName: string;
|
|
294
|
-
readonly timeoutMs: number;
|
|
295
|
-
constructor(ruleName: string, timeoutMs: number);
|
|
296
|
-
}
|
|
228
|
+
declare function defineHandler<TContext extends object = object>(options: HandlerConfig<TContext>): HandlerConfig<TContext>;
|
|
297
229
|
|
|
298
|
-
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type
|
|
230
|
+
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type ChainTrace, type DebugLevel, type HandlerConfig, type HandlerContext, type HandlerDiagnosticDetails, type HandlerTrace, type HandlerWhen, type HostMatcher, type MergeStrategy, type NativeProxy, type OnErrorHandler, type OnErrorResult, type PathMatcher, type RequestMetadata, type SkipReason, type TraceCallback, chain, defineHandler };
|