@semiont/api-client 0.1.0-build.6

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 (74) hide show
  1. package/README.md +85 -0
  2. package/dist/__tests__/client.test.d.ts +28 -0
  3. package/dist/__tests__/client.test.d.ts.map +1 -0
  4. package/dist/__tests__/client.test.js +567 -0
  5. package/dist/__tests__/client.test.js.map +1 -0
  6. package/dist/__tests__/sse-client.test.d.ts +7 -0
  7. package/dist/__tests__/sse-client.test.d.ts.map +1 -0
  8. package/dist/__tests__/sse-client.test.js +421 -0
  9. package/dist/__tests__/sse-client.test.js.map +1 -0
  10. package/dist/__tests__/sse-stream.test.d.ts +7 -0
  11. package/dist/__tests__/sse-stream.test.d.ts.map +1 -0
  12. package/dist/__tests__/sse-stream.test.js +394 -0
  13. package/dist/__tests__/sse-stream.test.js.map +1 -0
  14. package/dist/__tests__/svg-selectors.test.d.ts +5 -0
  15. package/dist/__tests__/svg-selectors.test.d.ts.map +1 -0
  16. package/dist/__tests__/svg-selectors.test.js +124 -0
  17. package/dist/__tests__/svg-selectors.test.js.map +1 -0
  18. package/dist/branded-types.d.ts +70 -0
  19. package/dist/branded-types.d.ts.map +1 -0
  20. package/dist/branded-types.js +62 -0
  21. package/dist/branded-types.js.map +1 -0
  22. package/dist/client.d.ts +243 -0
  23. package/dist/client.d.ts.map +1 -0
  24. package/dist/client.js +460 -0
  25. package/dist/client.js.map +1 -0
  26. package/dist/index.d.ts +43 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +62 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/mime-utils.d.ts +27 -0
  31. package/dist/mime-utils.d.ts.map +1 -0
  32. package/dist/mime-utils.js +49 -0
  33. package/dist/mime-utils.js.map +1 -0
  34. package/dist/sse/index.d.ts +343 -0
  35. package/dist/sse/index.d.ts.map +1 -0
  36. package/dist/sse/index.js +404 -0
  37. package/dist/sse/index.js.map +1 -0
  38. package/dist/sse/stream.d.ts +58 -0
  39. package/dist/sse/stream.d.ts.map +1 -0
  40. package/dist/sse/stream.js +187 -0
  41. package/dist/sse/stream.js.map +1 -0
  42. package/dist/sse/types.d.ts +295 -0
  43. package/dist/sse/types.d.ts.map +1 -0
  44. package/dist/sse/types.js +10 -0
  45. package/dist/sse/types.js.map +1 -0
  46. package/dist/types.d.ts +3177 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +7 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/utils/annotations.d.ts +191 -0
  51. package/dist/utils/annotations.d.ts.map +1 -0
  52. package/dist/utils/annotations.js +404 -0
  53. package/dist/utils/annotations.js.map +1 -0
  54. package/dist/utils/events.d.ts +74 -0
  55. package/dist/utils/events.d.ts.map +1 -0
  56. package/dist/utils/events.js +329 -0
  57. package/dist/utils/events.js.map +1 -0
  58. package/dist/utils/index.d.ts +12 -0
  59. package/dist/utils/index.d.ts.map +1 -0
  60. package/dist/utils/index.js +28 -0
  61. package/dist/utils/index.js.map +1 -0
  62. package/dist/utils/locales.d.ts +31 -0
  63. package/dist/utils/locales.d.ts.map +1 -0
  64. package/dist/utils/locales.js +83 -0
  65. package/dist/utils/locales.js.map +1 -0
  66. package/dist/utils/resources.d.ts +34 -0
  67. package/dist/utils/resources.d.ts.map +1 -0
  68. package/dist/utils/resources.js +63 -0
  69. package/dist/utils/resources.js.map +1 -0
  70. package/dist/utils/validation.d.ts +57 -0
  71. package/dist/utils/validation.d.ts.map +1 -0
  72. package/dist/utils/validation.js +89 -0
  73. package/dist/utils/validation.js.map +1 -0
  74. package/package.json +65 -0
@@ -0,0 +1,295 @@
1
+ /**
2
+ * TypeScript types for Server-Sent Events (SSE) streaming
3
+ *
4
+ * These types match the event payloads sent by backend SSE endpoints.
5
+ * They are not validated (per SSE-VALIDATION-CONSIDERATIONS.md) but provide
6
+ * type safety for client code consuming the streams.
7
+ */
8
+ /**
9
+ * Progress event for entity detection stream
10
+ *
11
+ * Sent by POST /resources/:id/detect-annotations-stream
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * stream.onProgress((progress: DetectionProgress) => {
16
+ * if (progress.status === 'scanning') {
17
+ * console.log(`Scanning for ${progress.currentEntityType}...`);
18
+ * console.log(`Progress: ${progress.processedEntityTypes}/${progress.totalEntityTypes}`);
19
+ * }
20
+ * });
21
+ * ```
22
+ */
23
+ export interface DetectionProgress {
24
+ /** Current status of detection operation */
25
+ status: 'started' | 'scanning' | 'complete' | 'error';
26
+ /** Resource ID being scanned */
27
+ resourceId: string;
28
+ /** Currently scanning for this entity type (only present during 'scanning') */
29
+ currentEntityType?: string;
30
+ /** Total number of entity types to scan */
31
+ totalEntityTypes: number;
32
+ /** Number of entity types processed so far */
33
+ processedEntityTypes: number;
34
+ /** Human-readable status message */
35
+ message?: string;
36
+ /** Total entities found (only present in 'complete') */
37
+ foundCount?: number;
38
+ }
39
+ /**
40
+ * Progress event for resource generation stream
41
+ *
42
+ * Sent by POST /resources/:resourceId/annotations/:annotationId/generate-resource-stream
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * stream.onProgress((progress: GenerationProgress) => {
47
+ * console.log(`${progress.status}: ${progress.percentage}%`);
48
+ * console.log(progress.message);
49
+ * });
50
+ * ```
51
+ */
52
+ export interface GenerationProgress {
53
+ /** Current stage of generation operation */
54
+ status: 'started' | 'fetching' | 'generating' | 'creating' | 'complete' | 'error';
55
+ /** Annotation ID being used as source */
56
+ referenceId: string;
57
+ /** Name of resource being generated */
58
+ resourceName?: string;
59
+ /** ID of generated resource (only present in 'complete') */
60
+ resourceId?: string;
61
+ /** ID of source resource */
62
+ sourceResourceId?: string;
63
+ /** Percentage complete (0-100) */
64
+ percentage: number;
65
+ /** Human-readable status message */
66
+ message?: string;
67
+ }
68
+ /**
69
+ * Progress event for highlight detection stream
70
+ *
71
+ * Sent by POST /resources/:id/detect-highlights-stream
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * stream.onProgress((progress: HighlightDetectionProgress) => {
76
+ * if (progress.status === 'analyzing') {
77
+ * console.log(`Analyzing: ${progress.percentage}%`);
78
+ * }
79
+ * });
80
+ * ```
81
+ */
82
+ export interface HighlightDetectionProgress {
83
+ /** Current status of highlight detection operation */
84
+ status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
85
+ /** Resource ID being analyzed */
86
+ resourceId: string;
87
+ /** Current stage of processing */
88
+ stage?: 'analyzing' | 'creating';
89
+ /** Percentage complete (0-100) */
90
+ percentage?: number;
91
+ /** Human-readable status message */
92
+ message?: string;
93
+ /** Total highlights found */
94
+ foundCount?: number;
95
+ /** Total highlights created */
96
+ createdCount?: number;
97
+ }
98
+ /**
99
+ * Progress event for assessment detection stream
100
+ *
101
+ * Sent by POST /resources/:id/detect-assessments-stream
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * stream.onProgress((progress: AssessmentDetectionProgress) => {
106
+ * if (progress.status === 'analyzing') {
107
+ * console.log(`Analyzing: ${progress.percentage}%`);
108
+ * }
109
+ * });
110
+ * ```
111
+ */
112
+ export interface AssessmentDetectionProgress {
113
+ /** Current status of assessment detection operation */
114
+ status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
115
+ /** Resource ID being analyzed */
116
+ resourceId: string;
117
+ /** Current stage of processing */
118
+ stage?: 'analyzing' | 'creating';
119
+ /** Percentage complete (0-100) */
120
+ percentage?: number;
121
+ /** Human-readable status message */
122
+ message?: string;
123
+ /** Total assessments found */
124
+ foundCount?: number;
125
+ /** Total assessments created */
126
+ createdCount?: number;
127
+ }
128
+ /**
129
+ * Progress event for comment detection stream
130
+ *
131
+ * Sent by POST /resources/:id/detect-comments-stream
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * stream.onProgress((progress: CommentDetectionProgress) => {
136
+ * if (progress.status === 'analyzing') {
137
+ * console.log(`Analyzing: ${progress.percentage}%`);
138
+ * }
139
+ * });
140
+ * ```
141
+ */
142
+ export interface CommentDetectionProgress {
143
+ /** Current status of comment detection operation */
144
+ status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
145
+ /** Resource ID being analyzed */
146
+ resourceId: string;
147
+ /** Current stage of processing */
148
+ stage?: 'analyzing' | 'creating';
149
+ /** Percentage complete (0-100) */
150
+ percentage?: number;
151
+ /** Human-readable status message */
152
+ message?: string;
153
+ /** Total comments found */
154
+ foundCount?: number;
155
+ /** Total comments created */
156
+ createdCount?: number;
157
+ }
158
+ /**
159
+ * Progress event for tag detection stream
160
+ *
161
+ * Sent by POST /resources/:id/detect-tags-stream
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * stream.onProgress((progress: TagDetectionProgress) => {
166
+ * if (progress.status === 'analyzing') {
167
+ * console.log(`Analyzing ${progress.currentCategory}: ${progress.percentage}%`);
168
+ * }
169
+ * });
170
+ * ```
171
+ */
172
+ export interface TagDetectionProgress {
173
+ /** Current status of tag detection operation */
174
+ status: 'started' | 'analyzing' | 'creating' | 'complete' | 'error';
175
+ /** Resource ID being analyzed */
176
+ resourceId: string;
177
+ /** Current stage of processing */
178
+ stage?: 'analyzing' | 'creating';
179
+ /** Percentage complete (0-100) */
180
+ percentage?: number;
181
+ /** Currently processing this category */
182
+ currentCategory?: string;
183
+ /** Number of categories processed */
184
+ processedCategories?: number;
185
+ /** Total number of categories */
186
+ totalCategories?: number;
187
+ /** Human-readable status message */
188
+ message?: string;
189
+ /** Total tags found */
190
+ tagsFound?: number;
191
+ /** Total tags created */
192
+ tagsCreated?: number;
193
+ /** Tags found by category */
194
+ byCategory?: Record<string, number>;
195
+ }
196
+ /**
197
+ * Resource event from real-time event stream
198
+ *
199
+ * Sent by GET /resources/:id/events/stream
200
+ *
201
+ * This represents a single event from the event store, broadcast in real-time
202
+ * as it occurs. Used for real-time collaboration - multiple users see each
203
+ * other's changes as they happen.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * stream.onEvent((event: ResourceEvent) => {
208
+ * console.log(`Event: ${event.type}`);
209
+ * console.log(`User: ${event.userId}`);
210
+ * console.log(`Payload:`, event.payload);
211
+ * console.log(`Sequence: ${event.metadata.sequenceNumber}`);
212
+ * });
213
+ * ```
214
+ */
215
+ export interface ResourceEvent {
216
+ /** Event ID (unique) */
217
+ id: string;
218
+ /** Event type (e.g., 'resource.created', 'annotation.created', etc.) */
219
+ type: string;
220
+ /** ISO 8601 timestamp */
221
+ timestamp: string;
222
+ /** User ID who triggered the event */
223
+ userId: string;
224
+ /** Resource ID this event relates to */
225
+ resourceId: string;
226
+ /** Event-specific payload (varies by event type) */
227
+ payload: any;
228
+ /** Event store metadata */
229
+ metadata: {
230
+ /** Monotonically increasing sequence number */
231
+ sequenceNumber: number;
232
+ /** SHA-256 hash of previous event (for integrity) */
233
+ prevEventHash: string;
234
+ /** SHA-256 checksum of this event */
235
+ checksum: string;
236
+ };
237
+ }
238
+ /**
239
+ * SSE stream controller interface
240
+ *
241
+ * Returned by all SSE methods. Provides callback registration and cleanup.
242
+ *
243
+ * @typeParam TProgress - Type of progress events
244
+ * @typeParam TComplete - Type of completion event
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const stream: SSEStream<DetectionProgress, DetectionProgress> =
249
+ * client.sse.detectAnnotations(resourceId, { entityTypes: ['Person'] });
250
+ *
251
+ * stream.onProgress((p) => console.log(p.message));
252
+ * stream.onComplete((r) => console.log(`Done! Found ${r.foundCount} entities`));
253
+ * stream.onError((e) => console.error('Failed:', e.message));
254
+ *
255
+ * // Cleanup when done
256
+ * stream.close();
257
+ * ```
258
+ */
259
+ export interface SSEStream<TProgress, TComplete> {
260
+ /**
261
+ * Register callback for progress events
262
+ *
263
+ * Called for each progress update (e.g., detection-started, detection-progress)
264
+ */
265
+ onProgress(callback: (progress: TProgress) => void): void;
266
+ /**
267
+ * Register callback for completion event
268
+ *
269
+ * Called once when operation completes successfully (e.g., detection-complete)
270
+ */
271
+ onComplete(callback: (result: TComplete) => void): void;
272
+ /**
273
+ * Register callback for error events
274
+ *
275
+ * Called if operation fails or stream encounters an error
276
+ */
277
+ onError(callback: (error: Error) => void): void;
278
+ /**
279
+ * Close the SSE stream and abort the connection
280
+ *
281
+ * Should be called to cleanup resources when stream is no longer needed.
282
+ * Safe to call multiple times.
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * // React cleanup
287
+ * useEffect(() => {
288
+ * const stream = client.sse.detectAnnotations(...);
289
+ * return () => stream.close();
290
+ * }, []);
291
+ * ```
292
+ */
293
+ close(): void;
294
+ }
295
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sse/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;IACtD,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,gBAAgB,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;IAClF,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,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C3B,QAAQ,EAAE;QACR,+CAA+C;QAC/C,cAAc,EAAE,MAAM,CAAC;QACvB,qDAAqD;QACrD,aAAa,EAAE,MAAM,CAAC;QACtB,qCAAqC;QACrC,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,SAAS,CAAC,SAAS,EAAE,SAAS;IAC7C;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAAC;IAE1D;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAAC;IAExD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IAEhD;;;;;;;;;;;;;;OAcG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * TypeScript types for Server-Sent Events (SSE) streaming
4
+ *
5
+ * These types match the event payloads sent by backend SSE endpoints.
6
+ * They are not validated (per SSE-VALIDATION-CONSIDERATIONS.md) but provide
7
+ * type safety for client code consuming the streams.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sse/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}