@jaaq/jaaq-sdk-js 1.1.1-dev-e4e4d9c-20251219 → 1.1.1-dev-b3e6bfd-20260515
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 +14 -7
- package/dist/embed/embed-collection.html +16 -3
- package/dist/embed/embed.html +14 -2
- package/dist/index.cjs +57 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +81 -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 +70 -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 +65 -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 +70 -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 +67 -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 +23 -23
package/README.md
CHANGED
|
@@ -63,13 +63,14 @@ const collection = await client.collections.getById('collection-id');
|
|
|
63
63
|
|
|
64
64
|
### Client config
|
|
65
65
|
|
|
66
|
-
| Option
|
|
67
|
-
|
|
|
68
|
-
| `apiKey`
|
|
69
|
-
| `clientId`
|
|
70
|
-
| `baseUrl`
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
66
|
+
| Option | Type | Required | Default | Notes |
|
|
67
|
+
| ------------ | -------------- | -------- | ---------------------- | ------------------------------------ |
|
|
68
|
+
| `apiKey` | `string` | Yes | - | Required for authentication |
|
|
69
|
+
| `clientId` | `string` | Yes | - | Used as subscription identifier |
|
|
70
|
+
| `baseUrl` | `string` | No | `https://api.jaaq.app` | API base URL |
|
|
71
|
+
| `apiVersion` | `string` | No | `v1` | API version |
|
|
72
|
+
| `fetch` | `typeof fetch` | No | `globalThis.fetch` | Provide for Node/custom runtimes |
|
|
73
|
+
| `timeoutMs` | `number` | No | - | Passed through to HTTP client config |
|
|
73
74
|
|
|
74
75
|
## UI Overview
|
|
75
76
|
|
|
@@ -310,6 +311,7 @@ export function App() {
|
|
|
310
311
|
| `clientId` | `string` | Conditional | - |
|
|
311
312
|
| `client` | `JaaqClient` | Conditional | - |
|
|
312
313
|
| `baseUrl` | `string` | No | - |
|
|
314
|
+
| `apiVersion` | `string` | Conditional | `v1` |
|
|
313
315
|
| `autoplay` | `boolean` | No | `false` |
|
|
314
316
|
| `controls` | `boolean` | No | `true` |
|
|
315
317
|
| `width` | `string` | No | `100%` |
|
|
@@ -384,6 +386,7 @@ export function App() {
|
|
|
384
386
|
| `subscriptionId` | `string` | No | - |
|
|
385
387
|
| `client` | `JaaqClient` | Conditional | - |
|
|
386
388
|
| `baseUrl` | `string` | No | - |
|
|
389
|
+
| `apiVersion` | `string` | Conditional | `v1` |
|
|
387
390
|
| `autoplay` | `boolean` | No | `false` |
|
|
388
391
|
| `showArrows` | `boolean` | No | `true` |
|
|
389
392
|
| `showDots` | `boolean` | No | `true` |
|
|
@@ -438,6 +441,7 @@ player.on('error', (err) => console.error(err));
|
|
|
438
441
|
| `clientId` | `string` | Conditional | - |
|
|
439
442
|
| `client` | `JaaqClient` | Conditional | - |
|
|
440
443
|
| `baseUrl` | `string` | No | - |
|
|
444
|
+
| `apiVersion` | `string` | Conditional | `v1` |
|
|
441
445
|
| `autoplay` | `boolean` | No | `false` |
|
|
442
446
|
| `controls` | `boolean` | No | `true` |
|
|
443
447
|
| `width` | `string` | No | `100%` |
|
|
@@ -512,6 +516,7 @@ player.on('error', (err) => console.error(err));
|
|
|
512
516
|
| `clientId` | `string` | Conditional | - |
|
|
513
517
|
| `client` | `JaaqClient` | Conditional | - |
|
|
514
518
|
| `baseUrl` | `string` | No | - |
|
|
519
|
+
| `apiVersion` | `string` | No | `v1` |
|
|
515
520
|
| `autoplay` | `boolean` | No | `false` |
|
|
516
521
|
| `showArrows` | `boolean` | No | `true` |
|
|
517
522
|
| `showDots` | `boolean` | No | `true` |
|
|
@@ -694,6 +699,7 @@ import { VideoPlayer } from '@jaaq/jaaq-sdk-js/ui/react';
|
|
|
694
699
|
| `width` | No | CSS width |
|
|
695
700
|
| `height` | No | CSS height |
|
|
696
701
|
| `baseUrl` | No | API base URL |
|
|
702
|
+
| `apiVersion` | No | API version |
|
|
697
703
|
|
|
698
704
|
### postMessage protocol
|
|
699
705
|
|
|
@@ -769,6 +775,7 @@ Embed a collection of videos in a carousel format:
|
|
|
769
775
|
| `collectionId` | Yes | Collection ID |
|
|
770
776
|
| `autoplay` | No | `true`, `false`, `1`, `0` |
|
|
771
777
|
| `baseUrl` | No | API base URL |
|
|
778
|
+
| `apiVersion` | No | API version |
|
|
772
779
|
| `controls` | No | `true`, `false`, `1`, `0` |
|
|
773
780
|
| `showLogo` | No | `true`, `false`, `1`, `0` |
|
|
774
781
|
| `showTitle` | No | `true`, `false`, `1`, `0` |
|
|
@@ -118,6 +118,11 @@
|
|
|
118
118
|
config.baseUrl = baseUrl;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
const apiVersion = params.get('apiVersion');
|
|
122
|
+
if (apiVersion) {
|
|
123
|
+
config.apiVersion = apiVersion;
|
|
124
|
+
}
|
|
125
|
+
|
|
121
126
|
const showArrows = params.get('showArrows');
|
|
122
127
|
if (showArrows !== null) {
|
|
123
128
|
config.showArrows = showArrows === 'true' || showArrows === '1';
|
|
@@ -188,6 +193,10 @@
|
|
|
188
193
|
player.setAttribute('base-url', config.baseUrl);
|
|
189
194
|
}
|
|
190
195
|
|
|
196
|
+
if (config.apiVersion) {
|
|
197
|
+
player.setAttribute('api-version', config.apiVersion);
|
|
198
|
+
}
|
|
199
|
+
|
|
191
200
|
if (config.autoplay) {
|
|
192
201
|
player.setAttribute('autoplay', 'true');
|
|
193
202
|
}
|
|
@@ -227,7 +236,8 @@
|
|
|
227
236
|
name: collection.name,
|
|
228
237
|
description: collection.description,
|
|
229
238
|
},
|
|
230
|
-
videoCount:
|
|
239
|
+
videoCount:
|
|
240
|
+
collection.videos?.length || collection.videoGroups?.reduce((sum, group) => sum + (group.videos?.length || 0), 0) || 0,
|
|
231
241
|
});
|
|
232
242
|
});
|
|
233
243
|
|
|
@@ -317,8 +327,11 @@
|
|
|
317
327
|
|
|
318
328
|
<script
|
|
319
329
|
src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
|
|
320
|
-
onerror="
|
|
321
|
-
|
|
330
|
+
onerror="
|
|
331
|
+
console.error('[Embed Collection] Failed to load web component script');
|
|
332
|
+
showError('Failed to load collection player script');
|
|
333
|
+
"
|
|
334
|
+
onload="console.log('[Embed Collection] Web component script loaded')"
|
|
322
335
|
></script>
|
|
323
336
|
</body>
|
|
324
337
|
</html>
|
package/dist/embed/embed.html
CHANGED
|
@@ -118,6 +118,11 @@
|
|
|
118
118
|
config.baseUrl = baseUrl;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
const apiVersion = params.get('apiVersion');
|
|
122
|
+
if (apiVersion) {
|
|
123
|
+
config.apiVersion = apiVersion;
|
|
124
|
+
}
|
|
125
|
+
|
|
121
126
|
const controls = params.get('controls');
|
|
122
127
|
if (controls !== null) {
|
|
123
128
|
config.controls = controls === 'true' || controls === '1';
|
|
@@ -186,6 +191,10 @@
|
|
|
186
191
|
player.setAttribute('base-url', config.baseUrl);
|
|
187
192
|
}
|
|
188
193
|
|
|
194
|
+
if (config.apiVersion) {
|
|
195
|
+
player.setAttribute('api-version', config.apiVersion);
|
|
196
|
+
}
|
|
197
|
+
|
|
189
198
|
if (config.autoplay) {
|
|
190
199
|
player.setAttribute('autoplay', 'true');
|
|
191
200
|
}
|
|
@@ -326,8 +335,11 @@
|
|
|
326
335
|
|
|
327
336
|
<script
|
|
328
337
|
src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
|
|
329
|
-
onerror="
|
|
330
|
-
|
|
338
|
+
onerror="
|
|
339
|
+
console.error('[Embed] Failed to load web component script');
|
|
340
|
+
showError('Failed to load player script');
|
|
341
|
+
"
|
|
342
|
+
onload="console.log('[Embed] Web component script loaded')"
|
|
331
343
|
></script>
|
|
332
344
|
</body>
|
|
333
345
|
</html>
|
package/dist/index.cjs
CHANGED
|
@@ -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/
|
|
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
|
-
|
|
84
|
-
|
|
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.
|
|
@@ -106,23 +143,32 @@ class JaaqClient {
|
|
|
106
143
|
function createJaaqClient(config) {
|
|
107
144
|
return buildClient(config);
|
|
108
145
|
}
|
|
146
|
+
function createJaaqClientV1(config) {
|
|
147
|
+
return createJaaqClient({ ...config, apiVersion: 'v1' });
|
|
148
|
+
}
|
|
149
|
+
function createJaaqClientV2(config) {
|
|
150
|
+
return createJaaqClient({ ...config, apiVersion: 'v2' });
|
|
151
|
+
}
|
|
109
152
|
/**
|
|
110
153
|
* Single source of truth for constructing the client.
|
|
111
154
|
* Both `createJaaqClient` and `JaaqClient.init` call this function.
|
|
112
155
|
* The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
|
|
113
156
|
*/
|
|
114
157
|
function buildClient(config) {
|
|
115
|
-
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
|
|
158
|
+
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
|
|
116
159
|
const http = createHttpClient({
|
|
117
160
|
baseUrl,
|
|
118
161
|
apiKey,
|
|
119
162
|
clientId,
|
|
120
163
|
fetch: fetchImpl ?? globalThis.fetch,
|
|
164
|
+
apiVersion,
|
|
121
165
|
});
|
|
122
|
-
return JaaqClient.fromHttp(http);
|
|
166
|
+
return JaaqClient.fromHttp(http, apiVersion);
|
|
123
167
|
}
|
|
124
168
|
|
|
125
169
|
exports.BASE_URL = BASE_URL;
|
|
126
170
|
exports.JaaqClient = JaaqClient;
|
|
127
171
|
exports.createJaaqClient = createJaaqClient;
|
|
172
|
+
exports.createJaaqClientV1 = createJaaqClientV1;
|
|
173
|
+
exports.createJaaqClientV2 = createJaaqClientV2;
|
|
128
174
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/core/httpClient.ts","../src/resources/videos.ts","../src/resources/collections.ts","../src/index.ts"],"sourcesContent":["export type FetchLike = typeof globalThis.fetch;\ntype RequestOptions = Parameters<typeof globalThis.fetch>[1];\ntype FetchResponse = Awaited<ReturnType<FetchLike>>;\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n clientId: string;\n fetch?: FetchLike;\n timeoutMs?: number;\n}\n\nexport interface HttpClient {\n get<T>(_path: string, _init?: RequestOptions): Promise<T>;\n post<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n put<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n patch<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n delete<T>(_path: string, _init?: RequestOptions): Promise<T>;\n}\n\nasync function parseJson<T>(res: FetchResponse): Promise<T> {\n if (!res.ok) {\n const text = await res.text().catch(() => '');\n throw new Error(`HTTP ${res.status}: ${text || res.statusText}`);\n }\n if (res.status === 204) return undefined as unknown as T;\n return res.json() as Promise<T>;\n}\n\nfunction joinUrl(baseUrl: string, clientId: string, path: string): string {\n // return path if it is an absolute URL\n if (/^https?:\\/\\//i.test(path)) return path;\n const base = baseUrl.replace(/\\/+$/, '');\n const relative = path.replace(/^\\/+/, '');\n return `${base}/b2b/v1/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;\n}\n\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;\n\n const f: FetchLike | undefined = fetchImpl ?? (globalThis.fetch as FetchLike | undefined);\n if (!f) {\n throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');\n }\n\n const baseHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n };\n\n const fullUrl = (path: string) => joinUrl(baseUrl, clientId, path);\n\n const request = async <T>(method: string, path: string, init?: RequestOptions, body?: unknown) => {\n const reqInit: RequestOptions = {\n method,\n headers: {\n ...baseHeaders,\n ...(init?.headers as Record<string, string> | undefined),\n },\n ...init,\n };\n if (body !== undefined) reqInit.body = JSON.stringify(body);\n const res = await f(fullUrl(path), reqInit);\n return parseJson<T>(res);\n };\n\n return {\n get: <T>(path: string, init?: RequestOptions) => request<T>('GET', path, init),\n post: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('POST', path, init, body),\n put: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('PUT', path, init, body),\n patch: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('PATCH', path, init, body),\n delete: <T>(path: string, init?: RequestOptions) => request<T>('DELETE', path, init),\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { VideoDTO } from '@src/types/videos';\n\nexport type VideosResource = {\n getById(_id: string): Promise<VideoDTO>;\n};\n\nexport function createVideosResource(http: HttpClient): VideosResource {\n return {\n async getById(id: string) {\n const path = `/videos/${encodeURIComponent(id)}`;\n const response = await http.get<{ video: VideoDTO }>(path);\n return response.video;\n },\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { CollectionDTO } from '@src/types/collection';\n\nexport type CollectionsResource = {\n list(): Promise<CollectionDTO[]>;\n getById(_id: string): Promise<CollectionDTO>;\n};\n\nexport function createCollectionsResource(http: HttpClient): CollectionsResource {\n return {\n async list() {\n const path = '/collections';\n const response = await http.get<{ collections: CollectionDTO[] }>(path);\n return response.collections;\n },\n async getById(id: string) {\n const path = `/collections/${encodeURIComponent(id)}`;\n const response = await http.get<{ collection: CollectionDTO }>(path);\n return response.collection;\n },\n };\n}\n","import { createHttpClient, type HttpClient, type FetchLike } from '@core/httpClient';\nimport { createVideosResource, type VideosResource } from '@resources/videos';\nimport { createCollectionsResource, type CollectionsResource } from '@resources/collections';\n\n// Public type exports for consumers (barrel)\nexport * from '@src/types';\n\nexport const BASE_URL = process.env.JAAQ_API_URL || 'https://api.jaaq.app';\n\nexport interface SDKConfig {\n baseUrl?: string; // Pending to approve\n apiKey: string; // Provided by backend per client\n clientId: string; // Provided by each consuming company at init\n fetch?: FetchLike; // Optional fetch injection (Node/custom envs) // Pending to approve\n timeoutMs?: number;\n}\n\nexport class JaaqClient {\n public readonly videos: VideosResource;\n public readonly collections: CollectionsResource;\n\n // Keep constructor private to enforce controlled instantiation.\n private constructor(http: HttpClient) {\n this.videos = createVideosResource(http);\n this.collections = createCollectionsResource(http);\n }\n\n /**\n * Public \"friend\" constructor that remains inside the class boundary.\n * This method is callable from the module-level build function\n * without exposing `new JaaqClient(...)` to consumers.\n */\n static fromHttp(http: HttpClient): JaaqClient {\n return new JaaqClient(http);\n }\n\n /**\n * OO-friendly static initializer.\n * Delegates to the single source of truth: `buildClient`.\n */\n static init(config: SDKConfig): JaaqClient {\n return buildClient(config);\n }\n}\n\n/**\n * Canonical factory (idiomatic for JS/TS).\n * Delegates to the single source of truth: `buildClient`.\n */\nexport function createJaaqClient(config: SDKConfig): JaaqClient {\n return buildClient(config);\n}\n\n/**\n * Single source of truth for constructing the client.\n * Both `createJaaqClient` and `JaaqClient.init` call this function.\n * The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.\n */\nfunction buildClient(config: SDKConfig): JaaqClient {\n const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;\n\n const http = createHttpClient({\n baseUrl,\n apiKey,\n clientId,\n fetch: fetchImpl ?? (globalThis.fetch as FetchLike | undefined),\n });\n\n return JaaqClient.fromHttp(http);\n}\n"],"names":[],"mappings":";;AAoBA,eAAe,SAAS,CAAI,GAAkB,EAAA;AAC5C,IAAA,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;AACX,QAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AAC7C,QAAA,MAAM,IAAI,KAAK,CAAC,CAAA,KAAA,EAAQ,GAAG,CAAC,MAAM,CAAA,EAAA,EAAK,IAAI,IAAI,GAAG,CAAC,UAAU,CAAA,CAAE,CAAC;IAClE;AACA,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG;AAAE,QAAA,OAAO,SAAyB;AACxD,IAAA,OAAO,GAAG,CAAC,IAAI,EAAgB;AACjC;AAEA,SAAS,OAAO,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAY,EAAA;;AAE9D,IAAA,IAAI,eAAe,CAAC,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ient.ts","../src/resources/v1/videos.ts","../src/resources/v1/collections.ts","../src/resources/v2/videos.ts","../src/resources/v2/collections.ts","../src/index.ts"],"sourcesContent":["export type FetchLike = typeof globalThis.fetch;\ntype RequestOptions = Parameters<typeof globalThis.fetch>[1];\ntype FetchResponse = Awaited<ReturnType<FetchLike>>;\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiVersion: string;\n apiKey: string;\n clientId: string;\n fetch?: FetchLike;\n timeoutMs?: number;\n}\n\nexport interface HttpClient {\n get<T>(_path: string, _init?: RequestOptions): Promise<T>;\n post<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n put<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n patch<T>(_path: string, _body?: unknown, _init?: RequestOptions): Promise<T>;\n delete<T>(_path: string, _init?: RequestOptions): Promise<T>;\n}\n\nasync function parseJson<T>(res: FetchResponse): Promise<T> {\n if (!res.ok) {\n const text = await res.text().catch(() => '');\n throw new Error(`HTTP ${res.status}: ${text || res.statusText}`);\n }\n if (res.status === 204) return undefined as unknown as T;\n return res.json() as Promise<T>;\n}\n\nfunction joinUrl(baseUrl: string, apiVersion: string, clientId: string, path: string): string {\n // return path if it is an absolute URL\n if (/^https?:\\/\\//i.test(path)) return path;\n const base = baseUrl.replace(/\\/+$/, '');\n const relative = path.replace(/^\\/+/, '');\n return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;\n}\n\nfunction convertToValidAPIVersion(version: string): string {\n const v = version.toLowerCase();\n if (v === 'v1' || v === 'v2') return v;\n return 'v1'; // default to v1 if invalid version provided\n}\n\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;\n\n const f: FetchLike | undefined = fetchImpl ?? (globalThis.fetch as FetchLike | undefined);\n if (!f) {\n throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');\n }\n\n const baseHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'x-api-key': apiKey,\n };\n\n const fullUrl = (path: string) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);\n\n const request = async <T>(method: string, path: string, init?: RequestOptions, body?: unknown) => {\n const reqInit: RequestOptions = {\n method,\n headers: {\n ...baseHeaders,\n ...(init?.headers as Record<string, string> | undefined),\n },\n ...init,\n };\n if (body !== undefined) reqInit.body = JSON.stringify(body);\n const res = await f(fullUrl(path), reqInit);\n return parseJson<T>(res);\n };\n\n return {\n get: <T>(path: string, init?: RequestOptions) => request<T>('GET', path, init),\n post: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('POST', path, init, body),\n put: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('PUT', path, init, body),\n patch: <T>(path: string, body?: unknown, init?: RequestOptions) => request<T>('PATCH', path, init, body),\n delete: <T>(path: string, init?: RequestOptions) => request<T>('DELETE', path, init),\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { VideoDTO } from '@src/types';\n\nexport type VideosResource = {\n getById(_id: string): Promise<VideoDTO>;\n};\n\nexport function createVideosResource(http: HttpClient): VideosResource {\n return {\n async getById(id: string) {\n const path = `/videos/${encodeURIComponent(id)}`;\n const response = await http.get<{ video: VideoDTO }>(path);\n return response.video;\n },\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { CollectionDTO } from '@src/types';\n\nexport type CollectionsResource = {\n list(): Promise<CollectionDTO[]>;\n getById(_id: string): Promise<CollectionDTO>;\n};\n\nexport function createCollectionsResource(http: HttpClient): CollectionsResource {\n return {\n async list() {\n const path = '/collections';\n const response = await http.get<{ collections: CollectionDTO[] }>(path);\n return response.collections;\n },\n async getById(id: string) {\n const path = `/collections/${encodeURIComponent(id)}`;\n const response = await http.get<{ collection: CollectionDTO }>(path);\n return response.collection;\n },\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { VideoV2DTO } from '@src/types';\n\nexport type VideosResourceV2 = {\n getById(_id: string): Promise<VideoV2DTO>;\n};\n\nexport function createVideosResourceV2(http: HttpClient): VideosResourceV2 {\n return {\n async getById(id: string) {\n const path = `/videos/${encodeURIComponent(id)}`;\n const response = await http.get<{ video: VideoV2DTO }>(path);\n return response.video;\n },\n };\n}\n","import type { HttpClient } from '@core/httpClient';\nimport type { CollectionV2DTO } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string): Promise<CollectionV2DTO>;\n};\n\nexport function createCollectionsResourceV2(http: HttpClient): CollectionsResourceV2 {\n return {\n async list() {\n const path = '/collections';\n const response = await http.get<{ collections: CollectionV2DTO[] }>(path);\n return response.collections;\n },\n async getById(id: string) {\n const path = `/collections/${encodeURIComponent(id)}`;\n const response = await http.get<{ collection: CollectionV2DTO }>(path);\n return response.collection;\n },\n };\n}\n","import { createHttpClient, type HttpClient, type FetchLike } from '@core/httpClient';\nimport {\n createCollectionsResource,\n createCollectionsResourceV2,\n createVideosResource,\n createVideosResourceV2,\n type VideosResource,\n type VideosResourceV2,\n type CollectionsResource,\n type CollectionsResourceV2,\n} from '@src/resources';\n\n// Public type exports for consumers (barrel)\nexport * from '@src/types';\n\nexport const BASE_URL = process.env.JAAQ_API_URL || 'https://api.jaaq.app';\n\nexport interface SDKConfig {\n baseUrl?: string; // Pending to approve\n apiVersion?: string; // Optional API version override (defaults to 'v1')\n apiKey: string; // Provided by backend per client\n clientId: string; // Provided by each consuming company at init\n fetch?: FetchLike; // Optional fetch injection (Node/custom envs) // Pending to approve\n timeoutMs?: number;\n}\n\nexport type V1 = {\n videos: VideosResource;\n collections: CollectionsResource;\n};\n\nexport type V2 = {\n videos: VideosResourceV2;\n collections: CollectionsResourceV2;\n};\n\nexport type ClientVersion = V1 | V2;\n\nexport class JaaqClient<T extends ClientVersion = V1> {\n public readonly videos: T['videos'];\n public readonly collections: T['collections'];\n\n // Keep constructor private to enforce controlled instantiation.\n private constructor(http: HttpClient, apiVersion: string) {\n if (apiVersion === 'v2') {\n this.videos = createVideosResourceV2(http);\n this.collections = createCollectionsResourceV2(http);\n } else {\n this.videos = createVideosResource(http);\n this.collections = createCollectionsResource(http);\n }\n }\n\n /**\n * Public \"friend\" constructor that remains inside the class boundary.\n * This method is callable from the module-level build function\n * without exposing `new JaaqClient(...)` to consumers.\n */\n static fromHttp<T extends ClientVersion = V1>(http: HttpClient, apiVersion: string): JaaqClient<T> {\n return new JaaqClient(http, apiVersion);\n }\n\n /**\n * OO-friendly static initializer.\n * Delegates to the single source of truth: `buildClient`.\n */\n static init<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T> {\n return buildClient(config);\n }\n}\n\n/**\n * Canonical factory (idiomatic for JS/TS).\n * Delegates to the single source of truth: `buildClient`.\n */\nexport function createJaaqClient<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T> {\n return buildClient(config);\n}\n\nexport function createJaaqClientV1(config: SDKConfig): JaaqClient<V1> {\n return createJaaqClient({ ...config, apiVersion: 'v1' });\n}\n\nexport function createJaaqClientV2(config: SDKConfig): JaaqClient<V2> {\n return createJaaqClient({ ...config, apiVersion: 'v2' });\n}\n\n/**\n * Single source of truth for constructing the client.\n * Both `createJaaqClient` and `JaaqClient.init` call this function.\n * The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.\n */\nfunction buildClient<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T> {\n const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;\n\n const http = createHttpClient({\n baseUrl,\n apiKey,\n clientId,\n fetch: fetchImpl ?? (globalThis.fetch as FetchLike | undefined),\n apiVersion,\n });\n\n return JaaqClient.fromHttp(http, apiVersion);\n}\n"],"names":[],"mappings":";;AAqBA,eAAe,SAAS,CAAI,GAAkB,EAAA;AAC5C,IAAA,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;AACX,QAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI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AEM,SAAU,kBAAkB,CAAC,MAAiB,EAAA;IAClD,OAAO,gBAAgB,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC1D;AAEM,SAAU,kBAAkB,CAAC,MAAiB,EAAA;IAClD,OAAO,gBAAgB,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC1D;AAEA;;;;AAIG;AACH,SAAS,WAAW,CAA+B,MAAiB,EAAA;AAClE,IAAA,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,GAAG,IAAI,EAAE,GAAG,MAAM;IAE5F,MAAM,IAAI,GAAG,gBAAgB,CAAC;QAC5B,OAAO;QACP,MAAM;QACN,QAAQ;AACR,QAAA,KAAK,EAAE,SAAS,IAAK,UAAU,CAAC,KAA+B;QAC/D,UAAU;AACX,KAAA,CAAC;IAEF,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;AAC9C;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,20 @@ interface HttpClient {
|
|
|
8
8
|
delete<T>(_path: string, _init?: RequestOptions): Promise<T>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
type ISODateTimeString = string;
|
|
12
|
+
interface ApiError {
|
|
13
|
+
description: string;
|
|
14
|
+
error: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Subtopic {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
createdAt: ISODateTimeString;
|
|
21
|
+
modifiedAt: ISODateTimeString;
|
|
22
|
+
modifiedBy: ISODateTimeString;
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
type VideoDTO = {
|
|
12
26
|
id: string;
|
|
13
27
|
videoId: string;
|
|
@@ -27,10 +41,6 @@ type VideoDTO = {
|
|
|
27
41
|
creatorBiography?: string;
|
|
28
42
|
};
|
|
29
43
|
|
|
30
|
-
type VideosResource = {
|
|
31
|
-
getById(_id: string): Promise<VideoDTO>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
44
|
type CollectionDTO = {
|
|
35
45
|
id: string;
|
|
36
46
|
name: string;
|
|
@@ -40,54 +50,101 @@ type CollectionDTO = {
|
|
|
40
50
|
videos: VideoDTO[];
|
|
41
51
|
};
|
|
42
52
|
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
type CreatorV2DTO = {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
biography: string;
|
|
57
|
+
videoUrl: string;
|
|
58
|
+
type: string;
|
|
46
59
|
};
|
|
47
60
|
|
|
48
|
-
type
|
|
49
|
-
|
|
61
|
+
type VideoV2DTO = {
|
|
62
|
+
id: string;
|
|
63
|
+
videoId: string;
|
|
64
|
+
question: string;
|
|
65
|
+
transcription: string;
|
|
66
|
+
subtitle: string;
|
|
67
|
+
videoUrl: string;
|
|
68
|
+
tags: string[];
|
|
69
|
+
severity: number | null;
|
|
70
|
+
duration: number;
|
|
50
71
|
description: string;
|
|
51
|
-
|
|
52
|
-
}
|
|
72
|
+
creator?: CreatorV2DTO;
|
|
73
|
+
};
|
|
53
74
|
|
|
54
|
-
|
|
75
|
+
type VideoGroupV2DTO = {
|
|
76
|
+
id: string;
|
|
77
|
+
title: string;
|
|
78
|
+
videos: VideoV2DTO[];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type CollectionV2DTO = {
|
|
55
82
|
id: string;
|
|
56
83
|
name: string;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
84
|
+
description: string;
|
|
85
|
+
imageUrl: string;
|
|
86
|
+
videoGroups: VideoGroupV2DTO[];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
type VideosResource = {
|
|
90
|
+
getById(_id: string): Promise<VideoDTO>;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
type CollectionsResource = {
|
|
94
|
+
list(): Promise<CollectionDTO[]>;
|
|
95
|
+
getById(_id: string): Promise<CollectionDTO>;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type VideosResourceV2 = {
|
|
99
|
+
getById(_id: string): Promise<VideoV2DTO>;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
type CollectionsResourceV2 = {
|
|
103
|
+
list(): Promise<CollectionV2DTO[]>;
|
|
104
|
+
getById(_id: string): Promise<CollectionV2DTO>;
|
|
105
|
+
};
|
|
61
106
|
|
|
62
107
|
declare const BASE_URL: string;
|
|
63
108
|
interface SDKConfig {
|
|
64
109
|
baseUrl?: string;
|
|
110
|
+
apiVersion?: string;
|
|
65
111
|
apiKey: string;
|
|
66
112
|
clientId: string;
|
|
67
113
|
fetch?: FetchLike;
|
|
68
114
|
timeoutMs?: number;
|
|
69
115
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
116
|
+
type V1 = {
|
|
117
|
+
videos: VideosResource;
|
|
118
|
+
collections: CollectionsResource;
|
|
119
|
+
};
|
|
120
|
+
type V2 = {
|
|
121
|
+
videos: VideosResourceV2;
|
|
122
|
+
collections: CollectionsResourceV2;
|
|
123
|
+
};
|
|
124
|
+
type ClientVersion = V1 | V2;
|
|
125
|
+
declare class JaaqClient<T extends ClientVersion = V1> {
|
|
126
|
+
readonly videos: T['videos'];
|
|
127
|
+
readonly collections: T['collections'];
|
|
73
128
|
private constructor();
|
|
74
129
|
/**
|
|
75
130
|
* Public "friend" constructor that remains inside the class boundary.
|
|
76
131
|
* This method is callable from the module-level build function
|
|
77
132
|
* without exposing `new JaaqClient(...)` to consumers.
|
|
78
133
|
*/
|
|
79
|
-
static fromHttp(http: HttpClient): JaaqClient
|
|
134
|
+
static fromHttp<T extends ClientVersion = V1>(http: HttpClient, apiVersion: string): JaaqClient<T>;
|
|
80
135
|
/**
|
|
81
136
|
* OO-friendly static initializer.
|
|
82
137
|
* Delegates to the single source of truth: `buildClient`.
|
|
83
138
|
*/
|
|
84
|
-
static init(config: SDKConfig): JaaqClient
|
|
139
|
+
static init<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T>;
|
|
85
140
|
}
|
|
86
141
|
/**
|
|
87
142
|
* Canonical factory (idiomatic for JS/TS).
|
|
88
143
|
* Delegates to the single source of truth: `buildClient`.
|
|
89
144
|
*/
|
|
90
|
-
declare function createJaaqClient(config: SDKConfig): JaaqClient
|
|
145
|
+
declare function createJaaqClient<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T>;
|
|
146
|
+
declare function createJaaqClientV1(config: SDKConfig): JaaqClient<V1>;
|
|
147
|
+
declare function createJaaqClientV2(config: SDKConfig): JaaqClient<V2>;
|
|
91
148
|
|
|
92
|
-
export { BASE_URL, JaaqClient, createJaaqClient };
|
|
93
|
-
export type { ApiError, CollectionDTO, ISODateTimeString, SDKConfig, Subtopic, VideoDTO };
|
|
149
|
+
export { BASE_URL, JaaqClient, createJaaqClient, createJaaqClientV1, createJaaqClientV2 };
|
|
150
|
+
export type { ApiError, ClientVersion, CollectionDTO, CollectionV2DTO, CreatorV2DTO, ISODateTimeString, SDKConfig, Subtopic, V1, V2, VideoDTO, VideoGroupV2DTO, VideoV2DTO };
|
package/dist/index.mjs
CHANGED
|
@@ -7,16 +7,22 @@ async function parseJson(res) {
|
|
|
7
7
|
return undefined;
|
|
8
8
|
return res.json();
|
|
9
9
|
}
|
|
10
|
-
function joinUrl(baseUrl, clientId, path) {
|
|
10
|
+
function joinUrl(baseUrl, apiVersion, clientId, path) {
|
|
11
11
|
// return path if it is an absolute URL
|
|
12
12
|
if (/^https?:\/\//i.test(path))
|
|
13
13
|
return path;
|
|
14
14
|
const base = baseUrl.replace(/\/+$/, '');
|
|
15
15
|
const relative = path.replace(/^\/+/, '');
|
|
16
|
-
return `${base}/b2b/
|
|
16
|
+
return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
|
|
17
|
+
}
|
|
18
|
+
function convertToValidAPIVersion(version) {
|
|
19
|
+
const v = version.toLowerCase();
|
|
20
|
+
if (v === 'v1' || v === 'v2')
|
|
21
|
+
return v;
|
|
22
|
+
return 'v1'; // default to v1 if invalid version provided
|
|
17
23
|
}
|
|
18
24
|
function createHttpClient(config) {
|
|
19
|
-
const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
|
|
25
|
+
const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;
|
|
20
26
|
const f = fetchImpl ?? globalThis.fetch;
|
|
21
27
|
if (!f) {
|
|
22
28
|
throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
|
|
@@ -25,7 +31,7 @@ function createHttpClient(config) {
|
|
|
25
31
|
'Content-Type': 'application/json',
|
|
26
32
|
'x-api-key': apiKey,
|
|
27
33
|
};
|
|
28
|
-
const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
|
|
34
|
+
const fullUrl = (path) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);
|
|
29
35
|
const request = async (method, path, init, body) => {
|
|
30
36
|
const reqInit = {
|
|
31
37
|
method,
|
|
@@ -74,20 +80,51 @@ function createCollectionsResource(http) {
|
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
|
|
83
|
+
function createVideosResourceV2(http) {
|
|
84
|
+
return {
|
|
85
|
+
async getById(id) {
|
|
86
|
+
const path = `/videos/${encodeURIComponent(id)}`;
|
|
87
|
+
const response = await http.get(path);
|
|
88
|
+
return response.video;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function createCollectionsResourceV2(http) {
|
|
94
|
+
return {
|
|
95
|
+
async list() {
|
|
96
|
+
const path = '/collections';
|
|
97
|
+
const response = await http.get(path);
|
|
98
|
+
return response.collections;
|
|
99
|
+
},
|
|
100
|
+
async getById(id) {
|
|
101
|
+
const path = `/collections/${encodeURIComponent(id)}`;
|
|
102
|
+
const response = await http.get(path);
|
|
103
|
+
return response.collection;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
77
108
|
const BASE_URL = "https://api.jaaq.app";
|
|
78
109
|
class JaaqClient {
|
|
79
110
|
// Keep constructor private to enforce controlled instantiation.
|
|
80
|
-
constructor(http) {
|
|
81
|
-
|
|
82
|
-
|
|
111
|
+
constructor(http, apiVersion) {
|
|
112
|
+
if (apiVersion === 'v2') {
|
|
113
|
+
this.videos = createVideosResourceV2(http);
|
|
114
|
+
this.collections = createCollectionsResourceV2(http);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
this.videos = createVideosResource(http);
|
|
118
|
+
this.collections = createCollectionsResource(http);
|
|
119
|
+
}
|
|
83
120
|
}
|
|
84
121
|
/**
|
|
85
122
|
* Public "friend" constructor that remains inside the class boundary.
|
|
86
123
|
* This method is callable from the module-level build function
|
|
87
124
|
* without exposing `new JaaqClient(...)` to consumers.
|
|
88
125
|
*/
|
|
89
|
-
static fromHttp(http) {
|
|
90
|
-
return new JaaqClient(http);
|
|
126
|
+
static fromHttp(http, apiVersion) {
|
|
127
|
+
return new JaaqClient(http, apiVersion);
|
|
91
128
|
}
|
|
92
129
|
/**
|
|
93
130
|
* OO-friendly static initializer.
|
|
@@ -104,21 +141,28 @@ class JaaqClient {
|
|
|
104
141
|
function createJaaqClient(config) {
|
|
105
142
|
return buildClient(config);
|
|
106
143
|
}
|
|
144
|
+
function createJaaqClientV1(config) {
|
|
145
|
+
return createJaaqClient({ ...config, apiVersion: 'v1' });
|
|
146
|
+
}
|
|
147
|
+
function createJaaqClientV2(config) {
|
|
148
|
+
return createJaaqClient({ ...config, apiVersion: 'v2' });
|
|
149
|
+
}
|
|
107
150
|
/**
|
|
108
151
|
* Single source of truth for constructing the client.
|
|
109
152
|
* Both `createJaaqClient` and `JaaqClient.init` call this function.
|
|
110
153
|
* The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
|
|
111
154
|
*/
|
|
112
155
|
function buildClient(config) {
|
|
113
|
-
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
|
|
156
|
+
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
|
|
114
157
|
const http = createHttpClient({
|
|
115
158
|
baseUrl,
|
|
116
159
|
apiKey,
|
|
117
160
|
clientId,
|
|
118
161
|
fetch: fetchImpl ?? globalThis.fetch,
|
|
162
|
+
apiVersion,
|
|
119
163
|
});
|
|
120
|
-
return JaaqClient.fromHttp(http);
|
|
164
|
+
return JaaqClient.fromHttp(http, apiVersion);
|
|
121
165
|
}
|
|
122
166
|
|
|
123
|
-
export { BASE_URL, JaaqClient, createJaaqClient };
|
|
167
|
+
export { BASE_URL, JaaqClient, createJaaqClient, createJaaqClientV1, createJaaqClientV2 };
|
|
124
168
|
//# sourceMappingURL=index.mjs.map
|