@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.
Files changed (97) hide show
  1. package/README.md +298 -466
  2. package/dist/boss-DI1r4kTS.d.ts +244 -0
  3. package/dist/cache/index.d.ts +13 -33
  4. package/dist/cache/index.js +14 -703
  5. package/dist/cache/index.js.map +1 -1
  6. package/dist/codegen/index.d.ts +214 -17
  7. package/dist/codegen/index.js +231 -1420
  8. package/dist/codegen/index.js.map +1 -1
  9. package/dist/config/index.d.ts +1227 -0
  10. package/dist/config/index.js +273 -0
  11. package/dist/config/index.js.map +1 -0
  12. package/dist/db/index.d.ts +741 -59
  13. package/dist/db/index.js +1063 -1226
  14. package/dist/db/index.js.map +1 -1
  15. package/dist/env/index.d.ts +658 -308
  16. package/dist/env/index.js +503 -928
  17. package/dist/env/index.js.map +1 -1
  18. package/dist/env/loader.d.ts +87 -0
  19. package/dist/env/loader.js +70 -0
  20. package/dist/env/loader.js.map +1 -0
  21. package/dist/errors/index.d.ts +417 -29
  22. package/dist/errors/index.js +359 -98
  23. package/dist/errors/index.js.map +1 -1
  24. package/dist/event/index.d.ts +41 -0
  25. package/dist/event/index.js +131 -0
  26. package/dist/event/index.js.map +1 -0
  27. package/dist/event/sse/client.d.ts +82 -0
  28. package/dist/event/sse/client.js +115 -0
  29. package/dist/event/sse/client.js.map +1 -0
  30. package/dist/event/sse/index.d.ts +40 -0
  31. package/dist/event/sse/index.js +92 -0
  32. package/dist/event/sse/index.js.map +1 -0
  33. package/dist/job/index.d.ts +218 -0
  34. package/dist/job/index.js +410 -0
  35. package/dist/job/index.js.map +1 -0
  36. package/dist/logger/index.d.ts +20 -79
  37. package/dist/logger/index.js +82 -387
  38. package/dist/logger/index.js.map +1 -1
  39. package/dist/middleware/index.d.ts +102 -20
  40. package/dist/middleware/index.js +51 -705
  41. package/dist/middleware/index.js.map +1 -1
  42. package/dist/nextjs/index.d.ts +120 -0
  43. package/dist/nextjs/index.js +448 -0
  44. package/dist/nextjs/index.js.map +1 -0
  45. package/dist/{client/nextjs/index.d.ts → nextjs/server.d.ts} +335 -262
  46. package/dist/nextjs/server.js +637 -0
  47. package/dist/nextjs/server.js.map +1 -0
  48. package/dist/route/index.d.ts +879 -25
  49. package/dist/route/index.js +697 -1271
  50. package/dist/route/index.js.map +1 -1
  51. package/dist/route/types.d.ts +9 -0
  52. package/dist/route/types.js +3 -0
  53. package/dist/route/types.js.map +1 -0
  54. package/dist/router-Di7ENoah.d.ts +151 -0
  55. package/dist/server/index.d.ts +345 -64
  56. package/dist/server/index.js +1174 -3233
  57. package/dist/server/index.js.map +1 -1
  58. package/dist/types-B-e_f2dQ.d.ts +121 -0
  59. package/dist/types-BGl4QL1w.d.ts +77 -0
  60. package/dist/types-BOPTApC2.d.ts +245 -0
  61. package/docs/cache.md +133 -0
  62. package/docs/codegen.md +74 -0
  63. package/docs/database.md +346 -0
  64. package/docs/entity.md +539 -0
  65. package/docs/env.md +477 -0
  66. package/docs/errors.md +319 -0
  67. package/docs/event.md +116 -0
  68. package/docs/file-upload.md +717 -0
  69. package/docs/job.md +131 -0
  70. package/docs/logger.md +108 -0
  71. package/docs/middleware.md +337 -0
  72. package/docs/nextjs.md +241 -0
  73. package/docs/repository.md +496 -0
  74. package/docs/route.md +497 -0
  75. package/docs/server.md +307 -0
  76. package/package.json +68 -48
  77. package/dist/auto-loader-JFaZ9gON.d.ts +0 -80
  78. package/dist/client/index.d.ts +0 -358
  79. package/dist/client/index.js +0 -357
  80. package/dist/client/index.js.map +0 -1
  81. package/dist/client/nextjs/index.js +0 -371
  82. package/dist/client/nextjs/index.js.map +0 -1
  83. package/dist/codegen/generators/index.d.ts +0 -19
  84. package/dist/codegen/generators/index.js +0 -1404
  85. package/dist/codegen/generators/index.js.map +0 -1
  86. package/dist/database-errors-BNNmLTJE.d.ts +0 -86
  87. package/dist/events/index.d.ts +0 -183
  88. package/dist/events/index.js +0 -77
  89. package/dist/events/index.js.map +0 -1
  90. package/dist/index-DHiAqhKv.d.ts +0 -101
  91. package/dist/index.d.ts +0 -8
  92. package/dist/index.js +0 -3674
  93. package/dist/index.js.map +0 -1
  94. package/dist/types/index.d.ts +0 -121
  95. package/dist/types/index.js +0 -38
  96. package/dist/types/index.js.map +0 -1
  97. 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
- * SPFN Next.js Proxy Interceptor Types
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: Array<{
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 API Route Proxy with Interceptor Pattern
444
+ * SPFN Next.js Proxy Interceptor Execution Engine
445
+ */
446
+
447
+ /**
448
+ * Check if path matches pattern
242
449
  *
243
- * Automatically proxies requests to SPFN API server with:
244
- * - Cookie forwarding
245
- * - Request/Response interceptors
246
- * - Flexible header manipulation
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
- * Usage:
249
- * ```typescript
250
- * // Basic usage (no interceptors)
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
- * Create proxy with custom configuration and interceptors
480
+ * Execute request interceptors in chain
273
481
  *
274
- * @param config - Proxy configuration with interceptors
275
- * @returns HTTP method handlers for Next.js API routes
482
+ * Interceptors are executed in order:
483
+ * 1. First registered interceptor
484
+ * 2. Second registered interceptor
485
+ * 3. ... and so on
276
486
  *
277
- * @example
278
- * ```typescript
279
- * // app/api/actions/[...path]/route.ts
280
- * import { createProxy } from '@spfn/core/nextjs';
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 createProxy(config?: ProxyConfig): {
312
- GET: (request: NextRequest, context: {
313
- params: Promise<{
314
- path: string[];
315
- }> | {
316
- path: string[];
317
- };
318
- }) => Promise<NextResponse<unknown>>;
319
- POST: (request: NextRequest, context: {
320
- params: Promise<{
321
- path: string[];
322
- }> | {
323
- path: string[];
324
- };
325
- }) => Promise<NextResponse<unknown>>;
326
- PUT: (request: NextRequest, context: {
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/client/nextjs';
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 };