blaizejs 0.4.0 → 0.5.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.
Files changed (27) hide show
  1. package/dist/{chunk-LMTJAVHX.js → chunk-6G464Q37.js} +3 -3
  2. package/dist/{chunk-ORFAFXHX.js → chunk-NA2GUVHF.js} +3 -3
  3. package/dist/chunk-VAD7G4RR.js +11 -0
  4. package/dist/chunk-VAD7G4RR.js.map +1 -0
  5. package/dist/{chunk-LI53MJIF.js → chunk-XZOKQ5VF.js} +3 -3
  6. package/dist/{chunk-N7F6OHDX.js → chunk-Y7KAZMOI.js} +3 -3
  7. package/dist/index.cjs +22 -9
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +1046 -7
  10. package/dist/index.d.ts +1046 -7
  11. package/dist/index.js +22 -9
  12. package/dist/index.js.map +1 -1
  13. package/dist/{internal-server-error-DAEFNRNG.js → internal-server-error-4S64KATC.js} +3 -3
  14. package/dist/{payload-too-large-error-YO3MSQJF.js → payload-too-large-error-BC6YVP2R.js} +3 -3
  15. package/dist/{unsupported-media-type-error-GW2UC37Q.js → unsupported-media-type-error-FV554WCH.js} +3 -3
  16. package/dist/{validation-error-SJTLEIZZ.js → validation-error-ZLDRDHW5.js} +3 -3
  17. package/package.json +4 -4
  18. package/dist/chunk-GP5NAYQS.js +0 -11
  19. package/dist/chunk-GP5NAYQS.js.map +0 -1
  20. /package/dist/{chunk-LMTJAVHX.js.map → chunk-6G464Q37.js.map} +0 -0
  21. /package/dist/{chunk-ORFAFXHX.js.map → chunk-NA2GUVHF.js.map} +0 -0
  22. /package/dist/{chunk-LI53MJIF.js.map → chunk-XZOKQ5VF.js.map} +0 -0
  23. /package/dist/{chunk-N7F6OHDX.js.map → chunk-Y7KAZMOI.js.map} +0 -0
  24. /package/dist/{internal-server-error-DAEFNRNG.js.map → internal-server-error-4S64KATC.js.map} +0 -0
  25. /package/dist/{payload-too-large-error-YO3MSQJF.js.map → payload-too-large-error-BC6YVP2R.js.map} +0 -0
  26. /package/dist/{unsupported-media-type-error-GW2UC37Q.js.map → unsupported-media-type-error-FV554WCH.js.map} +0 -0
  27. /package/dist/{validation-error-SJTLEIZZ.js.map → validation-error-ZLDRDHW5.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -135,6 +135,16 @@ interface ValidationFieldError {
135
135
  /** Expected type or format */
136
136
  expectedType?: string;
137
137
  }
138
+ interface ServiceNotAvailableDetails {
139
+ /** Service that's unavailable */
140
+ service?: string;
141
+ /** Seconds to wait before retry */
142
+ retryAfter?: number;
143
+ /** Why service is unavailable */
144
+ reason?: 'maintenance' | 'overload' | 'circuit_breaker' | 'dependency_down';
145
+ /** Additional context */
146
+ [key: string]: unknown;
147
+ }
138
148
  /**
139
149
  * Validation error details structure
140
150
  *
@@ -181,6 +191,8 @@ declare enum ErrorType {
181
191
  UNAUTHORIZED = "UNAUTHORIZED",
182
192
  /** Access forbidden (403) */
183
193
  FORBIDDEN = "FORBIDDEN",
194
+ /** SSE Not Acceptable (406) */
195
+ SSE_NOT_ACCEPTABLE = "SSE_NOT_ACCEPTABLE",
184
196
  /** Resource conflict (409) */
185
197
  CONFLICT = "CONFLICT",
186
198
  /** Rate limit exceeded (429) */
@@ -202,7 +214,15 @@ declare enum ErrorType {
202
214
  /** Response parsing failure (0) */
203
215
  PARSE_ERROR = "PARSE_ERROR",
204
216
  /** Generic HTTP error (varies) */
205
- HTTP_ERROR = "HTTP_ERROR"
217
+ HTTP_ERROR = "HTTP_ERROR",
218
+ /** SSE connection failed (502) */
219
+ SSE_CONNECTION_ERROR = "SSE_CONNECTION_ERROR",
220
+ /** SSE buffer overflow (503) */
221
+ SSE_BUFFER_OVERFLOW = "SSE_BUFFER_OVERFLOW",
222
+ /** SSE stream closed (410) */
223
+ SSE_STREAM_CLOSED = "SSE_STREAM_CLOSED",
224
+ /** Service temporarily unavailable (503) */
225
+ SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE"
206
226
  }
207
227
  /**
208
228
  * Error severity levels for logging and monitoring
@@ -357,7 +377,7 @@ interface ForbiddenErrorDetails {
357
377
  /** Action being attempted */
358
378
  action?: string;
359
379
  /** Reason for access denial */
360
- reason?: 'insufficient_permissions' | 'account_suspended' | 'resource_locked' | string;
380
+ reason?: 'insufficient_permissions' | 'account_suspended' | 'resource_locked' | 'origin_not_allowed' | string;
361
381
  /** Additional context */
362
382
  [key: string]: unknown;
363
383
  }
@@ -492,6 +512,115 @@ interface ErrorTransformContext {
492
512
  responseSample?: string;
493
513
  [key: string]: unknown;
494
514
  }
515
+ /**
516
+ * SSE-specific error detail interfaces for BlaizeJS framework
517
+ *
518
+ * These interfaces define the structure of details for SSE errors.
519
+ * The actual error classes are implemented in blaize-core.
520
+ */
521
+ /**
522
+ * Details for SSE connection errors
523
+ */
524
+ interface SSEConnectionErrorDetails {
525
+ /** Client identifier if available */
526
+ clientId?: string;
527
+ /** Connection attempt number */
528
+ attemptNumber?: number;
529
+ /** Maximum retry attempts configured */
530
+ maxRetries?: number;
531
+ /** The underlying error that caused connection failure */
532
+ cause?: string;
533
+ /** Suggested resolution */
534
+ suggestion?: string;
535
+ }
536
+ /**
537
+ * Details for SSE buffer overflow errors
538
+ */
539
+ interface SSEBufferOverflowErrorDetails {
540
+ /** Client identifier */
541
+ clientId?: string;
542
+ /** Current buffer size when overflow occurred */
543
+ currentSize: number;
544
+ /** Maximum buffer size configured */
545
+ maxSize: number;
546
+ /** Number of events dropped */
547
+ eventsDropped?: number;
548
+ /** Buffer strategy that was applied */
549
+ strategy: 'drop-oldest' | 'drop-newest' | 'close';
550
+ /** Event that triggered the overflow */
551
+ triggeringEvent?: string;
552
+ }
553
+ /**
554
+ * Details for SSE stream closed errors
555
+ */
556
+ interface SSEStreamClosedErrorDetails {
557
+ /** Client identifier */
558
+ clientId?: string;
559
+ /** When the stream was closed */
560
+ closedAt?: string;
561
+ /** Reason for closure */
562
+ closeReason?: 'client-disconnect' | 'server-close' | 'timeout' | 'error' | 'buffer-overflow';
563
+ /** Whether reconnection is possible */
564
+ canReconnect?: boolean;
565
+ /** Suggested retry interval in milliseconds */
566
+ retryAfter?: number;
567
+ }
568
+ /**
569
+ * Context for SSE connection errors
570
+ */
571
+ interface SSEConnectionErrorContext {
572
+ /** The SSE endpoint URL */
573
+ url: string;
574
+ /** Correlation ID for tracing */
575
+ correlationId: string;
576
+ /** Connection state when error occurred */
577
+ state: 'connecting' | 'connected' | 'disconnected' | 'closed';
578
+ /** Number of reconnection attempts made */
579
+ reconnectAttempts?: number;
580
+ /** The original error if available */
581
+ originalError?: Error;
582
+ /** Additional SSE-specific details */
583
+ sseDetails?: {
584
+ /** Whether credentials were included */
585
+ withCredentials?: boolean;
586
+ /** Last received event ID */
587
+ lastEventId?: string;
588
+ /** EventSource ready state */
589
+ readyState?: number;
590
+ };
591
+ }
592
+ /**
593
+ * Context for SSE stream errors (server-sent errors)
594
+ */
595
+ interface SSEStreamErrorContext {
596
+ /** The SSE endpoint URL */
597
+ url: string;
598
+ /** Correlation ID from server or client */
599
+ correlationId: string;
600
+ /** Error message from server */
601
+ message: string;
602
+ /** Error code if provided */
603
+ code?: string;
604
+ /** Error name/type from server */
605
+ name?: string;
606
+ /** Raw error data from server */
607
+ rawData?: any;
608
+ }
609
+ /**
610
+ * Context for SSE heartbeat timeout errors
611
+ */
612
+ interface SSEHeartbeatErrorContext {
613
+ /** The SSE endpoint URL */
614
+ url: string;
615
+ /** Correlation ID for tracing */
616
+ correlationId: string;
617
+ /** Configured heartbeat timeout in ms */
618
+ heartbeatTimeout: number;
619
+ /** Time since last event in ms */
620
+ timeSinceLastEvent?: number;
621
+ /** Last event ID received */
622
+ lastEventId?: string;
623
+ }
495
624
 
496
625
  /**
497
626
  * Represents an uploaded file in a multipart/form-data request
@@ -1251,6 +1380,295 @@ type CreateOptionsRoute = <TState extends State = State, TServices extends Servi
1251
1380
  */
1252
1381
  declare function compose(middlewareStack: Middleware[]): MiddlewareFunction;
1253
1382
 
1383
+ /**
1384
+ * CORS Types for BlaizeJS Framework
1385
+ *
1386
+ * Comprehensive type definitions for W3C-compliant CORS middleware
1387
+ * with support for string, regex, and async function origin validation.
1388
+ *
1389
+ * @module @blaizejs/types/cors
1390
+ */
1391
+
1392
+ /**
1393
+ * Origin configuration type supporting multiple validation methods
1394
+ *
1395
+ * @example
1396
+ * ```typescript
1397
+ * // String origin (exact match)
1398
+ * const origin: CorsOrigin = 'https://example.com';
1399
+ *
1400
+ * // RegExp pattern
1401
+ * const origin: CorsOrigin = /^https:\/\/.*\.example\.com$/;
1402
+ *
1403
+ * // Dynamic validation function
1404
+ * const origin: CorsOrigin = async (origin, ctx) => {
1405
+ * return await checkOriginAllowed(origin, ctx?.state.user);
1406
+ * };
1407
+ *
1408
+ * // Array of mixed types
1409
+ * const origin: CorsOrigin = [
1410
+ * 'https://localhost:3000',
1411
+ * /^https:\/\/.*\.example\.com$/,
1412
+ * (origin) => origin.endsWith('.trusted.com')
1413
+ * ];
1414
+ * ```
1415
+ */
1416
+ type CorsOrigin = string | RegExp | ((origin: string, ctx?: Context<any, any>) => boolean | Promise<boolean>) | Array<string | RegExp | ((origin: string, ctx?: Context<any, any>) => boolean | Promise<boolean>)>;
1417
+ /**
1418
+ * HTTP methods that can be allowed in CORS
1419
+ * Based on W3C CORS specification
1420
+ */
1421
+ type CorsHttpMethod = HttpMethod | 'CONNECT' | 'TRACE';
1422
+ /**
1423
+ * Main CORS configuration options
1424
+ *
1425
+ * @example
1426
+ * ```typescript
1427
+ * const corsOptions: CorsOptions = {
1428
+ * origin: 'https://example.com',
1429
+ * methods: ['GET', 'POST'],
1430
+ * credentials: true,
1431
+ * maxAge: 86400
1432
+ * };
1433
+ * ```
1434
+ */
1435
+ interface CorsOptions {
1436
+ /**
1437
+ * Configures the Access-Control-Allow-Origin header
1438
+ *
1439
+ * Possible values:
1440
+ * - `true`: Allow all origins (sets to '*' unless credentials is true, then reflects origin)
1441
+ * - `false`: Disable CORS (no headers set)
1442
+ * - `string`: Specific origin to allow
1443
+ * - `RegExp`: Pattern to match origins
1444
+ * - `function`: Custom validation logic
1445
+ * - `array`: Multiple origin configurations
1446
+ *
1447
+ * @default false
1448
+ */
1449
+ origin?: boolean | CorsOrigin;
1450
+ /**
1451
+ * Configures the Access-Control-Allow-Methods header
1452
+ *
1453
+ * @default ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE']
1454
+ * @example ['GET', 'POST']
1455
+ */
1456
+ methods?: CorsHttpMethod[] | string;
1457
+ /**
1458
+ * Configures the Access-Control-Allow-Headers header
1459
+ *
1460
+ * Pass an array of allowed headers or a comma-delimited string.
1461
+ *
1462
+ * @default Request's Access-Control-Request-Headers header value
1463
+ * @example ['Content-Type', 'Authorization']
1464
+ */
1465
+ allowedHeaders?: string[] | string;
1466
+ /**
1467
+ * Configures the Access-Control-Expose-Headers header
1468
+ *
1469
+ * Headers that the browser is allowed to access.
1470
+ *
1471
+ * @default []
1472
+ * @example ['Content-Range', 'X-Content-Range']
1473
+ */
1474
+ exposedHeaders?: string[] | string;
1475
+ /**
1476
+ * Configures the Access-Control-Allow-Credentials header
1477
+ *
1478
+ * Set to true to allow credentials (cookies, authorization headers, TLS client certificates).
1479
+ * Note: Cannot be used with origin: '*' for security reasons.
1480
+ *
1481
+ * @default false
1482
+ */
1483
+ credentials?: boolean;
1484
+ /**
1485
+ * Configures the Access-Control-Max-Age header in seconds
1486
+ *
1487
+ * Indicates how long browsers can cache preflight response.
1488
+ * Set to -1 to disable caching.
1489
+ *
1490
+ * @default undefined (browser decides)
1491
+ * @example 86400 // 24 hours
1492
+ */
1493
+ maxAge?: number;
1494
+ /**
1495
+ * Whether to pass the CORS preflight response to the next handler
1496
+ *
1497
+ * When false, the preflight response is sent immediately.
1498
+ * When true, control passes to the next middleware/handler.
1499
+ *
1500
+ * @default false
1501
+ */
1502
+ preflightContinue?: boolean;
1503
+ /**
1504
+ * HTTP status code for successful OPTIONS requests
1505
+ *
1506
+ * Some legacy browsers require 200, while 204 is more correct.
1507
+ *
1508
+ * @default 204
1509
+ */
1510
+ optionsSuccessStatus?: number;
1511
+ }
1512
+ /**
1513
+ * Internal CORS validation result
1514
+ * Used by middleware implementation
1515
+ */
1516
+ interface CorsValidationResult {
1517
+ /**
1518
+ * Whether the origin is allowed
1519
+ */
1520
+ allowed: boolean;
1521
+ /**
1522
+ * The origin value to set in the header
1523
+ * Can be '*', specific origin, or 'null'
1524
+ */
1525
+ origin?: string;
1526
+ /**
1527
+ * Whether to add Vary: Origin header
1528
+ */
1529
+ vary?: boolean;
1530
+ }
1531
+ /**
1532
+ * CORS preflight request information
1533
+ * Extracted from OPTIONS request headers
1534
+ */
1535
+ interface CorsPreflightInfo {
1536
+ /**
1537
+ * The origin making the request
1538
+ */
1539
+ origin?: string;
1540
+ /**
1541
+ * The method that will be used in the actual request
1542
+ * From Access-Control-Request-Method header
1543
+ */
1544
+ requestedMethod?: string;
1545
+ /**
1546
+ * The headers that will be sent in the actual request
1547
+ * From Access-Control-Request-Headers header
1548
+ */
1549
+ requestedHeaders?: string[];
1550
+ }
1551
+ /**
1552
+ * Cache entry for origin validation results
1553
+ * Used for performance optimization
1554
+ */
1555
+ interface CorsOriginCacheEntry {
1556
+ /**
1557
+ * Whether the origin is allowed
1558
+ */
1559
+ allowed: boolean;
1560
+ /**
1561
+ * When this cache entry expires (timestamp)
1562
+ */
1563
+ expiresAt: number;
1564
+ /**
1565
+ * Optional user identifier for cache key
1566
+ */
1567
+ userId?: string;
1568
+ }
1569
+ /**
1570
+ * Configuration for CORS origin validation cache
1571
+ */
1572
+ interface CorsOriginCacheConfig {
1573
+ /**
1574
+ * Time-to-live for cache entries in milliseconds
1575
+ * @default 60000 (1 minute)
1576
+ */
1577
+ ttl?: number;
1578
+ /**
1579
+ * Maximum number of entries in the cache
1580
+ * @default 1000
1581
+ */
1582
+ maxSize?: number;
1583
+ /**
1584
+ * Whether to include user ID in cache key
1585
+ * @default true
1586
+ */
1587
+ includeUserId?: boolean;
1588
+ }
1589
+ /**
1590
+ * Statistics for CORS middleware performance monitoring
1591
+ */
1592
+ interface CorsStats {
1593
+ /**
1594
+ * Total number of CORS requests processed
1595
+ */
1596
+ totalRequests: number;
1597
+ /**
1598
+ * Number of preflight requests handled
1599
+ */
1600
+ preflightRequests: number;
1601
+ /**
1602
+ * Number of allowed origins
1603
+ */
1604
+ allowedOrigins: number;
1605
+ /**
1606
+ * Number of denied origins
1607
+ */
1608
+ deniedOrigins: number;
1609
+ /**
1610
+ * Cache hit rate for origin validation
1611
+ */
1612
+ cacheHitRate: number;
1613
+ /**
1614
+ * Average origin validation time in milliseconds
1615
+ */
1616
+ avgValidationTime: number;
1617
+ }
1618
+ /**
1619
+ * Cache entry type
1620
+ */
1621
+ interface CacheEntry {
1622
+ allowed: boolean;
1623
+ expiresAt: number;
1624
+ lastAccessed: number;
1625
+ }
1626
+ /**
1627
+ * Cache configuration
1628
+ */
1629
+ interface CacheConfig {
1630
+ ttl: number;
1631
+ maxSize: number;
1632
+ }
1633
+
1634
+ /**
1635
+ * Create CORS middleware with the specified options
1636
+ *
1637
+ * @param userOptions - CORS configuration options or boolean
1638
+ * @returns Middleware function that handles CORS
1639
+ *
1640
+ * @example
1641
+ * ```typescript
1642
+ * import { cors } from '@blaize-core/middleware/cors';
1643
+ *
1644
+ * // Development mode - allow all origins
1645
+ * server.use(cors(true));
1646
+ *
1647
+ * // Production - specific origin
1648
+ * server.use(cors({
1649
+ * origin: 'https://app.example.com',
1650
+ * credentials: true,
1651
+ * maxAge: 86400
1652
+ * }));
1653
+ *
1654
+ * // Multiple origins with regex
1655
+ * server.use(cors({
1656
+ * origin: [
1657
+ * 'https://app.example.com',
1658
+ * /^https:\/\/.*\.example\.com$/
1659
+ * ]
1660
+ * }));
1661
+ *
1662
+ * // Dynamic origin validation
1663
+ * server.use(cors({
1664
+ * origin: async (origin, ctx) => {
1665
+ * return await checkOriginAllowed(origin, ctx.state.user);
1666
+ * }
1667
+ * }));
1668
+ * ```
1669
+ */
1670
+ declare function cors(userOptions?: CorsOptions | boolean): Middleware;
1671
+
1254
1672
  /**
1255
1673
  * Create a middleware
1256
1674
  */
@@ -1276,6 +1694,438 @@ declare function stateMiddleware<T = {}>(handler: MiddlewareFunction): Middlewar
1276
1694
  */
1277
1695
  declare function serviceMiddleware<T = {}>(handler: MiddlewareFunction): Middleware<{}, T>;
1278
1696
 
1697
+ /**
1698
+ * Represents a single Server-Sent Event
1699
+ * @template T - The type of data payload
1700
+ *
1701
+ * @example
1702
+ * ```typescript
1703
+ * const event: SSEEvent<{ message: string }> = {
1704
+ * id: '123',
1705
+ * event: 'message',
1706
+ * data: { message: 'Hello, world!' },
1707
+ * retry: 5000
1708
+ * };
1709
+ * ```
1710
+ */
1711
+ interface SSEEvent<T = unknown> {
1712
+ /** Unique identifier for the event */
1713
+ id: string;
1714
+ /** Event type/name for client-side event listeners */
1715
+ event: string;
1716
+ /** The actual data payload of the event */
1717
+ data: T;
1718
+ /** Optional retry interval in milliseconds for reconnection */
1719
+ retry?: number;
1720
+ }
1721
+ /**
1722
+ * Backpressure handling strategies for SSE streams
1723
+ *
1724
+ * - `drop-oldest`: Remove oldest events from buffer when full
1725
+ * - `drop-newest`: Reject new events when buffer is full
1726
+ * - `close`: Close the stream when buffer limit is reached
1727
+ */
1728
+ type SSEBufferStrategy = 'drop-oldest' | 'drop-newest' | 'close';
1729
+ /**
1730
+ * Configuration options for SSE streams
1731
+ *
1732
+ * @example
1733
+ * ```typescript
1734
+ * const options: SSEOptions = {
1735
+ * autoClose: true,
1736
+ * maxBufferSize: 100,
1737
+ * bufferStrategy: 'drop-oldest'
1738
+ * };
1739
+ * ```
1740
+ */
1741
+ interface SSEOptions {
1742
+ /** ms between heartbeat pings (0 to disable) */
1743
+ heartbeatInterval?: number;
1744
+ /** Maximum size in bytes for a single event */
1745
+ maxEventSize?: number;
1746
+ /** Automatically close stream when client disconnects */
1747
+ autoClose?: boolean;
1748
+ /** Maximum number of events to buffer before applying strategy */
1749
+ maxBufferSize?: number;
1750
+ /** Strategy to handle buffer overflow conditions */
1751
+ bufferStrategy?: SSEBufferStrategy;
1752
+ }
1753
+ /**
1754
+ * Connection states for SSE streams
1755
+ */
1756
+ type SSEConnectionState = 'connecting' | 'connected' | 'disconnected' | 'closed';
1757
+ /**
1758
+ * SSE stream interface for managing server-sent events
1759
+ *
1760
+ * @example
1761
+ * ```typescript
1762
+ * const stream: SSEStream = createSSEStream(response);
1763
+ *
1764
+ * // Send typed event
1765
+ * stream.send('notification', { type: 'info', message: 'Update available' });
1766
+ *
1767
+ * // Send error event
1768
+ * stream.sendError(new Error('Processing failed'));
1769
+ *
1770
+ * // Clean up on close
1771
+ * stream.onClose(() => {
1772
+ * console.log('Client disconnected');
1773
+ * });
1774
+ *
1775
+ * // Close stream
1776
+ * stream.close();
1777
+ * ```
1778
+ */
1779
+ interface SSEStream {
1780
+ /**
1781
+ * Send an event with typed data to the client
1782
+ * @template T - Type of the data payload
1783
+ * @param event - Event name/type
1784
+ * @param data - Event data payload
1785
+ */
1786
+ send<T>(event: string, data: T): void;
1787
+ /**
1788
+ * Send an error event to the client
1789
+ * @param error - Error object to send
1790
+ */
1791
+ sendError(error: Error): void;
1792
+ /**
1793
+ * Close the SSE stream connection
1794
+ */
1795
+ close(): void;
1796
+ /**
1797
+ * Register a callback for stream closure
1798
+ * @param cb - Callback function to execute on close
1799
+ */
1800
+ onClose(cb: () => void): void;
1801
+ }
1802
+ /**
1803
+ * Extended SSE stream with additional control methods
1804
+ */
1805
+ interface SSEStreamExtended extends SSEStream {
1806
+ readonly id: string;
1807
+ [Symbol.asyncIterator](): AsyncGenerator<BufferedEvent, void, unknown>;
1808
+ /** Current connection state */
1809
+ readonly state: SSEConnectionState;
1810
+ /** Number of events in the buffer */
1811
+ readonly bufferSize: number;
1812
+ /** Check if stream is writable */
1813
+ readonly isWritable: boolean;
1814
+ /**
1815
+ * Ping the client to keep connection alive
1816
+ * @param comment - Optional comment to include in ping
1817
+ */
1818
+ ping(comment?: string): void;
1819
+ /**
1820
+ * Set retry interval for client reconnection
1821
+ * @param milliseconds - Retry interval in milliseconds
1822
+ */
1823
+ setRetry(milliseconds: number): void;
1824
+ /**
1825
+ * Flush any buffered events immediately
1826
+ */
1827
+ flush(): void;
1828
+ getMetrics(): StreamMetrics;
1829
+ }
1830
+ /**
1831
+ * SSE event serialization format
1832
+ */
1833
+ interface SSESerializedEvent {
1834
+ /** Event ID field */
1835
+ id?: string;
1836
+ /** Event type field */
1837
+ event?: string;
1838
+ /** Data field (can be multi-line) */
1839
+ data: string;
1840
+ /** Retry field */
1841
+ retry?: number;
1842
+ /** Comment field for keep-alive */
1843
+ comment?: string;
1844
+ }
1845
+ /**
1846
+ * SSE event handler function type
1847
+ * @template T - Type of the event data
1848
+ */
1849
+ type SSEEventHandler<T = unknown> = (event: SSEEvent<T>) => void | Promise<void>;
1850
+ /**
1851
+ * SSE event listener registration
1852
+ */
1853
+ interface SSEEventListener {
1854
+ /** Event type to listen for (use '*' for all events) */
1855
+ event: string;
1856
+ /** Handler function for the event */
1857
+ handler: SSEEventHandler;
1858
+ /** Optional listener identifier for removal */
1859
+ id?: string;
1860
+ }
1861
+ /**
1862
+ * SSE metrics for monitoring stream performance
1863
+ */
1864
+ interface SSEMetrics {
1865
+ /** Total number of events sent */
1866
+ eventsSent: number;
1867
+ /** Total number of events dropped */
1868
+ eventsDropped: number;
1869
+ /** Current number of connected clients */
1870
+ activeConnections: number;
1871
+ /** Total bytes sent */
1872
+ bytesSent: number;
1873
+ /** Average event send latency in milliseconds */
1874
+ averageLatency: number;
1875
+ /** Connection duration in milliseconds */
1876
+ connectionDuration: number;
1877
+ }
1878
+ /**
1879
+ * SSE stream manager for handling multiple clients
1880
+ */
1881
+ interface SSEStreamManager {
1882
+ /**
1883
+ * Create a new SSE stream for a client
1884
+ * @param clientId - Unique identifier for the client
1885
+ * @param options - Stream configuration options
1886
+ */
1887
+ createStream(clientId: string, options?: SSEOptions): SSEStream;
1888
+ /**
1889
+ * Get an existing stream by client ID
1890
+ * @param clientId - Client identifier
1891
+ */
1892
+ getStream(clientId: string): SSEStream | undefined;
1893
+ /**
1894
+ * Broadcast an event to all connected clients
1895
+ * @template T - Type of the event data
1896
+ * @param event - Event name
1897
+ * @param data - Event data
1898
+ */
1899
+ broadcast<T>(event: string, data: T): void;
1900
+ /**
1901
+ * Broadcast to specific clients
1902
+ * @template T - Type of the event data
1903
+ * @param clientIds - Array of client IDs
1904
+ * @param event - Event name
1905
+ * @param data - Event data
1906
+ */
1907
+ multicast<T>(clientIds: string[], event: string, data: T): void;
1908
+ /**
1909
+ * Close a specific client stream
1910
+ * @param clientId - Client identifier
1911
+ */
1912
+ closeStream(clientId: string): void;
1913
+ /**
1914
+ * Close all active streams
1915
+ */
1916
+ closeAll(): void;
1917
+ /**
1918
+ * Get metrics for all streams
1919
+ */
1920
+ getMetrics(): SSEMetrics;
1921
+ }
1922
+ /**
1923
+ * Result type for operations that can fail
1924
+ */
1925
+ type RegistryResult<T> = {
1926
+ success: true;
1927
+ value: T;
1928
+ } | {
1929
+ success: false;
1930
+ error: string;
1931
+ };
1932
+ /**
1933
+ * Connection metadata stored in the registry
1934
+ */
1935
+ interface ConnectionEntry {
1936
+ stream: SSEStream;
1937
+ connectedAt: number;
1938
+ lastActivity: number;
1939
+ clientIp?: string;
1940
+ userAgent?: string;
1941
+ }
1942
+ /**
1943
+ * Internal connection registry interface
1944
+ */
1945
+ interface ConnectionRegistry {
1946
+ /** Add a new connection to the registry */
1947
+ add: (id: string, stream: SSEStream, metadata?: {
1948
+ clientIp?: string;
1949
+ userAgent?: string;
1950
+ }) => void;
1951
+ /** Remove a connection from the registry */
1952
+ remove: (id: string) => void;
1953
+ /** Get current connection count */
1954
+ count: () => number;
1955
+ /** Clean up inactive or closed connections */
1956
+ cleanup: () => void;
1957
+ /** Get connection by ID (for internal use) */
1958
+ get: (id: string) => SSEStream | undefined;
1959
+ /** Check if a connection exists */
1960
+ has: (id: string) => boolean;
1961
+ /** Get all connection IDs */
1962
+ getIds: () => string[];
1963
+ /** Shutdown the registry and close all connections */
1964
+ shutdown: () => void;
1965
+ }
1966
+ /**
1967
+ * Extended stream interface for typed events
1968
+ */
1969
+ interface TypedSSEStream<TEvents extends Record<string, z.ZodType>> extends SSEStreamExtended {
1970
+ send<K extends keyof TEvents>(event: K & string, data: z.infer<TEvents[K]>): void;
1971
+ }
1972
+ /**
1973
+ * Schema for SSE route validation with generic type parameters
1974
+ */
1975
+ interface SSERouteSchema<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, E = any> {
1976
+ /** Parameter schema for validation */
1977
+ params?: P;
1978
+ /** Query schema for validation */
1979
+ query?: Q;
1980
+ /** Events schema for validation (SSE-specific, replaces response) */
1981
+ events?: E;
1982
+ }
1983
+ /**
1984
+ * SSE route handler function with stream as first parameter
1985
+ * This is the user-facing API - they write handlers with this signature
1986
+ */
1987
+ type SSERouteHandler<TStream extends SSEStreamExtended = SSEStreamExtended, TParams = Record<string, string>, TQuery = Record<string, string | string[] | undefined>, TState extends State = State, TServices extends Services = Services> = (stream: TStream, ctx: Context<TState, TServices, never, TQuery>, // SSE never has body
1988
+ params: TParams) => Promise<void> | void;
1989
+ /**
1990
+ * SSE route creator with state and services support
1991
+ * Returns a higher-order function to handle generics properly
1992
+ *
1993
+ * The return type matches what the implementation actually returns:
1994
+ * - A route object with a GET property
1995
+ * - The GET property contains the wrapped handler and schemas
1996
+ * - The wrapped handler has the standard (ctx, params) signature expected by the router
1997
+ */
1998
+ type CreateSSERoute = <TState extends State = State, TServices extends Services = Services>() => <P = never, Q = never, E = never>(config: {
1999
+ schema?: {
2000
+ params?: P extends never ? never : P;
2001
+ query?: Q extends never ? never : Q;
2002
+ events?: E extends never ? never : E;
2003
+ };
2004
+ handler: SSERouteHandler<E extends Record<string, z.ZodType> ? TypedSSEStream<E> : SSEStreamExtended, P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, TState, TServices>;
2005
+ middleware?: Middleware[];
2006
+ options?: Record<string, unknown>;
2007
+ }) => {
2008
+ GET: {
2009
+ handler: (ctx: any, params: any) => Promise<void>;
2010
+ schema?: {
2011
+ params?: P extends never ? undefined : P;
2012
+ query?: Q extends never ? undefined : Q;
2013
+ };
2014
+ middleware?: Middleware[];
2015
+ options?: Record<string, unknown>;
2016
+ };
2017
+ path: string;
2018
+ };
2019
+ /**
2020
+ * Buffered event with metadata
2021
+ */
2022
+ interface BufferedEvent {
2023
+ id: string;
2024
+ event: string;
2025
+ data: unknown;
2026
+ size: number;
2027
+ timestamp: number;
2028
+ correlationId: string;
2029
+ }
2030
+ /**
2031
+ * Stream metrics for monitoring
2032
+ */
2033
+ interface StreamMetrics {
2034
+ eventsSent: number;
2035
+ eventsDropped: number;
2036
+ bytesWritten: number;
2037
+ bufferHighWatermark: number;
2038
+ lastEventTime: number;
2039
+ }
2040
+
2041
+ /**
2042
+ * SSE Client Types for BlaizeJS
2043
+ * Location: packages/blaize-client/src/sse/types.ts
2044
+ */
2045
+
2046
+ /**
2047
+ * Event handlers map
2048
+ */
2049
+ interface EventHandlers {
2050
+ [event: string]: Set<(data: any) => void>;
2051
+ }
2052
+ /**
2053
+ * SSE connection configuration options
2054
+ */
2055
+ interface SSEClientOptions {
2056
+ headers?: Record<string, string>;
2057
+ withCredentials?: boolean;
2058
+ reconnect?: {
2059
+ enabled: boolean;
2060
+ maxAttempts?: number;
2061
+ strategy?: ReconnectStrategy;
2062
+ initialDelay?: number;
2063
+ };
2064
+ bufferMissedEvents?: boolean;
2065
+ maxMissedEvents?: number;
2066
+ heartbeatTimeout?: number;
2067
+ parseJSON?: boolean;
2068
+ /**
2069
+ * Whether to wait for connection before resolving the promise.
2070
+ * If false, returns the client immediately without waiting.
2071
+ * Default: true
2072
+ */
2073
+ waitForConnection?: boolean;
2074
+ /**
2075
+ * Optional timeout for initial connection in milliseconds.
2076
+ * If not set, no timeout is applied (relies on EventSource native timeout).
2077
+ * Only applies if waitForConnection is true.
2078
+ */
2079
+ connectionTimeout?: number;
2080
+ }
2081
+ /**
2082
+ * Metrics for SSE connection monitoring
2083
+ */
2084
+ interface SSEClientMetrics {
2085
+ eventsReceived: number;
2086
+ bytesReceived: number;
2087
+ connectionDuration: number;
2088
+ reconnectAttempts: number;
2089
+ lastEventId?: string;
2090
+ }
2091
+ /**
2092
+ * Reconnection delay calculation strategy
2093
+ */
2094
+ type ReconnectStrategy = (attempt: number) => number;
2095
+ /**
2096
+ * SSE Client interface with type-safe event handling
2097
+ */
2098
+ interface SSEClient<TEvents extends Record<string, unknown> = Record<string, unknown>> {
2099
+ on<K extends keyof TEvents>(event: K & string, handler: (data: TEvents[K]) => void): void;
2100
+ on(event: 'error', handler: (error: BlaizeError) => void): void;
2101
+ on(event: 'open', handler: () => void): void;
2102
+ on(event: 'close', handler: (event: CloseEvent) => void): void;
2103
+ off<K extends keyof TEvents>(event: K & string, handler?: (data: TEvents[K]) => void): void;
2104
+ off(event: 'error', handler?: (error: BlaizeError) => void): void;
2105
+ off(event: 'open', handler?: () => void): void;
2106
+ off(event: 'close', handler?: (event: CloseEvent) => void): void;
2107
+ once<K extends keyof TEvents>(event: K & string, handler: (data: TEvents[K]) => void): void;
2108
+ once(event: 'error', handler: (error: BlaizeError) => void): void;
2109
+ once(event: 'open', handler: () => void): void;
2110
+ once(event: 'close', handler: (event: CloseEvent) => void): void;
2111
+ close(): void;
2112
+ readonly state: SSEConnectionState;
2113
+ readonly metrics: SSEClientMetrics;
2114
+ readonly lastEventId?: string;
2115
+ }
2116
+ /**
2117
+ * Close event for SSE connections
2118
+ */
2119
+ interface CloseEvent {
2120
+ reconnect: boolean;
2121
+ reason?: string;
2122
+ }
2123
+ /**
2124
+ * Internal SSE connection factory
2125
+ * Returns a Promise that resolves to an SSEClient instance
2126
+ */
2127
+ type SSEConnectionFactory<TEvents extends Record<string, unknown> = Record<string, unknown>> = (options?: SSEClientOptions) => Promise<SSEClient<TEvents>>;
2128
+
1279
2129
  type ExtractMethod<T> = T extends {
1280
2130
  GET: any;
1281
2131
  } ? 'GET' : T extends {
@@ -1331,6 +2181,7 @@ interface ClientConfig {
1331
2181
  baseUrl: string;
1332
2182
  defaultHeaders?: Record<string, string>;
1333
2183
  timeout?: number;
2184
+ sse?: SSEClientOptions;
1334
2185
  }
1335
2186
  interface InternalRequestArgs {
1336
2187
  params?: Record<string, any>;
@@ -1344,6 +2195,77 @@ interface RequestOptions {
1344
2195
  body?: string;
1345
2196
  timeout: number;
1346
2197
  }
2198
+ /**
2199
+ * Detect if a route has SSE support
2200
+ * SSE routes have a special 'SSE' method key
2201
+ */
2202
+ type HasSSEMethod<TRoute> = TRoute extends {
2203
+ SSE: any;
2204
+ } ? true : false;
2205
+ /**
2206
+ * Extract SSE event types from route schema
2207
+ */
2208
+ type ExtractSSEEvents<TRoute> = TRoute extends {
2209
+ SSE: {
2210
+ events?: infer E;
2211
+ };
2212
+ } ? E extends z.ZodType ? z.infer<E> : Record<string, unknown> : Record<string, unknown>;
2213
+ /**
2214
+ * Extract SSE query parameters from route
2215
+ */
2216
+ type ExtractSSEQuery<TRoute> = TRoute extends {
2217
+ SSE: {
2218
+ schema?: {
2219
+ query?: infer Q;
2220
+ };
2221
+ };
2222
+ } ? Q extends z.ZodType ? z.infer<Q> : Record<string, unknown> : never;
2223
+ /**
2224
+ * Extract SSE params from route
2225
+ */
2226
+ type ExtractSSEParams<TRoute> = TRoute extends {
2227
+ SSE: {
2228
+ schema?: {
2229
+ params?: infer P;
2230
+ };
2231
+ };
2232
+ } ? P extends z.ZodType ? z.infer<P> : Record<string, string> : never;
2233
+ /**
2234
+ * Build SSE method arguments
2235
+ */
2236
+ type BuildSSEArgs<TRoute> = ExtractSSEParams<TRoute> extends never ? ExtractSSEQuery<TRoute> extends never ? {
2237
+ options?: SSEClientOptions;
2238
+ } : {
2239
+ query: ExtractSSEQuery<TRoute>;
2240
+ options?: SSEClientOptions;
2241
+ } : ExtractSSEQuery<TRoute> extends never ? {
2242
+ params: ExtractSSEParams<TRoute>;
2243
+ options?: SSEClientOptions;
2244
+ } : {
2245
+ params: ExtractSSEParams<TRoute>;
2246
+ query: ExtractSSEQuery<TRoute>;
2247
+ options?: SSEClientOptions;
2248
+ };
2249
+ /**
2250
+ * Create SSE client method
2251
+ */
2252
+ type CreateSSEMethod<TRoute> = HasSSEMethod<TRoute> extends true ? BuildSSEArgs<TRoute> extends {
2253
+ options?: SSEClientOptions;
2254
+ } ? (args?: BuildSSEArgs<TRoute>) => Promise<SSEClient<ExtractSSEEvents<TRoute>>> : (args: BuildSSEArgs<TRoute>) => Promise<SSEClient<ExtractSSEEvents<TRoute>>> : never;
2255
+ /**
2256
+ * Extract SSE routes from registry
2257
+ */
2258
+ type ExtractSSERoutes<TRoutes extends Record<string, any>> = {
2259
+ [K in keyof TRoutes as HasSSEMethod<TRoutes[K]> extends true ? K : never]: TRoutes[K];
2260
+ };
2261
+ /**
2262
+ * Enhanced client with SSE support
2263
+ */
2264
+ type CreateEnhancedClient<TRoutes extends Record<string, any>, TRegistry> = TRegistry & {
2265
+ $sse: {
2266
+ [K in keyof ExtractSSERoutes<TRoutes>]: CreateSSEMethod<TRoutes[K]>;
2267
+ };
2268
+ };
1347
2269
 
1348
2270
  /**
1349
2271
  * BlaizeJS Server Module - Enhanced with Correlation Configuration
@@ -1411,6 +2333,35 @@ interface ServerOptionsInput {
1411
2333
  * @since 0.4.0
1412
2334
  */
1413
2335
  correlation?: CorrelationOptions;
2336
+ /**
2337
+ * CORS configuration
2338
+ *
2339
+ * - `true`: Enable CORS with development defaults (allow all origins)
2340
+ * - `false`: Disable CORS (no headers set)
2341
+ * - `CorsOptions`: Custom CORS configuration
2342
+ *
2343
+ * @default false (CORS disabled)
2344
+ * @since 0.5.0
2345
+ *
2346
+ * @example
2347
+ * ```typescript
2348
+ * // Enable with dev defaults
2349
+ * const server = createServer({ cors: true });
2350
+ *
2351
+ * // Custom configuration
2352
+ * const server = createServer({
2353
+ * cors: {
2354
+ * origin: 'https://example.com',
2355
+ * credentials: true,
2356
+ * maxAge: 86400
2357
+ * }
2358
+ * });
2359
+ *
2360
+ * // Disable CORS
2361
+ * const server = createServer({ cors: false });
2362
+ * ```
2363
+ */
2364
+ cors?: CorsOptions | boolean;
1414
2365
  }
1415
2366
  /**
1416
2367
  * Configuration for a BlaizeJS server
@@ -1440,6 +2391,11 @@ interface ServerOptions {
1440
2391
  * @since 0.4.0
1441
2392
  */
1442
2393
  correlation?: CorrelationOptions;
2394
+ /**
2395
+ * CORS configuration
2396
+ * @since 0.5.0
2397
+ */
2398
+ cors?: CorsOptions | boolean;
1443
2399
  }
1444
2400
  /**
1445
2401
  * BlaizeJS Server instance with generic type accumulation
@@ -1453,6 +2409,8 @@ interface Server<TState, TServices> {
1453
2409
  server: http.Server | http2.Http2Server | undefined;
1454
2410
  /** The port the server is configured to listen on */
1455
2411
  port: number;
2412
+ /** CORS configuration for this server */
2413
+ corsOptions?: CorsOptions | boolean;
1456
2414
  /** The host the server is bound to */
1457
2415
  host: string;
1458
2416
  events: EventEmitter;
@@ -1560,7 +2518,7 @@ interface Plugin<TState = {}, TServices = {}> extends PluginHooks {
1560
2518
  /**
1561
2519
  * Plugin factory function
1562
2520
  */
1563
- type PluginFactory<T = any, TState extends Record<string, unknown> = {}, TServices extends Record<string, unknown> = {}> = (options?: T) => Plugin<TState, TServices>;
2521
+ type PluginFactory<TConfig = any, TState = {}, TServices = {}> = (options?: TConfig) => Plugin<TState, TServices>;
1564
2522
  interface PluginLifecycleManager {
1565
2523
  initializePlugins(server: Server<any, any>): Promise<void>;
1566
2524
  terminatePlugins(server: Server<any, any>): Promise<void>;
@@ -1822,7 +2780,7 @@ declare function createPluginArray<T extends ReadonlyArray<Plugin<any, any>>>(..
1822
2780
  /**
1823
2781
  * Create a plugin with the given name, version, and setup function
1824
2782
  */
1825
- declare function create$1<T = any>(name: string, version: string, setup: (app: UnknownServer, options: T) => void | Partial<PluginHooks> | Promise<void> | Promise<Partial<PluginHooks>>, defaultOptions?: Partial<T>): PluginFactory<T>;
2783
+ declare function create$1<TConfig = any, TState = {}, TServices = {}>(name: string, version: string, setup: (app: UnknownServer, options: TConfig) => void | Partial<PluginHooks> | Promise<void> | Promise<Partial<PluginHooks>>, defaultOptions?: Partial<TConfig>): PluginFactory<TConfig, TState, TServices>;
1826
2784
 
1827
2785
  /**
1828
2786
  * Create a GET route
@@ -1968,7 +2926,53 @@ declare function createRouteFactory<TState extends State = State, TServices exte
1968
2926
  OPTIONS: RouteMethodOptions<P extends never ? never : P extends zod.ZodType<any, zod.ZodTypeDef, any> ? P : never, Q extends never ? never : Q extends zod.ZodType<any, zod.ZodTypeDef, any> ? Q : never, never, R extends never ? never : R extends zod.ZodType<any, zod.ZodTypeDef, any> ? R : never, zod.ZodType<any, zod.ZodTypeDef, any>>;
1969
2927
  path: string;
1970
2928
  };
2929
+ readonly sse: <P = never, Q = never, E = never>(config: {
2930
+ schema?: {
2931
+ params?: (P extends never ? never : P) | undefined;
2932
+ query?: (Q extends never ? never : Q) | undefined;
2933
+ events?: (E extends never ? never : E) | undefined;
2934
+ } | undefined;
2935
+ handler: SSERouteHandler<E extends Record<string, zod.ZodType<any, zod.ZodTypeDef, any>> ? TypedSSEStream<E> : SSEStreamExtended, P extends zod.ZodType<any, zod.ZodTypeDef, any> ? Infer<P> : Record<string, string>, Q extends zod.ZodType<any, zod.ZodTypeDef, any> ? Infer<Q> : QueryParams, TState, TServices>;
2936
+ middleware?: Middleware[];
2937
+ options?: Record<string, unknown>;
2938
+ }) => {
2939
+ GET: {
2940
+ handler: (ctx: any, params: any) => Promise<void>;
2941
+ schema?: {
2942
+ params?: (P extends never ? undefined : P) | undefined;
2943
+ query?: (Q extends never ? undefined : Q) | undefined;
2944
+ } | undefined;
2945
+ middleware?: Middleware[];
2946
+ options?: Record<string, unknown>;
2947
+ };
2948
+ path: string;
2949
+ };
2950
+ };
2951
+
2952
+ /**
2953
+ * Create a route matcher
2954
+ */
2955
+ declare function createMatcher(): Matcher;
2956
+
2957
+ /**
2958
+ * Extract parameter values from a URL path
2959
+ */
2960
+ declare function extractParams(path: string, pattern: RegExp, paramNames: string[]): Record<string, string>;
2961
+ /**
2962
+ * Compile a path pattern with parameters
2963
+ */
2964
+ declare function compilePathPattern(path: string): {
2965
+ pattern: RegExp;
2966
+ paramNames: string[];
1971
2967
  };
2968
+ /**
2969
+ * Convert parameters object to URL query string
2970
+ */
2971
+ declare function paramsToQuery(params: Record<string, string | number | boolean>): string;
2972
+ /**
2973
+ * Build a URL with path parameters
2974
+ */
2975
+ declare function buildUrl(pathPattern: string, params?: Record<string, string | number | boolean>, query?: Record<string, string | number | boolean>): string;
1972
2976
 
1973
2977
  /**
1974
2978
  * Creates a BlaizeJS server instance
@@ -2315,14 +3319,37 @@ declare class RequestTimeoutError extends BlaizeError {
2315
3319
  constructor(title: string, details?: unknown, correlationId?: string);
2316
3320
  }
2317
3321
 
2318
- declare class UnsupportedMediaTypeError extends BlaizeError {
3322
+ declare class UnprocessableEntityError extends BlaizeError {
2319
3323
  constructor(title: string, details?: unknown, correlationId?: string);
2320
3324
  }
2321
3325
 
2322
- declare class UnprocessableEntityError extends BlaizeError {
3326
+ declare class UnsupportedMediaTypeError extends BlaizeError {
2323
3327
  constructor(title: string, details?: unknown, correlationId?: string);
2324
3328
  }
2325
3329
 
3330
+ /**
3331
+ * Error thrown when a service is temporarily unavailable
3332
+ *
3333
+ * Automatically sets HTTP status to 503 and optionally includes Retry-After.
3334
+ *
3335
+ * @example Basic usage:
3336
+ * ```typescript
3337
+ * throw new ServiceNotAvailableError('Database unavailable');
3338
+ * ```
3339
+ *
3340
+ * @example With retry guidance:
3341
+ * ```typescript
3342
+ * throw new ServiceNotAvailableError('Payment service down', {
3343
+ * service: 'stripe',
3344
+ * retryAfter: 30,
3345
+ * reason: 'circuit_breaker'
3346
+ * });
3347
+ * ```
3348
+ */
3349
+ declare class ServiceNotAvailableError extends BlaizeError<ServiceNotAvailableDetails> {
3350
+ constructor(title: string, details?: ServiceNotAvailableDetails | undefined, correlationId?: string | undefined);
3351
+ }
3352
+
2326
3353
  declare const VERSION = "0.1.0";
2327
3354
  declare const ServerAPI: {
2328
3355
  createServer: typeof create;
@@ -2337,12 +3364,18 @@ declare const RouterAPI: {
2337
3364
  createPostRoute: CreatePostRoute;
2338
3365
  createPutRoute: CreatePutRoute;
2339
3366
  createRouteFactory: typeof createRouteFactory;
3367
+ createMatcher: typeof createMatcher;
3368
+ extractParams: typeof extractParams;
3369
+ compilePathPattern: typeof compilePathPattern;
3370
+ paramsToQuery: typeof paramsToQuery;
3371
+ buildUrl: typeof buildUrl;
2340
3372
  };
2341
3373
  declare const MiddlewareAPI: {
2342
3374
  createMiddleware: typeof create$2;
2343
3375
  createServiceMiddleware: typeof serviceMiddleware;
2344
3376
  createStateMiddleware: typeof stateMiddleware;
2345
3377
  compose: typeof compose;
3378
+ cors: typeof cors;
2346
3379
  };
2347
3380
  declare const PluginsAPI: {
2348
3381
  createPlugin: typeof create$1;
@@ -2368,12 +3401,18 @@ declare const Blaize: {
2368
3401
  createPostRoute: CreatePostRoute;
2369
3402
  createPutRoute: CreatePutRoute;
2370
3403
  createRouteFactory: typeof createRouteFactory;
3404
+ createMatcher: typeof createMatcher;
3405
+ extractParams: typeof extractParams;
3406
+ compilePathPattern: typeof compilePathPattern;
3407
+ paramsToQuery: typeof paramsToQuery;
3408
+ buildUrl: typeof buildUrl;
2371
3409
  };
2372
3410
  Middleware: {
2373
3411
  createMiddleware: typeof create$2;
2374
3412
  createServiceMiddleware: typeof serviceMiddleware;
2375
3413
  createStateMiddleware: typeof stateMiddleware;
2376
3414
  compose: typeof compose;
3415
+ cors: typeof cors;
2377
3416
  };
2378
3417
  Plugins: {
2379
3418
  createPlugin: typeof create$1;
@@ -2381,4 +3420,4 @@ declare const Blaize: {
2381
3420
  VERSION: string;
2382
3421
  };
2383
3422
 
2384
- export { Blaize, BlaizeError, type BlaizeErrorResponse, type BodyParseError, type BuildRoutesRegistry, type ClientConfig, type ComposeMiddlewareServices, type ComposeMiddlewareStates, type ComposeMiddlewareTypes, type ComposePluginServices, type ComposePluginStates, type ComposePluginTypes, ConflictError, type ConflictErrorDetails, type Context, type ContextOptions, type ContextRequest, type ContextResponse, type CorrelationOptions, type CreateClient, type CreateContextFn, type CreateDeleteRoute, type CreateGetRoute, type CreateHeadRoute, type CreateOptionsRoute, type CreatePatchRoute, type CreatePostRoute, type CreatePutRoute, type ErrorHandlerOptions, ErrorSeverity, type ErrorTransformContext, ErrorType, type ExtractMethod, type ExtractMiddlewareServices, type ExtractMiddlewareState, type ExtractMiddlewareTypes, type ExtractPluginServices, type ExtractPluginState, type ExtractPluginTypes, type FileCache, type FindRouteFilesOptions, ForbiddenError, type ForbiddenErrorDetails, type GetContextFn, type Http2Options, type HttpMethod, type Infer, type InferContext, type InternalRequestArgs, InternalServerError, type InternalServerErrorDetails, type Matcher, type MergeServices, type MergeStates, type Middleware, MiddlewareAPI, type MiddlewareFunction, type MiddlewareOptions, type MultipartData, type MultipartError, type MultipartLimits, type NetworkErrorContext, type NextFunction, NotFoundError, type NotFoundErrorDetails, type ParseErrorContext, type ParseOptions, type ParseResult, type ParsedRoute, type ParserState, PayloadTooLargeError, type PayloadTooLargeErrorDetails, type Plugin, type PluginFactory, type PluginHooks, type PluginLifecycleManager, type PluginLifecycleOptions, type PluginOptions, PluginsAPI, type ProcessResponseOptions, type ProcessingConfig, type QueryParams, RateLimitError, type RateLimitErrorDetails, type ReloadMetrics, type RequestHandler, type RequestOptions, type RequestParams, RequestTimeoutError, type Result, type Route, type RouteDefinition, type RouteEntry, type RouteHandler, type RouteMatch, type RouteMethodOptions, type RouteNode, type RouteOptions, type RouteRegistry, type RouteSchema, type Router, RouterAPI, type RouterOptions, type SafeComposeMiddlewareServices, type SafeComposeMiddlewareStates, type SafeComposePluginServices, type SafeComposePluginStates, type SafeExtractMiddlewareServices, type SafeExtractMiddlewareState, type SafeExtractPluginServices, type SafeExtractPluginState, type Server, ServerAPI, type ServerOptions, type ServerOptionsInput, type Services, type StandardErrorResponse, type StartOptions, type State, type StopOptions, type StreamOptions, type TimeoutErrorContext, UnauthorizedError, type UnauthorizedErrorDetails, type UnifiedRequest, type UnifiedResponse, type UnionToIntersection, type UnknownFunction, type UnknownServer, UnprocessableEntityError, UnsupportedMediaTypeError, type UnsupportedMediaTypeErrorDetails, type UploadProgress, type UploadedFile, VERSION, type ValidationConfig, ValidationError, type ValidationErrorDetails, type ValidationFieldError, type WatchOptions, asMiddlewareArray, asPluginArray, compose, createDeleteRoute, createGetRoute, createHeadRoute, create$2 as createMiddleware, createMiddlewareArray, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPluginArray, createPostRoute, createPutRoute, createRouteFactory, create as createServer, serviceMiddleware as createServiceMiddleware, stateMiddleware as createStateMiddleware, getCorrelationId, inferContext, isBodyParseError, isMiddleware, isPlugin };
3423
+ export { Blaize, BlaizeError, type BlaizeErrorResponse, type BodyParseError, type BufferedEvent, type BuildRoutesRegistry, type BuildSSEArgs, type CacheConfig, type CacheEntry, type ClientConfig, type CloseEvent, type ComposeMiddlewareServices, type ComposeMiddlewareStates, type ComposeMiddlewareTypes, type ComposePluginServices, type ComposePluginStates, type ComposePluginTypes, ConflictError, type ConflictErrorDetails, type ConnectionEntry, type ConnectionRegistry, type Context, type ContextOptions, type ContextRequest, type ContextResponse, type CorrelationOptions, type CorsHttpMethod, type CorsOptions, type CorsOrigin, type CorsOriginCacheConfig, type CorsOriginCacheEntry, type CorsPreflightInfo, type CorsStats, type CorsValidationResult, type CreateClient, type CreateContextFn, type CreateDeleteRoute, type CreateEnhancedClient, type CreateGetRoute, type CreateHeadRoute, type CreateOptionsRoute, type CreatePatchRoute, type CreatePostRoute, type CreatePutRoute, type CreateSSEMethod, type CreateSSERoute, type ErrorHandlerOptions, ErrorSeverity, type ErrorTransformContext, ErrorType, type EventHandlers, type ExtractMethod, type ExtractMiddlewareServices, type ExtractMiddlewareState, type ExtractMiddlewareTypes, type ExtractPluginServices, type ExtractPluginState, type ExtractPluginTypes, type ExtractSSEEvents, type ExtractSSEParams, type ExtractSSEQuery, type ExtractSSERoutes, type FileCache, type FindRouteFilesOptions, ForbiddenError, type ForbiddenErrorDetails, type GetContextFn, type HasSSEMethod, type Http2Options, type HttpMethod, type Infer, type InferContext, type InternalRequestArgs, InternalServerError, type InternalServerErrorDetails, type Matcher, type MergeServices, type MergeStates, type Middleware, MiddlewareAPI, type MiddlewareFunction, type MiddlewareOptions, type MultipartData, type MultipartError, type MultipartLimits, type NetworkErrorContext, type NextFunction, NotFoundError, type NotFoundErrorDetails, type ParseErrorContext, type ParseOptions, type ParseResult, type ParsedRoute, type ParserState, PayloadTooLargeError, type PayloadTooLargeErrorDetails, type Plugin, type PluginFactory, type PluginHooks, type PluginLifecycleManager, type PluginLifecycleOptions, type PluginOptions, PluginsAPI, type ProcessResponseOptions, type ProcessingConfig, type QueryParams, RateLimitError, type RateLimitErrorDetails, type ReconnectStrategy, type RegistryResult, type ReloadMetrics, type RequestHandler, type RequestOptions, type RequestParams, RequestTimeoutError, type Result, type Route, type RouteDefinition, type RouteEntry, type RouteHandler, type RouteMatch, type RouteMethodOptions, type RouteNode, type RouteOptions, type RouteRegistry, type RouteSchema, type Router, RouterAPI, type RouterOptions, type SSEBufferOverflowErrorDetails, type SSEBufferStrategy, type SSEClient, type SSEClientMetrics, type SSEClientOptions, type SSEConnectionErrorContext, type SSEConnectionErrorDetails, type SSEConnectionFactory, type SSEConnectionState, type SSEEvent, type SSEEventHandler, type SSEEventListener, type SSEHeartbeatErrorContext, type SSEMetrics, type SSEOptions, type SSERouteHandler, type SSERouteSchema, type SSESerializedEvent, type SSEStream, type SSEStreamClosedErrorDetails, type SSEStreamErrorContext, type SSEStreamExtended, type SSEStreamManager, type SafeComposeMiddlewareServices, type SafeComposeMiddlewareStates, type SafeComposePluginServices, type SafeComposePluginStates, type SafeExtractMiddlewareServices, type SafeExtractMiddlewareState, type SafeExtractPluginServices, type SafeExtractPluginState, type Server, ServerAPI, type ServerOptions, type ServerOptionsInput, type ServiceNotAvailableDetails, ServiceNotAvailableError, type Services, type StandardErrorResponse, type StartOptions, type State, type StopOptions, type StreamMetrics, type StreamOptions, type TimeoutErrorContext, type TypedSSEStream, UnauthorizedError, type UnauthorizedErrorDetails, type UnifiedRequest, type UnifiedResponse, type UnionToIntersection, type UnknownFunction, type UnknownServer, UnprocessableEntityError, UnsupportedMediaTypeError, type UnsupportedMediaTypeErrorDetails, type UploadProgress, type UploadedFile, VERSION, type ValidationConfig, ValidationError, type ValidationErrorDetails, type ValidationFieldError, type WatchOptions, asMiddlewareArray, asPluginArray, buildUrl, compilePathPattern, compose, cors, createDeleteRoute, createGetRoute, createHeadRoute, createMatcher, create$2 as createMiddleware, createMiddlewareArray, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPluginArray, createPostRoute, createPutRoute, createRouteFactory, create as createServer, serviceMiddleware as createServiceMiddleware, stateMiddleware as createStateMiddleware, extractParams, getCorrelationId, inferContext, isBodyParseError, isMiddleware, isPlugin, paramsToQuery };