@plyaz/types 1.36.0 → 1.36.2

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 (44) hide show
  1. package/dist/api/index.cjs +199 -1
  2. package/dist/api/index.cjs.map +1 -1
  3. package/dist/api/index.js +199 -1
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/auth/index.cjs +1 -2
  6. package/dist/auth/index.cjs.map +1 -1
  7. package/dist/auth/index.js +1 -2
  8. package/dist/auth/index.js.map +1 -1
  9. package/dist/campaign/schemas.d.ts +1 -1
  10. package/dist/core/domain/files/enums.d.ts +36 -0
  11. package/dist/core/domain/files/index.d.ts +4 -1
  12. package/dist/core/domain/files/schemas.d.ts +14 -21
  13. package/dist/core/domain/files/streaming.d.ts +167 -0
  14. package/dist/core/events/index.d.ts +2 -0
  15. package/dist/core/events/streaming/index.d.ts +18 -0
  16. package/dist/core/events/streaming/responses.d.ts +164 -0
  17. package/dist/core/events/streaming/types.d.ts +408 -0
  18. package/dist/core/frontend/index.d.ts +1 -1
  19. package/dist/core/frontend/types.d.ts +179 -5
  20. package/dist/core/index.cjs +221 -0
  21. package/dist/core/index.cjs.map +1 -1
  22. package/dist/core/index.d.ts +1 -1
  23. package/dist/core/index.js +192 -1
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/init/index.d.ts +1 -1
  26. package/dist/core/init/types.d.ts +51 -0
  27. package/dist/errors/codes.d.ts +47 -0
  28. package/dist/errors/enums.d.ts +1 -0
  29. package/dist/errors/index.cjs +231 -1
  30. package/dist/errors/index.cjs.map +1 -1
  31. package/dist/errors/index.js +231 -2
  32. package/dist/errors/index.js.map +1 -1
  33. package/dist/errors/types.d.ts +15 -0
  34. package/dist/index.cjs +450 -1
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.js +420 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/store/files/index.d.ts +1 -1
  39. package/dist/store/files/types.d.ts +47 -1
  40. package/dist/store/index.d.ts +1 -0
  41. package/dist/store/stream/index.d.ts +9 -0
  42. package/dist/store/stream/types.d.ts +294 -0
  43. package/dist/store/types.d.ts +3 -0
  44. package/package.json +1 -1
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * Store types for files/media domain.
5
5
  */
6
- export type { FilesStoreItem, GeneratedFileItem, FilesFrontendStoreState, FilesFrontendStoreData, FilesFrontendStoreActions, FilesFrontendStoreSlice, FilesStoreSelectors, } from './types';
6
+ export type { FilesStoreItem, GeneratedFileItem, FileUploadProgressState, FileDownloadProgressState, FileGenerateProgress, FilesFrontendStoreState, FilesFrontendStoreData, FilesFrontendStoreActions, FilesFrontendStoreSlice, FilesStoreSelectors, } from './types';
@@ -6,7 +6,8 @@
6
6
  * API types are in @plyaz/types/api/endpoints/files.
7
7
  */
8
8
  import type { CoreBaseFrontendStore } from '../../core/frontend';
9
- import type { FilesEntity, FileType } from '../../core/domain/files';
9
+ import type { FilesEntity, FileType, FilesDownloadStreamProgress } from '../../core/domain/files';
10
+ import type { UploadProgressEvent } from '../../storage';
10
11
  /**
11
12
  * Serializable store item for files
12
13
  */
@@ -41,6 +42,35 @@ export interface GeneratedFileItem {
41
42
  filename: string;
42
43
  generatedAt: string;
43
44
  }
45
+ /**
46
+ * Extended upload progress with status for store tracking
47
+ * Extends storage's UploadProgressEvent with additional UI state
48
+ */
49
+ export interface FileUploadProgressState extends UploadProgressEvent {
50
+ /** Upload status for UI display */
51
+ status: 'pending' | 'uploading' | 'downloading' | 'processing' | 'generating' | 'completed' | 'failed' | 'cancelled';
52
+ /** Error message if failed */
53
+ error?: string;
54
+ }
55
+ /**
56
+ * Download progress state for store tracking
57
+ * Extends core's FilesDownloadStreamProgress with additional UI state
58
+ */
59
+ export interface FileDownloadProgressState extends FilesDownloadStreamProgress {
60
+ }
61
+ /**
62
+ * Progress state for document generation
63
+ */
64
+ export interface FileGenerateProgress {
65
+ /** Template ID being generated */
66
+ templateId: string;
67
+ /** Progress percentage (0-100) */
68
+ percentage: number;
69
+ /** Generation status */
70
+ status: 'pending' | 'uploading' | 'downloading' | 'processing' | 'generating' | 'completed' | 'failed' | 'cancelled';
71
+ /** Error message if failed */
72
+ error?: string;
73
+ }
44
74
  /**
45
75
  * Files store state
46
76
  */
@@ -55,6 +85,14 @@ export interface FilesFrontendStoreState {
55
85
  isLoading: boolean;
56
86
  isUploading: boolean;
57
87
  isGenerating: boolean;
88
+ /** Progress tracking for uploads (keyed by fileId) */
89
+ uploadProgress: Record<string, FileUploadProgressState>;
90
+ /** Progress tracking for downloads (keyed by fileId) */
91
+ downloadProgress: Record<string, FileDownloadProgressState>;
92
+ /** Progress tracking for document generation */
93
+ generateProgress: FileGenerateProgress | null;
94
+ /** Overall upload progress percentage (0-100) for bulk uploads */
95
+ overallUploadProgress: number;
58
96
  }
59
97
  /**
60
98
  * Files store data for setData()
@@ -85,6 +123,14 @@ export interface FilesFrontendStoreActions extends CoreBaseFrontendStore<FilesFr
85
123
  setLoading: (isLoading: boolean) => void;
86
124
  setUploading: (isUploading: boolean) => void;
87
125
  setGenerating: (isGenerating: boolean) => void;
126
+ setUploadProgress: (fileId: string, progress: Partial<FileUploadProgressState>) => void;
127
+ removeUploadProgress: (fileId: string) => void;
128
+ clearUploadProgress: () => void;
129
+ setDownloadProgress: (fileId: string, progress: Partial<FileDownloadProgressState>) => void;
130
+ removeDownloadProgress: (fileId: string) => void;
131
+ clearDownloadProgress: () => void;
132
+ setGenerateProgress: (progress: FileGenerateProgress | null) => void;
133
+ setOverallUploadProgress: (percentage: number) => void;
88
134
  reset: () => void;
89
135
  }
90
136
  /**
@@ -2,3 +2,4 @@ export type * from './types';
2
2
  export { STORE_KEYS, ALL_STORE_KEYS } from './keys';
3
3
  export type { StoreKey } from './keys';
4
4
  export type * from './files';
5
+ export type * from './stream';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Stream Store Types
3
+ *
4
+ * Export all stream store types.
5
+ *
6
+ * Note: This store is CONNECTION-ONLY.
7
+ * Domain-specific progress belongs in domain stores (files, etc.)
8
+ */
9
+ export type { StreamMessageHandler, RegisteredStreamHandler, StreamMessageFilter, StreamStoreState, StreamStoreActions, StreamStoreSlice, StreamStoreSelectors, UseStreamStoreResult, UseStreamHandlerOptions, StreamErrorData, StreamSliceConfig, } from './types';
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Stream Store Types
3
+ *
4
+ * Store state, actions, and slice types for real-time streaming.
5
+ * This is a GLOBAL store slice (like errors, featureFlags), NOT per-service.
6
+ *
7
+ * IMPORTANT: This store handles CONNECTION STATE and MESSAGE HISTORY only.
8
+ * - Domain-specific progress belongs in domain stores (files, etc.)
9
+ * - Stream errors go to the GLOBAL errors store (not stream store)
10
+ *
11
+ * Domain stores (like files) use selectors to filter messages from this store
12
+ * by type, subtype, scope, transport, etc.
13
+ */
14
+ import type { StreamMessage, StreamMessageType, StreamMessageSubtype, StreamMessageScope, StreamTransportType } from '../../core/events/streaming';
15
+ /**
16
+ * Stream message handler function.
17
+ * Domain services register handlers to receive and process stream messages.
18
+ *
19
+ * @typeParam T - Type of message.data payload (default: unknown)
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Type-safe handler for upload progress
24
+ * const handler: StreamMessageHandler<FilesUploadStreamProgress> = (message) => {
25
+ * // message.data is typed as FilesUploadStreamProgress
26
+ * console.log(message.data.percentage);
27
+ * };
28
+ * ```
29
+ */
30
+ export type StreamMessageHandler<T = unknown> = (message: StreamMessage<T>) => void;
31
+ /**
32
+ * Registered message handler with metadata
33
+ */
34
+ export interface RegisteredStreamHandler {
35
+ /** Handler function (stores as unknown for registry, typed at call site) */
36
+ handler: StreamMessageHandler<unknown>;
37
+ /** Channels this handler is interested in (empty = all channels) */
38
+ channels: string[];
39
+ /** Event types this handler is interested in (empty = all events) */
40
+ events: string[];
41
+ /** Handler priority (higher = called first) */
42
+ priority: number;
43
+ }
44
+ /**
45
+ * Options for filtering stream messages
46
+ */
47
+ export interface StreamMessageFilter {
48
+ /** Filter by message type */
49
+ type?: StreamMessageType | StreamMessageType[];
50
+ /** Filter by message subtype */
51
+ subtype?: StreamMessageSubtype | StreamMessageSubtype[];
52
+ /** Filter by domain scope */
53
+ scope?: StreamMessageScope | StreamMessageScope[];
54
+ /** Filter by transport */
55
+ transport?: StreamTransportType | StreamTransportType[];
56
+ /** Filter by channel (exact or prefix match) */
57
+ channel?: string | string[];
58
+ /** Filter by event name */
59
+ event?: string | string[];
60
+ /** Limit number of results */
61
+ limit?: number;
62
+ /** Only messages after this timestamp */
63
+ since?: number;
64
+ }
65
+ /**
66
+ * Global stream store state
67
+ *
68
+ * This is a GLOBAL slice (like errors, featureFlags), NOT per-service like primaryStore.
69
+ * Handles CONNECTION STATE and MESSAGE HISTORY only.
70
+ *
71
+ * NOTE: Stream errors go to the GLOBAL errors store, NOT here.
72
+ * Domain progress belongs in domain stores (files, etc.).
73
+ */
74
+ export interface StreamStoreState {
75
+ /** Whether SSE/WebSocket connection is established */
76
+ connected: boolean;
77
+ /** Connection ID (from server) */
78
+ connectionId: string | null;
79
+ /** Transport type in use */
80
+ transport: 'sse' | 'websocket' | null;
81
+ /** Reconnect attempt count */
82
+ reconnectAttempts: number;
83
+ /**
84
+ * Recent messages with full metadata (type, subtype, scope, transport).
85
+ * Domain stores use selectors to filter messages from this list.
86
+ * Automatically trimmed to last N messages (configurable).
87
+ */
88
+ messages: StreamMessage[];
89
+ /** Maximum messages to keep */
90
+ maxMessages: number;
91
+ /**
92
+ * Currently subscribed channels
93
+ * Updated by domain services via subscribeToChannel/unsubscribeFromChannel
94
+ */
95
+ subscribedChannels: string[];
96
+ /**
97
+ * Registered message handlers by ID
98
+ * Domain services register handlers to receive their stream messages
99
+ */
100
+ handlers: Record<string, RegisteredStreamHandler>;
101
+ }
102
+ /**
103
+ * Stream store actions
104
+ *
105
+ * Note: No progress actions here - those belong in domain stores!
106
+ * Stream errors go to the GLOBAL errors store.
107
+ * This store manages connection state, message history, and routing.
108
+ */
109
+ export interface StreamStoreActions {
110
+ /** Set connection state */
111
+ setConnected(connected: boolean): void;
112
+ /** Set connection ID */
113
+ setConnectionId(id: string | null): void;
114
+ /** Set transport type */
115
+ setTransport(transport: 'sse' | 'websocket' | null): void;
116
+ /** Increment reconnect attempts */
117
+ incrementReconnectAttempts(): void;
118
+ /** Reset reconnect attempts */
119
+ resetReconnectAttempts(): void;
120
+ /**
121
+ * Add a message to history.
122
+ * Messages are stored with full metadata (type, subtype, scope, transport).
123
+ */
124
+ addMessage(message: StreamMessage): void;
125
+ /** Clear all messages */
126
+ clearMessages(): void;
127
+ /** Set max messages to keep */
128
+ setMaxMessages(max: number): void;
129
+ /**
130
+ * Get messages matching filter criteria.
131
+ * Domain stores use this to select their relevant messages.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Get all upload progress messages
136
+ * const uploadMessages = getMessages({
137
+ * type: 'progress',
138
+ * subtype: 'upload',
139
+ * scope: 'files',
140
+ * });
141
+ *
142
+ * // Get recent SSE messages
143
+ * const sseMessages = getMessages({
144
+ * transport: 'sse',
145
+ * limit: 10,
146
+ * });
147
+ * ```
148
+ */
149
+ getMessages(filter?: StreamMessageFilter): StreamMessage[];
150
+ /**
151
+ * Get the latest message matching filter criteria.
152
+ */
153
+ getLatestMessage(filter?: StreamMessageFilter): StreamMessage | undefined;
154
+ /** Subscribe to a channel */
155
+ subscribeToChannel(channel: string): void;
156
+ /** Subscribe to multiple channels */
157
+ subscribeToChannels(channels: string[]): void;
158
+ /** Unsubscribe from a channel */
159
+ unsubscribeFromChannel(channel: string): void;
160
+ /** Unsubscribe from all channels */
161
+ unsubscribeFromAllChannels(): void;
162
+ /** Check if subscribed to a channel */
163
+ isSubscribedToChannel(channel: string): boolean;
164
+ /**
165
+ * Register a message handler.
166
+ * Domain services use this to receive stream messages and update their own stores.
167
+ *
168
+ * @typeParam T - Type of message.data payload for type-safe handlers
169
+ * @param id - Unique handler ID (e.g., 'files', 'notifications')
170
+ * @param handler - Handler function (generic for type-safe message.data)
171
+ * @param options - Handler options (channels, events, priority)
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // Type-safe handler for upload progress
176
+ * streamStore.registerHandler<FilesUploadStreamProgress>(
177
+ * 'files:upload',
178
+ * (message) => {
179
+ * // message.data is typed as FilesUploadStreamProgress
180
+ * console.log(message.data.percentage);
181
+ * },
182
+ * { channels: ['uploads'], events: ['upload:progress'] }
183
+ * );
184
+ * ```
185
+ */
186
+ registerHandler<T = unknown>(id: string, handler: StreamMessageHandler<T>, options?: {
187
+ channels?: string[];
188
+ events?: string[];
189
+ priority?: number;
190
+ }): void;
191
+ /**
192
+ * Unregister a message handler.
193
+ *
194
+ * @param id - Handler ID to unregister
195
+ */
196
+ unregisterHandler(id: string): void;
197
+ /**
198
+ * Handle incoming stream message.
199
+ * - Adds message to history with metadata
200
+ * - Routes to registered handlers based on channel/event matching
201
+ * - Handles connection events (connected, heartbeat, close)
202
+ * - Adds error events to global errors store
203
+ */
204
+ handleMessage(message: StreamMessage): void;
205
+ /** Reset store to initial state */
206
+ reset(): void;
207
+ }
208
+ /**
209
+ * Complete stream store slice (state + actions)
210
+ */
211
+ export interface StreamStoreSlice extends StreamStoreState, StreamStoreActions {
212
+ }
213
+ /**
214
+ * Stream store selectors
215
+ *
216
+ * Note: No progress/completed selectors - use domain store selectors instead!
217
+ * e.g., useUploadProgress() from files store
218
+ *
219
+ * Note: No error selectors - stream errors go to GLOBAL errors store.
220
+ * Use useErrors({ scope: 'stream' }) from errors store.
221
+ */
222
+ export interface StreamStoreSelectors {
223
+ /** Select connection state */
224
+ selectConnected: (state: StreamStoreState) => boolean;
225
+ /** Select connection error */
226
+ selectConnectionError: (state: StreamStoreState) => Error | null;
227
+ /** Select connection ID */
228
+ selectConnectionId: (state: StreamStoreState) => string | null;
229
+ /** Select transport type */
230
+ selectTransport: (state: StreamStoreState) => 'sse' | 'websocket' | null;
231
+ /** Select subscribed channels */
232
+ selectSubscribedChannels: (state: StreamStoreState) => string[];
233
+ /** Select messages (with optional filter) */
234
+ selectMessages: (state: StreamStoreState, filter?: StreamMessageFilter) => StreamMessage[];
235
+ /** Check if connected */
236
+ selectIsConnected: (state: StreamStoreState) => boolean;
237
+ /** Check if reconnecting */
238
+ selectIsReconnecting: (state: StreamStoreState) => boolean;
239
+ /** Select registered handler IDs */
240
+ selectHandlerIds: (state: StreamStoreState) => string[];
241
+ }
242
+ /**
243
+ * Result type for useStreamStore hook
244
+ */
245
+ export interface UseStreamStoreResult extends StreamStoreState {
246
+ /** Store actions */
247
+ actions: StreamStoreActions;
248
+ }
249
+ /**
250
+ * Stream error data from an error event message.
251
+ * Used by `onError` callback to create SerializedError.
252
+ */
253
+ export interface StreamErrorData {
254
+ /** Error code (from STREAM_ERROR_CODES or custom) */
255
+ code?: string;
256
+ /** Error message */
257
+ message: string;
258
+ /** Error context/details */
259
+ context?: Record<string, unknown>;
260
+ /** Original error (if available) */
261
+ originalError?: Error;
262
+ /** Channel where error occurred */
263
+ channel?: string;
264
+ /** Event type that caused error */
265
+ event?: string;
266
+ }
267
+ /**
268
+ * Configuration for creating a stream slice.
269
+ * Used to wire up error routing to the global errors store.
270
+ */
271
+ export interface StreamSliceConfig {
272
+ /**
273
+ * Callback to add errors to the global errors store.
274
+ * Called when:
275
+ * - handleMessage receives an 'error' event
276
+ * - A registered handler throws an error
277
+ *
278
+ * @param error - Stream error data to be serialized and added
279
+ */
280
+ onError?: (error: StreamErrorData) => void;
281
+ }
282
+ /**
283
+ * Options for useStreamHandler hook
284
+ */
285
+ export interface UseStreamHandlerOptions {
286
+ /** Handler ID (must be unique) */
287
+ id: string;
288
+ /** Channels to listen to (empty = all) */
289
+ channels?: string[];
290
+ /** Event types to listen to (empty = all) */
291
+ events?: string[];
292
+ /** Handler priority (higher = called first, default: 0) */
293
+ priority?: number;
294
+ }
@@ -10,6 +10,7 @@ import type { SerializedError, ErrorStoreActions, ErrorStoreSlice } from '../err
10
10
  import type { FeatureFlagStoreState, FeatureFlagStoreSlice } from '../features/feature-flag/store.types';
11
11
  import type { ExampleFrontendStoreSlice } from '../examples';
12
12
  import type { FilesFrontendStoreSlice } from './files/types';
13
+ import type { StreamStoreSlice } from './stream/types';
13
14
  /**
14
15
  * Configuration for creating an error store.
15
16
  */
@@ -84,6 +85,8 @@ export interface RootStoreSlice {
84
85
  errors: ErrorStoreSlice;
85
86
  /** Feature flags slice (global) */
86
87
  featureFlags: FeatureFlagStoreSlice;
88
+ /** Stream events slice (global) - for real-time SSE/WebSocket */
89
+ stream: StreamStoreSlice;
87
90
  /** Example domain slice */
88
91
  example: ExampleFrontendStoreSlice;
89
92
  /** Files/media domain slice */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",