@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
package/dist/ui/react/index.cjs
CHANGED
|
@@ -31,16 +31,22 @@ async function parseJson(res) {
|
|
|
31
31
|
return undefined;
|
|
32
32
|
return res.json();
|
|
33
33
|
}
|
|
34
|
-
function joinUrl(baseUrl, clientId, path) {
|
|
34
|
+
function joinUrl(baseUrl, apiVersion, clientId, path) {
|
|
35
35
|
// return path if it is an absolute URL
|
|
36
36
|
if (/^https?:\/\//i.test(path))
|
|
37
37
|
return path;
|
|
38
38
|
const base = baseUrl.replace(/\/+$/, '');
|
|
39
39
|
const relative = path.replace(/^\/+/, '');
|
|
40
|
-
return `${base}/b2b/
|
|
40
|
+
return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
|
|
41
|
+
}
|
|
42
|
+
function convertToValidAPIVersion(version) {
|
|
43
|
+
const v = version.toLowerCase();
|
|
44
|
+
if (v === 'v1' || v === 'v2')
|
|
45
|
+
return v;
|
|
46
|
+
return 'v1'; // default to v1 if invalid version provided
|
|
41
47
|
}
|
|
42
48
|
function createHttpClient(config) {
|
|
43
|
-
const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
|
|
49
|
+
const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;
|
|
44
50
|
const f = fetchImpl ?? globalThis.fetch;
|
|
45
51
|
if (!f) {
|
|
46
52
|
throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
|
|
@@ -49,7 +55,7 @@ function createHttpClient(config) {
|
|
|
49
55
|
'Content-Type': 'application/json',
|
|
50
56
|
'x-api-key': apiKey,
|
|
51
57
|
};
|
|
52
|
-
const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
|
|
58
|
+
const fullUrl = (path) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);
|
|
53
59
|
const request = async (method, path, init, body) => {
|
|
54
60
|
const reqInit = {
|
|
55
61
|
method,
|
|
@@ -98,20 +104,51 @@ function createCollectionsResource(http) {
|
|
|
98
104
|
};
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
function createVideosResourceV2(http) {
|
|
108
|
+
return {
|
|
109
|
+
async getById(id) {
|
|
110
|
+
const path = `/videos/${encodeURIComponent(id)}`;
|
|
111
|
+
const response = await http.get(path);
|
|
112
|
+
return response.video;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function createCollectionsResourceV2(http) {
|
|
118
|
+
return {
|
|
119
|
+
async list() {
|
|
120
|
+
const path = '/collections';
|
|
121
|
+
const response = await http.get(path);
|
|
122
|
+
return response.collections;
|
|
123
|
+
},
|
|
124
|
+
async getById(id) {
|
|
125
|
+
const path = `/collections/${encodeURIComponent(id)}`;
|
|
126
|
+
const response = await http.get(path);
|
|
127
|
+
return response.collection;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
101
132
|
const BASE_URL = "https://api.jaaq.app";
|
|
102
133
|
class JaaqClient {
|
|
103
134
|
// Keep constructor private to enforce controlled instantiation.
|
|
104
|
-
constructor(http) {
|
|
105
|
-
|
|
106
|
-
|
|
135
|
+
constructor(http, apiVersion) {
|
|
136
|
+
if (apiVersion === 'v2') {
|
|
137
|
+
this.videos = createVideosResourceV2(http);
|
|
138
|
+
this.collections = createCollectionsResourceV2(http);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.videos = createVideosResource(http);
|
|
142
|
+
this.collections = createCollectionsResource(http);
|
|
143
|
+
}
|
|
107
144
|
}
|
|
108
145
|
/**
|
|
109
146
|
* Public "friend" constructor that remains inside the class boundary.
|
|
110
147
|
* This method is callable from the module-level build function
|
|
111
148
|
* without exposing `new JaaqClient(...)` to consumers.
|
|
112
149
|
*/
|
|
113
|
-
static fromHttp(http) {
|
|
114
|
-
return new JaaqClient(http);
|
|
150
|
+
static fromHttp(http, apiVersion) {
|
|
151
|
+
return new JaaqClient(http, apiVersion);
|
|
115
152
|
}
|
|
116
153
|
/**
|
|
117
154
|
* OO-friendly static initializer.
|
|
@@ -134,14 +171,15 @@ function createJaaqClient(config) {
|
|
|
134
171
|
* The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
|
|
135
172
|
*/
|
|
136
173
|
function buildClient(config) {
|
|
137
|
-
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
|
|
174
|
+
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
|
|
138
175
|
const http = createHttpClient({
|
|
139
176
|
baseUrl,
|
|
140
177
|
apiKey,
|
|
141
178
|
clientId,
|
|
142
179
|
fetch: fetchImpl ?? globalThis.fetch,
|
|
180
|
+
apiVersion,
|
|
143
181
|
});
|
|
144
|
-
return JaaqClient.fromHttp(http);
|
|
182
|
+
return JaaqClient.fromHttp(http, apiVersion);
|
|
145
183
|
}
|
|
146
184
|
|
|
147
185
|
/**
|
|
@@ -1012,6 +1050,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
1012
1050
|
const apiKey = this.getAttribute('api-key');
|
|
1013
1051
|
const clientId = this.getAttribute('client-id');
|
|
1014
1052
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
1053
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
1015
1054
|
const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
|
|
1016
1055
|
const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
|
|
1017
1056
|
const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
|
|
@@ -1031,6 +1070,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
1031
1070
|
clientId: clientId ?? undefined,
|
|
1032
1071
|
client: this.clientInstance || undefined,
|
|
1033
1072
|
baseUrl,
|
|
1073
|
+
apiVersion,
|
|
1034
1074
|
autoplay,
|
|
1035
1075
|
controls,
|
|
1036
1076
|
showLogo,
|
|
@@ -4408,6 +4448,21 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4408
4448
|
return defaultValue;
|
|
4409
4449
|
return v !== 'false';
|
|
4410
4450
|
}
|
|
4451
|
+
getVideosFromCollection(collection) {
|
|
4452
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4453
|
+
return collection.videos;
|
|
4454
|
+
}
|
|
4455
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4456
|
+
const videos = [];
|
|
4457
|
+
collection.videoGroups.forEach((group) => {
|
|
4458
|
+
if (group.videos && group.videos.length > 0) {
|
|
4459
|
+
videos.push(...group.videos);
|
|
4460
|
+
}
|
|
4461
|
+
});
|
|
4462
|
+
return videos;
|
|
4463
|
+
}
|
|
4464
|
+
return [];
|
|
4465
|
+
}
|
|
4411
4466
|
render() {
|
|
4412
4467
|
if (!this.shadowRoot)
|
|
4413
4468
|
return;
|
|
@@ -4434,6 +4489,7 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4434
4489
|
const apiKey = this.getAttribute('api-key');
|
|
4435
4490
|
const clientId = this.getAttribute('client-id');
|
|
4436
4491
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
4492
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4437
4493
|
if (!this.clientInstance && !apiKey && !clientId) {
|
|
4438
4494
|
this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
|
|
4439
4495
|
return;
|
|
@@ -4445,9 +4501,11 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4445
4501
|
apiKey: apiKey,
|
|
4446
4502
|
clientId: clientId,
|
|
4447
4503
|
baseUrl: baseUrl || BASE_URL,
|
|
4504
|
+
apiVersion: apiVersion,
|
|
4448
4505
|
});
|
|
4449
4506
|
this.collectionData = await client.collections.getById(collectionId);
|
|
4450
|
-
|
|
4507
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4508
|
+
if (videos.length === 0) {
|
|
4451
4509
|
this.emitError(new Error('No videos found in collection'));
|
|
4452
4510
|
return;
|
|
4453
4511
|
}
|
|
@@ -4495,7 +4553,8 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4495
4553
|
console.warn('[CollectionPlayer] Failed to parse video-settings attribute', e);
|
|
4496
4554
|
}
|
|
4497
4555
|
}
|
|
4498
|
-
this.collectionData
|
|
4556
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4557
|
+
videos.forEach((video) => {
|
|
4499
4558
|
const slide = document.createElement('li');
|
|
4500
4559
|
slide.className = 'splide__slide';
|
|
4501
4560
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -4577,8 +4636,9 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4577
4636
|
Components: this.splide?.Components,
|
|
4578
4637
|
});
|
|
4579
4638
|
this.handleSlideChange(newIndex);
|
|
4639
|
+
const videos = this.collectionData ? this.getVideosFromCollection(this.collectionData) : [];
|
|
4580
4640
|
this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
|
|
4581
|
-
detail: { index: newIndex, video:
|
|
4641
|
+
detail: { index: newIndex, video: videos[newIndex] },
|
|
4582
4642
|
bubbles: true,
|
|
4583
4643
|
composed: true,
|
|
4584
4644
|
}));
|
|
@@ -4754,7 +4814,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
|
4754
4814
|
if (typeof window !== 'undefined') {
|
|
4755
4815
|
registerJaaqComponents();
|
|
4756
4816
|
}
|
|
4757
|
-
function VideoPlayerComponent({ videoId, apiKey, clientId, client, baseUrl, autoplay = false, controls = true, width = '100%', height = 'auto', className = '', showLogo = true, showTitle = true, showAuthor = true, showDescription = true, showCaptions = true, startMuted = false, onPlay, onPause, onError, onLoaded, onTimeUpdate, onVolumeChange, onEnded, onFullscreenChange, showInfo = false, }, ref) {
|
|
4817
|
+
function VideoPlayerComponent({ videoId, apiKey, clientId, client, baseUrl, apiVersion, autoplay = false, controls = true, width = '100%', height = 'auto', className = '', showLogo = true, showTitle = true, showAuthor = true, showDescription = true, showCaptions = true, startMuted = false, onPlay, onPause, onError, onLoaded, onTimeUpdate, onVolumeChange, onEnded, onFullscreenChange, showInfo = false, }, ref) {
|
|
4758
4818
|
const playerRef = React.useRef(null);
|
|
4759
4819
|
const videoDataRef = React.useRef(null);
|
|
4760
4820
|
React.useImperativeHandle(ref, () => ({
|
|
@@ -4823,7 +4883,7 @@ function VideoPlayerComponent({ videoId, apiKey, clientId, client, baseUrl, auto
|
|
|
4823
4883
|
player.setAttribute('start-muted', startMuted ? 'true' : 'false');
|
|
4824
4884
|
}, [startMuted]);
|
|
4825
4885
|
return (React__namespace.createElement("div", { style: { width, height }, className: className },
|
|
4826
|
-
React__namespace.createElement("jaaq-video-player", { ref: playerRef, "video-id": videoId, "api-key": apiKey, "client-id": clientId, "base-url": baseUrl, autoplay: autoplay ? 'true' : 'false', controls: controls ? 'true' : 'false', "show-logo": showLogo ? 'true' : 'false', "show-title": showTitle ? 'true' : 'false', "show-author": showAuthor ? 'true' : 'false', "show-description": showDescription ? 'true' : 'false', "show-captions": showCaptions ? 'true' : 'false', "start-muted": startMuted ? 'true' : 'false', width: "100%", height: "auto" }),
|
|
4886
|
+
React__namespace.createElement("jaaq-video-player", { ref: playerRef, "video-id": videoId, "api-key": apiKey, "client-id": clientId, "base-url": baseUrl, "api-version": apiVersion, autoplay: autoplay ? 'true' : 'false', controls: controls ? 'true' : 'false', "show-logo": showLogo ? 'true' : 'false', "show-title": showTitle ? 'true' : 'false', "show-author": showAuthor ? 'true' : 'false', "show-description": showDescription ? 'true' : 'false', "show-captions": showCaptions ? 'true' : 'false', "start-muted": startMuted ? 'true' : 'false', width: "100%", height: "auto" }),
|
|
4827
4887
|
showInfo && videoDataRef.current && (React__namespace.createElement("div", { className: "jaaq-video-info", style: { marginTop: '16px', padding: '16px', background: '#f8f9fa', borderRadius: '8px' } },
|
|
4828
4888
|
React__namespace.createElement("h3", { style: { margin: '0 0 12px 0', fontSize: '18px' } }, videoDataRef.current.question || videoDataRef.current.description || 'Untitled Video'),
|
|
4829
4889
|
React__namespace.createElement("p", { style: { margin: '0 0 8px 0' } },
|
|
@@ -4842,7 +4902,7 @@ const VideoPlayer = React.forwardRef(VideoPlayerComponent);
|
|
|
4842
4902
|
if (typeof window !== 'undefined') {
|
|
4843
4903
|
registerJaaqComponents();
|
|
4844
4904
|
}
|
|
4845
|
-
function CollectionPlayerComponent({ collectionId, apiKey, clientId, subscriptionId, client, baseUrl, autoplay = false, showArrows = true, showDots = true, className = '', videoSettings, onLoaded, onError, onSlideChange, }, ref) {
|
|
4905
|
+
function CollectionPlayerComponent({ collectionId, apiKey, clientId, subscriptionId, client, baseUrl, apiVersion, autoplay = false, showArrows = true, showDots = true, className = '', videoSettings, onLoaded, onError, onSlideChange, }, ref) {
|
|
4846
4906
|
const playerRef = React.useRef(null);
|
|
4847
4907
|
React.useImperativeHandle(ref, () => ({
|
|
4848
4908
|
refresh: () => playerRef.current?.refresh(),
|
|
@@ -4887,7 +4947,7 @@ function CollectionPlayerComponent({ collectionId, apiKey, clientId, subscriptio
|
|
|
4887
4947
|
};
|
|
4888
4948
|
}, [client, videoSettings, onLoaded, onError, onSlideChange]);
|
|
4889
4949
|
return (React__namespace.createElement("div", { className: className },
|
|
4890
|
-
React__namespace.createElement("jaaq-collection-player", { ref: playerRef, "collection-id": collectionId, "api-key": apiKey, "client-id": clientId, "subscription-id": subscriptionId, "base-url": baseUrl, autoplay: autoplay ? 'true' : 'false', "show-arrows": showArrows ? 'true' : 'false', "show-dots": showDots ? 'true' : 'false' })));
|
|
4950
|
+
React__namespace.createElement("jaaq-collection-player", { ref: playerRef, "collection-id": collectionId, "api-key": apiKey, "client-id": clientId, "subscription-id": subscriptionId, "base-url": baseUrl, "api-version": apiVersion, autoplay: autoplay ? 'true' : 'false', "show-arrows": showArrows ? 'true' : 'false', "show-dots": showDots ? 'true' : 'false' })));
|
|
4891
4951
|
}
|
|
4892
4952
|
CollectionPlayerComponent.displayName = 'CollectionPlayer';
|
|
4893
4953
|
const CollectionPlayer = React.forwardRef(CollectionPlayerComponent);
|