@spfn/core 0.1.0-alpha.88 → 0.2.0-beta.10
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 +298 -466
- package/dist/boss-DI1r4kTS.d.ts +244 -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 +214 -17
- package/dist/codegen/index.js +231 -1420
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +1227 -0
- package/dist/config/index.js +273 -0
- package/dist/config/index.js.map +1 -0
- package/dist/db/index.d.ts +741 -59
- package/dist/db/index.js +1063 -1226
- package/dist/db/index.js.map +1 -1
- package/dist/env/index.d.ts +658 -308
- package/dist/env/index.js +503 -928
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.d.ts +87 -0
- package/dist/env/loader.js +70 -0
- package/dist/env/loader.js.map +1 -0
- 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 +41 -0
- package/dist/event/index.js +131 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/sse/client.d.ts +82 -0
- package/dist/event/sse/client.js +115 -0
- package/dist/event/sse/client.js.map +1 -0
- package/dist/event/sse/index.d.ts +40 -0
- package/dist/event/sse/index.js +92 -0
- package/dist/event/sse/index.js.map +1 -0
- package/dist/job/index.d.ts +218 -0
- package/dist/job/index.js +410 -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 +102 -20
- package/dist/middleware/index.js +51 -705
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +120 -0
- package/dist/nextjs/index.js +448 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +335 -262
- package/dist/nextjs/server.js +637 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/route/index.d.ts +879 -25
- package/dist/route/index.js +697 -1271
- package/dist/route/index.js.map +1 -1
- package/dist/route/types.d.ts +9 -0
- package/dist/route/types.js +3 -0
- package/dist/route/types.js.map +1 -0
- package/dist/router-Di7ENoah.d.ts +151 -0
- package/dist/server/index.d.ts +345 -64
- package/dist/server/index.js +1174 -3233
- package/dist/server/index.js.map +1 -1
- package/dist/types-B-e_f2dQ.d.ts +121 -0
- package/dist/types-BGl4QL1w.d.ts +77 -0
- package/dist/types-BOPTApC2.d.ts +245 -0
- package/docs/cache.md +133 -0
- package/docs/codegen.md +74 -0
- package/docs/database.md +346 -0
- package/docs/entity.md +539 -0
- package/docs/env.md +477 -0
- package/docs/errors.md +319 -0
- package/docs/event.md +116 -0
- package/docs/file-upload.md +717 -0
- package/docs/job.md +131 -0
- package/docs/logger.md +108 -0
- package/docs/middleware.md +337 -0
- package/docs/nextjs.md +241 -0
- package/docs/repository.md +496 -0
- package/docs/route.md +497 -0
- package/docs/server.md +307 -0
- package/package.json +68 -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,267 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Router, HttpMethod } from '@spfn/core/route';
|
|
3
|
+
import { InterceptorRule as InterceptorRule$1 } from '@spfn/core/nextjs/server';
|
|
4
|
+
import { f as SetCookie } from '../types-BOPTApC2.js';
|
|
5
|
+
import '@sinclair/typebox';
|
|
6
|
+
import '@spfn/core/errors';
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
|
-
*
|
|
9
|
+
* Request interceptor result
|
|
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
|
+
}
|
|
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 Using routeMap (recommended - no server code loaded)
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // app/api/rpc/[routeName]/route.ts
|
|
121
|
+
* import { routeMap } from '@/generated/route-map';
|
|
122
|
+
* import { createRpcProxy } from '@spfn/core/nextjs/proxy';
|
|
123
|
+
*
|
|
124
|
+
* export const { GET, POST } = createRpcProxy({ routeMap });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example Using router (legacy - loads full server code)
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // app/api/rpc/[routeName]/route.ts
|
|
130
|
+
* import { appRouter } from '@/server/router';
|
|
131
|
+
* import { createRpcProxy } from '@spfn/core/nextjs/proxy';
|
|
132
|
+
*
|
|
133
|
+
* export const { GET, POST } = createRpcProxy({ router: appRouter });
|
|
134
|
+
* ```
|
|
5
135
|
*/
|
|
6
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Route info from generated route map
|
|
139
|
+
*/
|
|
140
|
+
interface RouteMapEntry {
|
|
141
|
+
method: HttpMethod;
|
|
142
|
+
path: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Generated route map type
|
|
146
|
+
*/
|
|
147
|
+
type RouteMap = Record<string, RouteMapEntry>;
|
|
148
|
+
/**
|
|
149
|
+
* Base config for RPC proxy
|
|
150
|
+
*/
|
|
151
|
+
interface RpcProxyBaseConfig extends Omit<TypedProxyConfig, 'onRequest' | 'onResponse'> {
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Config using routeMap (recommended)
|
|
155
|
+
*
|
|
156
|
+
* Uses generated route map file - no server code loaded in Next.js process.
|
|
157
|
+
*/
|
|
158
|
+
interface RpcProxyRouteMapConfig extends RpcProxyBaseConfig {
|
|
159
|
+
/**
|
|
160
|
+
* Generated route map containing routeName → {method, path} mappings
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* import { routeMap } from '@/generated/route-map';
|
|
165
|
+
*
|
|
166
|
+
* export const { GET, POST } = createRpcProxy({ routeMap });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
routeMap: RouteMap;
|
|
170
|
+
router?: never;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Config using router (legacy)
|
|
174
|
+
*
|
|
175
|
+
* @deprecated Use routeMap instead to avoid loading server code in Next.js process
|
|
176
|
+
*/
|
|
177
|
+
interface RpcProxyRouterConfig<TRouter extends Router<any>> extends RpcProxyBaseConfig {
|
|
178
|
+
/**
|
|
179
|
+
* The router containing all route definitions
|
|
180
|
+
*
|
|
181
|
+
* @deprecated Use routeMap instead - router imports all server code
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* export const { GET, POST } = createRpcProxy({
|
|
186
|
+
* router: appRouter,
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
router: TRouter;
|
|
191
|
+
routeMap?: never;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Combined config type
|
|
195
|
+
*/
|
|
196
|
+
type RpcProxyConfig<TRouter extends Router<any> = Router<any>> = RpcProxyRouteMapConfig | RpcProxyRouterConfig<TRouter>;
|
|
197
|
+
/**
|
|
198
|
+
* Create RPC proxy handler for Next.js API Route
|
|
199
|
+
*
|
|
200
|
+
* Handles requests in the format:
|
|
201
|
+
* - GET /api/rpc/{routeName}?input={...}
|
|
202
|
+
* - POST /api/rpc/{routeName} with body
|
|
203
|
+
*
|
|
204
|
+
* Resolves routeName to actual HTTP method and path from the router or routeMap,
|
|
205
|
+
* then forwards to SPFN backend.
|
|
206
|
+
*/
|
|
207
|
+
declare function createRpcProxy<TRouter extends Router<any>>(config: RpcProxyConfig<TRouter>): {
|
|
208
|
+
GET: (req: NextRequest, context: {
|
|
209
|
+
params: Promise<{
|
|
210
|
+
routeName?: string;
|
|
211
|
+
}>;
|
|
212
|
+
}) => Promise<NextResponse<unknown>>;
|
|
213
|
+
POST: (req: NextRequest, context: {
|
|
214
|
+
params: Promise<{
|
|
215
|
+
routeName?: string;
|
|
216
|
+
}>;
|
|
217
|
+
}) => Promise<NextResponse<unknown>>;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Interceptor Rule
|
|
222
|
+
*
|
|
223
|
+
* Defines when and how to intercept requests/responses
|
|
224
|
+
*/
|
|
225
|
+
interface InterceptorRule {
|
|
226
|
+
/**
|
|
227
|
+
* Path pattern to match
|
|
228
|
+
*
|
|
229
|
+
* - String with wildcards: '/_auth/*', '/users/:id'
|
|
230
|
+
* - RegExp: /^\/_auth\/.+$/
|
|
231
|
+
* - '*' matches all paths
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* pathPattern: '/_auth/*' // matches /_auth/login, /_auth/register
|
|
236
|
+
* pathPattern: '/users/:id' // matches /users/123, /users/456
|
|
237
|
+
* pathPattern: /^\/_auth\/.+$/ // regex match
|
|
238
|
+
* pathPattern: '*' // matches all paths
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
pathPattern: string | RegExp;
|
|
242
|
+
/**
|
|
243
|
+
* HTTP method(s) to match (optional)
|
|
244
|
+
*
|
|
245
|
+
* - Single method: 'POST'
|
|
246
|
+
* - Multiple methods: ['POST', 'PUT']
|
|
247
|
+
* - Omit to match all methods
|
|
248
|
+
*
|
|
249
|
+
* @default undefined (matches all methods)
|
|
250
|
+
*/
|
|
251
|
+
method?: string | string[];
|
|
252
|
+
/**
|
|
253
|
+
* Request interceptor
|
|
254
|
+
*
|
|
255
|
+
* Called before SPFN API request
|
|
256
|
+
*/
|
|
257
|
+
request?: RequestInterceptor;
|
|
258
|
+
/**
|
|
259
|
+
* Response interceptor
|
|
260
|
+
*
|
|
261
|
+
* Called after SPFN API response
|
|
262
|
+
*/
|
|
263
|
+
response?: ResponseInterceptor;
|
|
264
|
+
}
|
|
7
265
|
/**
|
|
8
266
|
* Request Interceptor Context
|
|
9
267
|
*
|
|
@@ -68,6 +326,7 @@ interface ResponseInterceptorContext {
|
|
|
68
326
|
* Response data (mutable)
|
|
69
327
|
*/
|
|
70
328
|
response: {
|
|
329
|
+
ok: boolean;
|
|
71
330
|
status: number;
|
|
72
331
|
statusText: string;
|
|
73
332
|
headers: Headers;
|
|
@@ -85,18 +344,7 @@ interface ResponseInterceptorContext {
|
|
|
85
344
|
* });
|
|
86
345
|
* ```
|
|
87
346
|
*/
|
|
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
|
-
}>;
|
|
347
|
+
setCookies: SetCookie[];
|
|
100
348
|
/**
|
|
101
349
|
* Metadata shared from request interceptors
|
|
102
350
|
*/
|
|
@@ -148,51 +396,6 @@ type RequestInterceptor = (context: RequestInterceptorContext, next: () => Promi
|
|
|
148
396
|
* ```
|
|
149
397
|
*/
|
|
150
398
|
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
399
|
/**
|
|
197
400
|
* Proxy Configuration
|
|
198
401
|
*/
|
|
@@ -238,156 +441,90 @@ interface ProxyConfig {
|
|
|
238
441
|
}
|
|
239
442
|
|
|
240
443
|
/**
|
|
241
|
-
* SPFN Next.js
|
|
444
|
+
* SPFN Next.js Proxy Interceptor Execution Engine
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Check if path matches pattern
|
|
242
449
|
*
|
|
243
|
-
*
|
|
244
|
-
* -
|
|
245
|
-
* -
|
|
246
|
-
* -
|
|
450
|
+
* Supports:
|
|
451
|
+
* - Wildcards: '/_auth/*' matches '/_auth/login'
|
|
452
|
+
* - Path params: '/users/:id' matches '/users/123'
|
|
453
|
+
* - RegExp: /^\/_auth\/.+$/ matches '/_auth/login'
|
|
454
|
+
* - Exact match: '/_auth/login' matches '/_auth/login'
|
|
455
|
+
* - All: '*' matches any path
|
|
247
456
|
*
|
|
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
|
-
* ```
|
|
457
|
+
* @param path - Request path to test
|
|
458
|
+
* @param pattern - Pattern to match against
|
|
459
|
+
* @returns True if path matches pattern
|
|
269
460
|
*/
|
|
270
|
-
|
|
461
|
+
declare function matchPath(path: string, pattern: string | RegExp): boolean;
|
|
462
|
+
/**
|
|
463
|
+
* Check if method matches pattern
|
|
464
|
+
*
|
|
465
|
+
* @param method - Request method (e.g., 'POST')
|
|
466
|
+
* @param pattern - Method pattern (e.g., 'POST' or ['POST', 'PUT'])
|
|
467
|
+
* @returns True if method matches pattern
|
|
468
|
+
*/
|
|
469
|
+
declare function matchMethod(method: string, pattern?: string | string[]): boolean;
|
|
470
|
+
/**
|
|
471
|
+
* Filter interceptors that match the request
|
|
472
|
+
*
|
|
473
|
+
* @param rules - All interceptor rules
|
|
474
|
+
* @param path - Request path
|
|
475
|
+
* @param method - Request method
|
|
476
|
+
* @returns Matched interceptors
|
|
477
|
+
*/
|
|
478
|
+
declare function filterMatchingInterceptors(rules: InterceptorRule[], path: string, method: string): InterceptorRule[];
|
|
271
479
|
/**
|
|
272
|
-
*
|
|
480
|
+
* Execute request interceptors in chain
|
|
273
481
|
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
482
|
+
* Interceptors are executed in order:
|
|
483
|
+
* 1. First registered interceptor
|
|
484
|
+
* 2. Second registered interceptor
|
|
485
|
+
* 3. ... and so on
|
|
276
486
|
*
|
|
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
|
-
* ```
|
|
487
|
+
* Each interceptor must call next() to continue the chain.
|
|
488
|
+
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
489
|
+
*
|
|
490
|
+
* @param context - Request interceptor context
|
|
491
|
+
* @param interceptors - Interceptors to execute
|
|
310
492
|
*/
|
|
311
|
-
declare function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
params: Promise<{
|
|
328
|
-
path: string[];
|
|
329
|
-
}> | {
|
|
330
|
-
path: string[];
|
|
331
|
-
};
|
|
332
|
-
}) => Promise<NextResponse<unknown>>;
|
|
333
|
-
PATCH: (request: NextRequest, context: {
|
|
334
|
-
params: Promise<{
|
|
335
|
-
path: string[];
|
|
336
|
-
}> | {
|
|
337
|
-
path: string[];
|
|
338
|
-
};
|
|
339
|
-
}) => Promise<NextResponse<unknown>>;
|
|
340
|
-
DELETE: (request: NextRequest, context: {
|
|
341
|
-
params: Promise<{
|
|
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>>;
|
|
493
|
+
declare function executeRequestInterceptors(context: RequestInterceptorContext, interceptors: RequestInterceptor[]): Promise<void>;
|
|
494
|
+
/**
|
|
495
|
+
* Execute response interceptors in chain
|
|
496
|
+
*
|
|
497
|
+
* Interceptors are executed in order:
|
|
498
|
+
* 1. First registered interceptor
|
|
499
|
+
* 2. Second registered interceptor
|
|
500
|
+
* 3. ... and so on
|
|
501
|
+
*
|
|
502
|
+
* Each interceptor must call next() to continue the chain.
|
|
503
|
+
* If next() is not called, the chain stops and remaining interceptors are skipped.
|
|
504
|
+
*
|
|
505
|
+
* @param context - Response interceptor context
|
|
506
|
+
* @param interceptors - Interceptors to execute
|
|
507
|
+
*/
|
|
508
|
+
declare function executeResponseInterceptors(context: ResponseInterceptorContext, interceptors: ResponseInterceptor[]): Promise<void>;
|
|
383
509
|
|
|
384
510
|
/**
|
|
385
511
|
* Global Interceptor Registry
|
|
386
512
|
*
|
|
387
513
|
* Allows packages to automatically register their interceptors
|
|
388
514
|
* for Next.js proxy without manual configuration.
|
|
515
|
+
*
|
|
516
|
+
* Uses globalThis for persistence across module reloads (HMR).
|
|
389
517
|
*/
|
|
390
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Extend globalThis with interceptor registry
|
|
521
|
+
*
|
|
522
|
+
* Using globalThis allows the registry to persist across module reloads (HMR).
|
|
523
|
+
* preventing duplicate registrations during development with HMR.
|
|
524
|
+
*/
|
|
525
|
+
declare global {
|
|
526
|
+
var __SPFN_INTERCEPTOR_REGISTRY__: InterceptorRegistry | undefined;
|
|
527
|
+
}
|
|
391
528
|
/**
|
|
392
529
|
* Global interceptor registry
|
|
393
530
|
*
|
|
@@ -454,6 +591,9 @@ declare class InterceptorRegistry {
|
|
|
454
591
|
}
|
|
455
592
|
/**
|
|
456
593
|
* Global singleton registry instance
|
|
594
|
+
*
|
|
595
|
+
* Uses globalThis to persist across module reloads (HMR).
|
|
596
|
+
* This prevents duplicate registrations during development.
|
|
457
597
|
*/
|
|
458
598
|
declare const interceptorRegistry: InterceptorRegistry;
|
|
459
599
|
/**
|
|
@@ -468,7 +608,7 @@ declare const interceptorRegistry: InterceptorRegistry;
|
|
|
468
608
|
* @example
|
|
469
609
|
* ```typescript
|
|
470
610
|
* // packages/auth/src/adapters/nextjs/interceptors/index.ts
|
|
471
|
-
* import { registerInterceptors } from '@spfn/core/
|
|
611
|
+
* import { registerInterceptors } from '@spfn/core/nextjs';
|
|
472
612
|
*
|
|
473
613
|
* const authInterceptors = [
|
|
474
614
|
* {
|
|
@@ -487,71 +627,4 @@ declare const interceptorRegistry: InterceptorRegistry;
|
|
|
487
627
|
*/
|
|
488
628
|
declare function registerInterceptors(packageName: string, interceptors: InterceptorRule[]): void;
|
|
489
629
|
|
|
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 };
|
|
630
|
+
export { type InterceptorRule, type ProxyConfig, type RequestInterceptor, type RequestInterceptorContext, type ResponseInterceptor, type ResponseInterceptorContext, type RpcProxyConfig, createRpcProxy, executeRequestInterceptors, executeResponseInterceptors, filterMatchingInterceptors, interceptorRegistry, matchMethod, matchPath, registerInterceptors };
|