@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.
- package/README.md +18 -7
- package/dist/embed/embed-collection.html +17 -4
- package/dist/embed/embed.html +15 -3
- package/dist/index.cjs +57 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +100 -24
- package/dist/index.mjs +56 -12
- package/dist/index.mjs.map +1 -1
- package/dist/jaaq-sdk.min.js +1 -1
- package/dist/jaaq-sdk.min.js.map +1 -1
- package/dist/ui/index.cjs +102 -17
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.ts +89 -10
- package/dist/ui/index.mjs +102 -17
- package/dist/ui/index.mjs.map +1 -1
- package/dist/ui/jaaq-ui-bundled.min.js +2 -2
- package/dist/ui/jaaq-ui-bundled.min.js.map +1 -1
- package/dist/ui/jaaq-ui.min.js +2 -2
- package/dist/ui/jaaq-ui.min.js.map +1 -1
- package/dist/ui/react/index.cjs +78 -18
- package/dist/ui/react/index.cjs.map +1 -1
- package/dist/ui/react/index.d.ts +84 -7
- package/dist/ui/react/index.mjs +78 -18
- package/dist/ui/react/index.mjs.map +1 -1
- package/dist/ui/react/jaaq-ui-react.min.js +2 -2
- package/dist/ui/react/jaaq-ui-react.min.js.map +1 -1
- package/dist/ui/vanilla/index.cjs +102 -17
- package/dist/ui/vanilla/index.cjs.map +1 -1
- package/dist/ui/vanilla/index.d.ts +89 -10
- package/dist/ui/vanilla/index.mjs +102 -17
- package/dist/ui/vanilla/index.mjs.map +1 -1
- package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +2 -2
- package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -1
- package/dist/ui/vanilla/jaaq-vanilla.min.js +2 -2
- package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -1
- package/dist/ui/webcomponents/index.cjs +74 -14
- package/dist/ui/webcomponents/index.cjs.map +1 -1
- package/dist/ui/webcomponents/index.d.ts +86 -9
- package/dist/ui/webcomponents/index.mjs +74 -14
- package/dist/ui/webcomponents/index.mjs.map +1 -1
- package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +2 -2
- package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -1
- package/dist/ui/webcomponents/jaaq-webcomponents.min.js +2 -2
- package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -1
- package/package.json +38 -35
|
@@ -11,16 +11,22 @@ async function parseJson(res) {
|
|
|
11
11
|
return undefined;
|
|
12
12
|
return res.json();
|
|
13
13
|
}
|
|
14
|
-
function joinUrl(baseUrl, clientId, path) {
|
|
14
|
+
function joinUrl(baseUrl, apiVersion, clientId, path) {
|
|
15
15
|
// return path if it is an absolute URL
|
|
16
16
|
if (/^https?:\/\//i.test(path))
|
|
17
17
|
return path;
|
|
18
18
|
const base = baseUrl.replace(/\/+$/, '');
|
|
19
19
|
const relative = path.replace(/^\/+/, '');
|
|
20
|
-
return `${base}/b2b/
|
|
20
|
+
return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
|
|
21
|
+
}
|
|
22
|
+
function convertToValidAPIVersion(version) {
|
|
23
|
+
const v = version.toLowerCase();
|
|
24
|
+
if (v === 'v1' || v === 'v2')
|
|
25
|
+
return v;
|
|
26
|
+
return 'v1'; // default to v1 if invalid version provided
|
|
21
27
|
}
|
|
22
28
|
function createHttpClient(config) {
|
|
23
|
-
const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
|
|
29
|
+
const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;
|
|
24
30
|
const f = fetchImpl ?? globalThis.fetch;
|
|
25
31
|
if (!f) {
|
|
26
32
|
throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
|
|
@@ -29,7 +35,7 @@ function createHttpClient(config) {
|
|
|
29
35
|
'Content-Type': 'application/json',
|
|
30
36
|
'x-api-key': apiKey,
|
|
31
37
|
};
|
|
32
|
-
const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
|
|
38
|
+
const fullUrl = (path) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);
|
|
33
39
|
const request = async (method, path, init, body) => {
|
|
34
40
|
const reqInit = {
|
|
35
41
|
method,
|
|
@@ -78,20 +84,51 @@ function createCollectionsResource(http) {
|
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
86
|
|
|
87
|
+
function createVideosResourceV2(http) {
|
|
88
|
+
return {
|
|
89
|
+
async getById(id) {
|
|
90
|
+
const path = `/videos/${encodeURIComponent(id)}`;
|
|
91
|
+
const response = await http.get(path);
|
|
92
|
+
return response.video;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createCollectionsResourceV2(http) {
|
|
98
|
+
return {
|
|
99
|
+
async list() {
|
|
100
|
+
const path = '/collections';
|
|
101
|
+
const response = await http.get(path);
|
|
102
|
+
return response.collections;
|
|
103
|
+
},
|
|
104
|
+
async getById(id) {
|
|
105
|
+
const path = `/collections/${encodeURIComponent(id)}`;
|
|
106
|
+
const response = await http.get(path);
|
|
107
|
+
return response.collection;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
81
112
|
const BASE_URL = "https://api.jaaq.app";
|
|
82
113
|
class JaaqClient {
|
|
83
114
|
// Keep constructor private to enforce controlled instantiation.
|
|
84
|
-
constructor(http) {
|
|
85
|
-
|
|
86
|
-
|
|
115
|
+
constructor(http, apiVersion) {
|
|
116
|
+
if (apiVersion === 'v2') {
|
|
117
|
+
this.videos = createVideosResourceV2(http);
|
|
118
|
+
this.collections = createCollectionsResourceV2(http);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.videos = createVideosResource(http);
|
|
122
|
+
this.collections = createCollectionsResource(http);
|
|
123
|
+
}
|
|
87
124
|
}
|
|
88
125
|
/**
|
|
89
126
|
* Public "friend" constructor that remains inside the class boundary.
|
|
90
127
|
* This method is callable from the module-level build function
|
|
91
128
|
* without exposing `new JaaqClient(...)` to consumers.
|
|
92
129
|
*/
|
|
93
|
-
static fromHttp(http) {
|
|
94
|
-
return new JaaqClient(http);
|
|
130
|
+
static fromHttp(http, apiVersion) {
|
|
131
|
+
return new JaaqClient(http, apiVersion);
|
|
95
132
|
}
|
|
96
133
|
/**
|
|
97
134
|
* OO-friendly static initializer.
|
|
@@ -114,14 +151,15 @@ function createJaaqClient(config) {
|
|
|
114
151
|
* The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
|
|
115
152
|
*/
|
|
116
153
|
function buildClient(config) {
|
|
117
|
-
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
|
|
154
|
+
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
|
|
118
155
|
const http = createHttpClient({
|
|
119
156
|
baseUrl,
|
|
120
157
|
apiKey,
|
|
121
158
|
clientId,
|
|
122
159
|
fetch: fetchImpl ?? globalThis.fetch,
|
|
160
|
+
apiVersion,
|
|
123
161
|
});
|
|
124
|
-
return JaaqClient.fromHttp(http);
|
|
162
|
+
return JaaqClient.fromHttp(http, apiVersion);
|
|
125
163
|
}
|
|
126
164
|
|
|
127
165
|
/**
|
|
@@ -992,6 +1030,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
992
1030
|
const apiKey = this.getAttribute('api-key');
|
|
993
1031
|
const clientId = this.getAttribute('client-id');
|
|
994
1032
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
1033
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
995
1034
|
const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
|
|
996
1035
|
const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
|
|
997
1036
|
const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
|
|
@@ -1011,6 +1050,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
1011
1050
|
clientId: clientId ?? undefined,
|
|
1012
1051
|
client: this.clientInstance || undefined,
|
|
1013
1052
|
baseUrl,
|
|
1053
|
+
apiVersion,
|
|
1014
1054
|
autoplay,
|
|
1015
1055
|
controls,
|
|
1016
1056
|
showLogo,
|
|
@@ -4388,6 +4428,21 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4388
4428
|
return defaultValue;
|
|
4389
4429
|
return v !== 'false';
|
|
4390
4430
|
}
|
|
4431
|
+
getVideosFromCollection(collection) {
|
|
4432
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4433
|
+
return collection.videos;
|
|
4434
|
+
}
|
|
4435
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4436
|
+
const videos = [];
|
|
4437
|
+
collection.videoGroups.forEach((group) => {
|
|
4438
|
+
if (group.videos && group.videos.length > 0) {
|
|
4439
|
+
videos.push(...group.videos);
|
|
4440
|
+
}
|
|
4441
|
+
});
|
|
4442
|
+
return videos;
|
|
4443
|
+
}
|
|
4444
|
+
return [];
|
|
4445
|
+
}
|
|
4391
4446
|
render() {
|
|
4392
4447
|
if (!this.shadowRoot)
|
|
4393
4448
|
return;
|
|
@@ -4414,6 +4469,7 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4414
4469
|
const apiKey = this.getAttribute('api-key');
|
|
4415
4470
|
const clientId = this.getAttribute('client-id');
|
|
4416
4471
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
4472
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4417
4473
|
if (!this.clientInstance && !apiKey && !clientId) {
|
|
4418
4474
|
this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
|
|
4419
4475
|
return;
|
|
@@ -4425,9 +4481,11 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4425
4481
|
apiKey: apiKey,
|
|
4426
4482
|
clientId: clientId,
|
|
4427
4483
|
baseUrl: baseUrl || BASE_URL,
|
|
4484
|
+
apiVersion: apiVersion,
|
|
4428
4485
|
});
|
|
4429
4486
|
this.collectionData = await client.collections.getById(collectionId);
|
|
4430
|
-
|
|
4487
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4488
|
+
if (videos.length === 0) {
|
|
4431
4489
|
this.emitError(new Error('No videos found in collection'));
|
|
4432
4490
|
return;
|
|
4433
4491
|
}
|
|
@@ -4475,7 +4533,8 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4475
4533
|
console.warn('[CollectionPlayer] Failed to parse video-settings attribute', e);
|
|
4476
4534
|
}
|
|
4477
4535
|
}
|
|
4478
|
-
this.collectionData
|
|
4536
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4537
|
+
videos.forEach((video) => {
|
|
4479
4538
|
const slide = document.createElement('li');
|
|
4480
4539
|
slide.className = 'splide__slide';
|
|
4481
4540
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -4557,8 +4616,9 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4557
4616
|
Components: this.splide?.Components,
|
|
4558
4617
|
});
|
|
4559
4618
|
this.handleSlideChange(newIndex);
|
|
4619
|
+
const videos = this.collectionData ? this.getVideosFromCollection(this.collectionData) : [];
|
|
4560
4620
|
this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
|
|
4561
|
-
detail: { index: newIndex, video:
|
|
4621
|
+
detail: { index: newIndex, video: videos[newIndex] },
|
|
4562
4622
|
bubbles: true,
|
|
4563
4623
|
composed: true,
|
|
4564
4624
|
}));
|