@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
|
/**
|
|
@@ -4053,6 +4091,7 @@ class JaaqCollectionPlayer {
|
|
|
4053
4091
|
apiKey: config.apiKey,
|
|
4054
4092
|
clientId: config.clientId,
|
|
4055
4093
|
baseUrl: config.baseUrl || BASE_URL,
|
|
4094
|
+
apiVersion: config.apiVersion,
|
|
4056
4095
|
});
|
|
4057
4096
|
}
|
|
4058
4097
|
else {
|
|
@@ -4084,7 +4123,8 @@ class JaaqCollectionPlayer {
|
|
|
4084
4123
|
throw new Error('Client is not initialized');
|
|
4085
4124
|
}
|
|
4086
4125
|
this.collectionData = await this.client.collections.getById(collectionId);
|
|
4087
|
-
|
|
4126
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4127
|
+
if (videos.length === 0) {
|
|
4088
4128
|
this.emitError(new Error('No videos found in collection'));
|
|
4089
4129
|
return;
|
|
4090
4130
|
}
|
|
@@ -4105,6 +4145,21 @@ class JaaqCollectionPlayer {
|
|
|
4105
4145
|
</div>
|
|
4106
4146
|
`;
|
|
4107
4147
|
}
|
|
4148
|
+
getVideosFromCollection(collection) {
|
|
4149
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4150
|
+
return collection.videos;
|
|
4151
|
+
}
|
|
4152
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4153
|
+
const videos = [];
|
|
4154
|
+
collection.videoGroups.forEach((group) => {
|
|
4155
|
+
if (group.videos && group.videos.length > 0) {
|
|
4156
|
+
videos.push(...group.videos);
|
|
4157
|
+
}
|
|
4158
|
+
});
|
|
4159
|
+
return videos;
|
|
4160
|
+
}
|
|
4161
|
+
return [];
|
|
4162
|
+
}
|
|
4108
4163
|
renderCarousel() {
|
|
4109
4164
|
if (!this.playerElement || !this.collectionData)
|
|
4110
4165
|
return;
|
|
@@ -4115,7 +4170,8 @@ class JaaqCollectionPlayer {
|
|
|
4115
4170
|
track.className = 'splide__track';
|
|
4116
4171
|
const list = document.createElement('ul');
|
|
4117
4172
|
list.className = 'splide__list';
|
|
4118
|
-
this.collectionData
|
|
4173
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4174
|
+
videos.forEach((video) => {
|
|
4119
4175
|
const slide = document.createElement('li');
|
|
4120
4176
|
slide.className = 'splide__slide';
|
|
4121
4177
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -4126,6 +4182,8 @@ class JaaqCollectionPlayer {
|
|
|
4126
4182
|
player.setAttribute('client-id', this.config.clientId);
|
|
4127
4183
|
if (this.config.baseUrl)
|
|
4128
4184
|
player.setAttribute('base-url', this.config.baseUrl);
|
|
4185
|
+
if (this.config.apiVersion)
|
|
4186
|
+
player.setAttribute('api-version', this.config.apiVersion);
|
|
4129
4187
|
player.setAttribute('autoplay', 'false');
|
|
4130
4188
|
player.setAttribute('width', '100%');
|
|
4131
4189
|
if (this.config.videoSettings) {
|
|
@@ -4195,7 +4253,8 @@ class JaaqCollectionPlayer {
|
|
|
4195
4253
|
this.splide.on('moved', (newIndex) => {
|
|
4196
4254
|
this.handleSlideChange(newIndex);
|
|
4197
4255
|
if (this.collectionData) {
|
|
4198
|
-
|
|
4256
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4257
|
+
this.emit('slidechange', { index: newIndex, video: videos[newIndex] });
|
|
4199
4258
|
}
|
|
4200
4259
|
});
|
|
4201
4260
|
this.splide.mount();
|
|
@@ -4340,6 +4399,10 @@ function parseDataAttributes(element) {
|
|
|
4340
4399
|
if (baseUrl) {
|
|
4341
4400
|
config.baseUrl = baseUrl;
|
|
4342
4401
|
}
|
|
4402
|
+
const apiVersion = element.getAttribute('data-api-version');
|
|
4403
|
+
if (apiVersion) {
|
|
4404
|
+
config.apiVersion = apiVersion;
|
|
4405
|
+
}
|
|
4343
4406
|
const className = element.getAttribute('data-class-name');
|
|
4344
4407
|
if (className) {
|
|
4345
4408
|
config.className = className;
|
|
@@ -4591,6 +4654,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
4591
4654
|
const apiKey = this.getAttribute('api-key');
|
|
4592
4655
|
const clientId = this.getAttribute('client-id');
|
|
4593
4656
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
4657
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4594
4658
|
const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
|
|
4595
4659
|
const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
|
|
4596
4660
|
const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
|
|
@@ -4610,6 +4674,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
4610
4674
|
clientId: clientId ?? undefined,
|
|
4611
4675
|
client: this.clientInstance || undefined,
|
|
4612
4676
|
baseUrl,
|
|
4677
|
+
apiVersion,
|
|
4613
4678
|
autoplay,
|
|
4614
4679
|
controls,
|
|
4615
4680
|
showLogo,
|
|
@@ -4848,6 +4913,21 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4848
4913
|
return defaultValue;
|
|
4849
4914
|
return v !== 'false';
|
|
4850
4915
|
}
|
|
4916
|
+
getVideosFromCollection(collection) {
|
|
4917
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4918
|
+
return collection.videos;
|
|
4919
|
+
}
|
|
4920
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4921
|
+
const videos = [];
|
|
4922
|
+
collection.videoGroups.forEach((group) => {
|
|
4923
|
+
if (group.videos && group.videos.length > 0) {
|
|
4924
|
+
videos.push(...group.videos);
|
|
4925
|
+
}
|
|
4926
|
+
});
|
|
4927
|
+
return videos;
|
|
4928
|
+
}
|
|
4929
|
+
return [];
|
|
4930
|
+
}
|
|
4851
4931
|
render() {
|
|
4852
4932
|
if (!this.shadowRoot)
|
|
4853
4933
|
return;
|
|
@@ -4874,6 +4954,7 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4874
4954
|
const apiKey = this.getAttribute('api-key');
|
|
4875
4955
|
const clientId = this.getAttribute('client-id');
|
|
4876
4956
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
4957
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4877
4958
|
if (!this.clientInstance && !apiKey && !clientId) {
|
|
4878
4959
|
this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
|
|
4879
4960
|
return;
|
|
@@ -4885,9 +4966,11 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4885
4966
|
apiKey: apiKey,
|
|
4886
4967
|
clientId: clientId,
|
|
4887
4968
|
baseUrl: baseUrl || BASE_URL,
|
|
4969
|
+
apiVersion: apiVersion,
|
|
4888
4970
|
});
|
|
4889
4971
|
this.collectionData = await client.collections.getById(collectionId);
|
|
4890
|
-
|
|
4972
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4973
|
+
if (videos.length === 0) {
|
|
4891
4974
|
this.emitError(new Error('No videos found in collection'));
|
|
4892
4975
|
return;
|
|
4893
4976
|
}
|
|
@@ -4935,7 +5018,8 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4935
5018
|
console.warn('[CollectionPlayer] Failed to parse video-settings attribute', e);
|
|
4936
5019
|
}
|
|
4937
5020
|
}
|
|
4938
|
-
this.collectionData
|
|
5021
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
5022
|
+
videos.forEach((video) => {
|
|
4939
5023
|
const slide = document.createElement('li');
|
|
4940
5024
|
slide.className = 'splide__slide';
|
|
4941
5025
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -5017,8 +5101,9 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
5017
5101
|
Components: this.splide?.Components,
|
|
5018
5102
|
});
|
|
5019
5103
|
this.handleSlideChange(newIndex);
|
|
5104
|
+
const videos = this.collectionData ? this.getVideosFromCollection(this.collectionData) : [];
|
|
5020
5105
|
this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
|
|
5021
|
-
detail: { index: newIndex, video:
|
|
5106
|
+
detail: { index: newIndex, video: videos[newIndex] },
|
|
5022
5107
|
bubbles: true,
|
|
5023
5108
|
composed: true,
|
|
5024
5109
|
}));
|