@klnap/next-proxy-chain 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +272 -205
- package/dist/index.cjs +83 -201
- package/dist/index.d.cts +32 -101
- package/dist/index.d.ts +32 -101
- package/dist/index.js +82 -195
- 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
|
/**
|
|
@@ -156,7 +122,8 @@ type RouteScopeList = RouteScopeInput | RouteScopeInput[];
|
|
|
156
122
|
/** Compiled route scope evaluated during request execution. */
|
|
157
123
|
type CompiledScope = {
|
|
158
124
|
host?: RegExp;
|
|
159
|
-
|
|
125
|
+
/** Independent alternatives with OR semantics; each keeps its own flags. */
|
|
126
|
+
path?: RegExp[];
|
|
160
127
|
};
|
|
161
128
|
interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
162
129
|
run: TFn;
|
|
@@ -172,21 +139,16 @@ interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
|
172
139
|
exclude?: RouteScopeList;
|
|
173
140
|
};
|
|
174
141
|
}
|
|
175
|
-
type HandlerFilter = {
|
|
176
|
-
include?: RouteScopeList;
|
|
177
|
-
exclude?: RouteScopeList;
|
|
178
|
-
name?: string;
|
|
179
|
-
};
|
|
180
142
|
/**
|
|
181
|
-
* A
|
|
143
|
+
* A chain handler callback uses `(request, event, context)`. Native Next.js `(request, event)` handlers also work.
|
|
182
144
|
*/
|
|
183
|
-
type NativeProxy<TContext extends object = object> = (
|
|
145
|
+
type NativeProxy<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent,
|
|
184
146
|
/** Request context added by chain(); Next.js continues to pass its native event unchanged. */
|
|
185
|
-
context: HandlerContext<TContext>) => NextResponse | Response |
|
|
147
|
+
context: HandlerContext<TContext>) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
186
148
|
/**
|
|
187
149
|
* A single proxy execution function.
|
|
188
150
|
*/
|
|
189
|
-
type HandlerFn<TContext extends object = object> = (
|
|
151
|
+
type HandlerFn<TContext extends object = object> = (request: NextRequest, context: HandlerContext<TContext>, event: NextFetchEvent) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
190
152
|
type HandlerRule<TContext extends object = object> = BaseHandlerRule<HandlerFn<TContext>, TContext>;
|
|
191
153
|
type MergeStrategy = "last-write-wins" | "first-write-wins" | ((key: string, existing: string, incoming: string) => string | null);
|
|
192
154
|
interface ChainLogger {
|
|
@@ -195,25 +157,33 @@ interface ChainLogger {
|
|
|
195
157
|
warn: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
196
158
|
error: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
197
159
|
}
|
|
198
|
-
interface RequestHeaderPolicy {
|
|
199
|
-
blocked?: readonly string[];
|
|
200
|
-
allowed?: readonly string[];
|
|
201
|
-
}
|
|
202
160
|
/**
|
|
203
161
|
* Value returned from `onError`.
|
|
204
162
|
*
|
|
205
163
|
* - `Response` — stop the pipeline and return it
|
|
206
|
-
* - `
|
|
164
|
+
* - `NextResponse.next()` — continue after an ordinary rule error only
|
|
207
165
|
* - `undefined` / `void` / `null` — fail closed (`500`)
|
|
208
166
|
*/
|
|
209
|
-
type OnErrorResult = NextResponse | Response |
|
|
210
|
-
type OnErrorHandler<TContext extends object = object> = (
|
|
167
|
+
type OnErrorResult = NextResponse | Response | undefined | void | null;
|
|
168
|
+
type OnErrorHandler<TContext extends object = object> = (error: unknown,
|
|
211
169
|
/**
|
|
212
170
|
* 0-based index of the rule that threw.
|
|
213
171
|
* `-1` means the error originated in the pipeline engine.
|
|
214
172
|
* Engine-level errors cannot continue; only a `Response` is honored.
|
|
215
173
|
*/
|
|
216
|
-
ruleIndex: number,
|
|
174
|
+
ruleIndex: number, request: NextRequest, context: HandlerContext<TContext>) => OnErrorResult | Promise<OnErrorResult>;
|
|
175
|
+
type HandlerConfig<TContext extends object = object> = {
|
|
176
|
+
name: string;
|
|
177
|
+
rules?: {
|
|
178
|
+
include?: RouteScopeList;
|
|
179
|
+
exclude?: RouteScopeList;
|
|
180
|
+
when?: HandlerWhen<TContext>;
|
|
181
|
+
};
|
|
182
|
+
timeout?: number;
|
|
183
|
+
debug?: DebugLevel;
|
|
184
|
+
onError?: OnErrorHandler<TContext>;
|
|
185
|
+
handle: NativeProxy<TContext>;
|
|
186
|
+
};
|
|
217
187
|
interface ChainConfig<TContext extends object = object> {
|
|
218
188
|
cookieMergeStrategy: MergeStrategy;
|
|
219
189
|
/**
|
|
@@ -228,71 +198,32 @@ interface ChainConfig<TContext extends object = object> {
|
|
|
228
198
|
tracePath?: boolean;
|
|
229
199
|
/** Maximum execution time per handler, including its predicate, in milliseconds. 0 disables timeout. */
|
|
230
200
|
timeout: number;
|
|
231
|
-
requestHeaderPolicy: RequestHeaderPolicy;
|
|
232
201
|
/** Throw an error on startup if the runtime platform does not support request header overrides. */
|
|
233
202
|
strictOverrideCheck?: boolean;
|
|
234
203
|
}
|
|
235
204
|
type ChainOptions<TContext extends object = object> = Partial<ChainConfig<TContext>>;
|
|
236
205
|
|
|
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
206
|
type ProxyHandler = (req: NextRequest$1, event: NextFetchEvent) => Promise<NextResponse$1 | Response>;
|
|
253
207
|
/** Internal executor for the public chain() composition helper. */
|
|
254
208
|
declare function executeChain<TContext extends object = object>(options: ChainOptions<TContext>, entries: HandlerRule<TContext>[]): ProxyHandler;
|
|
255
209
|
|
|
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];
|
|
210
|
+
/** One entry of chain(): a native handler or configured handler. */
|
|
211
|
+
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | HandlerConfig<TContext>;
|
|
268
212
|
/**
|
|
269
|
-
* Composes native Next.js proxy handlers and
|
|
213
|
+
* Composes native Next.js proxy handlers and configured handlers into one proxy.
|
|
270
214
|
*
|
|
271
215
|
* - A plain function receives native `(request, event)` arguments plus context as a third argument.
|
|
272
|
-
* - A
|
|
273
|
-
* - `
|
|
216
|
+
* - A configured handler receives `(request, event, context)`.
|
|
217
|
+
* - `rules.include` and `rules.exclude` scope configured handlers to paths or hosts.
|
|
274
218
|
*
|
|
275
219
|
* @example
|
|
276
|
-
* export default chain([intlProxy,
|
|
220
|
+
* export default chain([intlProxy, { name: 'auth', rules: { include: '/dashboard/**' }, handle: authProxy }])
|
|
277
221
|
*/
|
|
278
222
|
declare function chain<TContext extends object = object>(entries: readonly ChainEntry<TContext>[], options?: ChainOptions<TContext>): ReturnType<typeof executeChain>;
|
|
279
223
|
|
|
280
224
|
/**
|
|
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
|
|
225
|
+
* Defines a native-signature handler with optional chain rules and local settings.
|
|
289
226
|
*/
|
|
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
|
-
}
|
|
227
|
+
declare function defineHandler<TContext extends object = object>(options: HandlerConfig<TContext>): HandlerConfig<TContext>;
|
|
297
228
|
|
|
298
|
-
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type
|
|
229
|
+
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
|
/**
|
|
@@ -156,7 +122,8 @@ type RouteScopeList = RouteScopeInput | RouteScopeInput[];
|
|
|
156
122
|
/** Compiled route scope evaluated during request execution. */
|
|
157
123
|
type CompiledScope = {
|
|
158
124
|
host?: RegExp;
|
|
159
|
-
|
|
125
|
+
/** Independent alternatives with OR semantics; each keeps its own flags. */
|
|
126
|
+
path?: RegExp[];
|
|
160
127
|
};
|
|
161
128
|
interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
162
129
|
run: TFn;
|
|
@@ -172,21 +139,16 @@ interface BaseHandlerRule<TFn, TContext extends object = object> {
|
|
|
172
139
|
exclude?: RouteScopeList;
|
|
173
140
|
};
|
|
174
141
|
}
|
|
175
|
-
type HandlerFilter = {
|
|
176
|
-
include?: RouteScopeList;
|
|
177
|
-
exclude?: RouteScopeList;
|
|
178
|
-
name?: string;
|
|
179
|
-
};
|
|
180
142
|
/**
|
|
181
|
-
* A
|
|
143
|
+
* A chain handler callback uses `(request, event, context)`. Native Next.js `(request, event)` handlers also work.
|
|
182
144
|
*/
|
|
183
|
-
type NativeProxy<TContext extends object = object> = (
|
|
145
|
+
type NativeProxy<TContext extends object = object> = (request: NextRequest, event: NextFetchEvent,
|
|
184
146
|
/** Request context added by chain(); Next.js continues to pass its native event unchanged. */
|
|
185
|
-
context: HandlerContext<TContext>) => NextResponse | Response |
|
|
147
|
+
context: HandlerContext<TContext>) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
186
148
|
/**
|
|
187
149
|
* A single proxy execution function.
|
|
188
150
|
*/
|
|
189
|
-
type HandlerFn<TContext extends object = object> = (
|
|
151
|
+
type HandlerFn<TContext extends object = object> = (request: NextRequest, context: HandlerContext<TContext>, event: NextFetchEvent) => NextResponse | Response | undefined | void | Promise<NextResponse | Response | undefined | void>;
|
|
190
152
|
type HandlerRule<TContext extends object = object> = BaseHandlerRule<HandlerFn<TContext>, TContext>;
|
|
191
153
|
type MergeStrategy = "last-write-wins" | "first-write-wins" | ((key: string, existing: string, incoming: string) => string | null);
|
|
192
154
|
interface ChainLogger {
|
|
@@ -195,25 +157,33 @@ interface ChainLogger {
|
|
|
195
157
|
warn: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
196
158
|
error: (metaOrMsg: unknown, maybeMsg?: string) => void;
|
|
197
159
|
}
|
|
198
|
-
interface RequestHeaderPolicy {
|
|
199
|
-
blocked?: readonly string[];
|
|
200
|
-
allowed?: readonly string[];
|
|
201
|
-
}
|
|
202
160
|
/**
|
|
203
161
|
* Value returned from `onError`.
|
|
204
162
|
*
|
|
205
163
|
* - `Response` — stop the pipeline and return it
|
|
206
|
-
* - `
|
|
164
|
+
* - `NextResponse.next()` — continue after an ordinary rule error only
|
|
207
165
|
* - `undefined` / `void` / `null` — fail closed (`500`)
|
|
208
166
|
*/
|
|
209
|
-
type OnErrorResult = NextResponse | Response |
|
|
210
|
-
type OnErrorHandler<TContext extends object = object> = (
|
|
167
|
+
type OnErrorResult = NextResponse | Response | undefined | void | null;
|
|
168
|
+
type OnErrorHandler<TContext extends object = object> = (error: unknown,
|
|
211
169
|
/**
|
|
212
170
|
* 0-based index of the rule that threw.
|
|
213
171
|
* `-1` means the error originated in the pipeline engine.
|
|
214
172
|
* Engine-level errors cannot continue; only a `Response` is honored.
|
|
215
173
|
*/
|
|
216
|
-
ruleIndex: number,
|
|
174
|
+
ruleIndex: number, request: NextRequest, context: HandlerContext<TContext>) => OnErrorResult | Promise<OnErrorResult>;
|
|
175
|
+
type HandlerConfig<TContext extends object = object> = {
|
|
176
|
+
name: string;
|
|
177
|
+
rules?: {
|
|
178
|
+
include?: RouteScopeList;
|
|
179
|
+
exclude?: RouteScopeList;
|
|
180
|
+
when?: HandlerWhen<TContext>;
|
|
181
|
+
};
|
|
182
|
+
timeout?: number;
|
|
183
|
+
debug?: DebugLevel;
|
|
184
|
+
onError?: OnErrorHandler<TContext>;
|
|
185
|
+
handle: NativeProxy<TContext>;
|
|
186
|
+
};
|
|
217
187
|
interface ChainConfig<TContext extends object = object> {
|
|
218
188
|
cookieMergeStrategy: MergeStrategy;
|
|
219
189
|
/**
|
|
@@ -228,71 +198,32 @@ interface ChainConfig<TContext extends object = object> {
|
|
|
228
198
|
tracePath?: boolean;
|
|
229
199
|
/** Maximum execution time per handler, including its predicate, in milliseconds. 0 disables timeout. */
|
|
230
200
|
timeout: number;
|
|
231
|
-
requestHeaderPolicy: RequestHeaderPolicy;
|
|
232
201
|
/** Throw an error on startup if the runtime platform does not support request header overrides. */
|
|
233
202
|
strictOverrideCheck?: boolean;
|
|
234
203
|
}
|
|
235
204
|
type ChainOptions<TContext extends object = object> = Partial<ChainConfig<TContext>>;
|
|
236
205
|
|
|
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
206
|
type ProxyHandler = (req: NextRequest$1, event: NextFetchEvent) => Promise<NextResponse$1 | Response>;
|
|
253
207
|
/** Internal executor for the public chain() composition helper. */
|
|
254
208
|
declare function executeChain<TContext extends object = object>(options: ChainOptions<TContext>, entries: HandlerRule<TContext>[]): ProxyHandler;
|
|
255
209
|
|
|
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];
|
|
210
|
+
/** One entry of chain(): a native handler or configured handler. */
|
|
211
|
+
type ChainEntry<TContext extends object = object> = NativeProxy<TContext> | HandlerConfig<TContext>;
|
|
268
212
|
/**
|
|
269
|
-
* Composes native Next.js proxy handlers and
|
|
213
|
+
* Composes native Next.js proxy handlers and configured handlers into one proxy.
|
|
270
214
|
*
|
|
271
215
|
* - A plain function receives native `(request, event)` arguments plus context as a third argument.
|
|
272
|
-
* - A
|
|
273
|
-
* - `
|
|
216
|
+
* - A configured handler receives `(request, event, context)`.
|
|
217
|
+
* - `rules.include` and `rules.exclude` scope configured handlers to paths or hosts.
|
|
274
218
|
*
|
|
275
219
|
* @example
|
|
276
|
-
* export default chain([intlProxy,
|
|
220
|
+
* export default chain([intlProxy, { name: 'auth', rules: { include: '/dashboard/**' }, handle: authProxy }])
|
|
277
221
|
*/
|
|
278
222
|
declare function chain<TContext extends object = object>(entries: readonly ChainEntry<TContext>[], options?: ChainOptions<TContext>): ReturnType<typeof executeChain>;
|
|
279
223
|
|
|
280
224
|
/**
|
|
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
|
|
225
|
+
* Defines a native-signature handler with optional chain rules and local settings.
|
|
289
226
|
*/
|
|
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
|
-
}
|
|
227
|
+
declare function defineHandler<TContext extends object = object>(options: HandlerConfig<TContext>): HandlerConfig<TContext>;
|
|
297
228
|
|
|
298
|
-
export { type ChainEntry, type ChainLogger, type ChainOptions, type ChainOutcome, type
|
|
229
|
+
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 };
|