@spfn/core 0.1.0-alpha.86 → 0.2.0-beta.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/README.md +1046 -384
- package/dist/boss-D-fGtVgM.d.ts +187 -0
- package/dist/cache/index.d.ts +13 -33
- package/dist/cache/index.js +14 -703
- package/dist/cache/index.js.map +1 -1
- package/dist/codegen/index.d.ts +167 -17
- package/dist/codegen/index.js +76 -1419
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +1191 -0
- package/dist/config/index.js +264 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/index.d.ts +728 -59
- package/dist/db/index.js +1028 -1225
- package/dist/db/index.js.map +1 -1
- package/dist/env/index.d.ts +579 -308
- package/dist/env/index.js +438 -930
- package/dist/env/index.js.map +1 -1
- package/dist/errors/index.d.ts +417 -29
- package/dist/errors/index.js +359 -98
- package/dist/errors/index.js.map +1 -1
- package/dist/event/index.d.ts +108 -0
- package/dist/event/index.js +122 -0
- package/dist/event/index.js.map +1 -0
- package/dist/job/index.d.ts +172 -0
- package/dist/job/index.js +361 -0
- package/dist/job/index.js.map +1 -0
- package/dist/logger/index.d.ts +20 -79
- package/dist/logger/index.js +82 -387
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/index.d.ts +2 -11
- package/dist/middleware/index.js +49 -703
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +120 -0
- package/dist/nextjs/index.js +416 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +288 -262
- package/dist/nextjs/server.js +568 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/route/index.d.ts +667 -25
- package/dist/route/index.js +437 -1287
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +38 -0
- package/dist/route/types.js +3 -0
- package/dist/route/types.js.map +1 -0
- package/dist/server/index.d.ts +201 -67
- package/dist/server/index.js +921 -3182
- package/dist/server/index.js.map +1 -1
- package/dist/types-BGl4QL1w.d.ts +77 -0
- package/dist/types-DRG2XMTR.d.ts +157 -0
- package/package.json +56 -48
- package/dist/auto-loader-JFaZ9gON.d.ts +0 -80
- package/dist/client/index.d.ts +0 -358
- package/dist/client/index.js +0 -357
- package/dist/client/index.js.map +0 -1
- package/dist/client/nextjs/index.js +0 -371
- package/dist/client/nextjs/index.js.map +0 -1
- package/dist/codegen/generators/index.d.ts +0 -19
- package/dist/codegen/generators/index.js +0 -1404
- package/dist/codegen/generators/index.js.map +0 -1
- package/dist/database-errors-BNNmLTJE.d.ts +0 -86
- package/dist/events/index.d.ts +0 -183
- package/dist/events/index.js +0 -77
- package/dist/events/index.js.map +0 -1
- package/dist/index-DHiAqhKv.d.ts +0 -101
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -3674
- package/dist/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -121
- package/dist/types/index.js +0 -38
- package/dist/types/index.js.map +0 -1
- package/dist/types-BXibIEyj.d.ts +0 -60
|
@@ -1,9 +1,221 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Router } from '@spfn/core/route';
|
|
3
|
+
import { InterceptorRule as InterceptorRule$1 } from '@spfn/core/nextjs/server';
|
|
4
|
+
import { S as SetCookie } from '../types-DRG2XMTR.js';
|
|
5
|
+
import '@sinclair/typebox';
|
|
6
|
+
import '@spfn/core/errors';
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
|
-
*
|
|
9
|
+
* Request interceptor result
|
|
5
10
|
*/
|
|
11
|
+
interface RequestInterceptorResult {
|
|
12
|
+
url: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Response interceptor result
|
|
17
|
+
*/
|
|
18
|
+
interface ResponseInterceptorResult {
|
|
19
|
+
response: Response;
|
|
20
|
+
body: any;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Request interceptor function
|
|
24
|
+
*/
|
|
25
|
+
type ProxyRequestInterceptor = (req: NextRequest, url: string) => Promise<RequestInterceptorResult> | RequestInterceptorResult;
|
|
26
|
+
/**
|
|
27
|
+
* Response interceptor function
|
|
28
|
+
*/
|
|
29
|
+
type ProxyResponseInterceptor = (response: Response, body: any) => Promise<ResponseInterceptorResult> | ResponseInterceptorResult;
|
|
30
|
+
/**
|
|
31
|
+
* Proxy configuration
|
|
32
|
+
*/
|
|
33
|
+
interface TypedProxyConfig {
|
|
34
|
+
/**
|
|
35
|
+
* SPFN API base URL
|
|
36
|
+
*
|
|
37
|
+
* @default process.env.SPFN_API_URL || 'http://localhost:8790'
|
|
38
|
+
*/
|
|
39
|
+
apiUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Enable debug logging
|
|
42
|
+
*
|
|
43
|
+
* @default process.env.NODE_ENV === 'development'
|
|
44
|
+
*/
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Request timeout in milliseconds
|
|
48
|
+
*
|
|
49
|
+
* @default 30000
|
|
50
|
+
*/
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Custom headers to add to all forwarded requests
|
|
54
|
+
*/
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* Simple request interceptor - modify request before forwarding
|
|
58
|
+
*
|
|
59
|
+
* For simple use cases. Use `interceptors` for advanced features like:
|
|
60
|
+
* - Path/method matching
|
|
61
|
+
* - Cookie setting
|
|
62
|
+
* - Multiple interceptors with chaining
|
|
63
|
+
*/
|
|
64
|
+
onRequest?: ProxyRequestInterceptor;
|
|
65
|
+
/**
|
|
66
|
+
* Simple response interceptor - modify response before returning
|
|
67
|
+
*
|
|
68
|
+
* For simple use cases. Use `interceptors` for advanced features.
|
|
69
|
+
*/
|
|
70
|
+
onResponse?: ProxyResponseInterceptor;
|
|
71
|
+
/**
|
|
72
|
+
* Advanced interceptors with path matching, cookie support, and chaining
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* interceptors: [{
|
|
77
|
+
* pathPattern: '/_auth/*',
|
|
78
|
+
* method: 'POST',
|
|
79
|
+
* request: async (ctx, next) => {
|
|
80
|
+
* ctx.headers['Authorization'] = 'Bearer token';
|
|
81
|
+
* await next();
|
|
82
|
+
* },
|
|
83
|
+
* response: async (ctx, next) => {
|
|
84
|
+
* ctx.setCookies.push({
|
|
85
|
+
* name: 'session',
|
|
86
|
+
* value: 'xxx',
|
|
87
|
+
* options: { httpOnly: true, maxAge: 3600 }
|
|
88
|
+
* });
|
|
89
|
+
* await next();
|
|
90
|
+
* }
|
|
91
|
+
* }]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
interceptors?: InterceptorRule$1[];
|
|
95
|
+
/**
|
|
96
|
+
* Enable automatic interceptor discovery from registry
|
|
97
|
+
*
|
|
98
|
+
* When enabled, interceptors registered via registerInterceptors()
|
|
99
|
+
* are automatically applied.
|
|
100
|
+
*
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
autoDiscoverInterceptors?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Disable interceptors from specific packages
|
|
106
|
+
*
|
|
107
|
+
* @example ['auth', 'storage']
|
|
108
|
+
*/
|
|
109
|
+
disableAutoInterceptors?: string[];
|
|
110
|
+
}
|
|
6
111
|
|
|
112
|
+
/**
|
|
113
|
+
* RPC-Style Proxy for define-route System
|
|
114
|
+
*
|
|
115
|
+
* Next.js API Route handler that resolves routeName to method/path
|
|
116
|
+
* and forwards requests to SPFN backend.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // app/api/rpc/[routeName]/route.ts
|
|
121
|
+
* import { appRouter } from '@/server/router';
|
|
122
|
+
* import { createRpcProxy } from '@spfn/core/nextjs/proxy';
|
|
123
|
+
*
|
|
124
|
+
* export const { GET, POST } = createRpcProxy({ router: appRouter });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
interface RpcProxyConfig<TRouter extends Router<any>> extends Omit<TypedProxyConfig, 'onRequest' | 'onResponse'> {
|
|
129
|
+
/**
|
|
130
|
+
* The router containing all route definitions
|
|
131
|
+
*
|
|
132
|
+
* Package routes registered via `.packages()` are automatically recognized.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // router.ts
|
|
137
|
+
* export const appRouter = defineRouter({
|
|
138
|
+
* getRoot,
|
|
139
|
+
* getHealth,
|
|
140
|
+
* })
|
|
141
|
+
* .packages([authRouter, cmsAppRouter]);
|
|
142
|
+
*
|
|
143
|
+
* // api/rpc/[routeName]/route.ts
|
|
144
|
+
* export const { GET, POST } = createRpcProxy({
|
|
145
|
+
* router: appRouter,
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
router: TRouter;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create RPC proxy handler for Next.js API Route
|
|
153
|
+
*
|
|
154
|
+
* Handles requests in the format:
|
|
155
|
+
* - GET /api/rpc/{routeName}?input={...}
|
|
156
|
+
* - POST /api/rpc/{routeName} with body
|
|
157
|
+
*
|
|
158
|
+
* Resolves routeName to actual HTTP method and path from the router,
|
|
159
|
+
* then forwards to SPFN backend.
|
|
160
|
+
*/
|
|
161
|
+
declare function createRpcProxy<TRouter extends Router<any>>(config: RpcProxyConfig<TRouter>): {
|
|
162
|
+
GET: (req: NextRequest, context: {
|
|
163
|
+
params: Promise<{
|
|
164
|
+
routeName?: string;
|
|
165
|
+
}>;
|
|
166
|
+
}) => Promise<NextResponse<unknown>>;
|
|
167
|
+
POST: (req: NextRequest, context: {
|
|
168
|
+
params: Promise<{
|
|
169
|
+
routeName?: string;
|
|
170
|
+
}>;
|
|
171
|
+
}) => Promise<NextResponse<unknown>>;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Interceptor Rule
|
|
176
|
+
*
|
|
177
|
+
* Defines when and how to intercept requests/responses
|
|
178
|
+
*/
|
|
179
|
+
interface InterceptorRule {
|
|
180
|
+
/**
|
|
181
|
+
* Path pattern to match
|
|
182
|
+
*
|
|
183
|
+
* - String with wildcards: '/_auth/*', '/users/:id'
|
|
184
|
+
* - RegExp: /^\/_auth\/.+$/
|
|
185
|
+
* - '*' matches all paths
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* pathPattern: '/_auth/*' // matches /_auth/login, /_auth/register
|
|
190
|
+
* pathPattern: '/users/:id' // matches /users/123, /users/456
|
|
191
|
+
* pathPattern: /^\/_auth\/.+$/ // regex match
|
|
192
|
+
* pathPattern: '*' // matches all paths
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
pathPattern: string | RegExp;
|
|
196
|
+
/**
|
|
197
|
+
* HTTP method(s) to match (optional)
|
|
198
|
+
*
|
|
199
|
+
* - Single method: 'POST'
|
|
200
|
+
* - Multiple methods: ['POST', 'PUT']
|
|
201
|
+
* - Omit to match all methods
|
|
202
|
+
*
|
|
203
|
+
* @default undefined (matches all methods)
|
|
204
|
+
*/
|
|
205
|
+
method?: string | string[];
|
|
206
|
+
/**
|
|
207
|
+
* Request interceptor
|
|
208
|
+
*
|
|
209
|
+
* Called before SPFN API request
|
|
210
|
+
*/
|
|
211
|
+
request?: RequestInterceptor;
|
|
212
|
+
/**
|
|
213
|
+
* Response interceptor
|
|
214
|
+
*
|
|
215
|
+
* Called after SPFN API response
|
|
216
|
+
*/
|
|
217
|
+
response?: ResponseInterceptor;
|
|
218
|
+
}
|
|
7
219
|
/**
|
|
8
220
|
* Request Interceptor Context
|
|
9
221
|
*
|
|
@@ -85,18 +297,7 @@ interface ResponseInterceptorContext {
|
|
|
85
297
|
* });
|
|
86
298
|
* ```
|
|
87
299
|
*/
|
|
88
|
-
setCookies:
|
|
89
|
-
name: string;
|
|
90
|
-
value: string;
|
|
91
|
-
options?: {
|
|
92
|
-
httpOnly?: boolean;
|
|
93
|
-
secure?: boolean;
|
|
94
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
95
|
-
maxAge?: number;
|
|
96
|
-
path?: string;
|
|
97
|
-
domain?: string;
|
|
98
|
-
};
|
|
99
|
-
}>;
|
|
300
|
+
setCookies: SetCookie[];
|
|
100
301
|
/**
|
|
101
302
|
* Metadata shared from request interceptors
|
|
102
303
|
*/
|
|
@@ -148,51 +349,6 @@ type RequestInterceptor = (context: RequestInterceptorContext, next: () => Promi
|
|
|
148
349
|
* ```
|
|
149
350
|
*/
|
|
150
351
|
type ResponseInterceptor = (context: ResponseInterceptorContext, next: () => Promise<void>) => Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* Interceptor Rule
|
|
153
|
-
*
|
|
154
|
-
* Defines when and how to intercept requests/responses
|
|
155
|
-
*/
|
|
156
|
-
interface InterceptorRule {
|
|
157
|
-
/**
|
|
158
|
-
* Path pattern to match
|
|
159
|
-
*
|
|
160
|
-
* - String with wildcards: '/_auth/*', '/users/:id'
|
|
161
|
-
* - RegExp: /^\/_auth\/.+$/
|
|
162
|
-
* - '*' matches all paths
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```typescript
|
|
166
|
-
* pathPattern: '/_auth/*' // matches /_auth/login, /_auth/register
|
|
167
|
-
* pathPattern: '/users/:id' // matches /users/123, /users/456
|
|
168
|
-
* pathPattern: /^\/_auth\/.+$/ // regex match
|
|
169
|
-
* pathPattern: '*' // matches all paths
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
pathPattern: string | RegExp;
|
|
173
|
-
/**
|
|
174
|
-
* HTTP method(s) to match (optional)
|
|
175
|
-
*
|
|
176
|
-
* - Single method: 'POST'
|
|
177
|
-
* - Multiple methods: ['POST', 'PUT']
|
|
178
|
-
* - Omit to match all methods
|
|
179
|
-
*
|
|
180
|
-
* @default undefined (matches all methods)
|
|
181
|
-
*/
|
|
182
|
-
method?: string | string[];
|
|
183
|
-
/**
|
|
184
|
-
* Request interceptor
|
|
185
|
-
*
|
|
186
|
-
* Called before SPFN API request
|
|
187
|
-
*/
|
|
188
|
-
request?: RequestInterceptor;
|
|
189
|
-
/**
|
|
190
|
-
* Response interceptor
|
|
191
|
-
*
|
|
192
|
-
* Called after SPFN API response
|
|
193
|
-
*/
|
|
194
|
-
response?: ResponseInterceptor;
|
|
195
|
-
}
|
|
196
352
|
/**
|
|
197
353
|
* Proxy Configuration
|
|
198
354
|
*/
|
|
@@ -238,156 +394,90 @@ interface ProxyConfig {
|
|
|
238
394
|
}
|
|
239
395
|
|
|
240
396
|
/**
|
|
241
|
-
* SPFN Next.js
|
|
397
|
+
* SPFN Next.js Proxy Interceptor Execution Engine
|
|
398
|
+
*/
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Check if path matches pattern
|
|
242
402
|
*
|
|
243
|
-
*
|
|
244
|
-
* -
|
|
245
|
-
* -
|
|
246
|
-
* -
|
|
403
|
+
* Supports:
|
|
404
|
+
* - Wildcards: '/_auth/*' matches '/_auth/login'
|
|
405
|
+
* - Path params: '/users/:id' matches '/users/123'
|
|
406
|
+
* - RegExp: /^\/_auth\/.+$/ matches '/_auth/login'
|
|
407
|
+
* - Exact match: '/_auth/login' matches '/_auth/login'
|
|
408
|
+
* - All: '*' matches any path
|
|
247
409
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* // app/api/actions/[...path]/route.ts
|
|
252
|
-
* export { GET, POST, PUT, DELETE, PATCH } from '@spfn/core/nextjs';
|
|
253
|
-
*
|
|
254
|
-
* // With interceptors
|
|
255
|
-
* import { createProxy } from '@spfn/core/nextjs';
|
|
256
|
-
*
|
|
257
|
-
* export const { GET, POST } = createProxy({
|
|
258
|
-
* interceptors: [
|
|
259
|
-
* {
|
|
260
|
-
* pathPattern: '/_auth/*',
|
|
261
|
-
* request: async (ctx, next) => {
|
|
262
|
-
* ctx.headers['Authorization'] = 'Bearer token';
|
|
263
|
-
* await next();
|
|
264
|
-
* }
|
|
265
|
-
* }
|
|
266
|
-
* ]
|
|
267
|
-
* });
|
|
268
|
-
* ```
|
|
410
|
+
* @param path - Request path to test
|
|
411
|
+
* @param pattern - Pattern to match against
|
|
412
|
+
* @returns True if path matches pattern
|
|
269
413
|
*/
|
|
270
|
-
|
|
414
|
+
declare function matchPath(path: string, pattern: string | RegExp): boolean;
|
|
271
415
|
/**
|
|
272
|
-
*
|
|
416
|
+
* Check if method matches pattern
|
|
273
417
|
*
|
|
274
|
-
* @param
|
|
275
|
-
* @
|
|
418
|
+
* @param method - Request method (e.g., 'POST')
|
|
419
|
+
* @param pattern - Method pattern (e.g., 'POST' or ['POST', 'PUT'])
|
|
420
|
+
* @returns True if method matches pattern
|
|
421
|
+
*/
|
|
422
|
+
declare function matchMethod(method: string, pattern?: string | string[]): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* Filter interceptors that match the request
|
|
276
425
|
*
|
|
277
|
-
* @
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* export const { GET, POST, PUT, DELETE, PATCH } = createProxy({
|
|
283
|
-
* apiUrl: 'http://localhost:8790',
|
|
284
|
-
* debug: true,
|
|
285
|
-
* interceptors: [
|
|
286
|
-
* {
|
|
287
|
-
* pathPattern: '/_auth/*',
|
|
288
|
-
* method: 'POST',
|
|
289
|
-
* request: async (ctx, next) => {
|
|
290
|
-
* const session = await getSession();
|
|
291
|
-
* if (session) {
|
|
292
|
-
* ctx.headers['Authorization'] = `Bearer ${session.token}`;
|
|
293
|
-
* }
|
|
294
|
-
* await next();
|
|
295
|
-
* },
|
|
296
|
-
* response: async (ctx, next) => {
|
|
297
|
-
* if (ctx.response.status === 200) {
|
|
298
|
-
* ctx.setCookies.push({
|
|
299
|
-
* name: 'session',
|
|
300
|
-
* value: ctx.response.body.token,
|
|
301
|
-
* options: { httpOnly: true, maxAge: 3600 }
|
|
302
|
-
* });
|
|
303
|
-
* }
|
|
304
|
-
* await next();
|
|
305
|
-
* }
|
|
306
|
-
* }
|
|
307
|
-
* ]
|
|
308
|
-
* });
|
|
309
|
-
* ```
|
|
426
|
+
* @param rules - All interceptor rules
|
|
427
|
+
* @param path - Request path
|
|
428
|
+
* @param method - Request method
|
|
429
|
+
* @returns Matched interceptors
|
|
310
430
|
*/
|
|
311
|
-
declare function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
path: string[];
|
|
343
|
-
}> | {
|
|
344
|
-
path: string[];
|
|
345
|
-
};
|
|
346
|
-
}) => Promise<NextResponse<unknown>>;
|
|
347
|
-
};
|
|
348
|
-
declare const GET: (request: NextRequest, context: {
|
|
349
|
-
params: Promise<{
|
|
350
|
-
path: string[];
|
|
351
|
-
}> | {
|
|
352
|
-
path: string[];
|
|
353
|
-
};
|
|
354
|
-
}) => Promise<NextResponse<unknown>>;
|
|
355
|
-
declare const POST: (request: NextRequest, context: {
|
|
356
|
-
params: Promise<{
|
|
357
|
-
path: string[];
|
|
358
|
-
}> | {
|
|
359
|
-
path: string[];
|
|
360
|
-
};
|
|
361
|
-
}) => Promise<NextResponse<unknown>>;
|
|
362
|
-
declare const PUT: (request: NextRequest, context: {
|
|
363
|
-
params: Promise<{
|
|
364
|
-
path: string[];
|
|
365
|
-
}> | {
|
|
366
|
-
path: string[];
|
|
367
|
-
};
|
|
368
|
-
}) => Promise<NextResponse<unknown>>;
|
|
369
|
-
declare const PATCH: (request: NextRequest, context: {
|
|
370
|
-
params: Promise<{
|
|
371
|
-
path: string[];
|
|
372
|
-
}> | {
|
|
373
|
-
path: string[];
|
|
374
|
-
};
|
|
375
|
-
}) => Promise<NextResponse<unknown>>;
|
|
376
|
-
declare const DELETE: (request: NextRequest, context: {
|
|
377
|
-
params: Promise<{
|
|
378
|
-
path: string[];
|
|
379
|
-
}> | {
|
|
380
|
-
path: string[];
|
|
381
|
-
};
|
|
382
|
-
}) => Promise<NextResponse<unknown>>;
|
|
431
|
+
declare function filterMatchingInterceptors(rules: InterceptorRule[], path: string, method: string): InterceptorRule[];
|
|
432
|
+
/**
|
|
433
|
+
* Execute request interceptors in chain
|
|
434
|
+
*
|
|
435
|
+
* Interceptors are executed in order:
|
|
436
|
+
* 1. First registered interceptor
|
|
437
|
+
* 2. Second registered interceptor
|
|
438
|
+
* 3. ... and so on
|
|
439
|
+
*
|
|
440
|
+
* Each interceptor must call next() to continue the chain.
|
|
441
|
+
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
442
|
+
*
|
|
443
|
+
* @param context - Request interceptor context
|
|
444
|
+
* @param interceptors - Interceptors to execute
|
|
445
|
+
*/
|
|
446
|
+
declare function executeRequestInterceptors(context: RequestInterceptorContext, interceptors: RequestInterceptor[]): Promise<void>;
|
|
447
|
+
/**
|
|
448
|
+
* Execute response interceptors in chain
|
|
449
|
+
*
|
|
450
|
+
* Interceptors are executed in order:
|
|
451
|
+
* 1. First registered interceptor
|
|
452
|
+
* 2. Second registered interceptor
|
|
453
|
+
* 3. ... and so on
|
|
454
|
+
*
|
|
455
|
+
* Each interceptor must call next() to continue the chain.
|
|
456
|
+
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
457
|
+
*
|
|
458
|
+
* @param context - Response interceptor context
|
|
459
|
+
* @param interceptors - Interceptors to execute
|
|
460
|
+
*/
|
|
461
|
+
declare function executeResponseInterceptors(context: ResponseInterceptorContext, interceptors: ResponseInterceptor[]): Promise<void>;
|
|
383
462
|
|
|
384
463
|
/**
|
|
385
464
|
* Global Interceptor Registry
|
|
386
465
|
*
|
|
387
466
|
* Allows packages to automatically register their interceptors
|
|
388
467
|
* for Next.js proxy without manual configuration.
|
|
468
|
+
*
|
|
469
|
+
* Uses globalThis for persistence across module reloads (HMR).
|
|
389
470
|
*/
|
|
390
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Extend globalThis with interceptor registry
|
|
474
|
+
*
|
|
475
|
+
* Using globalThis allows the registry to persist across module reloads (HMR).
|
|
476
|
+
* preventing duplicate registrations during development with HMR.
|
|
477
|
+
*/
|
|
478
|
+
declare global {
|
|
479
|
+
var __SPFN_INTERCEPTOR_REGISTRY__: InterceptorRegistry | undefined;
|
|
480
|
+
}
|
|
391
481
|
/**
|
|
392
482
|
* Global interceptor registry
|
|
393
483
|
*
|
|
@@ -454,6 +544,9 @@ declare class InterceptorRegistry {
|
|
|
454
544
|
}
|
|
455
545
|
/**
|
|
456
546
|
* Global singleton registry instance
|
|
547
|
+
*
|
|
548
|
+
* Uses globalThis to persist across module reloads (HMR).
|
|
549
|
+
* This prevents duplicate registrations during development.
|
|
457
550
|
*/
|
|
458
551
|
declare const interceptorRegistry: InterceptorRegistry;
|
|
459
552
|
/**
|
|
@@ -468,7 +561,7 @@ declare const interceptorRegistry: InterceptorRegistry;
|
|
|
468
561
|
* @example
|
|
469
562
|
* ```typescript
|
|
470
563
|
* // packages/auth/src/adapters/nextjs/interceptors/index.ts
|
|
471
|
-
* import { registerInterceptors } from '@spfn/core/
|
|
564
|
+
* import { registerInterceptors } from '@spfn/core/nextjs';
|
|
472
565
|
*
|
|
473
566
|
* const authInterceptors = [
|
|
474
567
|
* {
|
|
@@ -487,71 +580,4 @@ declare const interceptorRegistry: InterceptorRegistry;
|
|
|
487
580
|
*/
|
|
488
581
|
declare function registerInterceptors(packageName: string, interceptors: InterceptorRule[]): void;
|
|
489
582
|
|
|
490
|
-
|
|
491
|
-
* SPFN Next.js Proxy Interceptor Execution Engine
|
|
492
|
-
*/
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Check if path matches pattern
|
|
496
|
-
*
|
|
497
|
-
* Supports:
|
|
498
|
-
* - Wildcards: '/_auth/*' matches '/_auth/login'
|
|
499
|
-
* - Path params: '/users/:id' matches '/users/123'
|
|
500
|
-
* - RegExp: /^\/_auth\/.+$/ matches '/_auth/login'
|
|
501
|
-
* - Exact match: '/_auth/login' matches '/_auth/login'
|
|
502
|
-
* - All: '*' matches any path
|
|
503
|
-
*
|
|
504
|
-
* @param path - Request path to test
|
|
505
|
-
* @param pattern - Pattern to match against
|
|
506
|
-
* @returns True if path matches pattern
|
|
507
|
-
*/
|
|
508
|
-
declare function matchPath(path: string, pattern: string | RegExp): boolean;
|
|
509
|
-
/**
|
|
510
|
-
* Check if method matches pattern
|
|
511
|
-
*
|
|
512
|
-
* @param method - Request method (e.g., 'POST')
|
|
513
|
-
* @param pattern - Method pattern (e.g., 'POST' or ['POST', 'PUT'])
|
|
514
|
-
* @returns True if method matches pattern
|
|
515
|
-
*/
|
|
516
|
-
declare function matchMethod(method: string, pattern?: string | string[]): boolean;
|
|
517
|
-
/**
|
|
518
|
-
* Filter interceptors that match the request
|
|
519
|
-
*
|
|
520
|
-
* @param rules - All interceptor rules
|
|
521
|
-
* @param path - Request path
|
|
522
|
-
* @param method - Request method
|
|
523
|
-
* @returns Matched interceptors
|
|
524
|
-
*/
|
|
525
|
-
declare function filterMatchingInterceptors(rules: InterceptorRule[], path: string, method: string): InterceptorRule[];
|
|
526
|
-
/**
|
|
527
|
-
* Execute request interceptors in chain
|
|
528
|
-
*
|
|
529
|
-
* Interceptors are executed in order:
|
|
530
|
-
* 1. First registered interceptor
|
|
531
|
-
* 2. Second registered interceptor
|
|
532
|
-
* 3. ... and so on
|
|
533
|
-
*
|
|
534
|
-
* Each interceptor must call next() to continue the chain.
|
|
535
|
-
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
536
|
-
*
|
|
537
|
-
* @param context - Request interceptor context
|
|
538
|
-
* @param interceptors - Interceptors to execute
|
|
539
|
-
*/
|
|
540
|
-
declare function executeRequestInterceptors(context: RequestInterceptorContext, interceptors: RequestInterceptor[]): Promise<void>;
|
|
541
|
-
/**
|
|
542
|
-
* Execute response interceptors in chain
|
|
543
|
-
*
|
|
544
|
-
* Interceptors are executed in order:
|
|
545
|
-
* 1. First registered interceptor
|
|
546
|
-
* 2. Second registered interceptor
|
|
547
|
-
* 3. ... and so on
|
|
548
|
-
*
|
|
549
|
-
* Each interceptor must call next() to continue the chain.
|
|
550
|
-
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
551
|
-
*
|
|
552
|
-
* @param context - Response interceptor context
|
|
553
|
-
* @param interceptors - Interceptors to execute
|
|
554
|
-
*/
|
|
555
|
-
declare function executeResponseInterceptors(context: ResponseInterceptorContext, interceptors: ResponseInterceptor[]): Promise<void>;
|
|
556
|
-
|
|
557
|
-
export { DELETE, GET, type InterceptorRule, PATCH, POST, PUT, type ProxyConfig, type RequestInterceptor, type RequestInterceptorContext, type ResponseInterceptor, type ResponseInterceptorContext, createProxy, executeRequestInterceptors, executeResponseInterceptors, filterMatchingInterceptors, interceptorRegistry, matchMethod, matchPath, registerInterceptors };
|
|
583
|
+
export { type InterceptorRule, type ProxyConfig, type ProxyRequestInterceptor, type ProxyResponseInterceptor, type RequestInterceptor, type RequestInterceptorContext, type RequestInterceptorResult, type ResponseInterceptor, type ResponseInterceptorContext, type ResponseInterceptorResult, type RpcProxyConfig, type TypedProxyConfig, createRpcProxy, executeRequestInterceptors, executeResponseInterceptors, filterMatchingInterceptors, interceptorRegistry, matchMethod, matchPath, registerInterceptors };
|