@jaaq/jaaq-sdk-js 1.0.1 → 1.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.
Files changed (41) hide show
  1. package/README.md +733 -92
  2. package/dist/embed/embed-collection.html +275 -0
  3. package/dist/embed/embed.html +270 -0
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/jaaq-sdk.min.js.map +1 -1
  7. package/dist/ui/index.cjs +5051 -0
  8. package/dist/ui/index.cjs.map +1 -0
  9. package/dist/ui/index.d.ts +378 -0
  10. package/dist/ui/index.mjs +5044 -0
  11. package/dist/ui/index.mjs.map +1 -0
  12. package/dist/ui/jaaq-ui-bundled.min.js +8 -0
  13. package/dist/ui/jaaq-ui-bundled.min.js.map +1 -0
  14. package/dist/ui/jaaq-ui.min.js +8 -0
  15. package/dist/ui/jaaq-ui.min.js.map +1 -0
  16. package/dist/ui/react/index.cjs +4756 -0
  17. package/dist/ui/react/index.cjs.map +1 -0
  18. package/dist/ui/react/index.d.ts +182 -0
  19. package/dist/ui/react/index.mjs +4735 -0
  20. package/dist/ui/react/index.mjs.map +1 -0
  21. package/dist/ui/react/jaaq-ui-react.min.js +8 -0
  22. package/dist/ui/react/jaaq-ui-react.min.js.map +1 -0
  23. package/dist/ui/vanilla/index.cjs +5052 -0
  24. package/dist/ui/vanilla/index.cjs.map +1 -0
  25. package/dist/ui/vanilla/index.d.ts +465 -0
  26. package/dist/ui/vanilla/index.mjs +5044 -0
  27. package/dist/ui/vanilla/index.mjs.map +1 -0
  28. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +8 -0
  29. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -0
  30. package/dist/ui/vanilla/jaaq-vanilla.min.js +8 -0
  31. package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -0
  32. package/dist/ui/webcomponents/index.cjs +4619 -0
  33. package/dist/ui/webcomponents/index.cjs.map +1 -0
  34. package/dist/ui/webcomponents/index.d.ts +288 -0
  35. package/dist/ui/webcomponents/index.mjs +4614 -0
  36. package/dist/ui/webcomponents/index.mjs.map +1 -0
  37. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +8 -0
  38. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -0
  39. package/dist/ui/webcomponents/jaaq-webcomponents.min.js +8 -0
  40. package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -0
  41. package/package.json +42 -2
@@ -0,0 +1,378 @@
1
+ type FetchLike = typeof globalThis.fetch;
2
+ type RequestOptions = Parameters<typeof globalThis.fetch>[1];
3
+ interface HttpClient {
4
+ get<T>(_path: string, _init?: RequestOptions): Promise<T>;
5
+ post<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;
6
+ put<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;
7
+ patch<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;
8
+ delete<T>(_path: string, _init?: RequestOptions): Promise<T>;
9
+ }
10
+
11
+ type VideoDTO = {
12
+ id: string;
13
+ videoId: string;
14
+ question: string;
15
+ status: number;
16
+ transcription: string;
17
+ subtitle: string;
18
+ createdAt: string;
19
+ videoUrl: string;
20
+ published: boolean;
21
+ tags: string[];
22
+ severity: number | null;
23
+ duration: number;
24
+ description: string;
25
+ };
26
+
27
+ type VideosResource = {
28
+ getById(_id: string): Promise<VideoDTO>;
29
+ };
30
+
31
+ type CollectionDTO = {
32
+ id: string;
33
+ name: string;
34
+ description: string;
35
+ imageUrl: string;
36
+ createdAt: string;
37
+ videos: VideoDTO[];
38
+ };
39
+
40
+ type CollectionsResource = {
41
+ list(): Promise<CollectionDTO[]>;
42
+ getById(_id: string): Promise<CollectionDTO>;
43
+ };
44
+
45
+ interface SDKConfig {
46
+ baseUrl?: string;
47
+ apiKey: string;
48
+ clientId: string;
49
+ fetch?: FetchLike;
50
+ timeoutMs?: number;
51
+ }
52
+ declare class JaaqClient {
53
+ readonly videos: VideosResource;
54
+ readonly collections: CollectionsResource;
55
+ private constructor();
56
+ /**
57
+ * Public "friend" constructor that remains inside the class boundary.
58
+ * This method is callable from the module-level build function
59
+ * without exposing `new JaaqClient(...)` to consumers.
60
+ */
61
+ static fromHttp(http: HttpClient): JaaqClient;
62
+ /**
63
+ * OO-friendly static initializer.
64
+ * Delegates to the single source of truth: `buildClient`.
65
+ */
66
+ static init(config: SDKConfig): JaaqClient;
67
+ }
68
+
69
+ /**
70
+ * Configuration options for video player components
71
+ */
72
+ type PlayerConfig = {
73
+ /** Video ID to load */
74
+ videoId: string;
75
+ /** API key for authentication (required if no client provided) */
76
+ apiKey?: string;
77
+ /** Client ID for authentication (required if no client provided) */
78
+ clientId?: string;
79
+ /** Existing JaaqClient instance to use instead of creating a new one */
80
+ client?: JaaqClient;
81
+ /** Custom API base URL */
82
+ baseUrl?: string;
83
+ /** Whether to automatically start playback when video loads */
84
+ autoplay?: boolean;
85
+ /** Whether to show player controls */
86
+ controls?: boolean;
87
+ /** CSS width of the player container */
88
+ width?: string;
89
+ /** CSS height of the player container */
90
+ height?: string;
91
+ /** Additional CSS class name(s) to apply to the player */
92
+ className?: string;
93
+ /** Whether to show the JAAQ logo */
94
+ showLogo?: boolean;
95
+ /** Whether to show the video title */
96
+ showTitle?: boolean;
97
+ /** Whether to show the author name */
98
+ showAuthor?: boolean;
99
+ /** Whether to show the description */
100
+ showDescription?: boolean;
101
+ /** Whether to show captions button */
102
+ showCaptions?: boolean;
103
+ };
104
+ /**
105
+ * Current state of the video player
106
+ */
107
+ type PlayerState = {
108
+ /** Whether the video is currently playing */
109
+ isPlaying: boolean;
110
+ /** Current playback time in seconds */
111
+ currentTime: number;
112
+ /** Total video duration in seconds */
113
+ duration: number;
114
+ /** Current volume level (0-1) */
115
+ volume: number;
116
+ /** Whether the audio is muted */
117
+ isMuted: boolean;
118
+ /** Whether the player is in fullscreen mode */
119
+ isFullscreen: boolean;
120
+ /** Whether the video is currently loading */
121
+ isLoading: boolean;
122
+ /** Error message if an error occurred, null otherwise */
123
+ error: string | null;
124
+ /** Loaded video data, null if not yet loaded */
125
+ videoData: VideoDTO | null;
126
+ /** Whether captions are currently enabled */
127
+ captionsEnabled: boolean;
128
+ };
129
+ /**
130
+ * Map of player event names to their payload types
131
+ */
132
+ type PlayerEventMap = {
133
+ /** Fired when playback starts */
134
+ play: void;
135
+ /** Fired when playback pauses */
136
+ pause: void;
137
+ /** Fired when playback time updates, provides current time in seconds */
138
+ timeupdate: number;
139
+ /** Fired when volume changes, provides new volume level (0-1) */
140
+ volumechange: number;
141
+ /** Fired when playback reaches the end */
142
+ ended: void;
143
+ /** Fired when an error occurs, provides Error object */
144
+ error: Error;
145
+ /** Fired when video metadata is loaded, provides VideoDTO */
146
+ loaded: VideoDTO;
147
+ /** Fired when fullscreen state changes, provides boolean fullscreen state */
148
+ fullscreenchange: boolean;
149
+ };
150
+ /**
151
+ * Event callback function type for player events
152
+ * @template T - The type of data passed to the callback
153
+ */
154
+ type PlayerEventCallback<T> = (_data: T) => void;
155
+
156
+ declare class JaaqVideoPlayer {
157
+ private container;
158
+ private config;
159
+ private client;
160
+ private hls;
161
+ private videoElement;
162
+ private state;
163
+ private listeners;
164
+ private captionCues;
165
+ private elements;
166
+ /**
167
+ * Creates a new video player instance
168
+ * @param container - HTML element or CSS selector to render the player into
169
+ * @param config - Player configuration options
170
+ * @throws {Error} If container element is not found or if authentication credentials are missing
171
+ */
172
+ constructor(container: HTMLElement | string, config: PlayerConfig);
173
+ private init;
174
+ private createDOM;
175
+ private updateControlsVisibility;
176
+ private loadVideo;
177
+ private parseWebVTT;
178
+ private updateOverlayContent;
179
+ private attachEventListeners;
180
+ private setState;
181
+ private updatePlayPauseButton;
182
+ private updateProgress;
183
+ private updateVolumeUI;
184
+ private updateCaptions;
185
+ private handleSeek;
186
+ private showError;
187
+ private togglePlayPause;
188
+ private toggleCaptions;
189
+ private updateCaptionsButton;
190
+ private toggleFullscreen;
191
+ /**
192
+ * Starts or resumes video playback
193
+ */
194
+ play(): void;
195
+ /**
196
+ * Pauses video playback
197
+ */
198
+ pause(): void;
199
+ /**
200
+ * Sets the playback volume
201
+ * @param volume - Volume level between 0 (silent) and 1 (maximum)
202
+ */
203
+ setVolume(volume: number): void;
204
+ /**
205
+ * Toggles audio mute state
206
+ */
207
+ toggleMute(): void;
208
+ /**
209
+ * Seeks to a specific time in the video
210
+ * @param time - Target time in seconds
211
+ */
212
+ seek(time: number): void;
213
+ setFeatures(features: Partial<Pick<PlayerConfig, 'showLogo' | 'showTitle' | 'showAuthor' | 'showDescription' | 'showCaptions' | 'controls'>>): void;
214
+ /**
215
+ * Returns a copy of the current player state
216
+ * @returns Current player state object
217
+ */
218
+ getState(): PlayerState;
219
+ /**
220
+ * Registers an event listener for player events
221
+ * @param event - Event name to listen for
222
+ * @param callback - Function to call when event fires
223
+ */
224
+ on<K extends keyof PlayerEventMap>(event: K, callback: PlayerEventCallback<PlayerEventMap[K]>): void;
225
+ /**
226
+ * Removes an event listener for player events
227
+ * @param event - Event name to stop listening for
228
+ * @param callback - Function to remove from listeners
229
+ */
230
+ off<K extends keyof PlayerEventMap>(event: K, callback: PlayerEventCallback<PlayerEventMap[K]>): void;
231
+ private emit;
232
+ /**
233
+ * Destroys the player instance and cleans up resources
234
+ * Removes all event listeners, stops playback, and clears the DOM
235
+ */
236
+ destroy(): void;
237
+ }
238
+
239
+ type CollectionPlayerConfig = {
240
+ collectionId: string;
241
+ client?: JaaqClient;
242
+ apiKey?: string;
243
+ clientId?: string;
244
+ baseUrl?: string;
245
+ autoplay?: boolean;
246
+ showArrows?: boolean;
247
+ showDots?: boolean;
248
+ className?: string;
249
+ };
250
+ type CollectionPlayerEventMap = {
251
+ loaded: CollectionDTO;
252
+ slidechange: {
253
+ index: number;
254
+ video: VideoDTO;
255
+ };
256
+ error: Error;
257
+ };
258
+ type CollectionPlayerEventCallback<T> = (_data: T) => void;
259
+ declare class JaaqCollectionPlayer {
260
+ private container;
261
+ private config;
262
+ private client;
263
+ private splide;
264
+ private playerElement;
265
+ private carouselElement;
266
+ private collectionData;
267
+ private autoplayTimeoutId;
268
+ private listeners;
269
+ constructor(container: HTMLElement | string, config: CollectionPlayerConfig);
270
+ private init;
271
+ private render;
272
+ private initCarousel;
273
+ private showLoading;
274
+ private renderCarousel;
275
+ private initSplide;
276
+ private handleSlideChange;
277
+ private destroyCarousel;
278
+ private emitError;
279
+ on<K extends keyof CollectionPlayerEventMap>(event: K, callback: CollectionPlayerEventCallback<CollectionPlayerEventMap[K]>): void;
280
+ off<K extends keyof CollectionPlayerEventMap>(event: K, callback: CollectionPlayerEventCallback<CollectionPlayerEventMap[K]>): void;
281
+ private emit;
282
+ refresh(): void;
283
+ next(): void;
284
+ prev(): void;
285
+ go(index: number): void;
286
+ destroy(): void;
287
+ getCollection(): CollectionDTO | null;
288
+ }
289
+
290
+ /**
291
+ * Initializes all video players with data-jaaq-player attribute
292
+ * @param rootElement - Root element to search for players (defaults to document)
293
+ */
294
+ declare function initializePlayers(rootElement?: Document | Element): void;
295
+ /**
296
+ * Retrieves a player instance for a given element or selector
297
+ * @param elementOrSelector - DOM element or CSS selector
298
+ * @returns Player instance or null if not found
299
+ */
300
+ declare function getPlayer(elementOrSelector: Element | string): JaaqVideoPlayer | null;
301
+ /**
302
+ * Destroys all initialized player instances and cleans up resources
303
+ */
304
+ declare function destroyAll(): void;
305
+ /**
306
+ * Auto-initialization API for declarative video player setup
307
+ * Automatically finds and initializes players marked with [data-jaaq-player]
308
+ * @example
309
+ * // Auto-initialization on page load
310
+ * <div data-jaaq-player data-api-key="key" data-client-id="id" data-video-id="video"></div>
311
+ *
312
+ * // Manual initialization
313
+ * JaaqPlayer.init();
314
+ *
315
+ * // Get player instance
316
+ * const player = JaaqPlayer.getPlayer('[data-video-id="video"]');
317
+ * player.on('play', () => console.log('Playing'));
318
+ */
319
+ declare const JaaqPlayer: {
320
+ /** Initialize all players with [data-jaaq-player] attribute */
321
+ init: typeof initializePlayers;
322
+ /** Get player instance by element or selector */
323
+ getPlayer: typeof getPlayer;
324
+ /** Destroy all initialized players */
325
+ destroyAll: typeof destroyAll;
326
+ };
327
+
328
+ declare class JaaqCollectionPlayerElement extends HTMLElement {
329
+ private splide;
330
+ private container;
331
+ private carouselElement;
332
+ private clientInstance;
333
+ private connected;
334
+ private collectionData;
335
+ private autoplayTimeoutId;
336
+ static get observedAttributes(): string[];
337
+ constructor();
338
+ connectedCallback(): void;
339
+ disconnectedCallback(): void;
340
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
341
+ private getBooleanAttr;
342
+ private render;
343
+ private initCarousel;
344
+ private showLoading;
345
+ private renderCarousel;
346
+ private initSplide;
347
+ private handleSlideChange;
348
+ private destroyCarousel;
349
+ private emitError;
350
+ get client(): JaaqClient | null;
351
+ set client(value: JaaqClient | null);
352
+ get collectionId(): string | null;
353
+ set collectionId(value: string | null);
354
+ refresh(): void;
355
+ next(): void;
356
+ prev(): void;
357
+ go(index: number): void;
358
+ destroy(): void;
359
+ getCollection(): CollectionDTO | null;
360
+ }
361
+
362
+ /**
363
+ * Registers JAAQ custom elements (<jaaq-video-player> and <jaaq-collection-player>)
364
+ * Safe to call multiple times - only registers if not already registered
365
+ *
366
+ * @example
367
+ * import { registerJaaqComponents } from '@jaaq/jaaq-sdk-js/ui/webcomponents';
368
+ * registerJaaqComponents();
369
+ */
370
+ declare function registerJaaqComponents(): void;
371
+ /**
372
+ * Checks if the JAAQ web components are already registered
373
+ * @returns True if components are registered, false otherwise
374
+ */
375
+ declare function isRegistered(): boolean;
376
+
377
+ export { JaaqCollectionPlayer, JaaqCollectionPlayerElement, JaaqPlayer, JaaqVideoPlayer, isRegistered, registerJaaqComponents };
378
+ export type { PlayerConfig, PlayerEventMap, PlayerState };