@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
package/README.md CHANGED
@@ -10,6 +10,10 @@ It includes:
10
10
 
11
11
  ## Installation
12
12
 
13
+ ### Requirements
14
+
15
+ Node.js **≥ 22**. The SDK is tested in CI against Node 22 and supports anything Node ≥ 22 at runtime; consumers on EOL Node 20 (and below) may see an unsupported engine warning or error from their package manager (npm typically reports this as `EBADENGINE`).
16
+
13
17
  ```bash
14
18
  pnpm add @jaaq/jaaq-sdk-js
15
19
  ```
@@ -63,13 +67,14 @@ const collection = await client.collections.getById('collection-id');
63
67
 
64
68
  ### Client config
65
69
 
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
- | `fetch` | `typeof fetch` | No | `globalThis.fetch` | Provide for Node/custom runtimes |
72
- | `timeoutMs` | `number` | No | - | Passed through to HTTP client config |
70
+ | Option | Type | Required | Default | Notes |
71
+ | ------------ | -------------- | -------- | ---------------------- | ------------------------------------ |
72
+ | `apiKey` | `string` | Yes | - | Required for authentication |
73
+ | `clientId` | `string` | Yes | - | Used as subscription identifier |
74
+ | `baseUrl` | `string` | No | `https://api.jaaq.app` | API base URL |
75
+ | `apiVersion` | `string` | No | `v1` | API version |
76
+ | `fetch` | `typeof fetch` | No | `globalThis.fetch` | Provide for Node/custom runtimes |
77
+ | `timeoutMs` | `number` | No | - | Passed through to HTTP client config |
73
78
 
74
79
  ## UI Overview
75
80
 
@@ -310,6 +315,7 @@ export function App() {
310
315
  | `clientId` | `string` | Conditional | - |
311
316
  | `client` | `JaaqClient` | Conditional | - |
312
317
  | `baseUrl` | `string` | No | - |
318
+ | `apiVersion` | `string` | Conditional | `v1` |
313
319
  | `autoplay` | `boolean` | No | `false` |
314
320
  | `controls` | `boolean` | No | `true` |
315
321
  | `width` | `string` | No | `100%` |
@@ -384,6 +390,7 @@ export function App() {
384
390
  | `subscriptionId` | `string` | No | - |
385
391
  | `client` | `JaaqClient` | Conditional | - |
386
392
  | `baseUrl` | `string` | No | - |
393
+ | `apiVersion` | `string` | Conditional | `v1` |
387
394
  | `autoplay` | `boolean` | No | `false` |
388
395
  | `showArrows` | `boolean` | No | `true` |
389
396
  | `showDots` | `boolean` | No | `true` |
@@ -438,6 +445,7 @@ player.on('error', (err) => console.error(err));
438
445
  | `clientId` | `string` | Conditional | - |
439
446
  | `client` | `JaaqClient` | Conditional | - |
440
447
  | `baseUrl` | `string` | No | - |
448
+ | `apiVersion` | `string` | Conditional | `v1` |
441
449
  | `autoplay` | `boolean` | No | `false` |
442
450
  | `controls` | `boolean` | No | `true` |
443
451
  | `width` | `string` | No | `100%` |
@@ -512,6 +520,7 @@ player.on('error', (err) => console.error(err));
512
520
  | `clientId` | `string` | Conditional | - |
513
521
  | `client` | `JaaqClient` | Conditional | - |
514
522
  | `baseUrl` | `string` | No | - |
523
+ | `apiVersion` | `string` | No | `v1` |
515
524
  | `autoplay` | `boolean` | No | `false` |
516
525
  | `showArrows` | `boolean` | No | `true` |
517
526
  | `showDots` | `boolean` | No | `true` |
@@ -694,6 +703,7 @@ import { VideoPlayer } from '@jaaq/jaaq-sdk-js/ui/react';
694
703
  | `width` | No | CSS width |
695
704
  | `height` | No | CSS height |
696
705
  | `baseUrl` | No | API base URL |
706
+ | `apiVersion` | No | API version |
697
707
 
698
708
  ### postMessage protocol
699
709
 
@@ -769,6 +779,7 @@ Embed a collection of videos in a carousel format:
769
779
  | `collectionId` | Yes | Collection ID |
770
780
  | `autoplay` | No | `true`, `false`, `1`, `0` |
771
781
  | `baseUrl` | No | API base URL |
782
+ | `apiVersion` | No | API version |
772
783
  | `controls` | No | `true`, `false`, `1`, `0` |
773
784
  | `showLogo` | No | `true`, `false`, `1`, `0` |
774
785
  | `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: collection.videos?.length || 0,
239
+ videoCount:
240
+ collection.videos?.length || collection.videoGroups?.reduce((sum, group) => sum + (group.videos?.length || 0), 0) || 0,
231
241
  });
232
242
  });
233
243
 
@@ -316,9 +326,12 @@
316
326
  </script>
317
327
 
318
328
  <script
319
- src="https://cdn.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
320
- onerror="console.error('[Embed Collection] Failed to load web component script'); showError('Failed to load collection player script');"
321
- onload="console.log('[Embed Collection] Web component script loaded');"
329
+ src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
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>
@@ -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
  }
@@ -325,9 +334,12 @@
325
334
  </script>
326
335
 
327
336
  <script
328
- src="https://cdn.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
329
- onerror="console.error('[Embed] Failed to load web component script'); showError('Failed to load player script');"
330
- onload="console.log('[Embed] Web component script loaded');"
337
+ src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
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/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.
@@ -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
@@ -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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,gBAAgB,CAAC;QAC5B,OAAO;QACP,MAAM;QACN,QAAQ;AACR,QAAA,KAAK,EAAE,SAAS,IAAK,UAAU,CAAC,KAA+B;AAChE,KAAA,CAAC;AAEF,IAAA,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;AAClC;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/core/httpClient.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 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AAE,UAAU,CAAC;IACzC;AAEA;;;AAGG;IACH,OAAO,IAAI,CAA+B,MAAiB,EAAA;AACzD,QAAA,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B;AACD;AAED;;;AAGG;AACG,SAAU,gBAAgB,CAA+B,MAAiB,EAAA;AAC9E,IAAA,OAAO,WAAW,CAAC,MAAM,CAAC;AAC5B;AAEM,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,120 @@ type CollectionDTO = {
40
50
  videos: VideoDTO[];
41
51
  };
42
52
 
43
- type CollectionsResource = {
44
- list(): Promise<CollectionDTO[]>;
45
- getById(_id: string): Promise<CollectionDTO>;
53
+ type CreatorV2DTO = {
54
+ id: string;
55
+ name: string;
56
+ biography: string;
57
+ imageUrl: string;
58
+ type: string;
46
59
  };
47
60
 
48
- type ISODateTimeString = string;
49
- interface ApiError {
61
+ type CtaV2DTO = {
62
+ url?: string;
63
+ label?: string;
64
+ labelColor?: string;
65
+ };
66
+
67
+ type SubtitleV2DTO = {
68
+ code: string;
69
+ url: string;
70
+ default?: boolean;
71
+ };
72
+
73
+ type VideoV2DTO = {
74
+ id: string;
75
+ videoId: string;
76
+ question: string;
77
+ transcription: string;
78
+ subtitles: SubtitleV2DTO[];
79
+ videoUrl: string;
80
+ tags: string[];
81
+ severity: number | null;
82
+ duration: number;
50
83
  description: string;
51
- error: string;
52
- }
84
+ creator?: CreatorV2DTO;
85
+ cta?: CtaV2DTO;
86
+ allowFeedbackWidget?: boolean;
87
+ };
53
88
 
54
- interface Subtopic {
89
+ type VideoGroupV2DTO = {
90
+ id: string;
91
+ title: string;
92
+ videos: VideoV2DTO[];
93
+ };
94
+
95
+ type CollectionV2DTO = {
55
96
  id: string;
56
97
  name: string;
57
- createdAt: ISODateTimeString;
58
- modifiedAt: ISODateTimeString;
59
- modifiedBy: ISODateTimeString;
60
- }
98
+ description: string;
99
+ imageUrl: string;
100
+ idleVideo: {
101
+ id: string;
102
+ duration: number;
103
+ videoUrl: string;
104
+ } | null;
105
+ videoGroups: VideoGroupV2DTO[];
106
+ };
107
+
108
+ type VideosResource = {
109
+ getById(_id: string): Promise<VideoDTO>;
110
+ };
111
+
112
+ type CollectionsResource = {
113
+ list(): Promise<CollectionDTO[]>;
114
+ getById(_id: string): Promise<CollectionDTO>;
115
+ };
116
+
117
+ type VideosResourceV2 = {
118
+ getById(_id: string): Promise<VideoV2DTO>;
119
+ };
120
+
121
+ type CollectionsResourceV2 = {
122
+ list(): Promise<CollectionV2DTO[]>;
123
+ getById(_id: string): Promise<CollectionV2DTO>;
124
+ };
61
125
 
62
126
  declare const BASE_URL: string;
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
  * Canonical factory (idiomatic for JS/TS).
88
162
  * Delegates to the single source of truth: `buildClient`.
89
163
  */
90
- declare function createJaaqClient(config: SDKConfig): JaaqClient;
164
+ declare function createJaaqClient<T extends ClientVersion = V1>(config: SDKConfig): JaaqClient<T>;
165
+ declare function createJaaqClientV1(config: SDKConfig): JaaqClient<V1>;
166
+ declare function createJaaqClientV2(config: SDKConfig): JaaqClient<V2>;
91
167
 
92
- export { BASE_URL, JaaqClient, createJaaqClient };
93
- export type { ApiError, CollectionDTO, ISODateTimeString, SDKConfig, Subtopic, VideoDTO };
168
+ export { BASE_URL, JaaqClient, createJaaqClient, createJaaqClientV1, createJaaqClientV2 };
169
+ export type { ApiError, ClientVersion, CollectionDTO, CollectionV2DTO, CreatorV2DTO, CtaV2DTO, ISODateTimeString, SDKConfig, SubtitleV2DTO, 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/v1/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
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
- this.videos = createVideosResource(http);
82
- this.collections = createCollectionsResource(http);
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