@plyaz/types 1.35.4 → 1.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.cjs +199 -1
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.js +199 -1
- package/dist/api/index.js.map +1 -1
- package/dist/auth/index.cjs +1 -2
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.js +1 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/campaign/schemas.d.ts +1 -1
- package/dist/core/domain/files/enums.d.ts +36 -0
- package/dist/core/domain/files/index.d.ts +6 -1
- package/dist/core/domain/files/schemas.d.ts +183 -0
- package/dist/core/domain/files/streaming.d.ts +167 -0
- package/dist/core/domain/files/types.d.ts +5 -67
- package/dist/core/events/index.d.ts +2 -0
- package/dist/core/events/streaming/index.d.ts +18 -0
- package/dist/core/events/streaming/responses.d.ts +164 -0
- package/dist/core/events/streaming/types.d.ts +408 -0
- package/dist/core/frontend/index.d.ts +1 -1
- package/dist/core/frontend/types.d.ts +179 -5
- package/dist/core/index.cjs +221 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +192 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/init/index.d.ts +1 -1
- package/dist/core/init/types.d.ts +51 -0
- package/dist/errors/codes.d.ts +47 -0
- package/dist/errors/enums.d.ts +1 -0
- package/dist/errors/index.cjs +231 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js +231 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/types.d.ts +15 -0
- package/dist/examples/schemas.d.ts +1 -1
- package/dist/index.cjs +450 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +420 -2
- package/dist/index.js.map +1 -1
- package/dist/store/files/index.d.ts +1 -1
- package/dist/store/files/types.d.ts +47 -1
- package/dist/store/index.d.ts +1 -0
- package/dist/store/stream/index.d.ts +9 -0
- package/dist/store/stream/types.d.ts +303 -0
- package/dist/store/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream Response Types
|
|
3
|
+
*
|
|
4
|
+
* Response types for real-time streaming that follow the API patterns.
|
|
5
|
+
* Uses standard ErrorResponse from @plyaz/types/errors.
|
|
6
|
+
*/
|
|
7
|
+
import type { ErrorResponse, PackageErrorLike } from '../../../errors/types';
|
|
8
|
+
import type { StreamAuthResult, StreamConnection, StreamMessage } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Stream response wrapper - consistent with API ReturnResponseType
|
|
11
|
+
*/
|
|
12
|
+
export interface StreamResponse<T = unknown> {
|
|
13
|
+
/** Whether the operation succeeded */
|
|
14
|
+
success: boolean;
|
|
15
|
+
/** Human-readable message */
|
|
16
|
+
message: string;
|
|
17
|
+
/** Response data payload */
|
|
18
|
+
data?: T;
|
|
19
|
+
/** Channel this response is for */
|
|
20
|
+
channel: string;
|
|
21
|
+
/** Unix timestamp when response was created */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Correlation ID for tracing */
|
|
24
|
+
correlationId?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Stream error event - uses standard ErrorResponse
|
|
28
|
+
*/
|
|
29
|
+
export interface StreamErrorEvent {
|
|
30
|
+
/** Always false for errors */
|
|
31
|
+
success: false;
|
|
32
|
+
/** Standard ErrorResponse array from @plyaz/types/errors */
|
|
33
|
+
errors: ErrorResponse;
|
|
34
|
+
/** Channel this error occurred on */
|
|
35
|
+
channel: string;
|
|
36
|
+
/** Unix timestamp when error occurred */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
/** Correlation ID for tracing */
|
|
39
|
+
correlationId?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Paginated stream response for large datasets
|
|
43
|
+
*/
|
|
44
|
+
export interface PaginatedStreamResponse<T = unknown> extends StreamResponse<T[]> {
|
|
45
|
+
/** Pagination metadata */
|
|
46
|
+
pagination: {
|
|
47
|
+
/** Total items available */
|
|
48
|
+
total: number;
|
|
49
|
+
/** Current page number */
|
|
50
|
+
page: number;
|
|
51
|
+
/** Items per page */
|
|
52
|
+
pageSize: number;
|
|
53
|
+
/** Whether more items exist */
|
|
54
|
+
hasMore: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Configuration for stream endpoints
|
|
59
|
+
*/
|
|
60
|
+
export interface StreamEndpointConfig {
|
|
61
|
+
/** Unique endpoint key (like serviceKey in domain services) */
|
|
62
|
+
endpointKey: string;
|
|
63
|
+
/** Human-readable name */
|
|
64
|
+
name?: string;
|
|
65
|
+
/** Channels this endpoint manages */
|
|
66
|
+
channels: string[];
|
|
67
|
+
/** Whether endpoint is enabled */
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
/** Supported runtimes */
|
|
70
|
+
supportedRuntimes?: Array<'node' | 'bun' | 'deno' | 'edge'>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Options for creating stream endpoints
|
|
74
|
+
*/
|
|
75
|
+
export interface StreamEndpointCreateOptions {
|
|
76
|
+
/** Broadcaster interface */
|
|
77
|
+
broadcaster: StreamBroadcasterInterface;
|
|
78
|
+
/** Optional auth adapter */
|
|
79
|
+
auth?: unknown;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Interface for StreamBroadcaster (for dependency injection)
|
|
83
|
+
*/
|
|
84
|
+
export interface StreamBroadcasterInterface {
|
|
85
|
+
/** Initialize event subscriptions and cleanup timer */
|
|
86
|
+
initialize(): void;
|
|
87
|
+
/** Broadcast message to a channel (fire-and-forget) */
|
|
88
|
+
broadcastToChannel(channel: string, message: unknown): void;
|
|
89
|
+
/** Send message to a specific connection */
|
|
90
|
+
sendToConnection(connectionId: string, message: unknown): Promise<void>;
|
|
91
|
+
/** Broadcast to all connections (system-wide) */
|
|
92
|
+
broadcastToAll(message: unknown): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for channel controllers
|
|
96
|
+
*/
|
|
97
|
+
export interface ChannelControllerConfig {
|
|
98
|
+
/** Channel scope (e.g., 'upload', 'generate', 'system') */
|
|
99
|
+
scope: string;
|
|
100
|
+
/** Channel patterns this controller handles */
|
|
101
|
+
patterns: string[];
|
|
102
|
+
/** Whether controller is enabled */
|
|
103
|
+
enabled?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Context passed to stream middleware
|
|
107
|
+
*/
|
|
108
|
+
export interface StreamMiddlewareContext {
|
|
109
|
+
/** Active connection */
|
|
110
|
+
connection: StreamConnection;
|
|
111
|
+
/** Auth result for the connection */
|
|
112
|
+
authResult: StreamAuthResult;
|
|
113
|
+
/** Message being processed (if any) */
|
|
114
|
+
message?: StreamMessage;
|
|
115
|
+
/** Target channel (if any) */
|
|
116
|
+
channel?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Result returned by stream middleware
|
|
120
|
+
*/
|
|
121
|
+
export interface StreamMiddlewareResult {
|
|
122
|
+
/** Whether to continue to next middleware */
|
|
123
|
+
continue: boolean;
|
|
124
|
+
/** Updated context (merged with current) */
|
|
125
|
+
context?: Partial<StreamMiddlewareContext>;
|
|
126
|
+
/** Error to return (if continue is false) */
|
|
127
|
+
error?: PackageErrorLike;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Stream middleware function signature
|
|
131
|
+
*/
|
|
132
|
+
export type StreamMiddleware = (context: StreamMiddlewareContext) => Promise<StreamMiddlewareResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Rate limit middleware configuration
|
|
135
|
+
*/
|
|
136
|
+
export interface RateLimitConfig {
|
|
137
|
+
/** Max connections per IP */
|
|
138
|
+
maxConnectionsPerIp?: number;
|
|
139
|
+
/** Max messages per second per connection */
|
|
140
|
+
maxMessagesPerSecond?: number;
|
|
141
|
+
/** Window size in ms */
|
|
142
|
+
windowMs?: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Entry for registering stream endpoints
|
|
146
|
+
*/
|
|
147
|
+
export interface StreamEndpointEntry {
|
|
148
|
+
/** Endpoint class with static create() */
|
|
149
|
+
endpoint: {
|
|
150
|
+
endpointKey: string;
|
|
151
|
+
create(config: StreamEndpointConfig, options: StreamEndpointCreateOptions): Promise<unknown>;
|
|
152
|
+
};
|
|
153
|
+
/** Endpoint configuration overrides */
|
|
154
|
+
config: Partial<StreamEndpointConfig>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configuration for StreamRegistry initialization
|
|
158
|
+
*/
|
|
159
|
+
export interface StreamRegistryConfig {
|
|
160
|
+
/** Stream endpoints to register */
|
|
161
|
+
endpoints: StreamEndpointEntry[];
|
|
162
|
+
/** Broadcaster instance */
|
|
163
|
+
broadcaster: StreamBroadcasterInterface;
|
|
164
|
+
}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming Types
|
|
3
|
+
*
|
|
4
|
+
* Global types for real-time event streaming via SSE/WebSocket.
|
|
5
|
+
*
|
|
6
|
+
* Architecture:
|
|
7
|
+
* - Domain services define their own streaming constants (e.g., FILES_STREAM_SUBTYPE)
|
|
8
|
+
* - Global constants here MERGE domain-specific constants
|
|
9
|
+
* - System constants (heartbeat, connection) are defined here as base
|
|
10
|
+
*
|
|
11
|
+
* To add a new domain:
|
|
12
|
+
* 1. Create streaming constants in the domain folder (e.g., /domain/payments/streaming.ts)
|
|
13
|
+
* 2. Import domain constants here
|
|
14
|
+
* 3. Merge into global constants (STREAM_MESSAGE_TYPE, STREAM_SUBTYPE, etc.)
|
|
15
|
+
*/
|
|
16
|
+
import type { FilesStreamMessageType, FilesStreamSubtype, FilesStreamProgressStatus, FilesUploadStreamProgress, FilesDownloadStreamProgress, FilesGenerateStreamProgress, FilesStreamProgressData, FilesStreamChannel } from '../../domain/files';
|
|
17
|
+
import type { CorePlyazStreamConfig } from '../../frontend';
|
|
18
|
+
import type { RootStoreHook } from '../../../store';
|
|
19
|
+
import type { PackageErrorLike } from '../../../errors';
|
|
20
|
+
/**
|
|
21
|
+
* Supported transport types for streaming connections
|
|
22
|
+
*/
|
|
23
|
+
export declare const STREAM_TRANSPORT: {
|
|
24
|
+
readonly SSE: "sse";
|
|
25
|
+
readonly WEBSOCKET: "websocket";
|
|
26
|
+
};
|
|
27
|
+
export type StreamTransportType = (typeof STREAM_TRANSPORT)[keyof typeof STREAM_TRANSPORT];
|
|
28
|
+
/**
|
|
29
|
+
* System-level message type categories.
|
|
30
|
+
* Used for connection lifecycle and system-wide events.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SYSTEM_STREAM_MESSAGE_TYPE: {
|
|
33
|
+
readonly SYSTEM: "system";
|
|
34
|
+
readonly NOTIFICATION: "notification";
|
|
35
|
+
readonly DATA: "data";
|
|
36
|
+
};
|
|
37
|
+
export type SystemStreamMessageType = (typeof SYSTEM_STREAM_MESSAGE_TYPE)[keyof typeof SYSTEM_STREAM_MESSAGE_TYPE];
|
|
38
|
+
/**
|
|
39
|
+
* System-level message subtypes (not domain-specific).
|
|
40
|
+
* Used for connection lifecycle and system events.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SYSTEM_STREAM_SUBTYPE: {
|
|
43
|
+
readonly HEARTBEAT: "heartbeat";
|
|
44
|
+
readonly CONNECTED: "connected";
|
|
45
|
+
readonly DISCONNECTED: "disconnected";
|
|
46
|
+
readonly RECONNECTING: "reconnecting";
|
|
47
|
+
};
|
|
48
|
+
export type SystemStreamSubtype = (typeof SYSTEM_STREAM_SUBTYPE)[keyof typeof SYSTEM_STREAM_SUBTYPE];
|
|
49
|
+
/**
|
|
50
|
+
* System channel for connection-level events.
|
|
51
|
+
*/
|
|
52
|
+
export declare const SYSTEM_STREAM_CHANNEL: {
|
|
53
|
+
readonly SYSTEM: "system";
|
|
54
|
+
};
|
|
55
|
+
export type SystemStreamChannel = (typeof SYSTEM_STREAM_CHANNEL)[keyof typeof SYSTEM_STREAM_CHANNEL];
|
|
56
|
+
/**
|
|
57
|
+
* All message type categories.
|
|
58
|
+
* Merged from system + all domain-specific types.
|
|
59
|
+
*
|
|
60
|
+
* To add a new domain's message types:
|
|
61
|
+
* 1. Define `{DOMAIN}_STREAM_MESSAGE_TYPE` in the domain's streaming module
|
|
62
|
+
* 2. Import and spread into this object
|
|
63
|
+
*/
|
|
64
|
+
export declare const STREAM_MESSAGE_TYPE: {
|
|
65
|
+
readonly PROGRESS: "progress";
|
|
66
|
+
readonly STATUS: "status";
|
|
67
|
+
readonly ERROR: "error";
|
|
68
|
+
readonly SYSTEM: "system";
|
|
69
|
+
readonly NOTIFICATION: "notification";
|
|
70
|
+
readonly DATA: "data";
|
|
71
|
+
};
|
|
72
|
+
export type StreamMessageType = SystemStreamMessageType | FilesStreamMessageType;
|
|
73
|
+
/**
|
|
74
|
+
* All message subtypes.
|
|
75
|
+
* Merged from system + all domain-specific subtypes.
|
|
76
|
+
*
|
|
77
|
+
* To add a new domain's subtypes:
|
|
78
|
+
* 1. Define `{DOMAIN}_STREAM_SUBTYPE` in the domain's streaming module
|
|
79
|
+
* 2. Import and spread into this object
|
|
80
|
+
*/
|
|
81
|
+
export declare const STREAM_SUBTYPE: {
|
|
82
|
+
readonly UPLOAD: "upload";
|
|
83
|
+
readonly DOWNLOAD: "download";
|
|
84
|
+
readonly GENERATE: "generate";
|
|
85
|
+
readonly HEARTBEAT: "heartbeat";
|
|
86
|
+
readonly CONNECTED: "connected";
|
|
87
|
+
readonly DISCONNECTED: "disconnected";
|
|
88
|
+
readonly RECONNECTING: "reconnecting";
|
|
89
|
+
};
|
|
90
|
+
export type StreamMessageSubtype = SystemStreamSubtype | FilesStreamSubtype;
|
|
91
|
+
/**
|
|
92
|
+
* Message scope identifies the domain that owns the message.
|
|
93
|
+
* Used for routing messages to the correct domain store.
|
|
94
|
+
*
|
|
95
|
+
* To add a new domain:
|
|
96
|
+
* 1. Add the domain name to this constant
|
|
97
|
+
* 2. Create domain streaming types in the domain's types folder
|
|
98
|
+
*/
|
|
99
|
+
export declare const STREAM_SCOPE: {
|
|
100
|
+
readonly FILES: "files";
|
|
101
|
+
readonly SYSTEM: "system";
|
|
102
|
+
};
|
|
103
|
+
export type StreamMessageScope = (typeof STREAM_SCOPE)[keyof typeof STREAM_SCOPE];
|
|
104
|
+
/**
|
|
105
|
+
* System stream events.
|
|
106
|
+
*/
|
|
107
|
+
export declare const SYSTEM_STREAM_EVENT: {
|
|
108
|
+
readonly CONNECTED: "connected";
|
|
109
|
+
readonly DISCONNECTED: "disconnected";
|
|
110
|
+
readonly HEARTBEAT: "heartbeat";
|
|
111
|
+
readonly ERROR: "error";
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* All stream events.
|
|
115
|
+
* Merged from system + all domain-specific events.
|
|
116
|
+
*/
|
|
117
|
+
export declare const STREAM_EVENT: {
|
|
118
|
+
readonly UPLOAD_PROGRESS: "upload:progress";
|
|
119
|
+
readonly UPLOAD_COMPLETED: "upload:completed";
|
|
120
|
+
readonly UPLOAD_FAILED: "upload:failed";
|
|
121
|
+
readonly UPLOAD_CANCELLED: "upload:cancelled";
|
|
122
|
+
readonly DOWNLOAD_PROGRESS: "download:progress";
|
|
123
|
+
readonly DOWNLOAD_COMPLETED: "download:completed";
|
|
124
|
+
readonly DOWNLOAD_FAILED: "download:failed";
|
|
125
|
+
readonly DOWNLOAD_CANCELLED: "download:cancelled";
|
|
126
|
+
readonly GENERATE_PROGRESS: "generate:progress";
|
|
127
|
+
readonly GENERATE_COMPLETED: "generate:completed";
|
|
128
|
+
readonly GENERATE_FAILED: "generate:failed";
|
|
129
|
+
readonly CONNECTED: "connected";
|
|
130
|
+
readonly DISCONNECTED: "disconnected";
|
|
131
|
+
readonly HEARTBEAT: "heartbeat";
|
|
132
|
+
readonly ERROR: "error";
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* All channel prefixes (for subscription matching).
|
|
136
|
+
*/
|
|
137
|
+
export declare const STREAM_CHANNEL_PREFIX: {
|
|
138
|
+
readonly UPLOAD: "upload:";
|
|
139
|
+
readonly DOWNLOAD: "download:";
|
|
140
|
+
readonly GENERATE: "generate:";
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* All broadcast channels (user-scoped).
|
|
144
|
+
*/
|
|
145
|
+
export declare const STREAM_BROADCAST_CHANNEL: {
|
|
146
|
+
readonly UPLOADS: "uploads";
|
|
147
|
+
readonly DOWNLOADS: "downloads";
|
|
148
|
+
readonly GENERATIONS: "generations";
|
|
149
|
+
readonly SYSTEM: "system";
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* All possible channel patterns.
|
|
153
|
+
* Union of system channel + all domain-specific channels.
|
|
154
|
+
*/
|
|
155
|
+
export type StreamChannel = SystemStreamChannel | FilesStreamChannel;
|
|
156
|
+
/**
|
|
157
|
+
* Represents an active streaming connection
|
|
158
|
+
*/
|
|
159
|
+
export interface StreamConnection {
|
|
160
|
+
/** Unique connection identifier */
|
|
161
|
+
id: string;
|
|
162
|
+
/** Authenticated user ID (undefined for anonymous) */
|
|
163
|
+
userId?: string;
|
|
164
|
+
/** Transport type (SSE or WebSocket) */
|
|
165
|
+
transport: StreamTransportType;
|
|
166
|
+
/** Subscribed channels */
|
|
167
|
+
channels: Set<string>;
|
|
168
|
+
/** Connection creation timestamp */
|
|
169
|
+
createdAt: Date;
|
|
170
|
+
/** Last activity timestamp (for cleanup) */
|
|
171
|
+
lastActivity: Date;
|
|
172
|
+
/** Additional connection metadata */
|
|
173
|
+
metadata?: Record<string, unknown>;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Serializable version of StreamConnection for storage/transmission
|
|
177
|
+
*/
|
|
178
|
+
export interface StreamConnectionInfo {
|
|
179
|
+
id: string;
|
|
180
|
+
userId?: string;
|
|
181
|
+
transport: StreamTransportType;
|
|
182
|
+
channels: string[];
|
|
183
|
+
createdAt: string;
|
|
184
|
+
lastActivity: string;
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Message sent to streaming clients.
|
|
189
|
+
*
|
|
190
|
+
* @typeParam T - Payload data type (defaults to unknown)
|
|
191
|
+
*/
|
|
192
|
+
export interface StreamMessage<T = unknown> {
|
|
193
|
+
/** Event name (e.g., 'upload:progress', 'connected', 'heartbeat') */
|
|
194
|
+
event: string;
|
|
195
|
+
/** Event payload data */
|
|
196
|
+
data: T;
|
|
197
|
+
/** Optional message ID (for SSE reconnection) */
|
|
198
|
+
id?: string;
|
|
199
|
+
/** Optional retry interval in ms (for SSE) */
|
|
200
|
+
retry?: number;
|
|
201
|
+
/** Channel this message was sent to */
|
|
202
|
+
channel?: string;
|
|
203
|
+
/** Message type category */
|
|
204
|
+
type?: StreamMessageType;
|
|
205
|
+
/** Message subtype for granular filtering */
|
|
206
|
+
subtype?: StreamMessageSubtype;
|
|
207
|
+
/** Domain scope for routing to domain stores */
|
|
208
|
+
scope?: StreamMessageScope;
|
|
209
|
+
/** Transport used (sse or websocket) */
|
|
210
|
+
transport?: StreamTransportType;
|
|
211
|
+
/** Timestamp when message was created */
|
|
212
|
+
timestamp?: number;
|
|
213
|
+
/** Correlation ID for request tracing */
|
|
214
|
+
correlationId?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Progress data union type.
|
|
218
|
+
* Currently files-only, will expand as domains add streaming support.
|
|
219
|
+
*/
|
|
220
|
+
export type StreamProgressData = FilesStreamProgressData;
|
|
221
|
+
/**
|
|
222
|
+
* Progress status union type.
|
|
223
|
+
* Currently files-only, will expand as domains add streaming support.
|
|
224
|
+
*/
|
|
225
|
+
export type StreamProgressStatus = FilesStreamProgressStatus;
|
|
226
|
+
/**
|
|
227
|
+
* All progress status constants.
|
|
228
|
+
*/
|
|
229
|
+
export declare const STREAM_PROGRESS_STATUS: {
|
|
230
|
+
readonly PENDING: "pending";
|
|
231
|
+
readonly UPLOADING: "uploading";
|
|
232
|
+
readonly DOWNLOADING: "downloading";
|
|
233
|
+
readonly PROCESSING: "processing";
|
|
234
|
+
readonly GENERATING: "generating";
|
|
235
|
+
readonly COMPLETED: "completed";
|
|
236
|
+
readonly FAILED: "failed";
|
|
237
|
+
readonly CANCELLED: "cancelled";
|
|
238
|
+
};
|
|
239
|
+
export type { FilesUploadStreamProgress, FilesDownloadStreamProgress, FilesGenerateStreamProgress };
|
|
240
|
+
/**
|
|
241
|
+
* Channel subscription record
|
|
242
|
+
*/
|
|
243
|
+
export interface ChannelSubscription {
|
|
244
|
+
/** Channel name */
|
|
245
|
+
channel: string;
|
|
246
|
+
/** Connection ID */
|
|
247
|
+
connectionId: string;
|
|
248
|
+
/** Subscription timestamp */
|
|
249
|
+
subscribedAt: Date;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Result of authentication attempt
|
|
253
|
+
*/
|
|
254
|
+
export interface StreamAuthResult {
|
|
255
|
+
/** Whether authentication succeeded */
|
|
256
|
+
authenticated: boolean;
|
|
257
|
+
/** User ID (if authenticated) */
|
|
258
|
+
userId?: string;
|
|
259
|
+
/** Allowed channel patterns (e.g., ['upload:', 'generate:']) */
|
|
260
|
+
scopes?: string[];
|
|
261
|
+
/** Additional auth metadata */
|
|
262
|
+
metadata?: Record<string, unknown>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Base configuration for auth adapters
|
|
266
|
+
*/
|
|
267
|
+
export interface StreamAuthAdapterConfig {
|
|
268
|
+
/** Adapter name for logging */
|
|
269
|
+
name: string;
|
|
270
|
+
/** Whether adapter is enabled */
|
|
271
|
+
enabled?: boolean;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Configuration for token-based auth adapter
|
|
275
|
+
*/
|
|
276
|
+
export interface TokenAuthAdapterConfig extends StreamAuthAdapterConfig {
|
|
277
|
+
/** Token verification function */
|
|
278
|
+
verifyToken: (token: string) => Promise<{
|
|
279
|
+
valid: boolean;
|
|
280
|
+
userId?: string;
|
|
281
|
+
scopes?: string[];
|
|
282
|
+
}>;
|
|
283
|
+
/** Header name for token (default: 'Authorization') */
|
|
284
|
+
headerName?: string;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Base configuration for transport adapters
|
|
288
|
+
*/
|
|
289
|
+
export interface StreamTransportAdapterConfig {
|
|
290
|
+
/** Adapter name for logging */
|
|
291
|
+
name: string;
|
|
292
|
+
/** Heartbeat interval in ms (default: 30000) */
|
|
293
|
+
heartbeatInterval?: number;
|
|
294
|
+
/** Maximum concurrent connections (default: 1000) */
|
|
295
|
+
maxConnections?: number;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Configuration for StreamBroadcaster
|
|
299
|
+
*/
|
|
300
|
+
export interface StreamBroadcasterConfig {
|
|
301
|
+
/** Heartbeat interval in ms */
|
|
302
|
+
heartbeatInterval?: number;
|
|
303
|
+
/** Connection timeout in ms (for cleanup) */
|
|
304
|
+
connectionTimeout?: number;
|
|
305
|
+
/** Maximum stale connection age in ms before cleanup */
|
|
306
|
+
maxStaleAge?: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Statistics for stream manager
|
|
310
|
+
*/
|
|
311
|
+
export interface StreamManagerStats {
|
|
312
|
+
/** Total active connections */
|
|
313
|
+
totalConnections: number;
|
|
314
|
+
/** Connections by transport type */
|
|
315
|
+
connectionsByTransport: Record<StreamTransportType, number>;
|
|
316
|
+
/** Total channel subscriptions */
|
|
317
|
+
totalSubscriptions: number;
|
|
318
|
+
/** Unique channels with subscribers */
|
|
319
|
+
activeChannels: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Return type for useStreamConnection hook
|
|
323
|
+
*
|
|
324
|
+
* Note: Errors are added to the global error store automatically.
|
|
325
|
+
* Use useErrorStore or error hooks to access connection errors.
|
|
326
|
+
*/
|
|
327
|
+
export interface UseStreamConnectionResult {
|
|
328
|
+
/** Whether connection is established */
|
|
329
|
+
connected: boolean;
|
|
330
|
+
/** Reconnect function */
|
|
331
|
+
reconnect: () => void;
|
|
332
|
+
/** Disconnect function */
|
|
333
|
+
disconnect: () => void;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Options for useStreamConnection hook
|
|
337
|
+
*
|
|
338
|
+
* @template T - The expected message data type (defaults to unknown)
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* // Without generic (message.data is unknown)
|
|
343
|
+
* useStreamConnection({
|
|
344
|
+
* channels: ['uploads'],
|
|
345
|
+
* onMessage: (message) => { ... }
|
|
346
|
+
* });
|
|
347
|
+
*
|
|
348
|
+
* // With generic (message.data is properly typed)
|
|
349
|
+
* useStreamConnection<FilesUploadStreamProgress>({
|
|
350
|
+
* channels: [`upload:${fileId}`],
|
|
351
|
+
* onMessage: (message) => {
|
|
352
|
+
* // message.data is FilesUploadStreamProgress
|
|
353
|
+
* console.log(message.data.percentage);
|
|
354
|
+
* }
|
|
355
|
+
* });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export interface UseStreamConnectionOptions<T = unknown> {
|
|
359
|
+
/** Channels to subscribe to */
|
|
360
|
+
channels: StreamChannel[];
|
|
361
|
+
/** API endpoint URL (default: '/api/events/stream') */
|
|
362
|
+
endpoint?: string;
|
|
363
|
+
/** Whether to auto-connect on mount (default: true) */
|
|
364
|
+
autoConnect?: boolean;
|
|
365
|
+
/** Reconnect on error (default: true) */
|
|
366
|
+
autoReconnect?: boolean;
|
|
367
|
+
/** Max reconnect attempts (default: 5) */
|
|
368
|
+
maxReconnectAttempts?: number;
|
|
369
|
+
/** Reconnect delay in ms (default: 1000) */
|
|
370
|
+
reconnectDelay?: number;
|
|
371
|
+
/** Callback when connected */
|
|
372
|
+
onConnect?: () => void;
|
|
373
|
+
/** Callback when disconnected */
|
|
374
|
+
onDisconnect?: () => void;
|
|
375
|
+
/** Callback on error */
|
|
376
|
+
onError?: (error: PackageErrorLike) => void;
|
|
377
|
+
/** Callback on message received (message.data is typed as T) */
|
|
378
|
+
onMessage?: (message: StreamMessage<T>) => void;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Options for useStreamManager hook
|
|
382
|
+
*
|
|
383
|
+
* Used by PlyazProvider to manage SSE connection lifecycle.
|
|
384
|
+
*/
|
|
385
|
+
export interface UseStreamManagerOptions {
|
|
386
|
+
/** Streaming configuration (required when enabled) */
|
|
387
|
+
config?: CorePlyazStreamConfig;
|
|
388
|
+
/** Root store hook for accessing stream store */
|
|
389
|
+
store: RootStoreHook;
|
|
390
|
+
/** Enable verbose logging */
|
|
391
|
+
verbose?: boolean;
|
|
392
|
+
/** Whether streaming is enabled (default: false) */
|
|
393
|
+
enabled?: boolean;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Result type for useStreamManager hook
|
|
397
|
+
*
|
|
398
|
+
* Note: Errors are added to the global error store automatically.
|
|
399
|
+
* Use useErrorStore or error hooks to access connection errors.
|
|
400
|
+
*/
|
|
401
|
+
export interface UseStreamManagerResult {
|
|
402
|
+
/** Whether connected to SSE */
|
|
403
|
+
connected: boolean;
|
|
404
|
+
/** Subscribed channels */
|
|
405
|
+
channels: StreamChannel[];
|
|
406
|
+
/** Whether streaming is enabled */
|
|
407
|
+
enabled: boolean;
|
|
408
|
+
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Core Frontend Types
|
|
3
3
|
* Type definitions for @plyaz/core frontend services
|
|
4
4
|
*/
|
|
5
|
-
export type { CoreBaseFrontendStore, CoreBaseFrontendServiceConfig, CoreBaseFrontendServiceInterface, CoreStoreHandlers, CoreOptimisticUpdateConfig, OptimisticConflictResolution, CoreFetcherFunction, CoreServiceFetchers, CorePlyazApiConfig, FrontendFeatureFlagProvider, CorePlyazFeatureFlagConfig, CorePlyazStoreConfig, CorePlyazConfig, CoreFeatureFlagServiceLike, CoreFeatureFlagFetcherOptions, CoreFeatureFlagStoreInitConfig, CoreBaseFrontendServiceConstructorConfig, CoreInitializationErrorProps, CoreInitializationLoadingProps, CorePlyazServices, CorePlyazContextValue, CorePlyazProviderProps, } from './types';
|
|
5
|
+
export type { CoreBaseFrontendStore, CoreBaseFrontendServiceConfig, CoreBaseFrontendServiceInterface, CoreStoreHandlers, CoreOptimisticUpdateConfig, OptimisticConflictResolution, CoreFetcherFunction, CoreServiceFetchers, CorePlyazApiConfig, FrontendFeatureFlagProvider, CorePlyazFeatureFlagConfig, CorePlyazStoreConfig, CorePlyazStreamConfig, CorePlyazConfig, CoreFeatureFlagServiceLike, CoreFeatureFlagFetcherOptions, CoreFeatureFlagStoreInitConfig, CoreBaseFrontendServiceConstructorConfig, CoreInitializationErrorProps, CoreInitializationLoadingProps, CorePlyazServices, CorePlyazContextValue, CorePlyazProviderProps, CoreStreamStoreGetter, CoreStreamHandlerIds, CoreStreamHandlerDeclaration, } from './types';
|
|
6
6
|
export type { CoreFrontendFeatureFlagEventType, CoreFeatureFlagStore, CoreFeatureFlagServiceConfig, CoreFeatureFlagServiceInitConfig, CoreFeatureFlagServiceInterface, } from './featureFlags';
|