@seenn/types 0.1.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 ADDED
@@ -0,0 +1,81 @@
1
+ # @seenn/types
2
+
3
+ Shared TypeScript types for all Seenn SDKs. This package is the **single source of truth** for type definitions.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @seenn/types
9
+ # or
10
+ pnpm add @seenn/types
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import type {
17
+ SeennJob,
18
+ JobStatus,
19
+ StageInfo,
20
+ ConnectionState,
21
+ SSEEventType,
22
+ } from '@seenn/types';
23
+ ```
24
+
25
+ ## SDK Sync Guidelines
26
+
27
+ When updating types in this package:
28
+
29
+ 1. **Bump version** in package.json
30
+ 2. **Publish** to npm: `npm publish`
31
+ 3. **Update all SDKs** to use new version:
32
+ - `@seenn/react-native`
33
+ - `@seenn/node`
34
+ - `seenn_flutter` (generate from TypeScript)
35
+
36
+ ### Version Compatibility
37
+
38
+ | @seenn/types | @seenn/react-native | @seenn/node | seenn_flutter |
39
+ |--------------|---------------------|-------------|---------------|
40
+ | 0.1.0 | 0.2.6+ | 0.2.2+ | 0.1.0+ |
41
+
42
+ ## Type Categories
43
+
44
+ ### Core Types
45
+ - `SeennJob` - Main job object
46
+ - `JobStatus` - Status enum
47
+ - `StageInfo`, `QueueInfo` - Progress info
48
+ - `JobResult`, `JobError` - Completion data
49
+
50
+ ### Parent-Child Types
51
+ - `ParentInfo`, `ChildrenStats` - Relationship data
52
+ - `ChildJobSummary` - Child job info
53
+ - `ParentWithChildren` - Full parent with children
54
+
55
+ ### SSE Types
56
+ - `ConnectionState` - SSE connection states
57
+ - `SSEEventType` - All SSE event types
58
+ - `SSEEvent` - Event wrapper
59
+
60
+ ### API Types
61
+ - `CreateJobParams`, `UpdateJobParams` - Request types
62
+ - `CompleteJobParams`, `FailJobParams` - Completion types
63
+
64
+ ### Live Activity Types
65
+ - `LiveActivityStartParams`, `LiveActivityUpdateParams`
66
+ - `LiveActivityEndParams`, `LiveActivityResult`
67
+
68
+ ## Flutter Integration
69
+
70
+ For Flutter SDK, generate Dart types from this package:
71
+
72
+ ```bash
73
+ # In seenn-platform root
74
+ pnpm run generate:flutter-types
75
+ ```
76
+
77
+ This runs `scripts/generate-flutter-types.ts` which converts TypeScript to Dart.
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,416 @@
1
+ /**
2
+ * @seenn/types - Shared TypeScript types for Seenn SDKs
3
+ *
4
+ * This package is the single source of truth for all Seenn type definitions.
5
+ * All SDK packages (react-native, node, flutter) should depend on this package.
6
+ *
7
+ * @version 0.1.0
8
+ * @license MIT
9
+ */
10
+ /**
11
+ * Job status values
12
+ */
13
+ type JobStatus = 'pending' | 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
14
+ /**
15
+ * How parent job progress is calculated from children
16
+ */
17
+ type ChildProgressMode = 'average' | 'weighted' | 'sequential';
18
+ /**
19
+ * Main job object returned by API and SSE
20
+ */
21
+ interface SeennJob {
22
+ /** Unique job identifier (ULID format) */
23
+ jobId: string;
24
+ /** User who owns this job */
25
+ userId: string;
26
+ /** Application ID */
27
+ appId: string;
28
+ /** Current job status */
29
+ status: JobStatus;
30
+ /** Human-readable job title */
31
+ title: string;
32
+ /** Job type for categorization */
33
+ jobType: string;
34
+ /** Workflow ID for ETA tracking (default: jobType) */
35
+ workflowId?: string;
36
+ /** Progress percentage (0-100) */
37
+ progress: number;
38
+ /** Current status message */
39
+ message?: string;
40
+ /** Stage information for multi-step jobs */
41
+ stage?: StageInfo;
42
+ /** Estimated completion timestamp (ISO 8601) */
43
+ estimatedCompletionAt?: string;
44
+ /** ETA confidence score (0.0 - 1.0) */
45
+ etaConfidence?: number;
46
+ /** Number of historical jobs used to calculate ETA */
47
+ etaBasedOn?: number;
48
+ /** Queue position info */
49
+ queue?: QueueInfo;
50
+ /** Job result on completion */
51
+ result?: JobResult;
52
+ /** Error details on failure */
53
+ error?: JobError;
54
+ /** Custom metadata */
55
+ metadata?: Record<string, unknown>;
56
+ /** Parent info (if this is a child job) */
57
+ parent?: ParentInfo;
58
+ /** Children stats (if this is a parent job) */
59
+ children?: ChildrenStats;
60
+ /** Progress calculation mode for parent jobs */
61
+ childProgressMode?: ChildProgressMode;
62
+ /** Job creation timestamp (ISO 8601) */
63
+ createdAt: string;
64
+ /** Last update timestamp (ISO 8601) */
65
+ updatedAt: string;
66
+ /** When the job started running (ISO 8601) */
67
+ startedAt?: string;
68
+ /** Job completion timestamp (ISO 8601) */
69
+ completedAt?: string;
70
+ }
71
+ /**
72
+ * Stage information for multi-step jobs
73
+ */
74
+ interface StageInfo {
75
+ /** Current stage name */
76
+ name: string;
77
+ /** Current stage index (1-based) */
78
+ current: number;
79
+ /** Total number of stages */
80
+ total: number;
81
+ /** Optional stage description */
82
+ description?: string;
83
+ }
84
+ /**
85
+ * Queue position information
86
+ */
87
+ interface QueueInfo {
88
+ /** Position in queue (1-based) */
89
+ position: number;
90
+ /** Total items in queue */
91
+ total?: number;
92
+ /** Queue name/identifier */
93
+ queueName?: string;
94
+ }
95
+ /**
96
+ * Job result on successful completion
97
+ */
98
+ interface JobResult {
99
+ /** Result type (e.g., 'video', 'image', 'file') */
100
+ type?: string;
101
+ /** Result URL if applicable */
102
+ url?: string;
103
+ /** Additional result data */
104
+ data?: Record<string, unknown>;
105
+ }
106
+ /**
107
+ * Error details on job failure
108
+ */
109
+ interface JobError {
110
+ /** Error code for programmatic handling */
111
+ code: string;
112
+ /** Human-readable error message */
113
+ message: string;
114
+ /** Additional error details */
115
+ details?: Record<string, unknown>;
116
+ }
117
+ /**
118
+ * Parent info for child jobs
119
+ */
120
+ interface ParentInfo {
121
+ /** Parent job ID */
122
+ parentJobId: string;
123
+ /** Child index within parent (0-based) */
124
+ childIndex: number;
125
+ }
126
+ /**
127
+ * Children stats for parent jobs
128
+ */
129
+ interface ChildrenStats {
130
+ /** Total number of children */
131
+ total: number;
132
+ /** Number of completed children */
133
+ completed: number;
134
+ /** Number of failed children */
135
+ failed: number;
136
+ /** Number of running children */
137
+ running: number;
138
+ /** Number of pending children */
139
+ pending: number;
140
+ }
141
+ /**
142
+ * Summary of a child job (used in parent.children array)
143
+ */
144
+ interface ChildJobSummary {
145
+ /** Child job ID */
146
+ id: string;
147
+ /** Child index within parent (0-based) */
148
+ childIndex: number;
149
+ /** Child job title */
150
+ title: string;
151
+ /** Child job status */
152
+ status: JobStatus;
153
+ /** Child progress (0-100) */
154
+ progress: number;
155
+ /** Child status message */
156
+ message?: string;
157
+ /** Child result */
158
+ result?: JobResult;
159
+ /** Child error */
160
+ error?: JobError;
161
+ /** Child creation timestamp */
162
+ createdAt: string;
163
+ /** Child last update timestamp */
164
+ updatedAt: string;
165
+ /** Child completion timestamp */
166
+ completedAt?: string;
167
+ }
168
+ /**
169
+ * Parent job with all its children
170
+ */
171
+ interface ParentWithChildren {
172
+ /** Parent job */
173
+ parent: SeennJob;
174
+ /** List of child jobs */
175
+ children: ChildJobSummary[];
176
+ }
177
+ /**
178
+ * Connection state for SSE
179
+ */
180
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
181
+ /**
182
+ * SSE event types
183
+ */
184
+ type SSEEventType = 'connected' | 'job.sync' | 'job.started' | 'job.progress' | 'job.completed' | 'job.failed' | 'job.cancelled' | 'child.progress' | 'parent.updated' | 'in_app_message' | 'connection.idle' | 'heartbeat' | 'error';
185
+ /**
186
+ * SSE event wrapper
187
+ */
188
+ interface SSEEvent {
189
+ /** Event type */
190
+ event: SSEEventType;
191
+ /** Event data */
192
+ data: unknown;
193
+ /** Event ID for replay */
194
+ id?: string;
195
+ }
196
+ /**
197
+ * In-app message types
198
+ */
199
+ type InAppMessageType = 'job_complete_banner' | 'job_failed_modal' | 'job_toast';
200
+ /**
201
+ * In-app message for UI notifications
202
+ */
203
+ interface InAppMessage {
204
+ /** Message ID */
205
+ messageId: string;
206
+ /** Message type */
207
+ type: InAppMessageType;
208
+ /** Associated job ID */
209
+ jobId: string;
210
+ /** Message title */
211
+ title: string;
212
+ /** Message body */
213
+ body?: string;
214
+ /** Call-to-action text */
215
+ cta?: string;
216
+ /** Call-to-action URL */
217
+ ctaUrl?: string;
218
+ }
219
+ /**
220
+ * Create job request parameters
221
+ */
222
+ interface CreateJobParams {
223
+ /** User ID */
224
+ userId: string;
225
+ /** Job type */
226
+ jobType: string;
227
+ /** Job title */
228
+ title: string;
229
+ /** Workflow ID for ETA tracking (default: jobType) */
230
+ workflowId?: string;
231
+ /** Initial message */
232
+ message?: string;
233
+ /** Custom metadata */
234
+ metadata?: Record<string, unknown>;
235
+ /** Estimated duration in ms (for ETA default) */
236
+ estimatedDuration?: number;
237
+ /** Parent job ID (for child jobs) */
238
+ parentJobId?: string;
239
+ /** Child index (for child jobs) */
240
+ childIndex?: number;
241
+ /** Total children (for parent jobs) */
242
+ totalChildren?: number;
243
+ /** Child progress mode (for parent jobs) */
244
+ childProgressMode?: ChildProgressMode;
245
+ }
246
+ /**
247
+ * Update job request parameters
248
+ */
249
+ interface UpdateJobParams {
250
+ /** New progress (0-100) */
251
+ progress?: number;
252
+ /** New message */
253
+ message?: string;
254
+ /** New stage info */
255
+ stage?: StageInfo;
256
+ /** Custom metadata to merge */
257
+ metadata?: Record<string, unknown>;
258
+ }
259
+ /**
260
+ * Complete job request parameters
261
+ */
262
+ interface CompleteJobParams {
263
+ /** Job result */
264
+ result?: JobResult;
265
+ /** Final message */
266
+ message?: string;
267
+ }
268
+ /**
269
+ * Fail job request parameters
270
+ */
271
+ interface FailJobParams {
272
+ /** Error details */
273
+ error: JobError;
274
+ }
275
+ /**
276
+ * Webhook event types
277
+ */
278
+ type WebhookEventType = 'job.started' | 'job.progress' | 'job.completed' | 'job.failed' | 'job.cancelled';
279
+ /**
280
+ * Webhook payload
281
+ */
282
+ interface WebhookPayload {
283
+ /** Event type */
284
+ event: WebhookEventType;
285
+ /** Job data */
286
+ job: SeennJob;
287
+ /** Event timestamp (ISO 8601) */
288
+ timestamp: string;
289
+ /** Webhook delivery ID */
290
+ deliveryId: string;
291
+ }
292
+ /**
293
+ * ETA statistics for a workflow/jobType
294
+ */
295
+ interface EtaStats {
296
+ /** ETA key (workflowId or jobType) */
297
+ etaKey: string;
298
+ /** Number of completed jobs */
299
+ count: number;
300
+ /** Average duration in ms */
301
+ avgDuration: number;
302
+ /** Minimum duration in ms */
303
+ minDuration: number;
304
+ /** Maximum duration in ms */
305
+ maxDuration: number;
306
+ /** Default duration if no history */
307
+ defaultDuration?: number;
308
+ /** Last updated timestamp */
309
+ lastUpdated: string;
310
+ }
311
+ /**
312
+ * Base SDK configuration
313
+ */
314
+ interface SeennConfig {
315
+ /** API base URL */
316
+ baseUrl: string;
317
+ /** Authentication token (pk_* for client, sk_* for server) */
318
+ authToken?: string;
319
+ /** SSE endpoint URL (default: baseUrl + /v1/sse) */
320
+ sseUrl?: string;
321
+ /** Enable auto-reconnect (default: true) */
322
+ reconnect?: boolean;
323
+ /** Reconnect interval in ms (default: 1000) */
324
+ reconnectInterval?: number;
325
+ /** Max reconnect attempts (default: 10) */
326
+ maxReconnectAttempts?: number;
327
+ /** Enable debug logging (default: false) */
328
+ debug?: boolean;
329
+ }
330
+ /**
331
+ * Live Activity start parameters
332
+ */
333
+ interface LiveActivityStartParams {
334
+ /** Job ID */
335
+ jobId: string;
336
+ /** Activity title */
337
+ title: string;
338
+ /** Job type for icon selection */
339
+ jobType?: string;
340
+ /** Initial progress (0-100) */
341
+ initialProgress?: number;
342
+ /** Initial message */
343
+ initialMessage?: string;
344
+ }
345
+ /**
346
+ * Live Activity update parameters
347
+ */
348
+ interface LiveActivityUpdateParams {
349
+ /** Job ID */
350
+ jobId: string;
351
+ /** New progress (0-100) */
352
+ progress?: number;
353
+ /** New status */
354
+ status?: JobStatus;
355
+ /** New message */
356
+ message?: string;
357
+ /** Stage info */
358
+ stage?: StageInfo;
359
+ /** ETA timestamp (Unix ms) */
360
+ estimatedEndTime?: number;
361
+ }
362
+ /**
363
+ * Live Activity end parameters
364
+ */
365
+ interface LiveActivityEndParams {
366
+ /** Job ID */
367
+ jobId: string;
368
+ /** Final status */
369
+ finalStatus?: JobStatus;
370
+ /** Final progress */
371
+ finalProgress?: number;
372
+ /** Final message */
373
+ message?: string;
374
+ /** Result URL */
375
+ resultUrl?: string;
376
+ /** Error message */
377
+ errorMessage?: string;
378
+ /** Dismiss after seconds (default: 300) */
379
+ dismissAfter?: number;
380
+ }
381
+ /**
382
+ * Live Activity result
383
+ */
384
+ interface LiveActivityResult {
385
+ /** Success flag */
386
+ success: boolean;
387
+ /** Activity ID (platform-specific) */
388
+ activityId?: string;
389
+ /** Associated job ID */
390
+ jobId?: string;
391
+ /** Error message if failed */
392
+ error?: string;
393
+ }
394
+ /**
395
+ * Push token event for Live Activity updates
396
+ */
397
+ interface LiveActivityPushTokenEvent {
398
+ /** Job ID */
399
+ jobId: string;
400
+ /** APNs push token */
401
+ token: string;
402
+ }
403
+ /**
404
+ * SDK version info
405
+ */
406
+ declare const SDK_VERSION = "0.1.0";
407
+ /**
408
+ * Minimum API version required
409
+ */
410
+ declare const MIN_API_VERSION = "1.0.0";
411
+ /**
412
+ * SSE protocol version
413
+ */
414
+ declare const SSE_PROTOCOL_VERSION = "1.0";
415
+
416
+ export { type ChildJobSummary, type ChildProgressMode, type ChildrenStats, type CompleteJobParams, type ConnectionState, type CreateJobParams, type EtaStats, type FailJobParams, type InAppMessage, type InAppMessageType, type JobError, type JobResult, type JobStatus, type LiveActivityEndParams, type LiveActivityPushTokenEvent, type LiveActivityResult, type LiveActivityStartParams, type LiveActivityUpdateParams, MIN_API_VERSION, type ParentInfo, type ParentWithChildren, type QueueInfo, SDK_VERSION, type SSEEvent, type SSEEventType, SSE_PROTOCOL_VERSION, type SeennConfig, type SeennJob, type StageInfo, type UpdateJobParams, type WebhookEventType, type WebhookPayload };