@mdxui/do 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -266
- package/dist/{agents-xcIn2dUB.d.ts → agents-2_r9e9i7.d.ts} +213 -2
- package/dist/app/index.d.ts +347 -0
- package/dist/app/index.js +13 -0
- package/dist/app/index.js.map +1 -0
- package/dist/chunk-4KXVN3EQ.js +56 -0
- package/dist/chunk-4KXVN3EQ.js.map +1 -0
- package/dist/chunk-5AWTQDRF.js +76 -0
- package/dist/chunk-5AWTQDRF.js.map +1 -0
- package/dist/chunk-EQVOEEQO.js +95 -0
- package/dist/chunk-EQVOEEQO.js.map +1 -0
- package/dist/chunk-FO3N7SXV.js +469 -0
- package/dist/chunk-FO3N7SXV.js.map +1 -0
- package/dist/chunk-IESVTECE.js +536 -0
- package/dist/chunk-IESVTECE.js.map +1 -0
- package/dist/chunk-JWKIONEO.js +234 -0
- package/dist/chunk-JWKIONEO.js.map +1 -0
- package/dist/chunk-NTSEARBC.js +715 -0
- package/dist/chunk-NTSEARBC.js.map +1 -0
- package/dist/chunk-OWEAW4U6.js +116 -0
- package/dist/chunk-OWEAW4U6.js.map +1 -0
- package/dist/chunk-VRLUXCLD.js +31 -0
- package/dist/chunk-VRLUXCLD.js.map +1 -0
- package/dist/chunk-Y52IEYVM.js +131 -0
- package/dist/chunk-Y52IEYVM.js.map +1 -0
- package/dist/chunk-YGIBMNRH.js +1991 -0
- package/dist/chunk-YGIBMNRH.js.map +1 -0
- package/dist/components/index.d.ts +1 -738
- package/dist/components/index.js +2 -6
- package/dist/config-CmZBQQaT.d.ts +122 -0
- package/dist/{do-CaQVueZw.d.ts → do-C-t9UgjT.d.ts} +31 -33
- package/dist/errors-B4Oyyj4Z.d.ts +346 -0
- package/dist/hooks/index.d.ts +428 -696
- package/dist/hooks/index.js +6 -4
- package/dist/hooks/things/index.d.ts +298 -0
- package/dist/hooks/things/index.js +8 -0
- package/dist/hooks/things/index.js.map +1 -0
- package/dist/index.d.ts +21 -1010
- package/dist/index.js +11 -839
- package/dist/index.js.map +1 -1
- package/dist/lib/index.d.ts +100 -0
- package/dist/lib/index.js +6 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/providers/index.d.ts +244 -32
- package/dist/providers/index.js +3 -2
- package/dist/query-keys-BC901wog.d.ts +153 -0
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/index.js +2 -2
- package/dist/schemas/index.js.map +1 -1
- package/dist/{thing-DtI25yZh.d.ts → thing-BVhCTzOi.d.ts} +4 -4
- package/dist/types/index.d.ts +251 -216
- package/dist/types/index.js +1 -2
- package/dist/views/index.d.ts +131 -0
- package/dist/views/index.js +11 -0
- package/dist/views/index.js.map +1 -0
- package/package.json +39 -17
- package/dist/__test-utils__/index.d.ts +0 -399
- package/dist/__test-utils__/index.js +0 -34641
- package/dist/__test-utils__/index.js.map +0 -1
- package/dist/chunk-EEDMN7UF.js +0 -1351
- package/dist/chunk-EEDMN7UF.js.map +0 -1
- package/dist/chunk-G3PMV62Z.js +0 -33
- package/dist/chunk-G3PMV62Z.js.map +0 -1
- package/dist/chunk-NXPXL5NA.js +0 -3789
- package/dist/chunk-NXPXL5NA.js.map +0 -1
- package/dist/chunk-PC5FJY6M.js +0 -20
- package/dist/chunk-PC5FJY6M.js.map +0 -1
- package/dist/chunk-XF6LKY2M.js +0 -445
- package/dist/chunk-XF6LKY2M.js.map +0 -1
- package/dist/magic-string.es-J7BYFTTJ.js +0 -1307
- package/dist/magic-string.es-J7BYFTTJ.js.map +0 -1
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-GKSP5RIA.js';
|
|
4
|
-
import '../chunk-GGO5GW72.js';
|
|
5
|
-
import '../chunk-XF6LKY2M.js';
|
|
6
|
-
import '../chunk-G3PMV62Z.js';
|
|
1
|
+
export { DOErrorBoundary, useErrorBoundary } from '../chunk-EQVOEEQO.js';
|
|
2
|
+
import '../chunk-Y52IEYVM.js';
|
|
7
3
|
//# sourceMappingURL=index.js.map
|
|
8
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { i as DOAdminConfig } from './do-C-t9UgjT.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration types for DOShell
|
|
6
|
+
*
|
|
7
|
+
* These types define the configuration options for the DO Admin Dashboard Shell,
|
|
8
|
+
* including authentication, branding, and routing configuration.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Identity configuration for WorkOS AuthKit integration
|
|
13
|
+
*/
|
|
14
|
+
interface DOIdentity {
|
|
15
|
+
/** WorkOS AuthKit client ID */
|
|
16
|
+
clientId: string;
|
|
17
|
+
/** Custom API hostname for WorkOS (optional) */
|
|
18
|
+
apiHostname?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Enable development mode for testing without real auth.
|
|
21
|
+
* When true, WorkOS AuthKit will use its built-in dev mode.
|
|
22
|
+
*/
|
|
23
|
+
devMode?: boolean;
|
|
24
|
+
/** OAuth redirect URI (defaults to current origin + basePath) */
|
|
25
|
+
redirectUri?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether authentication is required.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
required?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Action when user is not authenticated.
|
|
33
|
+
* - 'redirect': Redirect to unauthenticatedRedirectUrl
|
|
34
|
+
* - 'landing': Show landing page (custom or default)
|
|
35
|
+
* - 'allow': Allow access without auth (useful for public routes)
|
|
36
|
+
* @default 'landing'
|
|
37
|
+
*/
|
|
38
|
+
onUnauthenticated?: 'redirect' | 'landing' | 'allow';
|
|
39
|
+
/** URL to redirect to when unauthenticated and onUnauthenticated is 'redirect' */
|
|
40
|
+
unauthenticatedRedirectUrl?: string;
|
|
41
|
+
/** Custom landing component to show when not authenticated */
|
|
42
|
+
landingComponent?: ReactNode;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Branding configuration for the shell
|
|
46
|
+
*/
|
|
47
|
+
interface DOBranding {
|
|
48
|
+
/** Application name shown in sidebar header */
|
|
49
|
+
name?: string;
|
|
50
|
+
/** Logo element or image */
|
|
51
|
+
logo?: ReactNode;
|
|
52
|
+
/** Favicon URL */
|
|
53
|
+
favicon?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Theme configuration
|
|
57
|
+
*/
|
|
58
|
+
interface DOTheme {
|
|
59
|
+
/** Theme mode */
|
|
60
|
+
mode?: 'light' | 'dark' | 'system';
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Custom route definition for extending the shell
|
|
64
|
+
*/
|
|
65
|
+
interface DOCustomRoute {
|
|
66
|
+
/** Route path (e.g., '/custom-page') */
|
|
67
|
+
path: string;
|
|
68
|
+
/** Navigation title */
|
|
69
|
+
title: string;
|
|
70
|
+
/** Navigation icon (Lucide icon component) */
|
|
71
|
+
icon?: React.ComponentType<{
|
|
72
|
+
className?: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** Component to render for this route */
|
|
75
|
+
component: React.ComponentType;
|
|
76
|
+
/** Parent group in navigation (optional) */
|
|
77
|
+
group?: 'main' | 'development' | 'dataModel' | 'saas' | 'admin' | 'custom';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Main configuration for DOShell
|
|
81
|
+
*/
|
|
82
|
+
interface DOShellConfig {
|
|
83
|
+
/** RPC and API configuration (existing DOAdminConfig) */
|
|
84
|
+
do: DOAdminConfig;
|
|
85
|
+
/** Base URL path for the shell (e.g., '/admin') */
|
|
86
|
+
basePath?: string;
|
|
87
|
+
/** Default namespace to select on load */
|
|
88
|
+
defaultNamespace?: string;
|
|
89
|
+
/** Branding configuration */
|
|
90
|
+
branding?: DOBranding;
|
|
91
|
+
/** Theme configuration */
|
|
92
|
+
theme?: DOTheme;
|
|
93
|
+
/**
|
|
94
|
+
* Enable/disable built-in routes.
|
|
95
|
+
* Use route names as keys (e.g., { agents: false, workflows: false })
|
|
96
|
+
*/
|
|
97
|
+
routes?: Partial<Record<string, boolean>>;
|
|
98
|
+
/** Add custom routes to the shell */
|
|
99
|
+
customRoutes?: DOCustomRoute[];
|
|
100
|
+
/** Authentication configuration */
|
|
101
|
+
identity: DOIdentity;
|
|
102
|
+
/**
|
|
103
|
+
* Development token for bypassing auth in dev mode.
|
|
104
|
+
* Use with identity.devMode for local development.
|
|
105
|
+
*/
|
|
106
|
+
devToken?: string;
|
|
107
|
+
/** Enable debug mode with extra logging */
|
|
108
|
+
debug?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Context value provided by DOShellProvider
|
|
112
|
+
*/
|
|
113
|
+
interface DOShellContextValue {
|
|
114
|
+
/** Shell configuration */
|
|
115
|
+
config: DOShellConfig;
|
|
116
|
+
/** Current namespace */
|
|
117
|
+
namespace: string;
|
|
118
|
+
/** Set current namespace */
|
|
119
|
+
setNamespace: (ns: string) => void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type { DOIdentity as D, DOBranding as a, DOTheme as b, DOCustomRoute as c, DOShellConfig as d, DOShellContextValue as e };
|
|
@@ -11,7 +11,7 @@ import { z } from 'zod';
|
|
|
11
11
|
* - ctx.storage.put/get/delete for persistence
|
|
12
12
|
* - blockConcurrencyWhile() for atomic operations
|
|
13
13
|
* - alarms for scheduled events
|
|
14
|
-
* - RPC via
|
|
14
|
+
* - RPC via capnweb for communication
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -138,51 +138,34 @@ interface DOMetrics {
|
|
|
138
138
|
alarmsTriggered: number;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
142
|
-
|
|
143
|
-
type ConflictStrategy = 'last-write-wins' | 'merge' | ConflictResolver;
|
|
144
|
-
type ConflictResolver = <T>(local: T, remote: T, base?: T) => T;
|
|
145
|
-
/**
|
|
146
|
-
* Offline persistence configuration
|
|
147
|
-
*/
|
|
148
|
-
interface OfflineConfig {
|
|
149
|
-
/** Enable IndexedDB persistence */
|
|
150
|
-
enabled: boolean;
|
|
151
|
-
/** IndexedDB database name */
|
|
152
|
-
dbName?: string;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Sync status for DO connection
|
|
141
|
+
* @deprecated Sync status is no longer available in the simplified RPC-only architecture.
|
|
142
|
+
* Kept for backward compatibility.
|
|
156
143
|
*/
|
|
157
144
|
type SyncStatus = 'disconnected' | 'connecting' | 'syncing' | 'synced' | 'error';
|
|
158
145
|
/**
|
|
159
146
|
* Configuration for DO admin interface
|
|
160
147
|
*
|
|
161
|
-
*
|
|
162
|
-
* - REST API mode: Traditional fetch-based API calls
|
|
163
|
-
* - TanStack DB mode: Reactive local-first with WebSocket sync
|
|
148
|
+
* Simplified single-mode RPC architecture using capnweb.
|
|
164
149
|
*/
|
|
165
150
|
interface DOAdminConfig {
|
|
166
|
-
/** API endpoint for DO management
|
|
151
|
+
/** API endpoint for DO management and health checks */
|
|
167
152
|
apiEndpoint: string;
|
|
168
|
-
/**
|
|
169
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Explicit RPC URL for capnweb session.
|
|
155
|
+
* If not provided, defaults to `${apiEndpoint}/rpc`
|
|
156
|
+
*/
|
|
157
|
+
rpcUrl?: string;
|
|
170
158
|
/** Authentication method */
|
|
171
|
-
authMethod: 'jwt' | 'api-key' | 'oauth';
|
|
159
|
+
authMethod: 'none' | 'jwt' | 'api-key' | 'oauth';
|
|
172
160
|
/** Auth token (JWT or API key) */
|
|
173
161
|
authToken?: string;
|
|
174
162
|
/** Available DO bindings */
|
|
175
163
|
bindings: DOBinding[];
|
|
176
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Enable real-time updates via RPC subscriptions.
|
|
166
|
+
* Note: This requires backend support for RPC subscriptions.
|
|
167
|
+
*/
|
|
177
168
|
realTimeUpdates: boolean;
|
|
178
|
-
/** WebSocket endpoint for real-time (legacy, prefer doUrl) */
|
|
179
|
-
wsEndpoint?: string;
|
|
180
|
-
/** Conflict resolution strategy for sync */
|
|
181
|
-
conflictStrategy?: ConflictStrategy;
|
|
182
|
-
/** Offline persistence configuration */
|
|
183
|
-
offline?: OfflineConfig;
|
|
184
|
-
/** Collections to auto-sync */
|
|
185
|
-
collections?: string[];
|
|
186
169
|
/** Number of retries for health check (default: 3) */
|
|
187
170
|
healthCheckRetries?: number;
|
|
188
171
|
/**
|
|
@@ -190,6 +173,21 @@ interface DOAdminConfig {
|
|
|
190
173
|
* @default 30000 (30 seconds)
|
|
191
174
|
*/
|
|
192
175
|
requestTimeout?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Skip the health check on initial connection.
|
|
178
|
+
* Useful for backends without a /health endpoint.
|
|
179
|
+
* @default false
|
|
180
|
+
*/
|
|
181
|
+
skipHealthCheck?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Client type for RPC communication.
|
|
184
|
+
* - 'capnweb-ws': Cap'n Proto over WebSocket - persistent connection, real-time updates (default)
|
|
185
|
+
* - 'capnweb-http': Cap'n Proto over HTTP batch - stateless requests
|
|
186
|
+
* - 'capnweb': Legacy @dotdo/client wrapper
|
|
187
|
+
* - 'json-rpc': JSON-RPC over HTTP - simple JSON format
|
|
188
|
+
* @default 'capnweb-ws'
|
|
189
|
+
*/
|
|
190
|
+
clientType?: 'capnweb-ws' | 'capnweb-http' | 'capnweb' | 'json-rpc';
|
|
193
191
|
}
|
|
194
192
|
|
|
195
|
-
export type {
|
|
193
|
+
export type { DOStatus as D, SyncStatus as S, DOClassType as a, DOInstance as b, DOAlarm as c, DOStorageEntry as d, DOBinding as e, DORPCMethod as f, DOHealthCheck as g, DOMetrics as h, DOAdminConfig as i };
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merge class names with Tailwind CSS support
|
|
5
|
+
*/
|
|
6
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Format a semantic ID (ns/type/id)
|
|
9
|
+
*/
|
|
10
|
+
declare function formatSemanticId(ns: string, type: string, id: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Parse a semantic ID into components
|
|
13
|
+
* Format: type/namespace/id where namespace can contain slashes
|
|
14
|
+
* @throws Error if the semantic ID format is invalid
|
|
15
|
+
*/
|
|
16
|
+
declare function parseSemanticId(semanticId: string): {
|
|
17
|
+
type: string;
|
|
18
|
+
namespace: string;
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Format a date for display
|
|
23
|
+
*/
|
|
24
|
+
declare function formatDate(date: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format a date and time for display
|
|
27
|
+
*/
|
|
28
|
+
declare function formatDateTime(date: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format a relative time (e.g., "2 hours ago")
|
|
31
|
+
*/
|
|
32
|
+
declare function formatRelativeTime(date: Date | string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Format a number with abbreviation (1K, 1M, etc.)
|
|
35
|
+
*/
|
|
36
|
+
declare function formatNumber(num: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* Format bytes to human-readable string
|
|
39
|
+
*/
|
|
40
|
+
declare function formatBytes(bytes: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Format duration in milliseconds to human-readable string
|
|
43
|
+
*/
|
|
44
|
+
declare function formatDuration(ms: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Truncate text with ellipsis
|
|
47
|
+
*/
|
|
48
|
+
declare function truncate(text: string, maxLength: number, suffix?: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Capitalize first letter
|
|
51
|
+
*/
|
|
52
|
+
declare function capitalize(text: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Convert camelCase to Title Case
|
|
55
|
+
*/
|
|
56
|
+
declare function camelToTitle(text: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Generate a random ID
|
|
59
|
+
*/
|
|
60
|
+
declare function generateId(prefix?: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Debounce function
|
|
63
|
+
*
|
|
64
|
+
* Creates a debounced version of the function that delays execution
|
|
65
|
+
* until after the specified delay has passed since the last call.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const debouncedSearch = debounce((query: string) => {
|
|
70
|
+
* fetch(`/search?q=${query}`)
|
|
71
|
+
* }, 300)
|
|
72
|
+
*
|
|
73
|
+
* // Only the last call within 300ms will execute
|
|
74
|
+
* debouncedSearch('h')
|
|
75
|
+
* debouncedSearch('he')
|
|
76
|
+
* debouncedSearch('hello') // Only this one runs
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function debounce<Args extends unknown[]>(fn: (...args: Args) => unknown, delay: number): (...args: Args) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Group array by key
|
|
82
|
+
*/
|
|
83
|
+
declare function groupBy<T, K extends string | number>(array: T[], keyFn: (item: T) => K): Record<K, T[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for retry with exponential backoff
|
|
86
|
+
*/
|
|
87
|
+
interface RetryConfig {
|
|
88
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
89
|
+
maxRetries?: number;
|
|
90
|
+
/** Base multiplier for backoff in ms (default: 1000). Backoff = 2^attempt * multiplier */
|
|
91
|
+
backoffMultiplier?: number;
|
|
92
|
+
/** Optional AbortSignal for cancellation */
|
|
93
|
+
signal?: AbortSignal;
|
|
94
|
+
/** Callback invoked before each retry with the error and attempt number */
|
|
95
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Execute an async function with retry and exponential backoff
|
|
99
|
+
*
|
|
100
|
+
* Retries the provided function on failure with exponential backoff delays.
|
|
101
|
+
* Backoff formula: 2^attempt * backoffMultiplier (default: 1s, 2s, 4s, etc.)
|
|
102
|
+
*
|
|
103
|
+
* @param fn - Async function to execute
|
|
104
|
+
* @param config - Retry configuration
|
|
105
|
+
* @returns Promise resolving to the function result
|
|
106
|
+
* @throws Last error if all retries exhausted
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* // Basic usage
|
|
111
|
+
* const result = await retryWithBackoff(
|
|
112
|
+
* () => fetch('/api/health'),
|
|
113
|
+
* { maxRetries: 3 }
|
|
114
|
+
* )
|
|
115
|
+
*
|
|
116
|
+
* // With cancellation
|
|
117
|
+
* const controller = new AbortController()
|
|
118
|
+
* const result = await retryWithBackoff(
|
|
119
|
+
* () => fetch('/api/health'),
|
|
120
|
+
* { maxRetries: 3, signal: controller.signal }
|
|
121
|
+
* )
|
|
122
|
+
* // Later: controller.abort()
|
|
123
|
+
*
|
|
124
|
+
* // With retry callback
|
|
125
|
+
* const result = await retryWithBackoff(
|
|
126
|
+
* () => fetch('/api/health'),
|
|
127
|
+
* {
|
|
128
|
+
* maxRetries: 3,
|
|
129
|
+
* onRetry: (error, attempt) => console.log(`Retry ${attempt}: ${error.message}`)
|
|
130
|
+
* }
|
|
131
|
+
* )
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function retryWithBackoff<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Fetch wrapper with configurable timeout
|
|
138
|
+
*
|
|
139
|
+
* Prevents indefinite hangs on slow networks or unresponsive servers
|
|
140
|
+
* by wrapping fetch with AbortController-based timeout.
|
|
141
|
+
*
|
|
142
|
+
* @module
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Default timeout in milliseconds (30 seconds)
|
|
146
|
+
*/
|
|
147
|
+
declare const DEFAULT_REQUEST_TIMEOUT = 30000;
|
|
148
|
+
/**
|
|
149
|
+
* Extended RequestInit that includes optional timeout
|
|
150
|
+
*/
|
|
151
|
+
interface FetchWithTimeoutOptions extends RequestInit {
|
|
152
|
+
/** Timeout in milliseconds. Defaults to 30000 (30 seconds) */
|
|
153
|
+
timeout?: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Fetch wrapper with configurable timeout
|
|
157
|
+
*
|
|
158
|
+
* Uses AbortController to cancel requests that exceed the timeout.
|
|
159
|
+
* If the request already has a signal, a composite abort will be used
|
|
160
|
+
* that respects both the existing signal and the timeout.
|
|
161
|
+
*
|
|
162
|
+
* @param url - The URL to fetch
|
|
163
|
+
* @param options - Fetch options including optional timeout
|
|
164
|
+
* @returns Promise resolving to the Response
|
|
165
|
+
* @throws {DOMException} AbortError if the request times out
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Basic usage with default 30s timeout
|
|
170
|
+
* const response = await fetchWithTimeout('https://api.example.com/data')
|
|
171
|
+
*
|
|
172
|
+
* // Custom timeout
|
|
173
|
+
* const response = await fetchWithTimeout('https://api.example.com/data', {
|
|
174
|
+
* timeout: 5000, // 5 seconds
|
|
175
|
+
* })
|
|
176
|
+
*
|
|
177
|
+
* // With other fetch options
|
|
178
|
+
* const response = await fetchWithTimeout('https://api.example.com/data', {
|
|
179
|
+
* method: 'POST',
|
|
180
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
181
|
+
* body: JSON.stringify({ key: 'value' }),
|
|
182
|
+
* timeout: 10000,
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function fetchWithTimeout(url: string, options?: FetchWithTimeoutOptions): Promise<Response>;
|
|
187
|
+
/**
|
|
188
|
+
* Create a fetch wrapper with a default timeout from config
|
|
189
|
+
*
|
|
190
|
+
* Useful for creating a configured fetch function that can be shared
|
|
191
|
+
* across multiple hooks/components with consistent timeout behavior.
|
|
192
|
+
*
|
|
193
|
+
* @param defaultTimeout - Default timeout in milliseconds
|
|
194
|
+
* @returns A fetch function with the default timeout applied
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* // Create a configured fetch
|
|
199
|
+
* const configuredFetch = createFetchWithTimeout(5000)
|
|
200
|
+
*
|
|
201
|
+
* // Use it (timeout defaults to 5000ms)
|
|
202
|
+
* const response = await configuredFetch('https://api.example.com/data')
|
|
203
|
+
*
|
|
204
|
+
* // Override the default timeout
|
|
205
|
+
* const response = await configuredFetch('https://api.example.com/data', {
|
|
206
|
+
* timeout: 10000,
|
|
207
|
+
* })
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function createFetchWithTimeout(defaultTimeout: number): (url: string, options?: FetchWithTimeoutOptions) => Promise<Response>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Standardized error classes for @mdxui/do
|
|
214
|
+
*
|
|
215
|
+
* These classes provide consistent error handling across the package:
|
|
216
|
+
* - APIError: HTTP/RPC errors from the backend
|
|
217
|
+
* - NetworkError: Connection/fetch failures
|
|
218
|
+
* - ValidationError: Input validation errors
|
|
219
|
+
* - SyncError: Real-time sync errors
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* import { APIError, NetworkError, isAPIError } from '@mdxui/do'
|
|
224
|
+
*
|
|
225
|
+
* try {
|
|
226
|
+
* const response = await fetch(url)
|
|
227
|
+
* if (!response.ok) {
|
|
228
|
+
* throw APIError.fromResponse(response)
|
|
229
|
+
* }
|
|
230
|
+
* } catch (error) {
|
|
231
|
+
* if (isAPIError(error)) {
|
|
232
|
+
* console.log(`API error ${error.code}: ${error.message}`)
|
|
233
|
+
* if (error.status === 401) {
|
|
234
|
+
* // Handle auth error
|
|
235
|
+
* }
|
|
236
|
+
* } else if (isNetworkError(error)) {
|
|
237
|
+
* console.log('Network unavailable, will retry...')
|
|
238
|
+
* }
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* API error from HTTP/RPC calls
|
|
244
|
+
*
|
|
245
|
+
* Provides structured error information including:
|
|
246
|
+
* - code: Machine-readable error code (e.g., 'HTTP_404', 'VALIDATION_ERROR')
|
|
247
|
+
* - message: Human-readable error message
|
|
248
|
+
* - status: HTTP status code (when applicable)
|
|
249
|
+
* - details: Additional error details from the server
|
|
250
|
+
*/
|
|
251
|
+
declare class APIError extends Error {
|
|
252
|
+
readonly code: string;
|
|
253
|
+
readonly status?: number | undefined;
|
|
254
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
255
|
+
constructor(code: string, message: string, status?: number | undefined, details?: Record<string, unknown> | undefined);
|
|
256
|
+
/**
|
|
257
|
+
* Create an APIError from a fetch Response
|
|
258
|
+
*
|
|
259
|
+
* @param response - The Response object from fetch
|
|
260
|
+
* @param body - Optional response body text (if already read)
|
|
261
|
+
* @returns An APIError with HTTP status information
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const response = await fetch('/api/things')
|
|
266
|
+
* if (!response.ok) {
|
|
267
|
+
* throw APIError.fromResponse(response, await response.text())
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
static fromResponse(response: Response, body?: string): APIError;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to check if an error is an APIError
|
|
274
|
+
*/
|
|
275
|
+
static isAPIError(error: unknown): error is APIError;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Network-level error (connection failures, timeouts, etc.)
|
|
279
|
+
*
|
|
280
|
+
* Use for errors that occur before an HTTP response is received:
|
|
281
|
+
* - DNS resolution failures
|
|
282
|
+
* - Connection refused
|
|
283
|
+
* - Request timeouts
|
|
284
|
+
* - CORS errors
|
|
285
|
+
*/
|
|
286
|
+
declare class NetworkError extends Error {
|
|
287
|
+
readonly cause?: Error | undefined;
|
|
288
|
+
constructor(message: string, cause?: Error | undefined);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Validation error with field-level details
|
|
292
|
+
*
|
|
293
|
+
* Use when input data fails validation checks.
|
|
294
|
+
* The fields property maps field names to arrays of error messages.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* throw new ValidationError('Invalid input', {
|
|
299
|
+
* email: ['Invalid email format'],
|
|
300
|
+
* name: ['Name is required', 'Name must be at least 2 characters'],
|
|
301
|
+
* })
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
declare class ValidationError extends Error {
|
|
305
|
+
readonly fields: Record<string, string[]>;
|
|
306
|
+
constructor(message: string, fields: Record<string, string[]>);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Real-time sync error
|
|
310
|
+
*
|
|
311
|
+
* Use for errors in the sync protocol (WebSocket, EventSource, etc.).
|
|
312
|
+
* The operation property indicates what sync operation failed.
|
|
313
|
+
* The recoverable property indicates whether the client should retry.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* // Recoverable connection error - client should retry
|
|
318
|
+
* throw new SyncError('WebSocket disconnected', 'connect', true)
|
|
319
|
+
*
|
|
320
|
+
* // Non-recoverable push error - user intervention needed
|
|
321
|
+
* throw new SyncError('Conflict: record modified by another user', 'push', false)
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare class SyncError extends Error {
|
|
325
|
+
readonly operation: 'push' | 'pull' | 'connect';
|
|
326
|
+
readonly recoverable: boolean;
|
|
327
|
+
constructor(message: string, operation: 'push' | 'pull' | 'connect', recoverable: boolean);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Type guard to check if an error is an APIError
|
|
331
|
+
*/
|
|
332
|
+
declare function isAPIError(error: unknown): error is APIError;
|
|
333
|
+
/**
|
|
334
|
+
* Type guard to check if an error is a NetworkError
|
|
335
|
+
*/
|
|
336
|
+
declare function isNetworkError(error: unknown): error is NetworkError;
|
|
337
|
+
/**
|
|
338
|
+
* Type guard to check if an error is a ValidationError
|
|
339
|
+
*/
|
|
340
|
+
declare function isValidationError(error: unknown): error is ValidationError;
|
|
341
|
+
/**
|
|
342
|
+
* Type guard to check if an error is a SyncError
|
|
343
|
+
*/
|
|
344
|
+
declare function isSyncError(error: unknown): error is SyncError;
|
|
345
|
+
|
|
346
|
+
export { APIError as A, DEFAULT_REQUEST_TIMEOUT as D, type FetchWithTimeoutOptions as F, NetworkError as N, type RetryConfig as R, SyncError as S, ValidationError as V, formatDate as a, formatDateTime as b, cn as c, formatRelativeTime as d, formatNumber as e, formatSemanticId as f, formatBytes as g, formatDuration as h, capitalize as i, camelToTitle as j, generateId as k, debounce as l, groupBy as m, fetchWithTimeout as n, isAPIError as o, parseSemanticId as p, isNetworkError as q, isValidationError as r, isSyncError as s, truncate as t, retryWithBackoff as u, createFetchWithTimeout as v };
|