@jaaq/jaaq-sdk-js 1.1.1 → 1.2.0-dev-ec79f7e-20260605

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 (45) hide show
  1. package/README.md +18 -7
  2. package/dist/embed/embed-collection.html +17 -4
  3. package/dist/embed/embed.html +15 -3
  4. package/dist/index.cjs +57 -11
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +100 -24
  7. package/dist/index.mjs +56 -12
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/jaaq-sdk.min.js +1 -1
  10. package/dist/jaaq-sdk.min.js.map +1 -1
  11. package/dist/ui/index.cjs +102 -17
  12. package/dist/ui/index.cjs.map +1 -1
  13. package/dist/ui/index.d.ts +89 -10
  14. package/dist/ui/index.mjs +102 -17
  15. package/dist/ui/index.mjs.map +1 -1
  16. package/dist/ui/jaaq-ui-bundled.min.js +2 -2
  17. package/dist/ui/jaaq-ui-bundled.min.js.map +1 -1
  18. package/dist/ui/jaaq-ui.min.js +2 -2
  19. package/dist/ui/jaaq-ui.min.js.map +1 -1
  20. package/dist/ui/react/index.cjs +78 -18
  21. package/dist/ui/react/index.cjs.map +1 -1
  22. package/dist/ui/react/index.d.ts +84 -7
  23. package/dist/ui/react/index.mjs +78 -18
  24. package/dist/ui/react/index.mjs.map +1 -1
  25. package/dist/ui/react/jaaq-ui-react.min.js +2 -2
  26. package/dist/ui/react/jaaq-ui-react.min.js.map +1 -1
  27. package/dist/ui/vanilla/index.cjs +102 -17
  28. package/dist/ui/vanilla/index.cjs.map +1 -1
  29. package/dist/ui/vanilla/index.d.ts +89 -10
  30. package/dist/ui/vanilla/index.mjs +102 -17
  31. package/dist/ui/vanilla/index.mjs.map +1 -1
  32. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +2 -2
  33. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -1
  34. package/dist/ui/vanilla/jaaq-vanilla.min.js +2 -2
  35. package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -1
  36. package/dist/ui/webcomponents/index.cjs +74 -14
  37. package/dist/ui/webcomponents/index.cjs.map +1 -1
  38. package/dist/ui/webcomponents/index.d.ts +86 -9
  39. package/dist/ui/webcomponents/index.mjs +74 -14
  40. package/dist/ui/webcomponents/index.mjs.map +1 -1
  41. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +2 -2
  42. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -1
  43. package/dist/ui/webcomponents/jaaq-webcomponents.min.js +2 -2
  44. package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -1
  45. package/package.json +38 -35
@@ -42,10 +42,6 @@ type VideoDTO = {
42
42
  creatorBiography?: string;
43
43
  };
44
44
 
45
- type VideosResource = {
46
- getById(_id: string): Promise<VideoDTO>;
47
- };
48
-
49
45
  type CollectionDTO = {
50
46
  id: string;
51
47
  name: string;
@@ -55,33 +51,111 @@ type CollectionDTO = {
55
51
  videos: VideoDTO[];
56
52
  };
57
53
 
54
+ type CreatorV2DTO = {
55
+ id: string;
56
+ name: string;
57
+ biography: string;
58
+ imageUrl: string;
59
+ type: string;
60
+ };
61
+
62
+ type CtaV2DTO = {
63
+ url?: string;
64
+ label?: string;
65
+ labelColor?: string;
66
+ };
67
+
68
+ type SubtitleV2DTO = {
69
+ code: string;
70
+ url: string;
71
+ default?: boolean;
72
+ };
73
+
74
+ type VideoV2DTO = {
75
+ id: string;
76
+ videoId: string;
77
+ question: string;
78
+ transcription: string;
79
+ subtitles: SubtitleV2DTO[];
80
+ videoUrl: string;
81
+ tags: string[];
82
+ severity: number | null;
83
+ duration: number;
84
+ description: string;
85
+ creator?: CreatorV2DTO;
86
+ cta?: CtaV2DTO;
87
+ allowFeedbackWidget?: boolean;
88
+ };
89
+
90
+ type VideoGroupV2DTO = {
91
+ id: string;
92
+ title: string;
93
+ videos: VideoV2DTO[];
94
+ };
95
+
96
+ type CollectionV2DTO = {
97
+ id: string;
98
+ name: string;
99
+ description: string;
100
+ imageUrl: string;
101
+ idleVideo: {
102
+ id: string;
103
+ duration: number;
104
+ videoUrl: string;
105
+ } | null;
106
+ videoGroups: VideoGroupV2DTO[];
107
+ };
108
+
109
+ type VideosResource = {
110
+ getById(_id: string): Promise<VideoDTO>;
111
+ };
112
+
58
113
  type CollectionsResource = {
59
114
  list(): Promise<CollectionDTO[]>;
60
115
  getById(_id: string): Promise<CollectionDTO>;
61
116
  };
62
117
 
118
+ type VideosResourceV2 = {
119
+ getById(_id: string): Promise<VideoV2DTO>;
120
+ };
121
+
122
+ type CollectionsResourceV2 = {
123
+ list(): Promise<CollectionV2DTO[]>;
124
+ getById(_id: string): Promise<CollectionV2DTO>;
125
+ };
126
+
63
127
  interface SDKConfig {
64
128
  baseUrl?: string;
129
+ apiVersion?: string;
65
130
  apiKey: string;
66
131
  clientId: string;
67
132
  fetch?: FetchLike;
68
133
  timeoutMs?: number;
69
134
  }
70
- declare class JaaqClient {
71
- readonly videos: VideosResource;
72
- readonly collections: CollectionsResource;
135
+ type V1 = {
136
+ videos: VideosResource;
137
+ collections: CollectionsResource;
138
+ };
139
+ type V2 = {
140
+ videos: VideosResourceV2;
141
+ collections: CollectionsResourceV2;
142
+ };
143
+ type ClientVersion = V1 | V2;
144
+ declare class JaaqClient<T extends ClientVersion = V1> {
145
+ readonly videos: T['videos'];
146
+ readonly collections: T['collections'];
73
147
  private constructor();
74
148
  /**
75
149
  * Public "friend" constructor that remains inside the class boundary.
76
150
  * This method is callable from the module-level build function
77
151
  * without exposing `new JaaqClient(...)` to consumers.
78
152
  */
79
- static fromHttp(http: HttpClient): JaaqClient;
153
+ static fromHttp<T extends ClientVersion = V1>(http: HttpClient, apiVersion: string): JaaqClient<T>;
80
154
  /**
81
155
  * OO-friendly static initializer.
82
156
  * Delegates to the single source of truth: `buildClient`.
83
157
  */
84
- static init(config: SDKConfig): JaaqClient;
158
+ static init<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T>;
85
159
  }
86
160
 
87
161
  /**
@@ -98,6 +172,8 @@ type PlayerConfig = {
98
172
  client?: JaaqClient;
99
173
  /** Custom API base URL */
100
174
  baseUrl?: string;
175
+ /** Custom API version */
176
+ apiVersion?: string;
101
177
  /** Whether to automatically start playback when video loads */
102
178
  autoplay?: boolean;
103
179
  /** Whether to show player controls */
@@ -269,6 +345,7 @@ declare class JaaqCollectionPlayerElement extends HTMLElement {
269
345
  disconnectedCallback(): void;
270
346
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
271
347
  private getBooleanAttr;
348
+ private getVideosFromCollection;
272
349
  private render;
273
350
  private initCarousel;
274
351
  private showLoading;
@@ -9,16 +9,22 @@ async function parseJson(res) {
9
9
  return undefined;
10
10
  return res.json();
11
11
  }
12
- function joinUrl(baseUrl, clientId, path) {
12
+ function joinUrl(baseUrl, apiVersion, clientId, path) {
13
13
  // return path if it is an absolute URL
14
14
  if (/^https?:\/\//i.test(path))
15
15
  return path;
16
16
  const base = baseUrl.replace(/\/+$/, '');
17
17
  const relative = path.replace(/^\/+/, '');
18
- return `${base}/b2b/v1/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
18
+ return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
19
+ }
20
+ function convertToValidAPIVersion(version) {
21
+ const v = version.toLowerCase();
22
+ if (v === 'v1' || v === 'v2')
23
+ return v;
24
+ return 'v1'; // default to v1 if invalid version provided
19
25
  }
20
26
  function createHttpClient(config) {
21
- const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
27
+ const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;
22
28
  const f = fetchImpl ?? globalThis.fetch;
23
29
  if (!f) {
24
30
  throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
@@ -27,7 +33,7 @@ function createHttpClient(config) {
27
33
  'Content-Type': 'application/json',
28
34
  'x-api-key': apiKey,
29
35
  };
30
- const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
36
+ const fullUrl = (path) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);
31
37
  const request = async (method, path, init, body) => {
32
38
  const reqInit = {
33
39
  method,
@@ -76,20 +82,51 @@ function createCollectionsResource(http) {
76
82
  };
77
83
  }
78
84
 
85
+ function createVideosResourceV2(http) {
86
+ return {
87
+ async getById(id) {
88
+ const path = `/videos/${encodeURIComponent(id)}`;
89
+ const response = await http.get(path);
90
+ return response.video;
91
+ },
92
+ };
93
+ }
94
+
95
+ function createCollectionsResourceV2(http) {
96
+ return {
97
+ async list() {
98
+ const path = '/collections';
99
+ const response = await http.get(path);
100
+ return response.collections;
101
+ },
102
+ async getById(id) {
103
+ const path = `/collections/${encodeURIComponent(id)}`;
104
+ const response = await http.get(path);
105
+ return response.collection;
106
+ },
107
+ };
108
+ }
109
+
79
110
  const BASE_URL = "https://api.jaaq.app";
80
111
  class JaaqClient {
81
112
  // Keep constructor private to enforce controlled instantiation.
82
- constructor(http) {
83
- this.videos = createVideosResource(http);
84
- this.collections = createCollectionsResource(http);
113
+ constructor(http, apiVersion) {
114
+ if (apiVersion === 'v2') {
115
+ this.videos = createVideosResourceV2(http);
116
+ this.collections = createCollectionsResourceV2(http);
117
+ }
118
+ else {
119
+ this.videos = createVideosResource(http);
120
+ this.collections = createCollectionsResource(http);
121
+ }
85
122
  }
86
123
  /**
87
124
  * Public "friend" constructor that remains inside the class boundary.
88
125
  * This method is callable from the module-level build function
89
126
  * without exposing `new JaaqClient(...)` to consumers.
90
127
  */
91
- static fromHttp(http) {
92
- return new JaaqClient(http);
128
+ static fromHttp(http, apiVersion) {
129
+ return new JaaqClient(http, apiVersion);
93
130
  }
94
131
  /**
95
132
  * OO-friendly static initializer.
@@ -112,14 +149,15 @@ function createJaaqClient(config) {
112
149
  * The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
113
150
  */
114
151
  function buildClient(config) {
115
- const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
152
+ const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
116
153
  const http = createHttpClient({
117
154
  baseUrl,
118
155
  apiKey,
119
156
  clientId,
120
157
  fetch: fetchImpl ?? globalThis.fetch,
158
+ apiVersion,
121
159
  });
122
- return JaaqClient.fromHttp(http);
160
+ return JaaqClient.fromHttp(http, apiVersion);
123
161
  }
124
162
 
125
163
  /**
@@ -990,6 +1028,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
990
1028
  const apiKey = this.getAttribute('api-key');
991
1029
  const clientId = this.getAttribute('client-id');
992
1030
  const baseUrl = this.getAttribute('base-url') || undefined;
1031
+ const apiVersion = this.getAttribute('api-version') || undefined;
993
1032
  const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
994
1033
  const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
995
1034
  const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
@@ -1009,6 +1048,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
1009
1048
  clientId: clientId ?? undefined,
1010
1049
  client: this.clientInstance || undefined,
1011
1050
  baseUrl,
1051
+ apiVersion,
1012
1052
  autoplay,
1013
1053
  controls,
1014
1054
  showLogo,
@@ -4386,6 +4426,21 @@ class JaaqCollectionPlayerElement extends HTMLElement {
4386
4426
  return defaultValue;
4387
4427
  return v !== 'false';
4388
4428
  }
4429
+ getVideosFromCollection(collection) {
4430
+ if (collection.videos && collection.videos.length > 0) {
4431
+ return collection.videos;
4432
+ }
4433
+ if (collection.videoGroups && collection.videoGroups.length > 0) {
4434
+ const videos = [];
4435
+ collection.videoGroups.forEach((group) => {
4436
+ if (group.videos && group.videos.length > 0) {
4437
+ videos.push(...group.videos);
4438
+ }
4439
+ });
4440
+ return videos;
4441
+ }
4442
+ return [];
4443
+ }
4389
4444
  render() {
4390
4445
  if (!this.shadowRoot)
4391
4446
  return;
@@ -4412,6 +4467,7 @@ class JaaqCollectionPlayerElement extends HTMLElement {
4412
4467
  const apiKey = this.getAttribute('api-key');
4413
4468
  const clientId = this.getAttribute('client-id');
4414
4469
  const baseUrl = this.getAttribute('base-url') || undefined;
4470
+ const apiVersion = this.getAttribute('api-version') || undefined;
4415
4471
  if (!this.clientInstance && !apiKey && !clientId) {
4416
4472
  this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
4417
4473
  return;
@@ -4423,9 +4479,11 @@ class JaaqCollectionPlayerElement extends HTMLElement {
4423
4479
  apiKey: apiKey,
4424
4480
  clientId: clientId,
4425
4481
  baseUrl: baseUrl || BASE_URL,
4482
+ apiVersion: apiVersion,
4426
4483
  });
4427
4484
  this.collectionData = await client.collections.getById(collectionId);
4428
- if (!this.collectionData.videos || this.collectionData.videos.length === 0) {
4485
+ const videos = this.getVideosFromCollection(this.collectionData);
4486
+ if (videos.length === 0) {
4429
4487
  this.emitError(new Error('No videos found in collection'));
4430
4488
  return;
4431
4489
  }
@@ -4473,7 +4531,8 @@ class JaaqCollectionPlayerElement extends HTMLElement {
4473
4531
  console.warn('[CollectionPlayer] Failed to parse video-settings attribute', e);
4474
4532
  }
4475
4533
  }
4476
- this.collectionData.videos.forEach((video) => {
4534
+ const videos = this.getVideosFromCollection(this.collectionData);
4535
+ videos.forEach((video) => {
4477
4536
  const slide = document.createElement('li');
4478
4537
  slide.className = 'splide__slide';
4479
4538
  const player = document.createElement('jaaq-video-player');
@@ -4555,8 +4614,9 @@ class JaaqCollectionPlayerElement extends HTMLElement {
4555
4614
  Components: this.splide?.Components,
4556
4615
  });
4557
4616
  this.handleSlideChange(newIndex);
4617
+ const videos = this.collectionData ? this.getVideosFromCollection(this.collectionData) : [];
4558
4618
  this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
4559
- detail: { index: newIndex, video: this.collectionData?.videos[newIndex] },
4619
+ detail: { index: newIndex, video: videos[newIndex] },
4560
4620
  bubbles: true,
4561
4621
  composed: true,
4562
4622
  }));